Skip to content

armgit / pibot

Public Imported from GitHub
0

Open-source, local-first AI agent team for your desktop: multi-agent group chats, computer use, browser, MCP, routines and approvals. macOS, Windows, Linux + Android. Built on pi.

1.5 KB
Raw Blame
// Keeps CLAUDE.md as a copy of AGENTS.md (the public contributor guide) plus the lines below.
// Edit AGENTS.md, then run `pnpm sync:agents`. `--check` exits non-zero when CLAUDE.md is out of
// date (wired into `pnpm lint`). The private development repository adds AGENTS.internal.md and
// CLAUDE.internal.md; Claude Code loads them through the @-imports when they exist.
import { readFileSync, writeFileSync } from "node:fs";
import { fileURLToPath } from "node:url";

const root = new URL("..", import.meta.url);
const agents = readFileSync(new URL("AGENTS.md", root), "utf8").trimEnd();

const HEADER = `<!-- Generated by scripts/sync-agent-docs.mjs from AGENTS.md; do not edit by hand.
     Edit AGENTS.md (or the notes in the script), then run pnpm sync:agents. -->`;

const CLAUDE_ONLY = `## Claude Code

- This file is AGENTS.md plus these notes. To change the rules, edit AGENTS.md and run
  \`pnpm sync:agents\`.
- When the private development repository is checked out, its rules load here as well:

@AGENTS.internal.md
@CLAUDE.internal.md`;

const expected = `${HEADER}\n\n${agents.replace(/^# AGENTS\.md\n/, "# CLAUDE.md\n")}\n\n${CLAUDE_ONLY}\n`;
const target = fileURLToPath(new URL("CLAUDE.md", root));

if (process.argv.includes("--check")) {
  const current = readFileSync(target, "utf8");
  if (current !== expected) {
    console.error("CLAUDE.md is out of sync with AGENTS.md. Run: pnpm sync:agents");
    process.exit(1);
  }
} else {
  writeFileSync(target, expected);
  console.log("CLAUDE.md synced from AGENTS.md");
}