toolroll 0.9.107 → 0.9.108
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/README.md +4 -3
- package/dist/browser/workspace.css +1 -1
- package/dist/browser/workspace.js +27 -25
- package/dist/browser-shell.js +1 -1
- package/dist/cli-help.js +5 -0
- package/dist/contracts/cli.js +2 -0
- package/dist/contracts/console-api.js +1 -1
- package/dist/folder-look.js +65 -4
- package/dist/guides.js +3 -1
- package/dist/lead-cli.js +2 -1
- package/dist/live-bus.js +14 -1
- package/dist/login-secrets.js +43 -0
- package/dist/operate.js +167 -18
- package/dist/project-admission.js +60 -29
- package/dist/project.js +73 -0
- package/dist/repos.js +37 -0
- package/dist/route-hooks.js +1 -0
- package/dist/sample-project.js +167 -9
- package/dist/scope.js +17 -2
- package/dist/serve.js +15 -3
- package/dist/server/live.js +5 -2
- package/dist/server/login-help.js +67 -0
- package/dist/server/pages.js +180 -26
- package/dist/server/people-tokens.js +36 -24
- package/dist/server/render-people.js +14 -2
- package/dist/server/render-projects.js +58 -10
- package/dist/server/route-table.js +2 -1
- package/dist/server/settings.js +3 -0
- package/dist/server/welcome.js +29 -18
- package/dist/settings-groups-ui.js +10 -1
- package/dist/store.js +33 -0
- package/dist/surface.js +4 -1
- package/dist/task-outcome-cli.js +99 -4
- package/dist/tui-source.js +11 -3
- package/dist/tui.js +39 -39
- package/dist/welcome-facts.js +12 -5
- package/package.json +1 -1
|
@@ -4,13 +4,14 @@ import { dirname, join, resolve } from "node:path";
|
|
|
4
4
|
import { run } from "./exec.js";
|
|
5
5
|
import { canonicalProject, projectName, sameRepo } from "./project.js";
|
|
6
6
|
import { remoteUrlProblem } from "./remote-main.js";
|
|
7
|
-
import { addRepos, loadProjectRegistry, removeRepos, updateRepos } from "./repos.js";
|
|
7
|
+
import { addRepos, loadProjectRegistry, removeRepos, updateProjectRegistry, updateRepos } from "./repos.js";
|
|
8
8
|
import { FolderUnavailable } from "./folder-gate.js";
|
|
9
9
|
const ADMISSION_GIT = {
|
|
10
10
|
envAllowlist: ["PATH", "HOME", "TMPDIR", "LANG", "LC_ALL"],
|
|
11
11
|
env: { GIT_CONFIG_NOSYSTEM: "1", GIT_CONFIG_GLOBAL: "/dev/null", GIT_NO_REPLACE_OBJECTS: "1" },
|
|
12
12
|
};
|
|
13
13
|
export const PROJECT_ADDED = "project added";
|
|
14
|
+
export const PROJECT_ADD_INCOMPLETE = "project add incomplete";
|
|
14
15
|
export const PROJECT_REMOVED = "project removed";
|
|
15
16
|
export async function proveProjectRoot(path, exec = run, resolveFolder) {
|
|
16
17
|
if (path.trim() === "" || path.length > 4096 || /[\x00-\x1f]/.test(path)) {
|
|
@@ -53,48 +54,78 @@ export async function admitProject(store, input) {
|
|
|
53
54
|
const discovered = !known && input.captureOrigin === true && input.actor.origin !== "console"
|
|
54
55
|
? await originOf(repo, input.exec ?? run) : null;
|
|
55
56
|
let remote = { url: store.projectRemote(repo), why: null };
|
|
56
|
-
let
|
|
57
|
+
let enrolledHere = false;
|
|
58
|
+
const latestAdmission = () => Number(store.handle.prepare("SELECT COALESCE(MAX(id), 0) AS id FROM action_ledger WHERE repo = ? AND action = ?").get(repo, PROJECT_ADDED)?.["id"] ?? 0);
|
|
59
|
+
let admittedBefore = 0;
|
|
57
60
|
const allowed = () => input.stillAllowed === undefined || input.stillAllowed(repo);
|
|
58
61
|
const moved = { ok: false, reason: "moved", message: `${projectName(repo)} wasn't added: a project folder changed while it was being checked. Try again.` };
|
|
59
62
|
if (input.registryFile !== null) {
|
|
60
63
|
let refused = false;
|
|
61
64
|
let had = false;
|
|
62
|
-
const enrolled = await
|
|
63
|
-
had = repos.includes(repo);
|
|
64
|
-
|
|
65
|
+
const enrolled = await updateProjectRegistry(input.registryFile, current => {
|
|
66
|
+
had = current.repos.includes(repo);
|
|
67
|
+
admittedBefore = latestAdmission();
|
|
68
|
+
if (!allowed() || (input.registryAllowed !== undefined && !input.registryAllowed(repo, current))) {
|
|
65
69
|
refused = true;
|
|
66
|
-
return
|
|
70
|
+
return current;
|
|
67
71
|
}
|
|
68
|
-
return addRepos(repos, [repo]);
|
|
72
|
+
return { ...current, repos: addRepos(current.repos, [repo]) };
|
|
69
73
|
});
|
|
70
74
|
if (!enrolled.ok)
|
|
71
75
|
return { ok: false, reason: enrolled.reason, message: `${projectName(repo)} wasn't added: ${enrolled.message}` };
|
|
72
76
|
if (refused)
|
|
73
77
|
return moved;
|
|
74
|
-
|
|
78
|
+
enrolledHere = !had;
|
|
75
79
|
}
|
|
76
|
-
const
|
|
77
|
-
if (!
|
|
78
|
-
return
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
if (
|
|
88
|
-
return
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
80
|
+
const giveBack = async (failure) => {
|
|
81
|
+
if (input.registryFile === null || !enrolledHere)
|
|
82
|
+
return failure;
|
|
83
|
+
let problem;
|
|
84
|
+
try {
|
|
85
|
+
const removed = await updateProjectRegistry(input.registryFile, current => !current.repos.includes(repo) || latestAdmission() > admittedBefore ? current : { ...current, repos: removeRepos(current.repos, [repo]) });
|
|
86
|
+
problem = removed.ok ? null : removed.message;
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
problem = error instanceof Error ? error.message : String(error);
|
|
90
|
+
}
|
|
91
|
+
if (problem === null)
|
|
92
|
+
return failure;
|
|
93
|
+
let unrecorded = "";
|
|
94
|
+
try {
|
|
95
|
+
store.recordAction({ at: input.now.toISOString(), actor: input.actor.label, repo, taskId: null, runId: null, action: PROJECT_ADD_INCOMPLETE, outcome: "rollback-failed", source: "access",
|
|
96
|
+
detail: `its line in the project list couldn't be taken back: ${problem}` });
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
unrecorded = ` It couldn't be recorded in the history either (${error instanceof Error ? error.message : String(error)}).`;
|
|
100
|
+
}
|
|
101
|
+
return { ok: false, reason: "incomplete", message: `${projectName(repo)} wasn't added, and its line in the project list couldn't be taken back (${problem}). Remove it with \`toolroll repos remove ${repo}\`.${unrecorded}` };
|
|
102
|
+
};
|
|
103
|
+
let added;
|
|
104
|
+
try {
|
|
105
|
+
added = store.transact(() => {
|
|
106
|
+
if (!allowed())
|
|
107
|
+
return null;
|
|
108
|
+
const rowHad = store.listProjects().some(one => one.path === repo);
|
|
109
|
+
const previous = store.projectRemote(repo);
|
|
110
|
+
const first = !known && !store.projectAdmissionKnown(repo);
|
|
111
|
+
remote = input.remoteUrl !== undefined ? { url: input.remoteUrl, why: null }
|
|
112
|
+
: first && discovered !== null ? discovered : { url: previous, why: previous === null ? "no remote recorded; use repos add --remote <url>" : null };
|
|
113
|
+
store.upsertProject(repo, projectName(repo), input.now, { remoteUrl: remote.url });
|
|
114
|
+
if (input.remoteUrl !== undefined)
|
|
115
|
+
store.recordProjectRemote(input.actor.label, repo, previous, input.remoteUrl, input.now);
|
|
116
|
+
input.withinAdmission?.(repo);
|
|
117
|
+
if (rowHad && !enrolledHere)
|
|
118
|
+
return false;
|
|
119
|
+
store.recordAction({ at: input.now.toISOString(), actor: input.actor.label, repo, taskId: null, runId: null, action: PROJECT_ADDED, outcome: "added", source: "access", detail: `from ${input.actor.origin}` });
|
|
120
|
+
return true;
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
return giveBack({ ok: false, reason: "failed", message: `${projectName(repo)} wasn't added: ${error instanceof Error ? error.message : String(error)}` });
|
|
96
125
|
}
|
|
97
|
-
|
|
126
|
+
if (added === null)
|
|
127
|
+
return giveBack(moved);
|
|
128
|
+
return { ok: true, repo, name: projectName(repo), added, remote, enrolled: enrolledHere };
|
|
98
129
|
}
|
|
99
130
|
export async function releaseProject(store, input) {
|
|
100
131
|
const unavailable = (error) => error instanceof FolderUnavailable;
|
package/dist/project.js
CHANGED
|
@@ -88,3 +88,76 @@ export function rowVisible(ceiling, repo) {
|
|
|
88
88
|
export function projectName(path) {
|
|
89
89
|
return basename(path);
|
|
90
90
|
}
|
|
91
|
+
export function expandHomePath(path, home) {
|
|
92
|
+
if (path === "~")
|
|
93
|
+
return home;
|
|
94
|
+
if (path.startsWith("~/"))
|
|
95
|
+
return resolve(home, path.slice(2));
|
|
96
|
+
if (path.startsWith("~"))
|
|
97
|
+
return null;
|
|
98
|
+
return path;
|
|
99
|
+
}
|
|
100
|
+
export const SYSTEM_TREES = ["/System", "/Library", "/usr", "/bin", "/sbin", "/etc", "/dev", "/private", "/var", "/proc", "/sys", "/boot", "/run", "/lib", "/lib64", "/cores", "/Network"];
|
|
101
|
+
export const SYSTEM_TOPS = ["/Applications", "/Volumes", "/Users", "/home", "/opt", "/mnt", "/media", "/srv", "/tmp", "/root", "/snap"];
|
|
102
|
+
export function comparisonPaths(home, protectedDirs) {
|
|
103
|
+
return ["/", home, resolve(home, "Library"), ...protectedDirs, ...SYSTEM_TOPS, ...SYSTEM_TREES];
|
|
104
|
+
}
|
|
105
|
+
export function comparisonsOf(found, protectedCount) {
|
|
106
|
+
const after = 3 + protectedCount;
|
|
107
|
+
const unread = { kind: "unreadable" };
|
|
108
|
+
return {
|
|
109
|
+
root: found[0] ?? unread, home: found[1] ?? unread, library: found[2] ?? unread,
|
|
110
|
+
protectedDirs: found.slice(3, after), tops: found.slice(after, after + SYSTEM_TOPS.length), trees: found.slice(after + SYSTEM_TOPS.length),
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
export function folderRefusal(kind, target, facts) {
|
|
114
|
+
const id = (one) => one.chain[0];
|
|
115
|
+
const lower = (path) => path.toLowerCase();
|
|
116
|
+
const underPath = (path, outer) => lower(path) === lower(outer) || lower(path).startsWith(outer === "/" ? "/" : `${lower(outer)}/`);
|
|
117
|
+
const within = (one, outer) => outer.kind === "found" ? one.chain.includes(id(outer)) : outer.kind === "missing" ? underPath(one.real, outer.path) : null;
|
|
118
|
+
const holds = (one, inner) => inner.kind === "found" ? inner.chain.includes(id(one)) : inner.kind === "missing" ? underPath(inner.path, one.real) : null;
|
|
119
|
+
const same = (one, other) => other.kind === "found" ? id(other) === id(one) : other.kind === "missing" ? lower(other.path) === lower(one.real) : null;
|
|
120
|
+
const cant = (why) => kind === "folder" ? `${why} can’t be the projects folder` : `${why} can’t be added`;
|
|
121
|
+
const unchecked = cant("a folder Toolroll couldn’t check against its own and the system’s folders");
|
|
122
|
+
const { root, home, library } = facts;
|
|
123
|
+
if (root.kind !== "found" || home.kind !== "found")
|
|
124
|
+
return unchecked;
|
|
125
|
+
if (id(target) === id(root))
|
|
126
|
+
return cant("the top of the disk");
|
|
127
|
+
if (id(target) === id(home))
|
|
128
|
+
return kind === "folder" ? "your home folder itself can’t be the projects folder. Choose a folder inside it, like ~/Developer" : "your home folder itself can’t be added";
|
|
129
|
+
if (holds(target, home))
|
|
130
|
+
return `that folder holds your home folder, so it can’t be ${kind === "folder" ? "the projects folder" : "added"}`;
|
|
131
|
+
for (const dir of facts.protectedDirs) {
|
|
132
|
+
const inDir = within(target, dir);
|
|
133
|
+
const holdsDir = dir.kind === "found" && id(dir) === id(home) ? false : holds(target, dir);
|
|
134
|
+
if (inDir === null || holdsDir === null)
|
|
135
|
+
return unchecked;
|
|
136
|
+
if ((dir.kind === "found" && id(dir) === id(home) ? false : inDir) || holdsDir)
|
|
137
|
+
return cant("a folder holding Toolroll’s own settings, records or task checkouts");
|
|
138
|
+
}
|
|
139
|
+
const inLibrary = within(target, library);
|
|
140
|
+
if (inLibrary === null)
|
|
141
|
+
return unchecked;
|
|
142
|
+
if (inLibrary)
|
|
143
|
+
return cant("a folder in ~/Library");
|
|
144
|
+
if (target.real.split("/").some(name => name.startsWith(".")))
|
|
145
|
+
return cant("a hidden folder");
|
|
146
|
+
if (within(target, home))
|
|
147
|
+
return null;
|
|
148
|
+
for (const top of facts.tops) {
|
|
149
|
+
const is = same(target, top);
|
|
150
|
+
if (is === null)
|
|
151
|
+
return unchecked;
|
|
152
|
+
if (is)
|
|
153
|
+
return cant("a system folder");
|
|
154
|
+
}
|
|
155
|
+
for (const tree of facts.trees) {
|
|
156
|
+
const under = within(target, tree);
|
|
157
|
+
if (under === null)
|
|
158
|
+
return unchecked;
|
|
159
|
+
if (under)
|
|
160
|
+
return cant("a system folder");
|
|
161
|
+
}
|
|
162
|
+
return null;
|
|
163
|
+
}
|
package/dist/repos.js
CHANGED
|
@@ -271,3 +271,40 @@ function bumpRegistryRemovals(file, lines, tag) {
|
|
|
271
271
|
writeFileSync(temp, `${JSON.stringify(counts)}\n`, { flag: "wx", mode: 0o600 });
|
|
272
272
|
renameFile(temp, registryRemovalsFile(file));
|
|
273
273
|
}
|
|
274
|
+
export function readProjectRegistryNow(file) {
|
|
275
|
+
let text;
|
|
276
|
+
try {
|
|
277
|
+
const fd = openFd(file, fsConstants.O_RDONLY);
|
|
278
|
+
try {
|
|
279
|
+
const size = fstatSync(fd).size;
|
|
280
|
+
if (size > 4 * 1024 * 1024)
|
|
281
|
+
return { error: `${file} is too large to be a Toolroll config` };
|
|
282
|
+
const buffer = Buffer.alloc(size);
|
|
283
|
+
let read = 0;
|
|
284
|
+
while (read < size) {
|
|
285
|
+
const got = readSync(fd, buffer, read, size - read, read);
|
|
286
|
+
if (got === 0)
|
|
287
|
+
break;
|
|
288
|
+
read += got;
|
|
289
|
+
}
|
|
290
|
+
text = buffer.subarray(0, read).toString("utf8");
|
|
291
|
+
}
|
|
292
|
+
finally {
|
|
293
|
+
closeFd(fd);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
catch (cause) {
|
|
297
|
+
if (cause.code === "ENOENT")
|
|
298
|
+
return { repos: [], roots: [] };
|
|
299
|
+
return { error: `${file} could not be read (${String(cause.message)})` };
|
|
300
|
+
}
|
|
301
|
+
let parsed;
|
|
302
|
+
try {
|
|
303
|
+
parsed = JSON.parse(text);
|
|
304
|
+
}
|
|
305
|
+
catch {
|
|
306
|
+
return { error: `${file} is not valid JSON` };
|
|
307
|
+
}
|
|
308
|
+
const registry = readProjectRegistryStrict(parsed);
|
|
309
|
+
return registry === null ? { error: `${file} does not look like a Toolroll config` } : { repos: sortUnique(registry.repos), roots: sortUnique(registry.roots) };
|
|
310
|
+
}
|
package/dist/route-hooks.js
CHANGED
|
@@ -11,6 +11,7 @@ const REVISION_CALLERS = [
|
|
|
11
11
|
{ file: "src/chat-review.ts", inside: "applyChatReview", calls: "createResultRevision", from: "./result-actions.js", args: true, why: "a confirmed review card passes the origin it was given" },
|
|
12
12
|
{ file: "src/lead-doors.ts", inside: "executeProposal", calls: "applyChatReview", from: "./chat-review.js", args: true, why: "a review card a person confirms is the person's; under a lead chain or remote run, the lead's" },
|
|
13
13
|
{ file: "src/task-outcome-cli.ts", inside: "runTaskOutcomeCommand", calls: "requestResultChanges", from: "./result-actions.js", args: true, why: "the command line tells a person from a lead or a machine" },
|
|
14
|
+
{ file: "src/task-outcome-cli.ts", inside: "reviseAsLocalOwner", calls: "requestResultChanges", from: "./result-actions.js", args: true, why: "the terminal's local owner is the person at this computer, in their own words" },
|
|
14
15
|
{ file: "src/server/tasks.ts", inside: "createTasksHandlers", calls: "requestResultChanges", from: "../result-actions.js", args: true, why: "a browser session is a person; a bearer credential a machine" },
|
|
15
16
|
{ file: "src/server/tasks.ts", inside: "createTasksHandlers", calls: "createResultRevision", from: "../result-actions.js", args: true, why: "a browser session is a person; a bearer credential a machine" },
|
|
16
17
|
];
|
package/dist/sample-project.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { randomBytes } from "node:crypto";
|
|
2
|
+
import { lstatSync, mkdirSync, readFileSync, rmSync, unlinkSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { dirname, isAbsolute, join } from "node:path";
|
|
3
4
|
import { run } from "./exec.js";
|
|
4
5
|
import { SAMPLE_PROJECT_NAME } from "./first-run.js";
|
|
6
|
+
import { admitProject } from "./project-admission.js";
|
|
7
|
+
import { authorizedProject, canonicalProject, rowVisible, unscoped } from "./project.js";
|
|
5
8
|
import { ENV, ENV_ALLOWLIST } from "./remote-main.js";
|
|
6
9
|
import { TEARDOWN_FLAGS } from "./teardown-git.js";
|
|
7
10
|
const MARKER = "toolroll-sample";
|
|
@@ -60,26 +63,49 @@ function isOurs(target) {
|
|
|
60
63
|
return false;
|
|
61
64
|
}
|
|
62
65
|
}
|
|
63
|
-
|
|
66
|
+
function removeMade(target, made) {
|
|
67
|
+
try {
|
|
68
|
+
const seen = lstatSync(target);
|
|
69
|
+
if (!seen.isDirectory() || seen.isSymbolicLink() || seen.dev !== made.dev || seen.ino !== made.ino)
|
|
70
|
+
return false;
|
|
71
|
+
const marker = join(target, ".git", MARKER);
|
|
72
|
+
if (kindOf(marker) !== "missing" && !isOurs(target))
|
|
73
|
+
return false;
|
|
74
|
+
rmSync(target, { recursive: true, force: true });
|
|
75
|
+
return kindOf(target) === "missing";
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
export async function createSampleProject(root, git = run, guard = () => true) {
|
|
82
|
+
const made = await claimSample(root, git, guard);
|
|
83
|
+
return made.ok ? { ok: true, path: made.path, created: made.created } : made;
|
|
84
|
+
}
|
|
85
|
+
async function claimSample(root, git, guard) {
|
|
64
86
|
if (root === null || root === "" || !isAbsolute(root) || kindOf(root) !== "dir") {
|
|
65
87
|
return { ok: false, reason: "no-root", message: "There's no project folder to put the sample in." };
|
|
66
88
|
}
|
|
67
89
|
const target = join(root, SAMPLE_PROJECT_NAME);
|
|
68
90
|
if (isOurs(target))
|
|
69
|
-
return { ok: true, path: target, created: false };
|
|
91
|
+
return { ok: true, path: target, created: false, identity: null };
|
|
92
|
+
const refused = { ok: false, reason: "refused", message: "Your access changed while the sample was being made. Nothing was added." };
|
|
93
|
+
if (!guard())
|
|
94
|
+
return refused;
|
|
95
|
+
let identity;
|
|
70
96
|
try {
|
|
71
97
|
mkdirSync(target);
|
|
98
|
+
const seen = lstatSync(target);
|
|
99
|
+
identity = { dev: seen.dev, ino: seen.ino };
|
|
72
100
|
}
|
|
73
101
|
catch {
|
|
74
102
|
return { ok: false, reason: "exists", message: `A folder named ${SAMPLE_PROJECT_NAME} is already there, so nothing was changed.` };
|
|
75
103
|
}
|
|
76
104
|
const fail = () => {
|
|
77
|
-
|
|
78
|
-
rmSync(target, { recursive: true, force: true });
|
|
79
|
-
}
|
|
80
|
-
catch { }
|
|
105
|
+
removeMade(target, identity);
|
|
81
106
|
return { ok: false, reason: "failed", message: "The sample project couldn't be made. Nothing was added." };
|
|
82
107
|
};
|
|
108
|
+
const stop = () => { removeMade(target, identity); return refused; };
|
|
83
109
|
try {
|
|
84
110
|
for (const [file, body] of Object.entries(FILES)) {
|
|
85
111
|
const path = join(target, file);
|
|
@@ -88,7 +114,11 @@ export async function createSampleProject(root, git = run) {
|
|
|
88
114
|
}
|
|
89
115
|
const options = { cwd: target, env: ENV, envAllowlist: ENV_ALLOWLIST, timeoutMs: 30_000 };
|
|
90
116
|
for (const args of [["init", "-q", "--template=", "-b", "main"], ["add", "--", "."], ["commit", "-q", "--no-verify", "-m", "Sample project"]]) {
|
|
117
|
+
if (!guard())
|
|
118
|
+
return stop();
|
|
91
119
|
const ran = await git("git", [...SAMPLE_FLAGS, ...args], options);
|
|
120
|
+
if (!guard())
|
|
121
|
+
return stop();
|
|
92
122
|
if (ran.code !== 0)
|
|
93
123
|
return fail();
|
|
94
124
|
}
|
|
@@ -97,7 +127,7 @@ export async function createSampleProject(root, git = run) {
|
|
|
97
127
|
catch {
|
|
98
128
|
return fail();
|
|
99
129
|
}
|
|
100
|
-
return { ok: true, path: target, created: true };
|
|
130
|
+
return { ok: true, path: target, created: true, identity };
|
|
101
131
|
}
|
|
102
132
|
export const SAMPLE_CHECK_COMMAND = "node --test";
|
|
103
133
|
const SAMPLE_CHECK_TIMEOUT_MS = 60_000;
|
|
@@ -114,3 +144,131 @@ export function registerSampleCheck(store, made, repo, addedBy, now) {
|
|
|
114
144
|
return true;
|
|
115
145
|
});
|
|
116
146
|
}
|
|
147
|
+
export function sampleRootOf(ceiling) {
|
|
148
|
+
if (unscoped(ceiling))
|
|
149
|
+
return null;
|
|
150
|
+
const root = ceiling.roots[0];
|
|
151
|
+
return root === undefined || root === "" || !isAbsolute(root) ? null : root.replace(/\/+$/, "") || null;
|
|
152
|
+
}
|
|
153
|
+
export async function addSampleProject(input) {
|
|
154
|
+
const { authority } = input;
|
|
155
|
+
if (!authority.stands())
|
|
156
|
+
return { ok: false, reason: "refused" };
|
|
157
|
+
const root = sampleRootOf(input.ceiling());
|
|
158
|
+
if (root === null)
|
|
159
|
+
return { ok: false, reason: "no-root" };
|
|
160
|
+
const expected = join(root, SAMPLE_PROJECT_NAME);
|
|
161
|
+
const rootServed = (ceiling) => !unscoped(ceiling) && ceiling.roots.some(one => one.replace(/\/+$/, "") === root);
|
|
162
|
+
const standing = () => !authority.stands() ? "refused" : !rootServed(input.ceiling()) ? "not-added" : null;
|
|
163
|
+
const lock = sampleLock(input.registryFile === null ? join(root, ".toolroll-sample.lock") : `${input.registryFile}.sample.lock`);
|
|
164
|
+
if (!(await lock.take()))
|
|
165
|
+
return { ok: false, reason: "not-added" };
|
|
166
|
+
try {
|
|
167
|
+
return await addHolding(input, root, expected, rootServed, standing);
|
|
168
|
+
}
|
|
169
|
+
finally {
|
|
170
|
+
lock.release();
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
async function addHolding(input, root, expected, rootServed, standing) {
|
|
174
|
+
const { store, authority } = input;
|
|
175
|
+
const made = await claimSample(root, input.git ?? run, () => standing() === null);
|
|
176
|
+
if (!made.ok)
|
|
177
|
+
return { ok: false, reason: made.reason === "refused" ? standing() ?? "refused" : made.reason };
|
|
178
|
+
const undo = (reason) => {
|
|
179
|
+
if (made.identity !== null && !store.listProjects().some(one => one.path === made.path))
|
|
180
|
+
removeMade(made.path, made.identity);
|
|
181
|
+
return { ok: false, reason };
|
|
182
|
+
};
|
|
183
|
+
const after = standing();
|
|
184
|
+
if (after !== null)
|
|
185
|
+
return undo(after);
|
|
186
|
+
const decidedOn = input.generation?.() ?? null;
|
|
187
|
+
const canonical = await (input.resolveFolder ?? (async (path) => canonicalProject(path)))(made.path);
|
|
188
|
+
const later = standing();
|
|
189
|
+
if (later !== null)
|
|
190
|
+
return undo(later);
|
|
191
|
+
const visible = (repo) => input.visible === undefined || input.visible(repo);
|
|
192
|
+
const servedBy = (ceiling, repo) => repo === expected && rootServed(ceiling) && rowVisible(ceiling, repo);
|
|
193
|
+
if (canonical === null || canonical === "no-answer" || canonical !== expected || !servedBy(input.ceiling(), canonical)
|
|
194
|
+
|| !(await authorizedProject(input.ceiling(), canonical)) || !visible(canonical))
|
|
195
|
+
return undo("not-added");
|
|
196
|
+
const stillAllowed = (repo) => repo === canonical && authority.stands()
|
|
197
|
+
&& (decidedOn === null || input.generation?.() === decidedOn) && servedBy(input.ceiling(), repo) && visible(repo);
|
|
198
|
+
let checkSet = false;
|
|
199
|
+
const admitted = await admitProject(store, {
|
|
200
|
+
registryFile: input.registryFile, path: canonical, actor: authority.actor, now: input.now, stillAllowed,
|
|
201
|
+
registryAllowed: (repo, registry) => stillAllowed(repo) && servedBy(input.ceiling(registry), repo),
|
|
202
|
+
withinAdmission: repo => { checkSet = registerSampleCheck(store, made, repo, authority.actor.label, input.now); },
|
|
203
|
+
...(input.resolveFolder === undefined ? {} : { resolveFolder: input.resolveFolder }),
|
|
204
|
+
});
|
|
205
|
+
if (!admitted.ok) {
|
|
206
|
+
if (admitted.reason === "incomplete")
|
|
207
|
+
return { ok: false, reason: "incomplete", message: admitted.message };
|
|
208
|
+
return undo(standing() ?? "not-added");
|
|
209
|
+
}
|
|
210
|
+
return { ok: true, repo: admitted.repo, created: made.created, added: admitted.added, checkSet };
|
|
211
|
+
}
|
|
212
|
+
function sampleLock(path) {
|
|
213
|
+
const token = `${process.pid}.${randomBytes(8).toString("hex")}`;
|
|
214
|
+
let held = false;
|
|
215
|
+
return {
|
|
216
|
+
async take() {
|
|
217
|
+
try {
|
|
218
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
219
|
+
}
|
|
220
|
+
catch {
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
const deadline = Date.now() + 60_000;
|
|
224
|
+
while (Date.now() < deadline) {
|
|
225
|
+
try {
|
|
226
|
+
writeFileSync(path, token, { flag: "wx", mode: 0o600 });
|
|
227
|
+
held = true;
|
|
228
|
+
return true;
|
|
229
|
+
}
|
|
230
|
+
catch (error) {
|
|
231
|
+
if (error.code !== "EEXIST")
|
|
232
|
+
return false;
|
|
233
|
+
}
|
|
234
|
+
let seen = "";
|
|
235
|
+
try {
|
|
236
|
+
seen = readFileSync(path, "utf8");
|
|
237
|
+
}
|
|
238
|
+
catch {
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
const owner = Number(seen.split(".")[0]);
|
|
242
|
+
let gone = !Number.isInteger(owner) || owner <= 0;
|
|
243
|
+
if (!gone) {
|
|
244
|
+
try {
|
|
245
|
+
process.kill(owner, 0);
|
|
246
|
+
}
|
|
247
|
+
catch (error) {
|
|
248
|
+
gone = error.code === "ESRCH";
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
if (gone) {
|
|
252
|
+
try {
|
|
253
|
+
if (readFileSync(path, "utf8") === seen)
|
|
254
|
+
unlinkSync(path);
|
|
255
|
+
}
|
|
256
|
+
catch { }
|
|
257
|
+
continue;
|
|
258
|
+
}
|
|
259
|
+
await new Promise(resolve => setTimeout(resolve, 50));
|
|
260
|
+
}
|
|
261
|
+
return false;
|
|
262
|
+
},
|
|
263
|
+
release() {
|
|
264
|
+
if (!held)
|
|
265
|
+
return;
|
|
266
|
+
held = false;
|
|
267
|
+
try {
|
|
268
|
+
if (readFileSync(path, "utf8") === token)
|
|
269
|
+
unlinkSync(path);
|
|
270
|
+
}
|
|
271
|
+
catch { }
|
|
272
|
+
},
|
|
273
|
+
};
|
|
274
|
+
}
|
package/dist/scope.js
CHANGED
|
@@ -1243,8 +1243,20 @@ const LOCAL_RETRY_WORDS = {
|
|
|
1243
1243
|
unsandboxed: "This project's checks run without a sandbox, so retrying needs your password.",
|
|
1244
1244
|
imported: "A task from outside needs your password to retry.",
|
|
1245
1245
|
};
|
|
1246
|
+
const LOCAL_REVISE_WORDS = {
|
|
1247
|
+
"local-mode-off": "Local mode is off, so sending this result back needs your password.",
|
|
1248
|
+
"not-owner": "Only this computer's owner sends results back here without a password.",
|
|
1249
|
+
"no-scope": "This task has no plan, so sending its result back needs your password.",
|
|
1250
|
+
release: "Sending a release back needs your password.",
|
|
1251
|
+
protected: "This result is protected work, so sending it back needs your password.",
|
|
1252
|
+
escalated: "Work with wider permissions needs your password to send back.",
|
|
1253
|
+
coordinator: "Work a coordinator filed needs your password to send back.",
|
|
1254
|
+
unsandboxed: "This project's checks run without a sandbox, so sending back needs your password.",
|
|
1255
|
+
imported: "A task from outside needs your password to send back.",
|
|
1256
|
+
};
|
|
1246
1257
|
export function localWorkEligible(store, by, taskId, purpose) {
|
|
1247
|
-
const words = purpose.act === "approve" ? LOCAL_APPROVAL_WORDS : purpose.act === "complete" ? LOCAL_COMPLETION_WORDS : purpose.act === "
|
|
1258
|
+
const words = purpose.act === "approve" ? LOCAL_APPROVAL_WORDS : purpose.act === "complete" ? LOCAL_COMPLETION_WORDS : purpose.act === "revise" ? LOCAL_REVISE_WORDS
|
|
1259
|
+
: purpose.act === "plan" ? LOCAL_PLAN_WORDS : LOCAL_RETRY_WORDS;
|
|
1248
1260
|
const no = (reason) => ({ ok: false, reason, message: words[reason] });
|
|
1249
1261
|
if (!localModeOn(store))
|
|
1250
1262
|
return no("local-mode-off");
|
|
@@ -1281,7 +1293,7 @@ export function localWorkEligible(store, by, taskId, purpose) {
|
|
|
1281
1293
|
}
|
|
1282
1294
|
if (ref === undefined || ref["coordinator_cid"] != null)
|
|
1283
1295
|
return no("coordinator");
|
|
1284
|
-
if (purpose.act === "complete")
|
|
1296
|
+
if (purpose.act === "complete" || purpose.act === "revise")
|
|
1285
1297
|
return { ok: true };
|
|
1286
1298
|
if ((purpose.act === "plan" || purpose.act === "retry") && issueImported(store, taskId))
|
|
1287
1299
|
return no("imported");
|
|
@@ -1290,3 +1302,6 @@ export function localWorkEligible(store, by, taskId, purpose) {
|
|
|
1290
1302
|
return no("unsandboxed");
|
|
1291
1303
|
return { ok: true };
|
|
1292
1304
|
}
|
|
1305
|
+
export function typedPasswordNow(proved) {
|
|
1306
|
+
return proved.ok && proved.method === "password-now";
|
|
1307
|
+
}
|
package/dist/serve.js
CHANGED
|
@@ -128,7 +128,7 @@ import { createBrowserKeys, KEY_FILL_SCRIPT, pagePathOf } from './server/mutatio
|
|
|
128
128
|
import { DEFAULT_GUARD_POLICY, passwordGuardOf, provenPasswordAccount, SourceBudget, withPasswordSource } from "./sign-in-guard.js";
|
|
129
129
|
import { sourceKey } from "./source-key.js";
|
|
130
130
|
import { readSsoSettings } from "./sso-settings.js";
|
|
131
|
-
import { LEAD_THREAD, latestLeadTurnOfThread, localOwnerBinding } from "./store.js";
|
|
131
|
+
import { LEAD_THREAD, latestLeadTurnOfThread, localOwnerBinding, projectRowKnown } from "./store.js";
|
|
132
132
|
import { waitingUpdate } from "./toolroll-update.js";
|
|
133
133
|
import { PACKAGE_VERSION } from "./version.js";
|
|
134
134
|
import { loadConsoleUrl } from "./webhooks.js";
|
|
@@ -291,7 +291,7 @@ export function createDecisionServer(options) {
|
|
|
291
291
|
const known = store.accountOf(account);
|
|
292
292
|
if (known === null || known.role !== "approver" || known.revokedAt !== null || !known.passwordSet)
|
|
293
293
|
return null;
|
|
294
|
-
return holdSignInLink({ kind: "full", account, expires: Date.now() + SIGN_IN_LINK_MS });
|
|
294
|
+
return holdSignInLink({ kind: "full", account, accountGeneration: known.generation, expires: Date.now() + SIGN_IN_LINK_MS });
|
|
295
295
|
}
|
|
296
296
|
const keyEpoch = options.keyEpoch ?? randomBytes(16).toString("hex");
|
|
297
297
|
const fromThisComputer = (request) => requestFromThisComputer(request);
|
|
@@ -356,10 +356,12 @@ export function createDecisionServer(options) {
|
|
|
356
356
|
const { ceiling, unresolved: unresolvedRepos, defaultProject, configured, configuredPaths } = startupCeiling([...(options.repo === undefined ? [] : [options.repo]), ...(options.repos ?? [])], options.projectRoots ?? [], options.identities === undefined ? undefined : identities, identities.strict);
|
|
357
357
|
const unscopedMode = !configured && options.admittedRepos === undefined;
|
|
358
358
|
const exactRepos = () => options.admittedRepos?.() ?? ceiling.repos;
|
|
359
|
+
const consoleAdmitted = new Set();
|
|
359
360
|
const liveCeiling = () => {
|
|
360
|
-
const repos = [...exactRepos(), ...(options.additionalProjectRepos?.() ?? [])];
|
|
361
|
+
const repos = [...exactRepos(), ...(options.additionalProjectRepos?.() ?? []), ...stillAdmitted(consoleAdmitted, deletedRepos, repo => projectRowKnown(store, repo))];
|
|
361
362
|
return { repos: repos.length === 0 && ceiling.roots.length === 0 && !unscopedMode ? [NO_PROJECT] : repos, roots: ceiling.roots, canon: identities.strict };
|
|
362
363
|
};
|
|
364
|
+
const outsideAdmissions = outsideAdmissionsOf(consoleAdmitted);
|
|
363
365
|
const deletedRepos = new Set();
|
|
364
366
|
const goneRepos = () => {
|
|
365
367
|
if (deletedRepos.size === 0)
|
|
@@ -1920,6 +1922,7 @@ export function createDecisionServer(options) {
|
|
|
1920
1922
|
get identities() { return identities; },
|
|
1921
1923
|
get keyEpoch() { return keyEpoch; },
|
|
1922
1924
|
get browserKeys() { return browserKeys; },
|
|
1925
|
+
get outsideAdmissions() { return outsideAdmissions; },
|
|
1923
1926
|
};
|
|
1924
1927
|
const tasksHandlers = createTasksHandlers(handlerRuntime);
|
|
1925
1928
|
const pagesHandlers = createPagesHandlers(handlerRuntime);
|
|
@@ -2066,3 +2069,12 @@ function consoleFolders(options, identities, work) {
|
|
|
2066
2069
|
}
|
|
2067
2070
|
return inFolderScope(gate, work);
|
|
2068
2071
|
}
|
|
2072
|
+
function stillAdmitted(admitted, gone, added) {
|
|
2073
|
+
for (const repo of admitted)
|
|
2074
|
+
if (gone.has(repo) || !added(repo))
|
|
2075
|
+
admitted.delete(repo);
|
|
2076
|
+
return [...admitted];
|
|
2077
|
+
}
|
|
2078
|
+
function outsideAdmissionsOf(admitted) {
|
|
2079
|
+
return { admit: repo => { admitted.add(repo); } };
|
|
2080
|
+
}
|
package/dist/server/live.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { randomBytes } from "node:crypto";
|
|
2
2
|
import { boardRunOf } from "../agent-board.js";
|
|
3
3
|
import { agentRunFingerprint } from "../agents-board.js";
|
|
4
|
-
import { createLiveRooms, LiveConnection } from "../live-bus.js";
|
|
4
|
+
import { createLiveRooms, KEEP_ALIVE_MS, LiveConnection } from "../live-bus.js";
|
|
5
5
|
import { reproveRemote } from "../operate-remote.js";
|
|
6
6
|
import { rowVisible } from "../project.js";
|
|
7
7
|
import { createLiveSender, LIVE_STATUS } from "../live-reply.js";
|
|
@@ -12,6 +12,8 @@ import { adapterPolicy } from "./route-policy.js";
|
|
|
12
12
|
import { requestContext } from "./request-context.js";
|
|
13
13
|
import { createAgentsLiveRooms } from "./agents-live-room.js";
|
|
14
14
|
import { leadTilesFor } from "./agents-live-lead.js";
|
|
15
|
+
export const LIVE_FRAMES_HEADER = "x-toolroll-live";
|
|
16
|
+
const INCARNATION = randomBytes(9).toString("hex");
|
|
15
17
|
export const LIVE_ROOMS_PER_PAGE = 6;
|
|
16
18
|
const ROOM_NAME = /^(workspace|task|flow|chat|team|agent|summary|agents-live)(?::([^?]{1,400}))?(?:\?([^#]{0,600}))?$/;
|
|
17
19
|
const WORKSPACE_SETTLE_MS = 1_000;
|
|
@@ -327,7 +329,8 @@ export function createLiveHandlers(runtime, live) {
|
|
|
327
329
|
}
|
|
328
330
|
response.writeHead(200, { "content-type": "text/event-stream", "cache-control": "no-store", "x-content-type-options": "nosniff", "x-accel-buffering": "no" });
|
|
329
331
|
response.flushHeaders();
|
|
330
|
-
const connection = new LiveConnection(response);
|
|
332
|
+
const connection = new LiveConnection(response, { frames: request.headers[LIVE_FRAMES_HEADER] === "1" });
|
|
333
|
+
connection.hello({ incarnation: INCARNATION, tick: KEEP_ALIVE_MS });
|
|
331
334
|
for (const join of joins)
|
|
332
335
|
if (connection.open)
|
|
333
336
|
join(connection);
|