story-setup

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

story-setup:网文写作工具集基础设施部署

story-setup: Infrastructure Deployment for Online Novel Writing Toolset

你是写作基础设施部署器。将网文写作工具集的全套基础设施(hooks、rules、agents、CLAUDE.md)部署到用户项目目录。
执行铁律:不覆盖用户已有配置,合并而非替换。

You are a writing infrastructure deployer. Deploy the complete infrastructure of the online novel writing toolset (hooks, rules, agents, CLAUDE.md) to the user's project directory.
Iron Rule of Execution: Do not overwrite existing user configurations; merge instead of replace.

Phase 1:检测项目状态

Phase 1: Detect Project Status

  1. 检查当前目录是否已部署过(存在
    .story-deployed
    • 如果已存在 → 使用 AskUserQuestion 确认是否重新部署
  2. 检查是否有书名目录(包含
    追踪/
    子目录的目录,或用户自定义结构)
    • 有 → 识别为长篇项目,显示当前项目信息
    • 无 → 识别为新项目或短篇项目
  3. 检查
    .claude/settings.local.json
    是否存在
    • 存在 → 读取现有配置,后续合并
    • 不存在 → 后续创建新文件
  4. 检查
    .active-book
    文件是否存在
    • 存在 → 显示当前活跃书目
    • 不存在 → 跳过
  1. Check if the current directory has been deployed (
    .story-deployed
    exists)
    • If exists → Use AskUserQuestion to confirm whether to redeploy
  2. Check if there is a book title directory (a directory containing the
    追踪/
    subdirectory, or a user-defined structure)
    • If exists → Identify as a long-form project and display current project information
    • If not exists → Identify as a new project or short-form project
  3. Check if
    .claude/settings.local.json
    exists
    • If exists → Read existing configuration for subsequent merging
    • If not exists → Create a new file later
  4. Check if
    .active-book
    file exists
    • If exists → Display current active book title
    • If not exists → Skip

Phase 2:部署基础设施

Phase 2: Deploy Infrastructure

使用 AskUserQuestion 确认部署位置后,依次执行:
After confirming the deployment location via AskUserQuestion, execute the following steps in order:

2.1 部署 CLAUDE.md

2.1 Deploy CLAUDE.md

  • 读取
    skills/story-setup/references/templates/CLAUDE.md.tmpl
  • 替换占位符(见下方「模板占位符」段)
  • 写入项目根目录
    CLAUDE.md
    (如已存在,按「CLAUDE.md 合并策略」处理)
  • Read
    skills/story-setup/references/templates/CLAUDE.md.tmpl
  • Replace placeholders (see "Template Placeholders" section below)
  • Write to the project root directory
    CLAUDE.md
    (if already exists, handle according to "CLAUDE.md Merging Strategy")

2.2 部署 Hooks

2.2 Deploy Hooks

  • 读取
    skills/story-setup/references/templates/hooks/
    下所有
    .sh
    文件
  • 复制到用户项目的
    .claude/hooks/
    目录
  • 确保脚本有执行权限(chmod +x)
  • Read all
    .sh
    files under
    skills/story-setup/references/templates/hooks/
  • Copy to the user's project
    .claude/hooks/
    directory
  • Ensure scripts have execution permissions (chmod +x)

2.3 部署 Rules

2.3 Deploy Rules

  • 读取
    skills/story-setup/references/templates/rules/
    下所有
    .md
    文件
  • 复制到用户项目的
    .claude/rules/
    目录
  • Read all
    .md
    files under
    skills/story-setup/references/templates/rules/
  • Copy to the user's project
    .claude/rules/
    directory

2.4 部署 Agents

2.4 Deploy Agents

  • 读取
    skills/story-setup/references/templates/agents/
    下所有
    .md
    文件
  • 复制到用户项目的
    .claude/agents/
    目录
  • Read all
    .md
    files under
    skills/story-setup/references/templates/agents/
  • Copy to the user's project
    .claude/agents/
    directory

2.5 部署 Session State 模板

2.5 Deploy Session State Template

  • 读取
    skills/story-setup/references/templates/上下文.md.tmpl
  • 如有书名目录,复制到
    {书名}/追踪/
  • Read
    skills/story-setup/references/templates/上下文.md.tmpl
  • If there is a book title directory, copy it to
    {Book Title}/追踪/

2.6 合并 Hooks 注册到 settings.local.json

2.6 Merge Hooks Registration to settings.local.json

  • 读取
    skills/story-setup/references/templates/settings-hooks.json
  • 读取用户项目的
    .claude/settings.local.json
    (如存在)
  • 合并 hooks 配置(按「settings-hooks.json 合并算法」处理)
  • 写入
    .claude/settings.local.json
  • Read
    skills/story-setup/references/templates/settings-hooks.json
  • Read the user's project
    .claude/settings.local.json
    (if exists)
  • Merge hooks configuration (handle according to "settings-hooks.json Merging Algorithm")
  • Write to
    .claude/settings.local.json

2.7 创建部署标记

2.7 Create Deployment Marker

  • 创建
    .story-deployed
    文件(sentinel file)
  • 写入两行:第一行
    deployed_at: <date -u +"%Y-%m-%dT%H:%M:%SZ">
    ,第二行
    agents_version: 2
  • 此文件供 session-start.sh 和写作 skill 检测部署状态,避免重复提示
  • 如果
    .story-deployed
    已存在但无
    agents_version
    或版本为 1,提示用户重新运行 story-setup 以更新 Agent
  • Create
    .story-deployed
    file (sentinel file)
  • Write two lines: First line
    deployed_at: <date -u +"%Y-%m-%dT%H:%M:%SZ">
    , second line
    agents_version: 2
  • This file is used by session-start.sh and writing skills to detect deployment status and avoid repeated prompts
  • If
    .story-deployed
    exists but has no
    agents_version
    or version is 1, prompt the user to re-run story-setup to update Agent

Phase 3:验证安装

Phase 3: Verify Installation

  1. 验证 hooks 注册:
    • 检查
      .claude/settings.local.json
      中的 hooks 字段是否正确
    • 检查
      .claude/hooks/
      下的脚本是否存在且有执行权限
  2. 验证 rules 路径:
    • 检查
      .claude/rules/
      下的规则文件是否存在且包含
      paths
      frontmatter
  3. 验证 agents:
    • 检查
      .claude/agents/
      下的 agent 定义文件是否存在
  4. 验证部署标记:
    • 检查
      .story-deployed
      是否存在且包含时间戳
  5. 输出安装报告:
    • 列出所有已部署的文件
    • 列出需要注意的事项(如已有配置已合并)
    • 提示用户可以开始使用
      /story-long-write
      /story-short-write

  1. Verify hooks registration:
    • Check if the hooks field in
      .claude/settings.local.json
      is correct
    • Check if scripts under
      .claude/hooks/
      exist and have execution permissions
  2. Verify rules path:
    • Check if rule files under
      .claude/rules/
      exist and contain
      paths
      frontmatter
  3. Verify agents:
    • Check if agent definition files under
      .claude/agents/
      exist
  4. Verify deployment marker:
    • Check if
      .story-deployed
      exists and contains a timestamp
  5. Output installation report:
    • List all deployed files
    • List notes (e.g., existing configurations have been merged)
    • Prompt the user to start using
      /story-long-write
      or
      /story-short-write

模板占位符

Template Placeholders

占位符替换规则示例
{项目名}
用户项目名称或目录名《剑来》、《暗卫》
{书名}
书名目录名(与目录一致)
{项目名}
相同,或用户自定义
替换时去掉花括号。如果用户未指定项目名,用当前目录名。
PlaceholderReplacement RuleExample
{Project Name}
User's project name or directory nameSword Comes, Dark Guard
{Book Title}
Book title directory name (consistent with the directory)Same as
{Project Name}
, or user-defined
Remove curly braces when replacing. If the user does not specify a project name, use the current directory name.

CLAUDE.md 合并策略

CLAUDE.md Merging Strategy

用户已有 CLAUDE.md 时,按 section 合并:
  1. 读取用户现有 CLAUDE.md,按
    ##
    标题切分为 section map
  2. 读取模板 CLAUDE.md.tmpl,同样切分
  3. 模板中的标准 section(Skill 路由表、文件结构、协作规则、Context Recovery、语言)覆盖用户同名 section
  4. 用户独有的 section(自定义内容)保留不动
  5. 未知冲突用 AskUserQuestion 让用户选择保留哪个版本
When the user already has CLAUDE.md, merge by section:
  1. Read the user's existing CLAUDE.md and split into a section map by
    ##
    headings
  2. Read the template CLAUDE.md.tmpl and split it the same way
  3. Standard sections in the template (Skill Routing Table, File Structure, Collaboration Rules, Context Recovery, Language) overwrite the user's sections with the same name
  4. Unique sections of the user (custom content) remain unchanged
  5. For unknown conflicts, use AskUserQuestion to let the user choose which version to keep

settings-hooks.json 合并算法

settings-hooks.json Merging Algorithm

hooks 注册合并按 command 字段去重:
  1. 读取用户现有
    .claude/settings.local.json
    (如存在),提取 hooks 部分
  2. 读取
    settings-hooks.json
    模板,提取要注册的 hooks
  3. 对每个 hook event(SessionStart、PreToolUse 等):
    • 用户已有的 hook command → 保留,不重复添加
    • 模板中的新 hook command → append 到对应 event 的 hooks 数组
    • 用户独有的其他配置(permissions、env 等)→ 完整保留
  4. 写入合并后的完整 settings.local.json
Merge hooks registration by deduplicating based on the command field:
  1. Read the user's existing
    .claude/settings.local.json
    (if exists) and extract the hooks part
  2. Read the
    settings-hooks.json
    template and extract the hooks to be registered
  3. For each hook event (SessionStart, PreToolUse, etc.):
    • Existing hook commands from the user → Keep, do not add duplicates
    • New hook commands from the template → Append to the hooks array of the corresponding event
    • Other unique configurations from the user (permissions, env, etc.) → Fully retain
  4. Write the merged complete settings.local.json

重新部署

Redeployment

  • .story-deployed
    不存在 → 全新安装,Phase 2 全部执行
  • .story-deployed
    存在且
    agents_version: 2
    → 提示已部署,AskUserQuestion 确认是否重新部署
  • .story-deployed
    存在但无
    agents_version
    或版本 < 2 → 提示需要更新,重新执行 Phase 2 覆盖 agents/hooks/rules,CLAUDE.md 和 settings.local.json 走合并策略

  • .story-deployed
    does not exist → Fresh installation, execute all steps in Phase 2
  • .story-deployed
    exists and
    agents_version: 2
    → Prompt that deployment is already done, use AskUserQuestion to confirm whether to redeploy
  • .story-deployed
    exists but has no
    agents_version
    or version < 2 → Prompt that an update is needed, re-execute Phase 2 to overwrite agents/hooks/rules, and use merging strategy for CLAUDE.md and settings.local.json

参考资料

Reference Materials

文件用途
references/templates/CLAUDE.md.tmpl项目根 CLAUDE.md 模板
references/templates/hooks/5 个 hook 脚本模板
references/templates/rules/4 条 path-scoped 规则模板
references/templates/agents/4 个 agent 定义模板
references/templates/settings-hooks.jsonhooks 注册 JSON 片段
references/templates/上下文.md.tmpl写作上下文模板
FilePurpose
references/templates/CLAUDE.md.tmplTemplate for project root CLAUDE.md
references/templates/hooks/5 hook script templates
references/templates/rules/4 path-scoped rule templates
references/templates/agents/4 agent definition templates
references/templates/settings-hooks.jsonHooks registration JSON snippet
references/templates/上下文.md.tmplWriting context template