@cloud411716/fancy-webnovel 1.0.46 → 3.0.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/client.js +369 -0
- package/cordis.patch.yml +4 -13
- package/docs/douyin-plugin.md +118 -0
- package/docs/material-library/README.md +404 -0
- package/docs/material-library/import.js +437 -0
- package/docs/material-library/prompt.md +370 -0
- package/docs/material-library/queries.surql +94 -0
- package/docs/material-library/sample.jsonl +14 -0
- package/docs/material-library/schema.surql +46 -0
- package/docs/mcp-profile.example.yml +24 -0
- package/docs/story-graph-design.md +602 -0
- package/docs/story-graph-validation.md +81 -0
- package/docs/workspace-mcp.md +284 -0
- package/index.js +26 -38
- package/lib/atomic-write.js +109 -0
- package/lib/chapter-order.js +100 -0
- package/lib/chinese-num.js +111 -0
- package/lib/confirmation.js +80 -0
- package/lib/db-init.js +123 -0
- package/lib/deployed-state.js +141 -0
- package/lib/direction-labels.js +265 -0
- package/lib/error-codes.js +104 -0
- package/lib/infra.js +594 -0
- package/lib/llm-wiki.js +109 -0
- package/lib/material-db.js +149 -0
- package/lib/path-guard.js +150 -0
- package/lib/projects.js +400 -0
- package/lib/scraper-utils.js +305 -0
- package/lib/surreal-server.js +338 -0
- package/lib/topic-decision.js +860 -0
- package/lib/topic-fields.js +251 -0
- package/lib/topic-schema.js +225 -0
- package/lib/workspace.js +501 -0
- package/package.json +62 -5
- package/plugins/fancy-analyze/analyze-definitions.md +519 -0
- package/plugins/fancy-analyze/command-input.js +65 -0
- package/plugins/fancy-analyze/index.js +2024 -0
- package/plugins/fancy-analyze/ingest-coverage.js +107 -0
- package/plugins/fancy-analyze/schema-analyze.md +627 -0
- package/plugins/fancy-analyze/schema-write.md +178 -0
- package/plugins/fancy-analyze/scripts/append-summary-chapter.js +612 -0
- package/plugins/fancy-analyze/scripts/split_source.js +292 -0
- package/plugins/fancy-analyze/summary-progress.js +495 -0
- package/plugins/fancy-analyze/templates.js +1179 -0
- package/plugins/fancy-bootstrap/index.js +313 -0
- package/plugins/fancy-bootstrap/scripts/init.js +177 -0
- package/plugins/fancy-bootstrap/scripts/path-utils.js +21 -0
- package/plugins/fancy-bootstrap/templates.js +71 -0
- package/plugins/fancy-db/index.js +172 -0
- package/plugins/fancy-douyin/deploy.js +134 -0
- package/plugins/fancy-douyin/index.js +551 -0
- package/plugins/fancy-douyin/prompts/01-analysis-prompt.md +84 -0
- package/plugins/fancy-douyin/scripts/crawl-note.cjs +194 -0
- package/plugins/fancy-douyin/scripts/lib.cjs +197 -0
- package/plugins/fancy-douyin/scripts/scan-account.cjs +128 -0
- package/plugins/fancy-douyin/scripts/start-chrome.cjs +203 -0
- package/plugins/fancy-douyin/state.js +197 -0
- package/plugins/fancy-douyin/templates.js +127 -0
- package/plugins/fancy-export/exporter.js +805 -0
- package/plugins/fancy-export/index.js +63 -0
- package/plugins/fancy-import/import-core.js +1118 -0
- package/plugins/fancy-import/import-driver.js +604 -0
- package/plugins/fancy-import/index.js +738 -0
- package/plugins/fancy-import/prompts/01-import-prompt.md +131 -0
- package/plugins/fancy-import/templates.js +58 -0
- package/plugins/fancy-material/exporter.js +153 -0
- package/plugins/fancy-material/genres.js +256 -0
- package/plugins/fancy-material/index.js +835 -0
- package/plugins/fancy-material/inventory.js +143 -0
- package/plugins/fancy-material/kinds.js +313 -0
- package/plugins/fancy-material/queue.js +55 -0
- package/plugins/fancy-material/scripts/query.js +254 -0
- package/plugins/fancy-material/templates.js +258 -0
- package/plugins/fancy-material/tool-deploy.js +138 -0
- package/plugins/fancy-material/validate.js +149 -0
- package/plugins/fancy-project/index.js +133 -0
- package/plugins/fancy-scan/existing-block.js +100 -0
- package/plugins/fancy-scan/index.js +708 -0
- package/plugins/fancy-scan/prompts/01-analysis-prompt.md +302 -0
- package/plugins/fancy-scan/scripts/append-block.js +725 -0
- package/plugins/fancy-scan/scripts/report-validate.js +824 -0
- package/plugins/fancy-scan/scripts/run-scan.js +667 -0
- package/plugins/fancy-scan/scripts/scrapers/fanqie-rank-scraper.js +923 -0
- package/plugins/fancy-scan/scripts/scrapers/jjwxc-rank-scraper.js +469 -0
- package/plugins/fancy-scan/scripts/scrapers/qimao-rank-scraper.js +629 -0
- package/plugins/fancy-scan/templates/blocks.js +155 -0
- package/plugins/fancy-scan/templates/platforms.js +372 -0
- package/plugins/fancy-scan/templates/report-schema.js +90 -0
- package/plugins/fancy-scan/templates.js +694 -0
- package/plugins/fancy-scan/tool-deploy.js +335 -0
- package/plugins/fancy-scan/wait-turn.js +46 -0
- package/plugins/fancy-story-builder/db/README.md +106 -0
- package/plugins/fancy-story-builder/db/client.js +228 -0
- package/plugins/fancy-story-builder/db/commands.js +145 -0
- package/plugins/fancy-story-builder/db/ids.js +39 -0
- package/plugins/fancy-story-builder/db/import.js +798 -0
- package/plugins/fancy-story-builder/db/project.js +299 -0
- package/plugins/fancy-story-builder/db/query.js +361 -0
- package/plugins/fancy-story-builder/db/schema.js +417 -0
- package/plugins/fancy-story-builder/db/stage-sync.js +238 -0
- package/plugins/fancy-story-builder/deploy-manifest.js +239 -0
- package/plugins/fancy-story-builder/deslop-driver.js +821 -0
- package/plugins/fancy-story-builder/flesh-output.js +168 -0
- package/plugins/fancy-story-builder/index.js +6861 -0
- package/plugins/fancy-story-builder/patch-driver.js +390 -0
- package/plugins/fancy-story-builder/prompts/01-skeleton-prompt.md +563 -0
- package/plugins/fancy-story-builder/prompts/02-flesh-prompt.md +602 -0
- package/plugins/fancy-story-builder/prompts/03-rhythm-prompt.md +539 -0
- package/plugins/fancy-story-builder/prompts/04-writing-prompt.md +225 -0
- package/plugins/fancy-story-builder/prompts/05-deslop-prompt.md +96 -0
- package/plugins/fancy-story-builder/purpose-template.md +83 -0
- package/plugins/fancy-story-builder/references/formulas-rhythm.json +302 -0
- package/plugins/fancy-story-builder/references/formulas-skeleton.json +402 -0
- package/plugins/fancy-story-builder/references/genre-profiles.json +3514 -0
- package/plugins/fancy-story-builder/references/glossary.md +594 -0
- package/plugins/fancy-story-builder/references/index.md +581 -0
- package/plugins/fancy-story-builder/references//345/206/231/344/275/234/346/214/207/345/257/274/00-index.md +174 -0
- package/plugins/fancy-story-builder/references//345/206/231/344/275/234/346/214/207/345/257/274/01-scene.md +150 -0
- package/plugins/fancy-story-builder/references//345/206/231/344/275/234/346/214/207/345/257/274/02-chapter-workflow.md +99 -0
- package/plugins/fancy-story-builder/references//345/206/231/344/275/234/346/214/207/345/257/274/03-opening-chapter.md +104 -0
- package/plugins/fancy-story-builder/references//345/206/231/344/275/234/346/214/207/345/257/274/04-dialogue-mastery.md +274 -0
- package/plugins/fancy-story-builder/references//345/206/231/344/275/234/346/214/207/345/257/274/05-genre-formulas.md +432 -0
- package/plugins/fancy-story-builder/references//345/206/231/344/275/234/346/214/207/345/257/274/06-tone-ensemble.md +259 -0
- package/plugins/fancy-story-builder/references//345/206/231/344/275/234/346/214/207/345/257/274/07-ledger-audit.md +222 -0
- package/plugins/fancy-story-builder/references//345/206/231/344/275/234/346/214/207/345/257/274/08-diagnosis-revision.md +205 -0
- package/plugins/fancy-story-builder/references//345/206/231/344/275/234/346/214/207/345/257/274/09-reading-power.md +135 -0
- package/plugins/fancy-story-builder/references//345/206/231/344/275/234/346/214/207/345/257/274/10-deslop.md +129 -0
- package/plugins/fancy-story-builder/references//350/212/202/345/245/217/346/214/207/345/257/274/00-index.md +98 -0
- package/plugins/fancy-story-builder/references//350/212/202/345/245/217/346/214/207/345/257/274/01-upgrade-rhythm.md +300 -0
- package/plugins/fancy-story-builder/references//350/212/202/345/245/217/346/214/207/345/257/274/02-arc-rhythm.md +168 -0
- package/plugins/fancy-story-builder/references//350/212/202/345/245/217/346/214/207/345/257/274/03-highpoint-hooks.md +189 -0
- package/plugins/fancy-story-builder/references//350/212/202/345/245/217/346/214/207/345/257/274/04-satisfaction.md +226 -0
- package/plugins/fancy-story-builder/references//350/212/202/345/245/217/346/214/207/345/257/274/05-foreshadow-density.md +195 -0
- package/plugins/fancy-story-builder/references//350/212/202/345/245/217/346/214/207/345/257/274/06-chapter-outline.md +226 -0
- package/plugins/fancy-story-builder/references//350/212/202/345/245/217/346/214/207/345/257/274/07-audit.md +181 -0
- package/plugins/fancy-story-builder/references//350/241/200/350/202/211/346/214/207/345/257/274/00-index.md +100 -0
- package/plugins/fancy-story-builder/references//350/241/200/350/202/211/346/214/207/345/257/274/01-character.md +243 -0
- package/plugins/fancy-story-builder/references//350/241/200/350/202/211/346/214/207/345/257/274/02-worldbuilding.md +245 -0
- package/plugins/fancy-story-builder/references//350/241/200/350/202/211/346/214/207/345/257/274/03-relations.md +185 -0
- package/plugins/fancy-story-builder/references//350/241/200/350/202/211/346/214/207/345/257/274/04-emotion-methods.md +286 -0
- package/plugins/fancy-story-builder/references//350/241/200/350/202/211/346/214/207/345/257/274/05-audit.md +187 -0
- package/plugins/fancy-story-builder/references//351/252/250/346/236/266/346/214/207/345/257/274/00-index.md +91 -0
- package/plugins/fancy-story-builder/references//351/252/250/346/236/266/346/214/207/345/257/274/01-positioning.md +209 -0
- package/plugins/fancy-story-builder/references//351/252/250/346/236/266/346/214/207/345/257/274/02-packaging.md +135 -0
- package/plugins/fancy-story-builder/references//351/252/250/346/236/266/346/214/207/345/257/274/03-entities.md +305 -0
- package/plugins/fancy-story-builder/references//351/252/250/346/236/266/346/214/207/345/257/274/04-conflict.md +328 -0
- package/plugins/fancy-story-builder/references//351/252/250/346/236/266/346/214/207/345/257/274/05-quota.md +187 -0
- package/plugins/fancy-story-builder/references//351/252/250/346/236/266/346/214/207/345/257/274/06-audit.md +160 -0
- package/plugins/fancy-story-builder/rhythm-output.js +140 -0
- package/plugins/fancy-story-builder/schema-setting.json +1100 -0
- package/plugins/fancy-story-builder/schema-setting.md +232 -0
- package/plugins/fancy-story-builder/scripts/ai-patterns.js +619 -0
- package/plugins/fancy-story-builder/scripts/brief-validate.js +164 -0
- package/plugins/fancy-story-builder/scripts/check-guide-compliance.js +289 -0
- package/plugins/fancy-story-builder/scripts/content-quality.js +416 -0
- package/plugins/fancy-story-builder/scripts/deslop-validate.js +143 -0
- package/plugins/fancy-story-builder/scripts/error-classes.js +112 -0
- package/plugins/fancy-story-builder/scripts/flesh-validate.js +1312 -0
- package/plugins/fancy-story-builder/scripts/formula-engine.js +112 -0
- package/plugins/fancy-story-builder/scripts/graph-utils.js +1484 -0
- package/plugins/fancy-story-builder/scripts/label-coverage.js +171 -0
- package/plugins/fancy-story-builder/scripts/prompt-drift-check.js +441 -0
- package/plugins/fancy-story-builder/scripts/reading-power.js +298 -0
- package/plugins/fancy-story-builder/scripts/reference-log.js +110 -0
- package/plugins/fancy-story-builder/scripts/rhythm-validate.js +1312 -0
- package/plugins/fancy-story-builder/scripts/schema-pages.js +2668 -0
- package/plugins/fancy-story-builder/scripts/semantic-lint.js +381 -0
- package/plugins/fancy-story-builder/scripts/skeleton-quota.js +145 -0
- package/plugins/fancy-story-builder/scripts/skeleton-validate.js +1973 -0
- package/plugins/fancy-story-builder/scripts/stage-batches.js +1405 -0
- package/plugins/fancy-story-builder/scripts/stage-contract.js +429 -0
- package/plugins/fancy-story-builder/scripts/story-artifacts.js +933 -0
- package/plugins/fancy-story-builder/scripts/upstream-query.js +198 -0
- package/plugins/fancy-story-builder/scripts/v2/baseline.js +112 -0
- package/plugins/fancy-story-builder/scripts/v2/cast.js +517 -0
- package/plugins/fancy-story-builder/scripts/v2/context.js +434 -0
- package/plugins/fancy-story-builder/scripts/v2/contracts.js +493 -0
- package/plugins/fancy-story-builder/scripts/v2/core.js +419 -0
- package/plugins/fancy-story-builder/scripts/v2/engine.js +1068 -0
- package/plugins/fancy-story-builder/scripts/v2/export-markdown.js +794 -0
- package/plugins/fancy-story-builder/scripts/v2/genre.js +195 -0
- package/plugins/fancy-story-builder/scripts/v2/knowledge.js +321 -0
- package/plugins/fancy-story-builder/scripts/v2/macro.js +409 -0
- package/plugins/fancy-story-builder/scripts/v2/manifest.js +538 -0
- package/plugins/fancy-story-builder/scripts/v2/migrate.js +137 -0
- package/plugins/fancy-story-builder/scripts/v2/prompts.js +1335 -0
- package/plugins/fancy-story-builder/scripts/v2/rhythm.js +618 -0
- package/plugins/fancy-story-builder/scripts/v2/scale.js +843 -0
- package/plugins/fancy-story-builder/scripts/v2/snapshot.js +121 -0
- package/plugins/fancy-story-builder/scripts/v2/stages.js +273 -0
- package/plugins/fancy-story-builder/scripts/v2/writing.js +216 -0
- package/plugins/fancy-story-builder/scripts/writing-rules.js +167 -0
- package/plugins/fancy-story-builder/scripts/writing-validate.js +682 -0
- package/plugins/fancy-story-builder/skeleton-output.js +199 -0
- package/plugins/fancy-story-builder/stage-driver.js +1049 -0
- package/plugins/fancy-story-builder/storydb/README.md +271 -0
- package/plugins/fancy-story-builder/storydb/cli.js +458 -0
- package/plugins/fancy-story-builder/storydb/client.js +351 -0
- package/plugins/fancy-story-builder/storydb/compile.js +452 -0
- package/plugins/fancy-story-builder/storydb/context.js +288 -0
- package/plugins/fancy-story-builder/storydb/definitions.js +699 -0
- package/plugins/fancy-story-builder/storydb/driver.js +106 -0
- package/plugins/fancy-story-builder/storydb/dsh-tools.js +313 -0
- package/plugins/fancy-story-builder/storydb/export.js +175 -0
- package/plugins/fancy-story-builder/storydb/ids.js +31 -0
- package/plugins/fancy-story-builder/storydb/impact.js +170 -0
- package/plugins/fancy-story-builder/storydb/import.js +559 -0
- package/plugins/fancy-story-builder/storydb/mcp.js +99 -0
- package/plugins/fancy-story-builder/storydb/prompts.js +952 -0
- package/plugins/fancy-story-builder/storydb/stage-command.js +379 -0
- package/plugins/fancy-story-builder/storydb/stage.js +426 -0
- package/plugins/fancy-story-builder/storydb/store.js +891 -0
- package/plugins/fancy-story-builder/storydb/tools.js +592 -0
- package/plugins/fancy-story-builder/storydb/validation.js +183 -0
- package/plugins/fancy-story-builder/templates/v2/10-scale/scale-template.json +144 -0
- package/plugins/fancy-story-builder/templates/v2/20-macro/emotion-template.json +15 -0
- package/plugins/fancy-story-builder/templates/v2/20-macro/endings-template.json +16 -0
- package/plugins/fancy-story-builder/templates/v2/20-macro/lines-template.json +28 -0
- package/plugins/fancy-story-builder/templates/v2/20-macro/roles-template.json +10 -0
- package/plugins/fancy-story-builder/templates/v2/20-macro/story-template.json +19 -0
- package/plugins/fancy-story-builder/templates/v2/20-macro/volumes-template.json +24 -0
- package/plugins/fancy-story-builder/templates/v2/20-macro/world-template.json +24 -0
- package/plugins/fancy-story-builder/templates/v2/30-cast/characters-template.json +49 -0
- package/plugins/fancy-story-builder/templates/v2/30-cast/climaxes-template.json +14 -0
- package/plugins/fancy-story-builder/templates/v2/30-cast/conflicts-template.json +30 -0
- package/plugins/fancy-story-builder/templates/v2/30-cast/factions-template.json +18 -0
- package/plugins/fancy-story-builder/templates/v2/30-cast/foreshadows-template.json +29 -0
- package/plugins/fancy-story-builder/templates/v2/30-cast/information-template.json +29 -0
- package/plugins/fancy-story-builder/templates/v2/30-cast/items-template.json +13 -0
- package/plugins/fancy-story-builder/templates/v2/30-cast/locations-template.json +12 -0
- package/plugins/fancy-story-builder/templates/v2/30-cast/payoffs-template.json +16 -0
- package/plugins/fancy-story-builder/templates/v2/30-cast/relations-template.json +44 -0
- package/plugins/fancy-story-builder/templates/v2/40-rhythm/chapter-map-template.json +81 -0
- package/plugins/fancy-story-builder/templates/v2/40-rhythm/outline-template.json +162 -0
- package/plugins/fancy-story-builder/templates/v2/50-writing/ledger-template.json +46 -0
- package/plugins/fancy-story-builder/templates/v2/60-deslop/report-template.json +10 -0
- package/plugins/fancy-story-builder/templates//350/212/202/345/245/217//346/227/266/345/272/217/346/230/240/345/260/204/346/250/241/346/235/277.json +427 -0
- package/plugins/fancy-story-builder/templates//350/212/202/345/245/217//347/253/240/350/212/202/347/273/206/347/272/262/346/250/241/346/235/277.json +34 -0
- package/plugins/fancy-story-builder/templates//350/212/202/345/245/217//347/253/240/350/212/202/350/247/204/345/210/222/346/250/241/346/235/277.json +24 -0
- package/plugins/fancy-story-builder/templates//350/212/202/345/245/217//350/212/202/345/245/217/345/217/202/346/225/260/346/250/241/346/235/277.json +27 -0
- package/plugins/fancy-story-builder/templates//350/241/200/350/202/211//344/270/226/347/225/214/350/247/202/350/247/204/345/210/231/346/250/241/346/235/277.json +168 -0
- package/plugins/fancy-story-builder/templates//350/241/200/350/202/211//345/205/263/351/224/256/351/201/223/345/205/267/346/250/241/346/235/277.json +184 -0
- package/plugins/fancy-story-builder/templates//350/241/200/350/202/211//345/205/266/344/273/226/345/256/236/344/275/223/346/250/241/346/235/277.json +62 -0
- package/plugins/fancy-story-builder/templates//350/241/200/350/202/211//345/206/262/347/252/201/346/250/241/346/235/277.json +131 -0
- package/plugins/fancy-story-builder/templates//350/241/200/350/202/211//345/211/247/346/203/205/346/250/241/346/235/277.json +85 -0
- package/plugins/fancy-story-builder/templates//350/241/200/350/202/211//345/212/277/345/212/233/346/250/241/346/235/277.json +103 -0
- package/plugins/fancy-story-builder/templates//350/241/200/350/202/211//345/234/260/347/202/271/346/250/241/346/235/277.json +68 -0
- package/plugins/fancy-story-builder/templates//350/241/200/350/202/211//347/273/223/345/261/200/346/250/241/346/235/277.json +142 -0
- package/plugins/fancy-story-builder/templates//350/241/200/350/202/211//350/247/222/350/211/262/346/250/241/346/235/277.json +292 -0
- package/plugins/fancy-story-builder/templates//351/252/250/346/236/266//345/205/263/347/263/273/346/250/241/346/235/277.json +266 -0
- package/plugins/fancy-story-builder/templates//351/252/250/346/236/266//345/256/236/344/275/223/346/250/241/346/235/277.json +336 -0
- package/plugins/fancy-story-builder/templates//351/252/250/346/236/266//345/261/202/347/272/247/346/250/241/346/235/277.json +65 -0
- package/plugins/fancy-story-builder/templates//351/252/250/346/236/266//346/241/206/346/236/266/346/250/241/346/235/277.json +308 -0
- package/plugins/fancy-story-builder/templates.js +1446 -0
- package/plugins/fancy-story-builder/wiki-references.js +540 -0
- package/plugins/fancy-story-builder/writing-driver.js +1388 -0
- package/plugins/fancy-topic/index.js +1057 -0
- package/plugins/fancy-topic/prompts/01-exploration-prompt.md +115 -0
- package/plugins/fancy-topic/scripts/save-suggestion.js +219 -0
- package/plugins/fancy-topic/scripts/select-topic.js +317 -0
- package/plugins/fancy-topic/templates.js +476 -0
- package/plugins/fancy-topic/tool-deploy.js +200 -0
- package/commands/bootstrap/index.js +0 -164
- package/commands/bootstrap/init-project.js +0 -121
- package/commands/scan/index.js +0 -283
- package/commands/scan/platforms/fanqie.js +0 -146
- package/commands/scan/platforms/jinjiang.js +0 -143
- package/commands/scan/platforms/qidian.js +0 -102
- package/commands/scan/platforms/qimao.js +0 -127
- package/commands/scan/scraper.js +0 -195
- package/infra.js +0 -160
|
@@ -0,0 +1,1312 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* 血肉阶段校验脚本 v1.2
|
|
4
|
+
* 源码中零反引号,避免 markdown 渲染问题。
|
|
5
|
+
*
|
|
6
|
+
* v1.2 变更(修复批次 P0-3 / P2-10):
|
|
7
|
+
* - P0-3:completenessCheck 的 directChecks 用"文件类型"作 fleshData 的 key
|
|
8
|
+
* (原版用 'characters' 等数组名作 key,fleshData 里实际是 '角色' 等文件类型,
|
|
9
|
+
* 导致 5 类直接映射实体的 FLESH_INCOMPLETE 全部误报刷屏)
|
|
10
|
+
* - P2-10:itemRefCheck 先校验 id 存在于骨架,再加入 fleshItemIds
|
|
11
|
+
* (原版先加入后校验,非法 id 会触发多余的 FLESH_DETAILS_ORPHAN)
|
|
12
|
+
*
|
|
13
|
+
* 保留 v1.1 的 P2-3 修复:
|
|
14
|
+
* - FLESH_GROUP_CATEGORY_MISMATCH / FLESH_FREETEXT_CHAPTER_REF / completenessCheck 扩展
|
|
15
|
+
*
|
|
16
|
+
* 用法:
|
|
17
|
+
* 单文件:node flesh-validate.js --input=<json> --template=<模板> --file=<类型> --upstream=<骨架目录>
|
|
18
|
+
* 全量: node flesh-validate.js --stage-dir=<血肉目录> --template-dir=<模板/血肉> --upstream=<骨架目录> --all
|
|
19
|
+
* 退出码:0=通过 1=内容错误 2=脚本异常
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import fs from 'node:fs';
|
|
23
|
+
import path from 'node:path';
|
|
24
|
+
import { fileURLToPath } from 'node:url';
|
|
25
|
+
import { parseGlossaryChecked, mdEscape, renderObject, renderArray, renderFleshByFileType, readStageGate, safeCheck, RELATION_KIND_META, suggestClosestName } from './graph-utils.js';
|
|
26
|
+
import { runContentQualityChecks, collectEnumLeaves } from './content-quality.js';
|
|
27
|
+
|
|
28
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
29
|
+
|
|
30
|
+
// ============================================================
|
|
31
|
+
// 参数解析
|
|
32
|
+
// ============================================================
|
|
33
|
+
function parseArgs() {
|
|
34
|
+
const args = process.argv.slice(2);
|
|
35
|
+
const result = { upstream: [] };
|
|
36
|
+
for (const arg of args) {
|
|
37
|
+
const m = arg.match(/^--([\w-]+)=(.+)$/);
|
|
38
|
+
if (m) {
|
|
39
|
+
if (m[1] === 'upstream') {
|
|
40
|
+
result.upstream.push(...m[2].split(',').map(s => s.trim()).filter(Boolean));
|
|
41
|
+
} else {
|
|
42
|
+
result[m[1]] = m[2];
|
|
43
|
+
}
|
|
44
|
+
} else if (arg === '--all') {
|
|
45
|
+
result.all = true;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// ============================================================
|
|
52
|
+
// IO
|
|
53
|
+
// ============================================================
|
|
54
|
+
function readJson(p) {
|
|
55
|
+
if (!fs.existsSync(p)) return { error: '文件不存在: ' + p };
|
|
56
|
+
try {
|
|
57
|
+
return { data: JSON.parse(fs.readFileSync(p, 'utf-8')) };
|
|
58
|
+
} catch (err) {
|
|
59
|
+
return { error: 'JSON 解析失败: ' + err.message };
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function readText(p) {
|
|
64
|
+
if (!fs.existsSync(p)) return { error: '文件不存在: ' + p };
|
|
65
|
+
try {
|
|
66
|
+
return { data: fs.readFileSync(p, 'utf-8') };
|
|
67
|
+
} catch (err) {
|
|
68
|
+
return { error: '读取失败: ' + err.message };
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// ============================================================
|
|
73
|
+
// glossary 加载
|
|
74
|
+
// ============================================================
|
|
75
|
+
function loadGlossary() {
|
|
76
|
+
const r = readText(path.join(__dirname, 'glossary.md'));
|
|
77
|
+
if (r.error) return { error: 'glossary.md 读取失败: ' + r.error };
|
|
78
|
+
return parseGlossaryChecked(r.data);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function loadSkeleton(upstreamDirs) {
|
|
82
|
+
const result = { entity: null, framework: null, hierarchy: null, relations: null };
|
|
83
|
+
for (const dir of upstreamDirs) {
|
|
84
|
+
const entRes = readJson(path.join(dir, '实体.json'));
|
|
85
|
+
if (entRes.data) result.entity = entRes.data;
|
|
86
|
+
const fwRes = readJson(path.join(dir, '框架.json'));
|
|
87
|
+
if (fwRes.data) result.framework = fwRes.data;
|
|
88
|
+
const hiRes = readJson(path.join(dir, '层级.json'));
|
|
89
|
+
if (hiRes.data) result.hierarchy = hiRes.data;
|
|
90
|
+
const relRes = readJson(path.join(dir, '关系.json'));
|
|
91
|
+
if (relRes.data) result.relations = relRes.data;
|
|
92
|
+
}
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// ============================================================
|
|
97
|
+
// 自环关系检查
|
|
98
|
+
// ============================================================
|
|
99
|
+
// 骨架阶段的 关系.json 有 NO_SELF_RELATION 拦截自环,血肉阶段此前没有对等检查,
|
|
100
|
+
// 于是"角色把自己列成自己的关系对象"可以一路写进角色档案。
|
|
101
|
+
function fleshSelfRelationCheck(data, fileType, errors) {
|
|
102
|
+
const selfCheck = (ownerName, targetName, path, label) => {
|
|
103
|
+
if (!targetName || !ownerName) return;
|
|
104
|
+
if (targetName === ownerName) {
|
|
105
|
+
errors.push({
|
|
106
|
+
code: 'FLESH_SELF_RELATION',
|
|
107
|
+
path: path,
|
|
108
|
+
message: label + ' "' + ownerName + '" 把自身列为关系对象',
|
|
109
|
+
hint: '自环关系无意义;角色的自我矛盾请写进 description / core_flaw'
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
if (fileType === '角色') {
|
|
115
|
+
for (const [i, c] of (data.characters || []).entries()) {
|
|
116
|
+
if (!c) continue;
|
|
117
|
+
const aliases = new Set([c.id, c.name].filter(Boolean));
|
|
118
|
+
for (const [j, r] of (c.relationships || []).entries()) {
|
|
119
|
+
if (!r) continue;
|
|
120
|
+
if (aliases.has(r.target_name)) {
|
|
121
|
+
selfCheck(c.name || c.id, r.target_name, 'characters[' + i + '].relationships[' + j + '].target_name', '角色');
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
} else if (fileType === '势力') {
|
|
126
|
+
for (const [i, f] of (data.factions || []).entries()) {
|
|
127
|
+
if (!f) continue;
|
|
128
|
+
const aliases = new Set([f.id, f.name].filter(Boolean));
|
|
129
|
+
for (const [j, r] of (f.relations || []).entries()) {
|
|
130
|
+
if (!r) continue;
|
|
131
|
+
if (aliases.has(r.target_name)) {
|
|
132
|
+
selfCheck(f.name || f.id, r.target_name, 'factions[' + i + '].relations[' + j + '].target_name', '势力');
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// ============================================================
|
|
140
|
+
// 个性化特征与关系阶段检查
|
|
141
|
+
// ============================================================
|
|
142
|
+
// `traits` 是角色的"独有特征",不是性格形容词堆砌。
|
|
143
|
+
// 模板只能要求字段存在,数量和重复要靠这里兜住。
|
|
144
|
+
function traitsAndChangesCheck(data, fileType, errors, warnings) {
|
|
145
|
+
const checkTraits = (item, path, label, min, max) => {
|
|
146
|
+
if (!item || item.traits === undefined) {
|
|
147
|
+
if (label === '角色') {
|
|
148
|
+
errors.push({
|
|
149
|
+
code: 'FLESH_TRAITS_MISSING',
|
|
150
|
+
path: path + '.traits',
|
|
151
|
+
message: '角色缺少 traits(独有特征/习惯)',
|
|
152
|
+
hint: '写 3-5 条能直接写进场景的具体特征,例如"紧张时反复摸腕环"'
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
if (!Array.isArray(item.traits)) return; // TYPE 已报
|
|
158
|
+
const values = item.traits.map((x) => (typeof x === 'string' ? x.trim() : '')).filter(Boolean);
|
|
159
|
+
if (values.length < min || values.length > max) {
|
|
160
|
+
errors.push({
|
|
161
|
+
code: 'FLESH_TRAITS_COUNT',
|
|
162
|
+
path: path + '.traits',
|
|
163
|
+
message: label + '的 traits 应为 ' + min + '-' + max + ' 条,实际 ' + values.length + ' 条',
|
|
164
|
+
hint: '特征要少而准:每条都能在场景里演出来,不要用"善良""勇敢"这类评价词凑数'
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
if (new Set(values).size !== values.length) {
|
|
168
|
+
errors.push({
|
|
169
|
+
code: 'FLESH_TRAITS_DUPLICATE',
|
|
170
|
+
path: path + '.traits',
|
|
171
|
+
message: label + '的 traits 有重复条目',
|
|
172
|
+
hint: '删掉重复项,换成不同的习惯/感官锚点'
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
const checkChanges = (rel, path, label) => {
|
|
178
|
+
if (!rel || !Array.isArray(rel.changes) || rel.changes.length === 0) return;
|
|
179
|
+
for (const [k, ch] of rel.changes.entries()) {
|
|
180
|
+
if (!ch || typeof ch !== 'object') continue;
|
|
181
|
+
for (const key of ['stage', 'from', 'to', 'trigger', 'description']) {
|
|
182
|
+
const v = ch[key];
|
|
183
|
+
if (typeof v !== 'string' || !v.trim()) {
|
|
184
|
+
errors.push({
|
|
185
|
+
code: 'REL_CHANGE_INCOMPLETE',
|
|
186
|
+
path: path + '.changes[' + k + '].' + key,
|
|
187
|
+
message: label + '的关系变化缺少 ' + key + ',无法判断这一阶段到底发生了什么',
|
|
188
|
+
hint: '每条变化至少写清:阶段名、变化前状态、变化后状态、触发事件、变化描述'
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
for (const key of ['stage', 'from', 'to', 'trigger', 'description', 'timing']) {
|
|
193
|
+
if (typeof ch[key] === 'string' && /第\s*(?:\d+|[一二三四五六七八九十百千万]+)\s*章/.test(ch[key])) {
|
|
194
|
+
errors.push({
|
|
195
|
+
code: 'FLESH_FREETEXT_CHAPTER_REF',
|
|
196
|
+
path: path + '.changes[' + k + '].' + key,
|
|
197
|
+
message: '关系变化里出现"第 N 章"引用;章节号属于节奏阶段',
|
|
198
|
+
hint: '这里只写"前期/转折/后期/某卷"或事件本身,章节落点由节奏阶段 relationship_timeline 决定'
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
if (fileType === '角色') {
|
|
206
|
+
for (const [i, c] of (data.characters || []).entries()) {
|
|
207
|
+
if (!c) continue;
|
|
208
|
+
checkTraits(c, 'characters[' + i + ']', '角色', 3, 5);
|
|
209
|
+
for (const [j, rel] of (c.relationships || []).entries()) {
|
|
210
|
+
if (!rel) continue;
|
|
211
|
+
if (rel.relationship_type === '其他' && !String(rel.relation_label || '').trim()) {
|
|
212
|
+
errors.push({
|
|
213
|
+
code: 'REL_LABEL_REQUIRED',
|
|
214
|
+
path: 'characters[' + i + '].relationships[' + j + '].relation_label',
|
|
215
|
+
message: 'relationship_type="其他" 时必须填 relation_label,写清具体关系(如 附身/寄生/契约/共生)',
|
|
216
|
+
hint: 'relation_label 是词表外关系的唯一语义来源'
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
checkChanges(rel, 'characters[' + i + '].relationships[' + j + ']', c.name || c.id);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
if (fileType === '其他实体') {
|
|
224
|
+
for (const [i, o] of (data.other_entities || []).entries()) {
|
|
225
|
+
if (!o) continue;
|
|
226
|
+
checkTraits(o, 'other_entities[' + i + ']', '其他实体', 2, 6);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// ============================================================
|
|
232
|
+
// 跨阶段:血肉关系 ↔ 骨架关系一致性
|
|
233
|
+
// ============================================================
|
|
234
|
+
// 骨架 `关系.json` 的 `character_relations` 是「from 对 to 的关系类型」,
|
|
235
|
+
// 血肉 `角色.json` 的 `relationships[]` 是「本角色对 target_name 的关系」,
|
|
236
|
+
// 方向语义与骨架一致。此前两个阶段之间没有任何关系语义的比对,
|
|
237
|
+
// 于是「骨架写 A 服从 B,血肉写 A 与 B 是上下级关系」这类不一致完全逃逸:
|
|
238
|
+
// 实体和边的拓扑都对得上,语义却对不上。
|
|
239
|
+
//
|
|
240
|
+
// 判定规则(有序对 S→T 表示「S 对 T 的关系」):
|
|
241
|
+
// 1. 骨架有 S→T=K,血肉也声明 S→T=L 且 L≠K → REL_TYPE_MISMATCH
|
|
242
|
+
// 2. 骨架只有反向 T→S=K,血肉声明 S→T=L:
|
|
243
|
+
// K 为对称关系且 L=K → 等价表述,放行
|
|
244
|
+
// K 为对称关系且 L≠K → REL_TYPE_MISMATCH
|
|
245
|
+
// K 为有向关系 → REL_DIRECTION_FLIP(有向关系被写反了)
|
|
246
|
+
// 3. 骨架正反两个方向都没有,血肉却声明了 → REL_NOT_IN_SKELETON
|
|
247
|
+
// 4. 骨架有 S→T=K,血肉正反两个方向都没声明 → REL_UNDECLARED(warning)
|
|
248
|
+
//
|
|
249
|
+
// 规则 4 只报 warning:血肉阶段允许先铺开主干关系,再补齐其余关系。
|
|
250
|
+
// 其余三条都是 error —— 它们是语义冲突,不是覆盖度问题。
|
|
251
|
+
function skeletonRelationConsistencyCheck(fleshData, sk, errors, warnings, opts) {
|
|
252
|
+
if (!sk || !sk.entity || !sk.relations) return;
|
|
253
|
+
const checkCoverage = !opts || opts.checkCoverage !== false;
|
|
254
|
+
|
|
255
|
+
// 骨架角色:id → id,name → id
|
|
256
|
+
const idByKey = new Map();
|
|
257
|
+
for (const c of (sk.entity.characters || [])) {
|
|
258
|
+
if (!c) continue;
|
|
259
|
+
if (c.id) idByKey.set(c.id, c.id);
|
|
260
|
+
if (c.name) idByKey.set(c.name, c.id);
|
|
261
|
+
}
|
|
262
|
+
const resolve = (v) => (v && idByKey.has(v) ? idByKey.get(v) : null);
|
|
263
|
+
|
|
264
|
+
// 骨架关系:'A→B' → { kind, label }
|
|
265
|
+
const skRel = new Map();
|
|
266
|
+
for (const r of (sk.relations.character_relations || [])) {
|
|
267
|
+
if (!r || !r.from || !r.to) continue;
|
|
268
|
+
skRel.set(r.from + '→' + r.to, {
|
|
269
|
+
kind: r.relation_kind,
|
|
270
|
+
label: typeof r.relation_label === 'string' ? r.relation_label.trim() : ''
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// 血肉关系:有序对 → { kind, path },并记录血肉已覆盖的无序对
|
|
275
|
+
const fleshRel = new Map();
|
|
276
|
+
const coveredPairs = new Set();
|
|
277
|
+
for (const [i, c] of (fleshData.characters || []).entries()) {
|
|
278
|
+
if (!c) continue;
|
|
279
|
+
const srcId = resolve(c.id) || resolve(c.name);
|
|
280
|
+
for (const [j, r] of (c.relationships || []).entries()) {
|
|
281
|
+
if (!r) continue;
|
|
282
|
+
const p = 'characters[' + i + '].relationships[' + j + ']';
|
|
283
|
+
const tgtId = resolve(r.target_name);
|
|
284
|
+
if (!srcId || !tgtId) continue; // 解析不出来由 xrefCheck / entityRefCheck 负责
|
|
285
|
+
const key = srcId + '→' + tgtId;
|
|
286
|
+
const pairKey = [srcId, tgtId].sort().join('↔');
|
|
287
|
+
coveredPairs.add(pairKey);
|
|
288
|
+
fleshRel.set(key, { kind: r.relationship_type, path: p, target: r.target_name, src: c.name || c.id });
|
|
289
|
+
|
|
290
|
+
const fwd = skRel.get(key);
|
|
291
|
+
if (fwd !== undefined) {
|
|
292
|
+
if (r.relationship_type !== fwd.kind) {
|
|
293
|
+
errors.push({
|
|
294
|
+
code: 'REL_TYPE_MISMATCH',
|
|
295
|
+
path: p + '.relationship_type',
|
|
296
|
+
message: '骨架 ' + srcId + '→' + tgtId + ' 的关系类型是 "' + fwd.kind + '",血肉写的是 "' + r.relationship_type + '"',
|
|
297
|
+
hint: '血肉阶段的关系类型必须与骨架一致;若语义确实变了,请在 description 里写清"关系在剧情中如何演变",而不是换掉类型'
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
const fleshLabel = typeof r.relation_label === 'string' ? r.relation_label.trim() : '';
|
|
301
|
+
if (fwd.label && fleshLabel && fwd.label !== fleshLabel) {
|
|
302
|
+
errors.push({
|
|
303
|
+
code: 'REL_LABEL_MISMATCH',
|
|
304
|
+
path: p + '.relation_label',
|
|
305
|
+
message: '骨架 ' + srcId + '→' + tgtId + ' 的关系标签是 "' + fwd.label + '",血肉写的是 "' + fleshLabel + '"',
|
|
306
|
+
hint: '关系标签必须与骨架完全一致'
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
if (fwd.kind === '其他' && !fleshLabel) {
|
|
310
|
+
errors.push({
|
|
311
|
+
code: 'REL_LABEL_REQUIRED',
|
|
312
|
+
path: p + '.relation_label',
|
|
313
|
+
message: '骨架把 ' + srcId + '→' + tgtId + ' 标为"其他",血肉必须写 relation_label',
|
|
314
|
+
hint: '照抄骨架的 relation_label,或补齐具体关系名'
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
continue;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
const revRow = skRel.get(tgtId + '→' + srcId);
|
|
321
|
+
if (revRow === undefined) {
|
|
322
|
+
errors.push({
|
|
323
|
+
code: 'REL_NOT_IN_SKELETON',
|
|
324
|
+
path: p,
|
|
325
|
+
message: '血肉声明了 ' + (c.name || c.id) + ' → ' + r.target_name + ' 的关系,但骨架没有这一对角色的任何关系',
|
|
326
|
+
hint: '骨架 `关系.json` 的 `character_relations` 里补上这一对,或删掉血肉里的这条关系'
|
|
327
|
+
});
|
|
328
|
+
continue;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
const rev = revRow.kind;
|
|
332
|
+
const meta = RELATION_KIND_META[rev];
|
|
333
|
+
if (meta && meta.direction === 'symmetric') {
|
|
334
|
+
if (r.relationship_type !== rev) {
|
|
335
|
+
errors.push({
|
|
336
|
+
code: 'REL_TYPE_MISMATCH',
|
|
337
|
+
path: p + '.relationship_type',
|
|
338
|
+
message: '骨架 ' + tgtId + '→' + srcId + ' 的关系类型是 "' + rev + '",血肉这边写的是 "' + r.relationship_type + '"',
|
|
339
|
+
hint: '对称关系写成反方向仍须是同一个类型;请与骨架保持一致'
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
} else {
|
|
343
|
+
errors.push({
|
|
344
|
+
code: 'REL_DIRECTION_FLIP',
|
|
345
|
+
path: p,
|
|
346
|
+
message: '骨架声明的是 ' + tgtId + '→' + srcId + '「' + rev + '」(有向关系),血肉却写成 ' + (c.name || c.id) + ' → ' + r.target_name + '「' + r.relationship_type + '」',
|
|
347
|
+
hint: '有向关系的方向不能反:该声明写在 ' + tgtId + ' 对应的角色文件里,关系类型与骨架保持一致'
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
// 骨架里声明了、但血肉正反两个方向都没写的关系
|
|
354
|
+
if (!checkCoverage) return;
|
|
355
|
+
for (const [key, kind] of skRel) {
|
|
356
|
+
const parts = key.split('→');
|
|
357
|
+
const pairKey = [parts[0], parts[1]].sort().join('↔');
|
|
358
|
+
if (coveredPairs.has(pairKey)) continue;
|
|
359
|
+
warnings.push({
|
|
360
|
+
code: 'REL_UNDECLARED',
|
|
361
|
+
path: '骨架关系 ' + key,
|
|
362
|
+
message: '骨架 ' + key + '("' + kind.kind + '")在血肉阶段没有对应的 relationships 条目',
|
|
363
|
+
hint: '该对角色的关系尚未血肉化;若刻意留白可忽略'
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
// ============================================================
|
|
369
|
+
// 模板校验
|
|
370
|
+
// ============================================================
|
|
371
|
+
function validateNode(data, spec, p, enums, errors) {
|
|
372
|
+
if (typeof spec === 'string') spec = { type: spec };
|
|
373
|
+
if (spec.required && (data === undefined || data === null || data === '')) {
|
|
374
|
+
errors.push({ code: 'REQUIRED', path: p, message: '必填字段不得为空', hint: null });
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
if (data === undefined || data === null) return;
|
|
378
|
+
|
|
379
|
+
const actualType = Array.isArray(data) ? 'array' : typeof data;
|
|
380
|
+
if (spec.type === 'array' && !Array.isArray(data)) {
|
|
381
|
+
errors.push({ code: 'TYPE', path: p, message: '应为 array,实际为 ' + actualType, hint: null });
|
|
382
|
+
} else if (spec.type === 'object' && (typeof data !== 'object' || Array.isArray(data))) {
|
|
383
|
+
errors.push({ code: 'TYPE', path: p, message: '应为 object,实际为 ' + actualType, hint: null });
|
|
384
|
+
} else if (spec.type === 'string' && typeof data !== 'string') {
|
|
385
|
+
errors.push({ code: 'TYPE', path: p, message: '应为 string,实际为 ' + actualType, hint: null });
|
|
386
|
+
} else if (spec.type === 'number' && typeof data !== 'number') {
|
|
387
|
+
errors.push({ code: 'TYPE', path: p, message: '应为 number,实际为 ' + actualType, hint: null });
|
|
388
|
+
} else if (spec.type === 'boolean' && typeof data !== 'boolean') {
|
|
389
|
+
errors.push({ code: 'TYPE', path: p, message: '应为 boolean,实际为 ' + actualType, hint: null });
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
if (spec.pattern && typeof data === 'string') {
|
|
393
|
+
try {
|
|
394
|
+
if (!new RegExp(spec.pattern).test(data)) {
|
|
395
|
+
errors.push({ code: 'PATTERN', path: p, message: '不匹配正则 ' + spec.pattern, hint: null });
|
|
396
|
+
}
|
|
397
|
+
} catch (e) {}
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
if (spec.enumRef) {
|
|
401
|
+
const allowed = enums[spec.enumRef];
|
|
402
|
+
if (!allowed) {
|
|
403
|
+
errors.push({ code: 'ENUM_MISSING', path: p, message: '枚举引用 ' + spec.enumRef + ' 未在 glossary 中定义', hint: null });
|
|
404
|
+
} else if (!allowed.includes(data)) {
|
|
405
|
+
errors.push({ code: 'ENUM', path: p, message: '值 "' + data + '" 不在允许的枚举范围内', hint: allowed.join(' / ') });
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
if (spec.properties && typeof data === 'object' && !Array.isArray(data)) {
|
|
410
|
+
const allowed = new Set(Object.keys(spec.properties));
|
|
411
|
+
for (const key of Object.keys(data)) {
|
|
412
|
+
if (!allowed.has(key)) {
|
|
413
|
+
errors.push({
|
|
414
|
+
code: 'EXTRA_FIELD',
|
|
415
|
+
path: p ? (p + '.' + key) : key,
|
|
416
|
+
message: '字段 "' + key + '" 不在模板中',
|
|
417
|
+
hint: '数据文件不得出现模板 properties 之外的字段'
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
for (const [k, child] of Object.entries(spec.properties)) {
|
|
422
|
+
validateNode(data[k], child, p ? (p + '.' + k) : k, enums, errors);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
if (spec.type === 'array' && spec.items && Array.isArray(data)) {
|
|
427
|
+
data.forEach((item, i) => validateNode(item, spec.items, p + '[' + i + ']', enums, errors));
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
// ============================================================
|
|
432
|
+
// 章节号越界检查
|
|
433
|
+
// ============================================================
|
|
434
|
+
function checkChapterForbidden(data, scalarSet, containerSet, errors) {
|
|
435
|
+
// 这些路径下的同名字段是文本描述,不是章节号
|
|
436
|
+
// 路径中的字段 segment 可被 `.` 或 `[` 包裹
|
|
437
|
+
const TEXT_DESCRIPTOR_PATH_REGEXES = [
|
|
438
|
+
/(?:^|\.|\[)arc_change_descriptions(?:\.|\[|$)/
|
|
439
|
+
];
|
|
440
|
+
const isUnderTextDescriptor = (path) => {
|
|
441
|
+
if (!path) return false;
|
|
442
|
+
return TEXT_DESCRIPTOR_PATH_REGEXES.some(re => re.test(path));
|
|
443
|
+
};
|
|
444
|
+
const walk = (node, p) => {
|
|
445
|
+
if (!node || typeof node !== 'object') return;
|
|
446
|
+
if (Array.isArray(node)) {
|
|
447
|
+
node.forEach((v, i) => walk(v, p + '[' + i + ']'));
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
for (const [k, v] of Object.entries(node)) {
|
|
451
|
+
const curPath = p ? (p + '.' + k) : k;
|
|
452
|
+
// 文本描述字段路径前缀豁免
|
|
453
|
+
if (!isUnderTextDescriptor(curPath)) {
|
|
454
|
+
if (containerSet.has(k)) {
|
|
455
|
+
errors.push({
|
|
456
|
+
code: 'FLESH_CHAPTER_FORBIDDEN',
|
|
457
|
+
path: curPath,
|
|
458
|
+
message: '血肉阶段不允许出现章节容器 "' + k + '"',
|
|
459
|
+
hint: '章节号属于节奏阶段'
|
|
460
|
+
});
|
|
461
|
+
continue;
|
|
462
|
+
}
|
|
463
|
+
if (scalarSet.has(k) && typeof v === 'number') {
|
|
464
|
+
errors.push({
|
|
465
|
+
code: 'FLESH_CHAPTER_FORBIDDEN',
|
|
466
|
+
path: curPath,
|
|
467
|
+
message: '血肉阶段不允许出现章节号字段 "' + k + '"(值 ' + v + ')',
|
|
468
|
+
hint: '章节号属于节奏阶段'
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
walk(v, curPath);
|
|
473
|
+
}
|
|
474
|
+
};
|
|
475
|
+
walk(data, '');
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
// ============================================================
|
|
479
|
+
// 自由文本字段的章节号引用检查
|
|
480
|
+
// ============================================================
|
|
481
|
+
const CHAPTER_REF_RE = /第\s*(?:\d+|[一二三四五六七八九十百千万]+)\s*章/;
|
|
482
|
+
|
|
483
|
+
const FREE_TEXT_FIELDS = new Set([
|
|
484
|
+
'description', 'content', 'notes', 'note',
|
|
485
|
+
'function', 'function_detail', 'limit', 'origin', 'appearance',
|
|
486
|
+
'symbolic_meaning', 'usage_scenario', 'relation',
|
|
487
|
+
'method', 'residual_impact', 'resolution_method',
|
|
488
|
+
'goal', 'core_goal', 'influence_scope',
|
|
489
|
+
'surface_contradiction', 'deep_contradiction', 'ultimate_contradiction',
|
|
490
|
+
'core_flaw', 'golden_finger', 'known_secrets', 'unknown_secrets', 'false_beliefs',
|
|
491
|
+
'short_term', 'medium_term', 'long_term',
|
|
492
|
+
'relationship_type', 'stage', 'main_relation', 'expected_outcome',
|
|
493
|
+
'layout', 'narrative_role_description',
|
|
494
|
+
'conflict_summary', 'conflict_solution',
|
|
495
|
+
'special_remaining', 'emotion_trajectory', 'core_emotion', 'final_point',
|
|
496
|
+
'climax_design', 'turning_design', 'cost_design', 'resolution_design',
|
|
497
|
+
'suppression_method', 'resource_seizure_path', 'main_line_connection',
|
|
498
|
+
'internal_structure', 'position_description', 'relation_description',
|
|
499
|
+
'core_drive',
|
|
500
|
+
'applicable_scope', 'exception', 'impact_on_protagonist',
|
|
501
|
+
'violation_consequence', 'impact_on_plot',
|
|
502
|
+
'contradiction', 'solution',
|
|
503
|
+
'catchphrase', 'speech_rhythm', 'info_preference', 'stance',
|
|
504
|
+
'identity_wording', 'personality_tone', 'relationship_stage_tone',
|
|
505
|
+
'personality',
|
|
506
|
+
// 以下字段虽然通常作 ID/枚举,但也可能写"第 N 章"提及,加入警告
|
|
507
|
+
'name', 'info_name', 'who_knows', 'who_does_not_know',
|
|
508
|
+
'foreshadow_id', 'related_characters', 'related_conflicts',
|
|
509
|
+
'target_name', 'from', 'to'
|
|
510
|
+
]);
|
|
511
|
+
|
|
512
|
+
function freeTextChapterCheck(data, warnings) {
|
|
513
|
+
const walk = (node, p, fieldName) => {
|
|
514
|
+
if (typeof node === 'string') {
|
|
515
|
+
if (fieldName && FREE_TEXT_FIELDS.has(fieldName) && CHAPTER_REF_RE.test(node)) {
|
|
516
|
+
warnings.push({
|
|
517
|
+
code: 'FLESH_FREETEXT_CHAPTER_REF',
|
|
518
|
+
path: p,
|
|
519
|
+
message: '自由文本中出现"第 N 章"引用,可能语义越界(章节号属于节奏阶段)',
|
|
520
|
+
hint: '如需表达时间位置,请改为"某阶段/某卷",或在节奏阶段处理'
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
return;
|
|
524
|
+
}
|
|
525
|
+
if (Array.isArray(node)) {
|
|
526
|
+
node.forEach((v, i) => walk(v, p + '[' + i + ']', fieldName));
|
|
527
|
+
return;
|
|
528
|
+
}
|
|
529
|
+
if (node && typeof node === 'object') {
|
|
530
|
+
for (const [k, v] of Object.entries(node)) {
|
|
531
|
+
walk(v, p ? (p + '.' + k) : k, k);
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
};
|
|
535
|
+
walk(data, '', null);
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
// ============================================================
|
|
539
|
+
// 字符集 / 占位符
|
|
540
|
+
// ============================================================
|
|
541
|
+
const KOREAN_RE = /[\uAC00-\uD7A3\u1100-\u11FF\u3130-\u318F]/;
|
|
542
|
+
const KANA_RE = /[\u3040-\u309F\u30A0-\u30FF]/;
|
|
543
|
+
const PLACEHOLDER_RE = /\[[XYZW]\]|待确认|待定|N\/A/;
|
|
544
|
+
|
|
545
|
+
function charsetAndForbiddenCheck(data, errors) {
|
|
546
|
+
const walk = (node, p) => {
|
|
547
|
+
if (typeof node === 'string') {
|
|
548
|
+
if (KOREAN_RE.test(node)) {
|
|
549
|
+
errors.push({ code: 'CHARSET_KO', path: p, message: '含韩文: "' + node.slice(0, 30) + '"', hint: null });
|
|
550
|
+
}
|
|
551
|
+
if (KANA_RE.test(node)) {
|
|
552
|
+
errors.push({ code: 'CHARSET_JP', path: p, message: '含日文假名: "' + node.slice(0, 30) + '"', hint: null });
|
|
553
|
+
}
|
|
554
|
+
if (PLACEHOLDER_RE.test(node)) {
|
|
555
|
+
errors.push({ code: 'PLACEHOLDER', path: p, message: '含占位符: "' + node.slice(0, 30) + '"', hint: null });
|
|
556
|
+
}
|
|
557
|
+
return;
|
|
558
|
+
}
|
|
559
|
+
if (Array.isArray(node)) {
|
|
560
|
+
node.forEach((v, i) => walk(v, p + '[' + i + ']'));
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
if (node && typeof node === 'object') {
|
|
564
|
+
for (const [k, v] of Object.entries(node)) walk(v, p ? (p + '.' + k) : k);
|
|
565
|
+
}
|
|
566
|
+
};
|
|
567
|
+
walk(data, '');
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
// ============================================================
|
|
571
|
+
// ID 唯一性
|
|
572
|
+
// ============================================================
|
|
573
|
+
const FLESH_ID_ARRAYS = {
|
|
574
|
+
'角色': ['characters'],
|
|
575
|
+
'其他实体': ['other_entities'],
|
|
576
|
+
'冲突': ['conflicts'],
|
|
577
|
+
'势力': ['factions'],
|
|
578
|
+
'剧情': ['main_lines', 'branches'],
|
|
579
|
+
'地点': ['locations'],
|
|
580
|
+
'结局': ['endings'],
|
|
581
|
+
'世界观规则': ['core_rules', 'information_rules', 'social_rules'],
|
|
582
|
+
// 关键道具:'details' 是每个 summary 数组里道具的详情副本,id 与 summary 故意重复。
|
|
583
|
+
// 跨数组唯一性只检查 3 个 summary 数组;details 通过 itemRefCheck 单独校验其 id 来自 summary。
|
|
584
|
+
'关键道具': ['core_items', 'branch_items', 'symbolic_items']
|
|
585
|
+
};
|
|
586
|
+
|
|
587
|
+
function idUniquenessCheck(data, fileType, errors) {
|
|
588
|
+
const seen = new Set();
|
|
589
|
+
for (const key of FLESH_ID_ARRAYS[fileType] || []) {
|
|
590
|
+
for (const item of data[key] || []) {
|
|
591
|
+
if (!item.id) continue;
|
|
592
|
+
if (seen.has(item.id)) {
|
|
593
|
+
errors.push({ code: 'ID_DUP', path: key + '.' + item.id, message: 'ID ' + item.id + ' 重复', hint: null });
|
|
594
|
+
}
|
|
595
|
+
seen.add(item.id);
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
// ============================================================
|
|
601
|
+
// 骨架引用与名称一致性
|
|
602
|
+
// ============================================================
|
|
603
|
+
const FLESH_TO_SKELETON = {
|
|
604
|
+
'角色': { fleshKey: 'characters', skeletonKey: 'characters' },
|
|
605
|
+
'其他实体': { fleshKey: 'other_entities', skeletonKey: 'other_entities' },
|
|
606
|
+
'冲突': { fleshKey: 'conflicts', skeletonKey: 'conflicts' },
|
|
607
|
+
'势力': { fleshKey: 'factions', skeletonKey: 'factions' },
|
|
608
|
+
'地点': { fleshKey: 'locations', skeletonKey: 'locations' },
|
|
609
|
+
'结局': { fleshKey: 'endings', skeletonKey: 'endings' }
|
|
610
|
+
};
|
|
611
|
+
|
|
612
|
+
function entityRefCheck(data, fileType, skeletonEntity, errors) {
|
|
613
|
+
const mapping = FLESH_TO_SKELETON[fileType];
|
|
614
|
+
if (!mapping) return;
|
|
615
|
+
const skeletonList = skeletonEntity[mapping.skeletonKey] || [];
|
|
616
|
+
const skMap = new Map(skeletonList.map(e => [e.id, e.name]));
|
|
617
|
+
for (const [i, item] of (data[mapping.fleshKey] || []).entries()) {
|
|
618
|
+
if (!item.id) continue;
|
|
619
|
+
if (!skMap.has(item.id)) {
|
|
620
|
+
errors.push({
|
|
621
|
+
code: 'FLESH_REF_MISSING',
|
|
622
|
+
path: mapping.fleshKey + '[' + i + '].id',
|
|
623
|
+
message: '血肉 id ' + item.id + ' 不存在于骨架 ' + mapping.skeletonKey,
|
|
624
|
+
hint: '血肉必须建立在骨架之上'
|
|
625
|
+
});
|
|
626
|
+
continue;
|
|
627
|
+
}
|
|
628
|
+
if (item.name && skMap.get(item.id) !== item.name) {
|
|
629
|
+
errors.push({
|
|
630
|
+
code: 'FLESH_NAME_MISMATCH',
|
|
631
|
+
path: mapping.fleshKey + '[' + i + '].name',
|
|
632
|
+
message: 'id ' + item.id + ' 的 name "' + item.name + '" 与骨架 "' + skMap.get(item.id) + '" 不一致',
|
|
633
|
+
hint: '同一 id 的 name 必须与骨架一致'
|
|
634
|
+
});
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
/**
|
|
640
|
+
* 结局的伏笔回收计划:foreshadow_id 必须真的存在于骨架的 foreshadows 里。
|
|
641
|
+
*
|
|
642
|
+
* 空白来源(2026-10 复查):结局模板里 foreshadow_recovery_plan 是必填,
|
|
643
|
+
* foreshadow_id 有格式约束(^FS\d{3}$),PATTERN 错误码能挡住格式错;
|
|
644
|
+
* 但"FS047 这个 id 在骨架的 31 条伏笔里到底存不存在"从来没人查过。
|
|
645
|
+
* 骨架只到 FS031 时,LLM 填一个格式正确但悬空的 FS047,
|
|
646
|
+
* 后面节奏阶段去回收它就永远对不上。
|
|
647
|
+
*/
|
|
648
|
+
function foreshadowRefCheck(data, skeletonEntity, errors) {
|
|
649
|
+
const skList = skeletonEntity.foreshadows || [];
|
|
650
|
+
if (!skList.length) return;
|
|
651
|
+
const skIds = new Set(skList.map((e) => e && e.id).filter(Boolean));
|
|
652
|
+
for (const [i, e] of (data.endings || []).entries()) {
|
|
653
|
+
const plans = e.foreshadow_recovery_plan;
|
|
654
|
+
if (!Array.isArray(plans)) continue;
|
|
655
|
+
for (const [j, plan] of plans.entries()) {
|
|
656
|
+
const fid = plan && plan.foreshadow_id;
|
|
657
|
+
if (!fid) continue;
|
|
658
|
+
if (!skIds.has(fid)) {
|
|
659
|
+
errors.push({
|
|
660
|
+
code: 'FLESH_FORESHADOW_REF_MISSING',
|
|
661
|
+
path: 'endings[' + i + '].foreshadow_recovery_plan[' + j + '].foreshadow_id',
|
|
662
|
+
message: '伏笔 id "' + fid + '" 不存在于骨架的 foreshadows',
|
|
663
|
+
hint: '伏笔 id 必须来自骨架 实体.json 的 foreshadows(可用 node references/upstream-query.js --stage=骨架 --file=实体 --list 查全部 id 名单)'
|
|
664
|
+
});
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
function storyRefCheck(data, skeletonEntity, errors) {
|
|
671
|
+
const mlMap = new Map((skeletonEntity.main_lines || []).map(e => [e.id, e.name]));
|
|
672
|
+
const bMap = new Map((skeletonEntity.branches || []).map(e => [e.id, e.name]));
|
|
673
|
+
for (const [i, item] of (data.main_lines || []).entries()) {
|
|
674
|
+
if (!item.id) continue;
|
|
675
|
+
if (!mlMap.has(item.id)) {
|
|
676
|
+
errors.push({ code: 'FLESH_REF_MISSING', path: 'main_lines[' + i + '].id', message: '主线 id ' + item.id + ' 不存在于骨架', hint: null });
|
|
677
|
+
} else if (item.name && mlMap.get(item.id) !== item.name) {
|
|
678
|
+
errors.push({ code: 'FLESH_NAME_MISMATCH', path: 'main_lines[' + i + '].name', message: '主线 id ' + item.id + ' 的 name 不一致', hint: null });
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
for (const [i, item] of (data.branches || []).entries()) {
|
|
682
|
+
if (!item.id) continue;
|
|
683
|
+
if (!bMap.has(item.id)) {
|
|
684
|
+
errors.push({ code: 'FLESH_REF_MISSING', path: 'branches[' + i + '].id', message: '支线 id ' + item.id + ' 不存在于骨架', hint: null });
|
|
685
|
+
} else if (item.name && bMap.get(item.id) !== item.name) {
|
|
686
|
+
errors.push({ code: 'FLESH_NAME_MISMATCH', path: 'branches[' + i + '].name', message: '支线 id ' + item.id + ' 的 name 不一致', hint: null });
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
// ============================================================
|
|
692
|
+
// 世界观规则:引用 + 前缀 + 分组 category 一致性
|
|
693
|
+
// ============================================================
|
|
694
|
+
const WORLD_RULE_GROUP_MAP = {
|
|
695
|
+
'core_rules': { prefix: /^R\d{3}$/, category: '核心规则' },
|
|
696
|
+
'information_rules': { prefix: /^I\d{3}$/, category: '信息规则' },
|
|
697
|
+
'social_rules': { prefix: /^SR\d{3}$/, category: '社会规则' }
|
|
698
|
+
};
|
|
699
|
+
|
|
700
|
+
function worldRuleRefCheck(data, skeletonEntity, errors) {
|
|
701
|
+
const skMap = new Map((skeletonEntity.world_rules || []).map(e => [e.id, e]));
|
|
702
|
+
|
|
703
|
+
for (const [key, spec] of Object.entries(WORLD_RULE_GROUP_MAP)) {
|
|
704
|
+
for (const [i, item] of (data[key] || []).entries()) {
|
|
705
|
+
if (!item.id) continue;
|
|
706
|
+
|
|
707
|
+
if (!spec.prefix.test(item.id)) {
|
|
708
|
+
errors.push({
|
|
709
|
+
code: 'FLESH_WORLD_RULE_CATEGORY',
|
|
710
|
+
path: key + '[' + i + '].id',
|
|
711
|
+
message: key + ' 的 id 应为 ' + spec.category + ' 对应的前缀,实际 "' + item.id + '"',
|
|
712
|
+
hint: null
|
|
713
|
+
});
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
const skItem = skMap.get(item.id);
|
|
717
|
+
if (!skItem) {
|
|
718
|
+
errors.push({
|
|
719
|
+
code: 'FLESH_REF_MISSING',
|
|
720
|
+
path: key + '[' + i + '].id',
|
|
721
|
+
message: '规则 id ' + item.id + ' 不存在于骨架 world_rules',
|
|
722
|
+
hint: null
|
|
723
|
+
});
|
|
724
|
+
continue;
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
if (item.name && skItem.name !== item.name) {
|
|
728
|
+
errors.push({
|
|
729
|
+
code: 'FLESH_NAME_MISMATCH',
|
|
730
|
+
path: key + '[' + i + '].name',
|
|
731
|
+
message: '规则 id ' + item.id + ' 的 name 不一致',
|
|
732
|
+
hint: null
|
|
733
|
+
});
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
if (skItem.category && skItem.category !== spec.category) {
|
|
737
|
+
errors.push({
|
|
738
|
+
code: 'FLESH_GROUP_CATEGORY_MISMATCH',
|
|
739
|
+
path: key + '[' + i + '].id',
|
|
740
|
+
message: '骨架中 ' + item.id + ' 的 category 是 "' + skItem.category + '",不应放在血肉的 ' + key,
|
|
741
|
+
hint: '按骨架的 category 把 ' + item.id + ' 移到对应数组'
|
|
742
|
+
});
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
// ============================================================
|
|
749
|
+
// 关键道具:引用 + 分组 category 一致性 + details 对应(P2-10 顺序修正)
|
|
750
|
+
// ============================================================
|
|
751
|
+
const ITEM_GROUP_MAP = {
|
|
752
|
+
'core_items': '核心道具',
|
|
753
|
+
'branch_items': '支线道具',
|
|
754
|
+
'symbolic_items': '象征道具'
|
|
755
|
+
};
|
|
756
|
+
|
|
757
|
+
function itemRefCheck(data, skeletonEntity, errors) {
|
|
758
|
+
const skMap = new Map((skeletonEntity.items || []).map(e => [e.id, e]));
|
|
759
|
+
const fleshItemIds = new Set();
|
|
760
|
+
|
|
761
|
+
// 道具 id → 它所在的分组数组名(core_items / branch_items / symbolic_items),
|
|
762
|
+
// 报错定位用。
|
|
763
|
+
const itemGroup = new Map();
|
|
764
|
+
|
|
765
|
+
for (const [key, expectedCategory] of Object.entries(ITEM_GROUP_MAP)) {
|
|
766
|
+
for (const [i, item] of (data[key] || []).entries()) {
|
|
767
|
+
if (!item.id) continue;
|
|
768
|
+
itemGroup.set(item.id, key);
|
|
769
|
+
|
|
770
|
+
const skItem = skMap.get(item.id);
|
|
771
|
+
if (!skItem) {
|
|
772
|
+
errors.push({ code: 'FLESH_REF_MISSING', path: key + '[' + i + '].id', message: '道具 id ' + item.id + ' 不存在于骨架 items', hint: null });
|
|
773
|
+
continue;
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
// P2-10:先校验存在,再加入 fleshItemIds
|
|
777
|
+
fleshItemIds.add(item.id);
|
|
778
|
+
|
|
779
|
+
if (item.name && skItem.name !== item.name) {
|
|
780
|
+
errors.push({ code: 'FLESH_NAME_MISMATCH', path: key + '[' + i + '].name', message: '道具 id ' + item.id + ' 的 name 不一致', hint: null });
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
if (skItem.category && skItem.category !== expectedCategory) {
|
|
784
|
+
errors.push({
|
|
785
|
+
code: 'FLESH_GROUP_CATEGORY_MISMATCH',
|
|
786
|
+
path: key + '[' + i + '].id',
|
|
787
|
+
message: '骨架中 ' + item.id + ' 的 category 是 "' + skItem.category + '",不应放在血肉的 ' + key,
|
|
788
|
+
hint: '按骨架的 category 把 ' + item.id + ' 移到对应数组'
|
|
789
|
+
});
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
const detailIds = new Set();
|
|
795
|
+
for (const [i, d] of (data.details || []).entries()) {
|
|
796
|
+
if (!d.id) continue;
|
|
797
|
+
detailIds.add(d.id);
|
|
798
|
+
if (!fleshItemIds.has(d.id)) {
|
|
799
|
+
errors.push({ code: 'FLESH_DETAILS_ORPHAN', path: 'details[' + i + '].id', message: 'details id ' + d.id + ' 没有对应的核心/支线/象征道具', hint: null });
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
for (const iid of fleshItemIds) {
|
|
803
|
+
if (!detailIds.has(iid)) {
|
|
804
|
+
// path 要指向"少 details 的那个道具条目"所在的**分组数组**:
|
|
805
|
+
// 之前写的是 'items.' + iid,而血肉的布局里根本没有 items 这个键
|
|
806
|
+
// (分组数组是 core_items / branch_items / symbolic_items)→
|
|
807
|
+
// 归因层匹配不上 → 归不到批次 → 整段重跑。
|
|
808
|
+
errors.push({
|
|
809
|
+
code: 'FLESH_DETAILS_ORPHAN',
|
|
810
|
+
path: (itemGroup.get(iid) || 'details') + '.' + iid,
|
|
811
|
+
message: '道具 ' + iid + ' 缺少对应 details',
|
|
812
|
+
hint: null
|
|
813
|
+
});
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
// ============================================================
|
|
819
|
+
// 跨文件名称引用
|
|
820
|
+
// ============================================================
|
|
821
|
+
function xrefCheck(data, fileType, skeletonEntity, errors) {
|
|
822
|
+
// 血同时收集 id 和 name 两种引用源——LLM 可能写 id (C001) 或 name (陆子仲)
|
|
823
|
+
const charNames = new Set();
|
|
824
|
+
for (const c of (skeletonEntity.characters || [])) {
|
|
825
|
+
if (c.name) charNames.add(c.name);
|
|
826
|
+
if (c.id) charNames.add(c.id);
|
|
827
|
+
}
|
|
828
|
+
const factionNames = new Set();
|
|
829
|
+
for (const f of (skeletonEntity.factions || [])) {
|
|
830
|
+
if (f.name) factionNames.add(f.name);
|
|
831
|
+
if (f.id) factionNames.add(f.id);
|
|
832
|
+
}
|
|
833
|
+
const conflictNames = new Set();
|
|
834
|
+
for (const x of (skeletonEntity.conflicts || [])) {
|
|
835
|
+
if (x.name) conflictNames.add(x.name);
|
|
836
|
+
if (x.id) conflictNames.add(x.id);
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
const checkName = (name, set, label, p) => {
|
|
840
|
+
if (!name) return;
|
|
841
|
+
if (!set.has(name)) {
|
|
842
|
+
// 拼错要给正确名字:只说"不存在"的话,LLM 只能靠猜;
|
|
843
|
+
// 给出最接近的那个,它能直接改对(算法见 graph-utils.js suggestClosestName)
|
|
844
|
+
const guess = suggestClosestName(name, set);
|
|
845
|
+
errors.push({
|
|
846
|
+
code: 'FLESH_XREF_MISSING',
|
|
847
|
+
path: p,
|
|
848
|
+
message: '引用' + label + ' "' + name + '" 不存在于骨架',
|
|
849
|
+
hint: guess
|
|
850
|
+
? '疑似拼错:骨架里有 "' + guess.name + '",请改成它'
|
|
851
|
+
: '引用必须用骨架里已有的' + label + '名字;可用 node references/upstream-query.js --stage=骨架 --file=实体 --list 查全量名单'
|
|
852
|
+
});
|
|
853
|
+
}
|
|
854
|
+
};
|
|
855
|
+
|
|
856
|
+
if (fileType === '角色') {
|
|
857
|
+
for (const [i, c] of (data.characters || []).entries()) {
|
|
858
|
+
for (const [j, r] of (c.relationships || []).entries()) {
|
|
859
|
+
checkName(r.target_name, charNames, '角色', 'characters[' + i + '].relationships[' + j + '].target_name');
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
} else if (fileType === '冲突') {
|
|
863
|
+
for (const [i, x] of (data.conflicts || []).entries()) {
|
|
864
|
+
for (const [j, g] of (x.information_gaps || []).entries()) {
|
|
865
|
+
for (const [k, n] of (g.who_knows || []).entries()) {
|
|
866
|
+
checkName(n, charNames, '角色', 'conflicts[' + i + '].information_gaps[' + j + '].who_knows[' + k + ']');
|
|
867
|
+
}
|
|
868
|
+
for (const [k, n] of (g.who_does_not_know || []).entries()) {
|
|
869
|
+
checkName(n, charNames, '角色', 'conflicts[' + i + '].information_gaps[' + j + '].who_does_not_know[' + k + ']');
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
} else if (fileType === '势力') {
|
|
874
|
+
for (const [i, f] of (data.factions || []).entries()) {
|
|
875
|
+
for (const [j, m] of (f.members || []).entries()) {
|
|
876
|
+
checkName(m.name, charNames, '角色', 'factions[' + i + '].members[' + j + '].name');
|
|
877
|
+
}
|
|
878
|
+
for (const [j, r] of (f.relations || []).entries()) {
|
|
879
|
+
checkName(r.target_name, factionNames, '势力', 'factions[' + i + '].relations[' + j + '].target_name');
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
} else if (fileType === '关键道具') {
|
|
883
|
+
for (const [i, d] of (data.details || []).entries()) {
|
|
884
|
+
for (const [j, n] of (d.related_characters || []).entries()) {
|
|
885
|
+
checkName(n, charNames, '角色', 'details[' + i + '].related_characters[' + j + ']');
|
|
886
|
+
}
|
|
887
|
+
for (const [j, n] of (d.related_conflicts || []).entries()) {
|
|
888
|
+
checkName(n, conflictNames, '冲突', 'details[' + i + '].related_conflicts[' + j + ']');
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
// ============================================================
|
|
895
|
+
// arc_type 与 arc_stages 兼容性 + expected_volume 校验
|
|
896
|
+
// ============================================================
|
|
897
|
+
function arcConsistencyCheck(data, warnings, hierarchy) {
|
|
898
|
+
const validVolumes = new Set();
|
|
899
|
+
if (hierarchy && Array.isArray(hierarchy.volumes)) {
|
|
900
|
+
for (const v of hierarchy.volumes) {
|
|
901
|
+
if (v && v.id) validVolumes.add(v.id);
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
for (const [i, c] of (data.characters || []).entries()) {
|
|
905
|
+
const t = c.arc_type;
|
|
906
|
+
const s = c.arc_stages;
|
|
907
|
+
if (typeof s === 'number') {
|
|
908
|
+
let minRequired = 0;
|
|
909
|
+
if (t === '成长型') minRequired = 3;
|
|
910
|
+
else if (t === '堕落型') minRequired = 2;
|
|
911
|
+
else if (t === '发现型') minRequired = 2;
|
|
912
|
+
else if (t === '不变型') minRequired = 1;
|
|
913
|
+
if (s <= 0) {
|
|
914
|
+
warnings.push({
|
|
915
|
+
code: 'FLESH_ARC_STAGES_INVALID',
|
|
916
|
+
path: 'characters[' + i + '].arc_stages',
|
|
917
|
+
message: 'arc_stages=' + s + ' 必须 > 0(弧光阶段数)',
|
|
918
|
+
hint: 'arc_stages 应为正整数'
|
|
919
|
+
});
|
|
920
|
+
} else if (minRequired > 0 && s < minRequired) {
|
|
921
|
+
warnings.push({
|
|
922
|
+
code: 'FLESH_ARC_INCONSISTENT',
|
|
923
|
+
path: 'characters[' + i + '].arc_stages',
|
|
924
|
+
message: 'arc_type="' + t + '" 通常需要至少 ' + minRequired + ' 个阶段,实际 arc_stages=' + s,
|
|
925
|
+
hint: 'arc_stages 表示弧光阶段数'
|
|
926
|
+
});
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
// expected_volume 必须存在于骨架层级 volumes
|
|
930
|
+
const ev = c.exclusive_needs && c.exclusive_needs.expected_volume;
|
|
931
|
+
if (ev && validVolumes.size > 0 && !validVolumes.has(ev)) {
|
|
932
|
+
warnings.push({
|
|
933
|
+
code: 'FLESH_EXPECTED_VOLUME_MISSING',
|
|
934
|
+
path: 'characters[' + i + '].exclusive_needs.expected_volume',
|
|
935
|
+
message: 'expected_volume "' + ev + '" 不存在于骨架层级 volumes',
|
|
936
|
+
hint: '改为骨架层级中已存在的卷 id'
|
|
937
|
+
});
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
// ============================================================
|
|
943
|
+
// 全量:覆盖完整性检查(P0-3:用文件类型 key)
|
|
944
|
+
// ============================================================
|
|
945
|
+
function checkEntityCoverage(skeletonIds, fleshIds, label, errors, warnings) {
|
|
946
|
+
for (const id of skeletonIds) {
|
|
947
|
+
if (!fleshIds.has(id)) {
|
|
948
|
+
warnings.push({ code: 'FLESH_INCOMPLETE', path: label + '.' + id, message: '骨架 ' + label + ' ' + id + ' 未在血肉中出现', hint: '全量写完时应覆盖所有骨架实体' });
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
for (const id of fleshIds) {
|
|
952
|
+
if (!skeletonIds.has(id)) {
|
|
953
|
+
errors.push({ code: 'FLESH_EXTRA_ENTITY', path: label + '.' + id, message: '血肉 ' + label + ' ' + id + ' 不在骨架中', hint: '本阶段不能自创实体:删掉这条,或把它列进交付说明的「骨架缺口」小节,由用户重新运行骨架阶段补全后再重跑血肉' });
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
// P0-3:数组名 → 文件类型 的映射
|
|
959
|
+
const DIRECT_FILE_TYPE_MAP = {
|
|
960
|
+
characters: '角色',
|
|
961
|
+
other_entities: '其他实体',
|
|
962
|
+
conflicts: '冲突',
|
|
963
|
+
factions: '势力',
|
|
964
|
+
locations: '地点',
|
|
965
|
+
endings: '结局'
|
|
966
|
+
};
|
|
967
|
+
|
|
968
|
+
function completenessCheck(fleshData, skeletonEntity, errors, warnings) {
|
|
969
|
+
const directChecks = [
|
|
970
|
+
{ fleshKey: 'characters', skKey: 'characters', label: 'character' },
|
|
971
|
+
{ fleshKey: 'other_entities', skKey: 'other_entities', label: 'other_entity' },
|
|
972
|
+
{ fleshKey: 'conflicts', skKey: 'conflicts', label: 'conflict' },
|
|
973
|
+
{ fleshKey: 'factions', skKey: 'factions', label: 'faction' },
|
|
974
|
+
{ fleshKey: 'locations', skKey: 'locations', label: 'location' },
|
|
975
|
+
{ fleshKey: 'endings', skKey: 'endings', label: 'ending' }
|
|
976
|
+
];
|
|
977
|
+
|
|
978
|
+
for (const { fleshKey, skKey, label } of directChecks) {
|
|
979
|
+
const fileType = DIRECT_FILE_TYPE_MAP[fleshKey];
|
|
980
|
+
const data = fleshData[fileType] ? fleshData[fileType].data : null;
|
|
981
|
+
const fleshIds = new Set(((data && data[fleshKey]) || []).map(e => e.id).filter(Boolean));
|
|
982
|
+
const skIds = new Set((skeletonEntity[skKey] || []).map(e => e.id));
|
|
983
|
+
checkEntityCoverage(skIds, fleshIds, label, errors, warnings);
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
// items
|
|
987
|
+
{
|
|
988
|
+
const data = fleshData['关键道具'] ? fleshData['关键道具'].data : null;
|
|
989
|
+
const fleshIds = new Set();
|
|
990
|
+
if (data) {
|
|
991
|
+
for (const key of ['core_items', 'branch_items', 'symbolic_items']) {
|
|
992
|
+
for (const x of (data[key] || [])) if (x.id) fleshIds.add(x.id);
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
const skIds = new Set((skeletonEntity.items || []).map(e => e.id));
|
|
996
|
+
checkEntityCoverage(skIds, fleshIds, 'item', errors, warnings);
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
// world_rules
|
|
1000
|
+
{
|
|
1001
|
+
const data = fleshData['世界观规则'] ? fleshData['世界观规则'].data : null;
|
|
1002
|
+
const fleshIds = new Set();
|
|
1003
|
+
if (data) {
|
|
1004
|
+
for (const key of ['core_rules', 'information_rules', 'social_rules']) {
|
|
1005
|
+
for (const x of (data[key] || [])) if (x.id) fleshIds.add(x.id);
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
const skIds = new Set((skeletonEntity.world_rules || []).map(e => e.id));
|
|
1009
|
+
checkEntityCoverage(skIds, fleshIds, 'world_rule', errors, warnings);
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
// main_lines / branches
|
|
1013
|
+
{
|
|
1014
|
+
const data = fleshData['剧情'] ? fleshData['剧情'].data : null;
|
|
1015
|
+
const fleshMlIds = new Set(((data && data.main_lines) || []).map(e => e.id).filter(Boolean));
|
|
1016
|
+
const fleshBrIds = new Set(((data && data.branches) || []).map(e => e.id).filter(Boolean));
|
|
1017
|
+
const skMlIds = new Set((skeletonEntity.main_lines || []).map(e => e.id));
|
|
1018
|
+
const skBrIds = new Set((skeletonEntity.branches || []).map(e => e.id));
|
|
1019
|
+
checkEntityCoverage(skMlIds, fleshMlIds, 'main_line', errors, warnings);
|
|
1020
|
+
checkEntityCoverage(skBrIds, fleshBrIds, 'branch', errors, warnings);
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
// 说明:foreshadows / climaxes / pleasures 在血肉阶段无独立档案,不检查。
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
// ============================================================
|
|
1027
|
+
// md 生成 + stage-status(结构化 markdown,零反引号)
|
|
1028
|
+
// ============================================================
|
|
1029
|
+
const BT = String.fromCharCode(96);
|
|
1030
|
+
const BT3 = BT + BT + BT;
|
|
1031
|
+
|
|
1032
|
+
function jsonToMd(data, fileType) {
|
|
1033
|
+
// flesh 阶段:按 FLESH_DISPATCH 把顶层数组分别渲染为 H2 分组(renderFleshByFileType)
|
|
1034
|
+
const body = renderFleshByFileType(data, fileType);
|
|
1035
|
+
return '# ' + fileType + '\n\n> 自动生成于 ' + new Date().toISOString() + '\n\n' +
|
|
1036
|
+
body + '\n---\n\n## 源数据\n\n' + BT3 + 'json\n' + JSON.stringify(data, null, 2) + '\n' + BT3 + '\n';
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
function regenerateMd(stageDir) {
|
|
1040
|
+
if (!fs.existsSync(stageDir)) return;
|
|
1041
|
+
for (const f of fs.readdirSync(stageDir)) {
|
|
1042
|
+
// 排除 .stage-status.json:它是校验状态记账文件,不是业务数据
|
|
1043
|
+
if (!f.endsWith('.json') || f.startsWith('.')) continue;
|
|
1044
|
+
const jsonPath = path.join(stageDir, f);
|
|
1045
|
+
const mdPath = jsonPath.replace(/\.json$/, '.md');
|
|
1046
|
+
try {
|
|
1047
|
+
const data = JSON.parse(fs.readFileSync(jsonPath, 'utf-8'));
|
|
1048
|
+
const fileType = f.replace(/\.json$/, '');
|
|
1049
|
+
fs.writeFileSync(mdPath, jsonToMd(data, fileType), 'utf-8');
|
|
1050
|
+
} catch (e) {}
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1054
|
+
function updateStageStatus(stageDir, fileType, status) {
|
|
1055
|
+
const statusPath = path.join(stageDir, '.stage-status.json');
|
|
1056
|
+
let s = { stage: '血肉', last_check: null, files: {}, all_check: { status: 'PENDING', rounds: 0 } };
|
|
1057
|
+
if (fs.existsSync(statusPath)) {
|
|
1058
|
+
try { s = JSON.parse(fs.readFileSync(statusPath, 'utf-8')); } catch (e) {}
|
|
1059
|
+
}
|
|
1060
|
+
// 兜底:旧 status 文件可能缺 files / all_check 字段
|
|
1061
|
+
s.stage = s.stage || '血肉';
|
|
1062
|
+
s.files = s.files || {};
|
|
1063
|
+
s.all_check = s.all_check || { status: 'PENDING', rounds: 0 };
|
|
1064
|
+
s.last_check = new Date().toISOString();
|
|
1065
|
+
if (fileType === 'ALL') {
|
|
1066
|
+
s.all_check = { status: status === 0 ? 'PASSED' : 'FAILED', rounds: (s.all_check.rounds || 0) + 1 };
|
|
1067
|
+
} else {
|
|
1068
|
+
const prev = s.files[fileType] || { retries: 0 };
|
|
1069
|
+
s.files[fileType] = { status: status === 0 ? 'PASSED' : 'FAILED', retries: (prev.retries || 0) + (status === 1 ? 1 : 0), last_check: new Date().toISOString() };
|
|
1070
|
+
// 单文件一旦被改动/失败,之前的全量结论就不再可信(全量含跨文件检查:
|
|
1071
|
+
// 配额一致性、图连通性、引用完整性等),必须作废,等重新跑 --all。
|
|
1072
|
+
if (s.all_check && s.all_check.status === 'PASSED') {
|
|
1073
|
+
s.all_check = {
|
|
1074
|
+
status: 'STALE',
|
|
1075
|
+
rounds: s.all_check.rounds || 0,
|
|
1076
|
+
stale_reason: '文件 ' + fileType + ' 在 ' + s.last_check + ' 被单文件校验改动,全量结论已作废,请重新执行全量校验',
|
|
1077
|
+
stale_at: s.last_check
|
|
1078
|
+
};
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
try { fs.writeFileSync(statusPath, JSON.stringify(s, null, 2), 'utf-8'); } catch (e) {}
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
function emit(status, file, errors, warnings) {
|
|
1085
|
+
const payload = { status: status, file: file, errors: errors, warnings: warnings };
|
|
1086
|
+
process.stdout.write(JSON.stringify(payload, null, 2) + '\n');
|
|
1087
|
+
process.exitCode = status;
|
|
1088
|
+
// 返回载荷对象:调用方可能用返回值做守卫(如 `if (err) return err;`),
|
|
1089
|
+
// 返回 undefined 会让守卫失效导致继续执行并二次输出。
|
|
1090
|
+
return payload;
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
// ============================================================
|
|
1094
|
+
// 单文件模式
|
|
1095
|
+
// ============================================================
|
|
1096
|
+
function validateSingle(args) {
|
|
1097
|
+
const input = args.input;
|
|
1098
|
+
const template = args.template;
|
|
1099
|
+
const file = args.file;
|
|
1100
|
+
const errors = [];
|
|
1101
|
+
const warnings = [];
|
|
1102
|
+
|
|
1103
|
+
if (!args.upstream || args.upstream.length === 0) {
|
|
1104
|
+
return emit(2, file, [{ code: 'UPSTREAM_MISSING', path: '', message: '血肉阶段必须提供 --upstream=<骨架目录>', hint: null }], []);
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
const gl = loadGlossary();
|
|
1108
|
+
if (gl.error) return emit(2, file, [{ code: 'GLOSSARY_LOAD', path: '', message: gl.error, hint: null }], []);
|
|
1109
|
+
|
|
1110
|
+
const inputRes = readJson(input);
|
|
1111
|
+
if (inputRes.error) return emit(2, file, [{ code: 'READ', path: input, message: inputRes.error, hint: null }], []);
|
|
1112
|
+
const data = inputRes.data;
|
|
1113
|
+
|
|
1114
|
+
const tplRes = readJson(template);
|
|
1115
|
+
if (tplRes.error) return emit(2, file, [{ code: 'TEMPLATE', path: template, message: tplRes.error, hint: null }], []);
|
|
1116
|
+
|
|
1117
|
+
const sk = loadSkeleton(args.upstream);
|
|
1118
|
+
if (!sk.entity) {
|
|
1119
|
+
return emit(2, file, [{ code: 'UPSTREAM_NOT_READY', path: '', message: '骨架 实体.json 读不到', hint: '请先完成骨架阶段' }], []);
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
// 阶段门禁:上游必须已通过全量校验(此前只在提示词里约定,脚本不校验)
|
|
1123
|
+
const gate = readStageGate(args.upstream[0]);
|
|
1124
|
+
if (!gate.ok) {
|
|
1125
|
+
return emit(2, file, [{ code: 'UPSTREAM_NOT_PASSED', path: '', message: gate.reason, hint: '请先对骨架阶段执行全量校验并通过' }], []);
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
const scalarSet = new Set(gl.chapterScalarFields);
|
|
1129
|
+
const containerSet = new Set(gl.chapterContainerFields);
|
|
1130
|
+
|
|
1131
|
+
safeCheck('checkChapterForbidden', () => checkChapterForbidden(data, scalarSet, containerSet, errors), errors);
|
|
1132
|
+
safeCheck('validateNode', () => validateNode(data, tplRes.data.structure || {}, '', gl.enums, errors), errors);
|
|
1133
|
+
safeCheck('charsetAndForbiddenCheck', () => charsetAndForbiddenCheck(data, errors), errors);
|
|
1134
|
+
safeCheck('freeTextChapterCheck', () => freeTextChapterCheck(data, warnings), errors);
|
|
1135
|
+
safeCheck('idUniquenessCheck', () => idUniquenessCheck(data, file, errors), errors);
|
|
1136
|
+
|
|
1137
|
+
if (file === '角色' || file === '其他实体' || file === '冲突' || file === '势力' || file === '地点' || file === '结局') {
|
|
1138
|
+
safeCheck('entityRefCheck', () => entityRefCheck(data, file, sk.entity, errors), errors);
|
|
1139
|
+
} else if (file === '剧情') {
|
|
1140
|
+
safeCheck('storyRefCheck', () => storyRefCheck(data, sk.entity, errors), errors);
|
|
1141
|
+
} else if (file === '世界观规则') {
|
|
1142
|
+
safeCheck('worldRuleRefCheck', () => worldRuleRefCheck(data, sk.entity, errors), errors);
|
|
1143
|
+
} else if (file === '关键道具') {
|
|
1144
|
+
safeCheck('itemRefCheck', () => itemRefCheck(data, sk.entity, errors), errors);
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
// 结局的伏笔回收计划:foreshadow_id 要真的在骨架里
|
|
1148
|
+
if (file === '结局') {
|
|
1149
|
+
safeCheck('foreshadowRefCheck', () => foreshadowRefCheck(data, sk.entity, errors), errors);
|
|
1150
|
+
}
|
|
1151
|
+
|
|
1152
|
+
safeCheck('xrefCheck', () => xrefCheck(data, file, sk.entity, errors), errors);
|
|
1153
|
+
safeCheck('fleshSelfRelationCheck', () => fleshSelfRelationCheck(data, file, errors), errors);
|
|
1154
|
+
safeCheck('contentQualityCheck', () => runContentQualityChecks(data, errors, { enumLeaves: collectEnumLeaves(tplRes.data.structure) }), errors);
|
|
1155
|
+
safeCheck('traitsAndChangesCheck', () => traitsAndChangesCheck(data, file, errors, warnings), errors);
|
|
1156
|
+
|
|
1157
|
+
if (file === '角色') {
|
|
1158
|
+
safeCheck('arcConsistencyCheck', () => arcConsistencyCheck(data, warnings, sk.hierarchy), errors);
|
|
1159
|
+
// 单文件模式看不到血肉全貌,只做语义比对,不做覆盖度比对
|
|
1160
|
+
safeCheck('skeletonRelationConsistencyCheck',
|
|
1161
|
+
() => skeletonRelationConsistencyCheck(data, sk, errors, warnings, { checkCoverage: false }), errors);
|
|
1162
|
+
}
|
|
1163
|
+
|
|
1164
|
+
const stageDir = path.dirname(input);
|
|
1165
|
+
updateStageStatus(stageDir, file, errors.length === 0 ? 0 : 1);
|
|
1166
|
+
regenerateMd(stageDir);
|
|
1167
|
+
|
|
1168
|
+
// 单文件模式不做跨文件检查,必须在全部文件单检完成后跑一次 --all 才算通过
|
|
1169
|
+
if (errors.length === 0) {
|
|
1170
|
+
warnings.push({
|
|
1171
|
+
code: 'NEED_ALL_CHECK',
|
|
1172
|
+
path: '',
|
|
1173
|
+
message: '本文件单检通过;跨文件一致性检查在 --all 模式下进行,全部文件单检完成后仍需执行一次全量校验(--all)',
|
|
1174
|
+
hint: null
|
|
1175
|
+
});
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1178
|
+
emit(errors.length === 0 ? 0 : 1, file, errors, warnings);
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
// ============================================================
|
|
1182
|
+
// 全量模式
|
|
1183
|
+
// ============================================================
|
|
1184
|
+
function validateAll(args) {
|
|
1185
|
+
const stageDir = args['stage-dir'];
|
|
1186
|
+
const templateDir = args['template-dir'];
|
|
1187
|
+
const errors = [];
|
|
1188
|
+
const warnings = [];
|
|
1189
|
+
|
|
1190
|
+
if (!args.upstream || args.upstream.length === 0) {
|
|
1191
|
+
return emit(2, 'ALL', [{ code: 'UPSTREAM_MISSING', path: '', message: '血肉阶段必须提供 --upstream=<骨架目录>', hint: null }], []);
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
const gl = loadGlossary();
|
|
1195
|
+
if (gl.error) return emit(2, 'ALL', [{ code: 'GLOSSARY_LOAD', path: '', message: gl.error, hint: null }], []);
|
|
1196
|
+
|
|
1197
|
+
if (!fs.existsSync(stageDir)) {
|
|
1198
|
+
return emit(2, 'ALL', [{ code: 'ARG', path: stageDir, message: '阶段目录不存在', hint: null }], []);
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1201
|
+
const sk = loadSkeleton(args.upstream);
|
|
1202
|
+
if (!sk.entity) {
|
|
1203
|
+
return emit(2, 'ALL', [{ code: 'UPSTREAM_NOT_READY', path: '', message: '骨架 实体.json 读不到', hint: null }], []);
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1206
|
+
// 阶段门禁:上游必须已通过全量校验(此前只在提示词里约定,脚本不校验)
|
|
1207
|
+
const gate = readStageGate(args.upstream[0]);
|
|
1208
|
+
if (!gate.ok) {
|
|
1209
|
+
return emit(2, 'ALL', [{ code: 'UPSTREAM_NOT_PASSED', path: '', message: gate.reason, hint: '请先对骨架阶段执行全量校验并通过' }], []);
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1212
|
+
const otherEntityCount = Array.isArray(sk.entity.other_entities) ? sk.entity.other_entities.length : 0;
|
|
1213
|
+
const FILES = [
|
|
1214
|
+
{ type: '角色', name: '角色.json', tpl: '角色模板.json' },
|
|
1215
|
+
{ type: '冲突', name: '冲突.json', tpl: '冲突模板.json' },
|
|
1216
|
+
{ type: '势力', name: '势力.json', tpl: '势力模板.json' },
|
|
1217
|
+
{ type: '剧情', name: '剧情.json', tpl: '剧情模板.json' },
|
|
1218
|
+
{ type: '地点', name: '地点.json', tpl: '地点模板.json' },
|
|
1219
|
+
{ type: '结局', name: '结局.json', tpl: '结局模板.json' },
|
|
1220
|
+
{ type: '世界观规则', name: '世界观规则.json', tpl: '世界观规则模板.json' },
|
|
1221
|
+
{ type: '关键道具', name: '关键道具.json', tpl: '关键道具模板.json' },
|
|
1222
|
+
...(otherEntityCount > 0 || fs.existsSync(path.join(stageDir, '其他实体.json'))
|
|
1223
|
+
? [{ type: '其他实体', name: '其他实体.json', tpl: '其他实体模板.json' }]
|
|
1224
|
+
: [])
|
|
1225
|
+
];
|
|
1226
|
+
|
|
1227
|
+
const loaded = {};
|
|
1228
|
+
const scalarSet = new Set(gl.chapterScalarFields);
|
|
1229
|
+
const containerSet = new Set(gl.chapterContainerFields);
|
|
1230
|
+
|
|
1231
|
+
for (const f of FILES) {
|
|
1232
|
+
const dataPath = path.join(stageDir, f.name);
|
|
1233
|
+
const tplPath = path.join(templateDir, f.tpl);
|
|
1234
|
+
const inputRes = readJson(dataPath);
|
|
1235
|
+
if (inputRes.error) {
|
|
1236
|
+
errors.push({ code: 'READ', path: dataPath, message: inputRes.error, hint: null });
|
|
1237
|
+
continue;
|
|
1238
|
+
}
|
|
1239
|
+
const tplRes = readJson(tplPath);
|
|
1240
|
+
if (tplRes.error) {
|
|
1241
|
+
errors.push({ code: 'TEMPLATE', path: tplPath, message: tplRes.error, hint: null });
|
|
1242
|
+
continue;
|
|
1243
|
+
}
|
|
1244
|
+
loaded[f.type] = { data: inputRes.data, tpl: tplRes.data };
|
|
1245
|
+
const data = inputRes.data;
|
|
1246
|
+
|
|
1247
|
+
safeCheck('checkChapterForbidden', () => checkChapterForbidden(data, scalarSet, containerSet, errors), errors);
|
|
1248
|
+
safeCheck('validateNode', () => validateNode(data, tplRes.data.structure || {}, '', gl.enums, errors), errors);
|
|
1249
|
+
safeCheck('charsetAndForbiddenCheck', () => charsetAndForbiddenCheck(data, errors), errors);
|
|
1250
|
+
safeCheck('freeTextChapterCheck', () => freeTextChapterCheck(data, warnings), errors);
|
|
1251
|
+
safeCheck('idUniquenessCheck', () => idUniquenessCheck(data, f.type, errors), errors);
|
|
1252
|
+
|
|
1253
|
+
if (f.type === '角色' || f.type === '其他实体' || f.type === '冲突' || f.type === '势力' || f.type === '地点' || f.type === '结局') {
|
|
1254
|
+
safeCheck('entityRefCheck', () => entityRefCheck(data, f.type, sk.entity, errors), errors);
|
|
1255
|
+
} else if (f.type === '剧情') {
|
|
1256
|
+
safeCheck('storyRefCheck', () => storyRefCheck(data, sk.entity, errors), errors);
|
|
1257
|
+
} else if (f.type === '世界观规则') {
|
|
1258
|
+
safeCheck('worldRuleRefCheck', () => worldRuleRefCheck(data, sk.entity, errors), errors);
|
|
1259
|
+
} else if (f.type === '关键道具') {
|
|
1260
|
+
safeCheck('itemRefCheck', () => itemRefCheck(data, sk.entity, errors), errors);
|
|
1261
|
+
}
|
|
1262
|
+
|
|
1263
|
+
// 结局的伏笔回收计划:foreshadow_id 要真的在骨架里
|
|
1264
|
+
if (f.type === '结局') {
|
|
1265
|
+
safeCheck('foreshadowRefCheck', () => foreshadowRefCheck(data, sk.entity, errors), errors);
|
|
1266
|
+
}
|
|
1267
|
+
|
|
1268
|
+
safeCheck('xrefCheck', () => xrefCheck(data, f.type, sk.entity, errors), errors);
|
|
1269
|
+
safeCheck('fleshSelfRelationCheck', () => fleshSelfRelationCheck(data, f.type, errors), errors);
|
|
1270
|
+
safeCheck('contentQualityCheck', () => runContentQualityChecks(data, errors, { enumLeaves: collectEnumLeaves(tplRes.data.structure) }), errors);
|
|
1271
|
+
safeCheck('traitsAndChangesCheck', () => traitsAndChangesCheck(data, f.type, errors, warnings), errors);
|
|
1272
|
+
|
|
1273
|
+
if (f.type === '角色') safeCheck('arcConsistencyCheck', () => arcConsistencyCheck(data, warnings, sk.hierarchy), errors);
|
|
1274
|
+
}
|
|
1275
|
+
|
|
1276
|
+
safeCheck('completenessCheck', () => completenessCheck(loaded, sk.entity, errors, warnings), errors);
|
|
1277
|
+
|
|
1278
|
+
if (loaded['角色']) {
|
|
1279
|
+
safeCheck('skeletonRelationConsistencyCheck',
|
|
1280
|
+
() => skeletonRelationConsistencyCheck(loaded['角色'].data, sk, errors, warnings, { checkCoverage: true }), errors);
|
|
1281
|
+
}
|
|
1282
|
+
|
|
1283
|
+
updateStageStatus(stageDir, 'ALL', errors.length === 0 ? 0 : 1);
|
|
1284
|
+
regenerateMd(stageDir);
|
|
1285
|
+
|
|
1286
|
+
emit(errors.length === 0 ? 0 : 1, 'ALL', errors, warnings);
|
|
1287
|
+
}
|
|
1288
|
+
|
|
1289
|
+
// ============================================================
|
|
1290
|
+
// 入口
|
|
1291
|
+
// ============================================================
|
|
1292
|
+
function main() {
|
|
1293
|
+
const args = parseArgs();
|
|
1294
|
+
|
|
1295
|
+
if (args.all) {
|
|
1296
|
+
if (!args['stage-dir'] || !args['template-dir']) {
|
|
1297
|
+
return emit(2, 'ALL', [{ code: 'ARG', path: '', message: '全量模式需要 --stage-dir 和 --template-dir', hint: null }], []);
|
|
1298
|
+
}
|
|
1299
|
+
return validateAll(args);
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
if (args.input) {
|
|
1303
|
+
if (!args.template || !args.file) {
|
|
1304
|
+
return emit(2, args.file || 'UNKNOWN', [{ code: 'ARG', path: '', message: '单文件模式需要 --template 和 --file', hint: null }], []);
|
|
1305
|
+
}
|
|
1306
|
+
return validateSingle(args);
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1309
|
+
return emit(2, 'UNKNOWN', [{ code: 'ARG', path: '', message: '需要 --input 或 --all', hint: null }], []);
|
|
1310
|
+
}
|
|
1311
|
+
|
|
1312
|
+
main();
|