novelws 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +161 -0
- package/LICENSE +22 -0
- package/README.md +372 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +50 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/check.d.ts +6 -0
- package/dist/commands/check.d.ts.map +1 -0
- package/dist/commands/check.js +32 -0
- package/dist/commands/check.js.map +1 -0
- package/dist/commands/init.d.ts +6 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +160 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/plugin.d.ts +6 -0
- package/dist/commands/plugin.d.ts.map +1 -0
- package/dist/commands/plugin.js +135 -0
- package/dist/commands/plugin.js.map +1 -0
- package/dist/commands/upgrade.d.ts +6 -0
- package/dist/commands/upgrade.d.ts.map +1 -0
- package/dist/commands/upgrade.js +92 -0
- package/dist/commands/upgrade.js.map +1 -0
- package/dist/core/config.d.ts +72 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/config.js +136 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/errors.d.ts +59 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +125 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/platform.d.ts +27 -0
- package/dist/core/platform.d.ts.map +1 -0
- package/dist/core/platform.js +75 -0
- package/dist/core/platform.js.map +1 -0
- package/dist/core/template.d.ts +35 -0
- package/dist/core/template.d.ts.map +1 -0
- package/dist/core/template.js +94 -0
- package/dist/core/template.js.map +1 -0
- package/dist/plugins/identifier.d.ts +13 -0
- package/dist/plugins/identifier.d.ts.map +1 -0
- package/dist/plugins/identifier.js +72 -0
- package/dist/plugins/identifier.js.map +1 -0
- package/dist/plugins/installers/base.d.ts +27 -0
- package/dist/plugins/installers/base.d.ts.map +1 -0
- package/dist/plugins/installers/base.js +30 -0
- package/dist/plugins/installers/base.js.map +1 -0
- package/dist/plugins/installers/github.d.ts +22 -0
- package/dist/plugins/installers/github.d.ts.map +1 -0
- package/dist/plugins/installers/github.js +133 -0
- package/dist/plugins/installers/github.js.map +1 -0
- package/dist/plugins/installers/local.d.ts +16 -0
- package/dist/plugins/installers/local.d.ts.map +1 -0
- package/dist/plugins/installers/local.js +69 -0
- package/dist/plugins/installers/local.js.map +1 -0
- package/dist/plugins/installers/npm.d.ts +20 -0
- package/dist/plugins/installers/npm.d.ts.map +1 -0
- package/dist/plugins/installers/npm.js +99 -0
- package/dist/plugins/installers/npm.js.map +1 -0
- package/dist/plugins/manager.d.ts +77 -0
- package/dist/plugins/manager.d.ts.map +1 -0
- package/dist/plugins/manager.js +349 -0
- package/dist/plugins/manager.js.map +1 -0
- package/dist/plugins/registry.d.ts +48 -0
- package/dist/plugins/registry.d.ts.map +1 -0
- package/dist/plugins/registry.js +111 -0
- package/dist/plugins/registry.js.map +1 -0
- package/dist/plugins/types.d.ts +66 -0
- package/dist/plugins/types.d.ts.map +1 -0
- package/dist/plugins/types.js +2 -0
- package/dist/plugins/types.js.map +1 -0
- package/dist/plugins/validator.d.ts +19 -0
- package/dist/plugins/validator.d.ts.map +1 -0
- package/dist/plugins/validator.js +164 -0
- package/dist/plugins/validator.js.map +1 -0
- package/dist/utils/logger.d.ts +13 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +48 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/project.d.ts +24 -0
- package/dist/utils/project.d.ts.map +1 -0
- package/dist/utils/project.js +61 -0
- package/dist/utils/project.js.map +1 -0
- package/dist/version.d.ts +3 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +21 -0
- package/dist/version.js.map +1 -0
- package/package.json +76 -0
- package/plugins/authentic-voice/README.md +31 -0
- package/plugins/authentic-voice/commands/authentic-voice.md +73 -0
- package/plugins/authentic-voice/commands/authenticity-audit.md +37 -0
- package/plugins/authentic-voice/config.yaml +30 -0
- package/plugins/authentic-voice/experts/authentic-editor.md +27 -0
- package/plugins/export/README.md +319 -0
- package/plugins/export/commands/export.md +460 -0
- package/plugins/export/commands/generate-cover.md +256 -0
- package/plugins/export/commands/metadata.md +309 -0
- package/plugins/export/config.yaml +47 -0
- package/plugins/export/experts/publishing-expert.md +171 -0
- package/plugins/export/templates/epub/chapter-template.html +13 -0
- package/plugins/export/templates/epub/cover-template.html +14 -0
- package/plugins/export/templates/epub/stylesheet.css +200 -0
- package/plugins/export/templates/pdf/ebook-style.css +137 -0
- package/plugins/export/templates/pdf/print-style.css +179 -0
- package/plugins/export/templates/platforms/jinjiang-format.md +101 -0
- package/plugins/export/templates/platforms/qidian-format.md +108 -0
- package/plugins/export/templates/platforms/tomato-format.md +95 -0
- package/plugins/translate/README.md +265 -0
- package/plugins/translate/commands/glossary.md +731 -0
- package/plugins/translate/commands/translate-preview.md +543 -0
- package/plugins/translate/commands/translate.md +649 -0
- package/plugins/translate/config.yaml +43 -0
- package/plugins/translate/experts/literary-translator.md +605 -0
- package/templates/commands/analyze.md +1485 -0
- package/templates/commands/checklist.md +434 -0
- package/templates/commands/clarify.md +257 -0
- package/templates/commands/constitution.md +257 -0
- package/templates/commands/expert.md +136 -0
- package/templates/commands/plan.md +749 -0
- package/templates/commands/recap.md +613 -0
- package/templates/commands/relations.md +96 -0
- package/templates/commands/revise.md +341 -0
- package/templates/commands/specify.md +682 -0
- package/templates/commands/tasks.md +142 -0
- package/templates/commands/timeline.md +73 -0
- package/templates/commands/track-init.md +137 -0
- package/templates/commands/track.md +463 -0
- package/templates/commands/write.md +1264 -0
- package/templates/config/keyword-mappings.json +106 -0
- package/templates/knowledge/audit-config.json +26 -0
- package/templates/knowledge/character-profiles.md +152 -0
- package/templates/knowledge/character-voices.md +137 -0
- package/templates/knowledge/locations.md +184 -0
- package/templates/knowledge/world-setting.md +121 -0
- package/templates/knowledge-base/README.md +285 -0
- package/templates/knowledge-base/character-archetypes/01-hero.md +233 -0
- package/templates/knowledge-base/character-archetypes/02-mentor.md +177 -0
- package/templates/knowledge-base/character-archetypes/03-shadow.md +221 -0
- package/templates/knowledge-base/character-archetypes/04-ally.md +178 -0
- package/templates/knowledge-base/character-archetypes/05-shapeshifter.md +177 -0
- package/templates/knowledge-base/character-archetypes/06-trickster.md +181 -0
- package/templates/knowledge-base/character-archetypes/07-threshold-guardian.md +177 -0
- package/templates/knowledge-base/character-archetypes/08-herald.md +180 -0
- package/templates/knowledge-base/character-archetypes/09-father.md +249 -0
- package/templates/knowledge-base/character-archetypes/10-mother.md +202 -0
- package/templates/knowledge-base/character-archetypes/11-child.md +183 -0
- package/templates/knowledge-base/character-archetypes/12-sage.md +202 -0
- package/templates/knowledge-base/character-archetypes/README.md +60 -0
- package/templates/knowledge-base/character-archetypes/application-guide.md +222 -0
- package/templates/knowledge-base/character-archetypes/archetype-combinations.md +242 -0
- package/templates/knowledge-base/character-archetypes/config.yaml +28 -0
- package/templates/knowledge-base/character-archetypes/examples-analysis.md +223 -0
- package/templates/knowledge-base/craft/character-arc.md +1153 -0
- package/templates/knowledge-base/craft/dialogue.md +1170 -0
- package/templates/knowledge-base/craft/pacing.md +1200 -0
- package/templates/knowledge-base/craft/scene-structure.md +1136 -0
- package/templates/knowledge-base/craft/show-not-tell.md +1012 -0
- package/templates/knowledge-base/emotional-beats/01-first-meeting.md +145 -0
- package/templates/knowledge-base/emotional-beats/02-bonding-moment.md +226 -0
- package/templates/knowledge-base/emotional-beats/03-declaration.md +284 -0
- package/templates/knowledge-base/emotional-beats/04-triumph.md +240 -0
- package/templates/knowledge-base/emotional-beats/05-reunion.md +396 -0
- package/templates/knowledge-base/emotional-beats/06-forgiveness.md +204 -0
- package/templates/knowledge-base/emotional-beats/07-betrayal.md +204 -0
- package/templates/knowledge-base/emotional-beats/08-loss.md +214 -0
- package/templates/knowledge-base/emotional-beats/09-rejection.md +254 -0
- package/templates/knowledge-base/emotional-beats/10-failure.md +244 -0
- package/templates/knowledge-base/emotional-beats/11-misunderstanding.md +205 -0
- package/templates/knowledge-base/emotional-beats/12-farewell.md +283 -0
- package/templates/knowledge-base/emotional-beats/13-revelation.md +242 -0
- package/templates/knowledge-base/emotional-beats/14-point-of-no-return.md +215 -0
- package/templates/knowledge-base/emotional-beats/15-dark-night.md +244 -0
- package/templates/knowledge-base/emotional-beats/16-sacrifice.md +246 -0
- package/templates/knowledge-base/emotional-beats/17-awakening.md +246 -0
- package/templates/knowledge-base/emotional-beats/18-confrontation.md +217 -0
- package/templates/knowledge-base/emotional-beats/19-bittersweet-goodbye.md +368 -0
- package/templates/knowledge-base/emotional-beats/20-moral-dilemma.md +248 -0
- package/templates/knowledge-base/emotional-beats/21-temptation.md +240 -0
- package/templates/knowledge-base/emotional-beats/22-redemption.md +210 -0
- package/templates/knowledge-base/emotional-beats/README.md +104 -0
- package/templates/knowledge-base/emotional-beats/beat-sequences.md +276 -0
- package/templates/knowledge-base/emotional-beats/config.yaml +30 -0
- package/templates/knowledge-base/emotional-beats/pacing-guide.md +390 -0
- package/templates/knowledge-base/genres/historical.md +1127 -0
- package/templates/knowledge-base/genres/mystery.md +1123 -0
- package/templates/knowledge-base/genres/revenge.md +846 -0
- package/templates/knowledge-base/genres/romance.md +948 -0
- package/templates/knowledge-base/genres/sci-fi.md +156 -0
- package/templates/knowledge-base/genres/thriller.md +166 -0
- package/templates/knowledge-base/genres/wuxia.md +143 -0
- package/templates/knowledge-base/references/README.md +96 -0
- package/templates/knowledge-base/references/china-1920s/culture.md +423 -0
- package/templates/knowledge-base/references/china-1920s/daily-life.md +616 -0
- package/templates/knowledge-base/references/china-1920s/overview.md +298 -0
- package/templates/knowledge-base/references/china-1920s/society.md +703 -0
- package/templates/knowledge-base/references/china-1920s/warlords.md +427 -0
- package/templates/knowledge-base/references/cultivation-world/daily-life.md +108 -0
- package/templates/knowledge-base/references/cultivation-world/overview.md +64 -0
- package/templates/knowledge-base/references/cultivation-world/power-system.md +108 -0
- package/templates/knowledge-base/references/cultivation-world/sects.md +104 -0
- package/templates/knowledge-base/references/cultivation-world/world-setting.md +108 -0
- package/templates/knowledge-base/references/modern-workplace/corporate.md +115 -0
- package/templates/knowledge-base/references/modern-workplace/daily-life.md +129 -0
- package/templates/knowledge-base/references/modern-workplace/overview.md +73 -0
- package/templates/knowledge-base/references/modern-workplace/relationships.md +107 -0
- package/templates/knowledge-base/references/modern-workplace/tech-industry.md +131 -0
- package/templates/knowledge-base/references/tang-dynasty/culture.md +135 -0
- package/templates/knowledge-base/references/tang-dynasty/daily-life.md +139 -0
- package/templates/knowledge-base/references/tang-dynasty/overview.md +76 -0
- package/templates/knowledge-base/references/tang-dynasty/politics.md +121 -0
- package/templates/knowledge-base/references/tang-dynasty/society.md +126 -0
- package/templates/knowledge-base/requirements/README.md +240 -0
- package/templates/knowledge-base/requirements/anti-ai-v3.md +46 -0
- package/templates/knowledge-base/requirements/anti-ai-v4.md +430 -0
- package/templates/knowledge-base/requirements/fast-paced.md +552 -0
- package/templates/knowledge-base/requirements/no-poison.md +60 -0
- package/templates/knowledge-base/requirements/romance-angst.md +102 -0
- package/templates/knowledge-base/requirements/romance-sweet.md +63 -0
- package/templates/knowledge-base/requirements/serious-literature.md +45 -0
- package/templates/knowledge-base/requirements/strong-emotion.md +60 -0
- package/templates/knowledge-base/styles/README.md +302 -0
- package/templates/knowledge-base/styles/ancient-style.md +579 -0
- package/templates/knowledge-base/styles/literary.md +439 -0
- package/templates/knowledge-base/styles/minimal.md +472 -0
- package/templates/knowledge-base/styles/natural-voice.md +930 -0
- package/templates/knowledge-base/styles/web-novel.md +525 -0
- package/templates/memory/constitution.md +140 -0
- package/templates/memory/personal-voice.md +113 -0
- package/templates/scripts/README.md +187 -0
- package/templates/scripts/bash/analyze-story.sh +170 -0
- package/templates/scripts/bash/check-consistency.sh +463 -0
- package/templates/scripts/bash/check-plot.sh +374 -0
- package/templates/scripts/bash/check-timeline.sh +346 -0
- package/templates/scripts/bash/check-world.sh +395 -0
- package/templates/scripts/bash/check-writing-state.sh +854 -0
- package/templates/scripts/bash/clarify-story.sh +117 -0
- package/templates/scripts/bash/common.sh +151 -0
- package/templates/scripts/bash/constitution.sh +114 -0
- package/templates/scripts/bash/generate-tasks.sh +65 -0
- package/templates/scripts/bash/init-tracking.sh +183 -0
- package/templates/scripts/bash/manage-relations.sh +174 -0
- package/templates/scripts/bash/plan-story.sh +100 -0
- package/templates/scripts/bash/specify-story.sh +93 -0
- package/templates/scripts/bash/tasks-story.sh +96 -0
- package/templates/scripts/bash/test-word-count.sh +182 -0
- package/templates/scripts/bash/tests/bench-preload-cache.sh +100 -0
- package/templates/scripts/bash/tests/run-all-benchmarks.sh +16 -0
- package/templates/scripts/bash/tests/test-cache-semantics.sh +199 -0
- package/templates/scripts/bash/tests/test-cross-platform.sh +35 -0
- package/templates/scripts/bash/tests/test-edge-cases-bash.sh +60 -0
- package/templates/scripts/bash/tests/test-phase1-bash.sh +28 -0
- package/templates/scripts/bash/tests/test-preload-cache.sh +123 -0
- package/templates/scripts/bash/tests/test-regex-precompile.sh +89 -0
- package/templates/scripts/bash/tests/test-regression-bash.sh +42 -0
- package/templates/scripts/bash/tests/test-task6-verification.sh +200 -0
- package/templates/scripts/bash/text-audit.sh +144 -0
- package/templates/scripts/bash/track-progress.sh +194 -0
- package/templates/scripts/powershell/analyze-story.ps1 +171 -0
- package/templates/scripts/powershell/check-analyze-stage.ps1 +110 -0
- package/templates/scripts/powershell/check-consistency.ps1 +138 -0
- package/templates/scripts/powershell/check-plot.ps1 +139 -0
- package/templates/scripts/powershell/check-timeline.ps1 +112 -0
- package/templates/scripts/powershell/check-writing-state.ps1 +490 -0
- package/templates/scripts/powershell/check-writing-state.ps1.backup +135 -0
- package/templates/scripts/powershell/clarify-story.ps1 +107 -0
- package/templates/scripts/powershell/common.ps1 +36 -0
- package/templates/scripts/powershell/constitution.ps1 +142 -0
- package/templates/scripts/powershell/generate-tasks.ps1 +75 -0
- package/templates/scripts/powershell/init-tracking.ps1 +98 -0
- package/templates/scripts/powershell/manage-relations.ps1 +134 -0
- package/templates/scripts/powershell/plan-story.ps1 +96 -0
- package/templates/scripts/powershell/specify-story.ps1 +82 -0
- package/templates/scripts/powershell/tests/bench-ps-cache.ps1 +80 -0
- package/templates/scripts/powershell/tests/test-cross-platform.ps1 +27 -0
- package/templates/scripts/powershell/tests/test-edge-cases-ps.ps1 +29 -0
- package/templates/scripts/powershell/tests/test-phase1-ps.ps1 +28 -0
- package/templates/scripts/powershell/tests/test-ps-cache.ps1 +73 -0
- package/templates/scripts/powershell/tests/test-regression-ps.ps1 +40 -0
- package/templates/scripts/powershell/text-audit.ps1 +100 -0
- package/templates/scripts/powershell/track-progress.ps1 +105 -0
- package/templates/skills/genre-knowledge/fantasy/SKILL.md +355 -0
- package/templates/skills/genre-knowledge/mystery/SKILL.md +337 -0
- package/templates/skills/genre-knowledge/romance/SKILL.md +228 -0
- package/templates/skills/genre-knowledge/sci-fi/SKILL.md +65 -0
- package/templates/skills/genre-knowledge/thriller/SKILL.md +95 -0
- package/templates/skills/quality-assurance/consistency-checker/SKILL.md +341 -0
- package/templates/skills/quality-assurance/continuity-tracker/SKILL.md +157 -0
- package/templates/skills/quality-assurance/forgotten-elements/SKILL.md +147 -0
- package/templates/skills/quality-assurance/getting-started/SKILL.md +224 -0
- package/templates/skills/quality-assurance/pacing-monitor/SKILL.md +143 -0
- package/templates/skills/quality-assurance/pov-validator/SKILL.md +135 -0
- package/templates/skills/quality-assurance/pre-write-checklist/SKILL.md +583 -0
- package/templates/skills/quality-assurance/requirement-detector/CONFLICT_RESOLUTION.md +119 -0
- package/templates/skills/quality-assurance/requirement-detector/EXAMPLES.md +146 -0
- package/templates/skills/quality-assurance/requirement-detector/KEYWORDS.md +160 -0
- package/templates/skills/quality-assurance/requirement-detector/SKILL.md +149 -0
- package/templates/skills/quality-assurance/setting-detector/SKILL.md +611 -0
- package/templates/skills/quality-assurance/style-detector/CONFLICT_RESOLUTION.md +126 -0
- package/templates/skills/quality-assurance/style-detector/EXAMPLES.md +206 -0
- package/templates/skills/quality-assurance/style-detector/KEYWORDS.md +207 -0
- package/templates/skills/quality-assurance/style-detector/SKILL.md +126 -0
- package/templates/skills/quality-assurance/workflow-guide/SKILL.md +381 -0
- package/templates/skills/writing-techniques/character-arc/SKILL.md +267 -0
- package/templates/skills/writing-techniques/dialogue-techniques/SKILL.md +366 -0
- package/templates/skills/writing-techniques/multi-thread-narrative/SKILL.md +553 -0
- package/templates/skills/writing-techniques/multi-thread-narrative/experts/thread-analyst.md +226 -0
- package/templates/skills/writing-techniques/pacing-control/SKILL.md +377 -0
- package/templates/skills/writing-techniques/reader-expectation/SKILL.md +578 -0
- package/templates/skills/writing-techniques/reader-expectation/experts/expectation-analyst.md +209 -0
- package/templates/skills/writing-techniques/revision-polish/SKILL.md +496 -0
- package/templates/skills/writing-techniques/revision-polish/experts/revision-editor.md +221 -0
- package/templates/skills/writing-techniques/scene-structure/SKILL.md +361 -0
- package/templates/skills/writing-techniques/style-learning/SKILL.md +436 -0
- package/templates/specification-example.md +146 -0
- package/templates/tracking/character-state.json +78 -0
- package/templates/tracking/plot-tracker.json +62 -0
- package/templates/tracking/relationships.json +70 -0
- package/templates/tracking/timeline.json +49 -0
- package/templates/tracking/tracking-log.md +110 -0
- package/templates/tracking/validation-rules.json +128 -0
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# 角色关系管理(Bash)
|
|
3
|
+
|
|
4
|
+
set -e
|
|
5
|
+
|
|
6
|
+
SCRIPT_DIR=$(dirname "$0")
|
|
7
|
+
source "$SCRIPT_DIR/common.sh"
|
|
8
|
+
|
|
9
|
+
PROJECT_ROOT=$(get_project_root)
|
|
10
|
+
STORY_DIR=$(get_current_story)
|
|
11
|
+
|
|
12
|
+
REL_FILE=""
|
|
13
|
+
if [ -n "$STORY_DIR" ] && [ -f "$STORY_DIR/spec/tracking/relationships.json" ]; then
|
|
14
|
+
REL_FILE="$STORY_DIR/spec/tracking/relationships.json"
|
|
15
|
+
elif [ -f "$PROJECT_ROOT/spec/tracking/relationships.json" ]; then
|
|
16
|
+
REL_FILE="$PROJECT_ROOT/spec/tracking/relationships.json"
|
|
17
|
+
else
|
|
18
|
+
# 尝试用模板初始化
|
|
19
|
+
mkdir -p "$PROJECT_ROOT/spec/tracking"
|
|
20
|
+
if [ -f "$PROJECT_ROOT/.specify/templates/tracking/relationships.json" ]; then
|
|
21
|
+
cp "$PROJECT_ROOT/.specify/templates/tracking/relationships.json" "$PROJECT_ROOT/spec/tracking/relationships.json"
|
|
22
|
+
REL_FILE="$PROJECT_ROOT/spec/tracking/relationships.json"
|
|
23
|
+
elif [ -f "$SCRIPT_DIR/../../templates/tracking/relationships.json" ]; then
|
|
24
|
+
cp "$SCRIPT_DIR/../../templates/tracking/relationships.json" "$PROJECT_ROOT/spec/tracking/relationships.json"
|
|
25
|
+
REL_FILE="$PROJECT_ROOT/spec/tracking/relationships.json"
|
|
26
|
+
else
|
|
27
|
+
echo "❌ 未找到 relationships.json,且无法从模板创建" >&2
|
|
28
|
+
exit 1
|
|
29
|
+
fi
|
|
30
|
+
fi
|
|
31
|
+
|
|
32
|
+
CMD=${1:-show}
|
|
33
|
+
shift || true
|
|
34
|
+
|
|
35
|
+
print_header() {
|
|
36
|
+
echo "👥 角色关系管理"
|
|
37
|
+
echo "━━━━━━━━━━━━━━━━━━━━"
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
cmd_show() {
|
|
41
|
+
print_header
|
|
42
|
+
if ! jq empty "$REL_FILE" >/dev/null 2>&1; then
|
|
43
|
+
echo "❌ relationships.json 格式无效" >&2; exit 1
|
|
44
|
+
fi
|
|
45
|
+
|
|
46
|
+
echo "文件:$REL_FILE"
|
|
47
|
+
echo ""
|
|
48
|
+
# 输出主角或首个角色关系摘要
|
|
49
|
+
local main_char=$(jq -r '.characters | keys[0] // ""' "$REL_FILE")
|
|
50
|
+
if [ -z "$main_char" ] || [ "$main_char" = "null" ]; then
|
|
51
|
+
echo "无角色记录"
|
|
52
|
+
exit 0
|
|
53
|
+
fi
|
|
54
|
+
echo "主角:$main_char"
|
|
55
|
+
# 支持两种结构:嵌套 relationships 或直接分类键
|
|
56
|
+
jq -r --arg name "$main_char" '
|
|
57
|
+
.characters[$name] as $c |
|
|
58
|
+
($c.relationships // $c) as $r |
|
|
59
|
+
[
|
|
60
|
+
{k:"romantic", v:($r.romantic // [])},
|
|
61
|
+
{k:"allies", v:($r.allies // [])},
|
|
62
|
+
{k:"mentors", v:($r.mentors // [])},
|
|
63
|
+
{k:"enemies", v:($r.enemies // [])},
|
|
64
|
+
{k:"family", v:($r.family // [])},
|
|
65
|
+
{k:"neutral", v:($r.neutral // [])}
|
|
66
|
+
] | .[] | select((.v|length)>0) |
|
|
67
|
+
"├─ " + (if .k=="romantic" then "💕 爱慕" elseif .k=="allies" then "🤝 盟友" elseif .k=="mentors" then "📚 导师" elseif .k=="enemies" then "⚔️ 敌对" elseif .k=="family" then "👪 家人" else "・ 关系" end) + ":" + (.v | join("、"))
|
|
68
|
+
' "$REL_FILE"
|
|
69
|
+
|
|
70
|
+
# 最近变化
|
|
71
|
+
echo ""
|
|
72
|
+
if jq -e '.history' "$REL_FILE" >/dev/null 2>&1; then
|
|
73
|
+
local recent=$(jq -r '.history[-1] // empty' "$REL_FILE")
|
|
74
|
+
if [ -n "$recent" ]; then
|
|
75
|
+
echo "最近变化:"
|
|
76
|
+
jq -r '.history[-1].changes[]? | "- " + (.characters|join("↔")) + ":" + (.relation // .type // "变化")' "$REL_FILE"
|
|
77
|
+
fi
|
|
78
|
+
elif jq -e '.relationshipChanges' "$REL_FILE" >/dev/null 2>&1; then
|
|
79
|
+
echo "最近变化:"
|
|
80
|
+
jq -r '.relationshipChanges[-5:][]? | "- " + (.type // "变化") + ": " + (.characters|join("↔"))' "$REL_FILE" 2>/dev/null || true
|
|
81
|
+
fi
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
cmd_update() {
|
|
85
|
+
local a="$1"; local rel="$2"; local b="$3"; shift 3 || true
|
|
86
|
+
local chapter=""; local note=""
|
|
87
|
+
while [ $# -gt 0 ]; do
|
|
88
|
+
case "$1" in
|
|
89
|
+
--chapter) chapter="$2"; shift 2;;
|
|
90
|
+
--note) note="$2"; shift 2;;
|
|
91
|
+
*) shift;;
|
|
92
|
+
esac
|
|
93
|
+
done
|
|
94
|
+
if [ -z "$a" ] || [ -z "$rel" ] || [ -z "$b" ]; then
|
|
95
|
+
echo "用法: manage-relations.sh update <人物A> <allies|enemies|romantic|neutral|family|mentors> <人物B> [--chapter N] [--note 说明]" >&2
|
|
96
|
+
exit 1
|
|
97
|
+
fi
|
|
98
|
+
|
|
99
|
+
# 确保角色节点存在
|
|
100
|
+
for name in "$a" "$b"; do
|
|
101
|
+
if ! jq --arg n "$name" '(.characters[$n] // null) != null' "$REL_FILE" | grep -q true; then
|
|
102
|
+
tmp=$(mktemp)
|
|
103
|
+
jq --arg n "$name" '.characters[$n] = (.characters[$n] // {name:$n, relationships:{allies:[],enemies:[],romantic:[],family:[],mentors:[],neutral:[]}})' "$REL_FILE" > "$tmp"
|
|
104
|
+
mv "$tmp" "$REL_FILE"
|
|
105
|
+
fi
|
|
106
|
+
done
|
|
107
|
+
|
|
108
|
+
# 写入关系
|
|
109
|
+
tmp=$(mktemp)
|
|
110
|
+
jq --arg a "$a" --arg b "$b" --arg rel "$rel" '
|
|
111
|
+
.characters[$a].relationships[$rel] = ((.characters[$a].relationships[$rel] // []) + [$b] | unique) |
|
|
112
|
+
.lastUpdated = now | todate
|
|
113
|
+
' "$REL_FILE" > "$tmp"
|
|
114
|
+
mv "$tmp" "$REL_FILE"
|
|
115
|
+
|
|
116
|
+
# 记录历史(history 优先,否则 relationshipChanges)
|
|
117
|
+
local now=$(date -Iseconds)
|
|
118
|
+
if jq -e '.history' "$REL_FILE" >/dev/null 2>&1; then
|
|
119
|
+
tmp=$(mktemp)
|
|
120
|
+
jq --arg ch "${chapter:-null}" --arg a "$a" --arg b "$b" --arg rel "$rel" --arg note "$note" --arg t "$now" '
|
|
121
|
+
.history += [{
|
|
122
|
+
chapter: ( ($ch|tonumber) // null ),
|
|
123
|
+
date: $t,
|
|
124
|
+
changes: [{ type: "update", characters: [$a,$b], relation: $rel, note: ($note // "") }]
|
|
125
|
+
}]
|
|
126
|
+
' "$REL_FILE" > "$tmp" && mv "$tmp" "$REL_FILE"
|
|
127
|
+
else
|
|
128
|
+
tmp=$(mktemp)
|
|
129
|
+
jq --arg a "$a" --arg b "$b" --arg rel "$rel" '.relationshipChanges += [{type:"update", characters:[$a,$b], relation:$rel}]' "$REL_FILE" > "$tmp" && mv "$tmp" "$REL_FILE"
|
|
130
|
+
fi
|
|
131
|
+
|
|
132
|
+
echo "✅ 已更新关系:$a [$rel] $b"
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
cmd_history() {
|
|
136
|
+
print_header
|
|
137
|
+
if jq -e '.history' "$REL_FILE" >/dev/null 2>&1; then
|
|
138
|
+
jq -r '.history[] | "第" + ((.chapter // 0|tostring)) + "章:" + (.changes | map((.characters|join("↔"))+"→"+(.relation // .type)) | join(";"))' "$REL_FILE"
|
|
139
|
+
elif jq -e '.relationshipChanges' "$REL_FILE" >/dev/null 2>&1; then
|
|
140
|
+
jq -r '.relationshipChanges[] | (.date // "") + " " + (.type // "") + ": " + (.characters|join("↔")) + "→" + (.relation // "")' "$REL_FILE"
|
|
141
|
+
else
|
|
142
|
+
echo "暂无历史记录"
|
|
143
|
+
fi
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
cmd_check() {
|
|
147
|
+
print_header
|
|
148
|
+
local issues=0
|
|
149
|
+
# 检查所有引用角色是否存在于 characters
|
|
150
|
+
missing=$(jq -r '
|
|
151
|
+
.characters as $c |
|
|
152
|
+
[
|
|
153
|
+
.characters | to_entries[] | .value.relationships // empty |
|
|
154
|
+
to_entries[] | .value[]
|
|
155
|
+
] | flatten | unique | map(select(has(.) | not))
|
|
156
|
+
' "$REL_FILE" 2>/dev/null || true)
|
|
157
|
+
if [ -n "$missing" ]; then
|
|
158
|
+
echo "⚠️ 发现未建档角色引用,建议补充:"
|
|
159
|
+
echo "$missing"
|
|
160
|
+
issues=1
|
|
161
|
+
fi
|
|
162
|
+
if [ "$issues" -eq 0 ]; then
|
|
163
|
+
echo "✅ 关系数据检查通过"
|
|
164
|
+
fi
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
case "$CMD" in
|
|
168
|
+
show) cmd_show ;;
|
|
169
|
+
update) cmd_update "$@" ;;
|
|
170
|
+
history) cmd_history ;;
|
|
171
|
+
check) cmd_check ;;
|
|
172
|
+
*) echo "用法: $0 [show|update|history|check]" >&2; exit 1;;
|
|
173
|
+
esac
|
|
174
|
+
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# 创作计划脚本
|
|
4
|
+
# 用于 /plan 命令
|
|
5
|
+
|
|
6
|
+
set -e
|
|
7
|
+
|
|
8
|
+
# Source common functions
|
|
9
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
10
|
+
source "$SCRIPT_DIR/common.sh"
|
|
11
|
+
|
|
12
|
+
# Parse arguments
|
|
13
|
+
STORY_NAME=""
|
|
14
|
+
if [ $# -gt 0 ]; then
|
|
15
|
+
STORY_NAME="$1"
|
|
16
|
+
fi
|
|
17
|
+
|
|
18
|
+
# Get project root
|
|
19
|
+
PROJECT_ROOT=$(get_project_root)
|
|
20
|
+
cd "$PROJECT_ROOT"
|
|
21
|
+
|
|
22
|
+
# 确定故事名称
|
|
23
|
+
if [ -z "$STORY_NAME" ]; then
|
|
24
|
+
STORY_NAME=$(get_active_story)
|
|
25
|
+
fi
|
|
26
|
+
|
|
27
|
+
STORY_DIR="stories/$STORY_NAME"
|
|
28
|
+
SPEC_FILE="$STORY_DIR/specification.md"
|
|
29
|
+
CLARIFY_FILE="$STORY_DIR/clarification.md"
|
|
30
|
+
PLAN_FILE="$STORY_DIR/creative-plan.md"
|
|
31
|
+
|
|
32
|
+
echo "创作计划制定"
|
|
33
|
+
echo "============"
|
|
34
|
+
echo "故事:$STORY_NAME"
|
|
35
|
+
echo ""
|
|
36
|
+
|
|
37
|
+
# 检查前置文档
|
|
38
|
+
missing=()
|
|
39
|
+
|
|
40
|
+
if [ ! -f ".specify/memory/constitution.md" ]; then
|
|
41
|
+
missing+=("宪法文件")
|
|
42
|
+
fi
|
|
43
|
+
|
|
44
|
+
if [ ! -f "$SPEC_FILE" ]; then
|
|
45
|
+
missing+=("规格文件")
|
|
46
|
+
fi
|
|
47
|
+
|
|
48
|
+
if [ ${#missing[@]} -gt 0 ]; then
|
|
49
|
+
echo "⚠️ 缺少以下前置文档:"
|
|
50
|
+
for doc in "${missing[@]}"; do
|
|
51
|
+
echo " - $doc"
|
|
52
|
+
done
|
|
53
|
+
echo ""
|
|
54
|
+
echo "请先完成:"
|
|
55
|
+
if [ ! -f ".specify/memory/constitution.md" ]; then
|
|
56
|
+
echo " 1. /constitution - 创建创作宪法"
|
|
57
|
+
fi
|
|
58
|
+
if [ ! -f "$SPEC_FILE" ]; then
|
|
59
|
+
echo " 2. /specify - 定义故事规格"
|
|
60
|
+
fi
|
|
61
|
+
exit 1
|
|
62
|
+
fi
|
|
63
|
+
|
|
64
|
+
# 检查是否有未澄清的点
|
|
65
|
+
if [ -f "$SPEC_FILE" ]; then
|
|
66
|
+
unclear_count=$(grep -o '\[需要澄清\]' "$SPEC_FILE" | wc -l | tr -d ' ')
|
|
67
|
+
|
|
68
|
+
if [ "$unclear_count" -gt 0 ]; then
|
|
69
|
+
echo "⚠️ 规格中有 $unclear_count 处需要澄清"
|
|
70
|
+
echo "建议先运行 /clarify 澄清关键决策"
|
|
71
|
+
echo ""
|
|
72
|
+
fi
|
|
73
|
+
fi
|
|
74
|
+
|
|
75
|
+
# 检查澄清记录
|
|
76
|
+
if [ -f "$CLARIFY_FILE" ]; then
|
|
77
|
+
echo "✅ 已完成澄清,将基于澄清决策制定计划"
|
|
78
|
+
else
|
|
79
|
+
echo "📝 未找到澄清记录,将基于原始规格制定计划"
|
|
80
|
+
fi
|
|
81
|
+
|
|
82
|
+
# 检查计划文件
|
|
83
|
+
if [ -f "$PLAN_FILE" ]; then
|
|
84
|
+
echo ""
|
|
85
|
+
echo "📋 计划文件已存在,将更新现有计划"
|
|
86
|
+
|
|
87
|
+
# 显示当前版本
|
|
88
|
+
if grep -q "版本:" "$PLAN_FILE"; then
|
|
89
|
+
version=$(grep "版本:" "$PLAN_FILE" | head -1 | sed 's/.*版本://')
|
|
90
|
+
echo " 当前版本:$version"
|
|
91
|
+
fi
|
|
92
|
+
else
|
|
93
|
+
echo ""
|
|
94
|
+
echo "📝 将创建新的创作计划"
|
|
95
|
+
fi
|
|
96
|
+
|
|
97
|
+
echo ""
|
|
98
|
+
echo "计划文件路径:$PLAN_FILE"
|
|
99
|
+
echo ""
|
|
100
|
+
echo "准备就绪,可以制定创作计划"
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# 故事规格定义脚本
|
|
4
|
+
# 用于 /specify 命令
|
|
5
|
+
|
|
6
|
+
set -e
|
|
7
|
+
|
|
8
|
+
# Source common functions
|
|
9
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
10
|
+
source "$SCRIPT_DIR/common.sh"
|
|
11
|
+
|
|
12
|
+
# Parse arguments
|
|
13
|
+
JSON_MODE=false
|
|
14
|
+
|
|
15
|
+
while [[ $# -gt 0 ]]; do
|
|
16
|
+
case $1 in
|
|
17
|
+
--json)
|
|
18
|
+
JSON_MODE=true
|
|
19
|
+
shift
|
|
20
|
+
;;
|
|
21
|
+
*)
|
|
22
|
+
STORY_NAME="$1"
|
|
23
|
+
shift
|
|
24
|
+
;;
|
|
25
|
+
esac
|
|
26
|
+
done
|
|
27
|
+
|
|
28
|
+
# Get project root
|
|
29
|
+
PROJECT_ROOT=$(get_project_root)
|
|
30
|
+
cd "$PROJECT_ROOT"
|
|
31
|
+
|
|
32
|
+
# 确定故事名称和路径
|
|
33
|
+
if [ -z "$STORY_NAME" ]; then
|
|
34
|
+
# 查找最新的故事
|
|
35
|
+
STORIES_DIR="stories"
|
|
36
|
+
if [ -d "$STORIES_DIR" ] && [ "$(ls -A $STORIES_DIR 2>/dev/null)" ]; then
|
|
37
|
+
STORY_DIR=$(find "$STORIES_DIR" -maxdepth 1 -type d ! -name "stories" | sort -r | head -n 1)
|
|
38
|
+
if [ -n "$STORY_DIR" ]; then
|
|
39
|
+
STORY_NAME=$(basename "$STORY_DIR")
|
|
40
|
+
fi
|
|
41
|
+
fi
|
|
42
|
+
|
|
43
|
+
# 如果还是没有,生成默认名称
|
|
44
|
+
if [ -z "$STORY_NAME" ]; then
|
|
45
|
+
STORY_NAME="story-$(date +%Y%m%d)"
|
|
46
|
+
fi
|
|
47
|
+
fi
|
|
48
|
+
|
|
49
|
+
# 设置路径
|
|
50
|
+
STORY_DIR="stories/$STORY_NAME"
|
|
51
|
+
SPEC_FILE="$STORY_DIR/specification.md"
|
|
52
|
+
|
|
53
|
+
# 创建目录
|
|
54
|
+
mkdir -p "$STORY_DIR"
|
|
55
|
+
|
|
56
|
+
# 检查文件状态
|
|
57
|
+
SPEC_EXISTS=false
|
|
58
|
+
STATUS="new"
|
|
59
|
+
|
|
60
|
+
if [ -f "$SPEC_FILE" ]; then
|
|
61
|
+
SPEC_EXISTS=true
|
|
62
|
+
STATUS="exists"
|
|
63
|
+
fi
|
|
64
|
+
|
|
65
|
+
# 输出 JSON 格式
|
|
66
|
+
if [ "$JSON_MODE" = true ]; then
|
|
67
|
+
cat <<EOF
|
|
68
|
+
{
|
|
69
|
+
"STORY_NAME": "$STORY_NAME",
|
|
70
|
+
"STORY_DIR": "$STORY_DIR",
|
|
71
|
+
"SPEC_PATH": "$SPEC_FILE",
|
|
72
|
+
"STATUS": "$STATUS",
|
|
73
|
+
"PROJECT_ROOT": "$PROJECT_ROOT"
|
|
74
|
+
}
|
|
75
|
+
EOF
|
|
76
|
+
else
|
|
77
|
+
echo "故事规格初始化"
|
|
78
|
+
echo "================"
|
|
79
|
+
echo "故事名称:$STORY_NAME"
|
|
80
|
+
echo "规格路径:$SPEC_FILE"
|
|
81
|
+
|
|
82
|
+
if [ "$SPEC_EXISTS" = true ]; then
|
|
83
|
+
echo "状态:规格文件已存在,准备更新"
|
|
84
|
+
else
|
|
85
|
+
echo "状态:准备创建新规格"
|
|
86
|
+
fi
|
|
87
|
+
|
|
88
|
+
# 检查宪法
|
|
89
|
+
if [ -f ".specify/memory/constitution.md" ]; then
|
|
90
|
+
echo ""
|
|
91
|
+
echo "✅ 检测到创作宪法,规格将遵循宪法原则"
|
|
92
|
+
fi
|
|
93
|
+
fi
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# 任务分解脚本
|
|
4
|
+
# 用于 /tasks 命令
|
|
5
|
+
|
|
6
|
+
set -e
|
|
7
|
+
|
|
8
|
+
# Source common functions
|
|
9
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
10
|
+
source "$SCRIPT_DIR/common.sh"
|
|
11
|
+
|
|
12
|
+
# Parse arguments
|
|
13
|
+
STORY_NAME=""
|
|
14
|
+
if [ $# -gt 0 ]; then
|
|
15
|
+
STORY_NAME="$1"
|
|
16
|
+
fi
|
|
17
|
+
|
|
18
|
+
# Get project root
|
|
19
|
+
PROJECT_ROOT=$(get_project_root)
|
|
20
|
+
cd "$PROJECT_ROOT"
|
|
21
|
+
|
|
22
|
+
# 确定故事名称
|
|
23
|
+
if [ -z "$STORY_NAME" ]; then
|
|
24
|
+
STORY_NAME=$(get_active_story)
|
|
25
|
+
fi
|
|
26
|
+
|
|
27
|
+
STORY_DIR="stories/$STORY_NAME"
|
|
28
|
+
SPEC_FILE="$STORY_DIR/specification.md"
|
|
29
|
+
PLAN_FILE="$STORY_DIR/creative-plan.md"
|
|
30
|
+
TASKS_FILE="$STORY_DIR/tasks.md"
|
|
31
|
+
|
|
32
|
+
echo "任务分解"
|
|
33
|
+
echo "========"
|
|
34
|
+
echo "故事:$STORY_NAME"
|
|
35
|
+
echo ""
|
|
36
|
+
|
|
37
|
+
# 检查前置文档
|
|
38
|
+
missing=()
|
|
39
|
+
|
|
40
|
+
if [ ! -f ".specify/memory/constitution.md" ]; then
|
|
41
|
+
missing+=("宪法文件")
|
|
42
|
+
fi
|
|
43
|
+
|
|
44
|
+
if [ ! -f "$SPEC_FILE" ]; then
|
|
45
|
+
missing+=("规格文件")
|
|
46
|
+
fi
|
|
47
|
+
|
|
48
|
+
if [ ! -f "$PLAN_FILE" ]; then
|
|
49
|
+
missing+=("计划文件")
|
|
50
|
+
fi
|
|
51
|
+
|
|
52
|
+
if [ ${#missing[@]} -gt 0 ]; then
|
|
53
|
+
echo "⚠️ 缺少以下前置文档:"
|
|
54
|
+
for doc in "${missing[@]}"; do
|
|
55
|
+
echo " - $doc"
|
|
56
|
+
done
|
|
57
|
+
echo ""
|
|
58
|
+
echo "请先完成:"
|
|
59
|
+
if [ ! -f ".specify/memory/constitution.md" ]; then
|
|
60
|
+
echo " 1. /constitution - 创建创作宪法"
|
|
61
|
+
fi
|
|
62
|
+
if [ ! -f "$SPEC_FILE" ]; then
|
|
63
|
+
echo " 2. /specify - 定义故事规格"
|
|
64
|
+
fi
|
|
65
|
+
if [ ! -f "$PLAN_FILE" ]; then
|
|
66
|
+
echo " 3. /plan - 制定创作计划"
|
|
67
|
+
fi
|
|
68
|
+
exit 1
|
|
69
|
+
fi
|
|
70
|
+
|
|
71
|
+
# 检查任务文件
|
|
72
|
+
if [ -f "$TASKS_FILE" ]; then
|
|
73
|
+
echo ""
|
|
74
|
+
echo "📋 任务文件已存在,将更新现有任务"
|
|
75
|
+
|
|
76
|
+
# 显示任务统计
|
|
77
|
+
total_tasks=$(grep -c "^- \[" "$TASKS_FILE" 2>/dev/null || echo "0")
|
|
78
|
+
completed_tasks=$(grep -c "^- \[x\]" "$TASKS_FILE" 2>/dev/null || echo "0")
|
|
79
|
+
echo " 总任务数:$total_tasks"
|
|
80
|
+
echo " 已完成:$completed_tasks"
|
|
81
|
+
else
|
|
82
|
+
echo ""
|
|
83
|
+
echo "📝 将创建新的任务清单"
|
|
84
|
+
fi
|
|
85
|
+
|
|
86
|
+
echo ""
|
|
87
|
+
echo "任务文件路径:$TASKS_FILE"
|
|
88
|
+
echo ""
|
|
89
|
+
echo "准备就绪,可以分解任务"
|
|
90
|
+
echo ""
|
|
91
|
+
echo "任务分解将包括:"
|
|
92
|
+
echo " - 章节写作任务(基于计划)"
|
|
93
|
+
echo " - 角色档案完善"
|
|
94
|
+
echo " - 世界观文档补充"
|
|
95
|
+
echo " - 质量检查节点"
|
|
96
|
+
echo " - 验证和修订任务"
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# 测试中文字数统计功能
|
|
4
|
+
# 用于验证 count_chinese_words 函数的准确性
|
|
5
|
+
|
|
6
|
+
set -e
|
|
7
|
+
|
|
8
|
+
# Source common functions
|
|
9
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
10
|
+
source "$SCRIPT_DIR/common.sh"
|
|
11
|
+
|
|
12
|
+
# 颜色输出
|
|
13
|
+
GREEN='\033[0;32m'
|
|
14
|
+
RED='\033[0;31m'
|
|
15
|
+
YELLOW='\033[1;33m'
|
|
16
|
+
NC='\033[0m' # No Color
|
|
17
|
+
|
|
18
|
+
echo "========================================"
|
|
19
|
+
echo "中文字数统计功能测试"
|
|
20
|
+
echo "========================================"
|
|
21
|
+
echo ""
|
|
22
|
+
|
|
23
|
+
# 创建临时测试文件
|
|
24
|
+
TEST_DIR=$(mktemp -d)
|
|
25
|
+
trap "rm -rf $TEST_DIR" EXIT
|
|
26
|
+
|
|
27
|
+
# 测试用例1: 纯中文文本
|
|
28
|
+
echo "## 测试1: 纯中文文本"
|
|
29
|
+
cat > "$TEST_DIR/test1.md" << 'EOF'
|
|
30
|
+
今天天气很好,我去公园散步。
|
|
31
|
+
看到很多人在锻炼身体。
|
|
32
|
+
EOF
|
|
33
|
+
expected1=16
|
|
34
|
+
actual1=$(count_chinese_words "$TEST_DIR/test1.md")
|
|
35
|
+
echo " 预期字数: $expected1"
|
|
36
|
+
echo " 实际字数: $actual1"
|
|
37
|
+
if [ "$actual1" -eq "$expected1" ]; then
|
|
38
|
+
echo -e " ${GREEN}✅ 测试通过${NC}"
|
|
39
|
+
else
|
|
40
|
+
echo -e " ${RED}❌ 测试失败${NC}"
|
|
41
|
+
fi
|
|
42
|
+
echo ""
|
|
43
|
+
|
|
44
|
+
# 测试用例2: 包含Markdown标记
|
|
45
|
+
echo "## 测试2: 包含Markdown标记的文本"
|
|
46
|
+
cat > "$TEST_DIR/test2.md" << 'EOF'
|
|
47
|
+
# 第一章
|
|
48
|
+
|
|
49
|
+
这是**重要**的内容。
|
|
50
|
+
|
|
51
|
+
- 列表项1
|
|
52
|
+
- 列表项2
|
|
53
|
+
|
|
54
|
+
> 这是引用
|
|
55
|
+
EOF
|
|
56
|
+
# 实际内容: 第一章这是重要的内容列表项1列表项2这是引用
|
|
57
|
+
expected2=21
|
|
58
|
+
actual2=$(count_chinese_words "$TEST_DIR/test2.md")
|
|
59
|
+
echo " 预期字数: $expected2"
|
|
60
|
+
echo " 实际字数: $actual2"
|
|
61
|
+
if [ "$actual2" -eq "$expected2" ]; then
|
|
62
|
+
echo -e " ${GREEN}✅ 测试通过${NC}"
|
|
63
|
+
else
|
|
64
|
+
echo -e " ${YELLOW}⚠️ 字数差异: $((actual2 - expected2))${NC}"
|
|
65
|
+
fi
|
|
66
|
+
echo ""
|
|
67
|
+
|
|
68
|
+
# 测试用例3: 中英混合
|
|
69
|
+
echo "## 测试3: 中英文混合文本"
|
|
70
|
+
cat > "$TEST_DIR/test3.md" << 'EOF'
|
|
71
|
+
这是一个测试test文件。
|
|
72
|
+
包含123数字和English单词。
|
|
73
|
+
EOF
|
|
74
|
+
# 实际内容(移除空格和标点后): 这是一个测试test文件包含123数字和English单词
|
|
75
|
+
expected3=27
|
|
76
|
+
actual3=$(count_chinese_words "$TEST_DIR/test3.md")
|
|
77
|
+
echo " 预期字数: 约$expected3"
|
|
78
|
+
echo " 实际字数: $actual3"
|
|
79
|
+
if [ "$actual3" -ge 20 ] && [ "$actual3" -le 35 ]; then
|
|
80
|
+
echo -e " ${GREEN}✅ 测试通过(在合理范围内)${NC}"
|
|
81
|
+
else
|
|
82
|
+
echo -e " ${YELLOW}⚠️ 字数差异较大${NC}"
|
|
83
|
+
fi
|
|
84
|
+
echo ""
|
|
85
|
+
|
|
86
|
+
# 测试用例4: 包含代码块
|
|
87
|
+
echo "## 测试4: 包含代码块的文本"
|
|
88
|
+
cat > "$TEST_DIR/test4.md" << 'EOF'
|
|
89
|
+
这是正常文本。
|
|
90
|
+
|
|
91
|
+
```javascript
|
|
92
|
+
console.log("这是代码不应该被计数");
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
这是结尾文本。
|
|
96
|
+
EOF
|
|
97
|
+
expected4=12
|
|
98
|
+
actual4=$(count_chinese_words "$TEST_DIR/test4.md")
|
|
99
|
+
echo " 预期字数: $expected4"
|
|
100
|
+
echo " 实际字数: $actual4"
|
|
101
|
+
if [ "$actual4" -eq "$expected4" ]; then
|
|
102
|
+
echo -e " ${GREEN}✅ 测试通过${NC}"
|
|
103
|
+
else
|
|
104
|
+
echo -e " ${YELLOW}⚠️ 字数差异: $((actual4 - expected4))${NC}"
|
|
105
|
+
fi
|
|
106
|
+
echo ""
|
|
107
|
+
|
|
108
|
+
# 对比测试: wc -w vs 新方法
|
|
109
|
+
echo "## 对比测试: wc -w vs count_chinese_words"
|
|
110
|
+
cat > "$TEST_DIR/compare.md" << 'EOF'
|
|
111
|
+
这是一个包含大约五十个字的测试文本。
|
|
112
|
+
我们需要验证字数统计的准确性。
|
|
113
|
+
使用wc命令统计中文字数是不准确的。
|
|
114
|
+
应该使用专门的中文字数统计方法。
|
|
115
|
+
这样才能得到正确的结果。
|
|
116
|
+
EOF
|
|
117
|
+
wc_result=$(wc -w < "$TEST_DIR/compare.md" | tr -d ' ')
|
|
118
|
+
new_result=$(count_chinese_words "$TEST_DIR/compare.md")
|
|
119
|
+
echo " wc -w 结果: $wc_result (不准确)"
|
|
120
|
+
echo " 新方法结果: $new_result (准确)"
|
|
121
|
+
echo -e " ${YELLOW}注意:wc -w 对中文统计极不准确!${NC}"
|
|
122
|
+
echo ""
|
|
123
|
+
|
|
124
|
+
# 性能测试
|
|
125
|
+
echo "## 性能测试: 大文件处理"
|
|
126
|
+
cat > "$TEST_DIR/large.md" << 'EOF'
|
|
127
|
+
# 第一章:开始
|
|
128
|
+
|
|
129
|
+
今天是个好天气,阳光明媚,万里无云。
|
|
130
|
+
小明决定去公园散步,顺便思考一下人生。
|
|
131
|
+
他一边走一边想,不知不觉来到了湖边。
|
|
132
|
+
湖水清澈见底,几只野鸭在水面游弋。
|
|
133
|
+
远处传来孩子们的欢笑声,让人心情愉悦。
|
|
134
|
+
|
|
135
|
+
## 第二节
|
|
136
|
+
|
|
137
|
+
突然,他看到一位老人坐在长椅上。
|
|
138
|
+
老人面带微笑,似乎在等待什么。
|
|
139
|
+
小明走上前去,礼貌地打了个招呼。
|
|
140
|
+
老人抬起头,慈祥的目光看向小明。
|
|
141
|
+
两人开始了一段有趣的对话。
|
|
142
|
+
|
|
143
|
+
**重要的转折点**:
|
|
144
|
+
- 老人讲述了一个神奇的故事
|
|
145
|
+
- 小明意识到生活的意义
|
|
146
|
+
- 他决定改变自己的人生轨迹
|
|
147
|
+
|
|
148
|
+
最后,夕阳西下,小明告别了老人。
|
|
149
|
+
他的内心充满了力量和希望。
|
|
150
|
+
这次偶遇,改变了他的一生。
|
|
151
|
+
EOF
|
|
152
|
+
|
|
153
|
+
start_time=$(date +%s%N)
|
|
154
|
+
large_count=$(count_chinese_words "$TEST_DIR/large.md")
|
|
155
|
+
end_time=$(date +%s%N)
|
|
156
|
+
elapsed=$((($end_time - $start_time) / 1000000)) # 转换为毫秒
|
|
157
|
+
|
|
158
|
+
echo " 文件字数: $large_count"
|
|
159
|
+
echo " 处理时间: ${elapsed}ms"
|
|
160
|
+
if [ "$elapsed" -lt 1000 ]; then
|
|
161
|
+
echo -e " ${GREEN}✅ 性能良好${NC}"
|
|
162
|
+
else
|
|
163
|
+
echo -e " ${YELLOW}⚠️ 处理时间较长${NC}"
|
|
164
|
+
fi
|
|
165
|
+
echo ""
|
|
166
|
+
|
|
167
|
+
# 总结
|
|
168
|
+
echo "========================================"
|
|
169
|
+
echo "测试完成!"
|
|
170
|
+
echo "========================================"
|
|
171
|
+
echo ""
|
|
172
|
+
echo -e "${GREEN}核心功能:${NC}"
|
|
173
|
+
echo " ✓ 准确统计中文字符"
|
|
174
|
+
echo " ✓ 排除Markdown标记"
|
|
175
|
+
echo " ✓ 排除代码块"
|
|
176
|
+
echo " ✓ 处理混合文本"
|
|
177
|
+
echo ""
|
|
178
|
+
echo -e "${YELLOW}使用建议:${NC}"
|
|
179
|
+
echo " • 不要使用 'wc -w' 统计中文字数"
|
|
180
|
+
echo " • 使用 'count_chinese_words' 函数获得准确结果"
|
|
181
|
+
echo " • 在写作完成后验证字数是否达标"
|
|
182
|
+
echo ""
|