toolroll 0.9.128 → 0.9.130
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 +41 -0
- package/dist/accent-colors.js +3 -1
- package/dist/agent-fence.js +0 -2
- package/dist/agents-board.js +0 -3
- package/dist/approval-authority.js +2 -1
- package/dist/assignment.js +56 -2
- package/dist/backup-ui.js +6 -3
- package/dist/backup.js +6 -0
- package/dist/bounded-spawn.js +0 -1
- package/dist/browser/manifest.json +57 -0
- package/dist/browser/terminal.2a682d0b91a35288271c73b7ee253e524cca0917d17fbaf6733e80b7a767a37c.js.br +0 -0
- package/dist/browser/terminal.2a682d0b91a35288271c73b7ee253e524cca0917d17fbaf6733e80b7a767a37c.js.gz +0 -0
- package/dist/browser/{terminal.css → terminal.4d1cf20c32ad7c2099df657358d540d5fd92bb55195a88121e74b28467238b42.css} +1 -1
- package/dist/browser/terminal.4d1cf20c32ad7c2099df657358d540d5fd92bb55195a88121e74b28467238b42.css.br +0 -0
- package/dist/browser/terminal.4d1cf20c32ad7c2099df657358d540d5fd92bb55195a88121e74b28467238b42.css.gz +0 -0
- package/dist/browser/{workspace.js → workspace.9bd1db81d3c897045a5d82d4804e374e41e78b1b2cfd05d37b982a4ea0d02626.js} +25 -25
- package/dist/browser/workspace.9bd1db81d3c897045a5d82d4804e374e41e78b1b2cfd05d37b982a4ea0d02626.js.br +0 -0
- package/dist/browser/workspace.9bd1db81d3c897045a5d82d4804e374e41e78b1b2cfd05d37b982a4ea0d02626.js.gz +0 -0
- package/dist/browser/{workspace.css → workspace.a0752f935cfeaf16758d1085fe8f3e1719a7cd525b91a9c9943c789d65879a54.css} +1 -1
- package/dist/browser/workspace.a0752f935cfeaf16758d1085fe8f3e1719a7cd525b91a9c9943c789d65879a54.css.br +0 -0
- package/dist/browser/workspace.a0752f935cfeaf16758d1085fe8f3e1719a7cd525b91a9c9943c789d65879a54.css.gz +0 -0
- package/dist/browser-shell.js +271 -25
- package/dist/canvas-freshness.js +122 -0
- package/dist/canvas-fs.js +273 -0
- package/dist/canvas-reads.js +747 -0
- package/dist/canvas-state-key.js +45 -0
- package/dist/canvas-state-worker.js +12 -0
- package/dist/central-recovery-stage.js +3 -3
- package/dist/chat-actions.js +26 -0
- package/dist/chat-channel.js +4 -3
- package/dist/chat-task-actions.js +1 -1
- package/dist/chat-warmth.js +0 -1
- package/dist/check-report.js +0 -6
- package/dist/commit-extract.js +79 -40
- package/dist/companion/access.js +162 -0
- package/dist/companion/actions.js +622 -0
- package/dist/companion/bonjour.js +45 -0
- package/dist/companion/canvas.js +141 -0
- package/dist/companion/chat-origin.js +92 -0
- package/dist/companion/chat.js +571 -0
- package/dist/companion/daemon.js +1387 -0
- package/dist/companion/direct-server.js +177 -0
- package/dist/companion/finish.js +51 -0
- package/dist/companion/framing.js +498 -0
- package/dist/companion/noise.js +461 -0
- package/dist/companion/passkey-gate.js +287 -0
- package/dist/companion/paths.js +90 -0
- package/dist/companion/reads.js +283 -0
- package/dist/companion/relay-auth.js +265 -0
- package/dist/companion/relay-server.js +870 -0
- package/dist/companion/schema.js +289 -0
- package/dist/companion/service.js +581 -0
- package/dist/companion/store.js +325 -0
- package/dist/companion/webauthn.js +407 -0
- package/dist/console-instance.js +0 -4
- package/dist/contracts/console-api.js +18 -0
- package/dist/converse.js +0 -1
- package/dist/coordinator.js +1 -1
- package/dist/design/kit.css +30 -0
- package/dist/desktop-config.js +156 -0
- package/dist/desktop-host.js +6 -152
- package/dist/desktop-update.js +1 -1
- package/dist/finished-task-sql.js +14 -0
- package/dist/flexible-answers.js +0 -1
- package/dist/github-read.js +41 -0
- package/dist/guides.js +4 -3
- package/dist/lead-doors.js +50 -3
- package/dist/lead-queue-runtime.js +11 -2
- package/dist/lead-queue.js +25 -0
- package/dist/live-backup-change.js +93 -0
- package/dist/live-backup.js +75 -31
- package/dist/live-bus.js +3 -2
- package/dist/live-records.js +0 -1
- package/dist/local-landing.js +47 -0
- package/dist/local-owner.js +0 -1
- package/dist/model-choices.js +0 -11
- package/dist/nightly-check.js +0 -3
- package/dist/nightly-github.js +1 -2
- package/dist/notification-retention.js +119 -0
- package/dist/observations.js +0 -1
- package/dist/operate.js +17 -4
- package/dist/person-proof.js +5 -1
- package/dist/pull-request-flow.js +116 -2
- package/dist/qr.js +360 -0
- package/dist/release-adapters.js +14 -43
- package/dist/release-auto.js +17 -13
- package/dist/release-card.js +0 -4
- package/dist/release-cli.js +37 -2
- package/dist/release.js +13 -2
- package/dist/restore-retirement.js +6 -1
- package/dist/result-review.js +0 -3
- package/dist/retention-ui.js +1 -1
- package/dist/retention.js +14 -21
- package/dist/review-context.js +0 -5
- package/dist/route-rules.js +1 -5
- package/dist/sandbox-runtime.js +0 -1
- package/dist/scope.js +68 -17
- package/dist/scout.js +0 -6
- package/dist/serve.js +60 -9
- package/dist/server/kit.js +1 -0
- package/dist/server/live.js +9 -2
- package/dist/server/pages.js +12 -4
- package/dist/server/phone-engine-api.js +79 -0
- package/dist/server/render-pages.js +1 -11
- package/dist/server/render-results.js +0 -1
- package/dist/server/render-tasks.js +0 -68
- package/dist/server/route-table.js +12 -1
- package/dist/server/settings-phone.js +515 -0
- package/dist/server/settings-scripts.js +2 -0
- package/dist/server/settings-section-table.js +0 -3
- package/dist/server/settings-sections.js +10 -4
- package/dist/server/settings.js +20 -5
- package/dist/server/terminals.js +2 -1
- package/dist/settings-groups-ui.js +2 -1
- package/dist/settings-proofs.js +6 -0
- package/dist/store.js +52 -4
- package/dist/structured-output.js +0 -1
- package/dist/style-asset.js +20 -7
- package/dist/tailnet.js +39 -0
- package/dist/task-control.js +5 -0
- package/dist/task-sizing.js +0 -1
- package/dist/toolroll-update-cli.js +19 -3
- package/dist/toolroll-update-ui.js +2 -2
- package/dist/toolroll-update.js +98 -16
- package/dist/youiyoux-intake.js +8 -0
- package/package.json +7 -2
- package/dist/contracts/contract-test.js +0 -55
- package/dist/unfenced-test-support.js +0 -6
- /package/dist/browser/{terminal.js → terminal.2a682d0b91a35288271c73b7ee253e524cca0917d17fbaf6733e80b7a767a37c.js} +0 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { lstatSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { viewedGitSync } from "./teardown-git.js";
|
|
5
|
+
const NAME_LIMIT = 20_000;
|
|
6
|
+
const READ_MS = 15_000;
|
|
7
|
+
export function gitStateKey(repo, pathspecs) {
|
|
8
|
+
try {
|
|
9
|
+
const deadline = Date.now() + READ_MS;
|
|
10
|
+
const staged = viewedGitSync(repo, ["ls-files", "-s", "-z", "--", ...pathspecs], { buffer: true, deadline, maxBuffer: 64 * 1024 * 1024 });
|
|
11
|
+
if (staged.status !== 0)
|
|
12
|
+
return null;
|
|
13
|
+
const changed = viewedGitSync(repo, ["ls-files", "-z", "-m", "-o", "--exclude-standard", "--", ...pathspecs], { buffer: true, deadline, maxBuffer: 64 * 1024 * 1024 });
|
|
14
|
+
const names = [...new Set((changed.status === 0 ? changed.stdout : Buffer.alloc(0)).toString("latin1").split("\0").filter(one => one !== ""))]
|
|
15
|
+
.sort((a, b) => Buffer.compare(Buffer.from(a, "latin1"), Buffer.from(b, "latin1"))).slice(0, NAME_LIMIT);
|
|
16
|
+
const utf8 = (name) => Buffer.from(name, "latin1").toString("utf8");
|
|
17
|
+
const present = names.filter(name => { try {
|
|
18
|
+
const st = lstatSync(join(repo, utf8(name)));
|
|
19
|
+
return st.isFile() && !st.isSymbolicLink();
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return false;
|
|
23
|
+
} });
|
|
24
|
+
const hashes = new Map();
|
|
25
|
+
for (let at = 0; at < present.length; at += 400) {
|
|
26
|
+
const chunk = present.slice(at, at + 400);
|
|
27
|
+
const out = viewedGitSync(repo, ["hash-object", "--no-filters", "--", ...chunk.map(utf8)], { buffer: true, deadline });
|
|
28
|
+
if (out.status !== 0)
|
|
29
|
+
continue;
|
|
30
|
+
out.stdout.toString("utf8").split("\n").filter(one => one !== "").forEach((hash, index) => { if (chunk[index] !== undefined)
|
|
31
|
+
hashes.set(chunk[index], hash); });
|
|
32
|
+
}
|
|
33
|
+
const hasher = createHash("sha256");
|
|
34
|
+
hasher.update(staged.stdout);
|
|
35
|
+
hasher.update("\n--\n");
|
|
36
|
+
for (const name of names) {
|
|
37
|
+
hasher.update(Buffer.from(name, "latin1"));
|
|
38
|
+
hasher.update(`\0${hashes.get(name) ?? "missing"}\n`);
|
|
39
|
+
}
|
|
40
|
+
return `s-${hasher.digest("hex").slice(0, 12)}`;
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { parentPort } from "node:worker_threads";
|
|
2
|
+
import { gitStateKey } from "./canvas-state-key.js";
|
|
3
|
+
parentPort.on("message", ({ id, repo, pathspecs }) => {
|
|
4
|
+
let key = null;
|
|
5
|
+
try {
|
|
6
|
+
key = gitStateKey(repo, pathspecs);
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
key = null;
|
|
10
|
+
}
|
|
11
|
+
parentPort.postMessage({ id, key });
|
|
12
|
+
});
|
|
@@ -6,9 +6,9 @@ import { openStore } from "./store.js";
|
|
|
6
6
|
import { holdAutoPublish, autoPublishHeld, PUBLISH_ALLOWED_ACTION, PUBLISH_HELD_ACTION } from "./release-auto.js";
|
|
7
7
|
import { revokeCoordinator } from "./coordinator.js";
|
|
8
8
|
export const MAX_STAGE_BYTES = 128 * 1024 * 1024;
|
|
9
|
-
const SUPPORTED_SCHEMA =
|
|
10
|
-
const SCHEMA_OBJECT_COUNT =
|
|
11
|
-
const SCHEMA_DIGEST = "
|
|
9
|
+
const SUPPORTED_SCHEMA = 189;
|
|
10
|
+
const SCHEMA_OBJECT_COUNT = 744;
|
|
11
|
+
const SCHEMA_DIGEST = "a82e2481b74fe91978efbec608e791876bb909df9a54acf084820fdcbab81cd8";
|
|
12
12
|
const INVENTORY = [
|
|
13
13
|
["person-credentials", "store.ts:revokeApiToken", "credential", true],
|
|
14
14
|
["lead-credentials", "store.ts:revokeLeadCredentials", "credential", true],
|
package/dist/chat-actions.js
CHANGED
|
@@ -1213,6 +1213,12 @@ export function executeSharedAction(store, who, id, payload, now, options) {
|
|
|
1213
1213
|
const refuse = (reason, said) => ({ ok: false, reason, said });
|
|
1214
1214
|
if (store.isDemo())
|
|
1215
1215
|
return refuse("refused", "The demo authorizes nothing.");
|
|
1216
|
+
if (options.via === "phone") {
|
|
1217
|
+
if (options.person !== undefined || options.typedStart !== undefined || options.confirm !== undefined || options.review !== undefined || !phoneSharedActionAllowed(payload))
|
|
1218
|
+
return refuse("refused", PHONE_NOT_CONFIRMABLE);
|
|
1219
|
+
if (!PHONE_CARDS_LIVE)
|
|
1220
|
+
return refuse("refused", PHONE_CARDS_LATER);
|
|
1221
|
+
}
|
|
1216
1222
|
if ((options.authority === "local-owner" || currentLocalOwner() !== null) && (!isChatAction(payload.operation) || CHAT_ACTION_LOCAL_ACTS[payload.operation] === null))
|
|
1217
1223
|
return refuse("refused", "Set a password to do this.");
|
|
1218
1224
|
let live;
|
|
@@ -1233,12 +1239,15 @@ export function executeSharedAction(store, who, id, payload, now, options) {
|
|
|
1233
1239
|
}
|
|
1234
1240
|
const savedStamp = payload.stamp;
|
|
1235
1241
|
payload = live;
|
|
1242
|
+
if (options.via === "phone" && !phoneSharedActionAllowed(live))
|
|
1243
|
+
return refuse("refused", PHONE_NOT_CONFIRMABLE);
|
|
1236
1244
|
const config = CHAT_ACTIONS[live.operation], req = live.request;
|
|
1237
1245
|
const typed = typedStartOpens(store, id, payload, options);
|
|
1238
1246
|
if (options.typedStart !== undefined && !typed)
|
|
1239
1247
|
return refuse("refused", TYPED_START_REFUSED);
|
|
1240
1248
|
const challenged = options.via !== "web" &&
|
|
1241
1249
|
options.via !== "cli" &&
|
|
1250
|
+
options.via !== "phone" &&
|
|
1242
1251
|
((options.confirm === true && sharedActionAllowsChallenge(payload, options.via)) || typed);
|
|
1243
1252
|
if (APPROVAL_ACTIONS.has(live.operation) && machineActing())
|
|
1244
1253
|
return refuse("needs-confirm", "Only a person approves this.");
|
|
@@ -1606,6 +1615,8 @@ function approvalBy(store, who, repo, now, options, drafted) {
|
|
|
1606
1615
|
return { ok: true, limits: { fullAccess: true, capMicrousd: null } };
|
|
1607
1616
|
if (options.via === "cli")
|
|
1608
1617
|
return { ok: false, why: "Approve this in chat or in Toolroll." };
|
|
1618
|
+
if (options.via === "phone")
|
|
1619
|
+
return { ok: false, why: PHONE_NOT_CONFIRMABLE };
|
|
1609
1620
|
const shown = { expect: String(drafted.state["shown"] ?? ""), terms: drafted.terms.join("\n") };
|
|
1610
1621
|
if (options.via === "web") {
|
|
1611
1622
|
const allowed = effectiveChatApproval(store, repo, who.name);
|
|
@@ -2113,3 +2124,18 @@ function runParityAction(store, who, payload, now, root) {
|
|
|
2113
2124
|
throw Error("Choose an available action.");
|
|
2114
2125
|
}
|
|
2115
2126
|
}
|
|
2127
|
+
export const PHONE_SHARED_ACTIONS = new Set([
|
|
2128
|
+
"finding_send", "finding_resend", "memory_decide", "lead_about_you", "lead_identity", "task_archive", "task_restore",
|
|
2129
|
+
"suggestion_not_now", "trial_stop", "mode_revoke", "flow_unattended_off", "flow_browser_off", "flow_trigger_pause",
|
|
2130
|
+
"flow_archive", "decision_record", "worker_note", "subagent_note", "subagent_ask", "subagent_answer",
|
|
2131
|
+
]);
|
|
2132
|
+
export const PHONE_CARDS_LIVE = false;
|
|
2133
|
+
export const PHONE_CARDS_LATER = "Confirm this on your Mac. Cards can't be confirmed from the iPhone app yet.";
|
|
2134
|
+
export const PHONE_NOT_CONFIRMABLE = "This can't be confirmed from the iPhone app. Open it on your Mac.";
|
|
2135
|
+
export function phoneSharedActionAllowed(action) {
|
|
2136
|
+
if (!isChatAction(action.operation) || !PHONE_SHARED_ACTIONS.has(action.operation))
|
|
2137
|
+
return false;
|
|
2138
|
+
const config = CHAT_ACTIONS[action.operation];
|
|
2139
|
+
return !config.protected && !config.password && !CREDENTIAL_ACTIONS.has(action.operation) && !APPROVAL_ACTIONS.has(action.operation)
|
|
2140
|
+
&& !CHALLENGE_ACTIONS.has(action.operation) && !sharedActionNeedsReview(action);
|
|
2141
|
+
}
|
package/dist/chat-channel.js
CHANGED
|
@@ -10,6 +10,7 @@ import { LEAD_TOOL_SCHEMAS } from "./lead-tools.js";
|
|
|
10
10
|
import { cardPlainOf, isCardProposal } from "./chat-card.js";
|
|
11
11
|
import { verifyApproverStanding } from "./principal.js";
|
|
12
12
|
import { canonicalProject } from "./project.js";
|
|
13
|
+
import { LEAD_THREAD } from "./store.js";
|
|
13
14
|
import { phoneText, projectLabel } from "./telegram-status.js";
|
|
14
15
|
import { CHAT_CONTROLS, chatControlHref, isChatControl, } from "./chat-controls.js";
|
|
15
16
|
import { CHAT_TASK_ACTIONS, isChatTaskAction } from "./chat-task-actions.js";
|
|
@@ -34,7 +35,7 @@ export function channelRepos(store, approver, registry) {
|
|
|
34
35
|
}
|
|
35
36
|
return repos;
|
|
36
37
|
}
|
|
37
|
-
export function resolveChannelLead(store, binding, repos, now) {
|
|
38
|
+
export function resolveChannelLead(store, binding, repos, now, scope = LEAD_THREAD) {
|
|
38
39
|
const config = store.getChatConfig();
|
|
39
40
|
if (config === null) {
|
|
40
41
|
return {
|
|
@@ -63,7 +64,7 @@ export function resolveChannelLead(store, binding, repos, now) {
|
|
|
63
64
|
const who = verified.who;
|
|
64
65
|
const credentialKey = subscriptionCredentialKey(config.provider);
|
|
65
66
|
let session = store.activeLeadSession(who.name);
|
|
66
|
-
const liveThread = store.liveLeadThreadFor(who.name);
|
|
67
|
+
const liveThread = store.liveLeadThreadFor(who.name, scope);
|
|
67
68
|
const sessionMismatch = session !== null &&
|
|
68
69
|
(session.approverGeneration !== who.generation ||
|
|
69
70
|
session.credentialKey !== credentialKey ||
|
|
@@ -88,7 +89,7 @@ export function resolveChannelLead(store, binding, repos, now) {
|
|
|
88
89
|
return { ok: false, reason: "no-session", said: couldNotAnswerText("a new chat session couldn't be started") };
|
|
89
90
|
}
|
|
90
91
|
const thread = threadMismatch || liveThread === null
|
|
91
|
-
? store.openLeadThread(who.name, who.ceilingDigest, now).thread
|
|
92
|
+
? store.openLeadThread(who.name, who.ceilingDigest, now, scope).thread
|
|
92
93
|
: liveThread;
|
|
93
94
|
return {
|
|
94
95
|
ok: true,
|
|
@@ -59,7 +59,7 @@ export function applyChatTaskAction(store, who, payload, now, web, controls = {}
|
|
|
59
59
|
return { ok: true, taskId: task, said: `Resume requested for ${task}. Finish it in your chat or on the task.` };
|
|
60
60
|
const allowed = effectiveChatApproval(store, ref.repo, who.name);
|
|
61
61
|
if (!allowed.ok && controls.via !== "web") {
|
|
62
|
-
const mode = controls.via === undefined || controls.via === "cli" ? allowed : chatApproveMode(store, ref.repo, who.name, now, controls.via);
|
|
62
|
+
const mode = controls.via === undefined || controls.via === "cli" || controls.via === "phone" ? allowed : chatApproveMode(store, ref.repo, who.name, now, controls.via);
|
|
63
63
|
if (!mode.ok)
|
|
64
64
|
return { ok: false, message: mode.why };
|
|
65
65
|
}
|
package/dist/chat-warmth.js
CHANGED
package/dist/check-report.js
CHANGED
|
@@ -12,12 +12,6 @@ export const TARGETED_PLAN_CAPTURE = "release check targeted plan v1";
|
|
|
12
12
|
export const OBLIGATION_SNAPSHOT_CAPTURE = "release check obligation snapshot v1";
|
|
13
13
|
export const CHECK_CONTEXT_CAPTURE = "release check context v1";
|
|
14
14
|
export const CHECK_ARTIFACT_CAP = CHECK_REPORT_MAX_BYTES;
|
|
15
|
-
export const HARNESS_FILES = Object.freeze([
|
|
16
|
-
"scripts/release-check.mjs", "scripts/release-check-ci.mjs", "scripts/upgrade-rule.mjs", "scripts/suite-lifecycle.mjs", "scripts/provider-gate.mjs",
|
|
17
|
-
"scripts/e2e-parallel.mjs", "scripts/e2e-kit.mjs", "scripts/isolated-env.mjs", "scripts/upgrade-path.mjs", "scripts/check-results.mjs",
|
|
18
|
-
"vitest.config.ts", "test/attacks/vitest.config.ts",
|
|
19
|
-
"test/setup-state.ts", "test/fresh-store.ts", "test/temp-root.ts", "test/ensure-build.ts", "test/release-reporter.ts",
|
|
20
|
-
]);
|
|
21
15
|
export const UNIT_INCLUDE = Object.freeze([/^src\/.+\.test\.ts$/, /^test\/attacks\/.+\.test\.ts$/]);
|
|
22
16
|
export const isUnitFile = (path) => UNIT_INCLUDE.some(one => one.test(path));
|
|
23
17
|
export function projectGitDir(repo) {
|
package/dist/commit-extract.js
CHANGED
|
@@ -381,51 +381,13 @@ export function verifiedTreeDiff(gitDir, beforeTree, afterTree) {
|
|
|
381
381
|
const reader = verifiedReader(gitDir);
|
|
382
382
|
if (!reader.ok)
|
|
383
383
|
return reader;
|
|
384
|
-
|
|
385
|
-
if (!before.ok)
|
|
386
|
-
return before;
|
|
387
|
-
const after = treeEntriesWith(reader.value, afterTree, EXTRACTION_LIMITS);
|
|
388
|
-
if (!after.ok)
|
|
389
|
-
return after;
|
|
390
|
-
const was = new Map(before.value.map(one => [one.path, one]));
|
|
391
|
-
const now = new Map(after.value.map(one => [one.path, one]));
|
|
392
|
-
const paths = [...new Set([...was.keys(), ...now.keys()])].sort();
|
|
393
|
-
const differing = paths.filter(path => { const a = was.get(path), b = now.get(path); return a === undefined || b === undefined || a.id !== b.id || a.mode !== b.mode; });
|
|
394
|
-
const blobIds = differing.flatMap(path => [was.get(path), now.get(path)]).filter((one) => one !== undefined && (one.mode === "100644" || one.mode === "100755")).map(one => one.id);
|
|
395
|
-
const blobs = reader.value.read(blobIds);
|
|
396
|
-
if (typeof blobs === "string")
|
|
397
|
-
return { ok: false, message: `A changed file couldn't be verified: ${blobs}.` };
|
|
398
|
-
const changes = [];
|
|
399
|
-
for (const path of differing) {
|
|
400
|
-
const a = was.get(path) ?? null, b = now.get(path) ?? null;
|
|
401
|
-
const bytesOf = (entry) => {
|
|
402
|
-
if (entry === null || (entry.mode !== "100644" && entry.mode !== "100755"))
|
|
403
|
-
return null;
|
|
404
|
-
const blob = blobs.get(entry.id);
|
|
405
|
-
return blob !== undefined && blob.type === "blob" ? blob.bytes : null;
|
|
406
|
-
};
|
|
407
|
-
const fileLike = (entry) => entry === null || entry.mode === "100644" || entry.mode === "100755";
|
|
408
|
-
const ab = bytesOf(a), bb = bytesOf(b);
|
|
409
|
-
if ((a !== null && fileLike(a) && ab === null) || (b !== null && fileLike(b) && bb === null))
|
|
410
|
-
return { ok: false, message: `${path} isn't a file in its commit.` };
|
|
411
|
-
const binary = !fileLike(a) || !fileLike(b) || (ab !== null && looksBinary(ab)) || (bb !== null && looksBinary(bb));
|
|
412
|
-
const counted = binary ? { added: 0, deleted: 0 } : lineChanges(ab ?? Buffer.alloc(0), bb ?? Buffer.alloc(0));
|
|
413
|
-
changes.push({ path, kind: a === null ? "added" : b === null ? "deleted" : "modified", before: a, after: b, ...counted, binary });
|
|
414
|
-
}
|
|
415
|
-
return { ok: true, value: changes };
|
|
384
|
+
return treeDiffWith(reader.value, tree => treeEntriesWith(reader.value, tree, EXTRACTION_LIMITS), beforeTree, afterTree);
|
|
416
385
|
}
|
|
417
386
|
export function verifiedBlobs(gitDir, tree, paths) {
|
|
418
387
|
const reader = verifiedReader(gitDir);
|
|
419
388
|
if (!reader.ok)
|
|
420
389
|
return reader;
|
|
421
|
-
|
|
422
|
-
if (!entries.ok)
|
|
423
|
-
return entries;
|
|
424
|
-
const wanted = entries.value.filter(one => paths.includes(one.path) && (one.mode === "100644" || one.mode === "100755"));
|
|
425
|
-
const blobs = reader.value.read(wanted.map(one => one.id));
|
|
426
|
-
if (typeof blobs === "string")
|
|
427
|
-
return { ok: false, message: `A file couldn't be verified: ${blobs}.` };
|
|
428
|
-
return { ok: true, value: new Map(wanted.map(one => [one.path, { id: one.id, bytes: blobs.get(one.id).bytes }])) };
|
|
390
|
+
return blobsWith(reader.value, one => treeEntriesWith(reader.value, one, EXTRACTION_LIMITS), tree, paths);
|
|
429
391
|
}
|
|
430
392
|
export function verifiedRange(gitDir, from, to, options = {}) {
|
|
431
393
|
const { max = 1_000, reach = 5_000 } = options;
|
|
@@ -522,3 +484,80 @@ export function verifiedFirstParentAncestry(gitDir, from, until, options) {
|
|
|
522
484
|
}
|
|
523
485
|
return "unknown";
|
|
524
486
|
}
|
|
487
|
+
function treeDiffWith(reader, entriesOf, beforeTree, afterTree) {
|
|
488
|
+
const before = entriesOf(beforeTree);
|
|
489
|
+
if (!before.ok)
|
|
490
|
+
return before;
|
|
491
|
+
const after = entriesOf(afterTree);
|
|
492
|
+
if (!after.ok)
|
|
493
|
+
return after;
|
|
494
|
+
const was = new Map(before.value.map(one => [one.path, one]));
|
|
495
|
+
const now = new Map(after.value.map(one => [one.path, one]));
|
|
496
|
+
const paths = [...new Set([...was.keys(), ...now.keys()])].sort();
|
|
497
|
+
const differing = paths.filter(path => { const a = was.get(path), b = now.get(path); return a === undefined || b === undefined || a.id !== b.id || a.mode !== b.mode; });
|
|
498
|
+
const blobIds = differing.flatMap(path => [was.get(path), now.get(path)]).filter((one) => one !== undefined && (one.mode === "100644" || one.mode === "100755")).map(one => one.id);
|
|
499
|
+
const blobs = reader.read(blobIds);
|
|
500
|
+
if (typeof blobs === "string")
|
|
501
|
+
return { ok: false, message: `A changed file couldn't be verified: ${blobs}.` };
|
|
502
|
+
const changes = [];
|
|
503
|
+
for (const path of differing) {
|
|
504
|
+
const a = was.get(path) ?? null, b = now.get(path) ?? null;
|
|
505
|
+
const bytesOf = (entry) => {
|
|
506
|
+
if (entry === null || (entry.mode !== "100644" && entry.mode !== "100755"))
|
|
507
|
+
return null;
|
|
508
|
+
const blob = blobs.get(entry.id);
|
|
509
|
+
return blob !== undefined && blob.type === "blob" ? blob.bytes : null;
|
|
510
|
+
};
|
|
511
|
+
const fileLike = (entry) => entry === null || entry.mode === "100644" || entry.mode === "100755";
|
|
512
|
+
const ab = bytesOf(a), bb = bytesOf(b);
|
|
513
|
+
if ((a !== null && fileLike(a) && ab === null) || (b !== null && fileLike(b) && bb === null))
|
|
514
|
+
return { ok: false, message: `${path} isn't a file in its commit.` };
|
|
515
|
+
const binary = !fileLike(a) || !fileLike(b) || (ab !== null && looksBinary(ab)) || (bb !== null && looksBinary(bb));
|
|
516
|
+
const counted = binary ? { added: 0, deleted: 0 } : lineChanges(ab ?? Buffer.alloc(0), bb ?? Buffer.alloc(0));
|
|
517
|
+
changes.push({ path, kind: a === null ? "added" : b === null ? "deleted" : "modified", before: a, after: b, ...counted, binary });
|
|
518
|
+
}
|
|
519
|
+
return { ok: true, value: changes };
|
|
520
|
+
}
|
|
521
|
+
function blobsWith(reader, entriesOf, tree, paths) {
|
|
522
|
+
const entries = entriesOf(tree);
|
|
523
|
+
if (!entries.ok)
|
|
524
|
+
return entries;
|
|
525
|
+
const wanted = entries.value.filter(one => paths.includes(one.path) && (one.mode === "100644" || one.mode === "100755"));
|
|
526
|
+
const blobs = reader.read(wanted.map(one => one.id));
|
|
527
|
+
if (typeof blobs === "string")
|
|
528
|
+
return { ok: false, message: `A file couldn't be verified: ${blobs}.` };
|
|
529
|
+
return { ok: true, value: new Map(wanted.map(one => [one.path, { id: one.id, bytes: blobs.get(one.id).bytes }])) };
|
|
530
|
+
}
|
|
531
|
+
export function verifiedView(gitDir) {
|
|
532
|
+
const opened = verifiedReader(gitDir);
|
|
533
|
+
if (!opened.ok)
|
|
534
|
+
return opened;
|
|
535
|
+
const objects = new Map();
|
|
536
|
+
const reader = { ...opened.value, read: ids => {
|
|
537
|
+
const missing = [...new Set(ids)].filter(id => !objects.has(id));
|
|
538
|
+
if (missing.length > 0) {
|
|
539
|
+
const got = opened.value.read(missing);
|
|
540
|
+
if (typeof got === "string")
|
|
541
|
+
return got;
|
|
542
|
+
for (const [id, object] of got)
|
|
543
|
+
objects.set(id, object);
|
|
544
|
+
}
|
|
545
|
+
return new Map(ids.map(id => [id, objects.get(id)]));
|
|
546
|
+
} };
|
|
547
|
+
const walked = new Map();
|
|
548
|
+
const entriesOf = (tree) => {
|
|
549
|
+
const known = walked.get(tree);
|
|
550
|
+
if (known !== undefined)
|
|
551
|
+
return { ok: true, value: [...known] };
|
|
552
|
+
const entries = treeEntriesWith(reader, tree, EXTRACTION_LIMITS);
|
|
553
|
+
if (entries.ok)
|
|
554
|
+
walked.set(tree, [...entries.value]);
|
|
555
|
+
return entries;
|
|
556
|
+
};
|
|
557
|
+
return { ok: true, value: {
|
|
558
|
+
commit: sha => readCommitWith(reader, sha),
|
|
559
|
+
treeEntries: entriesOf,
|
|
560
|
+
treeDiff: (beforeTree, afterTree) => treeDiffWith(reader, entriesOf, beforeTree, afterTree),
|
|
561
|
+
blobs: (tree, paths) => blobsWith(reader, entriesOf, tree, paths),
|
|
562
|
+
} };
|
|
563
|
+
}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { hostname } from "node:os";
|
|
2
|
+
import { CompanionService, relayAddressesOf } from "./service.js";
|
|
3
|
+
import { readCompanionHostKeys } from "./store.js";
|
|
4
|
+
export const DEFAULT_DIRECT_PORT = 4199;
|
|
5
|
+
export const FALLBACK_DIRECT_PORTS = Object.freeze([4200, 4201, 4202, 4203, 4204, 4205, 4206, 4207, 4208, 4209]);
|
|
6
|
+
export const DEFAULT_HOSTED_RELAY = "wss://relay.toolroll.dev";
|
|
7
|
+
const FETCH_BAD_PORTS = new Set([1719, 1720, 1723, 2049, 3659, 4045, 4190, 5060, 5061, 6000, 6566, 6665, 6666, 6667, 6668, 6669, 6679, 6697, 10080]);
|
|
8
|
+
function savedAccess(db) {
|
|
9
|
+
const row = db.prepare("SELECT enabled, hosted_relay, direct_port FROM companion_access WHERE singleton = 1").get();
|
|
10
|
+
const relay = row?.["hosted_relay"];
|
|
11
|
+
const port = row?.["direct_port"];
|
|
12
|
+
return {
|
|
13
|
+
enabled: row !== undefined && Number(row["enabled"]) === 1,
|
|
14
|
+
hostedRelay: typeof relay === "string" && relay.length > 0 ? relay : null,
|
|
15
|
+
directPort: typeof port === "number" && Number.isInteger(port) ? port : typeof port === "bigint" ? Number(port) : null,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function saveDirectPort(db, port) {
|
|
19
|
+
db.prepare("UPDATE companion_access SET direct_port = ? WHERE singleton = 1").run(port);
|
|
20
|
+
}
|
|
21
|
+
const relayIdentityOf = (url) => relayAddressesOf(url).ws;
|
|
22
|
+
export function phoneAccessEnabled(db) {
|
|
23
|
+
return savedAccess(db).enabled;
|
|
24
|
+
}
|
|
25
|
+
function savePhoneAccess(db, enabled, hostedRelay, by, now) {
|
|
26
|
+
db.prepare(`INSERT INTO companion_access (singleton, enabled, hosted_relay, changed_by, changed_at) VALUES (1, ?, ?, ?, ?)
|
|
27
|
+
ON CONFLICT(singleton) DO UPDATE SET enabled = excluded.enabled, hosted_relay = excluded.hosted_relay, changed_by = excluded.changed_by, changed_at = excluded.changed_at`)
|
|
28
|
+
.run(enabled ? 1 : 0, hostedRelay, by, now.toISOString());
|
|
29
|
+
}
|
|
30
|
+
export function hostedRelayOf(env) {
|
|
31
|
+
const raw = env["TOOLROLL_RELAY_URL"]?.trim();
|
|
32
|
+
if (raw === undefined || raw.length === 0)
|
|
33
|
+
return { ok: true, url: DEFAULT_HOSTED_RELAY };
|
|
34
|
+
if (raw.toLowerCase() === "off")
|
|
35
|
+
return { ok: false, off: true };
|
|
36
|
+
try {
|
|
37
|
+
relayAddressesOf(raw);
|
|
38
|
+
return { ok: true, url: raw };
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
return { ok: false, off: false, problem: `TOOLROLL_RELAY_URL: ${error instanceof Error ? error.message : String(error)}` };
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export function directPortOf(env) {
|
|
45
|
+
const name = env["TOOLROLL_PHONE_PORT"]?.trim() ? "TOOLROLL_PHONE_PORT" : "TOOLROLL_PHONE_RELAY_PORT";
|
|
46
|
+
const raw = env[name]?.trim();
|
|
47
|
+
const port = raw === undefined || raw.length === 0 ? DEFAULT_DIRECT_PORT : Number(raw);
|
|
48
|
+
if (!Number.isInteger(port) || port < 1024 || port > 65_535)
|
|
49
|
+
return { ok: false, problem: `${name} must be a port from 1024 to 65535.` };
|
|
50
|
+
if (FETCH_BAD_PORTS.has(port))
|
|
51
|
+
return { ok: false, problem: `${name} ${port} is a port web clients refuse to connect to; choose another.` };
|
|
52
|
+
return { ok: true, port };
|
|
53
|
+
}
|
|
54
|
+
export function createPhoneAccess(opts) {
|
|
55
|
+
const env = opts.env ?? process.env;
|
|
56
|
+
let running = null;
|
|
57
|
+
let changing = Promise.resolve();
|
|
58
|
+
const problems = () => {
|
|
59
|
+
const port = directPortOf(env), hosted = hostedRelayOf(env);
|
|
60
|
+
return [...(port.ok ? [] : [port.problem]), ...(!hosted.ok && !hosted.off ? [hosted.problem] : [])];
|
|
61
|
+
};
|
|
62
|
+
const start = async () => {
|
|
63
|
+
if (running !== null)
|
|
64
|
+
return;
|
|
65
|
+
const port = directPortOf(env), hosted = hostedRelayOf(env);
|
|
66
|
+
const saved = savedAccess(opts.store.handle);
|
|
67
|
+
const approved = saved.hostedRelay;
|
|
68
|
+
const wantHosted = hosted.ok && approved !== null && approved === relayIdentityOf(hosted.url);
|
|
69
|
+
const service = new CompanionService({
|
|
70
|
+
store: opts.store, reads: opts.reads,
|
|
71
|
+
...(opts.actions === undefined ? {} : { actions: opts.actions }),
|
|
72
|
+
...(opts.chat === undefined ? {} : { chat: opts.chat }),
|
|
73
|
+
direct: port.ok ? { port: port.port, fallbackPorts: FALLBACK_DIRECT_PORTS, preferredPort: saved.directPort, onBound: bound => saveDirectPort(opts.store.handle, bound) } : null,
|
|
74
|
+
hosted: wantHosted ? hosted.url : null,
|
|
75
|
+
...(opts.log === undefined ? {} : { log: opts.log }),
|
|
76
|
+
...(opts.consoleUrl === undefined ? {} : { consoleUrl: opts.consoleUrl }),
|
|
77
|
+
...(opts.bonjour === true ? { bonjour: true } : {}),
|
|
78
|
+
});
|
|
79
|
+
await service.start();
|
|
80
|
+
running = service;
|
|
81
|
+
};
|
|
82
|
+
const stop = async () => {
|
|
83
|
+
const service = running;
|
|
84
|
+
running = null;
|
|
85
|
+
if (service !== null)
|
|
86
|
+
await service.stop();
|
|
87
|
+
};
|
|
88
|
+
const serially = (work) => {
|
|
89
|
+
changing = changing.then(work, work);
|
|
90
|
+
return changing;
|
|
91
|
+
};
|
|
92
|
+
return {
|
|
93
|
+
service: () => running,
|
|
94
|
+
enabled: () => phoneAccessEnabled(opts.store.handle),
|
|
95
|
+
hostedEnabled: () => {
|
|
96
|
+
const hosted = hostedRelayOf(env), approved = savedAccess(opts.store.handle).hostedRelay;
|
|
97
|
+
return hosted.ok && approved !== null && approved === relayIdentityOf(hosted.url);
|
|
98
|
+
},
|
|
99
|
+
hostedApprovalStale: () => {
|
|
100
|
+
const hosted = hostedRelayOf(env), approved = savedAccess(opts.store.handle).hostedRelay;
|
|
101
|
+
return approved !== null && (!hosted.ok || approved !== relayIdentityOf(hosted.url));
|
|
102
|
+
},
|
|
103
|
+
hostedChoice: () => hostedRelayOf(env),
|
|
104
|
+
problems,
|
|
105
|
+
change: (change, by, now, allowed) => {
|
|
106
|
+
let outcome = "ok";
|
|
107
|
+
return serially(async () => {
|
|
108
|
+
if (allowed !== undefined && !allowed()) {
|
|
109
|
+
outcome = "not_allowed";
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const saved = savedAccess(opts.store.handle), hosted = hostedRelayOf(env);
|
|
113
|
+
const current = hosted.ok ? relayIdentityOf(hosted.url) : null;
|
|
114
|
+
let enabled, approved;
|
|
115
|
+
if (change.act === "on") {
|
|
116
|
+
enabled = true;
|
|
117
|
+
approved = change.hosted ? current : null;
|
|
118
|
+
}
|
|
119
|
+
else if (change.act === "off") {
|
|
120
|
+
enabled = false;
|
|
121
|
+
approved = null;
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
if (!saved.enabled) {
|
|
125
|
+
outcome = "not_on";
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
enabled = true;
|
|
129
|
+
approved = change.act === "hosted-on" ? current : null;
|
|
130
|
+
}
|
|
131
|
+
savePhoneAccess(opts.store.handle, enabled, approved, by, now);
|
|
132
|
+
const service = running;
|
|
133
|
+
if (service !== null && service.status().hosted.state !== "off" && (!enabled || approved === null))
|
|
134
|
+
await service.forgetHostedMachine();
|
|
135
|
+
await stop();
|
|
136
|
+
if (enabled) {
|
|
137
|
+
await start();
|
|
138
|
+
const deadline = Date.now() + 3_000;
|
|
139
|
+
while (running !== null && running.status().hosted.state === "starting" && Date.now() < deadline)
|
|
140
|
+
await new Promise(resolve => setTimeout(resolve, 50));
|
|
141
|
+
}
|
|
142
|
+
}).then(() => outcome);
|
|
143
|
+
},
|
|
144
|
+
resume: () => serially(async () => { if (phoneAccessEnabled(opts.store.handle))
|
|
145
|
+
await start(); }),
|
|
146
|
+
stop: () => serially(stop),
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
export function hostedRelayRoomOf(store) {
|
|
150
|
+
try {
|
|
151
|
+
const approved = savedAccess(store.handle).hostedRelay;
|
|
152
|
+
const keys = readCompanionHostKeys(store.handle);
|
|
153
|
+
return approved === null || keys === null ? null : { relayUrl: approved, keys };
|
|
154
|
+
}
|
|
155
|
+
catch {
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
export function workspaceLabelOf() {
|
|
160
|
+
const name = hostname().replace(/\.local$/i, "").replace(/-/g, " ").trim();
|
|
161
|
+
return name.length === 0 ? "Your Mac" : name.slice(0, 64);
|
|
162
|
+
}
|