toolroll 0.9.113 → 0.9.114

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/dist/store.js CHANGED
@@ -29,6 +29,8 @@ import { V168_OBJECTS, V168_SCHEMA, V168_STEPS } from "./flexible-ship-schema.js
29
29
  import { V169_ADDED_COLUMNS, V169_SCHEMA, V169_STEPS } from "./task-sizing-schema.js";
30
30
  import { V170_ADDED_COLUMNS, V170_STEPS } from "./agent-said-schema.js";
31
31
  import { V171_SCHEMA, V171_STEPS } from "./flexible-setting-schema.js";
32
+ import { V172_ADDED_COLUMNS, V172_OBJECTS, V172_SCHEMA, V172_STEPS } from "./flexible-sign-in-schema.js";
33
+ import { relayCancel } from "./flexible-relay-cancel.js";
32
34
  import { endLapsedFlexible } from "./flexible.js";
33
35
  import { refArchived, taskArchived, taskCancelled } from "./task-archive.js";
34
36
  export { refArchived, taskArchived } from "./task-archive.js";
@@ -833,7 +835,7 @@ export function checkSuitesOf(value) {
833
835
  }
834
836
  }
835
837
  const REGISTERED_AT_FILING = "again, as it was filed";
836
- export const SCHEMA_VERSION = 171;
838
+ export const SCHEMA_VERSION = 172;
837
839
  export const V118_MERGED_TABLES = Object.freeze({ api_token: "person", coordinator_credential: "coordinator", lead_credential: "lead" });
838
840
  const V118_REFERENCES = /REFERENCES (?:coordinator_credential\(cid\)|api_token\(id\))/g;
839
841
  const V118_COORDINATOR_COLUMNS = [["task_ref", "coordinator_cid"], ["coordinator_event", "cid"], ["mcp_idempotency", "cid"], ["coordinator_proposal", "cid"]];
@@ -898,7 +900,7 @@ export const V115_DROPPED_TABLES = Object.freeze([
898
900
  "fallback_config", "fallback_cycle", "fallback_transition",
899
901
  ]);
900
902
  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;
901
- 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, 169, 170, 171]);
903
+ 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, 169, 170, 171, 172]);
902
904
  export const V119_ADDED_COLUMNS = Object.freeze({
903
905
  task_ref: { planning_generation: { definition: "INTEGER NOT NULL DEFAULT 0", saved: "0" } },
904
906
  run: { planning_generation: { definition: "INTEGER NOT NULL DEFAULT 0", saved: "0" } },
@@ -1441,7 +1443,7 @@ export { V156_STEPS };
1441
1443
  export { V157_STEPS };
1442
1444
  export { V158_STEPS };
1443
1445
  export { V159_STEPS };
1444
- export { V160_STEPS, V161_STEPS, V162_STEPS, V163_STEPS, V164_STEPS, V165_STEPS, V166_STEPS, V167_STEPS, V168_STEPS, V169_STEPS, V170_STEPS, V171_STEPS };
1446
+ export { V160_STEPS, V161_STEPS, V162_STEPS, V163_STEPS, V164_STEPS, V165_STEPS, V166_STEPS, V167_STEPS, V168_STEPS, V169_STEPS, V170_STEPS, V171_STEPS, V172_STEPS };
1445
1447
  export const RELEASE_ONCE_SCHEMA = `
1446
1448
  CREATE TABLE IF NOT EXISTS release_authority (
1447
1449
  id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -4219,7 +4221,7 @@ function initializeStore(db, file, options = {}) {
4219
4221
  throw new Error(`${file}: ${problem}; refusing to move chat history it cannot name`);
4220
4222
  }
4221
4223
  if (preflight === SCHEMA_VERSION && !findingSourcesStale(db)) {
4222
- const missing = codeMapShapeProblem(db) ?? viewPreferenceShapeProblem(db) ?? flexibleTermsShapeProblem(db) ?? flexibleThreadShapeProblem(db) ?? typedByPersonShapeProblem(db) ?? flexibleTurnsShapeProblem(db) ?? flexibleLaunchShapeProblem(db) ?? flexibleRelayShapeProblem(db) ?? flexibleAnswersShapeProblem(db) ?? flexibleShipShapeProblem(db) ?? taskSizingShapeProblem(db) ?? agentSaidShapeProblem(db) ?? flexibleSettingShapeProblem(db);
4224
+ const missing = codeMapShapeProblem(db) ?? viewPreferenceShapeProblem(db) ?? flexibleTermsShapeProblem(db) ?? flexibleThreadShapeProblem(db) ?? typedByPersonShapeProblem(db) ?? flexibleTurnsShapeProblem(db) ?? flexibleLaunchShapeProblem(db) ?? flexibleRelayShapeProblem(db) ?? flexibleAnswersShapeProblem(db) ?? flexibleShipShapeProblem(db) ?? taskSizingShapeProblem(db) ?? agentSaidShapeProblem(db) ?? flexibleSettingShapeProblem(db) ?? flexibleSignInShapeProblem(db);
4223
4225
  if (missing !== null)
4224
4226
  throw new Error(`${file}: refusing to open — ${missing}, though the schema says v${SCHEMA_VERSION}`);
4225
4227
  db.exec("PRAGMA journal_mode = WAL; PRAGMA foreign_keys = ON;");
@@ -4619,6 +4621,15 @@ CREATE INDEX IF NOT EXISTS run_checkpoint_by_task ON run_checkpoint (task_ref, i
4619
4621
  if (flexibleSettingDamaged !== null)
4620
4622
  throw new Error(`${file}: refusing to open — ${flexibleSettingDamaged}`);
4621
4623
  step("flexible-setting");
4624
+ for (const [table, columns] of Object.entries(V172_ADDED_COLUMNS))
4625
+ for (const [column, { definition }] of Object.entries(columns))
4626
+ addColumn(db, table, column, definition);
4627
+ step("flexible-sign-in-columns");
4628
+ db.exec(V172_SCHEMA);
4629
+ const signInDamaged = flexibleSignInShapeProblem(db);
4630
+ if (signInDamaged !== null)
4631
+ throw new Error(`${file}: refusing to open — ${signInDamaged}`);
4632
+ step("flexible-sign-in");
4622
4633
  if (!fresh)
4623
4634
  reclaimDatabase(db, "migration");
4624
4635
  const expectedMarker = preflight < 0 ? preflight : -preflight;
@@ -6884,6 +6895,7 @@ export class Store {
6884
6895
  generation = approver.generation + 1`)
6885
6896
  .run(name, credentialHash, now.toISOString());
6886
6897
  this.revokeDerivedAuthority(name, "credential-rotation", now);
6898
+ relayCancel({ person: name });
6887
6899
  });
6888
6900
  return null;
6889
6901
  });
@@ -7931,6 +7943,8 @@ export class Store {
7931
7943
  this.db
7932
7944
  .prepare("UPDATE approver SET revoked_at = ?, revoked_by = ?, generation = generation + 1 WHERE name = ?")
7933
7945
  .run(stamp, by, name);
7946
+ this.db.prepare("UPDATE flexible_sign_in SET state = 'retiring', save_op = NULL, retire_after = NULL, retired_at = ? WHERE person = ? AND state IN ('staged', 'active')").run(stamp, name);
7947
+ relayCancel({ person: name });
7934
7948
  this.db.exec("SAVEPOINT view_preference_cleanup");
7935
7949
  try {
7936
7950
  this.db.prepare("DELETE FROM view_preference WHERE account = ?").run(name);
@@ -18901,7 +18915,8 @@ function flexibleRelayShapeProblem(db) {
18901
18915
  if (row === undefined)
18902
18916
  return `the Flexible relay calls ${type} ${name} is missing`;
18903
18917
  const want = statements.find(one => new RegExp(`^CREATE (?:UNIQUE )?${type.toUpperCase()} IF NOT EXISTS ${name}\\b`).test(one));
18904
- if (want === undefined || canonicalDdl(String(row["sql"]).replace(/;$/, "")).trim() !== canonicalDdl(want).trim())
18918
+ const stored = type === "table" ? withoutAddedColumns(String(row["sql"]).replace(/;$/, ""), V172_ADDED_COLUMNS[name] ?? {}) : canonicalDdl(String(row["sql"]).replace(/;$/, ""));
18919
+ if (want === undefined || stored === null || stored.trim() !== canonicalDdl(want).trim())
18905
18920
  return `the Flexible relay calls ${type} ${name} has an unknown shape`;
18906
18921
  }
18907
18922
  return null;
@@ -18975,3 +18990,40 @@ function flexibleSettingShapeProblem(db) {
18975
18990
  return "the interactive agent threads setting table has an unknown shape";
18976
18991
  return null;
18977
18992
  }
18993
+ function withoutAddedColumns(sql, columns) {
18994
+ let out = canonicalDdl(sql);
18995
+ for (const [name, { definition }] of Object.entries(columns)) {
18996
+ const piece = canonicalDdl(`, ${name} ${definition}`).trim();
18997
+ const at = out.indexOf(piece);
18998
+ if (at < 0)
18999
+ continue;
19000
+ if (out.indexOf(piece, at + 1) >= 0)
19001
+ return null;
19002
+ out = out.slice(0, at) + out.slice(at + piece.length);
19003
+ }
19004
+ for (const name of Object.keys(columns))
19005
+ if (new RegExp(`\\b${name}\\b`).test(out))
19006
+ return null;
19007
+ return out;
19008
+ }
19009
+ function flexibleSignInShapeProblem(db) {
19010
+ const statements = V172_SCHEMA.split(/;\s*\n(?=CREATE )/).map(one => one.trim().replace(/;$/, "")).filter(one => one !== "");
19011
+ for (const [type, name] of V172_OBJECTS) {
19012
+ const row = db.prepare("SELECT sql FROM sqlite_master WHERE type = ? AND name = ?").get(type, name);
19013
+ if (row === undefined)
19014
+ return `the Claude sign-ins ${type} ${name} is missing`;
19015
+ const want = statements.find(one => new RegExp(`^CREATE (?:UNIQUE )?${type.toUpperCase()} IF NOT EXISTS ${name}\\b`).test(one));
19016
+ if (want === undefined || canonicalDdl(String(row["sql"]).replace(/;$/, "")).trim() !== canonicalDdl(want).trim())
19017
+ return `the Claude sign-ins ${type} ${name} has an unknown shape`;
19018
+ }
19019
+ for (const [table, columns] of Object.entries(V172_ADDED_COLUMNS)) {
19020
+ const row = db.prepare("SELECT sql FROM sqlite_master WHERE type = 'table' AND name = ?").get(table);
19021
+ for (const [column, { definition }] of Object.entries(columns)) {
19022
+ if (!hasColumn(db, table, column))
19023
+ return `${table}.${column} is missing`;
19024
+ if (row === undefined || !canonicalDdl(String(row["sql"])).includes(canonicalDdl(`, ${column} ${definition}`).trim()))
19025
+ return `${table}.${column} has an unknown shape`;
19026
+ }
19027
+ }
19028
+ return null;
19029
+ }
@@ -5,6 +5,7 @@ import { closeSync, constants, fstatSync, fsyncSync, linkSync, lstatSync, mkdirS
5
5
  import { dirname, join } from "node:path";
6
6
  import { envValue } from "./names.js";
7
7
  import { sleep } from "./sleep.js";
8
+ import { signInSlot } from "./flexible-sign-in-slot.js";
8
9
  export class SecretStoreError extends Error {
9
10
  }
10
11
  export const STORE_WORDS = {
@@ -709,3 +710,107 @@ export function writeHeldSecret(state, name, file, value) {
709
710
  writeSealed(backend, folder, item, value);
710
711
  });
711
712
  }
713
+ const SIGN_IN_SLOT = /^[0-9a-f]{16}$/;
714
+ const SIGN_IN_GENERATION = /^[0-9a-f]{32}$/;
715
+ const SIGN_IN_VALUE = /^sk-ant-oat\d{2}-[A-Za-z0-9_-]{20,400}$/;
716
+ const WRONG_PERSON = "A saved Claude sign-in isn't the one its record names, so it isn't used.";
717
+ function signInAddress(folder, person, generation, make = false) {
718
+ if (typeof person !== "string" || person.length < 1 || person.length > 200 || typeof generation !== "string" || !SIGN_IN_GENERATION.test(generation))
719
+ throw new SecretStoreError("A secret's address can't be used.");
720
+ const slot = signInSlot(person);
721
+ if (!SIGN_IN_SLOT.test(slot))
722
+ throw new SecretStoreError("A secret's address can't be used.");
723
+ return { item: { service: serviceOf(folder), account: `flexible-sign-in.${slot}.${generation}` },
724
+ file: pathIn(folder.dir, ["flexible-sign-in", `${slot}.${generation}.json`], { make }), lock: `flexible-sign-in.${slot}` };
725
+ }
726
+ function signInOf(text, person, generation) {
727
+ let parsed;
728
+ try {
729
+ parsed = JSON.parse(text);
730
+ }
731
+ catch {
732
+ throw new SecretStoreError(WRONG_PERSON);
733
+ }
734
+ if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed))
735
+ throw new SecretStoreError(WRONG_PERSON);
736
+ const one = parsed;
737
+ if (Object.keys(one).sort().join(",") !== "generation,kind,person,value" || one["person"] !== person || one["generation"] !== generation || one["kind"] !== "setup-token"
738
+ || typeof one["value"] !== "string" || !SIGN_IN_VALUE.test(one["value"]))
739
+ throw new SecretStoreError(WRONG_PERSON);
740
+ return { person, generation, kind: "setup-token", value: one["value"] };
741
+ }
742
+ export function createSignInSecret(state, secret) {
743
+ if (secret.kind !== "setup-token" || typeof secret.value !== "string" || !SIGN_IN_VALUE.test(secret.value))
744
+ throw new SecretStoreError("A sign-in's form can't be used.");
745
+ const folder = secretFolder(state);
746
+ const address = signInAddress(folder, secret.person, secret.generation, true);
747
+ const text = JSON.stringify({ person: secret.person, generation: secret.generation, kind: secret.kind, value: secret.value });
748
+ const backend = secretBackend();
749
+ if (backend !== null)
750
+ return writeSealed(backend, folder, address.item, text, { create: true });
751
+ const staged = `${address.file}.${process.pid}.${randomBytes(4).toString("hex")}.new`;
752
+ const fd = openSync(staged, constants.O_CREAT | constants.O_EXCL | constants.O_WRONLY | constants.O_NOFOLLOW, 0o600);
753
+ try {
754
+ writeSync(fd, text);
755
+ fsyncSync(fd);
756
+ }
757
+ finally {
758
+ closeSync(fd);
759
+ }
760
+ try {
761
+ linkSync(staged, address.file);
762
+ }
763
+ catch (error) {
764
+ rmSync(staged, { force: true });
765
+ if (codeOf(error) === "EEXIST")
766
+ return "exists";
767
+ throw new SecretStoreError("A sign-in couldn't be saved in Toolroll's folder for secrets.");
768
+ }
769
+ rmSync(staged, { force: true });
770
+ return "ok";
771
+ }
772
+ export function readSignInSecret(state, person, generation) {
773
+ const folder = secretFolder(state);
774
+ const address = signInAddress(folder, person, generation);
775
+ const backend = secretBackend();
776
+ const text = backend === null ? readOwnFile(address.file) : readSealed(backend, folder, address.item);
777
+ return text === null ? null : signInOf(text, person, generation);
778
+ }
779
+ export function removeSignInSecret(state, person, generation) {
780
+ const folder = secretFolder(state);
781
+ const address = signInAddress(folder, person, generation);
782
+ const backend = secretBackend();
783
+ let text;
784
+ try {
785
+ text = backend === null ? readOwnFile(address.file) : readSealed(backend, folder, address.item);
786
+ }
787
+ catch (error) {
788
+ if (backend !== null && error instanceof SecretStoreError && /refused|couldn't be reached/.test(error.message))
789
+ throw error;
790
+ text = "";
791
+ }
792
+ if (text === null)
793
+ return "absent";
794
+ if (text !== "") {
795
+ let parsed = null;
796
+ try {
797
+ parsed = JSON.parse(text);
798
+ }
799
+ catch {
800
+ parsed = null;
801
+ }
802
+ const named = parsed !== null && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : null;
803
+ if (named !== null && (named["person"] !== person || named["generation"] !== generation))
804
+ return "not-theirs";
805
+ }
806
+ if (backend === null)
807
+ destroyOwnFile(address.file);
808
+ else
809
+ removeValue(backend, address.item);
810
+ return "removed";
811
+ }
812
+ export function withSignInLockAsync(state, person, work, options = {}) {
813
+ const folder = secretFolder(state);
814
+ const address = signInAddress(folder, person, "0".repeat(32));
815
+ return withSecretLockAsync(folder, address.lock, work, { staleMs: 120_000, waitMs: options.waitMs ?? 30_000 });
816
+ }
@@ -22,6 +22,7 @@ import { V153_ADDED_COLUMNS } from "./plain-schema.js";
22
22
  import { V158_ADDED_COLUMNS } from "./lead-latency-schema.js";
23
23
  import { V169_ADDED_COLUMNS } from "./task-sizing-schema.js";
24
24
  import { V170_ADDED_COLUMNS } from "./agent-said-schema.js";
25
+ import { V172_ADDED_COLUMNS } from "./flexible-sign-in-schema.js";
25
26
  import { V159_ADDED_COLUMNS } from "./one-step-chat-schema.js";
26
27
  import { isNewer, REGISTRY } from "./releases.js";
27
28
  import { markNeverIndex } from "./never-index.js";
@@ -326,7 +327,7 @@ const HISTORY_RULES = {
326
327
  ...Object.fromEntries(Object.entries(V117_RENAMED_TABLES).map(([old, now]) => [old, { moved: { into: now, where: "1" } }])),
327
328
  ...Object.fromEntries(V117_RENAMED_COLUMNS.filter(([table]) => !Object.values(V117_RENAMED_TABLES).includes(table)).map(([table, from, to]) => [table, { renamed: { [from]: to } }])),
328
329
  ...Object.fromEntries(Object.entries(V118_MERGED_TABLES).map(([table, kind]) => [table, { moved: { into: "credential", where: `kind = '${kind}'` } }])),
329
- ...Object.fromEntries(Object.entries(addedColumns(V119_ADDED_COLUMNS, V120_ADDED_COLUMNS, V121_ADDED_COLUMNS, V122_ADDED_COLUMNS, V123_ADDED_COLUMNS, V125_ADDED_COLUMNS, V126_ADDED_COLUMNS, V128_ADDED_COLUMNS, V129_ADDED_COLUMNS, V134_ADDED_COLUMNS, V135_ADDED_COLUMNS, V138_ADDED_COLUMNS, V143_ADDED_COLUMNS, V147_ADDED_COLUMNS, V148_ADDED_COLUMNS, V150_ADDED_COLUMNS, V151_ADDED_COLUMNS, V152_ADDED_COLUMNS, V153_ADDED_COLUMNS, V158_ADDED_COLUMNS, V159_ADDED_COLUMNS, V169_ADDED_COLUMNS, V170_ADDED_COLUMNS))
330
+ ...Object.fromEntries(Object.entries(addedColumns(V119_ADDED_COLUMNS, V120_ADDED_COLUMNS, V121_ADDED_COLUMNS, V122_ADDED_COLUMNS, V123_ADDED_COLUMNS, V125_ADDED_COLUMNS, V126_ADDED_COLUMNS, V128_ADDED_COLUMNS, V129_ADDED_COLUMNS, V134_ADDED_COLUMNS, V135_ADDED_COLUMNS, V138_ADDED_COLUMNS, V143_ADDED_COLUMNS, V147_ADDED_COLUMNS, V148_ADDED_COLUMNS, V150_ADDED_COLUMNS, V151_ADDED_COLUMNS, V152_ADDED_COLUMNS, V153_ADDED_COLUMNS, V158_ADDED_COLUMNS, V159_ADDED_COLUMNS, V169_ADDED_COLUMNS, V170_ADDED_COLUMNS, V172_ADDED_COLUMNS))
330
331
  .map(([table, rule]) => [table, { ...EARLIER_RULES[table], ...rule }])),
331
332
  };
332
333
  export const RETIRED_TABLES = Object.freeze(Object.keys(HISTORY_RULES).filter(name => HISTORY_RULES[name].retired));
Binary file
Binary file
Binary file
Binary file
@@ -1 +1,2 @@
1
- export {};
1
+ export const TUI_PAGES = Object.freeze(["flexible", "flexible-sign-in", "project"]);
2
+ export const isTuiPage = (value) => typeof value === "string" && TUI_PAGES.includes(value);
@@ -5,6 +5,7 @@ import { fileURLToPath } from "node:url";
5
5
  import { spawnHoldingLink } from "./engine-handoff.js";
6
6
  import { trustedBinary } from "./trusted-path.js";
7
7
  export { aclVerdictOf, trustedBinary } from "./trusted-path.js";
8
+ import { isTuiPage } from "./tui-contract.js";
8
9
  export const TUI_EXIT = { leave: 0, stop: 40, keep: 41, classic: 42, unprotected: 43 };
9
10
  export const TUI_PACKAGES = Object.freeze({
10
11
  "darwin-arm64": "@toolroll/tui-darwin-arm64", "darwin-x64": "@toolroll/tui-darwin-x64",
@@ -249,7 +250,8 @@ export async function runTuiBinary(input) {
249
250
  continue;
250
251
  }
251
252
  if (ask !== null && typeof ask === "object" && ask["want"] === "browser") {
252
- void input.session.openBrowser().catch(() => "The browser couldn't be opened.").then(said => {
253
+ const page = ask["page"];
254
+ void (isTuiPage(page) ? input.session.openBrowser(page) : input.session.openBrowser()).catch(() => "The browser couldn't be opened.").then(said => {
253
255
  if ("write" in asks && !child.killed && child.exitCode === null)
254
256
  asks.write(`${JSON.stringify({ said })}\n`);
255
257
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "toolroll",
3
- "version": "0.9.113",
3
+ "version": "0.9.114",
4
4
  "description": "Your agents build. You decide. A control plane for coding agents — Claude Code, Codex, Gemini: approve the exact scope once, get results back Ready with the diff, the passing check and screenshots. Runs on your machine.",
5
5
  "directories": {
6
6
  "doc": "docs"