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-hooks.js

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

// Unified hook configuration merger for story-setup across hosts:
//   --host claude      merge .claude/settings.local.json
//   --host codex       merge .codex/hooks.json
//   --host antigravity merge .agents/hooks.json (named-group schema)
//
// Only story-setup managed registrations (including legacy names for smooth
// upgrades) are replaced; unrelated user hooks and top-level settings survive.

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

const HOSTS = Object.freeze(["claude", "codex", "antigravity"]);

const CLAUDE_MANAGED_HOOK_SCRIPTS = Object.freeze([
  "run-story-hook.sh",
  "check-prose-after-write.sh",
  "detect-story-gaps.sh",
  "guard-outline-before-prose.sh",
  "post-compact.sh",
  "pre-compact.sh",
  "session-end.sh",
  "session-start.sh",
  "validate-story-commit.sh",
]);

const CODEX_MANAGED_COMMAND_MARKERS = Object.freeze([
  ".codex/hooks/story_codex_hook.py",
  ".codex/hooks/story_codex_hook.js",
  ".codex/hooks/run-story-hook.sh",
  ".codex/hooks/run-story-hook.cmd",
]);

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

function isPlainObject(value) {
  return value !== null && typeof value === "object" && !Array.isArray(value);
}

function deepClone(value) {
  return structuredClone(value);
}

function isClaudeStorySetupHook(hook) {
  if (!isPlainObject(hook) || typeof hook.command !== "string") {
    return false;
  }
  const normalized = hook.command.replace(/\\/g, "/");
  return CLAUDE_MANAGED_HOOK_SCRIPTS.some((name) => normalized.includes(`/.claude/hooks/${name}`));
}

function normalizedCommand(value) {
  return typeof value === "string" ? value.toLowerCase().replace(/\\/g, "/") : "";
}

function isCodexStorySetupHook(hook) {
  if (!isPlainObject(hook)) {
    return false;
  }
  const commands = [normalizedCommand(hook.command), normalizedCommand(hook.commandWindows)];
  return CODEX_MANAGED_COMMAND_MARKERS.some((marker) =>
    commands.some((command) => command.includes(marker))
  );
}

function requireHooks(document, label) {
  if (!isPlainObject(document)) {
    throw new MergeError(`${label} root must be a JSON object`);
  }
  const hooks = Object.prototype.hasOwnProperty.call(document, "hooks") ? document.hooks : {};
  if (!isPlainObject(hooks)) {
    throw new MergeError(`${label}.hooks must be a JSON object`);
  }
  return hooks;
}

function stripManagedRegistrations(hooks, isManagedHook) {
  const cleaned = {};
  for (const [event, rawBlocks] of Object.entries(hooks)) {
    if (!Array.isArray(rawBlocks)) {
      cleaned[event] = deepClone(rawBlocks);
      continue;
    }
    const blocks = [];
    for (const rawBlock of rawBlocks) {
      if (!isPlainObject(rawBlock) || !Array.isArray(rawBlock.hooks)) {
        blocks.push(deepClone(rawBlock));
        continue;
      }
      const keptHooks = rawBlock.hooks
        .filter((hook) => !isManagedHook(hook))
        .map((hook) => deepClone(hook));
      if (!keptHooks.length) {
        continue;
      }
      const block = deepClone(rawBlock);
      block.hooks = keptHooks;
      blocks.push(block);
    }
    if (blocks.length) {
      cleaned[event] = blocks;
    }
  }
  return cleaned;
}

function mergeHookMapDocuments(existing, template, isManagedHook) {
  const existingHooks = requireHooks(existing, "existing");
  const templateHooks = requireHooks(template, "template");
  for (const [event, blocks] of Object.entries(templateHooks)) {
    if (!Array.isArray(blocks)) {
      throw new MergeError(`template.hooks.${event} must be an array`);
    }
  }

  const result = deepClone(existing);
  const mergedHooks = stripManagedRegistrations(existingHooks, isManagedHook);
  for (const [event, blocks] of Object.entries(templateHooks)) {
    // 只在与模板事件撞名时要求用户侧是数组:未知事件的非数组值由
    // stripManagedRegistrations 原样保留(保留用户已有配置的契约),
    // 撞名却无法合并时给出 MergeError 诊断。
    if (Object.prototype.hasOwnProperty.call(mergedHooks, event) && !Array.isArray(mergedHooks[event])) {
      throw new MergeError(`existing.hooks.${event} must be an array`);
    }
    if (!Object.prototype.hasOwnProperty.call(mergedHooks, event)) {
      mergedHooks[event] = [];
    }
    mergedHooks[event].push(...deepClone(blocks));
  }
  result.hooks = mergedHooks;
  return result;
}

function mergeAntigravityDocuments(existing, template) {
  if (!isPlainObject(existing)) {
    throw new MergeError("expected a JSON object in existing");
  }
  if (!isPlainObject(template)) {
    throw new MergeError("expected a JSON object in template");
  }
  const managed = template["oh-story"];
  if (!isPlainObject(managed)) {
    throw new MergeError("template must contain an object-valued oh-story group");
  }
  const result = deepClone(existing);
  result["oh-story"] = deepClone(managed);
  return result;
}

function mergeDocuments(host, existing, template) {
  if (host === "claude") {
    return mergeHookMapDocuments(existing, template, isClaudeStorySetupHook);
  }
  if (host === "codex") {
    return mergeHookMapDocuments(existing, template, isCodexStorySetupHook);
  }
  if (host === "antigravity") {
    return mergeAntigravityDocuments(existing, template);
  }
  throw new MergeError(`unsupported host: ${host}`);
}

function readJson(filePath, { missingOk = false, requireObject = false } = {}) {
  if (missingOk && !fs.existsSync(filePath)) {
    return {};
  }
  let raw;
  try {
    raw = fs.readFileSync(filePath, "utf8").replace(/^\uFEFF/, "");
  } catch (err) {
    throw new MergeError(`unable to read ${filePath}: ${err.message || err}`);
  }
  let value;
  try {
    value = JSON.parse(raw);
  } catch (err) {
    throw new MergeError(`unable to read ${filePath}: ${err.message || err}`);
  }
  if (requireObject && !isPlainObject(value)) {
    throw new MergeError(`expected a JSON object in ${filePath}`);
  }
  return value;
}

function atomicWriteJson(filePath, document) {
  const dir = path.dirname(filePath);
  const base = path.basename(filePath);
  fs.mkdirSync(dir, { recursive: true });
  const mode = fs.existsSync(filePath) ? fs.statSync(filePath).mode & 0o777 : 0o644;
  const payload = JSON.stringify(document, null, 2) + "\n";
  const tmp = path.join(dir, `.${base}.${process.pid}.${crypto.randomBytes(6).toString("hex")}.tmp`);
  let fd = null;
  try {
    fd = fs.openSync(tmp, "wx", mode);
    fs.writeSync(fd, payload, 0, "utf8");
    fs.fsyncSync(fd);
    fs.closeSync(fd);
    fd = null;
    try {
      fs.chmodSync(tmp, mode);
    } catch (_) {
      // Ignore chmod quirks on Windows filesystems.
    }
    fs.renameSync(tmp, filePath);
  } finally {
    if (fd !== null) {
      try {
        fs.closeSync(fd);
      } catch (_) {}
    }
    try {
      fs.unlinkSync(tmp);
    } catch (_) {}
  }
}

function usage() {
  return (
    "usage:\n" +
    "  merge-hooks.js --host claude|codex --existing <path> --template <path> --output <path>\n" +
    "  merge-hooks.js --host antigravity --existing <path> --template <path> [--output <path>]\n" +
    "  merge-hooks.js --host antigravity <existing> <template>\n"
  );
}

function parseArgs(argv) {
  const opts = {};
  const positional = [];
  for (let i = 0; i < argv.length; i++) {
    const arg = argv[i];
    if (arg === "--host" || arg === "--existing" || arg === "--template" || arg === "--output") {
      const value = argv[++i];
      if (value === undefined) {
        process.stderr.write(`merge-hooks: ${arg} requires a value\n`);
        process.exit(2);
      }
      opts[arg.slice(2)] = value;
    } else if (arg === "-h" || arg === "--help") {
      process.stdout.write(usage());
      process.exit(0);
    } else if (arg.startsWith("-")) {
      process.stderr.write(`merge-hooks: unknown option: ${arg}\n`);
      process.exit(2);
    } else {
      positional.push(arg);
    }
  }

  if (!opts.host || !HOSTS.includes(opts.host)) {
    process.stderr.write(`merge-hooks: --host must be one of ${HOSTS.join(", ")}\n`);
    process.exit(2);
  }

  if (opts.host === "antigravity" && positional.length === 2 && !opts.existing && !opts.template) {
    opts.existing = positional[0];
    opts.template = positional[1];
    if (!opts.output) opts.output = opts.existing;
  } else if (positional.length > 0) {
    process.stderr.write(`merge-hooks: unexpected positional arguments: ${positional.join(" ")}\n`);
    process.exit(2);
  }

  if (opts.host === "antigravity" && !opts.output && opts.existing) {
    opts.output = opts.existing;
  }

  if (!opts.existing || !opts.template || !opts.output) {
    process.stderr.write(usage());
    process.exit(2);
  }

  return opts;
}

function main(argv = process.argv.slice(2)) {
  const args = parseArgs(argv);
  try {
    const requireObject = args.host === "antigravity";
    const existing = readJson(args.existing, { missingOk: true, requireObject });
    const template = readJson(args.template, { missingOk: false, requireObject });
    atomicWriteJson(args.output, mergeDocuments(args.host, existing, template));
    return 0;
  } catch (err) {
    if (err instanceof MergeError) {
      process.stderr.write(`ERROR: ${err.message}\n`);
      return 2;
    }
    process.stderr.write(`ERROR: ${err.message || err}\n`);
    return 2;
  }
}

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

module.exports = {
  CLAUDE_MANAGED_HOOK_SCRIPTS,
  CODEX_MANAGED_COMMAND_MARKERS,
  HOSTS,
  MergeError,
  atomicWriteJson,
  isClaudeStorySetupHook,
  isCodexStorySetupHook,
  main,
  mergeAntigravityDocuments,
  mergeDocuments,
  mergeHookMapDocuments,
  readJson,
};
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