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.
- package/README.md +8 -1
- package/dist/cli/index.js +8 -8
- package/dist/cli/index.js.map +1 -1
- package/dist/client/config.d.ts +6 -0
- package/dist/client/config.js +6 -0
- package/dist/client/config.js.map +1 -1
- package/dist/client/git.d.ts +5 -0
- package/dist/client/git.js +21 -4
- package/dist/client/git.js.map +1 -1
- package/dist/client/hooks.d.ts +1 -0
- package/dist/client/hooks.js +1 -1
- package/dist/client/hooks.js.map +1 -1
- package/dist/client/setup-files.d.ts +13 -3
- package/dist/client/setup-files.js +30 -12
- package/dist/client/setup-files.js.map +1 -1
- package/dist/client/workspace.js +1 -1
- package/dist/client/workspace.js.map +1 -1
- package/dist/core/room.d.ts +5 -0
- package/dist/core/room.js +29 -15
- package/dist/core/room.js.map +1 -1
- package/dist/dashboard/model.d.ts +2 -0
- package/dist/dashboard/model.js +1 -0
- package/dist/dashboard/model.js.map +1 -1
- package/dist/server/app.d.ts +4 -2
- package/dist/server/app.js +10 -11
- package/dist/server/app.js.map +1 -1
- package/dist/server/serve.d.ts +9 -0
- package/dist/server/serve.js +41 -1
- package/dist/server/serve.js.map +1 -1
- package/dist/store/file-store.d.ts +3 -0
- package/dist/store/file-store.js +32 -1
- package/dist/store/file-store.js.map +1 -1
- package/dist/store/memory-store.d.ts +2 -0
- package/dist/store/memory-store.js +14 -1
- package/dist/store/memory-store.js.map +1 -1
- package/dist/store/store.d.ts +4 -0
- package/dist/store/store.js +3 -0
- package/dist/store/store.js.map +1 -1
- package/dist/web/join-page.d.ts +9 -0
- package/dist/web/join-page.js +119 -0
- package/dist/web/join-page.js.map +1 -0
- package/dist/web/page.d.ts +3 -3
- package/dist/web/page.js +380 -142
- package/dist/web/page.js.map +1 -1
- package/dist/web/payload.d.ts +29 -0
- package/dist/web/payload.js +85 -15
- package/dist/web/payload.js.map +1 -1
- package/package.json +1 -1
package/dist/store/store.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/store/store.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IACd,MAAM;IAAlC,YAA4B,MAAc;QACxC,KAAK,CAAC,QAAQ,MAAM,kBAAkB,CAAC,CAAC;sBADd,MAAM;QAEhC,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;IAClC,CAAC;CACF;AAED,MAAM,OAAO,sBAAuB,SAAQ,KAAK;IACnB,MAAM;IAAlC,YAA4B,MAAc;QACxC,KAAK,CAAC,QAAQ,MAAM,kBAAkB,CAAC,CAAC;sBADd,MAAM;QAEhC,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;IACvC,CAAC;CACF;AAED,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IAClB,MAAM;IAAlC,YAA4B,MAAc;QACxC,KAAK,CAAC,gDAAgD,MAAM,GAAG,CAAC,CAAC;sBADvC,MAAM;QAEhC,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;IACtC,CAAC;CACF"}
|
|
1
|
+
{"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/store/store.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IACd,MAAM;IAAlC,YAA4B,MAAc;QACxC,KAAK,CAAC,QAAQ,MAAM,kBAAkB,CAAC,CAAC;sBADd,MAAM;QAEhC,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;IAClC,CAAC;CACF;AAED,MAAM,OAAO,sBAAuB,SAAQ,KAAK;IACnB,MAAM;IAAlC,YAA4B,MAAc;QACxC,KAAK,CAAC,QAAQ,MAAM,kBAAkB,CAAC,CAAC;sBADd,MAAM;QAEhC,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;IACvC,CAAC;CACF;AAED,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IAClB,MAAM;IAAlC,YAA4B,MAAc;QACxC,KAAK,CAAC,gDAAgD,MAAM,GAAG,CAAC,CAAC;sBADvC,MAAM;QAEhC,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;IACtC,CAAC;CACF;AAeD,MAAM,UAAU,WAAW,CAAC,IAAU,EAAE,MAAY;IAClD,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC;AACvD,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The page an invite link opens. The invite code sits after the #, which
|
|
3
|
+
* browsers never send, so the server cannot write it into the page: the
|
|
4
|
+
* script reads it from the address bar and fills in the exact commands.
|
|
5
|
+
*/
|
|
6
|
+
export declare const JOIN_PLACEHOLDER_COMMAND = "teamroom join '<paste the full invite link here>'";
|
|
7
|
+
export declare const JOIN_HTML: string;
|
|
8
|
+
export declare const JOIN_STYLES = "\n:root {\n --paper: #EDF0F3;\n --surface: #FFFFFF;\n --ink: #16233A;\n --muted: #56657A;\n --rule: #CBD3DD;\n --agent: #5B4BD6;\n --overlap: #F4C84A;\n --overlap-ink: #5A4300;\n --words: \"Schibsted Grotesk\", ui-sans-serif, system-ui, -apple-system, \"Segoe UI\", sans-serif;\n --code: \"JetBrains Mono\", ui-monospace, \"SF Mono\", Menlo, Consolas, monospace;\n color-scheme: light dark;\n}\n@media (prefers-color-scheme: dark) {\n :root {\n --paper: #121A28;\n --surface: #1A2436;\n --ink: #E6ECF3;\n --muted: #9AA8BB;\n --rule: #2C3A50;\n --agent: #9489F2;\n }\n}\n* { box-sizing: border-box; }\nhtml { background: var(--paper); color: var(--ink); font-family: var(--words); font-size: 16px; line-height: 1.5; }\nbody { margin: 0; }\n.join { max-width: 640px; margin: 0 auto; padding: 56px 20px 64px; }\nh1 { font-size: 28px; line-height: 1.2; margin: 0 0 10px; }\n.lede { color: var(--muted); margin: 0 0 32px; }\n.steps { list-style: none; counter-reset: step; margin: 0; padding: 0; display: grid; gap: 16px; }\n.steps > li { counter-increment: step; background: var(--surface); border: 1px solid var(--rule); border-radius: 10px; padding: 18px 20px 20px; }\n.steps h2 { font-size: 17px; margin: 0 0 2px; }\n.steps h2::before { content: counter(step) \". \"; color: var(--muted); }\n.steps p { margin: 0 0 12px; color: var(--muted); }\n.command { display: flex; align-items: flex-start; gap: 8px; }\n.command code { flex: 1; min-width: 0; font-family: var(--code); font-size: 13.5px; background: var(--paper); border: 1px solid var(--rule); border-radius: 4px; padding: 10px 12px; overflow-wrap: anywhere; user-select: all; }\n.command button { flex: none; font: inherit; font-weight: 600; font-size: 14px; color: #FFFFFF; background: var(--agent); border: 0; border-radius: 4px; padding: 10px 16px; line-height: 1.5; cursor: pointer; }\n.command button:focus-visible { outline: 3px solid var(--overlap); outline-offset: 2px; }\n.steps p.problem { margin: 12px 0 0; padding: 10px 12px; border-radius: 4px; background: var(--overlap); color: var(--overlap-ink); }\n.note { margin: 24px 0 0; color: var(--muted); font-size: 14px; }\n@media (max-width: 480px) {\n .command { flex-direction: column; align-items: stretch; }\n}\n";
|
|
9
|
+
export declare const JOIN_SCRIPT = "(function () {\n var ROOM_ID = /^room_[A-Za-z0-9_-]{16}$/;\n var INVITE_CODE = /^tri_[A-Za-z0-9_-]{16,128}$/;\n var COPIED_FOR_MS = 2000;\n\n var roomId = location.pathname.split(\"/\").pop();\n var inviteCode = location.hash.slice(1);\n var joinCommand = document.getElementById(\"join-command\");\n var incomplete = document.getElementById(\"link-incomplete\");\n\n if (ROOM_ID.test(roomId) && INVITE_CODE.test(inviteCode)) {\n joinCommand.textContent = \"teamroom join '\" + location.origin + location.pathname + \"#\" + inviteCode + \"'\";\n } else {\n incomplete.hidden = false;\n }\n\n var buttons = document.querySelectorAll(\"button[data-copy]\");\n for (var index = 0; index < buttons.length; index++) {\n buttons[index].addEventListener(\"click\", copyCommand);\n }\n\n function copyCommand(event) {\n var button = event.currentTarget;\n var text = document.getElementById(button.getAttribute(\"data-copy\")).textContent;\n if (!navigator.clipboard) return;\n navigator.clipboard.writeText(text).then(function () {\n button.textContent = \"Copied\";\n setTimeout(function () { button.textContent = \"Copy\"; }, COPIED_FOR_MS);\n });\n }\n})();\n";
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The page an invite link opens. The invite code sits after the #, which
|
|
3
|
+
* browsers never send, so the server cannot write it into the page: the
|
|
4
|
+
* script reads it from the address bar and fills in the exact commands.
|
|
5
|
+
*/
|
|
6
|
+
export const JOIN_PLACEHOLDER_COMMAND = "teamroom join '<paste the full invite link here>'";
|
|
7
|
+
const FAVICON = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Ccircle cx='8' cy='8' r='6' fill='%23F4C84A'/%3E%3C/svg%3E";
|
|
8
|
+
export const JOIN_HTML = `<!DOCTYPE html>
|
|
9
|
+
<html lang="en">
|
|
10
|
+
<head>
|
|
11
|
+
<meta charset="utf-8">
|
|
12
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
13
|
+
<title>Join a teamroom</title>
|
|
14
|
+
<link rel="icon" href="${FAVICON}">
|
|
15
|
+
<link rel="stylesheet" href="/join.css">
|
|
16
|
+
<script src="/join.js" defer></script>
|
|
17
|
+
</head>
|
|
18
|
+
<body>
|
|
19
|
+
<main class="join">
|
|
20
|
+
<h1>You're invited to a teamroom</h1>
|
|
21
|
+
<p class="lede">Once you join, your coding agents and your teammates' agents see which files each of you is changing, before the work collides.</p>
|
|
22
|
+
<ol class="steps">
|
|
23
|
+
<li>
|
|
24
|
+
<h2>Install teamroom</h2>
|
|
25
|
+
<p>Once per computer. It needs Node.js 22 or newer.</p>
|
|
26
|
+
<div class="command"><code id="install-command">npm install --global teamroom</code><button type="button" data-copy="install-command">Copy</button></div>
|
|
27
|
+
</li>
|
|
28
|
+
<li>
|
|
29
|
+
<h2>Join from the repo</h2>
|
|
30
|
+
<p>Run this in the folder of the git repo you work on.</p>
|
|
31
|
+
<div class="command"><code id="join-command">${JOIN_PLACEHOLDER_COMMAND.replace("<", "<").replace(">", ">")}</code><button type="button" data-copy="join-command">Copy</button></div>
|
|
32
|
+
<p id="link-incomplete" class="problem" hidden>This link is missing its invite code, the part after the #. Ask whoever invited you to send the whole link again.</p>
|
|
33
|
+
</li>
|
|
34
|
+
</ol>
|
|
35
|
+
<p class="note">Keep this link to yourself: anyone who has it can join the room.</p>
|
|
36
|
+
</main>
|
|
37
|
+
</body>
|
|
38
|
+
</html>
|
|
39
|
+
`;
|
|
40
|
+
export const JOIN_STYLES = `
|
|
41
|
+
:root {
|
|
42
|
+
--paper: #EDF0F3;
|
|
43
|
+
--surface: #FFFFFF;
|
|
44
|
+
--ink: #16233A;
|
|
45
|
+
--muted: #56657A;
|
|
46
|
+
--rule: #CBD3DD;
|
|
47
|
+
--agent: #5B4BD6;
|
|
48
|
+
--overlap: #F4C84A;
|
|
49
|
+
--overlap-ink: #5A4300;
|
|
50
|
+
--words: "Schibsted Grotesk", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
|
|
51
|
+
--code: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
|
|
52
|
+
color-scheme: light dark;
|
|
53
|
+
}
|
|
54
|
+
@media (prefers-color-scheme: dark) {
|
|
55
|
+
:root {
|
|
56
|
+
--paper: #121A28;
|
|
57
|
+
--surface: #1A2436;
|
|
58
|
+
--ink: #E6ECF3;
|
|
59
|
+
--muted: #9AA8BB;
|
|
60
|
+
--rule: #2C3A50;
|
|
61
|
+
--agent: #9489F2;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
* { box-sizing: border-box; }
|
|
65
|
+
html { background: var(--paper); color: var(--ink); font-family: var(--words); font-size: 16px; line-height: 1.5; }
|
|
66
|
+
body { margin: 0; }
|
|
67
|
+
.join { max-width: 640px; margin: 0 auto; padding: 56px 20px 64px; }
|
|
68
|
+
h1 { font-size: 28px; line-height: 1.2; margin: 0 0 10px; }
|
|
69
|
+
.lede { color: var(--muted); margin: 0 0 32px; }
|
|
70
|
+
.steps { list-style: none; counter-reset: step; margin: 0; padding: 0; display: grid; gap: 16px; }
|
|
71
|
+
.steps > li { counter-increment: step; background: var(--surface); border: 1px solid var(--rule); border-radius: 10px; padding: 18px 20px 20px; }
|
|
72
|
+
.steps h2 { font-size: 17px; margin: 0 0 2px; }
|
|
73
|
+
.steps h2::before { content: counter(step) ". "; color: var(--muted); }
|
|
74
|
+
.steps p { margin: 0 0 12px; color: var(--muted); }
|
|
75
|
+
.command { display: flex; align-items: flex-start; gap: 8px; }
|
|
76
|
+
.command code { flex: 1; min-width: 0; font-family: var(--code); font-size: 13.5px; background: var(--paper); border: 1px solid var(--rule); border-radius: 4px; padding: 10px 12px; overflow-wrap: anywhere; user-select: all; }
|
|
77
|
+
.command button { flex: none; font: inherit; font-weight: 600; font-size: 14px; color: #FFFFFF; background: var(--agent); border: 0; border-radius: 4px; padding: 10px 16px; line-height: 1.5; cursor: pointer; }
|
|
78
|
+
.command button:focus-visible { outline: 3px solid var(--overlap); outline-offset: 2px; }
|
|
79
|
+
.steps p.problem { margin: 12px 0 0; padding: 10px 12px; border-radius: 4px; background: var(--overlap); color: var(--overlap-ink); }
|
|
80
|
+
.note { margin: 24px 0 0; color: var(--muted); font-size: 14px; }
|
|
81
|
+
@media (max-width: 480px) {
|
|
82
|
+
.command { flex-direction: column; align-items: stretch; }
|
|
83
|
+
}
|
|
84
|
+
`;
|
|
85
|
+
// ES5 on purpose, like the dashboard script: it runs in whatever browser the teammate opens the link in.
|
|
86
|
+
// Only ids and codes of the expected shape are written into the command, so it is always safe to paste into a shell.
|
|
87
|
+
export const JOIN_SCRIPT = `(function () {
|
|
88
|
+
var ROOM_ID = /^room_[A-Za-z0-9_-]{16}$/;
|
|
89
|
+
var INVITE_CODE = /^tri_[A-Za-z0-9_-]{16,128}$/;
|
|
90
|
+
var COPIED_FOR_MS = 2000;
|
|
91
|
+
|
|
92
|
+
var roomId = location.pathname.split("/").pop();
|
|
93
|
+
var inviteCode = location.hash.slice(1);
|
|
94
|
+
var joinCommand = document.getElementById("join-command");
|
|
95
|
+
var incomplete = document.getElementById("link-incomplete");
|
|
96
|
+
|
|
97
|
+
if (ROOM_ID.test(roomId) && INVITE_CODE.test(inviteCode)) {
|
|
98
|
+
joinCommand.textContent = "teamroom join '" + location.origin + location.pathname + "#" + inviteCode + "'";
|
|
99
|
+
} else {
|
|
100
|
+
incomplete.hidden = false;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
var buttons = document.querySelectorAll("button[data-copy]");
|
|
104
|
+
for (var index = 0; index < buttons.length; index++) {
|
|
105
|
+
buttons[index].addEventListener("click", copyCommand);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function copyCommand(event) {
|
|
109
|
+
var button = event.currentTarget;
|
|
110
|
+
var text = document.getElementById(button.getAttribute("data-copy")).textContent;
|
|
111
|
+
if (!navigator.clipboard) return;
|
|
112
|
+
navigator.clipboard.writeText(text).then(function () {
|
|
113
|
+
button.textContent = "Copied";
|
|
114
|
+
setTimeout(function () { button.textContent = "Copy"; }, COPIED_FOR_MS);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
})();
|
|
118
|
+
`;
|
|
119
|
+
//# sourceMappingURL=join-page.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"join-page.js","sourceRoot":"","sources":["../../src/web/join-page.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,CAAC,MAAM,wBAAwB,GAAG,mDAAmD,CAAC;AAE5F,MAAM,OAAO,GACX,iJAAiJ,CAAC;AAEpJ,MAAM,CAAC,MAAM,SAAS,GAAG;;;;;;yBAMA,OAAO;;;;;;;;;;;;;;;;;+CAiBe,wBAAwB,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,CAAC;;;;;;;;CAQhH,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4C1B,CAAC;AAEF,yGAAyG;AACzG,qHAAqH;AACrH,MAAM,CAAC,MAAM,WAAW,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+B1B,CAAC"}
|
package/dist/web/page.d.ts
CHANGED
|
@@ -10,6 +10,6 @@ export declare const PAGE_SECURITY_HEADERS: {
|
|
|
10
10
|
readonly "Referrer-Policy": "no-referrer";
|
|
11
11
|
readonly "Cache-Control": "no-store";
|
|
12
12
|
};
|
|
13
|
-
export declare const PAGE_HTML = "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\">\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n<title>teamroom</title>\n<link rel=\"icon\" href=\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Ccircle cx='8' cy='8' r='6' fill='%23F4C84A'/%3E%3C/svg%3E\">\n<link rel=\"stylesheet\" href=\"/app.css\">\n<script src=\"/app.js\" defer></script>\n</head>\n<body>\n<header class=\"top\">\n <p class=\"brand\"><span class=\"dot\" aria-hidden=\"true\"></span>teamroom</p>\n <p class=\"where\" id=\"where\">Loading the room\u2026</p>\n <p class=\"
|
|
14
|
-
export declare const PAGE_STYLES = "\n:root {\n --paper: #EDF0F3;\n --surface: #FFFFFF;\n --ink: #16233A;\n --muted: #56657A;\n --rule: #CBD3DD;\n --working: #1F8A7A;\n --agent: #5B4BD6;\n --overlap: #F4C84A;\n --overlap-ink: #5A4300;\n --mark-band: var(--overlap);\n --radius-panel: 10px;\n --radius-chip: 4px;\n --words: \"Schibsted Grotesk\", ui-sans-serif, system-ui, -apple-system, \"Segoe UI\", sans-serif;\n --code: \"JetBrains Mono\", ui-monospace, \"SF Mono\", Menlo, Consolas, monospace;\n color-scheme: light dark;\n}\n@media (prefers-color-scheme: dark) {\n :root {\n --paper: #121A28;\n --surface: #1A2436;\n --ink: #E6ECF3;\n --muted: #9AA8BB;\n --rule: #2C3A50;\n --working: #3DBFA9;\n --agent: #9489F2;\n --overlap-ink: #2A1F00;\n --mark-band: color-mix(in srgb, var(--overlap) 40%, var(--paper));\n }\n}\n* { box-sizing: border-box; }\nhtml { background: var(--paper); color: var(--ink); font-family: var(--words); font-size: 16px; line-height: 1.5; }\nbody { margin: 0 auto; max-width: 1120px; padding: 24px 28px 64px; }\nh1, h2, p, ul, ol { margin: 0; }\nul, ol { padding: 0; list-style: none; }\
|
|
15
|
-
export declare const PAGE_SCRIPT = "\"use strict\";\n(function () {\n var POLL_MS = 3000;\n var MAX_BACKOFF_MS = 30000;\n var REQUEST_TIMEOUT_MS = 10000;\n var FILES_SHOWN = 8;\n var SHARED_FILES_SHOWN = 5;\n var KIND_WORDS = { wip: \"Shared changes\", note: \"Plan\", edit: \"Agent edit\", commit: \"Commit\" };\n\n // A view link carries the room and a read-only key after the #, which the browser never sends to the server.\n var linkParams = new URLSearchParams(location.hash.slice(1));\n var viewRoom = linkParams.get(\"room\");\n var viewKey = linkParams.get(\"key\");\n var hosted = location.pathname === \"/view\";\n var STOP_POLLING = -1;\n\n var failures = 0;\n var lastData = null;\n var lastVerdict = \"\";\n var hadSharedFiles = false;\n\n function el(tag, className, children) {\n var node = document.createElement(tag);\n if (className) node.className = className;\n [].concat(children === undefined ? [] : children).forEach(function (child) {\n if (child === null || child === undefined || child === false || child === \"\") return;\n node.append(child);\n });\n return node;\n }\n\n function plural(count, word) {\n return count + \" \" + word + (count === 1 ? \"\" : \"s\");\n }\n\n function ago(iso, now) {\n var seconds = Math.max(0, Math.round((now - Date.parse(iso)) / 1000));\n if (seconds < 60) return \"just now\";\n var minutes = Math.round(seconds / 60);\n if (minutes < 60) return minutes + \" min ago\";\n var hours = Math.round(minutes / 60);\n if (hours < 48) return plural(hours, \"hour\") + \" ago\";\n return plural(Math.round(hours / 24), \"day\") + \" ago\";\n }\n\n function personName(data, member) {\n return member === data.me ? \"You\" : member;\n }\n\n function renderTop(data) {\n var where = document.getElementById(\"where\");\n var scope = data.room.mode === \"local\"\n ? \"only on this computer\"\n : \"shared with \" + (data.room.people === 1 ? \"1 person\" : data.room.people + \" people\");\n where.replaceChildren(el(\"strong\", \"\", data.room.name), \", \" + scope);\n }\n\n function touchCard(data, session) {\n return el(\"div\", \"touch\", [\n el(\"p\", \"name\", session.label),\n el(\"p\", \"who\", [personName(data, session.member), session.agent ? el(\"span\", \"agent\", \", with \" + session.agent) : \", no agent\"]),\n el(\"p\", \"plan\", session.plan || session.doing)\n ]);\n }\n\n function renderVerdict(data) {\n var byKey = {};\n data.sessions.forEach(function (session) { byKey[session.key] = session; });\n var signature = JSON.stringify([data.sessions.length, data.sharedFiles, data.sharedFiles.map(function (file) {\n return file.sessionKeys.map(function (key) { return byKey[key] && [byKey[key].doing, byKey[key].agent]; });\n })]);\n if (signature === lastVerdict) return;\n lastVerdict = signature;\n\n var verdict = document.getElementById(\"verdict\");\n var hasShared = data.sharedFiles.length > 0;\n var arriving = hasShared && !hadSharedFiles;\n hadSharedFiles = hasShared;\n\n if (data.sessions.length === 0) {\n verdict.replaceChildren(\n el(\"h1\", \"\", \"Nobody has shared any work yet.\"),\n el(\"p\", \"\", [\"Make a commit in a project folder, or run \", el(\"span\", \"mono\", \"teamroom report\"), \", and it shows up here.\"])\n );\n return;\n }\n\n if (!hasShared) {\n verdict.replaceChildren(\n el(\"h1\", \"\", \"Everyone is working in their own files.\"),\n el(\"p\", \"\", \"No file is being changed in two places right now.\")\n );\n return;\n }\n\n var first = data.sharedFiles[0];\n var heading = data.sharedFiles.length === 1\n ? el(\"h1\", \"\", [el(\"mark\", arriving ? \"arrive\" : \"\", el(\"span\", \"mono\", first.path)), \" is being changed in \" + first.sessionKeys.length + \" places.\"])\n : el(\"h1\", \"\", [el(\"mark\", arriving ? \"arrive\" : \"\", plural(data.sharedFiles.length, \"file\")), \" are being changed in more than one place.\"]);\n\n var allMine = data.sharedFiles.every(function (file) {\n return file.sessionKeys.every(function (key) { return byKey[key] && byKey[key].isMine; });\n });\n var advice = allMine\n ? \"These are all your own folders. Let one finish before the other continues, or they will clash when you merge.\"\n : \"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.\";\n\n var meets = el(\"div\", \"meets\", data.sharedFiles.slice(0, SHARED_FILES_SHOWN).map(function (file) {\n var touching = file.sessionKeys.map(function (key) { return byKey[key]; }).filter(Boolean);\n var chip = el(\"p\", \"file\", file.path);\n if (touching.length === 2) {\n return el(\"div\", \"meet two\", [touchCard(data, touching[0]), chip, touchCard(data, touching[1])]);\n }\n return el(\"div\", \"meet many\", [chip].concat(touching.map(function (session) { return touchCard(data, session); })));\n }));\n\n verdict.replaceChildren(heading, el(\"p\", \"\", advice), meets);\n }\n\n function renderSessions(data, now) {\n var list = document.getElementById(\"sessions\");\n if (data.sessions.length === 0) {\n list.replaceChildren(el(\"li\", \"none\", \"No one has worked here in the last 3 days.\"));\n return;\n }\n list.replaceChildren.apply(list, data.sessions.map(function (session) {\n var state = el(\"span\", \"state\" + (session.active ? \" on\" : \"\"));\n state.setAttribute(\"title\", session.active ? \"Working now\" : \"Quiet\");\n state.setAttribute(\"aria-label\", session.active ? \"Working now\" : \"Quiet\");\n state.setAttribute(\"role\", \"img\");\n\n var shown = session.files.slice(0, FILES_SHOWN);\n var hidden = session.files.length - shown.length;\n var files = shown.map(function (file) {\n var chip = el(\"span\", \"chip\" + (file.shared ? \" shared\" : \"\"), file.path);\n if (file.shared) chip.setAttribute(\"title\", \"Also being changed somewhere else\");\n return chip;\n });\n if (hidden > 0) files.push(el(\"span\", \"more\", \"and \" + hidden + \" more\"));\n\n return el(\"li\", \"session\", [\n state,\n el(\"p\", \"title\", [session.label, session.isHere ? el(\"span\", \"here\", \"this folder\") : null]),\n el(\"p\", \"age\", ago(session.lastSeen, now)),\n el(\"p\", \"meta\", [\n el(\"span\", \"\", personName(data, session.member)),\n session.branch ? el(\"span\", \"\", [\"on \", el(\"span\", \"mono\", session.branch)]) : null,\n session.agent ? el(\"span\", \"agent\", session.agent) : el(\"span\", \"\", \"No agent\")\n ]),\n el(\"p\", \"doing\", session.plan || session.doing),\n files.length > 0 ? el(\"div\", \"files\", files) : null\n ]);\n }));\n }\n\n function renderLog(data, now) {\n var log = document.getElementById(\"log\");\n if (data.recent.length === 0) {\n log.replaceChildren(el(\"li\", \"\", \"Nothing yet.\"));\n return;\n }\n log.replaceChildren.apply(log, data.recent.map(function (entry) {\n var who = personName(data, entry.member) + (entry.sessionLabel ? \" in \" + entry.sessionLabel : \"\");\n return el(\"li\", entry.kind, [\n el(\"p\", \"line1\", [\n el(\"span\", \"kind\", KIND_WORDS[entry.kind] || entry.kind),\n el(\"span\", \"\", who + (entry.agent ? \", \" + entry.agent : \"\")),\n el(\"span\", \"\", ago(entry.at, now))\n ]),\n el(\"p\", \"text\", [entry.text, entry.count > 1 ? el(\"span\", \"times\", entry.count + \" times\") : null])\n ]);\n }));\n }\n\n function render(data) {\n var now = Date.now();\n renderTop(data);\n renderVerdict(data);\n renderSessions(data, now);\n renderLog(data, now);\n }\n\n function showProblem(message, retryMs) {\n var problem = document.getElementById(\"problem\");\n var shownSince = lastData ? \" Showing what was there \" + ago(lastData.updatedAt, Date.now()) + \".\" : \"\";\n problem.textContent = \"Can't reach the room: \" + message + shownSince + \" Trying again in \" + Math.round(retryMs / 1000) + \" s.\";\n problem.hidden = false;\n }\n\n function showUpdated() {\n document.getElementById(\"updated\").textContent = lastData ? \"Updated \" + ago(lastData.updatedAt, Date.now()) : \"\";\n }\n\n function request(signal) {\n if (!hosted) return fetch(\"/api/dashboard\", { signal: signal, cache: \"no-store\" });\n return fetch(\"/v1/rooms/\" + encodeURIComponent(viewRoom) + \"/dashboard\", {\n signal: signal,\n cache: \"no-store\",\n headers: { Authorization: \"Bearer \" + viewKey }\n });\n }\n\n function stopWith(message) {\n var problem = document.getElementById(\"problem\");\n problem.textContent = message;\n problem.hidden = false;\n document.getElementById(\"where\").textContent = \"\";\n document.querySelector(\"main\").hidden = true;\n }\n\n function poll() {\n var controller = new AbortController();\n var timeout = setTimeout(function () { controller.abort(); }, REQUEST_TIMEOUT_MS);\n request(controller.signal)\n .then(function (response) {\n if (response.status === 401 || response.status === 404) {\n var refused = new Error(\"refused\");\n refused.name = \"Refused\";\n throw refused;\n }\n return response.json().then(function (body) {\n if (!response.ok || !body.data) throw new Error((body.error && body.error.message) || \"the dashboard stopped answering.\");\n return body.data;\n });\n })\n .then(function (data) {\n failures = 0;\n lastData = data;\n document.getElementById(\"problem\").hidden = true;\n render(data);\n })\n .catch(function (error) {\n if (error && error.name === \"Refused\") {\n failures = STOP_POLLING;\n stopWith(\"This link no longer opens the room. The owner may have turned it off or made a new one: ask them for the current link.\");\n return;\n }\n failures += 1;\n var message = error && error.name === \"AbortError\"\n ? \"it took too long to answer.\"\n : error && error.name === \"TypeError\"\n ? (hosted ? \"the server did not answer.\" : \"the terminal that opened this page was closed.\")\n : (error && error.message) || \"unknown error.\";\n showProblem(message, Math.min(POLL_MS * Math.pow(2, failures), MAX_BACKOFF_MS));\n })\n .finally(function () {\n clearTimeout(timeout);\n showUpdated();\n if (failures === STOP_POLLING) return;\n setTimeout(poll, Math.min(POLL_MS * Math.pow(2, failures), MAX_BACKOFF_MS));\n });\n }\n\n if (hosted) {\n document.getElementById(\"closing\").textContent = \"This page updates on its own. It can only look: nothing you do here changes the room.\";\n }\n if (hosted && (!viewRoom || !viewKey)) {\n stopWith(\"This link is missing its key. Ask the room owner for the full view link: it ends with #room=...&key=...\");\n } else {\n poll();\n }\n})();\n";
|
|
13
|
+
export declare const PAGE_HTML = "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\">\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n<title>teamroom</title>\n<link rel=\"icon\" href=\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Ccircle cx='8' cy='8' r='6' fill='%23F4C84A'/%3E%3C/svg%3E\">\n<link rel=\"stylesheet\" href=\"/app.css\">\n<script src=\"/app.js\" defer></script>\n</head>\n<body>\n<header class=\"top\">\n <p class=\"brand\"><span class=\"dot\" aria-hidden=\"true\"></span>teamroom</p>\n <p class=\"where\" id=\"where\">Loading the room\u2026</p>\n <p class=\"live\" id=\"live\"><span class=\"pulse\" aria-hidden=\"true\"></span><span id=\"updated\">Connecting</span></p>\n</header>\n<p class=\"problem\" id=\"problem\" role=\"status\" hidden></p>\n<main>\n <section class=\"verdict\" id=\"verdict\" aria-live=\"polite\"></section>\n <div class=\"columns\">\n <section aria-labelledby=\"who-title\">\n <h2 id=\"who-title\">Who is working</h2>\n <ul class=\"people\" id=\"sessions\"></ul>\n </section>\n <section aria-labelledby=\"log-title\">\n <h2 id=\"log-title\">What happened</h2>\n <ol class=\"log\" id=\"log\"></ol>\n </section>\n </div>\n</main>\n<footer class=\"how\">\n <details>\n <summary>How this works</summary>\n <p>Every folder where someone works on this project shares the names of the files it is changing, never what is in them.</p>\n <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>\n <p id=\"closing\">This page updates on its own. To close it, stop the terminal that opened it.</p>\n </details>\n</footer>\n</body>\n</html>\n";
|
|
14
|
+
export declare const PAGE_STYLES = "\n:root {\n --paper: #EDF0F3;\n --surface: #FFFFFF;\n --ink: #16233A;\n --muted: #56657A;\n --rule: #CBD3DD;\n --working: #1F8A7A;\n --agent: #5B4BD6;\n --overlap: #F4C84A;\n --overlap-ink: #5A4300;\n --mark-band: var(--overlap);\n --radius-panel: 10px;\n --radius-chip: 4px;\n --words: \"Schibsted Grotesk\", ui-sans-serif, system-ui, -apple-system, \"Segoe UI\", sans-serif;\n --code: \"JetBrains Mono\", ui-monospace, \"SF Mono\", Menlo, Consolas, monospace;\n color-scheme: light dark;\n}\n@media (prefers-color-scheme: dark) {\n :root {\n --paper: #121A28;\n --surface: #1A2436;\n --ink: #E6ECF3;\n --muted: #9AA8BB;\n --rule: #2C3A50;\n --working: #3DBFA9;\n --agent: #9489F2;\n --overlap-ink: #2A1F00;\n --mark-band: color-mix(in srgb, var(--overlap) 40%, var(--paper));\n }\n}\n* { box-sizing: border-box; }\nhtml { background: var(--paper); color: var(--ink); font-family: var(--words); font-size: 16px; line-height: 1.5; }\nbody { margin: 0 auto; max-width: 1120px; padding: 24px 28px 64px; }\nh1, h2, p, ul, ol { margin: 0; }\nul, ol { padding: 0; list-style: none; }\nbutton { font: inherit; }\n:focus-visible { outline: 3px solid var(--overlap); outline-offset: 2px; border-radius: var(--radius-chip); }\n\n.top { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 20px; padding-bottom: 18px; border-bottom: 1px solid var(--rule); }\n.brand { font-weight: 800; letter-spacing: -0.02em; font-size: 18px; display: flex; align-items: center; gap: 8px; }\n.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); }\n.where { color: var(--muted); }\n.where strong { color: var(--ink); font-weight: 700; }\n.live { margin-left: auto; color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 8px; }\n.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--rule); }\n.live.ok .pulse { background: var(--working); }\n@media (prefers-reduced-motion: no-preference) {\n .live.ok .pulse { animation: pulse 2.4s ease-out infinite; }\n @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; } }\n}\n\n.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); }\n\n.verdict { padding: 52px 0 44px; }\n.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; }\n.verdict h1 .file { font-family: var(--code); font-size: 0.8em; font-weight: 700; letter-spacing: -0.02em; }\n.verdict > p { margin-top: 16px; color: var(--muted); font-size: 18px; max-width: 58ch; }\nmark { color: inherit; background: linear-gradient(transparent 60%, var(--mark-band) 60%, var(--mark-band) 92%, transparent 92%) no-repeat; background-size: 100% 100%; }\nmark.coming { background: none; text-decoration: underline 0.14em dashed var(--overlap); text-underline-offset: 0.16em; }\n@media (prefers-reduced-motion: no-preference) {\n mark.arrive { animation: band 700ms cubic-bezier(.2,.7,.2,1) both; }\n @keyframes band { from { background-size: 0% 100%; } to { background-size: 100% 100%; } }\n}\n\n.meets { margin-top: 34px; display: grid; gap: 22px; max-width: 940px; }\n.meet { position: relative; display: grid; gap: 16px; align-items: stretch; }\n.meet.two { grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); }\n.meet.two .shared-file { align-self: center; }\n.meet.two::before { content: \"\"; position: absolute; left: 12%; right: 12%; top: 50%; border-top: 2px solid var(--overlap); }\n.meet.two.coming::before { border-top-style: dashed; }\n.meet.many { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }\n.meet.many .shared-file { grid-column: 1 / -1; justify-self: start; }\n.shared-file .dir { opacity: 0.7; font-weight: 500; }\n.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); }\n.coming .shared-file { background: var(--surface); color: var(--ink); border: 2px dashed var(--overlap); }\n.touch { position: relative; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-panel); padding: 14px 16px; }\n.touch .head { display: flex; align-items: center; gap: 10px; }\n.touch .name { font-weight: 700; font-size: 17px; }\n.touch .role { color: var(--muted); font-size: 14px; }\n.touch .text { margin-top: 10px; }\n\n.columns { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr); gap: 44px; padding-top: 32px; border-top: 1px solid var(--rule); }\n.columns h2 { font-size: 15px; font-weight: 700; margin-bottom: 14px; }\n\n.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); }\n.avatar.small { width: 26px; height: 26px; font-size: 12px; }\n\n.people { display: grid; gap: 12px; }\n.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; }\n.person.waiting { border-color: var(--overlap); box-shadow: inset 3px 0 0 var(--overlap); }\n.person.quiet { border-style: dashed; }\n.person .avatar { grid-row: span 2; align-self: start; }\n.person .head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; }\n.person .name { font-weight: 700; font-size: 17px; }\n.person .place { color: var(--muted); font-size: 14px; }\n.status { margin-left: auto; font-size: 13px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }\n.status::before { content: \"\"; width: 8px; height: 8px; border-radius: 50%; border: 2px solid var(--rule); }\n.status.on::before { background: var(--working); border-color: var(--working); }\n.status.wait::before { background: var(--overlap); border-color: var(--overlap); }\n.person .meta { color: var(--muted); font-size: 14px; }\n.person .meta .branch { font-family: var(--code); font-size: 13px; }\n.person .body { grid-column: 1 / -1; margin-top: 10px; }\n.agent { color: var(--agent); font-weight: 600; }\n\n.clamp { overflow-wrap: anywhere; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; }\n.clamp.two { -webkit-line-clamp: 2; }\n.clamp.open { display: block; }\n.toggle { margin-top: 2px; padding: 0; border: 0; background: none; color: var(--agent); font-size: 14px; font-weight: 600; cursor: pointer; }\n\n.files { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }\n.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; }\n.chip .dir { color: var(--muted); }\n.chip.shared { background: var(--overlap); border-color: var(--overlap); color: var(--overlap-ink); }\n.chip.shared .dir { color: inherit; opacity: 0.75; }\n.chip.planned { border-style: dashed; border-color: var(--overlap); }\n.more { font-size: 13px; color: var(--muted); align-self: center; }\n.none { color: var(--muted); background: var(--surface); border: 1px dashed var(--rule); border-radius: var(--radius-panel); padding: 18px; }\n\n.log li { display: grid; grid-template-columns: 54px minmax(0, 1fr); gap: 2px 10px; padding: 10px 0; border-top: 1px solid var(--rule); }\n.log li:first-child { border-top: 0; padding-top: 0; }\n.log .when { color: var(--muted); font-size: 13px; padding-top: 2px; }\n.log .what { overflow-wrap: anywhere; }\n.log .what strong { font-weight: 700; }\n.log .with { color: var(--muted); font-size: 14px; }\n.log .quote { margin-top: 4px; color: var(--muted); }\n.log .files { margin-top: 6px; }\n.log .times { color: var(--muted); font-size: 13px; margin-left: 6px; }\n.log .empty { display: block; color: var(--muted); border: 0; }\n\n.how { margin-top: 56px; padding-top: 20px; border-top: 1px solid var(--rule); color: var(--muted); max-width: 68ch; }\n.how summary { cursor: pointer; font-weight: 700; color: var(--ink); font-size: 15px; }\n.how p { margin-top: 8px; }\n\n@media (max-width: 760px) {\n body { padding: 18px 16px 48px; }\n .columns { grid-template-columns: 1fr; }\n .meet.two { grid-template-columns: 1fr; justify-items: stretch; }\n .meet.two .shared-file { justify-self: center; }\n .meet.two::before { left: 50%; right: auto; top: 10%; bottom: 10%; border-top: 0; border-left: 2px solid var(--overlap); }\n .meet.two.coming::before { border-left-style: dashed; }\n .live { margin-left: 0; width: 100%; }\n}\n";
|
|
15
|
+
export declare const PAGE_SCRIPT = "\"use strict\";\n(function () {\n var POLL_MS = 3000;\n var MAX_BACKOFF_MS = 30000;\n var REQUEST_TIMEOUT_MS = 10000;\n var FILES_SHOWN = 6;\n var LOG_FILES_SHOWN = 3;\n var SHARED_FILES_SHOWN = 4;\n var DIRS_KEPT = 2;\n\n // A view link carries the room and a read-only key after the #, which the browser never sends to the server.\n var linkParams = new URLSearchParams(location.hash.slice(1));\n var viewRoom = linkParams.get(\"room\");\n var viewKey = linkParams.get(\"key\");\n var hosted = location.pathname === \"/view\";\n var STOP_POLLING = -1;\n\n var failures = 0;\n var lastData = null;\n var lastVerdict = \"\";\n var hadCollisions = false;\n var opened = {};\n\n function el(tag, className, children) {\n var node = document.createElement(tag);\n if (className) node.className = className;\n (function add(items) {\n [].concat(items === undefined ? [] : items).forEach(function (child) {\n if (child === null || child === undefined || child === false || child === \"\") return;\n if (Array.isArray(child)) add(child);\n else node.append(child);\n });\n })(children);\n return node;\n }\n\n function plural(count, word) {\n return count + \" \" + word + (count === 1 ? \"\" : \"s\");\n }\n\n function ago(iso, now) {\n var seconds = Math.max(0, Math.round((now - Date.parse(iso)) / 1000));\n if (seconds < 60) return \"just now\";\n var minutes = Math.round(seconds / 60);\n if (minutes < 60) return minutes + \" min ago\";\n var hours = Math.round(minutes / 60);\n if (hours < 48) return plural(hours, \"hour\") + \" ago\";\n return plural(Math.round(hours / 24), \"day\") + \" ago\";\n }\n\n function shortAgo(iso, now) {\n var minutes = Math.round(Math.max(0, now - Date.parse(iso)) / 60000);\n if (minutes < 1) return \"now\";\n if (minutes < 60) return minutes + \" min\";\n var hours = Math.round(minutes / 60);\n return hours < 48 ? hours + \" h\" : Math.round(hours / 24) + \" d\";\n }\n\n function personName(data, member) {\n return member === data.me ? \"You\" : member;\n }\n\n function initial(name) {\n var letter = (name || \"?\").trim().charAt(0);\n return letter ? letter.toUpperCase() : \"?\";\n }\n\n function avatar(name, small) {\n var node = el(\"span\", \"avatar\" + (small ? \" small\" : \"\"), initial(name));\n node.setAttribute(\"aria-hidden\", \"true\");\n return node;\n }\n\n // \"You are\", \"Ada and Bo are\", \"Ada is\".\n function verb(subject, one, many) {\n return subject === \"You\" || subject.indexOf(\" and \") !== -1 ? many : one;\n }\n\n function baseName(path) {\n return path.split(\"/\").pop();\n }\n\n function joinNames(names) {\n if (names.length <= 1) return names.join(\"\");\n return names.slice(0, -1).join(\", \") + \" and \" + names[names.length - 1];\n }\n\n // The last folders and the file name: enough to recognise a file, short enough for one line.\n function fileChip(path, className) {\n var parts = path.split(\"/\");\n var base = parts.pop();\n var dirs = parts.slice(-DIRS_KEPT);\n var prefix = dirs.length ? (parts.length > DIRS_KEPT ? \"\u2026/\" : \"\") + dirs.join(\"/\") + \"/\" : \"\";\n var chip = el(\"span\", \"chip\" + (className ? \" \" + className : \"\"), [prefix ? el(\"span\", \"dir\", prefix) : null, base]);\n chip.setAttribute(\"title\", path);\n return chip;\n }\n\n function fileList(paths, limit, classFor) {\n var shown = paths.slice(0, limit).map(function (path) { return fileChip(path, classFor ? classFor(path) : \"\"); });\n if (paths.length > limit) shown.push(el(\"span\", \"more\", \"and \" + (paths.length - limit) + \" more\"));\n return el(\"div\", \"files\", shown);\n }\n\n // Long text shows a few lines and a button that opens the rest; what is open stays open across refreshes.\n function clamped(id, text, className) {\n var body = el(\"p\", \"clamp \" + (className || \"\") + (opened[id] ? \" open\" : \"\"), text);\n var wrap = el(\"div\", \"\", body);\n requestAnimationFrame(function () {\n if (!opened[id] && body.scrollHeight <= body.clientHeight + 1) return;\n var button = el(\"button\", \"toggle\", opened[id] ? \"Show less\" : \"Show more\");\n button.type = \"button\";\n button.setAttribute(\"aria-expanded\", opened[id] ? \"true\" : \"false\");\n button.addEventListener(\"click\", function () {\n opened[id] = !opened[id];\n body.classList.toggle(\"open\", opened[id]);\n button.textContent = opened[id] ? \"Show less\" : \"Show more\";\n button.setAttribute(\"aria-expanded\", opened[id] ? \"true\" : \"false\");\n });\n wrap.append(button);\n });\n return wrap;\n }\n\n function sharedChip(path) {\n var chip = fileChip(path);\n chip.className = \"shared-file\";\n return chip;\n }\n\n function renderTop(data) {\n var where = document.getElementById(\"where\");\n var scope = data.room.mode === \"local\"\n ? \"only on this computer\"\n : \"shared with \" + (data.room.people === 1 ? \"1 person\" : data.room.people + \" people\");\n where.replaceChildren(el(\"strong\", \"\", data.room.name), \", \" + scope);\n }\n\n function sessionName(data, session) {\n return personName(data, session.member) + (session.place ? \" in \" + session.place : \"\");\n }\n\n function touchCard(data, session, role) {\n return el(\"div\", \"touch\", [\n el(\"div\", \"head\", [avatar(session.member), el(\"div\", \"\", [\n el(\"p\", \"name\", sessionName(data, session)),\n el(\"p\", \"role\", [role, session.agent ? el(\"span\", \"agent\", \", with \" + session.agent) : null])\n ])]),\n el(\"div\", \"text\", clamped(\"touch:\" + session.key, session.plan || session.doing))\n ]);\n }\n\n function verdictMessage(data, byKey) {\n var collisions = data.sharedFiles;\n var coming = data.plannedFiles || [];\n var names = function (keys) {\n return joinNames(keys.map(function (key) { return byKey[key] ? sessionName(data, byKey[key]) : \"someone\"; }));\n };\n\n if (data.sessions.length === 0) {\n return {\n heading: [\"Nobody is working right now.\"],\n detail: hosted\n ? \"This page fills in as soon as someone starts, and it refreshes on its own.\"\n : \"Start a coding agent in a project folder, or make a commit, and it shows up here.\"\n };\n }\n\n if (collisions.length > 0) {\n var first = collisions[0];\n var allMine = collisions.every(function (file) {\n return file.sessionKeys.every(function (key) { return byKey[key] && byKey[key].isMine; });\n });\n return {\n collision: true,\n heading: collisions.length === 1\n ? [{ mark: baseName(first.path), title: first.path, file: true }, \" is being changed by \" + names(first.sessionKeys) + \".\"]\n : [{ mark: plural(collisions.length, \"file\") }, \" are being changed in more than one place.\"],\n detail: allMine\n ? \"These are all your own folders. Let one finish before the other continues, or they will clash when you merge.\"\n : \"Agree on who goes first before everyone continues. What each one is doing is below.\"\n };\n }\n\n if (coming.length > 0) {\n var next = coming[0];\n var heading = coming.length > 1\n ? [{ mark: plural(coming.length, \"file\"), coming: true }, \" are about to be changed in two places.\"]\n : next.changingBy.length > 0\n ? [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.\"]\n : [names(next.plannedBy) + \" both plan to change \", { mark: baseName(next.path), title: next.path, file: true, coming: true }, \".\"];\n return {\n coming: true,\n heading: heading,\n detail: \"Caught before both edited it, so nothing clashes yet. Agree on who goes first.\"\n };\n }\n\n var fileCount = data.sessions.reduce(function (total, session) { return total + session.files.length; }, 0);\n var activePeople = [];\n data.sessions.forEach(function (session) {\n if (session.active && activePeople.indexOf(session.member) === -1) activePeople.push(session.member);\n });\n var inProgress = fileCount > 0 ? plural(fileCount, \"file\") + \" in progress\" : \"No files in progress\";\n if (activePeople.length === 0) {\n return { heading: [\"Nobody is working right now.\"], detail: inProgress + \". This page refreshes on its own.\" };\n }\n if (activePeople.length === 1) {\n var only = personName(data, activePeople[0]);\n return {\n heading: [only === \"You\" ? \"Only you are working right now.\" : \"Only \" + only + \" is working right now.\"],\n detail: inProgress + \".\"\n };\n }\n return {\n heading: [\"Everyone is on different files.\"],\n detail: plural(activePeople.length, \"person\").replace(\"persons\", \"people\") + \" working, \" + inProgress.charAt(0).toLowerCase() + inProgress.slice(1) + \", none of them shared.\"\n };\n }\n\n function renderVerdict(data) {\n var byKey = {};\n data.sessions.forEach(function (session) { byKey[session.key] = session; });\n var signature = JSON.stringify([data.sessions.map(function (session) {\n return [session.key, session.doing, session.plan, session.agent, session.files.length, session.active];\n }), data.sharedFiles, data.plannedFiles]);\n if (signature === lastVerdict) return;\n lastVerdict = signature;\n\n var message = verdictMessage(data, byKey);\n var arriving = !!message.collision && !hadCollisions;\n hadCollisions = !!message.collision;\n\n var heading = el(\"h1\", \"\", message.heading.map(function (part) {\n if (typeof part === \"string\") return part;\n var label = part.file ? el(\"span\", \"file\", part.mark) : part.mark;\n var marked = el(\"mark\", (part.coming ? \"coming\" : \"\") + (arriving ? \" arrive\" : \"\"), label);\n if (part.title) marked.setAttribute(\"title\", part.title);\n return marked;\n }));\n var parts = [heading, el(\"p\", \"\", message.detail)];\n\n if (message.collision) {\n parts.push(el(\"div\", \"meets\", data.sharedFiles.slice(0, SHARED_FILES_SHOWN).map(function (file) {\n var touching = file.sessionKeys.map(function (key) { return byKey[key]; }).filter(Boolean);\n var chip = sharedChip(file.path);\n var cards = touching.map(function (session) { return touchCard(data, session, \"Changing it\"); });\n return touching.length === 2\n ? el(\"div\", \"meet two\", [cards[0], chip, cards[1]])\n : el(\"div\", \"meet many\", [chip].concat(cards));\n })));\n } else if (message.coming) {\n parts.push(el(\"div\", \"meets\", data.plannedFiles.slice(0, SHARED_FILES_SHOWN).map(function (file) {\n var cards = file.changingBy.map(function (key) { return byKey[key] && touchCard(data, byKey[key], \"Changing it\"); })\n .concat(file.plannedBy.map(function (key) { return byKey[key] && touchCard(data, byKey[key], \"Wants to change it\"); }))\n .filter(Boolean);\n var chip = sharedChip(file.path);\n return cards.length === 2\n ? el(\"div\", \"meet two coming\", [cards[0], chip, cards[1]])\n : el(\"div\", \"meet many coming\", [chip].concat(cards));\n })));\n }\n document.getElementById(\"verdict\").replaceChildren.apply(document.getElementById(\"verdict\"), parts);\n }\n\n function renderSessions(data, now) {\n var list = document.getElementById(\"sessions\");\n var notStarted = data.notStarted || [];\n if (data.sessions.length === 0 && notStarted.length === 0) {\n list.replaceChildren(el(\"li\", \"none\", hosted\n ? \"No one has worked here in the last 3 days. People show up as soon as they start.\"\n : \"No one has worked here in the last 3 days.\"));\n return;\n }\n var waiting = {};\n (data.plannedFiles || []).forEach(function (file) {\n if (file.changingBy.length > 0) file.plannedBy.forEach(function (key) { waiting[key] = true; });\n });\n var planned = {};\n (data.plannedFiles || []).forEach(function (file) { planned[file.path] = true; });\n\n var cards = data.sessions.map(function (session) {\n var status = waiting[session.key]\n ? el(\"span\", \"status wait\", \"Waiting on a file\")\n : el(\"span\", \"status\" + (session.active ? \" on\" : \"\"), session.active ? \"Working now\" : \"Quiet, \" + ago(session.lastSeen, now));\n var filePaths = session.files.map(function (file) { return file.path; });\n var shared = {};\n session.files.forEach(function (file) { if (file.shared) shared[file.path] = true; });\n var wanted = session.plannedFiles.filter(function (path) { return filePaths.indexOf(path) === -1; });\n\n return el(\"li\", \"person\" + (waiting[session.key] ? \" waiting\" : \"\"), [\n avatar(session.member),\n el(\"p\", \"head\", [\n el(\"span\", \"name\", personName(data, session.member)),\n session.place ? el(\"span\", \"place\", \"in \" + session.place + (session.isHere ? \", this folder\" : \"\")) : null,\n status\n ]),\n el(\"p\", \"meta\", [\n session.agent ? el(\"span\", \"agent\", session.agent) : \"No agent\",\n session.branch ? [\" on \", el(\"span\", \"branch\", session.branch)] : null\n ]),\n el(\"div\", \"body\", [\n clamped(\"person:\" + session.key, session.plan || session.doing),\n filePaths.length > 0 ? fileList(filePaths, FILES_SHOWN, function (path) {\n return shared[path] ? \"shared\" : planned[path] ? \"planned\" : \"\";\n }) : null,\n wanted.length > 0 && waiting[session.key] ? fileList(wanted, FILES_SHOWN, function () { return \"planned\"; }) : null\n ])\n ]);\n });\n list.replaceChildren.apply(list, cards.concat(notStarted.map(function (quiet) {\n return quietCard(data, quiet, now);\n })));\n }\n\n function quietCard(data, quiet, now) {\n var you = quiet.member === data.me;\n return el(\"li\", \"person quiet\", [\n avatar(quiet.member),\n el(\"p\", \"head\", [\n el(\"span\", \"name\", personName(data, quiet.member)),\n el(\"span\", \"status\", \"Joined \" + ago(quiet.joinedAt, now))\n ]),\n el(\"p\", \"meta\", you\n ? \"Nothing shared yet. You show up here once you change a file or share a plan.\"\n : \"Nothing shared yet. They show up here once they change a file or share a plan.\")\n ]);\n }\n\n function logLine(data, entry, now) {\n var who = el(\"strong\", \"\", personName(data, entry.member) + (entry.place ? \" in \" + entry.place : \"\"));\n var with_ = entry.agent ? el(\"span\", \"with\", \" with \" + entry.agent) : null;\n var times = entry.count > 1 ? el(\"span\", \"times\", entry.count + \" times\") : null;\n var what;\n if (entry.kind === \"note\") {\n what = [el(\"p\", \"\", [who, \" shared a plan\", with_, times]), el(\"div\", \"quote\", clamped(\"log:\" + entry.id, entry.text, \"two\"))];\n } else if (entry.kind === \"edit\" && entry.files.length > 0) {\n what = [el(\"p\", \"\", [who, \" edited\", with_, times]), fileList(entry.files, LOG_FILES_SHOWN)];\n } else if (entry.kind === \"wip\") {\n var subject = personName(data, entry.member);\n what = [el(\"p\", \"\", [who, \" \" + verb(subject, \"is\", \"are\") + \" working on \" + plural(entry.files.length, \"file\"), times]), fileList(entry.files, LOG_FILES_SHOWN)];\n } else if (entry.kind === \"commit\") {\n what = [el(\"p\", \"\", [who, \" committed\", times]), el(\"div\", \"quote\", clamped(\"log:\" + entry.id, entry.text, \"two\"))];\n } else {\n what = [el(\"p\", \"\", [who, \": \" + entry.text, times])];\n }\n var when = el(\"time\", \"when\", shortAgo(entry.at, now));\n when.setAttribute(\"datetime\", entry.at);\n when.setAttribute(\"title\", ago(entry.at, now));\n return el(\"li\", entry.kind, [when, el(\"div\", \"what\", what)]);\n }\n\n function renderLog(data, now) {\n var log = document.getElementById(\"log\");\n if (data.recent.length === 0) {\n log.replaceChildren(el(\"li\", \"empty\", \"Nothing yet.\"));\n return;\n }\n log.replaceChildren.apply(log, data.recent.map(function (entry) { return logLine(data, entry, now); }));\n }\n\n // Rebuilding a list only when what it shows changed keeps clicks, focus and text selection intact between refreshes.\n var lastLists = \"\";\n var MINUTE_MS = 60000;\n\n function render(data) {\n var now = Date.now();\n renderTop(data);\n renderVerdict(data);\n var lists = JSON.stringify([data.me, data.sessions, data.plannedFiles, data.recent, Math.floor(now / MINUTE_MS)]);\n if (lists === lastLists) return;\n lastLists = lists;\n renderSessions(data, now);\n renderLog(data, now);\n }\n\n function setLive(ok) {\n document.getElementById(\"live\").classList.toggle(\"ok\", ok);\n }\n\n function showProblem(message, retryMs) {\n var problem = document.getElementById(\"problem\");\n var shownSince = lastData ? \" Showing what was there \" + ago(lastData.updatedAt, Date.now()) + \".\" : \"\";\n problem.textContent = \"Can't reach the room: \" + message + shownSince + \" Trying again in \" + Math.round(retryMs / 1000) + \" s.\";\n problem.hidden = false;\n setLive(false);\n }\n\n function showUpdated() {\n document.getElementById(\"updated\").textContent = lastData\n ? (failures === 0 ? \"Live, updated \" + ago(lastData.updatedAt, Date.now()) : \"Updated \" + ago(lastData.updatedAt, Date.now()))\n : \"Connecting\";\n }\n\n function request(signal) {\n if (!hosted) return fetch(\"/api/dashboard\", { signal: signal, cache: \"no-store\" });\n return fetch(\"/v1/rooms/\" + encodeURIComponent(viewRoom) + \"/dashboard\", {\n signal: signal,\n cache: \"no-store\",\n headers: { Authorization: \"Bearer \" + viewKey }\n });\n }\n\n function stopWith(message) {\n var problem = document.getElementById(\"problem\");\n problem.textContent = message;\n problem.hidden = false;\n document.getElementById(\"where\").textContent = \"\";\n document.querySelector(\"main\").hidden = true;\n setLive(false);\n }\n\n function poll() {\n var controller = new AbortController();\n var timeout = setTimeout(function () { controller.abort(); }, REQUEST_TIMEOUT_MS);\n request(controller.signal)\n .then(function (response) {\n if (response.status === 401 || response.status === 404) {\n var refused = new Error(\"refused\");\n refused.name = \"Refused\";\n throw refused;\n }\n return response.json().then(function (body) {\n if (!response.ok || !body.data) throw new Error((body.error && body.error.message) || \"the dashboard stopped answering.\");\n return body.data;\n });\n })\n .then(function (data) {\n failures = 0;\n lastData = data;\n document.getElementById(\"problem\").hidden = true;\n setLive(true);\n render(data);\n })\n .catch(function (error) {\n if (error && error.name === \"Refused\") {\n failures = STOP_POLLING;\n stopWith(\"This link no longer opens the room. The owner may have turned it off or made a new one: ask them for the current link.\");\n return;\n }\n failures += 1;\n var message = error && error.name === \"AbortError\"\n ? \"it took too long to answer.\"\n : error && error.name === \"TypeError\"\n ? (hosted ? \"the server did not answer.\" : \"the terminal that opened this page was closed.\")\n : (error && error.message) || \"unknown error.\";\n showProblem(message, Math.min(POLL_MS * Math.pow(2, failures), MAX_BACKOFF_MS));\n })\n .finally(function () {\n clearTimeout(timeout);\n showUpdated();\n if (failures === STOP_POLLING) return;\n setTimeout(poll, Math.min(POLL_MS * Math.pow(2, failures), MAX_BACKOFF_MS));\n });\n }\n\n if (hosted) {\n document.getElementById(\"closing\").textContent = \"This page updates on its own. It can only look: nothing you do here changes the room.\";\n }\n if (hosted && (!viewRoom || !viewKey)) {\n stopWith(\"This link is missing its key. Ask the room owner for the full view link: it ends with #room=...&key=...\");\n } else {\n poll();\n }\n})();\n";
|