toolroll 0.9.129 → 0.9.131
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 +44 -0
- package/dist/agent-fence.js +0 -2
- package/dist/agent-state.js +1 -1
- package/dist/agents-board.js +0 -3
- package/dist/assignment.js +4 -3
- package/dist/backup-ui.js +6 -3
- package/dist/bounded-spawn.js +0 -1
- package/dist/browser/manifest.json +57 -0
- package/dist/browser/terminal.4d1cf20c32ad7c2099df657358d540d5fd92bb55195a88121e74b28467238b42.css.br +0 -0
- package/dist/browser/terminal.4d1cf20c32ad7c2099df657358d540d5fd92bb55195a88121e74b28467238b42.css.gz +0 -0
- package/dist/browser/{terminal.js → terminal.8978c8cbb268e1006f4b0be371c2401b58078e6d9f1380f4a5c2a12da843909f.js} +1 -1
- package/dist/browser/terminal.8978c8cbb268e1006f4b0be371c2401b58078e6d9f1380f4a5c2a12da843909f.js.br +0 -0
- package/dist/browser/terminal.8978c8cbb268e1006f4b0be371c2401b58078e6d9f1380f4a5c2a12da843909f.js.gz +0 -0
- package/dist/browser/{workspace.js → workspace.4f5935dc80574baadf1adafd39a08c567fb1fac1323052ca355546622f9b06d2.js} +25 -25
- package/dist/browser/workspace.4f5935dc80574baadf1adafd39a08c567fb1fac1323052ca355546622f9b06d2.js.br +0 -0
- package/dist/browser/workspace.4f5935dc80574baadf1adafd39a08c567fb1fac1323052ca355546622f9b06d2.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/builder-restart.js +13 -4
- package/dist/builder.js +4 -1
- 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-follow.js +4 -0
- 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 +1 -0
- package/dist/companion/actions.js +79 -16
- 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 +46 -5
- package/dist/companion/finish.js +51 -0
- package/dist/companion/reads.js +5 -1
- package/dist/companion/schema.js +64 -0
- package/dist/companion/service.js +1 -0
- package/dist/companion/store.js +1 -0
- package/dist/companion/webauthn.js +11 -2
- package/dist/console-instance.js +0 -4
- package/dist/contracts/console-api.js +1 -1
- package/dist/converse.js +0 -1
- package/dist/coordinator.js +1 -1
- package/dist/db-tuning.js +16 -0
- package/dist/desktop-config.js +156 -0
- package/dist/desktop-host.js +6 -152
- package/dist/desktop-update.js +1 -1
- package/dist/discord.js +9 -3
- package/dist/dispatch.js +32 -4
- package/dist/doctor.js +30 -0
- package/dist/evidence.js +49 -3
- package/dist/exec.js +3 -0
- package/dist/finished-task-sql.js +14 -0
- package/dist/flexible-answers.js +0 -1
- package/dist/git-views.js +7 -1
- package/dist/github-read.js +41 -0
- package/dist/guides.js +4 -3
- package/dist/invoke.js +12 -2
- package/dist/lead-doors.js +50 -3
- package/dist/lead-queue-runtime.js +18 -6
- package/dist/lead-queue.js +25 -0
- package/dist/lead-status.js +3 -3
- 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-owner.js +0 -1
- package/dist/loop-recovery.js +40 -0
- package/dist/maintenance.js +29 -1
- package/dist/model-choices.js +0 -11
- package/dist/needs-you.js +2 -0
- 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 +393 -56
- package/dist/planner.js +4 -1
- package/dist/pull-request-flow.js +56 -15
- package/dist/qr.js +0 -25
- package/dist/query-index-schema.js +10 -0
- package/dist/read-executor-worker.js +9 -7
- package/dist/read-executor.js +18 -1
- package/dist/read-worker-connection.js +7 -0
- package/dist/release-adapters.js +63 -48
- package/dist/release-auto.js +17 -13
- package/dist/release-card.js +0 -4
- package/dist/release-cli.js +58 -10
- package/dist/release-next.js +1 -1
- package/dist/release-stops.js +71 -0
- package/dist/release-supersede.js +125 -0
- package/dist/release-supervise.js +90 -0
- package/dist/release.js +265 -42
- package/dist/restore-retirement.js +4 -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/runner.js +36 -1
- package/dist/sandbox-runtime.js +0 -1
- package/dist/scope.js +1 -13
- package/dist/scout.js +4 -7
- package/dist/serve.js +122 -12
- package/dist/server/kit.js +1 -0
- package/dist/server/live.js +9 -2
- package/dist/server/pages.js +3 -2
- package/dist/server/phone-engine-api.js +22 -2
- 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 +1 -1
- package/dist/server/settings-phone.js +32 -9
- package/dist/server/settings-scripts.js +1 -1
- package/dist/server/settings-section-table.js +0 -3
- package/dist/server/settings-sections.js +4 -2
- package/dist/server/settings.js +20 -5
- package/dist/server/terminals.js +2 -1
- package/dist/shutdown-proof.js +29 -0
- package/dist/slack.js +9 -3
- package/dist/sqlite-telemetry.js +26 -14
- package/dist/statement-cache.js +137 -0
- package/dist/store.js +86 -14
- package/dist/structured-output.js +0 -1
- package/dist/style-asset.js +20 -7
- package/dist/tailnet.js +0 -3
- package/dist/task-control.js +5 -0
- package/dist/task-sizing.js +0 -1
- package/dist/task-status.js +1 -1
- package/dist/teams.js +9 -3
- package/dist/teardown-git.js +10 -1
- package/dist/telegram.js +4 -1
- package/dist/toolroll-update-cli.js +19 -3
- package/dist/toolroll-update-ui.js +2 -2
- package/dist/toolroll-update.js +95 -15
- package/dist/up-processes.js +16 -1
- package/dist/up-role-child.js +2 -0
- package/dist/wake-hub.js +15 -6
- package/dist/work-index.js +101 -44
- package/dist/work-reads.js +53 -9
- package/dist/work-snapshots.js +185 -0
- package/dist/worker-statement-cache.js +83 -0
- package/dist/workspace-revision.js +145 -21
- package/package.json +1 -1
- package/dist/companion/webauthn-test-support.js +0 -44
- package/dist/contracts/contract-test.js +0 -55
- package/dist/unfenced-test-support.js +0 -6
- /package/dist/browser/{terminal.css → terminal.4d1cf20c32ad7c2099df657358d540d5fd92bb55195a88121e74b28467238b42.css} +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 = 190;
|
|
10
|
+
const SCHEMA_OBJECT_COUNT = 744;
|
|
11
|
+
const SCHEMA_DIGEST = "2c8956f909b9e12062c684ab857dff4737929172b510da6f4fece6b3a49112ad";
|
|
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,
|
package/dist/chat-follow.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { setTimeout as sleep } from "node:timers/promises";
|
|
2
|
+
export const busyError = (error) => {
|
|
3
|
+
const code = error?.errcode;
|
|
4
|
+
return typeof code === "number" && (code & 0xff) === 5;
|
|
5
|
+
};
|
|
2
6
|
export const abortablePause = (signal) => async (ms) => {
|
|
3
7
|
try {
|
|
4
8
|
await sleep(ms, undefined, { signal });
|
|
@@ -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
|
+
}
|
package/dist/companion/access.js
CHANGED
|
@@ -69,6 +69,7 @@ export function createPhoneAccess(opts) {
|
|
|
69
69
|
const service = new CompanionService({
|
|
70
70
|
store: opts.store, reads: opts.reads,
|
|
71
71
|
...(opts.actions === undefined ? {} : { actions: opts.actions }),
|
|
72
|
+
...(opts.chat === undefined ? {} : { chat: opts.chat }),
|
|
72
73
|
direct: port.ok ? { port: port.port, fallbackPorts: FALLBACK_DIRECT_PORTS, preferredPort: saved.directPort, onBound: bound => saveDirectPort(opts.store.handle, bound) } : null,
|
|
73
74
|
hosted: wantHosted ? hosted.url : null,
|
|
74
75
|
...(opts.log === undefined ? {} : { log: opts.log }),
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
1
2
|
import { acceptAndCompleteAsOperator, acceptWindowCovers, assignmentOf } from "../assignment.js";
|
|
2
|
-
import { land, readLanding } from "../local-landing.js";
|
|
3
|
+
import { land, landingWords, readLanding } from "../local-landing.js";
|
|
3
4
|
import { verifyApproverStanding } from "../principal.js";
|
|
4
|
-
import { completeAndOpenPullRequest, mergeAsPerson } from "../pull-request-flow.js";
|
|
5
|
+
import { completeAndOpenPullRequest, mergeAsPerson, pullRequestOnGitHub, pullRequestViewOf } from "../pull-request-flow.js";
|
|
5
6
|
import { approvalWindowCovers, approve } from "../scope.js";
|
|
6
7
|
import { requestContext } from "../server/request-context.js";
|
|
7
8
|
import { claimDeviceIdempotency, consumePasskeyChallenge, deviceAccountStands, getAccountPasskey, getPairedDevice, getPasskeyChallenge, insertAccountPasskey, listActiveAccountPasskeys, pruneDeviceIdempotency, prunePasskeyChallenges, reconcileIdempotencyOnStartup, savePasskeyChallenge, settleDeviceIdempotency, } from "./store.js";
|
|
8
|
-
import { acceptBindingOf, buildActionChallenge, canonicalJson, derivePasskeyUserHandle, minutesWords, normalizeAcceptNote, passkeyProofDetail, PASSKEY_CHALLENGE_TTL_MS, PASSKEY_ORIGIN, PASSKEY_RP_ID, PASSKEY_RP_NAME, randomChallenge32, sha256, verifyRegistrationResponse, } from "./webauthn.js";
|
|
9
|
+
import { acceptBindingOf, buildActionChallenge, canonicalJson, derivePasskeyUserHandle, minutesWords, normalizeAcceptNote, passkeyProofDetail, publishDestinationForRun, PASSKEY_CHALLENGE_TTL_MS, PASSKEY_ORIGIN, PASSKEY_RP_ID, PASSKEY_RP_NAME, randomChallenge32, sha256, verifyRegistrationResponse, } from "./webauthn.js";
|
|
9
10
|
import { activePasskeyLease, clearPasskeyLeases, passkeyApprovalWindowMinutes, startPasskeyLease, verifyPasskeyAction, } from "./passkey-gate.js";
|
|
10
11
|
export const APPROVALS_UNLOCKED_ACTION = "approvals unlocked";
|
|
11
12
|
export const PASSKEY_ENROLLMENT_WINDOW_MS = 5 * 60 * 1000;
|
|
@@ -18,6 +19,7 @@ export class CompanionActionError extends Error {
|
|
|
18
19
|
this.code = code;
|
|
19
20
|
}
|
|
20
21
|
}
|
|
22
|
+
export const PHONE_MERGE_OFF = "Merging from iPhone is off for now. Merge it on your Mac.";
|
|
21
23
|
function parseAssertion(raw) {
|
|
22
24
|
if (raw === null || typeof raw !== "object" || Array.isArray(raw)) {
|
|
23
25
|
throw new CompanionActionError("invalid_params", "assertion object is required");
|
|
@@ -124,10 +126,13 @@ export function createCompanionActions(deps) {
|
|
|
124
126
|
}
|
|
125
127
|
function openEnrollmentWindow(accountName, deviceId = null) {
|
|
126
128
|
const expiresAtMs = now().getTime() + PASSKEY_ENROLLMENT_WINDOW_MS;
|
|
127
|
-
|
|
128
|
-
|
|
129
|
+
const id = randomUUID();
|
|
130
|
+
windows.set(accountName, { id, accountName, deviceId, expiresAtMs });
|
|
131
|
+
return { expiresAtMs, windowId: id };
|
|
129
132
|
}
|
|
130
|
-
function closeEnrollmentWindow(accountName) {
|
|
133
|
+
function closeEnrollmentWindow(accountName, windowId) {
|
|
134
|
+
if (windowId !== undefined && windows.get(accountName)?.id !== windowId)
|
|
135
|
+
return;
|
|
131
136
|
windows.delete(accountName);
|
|
132
137
|
}
|
|
133
138
|
async function withIdempotency(principal, method, idempotencyKey, canonicalTarget, work) {
|
|
@@ -215,7 +220,7 @@ export function createCompanionActions(deps) {
|
|
|
215
220
|
passkeyRegisterBegin: async (principal) => {
|
|
216
221
|
const { accountName } = standsApprover(principal);
|
|
217
222
|
if (!isEnrollmentOpen(accountName, principal.deviceId)) {
|
|
218
|
-
throw new CompanionActionError("enrollment_closed", "
|
|
223
|
+
throw new CompanionActionError("enrollment_closed", "On your Mac, open Settings → Phone → Passkey approvals → Set up first.");
|
|
219
224
|
}
|
|
220
225
|
const identity = store.workspaceIdentity();
|
|
221
226
|
const t = now();
|
|
@@ -332,6 +337,7 @@ export function createCompanionActions(deps) {
|
|
|
332
337
|
let binding;
|
|
333
338
|
let windowCovers = false;
|
|
334
339
|
let wording = null;
|
|
340
|
+
let terms = null;
|
|
335
341
|
if (verb === "approve") {
|
|
336
342
|
const taskId = requireString(params, "task");
|
|
337
343
|
if (!TASK_ID.test(taskId))
|
|
@@ -367,7 +373,10 @@ export function createCompanionActions(deps) {
|
|
|
367
373
|
throw new CompanionActionError("refused", "This result changed. Refresh before accepting.");
|
|
368
374
|
}
|
|
369
375
|
windowCovers = acceptWindowCovers(store, before, publish, runtime.evidenceRoot);
|
|
370
|
-
|
|
376
|
+
const destination = publish ? publishDestinationForRun(store, before.receipt.runId) : undefined;
|
|
377
|
+
binding = acceptBindingOf({ taskId, runId, receiptDigest, note: params["note"], publish, destination }, before.receipt.runId);
|
|
378
|
+
if (publish)
|
|
379
|
+
terms = openPullRequestTerms(destination ?? null, before.state === "complete");
|
|
371
380
|
}
|
|
372
381
|
else if (verb === "land") {
|
|
373
382
|
const taskId = requireString(params, "task");
|
|
@@ -387,10 +396,13 @@ export function createCompanionActions(deps) {
|
|
|
387
396
|
throw new CompanionActionError("refused", "This result has already landed.");
|
|
388
397
|
const planKey = typeof params["key"] === "string" && params["key"].length > 0 ? params["key"] : read.plan.key;
|
|
389
398
|
if (planKey !== read.plan.key)
|
|
390
|
-
throw new CompanionActionError("
|
|
399
|
+
throw new CompanionActionError("changed", "The landing plan changed. Review it again.");
|
|
391
400
|
binding = { verb: "land", taskId, planKey, into, undo };
|
|
401
|
+
terms = landTerms(read.plan);
|
|
392
402
|
}
|
|
393
403
|
else if (verb === "ship") {
|
|
404
|
+
if (deps.phoneMerge !== true)
|
|
405
|
+
throw new CompanionActionError("refused", PHONE_MERGE_OFF);
|
|
394
406
|
const runIdRaw = params["runId"];
|
|
395
407
|
if (typeof runIdRaw !== "number" || !Number.isInteger(runIdRaw) || runIdRaw <= 0) {
|
|
396
408
|
throw new CompanionActionError("invalid_params", "runId is required");
|
|
@@ -407,7 +419,17 @@ export function createCompanionActions(deps) {
|
|
|
407
419
|
}
|
|
408
420
|
const method = grant?.mergeMethod ?? "squash";
|
|
409
421
|
const anyway = params["anyway"] === true;
|
|
410
|
-
|
|
422
|
+
const seen = await pullRequestOnGitHub(publication, deps.publishExec);
|
|
423
|
+
if (seen === null || seen.base === null)
|
|
424
|
+
throw new CompanionActionError("refused", "GitHub couldn't be read just now. Try again.");
|
|
425
|
+
if (seen.state !== "OPEN")
|
|
426
|
+
throw new CompanionActionError("refused", seen.state === "MERGED" ? "This pull request is already merged." : "This pull request is closed on GitHub.");
|
|
427
|
+
if (seen.head !== publication.headSha) {
|
|
428
|
+
throw new CompanionActionError("refused", "The pull request has commits that weren't part of the completed result, so it won't be merged from here.");
|
|
429
|
+
}
|
|
430
|
+
binding = { verb: "ship", runId: runIdRaw, taskId: taskRef.externalId, prNumber: publication.prNumber, headSha: publication.headSha, method, anyway,
|
|
431
|
+
githubRepo: publication.githubRepo, base: seen.base };
|
|
432
|
+
terms = mergeTerms(store, runIdRaw, binding);
|
|
411
433
|
}
|
|
412
434
|
else {
|
|
413
435
|
const windowMinutes = passkeyApprovalWindowMinutes(store);
|
|
@@ -427,7 +449,8 @@ export function createCompanionActions(deps) {
|
|
|
427
449
|
const allowCredentials = activeCreds.map(c => ({ id: c.credentialId, type: "public-key" }));
|
|
428
450
|
const freshUntil = !forceFresh && windowCovers ? windowUntil(principal) : null;
|
|
429
451
|
if (freshUntil !== null) {
|
|
430
|
-
return { challenge: "", rpId, allowCredentials, userVerification: "required", verb, wording: built.wording, expiresAt: freshUntil, binding, freshApproved: true, freshUntil
|
|
452
|
+
return { challenge: "", rpId, allowCredentials, userVerification: "required", verb, wording: built.wording, expiresAt: freshUntil, binding, freshApproved: true, freshUntil,
|
|
453
|
+
...(terms === null ? {} : { terms }) };
|
|
431
454
|
}
|
|
432
455
|
const expiresAt = new Date(t.getTime() + PASSKEY_CHALLENGE_TTL_MS).toISOString();
|
|
433
456
|
savePasskeyChallenge(store.handle, {
|
|
@@ -442,7 +465,7 @@ export function createCompanionActions(deps) {
|
|
|
442
465
|
});
|
|
443
466
|
return {
|
|
444
467
|
challenge: built.challenge, rpId, allowCredentials, userVerification: "required", verb, wording: wording ?? built.wording, expiresAt, binding,
|
|
445
|
-
freshApproved: false, freshUntil: null,
|
|
468
|
+
freshApproved: false, freshUntil: null, ...(terms === null ? {} : { terms }),
|
|
446
469
|
};
|
|
447
470
|
},
|
|
448
471
|
passkeyUnlock: async (principal, params) => {
|
|
@@ -492,6 +515,13 @@ export function createCompanionActions(deps) {
|
|
|
492
515
|
},
|
|
493
516
|
taskAccept: async (principal, params) => {
|
|
494
517
|
const taskId = requireString(params, "task");
|
|
518
|
+
const signedDestination = (challenge) => {
|
|
519
|
+
const row = typeof challenge === "string" ? getPasskeyChallenge(store.handle, challenge) : null;
|
|
520
|
+
if (row === null)
|
|
521
|
+
return undefined;
|
|
522
|
+
const bound = JSON.parse(row.bindingJson).destination;
|
|
523
|
+
return bound === undefined ? undefined : bound;
|
|
524
|
+
};
|
|
495
525
|
const receiptDigest = requireString(params, "receiptDigest");
|
|
496
526
|
const runId = typeof params["runId"] === "number" ? params["runId"] : null;
|
|
497
527
|
const note = normalizeAcceptNote(params["note"]);
|
|
@@ -505,16 +535,21 @@ export function createCompanionActions(deps) {
|
|
|
505
535
|
const targetRunId = runId ?? assignmentOf(store, taskId, now(), { principal: "operator", repos: who.repos }, runtime.evidenceRoot)?.receipt?.runId ?? null;
|
|
506
536
|
if (targetRunId === null)
|
|
507
537
|
return { ok: false, reason: "stale", message: "No result run found to publish." };
|
|
508
|
-
const
|
|
538
|
+
const destination = signedDestination(params["challenge"]);
|
|
539
|
+
const pub = completeAndOpenPullRequest(store, { taskId, digest, runId: targetRunId, who, root: runtime.evidenceRoot,
|
|
540
|
+
...(destination === undefined ? {} : { destination }) }, now());
|
|
509
541
|
if (!pub.ok)
|
|
510
|
-
return { ok: false, reason: "not-publishable", message: pub.message };
|
|
542
|
+
return { ok: false, reason: pub.reason === "changed" ? "changed" : "not-publishable", message: pub.message };
|
|
511
543
|
openedPrUrl = pub.publication.prUrl;
|
|
512
544
|
openedPrNumber = pub.publication.prNumber;
|
|
513
545
|
return { ok: true, digest };
|
|
514
546
|
})
|
|
515
547
|
: acceptAndCompleteAsOperator(store, taskId, { runId, receiptDigest, note, publish: false, passkey: proof }, who, now(), runtime.evidenceRoot);
|
|
516
|
-
if (!done.ok)
|
|
548
|
+
if (!done.ok) {
|
|
549
|
+
if (done.reason === "changed")
|
|
550
|
+
throw new CompanionActionError("changed", "Where the pull request opens changed since you reviewed it. Nothing was accepted or published.");
|
|
517
551
|
throw new CompanionActionError(done.reason === "step-up-required" ? "passkey_step_up_required" : "refused", done.message);
|
|
552
|
+
}
|
|
518
553
|
return { ok: true, accepted: true, published: publish, prUrl: openedPrUrl, prNumber: openedPrNumber, freshUntil: windowAfter(principal, proof) };
|
|
519
554
|
});
|
|
520
555
|
},
|
|
@@ -526,12 +561,17 @@ export function createCompanionActions(deps) {
|
|
|
526
561
|
const proof = liveProofOf(principal, params);
|
|
527
562
|
return perform(principal, params, "task.land", { taskId, key, into: into ?? null, undo }, async ({ who }) => {
|
|
528
563
|
const res = await land(store, taskId, { key, ...(into === undefined ? {} : { into }), ...(undo ? { undo: true } : {}) }, { kind: "passkey", who, proof, clock: runtime.clock }, { repos: who.repos }, now(), { root: runtime.evidenceRoot, ...(deps.git === undefined ? {} : { git: deps.git }) });
|
|
529
|
-
if (!res.ok)
|
|
564
|
+
if (!res.ok) {
|
|
565
|
+
if (res.reason === "stale")
|
|
566
|
+
throw new CompanionActionError("changed", "What would land changed since you reviewed it. Nothing landed.");
|
|
530
567
|
throw new CompanionActionError("refused", res.message);
|
|
568
|
+
}
|
|
531
569
|
return { ok: true, landed: true, replayed: res.replayed, branch: res.branch, commit: res.commit, mode: res.mode, handoffCommand: res.handoff?.command ?? null, freshUntil: windowUntil(principal) };
|
|
532
570
|
});
|
|
533
571
|
},
|
|
534
572
|
taskShip: async (principal, params) => {
|
|
573
|
+
if (deps.phoneMerge !== true)
|
|
574
|
+
throw new CompanionActionError("refused", PHONE_MERGE_OFF);
|
|
535
575
|
const runIdRaw = params["runId"];
|
|
536
576
|
if (typeof runIdRaw !== "number" || !Number.isInteger(runIdRaw) || runIdRaw <= 0) {
|
|
537
577
|
throw new CompanionActionError("invalid_params", "runId is required");
|
|
@@ -550,6 +590,10 @@ export function createCompanionActions(deps) {
|
|
|
550
590
|
if (!res.ok) {
|
|
551
591
|
if (res.reason === "unconfirmed")
|
|
552
592
|
throw new CompanionActionError("outcome_unknown", res.message);
|
|
593
|
+
if (res.reason === "changed")
|
|
594
|
+
throw new CompanionActionError("changed", "This pull request changed since you reviewed it. Nothing merged.");
|
|
595
|
+
if (res.reason === "elsewhere")
|
|
596
|
+
throw new CompanionActionError("merged_elsewhere", res.message);
|
|
553
597
|
throw new CompanionActionError("refused", res.message);
|
|
554
598
|
}
|
|
555
599
|
return { ok: true, shipped: true, commit: res.commit, freshUntil: windowUntil(principal) };
|
|
@@ -557,3 +601,22 @@ export function createCompanionActions(deps) {
|
|
|
557
601
|
},
|
|
558
602
|
};
|
|
559
603
|
}
|
|
604
|
+
function openPullRequestTerms(destination, accepted) {
|
|
605
|
+
const target = destination === null ? null : `${destination.githubRepo} into ${destination.base}`;
|
|
606
|
+
return { kind: "open-pr", title: accepted ? "Open pull request" : "Accept and open pull request", target, destination,
|
|
607
|
+
lines: [`${accepted ? "" : "Finishes the task. "}A pull request opens${target === null ? "" : ` on ${target}`} from this exact commit${destination?.draft === true ? ", as a draft" : ""}.`] };
|
|
608
|
+
}
|
|
609
|
+
function landTerms(plan) {
|
|
610
|
+
return { kind: plan.kind, title: plan.kind === "undo" ? "Undo landing" : `Land on ${plan.branch}`, branch: plan.branch,
|
|
611
|
+
commit: plan.kind === "undo" ? plan.reverts?.landed ?? null : plan.squash?.commit ?? null, onto: plan.old, checks: plan.checks,
|
|
612
|
+
handoff: plan.mode === "handoff", remembers: !plan.recorded, lines: landingWords(plan) };
|
|
613
|
+
}
|
|
614
|
+
function mergeTerms(store, runId, binding) {
|
|
615
|
+
const base = binding.base;
|
|
616
|
+
const view = pullRequestViewOf(store, runId);
|
|
617
|
+
const how = binding.method === "squash" ? "Squash-merges" : binding.method === "rebase" ? "Rebase-merges" : "Merges";
|
|
618
|
+
const anyway = view?.fullCheck == null ? null : view.fullCheck.message;
|
|
619
|
+
return { kind: "merge", title: `Merge pull request #${binding.prNumber}`, pr: binding.prNumber, url: view?.prUrl ?? null, head: binding.headSha,
|
|
620
|
+
method: binding.method, githubRepo: binding.githubRepo, base, checks: view?.label ?? null, checksDetail: view?.detail ?? null, anyway,
|
|
621
|
+
lines: [`${how} PR #${binding.prNumber} into ${base ?? "the base branch"} and deletes its branch.`] };
|
|
622
|
+
}
|