@open-tomato/rafa 0.53.0 → 0.54.0

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.
@@ -220,7 +220,7 @@ var HINT_FLAG_SPEC = Object.freeze({
220
220
  });
221
221
  var DEFAULT_CI_TIMEOUT_MIN = 20;
222
222
  // package.json
223
- var version = "0.53.0";
223
+ var version = "0.54.0";
224
224
 
225
225
  // packages/rafa/src/core/command/version.ts
226
226
  var RAFA_VERSION = version;
@@ -296,6 +296,13 @@ function unquoteGitPath(raw) {
296
296
  }
297
297
  return new TextDecoder().decode(new Uint8Array(bytes));
298
298
  }
299
+ // packages/rafa/src/utils/shell.ts
300
+ var PLAIN_WORD = /^[A-Za-z0-9._:/-]+$/;
301
+ var QUOTE = "'";
302
+ var QUOTED_QUOTE = "'\\''";
303
+ function shellQuote(word) {
304
+ return PLAIN_WORD.test(word) ? word : QUOTE + word.split(QUOTE).join(QUOTED_QUOTE) + QUOTE;
305
+ }
299
306
  // packages/rafa/src/core/git/commit.ts
300
307
  import { spawnSync as spawnSync2 } from "child_process";
301
308
  var DEFAULT_COMMIT_TYPE = "chore";
@@ -667,4 +674,4 @@ function asHopRecord(value) {
667
674
  };
668
675
  }
669
676
 
670
- export { PORT_VERSIONS, createAdapterRegistry, registerAdapters, restoreAdapters, activeAdapterRegistry, CORE_ADAPTER_REGISTRY, CommandExit, commandSpelling, createLinePrompter, lazyPrompter, GLOBAL_FLAGS, runningCommand, HINT_FLAG, HINT_FLAG_SPEC, DEFAULT_CI_TIMEOUT_MIN, RAFA_VERSION, createGitRunner, gitSaid, parseWorkingTree, commitTaskWork, TRUSTED_PERMISSIONS, isRecord, asPlace, asHopRecord, PROJECT_ID_LENGTH, PROJECT_ID_PATTERN, normalizeRemote, gitRemoteUrl, setActiveStoreSettings, activeStoreSettings };
677
+ export { PORT_VERSIONS, createAdapterRegistry, registerAdapters, restoreAdapters, activeAdapterRegistry, CORE_ADAPTER_REGISTRY, CommandExit, commandSpelling, createLinePrompter, lazyPrompter, GLOBAL_FLAGS, runningCommand, HINT_FLAG, HINT_FLAG_SPEC, DEFAULT_CI_TIMEOUT_MIN, RAFA_VERSION, createGitRunner, gitSaid, parseWorkingTree, shellQuote, commitTaskWork, TRUSTED_PERMISSIONS, isRecord, asPlace, asHopRecord, PROJECT_ID_LENGTH, PROJECT_ID_PATTERN, normalizeRemote, gitRemoteUrl, setActiveStoreSettings, activeStoreSettings };
@@ -197,6 +197,27 @@ var CHECKS_SECTION = Object.freeze({
197
197
  defaults: CHECKS_DEFAULTS
198
198
  });
199
199
 
200
+ // packages/rafa/src/config-schema-collaborate.ts
201
+ var COLLABORATE_TOOLS = Object.freeze(["rafa"]);
202
+ var COLLABORATE_DEFAULTS = Object.freeze({
203
+ collaborateRafa: null
204
+ });
205
+ var REPOSITORY = /^[^/\s]+\/[^/\s]+$/u;
206
+ var REPOSITORY_EXPECTED = "a repository as owner/name, such as open-tomato/rafa";
207
+ var collaborateRepository = (raw, at) => typeof raw === "string" && REPOSITORY.test(raw) ? { value: raw, problems: [], extras: [] } : refused(at, raw, REPOSITORY_EXPECTED);
208
+ var COLLABORATE_SETTINGS = {
209
+ collaborateRafa: { key: "collaborate.rafa", read: collaborateRepository, cli: false }
210
+ };
211
+ var FIELD_OF = Object.freeze({
212
+ rafa: "collaborateRafa"
213
+ });
214
+ var COLLABORATE_SECTION = Object.freeze({
215
+ package: "collaborate",
216
+ settings: Object.freeze(COLLABORATE_SETTINGS),
217
+ defaults: COLLABORATE_DEFAULTS,
218
+ checks: Object.freeze([])
219
+ });
220
+
200
221
  // packages/rafa/src/config-schema-errors.ts
201
222
  var ERROR_CODE_KEYS = ["code", "description", "hint", "level", "since"];
202
223
  var KNOWN_KEYS = new Set(ERROR_CODE_KEYS);
@@ -278,6 +299,19 @@ var FEATURES_SECTION = Object.freeze({
278
299
  defaults: FEATURES_DEFAULTS
279
300
  });
280
301
 
302
+ // packages/rafa/src/config-schema-hints.ts
303
+ var HINTS_DEFAULTS = Object.freeze({
304
+ hintsSkills: false
305
+ });
306
+ var HINTS_SETTINGS = {
307
+ hintsSkills: { key: "hints.skills", read: flag, cli: false }
308
+ };
309
+ var HINTS_SECTION = Object.freeze({
310
+ package: "hints",
311
+ settings: Object.freeze(HINTS_SETTINGS),
312
+ defaults: HINTS_DEFAULTS
313
+ });
314
+
281
315
  // packages/rafa/src/config-schema-hub.ts
282
316
  var HUB_TIMEOUT_MIN_SECONDS = 1;
283
317
  var HUB_TIMEOUT_MAX_SECONDS = 30;
@@ -796,7 +830,9 @@ var CONFIG_SECTIONS = Object.freeze([
796
830
  ISSUES_SECTION,
797
831
  TESTS_SECTION,
798
832
  CHECKS_SECTION,
799
- FEATURES_SECTION
833
+ FEATURES_SECTION,
834
+ COLLABORATE_SECTION,
835
+ HINTS_SECTION
800
836
  ]);
801
837
  function handConfigToLogger(config) {
802
838
  setActiveLoggerSettings(loggerSettingsOf(config));
@@ -877,7 +913,9 @@ var CONFIG_DEFAULTS = Object.freeze({
877
913
  ...run(CORE_VALUES, CORE_TAIL),
878
914
  ...TESTS_DEFAULTS,
879
915
  ...CHECKS_DEFAULTS,
880
- ...FEATURES_DEFAULTS
916
+ ...FEATURES_DEFAULTS,
917
+ ...COLLABORATE_DEFAULTS,
918
+ ...HINTS_DEFAULTS
881
919
  });
882
920
  var SETTINGS = Object.freeze({
883
921
  ...run(CORE_SPECS, CORE_HEAD),
@@ -901,7 +939,9 @@ var SETTINGS = Object.freeze({
901
939
  ...run(CORE_SPECS, CORE_TAIL),
902
940
  ...TESTS_SETTINGS,
903
941
  ...CHECKS_SETTINGS,
904
- ...FEATURES_SETTINGS
942
+ ...FEATURES_SETTINGS,
943
+ ...COLLABORATE_SETTINGS,
944
+ ...HINTS_SETTINGS
905
945
  });
906
946
  var SETTING_NAMES = Object.freeze(Object.keys(SETTINGS));
907
947
  function inSettingOrder(sections, names) {
@@ -8,7 +8,7 @@ import {
8
8
  createGitRunner,
9
9
  normalizeRemote,
10
10
  runningCommand
11
- } from "./index-rkrsdes6.js";
11
+ } from "./index-8rr1etrx.js";
12
12
  import {
13
13
  activeOutput,
14
14
  activeOutputMode,
@@ -1446,6 +1446,28 @@ var SQLITE_MIGRATIONS = [
1446
1446
  ON bug_routes (origin_store, origin_seq)
1447
1447
  WHERE origin_store IS NOT NULL;
1448
1448
  `
1449
+ },
1450
+ {
1451
+ id: "reading-supersedes",
1452
+ breaks: [],
1453
+ sql: `
1454
+ CREATE TABLE reading_supersedes (
1455
+ seq INTEGER PRIMARY KEY,
1456
+ table_name TEXT NOT NULL CHECK (table_name <> ''),
1457
+ canonical_key TEXT NOT NULL CHECK (canonical_key <> ''),
1458
+ superseded_key TEXT NOT NULL CHECK (superseded_key <> ''),
1459
+ rule TEXT NOT NULL CHECK (rule <> ''),
1460
+ origin_store TEXT CHECK (origin_store <> ''),
1461
+ origin_seq INTEGER
1462
+ );
1463
+
1464
+ CREATE UNIQUE INDEX reading_supersedes_by_fact
1465
+ ON reading_supersedes (table_name, canonical_key, superseded_key);
1466
+
1467
+ CREATE UNIQUE INDEX reading_supersedes_by_origin
1468
+ ON reading_supersedes (origin_store, origin_seq)
1469
+ WHERE origin_store IS NOT NULL;
1470
+ `
1449
1471
  }
1450
1472
  ];
1451
1473
  var SQLITE_SCHEMA_VERSION = SQLITE_MIGRATIONS.length;
@@ -2112,6 +2134,7 @@ var MERGE_RULES = {
2112
2134
  plan_ci: appendOnly("pr", "head_sha", "read_at"),
2113
2135
  stale_docs: appendOnly("id"),
2114
2136
  bug_routes: appendOnly("id"),
2137
+ reading_supersedes: appendOnly("table_name", "canonical_key", "superseded_key"),
2115
2138
  schema_migrations: { scope: "local" },
2116
2139
  store_meta: { scope: "local" },
2117
2140
  store_replaced: { scope: "local" },
@@ -2344,6 +2367,7 @@ function rebuildAside(options) {
2344
2367
  }
2345
2368
 
2346
2369
  // packages/rafa/src/effort/store/wire.ts
2370
+ var WIRE_CONTRACT_VERSION = 1;
2347
2371
  var WIRE_FORMAT = "rafa-effort-wire";
2348
2372
  var WIRE_VERSION = 1;
2349
2373
 
@@ -2893,6 +2917,163 @@ function liveLoop(path, options, nothingDone = "Nothing was migrated.", ownSessi
2893
2917
  return records.find((record) => (record.state === "running" || record.state === "paused") && record.sessionId !== ownSessionId);
2894
2918
  }
2895
2919
 
2920
+ // packages/rafa/src/effort/store/repository-facts.ts
2921
+ var REPOSITORY_FACTS = {
2922
+ plan_ci: { facts: ["pr", "head_sha", "verdict", "failing"], time: "read_at" }
2923
+ };
2924
+ var SAME_FACT_RULE = "same-fact@1";
2925
+ var INSERT_SUPERSEDE = `
2926
+ INSERT INTO reading_supersedes (table_name, canonical_key, superseded_key, rule, ${STAMPED_COLUMNS})
2927
+ VALUES (?, ?, ?, ?, ${stampedValues("reading_supersedes")})
2928
+ ON CONFLICT (table_name, canonical_key, superseded_key) DO NOTHING
2929
+ `;
2930
+ var SUPERSEDED = `
2931
+ SELECT 1 AS held FROM reading_supersedes
2932
+ WHERE table_name = ? AND rule = ? AND superseded_key = ?
2933
+ LIMIT 1
2934
+ `;
2935
+ function refused2(table, reason) {
2936
+ return new Error(`effort store: repository facts of ${table} ${reason}`);
2937
+ }
2938
+ function factTableOf(table) {
2939
+ const columns = Object.hasOwn(REPOSITORY_FACTS, table) ? REPOSITORY_FACTS[table] : undefined;
2940
+ if (columns === undefined)
2941
+ throw refused2(table, "are not read: the table has no REPOSITORY_FACTS entry");
2942
+ const rule = MERGE_RULES[table];
2943
+ if (rule?.scope !== "merged")
2944
+ throw refused2(table, "are not read: the table is no merged table of MERGE_RULES");
2945
+ return { name: table, identity: rule.identity, facts: columns.facts, time: columns.time };
2946
+ }
2947
+ function jsonPart(table, column, value) {
2948
+ if (value === null || typeof value === "string")
2949
+ return value;
2950
+ if (typeof value === "number" && Number.isFinite(value))
2951
+ return value;
2952
+ throw refused2(table, `cannot name a reading by ${column}: its value is not text, a finite number or NULL`);
2953
+ }
2954
+ function encode(table, columns, row) {
2955
+ return JSON.stringify(columns.map((column) => jsonPart(table, column, row[column])));
2956
+ }
2957
+ function readingKey(table, row) {
2958
+ return encode(table, factTableOf(table).identity, row);
2959
+ }
2960
+ function decodeKey(shape, key) {
2961
+ let parsed;
2962
+ try {
2963
+ parsed = JSON.parse(key);
2964
+ } catch {
2965
+ parsed = undefined;
2966
+ }
2967
+ if (!Array.isArray(parsed) || parsed.length !== shape.identity.length) {
2968
+ throw refused2(shape.name, `cannot read key ${key}: not a JSON array of ${String(shape.identity.length)} identity values`);
2969
+ }
2970
+ return parsed.map((value, index) => jsonPart(shape.name, shape.identity[index] ?? "", value));
2971
+ }
2972
+ function selectedColumns(shape) {
2973
+ const columns = [...new Set([...shape.identity, ...shape.facts, shape.time])];
2974
+ return [...columns.map(quoted), "origin_store"].join(", ");
2975
+ }
2976
+ function readingsWhere(shape, columns) {
2977
+ const where = columns.map((column) => `${quoted(column)} IS ?`).join(" AND ");
2978
+ return `SELECT ${selectedColumns(shape)} FROM ${quoted(shape.name)} WHERE ${where}`;
2979
+ }
2980
+ function readingOf(shape, row) {
2981
+ const time = row[shape.time];
2982
+ if (typeof time !== "string")
2983
+ throw refused2(shape.name, `hold a reading whose ${shape.time} is not text`);
2984
+ const origin = row.origin_store;
2985
+ return {
2986
+ key: encode(shape.name, shape.identity, row),
2987
+ fact: Object.fromEntries(shape.facts.map((column) => [column, row[column] ?? null])),
2988
+ time,
2989
+ origin: typeof origin === "string" ? origin : null
2990
+ };
2991
+ }
2992
+ function readBefore(left, right) {
2993
+ if (left.time !== right.time)
2994
+ return left.time < right.time;
2995
+ return left.key < right.key;
2996
+ }
2997
+ function earliestOf(readings) {
2998
+ return readings.reduce((earliest, reading) => earliest === undefined || readBefore(reading, earliest) ? reading : earliest, undefined);
2999
+ }
3000
+ function writeSupersedes(db, table, touchedKeys) {
3001
+ const shape = factTableOf(table);
3002
+ const byKey = db.query(readingsWhere(shape, shape.identity));
3003
+ const byFact = db.query(readingsWhere(shape, shape.facts));
3004
+ const superseded = db.query(SUPERSEDED);
3005
+ const insert = db.query(INSERT_SUPERSEDE);
3006
+ const facts = new Map;
3007
+ for (const key of touchedKeys) {
3008
+ const row = byKey.get(...decodeKey(shape, key));
3009
+ if (row === null)
3010
+ throw refused2(table, `name no reading by key ${key}`);
3011
+ const reading = readingOf(shape, row);
3012
+ const fact = encode(table, shape.facts, row);
3013
+ if (!facts.has(fact))
3014
+ facts.set(fact, reading);
3015
+ }
3016
+ let added = 0;
3017
+ for (const touched of facts.values()) {
3018
+ const readings = byFact.all(...shape.facts.map((column) => touched.fact[column] ?? null)).map((row) => readingOf(shape, row));
3019
+ const canonical2 = earliestOf(readings) ?? touched;
3020
+ for (const reading of readings) {
3021
+ if (reading.key === canonical2.key)
3022
+ continue;
3023
+ if (superseded.get(table, SAME_FACT_RULE, reading.key) !== null)
3024
+ continue;
3025
+ added += insert.run(table, canonical2.key, reading.key, SAME_FACT_RULE).changes;
3026
+ }
3027
+ }
3028
+ return added;
3029
+ }
3030
+ function supersedeTargets(db, table, readings) {
3031
+ const rows = db.query("SELECT canonical_key, superseded_key FROM reading_supersedes WHERE table_name = ? AND rule = ? ORDER BY seq").all(table, SAME_FACT_RULE);
3032
+ const targets = new Map;
3033
+ for (const { canonical_key: canonicalKey, superseded_key: supersededKey } of rows) {
3034
+ const canonical2 = readings.get(canonicalKey);
3035
+ if (canonical2 === undefined || !readings.has(supersededKey) || canonicalKey === supersededKey)
3036
+ continue;
3037
+ targets.set(supersededKey, [...targets.get(supersededKey) ?? [], canonical2]);
3038
+ }
3039
+ return targets;
3040
+ }
3041
+ function chainEnd(start, targets) {
3042
+ const path = [start];
3043
+ for (;; ) {
3044
+ const current = path[path.length - 1] ?? start;
3045
+ const next = earliestOf(targets.get(current.key) ?? []);
3046
+ if (next === undefined)
3047
+ return current;
3048
+ const seen = path.findIndex(({ key }) => key === next.key);
3049
+ if (seen >= 0)
3050
+ return earliestOf(path.slice(seen)) ?? next;
3051
+ path.push(next);
3052
+ }
3053
+ }
3054
+ function factOf(table, canonical2, readings) {
3055
+ const origins = [...new Set(readings.flatMap(({ origin }) => origin === null ? [] : [origin]))].sort();
3056
+ const lastSighting = readings.reduce((latest, { time }) => time > latest ? time : latest, canonical2.time);
3057
+ return { table, canonical: canonical2, sightings: readings.length - 1, origins, lastSighting };
3058
+ }
3059
+ function readRepositoryFacts(db, table) {
3060
+ const shape = factTableOf(table);
3061
+ const rows = db.query(`SELECT ${selectedColumns(shape)} FROM ${quoted(table)}`).all();
3062
+ const readings = new Map(rows.map((row) => {
3063
+ const reading = readingOf(shape, row);
3064
+ return [reading.key, reading];
3065
+ }));
3066
+ const targets = supersedeTargets(db, table, readings);
3067
+ const groups = new Map;
3068
+ for (const reading of readings.values()) {
3069
+ const canonical2 = chainEnd(reading, targets);
3070
+ const group = groups.get(canonical2.key) ?? { canonical: canonical2, readings: [] };
3071
+ group.readings.push(reading);
3072
+ groups.set(canonical2.key, group);
3073
+ }
3074
+ return [...groups.values()].sort((left, right) => readBefore(left.canonical, right.canonical) ? -1 : 1).map(({ canonical: canonical2, readings: grouped }) => factOf(table, canonical2, grouped));
3075
+ }
3076
+
2896
3077
  // packages/rafa/src/effort/store/merge-store.ts
2897
3078
  var MOVE_TO_SQLITE = "rafa effort move --to=sqlite";
2898
3079
 
@@ -2906,6 +3087,7 @@ class MergeRefusal extends RebuildRefusal {
2906
3087
  }
2907
3088
  var LIVE = "live";
2908
3089
  var MERGES_TABLE = "merges";
3090
+ var SUPERSEDES_TABLE = "reading_supersedes";
2909
3091
  var INSERT_MERGE = `INSERT INTO merges (id, other_store, merged_at, rows_added, rows_skipped, rows_in_conflict)
2910
3092
  VALUES (?, ?, ?, ?, ?, ?)`;
2911
3093
  var NOTHING_MERGED = "Nothing was merged.";
@@ -2994,16 +3176,31 @@ function openOther(otherPath, plan, stamp, tempRoot) {
2994
3176
  throw error;
2995
3177
  }
2996
3178
  }
3179
+ function addedKeys(db, { table, added }) {
3180
+ const columns = carriedColumns(db, table).map(quoted).join(", ");
3181
+ const bySeq = db.query(`SELECT ${columns} FROM ${quoted(table)} WHERE seq = ?`);
3182
+ return added.map((seq) => {
3183
+ const row = bySeq.get(seq);
3184
+ if (row === null)
3185
+ throw new Error(`effort store: the merge added ${table} row ${String(seq)} and cannot read it back`);
3186
+ return readingKey(table, row);
3187
+ });
3188
+ }
3189
+ function writeMergedSupersedes(db, unions) {
3190
+ return unions.filter((union) => Object.hasOwn(REPOSITORY_FACTS, union.table) && union.added.length > 0).reduce((written, union) => written + writeSupersedes(db, union.table, addedKeys(db, union)), 0);
3191
+ }
2997
3192
  function mergeInto(db, other, mergeId, otherStore, mergedAt) {
2998
3193
  return db.transaction(() => {
2999
3194
  const unions = unionStores(db, other);
3000
3195
  const settlements = settleMatches(db, other, unions, { mergeId, recordedAt: mergedAt });
3001
3196
  const gaps = recomputeCommitGaps(db, unions.find(({ table }) => table === "commits")?.added ?? []);
3197
+ const supersedes = writeMergedSupersedes(db, unions);
3002
3198
  const tables = unions.map((union, index) => {
3003
3199
  const settled = settlements[index];
3200
+ const written = union.table === SUPERSEDES_TABLE ? supersedes : 0;
3004
3201
  return {
3005
3202
  table: union.table,
3006
- added: union.added.length,
3203
+ added: union.added.length + written,
3007
3204
  skipped: settled?.skipped.length ?? 0,
3008
3205
  inConflict: settled?.conflicts.length ?? 0,
3009
3206
  filled: settled?.filled.length ?? 0,
@@ -3133,4 +3330,4 @@ function selectEffortStore(repoRoot, config) {
3133
3330
  return adapter.create({ repoRoot });
3134
3331
  }
3135
3332
 
3136
- export { storedLogPath, ACROSS_STORES_ORDER, STAMPED_COLUMNS, stampedValues, SessionRecordError, isSessionId, sessionSteps, sessionDecisions, SessionConflictError, runsDir, sessionFilePath, errorCode, isPidAlive, readSessions, readSession, samePlan, beginSession, updateSession, SESSION_ID_FLAG, claudeArgs, interruptClaudeSessions, spawnClaude, runClaude, spawnClaudeCaptured, runClaudeCaptured, RUNTIME_SUBDIR, EFFORT_DIR_VARIABLE, effortStoreDir, guardTestProcess, DEVELOPMENT_NEXT_STEP, DevelopmentBuildRefusedError, refuseUnownedDevelopmentWrite, SQLITE_MIGRATIONS, sqliteCatalogue, planSchema, readStoreSchema, writeNames, readReplacedStoreIds, readStoreMeta, EFFORT_KEY_PROJECTIONS, SQLITE_STORE_FILE_NAME, sqliteStorePath, LONE_SURROGATE, withSqliteStore, writeSqliteStore, openSqliteStore, copyEffortStore, WIRE_FORMAT, WIRE_VERSION, WireFormatError, WireExportRefusal, encodeWirePayload, decodeWirePayload, exportWirePayload, materialiseWirePayload, minutesBetween, MOVE_TO_SQLITE, mergeStore, openNdjsonStore, selectEffortStore };
3333
+ export { storedLogPath, ACROSS_STORES_ORDER, STAMPED_COLUMNS, stampedValues, SessionRecordError, isSessionId, sessionSteps, sessionDecisions, SessionConflictError, runsDir, sessionFilePath, errorCode, isPidAlive, readSessions, readSession, samePlan, beginSession, updateSession, SESSION_ID_FLAG, claudeArgs, interruptClaudeSessions, spawnClaude, runClaude, spawnClaudeCaptured, runClaudeCaptured, RUNTIME_SUBDIR, EFFORT_DIR_VARIABLE, effortStoreDir, guardTestProcess, DEVELOPMENT_NEXT_STEP, DevelopmentBuildRefusedError, refuseUnownedDevelopmentWrite, SQLITE_MIGRATIONS, sqliteCatalogue, planSchema, readStoreSchema, writeNames, readReplacedStoreIds, readStoreMeta, EFFORT_KEY_PROJECTIONS, SQLITE_STORE_FILE_NAME, sqliteStorePath, LONE_SURROGATE, withSqliteStore, writeSqliteStore, openSqliteStore, copyEffortStore, WIRE_CONTRACT_VERSION, WIRE_FORMAT, WIRE_VERSION, WireFormatError, WireExportRefusal, encodeWirePayload, decodeWirePayload, exportWirePayload, materialiseWirePayload, minutesBetween, readingKey, readRepositoryFacts, MOVE_TO_SQLITE, mergeStore, openNdjsonStore, selectEffortStore };