toolroll 0.9.106 → 0.9.108

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 (46) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/README.md +5 -4
  3. package/dist/browser/workspace.css +1 -1
  4. package/dist/browser/workspace.js +27 -25
  5. package/dist/browser-shell.js +1 -1
  6. package/dist/cli-help.js +5 -0
  7. package/dist/cli.js +18 -11
  8. package/dist/contracts/cli.js +3 -1
  9. package/dist/contracts/console-api.js +1 -1
  10. package/dist/demo-sign-in.js +1 -55
  11. package/dist/easy-start-args.js +4 -2
  12. package/dist/easy-start.js +78 -24
  13. package/dist/first-run.js +4 -1
  14. package/dist/folder-look.js +65 -4
  15. package/dist/git-floor.js +9 -2
  16. package/dist/guides.js +3 -1
  17. package/dist/lead-cli.js +2 -1
  18. package/dist/live-bus.js +14 -1
  19. package/dist/login-secrets.js +43 -0
  20. package/dist/operate.js +195 -27
  21. package/dist/project-admission.js +60 -29
  22. package/dist/project.js +73 -0
  23. package/dist/repos.js +37 -0
  24. package/dist/route-hooks.js +1 -0
  25. package/dist/sample-project.js +167 -9
  26. package/dist/sandbox-runtime.js +1 -1
  27. package/dist/scope.js +17 -2
  28. package/dist/serve.js +15 -3
  29. package/dist/server/live.js +5 -2
  30. package/dist/server/login-help.js +67 -0
  31. package/dist/server/pages.js +180 -26
  32. package/dist/server/people-tokens.js +36 -24
  33. package/dist/server/render-people.js +14 -2
  34. package/dist/server/render-projects.js +58 -10
  35. package/dist/server/route-table.js +2 -1
  36. package/dist/server/settings.js +3 -0
  37. package/dist/server/welcome.js +29 -18
  38. package/dist/settings-groups-ui.js +10 -1
  39. package/dist/sign-in-page.js +197 -0
  40. package/dist/store.js +33 -0
  41. package/dist/surface.js +4 -1
  42. package/dist/task-outcome-cli.js +99 -4
  43. package/dist/tui-source.js +11 -3
  44. package/dist/tui.js +46 -46
  45. package/dist/welcome-facts.js +17 -7
  46. package/package.json +1 -1
package/dist/repos.js CHANGED
@@ -271,3 +271,40 @@ function bumpRegistryRemovals(file, lines, tag) {
271
271
  writeFileSync(temp, `${JSON.stringify(counts)}\n`, { flag: "wx", mode: 0o600 });
272
272
  renameFile(temp, registryRemovalsFile(file));
273
273
  }
274
+ export function readProjectRegistryNow(file) {
275
+ let text;
276
+ try {
277
+ const fd = openFd(file, fsConstants.O_RDONLY);
278
+ try {
279
+ const size = fstatSync(fd).size;
280
+ if (size > 4 * 1024 * 1024)
281
+ return { error: `${file} is too large to be a Toolroll config` };
282
+ const buffer = Buffer.alloc(size);
283
+ let read = 0;
284
+ while (read < size) {
285
+ const got = readSync(fd, buffer, read, size - read, read);
286
+ if (got === 0)
287
+ break;
288
+ read += got;
289
+ }
290
+ text = buffer.subarray(0, read).toString("utf8");
291
+ }
292
+ finally {
293
+ closeFd(fd);
294
+ }
295
+ }
296
+ catch (cause) {
297
+ if (cause.code === "ENOENT")
298
+ return { repos: [], roots: [] };
299
+ return { error: `${file} could not be read (${String(cause.message)})` };
300
+ }
301
+ let parsed;
302
+ try {
303
+ parsed = JSON.parse(text);
304
+ }
305
+ catch {
306
+ return { error: `${file} is not valid JSON` };
307
+ }
308
+ const registry = readProjectRegistryStrict(parsed);
309
+ return registry === null ? { error: `${file} does not look like a Toolroll config` } : { repos: sortUnique(registry.repos), roots: sortUnique(registry.roots) };
310
+ }
@@ -11,6 +11,7 @@ const REVISION_CALLERS = [
11
11
  { file: "src/chat-review.ts", inside: "applyChatReview", calls: "createResultRevision", from: "./result-actions.js", args: true, why: "a confirmed review card passes the origin it was given" },
12
12
  { file: "src/lead-doors.ts", inside: "executeProposal", calls: "applyChatReview", from: "./chat-review.js", args: true, why: "a review card a person confirms is the person's; under a lead chain or remote run, the lead's" },
13
13
  { file: "src/task-outcome-cli.ts", inside: "runTaskOutcomeCommand", calls: "requestResultChanges", from: "./result-actions.js", args: true, why: "the command line tells a person from a lead or a machine" },
14
+ { file: "src/task-outcome-cli.ts", inside: "reviseAsLocalOwner", calls: "requestResultChanges", from: "./result-actions.js", args: true, why: "the terminal's local owner is the person at this computer, in their own words" },
14
15
  { file: "src/server/tasks.ts", inside: "createTasksHandlers", calls: "requestResultChanges", from: "../result-actions.js", args: true, why: "a browser session is a person; a bearer credential a machine" },
15
16
  { file: "src/server/tasks.ts", inside: "createTasksHandlers", calls: "createResultRevision", from: "../result-actions.js", args: true, why: "a browser session is a person; a bearer credential a machine" },
16
17
  ];
@@ -1,7 +1,10 @@
1
- import { lstatSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
2
- import { isAbsolute, join } from "node:path";
1
+ import { randomBytes } from "node:crypto";
2
+ import { lstatSync, mkdirSync, readFileSync, rmSync, unlinkSync, writeFileSync } from "node:fs";
3
+ import { dirname, isAbsolute, join } from "node:path";
3
4
  import { run } from "./exec.js";
4
5
  import { SAMPLE_PROJECT_NAME } from "./first-run.js";
6
+ import { admitProject } from "./project-admission.js";
7
+ import { authorizedProject, canonicalProject, rowVisible, unscoped } from "./project.js";
5
8
  import { ENV, ENV_ALLOWLIST } from "./remote-main.js";
6
9
  import { TEARDOWN_FLAGS } from "./teardown-git.js";
7
10
  const MARKER = "toolroll-sample";
@@ -60,26 +63,49 @@ function isOurs(target) {
60
63
  return false;
61
64
  }
62
65
  }
63
- export async function createSampleProject(root, git = run) {
66
+ function removeMade(target, made) {
67
+ try {
68
+ const seen = lstatSync(target);
69
+ if (!seen.isDirectory() || seen.isSymbolicLink() || seen.dev !== made.dev || seen.ino !== made.ino)
70
+ return false;
71
+ const marker = join(target, ".git", MARKER);
72
+ if (kindOf(marker) !== "missing" && !isOurs(target))
73
+ return false;
74
+ rmSync(target, { recursive: true, force: true });
75
+ return kindOf(target) === "missing";
76
+ }
77
+ catch {
78
+ return false;
79
+ }
80
+ }
81
+ export async function createSampleProject(root, git = run, guard = () => true) {
82
+ const made = await claimSample(root, git, guard);
83
+ return made.ok ? { ok: true, path: made.path, created: made.created } : made;
84
+ }
85
+ async function claimSample(root, git, guard) {
64
86
  if (root === null || root === "" || !isAbsolute(root) || kindOf(root) !== "dir") {
65
87
  return { ok: false, reason: "no-root", message: "There's no project folder to put the sample in." };
66
88
  }
67
89
  const target = join(root, SAMPLE_PROJECT_NAME);
68
90
  if (isOurs(target))
69
- return { ok: true, path: target, created: false };
91
+ return { ok: true, path: target, created: false, identity: null };
92
+ const refused = { ok: false, reason: "refused", message: "Your access changed while the sample was being made. Nothing was added." };
93
+ if (!guard())
94
+ return refused;
95
+ let identity;
70
96
  try {
71
97
  mkdirSync(target);
98
+ const seen = lstatSync(target);
99
+ identity = { dev: seen.dev, ino: seen.ino };
72
100
  }
73
101
  catch {
74
102
  return { ok: false, reason: "exists", message: `A folder named ${SAMPLE_PROJECT_NAME} is already there, so nothing was changed.` };
75
103
  }
76
104
  const fail = () => {
77
- try {
78
- rmSync(target, { recursive: true, force: true });
79
- }
80
- catch { }
105
+ removeMade(target, identity);
81
106
  return { ok: false, reason: "failed", message: "The sample project couldn't be made. Nothing was added." };
82
107
  };
108
+ const stop = () => { removeMade(target, identity); return refused; };
83
109
  try {
84
110
  for (const [file, body] of Object.entries(FILES)) {
85
111
  const path = join(target, file);
@@ -88,7 +114,11 @@ export async function createSampleProject(root, git = run) {
88
114
  }
89
115
  const options = { cwd: target, env: ENV, envAllowlist: ENV_ALLOWLIST, timeoutMs: 30_000 };
90
116
  for (const args of [["init", "-q", "--template=", "-b", "main"], ["add", "--", "."], ["commit", "-q", "--no-verify", "-m", "Sample project"]]) {
117
+ if (!guard())
118
+ return stop();
91
119
  const ran = await git("git", [...SAMPLE_FLAGS, ...args], options);
120
+ if (!guard())
121
+ return stop();
92
122
  if (ran.code !== 0)
93
123
  return fail();
94
124
  }
@@ -97,7 +127,7 @@ export async function createSampleProject(root, git = run) {
97
127
  catch {
98
128
  return fail();
99
129
  }
100
- return { ok: true, path: target, created: true };
130
+ return { ok: true, path: target, created: true, identity };
101
131
  }
102
132
  export const SAMPLE_CHECK_COMMAND = "node --test";
103
133
  const SAMPLE_CHECK_TIMEOUT_MS = 60_000;
@@ -114,3 +144,131 @@ export function registerSampleCheck(store, made, repo, addedBy, now) {
114
144
  return true;
115
145
  });
116
146
  }
147
+ export function sampleRootOf(ceiling) {
148
+ if (unscoped(ceiling))
149
+ return null;
150
+ const root = ceiling.roots[0];
151
+ return root === undefined || root === "" || !isAbsolute(root) ? null : root.replace(/\/+$/, "") || null;
152
+ }
153
+ export async function addSampleProject(input) {
154
+ const { authority } = input;
155
+ if (!authority.stands())
156
+ return { ok: false, reason: "refused" };
157
+ const root = sampleRootOf(input.ceiling());
158
+ if (root === null)
159
+ return { ok: false, reason: "no-root" };
160
+ const expected = join(root, SAMPLE_PROJECT_NAME);
161
+ const rootServed = (ceiling) => !unscoped(ceiling) && ceiling.roots.some(one => one.replace(/\/+$/, "") === root);
162
+ const standing = () => !authority.stands() ? "refused" : !rootServed(input.ceiling()) ? "not-added" : null;
163
+ const lock = sampleLock(input.registryFile === null ? join(root, ".toolroll-sample.lock") : `${input.registryFile}.sample.lock`);
164
+ if (!(await lock.take()))
165
+ return { ok: false, reason: "not-added" };
166
+ try {
167
+ return await addHolding(input, root, expected, rootServed, standing);
168
+ }
169
+ finally {
170
+ lock.release();
171
+ }
172
+ }
173
+ async function addHolding(input, root, expected, rootServed, standing) {
174
+ const { store, authority } = input;
175
+ const made = await claimSample(root, input.git ?? run, () => standing() === null);
176
+ if (!made.ok)
177
+ return { ok: false, reason: made.reason === "refused" ? standing() ?? "refused" : made.reason };
178
+ const undo = (reason) => {
179
+ if (made.identity !== null && !store.listProjects().some(one => one.path === made.path))
180
+ removeMade(made.path, made.identity);
181
+ return { ok: false, reason };
182
+ };
183
+ const after = standing();
184
+ if (after !== null)
185
+ return undo(after);
186
+ const decidedOn = input.generation?.() ?? null;
187
+ const canonical = await (input.resolveFolder ?? (async (path) => canonicalProject(path)))(made.path);
188
+ const later = standing();
189
+ if (later !== null)
190
+ return undo(later);
191
+ const visible = (repo) => input.visible === undefined || input.visible(repo);
192
+ const servedBy = (ceiling, repo) => repo === expected && rootServed(ceiling) && rowVisible(ceiling, repo);
193
+ if (canonical === null || canonical === "no-answer" || canonical !== expected || !servedBy(input.ceiling(), canonical)
194
+ || !(await authorizedProject(input.ceiling(), canonical)) || !visible(canonical))
195
+ return undo("not-added");
196
+ const stillAllowed = (repo) => repo === canonical && authority.stands()
197
+ && (decidedOn === null || input.generation?.() === decidedOn) && servedBy(input.ceiling(), repo) && visible(repo);
198
+ let checkSet = false;
199
+ const admitted = await admitProject(store, {
200
+ registryFile: input.registryFile, path: canonical, actor: authority.actor, now: input.now, stillAllowed,
201
+ registryAllowed: (repo, registry) => stillAllowed(repo) && servedBy(input.ceiling(registry), repo),
202
+ withinAdmission: repo => { checkSet = registerSampleCheck(store, made, repo, authority.actor.label, input.now); },
203
+ ...(input.resolveFolder === undefined ? {} : { resolveFolder: input.resolveFolder }),
204
+ });
205
+ if (!admitted.ok) {
206
+ if (admitted.reason === "incomplete")
207
+ return { ok: false, reason: "incomplete", message: admitted.message };
208
+ return undo(standing() ?? "not-added");
209
+ }
210
+ return { ok: true, repo: admitted.repo, created: made.created, added: admitted.added, checkSet };
211
+ }
212
+ function sampleLock(path) {
213
+ const token = `${process.pid}.${randomBytes(8).toString("hex")}`;
214
+ let held = false;
215
+ return {
216
+ async take() {
217
+ try {
218
+ mkdirSync(dirname(path), { recursive: true });
219
+ }
220
+ catch {
221
+ return false;
222
+ }
223
+ const deadline = Date.now() + 60_000;
224
+ while (Date.now() < deadline) {
225
+ try {
226
+ writeFileSync(path, token, { flag: "wx", mode: 0o600 });
227
+ held = true;
228
+ return true;
229
+ }
230
+ catch (error) {
231
+ if (error.code !== "EEXIST")
232
+ return false;
233
+ }
234
+ let seen = "";
235
+ try {
236
+ seen = readFileSync(path, "utf8");
237
+ }
238
+ catch {
239
+ continue;
240
+ }
241
+ const owner = Number(seen.split(".")[0]);
242
+ let gone = !Number.isInteger(owner) || owner <= 0;
243
+ if (!gone) {
244
+ try {
245
+ process.kill(owner, 0);
246
+ }
247
+ catch (error) {
248
+ gone = error.code === "ESRCH";
249
+ }
250
+ }
251
+ if (gone) {
252
+ try {
253
+ if (readFileSync(path, "utf8") === seen)
254
+ unlinkSync(path);
255
+ }
256
+ catch { }
257
+ continue;
258
+ }
259
+ await new Promise(resolve => setTimeout(resolve, 50));
260
+ }
261
+ return false;
262
+ },
263
+ release() {
264
+ if (!held)
265
+ return;
266
+ held = false;
267
+ try {
268
+ if (readFileSync(path, "utf8") === token)
269
+ unlinkSync(path);
270
+ }
271
+ catch { }
272
+ },
273
+ };
274
+ }
@@ -64,7 +64,7 @@ export function missingLinuxSandboxTools(path = process.env["PATH"] ?? "") {
64
64
  return LINUX_SANDBOX_TOOLS.filter(tool => !found(tool.command)).map(tool => tool.package);
65
65
  }
66
66
  export function linuxSandboxInstallLine(packages = LINUX_SANDBOX_TOOLS.map(tool => tool.package)) {
67
- return `sudo apt install ${packages.join(" ")} (Fedora: sudo dnf install ${packages.join(" ")})`;
67
+ return `sudo apt update && sudo apt install ${packages.join(" ")} (Fedora: sudo dnf install ${packages.join(" ")})`;
68
68
  }
69
69
  export const linuxSandboxToolsWords = () => toolWords(LINUX_SANDBOX_TOOLS.map(tool => tool.package));
70
70
  export function missingSandboxToolsWords(missing) {
package/dist/scope.js CHANGED
@@ -1243,8 +1243,20 @@ const LOCAL_RETRY_WORDS = {
1243
1243
  unsandboxed: "This project's checks run without a sandbox, so retrying needs your password.",
1244
1244
  imported: "A task from outside needs your password to retry.",
1245
1245
  };
1246
+ const LOCAL_REVISE_WORDS = {
1247
+ "local-mode-off": "Local mode is off, so sending this result back needs your password.",
1248
+ "not-owner": "Only this computer's owner sends results back here without a password.",
1249
+ "no-scope": "This task has no plan, so sending its result back needs your password.",
1250
+ release: "Sending a release back needs your password.",
1251
+ protected: "This result is protected work, so sending it back needs your password.",
1252
+ escalated: "Work with wider permissions needs your password to send back.",
1253
+ coordinator: "Work a coordinator filed needs your password to send back.",
1254
+ unsandboxed: "This project's checks run without a sandbox, so sending back needs your password.",
1255
+ imported: "A task from outside needs your password to send back.",
1256
+ };
1246
1257
  export function localWorkEligible(store, by, taskId, purpose) {
1247
- const words = purpose.act === "approve" ? LOCAL_APPROVAL_WORDS : purpose.act === "complete" ? LOCAL_COMPLETION_WORDS : purpose.act === "plan" ? LOCAL_PLAN_WORDS : LOCAL_RETRY_WORDS;
1258
+ const words = purpose.act === "approve" ? LOCAL_APPROVAL_WORDS : purpose.act === "complete" ? LOCAL_COMPLETION_WORDS : purpose.act === "revise" ? LOCAL_REVISE_WORDS
1259
+ : purpose.act === "plan" ? LOCAL_PLAN_WORDS : LOCAL_RETRY_WORDS;
1248
1260
  const no = (reason) => ({ ok: false, reason, message: words[reason] });
1249
1261
  if (!localModeOn(store))
1250
1262
  return no("local-mode-off");
@@ -1281,7 +1293,7 @@ export function localWorkEligible(store, by, taskId, purpose) {
1281
1293
  }
1282
1294
  if (ref === undefined || ref["coordinator_cid"] != null)
1283
1295
  return no("coordinator");
1284
- if (purpose.act === "complete")
1296
+ if (purpose.act === "complete" || purpose.act === "revise")
1285
1297
  return { ok: true };
1286
1298
  if ((purpose.act === "plan" || purpose.act === "retry") && issueImported(store, taskId))
1287
1299
  return no("imported");
@@ -1290,3 +1302,6 @@ export function localWorkEligible(store, by, taskId, purpose) {
1290
1302
  return no("unsandboxed");
1291
1303
  return { ok: true };
1292
1304
  }
1305
+ export function typedPasswordNow(proved) {
1306
+ return proved.ok && proved.method === "password-now";
1307
+ }
package/dist/serve.js CHANGED
@@ -128,7 +128,7 @@ import { createBrowserKeys, KEY_FILL_SCRIPT, pagePathOf } from './server/mutatio
128
128
  import { DEFAULT_GUARD_POLICY, passwordGuardOf, provenPasswordAccount, SourceBudget, withPasswordSource } from "./sign-in-guard.js";
129
129
  import { sourceKey } from "./source-key.js";
130
130
  import { readSsoSettings } from "./sso-settings.js";
131
- import { LEAD_THREAD, latestLeadTurnOfThread, localOwnerBinding } from "./store.js";
131
+ import { LEAD_THREAD, latestLeadTurnOfThread, localOwnerBinding, projectRowKnown } from "./store.js";
132
132
  import { waitingUpdate } from "./toolroll-update.js";
133
133
  import { PACKAGE_VERSION } from "./version.js";
134
134
  import { loadConsoleUrl } from "./webhooks.js";
@@ -291,7 +291,7 @@ export function createDecisionServer(options) {
291
291
  const known = store.accountOf(account);
292
292
  if (known === null || known.role !== "approver" || known.revokedAt !== null || !known.passwordSet)
293
293
  return null;
294
- return holdSignInLink({ kind: "full", account, expires: Date.now() + SIGN_IN_LINK_MS });
294
+ return holdSignInLink({ kind: "full", account, accountGeneration: known.generation, expires: Date.now() + SIGN_IN_LINK_MS });
295
295
  }
296
296
  const keyEpoch = options.keyEpoch ?? randomBytes(16).toString("hex");
297
297
  const fromThisComputer = (request) => requestFromThisComputer(request);
@@ -356,10 +356,12 @@ export function createDecisionServer(options) {
356
356
  const { ceiling, unresolved: unresolvedRepos, defaultProject, configured, configuredPaths } = startupCeiling([...(options.repo === undefined ? [] : [options.repo]), ...(options.repos ?? [])], options.projectRoots ?? [], options.identities === undefined ? undefined : identities, identities.strict);
357
357
  const unscopedMode = !configured && options.admittedRepos === undefined;
358
358
  const exactRepos = () => options.admittedRepos?.() ?? ceiling.repos;
359
+ const consoleAdmitted = new Set();
359
360
  const liveCeiling = () => {
360
- const repos = [...exactRepos(), ...(options.additionalProjectRepos?.() ?? [])];
361
+ const repos = [...exactRepos(), ...(options.additionalProjectRepos?.() ?? []), ...stillAdmitted(consoleAdmitted, deletedRepos, repo => projectRowKnown(store, repo))];
361
362
  return { repos: repos.length === 0 && ceiling.roots.length === 0 && !unscopedMode ? [NO_PROJECT] : repos, roots: ceiling.roots, canon: identities.strict };
362
363
  };
364
+ const outsideAdmissions = outsideAdmissionsOf(consoleAdmitted);
363
365
  const deletedRepos = new Set();
364
366
  const goneRepos = () => {
365
367
  if (deletedRepos.size === 0)
@@ -1920,6 +1922,7 @@ export function createDecisionServer(options) {
1920
1922
  get identities() { return identities; },
1921
1923
  get keyEpoch() { return keyEpoch; },
1922
1924
  get browserKeys() { return browserKeys; },
1925
+ get outsideAdmissions() { return outsideAdmissions; },
1923
1926
  };
1924
1927
  const tasksHandlers = createTasksHandlers(handlerRuntime);
1925
1928
  const pagesHandlers = createPagesHandlers(handlerRuntime);
@@ -2066,3 +2069,12 @@ function consoleFolders(options, identities, work) {
2066
2069
  }
2067
2070
  return inFolderScope(gate, work);
2068
2071
  }
2072
+ function stillAdmitted(admitted, gone, added) {
2073
+ for (const repo of admitted)
2074
+ if (gone.has(repo) || !added(repo))
2075
+ admitted.delete(repo);
2076
+ return [...admitted];
2077
+ }
2078
+ function outsideAdmissionsOf(admitted) {
2079
+ return { admit: repo => { admitted.add(repo); } };
2080
+ }
@@ -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, LiveConnection } from "../live-bus.js";
4
+ import { createLiveRooms, KEEP_ALIVE_MS, LiveConnection } 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";
@@ -12,6 +12,8 @@ import { adapterPolicy } from "./route-policy.js";
12
12
  import { requestContext } from "./request-context.js";
13
13
  import { createAgentsLiveRooms } from "./agents-live-room.js";
14
14
  import { leadTilesFor } from "./agents-live-lead.js";
15
+ export const LIVE_FRAMES_HEADER = "x-toolroll-live";
16
+ const INCARNATION = randomBytes(9).toString("hex");
15
17
  export const LIVE_ROOMS_PER_PAGE = 6;
16
18
  const ROOM_NAME = /^(workspace|task|flow|chat|team|agent|summary|agents-live)(?::([^?]{1,400}))?(?:\?([^#]{0,600}))?$/;
17
19
  const WORKSPACE_SETTLE_MS = 1_000;
@@ -327,7 +329,8 @@ export function createLiveHandlers(runtime, live) {
327
329
  }
328
330
  response.writeHead(200, { "content-type": "text/event-stream", "cache-control": "no-store", "x-content-type-options": "nosniff", "x-accel-buffering": "no" });
329
331
  response.flushHeaders();
330
- const connection = new LiveConnection(response);
332
+ const connection = new LiveConnection(response, { frames: request.headers[LIVE_FRAMES_HEADER] === "1" });
333
+ connection.hello({ incarnation: INCARNATION, tick: KEEP_ALIVE_MS });
331
334
  for (const join of joins)
332
335
  if (connection.open)
333
336
  join(connection);
@@ -0,0 +1,67 @@
1
+ import { lstatSync, realpathSync } from "node:fs";
2
+ import { homedir, userInfo } from "node:os";
3
+ import { dirname, sep } from "node:path";
4
+ import { savedLoginFile } from "../login-secrets.js";
5
+ import { localOwnerBinding } from "../store.js";
6
+ export function shownPath(path, home, user) {
7
+ const homes = new Set([home]);
8
+ try {
9
+ homes.add(realpathSync(home));
10
+ }
11
+ catch { }
12
+ for (const one of homes) {
13
+ if (one === "" || one === sep)
14
+ continue;
15
+ const rest = path === one ? "" : path.startsWith(one + sep) ? path.slice(one.length) : null;
16
+ if (rest === null)
17
+ continue;
18
+ if (user !== null && user !== "" && rest.split(/[\\/]/).includes(user))
19
+ return null;
20
+ return `~${rest}`;
21
+ }
22
+ return null;
23
+ }
24
+ const regularFile = (path) => {
25
+ try {
26
+ return lstatSync(path).isFile();
27
+ }
28
+ catch {
29
+ return false;
30
+ }
31
+ };
32
+ function databaseFileOf(store) {
33
+ const row = store.handle.prepare("PRAGMA database_list").all().find(one => one["name"] === "main");
34
+ return typeof row?.["file"] === "string" ? row["file"] : "";
35
+ }
36
+ function anyPasswordSet(store) {
37
+ return store.handle.prepare("SELECT 1 AS one FROM approver WHERE revoked_at IS NULL AND password_set = 1 AND credential_hash NOT LIKE 'sso-only$%' LIMIT 1").get() !== undefined;
38
+ }
39
+ export function loginHelpOf(store, where) {
40
+ try {
41
+ if (store.isDemo())
42
+ return { kind: "none" };
43
+ if (localOwnerBinding(store) !== null)
44
+ return { kind: "local", passwordSet: where.here ? anyPasswordSet(store) : null };
45
+ if (!where.here)
46
+ return { kind: "password", savedAt: null };
47
+ const database = databaseFileOf(store);
48
+ if (database === "")
49
+ return { kind: "password", savedAt: null };
50
+ const saved = savedLoginFile(dirname(database));
51
+ if (!regularFile(saved))
52
+ return { kind: "password", savedAt: null };
53
+ let user = where.user === undefined ? null : where.user;
54
+ if (where.user === undefined) {
55
+ try {
56
+ user = userInfo().username;
57
+ }
58
+ catch {
59
+ user = null;
60
+ }
61
+ }
62
+ return { kind: "password", savedAt: shownPath(saved, where.home ?? homedir(), user) };
63
+ }
64
+ catch {
65
+ return { kind: "password", savedAt: null };
66
+ }
67
+ }