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,622 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { acceptAndCompleteAsOperator, acceptWindowCovers, assignmentOf } from "../assignment.js";
|
|
3
|
+
import { land, landingWords, readLanding } from "../local-landing.js";
|
|
4
|
+
import { verifyApproverStanding } from "../principal.js";
|
|
5
|
+
import { completeAndOpenPullRequest, mergeAsPerson, pullRequestOnGitHub, pullRequestViewOf } from "../pull-request-flow.js";
|
|
6
|
+
import { approvalWindowCovers, approve } from "../scope.js";
|
|
7
|
+
import { requestContext } from "../server/request-context.js";
|
|
8
|
+
import { claimDeviceIdempotency, consumePasskeyChallenge, deviceAccountStands, getAccountPasskey, getPairedDevice, getPasskeyChallenge, insertAccountPasskey, listActiveAccountPasskeys, pruneDeviceIdempotency, prunePasskeyChallenges, reconcileIdempotencyOnStartup, savePasskeyChallenge, settleDeviceIdempotency, } from "./store.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";
|
|
10
|
+
import { activePasskeyLease, clearPasskeyLeases, passkeyApprovalWindowMinutes, startPasskeyLease, verifyPasskeyAction, } from "./passkey-gate.js";
|
|
11
|
+
export const APPROVALS_UNLOCKED_ACTION = "approvals unlocked";
|
|
12
|
+
export const PASSKEY_ENROLLMENT_WINDOW_MS = 5 * 60 * 1000;
|
|
13
|
+
const UUID_V4 = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
14
|
+
const TASK_ID = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,199}$/;
|
|
15
|
+
export class CompanionActionError extends Error {
|
|
16
|
+
code;
|
|
17
|
+
constructor(code, message) {
|
|
18
|
+
super(message);
|
|
19
|
+
this.code = code;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export const PHONE_MERGE_OFF = "Merging from iPhone is off for now. Merge it on your Mac.";
|
|
23
|
+
function parseAssertion(raw) {
|
|
24
|
+
if (raw === null || typeof raw !== "object" || Array.isArray(raw)) {
|
|
25
|
+
throw new CompanionActionError("invalid_params", "assertion object is required");
|
|
26
|
+
}
|
|
27
|
+
const obj = raw;
|
|
28
|
+
const credentialId = obj["credentialId"];
|
|
29
|
+
const clientDataJSON = obj["clientDataJSON"];
|
|
30
|
+
const authenticatorData = obj["authenticatorData"];
|
|
31
|
+
const signature = obj["signature"];
|
|
32
|
+
const userHandle = obj["userHandle"];
|
|
33
|
+
if (typeof credentialId !== "string" || credentialId.length === 0 ||
|
|
34
|
+
typeof clientDataJSON !== "string" || clientDataJSON.length === 0 ||
|
|
35
|
+
typeof authenticatorData !== "string" || authenticatorData.length === 0 ||
|
|
36
|
+
typeof signature !== "string" || signature.length === 0 ||
|
|
37
|
+
typeof userHandle !== "string" || userHandle.length === 0) {
|
|
38
|
+
throw new CompanionActionError("invalid_params", "assertion is missing required WebAuthn fields");
|
|
39
|
+
}
|
|
40
|
+
return { credentialId, clientDataJSON, authenticatorData, signature, userHandle };
|
|
41
|
+
}
|
|
42
|
+
function requireIdempotencyKey(params) {
|
|
43
|
+
const key = params["idempotencyKey"];
|
|
44
|
+
if (typeof key !== "string" || !UUID_V4.test(key)) {
|
|
45
|
+
throw new CompanionActionError("invalid_params", "idempotencyKey (UUIDv4) is required");
|
|
46
|
+
}
|
|
47
|
+
return key.toLowerCase();
|
|
48
|
+
}
|
|
49
|
+
function requireString(params, key) {
|
|
50
|
+
const val = params[key];
|
|
51
|
+
if (typeof val !== "string" || val.length === 0) {
|
|
52
|
+
throw new CompanionActionError("invalid_params", `${key} is required`);
|
|
53
|
+
}
|
|
54
|
+
return val;
|
|
55
|
+
}
|
|
56
|
+
export function createCompanionActions(deps) {
|
|
57
|
+
const { runtime } = deps;
|
|
58
|
+
const store = runtime.store;
|
|
59
|
+
const rpId = deps.rpId ?? PASSKEY_RP_ID;
|
|
60
|
+
const expectedOrigin = deps.expectedOrigin ?? PASSKEY_ORIGIN;
|
|
61
|
+
const windows = new Map();
|
|
62
|
+
const clearFreshLeases = (accountName, deviceId) => clearPasskeyLeases(store, accountName, deviceId);
|
|
63
|
+
const windowUntil = (principal) => {
|
|
64
|
+
const lease = activePasskeyLease(store, principal.deviceId, principal.accountName, now());
|
|
65
|
+
return lease === null ? null : new Date(lease.expiresAtMs).toISOString();
|
|
66
|
+
};
|
|
67
|
+
const windowAfter = (principal, proof) => (proof.kind === "lease" ? null : startPasskeyLease(store, { deviceId: principal.deviceId, accountName: principal.accountName, challenge: proof.challenge }))
|
|
68
|
+
?? windowUntil(principal);
|
|
69
|
+
const proofOf = (principal, params, lease) => {
|
|
70
|
+
if (params["useFreshSession"] === true) {
|
|
71
|
+
if (!lease)
|
|
72
|
+
throw new CompanionActionError("passkey_step_up_required", "Confirm with your passkey for this action.");
|
|
73
|
+
return { kind: "lease", deviceId: principal.deviceId };
|
|
74
|
+
}
|
|
75
|
+
return liveProofOf(principal, params);
|
|
76
|
+
};
|
|
77
|
+
const liveProofOf = (principal, params) => ({ kind: "assertion", deviceId: principal.deviceId, challenge: requireString(params, "challenge"), assertion: parseAssertion(params["assertion"]), rpId, expectedOrigin });
|
|
78
|
+
const unlockMinutes = (params, windowMinutes) => {
|
|
79
|
+
const raw = params["minutes"];
|
|
80
|
+
if (raw === undefined || raw === null)
|
|
81
|
+
return windowMinutes;
|
|
82
|
+
if (typeof raw !== "number" || !Number.isInteger(raw) || raw <= 0)
|
|
83
|
+
throw new CompanionActionError("invalid_params", "minutes must be a positive whole number");
|
|
84
|
+
return Math.min(raw, windowMinutes);
|
|
85
|
+
};
|
|
86
|
+
const windowOff = () => new CompanionActionError("approvals_window_off", "Your Mac asks for your passkey on every approval, so approvals can't be unlocked.");
|
|
87
|
+
reconcileIdempotencyOnStartup(store.handle, runtime.clock());
|
|
88
|
+
pruneDeviceIdempotency(store.handle, runtime.clock());
|
|
89
|
+
prunePasskeyChallenges(store.handle, runtime.clock());
|
|
90
|
+
function now() {
|
|
91
|
+
return runtime.clock();
|
|
92
|
+
}
|
|
93
|
+
function standsApprover(principal) {
|
|
94
|
+
const accountName = principal.accountName;
|
|
95
|
+
const identity = store.workspaceIdentity();
|
|
96
|
+
const device = getPairedDevice(store.handle, principal.deviceId);
|
|
97
|
+
const account = store.accountOf(accountName);
|
|
98
|
+
if (device === null ||
|
|
99
|
+
device.revokedAt !== null ||
|
|
100
|
+
device.activatedAt === null ||
|
|
101
|
+
device.accountName !== accountName ||
|
|
102
|
+
device.recoveryGeneration !== identity.recoveryGeneration ||
|
|
103
|
+
identity.recoveryGeneration !== principal.recoveryGeneration ||
|
|
104
|
+
!deviceAccountStands(device, account)) {
|
|
105
|
+
throw new CompanionActionError("standing_revoked", "This iPhone is no longer paired.");
|
|
106
|
+
}
|
|
107
|
+
if (account === null || account.role !== "approver") {
|
|
108
|
+
throw new CompanionActionError("refused", "Only an approver account can authorize actions from iPhone.");
|
|
109
|
+
}
|
|
110
|
+
const repos = store.knownRepos().filter(r => runtime.visible(r) && store.accountCanAccess(accountName, r));
|
|
111
|
+
const verified = verifyApproverStanding(store, accountName, account.generation, repos);
|
|
112
|
+
if (!verified.ok) {
|
|
113
|
+
throw new CompanionActionError("standing_revoked", "Your account standing changed. Pair again.");
|
|
114
|
+
}
|
|
115
|
+
return { accountName, account, who: verified.who, deviceName: device.deviceName };
|
|
116
|
+
}
|
|
117
|
+
function isEnrollmentOpen(accountName, deviceId = null) {
|
|
118
|
+
const win = windows.get(accountName);
|
|
119
|
+
if (win === undefined)
|
|
120
|
+
return false;
|
|
121
|
+
if (now().getTime() > win.expiresAtMs) {
|
|
122
|
+
windows.delete(accountName);
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
return win.deviceId === null || deviceId === null || win.deviceId === deviceId;
|
|
126
|
+
}
|
|
127
|
+
function openEnrollmentWindow(accountName, deviceId = null) {
|
|
128
|
+
const expiresAtMs = now().getTime() + PASSKEY_ENROLLMENT_WINDOW_MS;
|
|
129
|
+
const id = randomUUID();
|
|
130
|
+
windows.set(accountName, { id, accountName, deviceId, expiresAtMs });
|
|
131
|
+
return { expiresAtMs, windowId: id };
|
|
132
|
+
}
|
|
133
|
+
function closeEnrollmentWindow(accountName, windowId) {
|
|
134
|
+
if (windowId !== undefined && windows.get(accountName)?.id !== windowId)
|
|
135
|
+
return;
|
|
136
|
+
windows.delete(accountName);
|
|
137
|
+
}
|
|
138
|
+
async function withIdempotency(principal, method, idempotencyKey, canonicalTarget, work) {
|
|
139
|
+
const requestHash = sha256(canonicalJson({ method, target: canonicalTarget })).toString("hex");
|
|
140
|
+
const claim = claimDeviceIdempotency(store.handle, { deviceId: principal.deviceId, idempotencyKey, method, requestHash, now: now() });
|
|
141
|
+
if (claim.status === "conflict") {
|
|
142
|
+
throw new CompanionActionError("idempotency_key_conflict", "This idempotency key was already used for a different request.");
|
|
143
|
+
}
|
|
144
|
+
if (claim.status === "in_flight")
|
|
145
|
+
throw new CompanionActionError("in_progress", "That action is already running on your Mac.");
|
|
146
|
+
if (claim.status === "unknown") {
|
|
147
|
+
throw new CompanionActionError("outcome_unknown", "The previous attempt didn't finish cleanly. Refresh to check the current state.");
|
|
148
|
+
}
|
|
149
|
+
if (claim.status === "completed") {
|
|
150
|
+
const stored = JSON.parse(claim.outcomeJson);
|
|
151
|
+
if (stored.kind === "ok")
|
|
152
|
+
return stored.value;
|
|
153
|
+
if (stored.kind === "error" && typeof stored.code === "string" && typeof stored.message === "string") {
|
|
154
|
+
throw new CompanionActionError(stored.code, stored.message);
|
|
155
|
+
}
|
|
156
|
+
throw new CompanionActionError("outcome_unknown", "The previous attempt didn't finish cleanly. Refresh to check the current state.");
|
|
157
|
+
}
|
|
158
|
+
const settle = (state, outcome) => {
|
|
159
|
+
settleDeviceIdempotency(store.handle, principal.deviceId, idempotencyKey, state, outcome === null ? null : JSON.stringify(outcome), now());
|
|
160
|
+
pruneDeviceIdempotency(store.handle, now());
|
|
161
|
+
};
|
|
162
|
+
let outcome;
|
|
163
|
+
try {
|
|
164
|
+
outcome = await work();
|
|
165
|
+
}
|
|
166
|
+
catch (error) {
|
|
167
|
+
if (error instanceof CompanionActionError && error.code !== "outcome_unknown") {
|
|
168
|
+
settle("completed", { kind: "error", code: error.code, message: error.message });
|
|
169
|
+
throw error;
|
|
170
|
+
}
|
|
171
|
+
settle("unknown", null);
|
|
172
|
+
if (error instanceof CompanionActionError)
|
|
173
|
+
throw error;
|
|
174
|
+
throw new CompanionActionError("outcome_unknown", "Something went wrong on your Mac. Refresh to check the current state.");
|
|
175
|
+
}
|
|
176
|
+
settle("completed", { kind: "ok", value: outcome });
|
|
177
|
+
return outcome;
|
|
178
|
+
}
|
|
179
|
+
async function perform(principal, params, method, target, work) {
|
|
180
|
+
const standing = standsApprover(principal);
|
|
181
|
+
const idempotencyKey = requireIdempotencyKey(params);
|
|
182
|
+
return withIdempotency(principal, method, idempotencyKey, target, async () => {
|
|
183
|
+
const out = await work(standing);
|
|
184
|
+
deps.onMutated?.();
|
|
185
|
+
return out;
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
return {
|
|
189
|
+
openEnrollmentWindow,
|
|
190
|
+
isEnrollmentOpen,
|
|
191
|
+
closeEnrollmentWindow,
|
|
192
|
+
clearFreshLeases,
|
|
193
|
+
sweep: () => {
|
|
194
|
+
const t = now();
|
|
195
|
+
prunePasskeyChallenges(store.handle, t);
|
|
196
|
+
pruneDeviceIdempotency(store.handle, t);
|
|
197
|
+
for (const [k, w] of windows.entries()) {
|
|
198
|
+
if (t.getTime() > w.expiresAtMs)
|
|
199
|
+
windows.delete(k);
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
passkeyStatus: async (principal) => {
|
|
203
|
+
const { accountName } = standsApprover(principal);
|
|
204
|
+
const identity = store.workspaceIdentity();
|
|
205
|
+
const active = listActiveAccountPasskeys(store.handle, identity.id, accountName, identity.recoveryGeneration);
|
|
206
|
+
return {
|
|
207
|
+
registered: active.length > 0,
|
|
208
|
+
count: active.length,
|
|
209
|
+
enrollmentOpen: isEnrollmentOpen(accountName, principal.deviceId),
|
|
210
|
+
rpId,
|
|
211
|
+
windowMinutes: passkeyApprovalWindowMinutes(store),
|
|
212
|
+
freshUntil: windowUntil(principal),
|
|
213
|
+
};
|
|
214
|
+
},
|
|
215
|
+
passkeyLock: async (principal) => {
|
|
216
|
+
const { accountName } = standsApprover(principal);
|
|
217
|
+
clearFreshLeases(accountName, principal.deviceId);
|
|
218
|
+
return { ok: true, locked: true };
|
|
219
|
+
},
|
|
220
|
+
passkeyRegisterBegin: async (principal) => {
|
|
221
|
+
const { accountName } = standsApprover(principal);
|
|
222
|
+
if (!isEnrollmentOpen(accountName, principal.deviceId)) {
|
|
223
|
+
throw new CompanionActionError("enrollment_closed", "On your Mac, open Settings → Phone → Passkey approvals → Set up first.");
|
|
224
|
+
}
|
|
225
|
+
const identity = store.workspaceIdentity();
|
|
226
|
+
const t = now();
|
|
227
|
+
prunePasskeyChallenges(store.handle, t);
|
|
228
|
+
const challenge = randomChallenge32();
|
|
229
|
+
const expiresAt = new Date(t.getTime() + PASSKEY_CHALLENGE_TTL_MS).toISOString();
|
|
230
|
+
const userHandle = derivePasskeyUserHandle(identity.id, accountName).toString("base64url");
|
|
231
|
+
const active = listActiveAccountPasskeys(store.handle, identity.id, accountName, identity.recoveryGeneration);
|
|
232
|
+
savePasskeyChallenge(store.handle, {
|
|
233
|
+
challenge,
|
|
234
|
+
kind: "register",
|
|
235
|
+
workspaceId: identity.id,
|
|
236
|
+
accountName,
|
|
237
|
+
deviceId: principal.deviceId,
|
|
238
|
+
recoveryGeneration: identity.recoveryGeneration,
|
|
239
|
+
bindingJson: canonicalJson({ kind: "register", deviceId: principal.deviceId }),
|
|
240
|
+
expiresAt,
|
|
241
|
+
});
|
|
242
|
+
return {
|
|
243
|
+
challenge,
|
|
244
|
+
rp: { id: rpId, name: PASSKEY_RP_NAME },
|
|
245
|
+
user: {
|
|
246
|
+
id: userHandle,
|
|
247
|
+
name: accountName,
|
|
248
|
+
displayName: deps.workspaceLabel(),
|
|
249
|
+
},
|
|
250
|
+
pubKeyCredParams: [{ type: "public-key", alg: -7 }],
|
|
251
|
+
authenticatorSelection: { residentKey: "required", userVerification: "required" },
|
|
252
|
+
attestation: "none",
|
|
253
|
+
excludeCredentials: active.map(c => ({ id: c.credentialId, type: "public-key" })),
|
|
254
|
+
expiresAt,
|
|
255
|
+
};
|
|
256
|
+
},
|
|
257
|
+
passkeyRegisterFinish: async (principal, params) => {
|
|
258
|
+
const challenge = requireString(params, "challenge");
|
|
259
|
+
const clientDataJSON = requireString(params, "clientDataJSON");
|
|
260
|
+
const attestationObject = requireString(params, "attestationObject");
|
|
261
|
+
const credentialIdParam = typeof params["credentialId"] === "string" ? params["credentialId"] : undefined;
|
|
262
|
+
const customLabel = typeof params["label"] === "string" && params["label"].trim().length > 0 ? params["label"].trim() : null;
|
|
263
|
+
return store.transact(() => {
|
|
264
|
+
const { accountName, deviceName } = standsApprover(principal);
|
|
265
|
+
if (!isEnrollmentOpen(accountName, principal.deviceId)) {
|
|
266
|
+
throw new CompanionActionError("enrollment_closed", "The passkey enrollment window closed. Start again on your Mac.");
|
|
267
|
+
}
|
|
268
|
+
const identity = store.workspaceIdentity();
|
|
269
|
+
const t = now();
|
|
270
|
+
const row = getPasskeyChallenge(store.handle, challenge);
|
|
271
|
+
if (row === null ||
|
|
272
|
+
row.kind !== "register" ||
|
|
273
|
+
row.consumedAt !== null ||
|
|
274
|
+
Date.parse(row.expiresAt) <= t.getTime() ||
|
|
275
|
+
row.workspaceId !== identity.id ||
|
|
276
|
+
row.accountName !== accountName ||
|
|
277
|
+
row.deviceId !== principal.deviceId ||
|
|
278
|
+
row.recoveryGeneration !== identity.recoveryGeneration) {
|
|
279
|
+
throw new CompanionActionError("passkey_failed", "That registration challenge expired or isn't valid. Try again.");
|
|
280
|
+
}
|
|
281
|
+
const verified = verifyRegistrationResponse({
|
|
282
|
+
payload: {
|
|
283
|
+
...(credentialIdParam === undefined ? {} : { credentialId: credentialIdParam }),
|
|
284
|
+
clientDataJSON,
|
|
285
|
+
attestationObject,
|
|
286
|
+
},
|
|
287
|
+
expectedChallenge: row.challenge,
|
|
288
|
+
rpId,
|
|
289
|
+
expectedOrigin,
|
|
290
|
+
});
|
|
291
|
+
if (!verified.ok) {
|
|
292
|
+
throw new CompanionActionError("passkey_failed", verified.message);
|
|
293
|
+
}
|
|
294
|
+
if (getAccountPasskey(store.handle, verified.credentialId) !== null) {
|
|
295
|
+
throw new CompanionActionError("passkey_failed", "That passkey is already registered.");
|
|
296
|
+
}
|
|
297
|
+
const consumed = consumePasskeyChallenge(store.handle, row.challenge, t);
|
|
298
|
+
if (!consumed) {
|
|
299
|
+
throw new CompanionActionError("passkey_failed", "Registration challenge was already used.");
|
|
300
|
+
}
|
|
301
|
+
const userHandle = derivePasskeyUserHandle(identity.id, accountName).toString("base64url");
|
|
302
|
+
const label = customLabel ?? deviceName;
|
|
303
|
+
const inserted = insertAccountPasskey(store.handle, {
|
|
304
|
+
credentialId: verified.credentialId,
|
|
305
|
+
workspaceId: identity.id,
|
|
306
|
+
accountName,
|
|
307
|
+
userHandle,
|
|
308
|
+
publicKeySpki: verified.publicKeySpki,
|
|
309
|
+
signCount: verified.signCount,
|
|
310
|
+
label,
|
|
311
|
+
createdAt: t.toISOString(),
|
|
312
|
+
recoveryGeneration: identity.recoveryGeneration,
|
|
313
|
+
});
|
|
314
|
+
if (!inserted) {
|
|
315
|
+
throw new CompanionActionError("passkey_failed", "That passkey is already registered.");
|
|
316
|
+
}
|
|
317
|
+
closeEnrollmentWindow(accountName);
|
|
318
|
+
deps.onMutated?.();
|
|
319
|
+
return { ok: true, credentialId: verified.credentialId, label };
|
|
320
|
+
});
|
|
321
|
+
},
|
|
322
|
+
approvalChallenge: async (principal, params) => {
|
|
323
|
+
const { accountName, who, deviceName } = standsApprover(principal);
|
|
324
|
+
const identity = store.workspaceIdentity();
|
|
325
|
+
const activeCreds = listActiveAccountPasskeys(store.handle, identity.id, accountName, identity.recoveryGeneration);
|
|
326
|
+
if (activeCreds.length === 0) {
|
|
327
|
+
throw new CompanionActionError("no_passkey", "Set up a passkey in Settings before approving from this iPhone.");
|
|
328
|
+
}
|
|
329
|
+
const verbRaw = requireString(params, "verb");
|
|
330
|
+
if (verbRaw !== "approve" && verbRaw !== "accept" && verbRaw !== "land" && verbRaw !== "ship" && verbRaw !== "unlock") {
|
|
331
|
+
throw new CompanionActionError("invalid_params", "verb must be approve, accept, land, ship, or unlock");
|
|
332
|
+
}
|
|
333
|
+
const verb = verbRaw;
|
|
334
|
+
const forceFresh = params["forceFresh"] === true;
|
|
335
|
+
const t = now();
|
|
336
|
+
prunePasskeyChallenges(store.handle, t);
|
|
337
|
+
let binding;
|
|
338
|
+
let windowCovers = false;
|
|
339
|
+
let wording = null;
|
|
340
|
+
let terms = null;
|
|
341
|
+
if (verb === "approve") {
|
|
342
|
+
const taskId = requireString(params, "task");
|
|
343
|
+
if (!TASK_ID.test(taskId))
|
|
344
|
+
throw new CompanionActionError("invalid_params", "Invalid task id.");
|
|
345
|
+
const family = requestContext.run({ csrf: "", returnTo: "/", actor: accountName }, () => runtime.familyOf(taskId));
|
|
346
|
+
if (family === null || family.problem !== null || !runtime.visible(family.current.repo) || !store.accountCanAccess(accountName, family.current.repo)) {
|
|
347
|
+
throw new CompanionActionError("not_found", "No such task.");
|
|
348
|
+
}
|
|
349
|
+
const scope = store.getScope(family.current.id);
|
|
350
|
+
if (scope === null)
|
|
351
|
+
throw new CompanionActionError("refused", "This task has no plan waiting for approval.");
|
|
352
|
+
const sawDigest = typeof params["digest"] === "string" && params["digest"].length > 0 ? params["digest"] : scope.digest;
|
|
353
|
+
if (sawDigest !== scope.digest) {
|
|
354
|
+
throw new CompanionActionError("refused", "This plan changed. Refresh before approving.");
|
|
355
|
+
}
|
|
356
|
+
windowCovers = approvalWindowCovers(store, family.current.id, accountName);
|
|
357
|
+
binding = { verb: "approve", taskId: family.current.id, sawDigest };
|
|
358
|
+
}
|
|
359
|
+
else if (verb === "accept") {
|
|
360
|
+
const taskId = requireString(params, "task");
|
|
361
|
+
if (!TASK_ID.test(taskId))
|
|
362
|
+
throw new CompanionActionError("invalid_params", "Invalid task id.");
|
|
363
|
+
const before = assignmentOf(store, taskId, t, { principal: "operator", repos: who.repos }, runtime.evidenceRoot);
|
|
364
|
+
if (before === null || !runtime.visible(before.repo) || !store.accountCanAccess(accountName, before.repo)) {
|
|
365
|
+
throw new CompanionActionError("not_found", "No such task.");
|
|
366
|
+
}
|
|
367
|
+
if (before.receipt === null)
|
|
368
|
+
throw new CompanionActionError("refused", "This task has no result ready to accept.");
|
|
369
|
+
const runId = typeof params["runId"] === "number" ? params["runId"] : null;
|
|
370
|
+
const receiptDigest = typeof params["receiptDigest"] === "string" && params["receiptDigest"].length > 0 ? params["receiptDigest"] : before.receipt.digest;
|
|
371
|
+
const publish = params["publish"] === true;
|
|
372
|
+
if (receiptDigest !== before.receipt.digest || (runId !== null && runId !== before.receipt.runId)) {
|
|
373
|
+
throw new CompanionActionError("refused", "This result changed. Refresh before accepting.");
|
|
374
|
+
}
|
|
375
|
+
windowCovers = acceptWindowCovers(store, before, publish, runtime.evidenceRoot);
|
|
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");
|
|
380
|
+
}
|
|
381
|
+
else if (verb === "land") {
|
|
382
|
+
const taskId = requireString(params, "task");
|
|
383
|
+
if (!TASK_ID.test(taskId))
|
|
384
|
+
throw new CompanionActionError("invalid_params", "Invalid task id.");
|
|
385
|
+
const into = typeof params["into"] === "string" && params["into"].length > 0 ? params["into"] : null;
|
|
386
|
+
const undo = params["undo"] === true;
|
|
387
|
+
const read = await readLanding(store, taskId, { repos: who.repos }, t, {
|
|
388
|
+
root: runtime.evidenceRoot,
|
|
389
|
+
...(deps.git === undefined ? {} : { git: deps.git }),
|
|
390
|
+
...(into === null ? {} : { into }),
|
|
391
|
+
...(undo ? { undo: true } : {}),
|
|
392
|
+
});
|
|
393
|
+
if (!read.ok)
|
|
394
|
+
throw new CompanionActionError("refused", read.message);
|
|
395
|
+
if (!("plan" in read))
|
|
396
|
+
throw new CompanionActionError("refused", "This result has already landed.");
|
|
397
|
+
const planKey = typeof params["key"] === "string" && params["key"].length > 0 ? params["key"] : read.plan.key;
|
|
398
|
+
if (planKey !== read.plan.key)
|
|
399
|
+
throw new CompanionActionError("changed", "The landing plan changed. Review it again.");
|
|
400
|
+
binding = { verb: "land", taskId, planKey, into, undo };
|
|
401
|
+
terms = landTerms(read.plan);
|
|
402
|
+
}
|
|
403
|
+
else if (verb === "ship") {
|
|
404
|
+
if (deps.phoneMerge !== true)
|
|
405
|
+
throw new CompanionActionError("refused", PHONE_MERGE_OFF);
|
|
406
|
+
const runIdRaw = params["runId"];
|
|
407
|
+
if (typeof runIdRaw !== "number" || !Number.isInteger(runIdRaw) || runIdRaw <= 0) {
|
|
408
|
+
throw new CompanionActionError("invalid_params", "runId is required");
|
|
409
|
+
}
|
|
410
|
+
const run = store.getRun(runIdRaw);
|
|
411
|
+
const taskRef = run === null ? null : store.refById(run.taskRef);
|
|
412
|
+
if (run === null || taskRef === null || taskRef.repo === null || !runtime.visible(taskRef.repo) || !store.accountCanAccess(accountName, taskRef.repo)) {
|
|
413
|
+
throw new CompanionActionError("not_found", "No such run.");
|
|
414
|
+
}
|
|
415
|
+
const publication = store.publicationForRun(runIdRaw);
|
|
416
|
+
const grant = store.publicationGrantFor(taskRef.repo);
|
|
417
|
+
if (publication === null || publication.prNumber === null) {
|
|
418
|
+
throw new CompanionActionError("refused", "This result has no open pull request to merge.");
|
|
419
|
+
}
|
|
420
|
+
const method = grant?.mergeMethod ?? "squash";
|
|
421
|
+
const anyway = params["anyway"] === true;
|
|
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);
|
|
433
|
+
}
|
|
434
|
+
else {
|
|
435
|
+
const windowMinutes = passkeyApprovalWindowMinutes(store);
|
|
436
|
+
if (windowMinutes <= 0)
|
|
437
|
+
throw windowOff();
|
|
438
|
+
const minutes = unlockMinutes(params, windowMinutes);
|
|
439
|
+
binding = { verb: "unlock", minutes };
|
|
440
|
+
wording = `Unlock approvals on ${deviceName} for ${minutesWords(minutes)}`;
|
|
441
|
+
}
|
|
442
|
+
const built = buildActionChallenge({
|
|
443
|
+
workspaceId: identity.id,
|
|
444
|
+
recoveryGeneration: identity.recoveryGeneration,
|
|
445
|
+
accountName,
|
|
446
|
+
deviceId: principal.deviceId,
|
|
447
|
+
binding,
|
|
448
|
+
});
|
|
449
|
+
const allowCredentials = activeCreds.map(c => ({ id: c.credentialId, type: "public-key" }));
|
|
450
|
+
const freshUntil = !forceFresh && windowCovers ? windowUntil(principal) : null;
|
|
451
|
+
if (freshUntil !== null) {
|
|
452
|
+
return { challenge: "", rpId, allowCredentials, userVerification: "required", verb, wording: built.wording, expiresAt: freshUntil, binding, freshApproved: true, freshUntil,
|
|
453
|
+
...(terms === null ? {} : { terms }) };
|
|
454
|
+
}
|
|
455
|
+
const expiresAt = new Date(t.getTime() + PASSKEY_CHALLENGE_TTL_MS).toISOString();
|
|
456
|
+
savePasskeyChallenge(store.handle, {
|
|
457
|
+
challenge: built.challenge,
|
|
458
|
+
kind: verb,
|
|
459
|
+
workspaceId: identity.id,
|
|
460
|
+
accountName,
|
|
461
|
+
deviceId: principal.deviceId,
|
|
462
|
+
recoveryGeneration: identity.recoveryGeneration,
|
|
463
|
+
bindingJson: built.bindingJson,
|
|
464
|
+
expiresAt,
|
|
465
|
+
});
|
|
466
|
+
return {
|
|
467
|
+
challenge: built.challenge, rpId, allowCredentials, userVerification: "required", verb, wording: wording ?? built.wording, expiresAt, binding,
|
|
468
|
+
freshApproved: false, freshUntil: null, ...(terms === null ? {} : { terms }),
|
|
469
|
+
};
|
|
470
|
+
},
|
|
471
|
+
passkeyUnlock: async (principal, params) => {
|
|
472
|
+
const { accountName } = standsApprover(principal);
|
|
473
|
+
const proof = liveProofOf(principal, params);
|
|
474
|
+
const windowMinutes = passkeyApprovalWindowMinutes(store);
|
|
475
|
+
if (windowMinutes <= 0)
|
|
476
|
+
throw windowOff();
|
|
477
|
+
const minutes = unlockMinutes(params, windowMinutes);
|
|
478
|
+
store.transact(() => {
|
|
479
|
+
const t = now();
|
|
480
|
+
const unlocked = verifyPasskeyAction(store, {
|
|
481
|
+
accountName, repo: null, anyProject: true, verb: "unlock", expectedBinding: { verb: "unlock", minutes }, proof, now: t, startsLease: { minutes },
|
|
482
|
+
});
|
|
483
|
+
if (!unlocked.ok)
|
|
484
|
+
throw new CompanionActionError("passkey_failed", unlocked.message);
|
|
485
|
+
store.recordAction({ at: t.toISOString(), actor: accountName, repo: null, taskId: null, runId: null, action: APPROVALS_UNLOCKED_ACTION, outcome: "passkey", source: "request",
|
|
486
|
+
detail: passkeyProofDetail({ at: t, generation: unlocked.accountGeneration, digest: `${minutes}m`, verb: "unlock", credentialId: unlocked.credentialId,
|
|
487
|
+
pairedDeviceId: unlocked.deviceId, be: unlocked.be, bs: unlocked.bs }) });
|
|
488
|
+
});
|
|
489
|
+
const freshUntil = startPasskeyLease(store, { deviceId: principal.deviceId, accountName, challenge: proof.challenge });
|
|
490
|
+
return { ok: true, unlocked: freshUntil !== null, minutes, windowMinutes, freshUntil };
|
|
491
|
+
},
|
|
492
|
+
taskApprove: async (principal, params) => {
|
|
493
|
+
const taskId = requireString(params, "task");
|
|
494
|
+
const sawDigest = requireString(params, "digest");
|
|
495
|
+
const proof = proofOf(principal, params, true);
|
|
496
|
+
return perform(principal, params, "task.approve", { taskId, sawDigest }, ({ accountName }) => {
|
|
497
|
+
const family = requestContext.run({ csrf: "", returnTo: "/", actor: accountName }, () => runtime.familyOf(taskId));
|
|
498
|
+
if (family === null || family.problem !== null || !runtime.visible(family.current.repo) || !store.accountCanAccess(accountName, family.current.repo)) {
|
|
499
|
+
throw new CompanionActionError("not_found", "No such task.");
|
|
500
|
+
}
|
|
501
|
+
const res = approve(store, family.current.id, accountName, now(), sawDigest, "", {}, undefined, undefined, proof);
|
|
502
|
+
if (!res.ok) {
|
|
503
|
+
if (res.reason === "password-now")
|
|
504
|
+
throw new CompanionActionError("passkey_step_up_required", "Confirm with your passkey to approve this task.");
|
|
505
|
+
if (res.reason === "changed")
|
|
506
|
+
throw new CompanionActionError("refused", "This plan changed. Refresh and review the latest terms.");
|
|
507
|
+
if (res.reason === "policy")
|
|
508
|
+
throw new CompanionActionError("refused", res.message);
|
|
509
|
+
if (res.reason === "second-approver")
|
|
510
|
+
return { ok: true, approved: false, secondApprover: true, have: res.have, need: res.need };
|
|
511
|
+
throw new CompanionActionError("refused", `Couldn't approve this task (${res.reason}).`);
|
|
512
|
+
}
|
|
513
|
+
return { ok: true, approved: true, task: family.current.id, digest: res.scope.digest, freshUntil: windowAfter(principal, proof) };
|
|
514
|
+
});
|
|
515
|
+
},
|
|
516
|
+
taskAccept: async (principal, params) => {
|
|
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
|
+
};
|
|
525
|
+
const receiptDigest = requireString(params, "receiptDigest");
|
|
526
|
+
const runId = typeof params["runId"] === "number" ? params["runId"] : null;
|
|
527
|
+
const note = normalizeAcceptNote(params["note"]);
|
|
528
|
+
const publish = params["publish"] === true;
|
|
529
|
+
const proof = proofOf(principal, params, !publish);
|
|
530
|
+
return perform(principal, params, "task.accept", { taskId, runId, receiptDigest, note, publish }, ({ who }) => {
|
|
531
|
+
let openedPrUrl = null;
|
|
532
|
+
let openedPrNumber = null;
|
|
533
|
+
const done = publish
|
|
534
|
+
? acceptAndCompleteAsOperator(store, taskId, { runId, receiptDigest, note, publish: true, passkey: proof }, who, now(), runtime.evidenceRoot, digest => {
|
|
535
|
+
const targetRunId = runId ?? assignmentOf(store, taskId, now(), { principal: "operator", repos: who.repos }, runtime.evidenceRoot)?.receipt?.runId ?? null;
|
|
536
|
+
if (targetRunId === null)
|
|
537
|
+
return { ok: false, reason: "stale", message: "No result run found to publish." };
|
|
538
|
+
const destination = signedDestination(params["challenge"]);
|
|
539
|
+
const pub = completeAndOpenPullRequest(store, { taskId, digest, runId: targetRunId, who, root: runtime.evidenceRoot,
|
|
540
|
+
...(destination === undefined ? {} : { destination }) }, now());
|
|
541
|
+
if (!pub.ok)
|
|
542
|
+
return { ok: false, reason: pub.reason === "changed" ? "changed" : "not-publishable", message: pub.message };
|
|
543
|
+
openedPrUrl = pub.publication.prUrl;
|
|
544
|
+
openedPrNumber = pub.publication.prNumber;
|
|
545
|
+
return { ok: true, digest };
|
|
546
|
+
})
|
|
547
|
+
: acceptAndCompleteAsOperator(store, taskId, { runId, receiptDigest, note, publish: false, passkey: proof }, who, now(), runtime.evidenceRoot);
|
|
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.");
|
|
551
|
+
throw new CompanionActionError(done.reason === "step-up-required" ? "passkey_step_up_required" : "refused", done.message);
|
|
552
|
+
}
|
|
553
|
+
return { ok: true, accepted: true, published: publish, prUrl: openedPrUrl, prNumber: openedPrNumber, freshUntil: windowAfter(principal, proof) };
|
|
554
|
+
});
|
|
555
|
+
},
|
|
556
|
+
taskLand: async (principal, params) => {
|
|
557
|
+
const taskId = requireString(params, "task");
|
|
558
|
+
const key = requireString(params, "key");
|
|
559
|
+
const into = typeof params["into"] === "string" && params["into"].length > 0 ? params["into"] : undefined;
|
|
560
|
+
const undo = params["undo"] === true;
|
|
561
|
+
const proof = liveProofOf(principal, params);
|
|
562
|
+
return perform(principal, params, "task.land", { taskId, key, into: into ?? null, undo }, async ({ who }) => {
|
|
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 }) });
|
|
564
|
+
if (!res.ok) {
|
|
565
|
+
if (res.reason === "stale")
|
|
566
|
+
throw new CompanionActionError("changed", "What would land changed since you reviewed it. Nothing landed.");
|
|
567
|
+
throw new CompanionActionError("refused", res.message);
|
|
568
|
+
}
|
|
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) };
|
|
570
|
+
});
|
|
571
|
+
},
|
|
572
|
+
taskShip: async (principal, params) => {
|
|
573
|
+
if (deps.phoneMerge !== true)
|
|
574
|
+
throw new CompanionActionError("refused", PHONE_MERGE_OFF);
|
|
575
|
+
const runIdRaw = params["runId"];
|
|
576
|
+
if (typeof runIdRaw !== "number" || !Number.isInteger(runIdRaw) || runIdRaw <= 0) {
|
|
577
|
+
throw new CompanionActionError("invalid_params", "runId is required");
|
|
578
|
+
}
|
|
579
|
+
const anyway = params["anyway"] === true;
|
|
580
|
+
const proof = liveProofOf(principal, params);
|
|
581
|
+
return perform(principal, params, "task.ship", { runId: runIdRaw, anyway }, async ({ accountName }) => {
|
|
582
|
+
const res = await mergeAsPerson(store, {
|
|
583
|
+
runId: runIdRaw,
|
|
584
|
+
name: accountName,
|
|
585
|
+
passkey: proof,
|
|
586
|
+
anyway,
|
|
587
|
+
...(deps.publishExec === undefined ? {} : { exec: deps.publishExec }),
|
|
588
|
+
clock: runtime.clock,
|
|
589
|
+
});
|
|
590
|
+
if (!res.ok) {
|
|
591
|
+
if (res.reason === "unconfirmed")
|
|
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);
|
|
597
|
+
throw new CompanionActionError("refused", res.message);
|
|
598
|
+
}
|
|
599
|
+
return { ok: true, shipped: true, commit: res.commit, freshUntil: windowUntil(principal) };
|
|
600
|
+
});
|
|
601
|
+
},
|
|
602
|
+
};
|
|
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
|
+
}
|