Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

6.4 KB
Raw Blame
// screenpipe — AI that knows everything you've seen, said, or heard
// https://screenpipe.com

import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
import { basename, dirname, join, resolve } from "node:path";
import { fileURLToPath } from "node:url";

const __dirname = dirname(fileURLToPath(import.meta.url));
const repoRoot = resolve(__dirname, "../..");
const docsRoot = join(__dirname, "docs-mintlify-mig-tmp");
const publicRoot = join(docsRoot, "public");
const docsJsonPath = join(docsRoot, "docs.json");
const openApiPath = join(docsRoot, "openapi.yaml");
const connectionRefPath = join(docsRoot, "connection-reference.mdx");
const connectionsCodeRoot = join(
  repoRoot,
  "crates/screenpipe-connect/src/connections",
);

const errors = [];

function fail(message) {
  errors.push(message);
}

function walk(dir, predicate, out = []) {
  for (const entry of readdirSync(dir)) {
    const path = join(dir, entry);
    const stat = statSync(path);
    if (stat.isDirectory()) {
      walk(path, predicate, out);
    } else if (!predicate || predicate(path)) {
      out.push(path);
    }
  }
  return out;
}

function read(path) {
  return readFileSync(path, "utf8");
}

const docsJson = JSON.parse(read(docsJsonPath));
function checkLabel(value, location) {
  // Preserve proper names that intentionally begin with a lowercase letter.
  if (/^[a-z]/.test(value) && !/^(macOS|iOS|iMessage)\b/.test(value)) {
    fail(`${location}: use sentence case in source copy: ${value}`);
  }
  if (/(?<![.\w/-])(?:ai|api|mcp|cli|ocr|crm|faq|screenpipe|chatgpt|github|macos)\b/.test(value)) {
    fail(`${location}: preserve product names and acronym casing: ${value}`);
  }
}

if (docsJson.icons?.library !== "lucide") {
  fail("docs.json: use the shared Lucide icon library");
}
checkLabel(docsJson.name, "docs.json name");
for (const link of docsJson.navbar?.links ?? []) {
  checkLabel(link.label, "docs.json navbar");
}
checkLabel(docsJson.navbar.primary.label, "docs.json primary action");
for (const mode of ["light", "dark"]) {
  const logo = docsJson.logo?.[mode];
  if (!logo || !existsSync(join(docsRoot, logo.replace(/^\//, "")))) {
    fail(`docs.json: missing ${mode} logo asset`);
  }
}
const mdxFiles = walk(docsRoot, (path) => path.endsWith(".mdx"));
const mdxSlugs = new Set(
  mdxFiles.map((path) => basename(path, ".mdx")),
);

const navPages = new Set();
for (const tab of docsJson.navigation?.tabs ?? []) {
  checkLabel(tab.tab, "docs.json tab");
  for (const group of tab.groups ?? []) {
    checkLabel(group.group, "docs.json group");
    for (const page of group.pages ?? []) {
      navPages.add(page);
    }
  }
}

for (const page of navPages) {
  if (!mdxSlugs.has(page)) {
    fail(`docs.json references missing page: ${page}`);
  }
}

for (const slug of mdxSlugs) {
  if (!navPages.has(slug)) {
    fail(`MDX page is not in docs.json navigation: ${slug}`);
  }
}

for (const file of mdxFiles) {
  const source = read(file);
  const rel = file.slice(repoRoot.length + 1);
  const frontmatter = source.match(/^---\n([\s\S]*?)\n---/);
  if (!frontmatter) {
    fail(`${rel}: missing frontmatter`);
    continue;
  }
  if (!/^title:\s*.+/m.test(frontmatter[1])) {
    fail(`${rel}: missing title frontmatter`);
  }
  if (!/^description:\s*.+/m.test(frontmatter[1])) {
    fail(`${rel}: missing description frontmatter`);
  }
  for (const field of ["title", "sidebarTitle", "description"]) {
    const value = frontmatter[1].match(new RegExp(`^${field}:\\s*["'](.+)["']$`, "m"))?.[1];
    if (value) checkLabel(value, `${rel} ${field}`);
  }
  const icon = frontmatter[1].match(/^icon:\s*["']([^"']+)["']/m)?.[1];
  if (!icon) {
    fail(`${rel}: missing navigation icon`);
  } else if (!/^[a-z][a-z0-9-]*$/.test(icon)) {
    fail(`${rel}: use a named Lucide icon for consistent navigation`);
  }

  const linkRegex = /(?:href|src)=["'](\/[^"']+)["']|\]\((\/[^)]+)\)/g;
  for (const match of source.matchAll(linkRegex)) {
    const raw = match[1] ?? match[2];
    const target = raw.split("#")[0].split("?")[0];
    if (!target || target === "/") continue;
    if (target.startsWith("/api/")) continue;
    if (target.startsWith("/_")) continue;

    const slug = target.replace(/^\//, "");
    const assetPath = join(publicRoot, slug);
    const rootAssetPath = join(docsRoot, slug);
    if (mdxSlugs.has(slug)) continue;
    if (existsSync(assetPath)) continue;
    if (existsSync(rootAssetPath)) continue;

    fail(`${rel}: internal link does not resolve: ${raw}`);
  }

  const imgTagRegex = /<img\b[^>]*>/g;
  for (const match of source.matchAll(imgTagRegex)) {
    const tag = match[0];
    const src = tag.match(/\bsrc=["']([^"']+)["']/)?.[1];
    if (!src) continue;

    if (src.startsWith("/app-screenshots/")) {
      fail(`${rel}: app screenshot images must use https://docs.screenpi.pe/public/app-screenshots/... because Mintlify emits broken raw S3 URLs for ${src}`);
      continue;
    }

    if (src.startsWith("https://docs.screenpi.pe/public/app-screenshots/")) {
      const asset = src.replace("https://docs.screenpi.pe/public/", "");
      if (!existsSync(join(publicRoot, asset))) {
        fail(`${rel}: app screenshot image does not exist locally: ${src}`);
      }
      if (!/\bwidth=["'][0-9]+["']/.test(tag)) {
        fail(`${rel}: app screenshot image must include a width attribute: ${src}`);
      }
    }
  }
}

const openApi = read(openApiPath);
const apiPathCount = (openApi.match(/^  \/[^:\n]+:/gm) ?? []).length;
if (apiPathCount < 50) {
  fail(`openapi.yaml route count looks too low: ${apiPathCount}`);
}

const connectionRef = read(connectionRefPath).toLowerCase();
const connectionFiles = walk(connectionsCodeRoot, (path) => (
  path.endsWith(".rs") && basename(path) !== "mod.rs"
));

let connectionCount = 0;
for (const file of connectionFiles) {
  const source = read(file);
  const name = source.match(/name:\s*"([^"]+)"/)?.[1];
  const id = source.match(/id:\s*"([^"]+)"/)?.[1];
  if (!name || !id) continue;
  connectionCount += 1;
  if (!connectionRef.includes(name.toLowerCase())) {
    fail(`connection-reference.mdx does not mention integration: ${name} (${id})`);
  }
}

if (connectionCount < 50) {
  fail(`connection registry count looks too low: ${connectionCount}`);
}

if (errors.length) {
  console.error("docs validation failed:");
  for (const error of errors) {
    console.error(`- ${error}`);
  }
  process.exit(1);
}

console.log(`docs validation passed: ${mdxFiles.length} pages, ${apiPathCount} API paths, ${connectionCount} connections`);