toolroll 0.9.129 → 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 +24 -0
- package/dist/agent-fence.js +0 -2
- 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.2a682d0b91a35288271c73b7ee253e524cca0917d17fbaf6733e80b7a767a37c.js.br +0 -0
- package/dist/browser/terminal.2a682d0b91a35288271c73b7ee253e524cca0917d17fbaf6733e80b7a767a37c.js.gz +0 -0
- 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 +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/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-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/pull-request-flow.js +56 -15
- package/dist/qr.js +0 -25
- package/dist/release-adapters.js +12 -42
- 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 +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/sandbox-runtime.js +0 -1
- package/dist/scope.js +1 -13
- package/dist/scout.js +0 -6
- package/dist/serve.js +31 -7
- 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/store.js +20 -5
- 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/toolroll-update-cli.js +19 -3
- package/dist/toolroll-update-ui.js +2 -2
- package/dist/toolroll-update.js +95 -15
- 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.js → terminal.2a682d0b91a35288271c73b7ee253e524cca0917d17fbaf6733e80b7a767a37c.js} +0 -0
- /package/dist/browser/{terminal.css → terminal.4d1cf20c32ad7c2099df657358d540d5fd92bb55195a88121e74b28467238b42.css} +0 -0
package/dist/companion/daemon.js
CHANGED
|
@@ -3,6 +3,7 @@ import { pathsAllowed } from "./paths.js";
|
|
|
3
3
|
import { buildPairingPrologue, buildSessionPrologue, deriveConfirmationCode, deriveDevicePsk, MAX_SESSION_AGE_MS, MAX_SESSION_MESSAGES, NoiseIKpsk2Responder, NoiseTransportSession, randomPsk32, } from "./noise.js";
|
|
4
4
|
import { CompanionStreamGuard, decodeCreditPayload, decodeFrame, encodeErrorPayload, encodeFrame, FRAME_HEADER_BYTES, FrameType, GlobalBufferBudget, LiveWatchBuffer, MAX_FRAME_PAYLOAD_BYTES, PACING_PER_CONNECTION, TokenBucket, WATCH_IDLE_DEADLINE_MS, UnaryResponsePacer, } from "./framing.js";
|
|
5
5
|
import { decodeRelayEnvelope, encodeRelayEnvelope, RelayOp, signRelayToken } from "./relay-auth.js";
|
|
6
|
+
import { cancelPhoneWork, PHONE_ORIGIN_GONE } from "./chat-origin.js";
|
|
6
7
|
import { activatePendingDevice, deletePendingDevice, deviceAccountStands, getPairedDevice, livePairedDevices, loadOrCreateCompanionHostKeys, MAX_PHONES_PER_MAC, PENDING_ACTIVATION_MS, phoneCount, revokePairedDeviceRecord, sanitizeDeviceName, savePendingDevice, sweepCompanionRecords, touchPairedDeviceLastSeen, } from "./store.js";
|
|
7
8
|
export const PAIRING_TTL_MS = 5 * 60 * 1000;
|
|
8
9
|
export const DAEMON_HANDSHAKE_DEADLINE_MS = 5_000;
|
|
@@ -45,6 +46,20 @@ export const PAIRED_DEVICE_GATE2_ROUTES = new Set([
|
|
|
45
46
|
"task.land",
|
|
46
47
|
"task.ship",
|
|
47
48
|
]);
|
|
49
|
+
export const PAIRED_DEVICE_CHAT_ROUTES = new Set([
|
|
50
|
+
"chat.read",
|
|
51
|
+
"chat.send",
|
|
52
|
+
"chat.watch.subscribe",
|
|
53
|
+
]);
|
|
54
|
+
export const CHAT_FEATURE = "chat.v1";
|
|
55
|
+
export const CANVAS_FEATURE = "canvas.v1";
|
|
56
|
+
export const PAIRED_DEVICE_CANVAS_ROUTES = new Set([
|
|
57
|
+
"canvas.projects",
|
|
58
|
+
"canvas.list",
|
|
59
|
+
"canvas.screen.thumb",
|
|
60
|
+
"canvas.screen.image",
|
|
61
|
+
"canvas.pins",
|
|
62
|
+
]);
|
|
48
63
|
const TERMINAL = new Set(["paired", "cancelled", "expired", "contested", "failed"]);
|
|
49
64
|
const PAIRING_ERROR_MESSAGE = {
|
|
50
65
|
pairing_cancelled: "Pairing was cancelled on your Mac.",
|
|
@@ -121,6 +136,7 @@ export class CompanionDaemonEngine {
|
|
|
121
136
|
store;
|
|
122
137
|
handlers;
|
|
123
138
|
actions;
|
|
139
|
+
chat;
|
|
124
140
|
defaultLink;
|
|
125
141
|
onDeviceRegistered;
|
|
126
142
|
onDeviceRevoked;
|
|
@@ -140,6 +156,7 @@ export class CompanionDaemonEngine {
|
|
|
140
156
|
this.store = opts.store;
|
|
141
157
|
this.handlers = opts.handlers;
|
|
142
158
|
this.actions = opts.actions ?? null;
|
|
159
|
+
this.chat = opts.chat ?? null;
|
|
143
160
|
this.defaultLink = opts.sendToRelay === undefined ? null : relayEnvelopeLink("relay", opts.sendToRelay);
|
|
144
161
|
this.onDeviceRegistered = opts.onDeviceRegistered;
|
|
145
162
|
this.onDeviceRevoked = opts.onDeviceRevoked;
|
|
@@ -364,6 +381,8 @@ export class CompanionDaemonEngine {
|
|
|
364
381
|
}
|
|
365
382
|
revokeDevice(deviceId, reason = "removed") {
|
|
366
383
|
const revoked = revokePairedDeviceRecord(this.store.handle, deviceId, new Date(this.nowMs()), reason);
|
|
384
|
+
if (revoked)
|
|
385
|
+
cancelPhoneWork(this.store, { deviceId }, PHONE_ORIGIN_GONE, new Date(this.nowMs()));
|
|
367
386
|
for (const peer of [...this.peers.values()]) {
|
|
368
387
|
if (peer.role === "device" && peer.peerId === deviceId) {
|
|
369
388
|
if (peer.state === "authenticated" || peer.state === "awaiting_hello")
|
|
@@ -941,7 +960,9 @@ export class CompanionDaemonEngine {
|
|
|
941
960
|
}
|
|
942
961
|
const isGate1 = PAIRED_DEVICE_GATE1_ROUTES.has(method);
|
|
943
962
|
const isGate2 = this.actions !== null && PAIRED_DEVICE_GATE2_ROUTES.has(method);
|
|
944
|
-
|
|
963
|
+
const isChat = this.chat !== null && PAIRED_DEVICE_CHAT_ROUTES.has(method);
|
|
964
|
+
const isCanvas = this.handlers.canvas !== undefined && PAIRED_DEVICE_CANVAS_ROUTES.has(method);
|
|
965
|
+
if (!isGate1 && !isGate2 && !isChat && !isCanvas) {
|
|
945
966
|
this.sendRpcError(peer, frame.streamId, "route_not_allowed", `Method '${method}' is not on the paired-device allowlist`);
|
|
946
967
|
return;
|
|
947
968
|
}
|
|
@@ -957,8 +978,9 @@ export class CompanionDaemonEngine {
|
|
|
957
978
|
this.revokeDevice(principal.deviceId, "removed");
|
|
958
979
|
return;
|
|
959
980
|
}
|
|
960
|
-
if (method === "run.watch.subscribe") {
|
|
961
|
-
|
|
981
|
+
if (method === "run.watch.subscribe" || method === "chat.watch.subscribe") {
|
|
982
|
+
const subscribe = method === "run.watch.subscribe" ? this.handlers.runWatchSubscribe : this.chat?.chatWatchSubscribe;
|
|
983
|
+
if (subscribe === undefined) {
|
|
962
984
|
this.sendRpcError(peer, streamId, "unsupported", "Live watch not configured");
|
|
963
985
|
return;
|
|
964
986
|
}
|
|
@@ -971,7 +993,7 @@ export class CompanionDaemonEngine {
|
|
|
971
993
|
const watchEntry = { buffer, unsubscribe: () => { }, seq: 0, ending: false, lastCreditAtMs: this.nowMs() };
|
|
972
994
|
peer.watchStreams.set(streamId, watchEntry);
|
|
973
995
|
let unsubscribed = false;
|
|
974
|
-
const sub =
|
|
996
|
+
const sub = subscribe(principal, params, record => {
|
|
975
997
|
if (peer.watchStreams.get(streamId) !== watchEntry)
|
|
976
998
|
return;
|
|
977
999
|
buffer.push(record);
|
|
@@ -1008,7 +1030,7 @@ export class CompanionDaemonEngine {
|
|
|
1008
1030
|
const hello = await this.handlers.deviceHello(principal);
|
|
1009
1031
|
const paths = this.pathsOf();
|
|
1010
1032
|
result = hello !== null && typeof hello === "object"
|
|
1011
|
-
? { ...hello, consoleUrl: this.consoleUrl(), ...(pathsAllowed(paths) ? { paths } : {}) }
|
|
1033
|
+
? { ...hello, consoleUrl: this.consoleUrl(), ...(pathsAllowed(paths) ? { paths } : {}), ...this.helloFeatures(hello) }
|
|
1012
1034
|
: hello;
|
|
1013
1035
|
break;
|
|
1014
1036
|
}
|
|
@@ -1057,7 +1079,17 @@ export class CompanionDaemonEngine {
|
|
|
1057
1079
|
case "task.ship":
|
|
1058
1080
|
result = await this.actions.taskShip(principal, params);
|
|
1059
1081
|
break;
|
|
1082
|
+
case "chat.read":
|
|
1083
|
+
result = await this.chat.chatRead(principal, params);
|
|
1084
|
+
break;
|
|
1085
|
+
case "chat.send":
|
|
1086
|
+
result = await this.chat.chatSend(principal, params);
|
|
1087
|
+
break;
|
|
1060
1088
|
default:
|
|
1089
|
+
if (this.handlers.canvas !== undefined && PAIRED_DEVICE_CANVAS_ROUTES.has(method)) {
|
|
1090
|
+
result = await this.handlers.canvas.call(principal, method, params);
|
|
1091
|
+
break;
|
|
1092
|
+
}
|
|
1061
1093
|
this.sendRpcError(peer, streamId, "route_not_allowed", "Not allowed");
|
|
1062
1094
|
return;
|
|
1063
1095
|
}
|
|
@@ -1072,6 +1104,15 @@ export class CompanionDaemonEngine {
|
|
|
1072
1104
|
this.refuseLive(peer, this.standingOf(peer, true) ?? "account_revoked");
|
|
1073
1105
|
}
|
|
1074
1106
|
}
|
|
1107
|
+
helloFeatures(hello) {
|
|
1108
|
+
const given = hello.features;
|
|
1109
|
+
const features = Array.isArray(given) ? given.filter((one) => typeof one === "string") : [];
|
|
1110
|
+
if (this.chat !== null && !features.includes(CHAT_FEATURE))
|
|
1111
|
+
features.push(CHAT_FEATURE);
|
|
1112
|
+
if (this.handlers.canvas !== undefined && !features.includes(CANVAS_FEATURE))
|
|
1113
|
+
features.push(CANVAS_FEATURE);
|
|
1114
|
+
return { features };
|
|
1115
|
+
}
|
|
1075
1116
|
sendRpcResult(peer, streamId, result) {
|
|
1076
1117
|
if (!peer.streamGuard.isOpen(streamId) || this.peers.get(peer.key) !== peer)
|
|
1077
1118
|
return;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { assignmentOf } from "../assignment.js";
|
|
2
|
+
import { broughtInOnBranch, keptHandoffOf, landingBranchOf, landingHistoryOf, landingOf, publishesThroughPullRequests } from "../local-landing.js";
|
|
3
|
+
import { newestPullRequestOf, publishingOf, pullRequestBlocker } from "../pull-request-flow.js";
|
|
4
|
+
export function phoneFinishOf(store, family, viewer, input) {
|
|
5
|
+
const taskId = family.current.id;
|
|
6
|
+
const repo = store.lookupRef(taskId)?.repo ?? null;
|
|
7
|
+
if (repo === null)
|
|
8
|
+
return null;
|
|
9
|
+
const account = store.accountOf(viewer);
|
|
10
|
+
const canAct = account !== null && account.revokedAt === null && account.role === "approver" && store.accountCanAccess(viewer, repo);
|
|
11
|
+
const publishing = publishingOf(store, repo);
|
|
12
|
+
const view = newestPullRequestOf(store, family.versions.map(one => one.id));
|
|
13
|
+
if (view !== null) {
|
|
14
|
+
return { step: "merge", run: view.runId, pr: view.prNumber, url: view.prUrl, state: view.state, label: view.label, detail: view.detail,
|
|
15
|
+
method: view.mergeMethod, base: store.publicationForRun(view.runId)?.base ?? null, canMerge: canAct && view.canMerge && view.prNumber !== null,
|
|
16
|
+
anyway: view.fullCheck === null ? null : view.fullCheck.message, mergeCommit: view.mergeCommit, canAct };
|
|
17
|
+
}
|
|
18
|
+
const assignment = assignmentOf(store, taskId, input.now, input.access, input.evidenceRoot);
|
|
19
|
+
const receipt = assignment?.receipt ?? null;
|
|
20
|
+
if (publishing.on) {
|
|
21
|
+
if (assignment === null || receipt === null || store.publicationForRun(receipt.runId) !== null || pullRequestBlocker(store, receipt.runId) !== null)
|
|
22
|
+
return null;
|
|
23
|
+
const target = `${publishing.githubRepo} into ${publishing.base}`;
|
|
24
|
+
if (assignment.state === "complete")
|
|
25
|
+
return { step: "open-pr", accepted: true, run: receipt.runId, receipt: receipt.digest, target, canAct };
|
|
26
|
+
if (assignment.state === "ready-to-check" && !publishing.legacy && receipt.taskId === taskId) {
|
|
27
|
+
return { step: "open-pr", accepted: false, run: receipt.runId, receipt: receipt.digest, target, canAct };
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
if (publishesThroughPullRequests(store, repo))
|
|
32
|
+
return null;
|
|
33
|
+
const rootId = family.root.id;
|
|
34
|
+
const record = landingOf(store, rootId);
|
|
35
|
+
const complete = assignment?.state === "complete";
|
|
36
|
+
if (!complete && record === null)
|
|
37
|
+
return null;
|
|
38
|
+
const branch = landingBranchOf(store, repo, null);
|
|
39
|
+
const history = landingHistoryOf(store, repo, rootId, complete ? receipt?.head ?? null : null, input.git);
|
|
40
|
+
if (history !== null && !history.recorded) {
|
|
41
|
+
return { step: "land", branch, landed: history.words, canLand: false, canUndo: canAct && !history.reverted && broughtInOnBranch(store, repo, rootId, input.git), kept: null, canAct };
|
|
42
|
+
}
|
|
43
|
+
const kept = complete && (record === null || record.undone) ? keptHandoffOf(store, repo, rootId, receipt?.head ?? null) : null;
|
|
44
|
+
return {
|
|
45
|
+
step: "land", branch, landed: history?.words ?? null,
|
|
46
|
+
canLand: canAct && complete && (record === null || record.undone) && kept === null,
|
|
47
|
+
canUndo: canAct && record !== null && !record.undone && history?.reverted !== true,
|
|
48
|
+
kept: kept === null ? null : { commit: kept.commit, branch: kept.branch, command: kept.command },
|
|
49
|
+
canAct,
|
|
50
|
+
};
|
|
51
|
+
}
|
package/dist/companion/reads.js
CHANGED
|
@@ -7,7 +7,9 @@ import { readMainWindow } from "../live-main-read.js";
|
|
|
7
7
|
import { runLiveCommands } from "../store.js";
|
|
8
8
|
import { requestContext } from "../server/request-context.js";
|
|
9
9
|
import { ROUTES } from "../server/route-table.js";
|
|
10
|
+
import { recentGitReads } from "../task-base.js";
|
|
10
11
|
import { deviceAccountStands, getPairedDevice } from "./store.js";
|
|
12
|
+
import { phoneFinishOf } from "./finish.js";
|
|
11
13
|
export class CompanionReadError extends Error {
|
|
12
14
|
code;
|
|
13
15
|
constructor(code, message) {
|
|
@@ -33,6 +35,7 @@ export function createCompanionReads(deps) {
|
|
|
33
35
|
const store = runtime.store;
|
|
34
36
|
const cursorKey = globalThis.crypto.getRandomValues(new Uint8Array(32));
|
|
35
37
|
const cursorKeyBuf = Buffer.from(cursorKey);
|
|
38
|
+
const finishGit = recentGitReads();
|
|
36
39
|
function stands(principal) {
|
|
37
40
|
const device = getPairedDevice(store.handle, principal.deviceId);
|
|
38
41
|
const identity = store.workspaceIdentity();
|
|
@@ -143,8 +146,9 @@ export function createCompanionReads(deps) {
|
|
|
143
146
|
const family = familyInView(params);
|
|
144
147
|
const cards = stepCardsOf({ store, family, now: runtime.clock(), access: runtime.workAccess(), evidenceRoot: runtime.evidenceRoot, viewer: principal.accountName, withChoices: false });
|
|
145
148
|
const passkey = passkeyHintsOf(family);
|
|
149
|
+
const finish = phoneFinishOf(store, family, principal.accountName, { now: runtime.clock(), access: runtime.workAccess(), evidenceRoot: runtime.evidenceRoot, git: finishGit });
|
|
146
150
|
familyInView(params);
|
|
147
|
-
return { ...checkEngineResponse("stepCards", cards), passkey };
|
|
151
|
+
return { ...checkEngineResponse("stepCards", cards), passkey, finish };
|
|
148
152
|
}),
|
|
149
153
|
taskDiff: (principal, params) => asDevice(principal, () => {
|
|
150
154
|
const runParam = stringParam(params, "run");
|
package/dist/companion/schema.js
CHANGED
|
@@ -223,3 +223,67 @@ export function companionPasskeyShapeProblem(db) {
|
|
|
223
223
|
}
|
|
224
224
|
return null;
|
|
225
225
|
}
|
|
226
|
+
export const V189_LEAD_QUEUE_ORIGIN = "origin TEXT NOT NULL DEFAULT 'console' CHECK (origin IN ('console', 'phone'))";
|
|
227
|
+
export const V189_SCHEMA = `
|
|
228
|
+
CREATE TABLE IF NOT EXISTS companion_chat_origin (
|
|
229
|
+
message INTEGER PRIMARY KEY,
|
|
230
|
+
device_id TEXT NOT NULL,
|
|
231
|
+
account TEXT NOT NULL,
|
|
232
|
+
account_generation INTEGER NOT NULL,
|
|
233
|
+
workspace_id TEXT NOT NULL,
|
|
234
|
+
recovery_generation TEXT NOT NULL,
|
|
235
|
+
idempotency_key TEXT NOT NULL,
|
|
236
|
+
request_hash TEXT NOT NULL,
|
|
237
|
+
session INTEGER NOT NULL,
|
|
238
|
+
thread INTEGER NOT NULL,
|
|
239
|
+
thread_key TEXT NOT NULL,
|
|
240
|
+
created_at TEXT NOT NULL,
|
|
241
|
+
UNIQUE (device_id, idempotency_key)
|
|
242
|
+
);
|
|
243
|
+
CREATE INDEX IF NOT EXISTS idx_companion_chat_origin_account ON companion_chat_origin (account, created_at);
|
|
244
|
+
`;
|
|
245
|
+
export const V189_STEPS = Object.freeze(["companion-chat-origin"]);
|
|
246
|
+
export const V189_TABLES = Object.freeze(["companion_chat_origin"]);
|
|
247
|
+
const CHAT_ORIGIN_V189 = [
|
|
248
|
+
["message", "INTEGER", 0, 1], ["device_id", "TEXT", 1, 0], ["account", "TEXT", 1, 0], ["account_generation", "INTEGER", 1, 0],
|
|
249
|
+
["workspace_id", "TEXT", 1, 0], ["recovery_generation", "TEXT", 1, 0], ["idempotency_key", "TEXT", 1, 0], ["request_hash", "TEXT", 1, 0],
|
|
250
|
+
["session", "INTEGER", 1, 0], ["thread", "INTEGER", 1, 0], ["thread_key", "TEXT", 1, 0], ["created_at", "TEXT", 1, 0],
|
|
251
|
+
];
|
|
252
|
+
export function adoptCompanionChatOrigin(db) {
|
|
253
|
+
const queue = columnsOf(db, "lead_queue");
|
|
254
|
+
if (queue.length === 0)
|
|
255
|
+
throw new Error("the lead queue table lead_queue is missing; refusing to add phone origins");
|
|
256
|
+
if (!queue.some(([name]) => name === "origin"))
|
|
257
|
+
db.exec(`ALTER TABLE lead_queue ADD COLUMN ${V189_LEAD_QUEUE_ORIGIN}`);
|
|
258
|
+
db.exec(V189_SCHEMA);
|
|
259
|
+
}
|
|
260
|
+
export function companionChatShapeProblem(db) {
|
|
261
|
+
const origin = columnsOf(db, "lead_queue").find(([name]) => name === "origin");
|
|
262
|
+
if (origin === undefined)
|
|
263
|
+
return "the lead queue's phone origin column is missing";
|
|
264
|
+
if (origin[1] !== "TEXT" || origin[2] !== 1)
|
|
265
|
+
return "the lead queue's phone origin column has an unknown shape";
|
|
266
|
+
const declared = db.prepare("SELECT sql FROM sqlite_master WHERE type = 'table' AND name = 'lead_queue'").get();
|
|
267
|
+
if (!String(declared?.["sql"] ?? "").includes("CHECK (origin IN ('console', 'phone'))"))
|
|
268
|
+
return "the lead queue's phone origin column has an unknown shape";
|
|
269
|
+
for (const table of V189_TABLES) {
|
|
270
|
+
if (!tableExists(db, table))
|
|
271
|
+
return `the phone chat table ${table} is missing`;
|
|
272
|
+
if (shapeOf(columnsOf(db, table)) !== shapeOf(CHAT_ORIGIN_V189))
|
|
273
|
+
return `the phone chat table ${table} has an unknown shape`;
|
|
274
|
+
}
|
|
275
|
+
if (!uniqueIndexOn(db, "companion_chat_origin", ["device_id", "idempotency_key"]))
|
|
276
|
+
return "the phone chat table companion_chat_origin has lost its receipt uniqueness";
|
|
277
|
+
return null;
|
|
278
|
+
}
|
|
279
|
+
function uniqueIndexOn(db, table, columns) {
|
|
280
|
+
for (const index of db.prepare(`PRAGMA index_list(${table})`).all()) {
|
|
281
|
+
if (Number(index["unique"]) !== 1 || Number(index["partial"]) !== 0)
|
|
282
|
+
continue;
|
|
283
|
+
const names = db.prepare(`PRAGMA index_info(${JSON.stringify(String(index["name"]))})`).all()
|
|
284
|
+
.sort((a, b) => Number(a["seqno"]) - Number(b["seqno"])).map(row => String(row["name"]));
|
|
285
|
+
if (names.length === columns.length && names.every((name, at) => name === columns[at]))
|
|
286
|
+
return true;
|
|
287
|
+
}
|
|
288
|
+
return false;
|
|
289
|
+
}
|
|
@@ -141,6 +141,7 @@ export class CompanionService {
|
|
|
141
141
|
store: opts.store,
|
|
142
142
|
handlers: opts.reads,
|
|
143
143
|
...(opts.actions === undefined ? {} : { actions: opts.actions }),
|
|
144
|
+
...(opts.chat === undefined ? {} : { chat: opts.chat }),
|
|
144
145
|
onDeviceRegistered: async (deviceId, deviceRelayPub) => {
|
|
145
146
|
if (this.addresses === null)
|
|
146
147
|
return;
|
package/dist/companion/store.js
CHANGED
|
@@ -32,6 +32,14 @@ export function derivePasskeyUserHandle(workspaceId, accountName) {
|
|
|
32
32
|
export function normalizeAcceptNote(note) {
|
|
33
33
|
return typeof note === "string" && note.trim().length > 0 ? note.trim() : null;
|
|
34
34
|
}
|
|
35
|
+
export function publishDestinationOf(grant) {
|
|
36
|
+
return grant === null ? null : { githubRepo: grant.githubRepo, remote: grant.remote, base: grant.base, headPrefix: grant.headPrefix, draft: grant.draft };
|
|
37
|
+
}
|
|
38
|
+
export function publishDestinationForRun(store, runId) {
|
|
39
|
+
const run = store.getRun(runId);
|
|
40
|
+
const repo = run === null ? null : store.refById(run.taskRef)?.repo ?? null;
|
|
41
|
+
return publishDestinationOf(repo === null ? null : store.publicationGrantFor(repo));
|
|
42
|
+
}
|
|
35
43
|
export function acceptBindingOf(input, receiptRunId) {
|
|
36
44
|
return {
|
|
37
45
|
verb: "accept",
|
|
@@ -40,6 +48,7 @@ export function acceptBindingOf(input, receiptRunId) {
|
|
|
40
48
|
receiptDigest: input.receiptDigest,
|
|
41
49
|
noteHash: sha256(normalizeAcceptNote(input.note) ?? "").toString("hex"),
|
|
42
50
|
publish: input.publish,
|
|
51
|
+
...(input.publish ? { destination: input.destination ?? null } : {}),
|
|
43
52
|
};
|
|
44
53
|
}
|
|
45
54
|
export function buildActionChallenge(input) {
|
|
@@ -65,11 +74,11 @@ function wordingForBinding(binding) {
|
|
|
65
74
|
case "approve":
|
|
66
75
|
return `Approve task ${binding.taskId} plan (${binding.sawDigest.slice(0, 12)})`;
|
|
67
76
|
case "accept":
|
|
68
|
-
return `Accept task ${binding.taskId} result (${binding.receiptDigest.slice(0, 12)})${binding.publish ?
|
|
77
|
+
return `Accept task ${binding.taskId} result (${binding.receiptDigest.slice(0, 12)})${binding.publish ? ` and open pull request${binding.destination == null ? "" : ` on ${binding.destination.githubRepo} into ${binding.destination.base}`}` : ""}`;
|
|
69
78
|
case "land":
|
|
70
79
|
return `${binding.undo ? "Undo landing" : "Land"} task ${binding.taskId} (${binding.planKey})`;
|
|
71
80
|
case "ship":
|
|
72
|
-
return `Merge PR #${binding.prNumber} for task ${binding.taskId} at ${binding.headSha.slice(0, 10)} (${binding.method})`;
|
|
81
|
+
return `Merge PR #${binding.prNumber} into ${binding.base} for task ${binding.taskId} at ${binding.headSha.slice(0, 10)} (${binding.method})`;
|
|
73
82
|
case "unlock":
|
|
74
83
|
return `Unlock approvals for ${minutesWords(binding.minutes)}`;
|
|
75
84
|
}
|
package/dist/console-instance.js
CHANGED
|
@@ -45,10 +45,6 @@ export function readInstance(store) {
|
|
|
45
45
|
const read = readInstanceState(store);
|
|
46
46
|
return read.state === "ok" ? read.record : null;
|
|
47
47
|
}
|
|
48
|
-
export function instanceKeyEpoch(store) {
|
|
49
|
-
const row = store.handle.prepare("SELECT key_epoch FROM console_instance WHERE id = 1").get();
|
|
50
|
-
return row === undefined || row["key_epoch"] == null ? null : String(row["key_epoch"]);
|
|
51
|
-
}
|
|
52
48
|
export function clearInstance(store, secret) {
|
|
53
49
|
store.handle.prepare("DELETE FROM console_instance WHERE id = 1 AND secret = ?").run(secret);
|
|
54
50
|
}
|
|
@@ -119,7 +119,7 @@ export const CONSOLE_FORMS = {
|
|
|
119
119
|
telegramPair: formContract("POST /settings/telegram/pair, /settings/telegram/unpair", ["password"]),
|
|
120
120
|
phoneAccess: formContract("POST /settings/phone/access", ["password", "act", "hosted"]),
|
|
121
121
|
phonePair: formContract("POST /settings/phone/pair", ["password"]),
|
|
122
|
-
phonePairing: formContract("POST /settings/phone/confirm, /settings/phone/cancel", ["pairing"]),
|
|
122
|
+
phonePairing: formContract("POST /settings/phone/confirm, /settings/phone/cancel", ["pairing", "setup"]),
|
|
123
123
|
phoneRemove: formContract("POST /settings/phone/remove", ["password", "device"]),
|
|
124
124
|
phonePasskeyEnable: formContract("POST /settings/phone/passkey/enable", ["password"]),
|
|
125
125
|
phonePasskeyRevoke: formContract("POST /settings/phone/passkey/revoke", ["password", "credential"]),
|
package/dist/converse.js
CHANGED
|
@@ -11,7 +11,6 @@ export const MAX_PROPOSALS = 3;
|
|
|
11
11
|
export const MAX_DEPTH = 6;
|
|
12
12
|
export const MAX_OUTPUT_TOKENS = 2_048;
|
|
13
13
|
export const TURN_WALL_CLOCK_MS = 120_000;
|
|
14
|
-
export const PRICE_VERSION = 1;
|
|
15
14
|
const PRICES = {
|
|
16
15
|
"claude-sonnet-5": { inMicrousd: 3, outMicrousd: 15 },
|
|
17
16
|
"claude-opus-5": { inMicrousd: 15, outMicrousd: 75 },
|
package/dist/coordinator.js
CHANGED
|
@@ -3,7 +3,7 @@ import { hashSecret, mintCredential } from "./api-tokens.js";
|
|
|
3
3
|
import { canonicalRepos } from "./runner.js";
|
|
4
4
|
import { fileTaskProposal } from "./proposal.js";
|
|
5
5
|
import { describeScope, summaryContextOf } from "./approval-summary.js";
|
|
6
|
-
import { reportSummaryFor } from "./
|
|
6
|
+
import { reportSummaryFor } from "./report-summary.js";
|
|
7
7
|
import { claimedNowSql, markedRunningSql } from "./task-moves.js";
|
|
8
8
|
import { taskWorkSummaryOf } from "./work-summary.js";
|
|
9
9
|
import { assignmentOf, assignmentBrief } from "./assignment.js";
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { createHmac, randomBytes } from "node:crypto";
|
|
2
|
+
import { existsSync, readFileSync, realpathSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { dirname, join, resolve } from "node:path";
|
|
4
|
+
import { homedir } from "node:os";
|
|
5
|
+
import { createRequire } from "node:module";
|
|
6
|
+
import { openStoreNoMigrate, readSchemaVersion, SCHEMA_VERSION } from "./store.js";
|
|
7
|
+
import { daemonStatus, installLaunchdService, planDesktopService, stopLaunchdService } from "./daemon.js";
|
|
8
|
+
import { run as execRun } from "./exec.js";
|
|
9
|
+
import { containmentStatus, effectiveContainment, parseContainmentPolicy, probeContainmentCapability } from "./containment.js";
|
|
10
|
+
import { validRunnerName } from "./runner.js";
|
|
11
|
+
import { updateAdmissionPaused, updateGateOwned, UPDATE_PAUSED } from "./desktop-update-gate.js";
|
|
12
|
+
import { envTwins, envValue } from "./names.js";
|
|
13
|
+
export function readDesktopConfig(stateDir) {
|
|
14
|
+
const config = JSON.parse(readFileSync(join(stateDir, "desktop.json"), "utf8"));
|
|
15
|
+
if (config.version !== 1 || typeof config.databaseFile !== "string" || !Array.isArray(config.repos) || config.repos.some(repo => typeof repo !== "string") || !Number.isInteger(config.port) || config.port < 1024 || config.port > 65535 || !/^[a-f0-9]{64}$/.test(config.identity))
|
|
16
|
+
throw new Error("Desktop configuration is invalid.");
|
|
17
|
+
if (config.runnerName !== undefined && (typeof config.runnerName !== "string" || !validRunnerName(config.runnerName)))
|
|
18
|
+
throw new Error("Desktop worker identity is invalid.");
|
|
19
|
+
if (config.containment !== undefined && (typeof config.containment !== "string" || !parseContainmentPolicy(config.containment).ok))
|
|
20
|
+
throw new Error("Desktop containment policy is invalid.");
|
|
21
|
+
if (config.databaseInitialized !== undefined && typeof config.databaseInitialized !== "boolean")
|
|
22
|
+
throw new Error("Desktop database setup state is invalid.");
|
|
23
|
+
config.repos = [...new Set(config.repos.map(repo => {
|
|
24
|
+
try {
|
|
25
|
+
return realpathSync(repo);
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
if (["ENOENT", "EACCES", "EPERM"].includes(error.code ?? ""))
|
|
29
|
+
return resolve(repo);
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
}))];
|
|
33
|
+
return config;
|
|
34
|
+
}
|
|
35
|
+
export function desktopDatabaseStatus(file) {
|
|
36
|
+
let db;
|
|
37
|
+
const result = (ready, message) => ({ ready, message, expectedSchema: SCHEMA_VERSION });
|
|
38
|
+
try {
|
|
39
|
+
db = new createRequire(import.meta.url)("node:sqlite").DatabaseSync(file, { readOnly: true });
|
|
40
|
+
db.exec("PRAGMA busy_timeout = 1000");
|
|
41
|
+
const schema = readSchemaVersion(db);
|
|
42
|
+
if (!schema.ok)
|
|
43
|
+
return result(false, `This app cannot use the saved task database: ${schema.problem}. Keep the database; use a compatible release or restore a verified backup separately.`);
|
|
44
|
+
if (schema.version === SCHEMA_VERSION)
|
|
45
|
+
return result(true, "The saved task database is compatible with this app.");
|
|
46
|
+
if (schema.version === null)
|
|
47
|
+
return result(false, "The task database has not been set up. Complete setup before starting work.");
|
|
48
|
+
if (schema.version < 0)
|
|
49
|
+
return result(false, "A database update did not finish. Keep the service stopped and complete the documented database upgrade before starting work.");
|
|
50
|
+
return result(false, `The saved tasks need a database upgrade (version ${schema.version} → ${SCHEMA_VERSION}). Keep the service stopped, back up the database, then complete the documented upgrade. This check changes nothing.`);
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
return result(false, "The saved task database cannot be read. Check that its disk is connected and accessible. If the file is damaged, keep it and restore a verified backup separately; do not create a replacement queue.");
|
|
54
|
+
}
|
|
55
|
+
finally {
|
|
56
|
+
db?.close();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
export function desktopServiceDefinition(stateDir, args) {
|
|
60
|
+
const runtimeDir = dirname(args.node);
|
|
61
|
+
const home = args.home ?? homedir();
|
|
62
|
+
return planDesktopService({
|
|
63
|
+
node: args.node,
|
|
64
|
+
helper: args.helper,
|
|
65
|
+
stateDir,
|
|
66
|
+
label: args.label,
|
|
67
|
+
associatedBundleId: args.bundleId ?? "com.standing-orders.desktop",
|
|
68
|
+
home,
|
|
69
|
+
environment: { ...envTwins("CONTAINMENT", args.containment ?? "observed"), ...(args.buildId ? envTwins("DESKTOP_BUILD", args.buildId) : {}) },
|
|
70
|
+
pathEnv: [runtimeDir, ...(args.providerBin ? [args.providerBin] : []), join(home, ".local", "bin"), "/opt/homebrew/bin", "/usr/local/bin", "/usr/bin", "/bin", "/usr/sbin", "/sbin"].join(":"),
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
export async function verifyDesktopLiveness(config, fetchImpl = fetch) {
|
|
74
|
+
const challenge = randomBytes(32).toString("hex");
|
|
75
|
+
try {
|
|
76
|
+
const response = await fetchImpl(`http://127.0.0.1:${config.port}/desktop/health?challenge=${challenge}`, { signal: AbortSignal.timeout(2_000) });
|
|
77
|
+
if (response.status !== 200)
|
|
78
|
+
return { alive: false, port: config.port, problem: `the controller answered ${response.status} on port ${config.port}` };
|
|
79
|
+
const body = (await response.json());
|
|
80
|
+
const expected = createHmac("sha256", Buffer.from(config.identity, "hex")).update(challenge).digest("hex");
|
|
81
|
+
if (body.proof !== expected)
|
|
82
|
+
return { alive: false, port: config.port, problem: `something on port ${config.port} is not this installation's controller` };
|
|
83
|
+
return { alive: true, port: config.port };
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
return { alive: false, port: config.port, problem: `no controller answered on port ${config.port} (${error instanceof Error ? error.message : String(error)})` };
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
export async function desktopServiceCommand(verb, stateDir, config, argv, supervise = execRun) {
|
|
90
|
+
const read = (name) => {
|
|
91
|
+
const at = argv.indexOf(`--${name}`);
|
|
92
|
+
const value = at >= 0 ? argv[at + 1] : undefined;
|
|
93
|
+
if (value === undefined || value.startsWith("--"))
|
|
94
|
+
throw new Error(`${verb} needs --${name}.`);
|
|
95
|
+
return value;
|
|
96
|
+
};
|
|
97
|
+
const parsed = parseContainmentPolicy(config.containment ?? envValue(process.env, "CONTAINMENT"));
|
|
98
|
+
if (!parsed.ok)
|
|
99
|
+
throw new Error(parsed.problem);
|
|
100
|
+
const providerAt = argv.indexOf("--provider-bin");
|
|
101
|
+
const bundleAt = argv.indexOf("--bundle-id");
|
|
102
|
+
const buildAt = argv.indexOf("--build-id");
|
|
103
|
+
const definition = desktopServiceDefinition(stateDir, { node: read("node"), helper: read("helper"), label: read("label"), containment: parsed.policy, ...(providerAt >= 0 ? { providerBin: read("provider-bin") } : {}), ...(bundleAt >= 0 ? { bundleId: read("bundle-id") } : {}), ...(buildAt >= 0 ? { buildId: read("build-id") } : {}) });
|
|
104
|
+
if (verb === "service-start") {
|
|
105
|
+
if (argv.includes("--update-id")) {
|
|
106
|
+
const update = await import("./desktop-update.js");
|
|
107
|
+
const journal = update.readUpdateJournal(stateDir);
|
|
108
|
+
if (!journal || journal.id !== read("update-id") || update.updateStopRequested(journal))
|
|
109
|
+
throw new Error("This update is no longer allowed to start the background service.");
|
|
110
|
+
}
|
|
111
|
+
if (config.repos.length === 0)
|
|
112
|
+
throw new Error("Choose a repository in the desktop app first.");
|
|
113
|
+
const database = desktopDatabaseStatus(config.databaseFile);
|
|
114
|
+
if (!database.ready)
|
|
115
|
+
throw new Error(database.message);
|
|
116
|
+
const opened = openStoreNoMigrate(config.databaseFile);
|
|
117
|
+
if (!opened.ok)
|
|
118
|
+
throw new Error(opened.message);
|
|
119
|
+
try {
|
|
120
|
+
const updateAt = argv.indexOf("--update-id");
|
|
121
|
+
if (updateAdmissionPaused(opened.store.raw()) && (updateAt < 0 || !updateGateOwned(opened.store.raw(), read("update-id"))))
|
|
122
|
+
throw new Error(UPDATE_PAUSED);
|
|
123
|
+
}
|
|
124
|
+
finally {
|
|
125
|
+
opened.store.close();
|
|
126
|
+
}
|
|
127
|
+
if (!existsSync(definition.logPath))
|
|
128
|
+
writeFileSync(definition.logPath, "", { mode: 0o600 });
|
|
129
|
+
const started = await installLaunchdService(definition, supervise);
|
|
130
|
+
if (!started.ok)
|
|
131
|
+
throw new Error(started.message);
|
|
132
|
+
return { ok: true, action: started.action, changed: started.changed, label: definition.label, unit: definition.unitPath };
|
|
133
|
+
}
|
|
134
|
+
if (verb === "service-stop") {
|
|
135
|
+
if (!argv.includes("--update-id") && existsSync(join(stateDir, "desktop-update.json"))) {
|
|
136
|
+
try {
|
|
137
|
+
await (await import("./desktop-update.js")).requestUpdateStop(stateDir);
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
const recoveryLabel = `${definition.label}.update`;
|
|
141
|
+
const recoveryStopped = await stopLaunchdService({ ...definition, label: recoveryLabel, unitPath: join(dirname(definition.unitPath), `${recoveryLabel}.plist`) }, supervise);
|
|
142
|
+
console.error(recoveryStopped.ok ? "The update stop request could not be recorded, so automatic update recovery was disabled. Preserve the update files and check Update status before restarting." : "The update stop request and recovery-service stop could not be confirmed. Check Update status and service logs before leaving this installation unattended.");
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
const stopped = await stopLaunchdService(definition, supervise);
|
|
146
|
+
if (!stopped.ok)
|
|
147
|
+
throw new Error(stopped.message);
|
|
148
|
+
return { ok: true, wasLoaded: stopped.wasLoaded, label: definition.label };
|
|
149
|
+
}
|
|
150
|
+
if (verb === "service-status") {
|
|
151
|
+
const status = await daemonStatus(definition, supervise);
|
|
152
|
+
const liveness = status.state === "running" ? await verifyDesktopLiveness(config) : null;
|
|
153
|
+
return { ok: true, ...status, label: definition.label, liveness, database: desktopDatabaseStatus(config.databaseFile), containment: containmentStatus(effectiveContainment(parsed.policy, probeContainmentCapability())) };
|
|
154
|
+
}
|
|
155
|
+
throw new Error("Unknown desktop service operation.");
|
|
156
|
+
}
|