Skip to main content
Glama
yuelinghuashu/story-cli

yuelinghuashu/story-cli

📚 story-cli

Chinese English License Node CI npm version npm downloads

Zero-deployment, Git-native Markdown content management CLI. Manage stories/papers/notes/tutorials with a simple directory convention, auto-generate README, export EPUB, Chinese-English bilingual.


✨ Features

  • Simple directory convention — content is a folder: NN-名称/ containing config.json + text.md

  • Auto-generated README — per-entry and root index are generated automatically (template-driven, customizable)

  • Series grouping & ordering — series / seriesOrder control display order; insert anywhere without reshuffling

  • Runtime validation — checks configuration before building (required fields, enums, formats)

  • Compliance checks — story validate validates against the Story-Repo spec (directory naming / UTF-8 / duplicate sequence numbers / schema)

  • Story linking — story link manages weak links; story build automatically suggests candidate links from the same series

  • Bilingual support — Chinese/English content + auto-generated localized README

  • Chapters + word count — auto-extracts chapter titles and language-aware word counts

  • Multi-format export — EPUB (cover rendering / typesetting styles / series metadata) / HTML / TXT / JSON / Markdown / embeddings, with --stdout piping

  • General-purpose content platform — knowledge base mode (papers / interviews / notes), tech documentation mode (tutorials / API)

  • MCP Server — AI clients (Claude / Cursor) can read and write the content library directly

  • GitHub Action — zero-config CI entry point (yuelinghuashu/story-cli@v1), one-click "Push → Build → Publish"

  • Watch mode — auto-rebuilds on file changes


Related MCP server: obsidian-kb

🚀 Quick Start

# 安装(需要 Node.js >= 22)
npm install -g @yuelinghuashu/story-cli

# 创建示例仓库并查看效果
story demo

# 初始化仓库
story init

# 创建内容并编写
story new "我的新故事"

# 构建所有 README
story build

# 导出 EPUB / 统计
story epub --all
story stats
make init                 # 初始化
make new TITLE="我的故事"  # 新建并自动构建
make commit               # 构建 + 提交
make push                 # 构建 + 提交 + 推送
make stats                # 查看创作统计
make analyze              # 写作质量分析(重复短语 / 字数过期 / 章节趋势,需 jq)

Windows users can also use the story.ps1 (PowerShell workflow) generated by story init: .\story.ps1 init / .\story.ps1 new -Title '我的故事' / .\story.ps1 build.


🌱 More Than Just Stories

General-purpose content governance — any written asset that can be "normalized" can use the same workflow:

Template mode

Content type

Typical use case

--template=story (default)

Fiction / stories

Original works, fan fiction

--template=knowledge

Papers / interviews / blog posts / notes

Knowledge bases, research repositories

--template=tech

Tutorials / API docs / changelogs

Tech blogs, project documentation

story init --template=knowledge
story init --template=tech

🤖 Let AI Manage Your Content Library

story-cli has a built-in MCP Server — AI clients (Claude Desktop / Cursor / VSCode Copilot Chat) can directly read and write your content library. AI can independently complete the full loop of "create → write → build → stats" without manually executing commands in the terminal.

💡 Token efficiency: MCP tools were designed from day one with saving AI invocation costs as the core principle. scan_stories outputs tersely by default (saves ~80-95% for directory browsing), read_chapter supports on-demand truncation (saves ~95%+ for continuation scenarios), stats gets all data in one call (~99%) — every detail is reducing Token consumption for your AI workflow.

Capability

MCP tool

Description

📖 Browse

scan_stories / read_chapter

List the story library, read chapters (supports on-demand loading and tail truncation to save Tokens)

✍️ Write

write_chapter / create_story

Create new stories, atomically write the main text (optional post-write compliance check)

✅ Governance

edit_config / build / validate

Edit metadata fields directly, run README rebuild, validate configuration

📊 Stats

stats

Get total word count / chapter count / series progress / health score

# 启动 MCP Server(需在故事仓库根目录;--root 可从任意目录指定仓库)
story mcp-server

💡 See docs/mcp.md for detailed configuration and examples. The MCP Server reads and writes all files in the current working directory; only run it in repositories you trust.

🎯 Fine-Tuning Data Preparation (SFT / Embedding)

The structured output of a story library is naturally suited as an LLM training data source — config.json comes with classification tags, export json slices precisely by chapter, export embeddings outputs plain-text chunks. Combined with --stdout + Unix toolchain, a one-line pipeline converts to the standard fine-tuning format:

# 导出为指令微调 JSONL(summary → instruction,正文 → output)
story export json --stdout | jq -c '.stories[] | {messages: [{role: "user", content: .summary}, {role: "assistant", content: .content}]}' > sft_data.jsonl

# 导出为 Embedding 训练格式
story export embeddings --stdout | jq -c '{text: .content, metadata: {title: .title, series: .series}}' > embedding_data.jsonl

# 快速分析数据配比(总字数/章节分布/重复短语)
story stats --json | jq '{words: .totalWords, chapters: .totalChapters, repeated: .analysis.repeated}'

💡 story-cli already ensures UTF-8 encoding (auto-detects GBK with a warning), chapter-level slicing (avoids semantic truncation), and complete metadata (type/series/summary natively usable as classification labels). No secondary cleaning script is needed.


🛠️ Common Commands

Command

Description

story init [--template=story|knowledge|tech]

Initialize a repository (story / knowledge base / tech documentation modes)

story new "标题" [--type] [--lang] [--author] [--creator]

Create a new entry

story build [--validate-only] [--save-counts] [--watch]

Build README

story epub "标题" [--all] [--split-by-volume] [--output=dir] [--css=path]

Export EPUB

story export html / txt / json / md / embeddings [--stdout]

Export multiple formats (embeddings output as text-chunk JSONL)

story import json --file=xxx.json

Batch import from JSON

story stats [--json]

Writing statistics

story validate [--json]

Compliance check (Story-Repo spec)

story link "A" "B" [--remove=...] [--list]

Manage story links (weak links)

story mcp-server

Start the MCP Server (AI connection entry point)

See docs/commands.md (bilingual) for aliases, subcommands, arguments, and category descriptions of all commands.

Customize story types/statuses and localized labels:

{
  "types": ["original", "fanfic", "translation"],
  "statuses": ["completed", "ongoing", "planned"],
  "typeLabels": { "translation": { "zh": "翻译", "en": "Translation" } }
}

Built-in enums already include labels, so no repeated configuration is needed. Deleting the file falls back to defaults.


📚 Documentation

Documentation

Chinese

English

Content

Design Philosophy

design.md

design.en.md

Project philosophy

Repository Spec

specification.md

specification.en.md

Data specification

How to Add Content

add-story.md

add-story.en.md

Directory convention

Content Export

export.md

export.en.md

Export guide

EPUB / PDF

epub.md

epub.en.md

EPUB export

CI

ci.md

ci.en.md

GitHub Actions

MCP Server

mcp.md

mcp.en.md

AI connection guide

Architecture

architecture.md

architecture.en.md

Module design

Command Reference

commands.md

commands.en.md

Full command list

Changelog

CHANGELOG.md

CHANGELOG.en.md

Change log


⚠️ Encoding Requirements

All files must use UTF-8 encoding. A warning is raised when GBK/GB2312 is detected, but the build is not blocked.


🧪 Testing

make test         # 或 pnpm test

All 550+ tests pass. Coverage: scanner, series grouping, validation, template rendering, word counting, internationalization, README generation, EPUB export, CLI end-to-end (smoke tests cover all commands), .storyignore, MCP protocol, JSON import, GitHub Action structure, compliance checks, link suggestions, incremental build cache, embeddings export, and more.


☕ Sponsorship


⚖️ License

MIT


🤝 Contributing

Issues are welcome (bug reports / feature suggestions, form templates available); if you'd like to contribute code, please read CONTRIBUTING.md and learn about the project's positioning in ROADMAP.md.

Available Tools

9 tools
buildA
Idempotent

重建所有 README(等效 story build)。返回构建结果与捕获的输出日志

Inputs: no named parameters.

create_storyA

创建一个新故事(文件夹 + config.json + text.md 草稿)

Inputs: title (required), type, series, status, +3 more.

edit_configA
Idempotent

更新故事 config.json 的元数据字段。可编辑:summary/status/series/seriesOrder/volume/links/author/originalWork/originalAuthor/cover/language/wordCount。字段值传 null 表示移除该可选字段。title/type/created/isMultiChapter 为身份或审计字段,禁止修改。写入前经仓库级 schema 校验,校验失败不写盘。修改后请运行 build 更新 README

Inputs: fields (required), folder (required).

import_jsonA

从结构化 JSON 批量导入故事(与 CLI import json 同构)

Inputs: stories (required).

read_chapterA
Read-only

读取指定故事的章节内容(支持按章节索引按需加载)。tailLength 可只返回章节末尾 N 字符用于续写衔接,节省 Token

Inputs: folder (required), tailLength, chapterIndex.

scan_storiesA
Read-only

列出所有故事及元数据(标题/类型/状态/字数/系列)。默认返回精简列表节省 Token;传 verbose=true 获取完整详情

Inputs: verbose.

statsA
Read-only

获取故事库写作统计(总字数/章节数/系列分组/健康度/重复短语)

Inputs: no named parameters.

validateA
Read-only

检查仓库合规性(目录命名/必需文件/config schema/编码),等效 CLI story validate

Inputs: no named parameters.

write_chapterA
Idempotent

将正文写入指定故事(原子写入 text.md)。validate=true 时写入后立即执行仓库合规检查并返回结果(不阻断写入)

Inputs: folder (required), content (required), validate.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.9/5.0

    Scored across 9 tools

    Disambiguation5/5

    Each tool targets a distinct operation or resource: creating/importing stories, reading/writing chapters, editing config, validating, building, stats, and scanning. There is no real overlap, and the descriptions clarify boundaries even where purposes are adjacent, such as create_story vs import_json.

    Naming Consistency4/5

    Most tools follow a clear verb_noun snake_case pattern (create_story, scan_stories, read_chapter, write_chapter, edit_config, import_json). validate, build, and stats are shorter imperative/noun names but are still intuitive and do not break the overall predictability.

    Tool Count5/5

    Nine tools is well-scoped for a story authoring workflow. Each tool has a clearly defined role, and none feel redundant or unnecessary for the server's purpose.

    Completeness3/5

    The core authoring loop is covered: create, read/write chapters, edit metadata, validate, build, and get stats. However, there is no delete story/chapter operation and no explicit chapter listing tool, leaving lifecycle management incomplete. Agents could work around some gaps, but deletion is a notable missing capability.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • F
      license
      C
      quality
      D
      maintenance
      Git-backed MCP server for creating and maintaining an Obsidian-style markdown knowledge base with full CRUD, search, and git sync.
      7
      -
    • A
      license
      A
      quality
      B
      maintenance
      Repository-native protocol and MCP server for coordinating work items, documentation, changelogs, and project memory between humans and AI agents, using Markdown files in a Git repository as the canonical data source.
      30
      3
      MIT
    • A
      license
      A
      quality
      C
      maintenance
      Provides fast, read-only access to Karpathy-style Markdown wikis through MCP, with search, page retrieval, and orientation tools. Supports local stdio and remote Streamable HTTP deployments backed by Git, including automatic webhook synchronization.
      3
      MIT