toolroll 0.9.108 → 0.9.110
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/CHANGELOG.md +69 -0
- package/dist/advanced-view.js +0 -1
- package/dist/agent-detect.js +244 -0
- package/dist/agent-fence.js +47 -5
- package/dist/agent-state.js +5 -2
- package/dist/agentconfig.js +2 -2
- package/dist/approval-summary.js +344 -0
- package/dist/assignment-ui.js +5 -5
- package/dist/assignment.js +5 -2
- package/dist/attest.js +2 -2
- package/dist/browser/terminal.js +1 -1
- package/dist/browser/workspace.css +2 -2
- package/dist/browser/workspace.js +37 -34
- package/dist/browser-crew.js +4 -4
- package/dist/browser-workspace.js +4 -11
- package/dist/builder.js +45 -3
- package/dist/chat-actions.js +24 -17
- package/dist/chat-controls.js +6 -5
- package/dist/chat-core.js +3 -1
- package/dist/chat-decide.js +102 -47
- package/dist/chat-delivery-state.js +2 -0
- package/dist/chat-delivery.js +3 -2
- package/dist/chat-live.js +2 -1
- package/dist/chat-quiet.js +3 -3
- package/dist/chat-task-actions.js +6 -0
- package/dist/chat-voice.js +2 -2
- package/dist/check-report.js +1 -1
- package/dist/cli-help.js +12 -13
- package/dist/cli.js +6 -3
- package/dist/console-chrome.js +10 -3
- package/dist/console-instance.js +10 -1
- package/dist/contracts/console-api.js +14 -8
- package/dist/contracts/engine-api.js +271 -0
- package/dist/contracts/handoff.js +4 -0
- package/dist/coordinator.js +2 -2
- package/dist/decision.js +17 -0
- package/dist/demo-chat.js +1 -1
- package/dist/demo.js +6 -0
- package/dist/design/kit.js +4 -3
- package/dist/discord-api.js +4 -3
- package/dist/discord-chat.js +3 -1
- package/dist/dispatch.js +3 -8
- package/dist/easy-start-args.js +7 -3
- package/dist/easy-start.js +25 -0
- package/dist/egress.js +72 -10
- package/dist/engine-handoff.js +34 -0
- package/dist/engine-reads.js +261 -0
- package/dist/eval-world.js +3 -2
- package/dist/evidence.js +2 -0
- package/dist/fast-start.js +55 -14
- package/dist/fast-terms.js +2 -2
- package/dist/first-run.js +10 -2
- package/dist/flexible-agents.js +234 -0
- package/dist/flexible-answers-schema.js +61 -0
- package/dist/flexible-answers.js +889 -0
- package/dist/flexible-available.js +1 -0
- package/dist/flexible-custody.js +494 -0
- package/dist/flexible-import.js +782 -0
- package/dist/flexible-launch-schema.js +72 -0
- package/dist/flexible-launch.js +331 -0
- package/dist/flexible-launcher.js +88 -0
- package/dist/flexible-levels.js +34 -0
- package/dist/flexible-merge-guard.js +47 -0
- package/dist/flexible-refs.js +47 -0
- package/dist/flexible-relay-cancel.js +19 -0
- package/dist/flexible-relay-schema.js +55 -0
- package/dist/flexible-relay-upstreams.js +36 -0
- package/dist/flexible-relay.js +1032 -0
- package/dist/flexible-schema.js +32 -0
- package/dist/flexible-session.js +732 -0
- package/dist/flexible-ship-schema.js +81 -0
- package/dist/flexible-ship.js +694 -0
- package/dist/flexible-start.js +80 -0
- package/dist/flexible-thread-schema.js +30 -0
- package/dist/flexible-thread.js +676 -0
- package/dist/flexible-turns-schema.js +69 -0
- package/dist/flexible-turns.js +490 -0
- package/dist/flexible-ui.js +44 -0
- package/dist/flexible.js +368 -0
- package/dist/flow-actions.js +6 -4
- package/dist/flow-steps.js +1 -1
- package/dist/flows-cli.js +2 -1
- package/dist/git-views.js +44 -41
- package/dist/guides.js +11 -10
- package/dist/install-mode.js +225 -0
- package/dist/keymap.js +1 -1
- package/dist/lead-context.js +1 -1
- package/dist/lead-doors.js +7 -1
- package/dist/limits-ui.js +8 -1
- package/dist/live-bus.js +70 -13
- package/dist/live-reply.js +6 -0
- package/dist/live-terminal.js +425 -29
- package/dist/local-owner.js +6 -0
- package/dist/model-choices.js +12 -6
- package/dist/needs-you.js +3 -3
- package/dist/nightly-github.js +2 -2
- package/dist/notification-delivery.js +11 -0
- package/dist/operate.js +185 -33
- package/dist/outbound-privacy.js +204 -0
- package/dist/passwordless.js +2 -1
- package/dist/project-delete-ui.js +2 -1
- package/dist/project-delete.js +15 -0
- package/dist/provider-auth.js +1 -1
- package/dist/provider-connection.js +5 -3
- package/dist/publish.js +5 -0
- package/dist/pull-request-flow.js +26 -7
- package/dist/push.js +5 -1
- package/dist/release-card.js +11 -3
- package/dist/release.js +11 -1
- package/dist/result-actions.js +3 -0
- package/dist/result-evidence-readers.js +8 -2
- package/dist/result-review.js +20 -9
- package/dist/route-store.js +2 -2
- package/dist/sandbox-launch.js +32 -8
- package/dist/sandbox-runtime.js +16 -7
- package/dist/sandbox-tools.js +176 -0
- package/dist/scope.js +12 -36
- package/dist/scout-net.js +7 -2
- package/dist/serve.js +90 -40
- package/dist/server/chat.js +9 -9
- package/dist/server/chrome.js +19 -17
- package/dist/server/console.css +33 -6
- package/dist/server/engine-api.js +378 -0
- package/dist/server/flows.js +2 -2
- package/dist/server/guards.js +10 -4
- package/dist/server/home.js +37 -5
- package/dist/server/http.js +11 -2
- package/dist/server/in-place.js +5 -4
- package/dist/server/kit.js +2 -2
- package/dist/server/link-redemption.js +52 -0
- package/dist/server/live.js +100 -10
- package/dist/server/mutation-key.js +21 -7
- package/dist/server/pages.js +129 -74
- package/dist/server/people-tokens.js +17 -41
- package/dist/server/render-chat.js +2 -1
- package/dist/server/render-history.js +18 -4
- package/dist/server/render-new-task.js +4 -4
- package/dist/server/render-pages.js +21 -39
- package/dist/server/render-people.js +2 -2
- package/dist/server/render-projects.js +5 -5
- package/dist/server/render-results.js +30 -14
- package/dist/server/render-tasks.js +155 -155
- package/dist/server/retired-routes.js +37 -4
- package/dist/server/route-policy.js +8 -0
- package/dist/server/route-table.js +43 -5
- package/dist/server/settings-computers.js +140 -0
- package/dist/server/settings-scripts.js +15 -0
- package/dist/server/settings-section-table.js +59 -0
- package/dist/server/settings-sections.js +291 -0
- package/dist/server/settings.js +247 -28
- package/dist/server/task-views.js +55 -15
- package/dist/server/tasks.js +168 -98
- package/dist/server/terminals.js +181 -28
- package/dist/server/welcome.js +40 -14
- package/dist/settings-groups-ui.js +26 -107
- package/dist/settings-proofs.js +18 -11
- package/dist/slack-api.js +4 -3
- package/dist/slack-chat.js +5 -3
- package/dist/spend.js +46 -12
- package/dist/sqlite-telemetry.js +70 -21
- package/dist/status-probe.js +343 -0
- package/dist/store.js +206 -10
- package/dist/task-link.js +64 -0
- package/dist/teams-api.js +4 -3
- package/dist/teams-chat.js +4 -2
- package/dist/telegram-lead.js +2 -1
- package/dist/telegram-live.js +2 -1
- package/dist/telegram-team.js +2 -1
- package/dist/telegram.js +17 -5
- package/dist/trusted-path.js +162 -0
- package/dist/tui/darwin-arm64/toolroll-tui +0 -0
- package/dist/tui/darwin-x64/toolroll-tui +0 -0
- package/dist/tui/linux-arm64/toolroll-tui +0 -0
- package/dist/tui/linux-x64/toolroll-tui +0 -0
- package/dist/tui-launch.js +282 -0
- package/dist/tui-source.js +5 -3
- package/dist/tui.js +2 -2
- package/dist/typed-words-schema.js +18 -0
- package/dist/webhooks.js +8 -4
- package/dist/welcome-facts.js +25 -17
- package/dist/work-index.js +126 -29
- package/dist/work-reads.js +279 -0
- package/dist/workspace-ui.js +5 -0
- package/package.json +4 -2
- package/scripts/crash-canary.mjs +1 -1
- package/scripts/pilot.mjs +1 -1
- package/scripts/provider-canary.mjs +5 -3
package/dist/server/in-place.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
const SETTINGS_PAGES = [
|
|
2
2
|
"settings.page",
|
|
3
|
-
...["general", "agents", "alerts", "projects", "access", "system"].map(one => `settings.group-${one}`),
|
|
3
|
+
...["general", "agents", "computers", "alerts", "projects", "access", "system"].map(one => `settings.group-${one}`),
|
|
4
4
|
...["models", "tools", "project", "approval", "policy", "sessions", "integrations", "monitoring", "updates", "retention", "storage",
|
|
5
5
|
"pull-requests", "checks", "backups", "data", "sign-in", "lead", "teams", "discord", "slack",
|
|
6
6
|
"skills", "flows", "knowledge", "learning", "spend", "passwordless"].map(one => `settings.${one}`),
|
|
7
7
|
];
|
|
8
|
-
export const IN_PLACE_ROUTES = new Set(["home", "
|
|
9
|
-
export const PREFETCH_ROUTES = new Set(["home", "
|
|
8
|
+
export const IN_PLACE_ROUTES = new Set(["home", "task.page", "projects.page", "agents", "search", ...SETTINGS_PAGES]);
|
|
9
|
+
export const PREFETCH_ROUTES = new Set(["home", "projects.page", "agents", "search", "task.page"]);
|
|
10
10
|
const liveGrid = (id, url) => id === "agents" && url.searchParams.get("view") === "live";
|
|
11
|
+
const changeDocument = (id) => id.startsWith("settings.change.");
|
|
11
12
|
export function inPlaceRoute(id, url) {
|
|
12
|
-
return id !== undefined && IN_PLACE_ROUTES.has(id) && !liveGrid(id, url);
|
|
13
|
+
return id !== undefined && IN_PLACE_ROUTES.has(id) && !changeDocument(id) && !liveGrid(id, url);
|
|
13
14
|
}
|
|
14
15
|
const openedAgent = (id, url) => id === "agents" && url.searchParams.has("run");
|
|
15
16
|
export function prefetchRoute(id, url) {
|
package/dist/server/kit.js
CHANGED
|
@@ -158,7 +158,7 @@ export const card = (options) => html `<a class="k-card" href="${options.href}">
|
|
|
158
158
|
export function notFound(path, options = {}) {
|
|
159
159
|
return html `${pageHeader("Not found")}<div class="k-nf">${empty({
|
|
160
160
|
title: options.title ?? NOT_FOUND.title(path), text: options.text ?? NOT_FOUND.text,
|
|
161
|
-
action: acts(btn("Go to
|
|
161
|
+
action: acts(btn("Go to Work", { sm: true, href: "/" })),
|
|
162
162
|
})}</div>`;
|
|
163
163
|
}
|
|
164
164
|
export function settingsShell(options) {
|
|
@@ -265,7 +265,7 @@ export function ideas(options) {
|
|
|
265
265
|
}
|
|
266
266
|
export function settingsSection(options) {
|
|
267
267
|
const head = `${options.id}-h`;
|
|
268
|
-
return html `<section class="k-ssec" id="${options.id}" aria-labelledby="${head}"><div class="k-secthead"><h3 id="${head}">${options.title}\
|
|
268
|
+
return html `<section class="k-ssec" id="${options.id}" aria-labelledby="${head}"${attributes(options.attrs ?? {})}><div class="k-secthead"><h3 id="${head}">${options.title}\
|
|
269
269
|
${options.state ? html `<span class="k-ssec-state">${options.state}</span>` : ""}</h3>${options.right ?? ""}</div>\
|
|
270
270
|
${options.lead ? html `<p class="k-ssec-lead">${options.lead}</p>` : ""}${options.body}</section>`;
|
|
271
271
|
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { localOwnerBinding } from "../store.js";
|
|
2
|
+
import { FULL_SESSION } from "./session.js";
|
|
3
|
+
const CODE = /^[A-Za-z0-9_-]{43}$/;
|
|
4
|
+
export function spendLink(runtime, code) {
|
|
5
|
+
if (code === null || !CODE.test(code))
|
|
6
|
+
return undefined;
|
|
7
|
+
const key = runtime.linkKey(code);
|
|
8
|
+
const held = runtime.signInLinks.get(key);
|
|
9
|
+
if (held !== undefined)
|
|
10
|
+
runtime.signInLinks.delete(key);
|
|
11
|
+
return held;
|
|
12
|
+
}
|
|
13
|
+
export function admitLink(runtime, request, held, road) {
|
|
14
|
+
const refuse = (status, why) => ({ ok: false, refusal: { status, why } });
|
|
15
|
+
if (!runtime.fromThisComputer(request)) {
|
|
16
|
+
runtime.recordSignIn(held?.account ?? "unknown account", "sign-in refused", road === "terminal" ? "one-time link (terminal)" : "one-time link", "opened from another device");
|
|
17
|
+
return refuse(403, "elsewhere");
|
|
18
|
+
}
|
|
19
|
+
if (held === undefined || held.expires < Date.now())
|
|
20
|
+
return refuse(410, "used");
|
|
21
|
+
if (road === "terminal" && held.kind !== "local-owner")
|
|
22
|
+
return refuse(403, "local-owner");
|
|
23
|
+
const account = runtime.store.accountOf(held.account);
|
|
24
|
+
if (account === null || account.role !== "approver" || account.revokedAt !== null)
|
|
25
|
+
return refuse(403, "account");
|
|
26
|
+
if (!runtime.passwordAllowed(held.account))
|
|
27
|
+
return refuse(403, "provider");
|
|
28
|
+
return { ok: true, held };
|
|
29
|
+
}
|
|
30
|
+
export function saveLinkSession(runtime, request, held, road, made) {
|
|
31
|
+
const { store, sessions } = runtime;
|
|
32
|
+
const at = Date.now();
|
|
33
|
+
const base = { ...runtime.arrival(request), name: held.account, csrf: made.csrf, role: "approver", createdAt: at, lastSeen: at, sawBoardAt: null,
|
|
34
|
+
project: runtime.defaultProject, projectRevision: 1 };
|
|
35
|
+
const saved = store.transact(() => {
|
|
36
|
+
if (held.kind === "local-owner") {
|
|
37
|
+
const now = localOwnerBinding(store);
|
|
38
|
+
if (now === null || now.account !== held.account || now.localGeneration !== held.localGeneration || now.accountGeneration !== held.accountGeneration)
|
|
39
|
+
return false;
|
|
40
|
+
sessions.set(made.id, { ...base, generation: now.accountGeneration, authority: "local-owner", localGeneration: now.localGeneration, ...made.keys });
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
const now = store.accountOf(held.account);
|
|
44
|
+
if (now === null || now.role !== "approver" || now.revokedAt !== null || !now.passwordSet || now.generation !== held.accountGeneration)
|
|
45
|
+
return false;
|
|
46
|
+
sessions.set(made.id, { ...base, generation: held.accountGeneration, ...FULL_SESSION, ...made.keys });
|
|
47
|
+
return true;
|
|
48
|
+
});
|
|
49
|
+
if (saved)
|
|
50
|
+
runtime.recordSignIn(held.account, "signed in", road === "terminal" ? "local link (terminal)" : held.kind === "local-owner" ? "local link" : "one-time link");
|
|
51
|
+
return saved;
|
|
52
|
+
}
|
package/dist/server/live.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { randomBytes } from "node:crypto";
|
|
2
2
|
import { boardRunOf } from "../agent-board.js";
|
|
3
3
|
import { agentRunFingerprint } from "../agents-board.js";
|
|
4
|
-
import { createLiveRooms, KEEP_ALIVE_MS, LiveConnection } from "../live-bus.js";
|
|
4
|
+
import { createLiveRooms, KEEP_ALIVE_MS, LiveConnection, liveOrderAfter } from "../live-bus.js";
|
|
5
5
|
import { reproveRemote } from "../operate-remote.js";
|
|
6
6
|
import { rowVisible } from "../project.js";
|
|
7
7
|
import { createLiveSender, LIVE_STATUS } from "../live-reply.js";
|
|
@@ -14,6 +14,38 @@ import { createAgentsLiveRooms } from "./agents-live-room.js";
|
|
|
14
14
|
import { leadTilesFor } from "./agents-live-lead.js";
|
|
15
15
|
export const LIVE_FRAMES_HEADER = "x-toolroll-live";
|
|
16
16
|
const INCARNATION = randomBytes(9).toString("hex");
|
|
17
|
+
const CONN_NAME = /^[0-9a-f]{24}$/;
|
|
18
|
+
const PING_NUMBER = /^(0|[1-9][0-9]{0,8})$/;
|
|
19
|
+
export const PING_BUDGET = { perSession: 6, global: 120, windowMs: 10_000 };
|
|
20
|
+
export class PingBudget {
|
|
21
|
+
limits;
|
|
22
|
+
sessions = new Map();
|
|
23
|
+
global = { start: 0, count: 0 };
|
|
24
|
+
constructor(limits = PING_BUDGET) {
|
|
25
|
+
this.limits = limits;
|
|
26
|
+
}
|
|
27
|
+
take(session, now) {
|
|
28
|
+
const { perSession, global, windowMs } = this.limits;
|
|
29
|
+
if (now - this.global.start >= windowMs)
|
|
30
|
+
this.global = { start: now, count: 0 };
|
|
31
|
+
let mine = this.sessions.get(session);
|
|
32
|
+
if (mine === undefined || now - mine.start >= windowMs) {
|
|
33
|
+
if (this.sessions.size >= 4_096)
|
|
34
|
+
for (const [key, one] of this.sessions)
|
|
35
|
+
if (now - one.start >= windowMs)
|
|
36
|
+
this.sessions.delete(key);
|
|
37
|
+
mine = { start: now, count: 0 };
|
|
38
|
+
this.sessions.set(session, mine);
|
|
39
|
+
}
|
|
40
|
+
if (mine.count >= perSession)
|
|
41
|
+
return { ok: false, retryAfterMs: mine.start + windowMs - now };
|
|
42
|
+
if (this.global.count >= global)
|
|
43
|
+
return { ok: false, retryAfterMs: this.global.start + windowMs - now };
|
|
44
|
+
mine.count += 1;
|
|
45
|
+
this.global.count += 1;
|
|
46
|
+
return { ok: true };
|
|
47
|
+
}
|
|
48
|
+
}
|
|
17
49
|
export const LIVE_ROOMS_PER_PAGE = 6;
|
|
18
50
|
const ROOM_NAME = /^(workspace|task|flow|chat|team|agent|summary|agents-live)(?::([^?]{1,400}))?(?:\?([^#]{0,600}))?$/;
|
|
19
51
|
const WORKSPACE_SETTLE_MS = 1_000;
|
|
@@ -92,6 +124,9 @@ export function createLiveHandlers(runtime, live) {
|
|
|
92
124
|
const liveLeads = new Map();
|
|
93
125
|
const agentsLive = createAgentsLiveRooms({ store, bus: live.bus, evidenceRoot: runtime.evidenceRoot, localRunner: runtime.options.localRunner, clock, visible,
|
|
94
126
|
leads: key => liveLeads.get(key)?.() ?? null, forget: key => liveLeads.delete(key) });
|
|
127
|
+
const conns = new Map();
|
|
128
|
+
const connKey = (sessionHash, conn) => `${sessionHash}\u0000${conn}`;
|
|
129
|
+
const pingBudget = new PingBudget();
|
|
95
130
|
const readBrowser = (request, who) => rereadBrowser(runtime, request, who);
|
|
96
131
|
const sameBrowser = (request, who) => () => readBrowser(request, who) !== null;
|
|
97
132
|
function admitted(viewer, thread) {
|
|
@@ -112,21 +147,24 @@ export function createLiveHandlers(runtime, live) {
|
|
|
112
147
|
const turn = liveTurns.get(thread);
|
|
113
148
|
if (turn === undefined || turn.done || viewer.detach !== null)
|
|
114
149
|
return;
|
|
115
|
-
const
|
|
150
|
+
const firstWritten = viewer.connection.holdSynced();
|
|
151
|
+
const take = () => ({ snapshot: chatSnapshot(turn), order: viewer.order = liveOrderAfter(viewer.order) });
|
|
152
|
+
const send = (taken) => { viewer.connection.send(viewer.room, "turn", taken.snapshot, taken.order); firstWritten(); };
|
|
116
153
|
const sender = createLiveSender({ send, standing: () => admitted(viewer, thread), spacingMs: TURN_SETTLE_MS });
|
|
117
154
|
const listener = () => {
|
|
118
155
|
if (!turn.done) {
|
|
119
|
-
sender.offer(
|
|
156
|
+
sender.offer(take());
|
|
120
157
|
return;
|
|
121
158
|
}
|
|
122
159
|
stop();
|
|
160
|
+
const last = take();
|
|
123
161
|
void sender.close().then(() => { if (admitted(viewer, thread))
|
|
124
|
-
send(
|
|
162
|
+
send(last); firstWritten(); });
|
|
125
163
|
};
|
|
126
|
-
const stop = () => { turn.listeners.delete(listener); viewer.detach = null; void sender.close(); };
|
|
164
|
+
const stop = () => { turn.listeners.delete(listener); viewer.detach = null; void sender.close(); firstWritten(); };
|
|
127
165
|
turn.listeners.add(listener);
|
|
128
166
|
viewer.detach = stop;
|
|
129
|
-
sender.offer(
|
|
167
|
+
sender.offer(take());
|
|
130
168
|
}
|
|
131
169
|
function turnStarted(thread) {
|
|
132
170
|
for (const viewer of chatViewers) {
|
|
@@ -287,7 +325,7 @@ export function createLiveHandlers(runtime, live) {
|
|
|
287
325
|
return scope.kind !== "project" || live.chatProjectOf([scope.key]) === scope.key;
|
|
288
326
|
});
|
|
289
327
|
joins.push(connection => {
|
|
290
|
-
const viewer = { name: who.name, room: name, connection, scope, valid, detach: null, leave: () => {
|
|
328
|
+
const viewer = { name: who.name, room: name, connection, scope, valid, detach: null, order: 0, leave: () => {
|
|
291
329
|
viewer.detach?.();
|
|
292
330
|
chatViewers.delete(viewer);
|
|
293
331
|
unregister();
|
|
@@ -299,8 +337,18 @@ export function createLiveHandlers(runtime, live) {
|
|
|
299
337
|
const unregister = connection.onClose(() => { viewer.detach?.(); chatViewers.delete(viewer); });
|
|
300
338
|
const unprove = connection.onKeepAlive(() => { admitted(viewer); });
|
|
301
339
|
const thread = store.liveLeadThreadFor(who.name, scope);
|
|
302
|
-
|
|
340
|
+
const turn = thread === null ? undefined : liveTurns.get(thread.id);
|
|
341
|
+
if (thread !== null && turn !== undefined && !turn.done) {
|
|
303
342
|
follow(viewer, thread.id);
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
if (!connection.frames || !admitted(viewer, thread?.id))
|
|
346
|
+
return;
|
|
347
|
+
const order = viewer.order = liveOrderAfter(viewer.order);
|
|
348
|
+
if (turn !== undefined)
|
|
349
|
+
connection.send(name, "turn", chatSnapshot(turn), order);
|
|
350
|
+
else
|
|
351
|
+
connection.send(name, "turn", { state: "idle" }, order);
|
|
304
352
|
});
|
|
305
353
|
}
|
|
306
354
|
else {
|
|
@@ -329,21 +377,63 @@ export function createLiveHandlers(runtime, live) {
|
|
|
329
377
|
}
|
|
330
378
|
response.writeHead(200, { "content-type": "text/event-stream", "cache-control": "no-store", "x-content-type-options": "nosniff", "x-accel-buffering": "no" });
|
|
331
379
|
response.flushHeaders();
|
|
332
|
-
const
|
|
380
|
+
const frames = request.headers[LIVE_FRAMES_HEADER] === "1";
|
|
381
|
+
const sessionHash = frames && who.via === "cookie" ? runtime.sessions.hashOf(who.session) : null;
|
|
382
|
+
const conn = sessionHash === null ? undefined : randomBytes(12).toString("hex");
|
|
383
|
+
const connection = new LiveConnection(response, { frames, ...(conn === undefined ? {} : { conn }) });
|
|
384
|
+
if (conn !== undefined && sessionHash !== null && who.via === "cookie") {
|
|
385
|
+
const key = connKey(sessionHash, conn);
|
|
386
|
+
conns.set(key, { connection, name: who.name, generation: who.session.generation, lastPing: -1 });
|
|
387
|
+
connection.onEnd(() => { if (conns.get(key)?.connection === connection)
|
|
388
|
+
conns.delete(key); });
|
|
389
|
+
}
|
|
333
390
|
connection.hello({ incarnation: INCARNATION, tick: KEEP_ALIVE_MS });
|
|
334
391
|
for (const join of joins)
|
|
335
392
|
if (connection.open)
|
|
336
393
|
join(connection);
|
|
337
394
|
if (refusedJoin && connection.rooms === 0)
|
|
338
395
|
connection.refuse(() => connection.close());
|
|
396
|
+
connection.synced();
|
|
339
397
|
request.once("close", () => connection.close());
|
|
340
398
|
}
|
|
399
|
+
async function livePing(ctx) {
|
|
400
|
+
const { url, who, request, response } = ctx;
|
|
401
|
+
request.resume();
|
|
402
|
+
if (who === null)
|
|
403
|
+
return json(response, 401, { error: "session" });
|
|
404
|
+
if (who.via !== "cookie")
|
|
405
|
+
return json(response, 403, { error: "session" });
|
|
406
|
+
const params = url.searchParams, conn = params.get("conn") ?? "", n = params.get("n") ?? "";
|
|
407
|
+
if ([...params.keys()].some(key => key !== "conn" && key !== "n") || params.getAll("conn").length !== 1 || params.getAll("n").length !== 1
|
|
408
|
+
|| !CONN_NAME.test(conn) || !PING_NUMBER.test(n))
|
|
409
|
+
return json(response, 400, { error: "ping" });
|
|
410
|
+
const again = readBrowser(request, who);
|
|
411
|
+
const hash = again === null ? null : runtime.sessions.hashOf(again.session);
|
|
412
|
+
if (again === null || hash === null)
|
|
413
|
+
return json(response, 401, { error: "session" });
|
|
414
|
+
const spent = pingBudget.take(hash, clock().getTime());
|
|
415
|
+
if (!spent.ok) {
|
|
416
|
+
response.setHeader("Retry-After", String(Math.max(1, Math.ceil(spent.retryAfterMs / 1_000))));
|
|
417
|
+
return json(response, 429, { error: "busy" });
|
|
418
|
+
}
|
|
419
|
+
const held = conns.get(connKey(hash, conn));
|
|
420
|
+
if (held === undefined || !held.connection.open || held.name !== again.name || held.generation !== again.session.generation)
|
|
421
|
+
return json(response, 404, { error: "conn" });
|
|
422
|
+
const number = Number(n);
|
|
423
|
+
if (number <= held.lastPing)
|
|
424
|
+
return json(response, 409, { error: "ping" });
|
|
425
|
+
held.lastPing = number;
|
|
426
|
+
if (!held.connection.pong(number))
|
|
427
|
+
return json(response, 404, { error: "conn" });
|
|
428
|
+
response.writeHead(204, { "cache-control": "no-store", "x-content-type-options": "nosniff" });
|
|
429
|
+
response.end();
|
|
430
|
+
}
|
|
341
431
|
const detachChat = live.bus.subscribe(() => {
|
|
342
432
|
for (const viewer of [...chatViewers])
|
|
343
433
|
admitted(viewer);
|
|
344
434
|
});
|
|
345
435
|
return {
|
|
346
|
-
registrations: handlersOf("live", {}, { live: liveStream }),
|
|
436
|
+
registrations: handlersOf("live", {}, { live: liveStream, "live.ping": livePing }),
|
|
347
437
|
turnStarted,
|
|
348
438
|
close() {
|
|
349
439
|
detachChat();
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { createHash, randomBytes, timingSafeEqual } from "node:crypto";
|
|
2
2
|
import { html, htmlString, scriptElement } from "../html.js";
|
|
3
3
|
import { HANDOFF_STYLE } from "./http.js";
|
|
4
|
+
export const TERMINAL_EPOCH = "terminal:";
|
|
5
|
+
const terminalSession = (session) => typeof session.keyEpoch === "string" && session.keyEpoch.startsWith(TERMINAL_EPOCH);
|
|
6
|
+
const epochOf = (session) => session.keyEpoch === null ? null : terminalSession(session) ? session.keyEpoch.slice(TERMINAL_EPOCH.length) : session.keyEpoch;
|
|
4
7
|
export const KEY_HEADER = "x-toolroll-key";
|
|
5
8
|
export const KEY_FIELD = "toolroll-key";
|
|
6
9
|
export const KEY_PROTOCOL = "toolroll";
|
|
@@ -48,20 +51,27 @@ export function keyMatches(presented, hash) {
|
|
|
48
51
|
export function createBrowserKeys(deps) {
|
|
49
52
|
const canonicalHost = () => deps.enabled ? deps.protectedHost() : null;
|
|
50
53
|
const required = () => canonicalHost() !== null;
|
|
54
|
+
const keyed = (who) => who.via === "cookie" && (required() || (deps.enabled && terminalSession(who.session)));
|
|
55
|
+
const mint = (session, terminal) => {
|
|
56
|
+
const key = randomBytes(32).toString("hex");
|
|
57
|
+
session.keyHash = keyHashOf(key);
|
|
58
|
+
session.keyEpoch = terminal ? `${TERMINAL_EPOCH}${deps.epoch}` : deps.epoch;
|
|
59
|
+
return key;
|
|
60
|
+
};
|
|
51
61
|
const reconnectOf = (who, back = "/") => who.authority === "full"
|
|
52
62
|
? { kind: "password", href: back === "/" ? "/login/rekey" : `/login/rekey?return=${encodeURIComponent(back)}` }
|
|
53
63
|
: { kind: "command", command: "toolroll --web" };
|
|
54
64
|
const stale = (who, back) => {
|
|
55
|
-
if (!
|
|
65
|
+
if (!keyed(who))
|
|
56
66
|
return null;
|
|
57
67
|
const session = who.session;
|
|
58
|
-
return session
|
|
68
|
+
return epochOf(session) !== deps.epoch || session.keyHash === null ? reconnectOf(who, back) : null;
|
|
59
69
|
};
|
|
60
70
|
return {
|
|
61
71
|
required,
|
|
62
72
|
canonicalHost,
|
|
63
73
|
check(who, request, body) {
|
|
64
|
-
if (!
|
|
74
|
+
if (!keyed(who))
|
|
65
75
|
return null;
|
|
66
76
|
const local = who.authority !== "full";
|
|
67
77
|
const reconnect = reconnectOf(who);
|
|
@@ -77,10 +87,14 @@ export function createBrowserKeys(deps) {
|
|
|
77
87
|
const canonical = canonicalHost();
|
|
78
88
|
if (canonical === null || request.headers.host !== canonical)
|
|
79
89
|
return null;
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
90
|
+
return mint(session, false);
|
|
91
|
+
},
|
|
92
|
+
issueForClient(session, request) {
|
|
93
|
+
const host = request.headers.host;
|
|
94
|
+
const port = deps.servedPort?.() ?? null;
|
|
95
|
+
if (!deps.enabled || port === null || (host !== `127.0.0.1:${port}` && host !== `[::1]:${port}`))
|
|
96
|
+
return null;
|
|
97
|
+
return mint(session, true);
|
|
84
98
|
},
|
|
85
99
|
deliver(response, key, to, cookies = []) {
|
|
86
100
|
const nonce = randomBytes(16).toString("base64");
|