Back to home@Tinger-X

dsh-chapter-word-counter

DeepSeek Harness (DSH) tool plugin: count the body word count of novel chapter files — chapter_words_count(files) -> [counts]

Stars
0
Language
JavaScript
Created
Sep 7, 2026
Updated
Sep 7, 2026

Introduction

dsh-chapter-word-counter

DeepSeek Harness (DSH) 章节字数统计工具插件(Cordis 插件)。 DSH tool plugin: count the body word count of novel chapter text files.

注册一个模型可直接调用的工具 chapter_words_count:传入章节文件路径列表,返回与输入顺序一致的正文字数列表。

chapter_words_count(file1, file2, ...) -> [3156, 3349, ...]

统计规则(Counting rule)

  1. 忽略第一行(章节号 + 标题,如「第001章 开篇」);
  2. 去除换行符(以及空格、制表符、全角空格等一切空白字符)——只统计正文中的文字和标点;
  3. 其余每个字符(汉字、标点、数字、字母)计 1 字,按码点计数。
  • 路径由 DSH 文件系统后端解析(绝对路径或工作区相对路径),受当前沙箱权限约束;
  • 文件不存在或不是普通文件时报错;
  • 空文件或只有标题行的文件计 0。

包结构(Layout)

lib/count.js   纯计数逻辑(零依赖,可独立测试、独立 import)
lib/index.js   Cordis 插件本体:name / inject / Config / apply
test/          node:test 单元测试(npm test)

插件按 Cordis/DSP 惯例导出 { Config, apply, inject, name }

  • name = "dsh-chapter-word-counter"(加载器补丁行按此名引用)
  • inject = ["tools", "fs"](工具注册表 + 沙箱化文件系统服务)
  • ctx.tools.register(defineTool({...})) 注册,工具名 chapter_words_count
  • 读取文件一律走 ctx.fs(与内置 read/write 工具同一沙箱与观测链路)

安装到 DeepSeek Harness(Install & activate)

在 profile 的补丁层($DSH_HOME/profiles/<name>/cordis.patch.yml)插入一行:

- insert:
    - id: dsh-chapter-word-counter
      name: 'dsh-chapter-word-counter'

并把本包安装到插件解析路径。两种方式:

方式 A(推荐,标准):在 profile 目录用 pnpm 安装本包后,按包名引用:

dsh plugin --profile web add dsh-chapter-word-counter@github:Tinger-X/dsh-chapter-word-counter
# 或先克隆到本地后:dsh plugin --profile web add file:D:\...\dsh-chapter-word-counter

方式 B(手动):把整个包目录复制到 DSH 安装目录的 node_modules 下(加载器从安装目录解析裸包名):

$src = '<本仓库目录>'
$dst = '<DSH 安装目录>\node_modules\dsh-chapter-word-counter'
Copy-Item $src $dst -Recurse

profile 补丁层会被运行中的服务热加载(watchUserPatches),通常无需重启;若未生效,重启 dsh web 即可。

开发与测试(Develop & test)

npm install     # 安装 schemastery 及 @deepseek-ai/* 开发依赖
npm test        # node --test test/

计数规则自检样例:

输入正文字数
第001章 开篇\n晨光落进窗来,檐角有风。\n猫在打盹。\n17
第999章 测试\nABC123,。!?\n10
空文件 / 只有标题行0

License

MIT © Tinger-X