toolroll 0.9.108 → 0.9.109
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 +34 -0
- package/dist/advanced-view.js +0 -1
- package/dist/agent-fence.js +35 -4
- package/dist/agent-state.js +5 -2
- package/dist/assignment-ui.js +5 -5
- package/dist/assignment.js +5 -2
- package/dist/browser/terminal.js +1 -1
- package/dist/browser/workspace.css +1 -1
- 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 +9 -1
- package/dist/chat-controls.js +6 -5
- package/dist/chat-decide.js +1 -1
- package/dist/chat-quiet.js +3 -3
- package/dist/chat-voice.js +2 -2
- package/dist/cli-help.js +12 -13
- package/dist/cli.js +4 -3
- package/dist/console-chrome.js +10 -3
- package/dist/contracts/console-api.js +4 -3
- package/dist/contracts/handoff.js +4 -0
- 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/dispatch.js +3 -8
- package/dist/flexible-available.js +1 -0
- package/dist/flexible-schema.js +32 -0
- package/dist/flexible-thread-schema.js +30 -0
- package/dist/flexible-thread.js +526 -0
- package/dist/flexible-ui.js +44 -0
- package/dist/flexible.js +359 -0
- package/dist/git-views.js +38 -38
- package/dist/guides.js +11 -10
- package/dist/keymap.js +1 -1
- package/dist/lead-context.js +1 -1
- package/dist/limits-ui.js +1 -1
- package/dist/live-bus.js +70 -13
- package/dist/needs-you.js +3 -3
- package/dist/nightly-github.js +2 -2
- package/dist/operate.js +111 -3
- package/dist/project-delete-ui.js +2 -1
- package/dist/project-delete.js +1 -0
- package/dist/provider-auth.js +1 -1
- package/dist/release.js +1 -0
- package/dist/result-actions.js +3 -0
- package/dist/result-evidence-readers.js +8 -2
- package/dist/result-review.js +20 -9
- package/dist/serve.js +32 -29
- package/dist/server/chat.js +9 -9
- package/dist/server/chrome.js +16 -16
- package/dist/server/guards.js +10 -4
- package/dist/server/home.js +37 -5
- package/dist/server/http.js +4 -2
- package/dist/server/in-place.js +5 -4
- package/dist/server/kit.js +2 -2
- package/dist/server/live.js +100 -10
- package/dist/server/pages.js +79 -53
- package/dist/server/render-chat.js +1 -1
- package/dist/server/render-history.js +18 -4
- package/dist/server/render-new-task.js +2 -2
- 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 +26 -10
- package/dist/server/render-tasks.js +26 -17
- package/dist/server/retired-routes.js +37 -4
- package/dist/server/route-policy.js +8 -0
- package/dist/server/route-table.js +13 -4
- package/dist/server/settings-computers.js +140 -0
- package/dist/server/settings-scripts.js +15 -0
- package/dist/server/settings-section-table.js +56 -0
- package/dist/server/settings-sections.js +258 -0
- package/dist/server/settings.js +164 -19
- package/dist/server/task-views.js +47 -13
- package/dist/server/tasks.js +143 -90
- package/dist/server/welcome.js +6 -5
- package/dist/settings-groups-ui.js +24 -105
- package/dist/settings-proofs.js +5 -2
- package/dist/sqlite-telemetry.js +70 -21
- package/dist/store.js +108 -9
- package/dist/task-link.js +64 -0
- package/dist/tui.js +1 -1
- package/dist/typed-words-schema.js +18 -0
- package/dist/welcome-facts.js +3 -2
- package/dist/work-index.js +126 -29
- package/dist/work-reads.js +279 -0
- package/package.json +4 -2
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { plural, RESOURCE } from "../design/kit.js";
|
|
2
|
+
import { html, joinHtml, postForm } from "../html.js";
|
|
3
|
+
import { START_BUILDER_COMMAND } from "../needs-you.js";
|
|
4
|
+
import { kitSectionForm, textField } from "../settings-kit.js";
|
|
5
|
+
import { btn, chip, codeLine, doc, docHeader, facts, infoLine, note, notice, phoneHeader, select, settingsRecord, settingsSection } from "./kit.js";
|
|
6
|
+
import { changeDocumentOf, changeHref, sectionHref } from "./settings-section-table.js";
|
|
7
|
+
const AREA = "/settings/computers";
|
|
8
|
+
export const RUNNER_REGISTER = "runner-register";
|
|
9
|
+
const chipOf = (one) => one.retired ? chip("Retired") : chip(RESOURCE[one.state].word, RESOURCE[one.state].tone);
|
|
10
|
+
function lineOf(one, now, ago) {
|
|
11
|
+
const reserved = one.reserved.length > 0 ? ` · ${one.reserved.length} reserved` : "";
|
|
12
|
+
if (one.retired)
|
|
13
|
+
return `Retired${reserved}`;
|
|
14
|
+
if (one.state === "offline")
|
|
15
|
+
return `Stopped answering ${ago(one.heardAt, now)}${reserved}`;
|
|
16
|
+
const busy = one.building.length + one.hidden;
|
|
17
|
+
if (one.state === "building")
|
|
18
|
+
return `${busy} of ${one.capacity} building · heard ${ago(one.heardAt, now)}${reserved}`;
|
|
19
|
+
return `Free · ${plural(one.capacity, "slot", "slots")} · heard ${ago(one.heardAt, now)}${reserved}`;
|
|
20
|
+
}
|
|
21
|
+
function startSection(deps, subject) {
|
|
22
|
+
return {
|
|
23
|
+
loadSummary: ctx => {
|
|
24
|
+
const task = subject.task;
|
|
25
|
+
const repo = task?.repo ?? ctx.project;
|
|
26
|
+
return { project: repo === null ? null : deps.projectName(repo), connected: repo === null ? null : deps.connected(repo, ctx.now, task?.runner ?? null),
|
|
27
|
+
whole: !ctx.person.restricted, register: ctx.can["register"] === true };
|
|
28
|
+
},
|
|
29
|
+
render: ({ declaration, summary, attrs }) => {
|
|
30
|
+
const where = summary.project === null ? "" : html ` to <strong>${summary.project}</strong>`;
|
|
31
|
+
const state = summary.connected === null ? html `` : summary.connected
|
|
32
|
+
? html `<p>A builder is connected${where}. Approved tasks there start on their own.</p>`
|
|
33
|
+
: html `<p><strong>No builder is connected</strong>${where}. Tasks wait until one is.</p>`;
|
|
34
|
+
const register = changeDocumentOf("register-computer");
|
|
35
|
+
return settingsSection({
|
|
36
|
+
id: "start", title: declaration.title, attrs,
|
|
37
|
+
...(summary.register && register !== undefined ? { right: btn("Register a computer", { sm: true, href: changeHref(register) }) } : {}),
|
|
38
|
+
body: joinHtml([
|
|
39
|
+
state,
|
|
40
|
+
html `<p>On the computer where ${summary.project ?? "the project"} lives, open the project's folder in a terminal and run:</p>`,
|
|
41
|
+
html `<p id="builder">${codeLine(START_BUILDER_COMMAND)}</p>`,
|
|
42
|
+
summary.whole
|
|
43
|
+
? note(html `Keep it running. Approved tasks start on their own. The console alone (<code>toolroll serve</code>) doesn't build.`)
|
|
44
|
+
: note("Starting a builder takes someone who manages this Toolroll. Ask them to run it there; your tasks start on their own once it connects."),
|
|
45
|
+
]),
|
|
46
|
+
});
|
|
47
|
+
},
|
|
48
|
+
refusal: "An approver with access to the whole installation registers computers, from a browser.",
|
|
49
|
+
renderChange: ({ ctx, problem }) => {
|
|
50
|
+
const title = "Register a computer";
|
|
51
|
+
const back = sectionHref({ id: "start", area: "computers" });
|
|
52
|
+
const drafts = subject.drafts;
|
|
53
|
+
const capacity = /^(1|2|3|4|6|8)$/.test(drafts["capacity"] ?? "") ? drafts["capacity"] : "1";
|
|
54
|
+
const form = kitSectionForm({ proof: "runner-register", action: "/fleet/runner/register", id: "register-form", native: true, save: { label: "Register computer" },
|
|
55
|
+
hidden: { nonce: deps.registerNonce(ctx.person.name) },
|
|
56
|
+
body: joinHtml([
|
|
57
|
+
textField({ id: "register-name", name: "name", label: "Computer name", value: drafts["name"] ?? "", hint: "One short line, like the computer's own name.",
|
|
58
|
+
error: drafts["field"] === "name" ? problem : null, attrs: { maxlength: 60, autocomplete: "off", spellcheck: "false", required: true } }),
|
|
59
|
+
html `<div class="kit-field"><label for="register-capacity">Tasks at a time</label>${select({ id: "register-capacity", name: "capacity", current: capacity, items: ["1", "2", "3", "4", "6", "8"] })}</div>`,
|
|
60
|
+
]) });
|
|
61
|
+
const body = joinHtml([
|
|
62
|
+
html `<p>Registering makes a token that lets the computer take work. It is shown once, on the next page; only its hash is kept. Most computers don't need this: <code>${START_BUILDER_COMMAND}</code> registers the computer it runs on.</p>`,
|
|
63
|
+
problem === null || drafts["field"] === "name" ? "" : notice(problem),
|
|
64
|
+
form,
|
|
65
|
+
html `<div class="k-acts">${btn("Cancel", { variant: "ghost", href: back })}</div>`,
|
|
66
|
+
]);
|
|
67
|
+
return { title, body: html `<div data-kit-page>${phoneHeader(title, { back })}${doc(docHeader({ title, back: [back, "Computers"], same: true }), body)}</div>` };
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function buildersSection(deps, subject) {
|
|
72
|
+
const detailOf = (computers, name) => name === null ? null : ((one) => one === undefined ? { missing: name } : { one })(computers.list.find(each => each.name === name));
|
|
73
|
+
return {
|
|
74
|
+
loadSummary: ctx => deps.computers(ctx.now, ctx.can["manage"] === true),
|
|
75
|
+
loadDetail: ctx => detailOf(deps.computers(ctx.now, ctx.can["manage"] === true), subject.computer),
|
|
76
|
+
render: ({ declaration, ctx, summary, detail, attrs }) => {
|
|
77
|
+
const retire = changeDocumentOf("retire-computer");
|
|
78
|
+
const rows = summary.list.map(one => {
|
|
79
|
+
const opened = detail !== null && "one" in detail && detail.one.name === one.name;
|
|
80
|
+
return settingsRecord({ attrs: { "data-computer": one.name },
|
|
81
|
+
title: html `${one.name} ${chipOf(one)}`, sub: `${one.host} · ${lineOf(one, ctx.now, deps.ago)}`,
|
|
82
|
+
action: opened ? html `` : btn("Details", { sm: true, variant: "ghost", href: `${sectionHref(declaration, { open: true, extra: { computer: one.name } })}#builders` }),
|
|
83
|
+
more: opened ? detailHtml(one, summary, ctx, deps, retire === undefined ? null : changeHref(retire, null, { computer: one.name })) : undefined });
|
|
84
|
+
});
|
|
85
|
+
return settingsSection({
|
|
86
|
+
id: "builders", title: declaration.title, state: summary.list.length === 0 ? "" : ` · ${summary.list.length}`, attrs,
|
|
87
|
+
body: joinHtml([
|
|
88
|
+
html `<div id="workers">${summary.list.length === 0 ? note("No computer is building yet. Approved tasks wait until one is connected (above).") : joinHtml(rows)}</div>`,
|
|
89
|
+
detail !== null && "missing" in detail ? notice(`There's no computer named ${detail.missing}.`) : "",
|
|
90
|
+
summary.shared > 0 ? note(html `${plural(summary.shared, "task waits", "tasks wait")} in the shared queue for any free computer. <a class="k-link" href="/?view=order">Reserve one for a computer</a>`) : "",
|
|
91
|
+
]),
|
|
92
|
+
});
|
|
93
|
+
},
|
|
94
|
+
refusal: "An approver with access to the whole installation retires computers, from a browser.",
|
|
95
|
+
renderChange: ({ ctx, problem }) => {
|
|
96
|
+
const back = sectionHref({ id: "builders", area: "computers" });
|
|
97
|
+
const name = subject.computer;
|
|
98
|
+
const one = name === null ? undefined : deps.computers(ctx.now, true).list.find(each => each.name === name);
|
|
99
|
+
const title = one === undefined ? "Retire a computer" : `Retire ${one.name}`;
|
|
100
|
+
const body = one === undefined || one.retired
|
|
101
|
+
? joinHtml([infoLine(one === undefined ? "There's no computer by that name to retire." : `${one.name} is already retired.`), html `<div class="k-acts">${btn("Back to Computers", { href: back })}</div>`])
|
|
102
|
+
: joinHtml([
|
|
103
|
+
html `<p>${one.name} stops taking work. Tasks reserved for it wait until you move them. To use it again, register the name again.</p>`,
|
|
104
|
+
facts([["Computer", one.host], ["Status", lineOf(one, ctx.now, deps.ago)], ["Reserved for it", one.reserved.length === 0 ? "Nothing" : plural(one.reserved.length, "task", "tasks")]]),
|
|
105
|
+
problem === null ? "" : notice(problem),
|
|
106
|
+
kitSectionForm({ proof: "runner-retire", action: "/fleet/runner/retire", id: "retire-form", native: true, save: { label: "Retire computer" }, hidden: { name: one.name }, body: html `` }),
|
|
107
|
+
html `<div class="k-acts">${btn("Cancel", { variant: "ghost", href: `${sectionHref({ id: "builders", area: "computers" }, { open: true, extra: { computer: one.name } })}#builders` })}</div>`,
|
|
108
|
+
]);
|
|
109
|
+
return { title, body: html `<div data-kit-page>${phoneHeader(title, { back })}${doc(docHeader({ title, back: [back, "Computers"], same: true }), body)}</div>` };
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
function detailHtml(one, computers, ctx, deps, retireHref) {
|
|
114
|
+
const others = computers.list.filter(other => other.name !== one.name && !other.retired);
|
|
115
|
+
const reserved = one.reserved.length === 0 ? note("Nothing reserved. It takes from the shared queue, top first.")
|
|
116
|
+
: html `<ul class="k-list">${one.reserved.map(task => html `<li data-reserved="${task.id}"><a href="${task.href}">${task.title}</a>${task.project === null ? "" : html ` <span class="k-muted">· ${task.project}</span>`}${task.taken ? html ` <span class="k-note">Being taken</span>`
|
|
117
|
+
: computers.manage ? postForm("/queue/move", html `${select({ name: "column", sm: true, label: `Move ${task.title} to`, current: "anyone", items: [["anyone", "Shared queue"], ...others.map(other => [other.name, other.name])] })}${btn("Move", { sm: true, type: "submit" })}`, { hidden: { queueRevision: String(computers.queueRevision), task: task.id, before: "" }, attrs: { class: "k-acts" } }) : ""}</li>`)}</ul>`;
|
|
118
|
+
return joinHtml([
|
|
119
|
+
facts([
|
|
120
|
+
["Computer", one.host],
|
|
121
|
+
["Takes work from", one.projects.length > 0 ? one.projects.join(", ") : "No projects yet"],
|
|
122
|
+
["Building now", one.building.length === 0 && one.hidden === 0 ? "Nothing"
|
|
123
|
+
: joinHtml([...one.building.map(build => html `<a href="${build.href}">${build.title}</a>`), one.hidden > 0 ? plural(one.hidden, "task in a project you can't see", "tasks in projects you can't see") : ""].filter(Boolean), html `<br>`)],
|
|
124
|
+
["At a time", computers.manage ? html `${plural(one.capacity, "task", "tasks")} <span class="k-muted">· change it there with <code class="k-mono">toolroll runner capacity ${one.name} <n></code></span>` : plural(one.capacity, "task", "tasks")],
|
|
125
|
+
["Last heard", deps.ago(one.heardAt, ctx.now)],
|
|
126
|
+
["Registered", deps.ago(one.registeredAt, ctx.now)],
|
|
127
|
+
...(!computers.manage && one.note !== null ? [["Note", one.note]] : []),
|
|
128
|
+
]),
|
|
129
|
+
one.state === "offline" && !one.retired ? note(html `To bring it back, open a terminal on ${one.host}, go to the project's folder and run ${codeLine(START_BUILDER_COMMAND)}.`) : "",
|
|
130
|
+
html `<h4>Reserved for it</h4>`, reserved,
|
|
131
|
+
computers.manage && !one.retired ? postForm("/queue/note", html `<div class="kit-field"><label for="note-${one.name}">Note on its queue</label>\
|
|
132
|
+
<input class="k-input" id="note-${one.name}" name="note" maxlength="200" value="${one.note ?? ""}">\
|
|
133
|
+
<p class="kit-hint">What it is working through, for whoever looks next.</p></div>${btn("Save note", { sm: true, type: "submit" })}`, { hidden: { runner: one.name, from: "fleet" } }) : "",
|
|
134
|
+
computers.manage && !one.retired && retireHref !== null ? html `<div class="k-acts">${btn(`Retire ${one.name}`, { sm: true, href: retireHref })}</div>` : "",
|
|
135
|
+
]);
|
|
136
|
+
}
|
|
137
|
+
export function computersSections(deps, subject) {
|
|
138
|
+
return { start: startSection(deps, subject), builders: buildersSection(deps, subject) };
|
|
139
|
+
}
|
|
140
|
+
export { AREA as COMPUTERS_PATH };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export const SCRIPT_INVENTORY = Object.freeze([
|
|
2
|
+
{ id: "skills", does: "Filters skills, and packages a chosen folder's files into the import form", symbol: "skillsScript", module: "skills-ui.ts", today: "settings.skills", section: "skills", slice: "F5", fetches: false,
|
|
3
|
+
keep: "folder import works only with the script (verified with JavaScript on); paste and GitHub import work without it" },
|
|
4
|
+
{ id: "updates", does: "Polls an update in progress and shows its steps", symbol: "updatesScript", module: "toolroll-update-ui.ts", today: "settings.updates", section: "updates", slice: "S1", fetches: true,
|
|
5
|
+
keep: "an admitted /settings/updates?fragment=steps endpoint (or a retargeted poller) stays when the page retires (round 2, change 3)" },
|
|
6
|
+
{ id: "spend", does: "The monthly limit form's live amount and stop choice", symbol: "spendScript", module: "spend-ui.ts", today: "spend", section: "spend-limit", slice: "S2", fetches: false,
|
|
7
|
+
keep: "/spend joins in-place only once the form and this script are on the spend-limit change document" },
|
|
8
|
+
{ id: "openrouter-picker", does: "Searches OpenRouter's model catalog in project setup", symbol: "openRouterPickerScript", module: "openrouter-models.ts", today: "control", section: "builder", slice: "P5", fetches: false },
|
|
9
|
+
{ id: "models", does: "The models page's choices and preview", symbol: "modelsScript", module: "models-ui.ts", today: "settings.models", section: "models", slice: "F4", fetches: false },
|
|
10
|
+
{ id: "tools", does: "Saves a tool's settings as they change, and switches project", symbol: "TOOLS_PROJECT_SCRIPT", module: "tools-ui.ts", today: "settings.tools", section: "tools", slice: "P4", fetches: false,
|
|
11
|
+
keep: "kit and connect links lead to the tools change document, which owns the script (round 2, change 4)" },
|
|
12
|
+
{ id: "push", does: "Enrolls this device for alerts (a service worker and a push subscription)", symbol: "pushScriptOf", module: "settings-groups-ui.ts", today: "settings.group-alerts", section: "this-device", slice: "C1", fetches: true },
|
|
13
|
+
{ id: "hub-anchors", does: "Forwards the overview's old #anchors to their group pages", symbol: "HUB_ANCHOR_SCRIPT", module: "settings-groups-ui.ts", today: "settings.page", section: "home", slice: "D", fetches: false,
|
|
14
|
+
keep: "replaced by the retired-address resolvers once every anchor's page is an area" },
|
|
15
|
+
]);
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
const GROUP_PAGE = Object.freeze({
|
|
2
|
+
callers: Object.freeze(["cookie", "bearer"]), scope: "read", project: "session", limited: "unscoped", needsProject: false,
|
|
3
|
+
role: "any", roleBrowser: false, viewer: false, local: "allow",
|
|
4
|
+
});
|
|
5
|
+
const START_BUILDER = Object.freeze({ ...GROUP_PAGE });
|
|
6
|
+
const FLEET = Object.freeze({ ...GROUP_PAGE, limited: "deny" });
|
|
7
|
+
const MANAGE_COMPUTERS = ["full-session", "approver", "whole-installation", "not-demo"];
|
|
8
|
+
export const SETTINGS_SECTIONS = Object.freeze([
|
|
9
|
+
{ id: "appearance", area: "general", title: "Appearance", pinnedFrom: "settings.group-general", policy: GROUP_PAGE,
|
|
10
|
+
read: [], scope: {}, act: {}, changes: [], opens: false, scripts: [], oldIds: ["accent", "accent-own"] },
|
|
11
|
+
{ id: "this-browser", area: "general", title: "This browser", pinnedFrom: "settings.group-general", policy: GROUP_PAGE,
|
|
12
|
+
read: ["password-holder"], scope: {}, act: { forget: ["cookie-session"] }, changes: [], opens: false, scripts: [], oldIds: [] },
|
|
13
|
+
{ id: "your-password", area: "general", title: "Your password", pinnedFrom: "settings.group-general", policy: GROUP_PAGE,
|
|
14
|
+
read: ["password-holder"], scope: { passwordless: ["installation"] }, act: {}, changes: [], opens: false, scripts: [], oldIds: [] },
|
|
15
|
+
{ id: "version", area: "general", title: "Version", pinnedFrom: "settings.group-general", policy: GROUP_PAGE,
|
|
16
|
+
read: [], scope: { "updates-version": ["installation"], "package-version": ["operator"] }, act: { updates: ["operator"] }, changes: [], opens: false, scripts: [], oldIds: [] },
|
|
17
|
+
{ id: "advanced", area: "general", title: "Show advanced features", pinnedFrom: "settings.group-advanced", policy: GROUP_PAGE,
|
|
18
|
+
read: [], scope: { "operator-pages": ["operator"] }, act: { switch: ["cookie-session"] }, changes: [], opens: true, scripts: [], oldIds: ["show-advanced"] },
|
|
19
|
+
{ id: "local-mode", area: "general", title: "Local mode", pinnedFrom: "settings.group-access", policy: GROUP_PAGE,
|
|
20
|
+
read: ["cookie-session"], scope: {}, act: { "turn-off": ["full-session", "operator"] }, changes: [{ id: "local-mode", act: "turn-off", proof: "local-mode-off" }],
|
|
21
|
+
opens: false, scripts: [], oldIds: [] },
|
|
22
|
+
{ id: "start", area: "computers", title: "Connect a builder", pinnedFrom: "start-builder", policy: START_BUILDER,
|
|
23
|
+
read: [], scope: {}, act: { register: MANAGE_COMPUTERS }, changes: [{ id: "register-computer", act: "register", proof: "runner-register" }],
|
|
24
|
+
opens: false, scripts: [], oldIds: ["builder"] },
|
|
25
|
+
{ id: "builders", area: "computers", title: "Computers that build", pinnedFrom: "fleet", policy: FLEET,
|
|
26
|
+
read: [], scope: {}, act: { manage: MANAGE_COMPUTERS }, changes: [{ id: "retire-computer", act: "manage", proof: "runner-retire" }],
|
|
27
|
+
opens: true, scripts: [], oldIds: ["workers"] },
|
|
28
|
+
]);
|
|
29
|
+
export const CHANGE_DOCUMENTS = SETTINGS_SECTIONS.flatMap(section => section.changes.map(change => ({ ...change, section })));
|
|
30
|
+
export function changeDocumentOf(id) {
|
|
31
|
+
return CHANGE_DOCUMENTS.find(one => one.id === id);
|
|
32
|
+
}
|
|
33
|
+
export function sectionDeclaration(id) {
|
|
34
|
+
return SETTINGS_SECTIONS.find(one => one.id === id);
|
|
35
|
+
}
|
|
36
|
+
export const AREA_PATHS = Object.freeze({ general: "/settings/general", computers: "/settings/computers" });
|
|
37
|
+
export function sectionHref(declaration, options = {}) {
|
|
38
|
+
const path = AREA_PATHS[declaration.area] ?? "/settings";
|
|
39
|
+
const query = new URLSearchParams();
|
|
40
|
+
if (options.project != null)
|
|
41
|
+
query.set("repo", options.project);
|
|
42
|
+
query.set("section", declaration.id);
|
|
43
|
+
if (options.open === true)
|
|
44
|
+
query.set("open", "1");
|
|
45
|
+
for (const [key, value] of Object.entries(options.extra ?? {}))
|
|
46
|
+
query.set(key, value);
|
|
47
|
+
return `${path}?${query}`;
|
|
48
|
+
}
|
|
49
|
+
export function changeHref(document, project = null, extra = {}) {
|
|
50
|
+
const query = new URLSearchParams();
|
|
51
|
+
if (project !== null)
|
|
52
|
+
query.set("repo", project);
|
|
53
|
+
for (const [key, value] of Object.entries(extra))
|
|
54
|
+
query.set(key, value);
|
|
55
|
+
return `/settings/change/${document.id}${query.size === 0 ? "" : `?${query}`}`;
|
|
56
|
+
}
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import { ADVANCED_PAGES } from "../advanced-view.js";
|
|
2
|
+
import { accentNote, ACCENT_PRESETS } from "../accent-colors.js";
|
|
3
|
+
import { html, joinHtml, postForm } from "../html.js";
|
|
4
|
+
import { kitSectionForm } from "../settings-kit.js";
|
|
5
|
+
import { evaluateRoutePolicy, holdsRole } from "./route-policy.js";
|
|
6
|
+
import { btn, codeLine, disclose, doc, docHeader, formRow, infoLine, input, notice, phoneHeader, select, settingsLink, settingsSection } from "./kit.js";
|
|
7
|
+
import { changeDocumentOf, changeHref, sectionHref, SETTINGS_SECTIONS } from "./settings-section-table.js";
|
|
8
|
+
export function gateHolds(gate, person) {
|
|
9
|
+
switch (gate) {
|
|
10
|
+
case "installation": return person.installation && !person.restricted;
|
|
11
|
+
case "cookie-session": return person.via === "cookie";
|
|
12
|
+
case "full-session": return person.via === "cookie" && person.authority === "full";
|
|
13
|
+
case "operator": return person.via === "cookie" && person.operator;
|
|
14
|
+
case "approver": return person.role === "approver";
|
|
15
|
+
case "password-holder": return !(person.via === "cookie" && person.authority !== "full" && !person.passwordSet);
|
|
16
|
+
case "whole-installation": return !person.restricted;
|
|
17
|
+
case "not-demo": return !person.demo;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const SECTION_RESOLVERS = new Set(["none", "session", "form", "form-path"]);
|
|
21
|
+
const SECTION_LIMITED = new Set(["deny", "collection", "unscoped", "self", "conversation"]);
|
|
22
|
+
export function admitSection(declaration, person, project = null) {
|
|
23
|
+
const policy = declaration.policy;
|
|
24
|
+
if (person.via === "cookie" && person.authority !== "full" && policy.local !== "allow")
|
|
25
|
+
return { ok: false, why: "local" };
|
|
26
|
+
let why = null;
|
|
27
|
+
const projectAdmits = (source) => {
|
|
28
|
+
if (!SECTION_RESOLVERS.has(source) || !SECTION_LIMITED.has(policy.limited)) {
|
|
29
|
+
why = "project";
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
if (person.restricted && (policy.limited === "deny" || policy.limited === "conversation")) {
|
|
33
|
+
why = "limited";
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
if (person.restricted && policy.limited !== "unscoped" && policy.limited !== "self" && project === null) {
|
|
37
|
+
why = "limited";
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
if (policy.needsProject && person.via === "cookie" && project === null && !person.unscopedConsole) {
|
|
41
|
+
why = "project";
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
return true;
|
|
45
|
+
};
|
|
46
|
+
const checked = evaluateRoutePolicy(policy, person.principal, projectAdmits);
|
|
47
|
+
if (!checked.ok)
|
|
48
|
+
return { ok: false, why: checked.reason === "project" ? why ?? "project" : checked.reason };
|
|
49
|
+
if (!holdsRole(policy, person, name => name === person.name && person.operator))
|
|
50
|
+
return { ok: false, why: "role" };
|
|
51
|
+
for (const gate of declaration.read)
|
|
52
|
+
if (!gateHolds(gate, person))
|
|
53
|
+
return { ok: false, why: `read:${gate}` };
|
|
54
|
+
const scopes = new Set(Object.entries(declaration.scope).filter(([, gates]) => gates.every(gate => gateHolds(gate, person))).map(([name]) => name));
|
|
55
|
+
const can = Object.fromEntries(Object.entries(declaration.act).map(([act, gates]) => [act, gates.every(gate => gateHolds(gate, person))]));
|
|
56
|
+
return { ok: true, scopes, can };
|
|
57
|
+
}
|
|
58
|
+
export const PROJECT_NOT_AVAILABLE = "That project is not available in this workspace.";
|
|
59
|
+
export function resolveSettingsProject(url, session, deps) {
|
|
60
|
+
const named = url.searchParams.getAll("repo");
|
|
61
|
+
if (named.length > 1)
|
|
62
|
+
return { ok: false, status: 400, message: "Name one project." };
|
|
63
|
+
if (named.length === 1) {
|
|
64
|
+
const repo = named[0];
|
|
65
|
+
if (repo === "" || !deps.projects().includes(repo) || !deps.canOpen(repo))
|
|
66
|
+
return { ok: false, status: 404, message: PROJECT_NOT_AVAILABLE };
|
|
67
|
+
return { ok: true, project: repo, requested: true };
|
|
68
|
+
}
|
|
69
|
+
return { ok: true, project: session, requested: false };
|
|
70
|
+
}
|
|
71
|
+
export function sessionProjectCheck(posted, session, projectName) {
|
|
72
|
+
if (posted.length !== 1 || posted[0] === "")
|
|
73
|
+
return { ok: false, rendered: null, session, message: "This form names no project. Open the project and try again." };
|
|
74
|
+
const rendered = posted[0];
|
|
75
|
+
if (session === null || rendered !== session) {
|
|
76
|
+
return { ok: false, rendered, session, message: `${projectName(rendered)} is no longer the open project${session === null ? "" : ` (${projectName(session)} is)`}. Nothing changed.` };
|
|
77
|
+
}
|
|
78
|
+
return { ok: true, project: rendered };
|
|
79
|
+
}
|
|
80
|
+
export function openProjectAgain(rendered, name, back) {
|
|
81
|
+
return postForm("/projects/select", btn(`Open ${name}`, { sm: true, type: "submit", variant: "primary" }), { hidden: { path: rendered, return: back } });
|
|
82
|
+
}
|
|
83
|
+
export function askedSection(url) {
|
|
84
|
+
const sections = url.searchParams.getAll("section");
|
|
85
|
+
const section = sections.length === 1 && /^[a-z][a-z-]{0,39}$/.test(sections[0]) ? sections[0] : null;
|
|
86
|
+
return { section, open: section !== null && url.searchParams.getAll("open").length === 1 && url.searchParams.get("open") === "1" };
|
|
87
|
+
}
|
|
88
|
+
export function renderArea(area, impls, base, asked, declarations = SETTINGS_SECTIONS) {
|
|
89
|
+
const sections = [];
|
|
90
|
+
const shown = [];
|
|
91
|
+
let jump = html ``;
|
|
92
|
+
for (const declaration of declarations.filter(one => one.area === area)) {
|
|
93
|
+
const impl = impls[declaration.id];
|
|
94
|
+
if (impl === undefined)
|
|
95
|
+
throw new Error(`settings section ${declaration.id} has no implementation`);
|
|
96
|
+
const admitted = admitSection(declaration, base.person, base.project);
|
|
97
|
+
if (!admitted.ok)
|
|
98
|
+
continue;
|
|
99
|
+
const ctx = { ...base, scopes: admitted.scopes, can: admitted.can };
|
|
100
|
+
const summary = impl.loadSummary(ctx);
|
|
101
|
+
if (summary === null)
|
|
102
|
+
continue;
|
|
103
|
+
const isAsked = asked.section === declaration.id;
|
|
104
|
+
const detail = isAsked && asked.open && declaration.opens && impl.loadDetail !== undefined ? impl.loadDetail(ctx) : null;
|
|
105
|
+
sections.push(impl.render({ declaration, ctx, summary, detail, asked: isAsked, attrs: { "data-section": declaration.id, tabindex: isAsked ? "-1" : null } }));
|
|
106
|
+
shown.push(declaration.id);
|
|
107
|
+
if (isAsked)
|
|
108
|
+
jump = html `<p class="k-note k-jump"><a href="#${declaration.id}">Jump to ${declaration.title}</a></p>`;
|
|
109
|
+
}
|
|
110
|
+
return { sections, jump, shown };
|
|
111
|
+
}
|
|
112
|
+
export function changeDocument(id, impls, base, problem) {
|
|
113
|
+
const change = changeDocumentOf(id);
|
|
114
|
+
const declaration = change?.section;
|
|
115
|
+
const impl = declaration === undefined ? undefined : impls[declaration.id];
|
|
116
|
+
if (change === undefined || declaration === undefined || impl?.renderChange === undefined)
|
|
117
|
+
return { ok: false, status: 404, message: "There's no page at this address." };
|
|
118
|
+
const admitted = admitSection(declaration, base.person, base.project);
|
|
119
|
+
if (!admitted.ok || admitted.can[change.act] !== true)
|
|
120
|
+
return { ok: false, status: 403, message: impl.refusal ?? "You can't change this here." };
|
|
121
|
+
const ctx = { ...base, scopes: admitted.scopes, can: admitted.can };
|
|
122
|
+
const drawn = impl.renderChange({ declaration, ctx, summary: impl.loadSummary(ctx), detail: null, asked: true, attrs: {}, problem, document: change.id });
|
|
123
|
+
return { ok: true, ...drawn };
|
|
124
|
+
}
|
|
125
|
+
const ACCENT_CHOICES = ACCENT_PRESETS.slice(0, 6);
|
|
126
|
+
const back = "/settings/general";
|
|
127
|
+
function appearanceSection() {
|
|
128
|
+
return {
|
|
129
|
+
loadSummary: ctx => ctx.prefs,
|
|
130
|
+
render: ({ summary: prefs, attrs }) => {
|
|
131
|
+
const themeButton = (value, label) => html `<button type="submit" name="theme" value="${value}" aria-pressed="${String(prefs.theme === value)}">${label}</button>`;
|
|
132
|
+
const custom = ACCENT_CHOICES.some(one => one.hex === prefs.accent) ? null : prefs.accent;
|
|
133
|
+
const accentNoteWords = accentNote(prefs.accent);
|
|
134
|
+
return settingsSection({
|
|
135
|
+
id: "appearance", title: "Appearance", state: " · saved for this browser", attrs,
|
|
136
|
+
body: joinHtml([
|
|
137
|
+
formRow("Theme", "Light, dark, or whatever this device uses.", postForm("/settings/appearance", html `<div class="k-seg" role="group" aria-label="Theme">${themeButton("system", "Match device")}${themeButton("light", "Light")}${themeButton("dark", "Dark")}</div>`, { returnTo: back })),
|
|
138
|
+
kitSectionForm({ proof: "appearance", action: "/settings/appearance", id: "accent", gate: true, hidden: { return: back },
|
|
139
|
+
body: joinHtml([
|
|
140
|
+
formRow("Accent", "Buttons, focus and what needs you.", select({ name: "accent", label: "Accent", current: prefs.accent, items: [...ACCENT_CHOICES.map(one => [one.hex, one.id === "ink" ? "Ink (default)" : one.name]), ...(custom === null ? [] : [[custom, `Your own colour (${custom})`]])] })),
|
|
141
|
+
accentNoteWords === null ? "" : html `<p class="k-note">${accentNoteWords}</p>`,
|
|
142
|
+
]) }),
|
|
143
|
+
disclose("Use your own colour", kitSectionForm({ proof: "appearance", action: "/settings/appearance", id: "accent-own", gate: true, hidden: { return: back },
|
|
144
|
+
body: formRow("Your own colour", "Six hex digits, like #6e56cf.", input({ id: "accent-hex", name: "accent", value: custom ?? "", attrs: { placeholder: "#6e56cf", spellcheck: "false", autocomplete: "off", "aria-label": "Your own colour", pattern: "#?[0-9a-fA-F]{6}", required: true } })) }), custom !== null),
|
|
145
|
+
]),
|
|
146
|
+
});
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
function thisBrowserSection() {
|
|
151
|
+
return {
|
|
152
|
+
loadSummary: ctx => ({ forget: ctx.can["forget"] === true }),
|
|
153
|
+
render: ({ summary, attrs }) => settingsSection({
|
|
154
|
+
id: "this-browser", title: "This browser", attrs,
|
|
155
|
+
body: formRow("Remembered password", "After you type your password, standard approvals skip it on this computer for 15 minutes. Forget ends that now.", summary.forget ? postForm("/session/forget-password", btn("Forget now", { sm: true, type: "submit" }), { returnTo: back }) : html ``, "inline"),
|
|
156
|
+
}),
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
function yourPasswordSection(deps) {
|
|
160
|
+
return {
|
|
161
|
+
loadSummary: ctx => ({ passwordless: ctx.scopes.has("passwordless") ? deps.passwordless() : null }),
|
|
162
|
+
render: ({ summary, attrs }) => settingsSection({
|
|
163
|
+
id: "your-password", title: "Your password", attrs,
|
|
164
|
+
body: joinHtml([
|
|
165
|
+
formRow("Where it is", "If you started Toolroll with toolroll up, your password is saved on the computer running Toolroll. Toolroll never shows it in a browser. To read it, run this there:", html ``, "wide"),
|
|
166
|
+
codeLine("cat ~/.config/toolroll/.toolroll-secrets/up-login.txt"),
|
|
167
|
+
summary.passwordless === null ? "" : formRow("Passwordless", "Sign in once; most approvals then need no password.", btn(`${summary.passwordless ? "On" : "Off"} · Change`, { sm: true, href: "/settings/passwordless" }), "inline"),
|
|
168
|
+
]),
|
|
169
|
+
}),
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
function versionSection(deps) {
|
|
173
|
+
return {
|
|
174
|
+
loadSummary: ctx => {
|
|
175
|
+
const version = (ctx.scopes.has("updates-version") ? deps.updatesVersion(ctx.person.name) : null) ?? (ctx.scopes.has("package-version") ? deps.packageVersion : null);
|
|
176
|
+
return version === null ? null : { version, firstResult: deps.firstResult(ctx.now), updates: ctx.can["updates"] === true };
|
|
177
|
+
},
|
|
178
|
+
render: ({ summary, attrs }) => settingsSection({
|
|
179
|
+
id: "version", title: "Version", attrs,
|
|
180
|
+
body: joinHtml([
|
|
181
|
+
formRow("Toolroll", summary.firstResult ?? "Installed on this computer.", html `<span class="k-mono">${summary.version}</span>`, "inline"),
|
|
182
|
+
summary.updates ? formRow("Updates", null, btn("Open updates", { sm: true, variant: "ghost", href: "/settings/updates" }), "inline") : "",
|
|
183
|
+
]),
|
|
184
|
+
}),
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
function advancedSection() {
|
|
188
|
+
return {
|
|
189
|
+
loadSummary: ctx => ({ on: ctx.prefs.advanced, canSwitch: ctx.can["switch"] === true }),
|
|
190
|
+
loadDetail: ctx => ADVANCED_PAGES.filter(one => one.operator !== true || ctx.scopes.has("operator-pages")),
|
|
191
|
+
render: ({ declaration, summary, detail, attrs }) => {
|
|
192
|
+
const change = summary.canSwitch
|
|
193
|
+
? postForm("/settings/advanced", btn(summary.on ? "Turn off" : "Turn on", { sm: true, type: "submit" }), { hidden: { advanced: summary.on ? "off" : "on" } })
|
|
194
|
+
: html ``;
|
|
195
|
+
const pages = detail === null
|
|
196
|
+
? html `<div class="k-acts">${btn("See advanced pages", { sm: true, variant: "ghost", href: `${sectionHref(declaration, { open: true })}#advanced` })}</div>`
|
|
197
|
+
: html `<div class="k-slinks" aria-label="Advanced pages">${detail.map(one => settingsLink({ href: one.href, title: one.title, status: one.words }))}</div>`;
|
|
198
|
+
return settingsSection({
|
|
199
|
+
id: "advanced", title: "Show advanced features", state: summary.on ? " · on" : " · off", attrs,
|
|
200
|
+
right: html `<span id="show-advanced">${change}</span>`,
|
|
201
|
+
lead: "Flows, other computers, spend limits, operating modes and the rest, in your menus. They keep working either way.",
|
|
202
|
+
body: pages,
|
|
203
|
+
});
|
|
204
|
+
},
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
function localModeSection(deps) {
|
|
208
|
+
return {
|
|
209
|
+
loadSummary: ctx => {
|
|
210
|
+
if (!deps.localModeOn())
|
|
211
|
+
return null;
|
|
212
|
+
const owner = ctx.person.authority !== "full";
|
|
213
|
+
if (owner)
|
|
214
|
+
return ctx.person.passwordSet ? null : { owner, turnOff: false };
|
|
215
|
+
return ctx.can["turn-off"] === true ? { owner, turnOff: true } : null;
|
|
216
|
+
},
|
|
217
|
+
render: ({ declaration, summary, attrs }) => summary.owner
|
|
218
|
+
? settingsSection({ id: "local-mode", title: "Let agents work on their own", attrs,
|
|
219
|
+
lead: "Agents can work on their own, merge and release only after you set a password.",
|
|
220
|
+
body: html `<div class="k-acts">${btn("Set a password", { sm: true, href: "/password/set?next=%2Fsettings%2Fgeneral" })}</div>` })
|
|
221
|
+
: settingsSection({ id: "local-mode", title: "Local mode", state: " · on", attrs,
|
|
222
|
+
lead: "A browser on this computer can file tasks, approve plans and add projects without your password.",
|
|
223
|
+
right: btn("Turn off local mode", { sm: true, href: changeHref(declaration.changes[0]) }), body: html `` }),
|
|
224
|
+
refusal: "An instance operator signed in with a password turns off local mode.",
|
|
225
|
+
renderChange: ({ declaration, summary, problem }) => {
|
|
226
|
+
const home = sectionHref(declaration);
|
|
227
|
+
const title = "Turn off local mode";
|
|
228
|
+
const words = summary === null || !summary.turnOff
|
|
229
|
+
? html `${infoLine("Local mode is off. This computer's browser signs in with a password.")}<div class="k-acts">${btn("Back to General", { href: home })}</div>`
|
|
230
|
+
: joinHtml([
|
|
231
|
+
html `<p>Local mode lets a browser on this computer file tasks, approve plans and add projects without a password. Turned off, every browser signs in with a password, and the local owner's sessions and links stop working. You can't turn it back on here.</p>`,
|
|
232
|
+
problem === null ? "" : notice(problem),
|
|
233
|
+
kitSectionForm({ proof: "local-mode-off", action: "/settings/local-mode/off", id: "local-mode-form", native: true, save: { label: "Turn off" }, confirm: title, body: html `` }),
|
|
234
|
+
html `<div class="k-acts">${btn("Cancel", { variant: "ghost", href: home })}</div>`,
|
|
235
|
+
]);
|
|
236
|
+
return { title, body: html `<div data-kit-page>${phoneHeader(title, { back: home })}${doc(docHeader({ title, back: [home, "General"], same: true }), words)}</div>` };
|
|
237
|
+
},
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
export function generalSections(deps) {
|
|
241
|
+
return {
|
|
242
|
+
appearance: appearanceSection(),
|
|
243
|
+
"this-browser": thisBrowserSection(),
|
|
244
|
+
"your-password": yourPasswordSection(deps),
|
|
245
|
+
version: versionSection(deps),
|
|
246
|
+
advanced: advancedSection(),
|
|
247
|
+
"local-mode": localModeSection(deps),
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
export function generalBody(impls, base, asked, said) {
|
|
251
|
+
return areaBody("general", impls, base, asked, said);
|
|
252
|
+
}
|
|
253
|
+
export function areaBody(name, impls, base, asked, said) {
|
|
254
|
+
const area = renderArea(name, impls, base, asked);
|
|
255
|
+
const sentence = (text) => `${text.charAt(0).toUpperCase()}${text.slice(1)}`;
|
|
256
|
+
const answered = said.problem ? notice(sentence(said.problem)) : said.said ? infoLine(sentence(said.said)) : html ``;
|
|
257
|
+
return { body: joinHtml([answered, area.jump, ...area.sections]), shown: area.shown };
|
|
258
|
+
}
|