toolroll 0.9.107 → 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.
Files changed (105) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/README.md +4 -3
  3. package/dist/advanced-view.js +0 -1
  4. package/dist/agent-fence.js +35 -4
  5. package/dist/agent-state.js +5 -2
  6. package/dist/assignment-ui.js +5 -5
  7. package/dist/assignment.js +5 -2
  8. package/dist/browser/terminal.js +1 -1
  9. package/dist/browser/workspace.css +1 -1
  10. package/dist/browser/workspace.js +38 -33
  11. package/dist/browser-crew.js +4 -4
  12. package/dist/browser-shell.js +1 -1
  13. package/dist/browser-workspace.js +4 -11
  14. package/dist/builder.js +9 -1
  15. package/dist/chat-controls.js +6 -5
  16. package/dist/chat-decide.js +1 -1
  17. package/dist/chat-quiet.js +3 -3
  18. package/dist/chat-voice.js +2 -2
  19. package/dist/cli-help.js +17 -13
  20. package/dist/cli.js +4 -3
  21. package/dist/console-chrome.js +10 -3
  22. package/dist/contracts/cli.js +2 -0
  23. package/dist/contracts/console-api.js +5 -4
  24. package/dist/contracts/handoff.js +4 -0
  25. package/dist/decision.js +17 -0
  26. package/dist/demo-chat.js +1 -1
  27. package/dist/demo.js +6 -0
  28. package/dist/design/kit.js +4 -3
  29. package/dist/dispatch.js +3 -8
  30. package/dist/flexible-available.js +1 -0
  31. package/dist/flexible-schema.js +32 -0
  32. package/dist/flexible-thread-schema.js +30 -0
  33. package/dist/flexible-thread.js +526 -0
  34. package/dist/flexible-ui.js +44 -0
  35. package/dist/flexible.js +359 -0
  36. package/dist/folder-look.js +65 -4
  37. package/dist/git-views.js +38 -38
  38. package/dist/guides.js +14 -11
  39. package/dist/keymap.js +1 -1
  40. package/dist/lead-cli.js +2 -1
  41. package/dist/lead-context.js +1 -1
  42. package/dist/limits-ui.js +1 -1
  43. package/dist/live-bus.js +82 -12
  44. package/dist/login-secrets.js +43 -0
  45. package/dist/needs-you.js +3 -3
  46. package/dist/nightly-github.js +2 -2
  47. package/dist/operate.js +278 -21
  48. package/dist/project-admission.js +60 -29
  49. package/dist/project-delete-ui.js +2 -1
  50. package/dist/project-delete.js +1 -0
  51. package/dist/project.js +73 -0
  52. package/dist/provider-auth.js +1 -1
  53. package/dist/release.js +1 -0
  54. package/dist/repos.js +37 -0
  55. package/dist/result-actions.js +3 -0
  56. package/dist/result-evidence-readers.js +8 -2
  57. package/dist/result-review.js +20 -9
  58. package/dist/route-hooks.js +1 -0
  59. package/dist/sample-project.js +167 -9
  60. package/dist/scope.js +17 -2
  61. package/dist/serve.js +47 -32
  62. package/dist/server/chat.js +9 -9
  63. package/dist/server/chrome.js +16 -16
  64. package/dist/server/guards.js +10 -4
  65. package/dist/server/home.js +37 -5
  66. package/dist/server/http.js +4 -2
  67. package/dist/server/in-place.js +5 -4
  68. package/dist/server/kit.js +2 -2
  69. package/dist/server/live.js +103 -10
  70. package/dist/server/login-help.js +67 -0
  71. package/dist/server/pages.js +258 -78
  72. package/dist/server/people-tokens.js +36 -24
  73. package/dist/server/render-chat.js +1 -1
  74. package/dist/server/render-history.js +18 -4
  75. package/dist/server/render-new-task.js +2 -2
  76. package/dist/server/render-pages.js +21 -39
  77. package/dist/server/render-people.js +16 -4
  78. package/dist/server/render-projects.js +63 -15
  79. package/dist/server/render-results.js +26 -10
  80. package/dist/server/render-tasks.js +26 -17
  81. package/dist/server/retired-routes.js +37 -4
  82. package/dist/server/route-policy.js +8 -0
  83. package/dist/server/route-table.js +15 -5
  84. package/dist/server/settings-computers.js +140 -0
  85. package/dist/server/settings-scripts.js +15 -0
  86. package/dist/server/settings-section-table.js +56 -0
  87. package/dist/server/settings-sections.js +258 -0
  88. package/dist/server/settings.js +167 -19
  89. package/dist/server/task-views.js +47 -13
  90. package/dist/server/tasks.js +143 -90
  91. package/dist/server/welcome.js +35 -23
  92. package/dist/settings-groups-ui.js +34 -106
  93. package/dist/settings-proofs.js +5 -2
  94. package/dist/sqlite-telemetry.js +70 -21
  95. package/dist/store.js +141 -9
  96. package/dist/surface.js +4 -1
  97. package/dist/task-link.js +64 -0
  98. package/dist/task-outcome-cli.js +99 -4
  99. package/dist/tui-source.js +11 -3
  100. package/dist/tui.js +39 -39
  101. package/dist/typed-words-schema.js +18 -0
  102. package/dist/welcome-facts.js +15 -7
  103. package/dist/work-index.js +126 -29
  104. package/dist/work-reads.js +279 -0
  105. package/package.json +4 -2
@@ -4,27 +4,29 @@ 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 { admitProject } from "../project-admission.js";
8
- import { authorizedProject } from "../project.js";
9
- import { createSampleProject, registerSampleCheck } from "../sample-project.js";
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}`;
22
24
  const AGENT_WORDS = { "signed-in": "Signed in", "signed-out": "Not signed in", "not-installed": "Not installed", checking: "Checking…" };
23
25
  const PROJECTS_SHOWN = 3;
24
26
  const ADD_FOLDER = "/projects?return=%2Fwelcome";
25
- function step(key, index, title, done, body) {
27
+ function step(key, index, title, done, body, filed = false) {
26
28
  return html `<section class="k-sec welcome-step" id="welcome-${key}" data-step="${key}" data-done="${done ? "1" : "0"}" aria-labelledby="welcome-${key}-h">\
27
- <div class="k-secthead"><h3 id="welcome-${key}-h">${index}. ${title}</h3>${done ? chip("Done", "done") : ""}</div>${body}</section>`;
29
+ <div class="k-secthead"><h3 id="welcome-${key}-h">${index}. ${title}</h3>${filed ? chip("Filed", "", { dot: false }) : done ? chip("Done", "done") : ""}</div>${body}</section>`;
28
30
  }
29
31
  const useForm = (agent, button) => postForm("/settings/lead/on", button, { hidden: { agent, return: "/welcome" } });
30
32
  function agentRow(agent, leads) {
@@ -73,13 +75,14 @@ ${listed.length === 0 ? "" : html `<div class="welcome-rows">${listed}</div>`}${
73
75
  const taskLeads = lead === "task";
74
76
  if (taskLeads)
75
77
  primary = btn("Write a task", { variant: "primary", href: "/tasks/new" });
76
- const taskBody = model.task.done ? !model.agent.done && !model.agent.checking ? html `<p class="k-note">Filed. It starts by itself once an agent is signed in (step 1).</p>`
77
- : html `<p class="k-note">Filed. Its plan waits for your approval in <a class="k-link" href="/tasks">Tasks</a>.</p>`
78
+ const waitsForAgent = model.task.done && !model.agent.done && !model.agent.checking;
79
+ const taskBody = model.task.done ? waitsForAgent ? html `<p class="k-note">It starts by itself once an agent is signed in (step 1).</p>`
80
+ : html `<p class="k-note">Filed. Its plan waits for your approval in <a class="k-link" href="/">Work</a>.</p>`
78
81
  : !model.task.open ? html `<p class="k-note">Add a project first.</p>`
79
82
  : html `<p class="k-note">Describe a change in a sentence or two. Nothing starts until you approve its plan.</p>\
80
83
  ${model.task.starters.length === 0 ? "" : html `<div class="k-ideas" aria-label="Ideas to start from" data-starters>${model.task.starters.map(one => html `<a class="k-btn k-btn-outline k-idea" href="${one.href}">${one.label}</a>`)}</div>`}\
81
84
  <div class="k-acts">${btn("Write a task", { sm: true, href: "/tasks/new", ...(taskLeads ? { variant: "primary", docked: true } : {}) })}</div>`;
82
- const task = step("task", 3, "First task", model.task.done, taskBody);
85
+ const task = step("task", 3, "First task", model.task.done, taskBody, waitsForAgent);
83
86
  const hello = html `<div class="k-hello"><h2>Get to your first result.</h2><p>${model.left === 0 ? "Setup is done." : `${plural(model.left, "step", "steps")} left.`}</p></div>`;
84
87
  return { body: html `${hello}${agent}${project}${task}`, primary };
85
88
  }
@@ -118,27 +121,36 @@ export function createWelcomeHandlers(runtime) {
118
121
  return sendScreen(response, 200, welcomePage(chrome, model, { problem: isSampleProblem(asked) ? asked : null, canAdd: approver && !store.isDemo() }));
119
122
  }
120
123
  async function addSample(ctx) {
121
- const { who, response, now, posted } = ctx;
124
+ const { who, response, now, posted, request } = ctx;
122
125
  readForm(posted, CONSOLE_FORMS.welcomeSample);
123
126
  if (who.via !== "cookie")
124
127
  return refuse(response, who, 403, "adding a project is a browser session's act");
125
128
  if (store.isDemo())
126
129
  return refuse(response, who, 403, "the sandbox never makes projects");
127
130
  const back = (problem) => redirect(response, `/welcome?sample=${problem}#welcome-project`);
128
- const made = await createSampleProject(liveCeiling().roots[0] ?? null);
129
- if (!made.ok)
130
- return back(made.reason);
131
- const decidedOn = identities.generation();
132
- const canonical = await identities.resolveNow(made.path);
133
- if (canonical === null || canonical === "no-answer" || !(await authorizedProject(liveCeiling(), canonical)) || !visible(canonical))
134
- return back("not-added");
135
- const stillAllowed = (repo) => identities.generation() === decidedOn && visible(repo);
136
- const admitted = await admitProject(store, { registryFile: options.registryPath ?? null, path: canonical, actor: { label: who.name, origin: "console" }, now, stillAllowed, resolveFolder: identities.resolveNow });
137
- if (!admitted.ok || !stillAllowed(admitted.repo))
138
- return back("not-added");
139
- registerSampleCheck(store, made, admitted.repo, who.name, now);
140
- deletedRepos.delete(admitted.repo);
141
- who.session.project = admitted.repo;
131
+ const stands = () => { const again = rereadBrowser(runtime, request, who); return again !== null && again.role === "approver" && !store.isDemo(); };
132
+ const registryPath = options.registryPath ?? null;
133
+ const registryBacked = registryPath !== null && options.admittedRepos !== undefined;
134
+ const ceiling = (registry) => {
135
+ const live = liveCeiling();
136
+ if (!registryBacked)
137
+ return live;
138
+ const read = registry ?? readProjectRegistryNow(registryPath);
139
+ const current = "error" in read ? [] : resolveCeiling([], read.roots).ceiling.roots;
140
+ return { ...live, roots: live.roots.filter(root => current.includes(root)) };
141
+ };
142
+ const added = await addSampleProject({
143
+ store, registryFile: registryPath, ceiling, now, visible,
144
+ authority: { actor: { label: who.name, origin: "console" }, stands },
145
+ resolveFolder: identities.resolveNow, generation: () => identities.generation(),
146
+ });
147
+ if (!added.ok) {
148
+ if (added.reason === "refused")
149
+ return refuse(response, who, 403, "your access changed while the sample was being added");
150
+ return back(added.reason);
151
+ }
152
+ deletedRepos.delete(added.repo);
153
+ who.session.project = added.repo;
142
154
  who.session.projectRevision++;
143
155
  sessions.persist(who.session);
144
156
  return redirect(response, "/welcome");
@@ -1,4 +1,3 @@
1
- import { ACCENT_PRESETS, accentNote } from "./accent-colors.js";
2
1
  import {} from "./browser-workspace.js";
3
2
  import { SETTINGS_GROUP_ICONS, SETTINGS_GROUPS, plural } from "./design/kit.js";
4
3
  import { digestTimes } from "./digest-times.js";
@@ -8,11 +7,11 @@ import {} from "./scope.js";
8
7
  import { qualityModeTitle } from "./quality.js";
9
8
  import {} from "./store.js";
10
9
  import { kitSectionForm, SECRET_OPT_OUTS } from "./settings-kit.js";
11
- import { ADVANCED_PAGES } from "./advanced-view.js";
10
+ import { START_BUILDER_HREF } from "./needs-you.js";
12
11
  import { btn, chip, codeLine, disclose, formRow, infoLine, input, needsPanel, note, notice, radios, select, settingsLink, settingsLinks, settingsRecord, settingsSection, settingsShell, switchInput, } from "./server/kit.js";
13
12
  export const GROUP_PATHS = {
14
- "/settings": "hub", "/settings/general": "general", "/settings/agents": "agents", "/settings/alerts": "alerts",
15
- "/settings/projects": "projects", "/settings/access": "access", "/settings/system": "system", "/settings/advanced": "advanced",
13
+ "/settings": "hub", "/settings/agents": "agents", "/settings/alerts": "alerts",
14
+ "/settings/projects": "projects", "/settings/access": "access", "/settings/system": "system",
16
15
  };
17
16
  const CHAT_APPS = [["telegram", "Telegram"], ["slack", "Slack"], ["discord", "Discord"], ["teams", "Teams"]];
18
17
  const and = (names) => names.length > 1 ? `${names.slice(0, -1).join(", ")} and ${names.at(-1)}` : names[0] ?? "";
@@ -23,8 +22,8 @@ const answered = (facts) => facts.problem ? notice(sentence(facts.problem)) : fa
23
22
  export function settingsNeeds(facts) {
24
23
  const out = [];
25
24
  if (facts.workers !== null && facts.approver && !facts.workers.some(one => one.tone === "ok")) {
26
- out.push({ group: "agents", title: facts.workers.length === 0 ? "Nothing is taking work" : "Nothing is taking work right now",
27
- text: "Approved work waits until a computer builds it. Run toolroll up on the computer with your projects.", action: ["Start taking work", "/settings/agents#workers"] });
25
+ out.push({ group: "computers", title: facts.workers.length === 0 ? "Nothing is taking work" : "Nothing is taking work right now",
26
+ text: "Approved work waits until a computer builds it. Run toolroll up on the computer with your projects.", action: ["Start taking work", START_BUILDER_HREF] });
28
27
  }
29
28
  if (facts.telegram.failing)
30
29
  out.push({ group: "alerts", title: "Telegram isn’t delivering", text: facts.telegram.delivery ?? "Alerts to your phone are failing.", action: ["Open Telegram", "/settings/telegram"] });
@@ -38,13 +37,17 @@ export function needsByGroup(items) {
38
37
  out[item.group] = (out[item.group] ?? 0) + 1;
39
38
  return out;
40
39
  }
41
- const flagsOf = (counts) => Object.fromEntries(Object.keys(counts).map(key => [key, true]));
40
+ export const flagsOf = (counts) => Object.fromEntries(Object.keys(counts).map(key => [key, true]));
42
41
  const themeWords = (theme) => theme === "light" ? "Light" : theme === "dark" ? "Dark" : "Match this device";
43
42
  function agentsWords(facts) {
44
43
  const signed = facts.providers?.find(one => one.connection !== null && one.tone === "ok") ?? facts.providers?.find(one => one.tone === "ok");
45
- const builders = facts.workers === null ? null : facts.workers.filter(one => one.tone === "ok").length;
46
- return [signed ? `${signed.name}: ${signed.words}` : facts.providers === null ? "Models, chat and tools" : "No agent signed in yet",
47
- builders === null ? null : builders === 0 ? "not taking work yet" : "taking work"].filter(Boolean).join(" · ");
44
+ return signed ? `${signed.name}: ${signed.words}` : facts.providers === null ? "Models, chat and tools" : "No agent signed in yet";
45
+ }
46
+ function computersWords(facts) {
47
+ if (facts.workers === null)
48
+ return "Connect a builder: the computer that does the work";
49
+ const taking = facts.workers.filter(one => one.tone === "ok").length;
50
+ return taking === 0 ? "Nothing is taking work yet" : `${plural(taking, "computer", "computers")} taking work`;
48
51
  }
49
52
  function alertsWords(facts) {
50
53
  const configured = facts.messaging?.configured ?? [];
@@ -71,26 +74,19 @@ function systemWords(facts) {
71
74
  }
72
75
  function localModeSection(facts) {
73
76
  const local = facts.local;
74
- if (local === undefined || local === null)
75
- return html ``;
76
- if (local.owner) {
77
- return local.passwordSet ? html `` : settingsSection({ id: "set-password", title: "Let agents work on their own",
78
- lead: "Agents can work on their own, merge and release only after you set a password.",
79
- body: html `<div class="k-acts">${btn("Set a password", { sm: true, href: "/password/set?next=%2Fsettings" })}</div>` });
80
- }
81
- if (!local.canTurnOff)
77
+ if (local === undefined || local === null || !local.owner || local.passwordSet)
82
78
  return html ``;
83
- return settingsSection({ id: "local-mode", title: "Local mode", state: " · on",
84
- lead: "A browser on this computer can file tasks, approve plans and add projects without your password.",
85
- body: kitSectionForm({ proof: "local-mode-off", action: "/settings/local-mode/off", id: "local-mode-form", save: { label: "Turn off", variant: "outline" },
86
- confirm: "Turn off local mode", body: html `` }) });
79
+ return settingsSection({ id: "set-password", title: "Let agents work on their own",
80
+ lead: "Agents can work on their own, merge and release only after you set a password.",
81
+ body: html `<div class="k-acts">${btn("Set a password", { sm: true, href: "/password/set?next=%2Fsettings" })}</div>` });
87
82
  }
88
83
  export function settingsHub(facts) {
89
84
  const items = settingsNeeds(facts);
90
85
  const counts = needsByGroup(items);
91
86
  const words = {
92
- general: [`Theme: ${themeWords(facts.theme).toLowerCase()}`, facts.version === null ? null : `Toolroll ${facts.version}`].filter(Boolean).join(" · "),
87
+ general: [`Theme: ${themeWords(facts.theme).toLowerCase()}`, facts.version === null ? null : `Toolroll ${facts.version}`, `advanced features ${advancedOn(facts) ? "on" : "off"}`].filter(Boolean).join(" · "),
93
88
  agents: agentsWords(facts),
89
+ computers: computersWords(facts),
94
90
  alerts: alertsWords(facts),
95
91
  approval: approvalWords(facts),
96
92
  projects: facts.projects.length === 0 ? "No projects yet" : `${plural(facts.projects.length, "project", "projects")} · network, checks, pull requests and tools for each`,
@@ -100,7 +96,6 @@ export function settingsHub(facts) {
100
96
  };
101
97
  const shown = SETTINGS_GROUPS.filter(([, slug]) => slug !== "spend" || facts.operator).filter(([, slug]) => slug !== "system" || facts.operator || facts.approver)
102
98
  .filter(([, slug]) => slug !== "spend" || advancedOn(facts));
103
- words["advanced"] = advancedWords(facts);
104
99
  const panel = needsPanel(items.map((item, index) => ({ title: item.title, text: item.text, action: btn(item.action[0], { variant: index === 0 ? "primary" : "outline", href: item.action[1] }) })));
105
100
  return settingsShell({
106
101
  group: "hub", title: "Settings", flags: flagsOf(counts),
@@ -113,53 +108,11 @@ export function settingsHub(facts) {
113
108
  });
114
109
  }
115
110
  export const HUB_ANCHORS = {
116
- providers: "/settings/agents#providers", workers: "/settings/agents#workers", email: "/settings/alerts#email", "settings-chat-apps": "/settings/alerts#chat-apps",
111
+ providers: "/settings/agents#providers", workers: "/settings/computers#workers", email: "/settings/alerts#email", "settings-chat-apps": "/settings/alerts#chat-apps",
117
112
  "telegram-token": "/settings/alerts#telegram-token", phone: "/settings/alerts#phone", notifications: "/settings/alerts#notifications",
118
113
  updates: "/settings/system#updates", accent: "/settings/general#appearance", appearance: "/settings/general#appearance",
119
114
  };
120
115
  export const HUB_ANCHOR_SCRIPT = `(function(){var m=${JSON.stringify(HUB_ANCHORS)};var h=decodeURIComponent(location.hash.slice(1));if(Object.prototype.hasOwnProperty.call(m,h))location.replace(m[h]);})();`;
121
- const ACCENT_CHOICES = ACCENT_PRESETS.slice(0, 6);
122
- export function generalGroup(facts, flags) {
123
- const themeButton = (value, label) => html `<button type="submit" name="theme" value="${value}" aria-pressed="${String(facts.theme === value)}">${label}</button>`;
124
- const custom = ACCENT_CHOICES.some(one => one.hex === facts.accent) ? null : facts.accent;
125
- const accentNoteWords = accentNote(facts.accent);
126
- const appearance = settingsSection({
127
- id: "appearance", title: "Appearance", state: " · saved for this browser",
128
- body: joinHtml([
129
- 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: "/settings/general" })),
130
- kitSectionForm({ proof: "appearance", action: "/settings/appearance", id: "accent", gate: true, hidden: { return: "/settings/general" },
131
- body: joinHtml([
132
- formRow("Accent", "Buttons, focus and what needs you.", select({ name: "accent", label: "Accent", current: facts.accent, items: [...ACCENT_CHOICES.map(one => [one.hex, one.id === "ink" ? "Ink (default)" : one.name]), ...(custom === null ? [] : [[custom, `Your own colour (${custom})`]])] })),
133
- accentNoteWords === null ? "" : note(accentNoteWords),
134
- ]) }),
135
- disclose("Use your own colour", kitSectionForm({ proof: "appearance", action: "/settings/appearance", id: "accent-own", gate: true, hidden: { return: "/settings/general" },
136
- 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),
137
- ]),
138
- });
139
- const browser = settingsSection({
140
- id: "this-browser", title: "This browser",
141
- body: joinHtml([
142
- formRow("Remembered password", "After you type your password, standard approvals skip it on this computer for 15 minutes. Forget ends that now.", facts.browser ? postForm("/session/forget-password", btn("Forget now", { sm: true, type: "submit" }), { returnTo: "/settings/general" }) : html ``, "inline"),
143
- ]),
144
- });
145
- const password = settingsSection({
146
- id: "your-password", title: "Your password",
147
- body: joinHtml([
148
- 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"),
149
- codeLine("cat ~/.config/toolroll/.toolroll-secrets/up-login.txt"),
150
- facts.passwordless === null ? "" : formRow("Passwordless", "Sign in once; most approvals then need no password.", btn(`${facts.passwordless ? "On" : "Off"} · Change`, { sm: true, href: "/settings/passwordless" }), "inline"),
151
- ]),
152
- });
153
- const version = facts.version === null ? "" : settingsSection({
154
- id: "version", title: "Version",
155
- body: joinHtml([
156
- formRow("Toolroll", facts.firstResult ?? "Installed on this computer.", html `<span class="k-mono">${facts.version}</span>`, "inline"),
157
- facts.operator ? formRow("Updates", null, btn("Open updates", { sm: true, variant: "ghost", href: "/settings/updates" }), "inline") : "",
158
- ]),
159
- });
160
- const withPassword = passwordFree(facts) ? [] : [browser, password];
161
- return settingsShell({ group: "general", title: "General", lead: "How Toolroll looks and behaves in this browser.", flags, body: joinHtml([answered(facts), appearance, ...withPassword, version]) });
162
- }
163
116
  const toneChip = (tone, words) => chip(words, tone === "ok" ? "done" : tone === "warn" ? "failed" : "");
164
117
  function providerRecord(one) {
165
118
  const form = kitSectionForm({ proof: "provider-key", action: "/settings/provider-key", id: `provider-${one.provider}`, gate: true, hidden: { provider: one.provider }, save: { label: `Save ${one.name}` },
@@ -173,21 +126,6 @@ function providerRecord(one) {
173
126
  return settingsRecord({ title: html `${one.name} ${toneChip(one.tone, one.words)}`, sub: one.connection === null ? one.usage : `${one.connection.words}${one.connection.facts ? ` · ${one.connection.facts}` : ""}`,
174
127
  attrs: { "data-provider": one.provider }, more: disclose(`Manage ${one.name}`, joinHtml([form, remove])) });
175
128
  }
176
- function workersSection(workers) {
177
- return settingsSection({
178
- id: "workers", title: "Builders", lead: "The computers that build approved work, and what each runs now.",
179
- body: workers.length === 0
180
- ? joinHtml([note("No builder is connected. Run this on the computer with your projects:"), codeLine("toolroll up")])
181
- : joinHtml([
182
- ...workers.map(one => settingsRecord({
183
- title: html `<span class="k-mono">${one.name}</span> ${chip(one.state, one.tone === "ok" ? "done" : one.tone === "off" ? "failed" : "")}`,
184
- sub: one.running.length === 0 ? "Nothing running" : joinHtml(one.running.map(task => html `<a class="k-link" href="${task.href}">${task.title}</a>${task.project === null ? "" : html ` <span class="k-muted">${task.project}</span>`}`), " · "),
185
- when: html `<span class="k-num">${one.busy} of ${one.capacity}</span> running`, attrs: { "data-worker": one.name },
186
- })),
187
- note(html `To change how many a builder runs at once: <code class="k-mono">toolroll runner capacity &lt;name&gt; &lt;n&gt;</code>`),
188
- ]),
189
- });
190
- }
191
129
  export function agentsGroup(facts, flags) {
192
130
  const providers = facts.providers === null ? "" : settingsSection({
193
131
  id: "providers", title: "How agents are paid for", lead: "A plan first; an API key is used when the agent is set to it, or for agents without a plan. Keys stay on this computer.",
@@ -204,7 +142,7 @@ export function agentsGroup(facts, flags) {
204
142
  ]);
205
143
  return settingsShell({
206
144
  group: "agents", title: "Agents and models", lead: "Which agent does the work, how it’s paid for, and which model plans, builds and reviews.", flags,
207
- body: joinHtml([answered(facts), providers, facts.workers === null ? "" : workersSection(facts.workers), links]),
145
+ body: joinHtml([answered(facts), providers, facts.workers === null ? "" : html `<div id="workers">${settingsLinks(null, [settingsLink({ href: "/settings/computers?section=builders", title: "Computers that build", status: "In Settings → Computers" })], { label: "Computers" })}</div>`, links]),
208
146
  });
209
147
  }
210
148
  function chatAppsSection(facts) {
@@ -234,7 +172,7 @@ function reachSection(facts) {
234
172
  const projects = (chat.projects ?? []).length === 0 ? "" : joinHtml([
235
173
  ...chat.projects.map(one => kitSectionForm({ proof: "notifications-mute", action: "/settings/notifications/mute", id: `mute-${one.repo.replace(/[^a-z0-9]+/gi, "-")}`, gate: true, hidden: { repo: one.repo },
236
174
  body: formRow(one.name, one.muted ? "Muted: no pings" : "Pings on", switchInput({ id: `pings-${one.repo.replace(/[^a-z0-9]+/gi, "-")}`, name: "pings", label: "Pings", on: !one.muted, attrs: { "aria-label": `Pings for ${one.name}` } }), "inline") })),
237
- note("Muted projects still show in Tasks and the evening digest."),
175
+ note("Muted projects still show in Work and the evening digest."),
238
176
  ]);
239
177
  return settingsSection({ id: "notifications", title: "What reaches you", body: joinHtml([form, projects]) });
240
178
  }
@@ -402,13 +340,22 @@ export function projectsGroup(facts, flags) {
402
340
  ]);
403
341
  return settingsShell({
404
342
  group: "projects", title: "Projects", lead: "Each project has its own network, writes, checks, pull requests and tools.", flags,
405
- body: joinHtml([answered(facts),
343
+ body: joinHtml([answered(facts), projectsFolderSection(facts.projectsFolder ?? null),
406
344
  facts.projects.length === 0
407
345
  ? settingsSection({ id: "projects", title: "Projects", body: note(html `No projects yet. <a class="k-link" href="/projects">Add one on Projects</a>.`) })
408
346
  : settingsLinks("Projects", rows),
409
347
  per]),
410
348
  });
411
349
  }
350
+ function projectsFolderSection(view) {
351
+ if (view === null || view.folders.length === 0)
352
+ return html ``;
353
+ return settingsSection({
354
+ id: "projects-folder", title: view.folders.length === 1 ? "Projects folder" : "Projects folders",
355
+ lead: "Toolroll can add any git repository inside it.",
356
+ body: joinHtml(view.folders.map(one => formRow("Folder", null, html `<span class="k-mono">${one.shown}</span>`, "inline"))),
357
+ });
358
+ }
412
359
  export function accessGroup(facts, flags) {
413
360
  const people = facts.people;
414
361
  const links = [
@@ -420,9 +367,10 @@ export function accessGroup(facts, flags) {
420
367
  ...(facts.operator && (advancedOn(facts) || facts.passwordless === true) ? [
421
368
  settingsLink({ href: "/settings/passwordless", title: "Passwordless", status: facts.passwordless ? "On: signing in is the only password" : "Off: approvals ask for your password" })
422
369
  ] : []),
370
+ ...(facts.local?.canTurnOff === true ? [html `<div id="local-mode">${settingsLink({ href: "/settings/general?section=local-mode", title: "Local mode", status: "On · in General" })}</div>`] : []),
423
371
  ];
424
372
  return settingsShell({ group: "access", title: "People and sign-in", lead: "Who can get in, how they sign in, and the ways in they hold.", flags,
425
- body: joinHtml([answered(facts), localModeSection(facts), settingsLinks(null, links, { label: "People and sign-in" })]) });
373
+ body: joinHtml([answered(facts), settingsLinks(null, links, { label: "People and sign-in" })]) });
426
374
  }
427
375
  function updatesSection(updates) {
428
376
  const latest = updates.latest;
@@ -449,10 +397,8 @@ export function systemGroup(facts, flags) {
449
397
  ...(advancedOn(facts) ? [settingsLink({ href: "/settings/monitoring", title: "Monitoring", status: "Send the audit stream and traces to your own systems" })] : []),
450
398
  settingsLink({ href: "/settings/data", title: "Data export", status: "Everything except secrets, as one download" }),
451
399
  settingsLink({ href: "/settings/integrations", title: "Integrations", status: "Which connected services work" }),
452
- ...(advancedOn(facts) ? [settingsLink({ href: "/fleet", title: "Builders", status: "Every computer that builds, on Agents" })] : []),
453
400
  ]) : settingsLinks("In this group", [
454
401
  settingsLink({ href: "/settings/integrations", title: "Integrations", status: "Which connected services work" }),
455
- ...(advancedOn(facts) ? [settingsLink({ href: "/fleet", title: "Builders", status: "Every computer that builds" })] : []),
456
402
  ]);
457
403
  return settingsShell({ group: "system", title: "System", lead: "This Toolroll’s version, backups, storage and what leaves this computer.", flags,
458
404
  body: joinHtml([answered(facts), facts.updates === null ? "" : updatesSection(facts.updates), links]) });
@@ -461,13 +407,11 @@ export function settingsGroupPage(group, facts) {
461
407
  const flags = flagsOf(needsByGroup(settingsNeeds(facts)));
462
408
  switch (group) {
463
409
  case "hub": return settingsHub(facts);
464
- case "general": return generalGroup(facts, flags);
465
410
  case "agents": return agentsGroup(facts, flags);
466
411
  case "alerts": return alertsGroup(facts, flags);
467
412
  case "projects": return projectsGroup(facts, flags);
468
413
  case "access": return accessGroup(facts, flags);
469
414
  case "system": return systemGroup(facts, flags);
470
- case "advanced": return advancedGroup(facts, flags);
471
415
  case "approval": return settingsHub(facts);
472
416
  }
473
417
  }
@@ -607,19 +551,3 @@ function passwordFree(facts) {
607
551
  return facts.local?.owner === true && !facts.local.passwordSet;
608
552
  }
609
553
  function advancedOn(facts) { return facts.advanced === undefined || facts.advanced.on; }
610
- function advancedWords(facts) {
611
- return advancedOn(facts) ? "On: every page shows in the menus" : "Off: menus show only the main steps";
612
- }
613
- export function advancedGroup(facts, flags) {
614
- const on = advancedOn(facts);
615
- const change = facts.advanced?.canChange === true
616
- ? postForm("/settings/advanced", btn(on ? "Turn off" : "Turn on", { sm: true, type: "submit" }), { hidden: { advanced: on ? "off" : "on" } })
617
- : html ``;
618
- const toggle = settingsSection({ id: "show-advanced", title: "Show advanced features", state: on ? " · on" : " · off", right: change,
619
- lead: "Flows, other computers, spend limits, operating modes and the rest, in your menus. They keep working either way, and each opens from below.",
620
- body: html `` });
621
- const pages = ADVANCED_PAGES.filter(one => one.operator !== true || facts.operator)
622
- .map(one => settingsLink({ href: one.href, title: one.title, status: one.words }));
623
- return settingsShell({ group: "advanced", title: "Advanced", lead: "Everything beyond filing, approving and accepting work.", flags,
624
- body: joinHtml([answered(facts), toggle, settingsLinks("Advanced pages", pages)]) });
625
- }
@@ -50,12 +50,14 @@ export const PROOF_INVENTORY = [
50
50
  { id: "people-close", action: "Cancel an invite or remove a person", routes: ["/people/invite-revoke", "/people/revoke"], form: "peopleRevoke", field: "token", proof: "step-up", ...ACCEPT, role: "any", handlerRole: "an approver", secrets: [], terms: [] },
51
51
  { id: "project-setup", action: "Approve project setup", routes: ["/control/setup-approve"], form: "projectSetup", field: "token", proof: "step-up", ...ACCEPT, role: "any", handlerRole: "an approver of the project; models for a new installation need an instance operator", secrets: [], terms: ["repo", "nonce", "fingerprint", "provider", "model", "command", "seconds"], note: "the nonce is spent before the password is checked: after a refusal, review again; the reviewed inputs are previewed again and must match the fingerprint" },
52
52
  { id: "project-instructions", action: "Add the agent instructions", routes: ["/control/instructions-approve"], form: "projectSetup", field: "token", proof: "step-up", ...ACCEPT, role: "any", handlerRole: "an approver of the project", secrets: [], terms: ["repo", "nonce", "fingerprint"], note: "the nonce is spent before the password is checked" },
53
+ { id: "runner-retire", action: "Retire a computer that builds", routes: ["/fleet/runner/retire"], form: "runnerRetire", field: "token", proof: "step-up", ...ACCEPT, role: "any", handlerRole: "an approver, from a browser", secrets: [], terms: ["name"] },
53
54
  { id: "local-mode-off", action: "Turn off local mode", routes: ["/settings/local-mode/off"], form: "localModeOff", field: "password", proof: "step-up", ...ACCEPT, role: "operator", handlerRole: "a full session (never the local owner)", secrets: [], terms: [] },
54
55
  { id: "mode-sign", action: "Sign an operating mode", routes: ["/mode/sign"], form: "mode", field: "token", proof: "step-up", ...ACCEPT, role: "any", handlerRole: "an approver of the project", secrets: [], terms: MODE_TERMS },
55
56
  { id: "mode-sign-chat-approve", action: "Sign an operating mode that lets your chat app approve", routes: ["/mode/sign"], select: { field: "chat-approve", value: "1" }, form: "mode", field: "token", proof: "credential", ...CREDENTIAL, role: "any", handlerRole: "an approver of the project", secrets: [], terms: MODE_TERMS },
56
57
  { id: "mode-sign-repair", action: "Sign an operating mode that repairs failed checks by itself", routes: ["/mode/sign"], select: { field: "repair-auto", value: "1" }, form: "mode", field: "token", proof: "credential", ...CREDENTIAL, role: "any", handlerRole: "an approver of the project", secrets: [], terms: MODE_TERMS },
57
58
  { id: "passwordless-on", action: "Turn Passwordless on", routes: ["/settings/passwordless"], form: "passwordless", field: "password", proof: "credential", when: "only to turn it on (off needs nothing)", ...CREDENTIAL, role: "operator", secrets: [], terms: [] },
58
59
  { id: "sign-in", action: "Change sign-in (SSO)", routes: ["/settings/sign-in"], form: "signIn", field: "password", proof: "credential", when: "every action except Test", ...CREDENTIAL, role: "operator", secrets: ["client-secret"], terms: [] },
60
+ { id: "project-flexible", action: "Turn on Flexible", routes: ["/settings/project/flexible"], form: "projectFlexible", field: "password", proof: "credential", when: "only to turn it on (lowering and turning off need nothing)", ...CREDENTIAL, role: "approver", handlerRole: "an approver of the project", secrets: [], terms: ["repo", "action", "digest"], note: "`digest` is the terms the page showed; the handler rebuilds them and refuses a difference" },
59
61
  { id: "release-approval", action: "Approve releases automatically", routes: ["/settings/release-approval"], form: "releaseApproval", field: "password", proof: "credential", when: "only to approve automatically (Ask me needs nothing)", ...CREDENTIAL, role: "approver", handlerRole: "an approver of the project", secrets: [], terms: ["repo"] },
60
62
  { id: "project-network", action: "Change what builds may reach", routes: ["/settings/project/network"], form: "projectNetwork", field: "password", proof: "credential", ...CREDENTIAL, role: "any", handlerRole: "an approver of the project", secrets: [], terms: ["repo"] },
61
63
  { id: "project-fallback", action: "Change a project's fallback agents", routes: ["/settings/project/fallback"], form: "projectFallback", field: "password", proof: "credential", ...CREDENTIAL, role: "any", handlerRole: "an approver of the project", secrets: [], terms: [] },
@@ -64,8 +66,9 @@ export const PROOF_INVENTORY = [
64
66
  { id: "project-check-access", action: "Narrow how far checks reach", routes: ["/settings/project/check-access"], form: "projectCheckAccess", field: "password", proof: "credential", ...CREDENTIAL, role: "any", handlerRole: "an approver of the project", secrets: [], terms: ["repo"], note: "for a form that can only narrow; one that offers a wider level uses project-check-access-widen" },
65
67
  { id: "project-check-access-widen", action: "Widen how far checks reach", routes: ["/settings/project/check-access"], explicit: true, form: "projectCheckAccess", field: "password", proof: "typed-now-operator", ...TYPED, role: "any", handlerRole: "an instance operator", secrets: [], terms: ["repo"], note: "the server decides whether a choice widens; a form offering any wider level asks for this proof" },
66
68
  ...CHAT_APPS.map(([app, name, form, secrets]) => ({ id: `${app}-open`, action: `Connect or pair ${name}`, routes: [`/settings/${app}/connect`, `/settings/${app}/pair`], form, field: "password", proof: "credential", ...CREDENTIAL, role: "approver", secrets, terms: [] })),
67
- { id: "sessions-token", action: "Make an API token", routes: ["/settings/sessions"], form: "sessions", field: "password", proof: "credential", when: "only to make a token (ending sessions and revoking tokens need nothing)", ...CREDENTIAL, role: "any", secrets: [], notProof: ["token"], terms: [], note: "`token` here names an API token to revoke" },
68
- { id: "people-invite", action: "Invite someone", routes: ["/people/invite"], form: "peopleInvite", field: "token", proof: "credential", ...CREDENTIAL, role: "any", handlerRole: "an approver", secrets: [], terms: [] },
69
+ { id: "sessions-token", action: "Make an API token", routes: ["/settings/sessions"], form: "sessions", field: "password", proof: "credential", when: "only to make a token (ending sessions and revoking tokens need nothing)", ...CREDENTIAL, role: "any", secrets: [], notProof: ["token"], terms: [], reveal: "once", note: "`token` here names an API token to revoke" },
70
+ { id: "people-invite", action: "Invite someone", routes: ["/people/invite"], form: "peopleInvite", field: "token", proof: "credential", ...CREDENTIAL, role: "any", handlerRole: "an approver", secrets: [], terms: [], reveal: "once" },
71
+ { id: "runner-register", action: "Register a computer that builds", routes: ["/fleet/runner/register"], form: "runnerRegister", field: "token", proof: "credential", ...CREDENTIAL, role: "any", handlerRole: "an approver, from a browser", secrets: [], terms: ["nonce"], reveal: "once", note: "`token` is the person's own password; `nonce` is the register document's one-use form token (spent before the password is checked: after a refusal, register again from the document); the worker's new token is shown once on the answer and only its hash is kept" },
69
72
  { id: "people-projects", action: "Change a person's projects", routes: ["/people/projects"], form: "peopleProjects", field: "token", proof: "credential", ...CREDENTIAL, role: "operator", secrets: [], terms: ["name"] },
70
73
  { id: "telegram-pair", action: "Pair your phone with Telegram", routes: ["/settings/telegram/pair"], form: "telegramPair", field: "password", proof: "typed-password", ...TYPED, role: "approver", secrets: [], terms: [] },
71
74
  { id: "chat-approval-save", action: "Turn on approving from chat", routes: ["/settings/chat-approval/save"], form: "chatApproval", field: "token", proof: "typed-password", ...TYPED, role: "approver", secrets: [], terms: ["nonce", "digest", "scope", "full-access", "cap-usd"] },
@@ -1,3 +1,9 @@
1
+ let writes = 0;
2
+ export const writesSoFar = () => writes;
3
+ const ownTemp = (op) => /^(?:CREATE\s+TEMP\s+TABLE\s+"so_work_ranked_\d+"|DROP\s+TABLE\s+IF\s+EXISTS\s+temp\."so_work_ranked_\d+"$)/i.test(op);
4
+ const opening = (op) => /^(?:BEGIN(?:\s+(?:DEFERRED|IMMEDIATE|EXCLUSIVE))?(?:\s+TRANSACTION)?|SAVEPOINT\s+\w+)\s*;?$/i.test(op);
5
+ const settingOnly = (op) => /^PRAGMA\s+busy_timeout\s*=\s*\d+\s*;?$/i.test(op);
6
+ const ending = (op) => /^(?:COMMIT|END|ROLLBACK|RELEASE)\b[^;]*;?\s*$/i.test(op);
1
7
  const states = new WeakMap();
2
8
  export function measureWriteWait(db, body) {
3
9
  const state = states.get(db);
@@ -34,34 +40,77 @@ export function instrumentDatabase(db, telemetry) {
34
40
  telemetry.writeHold.observe(elapsed(heldAt));
35
41
  heldAt = null;
36
42
  } };
43
+ let openedAt = null;
44
+ const native = db;
45
+ const counted = (counts, body) => {
46
+ if (counts)
47
+ writes++;
48
+ try {
49
+ return body();
50
+ }
51
+ catch (error) {
52
+ writes++;
53
+ throw error;
54
+ }
55
+ };
56
+ const execNow = (sql, op) => {
57
+ if (/^BEGIN\s+(?:IMMEDIATE|EXCLUSIVE)\b/i.test(op)) {
58
+ const at = telemetry.clock();
59
+ try {
60
+ db.exec(sql);
61
+ heldAt = telemetry.clock();
62
+ }
63
+ finally {
64
+ if (!state.measuringWait)
65
+ telemetry.writeWait.observe(elapsed(at));
66
+ }
67
+ }
68
+ else if (/^(?:COMMIT|END|ROLLBACK(?!\s+TO))\b/i.test(op)) {
69
+ db.exec(sql);
70
+ finish();
71
+ }
72
+ else
73
+ standalone(writing(op), () => db.exec(sql));
74
+ };
75
+ const counts = (op, path, write) => {
76
+ if (ownTemp(op) || settingOnly(op))
77
+ return false;
78
+ if (opening(op)) {
79
+ if (openedAt === null && native.isTransaction !== true)
80
+ openedAt = writes;
81
+ return false;
82
+ }
83
+ if (ending(op))
84
+ return openedAt === null || writes !== openedAt;
85
+ return path !== 'read' || write;
86
+ };
87
+ const settled = (op) => {
88
+ if (native.isTransaction === false || (native.isTransaction === undefined && /^(?:COMMIT|END|ROLLBACK(?!\s+TO))\b/i.test(op)))
89
+ openedAt = null;
90
+ };
91
+ const tracked = (op, path, write, body) => {
92
+ try {
93
+ return counted(counts(op, path, write), body);
94
+ }
95
+ finally {
96
+ settled(op);
97
+ }
98
+ };
37
99
  const methods = {
38
100
  exec(sql) {
39
101
  const op = operation(sql);
40
- if (/^BEGIN\s+(?:IMMEDIATE|EXCLUSIVE)\b/i.test(op)) {
41
- const at = telemetry.clock();
42
- try {
43
- db.exec(sql);
44
- heldAt = telemetry.clock();
45
- }
46
- finally {
47
- if (!state.measuringWait)
48
- telemetry.writeWait.observe(elapsed(at));
49
- }
50
- }
51
- else if (/^(?:COMMIT|END|ROLLBACK(?!\s+TO))\b/i.test(op)) {
52
- db.exec(sql);
53
- finish();
54
- }
55
- else
56
- standalone(writing(op), () => db.exec(sql));
102
+ tracked(op, 'exec', true, () => execNow(sql, op));
57
103
  },
58
104
  prepare(sql) {
59
- const statement = db.prepare(sql), write = writing(operation(sql));
105
+ const op = operation(sql), statement = db.prepare(sql), write = writing(op);
60
106
  const methods = {
61
- run: (...params) => standalone(write, () => statement.run(...params)),
62
- get: (...params) => standalone(write, () => statement.get(...params)),
63
- all: (...params) => standalone(write, () => statement.all(...params)),
107
+ run: (...params) => tracked(op, 'run', write, () => standalone(write, () => statement.run(...params))),
108
+ get: (...params) => tracked(op, 'read', write, () => standalone(write, () => statement.get(...params))),
109
+ all: (...params) => tracked(op, 'read', write, () => standalone(write, () => statement.all(...params))),
64
110
  };
111
+ const rows = statement;
112
+ if (typeof rows.iterate === 'function')
113
+ Object.assign(methods, { iterate: (...params) => tracked(op, 'read', write, () => rows.iterate(...params)) });
65
114
  return preservingNative(statement, methods);
66
115
  },
67
116
  close() { try {