Docs/Skills and code/src/

src/stages/06-import-reference-channels.js

Code62 lines2.0 KBsrc/

import { getDb } from "../db.js";
import { ensureResearchSchema } from "../analysis/research-schema.js";
import { config } from "../../config.js";

const seeds = config.ecosystem.referenceChannels ?? [];
const db = getDb();
ensureResearchSchema();
const now = new Date().toISOString();

const findByHandle = db.prepare(`
  SELECT channel_url, name FROM channels
  WHERE lower(channel_url) LIKE lower(?)
  LIMIT 1
`);
const insertChannel = db.prepare(`
  INSERT OR IGNORE INTO channels (channel_url, name, discovered_at)
  VALUES (?, ?, ?)
`);
const annotate = db.prepare(`
  INSERT INTO editorial_annotations (
    object_type, object_id, important, editorial_status,
    reasons_json, note, source, updated_at
  ) VALUES ('channel', ?, 1, 'unknown', ?, ?, 'human_reference_set', ?)
  ON CONFLICT(object_type, object_id) DO UPDATE SET
    important = 1,
    reasons_json = excluded.reasons_json,
    source = 'human_reference_set',
    updated_at = excluded.updated_at
`);

let found = 0;
let inserted = 0;
const tx = db.transaction(() => {
  for (const seed of seeds) {
    const fragment = `%@${seed.handle.toLowerCase()}%`;
    let channel = findByHandle.get(fragment);
    if (channel) {
      found++;
    } else {
      const url = `https://www.youtube.com/@${seed.handle}`;
      insertChannel.run(url, seed.name, now);
      channel = { channel_url: url, name: seed.name };
      if (db.prepare("SELECT 1 FROM channels WHERE channel_url = ?").get(url)) inserted++;
      console.log(`[reference-seed] Added missing channel shell: ${seed.name} (${url})`);
    }
    annotate.run(
      channel.channel_url,
      JSON.stringify(["human_reference_set"]),
      "Selected by the user as a reference channel; relevance/role still requires analysis.",
      now
    );
  }
});
tx();
console.log("\n[reference-seed] Complete", {
  seedCount: seeds.length,
  matchedExisting: found,
  insertedShells: inserted,
  ecosystem: config.ecosystem.name,
  note: "New shells contain no fetched metadata/videos yet; run channel enrichment/discovery next."
});

Shown as it is in the repository at build time (2026-11-03); the home directory appears as <home>. If this page and the file differ, the file is right. Back to the catalogue.