toolroll 0.9.116 → 0.9.118
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 +46 -0
- package/README.md +43 -26
- package/dist/acp-agents.js +14 -1
- package/dist/acp-client.js +19 -1
- package/dist/agent-change-check.js +60 -0
- package/dist/agent-change-schema.js +19 -0
- package/dist/agent-detect.js +11 -1
- package/dist/agent-fence.js +93 -16
- package/dist/agent-network-request.js +108 -0
- package/dist/agent-requests.js +105 -0
- package/dist/approval-summary.js +3 -3
- package/dist/backup.js +17 -1
- package/dist/batch-checks.js +81 -18
- package/dist/browser/terminal.js +41 -41
- package/dist/browser/workspace.css +2 -2
- package/dist/browser/workspace.js +36 -36
- package/dist/builder.js +12 -2
- package/dist/candidate-materialize.js +119 -0
- package/dist/central-enrollment-contract.js +156 -0
- package/dist/central-recovery-stage.js +329 -0
- package/dist/chat-actions.js +101 -2
- package/dist/chat-channel.js +40 -0
- package/dist/check-only-standing.js +13 -0
- package/dist/check-only.js +25 -13
- package/dist/check-recovery-hold.js +199 -0
- package/dist/check-recovery-index-schema.js +3 -0
- package/dist/check-screenshots.js +83 -0
- package/dist/cli.js +125 -6
- package/dist/codex-limits.js +4 -0
- package/dist/coding-context.js +16 -2
- package/dist/coding-provider.js +7 -3
- package/dist/coding-workspace.js +5 -5
- package/dist/connect-cli.js +257 -11
- package/dist/contracts/chat-actions.js +4 -0
- package/dist/contracts/console-api.js +14 -3
- package/dist/contracts/engine-api.js +331 -2
- package/dist/contracts/lead-tools.js +56 -2
- package/dist/contracts/provider.js +1 -1
- package/dist/contracts/route.js +1 -1
- package/dist/contracts/terminal-connection.js +50 -0
- package/dist/converse.js +80 -4
- package/dist/device-pair.js +280 -0
- package/dist/direct-chat-artifacts.js +347 -0
- package/dist/direct-chat-catalog.js +311 -0
- package/dist/direct-chat-fence.js +96 -0
- package/dist/direct-chat-git.js +343 -0
- package/dist/direct-chat-laptop.js +19 -0
- package/dist/direct-chat-schema.js +181 -0
- package/dist/direct-chat-ship.js +861 -0
- package/dist/direct-chat-workspace.js +389 -0
- package/dist/direct-chat.js +2107 -0
- package/dist/doctor.js +1 -1
- package/dist/easy-start.js +18 -0
- package/dist/egress.js +25 -4
- package/dist/engine-chat.js +454 -0
- package/dist/engine-reads.js +141 -13
- package/dist/exec.js +4 -3
- package/dist/flexible-agents.js +8 -16
- package/dist/flexible-session.js +91 -47
- package/dist/flexible-ship.js +87 -7
- package/dist/flexible-start.js +4 -1
- package/dist/flexible-thread.js +2 -3
- package/dist/flexible-turns.js +26 -5
- package/dist/flow-triggers.js +13 -4
- package/dist/flows-ui.js +54 -20
- package/dist/handoff-cli.js +630 -0
- package/dist/invoke.js +71 -17
- package/dist/lead-contract.js +5 -4
- package/dist/lead-doors.js +80 -1
- package/dist/lead-progress.js +9 -0
- package/dist/lead-tools.js +681 -10
- package/dist/lead.js +37 -9
- package/dist/live-bus.js +11 -0
- package/dist/live-terminal.js +132 -12
- package/dist/local-handoff.js +363 -0
- package/dist/local-owner-acts.js +264 -2
- package/dist/local-owner.js +16 -1
- package/dist/multiplayer-handoff.js +528 -0
- package/dist/multiplayer-presence.js +471 -0
- package/dist/names.js +17 -4
- package/dist/needs-you.js +10 -0
- package/dist/operate.js +280 -19
- package/dist/planner.js +6 -1
- package/dist/policy.js +2 -2
- package/dist/project-delete-ui.js +18 -11
- package/dist/project-delete.js +65 -4
- package/dist/project-skills.js +28 -13
- package/dist/project-tools.js +1 -1
- package/dist/prompt.js +1 -1
- package/dist/provider-connection.js +2 -0
- package/dist/provider-home.js +251 -8
- package/dist/provider.js +3 -2
- package/dist/publish.js +119 -64
- package/dist/pull-request-flow.js +35 -14
- package/dist/read-executor-worker.js +1 -1
- package/dist/read-executor.js +95 -1
- package/dist/restore-retirement.js +152 -0
- package/dist/result-follow-ups.js +116 -37
- package/dist/route-change.js +44 -4
- package/dist/scope.js +62 -5
- package/dist/scout.js +6 -2
- package/dist/serve.js +49 -5
- package/dist/server/chat.js +94 -13
- package/dist/server/direct-chat.js +583 -0
- package/dist/server/engine-api.js +219 -21
- package/dist/server/flows.js +43 -10
- package/dist/server/found-repos.js +25 -0
- package/dist/server/guards.js +20 -6
- package/dist/server/live.js +81 -23
- package/dist/server/pages.js +67 -13
- package/dist/server/people-tokens.js +47 -6
- package/dist/server/remote.js +29 -0
- package/dist/server/render-results.js +6 -2
- package/dist/server/render-settings.js +4 -2
- package/dist/server/render-tasks.js +18 -17
- package/dist/server/route-table.js +69 -2
- package/dist/server/settings.js +22 -7
- package/dist/server/task-views.js +15 -3
- package/dist/server/tasks.js +39 -2
- package/dist/server/terminals.js +185 -11
- package/dist/settings-proofs.js +1 -1
- package/dist/skills-manifest.js +57 -0
- package/dist/store.js +499 -56
- package/dist/subscription-chat.js +33 -6
- package/dist/subscription-usage.js +233 -0
- package/dist/task-live.js +2 -1
- package/dist/teardown-git.js +34 -4
- package/dist/terminal-connection.js +159 -0
- package/dist/tui/darwin-arm64/toolroll-tui +0 -0
- package/dist/tui/darwin-x64/toolroll-tui +0 -0
- package/dist/tui/linux-arm64/toolroll-tui +0 -0
- package/dist/tui/linux-x64/toolroll-tui +0 -0
- package/dist/tui-contract.js +1 -1
- package/dist/tui-launch.js +32 -1
- package/dist/workspace-identity-schema.js +21 -0
- package/package.json +4 -2
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import { resolve, join } from "node:path";
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
import { DatabaseSync } from "node:sqlite";
|
|
5
|
+
import { openStore } from "./store.js";
|
|
6
|
+
import { holdAutoPublish, autoPublishHeld, PUBLISH_ALLOWED_ACTION, PUBLISH_HELD_ACTION } from "./release-auto.js";
|
|
7
|
+
import { revokeCoordinator } from "./coordinator.js";
|
|
8
|
+
export const MAX_STAGE_BYTES = 128 * 1024 * 1024;
|
|
9
|
+
const SUPPORTED_SCHEMA = 184;
|
|
10
|
+
const SCHEMA_OBJECT_COUNT = 724;
|
|
11
|
+
const SCHEMA_DIGEST = "e56d12d9ce4f612ab6de397055ca9aeb233d939c001446fd90b7b3ebbcc5a62c";
|
|
12
|
+
const INVENTORY = [
|
|
13
|
+
["person-credentials", "store.ts:revokeApiToken", "credential", true],
|
|
14
|
+
["lead-credentials", "store.ts:revokeLeadCredentials", "credential", true],
|
|
15
|
+
["coordinator-credentials", "coordinator.ts:revokeCoordinator", "credential/coordinator_proposal", true],
|
|
16
|
+
["inbound-oauth", "mcp-oauth.ts/store.ts", "oauth_code/oauth_grant/oauth_refresh", true],
|
|
17
|
+
["publication-grant-verifier", "store.ts:revokePublicationGrant/publish.ts:permitsPublication", "publication_grant", true],
|
|
18
|
+
["release-publish-ledger-hold", "release-auto.ts:holdAutoPublish/autoPublishHeld", "action_ledger (latest held/allowed by id for nonnull task ids)", true],
|
|
19
|
+
["intake-grant-fresh-command-admission", "store.ts:clearIntakeGrant/operate.ts:intakeCommand", "intake_grant", true],
|
|
20
|
+
["flexible-snapshot-sign-in-admission", "flexible-sign-in.ts verifier semantics (private snapshot SQL only)", "flexible_sign_in/flexible_sign_in_epoch", true],
|
|
21
|
+
["durable-browser-sessions", "server/guards.ts/session.ts", "web_session", true],
|
|
22
|
+
["local-owner-and-memory", "local-owner.ts/server/guards.ts", "local_mode/in-memory nonces and links", false],
|
|
23
|
+
["password-and-saved-login", "scope.ts/login-secrets.ts", "approver/protected login files", false],
|
|
24
|
+
["sso-membership", "sso-settings.ts/store.ts", "sso_identity/protected sign-in settings", false],
|
|
25
|
+
["derived-chat-invites-push", "store.ts/chat-approval.ts", "paired chat/confirmations/invites/push", false],
|
|
26
|
+
["flexible-authority", "flexible-sign-in.ts", "flexible sign-ins/threads/protected secrets", false],
|
|
27
|
+
["runner-and-native-custody", "runner.ts/runner-process.ts", "claims/leases/attempts/protected process records", false],
|
|
28
|
+
["execution-and-publication", "approval-authority.ts/approval-policy.ts", "approvals/modes/releases/schedules/repair", false],
|
|
29
|
+
["public-hooks-and-triggers", "server/remote-hooks.ts/flow-triggers.ts", "intake/trigger/delivery standing", false],
|
|
30
|
+
["provider-and-outbound-oauth", "keys.ts/tool-secret-store.ts", "external secrets/tool and task references", false],
|
|
31
|
+
["central-device-and-transfer", "future central protocol", "enrollment/lease/transfer/settlement", false],
|
|
32
|
+
];
|
|
33
|
+
const stages = new WeakMap();
|
|
34
|
+
const stamp = (s) => ({ dev: s.dev, ino: s.ino, size: s.size, mtimeMs: s.mtimeMs, ctimeMs: s.ctimeMs });
|
|
35
|
+
const same = (a, b) => a.dev === b.dev && a.ino === b.ino && a.size === b.size && a.mtimeMs === b.mtimeMs && a.ctimeMs === b.ctimeMs;
|
|
36
|
+
const digest = (bytes) => createHash("sha256").update(bytes).digest("hex");
|
|
37
|
+
function canonical(path, directory = false) {
|
|
38
|
+
if (typeof path !== "string" || resolve(path) !== path || fs.realpathSync(path) !== path)
|
|
39
|
+
throw Error("Stage path must be canonical and contain no symlink");
|
|
40
|
+
const s = fs.lstatSync(path);
|
|
41
|
+
if (s.isSymbolicLink() || (directory ? !s.isDirectory() : !s.isFile()))
|
|
42
|
+
throw Error("Stage path is not a plain file or directory");
|
|
43
|
+
return s;
|
|
44
|
+
}
|
|
45
|
+
function noSidecars(path) {
|
|
46
|
+
for (const suffix of ["-wal", "-shm", "-journal"]) {
|
|
47
|
+
try {
|
|
48
|
+
fs.lstatSync(path + suffix);
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
if (error.code === "ENOENT")
|
|
52
|
+
continue;
|
|
53
|
+
throw error;
|
|
54
|
+
}
|
|
55
|
+
throw Error("Cold backup has a journal or WAL sidecar");
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function regularBounded(fd) {
|
|
59
|
+
const info = fs.fstatSync(fd);
|
|
60
|
+
if (!info.isFile())
|
|
61
|
+
throw Error("Opened backup is not a regular file");
|
|
62
|
+
if (!Number.isSafeInteger(info.size) || info.size < 0 || info.size > MAX_STAGE_BYTES)
|
|
63
|
+
throw Error("Backup exceeds128MiB stage byte limit");
|
|
64
|
+
return info;
|
|
65
|
+
}
|
|
66
|
+
function readBounded(fd) {
|
|
67
|
+
const initial = regularBounded(fd);
|
|
68
|
+
const bytes = Buffer.allocUnsafe(initial.size);
|
|
69
|
+
let offset = 0;
|
|
70
|
+
while (offset < bytes.length) {
|
|
71
|
+
if (!same(stamp(initial), stamp(regularBounded(fd))))
|
|
72
|
+
throw Error("File changed while being read");
|
|
73
|
+
const size = fs.readSync(fd, bytes, offset, Math.min(64 * 1024, bytes.length - offset), offset);
|
|
74
|
+
if (size === 0)
|
|
75
|
+
throw Error("File changed while being read");
|
|
76
|
+
offset += size;
|
|
77
|
+
}
|
|
78
|
+
if (!same(stamp(initial), stamp(regularBounded(fd))))
|
|
79
|
+
throw Error("File changed while being read");
|
|
80
|
+
const extra = Buffer.allocUnsafe(1);
|
|
81
|
+
if (fs.readSync(fd, extra, 0, 1, offset) !== 0)
|
|
82
|
+
throw Error("File changed while being read");
|
|
83
|
+
if (!same(stamp(initial), stamp(regularBounded(fd))))
|
|
84
|
+
throw Error("File changed while being read");
|
|
85
|
+
return bytes;
|
|
86
|
+
}
|
|
87
|
+
function readStable(path) {
|
|
88
|
+
noSidecars(path);
|
|
89
|
+
const before = stamp(canonical(path));
|
|
90
|
+
const fd = fs.openSync(path, fs.constants.O_RDONLY | fs.constants.O_NOFOLLOW | fs.constants.O_NONBLOCK);
|
|
91
|
+
try {
|
|
92
|
+
if (!same(before, stamp(regularBounded(fd))))
|
|
93
|
+
throw Error("File identity changed");
|
|
94
|
+
const bytes = readBounded(fd), hash = digest(bytes);
|
|
95
|
+
if (!same(before, stamp(regularBounded(fd))) || !same(before, stamp(canonical(path))))
|
|
96
|
+
throw Error("File changed while being read");
|
|
97
|
+
noSidecars(path);
|
|
98
|
+
return { mark: before, hash, header: Buffer.from(bytes.subarray(0, 100)) };
|
|
99
|
+
}
|
|
100
|
+
finally {
|
|
101
|
+
fs.closeSync(fd);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function schemaOf(path) {
|
|
105
|
+
const db = new DatabaseSync(path, { readOnly: true });
|
|
106
|
+
try {
|
|
107
|
+
if (db.prepare("PRAGMA quick_check").get()?.["quick_check"] !== "ok")
|
|
108
|
+
throw Error("Copied backup integrity check failed");
|
|
109
|
+
const rows = db.prepare("SELECT type,name,tbl_name,sql FROM sqlite_master WHERE name NOT LIKE 'sqlite_%' ORDER BY type,name").all();
|
|
110
|
+
const version = db.prepare("SELECT version FROM schema_version").all();
|
|
111
|
+
const schema = version.length === 1 && typeof version[0]?.["version"] === "number" ? version[0]["version"] : null;
|
|
112
|
+
return { schema, supported: schema === SUPPORTED_SCHEMA && rows.length === SCHEMA_OBJECT_COUNT && createHash("sha256").update(JSON.stringify(rows)).digest("hex") === SCHEMA_DIGEST };
|
|
113
|
+
}
|
|
114
|
+
finally {
|
|
115
|
+
db.close();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
export function copyCentralRecoveryStage(source, privateParent) {
|
|
119
|
+
const parent = canonical(privateParent, true);
|
|
120
|
+
if (parent.uid !== process.getuid?.() || (parent.mode & 0o077) !== 0)
|
|
121
|
+
throw Error("Stage parent must be owner-private");
|
|
122
|
+
const initial = readStable(source);
|
|
123
|
+
const header = initial.header;
|
|
124
|
+
if (header.toString("ascii", 0, 16) !== "SQLite format 3\0" || header[18] !== 1 || header[19] !== 1)
|
|
125
|
+
throw Error("Cold backup must be a standalone rollback-journal database, not WAL mode");
|
|
126
|
+
const directory = fs.mkdtempSync(join(privateParent, "central-recovery-"));
|
|
127
|
+
fs.chmodSync(directory, 0o700);
|
|
128
|
+
const copy = join(directory, "stage.db");
|
|
129
|
+
let stageStore;
|
|
130
|
+
try {
|
|
131
|
+
const fd = fs.openSync(source, fs.constants.O_RDONLY | fs.constants.O_NOFOLLOW | fs.constants.O_NONBLOCK);
|
|
132
|
+
try {
|
|
133
|
+
if (!same(initial.mark, stamp(regularBounded(fd))))
|
|
134
|
+
throw Error("Source changed before copy");
|
|
135
|
+
const bytes = readBounded(fd);
|
|
136
|
+
if (digest(bytes) !== initial.hash || !same(initial.mark, stamp(regularBounded(fd))))
|
|
137
|
+
throw Error("Source changed during copy");
|
|
138
|
+
const output = fs.openSync(copy, fs.constants.O_CREAT | fs.constants.O_EXCL | fs.constants.O_WRONLY | fs.constants.O_NOFOLLOW, 0o600);
|
|
139
|
+
try {
|
|
140
|
+
fs.writeFileSync(output, bytes);
|
|
141
|
+
fs.fsyncSync(output);
|
|
142
|
+
}
|
|
143
|
+
finally {
|
|
144
|
+
fs.closeSync(output);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
finally {
|
|
148
|
+
fs.closeSync(fd);
|
|
149
|
+
}
|
|
150
|
+
const after = readStable(source), copied = readStable(copy);
|
|
151
|
+
if (!same(initial.mark, after.mark) || initial.hash !== after.hash || copied.hash !== initial.hash
|
|
152
|
+
|| (copied.mark.dev === initial.mark.dev && copied.mark.ino === initial.mark.ino))
|
|
153
|
+
throw Error("Source/copy identity disagrees");
|
|
154
|
+
const shape = schemaOf(copy), validated = readStable(copy);
|
|
155
|
+
if (validated.hash !== copied.hash || !same(validated.mark, copied.mark))
|
|
156
|
+
throw Error("Stage changed during validation");
|
|
157
|
+
if (shape.supported) {
|
|
158
|
+
stageStore = openStore(copy);
|
|
159
|
+
const openedFile = canonical(copy);
|
|
160
|
+
if (stageStore.databaseFile() !== copy || openedFile.dev !== copied.mark.dev || openedFile.ino !== copied.mark.ino) {
|
|
161
|
+
throw Error("Retained stage database file changed after open");
|
|
162
|
+
}
|
|
163
|
+
const openedVersion = stageStore.handle.prepare("SELECT version FROM schema_version").all();
|
|
164
|
+
const openedRows = stageStore.handle.prepare("SELECT type,name,tbl_name,sql FROM sqlite_master WHERE name NOT LIKE 'sqlite_%' ORDER BY type,name").all();
|
|
165
|
+
if (openedVersion.length !== 1 || openedVersion[0]?.["version"] !== SUPPORTED_SCHEMA || openedRows.length !== SCHEMA_OBJECT_COUNT
|
|
166
|
+
|| createHash("sha256").update(JSON.stringify(openedRows)).digest("hex") !== SCHEMA_DIGEST)
|
|
167
|
+
throw Error("Retained stage schema changed after open");
|
|
168
|
+
stageStore.handle.exec("PRAGMA wal_checkpoint(TRUNCATE); PRAGMA journal_mode=DELETE");
|
|
169
|
+
}
|
|
170
|
+
const final = readStable(copy);
|
|
171
|
+
if (final.mark.dev !== copied.mark.dev || final.mark.ino !== copied.mark.ino)
|
|
172
|
+
throw Error("Copied stage identity replaced");
|
|
173
|
+
const handle = Object.freeze({ copyPath: copy });
|
|
174
|
+
stages.set(handle, { source, sourceStamp: initial.mark, sourceDigest: initial.hash, copy, copyStamp: final.mark, copyDigest: final.hash,
|
|
175
|
+
directory, directoryStamp: stamp(canonical(directory, true)), ...(stageStore === undefined ? {} : { store: stageStore }), ...shape });
|
|
176
|
+
return handle;
|
|
177
|
+
}
|
|
178
|
+
catch (error) {
|
|
179
|
+
stageStore?.close();
|
|
180
|
+
fs.rmSync(directory, { recursive: true, force: true });
|
|
181
|
+
throw error;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
function admitted(handle) {
|
|
185
|
+
const kept = typeof handle === "object" && handle !== null ? stages.get(handle) : undefined;
|
|
186
|
+
if (kept === undefined)
|
|
187
|
+
throw Error("Not an internally constructed recovery stage");
|
|
188
|
+
const dir = stamp(canonical(kept.directory, true));
|
|
189
|
+
if (dir.dev !== kept.directoryStamp.dev || dir.ino !== kept.directoryStamp.ino)
|
|
190
|
+
throw Error("Private stage directory replaced");
|
|
191
|
+
const source = readStable(kept.source), copy = readStable(kept.copy);
|
|
192
|
+
if (!same(source.mark, kept.sourceStamp) || source.hash !== kept.sourceDigest || !same(copy.mark, kept.copyStamp)
|
|
193
|
+
|| copy.hash !== kept.copyDigest || (copy.mark.dev === source.mark.dev && copy.mark.ino === source.mark.ino))
|
|
194
|
+
throw Error("Recovery stage/source changed");
|
|
195
|
+
return kept;
|
|
196
|
+
}
|
|
197
|
+
function report(kept, outcome, counts = new Map()) {
|
|
198
|
+
return { manifestVersion: 1, manifestDigest: createHash("sha256").update(JSON.stringify({ schema: SUPPORTED_SCHEMA, shape: SCHEMA_DIGEST, inventory: INVENTORY })).digest("hex"), schema: kept.schema, schemaSupported: kept.supported, complete: false, recoveryReady: false, outcome, repeated: false,
|
|
199
|
+
entries: INVENTORY.map(([id, owner, storage, implemented]) => ({ id, owner, storage,
|
|
200
|
+
status: outcome === "retired-partial" && implemented ? "retired" : "unsupported",
|
|
201
|
+
affected: outcome === "retired-partial" && implemented ? counts.get(id) ?? 0 : null,
|
|
202
|
+
remaining: outcome === "retired-partial" && implemented ? 0 : null })) };
|
|
203
|
+
}
|
|
204
|
+
const count = (store, sql) => Number(store.handle.prepare(sql).get()?.["n"]);
|
|
205
|
+
export function retireCentralRecoveryStage(handle) {
|
|
206
|
+
const kept = admitted(handle);
|
|
207
|
+
if (kept.report !== undefined)
|
|
208
|
+
return structuredClone({ ...kept.report, repeated: true });
|
|
209
|
+
if (!kept.supported)
|
|
210
|
+
return report(kept, "unsupported-schema");
|
|
211
|
+
let store, result;
|
|
212
|
+
try {
|
|
213
|
+
store = kept.store;
|
|
214
|
+
if (store === undefined)
|
|
215
|
+
throw Error("Stage is closed");
|
|
216
|
+
const stage = store, now = new Date(), by = "central-recovery-stage";
|
|
217
|
+
result = stage.transact(() => {
|
|
218
|
+
const counts = new Map();
|
|
219
|
+
counts.set("person-credentials", count(stage, "SELECT count(*) AS n FROM credential WHERE kind='person' AND revoked_at IS NULL"));
|
|
220
|
+
for (const token of stage.apiTokens(null))
|
|
221
|
+
if (token.revokedAt === null)
|
|
222
|
+
stage.revokeApiToken(token.id, by, now, "isolated recovery stage");
|
|
223
|
+
counts.set("lead-credentials", count(stage, "SELECT count(*) AS n FROM credential WHERE kind='lead' AND revoked_at IS NULL"));
|
|
224
|
+
for (const row of stage.handle.prepare("SELECT DISTINCT account FROM credential WHERE kind='lead' AND revoked_at IS NULL").all())
|
|
225
|
+
stage.revokeLeadCredentials(String(row["account"]), by, now);
|
|
226
|
+
counts.set("coordinator-credentials", count(stage, "SELECT count(*) AS n FROM credential WHERE kind='coordinator' AND revoked_at IS NULL"));
|
|
227
|
+
for (const row of stage.handle.prepare("SELECT id FROM credential WHERE kind='coordinator' AND revoked_at IS NULL").all()) {
|
|
228
|
+
if (!revokeCoordinator(stage, String(row["id"]), by, now).ok)
|
|
229
|
+
throw Error("Coordinator retirement failed");
|
|
230
|
+
}
|
|
231
|
+
for (const row of stage.handle.prepare("SELECT id FROM credential WHERE kind='coordinator'").all())
|
|
232
|
+
stage.sweepCoordinatorProposals(now, String(row["id"]));
|
|
233
|
+
counts.set("inbound-oauth", count(stage, "SELECT (SELECT count(*) FROM oauth_code)+(SELECT count(*) FROM oauth_grant)+(SELECT count(*) FROM oauth_refresh) AS n"));
|
|
234
|
+
stage.handle.exec("DELETE FROM oauth_code; DELETE FROM oauth_refresh; DELETE FROM oauth_grant");
|
|
235
|
+
counts.set("publication-grant-verifier", count(stage, "SELECT count(*) AS n FROM publication_grant WHERE revoked_at IS NULL"));
|
|
236
|
+
for (const row of stage.handle.prepare("SELECT DISTINCT repo FROM publication_grant WHERE revoked_at IS NULL").all()) {
|
|
237
|
+
if (!stage.revokePublicationGrant(String(row["repo"]), by, now))
|
|
238
|
+
throw Error("Publication grant retirement failed");
|
|
239
|
+
}
|
|
240
|
+
const releaseTasks = stage.handle.prepare("SELECT DISTINCT task_id FROM action_ledger WHERE task_id IS NOT NULL AND action IN (?, ?)").all(PUBLISH_HELD_ACTION, PUBLISH_ALLOWED_ACTION);
|
|
241
|
+
let held = 0;
|
|
242
|
+
for (const row of releaseTasks) {
|
|
243
|
+
const taskId = String(row["task_id"]);
|
|
244
|
+
if (autoPublishHeld(stage, taskId) === null) {
|
|
245
|
+
holdAutoPublish(stage, { taskId, now, why: "Restored publication permission is on hold. This does not establish whether earlier work ran or stopped." });
|
|
246
|
+
held += 1;
|
|
247
|
+
}
|
|
248
|
+
if (autoPublishHeld(stage, taskId) === null)
|
|
249
|
+
throw Error("Release publication hold failed");
|
|
250
|
+
}
|
|
251
|
+
counts.set("release-publish-ledger-hold", held);
|
|
252
|
+
const stillAllowed = stage.handle.prepare(`SELECT count(*) AS n FROM action_ledger a
|
|
253
|
+
JOIN (SELECT max(id) AS id FROM action_ledger WHERE task_id IS NOT NULL AND action IN (?, ?) GROUP BY task_id) latest ON latest.id = a.id
|
|
254
|
+
WHERE a.action = ?`).get(PUBLISH_HELD_ACTION, PUBLISH_ALLOWED_ACTION, PUBLISH_ALLOWED_ACTION);
|
|
255
|
+
if (Number(stillAllowed?.["n"]) !== 0)
|
|
256
|
+
throw Error("Restored release permission remains allowed");
|
|
257
|
+
counts.set("intake-grant-fresh-command-admission", count(stage, "SELECT count(*) AS n FROM intake_grant WHERE revoked_at IS NULL"));
|
|
258
|
+
for (const row of stage.handle.prepare("SELECT DISTINCT repo FROM intake_grant WHERE revoked_at IS NULL").all()) {
|
|
259
|
+
if (!stage.clearIntakeGrant(String(row["repo"]), by, now))
|
|
260
|
+
throw Error("Intake grant retirement failed");
|
|
261
|
+
}
|
|
262
|
+
const people = stage.handle.prepare(`SELECT person FROM flexible_sign_in UNION SELECT person FROM flexible_sign_in_epoch
|
|
263
|
+
UNION SELECT created_by AS person FROM flexible_thread UNION SELECT owner AS person FROM thread_turn
|
|
264
|
+
UNION SELECT owner AS person FROM flexible_interactive_session
|
|
265
|
+
UNION SELECT sign_in_person AS person FROM thread_relay_call WHERE sign_in_person IS NOT NULL
|
|
266
|
+
UNION SELECT sign_in_person AS person FROM thread_relay_pending WHERE sign_in_person IS NOT NULL`).all();
|
|
267
|
+
const epochs = new Map();
|
|
268
|
+
for (const row of people) {
|
|
269
|
+
const person = row["person"];
|
|
270
|
+
if (typeof person !== "string" || person.length < 1 || person.length > 200)
|
|
271
|
+
throw Error("Unknown snapshot sign-in identity");
|
|
272
|
+
const old = stage.handle.prepare("SELECT epoch FROM flexible_sign_in_epoch WHERE person = ?").get(person)?.["epoch"] ?? 0;
|
|
273
|
+
if (typeof old !== "number" || !Number.isSafeInteger(old) || old < 0 || old >= Number.MAX_SAFE_INTEGER)
|
|
274
|
+
throw Error("Unsafe snapshot epoch");
|
|
275
|
+
epochs.set(person, old);
|
|
276
|
+
}
|
|
277
|
+
const captured = stage.handle.prepare(`SELECT owner AS person, sign_in_epoch AS epoch FROM flexible_interactive_session
|
|
278
|
+
UNION ALL SELECT sign_in_person AS person, sign_in_epoch AS epoch FROM thread_relay_call WHERE sign_in_epoch IS NOT NULL
|
|
279
|
+
UNION ALL SELECT sign_in_person AS person, sign_in_epoch AS epoch FROM thread_relay_pending WHERE sign_in_epoch IS NOT NULL`).all();
|
|
280
|
+
for (const row of captured) {
|
|
281
|
+
const person = row["person"], epoch = row["epoch"];
|
|
282
|
+
if (typeof person !== "string" || !epochs.has(person) || typeof epoch !== "number" || !Number.isSafeInteger(epoch) || epoch < 0 || epoch > epochs.get(person))
|
|
283
|
+
throw Error("Snapshot captured epoch disagrees");
|
|
284
|
+
}
|
|
285
|
+
counts.set("flexible-snapshot-sign-in-admission", count(stage, "SELECT count(*) AS n FROM flexible_sign_in WHERE state IN ('active','staged')"));
|
|
286
|
+
stage.handle.prepare("UPDATE flexible_sign_in SET state='retiring', save_op=NULL, retire_after=NULL, retired_at=? WHERE state IN ('active','staged')").run(now.toISOString());
|
|
287
|
+
for (const [person, old] of epochs) {
|
|
288
|
+
stage.handle.prepare("INSERT INTO flexible_sign_in_epoch (person,epoch) VALUES (?,?) ON CONFLICT(person) DO UPDATE SET epoch=excluded.epoch").run(person, old + 1);
|
|
289
|
+
if (stage.handle.prepare("SELECT epoch FROM flexible_sign_in_epoch WHERE person=?").get(person)?.["epoch"] !== old + 1)
|
|
290
|
+
throw Error("Snapshot epoch fence failed");
|
|
291
|
+
}
|
|
292
|
+
if (count(stage, "SELECT count(*) AS n FROM flexible_sign_in WHERE state IN ('active','staged')") !== 0)
|
|
293
|
+
throw Error("Snapshot sign-in admission remains live");
|
|
294
|
+
const sessions = stage.webSessions(null);
|
|
295
|
+
counts.set("durable-browser-sessions", sessions.length);
|
|
296
|
+
for (const session of sessions)
|
|
297
|
+
stage.dropWebSession(session.idHash);
|
|
298
|
+
if (count(stage, "SELECT count(*) AS n FROM intake_grant WHERE revoked_at IS NULL") !== 0
|
|
299
|
+
|| count(stage, "SELECT count(*) AS n FROM publication_grant WHERE revoked_at IS NULL") !== 0
|
|
300
|
+
|| count(stage, "SELECT count(*) AS n FROM coordinator_proposal WHERE state IN ('pending','confirming')") !== 0
|
|
301
|
+
|| count(stage, "SELECT count(*) AS n FROM credential WHERE revoked_at IS NULL") !== 0
|
|
302
|
+
|| count(stage, "SELECT (SELECT count(*) FROM oauth_code)+(SELECT count(*) FROM oauth_grant)+(SELECT count(*) FROM oauth_refresh)+(SELECT count(*) FROM web_session) AS n") !== 0)
|
|
303
|
+
throw Error("Retirement postcondition failed");
|
|
304
|
+
return report(kept, "retired-partial", counts);
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
catch {
|
|
308
|
+
result = report(kept, "failed");
|
|
309
|
+
}
|
|
310
|
+
finally {
|
|
311
|
+
store?.close();
|
|
312
|
+
delete kept.store;
|
|
313
|
+
}
|
|
314
|
+
const copy = readStable(kept.copy);
|
|
315
|
+
if (copy.mark.dev !== kept.copyStamp.dev || copy.mark.ino !== kept.copyStamp.ino)
|
|
316
|
+
throw Error("Retired stage identity replaced");
|
|
317
|
+
kept.copyStamp = copy.mark;
|
|
318
|
+
kept.copyDigest = copy.hash;
|
|
319
|
+
admitted(handle);
|
|
320
|
+
kept.report = structuredClone(result);
|
|
321
|
+
return result;
|
|
322
|
+
}
|
|
323
|
+
export function closeCentralRecoveryStage(handle) {
|
|
324
|
+
const kept = stages.get(handle);
|
|
325
|
+
if (kept === undefined)
|
|
326
|
+
throw Error("Not an internally constructed recovery stage");
|
|
327
|
+
kept.store?.close();
|
|
328
|
+
delete kept.store;
|
|
329
|
+
}
|
package/dist/chat-actions.js
CHANGED
|
@@ -163,6 +163,10 @@ export const CHAT_ACTIONS = {
|
|
|
163
163
|
task_cancel: { label: "Cancel task", protected: true, password: false },
|
|
164
164
|
task_resume: { label: "Resume task", protected: true, password: false },
|
|
165
165
|
task_start: { label: "Start work", protected: true, password: false },
|
|
166
|
+
direct_chat_start: { label: "Start Direct Chat", protected: false, password: false },
|
|
167
|
+
direct_chat_reply: { label: "Send to Direct Chat", protected: false, password: false },
|
|
168
|
+
direct_chat_promote: { label: "Promote to Task", protected: false, password: false },
|
|
169
|
+
direct_chat_ship: { label: "Open Ship preview", protected: false, password: false },
|
|
166
170
|
};
|
|
167
171
|
const CREDENTIAL_ACTIONS = new Set(["tool_add", "flow_browser"]);
|
|
168
172
|
const SAME_ACTIONS = true;
|
|
@@ -302,7 +306,7 @@ export function prepareSharedAction(store, who, operation, input, root, now = ne
|
|
|
302
306
|
const stamp = hash({ operation, request, repo: "", state, terms, actor: who.name, generation: who.generation, ceiling: who.ceilingDigest });
|
|
303
307
|
return { version: SHARED_ACTION_VERSION, operation, request, repo: "", title, terms, stamp, state };
|
|
304
308
|
}
|
|
305
|
-
const task = operation === "mode_revoke" || operation === "memory_decide" || operation === "incident_resolve" || operation === "finding_resend" || operation.startsWith("code_map_") || operation.startsWith("skill_") || operation.startsWith("knowledge_") || operation.startsWith("decision_") || operation.startsWith("tool_") || operation.startsWith("flow_") || operation.startsWith("subagent_") || operation.startsWith("kit_") || operation.startsWith("sweep_") || operation.startsWith("suggestion_") || operation.startsWith("trial_") || operation === "task_start"
|
|
309
|
+
const task = operation === "mode_revoke" || operation === "memory_decide" || operation === "incident_resolve" || operation === "finding_resend" || operation.startsWith("code_map_") || operation.startsWith("skill_") || operation.startsWith("knowledge_") || operation.startsWith("decision_") || operation.startsWith("tool_") || operation.startsWith("flow_") || operation.startsWith("subagent_") || operation.startsWith("kit_") || operation.startsWith("sweep_") || operation.startsWith("suggestion_") || operation.startsWith("trial_") || operation === "task_start" || operation.startsWith("direct_chat_")
|
|
306
310
|
? null
|
|
307
311
|
: text(input, "task", 64);
|
|
308
312
|
const flowTarget = operation.startsWith("flow_") && operation !== "flow_create" && operation !== "flow_script_save" && operation !== "flow_starter" ? flowTargetOf(store, input) : null;
|
|
@@ -322,7 +326,63 @@ export function prepareSharedAction(store, who, operation, input, root, now = ne
|
|
|
322
326
|
requireActor(store, who, repo);
|
|
323
327
|
const request = structuredClone(input), terms = [];
|
|
324
328
|
let state, title = CHAT_ACTIONS[operation].label;
|
|
325
|
-
if (
|
|
329
|
+
if (operation.startsWith("direct_chat_")) {
|
|
330
|
+
if (operation === "direct_chat_start") {
|
|
331
|
+
const provider = text(input, "provider", 40);
|
|
332
|
+
const model = text(input, "model", 120);
|
|
333
|
+
const prompt = text(input, "prompt", 4000);
|
|
334
|
+
const effort = typeof input["effort"] === "string" ? input["effort"] : null;
|
|
335
|
+
if (scanForSecrets(prompt).length > 0)
|
|
336
|
+
throw Error("Direct Chat prompt cannot contain credentials.");
|
|
337
|
+
state = { repo };
|
|
338
|
+
title = `Start ${provider} Direct Chat`;
|
|
339
|
+
terms.push(`Agent: ${provider} · ${model}${effort ? ` (${effort} effort)` : ""}`, `Prompt: ${prompt.slice(0, 280)}${prompt.length > 280 ? "…" : ""}`, "Runs inside an isolated local clone with no remote until you press Ship.");
|
|
340
|
+
}
|
|
341
|
+
else if (operation === "direct_chat_reply") {
|
|
342
|
+
const chat = text(input, "chat", 80);
|
|
343
|
+
const prompt = text(input, "prompt", 4000);
|
|
344
|
+
if (scanForSecrets(prompt).length > 0)
|
|
345
|
+
throw Error("Direct Chat message cannot contain credentials.");
|
|
346
|
+
const row = store.handle.prepare("SELECT id, title, repo, provider, model_id FROM direct_chat_thread WHERE id = ? AND owner = ?").get(chat, who.name);
|
|
347
|
+
if (row === undefined || String(row["repo"]) !== repo)
|
|
348
|
+
throw Error("That Direct Chat is not available in this project.");
|
|
349
|
+
state = { chat, repo };
|
|
350
|
+
title = `Send to "${String(row["title"]).slice(0, 60)}"`;
|
|
351
|
+
terms.push(`Direct Chat: ${String(row["title"])} (${String(row["provider"])} · ${String(row["model_id"])})`, `Message: ${prompt.slice(0, 280)}${prompt.length > 280 ? "…" : ""}`);
|
|
352
|
+
}
|
|
353
|
+
else if (operation === "direct_chat_ship") {
|
|
354
|
+
const chat = text(input, "chat", 80);
|
|
355
|
+
const mode = input["mode"] === "keep-branch" ? "keep-branch" : "ship";
|
|
356
|
+
const row = store.handle.prepare("SELECT id, title, repo, branch, diff_cache_json FROM direct_chat_thread WHERE id = ? AND owner = ? AND archived_at IS NULL").get(chat, who.name);
|
|
357
|
+
if (row === undefined || String(row["repo"]) !== repo)
|
|
358
|
+
throw Error("That Direct Chat is not available in this project.");
|
|
359
|
+
let changedCount = 0;
|
|
360
|
+
try {
|
|
361
|
+
const parsed = typeof row["diff_cache_json"] === "string" ? JSON.parse(row["diff_cache_json"]) : null;
|
|
362
|
+
if (Array.isArray(parsed?.changedFiles))
|
|
363
|
+
changedCount = parsed.changedFiles.length;
|
|
364
|
+
}
|
|
365
|
+
catch { }
|
|
366
|
+
state = { chat, repo };
|
|
367
|
+
const chatTitle = String(row["title"] ?? "Direct Chat").slice(0, 60);
|
|
368
|
+
title = `Ship "${chatTitle}"`;
|
|
369
|
+
terms.push(`Direct Chat: ${chatTitle} (branch ${String(row["branch"] ?? "")})`, changedCount > 0 ? `Changes: ${changedCount} ${changedCount === 1 ? "file" : "files"} changed` : "Inspect current clone changes in the Ship preview.", mode === "keep-branch" ? "Mode: Keep branch on this Mac." : "Mode: Ship (runs project check before merging).", "Opens the Ship preview so you can review and confirm before anything is pushed or merged.");
|
|
370
|
+
}
|
|
371
|
+
else {
|
|
372
|
+
const chat = text(input, "chat", 80);
|
|
373
|
+
const taskTitle = text(input, "title", 200);
|
|
374
|
+
const goal = text(input, "goal", 8000);
|
|
375
|
+
if ([taskTitle, goal].some(s => scanForSecrets(s).length > 0))
|
|
376
|
+
throw Error("Task text cannot contain credentials.");
|
|
377
|
+
const row = store.handle.prepare("SELECT id, title, repo, branch FROM direct_chat_thread WHERE id = ? AND owner = ?").get(chat, who.name);
|
|
378
|
+
if (row === undefined || String(row["repo"]) !== repo)
|
|
379
|
+
throw Error("That Direct Chat is not available in this project.");
|
|
380
|
+
state = { chat, repo };
|
|
381
|
+
title = `Promote "${String(row["title"]).slice(0, 50)}" to Task`;
|
|
382
|
+
terms.push(`Task title: ${taskTitle}`, `Goal: ${goal.slice(0, 280)}${goal.length > 280 ? "…" : ""}`, `Source Direct Chat branch: ${String(row["branch"] ?? "")}`, "Files an ordinary task. Building still requires your approval.");
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
else if (PARITY_ACTIONS.has(operation)) {
|
|
326
386
|
const made = parityAction(store, who, operation, input, repo, flowTarget?.flow ?? null, now, request, root);
|
|
327
387
|
state = made.state;
|
|
328
388
|
title = made.title;
|
|
@@ -1208,6 +1268,45 @@ export function executeSharedAction(store, who, id, payload, now, options) {
|
|
|
1208
1268
|
return runLateApproval(store, who, payload, repo => approvalBy(store, who, repo, now, options, drafted), approvalRoad(options), now);
|
|
1209
1269
|
if (PARITY_ACTIONS.has(payload.operation) || OWNER_PARITY.has(payload.operation))
|
|
1210
1270
|
return runParityAction(store, who, payload, now, options.root);
|
|
1271
|
+
if (payload.operation === "direct_chat_promote") {
|
|
1272
|
+
const taskTitle = String(req["title"] ?? "").trim();
|
|
1273
|
+
const goal = String(req["goal"] ?? "").trim();
|
|
1274
|
+
const planning = req["planning"] === "required" || req["planning"] === "skip" ? req["planning"] : "auto";
|
|
1275
|
+
const filed = fileTaskProposal(store, {
|
|
1276
|
+
title: taskTitle,
|
|
1277
|
+
repo,
|
|
1278
|
+
goal,
|
|
1279
|
+
outOfScope: null,
|
|
1280
|
+
touches: [],
|
|
1281
|
+
acceptance: [{ id: "c1", statement: taskTitle, evidence: ["manual-review"] }],
|
|
1282
|
+
planning,
|
|
1283
|
+
filedVia: "mate",
|
|
1284
|
+
filedBy: { name: actor, kind: "person" },
|
|
1285
|
+
proposedVia: "mate",
|
|
1286
|
+
admittedRepos: [...who.repos],
|
|
1287
|
+
}, now);
|
|
1288
|
+
if (!filed.ok)
|
|
1289
|
+
throw Error(`Not filed: ${filed.message}`);
|
|
1290
|
+
return {
|
|
1291
|
+
ok: true,
|
|
1292
|
+
taskId: filed.id,
|
|
1293
|
+
said: `Promoted Direct Chat to task ${filed.id}. Review and approve its plan to start.`,
|
|
1294
|
+
href: `/tasks/${encodeURIComponent(filed.id)}`,
|
|
1295
|
+
};
|
|
1296
|
+
}
|
|
1297
|
+
if (payload.operation === "direct_chat_start") {
|
|
1298
|
+
return { ok: true, taskId: null, said: "Direct Chat confirmed." };
|
|
1299
|
+
}
|
|
1300
|
+
if (payload.operation === "direct_chat_reply") {
|
|
1301
|
+
const chatId = String(req["chat"] ?? "");
|
|
1302
|
+
return { ok: true, taskId: null, said: "Message queued for Direct Chat.", href: `/direct-chats/${encodeURIComponent(chatId)}` };
|
|
1303
|
+
}
|
|
1304
|
+
if (payload.operation === "direct_chat_ship") {
|
|
1305
|
+
const chatId = String(req["chat"] ?? "");
|
|
1306
|
+
const row = store.handle.prepare("SELECT title FROM direct_chat_thread WHERE id = ? AND owner = ?").get(chatId, actor);
|
|
1307
|
+
const label = typeof row?.["title"] === "string" && row["title"].trim() !== "" ? row["title"].trim() : "Direct Chat";
|
|
1308
|
+
return { ok: true, taskId: null, said: `Ready to ship "${label}". Review and confirm in the Ship sheet.`, href: `/direct-chats/${encodeURIComponent(chatId)}/ship` };
|
|
1309
|
+
}
|
|
1211
1310
|
if (payload.operation === "lead_about_you") {
|
|
1212
1311
|
const next = withAboutYouLine(aboutYouOf(store, actor), String(req["line"]), Number(req["replaces"] ?? 0));
|
|
1213
1312
|
if (!next.ok)
|
package/dist/chat-channel.js
CHANGED
|
@@ -681,6 +681,46 @@ export const CHAT_ACTION_PARITY = {
|
|
|
681
681
|
how: "Refused on the phone by design: the workbench's look is the person's own conversation in the console on this computer (view-tools.ts); the tool answers in words and nothing is read or written.",
|
|
682
682
|
gap: "No phone path by design: restyle from the console on this computer, or edit tui.toml.",
|
|
683
683
|
},
|
|
684
|
+
list_direct_chats: {
|
|
685
|
+
support: "direct",
|
|
686
|
+
how: "Read during a turn: lists active Direct Chat threads in admitted projects with model, effort, status, and token usage.",
|
|
687
|
+
gap: null,
|
|
688
|
+
},
|
|
689
|
+
get_direct_chat: {
|
|
690
|
+
support: "direct",
|
|
691
|
+
how: "Read during a turn: reads one Direct Chat's full turn transcript, tool history, and token usage from SQLite.",
|
|
692
|
+
gap: null,
|
|
693
|
+
},
|
|
694
|
+
get_direct_chat_diff: {
|
|
695
|
+
support: "direct",
|
|
696
|
+
how: "Read during a turn: inspects a Direct Chat's changed files, bounded patch, and Ship readiness.",
|
|
697
|
+
gap: null,
|
|
698
|
+
},
|
|
699
|
+
manage_direct_chat: {
|
|
700
|
+
support: "missing",
|
|
701
|
+
how: "Refused on the phone by design: instant Direct Chat controls require the owner's local solo console session on this computer.",
|
|
702
|
+
gap: "No phone path by design: stop, rename, switch model, or archive Direct Chats from the local Mac app or console.",
|
|
703
|
+
},
|
|
704
|
+
get_usage_limits: {
|
|
705
|
+
support: "direct",
|
|
706
|
+
how: "Read during a turn: reports live Claude, Codex, and Gemini subscription windows and monthly spend budgets.",
|
|
707
|
+
gap: null,
|
|
708
|
+
},
|
|
709
|
+
get_recent_updates: {
|
|
710
|
+
support: "direct",
|
|
711
|
+
how: "Read during a turn: aggregates Ready results, completions, failures, updated Direct Chats, open decisions, and recent actions.",
|
|
712
|
+
gap: null,
|
|
713
|
+
},
|
|
714
|
+
propose_direct_chat: {
|
|
715
|
+
support: "handoff",
|
|
716
|
+
how: "Drafts a confirmation card to start, reply to, or promote a Direct Chat; promote files a Task on confirm while start and reply execute only on the local solo console.",
|
|
717
|
+
gap: "Incomplete phone action: starting or replying to a local Direct Chat clone runs in the local console or Mac app.",
|
|
718
|
+
},
|
|
719
|
+
propose_report_followups: {
|
|
720
|
+
support: "direct",
|
|
721
|
+
how: "Batch-drafts standard Task confirmation cards from a verified Scout Report's follow-up recommendations through the shared door.",
|
|
722
|
+
gap: null,
|
|
723
|
+
},
|
|
684
724
|
};
|
|
685
725
|
export function parityGaps() {
|
|
686
726
|
return LEAD_TOOL_SCHEMAS.map((tool) => tool.name).filter((name) => CHAT_ACTION_PARITY[name] === undefined);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CHECK_RECOVERY_HELD, readCheckRecoveryHoldsForRun } from "./check-recovery-hold.js";
|
|
1
2
|
import { authorityStandsSql } from "./approval-authority.js";
|
|
2
3
|
import { checkAccessOf } from "./check-access.js";
|
|
3
4
|
import { refArchived } from "./task-archive.js";
|
|
@@ -13,6 +14,9 @@ export function approvedScopeStands(store, taskRef, scopeDigest, now) {
|
|
|
13
14
|
AND ${authorityStandsSql("task_scope", "task_ref.repo", "?")}`).get(taskRef, scopeDigest, stamp, stamp, stamp, stamp) !== undefined;
|
|
14
15
|
}
|
|
15
16
|
export function authorizationProblem(store, auth, input, now) {
|
|
17
|
+
const held = checkOnlyRecoveryProblem(store, auth.run);
|
|
18
|
+
if (held !== null)
|
|
19
|
+
return held;
|
|
16
20
|
if (auth.candidate !== input.head)
|
|
17
21
|
return "The commit changed.";
|
|
18
22
|
if (auth.commandDigest !== input.digest)
|
|
@@ -24,6 +28,9 @@ export function authorizationProblem(store, auth, input, now) {
|
|
|
24
28
|
return null;
|
|
25
29
|
}
|
|
26
30
|
export function recheckStanding(store, input) {
|
|
31
|
+
const held = checkOnlyRecoveryProblem(store, input.runId);
|
|
32
|
+
if (held !== null)
|
|
33
|
+
return { ok: false, problem: held };
|
|
27
34
|
const row = store.handle.prepare("SELECT * FROM check_authorization WHERE used_request = ? AND run = ?").get(input.request, input.runId);
|
|
28
35
|
if (row === undefined)
|
|
29
36
|
return { ok: false, problem: "Its authorization couldn't be read." };
|
|
@@ -31,3 +38,9 @@ export function recheckStanding(store, input) {
|
|
|
31
38
|
const problem = authorizationProblem(store, auth, input, new Date());
|
|
32
39
|
return problem === null ? { ok: true, access: auth.access } : { ok: false, problem };
|
|
33
40
|
}
|
|
41
|
+
export function checkOnlyRecoveryProblem(store, runId) {
|
|
42
|
+
if (store.handle.prepare("SELECT 1 FROM action_ledger WHERE action = ? LIMIT 1").get(CHECK_RECOVERY_HELD) === undefined)
|
|
43
|
+
return null;
|
|
44
|
+
const evidence = readCheckRecoveryHoldsForRun(store, runId);
|
|
45
|
+
return evidence.kind === "no-evidence" ? null : "Checks are on hold after recovery. Earlier execution is unverified.";
|
|
46
|
+
}
|
package/dist/check-only.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { assignmentChecksForRun } from "./assignment.js";
|
|
2
2
|
import { runCheckLevel, repoOfRun, checkCommandFor } from "./check-levels.js";
|
|
3
|
-
import { approvedScopeStands, authorizationProblem, readAuthorization } from "./check-only-standing.js";
|
|
3
|
+
import { approvedScopeStands, authorizationProblem, readAuthorization, checkOnlyRecoveryProblem } from "./check-only-standing.js";
|
|
4
4
|
import { requestFollowUpChecks } from "./result-follow-ups.js";
|
|
5
5
|
import { releaseCheckScope } from "./scope.js";
|
|
6
6
|
import { refArchived } from "./task-archive.js";
|
|
@@ -9,6 +9,8 @@ export const CHECK_ONLY_WINDOW_MS = 24 * 60 * 60_000;
|
|
|
9
9
|
export const RECHECK_ACTOR = "Toolroll";
|
|
10
10
|
export function authorizeCheckOnly(store, runId, now) {
|
|
11
11
|
return store.transact(() => {
|
|
12
|
+
if (checkOnlyRecoveryProblem(store, runId) !== null)
|
|
13
|
+
return null;
|
|
12
14
|
const run = store.getRun(runId);
|
|
13
15
|
if (run === null || run.role !== "builder" || run.outcome !== "built" || run.headRevision === null || !/^[a-f0-9]{40}$/.test(run.headRevision))
|
|
14
16
|
return null;
|
|
@@ -40,6 +42,8 @@ export function claimRecheck(store, authorization, now) {
|
|
|
40
42
|
if (row === undefined)
|
|
41
43
|
return null;
|
|
42
44
|
const auth = readAuthorization(row);
|
|
45
|
+
if (checkOnlyRecoveryProblem(store, auth.run) !== null)
|
|
46
|
+
return null;
|
|
43
47
|
const run = store.getRun(auth.run);
|
|
44
48
|
const repo = repoOfRun(store, auth.run);
|
|
45
49
|
if (run === null || repo === null || store.lastBuilderRun(auth.taskRef)?.id !== auth.run || store.hasLiveClaim(auth.taskRef, now))
|
|
@@ -50,6 +54,8 @@ export function claimRecheck(store, authorization, now) {
|
|
|
50
54
|
const asked = requestFollowUpChecks(store, { runId: auth.run, level: auth.level, actor: RECHECK_ACTOR, why: "recheck" }, now);
|
|
51
55
|
if (!asked.ok || asked.existing)
|
|
52
56
|
return null;
|
|
57
|
+
if (checkOnlyRecoveryProblem(store, auth.run) !== null)
|
|
58
|
+
return null;
|
|
53
59
|
const spent = store.handle.prepare("UPDATE check_authorization SET used_at = ?, used_request = ? WHERE id = ? AND used_at IS NULL").run(now.toISOString(), asked.request, auth.id);
|
|
54
60
|
if (Number(spent.changes) !== 1)
|
|
55
61
|
throw new Error("the recheck's authorization moved inside its own transaction");
|
|
@@ -60,18 +66,24 @@ export function requestMissingRechecks(store, root, now) {
|
|
|
60
66
|
const open = store.handle.prepare("SELECT * FROM check_authorization WHERE used_at IS NULL AND closed_at IS NULL AND expires_at > ? ORDER BY id").all(now.toISOString());
|
|
61
67
|
let asked = 0;
|
|
62
68
|
for (const row of open) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
69
|
+
asked += store.transact(() => {
|
|
70
|
+
const current = store.handle.prepare("SELECT * FROM check_authorization WHERE id = ? AND used_at IS NULL AND closed_at IS NULL AND expires_at > ?").get(row["id"], now.toISOString());
|
|
71
|
+
if (current === undefined)
|
|
72
|
+
return 0;
|
|
73
|
+
const auth = readAuthorization(current);
|
|
74
|
+
if (checkOnlyRecoveryProblem(store, auth.run) !== null)
|
|
75
|
+
return 0;
|
|
76
|
+
const run = store.getRun(auth.run);
|
|
77
|
+
if (run === null || run.finishedAt === null)
|
|
78
|
+
return 0;
|
|
79
|
+
const state = approvedCheckStateOf(assignmentChecksForRun(store, root, auth.run, now));
|
|
80
|
+
if (state === "not-run" || state === "unreadable")
|
|
81
|
+
return claimRecheck(store, auth.id, now) === null ? 0 : 1;
|
|
82
|
+
if (state !== "running" && checkOnlyRecoveryProblem(store, auth.run) === null) {
|
|
83
|
+
store.handle.prepare("UPDATE check_authorization SET closed_at = ? WHERE id = ? AND used_at IS NULL AND closed_at IS NULL").run(now.toISOString(), auth.id);
|
|
84
|
+
}
|
|
85
|
+
return 0;
|
|
86
|
+
});
|
|
75
87
|
}
|
|
76
88
|
return asked;
|
|
77
89
|
}
|