@marktiderman/genesis-cli 1.26.1 → 1.27.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.
package/dist/doctor.js CHANGED
@@ -284,8 +284,11 @@ var init_model = __esm({
284
284
  });
285
285
 
286
286
  // src/introspect/postgres.ts
287
- function where(sql, scope) {
288
- return "schemas" in scope ? sql`n.nspname = any(${scope.schemas})` : sql`c.oid = any(${scope.oids}::oid[])`;
287
+ function where(scope) {
288
+ return "schemas" in scope ? { condition: "n.nspname = any(array(select jsonb_array_elements_text($1::text::jsonb)))", param: JSON.stringify(scope.schemas) } : { condition: "c.oid = any(array(select jsonb_array_elements_text($1::text::jsonb)::oid))", param: JSON.stringify(scope.oids) };
289
+ }
290
+ async function read(sql, text, param) {
291
+ return [...await sql.unsafe(text, [param])];
289
292
  }
290
293
  function linkOf(columns, refColumns, refUnique = []) {
291
294
  if (columns.length === 1) return 0;
@@ -294,7 +297,8 @@ function linkOf(columns, refColumns, refUnique = []) {
294
297
  return own.length === 1 && refUnique[own[0]] === true ? own[0] : -1;
295
298
  }
296
299
  async function readRelations(sql, scope, into) {
297
- const columns = await sql`
300
+ const { condition, param } = where(scope);
301
+ const columns = await read(sql, `
298
302
  select c.oid::text as oid, c.relkind::text as relkind, n.nspname as schema, c.relname as table,
299
303
  obj_description(c.oid, 'pg_class') as table_comment,
300
304
  a.attnum::int as attnum,
@@ -313,17 +317,17 @@ async function readRelations(sql, scope, into) {
313
317
  join pg_attribute a on a.attrelid = c.oid and a.attnum > 0 and not a.attisdropped
314
318
  join pg_type t on t.oid = a.atttypid
315
319
  where c.relkind in ('r', 'p', 'v', 'm', 'f')
316
- and ${where(sql, scope)}
317
- order by n.nspname, c.relname, a.attnum`;
318
- const keys = await sql`
320
+ and ${condition}
321
+ order by n.nspname, c.relname, a.attnum`, param);
322
+ const keys = await read(sql, `
319
323
  select c.oid::text as oid, array_agg(k.attnum::int order by k.ord) as columns
320
324
  from pg_constraint con
321
325
  join pg_class c on c.oid = con.conrelid
322
326
  join pg_namespace n on n.oid = c.relnamespace
323
327
  cross join lateral unnest(con.conkey) with ordinality as k(attnum, ord)
324
- where con.contype = 'p' and ${where(sql, scope)}
325
- group by c.oid`;
326
- const links = await sql`
328
+ where con.contype = 'p' and ${condition}
329
+ group by c.oid`, param);
330
+ const links = await read(sql, `
327
331
  select c.oid::text as oid, con.conkey::int[] as attnums,
328
332
  array(select a.attname::text from unnest(con.conkey) with ordinality k(attnum, ord)
329
333
  join pg_attribute a on a.attrelid = c.oid and a.attnum = k.attnum order by k.ord) as columns,
@@ -340,9 +344,9 @@ async function readRelations(sql, scope, into) {
340
344
  join pg_class rc on rc.oid = con.confrelid
341
345
  join pg_namespace rn on rn.oid = rc.relnamespace
342
346
  where con.contype = 'f'
343
- and ${where(sql, scope)}
344
- order by con.conname`;
345
- const checks = await sql`
347
+ and ${condition}
348
+ order by con.conname`, param);
349
+ const checks = await read(sql, `
346
350
  select c.oid::text as oid, con.conkey[1]::int as attnum, a.attname as column,
347
351
  pg_get_constraintdef(con.oid) as definition
348
352
  from pg_constraint con
@@ -350,9 +354,9 @@ async function readRelations(sql, scope, into) {
350
354
  join pg_namespace n on n.oid = c.relnamespace
351
355
  join pg_attribute a on a.attrelid = c.oid and a.attnum = con.conkey[1]
352
356
  where con.contype = 'c' and array_length(con.conkey, 1) = 1
353
- and ${where(sql, scope)}
354
- order by con.conname`;
355
- const views = await sql`
357
+ and ${condition}
358
+ order by con.conname`, param);
359
+ const views = await read(sql, `
356
360
  select c.oid::text as oid, r.ev_action::text as ev_action
357
361
  from pg_class c
358
362
  join pg_namespace n on n.oid = c.relnamespace
@@ -360,7 +364,7 @@ async function readRelations(sql, scope, into) {
360
364
  where c.relkind = 'v'
361
365
  and (pg_relation_is_updatable(c.oid, false) & 20) = 20
362
366
  and not exists (select 1 from pg_rewrite o where o.ev_class = c.oid and o.rulename <> '_RETURN')
363
- and ${where(sql, scope)}`;
367
+ and ${condition}`, param);
364
368
  const added = [];
365
369
  for (const row of columns) {
366
370
  let relation = into.get(row.oid);
@@ -3818,7 +3822,7 @@ function createTrail(ctx) {
3818
3822
  declared = null;
3819
3823
  }
3820
3824
  const byPath = new Map(ctx.files.map((f) => [f.absolutePath, f]));
3821
- const read2 = (abs) => byPath.get(abs) ?? readSource(abs);
3825
+ const read3 = (abs) => byPath.get(abs) ?? readSource(abs);
3822
3826
  const importsCache = /* @__PURE__ */ new Map();
3823
3827
  const importsOf = (file) => {
3824
3828
  const hit = importsCache.get(file.absolutePath);
@@ -3895,7 +3899,7 @@ function createTrail(ctx) {
3895
3899
  cut.add(abs);
3896
3900
  continue;
3897
3901
  }
3898
- const target = read2(abs);
3902
+ const target = read3(abs);
3899
3903
  if (!target) {
3900
3904
  unknown = true;
3901
3905
  continue;
@@ -6559,7 +6563,7 @@ function sourceSchemas(source) {
6559
6563
  return schemas?.length ? schemas : null;
6560
6564
  }
6561
6565
  var lf = (text) => text.replace(/\r\n/g, "\n");
6562
- async function checkContracts(ctx, read2 = postgresContract) {
6566
+ async function checkContracts(ctx, read3 = postgresContract) {
6563
6567
  const settings = ctx.config.contracts;
6564
6568
  if (!settings) return;
6565
6569
  const out = settings.out ?? DEFAULT_CONTRACT_OUT;
@@ -6583,7 +6587,7 @@ async function checkContracts(ctx, read2 = postgresContract) {
6583
6587
  }
6584
6588
  let expected;
6585
6589
  try {
6586
- expected = lf((await read2(url, schemas)).content);
6590
+ expected = lf((await read3(url, schemas)).content);
6587
6591
  } catch (err) {
6588
6592
  const generation = err.name === "EmitError";
6589
6593
  const message = err.message.split("\n")[0];
@@ -6601,7 +6605,7 @@ async function checkContracts(ctx, read2 = postgresContract) {
6601
6605
  }
6602
6606
  }
6603
6607
  var GENESIS_DOCS = "https://github.com/marktiderman/genesis/blob/main/docs";
6604
- var read = (file) => existsSync(file) ? readFileSync(file, "utf8") : null;
6608
+ var read2 = (file) => existsSync(file) ? readFileSync(file, "utf8") : null;
6605
6609
  var CLAUDE_IMPORT = "@AGENTS.md\n";
6606
6610
  function pathTaken(file) {
6607
6611
  try {
@@ -6754,7 +6758,7 @@ function packageGuides(root, packages) {
6754
6758
  const guides = [];
6755
6759
  for (const p of packages) {
6756
6760
  const stable = p.local ? path21.join(p.dir, "SKILL.md") : stableGuidePath(root, p);
6757
- const text = stable === null ? null : read(stable);
6761
+ const text = stable === null ? null : read2(stable);
6758
6762
  if (stable === null || text === null) continue;
6759
6763
  const description = skillDescription(text);
6760
6764
  const at = description.indexOf("Load before");
@@ -6846,11 +6850,11 @@ function writeAgentGuide(root, packages, agentsFile = "AGENTS.md") {
6846
6850
  const guides = packageGuides(root, packages);
6847
6851
  const changed = [];
6848
6852
  const agents = path21.join(root, agentsFile);
6849
- const before = read(agents);
6853
+ const before = read2(agents);
6850
6854
  const after = mergeAgentsBlock(before, renderAgentsBlock(rows, guides));
6851
6855
  const skill = path21.join(root, SKILL_PATH);
6852
6856
  const skillText = renderSkill(rows, guides);
6853
- if (read(skill)?.replace(/\r\n/g, "\n") !== skillText) {
6857
+ if (read2(skill)?.replace(/\r\n/g, "\n") !== skillText) {
6854
6858
  mkdirSync(path21.dirname(skill), { recursive: true });
6855
6859
  writeFileSync(skill, skillText);
6856
6860
  changed.push(SKILL_PATH);
@@ -6890,8 +6894,8 @@ function claudeState(root) {
6890
6894
  function agentGuideState(root, packages, agentsFile = "AGENTS.md") {
6891
6895
  const rows = primitivesCatalog(packages);
6892
6896
  const guides = packageGuides(root, packages);
6893
- const skill = read(path21.join(root, SKILL_PATH))?.replace(/\r\n/g, "\n") ?? null;
6894
- const block = currentAgentsBlock(read(path21.join(root, agentsFile)));
6897
+ const skill = read2(path21.join(root, SKILL_PATH))?.replace(/\r\n/g, "\n") ?? null;
6898
+ const block = currentAgentsBlock(read2(path21.join(root, agentsFile)));
6895
6899
  return {
6896
6900
  skill: skill === null ? "missing" : skill === renderSkill(rows, guides) ? "ok" : "stale",
6897
6901
  agents: block === null || block === "broken" ? block ?? "missing" : block === renderAgentsBlock(rows, guides) ? "ok" : "stale",