Skip to content

zenstory-ai/oh-story-claudecode / skills/story-setup

story-setup

Unverified

网文写作工具集基础设施部署与检查。为 Claude Code / OpenCode / Codex / Google Antigravity / ZCode / OpenClaw / Reasonix 提供内置适配;Web AI / 通用 Agent 可走 skills + AGENTS.md 文件模式。触发方式:/story-setup、$story-setup、「准备写书」「帮我搭一下环境」「配置写作项目」「检查写作环境」。

FileKindSize
SKILL.mdskill md16.7 KB
UPGRADING.mdmarkdown17.4 KB
references/agent-references/agent-quality.mdmarkdown3.7 KB
references/agent-references/agent-reference-profiles.mdmarkdown4.3 KB
references/agent-references/banned-words.mdmarkdown10.9 KB
references/agent-references/benchmark-style-load.mdmarkdown10.1 KB
references/agent-references/character-basics.mdmarkdown12.3 KB
references/agent-references/character-relations.mdmarkdown10.2 KB
references/agent-references/cross-book-recall.mdmarkdown3.9 KB
references/agent-references/deslop-gates.mdmarkdown2.3 KB
references/agent-references/dialogue-mastery.mdmarkdown11.0 KB
references/agent-references/expression.mdmarkdown9.6 KB
references/agent-references/female-audience-writing.mdmarkdown7.5 KB
references/agent-references/format-and-structure.mdmarkdown8.0 KB
references/agent-references/genre-prose-cards.mdmarkdown7.0 KB
references/agent-references/genre-prose-cards/东方仙侠.mdmarkdown2.3 KB
references/agent-references/genre-prose-cards/传统玄幻.mdmarkdown1.9 KB
references/agent-references/genre-prose-cards/历史古代.mdmarkdown1.7 KB
references/agent-references/genre-prose-cards/历史脑洞.mdmarkdown2.0 KB
references/agent-references/genre-prose-cards/双男主.mdmarkdown2.3 KB
references/agent-references/genre-prose-cards/古言脑洞.mdmarkdown1.8 KB
references/agent-references/genre-prose-cards/古风世情.mdmarkdown2.3 KB
references/agent-references/genre-prose-cards/女频悬疑.mdmarkdown1.8 KB
references/agent-references/genre-prose-cards/女频种田.mdmarkdown1.8 KB
references/agent-references/genre-prose-cards/宫斗宅斗.mdmarkdown1.6 KB
references/agent-references/genre-prose-cards/年代.mdmarkdown2.1 KB
references/agent-references/genre-prose-cards/快穿.mdmarkdown1.9 KB
references/agent-references/genre-prose-cards/悬疑灵异.mdmarkdown1.7 KB
references/agent-references/genre-prose-cards/悬疑脑洞.mdmarkdown1.9 KB
references/agent-references/genre-prose-cards/战神赘婿.mdmarkdown1.9 KB
references/agent-references/genre-prose-cards/抗战谍战.mdmarkdown1.8 KB
references/agent-references/genre-prose-cards/星光璀璨.mdmarkdown1.8 KB
references/agent-references/genre-prose-cards/民国言情.mdmarkdown1.9 KB
references/agent-references/genre-prose-cards/流派兜底.mdmarkdown8.4 KB
references/agent-references/genre-prose-cards/游戏体育.mdmarkdown1.9 KB
references/agent-references/genre-prose-cards/玄幻脑洞.mdmarkdown2.0 KB
references/agent-references/genre-prose-cards/玄幻言情.mdmarkdown1.7 KB
references/agent-references/genre-prose-cards/现言脑洞.mdmarkdown1.8 KB
references/agent-references/genre-prose-cards/科幻末世.mdmarkdown1.7 KB
references/agent-references/genre-prose-cards/职场婚恋.mdmarkdown1.7 KB
references/agent-references/genre-prose-cards/西方奇幻.mdmarkdown1.9 KB
references/agent-references/genre-prose-cards/豪门总裁.mdmarkdown2.3 KB
references/agent-references/genre-prose-cards/都市修真.mdmarkdown1.7 KB
references/agent-references/genre-prose-cards/都市日常.mdmarkdown2.8 KB
references/agent-references/genre-prose-cards/都市种田.mdmarkdown1.7 KB
references/agent-references/genre-prose-cards/都市脑洞.mdmarkdown2.4 KB
references/agent-references/genre-prose-cards/都市高武.mdmarkdown2.0 KB
references/agent-references/genre-prose-cards/青春甜宠.mdmarkdown1.8 KB
references/agent-references/genre-readers.mdmarkdown6.9 KB
references/agent-references/long-chapter-hooks.mdmarkdown6.5 KB
references/agent-references/long-emotional-methods.mdmarkdown7.9 KB
references/agent-references/long-genre-catalog.mdmarkdown11.9 KB
references/agent-references/long-genre-mechanics.mdmarkdown8.3 KB
references/agent-references/long-quality.mdmarkdown3.2 KB
references/agent-references/long-reversal.mdmarkdown12.3 KB
references/agent-references/long-suspense.mdmarkdown9.2 KB
references/agent-references/narrative-focus.mdmarkdown6.7 KB
references/agent-references/opening-design.mdmarkdown4.5 KB
references/agent-references/outline-methods.mdmarkdown12.5 KB
references/agent-references/plot-core-methods.mdmarkdown5.3 KB
references/agent-references/short-chapter-hooks.mdmarkdown8.0 KB
references/agent-references/short-emotional-methods.mdmarkdown4.6 KB
references/agent-references/short-genre-formulas.mdmarkdown18.8 KB
references/agent-references/short-quality.mdmarkdown2.8 KB
references/agent-references/short-reversal.mdmarkdown12.7 KB
references/agent-references/story-logic.mdmarkdown5.9 KB
references/agent-references/style-combat-face.mdmarkdown9.1 KB
references/agent-references/style-resolution.mdmarkdown3.0 KB
references/agent-references/writing-craft.mdmarkdown23.6 KB
references/antigravity/hooks/hooks.jsonconfig1.0 KB
references/antigravity/hooks/story_antigravity_hook.jsscript8.4 KB
references/antigravity/hooks/story_hook_core.jsscript67.0 KB
references/antigravity/rules/oh-story.mdmarkdown3.7 KB
references/codex/AGENTS.md.tmplother3.8 KB
references/codex/agents/chapter-extractor.tomlconfig14.0 KB
references/codex/agents/character-designer.tomlconfig5.1 KB
references/codex/agents/consistency-checker.tomlconfig12.0 KB
references/codex/agents/narrative-writer.tomlconfig15.7 KB
references/codex/agents/story-architect.tomlconfig9.0 KB
references/codex/agents/story-explorer.tomlconfig11.7 KB
references/codex/agents/story-researcher.tomlconfig10.6 KB
references/codex/hooks/hooks.jsonconfig6.8 KB
references/codex/hooks/run-story-hook.cmdscript717 B
references/codex/hooks/run-story-hook.shexecutablescript805 B
references/codex/hooks/story_codex_hook.jsexecutablescript10.4 KB
references/codex/hooks/story_hook_core.jsscript67.0 KB
references/deploy-antigravity.mdmarkdown8.9 KB
references/deploy-claude-code.mdmarkdown7.6 KB
references/deploy-codex.mdmarkdown6.1 KB
references/deploy-generic.mdmarkdown2.5 KB
references/deploy-openclaw.mdmarkdown3.0 KB
references/deploy-opencode.mdmarkdown14.7 KB
references/deploy-reasonix.mdmarkdown3.5 KB
references/deploy-zcode.mdmarkdown7.5 KB
references/diagnostics.mdmarkdown4.3 KB
references/generic/AGENTS.md.tmplother4.4 KB
references/openclaw/AGENTS.md.tmplother5.0 KB
references/opencode/AGENTS.md.tmplother3.2 KB
references/opencode/agents/chapter-extractor.mdmarkdown13.8 KB
references/opencode/agents/character-designer.mdmarkdown4.7 KB
references/opencode/agents/consistency-checker.mdmarkdown11.5 KB
references/opencode/agents/narrative-writer.mdmarkdown15.3 KB
references/opencode/agents/story-architect.mdmarkdown8.5 KB
references/opencode/agents/story-explorer.mdmarkdown11.2 KB
references/opencode/agents/story-researcher.mdmarkdown10.1 KB
references/opencode/commands/browser-cdp.mdmarkdown284 B
references/opencode/commands/story-cover.mdmarkdown189 B
references/opencode/commands/story-deslop.mdmarkdown222 B
references/opencode/commands/story-import.mdmarkdown235 B
references/opencode/commands/story-long-analyze.mdmarkdown214 B
references/opencode/commands/story-long-scan.mdmarkdown232 B
references/opencode/commands/story-long-write.mdmarkdown200 B
references/opencode/commands/story-publish.mdmarkdown224 B
references/opencode/commands/story-review.mdmarkdown212 B
references/opencode/commands/story-setup.mdmarkdown322 B
references/opencode/commands/story-short-analyze.mdmarkdown209 B
references/opencode/commands/story-short-scan.mdmarkdown215 B
references/opencode/commands/story-short-write.mdmarkdown192 B
references/opencode/commands/story.mdmarkdown243 B
references/opencode/plugin.tsscript12.6 KB
references/opencode/pre-commit.shexecutablescript525 B
references/opencode/story_hook_core.jsscript67.0 KB
references/reasonix/AGENTS.md.tmplother5.3 KB
references/templates/.gitkeepother0 B
references/templates/CLAUDE.md.tmplother3.2 KB
references/templates/agents/chapter-extractor.mdmarkdown13.9 KB
references/templates/agents/character-designer.mdmarkdown4.5 KB
references/templates/agents/consistency-checker.mdmarkdown11.3 KB
references/templates/agents/narrative-writer.mdmarkdown15.2 KB
references/templates/agents/story-architect.mdmarkdown8.4 KB
references/templates/agents/story-explorer.mdmarkdown10.9 KB
references/templates/agents/story-researcher.mdmarkdown10.0 KB
references/templates/hooks/run-story-hook.shexecutablescript1.2 KB
references/templates/hooks/story_hook_cli.jsexecutablescript19.3 KB
references/templates/hooks/story_hook_core.jsscript67.0 KB
references/templates/rules/story-consistency.mdmarkdown2.5 KB
references/templates/rules/story-format.mdmarkdown3.4 KB
references/templates/rules/story-narrative.mdmarkdown1.5 KB
references/templates/rules/story-outline.mdmarkdown3.5 KB
references/templates/settings-hooks.jsonconfig2.1 KB
references/zcode/AGENTS.md.tmplother4.3 KB
references/zcode/agents/chapter-extractor.mdmarkdown13.5 KB
references/zcode/agents/character-designer.mdmarkdown4.4 KB
references/zcode/agents/consistency-checker.mdmarkdown11.3 KB
references/zcode/agents/narrative-writer.mdmarkdown15.0 KB
references/zcode/agents/story-architect.mdmarkdown8.3 KB
references/zcode/agents/story-explorer.mdmarkdown11.0 KB
references/zcode/agents/story-researcher.mdmarkdown9.9 KB
references/zcode/commands/browser-cdp.mdmarkdown221 B
references/zcode/commands/story-cover.mdmarkdown204 B
references/zcode/commands/story-deslop.mdmarkdown234 B
references/zcode/commands/story-import.mdmarkdown200 B
references/zcode/commands/story-long-analyze.mdmarkdown218 B
references/zcode/commands/story-long-scan.mdmarkdown206 B
references/zcode/commands/story-long-write.mdmarkdown202 B
references/zcode/commands/story-publish.mdmarkdown247 B
references/zcode/commands/story-review.mdmarkdown217 B
references/zcode/commands/story-setup.mdmarkdown363 B
references/zcode/commands/story-short-analyze.mdmarkdown214 B
references/zcode/commands/story-short-scan.mdmarkdown217 B
references/zcode/commands/story-short-write.mdmarkdown204 B
references/zcode/commands/story.mdmarkdown221 B
references/zcode/config.json.patchother1.7 KB
references/zcode/hooks/hooks.jsonconfig1.6 KB
references/zcode/hooks/story_hook_core.jsscript67.0 KB
references/zcode/hooks/story_zcode_hook.jsexecutablescript6.9 KB
scripts/copy-path-safety.jsexecutablescript8.9 KB
scripts/deploy-antigravity-skills.jsexecutablescript9.3 KB
scripts/generate-antigravity-agents.mjsexecutablescript12.4 KB
scripts/merge-hooks.jsexecutablescript9.5 KB
scripts/merge-project-instructions.jsexecutablescript12.8 KB

scripts/merge-project-instructions.js

View on GitHub
#!/usr/bin/env node
"use strict";

// Merge one host's oh-story block into a project instruction file.
//
// CLAUDE.md and the shared root AGENTS.md carry one managed block per host:
//
//     <!-- oh-story:codex 开始:重新部署时整块替换,自己的内容写在块外 -->
//     ...rendered template...
//     <!-- oh-story:codex 结束 -->
//
// Redeploying replaces only this host's block; text outside every block and
// other hosts' blocks stay byte-identical. Files written before blocks existed
// are migrated once: the oh-story title line, its intro and the sections whose
// headings the current template owns are removed and the block takes their place.

const crypto = require("node:crypto");
const fs = require("node:fs");
const path = require("node:path");

const HOSTS = Object.freeze([
  "claude-code",
  "opencode",
  "codex",
  "zcode",
  "openclaw",
  "reasonix",
  "generic",
]);
// 旧模板里有、现模板已删的受管节;迁移旧文件时一并清掉。
const RETIRED_HEADINGS = new Set(["协作规则"]);
// 名字太常见的节,旧文件里只有带 oh-story 痕迹才算受管,避免误删作者自己的同名节。
const GENERIC_HEADINGS = new Set(["Skill 路由表", "文件结构", "写作约束"]);
const LEGACY_SIGNALS = Object.freeze([
  "story-",
  "拆文库",
  "追踪/",
  "细纲",
  "作者记忆",
  "oh-story",
]);
// 各宿主模板共有的节;文件里已有别的宿主的块、块外又没有旧标题时,这些节归作者。
const SHARED_HEADINGS = new Set([
  "Skill 路由表",
  "文件结构",
  "写作约束",
  "与作者协作",
  "Compact 后恢复上下文",
]);
const TITLE_SIGNAL = "网文写作工具集";
const LEGACY_MARKER = "<!-- managed-by: story-setup -->";
const HEADING_RE = /^##\s+(.+?)\s*$/;

class MergeError extends Error {
  constructor(message) {
    super(message);
    this.name = "MergeError";
  }
}

function escapeRegExp(value) {
  return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}

function beginMarker(host) {
  return `<!-- oh-story:${host} 开始:重新部署时整块替换,自己的内容写在块外 -->`;
}

function endMarker(host) {
  return `<!-- oh-story:${host} 结束 -->`;
}

function blockRe(host) {
  const escaped = escapeRegExp(host);
  return new RegExp(
    `^<!-- oh-story:${escaped} 开始[^\\n]*-->\\n[\\s\\S]*?^<!-- oh-story:${escaped} 结束 -->[ \\t]*$`,
    "gm"
  );
}

function splitLines(text) {
  if (!text) return [];
  const normalized = text.replace(/\r\n?/g, "\n");
  return (normalized.endsWith("\n") ? normalized.slice(0, -1) : normalized).split("\n");
}

function renderBlock(template, host, projectName) {
  const body = template
    .replace(/\r\n/g, "\n")
    .split("{项目名}")
    .join(projectName)
    .replace(/^\n+|\n+$/g, "");
  if (body.includes("<!-- oh-story:")) {
    throw new MergeError("template must not carry its own oh-story markers");
  }
  return `${beginMarker(host)}\n${body}\n${endMarker(host)}`;
}

function managedHeadings(template) {
  const headings = new Set(RETIRED_HEADINGS);
  for (const line of splitLines(template)) {
    const match = line.match(HEADING_RE);
    if (match) headings.add(match[1]);
  }
  return headings;
}

function protectedSpans(text) {
  const spans = [];
  const anyBeginRe = /^<!-- oh-story:([a-z-]+) 开始[^\n]*-->$/gm;
  let match;
  while ((match = anyBeginRe.exec(text)) !== null) {
    const host = match[1];
    const endRe = new RegExp(`^<!-- oh-story:${escapeRegExp(host)} 结束 -->[ \\t]*$`, "gm");
    endRe.lastIndex = match.index + match[0].length;
    const end = endRe.exec(text);
    if (!end) {
      throw new MergeError(`unterminated oh-story:${host} block`);
    }
    spans.push([match.index, end.index + end[0].length]);
  }
  return spans;
}

function titleRe(template) {
  const first = splitLines(template).find((line) => line.startsWith("# ")) || "";
  if (!first.includes(TITLE_SIGNAL)) return null;
  const parts = first
    .trim()
    .split("{项目名}")
    .map((part) => escapeRegExp(part));
  return new RegExp("^" + parts.join(".*") + "\\s*$");
}

function stripLegacy(text, template) {
  let headings = managedHeadings(template);
  const ownTitle = titleRe(template);
  const spans = protectedSpans(text);
  const lines = text.split("\n");
  const offsets = [];
  let pos = 0;
  for (const line of lines) {
    offsets.push(pos);
    pos += line.length + 1;
  }

  function insideBlock(index) {
    const offset = offsets[index];
    return spans.some(([start, end]) => start <= offset && offset < end);
  }

  // 旧部署的凭据:块外有 oh-story 标题行(任一宿主)或旧版托管标记。
  const outside = lines.filter((_, i) => !insideBlock(i));
  const legacyDeploy = outside.some(
    (line) => (line.startsWith("# ") && line.includes(TITLE_SIGNAL)) || line.trim() === LEGACY_MARKER
  );
  if (!legacyDeploy) {
    if (!spans.length) {
      return { text, insertAt: null, removed: [] };
    }
    // 已有别的宿主的块:共有节在先迁移的宿主那里清过了,剩下的只可能是本宿主独有的节。
    headings = new Set(
      [...headings].filter((h) => !SHARED_HEADINGS.has(h) && !RETIRED_HEADINGS.has(h))
    );
  }

  // 把块外的行切成「本宿主标题行 + 引言」与「## 节」两类片段。
  const pieces = [];
  let index = 0;
  while (index < lines.length) {
    if (insideBlock(index)) {
      index += 1;
      continue;
    }
    const line = lines[index];
    if (ownTitle !== null && ownTitle.test(line)) {
      let end = index + 1;
      while (end < lines.length && !lines[end].startsWith("#") && !insideBlock(end)) {
        end += 1;
      }
      pieces.push(["#title", index, end]);
      index = end;
      continue;
    }
    const heading = line.match(HEADING_RE);
    if (heading) {
      let end = index + 1;
      while (
        end < lines.length &&
        !lines[end].startsWith("# ") &&
        !HEADING_RE.test(lines[end]) &&
        !insideBlock(end)
      ) {
        end += 1;
      }
      pieces.push([heading[1], index, end]);
      index = end;
      continue;
    }
    index += 1;
  }

  const removedRanges = [];
  const removedTitles = [];
  for (const [title, start, end] of pieces) {
    const body = lines.slice(start, end).join("\n");
    if (title === "#title") {
      removedRanges.push([start, end]);
      removedTitles.push(lines[start].replace(/^[# ]+/, "").trim());
    } else if (
      headings.has(title) &&
      (!GENERIC_HEADINGS.has(title) || LEGACY_SIGNALS.some((signal) => body.includes(signal)))
    ) {
      removedRanges.push([start, end]);
      removedTitles.push(title);
    }
  }
  if (!removedRanges.length) {
    return { text, insertAt: null, removed: [] };
  }

  const drop = new Set();
  for (const [start, end] of removedRanges) {
    for (let i = start; i < end; i++) drop.add(i);
  }
  const first = Math.min(...removedRanges.map(([start]) => start));
  const keptBefore = [];
  for (let i = 0; i < first; i++) {
    if (!drop.has(i)) keptBefore.push(lines[i]);
  }
  const keptAfter = [];
  for (let i = first; i < lines.length; i++) {
    if (!drop.has(i)) keptAfter.push(lines[i]);
  }
  const head = keptBefore.join("\n");
  const insertAt = head.length + (keptBefore.length ? 1 : 0);
  const newText = head + (keptBefore.length ? "\n" : "") + keptAfter.join("\n");
  return { text: newText, insertAt, removed: removedTitles };
}

function tidy(text) {
  return text.replace(/\n{3,}/g, "\n\n").replace(/^\n+|\n+$/g, "") + "\n";
}

function countOccurrences(text, needle) {
  if (!text) return 0;
  let count = 0;
  let idx = 0;
  while ((idx = text.indexOf(needle, idx)) !== -1) {
    count += 1;
    idx += needle.length;
  }
  return count;
}

function merge(existing, template, host, projectName) {
  const block = renderBlock(template, host, projectName);
  const crlf = existing
    ? countOccurrences(existing, "\r\n") > countOccurrences(existing, "\n") / 2
    : false;
  const text = existing.replace(/\r\n/g, "\n");
  const report = { host, removed_legacy_sections: [] };
  let merged;

  if (!text.trim()) {
    report.status = "created";
    merged = block + "\n";
  } else {
    protectedSpans(text); // 先校验已有块都闭合
    const pattern = blockRe(host);
    const matches = [...text.matchAll(pattern)];
    if (matches.length > 1) {
      throw new MergeError(`more than one oh-story:${host} block`);
    }
    if (matches.length === 1) {
      report.status = "replaced";
      const m = matches[0];
      merged = tidy(text.slice(0, m.index) + block + text.slice(m.index + m[0].length));
    } else {
      const { text: stripped, insertAt, removed } = stripLegacy(text, template);
      if (insertAt === null) {
        report.status = "appended";
        merged = tidy(text.replace(/\n+$/g, "") + "\n\n" + block);
      } else {
        report.status = "migrated";
        report.removed_legacy_sections = removed;
        const before = stripped.slice(0, insertAt);
        const after = stripped.slice(insertAt);
        merged = tidy(
          (before.trim() ? before.replace(/\n+$/g, "") + "\n\n" : "") +
            block +
            (after.trim() ? "\n\n" + after.replace(/^\n+/g, "") : "")
        );
      }
    }
  }

  if (crlf) {
    merged = merged.replace(/\n/g, "\r\n");
  }
  return { merged, report };
}

function atomicWrite(filePath, text) {
  const dir = path.dirname(filePath);
  const base = path.basename(filePath);
  fs.mkdirSync(dir, { recursive: true });
  const tmp = path.join(dir, `.${base}.${process.pid}.${crypto.randomBytes(6).toString("hex")}.tmp`);
  let fd = null;
  try {
    fd = fs.openSync(tmp, "wx", 0o644);
    fs.writeSync(fd, text, 0, "utf8");
    fs.fsyncSync(fd);
    fs.closeSync(fd);
    fd = null;
    fs.renameSync(tmp, filePath);
  } catch (err) {
    if (fd !== null) {
      try {
        fs.closeSync(fd);
      } catch (_) {}
    }
    try {
      fs.unlinkSync(tmp);
    } catch (_) {}
    throw err;
  }
}

function toAsciiJson(value) {
  return JSON.stringify(value).replace(/[^\x00-\x7F]/g, (ch) => {
    const code = ch.charCodeAt(0);
    return "\\u" + code.toString(16).padStart(4, "0");
  });
}

class CliUsageError extends Error {
  constructor(message) {
    super(message);
    this.name = "CliUsageError";
  }
}

const USAGE =
  "usage: merge-project-instructions.js --host <host> --template <path> --existing <path> --output <path> --project-name <name>\n";

const VALUE_FLAGS = new Set(["--host", "--template", "--existing", "--output", "--project-name"]);

function parseArgs(argv) {
  const args = {};
  for (let i = 0; i < argv.length; i++) {
    const arg = argv[i];
    if (arg === "-h" || arg === "--help") {
      return { help: true };
    }
    let flag = arg;
    let inlineValue = null;
    const eqIdx = arg.indexOf("=");
    if (arg.startsWith("--") && eqIdx !== -1) {
      flag = arg.slice(0, eqIdx);
      inlineValue = arg.slice(eqIdx + 1);
    }
    if (VALUE_FLAGS.has(flag)) {
      const value = inlineValue !== null ? inlineValue : argv[++i];
      if (value === undefined) {
        throw new CliUsageError(`merge-project-instructions: ${flag} requires a value\n`);
      }
      args[flag.slice(2)] = value;
    } else {
      throw new CliUsageError(`merge-project-instructions: unknown argument: ${arg}\n`);
    }
  }
  const required = ["host", "template", "existing", "output", "project-name"];
  for (const key of required) {
    if (args[key] === undefined) {
      throw new CliUsageError(`merge-project-instructions: missing required option --${key}\n`);
    }
  }
  if (!HOSTS.includes(args.host)) {
    throw new CliUsageError(
      `merge-project-instructions: invalid --host ${args.host} (choose from ${HOSTS.join(", ")})\n`
    );
  }
  args.help = false;
  return args;
}

function main(argv = process.argv.slice(2)) {
  let args;
  try {
    args = parseArgs(argv);
  } catch (err) {
    if (err instanceof CliUsageError) {
      process.stderr.write(err.message);
      return 2;
    }
    throw err;
  }
  if (args.help) {
    process.stdout.write(USAGE);
    return 0;
  }
  try {
    const template = fs.readFileSync(args.template, "utf8");
    const existing =
      fs.existsSync(args.existing) && fs.statSync(args.existing).isFile()
        ? fs.readFileSync(args.existing, "utf8")
        : "";
    const { merged, report } = merge(existing, template, args.host, args["project-name"]);
    const unchanged =
      merged === existing && path.resolve(args.output) === path.resolve(args.existing);
    if (!unchanged) {
      atomicWrite(args.output, merged);
    }
    // 只输出 ASCII(中文转义),避免 Windows 控制台编码把报告打成乱码。
    process.stdout.write(toAsciiJson(report) + "\n");
    return 0;
  } catch (err) {
    process.stdout.write(toAsciiJson({ status: "error", error: String(err.message || err) }) + "\n");
    return 1;
  }
}

if (require.main === module) {
  process.exit(main());
}

module.exports = {
  HOSTS,
  MergeError,
  atomicWrite,
  beginMarker,
  endMarker,
  main,
  merge,
  protectedSpans,
  renderBlock,
  stripLegacy,
};
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 323kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 323kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 323kUpdated Claude CodeCodexVerifiedInstall