story-setup
The story-setup skill deploys a complete web novel writing infrastructure framework to a user's project directory, including hooks, rules, agents, and configuration templates while preserving existing user settings through intelligent merging. Use this when initializing a new writing project or adding the structured writing toolkit to an existing project directory.
git clone --depth 1 https://github.com/worldwonderer/oh-story-claudecode /tmp/story-setup && cp -r /tmp/story-setup/skills/story-setup ~/.claude/skills/story-setupSKILL.md
# story-setup:网文写作工具集基础设施部署
你是写作基础设施部署器。将网文写作工具集的全套基础设施(hooks、rules、agents、CLAUDE.md)部署到用户项目目录。
**执行铁律:不覆盖用户已有配置,合并而非替换。**
---
## Phase 1:检测项目状态
1. 检查当前目录是否已部署过(存在 `.story-deployed`)
- 如果已存在 → 使用 AskUserQuestion 确认是否重新部署
2. 检查是否有书名目录(包含 `追踪/` 子目录的目录,或用户自定义结构)
- 有 → 识别为长篇项目,显示当前项目信息
- 无 → 识别为新项目或短篇项目
3. 检查 `.claude/settings.local.json` 是否存在
- 存在 → 读取现有配置,后续合并
- 不存在 → 后续创建新文件
4. 检查 `.active-book` 文件是否存在
- 存在 → 显示当前活跃书目
- 不存在 → 跳过
5. 检查 `opencode.json` 或 `.opencode/` 是否存在
- 存在 → 识别为 opencode 项目,`target_cli = opencode`
- 不存在 → 跳过
6. 如 `.claude/` 或 `CLAUDE.md` 与 opencode 标记同时存在 → 使用 AskUserQuestion 让用户选择目标 CLI(选项:仅 Claude Code / 仅 OpenCode / 两者都部署)
7. 如两者都不存在(全新项目)→ 使用 AskUserQuestion 让用户选择目标 CLI
- 用户选择 opencode → `target_cli = opencode`,部署时创建 `opencode.json` 和 `.opencode/`
- 用户选择 claude-code → 按现有逻辑处理
- 用户选择两者 → `target_cli = claude-code,opencode`
## Phase 2:部署基础设施
使用 AskUserQuestion 确认部署位置后,依次执行。
### 2.0 部署清单(机械可检查)
| Source path | Target path | Owner class | Merge mode | Validation check |
|-------------|-------------|-------------|------------|------------------|
| `skills/story-setup/references/templates/CLAUDE.md.tmpl` | `CLAUDE.md` | user+managed | marker/section merge | contains story skill routing sections |
| `skills/story-setup/references/templates/hooks/` | `.claude/hooks/` | story-setup managed | recursive replace | `session-*.sh`, `detect-story-gaps.sh`, `validate-story-commit.sh`, `guard-outline-before-prose.sh`, `lib/common.sh`, `lib/sentinel.sh` exist |
| `skills/story-setup/references/templates/rules/*.md` | `.claude/rules/*.md` | story-setup managed | replace | every rule contains `paths` frontmatter |
| `skills/story-setup/references/templates/agents/*.md` | `.claude/agents/*.md` | story-setup managed | replace | 7 agent files exist |
| `skills/story-setup/references/agent-references/*.md` | `.claude/skills/story-setup/references/agent-references/*.md` | story-setup managed | replace | every `story-setup/references/agent-references/*.md` reference resolves |
| `skills/story-setup/references/templates/settings-hooks.json` | `.claude/settings.local.json` | user+managed | merge by hook command | hook JSON valid and registered commands deduped |
| `skills/story-setup/references/templates/上下文.md.tmpl` | `{书名}/追踪/上下文.md` | user state | create only if absent | never overwrite existing writing context |
| generated sentinel | `.story-deployed` | story-setup managed | replace | contains `agents_version`, `setup_skill_version`, `target_cli`, `resolver_strategy`, `references_dir` |
| `skills/story-setup/references/opencode/AGENTS.md.tmpl` | `AGENTS.md` | user+managed | marker/section merge | contains story skill routing sections | target_cli 含 opencode |
| `skills/story-setup/references/opencode/agents/` | `.opencode/agents/` | story-setup managed | replace | 7 agent files exist | target_cli 含 opencode |
| `skills/story-setup/references/opencode/plugin.ts` | `.opencode/plugins/story-hooks.ts` | story-setup managed | replace | TypeScript plugin file exists | target_cli 含 opencode |
| `skills/story-setup/references/opencode/commands/` | `.opencode/commands/` | story-setup managed | replace | 13 command files exist | target_cli 含 opencode |
| `skills/story-setup/references/opencode/opencode.json.patch` | merge into `opencode.json` | user+managed | merge by plugin/permission key | plugin entry registered | target_cli 含 opencode |
| `skills/story-setup/references/agent-references/` | `skills/story-setup/references/agent-references/` | story-setup managed | replace | every reference resolves | target_cli 含 opencode |
| `skills/story-setup/references/opencode/pre-commit.sh` | `.git/hooks/pre-commit` | user+managed | append or create | file exists and is executable;含 marker 块则替换块内容,不含则检测 exit 0 位置智能插入 | target_cli 含 opencode |
### opencode.json 合并算法
部署 `opencode.json.patch` 时按以下规则合并:
1. 读取现有 `opencode.json`(如存在),解析 JSON
2. 合并 `plugin` 数组:将 `./.opencode/plugins/story-hooks.ts` 加入数组,去重
3. 保留用户已有的其他配置字段(`permission`、`model`、`provider` 等),不覆盖
4. 写入合并后的 `opencode.json`
### 2.1 部署 CLAUDE.md
- 读取 `skills/story-setup/references/templates/CLAUDE.md.tmpl`
- 替换占位符(见下方「模板占位符」段)
- 写入项目根目录 `CLAUDE.md`(如已存在,按「CLAUDE.md 合并策略」处理)
### 2.2 部署 Hooks
- **递归复制完整目录树**:将 `skills/story-setup/references/templates/hooks/` 复制到用户项目 `.claude/hooks/`
- 必须保留子目录 `lib/`,其中:
- `lib/common.sh` 提供 `project_root`、`discover_active_book`、`discover_all_books`
- `lib/sentinel.sh` 提供 `.story-deployed` 字段读取
- 只需对 `.claude/hooks/*.sh` 设置执行权限(`chmod +x`);`lib/*.sh` 由 hook `source`,不要求可执行位
### 2.3 部署 Rules
- 读取 `skills/story-setup/references/templates/rules/` 下所有 `.md` 文件
- 复制到用户项目的 `.claude/rules/` 目录
### 2.4 部署 Agents
- 读取 `skills/story-setup/references/templates/agents/` 下所有 `.md` 文件
- 复制到用户项目的 `.claude/agents/` 目录
- Agent 文件属于 story-setup 管理文件,可安全覆盖;版本升级时按 `UPGRADING.md` 的版本检测结果重新部署
- **部署后必须新开会话**:Claude Code 只在会话启动时扫描 `.claude/agents/` 注册 subagent。当前会话内新部署的 agent 不会立即可用——必须让用户新开一个 Claude Code 会话,`story-architect`/`narrative-writer` 等 custom agent 才会注册成 `subagent_type`;否则 story-review、story-long-write 等想 spawn 时会拿到「subagent_type 不可用」并降级 solo(单视角)。这一步必须在安装报告里明确告知用户(见 Phase 3 第 6 步)。
### 2.4.1 Agent 兼容性处理
- Agent frontmatter 以 Claude Code 为主;OpenClaw/qclaw 等只要支持 AgentSkills,未知字段(如 `memory`、`skills`、`disallowedTools`)应被忽略。若目标工具报 frontmatter 错误,保留 `name`、`description`、`tools` 三项,删除不支持字段后再部署。
- 部署到项目后,agent 内引用的参考资料必须走 `story-setup/references/agent-references/*.md` 这一本 skill 内复制路径;不要跨 skill 引用其他 skill 的 references。若全局安装路径不同,优先用项目内 `.claude/skills/` 或 `skills/` 作为规范路径前缀,其次用工具的 skill 搜索能力,不要假定固定绝对路径。
### 2.4.2 部署 Agent References
- 将 `skills/story-setup/references/agent-references/` 下所有 `.md` 复制到项目内 `.claude/skills/story-setup/references/agent-references/`
- 如目标项目已经使用项目本地 `skills/` 目录,也可以同步复制到 `skills/story-setup/references/agent-references/` 作为 fallback,但不得只复制 fallback 而遗漏 `.claude/skills/` 主路径
- 校验:凡 agent 或 reference 中出现 `story-setup/references/agent-references/<file>.md`,Use this skill when you need to control a Chrome browser via CDP (Chrome DevTools Protocol) to reuse existing login sessions. Covers: launching Chrome in debug mode, opening URLs, waiting for page load, evaluating JavaScript, taking snapshots, and extracting auth tokens. Trigger phrases: browser automation, CDP, agent-browser, 浏览器操作, 操作浏览器, Chrome CDP, 复用登录态, extract token from browser.
|
|
|
|
|
|
|