toolroll 0.9.109 → 0.9.110
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 +35 -0
- package/dist/agent-detect.js +244 -0
- package/dist/agent-fence.js +12 -1
- package/dist/agentconfig.js +2 -2
- package/dist/approval-summary.js +344 -0
- package/dist/attest.js +2 -2
- package/dist/browser/workspace.css +2 -2
- package/dist/browser/workspace.js +27 -27
- package/dist/builder.js +36 -2
- package/dist/chat-actions.js +24 -17
- package/dist/chat-core.js +3 -1
- package/dist/chat-decide.js +101 -46
- package/dist/chat-delivery-state.js +2 -0
- package/dist/chat-delivery.js +3 -2
- package/dist/chat-live.js +2 -1
- package/dist/chat-task-actions.js +6 -0
- package/dist/check-report.js +1 -1
- package/dist/cli.js +2 -0
- package/dist/console-instance.js +10 -1
- package/dist/contracts/console-api.js +10 -5
- package/dist/contracts/engine-api.js +271 -0
- package/dist/coordinator.js +2 -2
- package/dist/discord-api.js +4 -3
- package/dist/discord-chat.js +3 -1
- package/dist/easy-start-args.js +7 -3
- package/dist/easy-start.js +25 -0
- package/dist/egress.js +72 -10
- package/dist/engine-handoff.js +34 -0
- package/dist/engine-reads.js +261 -0
- package/dist/eval-world.js +3 -2
- package/dist/evidence.js +2 -0
- package/dist/fast-start.js +55 -14
- package/dist/fast-terms.js +2 -2
- package/dist/first-run.js +10 -2
- package/dist/flexible-agents.js +234 -0
- package/dist/flexible-answers-schema.js +61 -0
- package/dist/flexible-answers.js +889 -0
- package/dist/flexible-custody.js +494 -0
- package/dist/flexible-import.js +782 -0
- package/dist/flexible-launch-schema.js +72 -0
- package/dist/flexible-launch.js +331 -0
- package/dist/flexible-launcher.js +88 -0
- package/dist/flexible-levels.js +34 -0
- package/dist/flexible-merge-guard.js +47 -0
- package/dist/flexible-refs.js +47 -0
- package/dist/flexible-relay-cancel.js +19 -0
- package/dist/flexible-relay-schema.js +55 -0
- package/dist/flexible-relay-upstreams.js +36 -0
- package/dist/flexible-relay.js +1032 -0
- package/dist/flexible-session.js +732 -0
- package/dist/flexible-ship-schema.js +81 -0
- package/dist/flexible-ship.js +694 -0
- package/dist/flexible-start.js +80 -0
- package/dist/flexible-thread.js +175 -25
- package/dist/flexible-turns-schema.js +69 -0
- package/dist/flexible-turns.js +490 -0
- package/dist/flexible.js +10 -1
- package/dist/flow-actions.js +6 -4
- package/dist/flow-steps.js +1 -1
- package/dist/flows-cli.js +2 -1
- package/dist/git-views.js +6 -3
- package/dist/install-mode.js +225 -0
- package/dist/lead-doors.js +7 -1
- package/dist/limits-ui.js +7 -0
- package/dist/live-reply.js +6 -0
- package/dist/live-terminal.js +425 -29
- package/dist/local-owner.js +6 -0
- package/dist/model-choices.js +12 -6
- package/dist/notification-delivery.js +11 -0
- package/dist/operate.js +74 -30
- package/dist/outbound-privacy.js +204 -0
- package/dist/passwordless.js +2 -1
- package/dist/project-delete.js +14 -0
- package/dist/provider-connection.js +5 -3
- package/dist/publish.js +5 -0
- package/dist/pull-request-flow.js +26 -7
- package/dist/push.js +5 -1
- package/dist/release-card.js +11 -3
- package/dist/release.js +10 -1
- package/dist/route-store.js +2 -2
- package/dist/sandbox-launch.js +32 -8
- package/dist/sandbox-runtime.js +16 -7
- package/dist/sandbox-tools.js +176 -0
- package/dist/scope.js +12 -36
- package/dist/scout-net.js +7 -2
- package/dist/serve.js +58 -11
- package/dist/server/chrome.js +3 -1
- package/dist/server/console.css +33 -6
- package/dist/server/engine-api.js +378 -0
- package/dist/server/flows.js +2 -2
- package/dist/server/http.js +7 -0
- package/dist/server/link-redemption.js +52 -0
- package/dist/server/mutation-key.js +21 -7
- package/dist/server/pages.js +69 -40
- package/dist/server/people-tokens.js +17 -41
- package/dist/server/render-chat.js +1 -0
- package/dist/server/render-new-task.js +3 -3
- package/dist/server/render-results.js +4 -4
- package/dist/server/render-tasks.js +129 -138
- package/dist/server/route-table.js +30 -1
- package/dist/server/settings-section-table.js +3 -0
- package/dist/server/settings-sections.js +33 -0
- package/dist/server/settings.js +84 -10
- package/dist/server/task-views.js +8 -2
- package/dist/server/tasks.js +25 -8
- package/dist/server/terminals.js +181 -28
- package/dist/server/welcome.js +35 -10
- package/dist/settings-groups-ui.js +2 -2
- package/dist/settings-proofs.js +13 -9
- package/dist/slack-api.js +4 -3
- package/dist/slack-chat.js +5 -3
- package/dist/spend.js +46 -12
- package/dist/status-probe.js +343 -0
- package/dist/store.js +102 -5
- package/dist/teams-api.js +4 -3
- package/dist/teams-chat.js +4 -2
- package/dist/telegram-lead.js +2 -1
- package/dist/telegram-live.js +2 -1
- package/dist/telegram-team.js +2 -1
- package/dist/telegram.js +17 -5
- package/dist/trusted-path.js +162 -0
- package/dist/tui/darwin-arm64/toolroll-tui +0 -0
- package/dist/tui/darwin-x64/toolroll-tui +0 -0
- package/dist/tui/linux-arm64/toolroll-tui +0 -0
- package/dist/tui/linux-x64/toolroll-tui +0 -0
- package/dist/tui-launch.js +282 -0
- package/dist/tui-source.js +5 -3
- package/dist/tui.js +1 -1
- package/dist/webhooks.js +8 -4
- package/dist/welcome-facts.js +22 -15
- package/dist/workspace-ui.js +5 -0
- package/package.json +1 -1
- package/scripts/crash-canary.mjs +1 -1
- package/scripts/pilot.mjs +1 -1
- package/scripts/provider-canary.mjs +5 -3
package/dist/server/terminals.js
CHANGED
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
import { randomBytes } from "node:crypto";
|
|
2
2
|
import { STATUS_CODES } from "node:http";
|
|
3
3
|
import { dirname, join } from "node:path";
|
|
4
|
-
import { KEY_PROTOCOL } from "./mutation-key.js";
|
|
4
|
+
import { KEY_PROTOCOL, TERMINAL_EPOCH } from "./mutation-key.js";
|
|
5
5
|
import { WebSocketServer } from "ws";
|
|
6
6
|
import { readForm, CONSOLE_FORMS } from "../contracts/console-api.js";
|
|
7
7
|
import { html, htmlString } from "../html.js";
|
|
8
8
|
import { openTerminalLedger } from "../terminal-catalog.js";
|
|
9
9
|
import { loadPtySpawn, MAX_FRAME_BYTES, TerminalHost, MAX_VIEWERS, parseTerminalFrame, TERMINAL_PROGRAMS, TerminalError } from "../live-terminal.js";
|
|
10
10
|
import { logEvent } from "../log.js";
|
|
11
|
-
import {
|
|
11
|
+
import { sessionStandsIn, soloNow } from "../install-mode.js";
|
|
12
|
+
import { localOwnerStandsNow } from "../local-owner.js";
|
|
13
|
+
import { resultRunsOf } from "../engine-reads.js";
|
|
14
|
+
import { checkEngineResponse } from "../contracts/engine-api.js";
|
|
12
15
|
import { projectName, rowVisible } from "../project.js";
|
|
13
16
|
import { transportOf } from "../public-access.js";
|
|
17
|
+
import { agentSetupOf } from "../agent-detect.js";
|
|
18
|
+
import { excludedFolders, launchPath, resolveLaunch, statusEnvironment } from "../status-probe.js";
|
|
19
|
+
import { boundedAcl } from "../trusted-path.js";
|
|
14
20
|
import { handlersOf } from "./handler-registry.js";
|
|
15
21
|
import { respond } from "./http.js";
|
|
16
22
|
import { rereadBrowser } from "./live.js";
|
|
@@ -30,7 +36,8 @@ export function terminalHostFor(store, options) {
|
|
|
30
36
|
if (spawn === null)
|
|
31
37
|
return { host: null, problem: "This install has no terminal support (the optional @lydell/node-pty package didn't load). Reinstall Toolroll to add it." };
|
|
32
38
|
const ledger = openTerminalLedger(store.raw());
|
|
33
|
-
|
|
39
|
+
const buildWritable = () => [dirname(database), ...store.knownRepos()];
|
|
40
|
+
return { host: new TerminalHost({ spawn, worktreeRoot: join(dirname(database), "live-worktrees"), buildWritable, ...(ledger === null ? {} : { ledger }) }), problem: null };
|
|
34
41
|
}
|
|
35
42
|
export function createTerminalHandlers(runtime, deps) {
|
|
36
43
|
const { store, codingActorAllowed, codingProjectAllowed, liveCeiling } = runtime;
|
|
@@ -39,14 +46,42 @@ export function createTerminalHandlers(runtime, deps) {
|
|
|
39
46
|
const sockets = new Set();
|
|
40
47
|
const wss = new WebSocketServer({ noServer: true, maxPayload: MAX_FRAME_BYTES, perMessageDeflate: false,
|
|
41
48
|
handleProtocols: protocols => protocols.has(KEY_PROTOCOL) ? KEY_PROTOCOL : false });
|
|
42
|
-
const
|
|
49
|
+
const localOwnerNow = (who) => {
|
|
50
|
+
const hash = runtime.sessions.hashOf(who.session);
|
|
51
|
+
return who.session.localGeneration !== null && hash !== null && soloNow(store)
|
|
52
|
+
&& localOwnerStandsNow(store, { account: who.name, localGeneration: who.session.localGeneration, accountGeneration: who.session.generation,
|
|
53
|
+
transport: "browser", act: "take-over", sessionHash: hash, request: null });
|
|
54
|
+
};
|
|
55
|
+
const operatorOf = (who) => {
|
|
56
|
+
if (who?.via !== "cookie" || who.role !== "approver" || store.isDemo() || !codingActorAllowed({ name: who.name, generation: who.session.generation }))
|
|
57
|
+
return null;
|
|
58
|
+
if (who.authority === "full")
|
|
59
|
+
return who;
|
|
60
|
+
return who.authority === "local-owner" && localOwnerNow(who) ? who : null;
|
|
61
|
+
};
|
|
43
62
|
const projectAllowed = (name, repo) => rowVisible(liveCeiling(), repo) && store.accountCanAccess(name, repo) && codingProjectAllowed(repo);
|
|
44
|
-
const owned = (who, terminal) => terminal !== null && terminal.owner === who.name && terminal.generation === who.session.generation
|
|
63
|
+
const owned = (who, terminal) => terminal !== null && terminal.owner === who.name && terminal.generation === who.session.generation
|
|
64
|
+
&& terminal.localGeneration === (who.authority === "full" ? null : who.session.localGeneration);
|
|
65
|
+
const reachable = (who, terminal, request) => owned(who, terminal) && (terminal.agent !== null ? workbenchNow(request, who) : projectAllowed(who.name, terminal.repo));
|
|
66
|
+
const workbenchNow = (request, who) => {
|
|
67
|
+
if (who?.via !== "cookie" || who.authority !== "local-owner")
|
|
68
|
+
return false;
|
|
69
|
+
const epoch = `${TERMINAL_EPOCH}${runtime.keyEpoch}`;
|
|
70
|
+
if (who.session.keyEpoch !== epoch)
|
|
71
|
+
return false;
|
|
72
|
+
const hash = runtime.sessions.hashOf(who.session);
|
|
73
|
+
if (hash === null || store.webSession(hash)?.keyEpoch !== epoch)
|
|
74
|
+
return false;
|
|
75
|
+
return soloNow(store) && runtime.fromThisComputer(request) && operatorOf(who) !== null;
|
|
76
|
+
};
|
|
45
77
|
const record = (event, who, terminal) => logEvent("info", `terminal.${event}`, { actor: who, terminal: terminal.id, repo: terminal.repo, program: terminal.program });
|
|
46
78
|
const json = (ctx, status, value) => respond(ctx.response, status, "application/json", JSON.stringify(value));
|
|
79
|
+
const checked = (ctx, status, name, value) => json(ctx, status, checkEngineResponse(name, value));
|
|
80
|
+
const WORKBENCH_ONLY = "Sign in to agents from your own terminal: run toolroll there";
|
|
81
|
+
const LOCAL_TEAM = "Taking over works while you're the only person using this Toolroll. Set a password (run `toolroll password set`) and sign in with it.";
|
|
47
82
|
const refusal = (ctx) => {
|
|
48
83
|
if (operatorOf(ctx.who) === null)
|
|
49
|
-
return "Terminals are for installation-wide operators signed in with a browser.";
|
|
84
|
+
return ctx.who?.via === "cookie" && ctx.who.authority === "local-owner" ? LOCAL_TEAM : "Terminals are for installation-wide operators signed in with a browser.";
|
|
50
85
|
if (deps.host === null)
|
|
51
86
|
return deps.problem ?? "Terminals aren't available on this install.";
|
|
52
87
|
return null;
|
|
@@ -58,7 +93,7 @@ export function createTerminalHandlers(runtime, deps) {
|
|
|
58
93
|
const id = TERMINAL_ID.exec(url.pathname)?.[1] ?? "";
|
|
59
94
|
const nonce = randomBytes(16).toString("base64");
|
|
60
95
|
const host = request.headers.host ?? "";
|
|
61
|
-
const document = html `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover, interactive-widget=resizes-content"><meta name="theme-color" content="#0C0E12"><meta name="apple-mobile-web-app-capable" content="yes"><title>Terminals — Toolroll</title><link rel="icon" href="/icon.svg"><link rel="manifest" href="/manifest.webmanifest"><link rel="stylesheet" href="/assets/terminal.css"></head><body><div id="so-term"></div><div id="so-term-boot" hidden data-csrf="${who.session.csrf}" data-session="${id}" data-passwordless="${
|
|
96
|
+
const document = html `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover, interactive-widget=resizes-content"><meta name="theme-color" content="#0C0E12"><meta name="apple-mobile-web-app-capable" content="yes"><title>Terminals — Toolroll</title><link rel="icon" href="/icon.svg"><link rel="manifest" href="/manifest.webmanifest"><link rel="stylesheet" href="/assets/terminal.css"></head><body><div id="so-term"></div><div id="so-term-boot" hidden data-csrf="${who.session.csrf}" data-session="${id}" data-passwordless="${sessionStandsIn(store) || who.authority === "local-owner" ? "1" : ""}"></div><script type="module" src="/assets/terminal.js" nonce="${nonce}"></script></body></html>`;
|
|
62
97
|
response.writeHead(200, {
|
|
63
98
|
"Content-Type": "text/html; charset=utf-8", "Cache-Control": "no-store", "X-Content-Type-Options": "nosniff", "Referrer-Policy": "no-referrer",
|
|
64
99
|
"Content-Security-Policy": `default-src 'none'; style-src 'self' 'unsafe-inline'; font-src 'self'; img-src 'self'; manifest-src 'self'; script-src 'nonce-${nonce}'; connect-src 'self' ws://${host} wss://${host}; form-action 'self'; base-uri 'none'; frame-ancestors 'none'`,
|
|
@@ -68,63 +103,176 @@ export function createTerminalHandlers(runtime, deps) {
|
|
|
68
103
|
async function state(ctx) {
|
|
69
104
|
const who = operatorOf(ctx.who);
|
|
70
105
|
if (who === null)
|
|
71
|
-
return
|
|
72
|
-
const sessions = deps.host === null ? [] : deps.host.list(who.name).filter(one => owned(who, one) && projectAllowed(who.name, one.repo));
|
|
73
|
-
return
|
|
106
|
+
return checked(ctx, 403, "refusal", { error: "operator" });
|
|
107
|
+
const sessions = deps.host === null ? [] : deps.host.list(who.name).filter(one => one.agent === null && owned(who, one) && projectAllowed(who.name, one.repo));
|
|
108
|
+
return checked(ctx, 200, "termState", {
|
|
74
109
|
available: deps.host !== null, problem: deps.host === null ? deps.problem ?? "Terminals aren't available on this install." : null,
|
|
75
|
-
programs: TERMINAL_PROGRAMS,
|
|
110
|
+
programs: [...TERMINAL_PROGRAMS],
|
|
76
111
|
projects: runtime.consoleProjects().filter(repo => projectAllowed(who.name, repo)).map(path => ({ path, name: projectName(path) })),
|
|
77
|
-
sessions: sessions.map(one => ({ id: one.id, repo: one.repo, project: projectName(one.repo), program: one.program, branch: one.branch, startedAt: one.startedAt, endedAt: one.endedAt,
|
|
112
|
+
sessions: sessions.map(one => ({ id: one.id, repo: one.repo, project: projectName(one.repo), program: one.program, branch: one.branch, startedAt: one.startedAt, endedAt: one.endedAt,
|
|
113
|
+
exit: one.exit, cleanup: one.cleanup, task: one.task, run: one.run })),
|
|
78
114
|
});
|
|
79
115
|
}
|
|
116
|
+
const takeOverOf = (taskId, runId) => {
|
|
117
|
+
const family = runtime.familyOf(taskId);
|
|
118
|
+
if (family === null || family.problem !== null)
|
|
119
|
+
return "No such task.";
|
|
120
|
+
const run = resultRunsOf(store, family).filter(one => runtime.runVisible(one)).find(one => one.id === runId) ?? null;
|
|
121
|
+
if (run === null)
|
|
122
|
+
return "This build has no saved result yet. Wait for it to finish (or stop it), then take over.";
|
|
123
|
+
const revision = run.headRevision;
|
|
124
|
+
if (revision === null || !/^[0-9a-f]{40}(?:[0-9a-f]{24})?$/.test(revision))
|
|
125
|
+
return "This build has no saved commit to open a terminal on.";
|
|
126
|
+
const repo = runtime.taskRepoOf(run.taskRef);
|
|
127
|
+
if (repo === null)
|
|
128
|
+
return "This build's project isn't known here.";
|
|
129
|
+
return { repo, revision };
|
|
130
|
+
};
|
|
80
131
|
async function start(ctx) {
|
|
132
|
+
const answer = (status, value) => checked(ctx, status, "termStarted", value);
|
|
81
133
|
const refused = refusal(ctx);
|
|
82
134
|
if (refused !== null)
|
|
83
|
-
return
|
|
135
|
+
return answer(403, { ok: false, error: refused });
|
|
84
136
|
const who = ctx.who;
|
|
85
137
|
const body = readForm(ctx.posted, CONSOLE_FORMS.term);
|
|
86
138
|
if ([...new Set(body.keys())].some(key => body.sent.getAll(key).length !== 1))
|
|
87
|
-
return
|
|
88
|
-
const
|
|
139
|
+
return answer(400, { ok: false, error: "Submit one value for each field." });
|
|
140
|
+
const program = body.get("program") ?? "";
|
|
89
141
|
if (!TERMINAL_PROGRAMS.includes(program))
|
|
90
|
-
return
|
|
142
|
+
return answer(400, { ok: false, error: "Choose Claude Code, Codex or a shell." });
|
|
143
|
+
const taskField = body.get("task"), runField = body.get("run");
|
|
144
|
+
if ((taskField === null) !== (runField === null))
|
|
145
|
+
return answer(400, { ok: false, error: "Name the task and its build." });
|
|
146
|
+
let from = null, repo;
|
|
147
|
+
if (taskField !== null && runField !== null) {
|
|
148
|
+
if (body.get("repo") !== null || !/^[1-9][0-9]{0,14}$/.test(runField) || taskField === "" || taskField.length > 200)
|
|
149
|
+
return answer(400, { ok: false, error: "Name the task and its build." });
|
|
150
|
+
const found = takeOverOf(taskField, Number(runField));
|
|
151
|
+
if (typeof found === "string")
|
|
152
|
+
return answer(404, { ok: false, error: found });
|
|
153
|
+
from = { revision: found.revision, task: taskField, run: Number(runField) };
|
|
154
|
+
repo = found.repo;
|
|
155
|
+
}
|
|
156
|
+
else
|
|
157
|
+
repo = body.get("repo") ?? "";
|
|
91
158
|
if (!runtime.consoleProjects().includes(repo) || !projectAllowed(who.name, repo))
|
|
92
|
-
return
|
|
159
|
+
return answer(403, { ok: false, error: "Choose a project available to your account." });
|
|
93
160
|
if (program !== "shell") {
|
|
94
161
|
const stopped = store.sessionPolicyRefusal(program, null, "live terminals");
|
|
95
162
|
if (stopped !== null)
|
|
96
|
-
return
|
|
163
|
+
return answer(403, { ok: false, error: stopped });
|
|
97
164
|
}
|
|
98
|
-
|
|
99
|
-
|
|
165
|
+
const proved = runtime.authenticateApprover(who, body.get("password") ?? "");
|
|
166
|
+
if (!proved.ok)
|
|
167
|
+
return answer(403, { ok: false, error: "Enter your Toolroll password to start a terminal." });
|
|
168
|
+
if ((proved.method === "local-owner") !== (who.authority !== "full"))
|
|
169
|
+
return answer(403, { ok: false, error: "Your access changed. Sign in again." });
|
|
100
170
|
const stillAllowed = () => {
|
|
101
171
|
const again = rereadBrowser(runtime, ctx.request, who);
|
|
102
172
|
if (again === null || operatorOf(again) === null)
|
|
103
173
|
return "Your access changed. Sign in again.";
|
|
104
|
-
|
|
174
|
+
if (proved.method === "session" && !sessionStandsIn(store))
|
|
175
|
+
return "This install's sign-in rules changed. Enter your Toolroll password to start a terminal.";
|
|
176
|
+
if (proved.method === "local-owner" && (again.authority !== "local-owner" || again.session.localGeneration !== who.session.localGeneration))
|
|
177
|
+
return "Your access changed. Sign in again.";
|
|
178
|
+
if (!projectAllowed(who.name, repo) || !runtime.consoleProjects().includes(repo))
|
|
179
|
+
return "That project is no longer available to your account.";
|
|
180
|
+
if (from !== null) {
|
|
181
|
+
const now = takeOverOf(from.task, from.run);
|
|
182
|
+
if (typeof now === "string" || now.repo !== repo || now.revision !== from.revision)
|
|
183
|
+
return "This build changed. Look again.";
|
|
184
|
+
}
|
|
185
|
+
return null;
|
|
105
186
|
};
|
|
106
187
|
try {
|
|
107
|
-
const
|
|
188
|
+
const owner = { name: who.name, generation: who.session.generation, localGeneration: who.authority === "full" ? null : who.session.localGeneration };
|
|
189
|
+
const terminal = await deps.host.start(owner, repo, program, undefined, stillAllowed, from);
|
|
108
190
|
const after = stillAllowed();
|
|
109
191
|
if (after !== null) {
|
|
110
192
|
await deps.host.close(terminal.id);
|
|
111
193
|
await deps.host.remove(terminal.id).catch(() => { });
|
|
112
|
-
return
|
|
194
|
+
return answer(403, { ok: false, error: after });
|
|
113
195
|
}
|
|
114
196
|
record("start", who.name, terminal);
|
|
115
|
-
return
|
|
197
|
+
return answer(200, { ok: true, id: terminal.id });
|
|
116
198
|
}
|
|
117
199
|
catch (error) {
|
|
118
|
-
return
|
|
200
|
+
return answer(409, { ok: false, error: error instanceof TerminalError ? error.message : "The terminal didn't start." });
|
|
119
201
|
}
|
|
120
202
|
}
|
|
203
|
+
const agentStart = (kind) => async (ctx) => {
|
|
204
|
+
const answer = (status, value) => checked(ctx, status, "termStarted", value);
|
|
205
|
+
const refused = refusal(ctx);
|
|
206
|
+
if (refused !== null)
|
|
207
|
+
return answer(403, { ok: false, error: refused });
|
|
208
|
+
const who = ctx.who;
|
|
209
|
+
if (!workbenchNow(ctx.request, who))
|
|
210
|
+
return answer(403, { ok: false, error: WORKBENCH_ONLY });
|
|
211
|
+
const body = readForm(ctx.posted, CONSOLE_FORMS.termAgent);
|
|
212
|
+
if ([...new Set(body.keys())].some(key => body.sent.getAll(key).length !== 1))
|
|
213
|
+
return answer(400, { ok: false, error: "Submit one value for each field." });
|
|
214
|
+
const agentId = body.get("agent") ?? "";
|
|
215
|
+
const setup = agentSetupOf(agentId);
|
|
216
|
+
if (setup === null)
|
|
217
|
+
return answer(400, { ok: false, error: "Choose an agent Toolroll supports." });
|
|
218
|
+
const run = kind === "sign-in" ? setup.signInRun : setup.installRun;
|
|
219
|
+
const shown = kind === "sign-in" ? setup.signIn : setup.install;
|
|
220
|
+
if (run === null || shown === null)
|
|
221
|
+
return answer(409, { ok: false, error: kind === "sign-in" ? "This agent signs in another way: its screen says how." : "Toolroll doesn't run this agent's installer: run the command shown in your own terminal." });
|
|
222
|
+
if (kind === "install" && body.get("confirm") !== shown)
|
|
223
|
+
return answer(409, { ok: false, error: "Confirm the exact install command first." });
|
|
224
|
+
if (agentId === "claude" || agentId === "codex") {
|
|
225
|
+
const stopped = store.sessionPolicyRefusal(agentId, null, "live terminals");
|
|
226
|
+
if (stopped !== null)
|
|
227
|
+
return answer(403, { ok: false, error: stopped });
|
|
228
|
+
}
|
|
229
|
+
const proved = runtime.authenticateApprover(who, body.get("password") ?? "");
|
|
230
|
+
if (!proved.ok)
|
|
231
|
+
return answer(403, { ok: false, error: "Enter your Toolroll password to start a terminal." });
|
|
232
|
+
if ((proved.method === "local-owner") !== (who.authority !== "full"))
|
|
233
|
+
return answer(403, { ok: false, error: "Your access changed. Sign in again." });
|
|
234
|
+
const source = (deps.agentEnv ?? (() => process.env))();
|
|
235
|
+
const untrusted = await excludedFolders({ store });
|
|
236
|
+
if (untrusted === null)
|
|
237
|
+
return answer(409, { ok: false, error: "Toolroll couldn't read its own records, so it won't start a program." });
|
|
238
|
+
const trust = { path: source["PATH"] ?? "", uid: process.getuid?.(), untrusted, acl: boundedAcl(Date.now() + 3_000) };
|
|
239
|
+
const program = run.binary;
|
|
240
|
+
const found = resolveLaunch(program, trust);
|
|
241
|
+
if (!found.ok)
|
|
242
|
+
return answer(409, { ok: false, error: found.missing ? `\`${program}\` isn't installed on this computer.` : `Toolroll won't run \`${program}\`: ${found.why}.` });
|
|
243
|
+
const env = { ...statusEnvironment(source, trust), PATH: launchPath(found, trust) };
|
|
244
|
+
const stillAllowed = () => {
|
|
245
|
+
const again = rereadBrowser(runtime, ctx.request, who);
|
|
246
|
+
if (again === null || operatorOf(again) === null)
|
|
247
|
+
return "Your access changed. Sign in again.";
|
|
248
|
+
if (proved.method === "session" && !sessionStandsIn(store))
|
|
249
|
+
return "This install's sign-in rules changed. Enter your Toolroll password to start a terminal.";
|
|
250
|
+
if (proved.method === "local-owner" && (again.authority !== "local-owner" || again.session.localGeneration !== who.session.localGeneration))
|
|
251
|
+
return "Your access changed. Sign in again.";
|
|
252
|
+
if (!workbenchNow(ctx.request, again))
|
|
253
|
+
return WORKBENCH_ONLY;
|
|
254
|
+
const now = resolveLaunch(program, { ...trust, acl: boundedAcl(Date.now() + 3_000) });
|
|
255
|
+
if (!now.ok || now.real !== found.real || now.file !== found.file)
|
|
256
|
+
return `\`${program}\` changed while it was being checked. Try again.`;
|
|
257
|
+
return null;
|
|
258
|
+
};
|
|
259
|
+
try {
|
|
260
|
+
const owner = { name: who.name, generation: who.session.generation, localGeneration: who.authority === "full" ? null : who.session.localGeneration };
|
|
261
|
+
const terminal = await deps.host.startCommand(owner, { id: agentId, kind }, { file: found.file, args: [...found.args, ...run.args] }, env, undefined, stillAllowed, () => { void runtime.checkLocalAgents(true); });
|
|
262
|
+
record(`agent-${kind}`, who.name, terminal);
|
|
263
|
+
return answer(200, { ok: true, id: terminal.id });
|
|
264
|
+
}
|
|
265
|
+
catch (error) {
|
|
266
|
+
return answer(409, { ok: false, error: error instanceof TerminalError ? error.message : "The terminal didn't start." });
|
|
267
|
+
}
|
|
268
|
+
};
|
|
121
269
|
const act = (verb) => async (ctx) => {
|
|
122
270
|
const refused = refusal(ctx);
|
|
123
271
|
if (refused !== null)
|
|
124
272
|
return json(ctx, 403, { ok: false, error: refused });
|
|
125
273
|
const who = ctx.who;
|
|
126
274
|
const terminal = deps.host.get(TERMINAL_ID.exec(ctx.url.pathname)?.[1] ?? "");
|
|
127
|
-
if (!
|
|
275
|
+
if (!reachable(who, terminal, ctx.request))
|
|
128
276
|
return json(ctx, 404, { ok: false, error: "No such terminal." });
|
|
129
277
|
try {
|
|
130
278
|
if (verb === "close")
|
|
@@ -207,7 +355,7 @@ export function createTerminalHandlers(runtime, deps) {
|
|
|
207
355
|
return true;
|
|
208
356
|
}
|
|
209
357
|
const terminal = deps.host?.get(id) ?? null;
|
|
210
|
-
if (!
|
|
358
|
+
if (!reachable(who, terminal, request)) {
|
|
211
359
|
refuseUpgrade(socket, 404, "No such terminal.");
|
|
212
360
|
return true;
|
|
213
361
|
}
|
|
@@ -239,7 +387,7 @@ export function createTerminalHandlers(runtime, deps) {
|
|
|
239
387
|
};
|
|
240
388
|
const prove = () => {
|
|
241
389
|
const again = rereadBrowser(runtime, request, who);
|
|
242
|
-
const ok = again !== null && operatorOf(again) !== null &&
|
|
390
|
+
const ok = again !== null && operatorOf(again) !== null && reachable(again, host.get(terminal.id), request);
|
|
243
391
|
if (ok)
|
|
244
392
|
provedAt = Date.now();
|
|
245
393
|
return ok;
|
|
@@ -264,6 +412,8 @@ export function createTerminalHandlers(runtime, deps) {
|
|
|
264
412
|
return shut(4401, "signed out");
|
|
265
413
|
ws.send(JSON.stringify(message));
|
|
266
414
|
},
|
|
415
|
+
backlog: () => closed ? 0 : ws.bufferedAmount,
|
|
416
|
+
overflow: () => shut(4008, "fell behind"),
|
|
267
417
|
};
|
|
268
418
|
ws.on("message", (data, isBinary) => {
|
|
269
419
|
if (closed)
|
|
@@ -301,6 +451,7 @@ export function createTerminalHandlers(runtime, deps) {
|
|
|
301
451
|
reprovers.add(reprove);
|
|
302
452
|
record("attach", who.name, terminal);
|
|
303
453
|
}
|
|
454
|
+
deps.host?.alsoBuildWritable?.(runtime.consoleProjects);
|
|
304
455
|
deps.server.on("upgrade", (request, socket, head) => {
|
|
305
456
|
if (!upgrade(request, socket, head))
|
|
306
457
|
socket.destroy();
|
|
@@ -311,6 +462,8 @@ export function createTerminalHandlers(runtime, deps) {
|
|
|
311
462
|
"term.session": async (ctx) => page(ctx),
|
|
312
463
|
"term.state": state,
|
|
313
464
|
"term.start": start,
|
|
465
|
+
"term.agent-sign-in": agentStart("sign-in"),
|
|
466
|
+
"term.agent-install": agentStart("install"),
|
|
314
467
|
"term.close": act("close"),
|
|
315
468
|
"term.remove": act("remove"),
|
|
316
469
|
"term.socket": socketWithoutUpgrade,
|
package/dist/server/welcome.js
CHANGED
|
@@ -5,6 +5,7 @@ import { firstTaskSuggestions, SAMPLE_FIRST_TASKS, SAMPLE_PROJECT_NAME, welcomeM
|
|
|
5
5
|
import { html, joinHtml, postForm } from "../html.js";
|
|
6
6
|
import { START_BUILDER_HREF } from "../needs-you.js";
|
|
7
7
|
import { addSampleProject } from "../sample-project.js";
|
|
8
|
+
import { firstTaskRouted } from "../welcome-facts.js";
|
|
8
9
|
import { resolveCeiling } from "../project.js";
|
|
9
10
|
import { readProjectRegistryNow } from "../repos.js";
|
|
10
11
|
import { refuse, screen } from "./chrome.js";
|
|
@@ -12,6 +13,7 @@ import { handlersOf } from "./handler-registry.js";
|
|
|
12
13
|
import { redirect } from "./http.js";
|
|
13
14
|
import { rereadBrowser } from "./live.js";
|
|
14
15
|
import { btn, chip, codeLine, dock, note, notice, pageHeader, settingsRecord } from "./kit.js";
|
|
16
|
+
import { NO_AGENT_YET } from "../agent-detect.js";
|
|
15
17
|
export const SAMPLE_PROBLEMS = {
|
|
16
18
|
"no-root": "There's no project folder to put the sample in. Add a folder instead.",
|
|
17
19
|
exists: `A folder named ${SAMPLE_PROJECT_NAME} is already there and wasn't made here, so nothing was changed.`,
|
|
@@ -37,17 +39,33 @@ function agentRow(agent, leads) {
|
|
|
37
39
|
: "";
|
|
38
40
|
return settingsRecord({ title: agent.name, sub, action, attrs: { "data-agent": agent.id, "data-state": agent.state } });
|
|
39
41
|
}
|
|
42
|
+
const OTHER_WORDS = { "signed-in": "Signed in", "signed-out": "Not signed in", unknown: "Installed", "not-installed": "Not installed" };
|
|
43
|
+
const withCode = (text) => joinHtml(text.split("`").map((part, index) => index % 2 === 1 ? html `<code class="k-mono">${part}</code>` : html `${part}`));
|
|
44
|
+
function otherRow(agent) {
|
|
45
|
+
const sub = agent.state !== "signed-in" && agent.signIn !== null
|
|
46
|
+
? html `${OTHER_WORDS[agent.state]}. To sign in, run this on the computer running Toolroll:${codeLine(agent.signIn)}`
|
|
47
|
+
: agent.next !== null ? html `${OTHER_WORDS[agent.state]}. ${withCode(agent.next)}` : OTHER_WORDS[agent.state];
|
|
48
|
+
return settingsRecord({ title: agent.name, sub, action: "", attrs: { "data-agent": agent.id, "data-state": agent.state } });
|
|
49
|
+
}
|
|
40
50
|
export function welcomeBody(model, options) {
|
|
41
|
-
const lead = model.next;
|
|
42
51
|
let primary = null;
|
|
43
|
-
const
|
|
52
|
+
const inventory = options.inventory ?? "full";
|
|
53
|
+
const blind = inventory === "none";
|
|
54
|
+
const agentDone = blind ? false : model.agent.done;
|
|
55
|
+
const lead = !blind || model.next !== "agent" ? model.next : !model.project.done ? "project" : !model.task.done ? "task" : null;
|
|
56
|
+
const left = blind ? [false, model.project.done, model.task.done].filter(done => !done).length : model.left;
|
|
57
|
+
const agentLead = lead === "agent" && inventory === "full" ? model.agent.agents.find(one => one.canUse) ?? null : null;
|
|
44
58
|
if (agentLead !== null)
|
|
45
59
|
primary = useForm(agentLead.id, btn(`Use ${agentLead.name}`, { variant: "primary", type: "submit" }));
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
60
|
+
const firstTaskNote = model.agent.firstTask !== null ? note(`Your first task goes to ${model.agent.firstTask}.`) : "";
|
|
61
|
+
const agentNote = inventory === "none" ? ""
|
|
62
|
+
: inventory === "summary" ? model.agent.firstTask !== null ? firstTaskNote : note(model.agent.checking ? "Checking for a signed-in agent on this computer…" : NO_AGENT_YET)
|
|
63
|
+
: model.agent.checking ? note("Checking for a signed-in agent on this computer…")
|
|
64
|
+
: !model.agent.done ? note("Sign in to one of these, then come back to this page.")
|
|
65
|
+
: model.agent.buildsWith !== null ? note(html `Tasks are built with ${model.agent.buildsWith}. <a class="k-link" href="/settings/models">Change</a>`)
|
|
66
|
+
: firstTaskNote;
|
|
67
|
+
const rows = inventory !== "full" ? "" : html `<div class="welcome-rows">${model.agent.agents.map(one => agentRow(one, agentLead?.id === one.id))}${model.agent.others.map(otherRow)}</div>`;
|
|
68
|
+
const agent = step("agent", 1, "Agent", agentDone, html `<p class="k-note">The AI coding agent that plans and builds your tasks.</p>${rows}${agentNote}`);
|
|
51
69
|
const projects = model.project.projects;
|
|
52
70
|
const listed = projects.slice(0, PROJECTS_SHOWN).map(one => settingsRecord({ title: one.name, sub: html `<span class="k-mono">${one.path}</span>`, attrs: { "data-project": "" } }));
|
|
53
71
|
const more = projects.length > PROJECTS_SHOWN ? note(html `And ${plural(projects.length - PROJECTS_SHOWN, "more project", "more projects")} in <a class="k-link" href="/projects">Projects</a>.`) : "";
|
|
@@ -75,7 +93,7 @@ ${listed.length === 0 ? "" : html `<div class="welcome-rows">${listed}</div>`}${
|
|
|
75
93
|
const taskLeads = lead === "task";
|
|
76
94
|
if (taskLeads)
|
|
77
95
|
primary = btn("Write a task", { variant: "primary", href: "/tasks/new" });
|
|
78
|
-
const waitsForAgent = model.task.done && !model.agent.done && !model.agent.checking;
|
|
96
|
+
const waitsForAgent = !blind && model.task.done && !model.agent.done && !model.agent.checking;
|
|
79
97
|
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
98
|
: html `<p class="k-note">Filed. Its plan waits for your approval in <a class="k-link" href="/">Work</a>.</p>`
|
|
81
99
|
: !model.task.open ? html `<p class="k-note">Add a project first.</p>`
|
|
@@ -83,9 +101,14 @@ ${listed.length === 0 ? "" : html `<div class="welcome-rows">${listed}</div>`}${
|
|
|
83
101
|
${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>`}\
|
|
84
102
|
<div class="k-acts">${btn("Write a task", { sm: true, href: "/tasks/new", ...(taskLeads ? { variant: "primary", docked: true } : {}) })}</div>`;
|
|
85
103
|
const task = step("task", 3, "First task", model.task.done, taskBody, waitsForAgent);
|
|
86
|
-
const hello = html `<div class="k-hello"><h2>Get to your first result.</h2><p>${
|
|
104
|
+
const hello = html `<div class="k-hello"><h2>Get to your first result.</h2><p>${left === 0 ? "Setup is done." : `${plural(left, "step", "steps")} left.`}</p></div>`;
|
|
87
105
|
return { body: html `${hello}${agent}${project}${task}`, primary };
|
|
88
106
|
}
|
|
107
|
+
export function agentInventoryOf(who, store) {
|
|
108
|
+
if (who.via !== "cookie")
|
|
109
|
+
return "none";
|
|
110
|
+
return store.isInstanceOperator(who.name) ? "full" : "summary";
|
|
111
|
+
}
|
|
89
112
|
export function welcomePage(chrome, model, options) {
|
|
90
113
|
const { body, primary } = welcomeBody(model, options);
|
|
91
114
|
return screen("Welcome", html `${pageHeader("Welcome")}<div class="k-doc welcome" data-welcome>${body}</div>${dock(primary)}`, { chrome });
|
|
@@ -107,8 +130,10 @@ export function createWelcomeHandlers(runtime) {
|
|
|
107
130
|
const states = runtime.localSignIn?.states ?? null;
|
|
108
131
|
const build = resolvePhaseAgent(store, "build", repo, {});
|
|
109
132
|
const approver = who.via === "cookie" && who.role === "approver";
|
|
133
|
+
const routed = firstTaskRouted(store, repo);
|
|
110
134
|
const model = welcomeModel({
|
|
111
135
|
agents: { claude: states?.claude ?? null, codex: states?.codex ?? null },
|
|
136
|
+
others: runtime.localAgents?.agents ?? null, routed,
|
|
112
137
|
inUse: AGENT_OF[store.getChatConfig()?.provider ?? ""] ?? null,
|
|
113
138
|
buildsOn: build.ok ? build.spec.provider : null,
|
|
114
139
|
canChoose: approver,
|
|
@@ -118,7 +143,7 @@ export function createWelcomeHandlers(runtime) {
|
|
|
118
143
|
starters, platform: options.platform ?? process.platform,
|
|
119
144
|
});
|
|
120
145
|
const asked = url.searchParams.get("sample");
|
|
121
|
-
return sendScreen(response, 200, welcomePage(chrome, model, { problem: isSampleProblem(asked) ? asked : null, canAdd: approver && !store.isDemo() }));
|
|
146
|
+
return sendScreen(response, 200, welcomePage(chrome, model, { problem: isSampleProblem(asked) ? asked : null, canAdd: approver && !store.isDemo(), inventory: agentInventoryOf(who, store) }));
|
|
122
147
|
}
|
|
123
148
|
async function addSample(ctx) {
|
|
124
149
|
const { who, response, now, posted, request } = ctx;
|
|
@@ -119,9 +119,9 @@ function providerRecord(one) {
|
|
|
119
119
|
body: joinHtml([
|
|
120
120
|
one.connection === null ? "" : formRow("Sign-in", `${one.connection.words}${one.connection.facts ? ` · ${one.connection.facts}` : ""}`, html `<button class="k-btn k-btn-ghost k-btn-sm" type="submit" formaction="/settings/connection/check" formnovalidate><span class="k-face">Check again</span></button>`, "inline"),
|
|
121
121
|
one.subscriptionCapable ? formRow("How it’s paid", `${one.usage} · ${one.envName}`, select({ name: "auth-mode", label: `How ${one.name} is paid`, current: one.mode, items: [["subscription", `${one.name} subscription`], ["api-key", "API key"]] })) : note(`${one.usage} · ${one.envName}`),
|
|
122
|
-
formRow(`${one.name} API key`, "Stored privately on this computer and never shown again.
|
|
122
|
+
formRow(`${one.name} API key`, "Stored privately on this computer and never shown again.", html `<input class="k-input" id="key-${one.provider}" type="password" name="value" autocomplete="off" spellcheck="false" autocapitalize="none" data-so-secret data-1p-ignore data-lpignore="${SECRET_OPT_OUTS["data-lpignore"]}" data-bwignore data-form-type="other" aria-label="${one.name} API key" placeholder="${one.set ? "Paste to replace the stored key" : "Paste a key"}">`),
|
|
123
123
|
]) });
|
|
124
|
-
const remove = one.set ? kitSectionForm({ proof: "provider-key", action: "/settings/provider-key-clear", id: `provider-${one.provider}-clear`, hidden: { provider: one.provider }, save: { label: "Remove key", variant: "danger" },
|
|
124
|
+
const remove = one.set ? kitSectionForm({ proof: "provider-key-clear", action: "/settings/provider-key-clear", id: `provider-${one.provider}-clear`, hidden: { provider: one.provider }, save: { label: "Remove key", variant: "danger" },
|
|
125
125
|
body: note("Runs that use this API key stop until you add one again.") }) : "";
|
|
126
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}` : ""}`,
|
|
127
127
|
attrs: { "data-provider": one.provider }, more: disclose(`Manage ${one.name}`, joinHtml([form, remove])) });
|
package/dist/settings-proofs.js
CHANGED
|
@@ -11,15 +11,14 @@ export const PROOF_INVENTORY = [
|
|
|
11
11
|
{ id: "notifications-mute", action: "Mute a project", routes: ["/settings/notifications/mute"], form: "notificationsMute", field: null, proof: "none", ...NONE, role: "any", secrets: [], terms: [] },
|
|
12
12
|
{ id: "messaging", action: "Choose the chat app that receives alerts", routes: ["/settings/messaging"], form: "messaging", field: null, proof: "none", ...NONE, role: "any", secrets: [], terms: [] },
|
|
13
13
|
{ id: "telegram-digest", action: "Set the Telegram digest", routes: ["/settings/telegram-digest"], form: "telegramDigest", field: null, proof: "none", ...NONE, role: "any", secrets: [], terms: [] },
|
|
14
|
-
{ id: "provider-key", action: "
|
|
15
|
-
{ id: "
|
|
16
|
-
{ id: "
|
|
17
|
-
{ id: "google", action: "Connect or disconnect Google", routes: ["/settings/google", "/settings/google/disconnect"], form: "google", field: null, proof: "none", ...NONE, role: "any", secrets: ["clientSecret"], terms: [] },
|
|
14
|
+
{ id: "provider-key-clear", action: "Clear an AI provider key", routes: ["/settings/provider-key-clear"], form: "providerKey", field: null, proof: "none", ...NONE, role: "any", secrets: [], terms: [] },
|
|
15
|
+
{ id: "email-test", action: "Test email", routes: ["/settings/email-test", "/settings/email-read-test"], form: "email", field: null, proof: "none", ...NONE, role: "any", secrets: [], terms: [] },
|
|
16
|
+
{ id: "google-disconnect", action: "Disconnect Google", routes: ["/settings/google/disconnect"], form: "google", field: null, proof: "none", ...NONE, role: "any", secrets: [], terms: [] },
|
|
18
17
|
{ id: "appearance", action: "Change the theme or accent", routes: ["/settings/appearance"], form: "appearance", field: null, proof: "none", ...NONE, role: "any", secrets: [], terms: [] },
|
|
19
18
|
{ id: "chat-approval-confirm", action: "Review approving from chat", routes: ["/settings/chat-approval/confirm", "/settings/chat-approval/off"], form: "chatApproval", field: null, proof: "none", ...NONE, role: "approver", secrets: [], terms: [] },
|
|
20
19
|
{ id: "models-rules-off", action: "Turn an earned rule off, stop a trial, say Not now, or turn suggestions off", routes: ["/settings/models/turn-off", "/settings/models/not-now", "/settings/models/suggest-off", "/settings/models/stop"], form: "modelsRules", field: null, proof: "none", ...NONE, role: "operator", secrets: [], terms: [] },
|
|
21
20
|
...CHAT_APPS.map(([app, name, form]) => ({ id: `${app}-alerts`, action: `Send alerts to ${name}`, routes: [`/settings/${app}/alerts`], form, field: null, proof: "none", ...NONE, role: "approver", secrets: [], terms: [] })),
|
|
22
|
-
{ id: "permission-default", action: "Start new tasks with Full access", routes: ["/settings/permission-default"], form: "permissionDefault", field: "password", proof: "
|
|
21
|
+
{ id: "permission-default", action: "Start new tasks with Full access", routes: ["/settings/permission-default"], form: "permissionDefault", field: "password", proof: "credential", when: "only when widening to Full access", ...CREDENTIAL, role: "any", secrets: [], terms: [] },
|
|
23
22
|
{ id: "spend-budget", action: "Set a monthly limit", routes: ["/spend/budget"], form: "spendBudget", field: "password", proof: "step-up", ...ACCEPT, role: "operator", secrets: [], terms: [] },
|
|
24
23
|
{ id: "models-agent", action: "Change which model does each job", routes: ["/settings/models/agent"], form: "modelsChange", field: "password", proof: "step-up", ...ACCEPT, role: "operator", secrets: [], terms: ["scope", "digest"] },
|
|
25
24
|
{ id: "models-rules", action: "Accept a suggested model, try a cheaper one, keep a paused rule, or turn suggestions on", routes: ["/settings/models/accept", "/settings/models/keep", "/settings/models/suggest-on", "/settings/models/try"], form: "modelsRules", field: "password", proof: "step-up", ...ACCEPT, role: "operator", secrets: [], terms: ["scope", "id", "rule"], note: "the rule door re-proves the session and its generation in the write" },
|
|
@@ -33,9 +32,9 @@ export const PROOF_INVENTORY = [
|
|
|
33
32
|
["data", "Download everything", "data", "operator"],
|
|
34
33
|
].map(([path, action, form, role]) => ({ id: path, action, routes: [`/settings/${path}`], form, field: "password", proof: "step-up", ...ACCEPT, role, secrets: [], terms: path === "approval" ? ["repo"] : [] })),
|
|
35
34
|
{ id: "pull-requests", action: "Change pull-request settings, or turn them off", routes: ["/settings/pull-requests"], form: "pullRequests", field: "password", proof: "step-up", ...ACCEPT, role: "any", handlerRole: "an approver of the project", secrets: [], terms: ["repo", "act"] },
|
|
36
|
-
{ id: "pull-requests-on", action: "Turn pull requests on", routes: ["/settings/pull-requests"], select: { field: "act", value: "on" }, form: "pullRequests", field: "password", proof: "
|
|
35
|
+
{ id: "pull-requests-on", action: "Turn pull requests on", routes: ["/settings/pull-requests"], select: { field: "act", value: "on" }, form: "pullRequests", field: "password", proof: "credential", ...CREDENTIAL, role: "any", handlerRole: "an approver of the project", secrets: [], terms: ["repo", "act", "github", "base"], note: "`github` and `base` are what the page showed; the handler checks again and refuses a difference" },
|
|
37
36
|
{ id: "checks", action: "Change checks", routes: ["/settings/checks"], form: "checks", field: "password", proof: "step-up", ...ACCEPT, role: "any", handlerRole: "an approver of the project", secrets: [], terms: ["repo", "act"] },
|
|
38
|
-
{ id: "monitoring", action: "Change monitoring", routes: ["/settings/monitoring"], form: "monitoring", field: "password", proof: "
|
|
37
|
+
{ id: "monitoring", action: "Change monitoring", routes: ["/settings/monitoring"], form: "monitoring", field: "password", proof: "credential", ...CREDENTIAL, role: "operator", secrets: ["header-value"], terms: [] },
|
|
39
38
|
{ id: "updates", action: "Update Toolroll", routes: ["/settings/updates", "/settings/updates/seen", "/settings/updates/cancel"], form: "updates", field: "password", proof: "step-up", ...ACCEPT, role: "operator", secrets: [], terms: [] },
|
|
40
39
|
{ id: "storage-cleanup", action: "Choose when checkouts are removed", routes: ["/settings/storage"], form: "storage", field: "password", proof: "step-up", ...ACCEPT, role: "operator", secrets: [], terms: [] },
|
|
41
40
|
{ id: "storage-clean", action: "Clean up checkouts", routes: ["/settings/storage/clean"], form: "storage", field: "password", proof: "step-up", ...ACCEPT, role: "operator", secrets: [], terms: ["preview"], note: "`preview` is the digest of what the page showed; a changed list is refused" },
|
|
@@ -43,8 +42,8 @@ export const PROOF_INVENTORY = [
|
|
|
43
42
|
{ id: "storage-discard", action: "Discard a checkout", routes: ["/settings/storage/discard"], form: "storage", field: "password", proof: "step-up", ...ACCEPT, role: "operator", secrets: [], terms: ["path"] },
|
|
44
43
|
{ id: "project-live-view", action: "Show a project's commands in the live view", routes: ["/settings/project/live-view"], form: "projectLiveView", field: "password", proof: "step-up", ...ACCEPT, role: "any", handlerRole: "an approver of the project", secrets: [], terms: ["repo", "nonce"] },
|
|
45
44
|
{ id: "project-delete", action: "Delete a project", routes: ["/settings/project/delete"], form: "projectDelete", field: "password", proof: "step-up", ...ACCEPT, role: "operator", secrets: [], terms: ["repo", "step"], note: "the project's name typed too" },
|
|
46
|
-
{ id: "tools-connect", action: "Connect a tool", routes: ["/settings/tools/connect"], form: "toolsConnect", field: "password", proof: "
|
|
47
|
-
{ id: "tools-change", action: "Change a project's tools", routes: ["/settings/tools/change"], form: "toolsChange", field: "password", proof: "
|
|
45
|
+
{ id: "tools-connect", action: "Connect a tool", routes: ["/settings/tools/connect"], form: "toolsConnect", field: "password", proof: "credential", ...CREDENTIAL, role: "approver", secrets: [], terms: ["repo", "shown"], note: "`shown` is the project the page showed (a post from another project is refused), not a digest" },
|
|
46
|
+
{ id: "tools-change", action: "Change a project's tools", routes: ["/settings/tools/change"], form: "toolsChange", field: "password", proof: "credential", when: "only to add a tool (catalog, custom, import) or set a secret", ...CREDENTIAL, role: "approver", secrets: ["value"], terms: ["repo", "shown", "action"] },
|
|
48
47
|
...CHAT_APPS.map(([app, name, form]) => ({ id: `${app}-close`, action: `Unpair or disconnect ${name}`, routes: [`/settings/${app}/unpair`, `/settings/${app}/disconnect`], form, field: "password", proof: "step-up", ...ACCEPT, role: "approver", secrets: [], terms: [] })),
|
|
49
48
|
{ id: "telegram-unpair", action: "Unpair your phone from Telegram", routes: ["/settings/telegram/unpair"], form: "telegramPair", field: "password", proof: "step-up", ...ACCEPT, role: "approver", secrets: [], terms: [] },
|
|
50
49
|
{ 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: [] },
|
|
@@ -55,6 +54,11 @@ export const PROOF_INVENTORY = [
|
|
|
55
54
|
{ 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 },
|
|
56
55
|
{ 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 },
|
|
57
56
|
{ 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
|
+
{ id: "install-solo", action: "Say it's just you", routes: ["/settings/install-mode/solo"], form: "justMe", field: "password", proof: "credential", ...CREDENTIAL, role: "operator", handlerRole: "a full session (never the local owner)", secrets: [], terms: [] },
|
|
58
|
+
{ id: "provider-key", action: "Save an AI provider key", routes: ["/settings/provider-key"], form: "providerKey", field: "password", proof: "credential", ...CREDENTIAL, role: "any", secrets: ["value"], terms: [] },
|
|
59
|
+
{ id: "telegram-token", action: "Save the Telegram bot token", routes: ["/settings/telegram-token"], form: "telegramToken", field: "password", proof: "credential", ...CREDENTIAL, role: "any", secrets: ["token"], notProof: ["token"], terms: [] },
|
|
60
|
+
{ id: "email", action: "Set up email", routes: ["/settings/email"], form: "email", field: "token", proof: "credential", ...CREDENTIAL, role: "any", secrets: ["password"], notProof: ["password"], terms: [] },
|
|
61
|
+
{ id: "google", action: "Connect Google", routes: ["/settings/google"], form: "google", field: "password", proof: "credential", ...CREDENTIAL, role: "any", secrets: ["clientSecret"], terms: [] },
|
|
58
62
|
{ 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: [] },
|
|
59
63
|
{ 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
64
|
{ 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" },
|
package/dist/slack-api.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { ChatDeliveryError } from "./chat-delivery-state.js";
|
|
1
|
+
import { ChatDeliveryError, withheldPart } from "./chat-delivery-state.js";
|
|
2
|
+
import { guardSlack } from "./outbound-privacy.js";
|
|
2
3
|
import { chmodSync, readFileSync, renameSync, rmSync, writeFileSync, } from "node:fs";
|
|
3
4
|
import { join } from "node:path";
|
|
4
5
|
import { randomBytes } from "node:crypto";
|
|
@@ -46,7 +47,7 @@ const errors = new Set([
|
|
|
46
47
|
"edit_window_closed",
|
|
47
48
|
]);
|
|
48
49
|
export function slackApi(token, fetcher = fetch) {
|
|
49
|
-
return async (method, args = {}) => {
|
|
50
|
+
return guardSlack(async (method, args = {}) => {
|
|
50
51
|
if (!/^[a-zA-Z]+(?:\.[a-zA-Z]+){1,2}$/.test(method))
|
|
51
52
|
throw new SlackError("Invalid Slack method");
|
|
52
53
|
let response;
|
|
@@ -85,7 +86,7 @@ export function slackApi(token, fetcher = fetch) {
|
|
|
85
86
|
? String(body.error)
|
|
86
87
|
: "Slack could not complete the request", 5_000, body.error === "internal_error" || body.error === "fatal_error");
|
|
87
88
|
return body;
|
|
88
|
-
};
|
|
89
|
+
}, withheldPart);
|
|
89
90
|
}
|
|
90
91
|
export const slackCredentialFile = (dir) => join(dir, "slack-connection.json");
|
|
91
92
|
export function loadSlackCredentials(dir) {
|
package/dist/slack-chat.js
CHANGED
|
@@ -10,13 +10,14 @@ import { processChatEvent, planChatNotifications, channelAccess, planRoomMessage
|
|
|
10
10
|
import { proposalPreview, proposalLink, proposalOutcomeText, armedCardText, armedYesLabel, } from "./chat-channel.js";
|
|
11
11
|
import { LEAD_MESSAGE_MAX_CHARS } from "./lead.js";
|
|
12
12
|
import { renderReply } from "./reply-shape.js";
|
|
13
|
-
import { ChatDeliveryError, ChatState, chatHash, chatRetryAt, partContent } from "./chat-delivery-state.js";
|
|
13
|
+
import { ChatDeliveryError, ChatState, chatHash, chatRetryAt, partContent, withheldPart } from "./chat-delivery-state.js";
|
|
14
14
|
import { readChatPart } from "./contracts/chat-content.js";
|
|
15
15
|
import { readSlackBlockActions, readSlackButton, SLACK_LINK_ACTION } from "./contracts/slack-callback.js";
|
|
16
16
|
import { object, slackId, slackTs, slackMember, SlackError, uploadSlackBytes, } from "./slack-api.js";
|
|
17
17
|
import { resultImageFileName, safeResultImageCaption, verifyResultImage, } from "./chat-evidence.js";
|
|
18
18
|
import {} from "./store.js";
|
|
19
19
|
import { isLiveMessage, liveSpacingOf } from "./chat-live.js";
|
|
20
|
+
import { checkedChunks, guardSlack, taskSubject } from "./outbound-privacy.js";
|
|
20
21
|
const SLACK_REFUSED_BLOCKS = new Set(["invalid_blocks", "invalid_blocks_format", "invalid_arguments", "msg_too_long", "msg_blocks_too_long"]);
|
|
21
22
|
const SLACK_UNEDITABLE = new Set(["message_not_found", "cant_update_message", "edit_window_closed"]);
|
|
22
23
|
const nowOf = (options) => options.clock?.() ?? new Date();
|
|
@@ -137,7 +138,7 @@ export function slackBlocks(text, buttons = []) {
|
|
|
137
138
|
});
|
|
138
139
|
text = lines.slice(1).join("\n").trim();
|
|
139
140
|
}
|
|
140
|
-
for (const part of split(text))
|
|
141
|
+
for (const part of checkedChunks(text, split(text)))
|
|
141
142
|
blocks.push({
|
|
142
143
|
type: "section",
|
|
143
144
|
text: { type: "plain_text", text: part, emoji: true },
|
|
@@ -147,7 +148,7 @@ export function slackBlocks(text, buttons = []) {
|
|
|
147
148
|
return blocks;
|
|
148
149
|
}
|
|
149
150
|
export function slackVoiceBlocks(mrkdwn, buttons = []) {
|
|
150
|
-
const blocks = split(mrkdwn).map((part) => ({
|
|
151
|
+
const blocks = checkedChunks(mrkdwn, split(mrkdwn)).map((part) => ({
|
|
151
152
|
type: "section",
|
|
152
153
|
text: { type: "mrkdwn", text: part, verbatim: true },
|
|
153
154
|
}));
|
|
@@ -205,6 +206,7 @@ export async function deliverSlackPart(options) {
|
|
|
205
206
|
if (event.kind === "notice" && options.canNotify?.() === false)
|
|
206
207
|
return false;
|
|
207
208
|
const content = partContent(row.payload);
|
|
209
|
+
options = { ...options, api: guardSlack(options.api, withheldPart, taskSubject(store, content.task ?? content.image?.taskId)) };
|
|
208
210
|
const destination = content.channel ?? binding.channel;
|
|
209
211
|
let text = content.text, buttons = [];
|
|
210
212
|
if (content.task &&
|