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.
- package/CHANGELOG.md +54 -0
- package/README.md +4 -3
- 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 +38 -33
- package/dist/browser-crew.js +4 -4
- package/dist/browser-shell.js +1 -1
- 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 +17 -13
- package/dist/cli.js +4 -3
- package/dist/console-chrome.js +10 -3
- package/dist/contracts/cli.js +2 -0
- package/dist/contracts/console-api.js +5 -4
- 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/folder-look.js +65 -4
- package/dist/git-views.js +38 -38
- package/dist/guides.js +14 -11
- package/dist/keymap.js +1 -1
- package/dist/lead-cli.js +2 -1
- package/dist/lead-context.js +1 -1
- package/dist/limits-ui.js +1 -1
- package/dist/live-bus.js +82 -12
- package/dist/login-secrets.js +43 -0
- package/dist/needs-you.js +3 -3
- package/dist/nightly-github.js +2 -2
- package/dist/operate.js +278 -21
- package/dist/project-admission.js +60 -29
- package/dist/project-delete-ui.js +2 -1
- package/dist/project-delete.js +1 -0
- package/dist/project.js +73 -0
- package/dist/provider-auth.js +1 -1
- package/dist/release.js +1 -0
- package/dist/repos.js +37 -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/route-hooks.js +1 -0
- package/dist/sample-project.js +167 -9
- package/dist/scope.js +17 -2
- package/dist/serve.js +47 -32
- 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 +103 -10
- package/dist/server/login-help.js +67 -0
- package/dist/server/pages.js +258 -78
- package/dist/server/people-tokens.js +36 -24
- 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 +16 -4
- package/dist/server/render-projects.js +63 -15
- 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 +15 -5
- 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 +167 -19
- package/dist/server/task-views.js +47 -13
- package/dist/server/tasks.js +143 -90
- package/dist/server/welcome.js +35 -23
- package/dist/settings-groups-ui.js +34 -106
- package/dist/settings-proofs.js +5 -2
- package/dist/sqlite-telemetry.js +70 -21
- package/dist/store.js +141 -9
- package/dist/surface.js +4 -1
- package/dist/task-link.js +64 -0
- package/dist/task-outcome-cli.js +99 -4
- package/dist/tui-source.js +11 -3
- package/dist/tui.js +39 -39
- package/dist/typed-words-schema.js +18 -0
- package/dist/welcome-facts.js +15 -7
- package/dist/work-index.js +126 -29
- package/dist/work-reads.js +279 -0
- package/package.json +4 -2
package/dist/server/pages.js
CHANGED
|
@@ -7,13 +7,12 @@ import { handlersOf } from './handler-registry.js';
|
|
|
7
7
|
import { html, joinHtml, postForm, reauth } from "../html.js";
|
|
8
8
|
import * as kit from "./kit.js";
|
|
9
9
|
import { createHmac, randomBytes } from "node:crypto";
|
|
10
|
-
import { realpathSync } from "node:fs";
|
|
11
10
|
import {} from "node:http";
|
|
12
11
|
import { homedir, hostname } from "node:os";
|
|
13
12
|
import { basename, dirname, join, resolve } from "node:path";
|
|
14
|
-
import { builderReadyFor,
|
|
13
|
+
import { builderReadyFor, firstRunBuilderRepo } from "../dispatch.js";
|
|
15
14
|
import { withBuilderStep } from "../first-run.js";
|
|
16
|
-
import { listFolder, localOrigins } from "../folder-look.js";
|
|
15
|
+
import { folderFacts, listFolder, localOrigins } from "../folder-look.js";
|
|
17
16
|
import { Readable } from "node:stream";
|
|
18
17
|
import { pipeline } from "node:stream/promises";
|
|
19
18
|
import { setImmediate as yieldEventLoop } from "node:timers/promises";
|
|
@@ -39,8 +38,9 @@ import { prometheusMetrics } from "../metrics.js";
|
|
|
39
38
|
import { readMonitoring } from "../monitoring-settings.js";
|
|
40
39
|
import { targetOf } from "../monitoring.js";
|
|
41
40
|
import { cloneGithubRepo, isLargeRepo, listGithubRepos, parseGithubRepo, previewGithubRepo } from "../onboard.js";
|
|
42
|
-
import { admitProject, releaseProject } from "../project-admission.js";
|
|
43
|
-
import {
|
|
41
|
+
import { admitProject, proveProjectRoot, releaseProject } from "../project-admission.js";
|
|
42
|
+
import { typedPasswordNow } from "../scope.js";
|
|
43
|
+
import { authorizedProject, canonicalProject, expandHomePath, isGitRepo, comparisonPaths, comparisonsOf, folderRefusal, projectName, sameRepo } from "../project.js";
|
|
44
44
|
import { publishingOf } from '../pull-request-flow.js';
|
|
45
45
|
import { register as registerRunner } from "../runner.js";
|
|
46
46
|
import { healthWords } from "../server-telemetry.js";
|
|
@@ -51,17 +51,20 @@ import { slowRequestLines, SLOW_REQUEST_MS } from "../latency-timeline.js";
|
|
|
51
51
|
import { leadsStillAdmitted, leadTilesFor } from './agents-live-lead.js';
|
|
52
52
|
import { refuse, regionScript, relativeAge as relativeAgeOf, screen, settingsRows, WORKSPACE_STYLE, workToolRows } from "./chrome.js";
|
|
53
53
|
import { redirect, respond, safeReturn, SAFETY, taskHref } from "./http.js";
|
|
54
|
+
import { taskLinkOf } from "../task-link.js";
|
|
54
55
|
import { assignmentOf } from "../assignment.js";
|
|
55
56
|
import { assignmentTaskStatusOf } from "../assignment-presentation.js";
|
|
56
|
-
import { githubIdentityOf, homePage
|
|
57
|
+
import { githubIdentityOf, homePage } from "./render-pages.js";
|
|
57
58
|
import { retiredRedirect } from "./retired-routes.js";
|
|
59
|
+
import { RUNNER_REGISTER } from "./settings-computers.js";
|
|
58
60
|
import { codeMapStatus, openMap } from "../code-map-read.js";
|
|
59
61
|
import { requestRefresh } from "../code-map-store.js";
|
|
60
62
|
import { codeMapReport } from "../code-map-report.js";
|
|
61
63
|
import { codeMapPage, codeMapReportBlock } from "./render-code-map.js";
|
|
62
64
|
import { FLAKY_WINDOW_DAYS, flakyList, flakyShow } from "../flaky.js";
|
|
63
65
|
import { flakyPage, flakyRowPage } from "./render-flaky.js";
|
|
64
|
-
import {
|
|
66
|
+
import { configBase, NAMES } from "../names.js";
|
|
67
|
+
import { browsePage, folderPickerPage, githubReposPage, pickRepoChosen, outsideAddPage, shortPathOf, projectHref, projectPage, projectsPage, unknownProject } from "./render-projects.js";
|
|
65
68
|
import { notFound as kitNotFound } from "./kit.js";
|
|
66
69
|
import {} from "./render-pages.js";
|
|
67
70
|
import {} from "../project-outcomes.js";
|
|
@@ -70,11 +73,11 @@ import { capsPage } from "./render-settings.js";
|
|
|
70
73
|
import { consentDoorOf, decisionAnswerScript, taskBody } from "./render-tasks.js";
|
|
71
74
|
import {} from "./session.js";
|
|
72
75
|
import { rereadBrowser } from "./live.js";
|
|
73
|
-
import {
|
|
74
|
-
import { flowAsks, releaseAsks, setupAsks } from "./home-asks.js";
|
|
76
|
+
import { workNeeds } from "./home.js";
|
|
77
|
+
import { flowAsks, NO_HOME_ASKS, releaseAsks, setupAsks } from "./home-asks.js";
|
|
75
78
|
import { workIndexPage } from "../work-index.js";
|
|
76
|
-
export function createPagesHandlers(runtime) {
|
|
77
|
-
const { identities, clock, lastChecks, store, visible, consoleProjects, restricted, ceiling, options, projectFamilyPeek, sendScreen, chromeFor, unscopedMode, admissionList, taskRepoOf, taskViewData, runVisible, evidenceRoot, workAccess, identify, liveCeiling, sessions, deletedRepos, authenticateApprover, authenticateCredential, projectOf, lookupSession, firstRunStepsNow, chatEnablement, leadPrincipal, leadConversationRows } = runtime;
|
|
79
|
+
export function createPagesHandlers(runtime, work) {
|
|
80
|
+
const { identities, clock, lastChecks, store, visible, consoleProjects, restricted, ceiling, options, projectFamilyPeek, sendScreen, chromeFor, unscopedMode, admissionList, taskRepoOf, taskViewData, runVisible, evidenceRoot, workAccess, identify, liveCeiling, sessions, deletedRepos, authenticateApprover, authenticateCredential, consumeApprovalNonce, projectOf, lookupSession, firstRunStepsNow, chatEnablement, leadPrincipal, leadConversationRows, outsideAdmissions } = runtime;
|
|
78
81
|
async function projectsBrowse(ctx) {
|
|
79
82
|
const { url, who, response } = ctx;
|
|
80
83
|
if (who.via !== "cookie")
|
|
@@ -162,24 +165,39 @@ export function createPagesHandlers(runtime) {
|
|
|
162
165
|
return void projectsScreen(response, who, url.searchParams.get("said"), 200, safeReturn(url.searchParams.get("return")), "said");
|
|
163
166
|
}
|
|
164
167
|
async function homeRedirect(ctx) {
|
|
165
|
-
const { who, response, now, project } = ctx;
|
|
166
|
-
if (
|
|
167
|
-
return
|
|
168
|
-
if (firstRunStepsNow(now) !== null && !store.hasAnyWork())
|
|
168
|
+
const { url, who, response, now, project } = ctx;
|
|
169
|
+
if (url.searchParams.get("view") === "order")
|
|
170
|
+
return work.showOrder(ctx);
|
|
171
|
+
if (who.via === "cookie" && url.search === "" && firstRunStepsNow(now) !== null && !store.hasAnyWork())
|
|
169
172
|
return redirect(response, "/chat");
|
|
170
|
-
const
|
|
171
|
-
|
|
173
|
+
const found = await work.listFor(ctx);
|
|
174
|
+
if (found === null)
|
|
175
|
+
return;
|
|
176
|
+
const listed = found.screen;
|
|
177
|
+
const list = listed.workspace?.view;
|
|
178
|
+
if (list?.kind !== "tasks")
|
|
179
|
+
throw new Error("Work's list is not the Tasks list");
|
|
180
|
+
const chrome = listed.chrome ?? chromeFor(project, "work");
|
|
181
|
+
const access = workAccess(), approver = who.via === "cookie" && who.role === "approver";
|
|
172
182
|
const closedDoor = (taskId) => {
|
|
173
183
|
const scope = store.getScope(taskId);
|
|
174
184
|
const door = consentDoorOf(scope, runtime.routeViewOf(taskId, store.lookupRef(taskId), scope, now, who));
|
|
175
185
|
return door.open ? null : door;
|
|
176
186
|
};
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
const
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
187
|
+
const needs = workNeeds({ store, now, access, evidenceRoot, project, projects: chrome.projects ?? [], chat: false, canAnswer: approver, approver, closedDoor,
|
|
188
|
+
asks: who.via === "cookie" && !found.filtered ? homeAsksFor(who, access, now, project) : NO_HOME_ASKS }, found.work, found.filtered);
|
|
189
|
+
const asked = new Map(needs.groups.flatMap(group => group.rows).map(row => [row.id, row]));
|
|
190
|
+
const rows = list.rows.map(row => { const need = asked.get(row.id); return need === undefined ? row : { ...row, need }; });
|
|
191
|
+
const onRows = new Set(rows.flatMap(row => row.need === undefined ? [] : [row.id]));
|
|
192
|
+
const view = {
|
|
193
|
+
kind: "work", list: { ...list, rows }, needs: needs.groups.map(group => ({ ...group, rows: group.rows.filter(row => !onRows.has(row.id)) })), needsCount: needs.total, project,
|
|
194
|
+
projectName: project === null ? "All projects" : (chrome.projects ?? []).find(one => one.path === project)?.name ?? projectName(project),
|
|
195
|
+
setup: firstRunStepsNow(now) !== null ? "/welcome" : null,
|
|
196
|
+
empty: needs.any || needs.total > 0 ? null : { title: "No tasks yet", text: "Describe a change in a sentence; an agent writes a plan for you to approve." },
|
|
197
|
+
};
|
|
198
|
+
const asks = needs.groups.flatMap(group => group.rows).filter(row => row.id.includes(":"));
|
|
199
|
+
const stub = html `<div data-kit-page><h1>Work</h1>${asks.length === 0 ? null : html `<ul class="work-asks">${asks.map(row => html `<li><a href="${row.href}">${row.title}</a></li>`)}</ul>`}${listed.body}<p><a href="/tasks/new">New task</a> · <a href="/chat">Chat</a> · <a href="/settings">Settings</a></p></div>`;
|
|
200
|
+
return sendScreen(response, 200, screen("Work", stub, { chrome, workspace: { view } }));
|
|
183
201
|
}
|
|
184
202
|
async function searchPage(ctx) {
|
|
185
203
|
const { url, response, now } = ctx;
|
|
@@ -301,7 +319,7 @@ export function createPagesHandlers(runtime) {
|
|
|
301
319
|
const versionOf = (id) => family !== null && id !== family.current.id ? `version=${encodeURIComponent(id)}&` : "";
|
|
302
320
|
const run = store.getRun(runId);
|
|
303
321
|
const open = live || run === null ? null
|
|
304
|
-
: run.finishedAt !== null && (run.role === "builder" || run.role === "scout") ? { label: run.role === "scout" ? "Report" : "Result", href:
|
|
322
|
+
: run.finishedAt !== null && (run.role === "builder" || run.role === "scout") ? { label: run.role === "scout" ? "Report" : "Result", href: taskLinkOf({ task: root, revision: family !== null && taskId !== family.current.id ? taskId : null, run: runId }) }
|
|
305
323
|
: run.role === "planner" ? { label: "Plan", href: `${taskHref(root)}?${versionOf(taskId)}tab=plan` }
|
|
306
324
|
: { label: "Record", href: `/r/${runId}?record=1` };
|
|
307
325
|
let task = null;
|
|
@@ -310,7 +328,7 @@ export function createPagesHandlers(runtime) {
|
|
|
310
328
|
if (assignment !== null) {
|
|
311
329
|
const words = assignmentTaskStatusOf(assignment);
|
|
312
330
|
const wants = words.primaryAction?.href ?? "";
|
|
313
|
-
const href = /^\/review\?result=|[?&]result
|
|
331
|
+
const href = /^\/review\?result=|[?&]result=|^\/t\/[^?#]+\?(?:[^#]*&)?tab=result\b/.test(wants) ? taskLinkOf({ task: root, result: true }) : taskHref(root);
|
|
314
332
|
task = { headline: words.headline, sentence: words.sentence, tone: words.tone, action: { label: words.primaryAction?.label ?? "Open task", href } };
|
|
315
333
|
}
|
|
316
334
|
}
|
|
@@ -392,7 +410,7 @@ export function createPagesHandlers(runtime) {
|
|
|
392
410
|
const refreshSeconds = selected !== null ? undefined : store.liveClaims(null, now).length > 0 ? 10 : installation ? 60 : undefined;
|
|
393
411
|
return sendScreen(response, 200, screen("Agents", fallback, { chrome: chromeFor(project, "runs"), workspace: { view }, ...(refreshSeconds === undefined ? {} : { refreshSeconds }) }));
|
|
394
412
|
}
|
|
395
|
-
const fleetPage = aliasTo("/
|
|
413
|
+
const fleetPage = aliasTo("/settings/computers?section=builders");
|
|
396
414
|
async function ledgerExport(ctx) {
|
|
397
415
|
const { url, who, request, response, now } = ctx;
|
|
398
416
|
const from = exportDay(url.searchParams.get("from")), last = exportDay(url.searchParams.get("to"));
|
|
@@ -524,63 +542,122 @@ export function createPagesHandlers(runtime) {
|
|
|
524
542
|
if (who.via !== "cookie") {
|
|
525
543
|
return refuse(response, who, 403, "opening a project is a browser session's act");
|
|
526
544
|
}
|
|
527
|
-
const
|
|
545
|
+
const pathTyped = (body.get("path") ?? "").trim();
|
|
546
|
+
const at = body.get("via") === "path" ? "path" : "open";
|
|
547
|
+
const back = safeReturn(body.get("return"));
|
|
548
|
+
const say = (words, status) => void projectsScreen(response, who, words, status, back, at, at === "path" ? pathTyped : "");
|
|
549
|
+
const asked = pathTyped.length === 0 ? "" : expandHomePath(pathTyped, homedir());
|
|
550
|
+
if (asked === null)
|
|
551
|
+
return say("only ~ for your own home folder works here, like ~/code/your-repo", 400);
|
|
528
552
|
const decidedOn = identities.generation();
|
|
529
553
|
const resolved = asked === "" ? null : await identities.resolveNow(asked);
|
|
530
554
|
if (resolved === "no-answer") {
|
|
531
|
-
return
|
|
555
|
+
return say("that folder didn't answer — it may be on a drive that's disconnected, or waiting on macOS; try again in a moment", 503);
|
|
532
556
|
}
|
|
533
557
|
const canonical = resolved;
|
|
534
558
|
if (canonical === null) {
|
|
535
|
-
return
|
|
559
|
+
return say(asked === "" ? "enter the path of a git repository" : `${shortPathOf(resolve(asked))} isn't a folder on this computer`, 400);
|
|
536
560
|
}
|
|
561
|
+
let target = canonical;
|
|
562
|
+
let outside = false;
|
|
537
563
|
if (!(await authorizedProject(liveCeiling(), canonical))) {
|
|
538
|
-
|
|
564
|
+
const roots = ceiling.roots;
|
|
565
|
+
const outsideWords = roots.length === 0 ? "that folder isn't inside a projects folder" : `that folder isn't inside ${roots.map(shortPathOf).join(" or ")}`;
|
|
566
|
+
if (at !== "path" || who.role !== "approver" || who.authority !== "full" || store.isDemo() || restricted()) {
|
|
567
|
+
return say(`${outsideWords}, and only an approver signed in with a password can add one from elsewhere`, 403);
|
|
568
|
+
}
|
|
569
|
+
const password = body.get("password") ?? "";
|
|
570
|
+
const root = await proveProjectRoot(canonical, undefined, identities.resolveNow);
|
|
571
|
+
if (!root.ok)
|
|
572
|
+
return say(root.reason === "not-git" ? "that path is not a git repository" : root.message, 400);
|
|
573
|
+
const refused = await additionRefusal(root.repo);
|
|
574
|
+
if (refused !== null)
|
|
575
|
+
return say(refused.words, refused.status);
|
|
576
|
+
if (password === "") {
|
|
577
|
+
const chrome = chromeFor(who.session.project, "projects");
|
|
578
|
+
return void sendScreen(response, 200, outsideAddPage(chrome, { name: projectName(root.repo), path: root.repo }));
|
|
579
|
+
}
|
|
580
|
+
if (!typedPasswordNow(authenticateCredential(who, password)))
|
|
581
|
+
return say("that password didn't match", 403);
|
|
582
|
+
target = root.repo;
|
|
583
|
+
outside = true;
|
|
539
584
|
}
|
|
540
|
-
|
|
541
|
-
|
|
585
|
+
else {
|
|
586
|
+
if (!(await isGitRepo(canonical)))
|
|
587
|
+
return say("that path is not a git repository", 400);
|
|
588
|
+
const known = liveCeiling().repos.includes(canonical) || store.listProjects().some(one => one.path === canonical);
|
|
589
|
+
if (!known) {
|
|
590
|
+
const root = await proveProjectRoot(canonical, undefined, identities.resolveNow);
|
|
591
|
+
if (!root.ok)
|
|
592
|
+
return say(root.reason === "not-git" ? "that path is not a git repository" : root.message, 400);
|
|
593
|
+
const refused = await additionRefusal(root.repo, true);
|
|
594
|
+
if (refused !== null)
|
|
595
|
+
return say(refused.words, refused.status);
|
|
596
|
+
}
|
|
542
597
|
}
|
|
543
|
-
if (!visible(canonical)) {
|
|
544
|
-
return
|
|
598
|
+
if (!outside && !visible(canonical)) {
|
|
599
|
+
return say("That project is outside your access.", 403);
|
|
545
600
|
}
|
|
546
601
|
if (identities.generation() !== decidedOn)
|
|
547
|
-
return
|
|
548
|
-
const stillAllowed = (repo) => identities.generation() === decidedOn &&
|
|
549
|
-
|
|
602
|
+
return say("a project folder changed while this was being checked — try again", 409);
|
|
603
|
+
const stillAllowed = (repo) => identities.generation() === decidedOn && (outside
|
|
604
|
+
? repo === target && store.accountOf(who.name)?.revokedAt === null && store.accountOf(who.name)?.role === "approver" && store.accountOf(who.name)?.generation === who.session.generation && store.accountCanAccess(who.name, repo)
|
|
605
|
+
: visible(repo));
|
|
606
|
+
const admitted = await admitProject(store, { registryFile: options.registryPath ?? null, path: target, actor: { label: who.name, origin: "console" }, now, stillAllowed, resolveFolder: identities.resolveNow });
|
|
550
607
|
if (!admitted.ok) {
|
|
551
|
-
return
|
|
608
|
+
return say(admitted.reason === "not-git" ? "that path is not a git repository" : `that project is valid, but it could not be added — ${admitted.message}`, admitted.reason === "moved" ? 409 : 400);
|
|
552
609
|
}
|
|
553
610
|
if (!stillAllowed(admitted.repo))
|
|
554
|
-
return
|
|
611
|
+
return say("a project folder changed while this was being checked — try again", 409);
|
|
612
|
+
if (outside) {
|
|
613
|
+
outsideAdmissions.admit(admitted.repo);
|
|
614
|
+
try {
|
|
615
|
+
store.recordAction({ at: now.toISOString(), actor: who.name, repo: admitted.repo, taskId: null, runId: null, action: PROJECT_ADDED_OUTSIDE, outcome: "added", source: "access", detail: "outside the projects folder, with a password typed now" });
|
|
616
|
+
}
|
|
617
|
+
catch { }
|
|
618
|
+
}
|
|
555
619
|
deletedRepos.delete(admitted.repo);
|
|
556
620
|
who.session.project = admitted.repo;
|
|
557
621
|
who.session.projectRevision++;
|
|
558
|
-
return redirect(response,
|
|
622
|
+
return redirect(response, back);
|
|
559
623
|
}
|
|
560
624
|
async function fleetRegister(ctx) {
|
|
561
625
|
const { who, request, response, posted, now } = ctx;
|
|
562
626
|
const body = readForm(posted, CONSOLE_FORMS.runnerRegister);
|
|
563
627
|
if (who.via !== "cookie")
|
|
564
628
|
return refuse(response, who, 403, "runner registration is a browser surface");
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
return refuse(response, who, 403, "registering a worker takes your password, typed again", "/agents#computers");
|
|
568
|
-
}
|
|
629
|
+
if (store.isDemo())
|
|
630
|
+
return refuse(response, who, 403, "The demo doesn't register computers.", "/settings/computers");
|
|
569
631
|
const name = (body.get("name") ?? "").trim();
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
632
|
+
const capacityField = (body.get("capacity") ?? "1").trim() || "1";
|
|
633
|
+
const again = (problem, field) => {
|
|
634
|
+
const query = new URLSearchParams({ problem });
|
|
635
|
+
if (name !== "" && name.length <= 60 && !/[\r\n\t]/.test(name) && !hasForbiddenControls(name))
|
|
636
|
+
query.set("name", name);
|
|
637
|
+
if (/^[0-9]{1,2}$/.test(capacityField))
|
|
638
|
+
query.set("capacity", capacityField);
|
|
639
|
+
if (field !== undefined)
|
|
640
|
+
query.set("field", field);
|
|
641
|
+
return redirect(response, `/settings/change/register-computer?${query}`);
|
|
642
|
+
};
|
|
643
|
+
if (!consumeApprovalNonce(body.get("nonce") ?? "", who.name, RUNNER_REGISTER, ""))
|
|
644
|
+
return again("That form was already used or has expired. Nothing was registered; check the details and register again.");
|
|
645
|
+
const token = body.get("token") ?? "";
|
|
646
|
+
if (!authenticateCredential(who, token).ok)
|
|
647
|
+
return again("Registering a computer takes your password, typed now. Nothing was registered.");
|
|
648
|
+
if (name === "" || name.length > 60 || /[\r\n\t]/.test(name) || hasForbiddenControls(name))
|
|
649
|
+
return again("A computer's name is one short line, no control characters.", "name");
|
|
650
|
+
const capacity = Number(capacityField);
|
|
651
|
+
if (!Number.isInteger(capacity) || capacity < 1 || capacity > 64)
|
|
652
|
+
return again("Tasks at a time is a whole number from 1 to 64.", "capacity");
|
|
577
653
|
const { token: minted } = registerRunner(store, { name, host: hostname(), capacity, now });
|
|
578
|
-
const
|
|
654
|
+
const home = "/settings/computers?section=builders";
|
|
655
|
+
const tokenScreen = screen("fleet", html `<div data-kit-page>${kit.phoneHeader("Computer registered", { back: home })}${kit.doc(kit.docHeader({ title: `${name} is registered`, back: [home, "Computers"], same: true, meta: html `Takes up to ${capacity} ${capacity === 1 ? "task" : "tasks"} at a time` }), kit.slots({
|
|
579
656
|
status: html `<h2>Its token, shown once</h2>`,
|
|
580
657
|
text: "Only a hash is kept, so copy it now.",
|
|
581
658
|
acts: html `<code class="k-code" data-runner-token>${minted}</code>`,
|
|
582
659
|
terms: "Keep it beside the computer, in a file only you can read (0600) or a secrets manager. If it's lost, register the name again; its old claims are taken back.",
|
|
583
|
-
}), kit.acts(kit.btn("Back to
|
|
660
|
+
}), kit.acts(kit.btn("Back to Computers", { href: home })))}</div>`, { chrome: chromeFor(projectOf(who, request) ?? null, "fleet"), forceSensitive: true });
|
|
584
661
|
return sendScreen(response, 200, tokenScreen);
|
|
585
662
|
}
|
|
586
663
|
async function fleetRetire(ctx) {
|
|
@@ -588,15 +665,23 @@ export function createPagesHandlers(runtime) {
|
|
|
588
665
|
const body = readForm(posted, CONSOLE_FORMS.runnerRetire);
|
|
589
666
|
if (who.via !== "cookie")
|
|
590
667
|
return refuse(response, who, 403, "runner retirement is a browser surface");
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
return refuse(response, who, 403, "retiring a worker takes your password, typed again", "/agents#computers");
|
|
594
|
-
}
|
|
668
|
+
if (store.isDemo())
|
|
669
|
+
return refuse(response, who, 403, "The demo doesn't retire computers.", "/settings/computers");
|
|
595
670
|
const name = (body.get("name") ?? "").trim();
|
|
671
|
+
const again = (problem) => {
|
|
672
|
+
const query = new URLSearchParams();
|
|
673
|
+
if (name !== "" && name.length <= 60 && !hasForbiddenControls(name))
|
|
674
|
+
query.set("computer", name);
|
|
675
|
+
query.set("problem", problem);
|
|
676
|
+
return redirect(response, `/settings/change/retire-computer?${query}`);
|
|
677
|
+
};
|
|
678
|
+
const token = body.get("token") ?? "";
|
|
679
|
+
if (!authenticateApprover(who, token).ok)
|
|
680
|
+
return again("Retiring a computer takes your password. Nothing changed.");
|
|
596
681
|
const retired = store.retireRunner(name, now);
|
|
597
682
|
if (!retired)
|
|
598
|
-
return
|
|
599
|
-
return redirect(response, `/
|
|
683
|
+
return again("There's no computer by that name to retire. Nothing changed.");
|
|
684
|
+
return redirect(response, `/settings/computers?section=builders&said=${encodeURIComponent(`${name} is retired. It takes no more work.`)}`);
|
|
600
685
|
}
|
|
601
686
|
async function onboardPreview(ctx) {
|
|
602
687
|
const { who, response, posted } = ctx;
|
|
@@ -608,7 +693,7 @@ export function createPagesHandlers(runtime) {
|
|
|
608
693
|
if (process.platform === "win32")
|
|
609
694
|
return refuse(response, who, 403, "adding from GitHub is not supported on Windows yet");
|
|
610
695
|
if (ceiling.roots.length === 0)
|
|
611
|
-
return projectsScreen(response, who, "
|
|
696
|
+
return projectsScreen(response, who, "cloning from GitHub needs a projects folder to clone into, and this Toolroll has none", 400, "/", "link");
|
|
612
697
|
const shape = parseGithubRepo(body.get("repo") ?? "");
|
|
613
698
|
if (!shape.ok)
|
|
614
699
|
return projectsScreen(response, who, shape.problem, 400, "/", "link");
|
|
@@ -660,7 +745,7 @@ export function createPagesHandlers(runtime) {
|
|
|
660
745
|
if (process.platform === "win32")
|
|
661
746
|
return refuse(response, who, 403, "adding from GitHub is not supported on Windows yet");
|
|
662
747
|
if (ceiling.roots.length === 0)
|
|
663
|
-
return projectsScreen(response, who, "
|
|
748
|
+
return projectsScreen(response, who, "cloning from GitHub needs a projects folder to clone into, and this Toolroll has none", 400, "/", "clone");
|
|
664
749
|
const password = body.get("token") ?? "";
|
|
665
750
|
if (!authenticateApprover(who, password).ok) {
|
|
666
751
|
return projectsScreen(response, who, "cloning takes your password, typed again", 403, "/", "clone");
|
|
@@ -735,7 +820,7 @@ export function createPagesHandlers(runtime) {
|
|
|
735
820
|
return null;
|
|
736
821
|
}
|
|
737
822
|
}
|
|
738
|
-
async function projectsScreen(response, who, problem, status, returnTo = "/", problemAt = null) {
|
|
823
|
+
async function projectsScreen(response, who, problem, status, returnTo = "/", problemAt = null, typed = "") {
|
|
739
824
|
const now = clock();
|
|
740
825
|
const { recent, candidates } = visibleProjects();
|
|
741
826
|
const open = who.via === "cookie" ? who.session.project : null;
|
|
@@ -748,9 +833,7 @@ export function createPagesHandlers(runtime) {
|
|
|
748
833
|
: ceiling.roots.length === 0
|
|
749
834
|
? {
|
|
750
835
|
enabled: false,
|
|
751
|
-
why:
|
|
752
|
-
? "Choose a projects folder once: toolroll up --project-root <dir>"
|
|
753
|
-
: "choose which folder this server may use with --project-root <dir>",
|
|
836
|
+
why: "Cloning from GitHub needs a projects folder to clone into, and this Toolroll has none.",
|
|
754
837
|
}
|
|
755
838
|
: { enabled: true, roots: ceiling.roots, localOwner: who.authority !== "full", record: [...(who.session.onboard?.entries() ?? [])][0] ?? null };
|
|
756
839
|
const peeks = {};
|
|
@@ -761,6 +844,11 @@ export function createPagesHandlers(runtime) {
|
|
|
761
844
|
return sendScreen(response, status, projectsPage(chromeFor(open, "projects"), {
|
|
762
845
|
recent, candidates, open, problem, problemAt, onboard: onboardState, peeks, returnTo,
|
|
763
846
|
browsable: !restricted() && (ceiling.roots.length > 0 || unscopedMode),
|
|
847
|
+
local: {
|
|
848
|
+
pick: who.via === "cookie" && who.role === "approver" && !restricted(),
|
|
849
|
+
outside: who.via === "cookie" && who.role === "approver" && who.authority === "full" && !store.isDemo() && !restricted() && !unscopedMode,
|
|
850
|
+
pathValue: typed,
|
|
851
|
+
},
|
|
764
852
|
}));
|
|
765
853
|
}
|
|
766
854
|
async function projectFound(ctx, page) {
|
|
@@ -973,18 +1061,6 @@ export function createPagesHandlers(runtime) {
|
|
|
973
1061
|
return respond(response, 404, "application/json", JSON.stringify({ error: "run" }));
|
|
974
1062
|
return respond(response, 200, "application/json", JSON.stringify(window.ok ? window : { error: window.reason }));
|
|
975
1063
|
}
|
|
976
|
-
async function startBuilderPage(ctx) {
|
|
977
|
-
const { response, now, project, url, who } = ctx;
|
|
978
|
-
const taskId = url.searchParams.get("task");
|
|
979
|
-
const ref = taskId === null ? null : store.lookupRef(taskId.slice(0, 200));
|
|
980
|
-
if (taskId !== null && (ref === null || ref.repo === null || !visible(ref.repo)))
|
|
981
|
-
return refuse(response, who, 404, "That task is not available.", "/tasks");
|
|
982
|
-
const shown = ref !== null ? ref.repo : project !== null && visible(project) ? project : null;
|
|
983
|
-
const connected = shown === null ? null : buildersFor(store, shown, now, ref?.assignedRunner ?? null).alive.length > 0;
|
|
984
|
-
return sendScreen(response, 200, screen("Start a builder", startBuilderHtml({
|
|
985
|
-
heading: "h1", project: shown === null ? null : basename(shown), connected, managed: !restricted(),
|
|
986
|
-
}), { chrome: chromeFor(project, "none") }));
|
|
987
|
-
}
|
|
988
1064
|
const registrations = handlersOf("pages", {
|
|
989
1065
|
"projects.browse": projectsBrowse,
|
|
990
1066
|
"projects.github": projectsGithub,
|
|
@@ -1001,7 +1077,7 @@ export function createPagesHandlers(runtime) {
|
|
|
1001
1077
|
"ledger": ledgerPage,
|
|
1002
1078
|
"activity": activityPage,
|
|
1003
1079
|
"system": systemScreen,
|
|
1004
|
-
"start-builder":
|
|
1080
|
+
"start-builder": async (ctx) => retiredRedirect("start-builder", ctx.url, ctx.response),
|
|
1005
1081
|
"peek": peekPage,
|
|
1006
1082
|
"agents": agentsPage,
|
|
1007
1083
|
"agents.live": agentsLive,
|
|
@@ -1021,6 +1097,7 @@ export function createPagesHandlers(runtime) {
|
|
|
1021
1097
|
"fleet.retire": fleetRetire,
|
|
1022
1098
|
"projects.onboard-preview": onboardPreview,
|
|
1023
1099
|
"projects.onboard-confirm": onboardConfirm,
|
|
1100
|
+
"projects.pick": projectsPick,
|
|
1024
1101
|
}, {
|
|
1025
1102
|
"edge.healthz": healthzEdge,
|
|
1026
1103
|
"edge.instance": instanceEdge,
|
|
@@ -1050,5 +1127,108 @@ export function createPagesHandlers(runtime) {
|
|
|
1050
1127
|
return { ...releaseAsks(store, now, access, project, approver), flows: flowAsks(store, consoleProjects(), { name: who.name, approver }, project),
|
|
1051
1128
|
setup: setupAsks(steps, approver) };
|
|
1052
1129
|
}
|
|
1130
|
+
function toolrollStateFolders(home) {
|
|
1131
|
+
const base = configBase(process.env, home);
|
|
1132
|
+
return [...new Set([
|
|
1133
|
+
options.configDir, options.registryPath === undefined ? undefined : dirname(options.registryPath), evidenceRoot, options.poolRoot, options.toolHome,
|
|
1134
|
+
...NAMES.map(name => join(base, name)), ...NAMES.map(name => join(home, `.${name}`)),
|
|
1135
|
+
].filter((one) => typeof one === "string" && one !== "").map(one => resolve(one)))];
|
|
1136
|
+
}
|
|
1137
|
+
const lookOptions = () => ({ home: homedir(), ...(options.folderLook === undefined ? {} : { runner: options.folderLook }), ...(options.folderLookMs === undefined ? {} : { deadlineMs: options.folderLookMs }) });
|
|
1138
|
+
async function widenFacts(path) {
|
|
1139
|
+
const home = homedir();
|
|
1140
|
+
const protect = toolrollStateFolders(home);
|
|
1141
|
+
const looked = await folderFacts(path, comparisonPaths(home, protect), lookOptions());
|
|
1142
|
+
if (!looked.ok)
|
|
1143
|
+
return { ok: false, words: looked.why === "no-answer" ? "That folder didn't answer. It may be on a drive that's disconnected, or waiting on macOS. Try again in a moment." : "That folder couldn't be read." };
|
|
1144
|
+
const facts = comparisonsOf(looked.value.compare, protect.length);
|
|
1145
|
+
if (facts.home.kind !== "found")
|
|
1146
|
+
return { ok: false, words: "Your home folder couldn't be read. Try again in a moment." };
|
|
1147
|
+
const protectedReal = [];
|
|
1148
|
+
for (const one of facts.protectedDirs) {
|
|
1149
|
+
if (one.kind === "unreadable")
|
|
1150
|
+
return { ok: false, words: "One of Toolroll's own folders couldn't be read, so nothing here can be checked. Try again in a moment." };
|
|
1151
|
+
protectedReal.push(one.kind === "found" ? one.real : one.path);
|
|
1152
|
+
}
|
|
1153
|
+
return { ok: true, target: looked.value.target, home: facts.home, facts, protectedReal };
|
|
1154
|
+
}
|
|
1155
|
+
async function additionRefusal(repo, insideRoot = false) {
|
|
1156
|
+
const seen = await widenFacts(repo);
|
|
1157
|
+
if (!seen.ok)
|
|
1158
|
+
return { words: seen.words, status: 503 };
|
|
1159
|
+
if (seen.target.kind !== "found" || !seen.target.dir)
|
|
1160
|
+
return { words: "that path is not a git repository", status: 400 };
|
|
1161
|
+
const refusal = folderRefusal("repo", seen.target, insideRoot ? { ...seen.facts, tops: [], trees: [] } : seen.facts);
|
|
1162
|
+
if (refusal !== null)
|
|
1163
|
+
return { words: refusal, status: 400 };
|
|
1164
|
+
if (process.getuid !== undefined && seen.target.uid !== process.getuid())
|
|
1165
|
+
return { words: `${shortPathOf(repo)} must be a repository you own`, status: 403 };
|
|
1166
|
+
if (seen.target.real !== repo)
|
|
1167
|
+
return { words: `use the folder's own name: ${shortPathOf(seen.target.real)}`, status: 400 };
|
|
1168
|
+
return null;
|
|
1169
|
+
}
|
|
1170
|
+
async function pickerScreen(ctx) {
|
|
1171
|
+
const { url, who, response } = ctx;
|
|
1172
|
+
const chrome = chromeFor(who.via === "cookie" ? who.session.project : null, "projects");
|
|
1173
|
+
const back = ["/projects", "Projects"];
|
|
1174
|
+
const inside = (one, root) => one === root || one.startsWith(`${root}/`);
|
|
1175
|
+
const base = { problem: url.searchParams.get("problem"), said: url.searchParams.get("said"), back };
|
|
1176
|
+
const seenHome = await widenFacts(homedir());
|
|
1177
|
+
if (!seenHome.ok) {
|
|
1178
|
+
return sendScreen(response, 200, folderPickerPage(chrome, { ...base, at: null, entries: [], shortcuts: [], chosen: null, lookProblem: seenHome.words }));
|
|
1179
|
+
}
|
|
1180
|
+
const home = seenHome.home.real;
|
|
1181
|
+
const roots = [home, ...ceiling.roots.filter(root => !inside(root, home) && !inside(home, root))];
|
|
1182
|
+
const hrefOf = (path) => `/projects/pick?at=${encodeURIComponent(path)}`;
|
|
1183
|
+
const fallback = ceiling.roots[0] ?? home;
|
|
1184
|
+
const expanded = expandHomePath((url.searchParams.get("at") ?? "").trim(), home);
|
|
1185
|
+
const spelled = expanded === null || !expanded.startsWith("/") ? fallback : resolve(expanded);
|
|
1186
|
+
const start = roots.some(root => inside(spelled, root)) ? spelled : fallback;
|
|
1187
|
+
const listOptions = { ...lookOptions(), home, native: true };
|
|
1188
|
+
const protectedDirs = seenHome.protectedReal;
|
|
1189
|
+
const hiddenBelow = (path) => { const root = roots.find(one => inside(path, one)); return root !== undefined && path.slice(root.length).split("/").some(name => name.startsWith(".")); };
|
|
1190
|
+
const kept = (path) => roots.some(root => inside(path, root)) && !protectedDirs.some(dir => inside(path, dir)) && !hiddenBelow(path);
|
|
1191
|
+
const looked = await listFolder(start, roots, listOptions);
|
|
1192
|
+
const at = looked.ok ? looked.value.at : null;
|
|
1193
|
+
if (!looked.ok || at === null || !kept(at)) {
|
|
1194
|
+
const lookProblem = looked.ok ? "This folder couldn't be read." : looked.why === "no-answer" ? "This folder didn't answer. It may be on a drive that's disconnected, or waiting on macOS. Try again in a moment." : "This folder couldn't be read.";
|
|
1195
|
+
return sendScreen(response, 200, folderPickerPage(chrome, { ...base, at: null, entries: [], shortcuts: [{ label: "Home folder", href: hrefOf(home) }], chosen: null, lookProblem }));
|
|
1196
|
+
}
|
|
1197
|
+
const registered = new Set(store.listProjects().filter(one => visible(one.path)).map(one => one.path));
|
|
1198
|
+
const entries = looked.value.entries.filter(one => kept(one.path))
|
|
1199
|
+
.sort((a, b) => Number(b.git) - Number(a.git) || a.name.localeCompare(b.name)).slice(0, 200)
|
|
1200
|
+
.map(one => ({ name: one.name, git: one.git, registered: registered.has(one.path), href: hrefOf(one.path) }));
|
|
1201
|
+
const root = roots.filter(one => inside(at, one)).sort((a, b) => b.length - a.length)[0] ?? home;
|
|
1202
|
+
const parts = at === root ? [] : at.slice(root.length + 1).split("/");
|
|
1203
|
+
const crumbs = [{ label: root === home ? "~" : shortPathOf(root), href: at === root ? null : hrefOf(root) },
|
|
1204
|
+
...parts.map((part, index) => ({ label: part, href: index === parts.length - 1 ? null : hrefOf(`${root}/${parts.slice(0, index + 1).join("/")}`) }))];
|
|
1205
|
+
const up = at === root ? null : hrefOf(at.slice(0, at.lastIndexOf("/")) || root);
|
|
1206
|
+
const homeLook = at === home ? looked : await listFolder(home, roots, listOptions);
|
|
1207
|
+
const homeNames = new Set(homeLook.ok ? homeLook.value.entries.map(one => one.name) : []);
|
|
1208
|
+
const shortcuts = [
|
|
1209
|
+
...(at === home ? [] : [{ label: "Home folder", href: hrefOf(home) }]),
|
|
1210
|
+
...["Developer", "Documents", "code", "Projects"].filter(name => homeNames.has(name) && `${home}/${name}` !== at).map(name => ({ label: `~/${name}`, href: hrefOf(`${home}/${name}`) })),
|
|
1211
|
+
...ceiling.roots.filter(one => one !== at && !["Developer", "Documents", "code", "Projects"].some(name => one === `${home}/${name}`)).map(one => ({ label: shortPathOf(one), href: hrefOf(one) })),
|
|
1212
|
+
];
|
|
1213
|
+
let chosen = null;
|
|
1214
|
+
if (at !== home) {
|
|
1215
|
+
const proved = await proveProjectRoot(at, undefined, identities.resolveNow);
|
|
1216
|
+
if (proved.ok && proved.repo === at) {
|
|
1217
|
+
const name = projectName(at);
|
|
1218
|
+
const inCeiling = await authorizedProject(liveCeiling(), at);
|
|
1219
|
+
const refused = registered.has(at) && inCeiling ? null : await additionRefusal(at, inCeiling);
|
|
1220
|
+
const refusal = refused === null ? null : refused.words;
|
|
1221
|
+
const may = who.via === "cookie" && who.role === "approver" && who.authority === "full" && !store.isDemo() && !restricted();
|
|
1222
|
+
chosen = pickRepoChosen({ name, path: at, refusal, state: registered.has(at) && inCeiling ? "open" : inCeiling ? "inside" : may ? "outside" : "blocked" });
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
return sendScreen(response, 200, folderPickerPage(chrome, { ...base, at: { shown: shortPathOf(at), crumbs, up }, entries, shortcuts, chosen, lookProblem: null }));
|
|
1226
|
+
}
|
|
1227
|
+
async function projectsPick(ctx) {
|
|
1228
|
+
if (ctx.who.via !== "cookie")
|
|
1229
|
+
return refuse(ctx.response, ctx.who, 403, "Choosing a repository is a browser session's act.", "/projects");
|
|
1230
|
+
return pickerScreen(ctx);
|
|
1231
|
+
}
|
|
1053
1232
|
return { registrations, projectsScreen };
|
|
1054
1233
|
}
|
|
1234
|
+
export const PROJECT_ADDED_OUTSIDE = "project added from outside the projects folder";
|