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.
- package/CHANGELOG.md +38 -0
- package/README.md +5 -4
- package/dist/browser/workspace.css +1 -1
- package/dist/browser/workspace.js +27 -25
- package/dist/browser-shell.js +1 -1
- package/dist/cli-help.js +5 -0
- package/dist/cli.js +18 -11
- package/dist/contracts/cli.js +3 -1
- package/dist/contracts/console-api.js +1 -1
- package/dist/demo-sign-in.js +1 -55
- package/dist/easy-start-args.js +4 -2
- package/dist/easy-start.js +78 -24
- package/dist/first-run.js +4 -1
- package/dist/folder-look.js +65 -4
- package/dist/git-floor.js +9 -2
- package/dist/guides.js +3 -1
- package/dist/lead-cli.js +2 -1
- package/dist/live-bus.js +14 -1
- package/dist/login-secrets.js +43 -0
- package/dist/operate.js +195 -27
- package/dist/project-admission.js +60 -29
- package/dist/project.js +73 -0
- package/dist/repos.js +37 -0
- package/dist/route-hooks.js +1 -0
- package/dist/sample-project.js +167 -9
- package/dist/sandbox-runtime.js +1 -1
- package/dist/scope.js +17 -2
- package/dist/serve.js +15 -3
- package/dist/server/live.js +5 -2
- package/dist/server/login-help.js +67 -0
- package/dist/server/pages.js +180 -26
- package/dist/server/people-tokens.js +36 -24
- package/dist/server/render-people.js +14 -2
- package/dist/server/render-projects.js +58 -10
- package/dist/server/route-table.js +2 -1
- package/dist/server/settings.js +3 -0
- package/dist/server/welcome.js +29 -18
- package/dist/settings-groups-ui.js +10 -1
- package/dist/sign-in-page.js +197 -0
- package/dist/store.js +33 -0
- package/dist/surface.js +4 -1
- package/dist/task-outcome-cli.js +99 -4
- package/dist/tui-source.js +11 -3
- package/dist/tui.js +46 -46
- package/dist/welcome-facts.js +17 -7
- package/package.json +1 -1
|
@@ -11,7 +11,7 @@ import { acts, approvalFactsNow, approvalTerms, approveForm, btn, chip, count, d
|
|
|
11
11
|
import {} from "./render-pages.js";
|
|
12
12
|
export function shortPathOf(path) {
|
|
13
13
|
const home = homedir();
|
|
14
|
-
return path.startsWith(`${home}/`) ? `~${path.slice(home.length)}` : path;
|
|
14
|
+
return path === home ? "~" : path.startsWith(`${home}/`) ? `~${path.slice(home.length)}` : path;
|
|
15
15
|
}
|
|
16
16
|
export function projectHref(name, path, ambiguous, page = "") {
|
|
17
17
|
return `/projects/${encodeURIComponent(name)}${page === "" ? "" : `/${page}`}${ambiguous ? `?path=${encodeURIComponent(path)}` : ""}`;
|
|
@@ -29,6 +29,7 @@ const mono = (text) => html `<span class="k-mono">${text}</span>`;
|
|
|
29
29
|
const sentence = (text) => text === "" ? text : `${text.charAt(0).toUpperCase()}${text.slice(1)}`;
|
|
30
30
|
const refused = (text) => /nothing (changed|was)/i.test(text) ? sentence(text) : `${sentence(text).replace(/[.\s]+$/, "")}. Nothing changed.`;
|
|
31
31
|
export function addWaysHtml(data) {
|
|
32
|
+
const local = data.local ?? { outside: false, pick: false, pathProblem: null, pathValue: "" };
|
|
32
33
|
const onboard = data.onboard;
|
|
33
34
|
const github = onboard === null
|
|
34
35
|
? null
|
|
@@ -46,15 +47,19 @@ export function addWaysHtml(data) {
|
|
|
46
47
|
onboard.roots.length === 1 ? note(html `Clones into ${mono(shortPathOf(onboard.roots[0] ?? ""))}.`) : "",
|
|
47
48
|
]), { attrs: { class: "k-sec" } }),
|
|
48
49
|
])}</section>`;
|
|
49
|
-
const
|
|
50
|
-
|
|
50
|
+
const thisComputer = html `<section class="k-sec" aria-labelledby="add-local"><h3 id="add-local">From this computer</h3>${joinHtml([
|
|
51
|
+
local.pathProblem === null ? "" : notice(refused(local.pathProblem)),
|
|
52
|
+
local.pick ? acts(btn("Browse…", { sm: true, href: "/projects/pick" }))
|
|
53
|
+
: data.browsable ? acts(btn("Choose a folder", { sm: true, href: "/projects/browse" })) : "",
|
|
51
54
|
postForm("/projects/open", joinHtml([
|
|
52
|
-
field({ id: "add-path", label: "Or enter an exact path",
|
|
53
|
-
|
|
55
|
+
field({ id: "add-path", label: "Or enter an exact path",
|
|
56
|
+
hint: local.outside ? "Add any git repository on this computer — outside your projects folder, Toolroll asks for your password." : "It must be a git repository.",
|
|
57
|
+
error: null,
|
|
58
|
+
control: input({ id: "add-path", name: "path", hint: true, error: local.pathProblem !== null, value: local.pathValue, attrs: { placeholder: "~/code/your-repo", autocomplete: "off", spellcheck: "false", autocapitalize: "none" } }) }),
|
|
54
59
|
acts(btn("Add and open", { sm: true, type: "submit", variant: "primary" })),
|
|
55
|
-
]), { attrs: { class: "k-sec" }, returnTo: data.returnTo }),
|
|
60
|
+
]), { attrs: { class: "k-sec" }, returnTo: data.returnTo, hidden: { via: "path" } }),
|
|
56
61
|
])}</section>`;
|
|
57
|
-
return html `<div class="k-sec">${github ?? ""}${
|
|
62
|
+
return html `<div class="k-sec">${github ?? ""}${thisComputer}</div>`;
|
|
58
63
|
}
|
|
59
64
|
export function cloneReviewHtml(onboard, problem) {
|
|
60
65
|
if (onboard === null || !onboard.enabled || onboard.record === null)
|
|
@@ -97,8 +102,10 @@ export function projectsPage(chrome, data) {
|
|
|
97
102
|
const review = cloneReviewHtml(data.onboard, data.problemAt === "clone" ? data.problem : null);
|
|
98
103
|
const reviewHasProblem = review !== null && data.problemAt === "clone";
|
|
99
104
|
const said = data.problemAt === "said" && data.problem !== null ? sentence(data.problem) : null;
|
|
100
|
-
const
|
|
101
|
-
const
|
|
105
|
+
const pathProblem = data.problemAt === "path" ? data.problem : null;
|
|
106
|
+
const topProblem = data.problem === null || said !== null || linkProblem !== null || pathProblem !== null || reviewHasProblem ? null : data.problemAt === "clone" ? sentence(data.problem) : refused(data.problem);
|
|
107
|
+
const addHtml = addWaysHtml({ browsable: data.browsable, onboard: data.onboard, returnTo: data.returnTo, linkProblem,
|
|
108
|
+
...(data.local === undefined ? {} : { local: { ...data.local, pathProblem } }) });
|
|
102
109
|
const rowHtml = (one) => row({
|
|
103
110
|
href: one.href, chip: one.status === null ? html `` : one.status === "needs" ? chip(waitingWords(one.waiting), "ask") : status(one.status), title: one.name, wait: one.status === "needs",
|
|
104
111
|
desc: mono(one.shortPath), meta: html `<span>${one.summary ?? "Not scanned"}</span>${one.open ? html `<span>Open now</span>` : ""}`,
|
|
@@ -118,7 +125,7 @@ export function projectsPage(chrome, data) {
|
|
|
118
125
|
], "\n");
|
|
119
126
|
return screen(title, body, { chrome, workspace: { view: {
|
|
120
127
|
kind: "projects", choosing, problem: topProblem, said, returnTo: data.returnTo, recent, available,
|
|
121
|
-
add: { html: htmlString(addHtml), review: review === null ? null : htmlString(review), openOnLoad: linkProblem !== null },
|
|
128
|
+
add: { html: htmlString(addHtml), review: review === null ? null : htmlString(review), openOnLoad: linkProblem !== null || pathProblem !== null },
|
|
122
129
|
} } });
|
|
123
130
|
}
|
|
124
131
|
function activityHtml(report) {
|
|
@@ -232,3 +239,44 @@ export const unknownProject = (name) => ({ title: `There is no project called ${
|
|
|
232
239
|
export function waitingWords(count) {
|
|
233
240
|
return `${count} waiting on you`;
|
|
234
241
|
}
|
|
242
|
+
export function folderPickerPage(chrome, view) {
|
|
243
|
+
const title = "Choose a repository";
|
|
244
|
+
const crumbs = view.at === null ? "" : html `<nav class="k-mono" aria-label="Folder">${joinHtml(view.at.crumbs.map(one => one.href === null
|
|
245
|
+
? html `<span aria-current="location">${one.label}</span>`
|
|
246
|
+
: html `<a class="k-link" href="${one.href}">${one.label}</a>`), html `<span aria-hidden="true"> / </span>`)}</nav>`;
|
|
247
|
+
const gits = view.entries.filter(one => one.git).length;
|
|
248
|
+
const list = view.lookProblem !== null ? notice(view.lookProblem)
|
|
249
|
+
: view.entries.length === 0 && view.chosen !== null ? ""
|
|
250
|
+
: view.entries.length === 0 ? empty({ title: "No repositories here.", text: view.at?.up ? "Go up one folder, or try a shortcut." : "Try a shortcut." })
|
|
251
|
+
: html `${gits === 0 ? note("No repositories here. Open a folder to look inside it.") : ""}${group("Folders", count(view.entries.length))}${view.entries.map(one => row({
|
|
252
|
+
href: one.href, chip: one.git ? chip(one.registered ? "Project" : "Git repository", "") : html ``, title: one.name,
|
|
253
|
+
desc: one.git ? (one.registered ? "Already added" : "Choose to add it") : "Folder",
|
|
254
|
+
}))}`;
|
|
255
|
+
const body = joinHtml([
|
|
256
|
+
phoneHeader(title, { back: view.back[0] }),
|
|
257
|
+
doc(docHeader({ back: view.back, title, meta: crumbs, same: true }), view.problem === null ? "" : notice(sentence(view.problem)), view.said === null ? "" : infoLine(sentence(view.said)), view.chosen ?? "", view.shortcuts.length === 0 && !view.at?.up ? "" : html `<nav class="k-acts" aria-label="Go to">${view.at?.up ? btn("Up one folder", { sm: true, lead: "back", href: view.at.up }) : ""}${view.shortcuts.map(one => btn(one.label, { sm: true, variant: "ghost", href: one.href }))}</nav>`, html `<div>${list}</div>`),
|
|
258
|
+
], "\n");
|
|
259
|
+
return screen(title, body, { chrome });
|
|
260
|
+
}
|
|
261
|
+
export const typedPasswordField = (id) => field({ id, label: "Your password",
|
|
262
|
+
control: html `<input class="k-input" id="${id}" type="password" name="password" data-so-typed autocomplete="current-password" required>` });
|
|
263
|
+
export function pickRepoChosen(data) {
|
|
264
|
+
const form = (label, extra = "") => postForm("/projects/open", joinHtml([extra, acts(btn(label, { type: "submit", variant: "primary" }))]), { returnTo: "/projects", hidden: { path: data.path, via: "path" } });
|
|
265
|
+
const text = data.refusal !== null ? sentence(data.refusal)
|
|
266
|
+
: data.state === "open" ? "Already a project here."
|
|
267
|
+
: data.state === "outside" ? "It’s outside your projects folder, so Toolroll asks for your password."
|
|
268
|
+
: data.state === "blocked" ? "It’s outside your projects folder. Only an approver signed in with a password can add it."
|
|
269
|
+
: "Adds it as a project.";
|
|
270
|
+
const acts_ = data.refusal !== null || data.state === "blocked" ? ""
|
|
271
|
+
: data.state === "open" ? form("Open") : data.state === "outside" ? form("Add and open", typedPasswordField("pick-password")) : form("Add and open");
|
|
272
|
+
return slots({ status: html `<h2>${data.name}</h2>`, text: html `${mono(shortPathOf(data.path))} · ${text}`, acts: acts_, terms: "", attrs: { "aria-label": `Add ${data.name}` } });
|
|
273
|
+
}
|
|
274
|
+
export function outsideAddPage(chrome, data) {
|
|
275
|
+
const title = "Add a project from outside your projects folder";
|
|
276
|
+
const back = ["/projects", "Projects"];
|
|
277
|
+
const body = joinHtml([
|
|
278
|
+
phoneHeader(title, { back: back[0] }),
|
|
279
|
+
doc(docHeader({ back, title, same: true }), pickRepoChosen({ name: data.name, path: data.path, state: "outside", refusal: null })),
|
|
280
|
+
], "\n");
|
|
281
|
+
return screen(title, body, { chrome });
|
|
282
|
+
}
|
|
@@ -198,6 +198,7 @@ get("tasks", "term.state", "/term/state", TERM);
|
|
|
198
198
|
get("tasks", "term.session", `^\\/term\\/${TERMINAL}$`, { ...TERM, sample: `/term/${"a".repeat(32)}` });
|
|
199
199
|
get("tasks", "term.socket", `^\\/term\\/${TERMINAL}\\/socket$`, { ...TERM, sample: `/term/${"a".repeat(32)}/socket` });
|
|
200
200
|
get("pages", "projects.browse", "/projects/browse", free);
|
|
201
|
+
get("pages", "projects.pick", "/projects/pick", { ...free, callers: ["cookie"], project: "none", ...approver("Sign in as an approver to add projects.", "/projects") });
|
|
201
202
|
get("pages", "projects.github", "/projects/github", { ...free, callers: ["cookie"], callerRefusal: { status: 403, type: "text/plain; charset=utf-8", body: "listing repositories feeds a browser session's act" },
|
|
202
203
|
...anyApprover("your login can watch — adding projects is an approver's act") });
|
|
203
204
|
get("pages", "projects.page", "/projects", { limited: "unscoped", ...free });
|
|
@@ -449,7 +450,7 @@ post("pages", "projects.github-list", "/projects/github", { callers: ["cookie"],
|
|
|
449
450
|
post("pages", "projects.select", "/projects/select", { project: "form-path", limited: "unscoped", viewer: true });
|
|
450
451
|
post("pages", "projects.map-refresh", "^\\/projects\\/[^/]+\\/map\\/refresh$", { project: "form", sample: "/projects/payments-api/map/refresh", ...approver("An approver asks for a check of main.", "/projects") });
|
|
451
452
|
post("pages", "projects.remove", "/projects/remove", { project: "form", ...operator("An instance operator removes projects.", "/settings/project") });
|
|
452
|
-
post("pages", "projects.open", "/projects/open", { project: "
|
|
453
|
+
post("pages", "projects.open", "/projects/open", { project: "none" });
|
|
453
454
|
post("tasks", "tasks.add", "/tasks/add", { project: "form", limited: "collection", bodyCap: LARGE_FORM });
|
|
454
455
|
post("tasks", "tasks.fast", "/tasks/fast", { callers: ["cookie"], project: "none", limited: "collection", ...approver("An approver starts builds.", "/tasks/new") });
|
|
455
456
|
post("tasks", "queue.move", "/queue/move");
|
package/dist/server/settings.js
CHANGED
|
@@ -39,6 +39,7 @@ import { handlersOf } from './handler-registry.js';
|
|
|
39
39
|
import { refuse, screen, when } from "./chrome.js";
|
|
40
40
|
import { requestContext } from "./request-context.js";
|
|
41
41
|
import { btn, empty, infoLine, settingsSection } from "./kit.js";
|
|
42
|
+
import { shortPathOf } from "./render-projects.js";
|
|
42
43
|
import { approvalGroup, projectPicker, GROUP_PATHS, groupTitle, modeCeremonyHtml, modePageHtml, passwordlessHtml, HUB_ANCHOR_SCRIPT, pushScriptOf, settingsGroupPage, settingsSubPage } from "../settings-groups-ui.js";
|
|
43
44
|
import { HANDOFF_STYLE, redirect, respond, safeReturn, sayTo, signInSpent, startedHere } from "./http.js";
|
|
44
45
|
import { html, htmlString, joinHtml, postForm, reauth } from "../html.js";
|
|
@@ -769,6 +770,8 @@ ${restoreHtml(chosen, retired, undoableMerges(store, chosen), disabledLessons(st
|
|
|
769
770
|
return { owner: who.authority !== "full", passwordSet: store.accountOf(who.name)?.passwordSet === true, canTurnOff: who.authority === "full" && operator };
|
|
770
771
|
})(),
|
|
771
772
|
advanced: { on: requestContext.getStore()?.advanced !== false, canChange: who.via === "cookie" },
|
|
773
|
+
projectsFolder: restricted() || runtime.unscopedMode ? null
|
|
774
|
+
: { folders: runtime.ceiling.roots.map(path => ({ path, shown: shortPathOf(path) })) },
|
|
772
775
|
backup: lastBackup === null ? null : lastBackup.ok === false
|
|
773
776
|
? { failed: true, words: `Failed ${when(lastBackup.startedAt)}${lastBackup.error === null ? "" : `: ${lastBackup.error}`}` }
|
|
774
777
|
: { failed: false, words: lastBackup.finishedAt === null ? "Backing up now" : `Backed up ${when(lastBackup.finishedAt)}` },
|
package/dist/server/welcome.js
CHANGED
|
@@ -4,18 +4,20 @@ import { builderReadyFor, firstRunBuilderRepo } from "../dispatch.js";
|
|
|
4
4
|
import { firstTaskSuggestions, SAMPLE_FIRST_TASKS, SAMPLE_PROJECT_NAME, welcomeModel, withBuilderStep } from "../first-run.js";
|
|
5
5
|
import { html, joinHtml, postForm } from "../html.js";
|
|
6
6
|
import { START_BUILDER_HREF } from "../needs-you.js";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
7
|
+
import { addSampleProject } from "../sample-project.js";
|
|
8
|
+
import { resolveCeiling } from "../project.js";
|
|
9
|
+
import { readProjectRegistryNow } from "../repos.js";
|
|
10
10
|
import { refuse, screen } from "./chrome.js";
|
|
11
11
|
import { handlersOf } from "./handler-registry.js";
|
|
12
12
|
import { redirect } from "./http.js";
|
|
13
|
+
import { rereadBrowser } from "./live.js";
|
|
13
14
|
import { btn, chip, codeLine, dock, note, notice, pageHeader, settingsRecord } from "./kit.js";
|
|
14
15
|
export const SAMPLE_PROBLEMS = {
|
|
15
16
|
"no-root": "There's no project folder to put the sample in. Add a folder instead.",
|
|
16
17
|
exists: `A folder named ${SAMPLE_PROJECT_NAME} is already there and wasn't made here, so nothing was changed.`,
|
|
17
18
|
failed: "The sample project couldn't be made. Nothing was added. Try again, or add a folder instead.",
|
|
18
19
|
"not-added": "The sample project was made but couldn't be added. Try again, or add it from Projects.",
|
|
20
|
+
incomplete: "The sample project wasn't added, and its line in the project list couldn't be taken back. Remove it in Projects, then try again.",
|
|
19
21
|
};
|
|
20
22
|
const isSampleProblem = (value) => value !== null && Object.hasOwn(SAMPLE_PROBLEMS, value);
|
|
21
23
|
const plural = (n, one, many) => `${n} ${n === 1 ? one : many}`;
|
|
@@ -118,27 +120,36 @@ export function createWelcomeHandlers(runtime) {
|
|
|
118
120
|
return sendScreen(response, 200, welcomePage(chrome, model, { problem: isSampleProblem(asked) ? asked : null, canAdd: approver && !store.isDemo() }));
|
|
119
121
|
}
|
|
120
122
|
async function addSample(ctx) {
|
|
121
|
-
const { who, response, now, posted } = ctx;
|
|
123
|
+
const { who, response, now, posted, request } = ctx;
|
|
122
124
|
readForm(posted, CONSOLE_FORMS.welcomeSample);
|
|
123
125
|
if (who.via !== "cookie")
|
|
124
126
|
return refuse(response, who, 403, "adding a project is a browser session's act");
|
|
125
127
|
if (store.isDemo())
|
|
126
128
|
return refuse(response, who, 403, "the sandbox never makes projects");
|
|
127
129
|
const back = (problem) => redirect(response, `/welcome?sample=${problem}#welcome-project`);
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
130
|
+
const stands = () => { const again = rereadBrowser(runtime, request, who); return again !== null && again.role === "approver" && !store.isDemo(); };
|
|
131
|
+
const registryPath = options.registryPath ?? null;
|
|
132
|
+
const registryBacked = registryPath !== null && options.admittedRepos !== undefined;
|
|
133
|
+
const ceiling = (registry) => {
|
|
134
|
+
const live = liveCeiling();
|
|
135
|
+
if (!registryBacked)
|
|
136
|
+
return live;
|
|
137
|
+
const read = registry ?? readProjectRegistryNow(registryPath);
|
|
138
|
+
const current = "error" in read ? [] : resolveCeiling([], read.roots).ceiling.roots;
|
|
139
|
+
return { ...live, roots: live.roots.filter(root => current.includes(root)) };
|
|
140
|
+
};
|
|
141
|
+
const added = await addSampleProject({
|
|
142
|
+
store, registryFile: registryPath, ceiling, now, visible,
|
|
143
|
+
authority: { actor: { label: who.name, origin: "console" }, stands },
|
|
144
|
+
resolveFolder: identities.resolveNow, generation: () => identities.generation(),
|
|
145
|
+
});
|
|
146
|
+
if (!added.ok) {
|
|
147
|
+
if (added.reason === "refused")
|
|
148
|
+
return refuse(response, who, 403, "your access changed while the sample was being added");
|
|
149
|
+
return back(added.reason);
|
|
150
|
+
}
|
|
151
|
+
deletedRepos.delete(added.repo);
|
|
152
|
+
who.session.project = added.repo;
|
|
142
153
|
who.session.projectRevision++;
|
|
143
154
|
sessions.persist(who.session);
|
|
144
155
|
return redirect(response, "/welcome");
|
|
@@ -402,13 +402,22 @@ export function projectsGroup(facts, flags) {
|
|
|
402
402
|
]);
|
|
403
403
|
return settingsShell({
|
|
404
404
|
group: "projects", title: "Projects", lead: "Each project has its own network, writes, checks, pull requests and tools.", flags,
|
|
405
|
-
body: joinHtml([answered(facts),
|
|
405
|
+
body: joinHtml([answered(facts), projectsFolderSection(facts.projectsFolder ?? null),
|
|
406
406
|
facts.projects.length === 0
|
|
407
407
|
? settingsSection({ id: "projects", title: "Projects", body: note(html `No projects yet. <a class="k-link" href="/projects">Add one on Projects</a>.`) })
|
|
408
408
|
: settingsLinks("Projects", rows),
|
|
409
409
|
per]),
|
|
410
410
|
});
|
|
411
411
|
}
|
|
412
|
+
function projectsFolderSection(view) {
|
|
413
|
+
if (view === null || view.folders.length === 0)
|
|
414
|
+
return html ``;
|
|
415
|
+
return settingsSection({
|
|
416
|
+
id: "projects-folder", title: view.folders.length === 1 ? "Projects folder" : "Projects folders",
|
|
417
|
+
lead: "Toolroll can add any git repository inside it.",
|
|
418
|
+
body: joinHtml(view.folders.map(one => formRow("Folder", null, html `<span class="k-mono">${one.shown}</span>`, "inline"))),
|
|
419
|
+
});
|
|
420
|
+
}
|
|
412
421
|
export function accessGroup(facts, flags) {
|
|
413
422
|
const people = facts.people;
|
|
414
423
|
const links = [
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { spawn as spawnChild } from "node:child_process";
|
|
2
|
+
import { chmodSync, lstatSync, mkdtempSync, readdirSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { basename, dirname, join } from "node:path";
|
|
4
|
+
import { SIGN_IN_LINK_MS } from "./server/session.js";
|
|
5
|
+
export const NO_SAFE_OPENER = "this computer can't open a browser for Toolroll safely. To use the browser, run `toolroll password set` and sign in with that password";
|
|
6
|
+
export function platformOpener(platform = process.platform) {
|
|
7
|
+
return platform === "darwin" ? "open" : platform === "linux" ? "xdg-open" : null;
|
|
8
|
+
}
|
|
9
|
+
const PAGE_FOLDER = /^sign-in-[A-Za-z0-9]{6}$/;
|
|
10
|
+
const PAGE_FILE = "open.html";
|
|
11
|
+
export function writeSignInPage(parent, link, now = Date.now()) {
|
|
12
|
+
sweepSignInPages(parent, now);
|
|
13
|
+
const dir = mkdtempSync(join(parent, "sign-in-"));
|
|
14
|
+
const file = join(dir, PAGE_FILE);
|
|
15
|
+
try {
|
|
16
|
+
chmodSync(dir, 0o700);
|
|
17
|
+
const attribute = link.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<");
|
|
18
|
+
writeFileSync(file, `<!doctype html><meta charset="utf-8"><meta name="referrer" content="no-referrer">`
|
|
19
|
+
+ `<meta http-equiv="refresh" content="0;url=${attribute}"><title>Toolroll</title>`
|
|
20
|
+
+ `<script>location.replace(${JSON.stringify(link).replace(/</g, "\\u003c")})</script><p>Opening Toolroll…</p>\n`, { mode: 0o600 });
|
|
21
|
+
chmodSync(file, 0o600);
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
rmSync(dir, { recursive: true, force: true });
|
|
25
|
+
throw error;
|
|
26
|
+
}
|
|
27
|
+
return file;
|
|
28
|
+
}
|
|
29
|
+
export function removeSignInPage(file) {
|
|
30
|
+
const dir = dirname(file);
|
|
31
|
+
if (basename(file) !== PAGE_FILE || !PAGE_FOLDER.test(basename(dir)))
|
|
32
|
+
throw Error(`${file} isn't a sign-in page`);
|
|
33
|
+
let info;
|
|
34
|
+
try {
|
|
35
|
+
info = lstatSync(dir);
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
if (error.code === "ENOENT")
|
|
39
|
+
return;
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
42
|
+
if (!info.isDirectory())
|
|
43
|
+
throw Error(`${dir} isn't a sign-in page's folder`);
|
|
44
|
+
rmSync(dir, { recursive: true, force: true });
|
|
45
|
+
}
|
|
46
|
+
function sweepSignInPages(parent, now) {
|
|
47
|
+
let names;
|
|
48
|
+
try {
|
|
49
|
+
names = readdirSync(parent);
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const uid = process.getuid?.() ?? -1;
|
|
55
|
+
for (const name of names) {
|
|
56
|
+
if (!PAGE_FOLDER.test(name))
|
|
57
|
+
continue;
|
|
58
|
+
try {
|
|
59
|
+
const info = lstatSync(join(parent, name));
|
|
60
|
+
if (!info.isDirectory() || (uid >= 0 && info.uid !== uid) || now - info.mtimeMs < SIGN_IN_LINK_MS)
|
|
61
|
+
continue;
|
|
62
|
+
removeSignInPage(join(parent, name, PAGE_FILE));
|
|
63
|
+
}
|
|
64
|
+
catch { }
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
export function openSignInPage(file, spawn = spawnChild, platform = process.platform, settleMs = 3_000) {
|
|
68
|
+
const command = platformOpener(platform);
|
|
69
|
+
if (command === null)
|
|
70
|
+
return Promise.resolve(false);
|
|
71
|
+
return new Promise(resolve => {
|
|
72
|
+
let settled = false;
|
|
73
|
+
let timer;
|
|
74
|
+
const end = (opened) => {
|
|
75
|
+
if (settled)
|
|
76
|
+
return;
|
|
77
|
+
settled = true;
|
|
78
|
+
if (timer !== undefined)
|
|
79
|
+
clearTimeout(timer);
|
|
80
|
+
resolve(opened);
|
|
81
|
+
};
|
|
82
|
+
let child;
|
|
83
|
+
try {
|
|
84
|
+
child = spawn(command, [file], { detached: true, stdio: "ignore" });
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
end(false);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
child.on("error", () => end(false));
|
|
91
|
+
child.once("exit", code => end(code === 0));
|
|
92
|
+
timer = setTimeout(() => end(true), settleMs);
|
|
93
|
+
child.unref();
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
export function ledgerSpent(store, outcome, account) {
|
|
97
|
+
const sinceRow = store.handle.prepare("SELECT coalesce(max(id), 0) AS id FROM action_ledger").get();
|
|
98
|
+
const since = Number(sinceRow?.["id"] ?? 0);
|
|
99
|
+
const spent = store.handle.prepare("SELECT actor FROM action_ledger WHERE id > ? AND source = 'sign-in' AND action = 'signed in' AND outcome = ?");
|
|
100
|
+
return () => spent.all(since, outcome).some(row => account === null || row["actor"] === account);
|
|
101
|
+
}
|
|
102
|
+
const held = new Set();
|
|
103
|
+
let exitHooked = false;
|
|
104
|
+
function holdUntilExit(finish) {
|
|
105
|
+
held.add(finish);
|
|
106
|
+
if (exitHooked)
|
|
107
|
+
return;
|
|
108
|
+
exitHooked = true;
|
|
109
|
+
process.once("exit", () => { for (const one of [...held])
|
|
110
|
+
one(); });
|
|
111
|
+
}
|
|
112
|
+
const REMOVE_RETRIES = 3;
|
|
113
|
+
const REMOVE_RETRY_MS = 250;
|
|
114
|
+
export function removeSignInPageWhenSpent(file, spent, options = {}) {
|
|
115
|
+
let done = false;
|
|
116
|
+
let resolveGone = () => { };
|
|
117
|
+
const gone = new Promise(resolve => { resolveGone = resolve; });
|
|
118
|
+
const removeOnce = options.remove ?? removeSignInPage;
|
|
119
|
+
const remove = (left) => {
|
|
120
|
+
try {
|
|
121
|
+
removeOnce(file);
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
if (left > 0) {
|
|
125
|
+
const again = setTimeout(() => remove(left - 1), REMOVE_RETRY_MS);
|
|
126
|
+
again.unref?.();
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
const finish = () => {
|
|
131
|
+
if (done)
|
|
132
|
+
return;
|
|
133
|
+
done = true;
|
|
134
|
+
held.delete(finish);
|
|
135
|
+
clearInterval(timer);
|
|
136
|
+
clearTimeout(expiry);
|
|
137
|
+
try {
|
|
138
|
+
remove(REMOVE_RETRIES);
|
|
139
|
+
}
|
|
140
|
+
finally {
|
|
141
|
+
try {
|
|
142
|
+
options.onEnd?.();
|
|
143
|
+
}
|
|
144
|
+
catch { }
|
|
145
|
+
resolveGone();
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
const timer = setInterval(() => { try {
|
|
149
|
+
if (spent())
|
|
150
|
+
finish();
|
|
151
|
+
}
|
|
152
|
+
catch {
|
|
153
|
+
finish();
|
|
154
|
+
} }, options.everyMs ?? 500);
|
|
155
|
+
const expiry = setTimeout(finish, Math.max(0, (options.expiresAt ?? Date.now() + SIGN_IN_LINK_MS) - Date.now()));
|
|
156
|
+
timer.unref?.();
|
|
157
|
+
expiry.unref?.();
|
|
158
|
+
holdUntilExit(finish);
|
|
159
|
+
return { stop: finish, gone };
|
|
160
|
+
}
|
|
161
|
+
export async function openSignInLink(link, options) {
|
|
162
|
+
const platform = options.platform ?? process.platform;
|
|
163
|
+
const nothing = { opened: false, stop: () => { }, wait: async () => { } };
|
|
164
|
+
const end = () => { try {
|
|
165
|
+
options.onEnd?.();
|
|
166
|
+
}
|
|
167
|
+
catch { } };
|
|
168
|
+
if (platformOpener(platform) === null) {
|
|
169
|
+
end();
|
|
170
|
+
return nothing;
|
|
171
|
+
}
|
|
172
|
+
let file;
|
|
173
|
+
try {
|
|
174
|
+
file = writeSignInPage(options.parent, link);
|
|
175
|
+
}
|
|
176
|
+
catch {
|
|
177
|
+
end();
|
|
178
|
+
return nothing;
|
|
179
|
+
}
|
|
180
|
+
const watch = removeSignInPageWhenSpent(file, options.spent, {
|
|
181
|
+
expiresAt: options.expiresAt,
|
|
182
|
+
...(options.everyMs === undefined ? {} : { everyMs: options.everyMs }),
|
|
183
|
+
...(options.onEnd === undefined ? {} : { onEnd: options.onEnd }),
|
|
184
|
+
});
|
|
185
|
+
if (!await openSignInPage(file, options.opener ?? spawnChild, platform)) {
|
|
186
|
+
watch.stop();
|
|
187
|
+
return nothing;
|
|
188
|
+
}
|
|
189
|
+
const wait = async (ms) => {
|
|
190
|
+
let bound;
|
|
191
|
+
await Promise.race([watch.gone, new Promise(resolve => { bound = setTimeout(resolve, ms); })]);
|
|
192
|
+
if (bound !== undefined)
|
|
193
|
+
clearTimeout(bound);
|
|
194
|
+
watch.stop();
|
|
195
|
+
};
|
|
196
|
+
return { opened: true, stop: watch.stop, wait };
|
|
197
|
+
}
|
package/dist/store.js
CHANGED
|
@@ -18660,3 +18660,36 @@ export const CONTAINMENT_NOTICE_FACT = "containment-notice-shown";
|
|
|
18660
18660
|
export function noticeDueOnce(store, key, now) {
|
|
18661
18661
|
return Number(store.handle.prepare("INSERT OR IGNORE INTO installation_fact (key, value, created_at) VALUES (?, 'yes', ?)").run(key, now.toISOString()).changes) === 1;
|
|
18662
18662
|
}
|
|
18663
|
+
export function passwordResetRefusal(store, name, passwordsOnlyForOperators) {
|
|
18664
|
+
const row = store.handle.prepare("SELECT credential_hash, password_set, revoked_at FROM approver WHERE name = ?").get(name);
|
|
18665
|
+
if (row === undefined)
|
|
18666
|
+
return "no-account";
|
|
18667
|
+
if (row["revoked_at"] !== null && row["revoked_at"] !== undefined)
|
|
18668
|
+
return "revoked";
|
|
18669
|
+
if (String(row["credential_hash"]).startsWith("sso-only$"))
|
|
18670
|
+
return "sso-only";
|
|
18671
|
+
if (Number(row["password_set"]) !== 1)
|
|
18672
|
+
return "no-password";
|
|
18673
|
+
if (passwordsOnlyForOperators && !store.isInstanceOperator(name))
|
|
18674
|
+
return "password-not-allowed";
|
|
18675
|
+
return null;
|
|
18676
|
+
}
|
|
18677
|
+
export function resetAccountPassword(store, name, credentialHash, expectedGeneration, passwordsOnlyForOperators, now) {
|
|
18678
|
+
return store.transact(() => {
|
|
18679
|
+
const refusal = passwordResetRefusal(store, name, passwordsOnlyForOperators);
|
|
18680
|
+
if (refusal !== null)
|
|
18681
|
+
return { ok: false, reason: refusal };
|
|
18682
|
+
const written = store.handle.prepare(`UPDATE approver SET credential_hash = ?, generation = generation + 1
|
|
18683
|
+
WHERE name = ? AND generation = ? AND password_set = 1 AND revoked_at IS NULL AND credential_hash NOT LIKE 'sso-only$%'`).run(credentialHash, name, expectedGeneration);
|
|
18684
|
+
if (Number(written.changes) !== 1)
|
|
18685
|
+
return { ok: false, reason: "changed" };
|
|
18686
|
+
store.revokeDerivedAuthority(name, "credential-rotation", now);
|
|
18687
|
+
const leadTokens = store.revokeLeadCredentials(name, name, now);
|
|
18688
|
+
store.recordAction({ at: now.toISOString(), actor: name, repo: null, taskId: null, runId: null, action: "password reset at this computer", outcome: "changed", source: "access",
|
|
18689
|
+
detail: `every session of ${name} ended (generation ${expectedGeneration + 1})${leadTokens > 0 ? `; ${leadTokens} lead token${leadTokens === 1 ? "" : "s"} ended` : ""}` });
|
|
18690
|
+
return { ok: true, generation: expectedGeneration + 1, leadTokens };
|
|
18691
|
+
});
|
|
18692
|
+
}
|
|
18693
|
+
export function projectRowKnown(store, path) {
|
|
18694
|
+
return store.handle.prepare("SELECT 1 FROM project WHERE path = ?").get(path) !== undefined;
|
|
18695
|
+
}
|
package/dist/surface.js
CHANGED
|
@@ -455,7 +455,9 @@ const GUIDE_ROWS = [
|
|
|
455
455
|
operator("stop", "stop this computer's Toolroll after its running work is saved: the background service (until the next login), or the `up` running in a terminal"),
|
|
456
456
|
operator("open", "open this computer's Toolroll at a terminal, signed in: the terminal UI, or the browser with --web (starts it first when it isn't running); never prints a sign-in link"),
|
|
457
457
|
{ ...operatorRead("welcome", "the three steps to a first result (agent, project, first task) as the console's welcome shows them; at a terminal it walks them one at a time"), flags: [jsonFlag, dbFlag] },
|
|
458
|
+
{ ...operator("welcome sample", "add the sample project (a tiny repository with one function and its test) in your projects folder, as this computer's password-free owner at a terminal: the console welcome's Try a sample project; takes no folder or name"), flags: [jsonFlag, dbFlag] },
|
|
458
459
|
operator("password set", "set this computer's first password, typed twice at your own terminal (never a flag, file or environment variable); every session signs in again and local mode stays on"),
|
|
460
|
+
operator("password reset", "reset a forgotten password at the computer running Toolroll, typed twice at your own terminal (the one approver, or --as <name>); every session of that account ends and a saved first password that no longer works is removed. Anyone who can run commands as you on this computer can do this, as they could read the saved file"),
|
|
459
461
|
{ ...operatorRead("doctor", "check that Toolroll's service holds no key, token or password a build could read; names what it finds and the steps to fix it, never a value, and changes nothing"), flags: [jsonFlag] },
|
|
460
462
|
];
|
|
461
463
|
const REMOTE_NO = [
|
|
@@ -466,7 +468,7 @@ const REMOTE_NO = [
|
|
|
466
468
|
"assignment show", "assignment updates", "assignment claim", "assignment check", "assignment brief", "assignment inbox", "assignment ack",
|
|
467
469
|
"claim", "heartbeat", "worker release", "reap", "tick", "build", "reconcile",
|
|
468
470
|
"runner register", "runner retire", "runner bind", "runner capacity", "coordinator mint", "coordinator revoke", "mcp", "outbox deliver", "peek",
|
|
469
|
-
"serve", "serve check-public", "watch", "up", "onboard", "daemon", "background on", "background off", "background show", "stop", "open", "welcome", "password set", "doctor", "bridge", "setup show", "setup clear",
|
|
471
|
+
"serve", "serve check-public", "watch", "up", "onboard", "daemon", "background on", "background off", "background show", "stop", "open", "welcome", "welcome sample", "password set", "password reset", "doctor", "bridge", "setup show", "setup clear",
|
|
470
472
|
"providers", "keys status", "keys set", "keys clear", "keys verify", "keys auth", "models check", "models update", "models watch",
|
|
471
473
|
"models results",
|
|
472
474
|
"models suggestions", "models accept", "models dismiss", "models turn-off", "models keep", "models try", "models stop",
|
|
@@ -538,6 +540,7 @@ const LOCAL_ALLOW = {
|
|
|
538
540
|
"task archive": "archive-task",
|
|
539
541
|
"task restore": "archive-task",
|
|
540
542
|
"repos add": "add-project",
|
|
543
|
+
"welcome sample": "add-project",
|
|
541
544
|
"models suggestions": "read",
|
|
542
545
|
"models turn-off": "routing-turn-off",
|
|
543
546
|
"models dismiss": "dismiss-suggestion",
|