toolroll 0.9.109 → 0.9.110
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 +35 -0
- package/dist/agent-detect.js +244 -0
- package/dist/agent-fence.js +12 -1
- package/dist/agentconfig.js +2 -2
- package/dist/approval-summary.js +344 -0
- package/dist/attest.js +2 -2
- package/dist/browser/workspace.css +2 -2
- package/dist/browser/workspace.js +27 -27
- package/dist/builder.js +36 -2
- package/dist/chat-actions.js +24 -17
- package/dist/chat-core.js +3 -1
- package/dist/chat-decide.js +101 -46
- package/dist/chat-delivery-state.js +2 -0
- package/dist/chat-delivery.js +3 -2
- package/dist/chat-live.js +2 -1
- package/dist/chat-task-actions.js +6 -0
- package/dist/check-report.js +1 -1
- package/dist/cli.js +2 -0
- package/dist/console-instance.js +10 -1
- package/dist/contracts/console-api.js +10 -5
- package/dist/contracts/engine-api.js +271 -0
- package/dist/coordinator.js +2 -2
- package/dist/discord-api.js +4 -3
- package/dist/discord-chat.js +3 -1
- package/dist/easy-start-args.js +7 -3
- package/dist/easy-start.js +25 -0
- package/dist/egress.js +72 -10
- package/dist/engine-handoff.js +34 -0
- package/dist/engine-reads.js +261 -0
- package/dist/eval-world.js +3 -2
- package/dist/evidence.js +2 -0
- package/dist/fast-start.js +55 -14
- package/dist/fast-terms.js +2 -2
- package/dist/first-run.js +10 -2
- package/dist/flexible-agents.js +234 -0
- package/dist/flexible-answers-schema.js +61 -0
- package/dist/flexible-answers.js +889 -0
- package/dist/flexible-custody.js +494 -0
- package/dist/flexible-import.js +782 -0
- package/dist/flexible-launch-schema.js +72 -0
- package/dist/flexible-launch.js +331 -0
- package/dist/flexible-launcher.js +88 -0
- package/dist/flexible-levels.js +34 -0
- package/dist/flexible-merge-guard.js +47 -0
- package/dist/flexible-refs.js +47 -0
- package/dist/flexible-relay-cancel.js +19 -0
- package/dist/flexible-relay-schema.js +55 -0
- package/dist/flexible-relay-upstreams.js +36 -0
- package/dist/flexible-relay.js +1032 -0
- package/dist/flexible-session.js +732 -0
- package/dist/flexible-ship-schema.js +81 -0
- package/dist/flexible-ship.js +694 -0
- package/dist/flexible-start.js +80 -0
- package/dist/flexible-thread.js +175 -25
- package/dist/flexible-turns-schema.js +69 -0
- package/dist/flexible-turns.js +490 -0
- package/dist/flexible.js +10 -1
- package/dist/flow-actions.js +6 -4
- package/dist/flow-steps.js +1 -1
- package/dist/flows-cli.js +2 -1
- package/dist/git-views.js +6 -3
- package/dist/install-mode.js +225 -0
- package/dist/lead-doors.js +7 -1
- package/dist/limits-ui.js +7 -0
- package/dist/live-reply.js +6 -0
- package/dist/live-terminal.js +425 -29
- package/dist/local-owner.js +6 -0
- package/dist/model-choices.js +12 -6
- package/dist/notification-delivery.js +11 -0
- package/dist/operate.js +74 -30
- package/dist/outbound-privacy.js +204 -0
- package/dist/passwordless.js +2 -1
- package/dist/project-delete.js +14 -0
- package/dist/provider-connection.js +5 -3
- package/dist/publish.js +5 -0
- package/dist/pull-request-flow.js +26 -7
- package/dist/push.js +5 -1
- package/dist/release-card.js +11 -3
- package/dist/release.js +10 -1
- package/dist/route-store.js +2 -2
- package/dist/sandbox-launch.js +32 -8
- package/dist/sandbox-runtime.js +16 -7
- package/dist/sandbox-tools.js +176 -0
- package/dist/scope.js +12 -36
- package/dist/scout-net.js +7 -2
- package/dist/serve.js +58 -11
- package/dist/server/chrome.js +3 -1
- package/dist/server/console.css +33 -6
- package/dist/server/engine-api.js +378 -0
- package/dist/server/flows.js +2 -2
- package/dist/server/http.js +7 -0
- package/dist/server/link-redemption.js +52 -0
- package/dist/server/mutation-key.js +21 -7
- package/dist/server/pages.js +69 -40
- package/dist/server/people-tokens.js +17 -41
- package/dist/server/render-chat.js +1 -0
- package/dist/server/render-new-task.js +3 -3
- package/dist/server/render-results.js +4 -4
- package/dist/server/render-tasks.js +129 -138
- package/dist/server/route-table.js +30 -1
- package/dist/server/settings-section-table.js +3 -0
- package/dist/server/settings-sections.js +33 -0
- package/dist/server/settings.js +84 -10
- package/dist/server/task-views.js +8 -2
- package/dist/server/tasks.js +25 -8
- package/dist/server/terminals.js +181 -28
- package/dist/server/welcome.js +35 -10
- package/dist/settings-groups-ui.js +2 -2
- package/dist/settings-proofs.js +13 -9
- package/dist/slack-api.js +4 -3
- package/dist/slack-chat.js +5 -3
- package/dist/spend.js +46 -12
- package/dist/status-probe.js +343 -0
- package/dist/store.js +102 -5
- package/dist/teams-api.js +4 -3
- package/dist/teams-chat.js +4 -2
- package/dist/telegram-lead.js +2 -1
- package/dist/telegram-live.js +2 -1
- package/dist/telegram-team.js +2 -1
- package/dist/telegram.js +17 -5
- package/dist/trusted-path.js +162 -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-launch.js +282 -0
- package/dist/tui-source.js +5 -3
- package/dist/tui.js +1 -1
- package/dist/webhooks.js +8 -4
- package/dist/welcome-facts.js +22 -15
- package/dist/workspace-ui.js +5 -0
- package/package.json +1 -1
- package/scripts/crash-canary.mjs +1 -1
- package/scripts/pilot.mjs +1 -1
- package/scripts/provider-canary.mjs +5 -3
package/dist/spend.js
CHANGED
|
@@ -55,14 +55,14 @@ export function ceilingPriceFor(db, provider) {
|
|
|
55
55
|
return row === undefined || row["input_usd"] == null || row["output_usd"] == null ? null
|
|
56
56
|
: { inputUsd: Number(row["input_usd"]), outputUsd: Number(row["output_usd"]), model: "highest listed price" };
|
|
57
57
|
}
|
|
58
|
-
export function priceWork(db, work) {
|
|
58
|
+
export function priceWork(db, work, lookup = (provider, model) => priceFor(db, provider, model) ?? ceilingPriceFor(db, provider)) {
|
|
59
59
|
if (work.billing === "subscription")
|
|
60
60
|
return { microusd: 0, source: "subscription", price: null };
|
|
61
61
|
if (work.costUsd !== null && Number.isFinite(work.costUsd))
|
|
62
62
|
return { microusd: Math.round(work.costUsd * 1_000_000), source: "reported", price: null };
|
|
63
63
|
if (work.tokensIn === null && work.tokensOut === null)
|
|
64
64
|
return { microusd: null, source: "unpriced", price: null };
|
|
65
|
-
const price =
|
|
65
|
+
const price = lookup(work.provider, work.model);
|
|
66
66
|
if (price === null)
|
|
67
67
|
return { microusd: null, source: "unpriced", price: null };
|
|
68
68
|
return { microusd: Math.round((work.tokensIn ?? 0) * price.inputUsd + (work.tokensOut ?? 0) * price.outputUsd), source: "estimated", price };
|
|
@@ -172,12 +172,33 @@ export function filersOf(db) {
|
|
|
172
172
|
return found;
|
|
173
173
|
};
|
|
174
174
|
}
|
|
175
|
-
export function spendItems(db, from, to,
|
|
176
|
-
const
|
|
175
|
+
export function spendItems(db, from, to, readMode = provider => billingOf(provider, db)) {
|
|
176
|
+
const modes = new Map();
|
|
177
|
+
const modeOf = (provider) => { let mode = modes.get(provider); if (mode === undefined) {
|
|
178
|
+
mode = readMode(provider);
|
|
179
|
+
modes.set(provider, mode);
|
|
180
|
+
} return mode; };
|
|
181
|
+
const prices = new Map();
|
|
182
|
+
const lookup = (provider, model) => {
|
|
183
|
+
const key = `${provider}\n${model ?? ""}`;
|
|
184
|
+
if (!prices.has(key))
|
|
185
|
+
prices.set(key, priceFor(db, provider, model) ?? ceilingPriceFor(db, provider));
|
|
186
|
+
return prices.get(key);
|
|
187
|
+
};
|
|
188
|
+
const has = db.prepare(`SELECT EXISTS(SELECT 1 FROM run WHERE started_at >= ?1 AND started_at < ?2) AS runs,
|
|
189
|
+
EXISTS(SELECT 1 FROM subagent_turn WHERE at >= ?1 AND at < ?2) AS subagent,
|
|
190
|
+
(EXISTS(SELECT 1 FROM chat_turn WHERE created_at >= ?1 AND created_at < ?2) OR EXISTS(SELECT 1 FROM mate_turn WHERE created_at >= ?1 AND created_at < ?2)) AS chat,
|
|
191
|
+
EXISTS(SELECT 1 FROM side_spend WHERE at >= ?1 AND at < ?2) AS side,
|
|
192
|
+
EXISTS(SELECT 1 FROM flow_step_run WHERE kind = 'sort' AND started_at >= ?1 AND started_at < ?2) AS sort,
|
|
193
|
+
EXISTS(SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'thread_turn') AS threads,
|
|
194
|
+
EXISTS(SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'thread_relay_pending') AS reservations`).get(from, to) ?? {};
|
|
195
|
+
const any = (key) => Number(has[key]) === 1;
|
|
196
|
+
let filers = null;
|
|
197
|
+
const subagentOf = (repo, filedBy, kind) => (filers ??= subagentFilers(db))(repo, filedBy, kind);
|
|
177
198
|
const filerOf = filersOf(db);
|
|
178
199
|
const text = (value) => value == null ? null : String(value);
|
|
179
200
|
const count = (value) => value == null ? null : Number(value);
|
|
180
|
-
const runs = db.prepare(`SELECT run.id, run.task_ref, run.provider, run.model, run.cost_usd, run.tokens_in, run.tokens_out, run.started_at, run.auth_mode,
|
|
201
|
+
const runs = !any("runs") ? [] : db.prepare(`SELECT run.id, run.task_ref, run.provider, run.model, run.cost_usd, run.tokens_in, run.tokens_out, run.started_at, run.auth_mode,
|
|
181
202
|
r.external_id AS task, r.repo, r.filed_by, r.filed_by_kind, r.revision_of, s.microusd, s.source, s.billing
|
|
182
203
|
FROM run JOIN task_ref r ON r.id = run.task_ref LEFT JOIN run_spend s ON s.run = run.id
|
|
183
204
|
WHERE run.started_at >= ? AND run.started_at < ? ORDER BY run.id`).all(from, to);
|
|
@@ -186,7 +207,7 @@ export function spendItems(db, from, to, modeOf = provider => billingOf(provider
|
|
|
186
207
|
const billing = row["billing"] === "subscription" || row["billing"] === "api-key" ? row["billing"]
|
|
187
208
|
: row["auth_mode"] === "subscription" || row["auth_mode"] === "api-key" ? row["auth_mode"] : modeOf(provider);
|
|
188
209
|
const settled = row["source"] != null;
|
|
189
|
-
const priced = settled ? null : priceWork(db, { provider, model: text(row["model"]), costUsd: count(row["cost_usd"]), tokensIn: count(row["tokens_in"]), tokensOut: count(row["tokens_out"]), billing });
|
|
210
|
+
const priced = settled ? null : priceWork(db, { provider, model: text(row["model"]), costUsd: count(row["cost_usd"]), tokensIn: count(row["tokens_in"]), tokensOut: count(row["tokens_out"]), billing }, lookup);
|
|
190
211
|
const filer = row["filed_by"] == null && row["revision_of"] != null ? filerOf(Number(row["task_ref"]))
|
|
191
212
|
: { repo: text(row["repo"]), filedBy: text(row["filed_by"]), kind: text(row["filed_by_kind"]) };
|
|
192
213
|
const kind = filer.kind;
|
|
@@ -200,15 +221,15 @@ export function spendItems(db, from, to, modeOf = provider => billingOf(provider
|
|
|
200
221
|
taskId: String(row["task"]), runId: Number(row["id"]), authMode: billing,
|
|
201
222
|
};
|
|
202
223
|
});
|
|
203
|
-
for (const row of db.prepare(`SELECT t.at, t.subagent, t.model, t.cost_usd, t.tokens_in, t.tokens_out, t.billing, m.repo FROM subagent_turn t JOIN subagent m ON m.id = t.subagent
|
|
224
|
+
for (const row of !any("subagent") ? [] : db.prepare(`SELECT t.at, t.subagent, t.model, t.cost_usd, t.tokens_in, t.tokens_out, t.billing, m.repo FROM subagent_turn t JOIN subagent m ON m.id = t.subagent
|
|
204
225
|
WHERE t.at >= ? AND t.at < ? ORDER BY t.id`).all(from, to)) {
|
|
205
226
|
const billing = row["billing"] === "api-key" ? "api-key" : "subscription";
|
|
206
|
-
const priced = priceWork(db, { provider: "claude", model: text(row["model"]), costUsd: count(row["cost_usd"]), tokensIn: count(row["tokens_in"]), tokensOut: count(row["tokens_out"]), billing });
|
|
227
|
+
const priced = priceWork(db, { provider: "claude", model: text(row["model"]), costUsd: count(row["cost_usd"]), tokensIn: count(row["tokens_in"]), tokensOut: count(row["tokens_out"]), billing }, lookup);
|
|
207
228
|
items.push({ at: String(row["at"]), kind: "subagent", microusd: priced.microusd, source: priced.source, project: String(row["repo"]), person: null,
|
|
208
229
|
subagent: Number(row["subagent"]), provider: "claude", model: text(row["model"]),
|
|
209
230
|
tokensIn: count(row["tokens_in"]), tokensOut: count(row["tokens_out"]), taskId: null, runId: null, authMode: billing });
|
|
210
231
|
}
|
|
211
|
-
for (const row of db.prepare(`SELECT created_at AS at, approver, provider, model, settled_microusd, tokens_in, tokens_out, NULL AS project
|
|
232
|
+
for (const row of !any("chat") ? [] : db.prepare(`SELECT created_at AS at, approver, provider, model, settled_microusd, tokens_in, tokens_out, NULL AS project
|
|
212
233
|
FROM chat_turn WHERE mate_turn IS NULL AND created_at >= ? AND created_at < ?
|
|
213
234
|
UNION ALL SELECT t.created_at, t.approver, COALESCE((SELECT c.provider FROM chat_turn c WHERE c.mate_turn = t.id ORDER BY c.id LIMIT 1), 'lead'),
|
|
214
235
|
(SELECT c.model FROM chat_turn c WHERE c.mate_turn = t.id ORDER BY c.id LIMIT 1), t.settled_microusd, t.tokens_in, t.tokens_out,
|
|
@@ -221,19 +242,32 @@ export function spendItems(db, from, to, modeOf = provider => billingOf(provider
|
|
|
221
242
|
project: text(row["project"]), person: text(row["approver"]), subagent: null, provider, model: text(row["model"]),
|
|
222
243
|
tokensIn: count(row["tokens_in"]), tokensOut: count(row["tokens_out"]), taskId: null, runId: null, authMode: subscription ? "subscription" : "api-key" });
|
|
223
244
|
}
|
|
224
|
-
for (const row of db.prepare("SELECT at, kind, repo, provider, model, cost_usd, billing FROM side_spend WHERE at >= ? AND at < ? ORDER BY id").all(from, to)) {
|
|
245
|
+
for (const row of !any("side") ? [] : db.prepare("SELECT at, kind, repo, provider, model, cost_usd, billing FROM side_spend WHERE at >= ? AND at < ? ORDER BY id").all(from, to)) {
|
|
225
246
|
const billing = row["billing"] === "api-key" ? "api-key" : "subscription";
|
|
226
|
-
const priced = priceWork(db, { provider: String(row["provider"]), model: text(row["model"]), costUsd: count(row["cost_usd"]), tokensIn: null, tokensOut: null, billing });
|
|
247
|
+
const priced = priceWork(db, { provider: String(row["provider"]), model: text(row["model"]), costUsd: count(row["cost_usd"]), tokensIn: null, tokensOut: null, billing }, lookup);
|
|
227
248
|
items.push({ at: String(row["at"]), kind: "draft", microusd: priced.microusd, source: priced.source, project: text(row["repo"]), person: null, subagent: null,
|
|
228
249
|
provider: String(row["provider"]), model: text(row["model"]), tokensIn: null, tokensOut: null, taskId: null, runId: null, authMode: billing });
|
|
229
250
|
}
|
|
230
|
-
for (const row of db.prepare(`SELECT fs.started_at AS at, json_extract(fs.decision_json, '$.cost') AS cost, json_extract(fs.decision_json, '$.model') AS model, f.repo
|
|
251
|
+
for (const row of !any("sort") ? [] : db.prepare(`SELECT fs.started_at AS at, json_extract(fs.decision_json, '$.cost') AS cost, json_extract(fs.decision_json, '$.model') AS model, f.repo
|
|
231
252
|
FROM flow_step_run fs JOIN flow_card c ON c.id = fs.card JOIN flow f ON f.id = c.flow
|
|
232
253
|
WHERE fs.kind = 'sort' AND fs.decision_json IS NOT NULL AND fs.started_at >= ? AND fs.started_at < ? ORDER BY fs.started_at`).all(from, to)) {
|
|
233
254
|
const cost = typeof row["cost"] === "number" && Number.isFinite(row["cost"]) && row["cost"] >= 0 ? row["cost"] : null;
|
|
234
255
|
items.push({ at: String(row["at"]), kind: "sort", microusd: cost === null ? null : Math.round(cost * 1_000_000), source: cost === null ? "unpriced" : "reported",
|
|
235
256
|
project: text(row["repo"]), person: null, subagent: null, provider: "openrouter", model: text(row["model"]), tokensIn: null, tokensOut: null, taskId: null, runId: null, authMode: "api-key" });
|
|
236
257
|
}
|
|
258
|
+
if (any("threads")) {
|
|
259
|
+
const reservations = any("reservations");
|
|
260
|
+
for (const row of db.prepare(`SELECT COALESCE(started_at, admitted_at) AS at, repo, owner, provider, model, billing, status, cost_basis, cost_microusd, tokens_in, tokens_out,
|
|
261
|
+
${reservations ? "(status IN ('finished', 'interrupted', 'unknown') AND id IN (SELECT turn FROM thread_relay_pending))" : "0"} AS unsettled
|
|
262
|
+
FROM thread_turn WHERE status <> 'withdrawn' AND COALESCE(started_at, admitted_at) >= ? AND COALESCE(started_at, admitted_at) < ? ORDER BY admitted_at, id`).all(from, to)) {
|
|
263
|
+
const billing = row["billing"] === "subscription" ? "subscription" : "api-key";
|
|
264
|
+
const blind = billing === "api-key" && (row["cost_basis"] === "unknown" || Number(row["unsettled"]) === 1);
|
|
265
|
+
items.push({ at: String(row["at"]), kind: "flexible", microusd: billing === "subscription" ? 0 : blind ? null : Number(row["cost_microusd"]),
|
|
266
|
+
source: billing === "subscription" ? "subscription" : blind ? "unpriced" : row["cost_basis"] === "measured" ? "reported" : "estimated",
|
|
267
|
+
project: String(row["repo"]), person: String(row["owner"]), subagent: null, provider: String(row["provider"]), model: text(row["model"]),
|
|
268
|
+
tokensIn: count(row["tokens_in"]), tokensOut: count(row["tokens_out"]), taskId: null, runId: null, authMode: billing });
|
|
269
|
+
}
|
|
270
|
+
}
|
|
237
271
|
return items;
|
|
238
272
|
}
|
|
239
273
|
export function countsToward(item, budget) {
|
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { accessSync, closeSync, constants, existsSync, lstatSync, mkdtempSync, openSync, readSync, realpathSync, rmSync } from "node:fs";
|
|
3
|
+
import { homedir, tmpdir } from "node:os";
|
|
4
|
+
import { delimiter, dirname, isAbsolute, join, resolve, sep } from "node:path";
|
|
5
|
+
import { boundedAcl, trustedBinary, trustedFolders } from "./trusted-path.js";
|
|
6
|
+
export const STATUS_TIMEOUT_MS = 800;
|
|
7
|
+
export const BACKGROUND_STATUS_TIMEOUT_MS = 3_000;
|
|
8
|
+
const KILL_GRACE_MS = 250;
|
|
9
|
+
const STATUS_MAX_BUFFER = 32 * 1024;
|
|
10
|
+
export const STATUS_ENV_NAMES = ["USER", "LOGNAME", "LANG", "LC_ALL", "LC_CTYPE", "TZ"];
|
|
11
|
+
export const STATUS_LOCATION_NAMES = ["HOME", "TMPDIR", "CLAUDE_CONFIG_DIR", "CODEX_HOME"];
|
|
12
|
+
const inside = (path, root) => path === root || path.startsWith(root.endsWith(sep) ? root : `${root}${sep}`);
|
|
13
|
+
const realOrNull = (path) => { try {
|
|
14
|
+
return realpathSync(path);
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return null;
|
|
18
|
+
} };
|
|
19
|
+
const NOT_FOUND = { code: 127, stdout: "", stderr: "", timedOut: false, notFound: true };
|
|
20
|
+
const REFUSED = { code: 126, stdout: "", stderr: "", timedOut: false, notFound: false };
|
|
21
|
+
export function repositoryOf(dir) {
|
|
22
|
+
let at = realOrNull(dir);
|
|
23
|
+
while (at !== null) {
|
|
24
|
+
if (existsSync(join(at, ".git")))
|
|
25
|
+
return at;
|
|
26
|
+
const up = dirname(at);
|
|
27
|
+
if (up === at)
|
|
28
|
+
return null;
|
|
29
|
+
at = up;
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
export async function excludedFolders(source, extra = []) {
|
|
34
|
+
const { databasePath, openStoreReadOnly } = await import("./store.js");
|
|
35
|
+
const file = source.store?.databaseFile() ?? source.databaseFile ?? databasePath(process.env, homedir());
|
|
36
|
+
const found = [...extra];
|
|
37
|
+
let store = source.store ?? null;
|
|
38
|
+
let opened = null;
|
|
39
|
+
if (file !== null && file !== ":memory:") {
|
|
40
|
+
found.push(dirname(file));
|
|
41
|
+
const { readProjectRegistryNow } = await import("./repos.js");
|
|
42
|
+
const registry = readProjectRegistryNow(join(dirname(file), "repos.json"));
|
|
43
|
+
if ("error" in registry)
|
|
44
|
+
return null;
|
|
45
|
+
found.push(...registry.repos);
|
|
46
|
+
if (store === null && existsSync(file)) {
|
|
47
|
+
opened = openStoreReadOnly(file);
|
|
48
|
+
if (opened === null)
|
|
49
|
+
return null;
|
|
50
|
+
store = opened;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
if (store !== null)
|
|
55
|
+
found.push(...store.knownRepos(), ...store.listProjects().map(one => one.path), ...store.listWorktrees().map(one => one.path));
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
finally {
|
|
61
|
+
opened?.close();
|
|
62
|
+
}
|
|
63
|
+
const repo = repositoryOf(process.cwd());
|
|
64
|
+
if (repo !== null)
|
|
65
|
+
found.push(repo);
|
|
66
|
+
return [...new Set(found.flatMap(one => { const real = realOrNull(one); return isAbsolute(one) ? [resolve(one), ...(real === null ? [] : [real])] : real === null ? [] : [real]; }))];
|
|
67
|
+
}
|
|
68
|
+
function isScript(file) {
|
|
69
|
+
let fd = null;
|
|
70
|
+
try {
|
|
71
|
+
fd = openSync(file, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
72
|
+
const head = Buffer.alloc(2);
|
|
73
|
+
return readSync(fd, head, 0, 2, 0) === 2 && head[0] === 0x23 && head[1] === 0x21;
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
finally {
|
|
79
|
+
if (fd !== null)
|
|
80
|
+
closeSync(fd);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
export function packageFolderOf(script) {
|
|
84
|
+
for (let folder = dirname(script);;) {
|
|
85
|
+
if (existsSync(join(folder, "package.json")))
|
|
86
|
+
return folder;
|
|
87
|
+
const up = dirname(folder);
|
|
88
|
+
if (up === folder)
|
|
89
|
+
return dirname(script);
|
|
90
|
+
folder = up;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
export function resolveStatusBinary(binary, trust) {
|
|
94
|
+
const refused = (why) => ({ ok: false, missing: false, why });
|
|
95
|
+
const excluded = (path) => trust.untrusted.some(root => inside(path, root));
|
|
96
|
+
for (const entry of trust.path.split(delimiter)) {
|
|
97
|
+
if (entry === "")
|
|
98
|
+
continue;
|
|
99
|
+
const candidate = join(isAbsolute(entry) ? entry : resolve(entry), binary);
|
|
100
|
+
try {
|
|
101
|
+
accessSync(candidate, constants.X_OK);
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
if (!isAbsolute(entry))
|
|
107
|
+
return refused("it was found through a relative PATH entry");
|
|
108
|
+
if (trust.uid === undefined)
|
|
109
|
+
return refused("who owns it can't be checked on this system");
|
|
110
|
+
const folder = realOrNull(entry);
|
|
111
|
+
if (folder === null)
|
|
112
|
+
return refused("its PATH folder can't be read");
|
|
113
|
+
if (excluded(folder))
|
|
114
|
+
return refused("its PATH folder is inside a project, worktree or Toolroll's own folder");
|
|
115
|
+
const folders = trustedFolders(folder, trust.uid, trust.acl);
|
|
116
|
+
if (!folders.ok)
|
|
117
|
+
return refused(folders.why);
|
|
118
|
+
const file = trustedBinary(candidate, trust.uid, trust.acl);
|
|
119
|
+
if (!file.ok)
|
|
120
|
+
return refused(file.why);
|
|
121
|
+
if (excluded(file.real))
|
|
122
|
+
return refused("it is inside a project, worktree or Toolroll's own folder");
|
|
123
|
+
if (isScript(file.real)) {
|
|
124
|
+
const pack = packageFolderOf(file.real);
|
|
125
|
+
if (excluded(pack))
|
|
126
|
+
return refused("its package folder is inside a project, worktree or Toolroll's own folder");
|
|
127
|
+
const packed = trustedFolders(pack, trust.uid, trust.acl);
|
|
128
|
+
if (!packed.ok)
|
|
129
|
+
return refused(`its package folder: ${packed.why}`);
|
|
130
|
+
}
|
|
131
|
+
return { ok: true, real: file.real };
|
|
132
|
+
}
|
|
133
|
+
return { ok: false, missing: true };
|
|
134
|
+
}
|
|
135
|
+
export function shebangOf(script) {
|
|
136
|
+
let fd = null;
|
|
137
|
+
let head;
|
|
138
|
+
try {
|
|
139
|
+
fd = openSync(script, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
140
|
+
const buffer = Buffer.alloc(256);
|
|
141
|
+
const read = readSync(fd, buffer, 0, 256, 0);
|
|
142
|
+
head = buffer.subarray(0, read).toString("utf8");
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
finally {
|
|
148
|
+
if (fd !== null)
|
|
149
|
+
closeSync(fd);
|
|
150
|
+
}
|
|
151
|
+
const end = head.indexOf("\n");
|
|
152
|
+
if (!head.startsWith("#!") || end < 0)
|
|
153
|
+
return null;
|
|
154
|
+
const words = head.slice(2, end).replace(/\r$/, "").trim().split(/[ \t]+/).filter(one => one !== "");
|
|
155
|
+
const [first, ...rest] = words;
|
|
156
|
+
if (first === undefined || !isAbsolute(first))
|
|
157
|
+
return null;
|
|
158
|
+
if (first.split(sep).at(-1) === "env") {
|
|
159
|
+
const named = rest[0] === "-S" ? [...rest.slice(1, 2), "-S", ...rest.slice(2)] : rest;
|
|
160
|
+
const [name, ...args] = named;
|
|
161
|
+
if (name === undefined || !/^[A-Za-z0-9._+-]+$/.test(name))
|
|
162
|
+
return null;
|
|
163
|
+
return { kind: "env", name, args };
|
|
164
|
+
}
|
|
165
|
+
return { kind: "absolute", path: first, args: rest };
|
|
166
|
+
}
|
|
167
|
+
export function resolveLaunch(binary, trust) {
|
|
168
|
+
const found = resolveStatusBinary(binary, trust);
|
|
169
|
+
if (!found.ok)
|
|
170
|
+
return found;
|
|
171
|
+
if (!isScript(found.real))
|
|
172
|
+
return { ok: true, file: found.real, args: [], folders: [dirname(found.real)], real: found.real };
|
|
173
|
+
const refused = (why) => ({ ok: false, missing: false, why });
|
|
174
|
+
const bang = shebangOf(found.real);
|
|
175
|
+
if (bang === null)
|
|
176
|
+
return refused("its first line doesn't name an interpreter Toolroll can check");
|
|
177
|
+
if (bang.args.length > 0)
|
|
178
|
+
return refused(`its first line passes its interpreter arguments (${bang.args.join(" ").slice(0, 60)}), which Toolroll doesn't run`);
|
|
179
|
+
let interpreter;
|
|
180
|
+
if (bang.kind === "env") {
|
|
181
|
+
const named = resolveStatusBinary(bang.name, trust);
|
|
182
|
+
if (!named.ok)
|
|
183
|
+
return refused(named.missing ? `its interpreter \`${bang.name}\` isn't on PATH` : `its interpreter \`${bang.name}\`: ${named.why}`);
|
|
184
|
+
interpreter = named.real;
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
if (trust.uid === undefined)
|
|
188
|
+
return refused("who owns it can't be checked on this system");
|
|
189
|
+
const file = trustedBinary(bang.path, trust.uid, trust.acl);
|
|
190
|
+
if (!file.ok)
|
|
191
|
+
return refused(`its interpreter ${bang.path}: ${file.why}`);
|
|
192
|
+
if (trust.untrusted.some(root => inside(file.real, root) || inside(resolve(bang.path), root)))
|
|
193
|
+
return refused("its interpreter is inside a project, worktree or Toolroll's own folder");
|
|
194
|
+
interpreter = file.real;
|
|
195
|
+
}
|
|
196
|
+
if (isScript(interpreter))
|
|
197
|
+
return refused("its interpreter is itself a script");
|
|
198
|
+
return { ok: true, file: interpreter, args: [found.real], folders: [dirname(interpreter)], real: found.real };
|
|
199
|
+
}
|
|
200
|
+
export function launchPath(launch, trust) {
|
|
201
|
+
const kept = [];
|
|
202
|
+
for (const one of [...launch.folders, ...trustedPathOf(trust).split(delimiter)])
|
|
203
|
+
if (one !== "" && !kept.includes(one) && !trust.untrusted.some(root => inside(one, root)))
|
|
204
|
+
kept.push(one);
|
|
205
|
+
return kept.join(delimiter);
|
|
206
|
+
}
|
|
207
|
+
export function trustedPathOf(trust) {
|
|
208
|
+
if (trust.uid === undefined)
|
|
209
|
+
return "";
|
|
210
|
+
const kept = [];
|
|
211
|
+
for (const entry of trust.path.split(delimiter)) {
|
|
212
|
+
if (entry === "" || !isAbsolute(entry))
|
|
213
|
+
continue;
|
|
214
|
+
const folder = realOrNull(entry);
|
|
215
|
+
if (folder === null || trust.untrusted.some(root => inside(folder, root)) || !trustedFolders(folder, trust.uid, trust.acl).ok)
|
|
216
|
+
continue;
|
|
217
|
+
if (!kept.includes(folder))
|
|
218
|
+
kept.push(folder);
|
|
219
|
+
}
|
|
220
|
+
return kept.join(delimiter);
|
|
221
|
+
}
|
|
222
|
+
export function trustedLocation(value, trust) {
|
|
223
|
+
if (value === undefined || value === "" || !isAbsolute(value) || trust.uid === undefined)
|
|
224
|
+
return null;
|
|
225
|
+
const outside = (path) => !trust.untrusted.some(root => inside(path, root));
|
|
226
|
+
if (!outside(resolve(value)))
|
|
227
|
+
return null;
|
|
228
|
+
const real = realOrNull(value);
|
|
229
|
+
if (real === null || !outside(real))
|
|
230
|
+
return null;
|
|
231
|
+
try {
|
|
232
|
+
if (lstatSync(real).uid !== trust.uid)
|
|
233
|
+
return null;
|
|
234
|
+
}
|
|
235
|
+
catch {
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
return trustedFolders(real, trust.uid, trust.acl).ok ? real : null;
|
|
239
|
+
}
|
|
240
|
+
export function statusEnvironment(source, trust) {
|
|
241
|
+
const env = { PATH: trustedPathOf(trust) };
|
|
242
|
+
for (const name of STATUS_ENV_NAMES) {
|
|
243
|
+
const value = source[name];
|
|
244
|
+
if (value !== undefined && value !== "")
|
|
245
|
+
env[name] = value;
|
|
246
|
+
}
|
|
247
|
+
for (const name of STATUS_LOCATION_NAMES) {
|
|
248
|
+
const value = trustedLocation(source[name], trust);
|
|
249
|
+
if (value !== null)
|
|
250
|
+
env[name] = value;
|
|
251
|
+
}
|
|
252
|
+
return env;
|
|
253
|
+
}
|
|
254
|
+
function endGroup(pgid, signal) {
|
|
255
|
+
try {
|
|
256
|
+
process.kill(-pgid, signal);
|
|
257
|
+
}
|
|
258
|
+
catch { }
|
|
259
|
+
}
|
|
260
|
+
export function runBoundedStatus(file, args, options) {
|
|
261
|
+
const cap = options.maxBuffer ?? STATUS_MAX_BUFFER;
|
|
262
|
+
return new Promise(done => {
|
|
263
|
+
let stdout = "", stderr = "", timedOut = false, settled = false, code = null;
|
|
264
|
+
const timers = [];
|
|
265
|
+
const finish = (result) => { if (settled)
|
|
266
|
+
return; settled = true; for (const one of timers)
|
|
267
|
+
clearTimeout(one); done(result); };
|
|
268
|
+
if (options.timeoutMs <= 0)
|
|
269
|
+
return finish({ code: 124, stdout: "", stderr: "", timedOut: true, notFound: false });
|
|
270
|
+
let child;
|
|
271
|
+
try {
|
|
272
|
+
child = spawn(file, [...args], { cwd: options.cwd, env: options.env, detached: process.platform !== "win32", stdio: ["ignore", "pipe", "pipe"], windowsHide: true });
|
|
273
|
+
}
|
|
274
|
+
catch (error) {
|
|
275
|
+
const missing = error.code === "ENOENT";
|
|
276
|
+
return finish({ code: missing ? 127 : -1, stdout: "", stderr: "", timedOut: false, notFound: missing });
|
|
277
|
+
}
|
|
278
|
+
const pgid = child.pid;
|
|
279
|
+
const end = (signal) => {
|
|
280
|
+
if (pgid === undefined)
|
|
281
|
+
return;
|
|
282
|
+
if (process.platform === "win32") {
|
|
283
|
+
try {
|
|
284
|
+
child.kill(signal);
|
|
285
|
+
}
|
|
286
|
+
catch { }
|
|
287
|
+
}
|
|
288
|
+
else
|
|
289
|
+
endGroup(pgid, signal);
|
|
290
|
+
};
|
|
291
|
+
child.stdout?.setEncoding("utf8").on("data", (chunk) => { if (stdout.length < cap)
|
|
292
|
+
stdout += chunk.slice(0, cap - stdout.length); });
|
|
293
|
+
child.stderr?.setEncoding("utf8").on("data", (chunk) => { if (stderr.length < cap)
|
|
294
|
+
stderr += chunk.slice(0, cap - stderr.length); });
|
|
295
|
+
child.once("error", error => {
|
|
296
|
+
const missing = error.code === "ENOENT";
|
|
297
|
+
finish({ code: missing ? 127 : -1, stdout, stderr, timedOut: false, notFound: missing });
|
|
298
|
+
});
|
|
299
|
+
child.once("exit", exitCode => { code = exitCode; end("SIGKILL"); });
|
|
300
|
+
child.once("close", () => finish({ code: timedOut ? 124 : code ?? -1, stdout, stderr, timedOut, notFound: false }));
|
|
301
|
+
timers.push(setTimeout(() => {
|
|
302
|
+
timedOut = true;
|
|
303
|
+
end("SIGTERM");
|
|
304
|
+
timers.push(setTimeout(() => end("SIGKILL"), KILL_GRACE_MS));
|
|
305
|
+
timers.push(setTimeout(() => { child.stdout?.destroy(); child.stderr?.destroy(); finish({ code: 124, stdout, stderr, timedOut: true, notFound: false }); }, KILL_GRACE_MS + 250));
|
|
306
|
+
}, options.timeoutMs));
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
export function givenRepos(given) {
|
|
310
|
+
return () => [...(given.repo === undefined ? [] : [given.repo]), ...(given.repos ?? []), ...(given.currentRepos?.() ?? [])];
|
|
311
|
+
}
|
|
312
|
+
export function statusProbe(options = {}) {
|
|
313
|
+
return async (file, args, runOptions) => {
|
|
314
|
+
const deadline = Date.now() + Math.min(runOptions?.timeoutMs ?? STATUS_TIMEOUT_MS, options.timeoutMs ?? STATUS_TIMEOUT_MS);
|
|
315
|
+
const env = options.env ?? process.env;
|
|
316
|
+
const untrusted = await excludedFolders({ store: options.store, databaseFile: options.databaseFile }, options.untrusted?.() ?? []);
|
|
317
|
+
if (untrusted === null)
|
|
318
|
+
return REFUSED;
|
|
319
|
+
const aclFor = options.aclFor ?? ((at) => boundedAcl(at));
|
|
320
|
+
const trustWith = (acl) => ({ path: env["PATH"] ?? "", uid: options.uid ?? process.getuid?.(), untrusted, acl });
|
|
321
|
+
const trust = trustWith(aclFor(deadline));
|
|
322
|
+
const found = resolveLaunch(file, trust);
|
|
323
|
+
if (!found.ok)
|
|
324
|
+
return found.missing ? NOT_FOUND : REFUSED;
|
|
325
|
+
const childEnv = { ...statusEnvironment(env, trust), PATH: launchPath(found, trust) };
|
|
326
|
+
const again = resolveLaunch(file, trustWith(aclFor(deadline)));
|
|
327
|
+
if (!again.ok || again.real !== found.real || again.file !== found.file)
|
|
328
|
+
return REFUSED;
|
|
329
|
+
let cwd;
|
|
330
|
+
try {
|
|
331
|
+
cwd = mkdtempSync(join(tmpdir(), "toolroll-status-"));
|
|
332
|
+
}
|
|
333
|
+
catch {
|
|
334
|
+
return REFUSED;
|
|
335
|
+
}
|
|
336
|
+
try {
|
|
337
|
+
return await runBoundedStatus(found.file, [...found.args, ...args], { env: childEnv, cwd, timeoutMs: deadline - Date.now(), maxBuffer: Math.min(runOptions?.maxBuffer ?? STATUS_MAX_BUFFER, STATUS_MAX_BUFFER) });
|
|
338
|
+
}
|
|
339
|
+
finally {
|
|
340
|
+
rmSync(cwd, { recursive: true, force: true });
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
}
|
package/dist/store.js
CHANGED
|
@@ -20,6 +20,11 @@ import { V160_BACKFILL, V160_SCHEMA, V160_STEPS } from "./advanced-schema.js";
|
|
|
20
20
|
import { V161_SCHEMA, V161_STEPS } from "./flexible-schema.js";
|
|
21
21
|
import { V162_SCHEMA, V162_STEPS } from "./flexible-thread-schema.js";
|
|
22
22
|
import { V163_SCHEMA, V163_STEPS } from "./typed-words-schema.js";
|
|
23
|
+
import { V164_OBJECTS, V164_SCHEMA, V164_STEPS } from "./flexible-turns-schema.js";
|
|
24
|
+
import { V165_OBJECTS, V165_SCHEMA, V165_STEPS } from "./flexible-launch-schema.js";
|
|
25
|
+
import { V166_OBJECTS, V166_SCHEMA, V166_STEPS } from "./flexible-relay-schema.js";
|
|
26
|
+
import { V167_OBJECTS, V167_SCHEMA, V167_STEPS } from "./flexible-answers-schema.js";
|
|
27
|
+
import { V168_OBJECTS, V168_SCHEMA, V168_STEPS } from "./flexible-ship-schema.js";
|
|
23
28
|
import { endLapsedFlexible } from "./flexible.js";
|
|
24
29
|
import { refArchived, taskArchived, taskCancelled } from "./task-archive.js";
|
|
25
30
|
export { refArchived, taskArchived } from "./task-archive.js";
|
|
@@ -65,6 +70,7 @@ import { ACTIVITY_ONLY_KINDS } from "./needs-you.js";
|
|
|
65
70
|
import { parseReviewContext, reviewContextCustodyProblem } from "./review-context.js";
|
|
66
71
|
import { foldReview, manualReviewOnly } from "./proof.js";
|
|
67
72
|
import { hashPassword, liveReleaseOf } from "./scope.js";
|
|
73
|
+
import { declareNewInstallSolo } from "./install-mode.js";
|
|
68
74
|
import { currentLocalOwner, LOCAL_MODE_CONFINES, LOCAL_OWNER_LAPSED, localModeOn, localOwnerInFlight, localOwnerStandsNow } from "./local-owner.js";
|
|
69
75
|
import { nightlyDebtHold } from "./nightly-github.js";
|
|
70
76
|
import { releaseCiHoldOf, releaseCiRunningOf } from "./release-ci-hold.js";
|
|
@@ -823,7 +829,7 @@ export function checkSuitesOf(value) {
|
|
|
823
829
|
}
|
|
824
830
|
}
|
|
825
831
|
const REGISTERED_AT_FILING = "again, as it was filed";
|
|
826
|
-
export const SCHEMA_VERSION =
|
|
832
|
+
export const SCHEMA_VERSION = 168;
|
|
827
833
|
export const V118_MERGED_TABLES = Object.freeze({ api_token: "person", coordinator_credential: "coordinator", lead_credential: "lead" });
|
|
828
834
|
const V118_REFERENCES = /REFERENCES (?:coordinator_credential\(cid\)|api_token\(id\))/g;
|
|
829
835
|
const V118_COORDINATOR_COLUMNS = [["task_ref", "coordinator_cid"], ["coordinator_event", "cid"], ["mcp_idempotency", "cid"], ["coordinator_proposal", "cid"]];
|
|
@@ -888,7 +894,7 @@ export const V115_DROPPED_TABLES = Object.freeze([
|
|
|
888
894
|
"fallback_config", "fallback_cycle", "fallback_transition",
|
|
889
895
|
]);
|
|
890
896
|
const V115_DROPPED_REFERENCES = /\s+REFERENCES (?:contestant|contest|tournament_terms|session_turn|attended_authorization|held_session|fallback_cycle|fallback_config|fallback_transition|routine|routine_fire)\(id\)(?: ON DELETE CASCADE)?/g;
|
|
891
|
-
export const UPDATE_SAFE_MIGRATIONS = Object.freeze([108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163]);
|
|
897
|
+
export const UPDATE_SAFE_MIGRATIONS = Object.freeze([108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168]);
|
|
892
898
|
export const V119_ADDED_COLUMNS = Object.freeze({
|
|
893
899
|
task_ref: { planning_generation: { definition: "INTEGER NOT NULL DEFAULT 0", saved: "0" } },
|
|
894
900
|
run: { planning_generation: { definition: "INTEGER NOT NULL DEFAULT 0", saved: "0" } },
|
|
@@ -1431,7 +1437,7 @@ export { V156_STEPS };
|
|
|
1431
1437
|
export { V157_STEPS };
|
|
1432
1438
|
export { V158_STEPS };
|
|
1433
1439
|
export { V159_STEPS };
|
|
1434
|
-
export { V160_STEPS, V161_STEPS, V162_STEPS, V163_STEPS };
|
|
1440
|
+
export { V160_STEPS, V161_STEPS, V162_STEPS, V163_STEPS, V164_STEPS, V165_STEPS, V166_STEPS, V167_STEPS, V168_STEPS };
|
|
1435
1441
|
export const RELEASE_ONCE_SCHEMA = `
|
|
1436
1442
|
CREATE TABLE IF NOT EXISTS release_authority (
|
|
1437
1443
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
@@ -4209,7 +4215,7 @@ function initializeStore(db, file, options = {}) {
|
|
|
4209
4215
|
throw new Error(`${file}: ${problem}; refusing to move chat history it cannot name`);
|
|
4210
4216
|
}
|
|
4211
4217
|
if (preflight === SCHEMA_VERSION && !findingSourcesStale(db)) {
|
|
4212
|
-
const missing = codeMapShapeProblem(db) ?? viewPreferenceShapeProblem(db) ?? flexibleTermsShapeProblem(db) ?? flexibleThreadShapeProblem(db) ?? typedByPersonShapeProblem(db);
|
|
4218
|
+
const missing = codeMapShapeProblem(db) ?? viewPreferenceShapeProblem(db) ?? flexibleTermsShapeProblem(db) ?? flexibleThreadShapeProblem(db) ?? typedByPersonShapeProblem(db) ?? flexibleTurnsShapeProblem(db) ?? flexibleLaunchShapeProblem(db) ?? flexibleRelayShapeProblem(db) ?? flexibleAnswersShapeProblem(db) ?? flexibleShipShapeProblem(db);
|
|
4213
4219
|
if (missing !== null)
|
|
4214
4220
|
throw new Error(`${file}: refusing to open — ${missing}, though the schema says v${SCHEMA_VERSION}`);
|
|
4215
4221
|
db.exec("PRAGMA journal_mode = WAL; PRAGMA foreign_keys = ON;");
|
|
@@ -4566,6 +4572,31 @@ CREATE INDEX IF NOT EXISTS run_checkpoint_by_task ON run_checkpoint (task_ref, i
|
|
|
4566
4572
|
if (typedDamaged !== null)
|
|
4567
4573
|
throw new Error(`${file}: refusing to open — ${typedDamaged}`);
|
|
4568
4574
|
step("typed-by-person");
|
|
4575
|
+
db.exec(V164_SCHEMA);
|
|
4576
|
+
const turnsDamaged = flexibleTurnsShapeProblem(db);
|
|
4577
|
+
if (turnsDamaged !== null)
|
|
4578
|
+
throw new Error(`${file}: refusing to open — ${turnsDamaged}`);
|
|
4579
|
+
step("thread-turn");
|
|
4580
|
+
db.exec(V165_SCHEMA);
|
|
4581
|
+
const launchDamaged = flexibleLaunchShapeProblem(db);
|
|
4582
|
+
if (launchDamaged !== null)
|
|
4583
|
+
throw new Error(`${file}: refusing to open — ${launchDamaged}`);
|
|
4584
|
+
step("thread-launch");
|
|
4585
|
+
db.exec(V166_SCHEMA);
|
|
4586
|
+
const relayDamaged = flexibleRelayShapeProblem(db);
|
|
4587
|
+
if (relayDamaged !== null)
|
|
4588
|
+
throw new Error(`${file}: refusing to open — ${relayDamaged}`);
|
|
4589
|
+
step("thread-relay-call");
|
|
4590
|
+
db.exec(V167_SCHEMA);
|
|
4591
|
+
const answersDamaged = flexibleAnswersShapeProblem(db);
|
|
4592
|
+
if (answersDamaged !== null)
|
|
4593
|
+
throw new Error(`${file}: refusing to open — ${answersDamaged}`);
|
|
4594
|
+
step("thread-decision");
|
|
4595
|
+
db.exec(V168_SCHEMA);
|
|
4596
|
+
const shipDamaged = flexibleShipShapeProblem(db);
|
|
4597
|
+
if (shipDamaged !== null)
|
|
4598
|
+
throw new Error(`${file}: refusing to open — ${shipDamaged}`);
|
|
4599
|
+
step("flexible-ship");
|
|
4569
4600
|
if (!fresh)
|
|
4570
4601
|
reclaimDatabase(db, "migration");
|
|
4571
4602
|
const expectedMarker = preflight < 0 ? preflight : -preflight;
|
|
@@ -7032,7 +7063,8 @@ export class Store {
|
|
|
7032
7063
|
WHERE task_ref.repo = ? AND run.cost_usd IS NOT NULL
|
|
7033
7064
|
AND run.provider_started_at >= ? AND run.provider_started_at < ?`)
|
|
7034
7065
|
.get(repo, `${day}T00:00:00.000Z`, `${day}T23:59:59.999Z`);
|
|
7035
|
-
|
|
7066
|
+
const threads = this.db.prepare("SELECT COALESCE(SUM(cost_microusd), 0) AS total FROM thread_turn WHERE repo = ? AND utc_day = ? AND status <> 'withdrawn'").get(repo, day);
|
|
7067
|
+
if (Number(spent?.["total"] ?? 0) + Number(threads?.["total"] ?? 0) >= terms.dailyMeasuredCapMicrousd) {
|
|
7036
7068
|
return {
|
|
7037
7069
|
ok: false,
|
|
7038
7070
|
rail: "daily-dollars",
|
|
@@ -11770,6 +11802,9 @@ export class Store {
|
|
|
11770
11802
|
reached: Number(row["reached"]) === 1, plan: row["plan"] == null ? null : String(row["plan"]), observedAt: String(row["observed_at"]),
|
|
11771
11803
|
}));
|
|
11772
11804
|
}
|
|
11805
|
+
spendBetween(from, to) {
|
|
11806
|
+
return spendItems(this.db, from, to);
|
|
11807
|
+
}
|
|
11773
11808
|
monthSpend(now) {
|
|
11774
11809
|
const month = monthOf(now);
|
|
11775
11810
|
const items = spendItems(this.db, month.from, month.to);
|
|
@@ -15071,6 +15106,7 @@ export class Store {
|
|
|
15071
15106
|
this.db
|
|
15072
15107
|
.prepare("INSERT INTO approver (name, credential_hash, added_at, generation) VALUES (?, ?, ?, 1)")
|
|
15073
15108
|
.run(name, credentialHash, now.toISOString());
|
|
15109
|
+
declareNewInstallSolo(this, name, now);
|
|
15074
15110
|
return { ok: true };
|
|
15075
15111
|
});
|
|
15076
15112
|
}
|
|
@@ -18310,6 +18346,7 @@ export function initLocalMode(store, input) {
|
|
|
18310
18346
|
return { ok: false, reason: "has-accounts" };
|
|
18311
18347
|
store.handle.prepare("INSERT INTO local_mode (id, owner, generation, enabled, initialized_at, changed_at) VALUES (1, ?, 1, 1, ?, ?)").run(input.owner, stamp, stamp);
|
|
18312
18348
|
store.recordAction({ at: stamp, actor: input.owner, repo: null, taskId: null, runId: null, action: "local mode on", outcome: "initialized", source: "access", detail: "a new install with no account, started at its own terminal: the owner has no password yet" });
|
|
18349
|
+
declareNewInstallSolo(store, input.owner, input.now);
|
|
18313
18350
|
return { ok: true, owner: input.owner, generation: 1 };
|
|
18314
18351
|
});
|
|
18315
18352
|
}
|
|
@@ -18792,3 +18829,63 @@ export function typedNotesFor(store, taskId, cap) {
|
|
|
18792
18829
|
return rows.map(row => ({ kind: row["kind"] === "sent-back" ? "sent-back" : "to-agent", id: Number(row["id"]), author: String(row["author"]),
|
|
18793
18830
|
at: String(row["at"]), note: String(row["words"]), question: row["question"] == null ? null : String(row["question"]) }));
|
|
18794
18831
|
}
|
|
18832
|
+
function flexibleTurnsShapeProblem(db) {
|
|
18833
|
+
const statements = V164_SCHEMA.split(/;\s*\n(?=CREATE )/).map(one => one.trim().replace(/;$/, "")).filter(one => one !== "");
|
|
18834
|
+
for (const [type, name] of V164_OBJECTS) {
|
|
18835
|
+
const row = db.prepare("SELECT sql FROM sqlite_master WHERE type = ? AND name = ?").get(type, name);
|
|
18836
|
+
if (row === undefined)
|
|
18837
|
+
return `the Flexible turns ${type} ${name} is missing`;
|
|
18838
|
+
const want = statements.find(one => new RegExp(`^CREATE (?:UNIQUE )?${type.toUpperCase()} IF NOT EXISTS ${name}\\b`).test(one));
|
|
18839
|
+
if (want === undefined || canonicalDdl(String(row["sql"]).replace(/;$/, "")).trim() !== canonicalDdl(want).trim())
|
|
18840
|
+
return `the Flexible turns ${type} ${name} has an unknown shape`;
|
|
18841
|
+
}
|
|
18842
|
+
return null;
|
|
18843
|
+
}
|
|
18844
|
+
function flexibleLaunchShapeProblem(db) {
|
|
18845
|
+
const statements = V165_SCHEMA.split(/;\s*\n(?=CREATE )/).map(one => one.trim().replace(/;$/, "")).filter(one => one !== "");
|
|
18846
|
+
for (const [type, name] of V165_OBJECTS) {
|
|
18847
|
+
const row = db.prepare("SELECT sql FROM sqlite_master WHERE type = ? AND name = ?").get(type, name);
|
|
18848
|
+
if (row === undefined)
|
|
18849
|
+
return `the Flexible launches ${type} ${name} is missing`;
|
|
18850
|
+
const want = statements.find(one => new RegExp(`^CREATE (?:UNIQUE )?${type.toUpperCase()} IF NOT EXISTS ${name}\\b`).test(one));
|
|
18851
|
+
if (want === undefined || canonicalDdl(String(row["sql"]).replace(/;$/, "")).trim() !== canonicalDdl(want).trim())
|
|
18852
|
+
return `the Flexible launches ${type} ${name} has an unknown shape`;
|
|
18853
|
+
}
|
|
18854
|
+
return null;
|
|
18855
|
+
}
|
|
18856
|
+
function flexibleRelayShapeProblem(db) {
|
|
18857
|
+
const statements = V166_SCHEMA.split(/;\s*\n(?=CREATE )/).map(one => one.trim().replace(/;$/, "")).filter(one => one !== "");
|
|
18858
|
+
for (const [type, name] of V166_OBJECTS) {
|
|
18859
|
+
const row = db.prepare("SELECT sql FROM sqlite_master WHERE type = ? AND name = ?").get(type, name);
|
|
18860
|
+
if (row === undefined)
|
|
18861
|
+
return `the Flexible relay calls ${type} ${name} is missing`;
|
|
18862
|
+
const want = statements.find(one => new RegExp(`^CREATE (?:UNIQUE )?${type.toUpperCase()} IF NOT EXISTS ${name}\\b`).test(one));
|
|
18863
|
+
if (want === undefined || canonicalDdl(String(row["sql"]).replace(/;$/, "")).trim() !== canonicalDdl(want).trim())
|
|
18864
|
+
return `the Flexible relay calls ${type} ${name} has an unknown shape`;
|
|
18865
|
+
}
|
|
18866
|
+
return null;
|
|
18867
|
+
}
|
|
18868
|
+
function flexibleAnswersShapeProblem(db) {
|
|
18869
|
+
const statements = V167_SCHEMA.split(/;\s*\n(?=CREATE )/).map(one => one.trim().replace(/;$/, "")).filter(one => one !== "");
|
|
18870
|
+
for (const [type, name] of V167_OBJECTS) {
|
|
18871
|
+
const row = db.prepare("SELECT sql FROM sqlite_master WHERE type = ? AND name = ?").get(type, name);
|
|
18872
|
+
if (row === undefined)
|
|
18873
|
+
return `the Flexible answers ${type} ${name} is missing`;
|
|
18874
|
+
const want = statements.find(one => new RegExp(`^CREATE (?:UNIQUE )?${type.toUpperCase()} IF NOT EXISTS ${name}\\b`).test(one));
|
|
18875
|
+
if (want === undefined || canonicalDdl(String(row["sql"]).replace(/;$/, "")).trim() !== canonicalDdl(want).trim())
|
|
18876
|
+
return `the Flexible answers ${type} ${name} has an unknown shape`;
|
|
18877
|
+
}
|
|
18878
|
+
return null;
|
|
18879
|
+
}
|
|
18880
|
+
function flexibleShipShapeProblem(db) {
|
|
18881
|
+
const statements = V168_SCHEMA.split(/;\s*\n(?=CREATE )/).map(one => one.trim().replace(/;$/, "")).filter(one => one !== "");
|
|
18882
|
+
for (const [type, name] of V168_OBJECTS) {
|
|
18883
|
+
const row = db.prepare("SELECT sql FROM sqlite_master WHERE type = ? AND name = ?").get(type, name);
|
|
18884
|
+
if (row === undefined)
|
|
18885
|
+
return `the Flexible ship ${type} ${name} is missing`;
|
|
18886
|
+
const want = statements.find(one => new RegExp(`^CREATE (?:UNIQUE )?${type.toUpperCase()} IF NOT EXISTS ${name}\\b`).test(one));
|
|
18887
|
+
if (want === undefined || canonicalDdl(String(row["sql"]).replace(/;$/, "")).trim() !== canonicalDdl(want).trim())
|
|
18888
|
+
return `the Flexible ship ${type} ${name} has an unknown shape`;
|
|
18889
|
+
}
|
|
18890
|
+
return null;
|
|
18891
|
+
}
|