@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,198 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* upstream-query.js —— 上游数据按需查询(只读)
|
|
4
|
+
*
|
|
5
|
+
* 用途:摘要(summarizeStage)给出的是"全量 id + 名称"总览,
|
|
6
|
+
* 但逐章细纲、单个角色档案这类明细体量大,无法塞进 prompt。
|
|
7
|
+
* 本脚本让 Agent 按需精确取出单条/单章,避免"为了看一条而读整个文件"。
|
|
8
|
+
*
|
|
9
|
+
* 用法(在项目根目录下执行):
|
|
10
|
+
* node references/upstream-query.js --stage=节奏 --file=章节细纲 --ch=12
|
|
11
|
+
* node references/upstream-query.js --stage=节奏 --file=章节规划 --ch=12
|
|
12
|
+
* node references/upstream-query.js --stage=血肉 --file=角色 --id=C001
|
|
13
|
+
* node references/upstream-query.js --stage=骨架 --file=实体 --id=FS042
|
|
14
|
+
* node references/upstream-query.js --stage=骨架 --file=实体 --ids=FS042,FS043
|
|
15
|
+
* node references/upstream-query.js --stage=节奏 --file=章节细纲 --list
|
|
16
|
+
*
|
|
17
|
+
* 输出:stdout 为 JSON
|
|
18
|
+
* { "status": 0, "stage": "节奏", "file": "章节细纲", "matched": 1, "items": [ ... ] }
|
|
19
|
+
* status: 0=命中 1=未命中 2=参数/读取错误
|
|
20
|
+
*/
|
|
21
|
+
import fs from 'node:fs';
|
|
22
|
+
import path from 'node:path';
|
|
23
|
+
import { fileURLToPath } from 'url';
|
|
24
|
+
|
|
25
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
26
|
+
|
|
27
|
+
// 各阶段的文件名白名单(防止路径穿越)
|
|
28
|
+
const STAGE_FILES = {
|
|
29
|
+
骨架: ['框架', '实体', '关系', '层级'],
|
|
30
|
+
血肉: ['角色', '其他实体', '冲突', '势力', '剧情', '地点', '结局', '世界观规则', '关键道具'],
|
|
31
|
+
节奏: ['章节规划', '时序映射', '节奏参数', '章节细纲'],
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
function emit(status, payload) {
|
|
35
|
+
process.stdout.write(JSON.stringify(payload, null, 2) + '\n');
|
|
36
|
+
process.exitCode = status;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function parseArgs(argv) {
|
|
40
|
+
const args = {};
|
|
41
|
+
for (const a of argv.slice(2)) {
|
|
42
|
+
const m = a.match(/^--([\w-]+)(?:=(.*))?$/);
|
|
43
|
+
if (m) args[m[1]] = m[2] === undefined ? true : m[2];
|
|
44
|
+
}
|
|
45
|
+
return args;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 找项目根:向上找带 `.fancy-deployed` 标记的目录。
|
|
50
|
+
*
|
|
51
|
+
* 旧实现是 `path.join(__dirname, '..', ...)` —— 部署后 __dirname 是
|
|
52
|
+
* `<项目根>/references`,`..` 正好是项目根;但从插件目录直接跑
|
|
53
|
+
* (开发/测试/模型手动 node plugins/.../upstream-query.js)时,
|
|
54
|
+
* `..` 是**插件根**,会指向 plugins/fancy-story-builder/设定/...,
|
|
55
|
+
* 报"文件不存在"。
|
|
56
|
+
*
|
|
57
|
+
* @returns {string|null} 项目根;找不到返回 null
|
|
58
|
+
*/
|
|
59
|
+
function findProjectRoot(startDir) {
|
|
60
|
+
let dir = startDir;
|
|
61
|
+
for (let i = 0; i < 8; i++) {
|
|
62
|
+
try {
|
|
63
|
+
if (fs.existsSync(path.join(dir, '.fancy-deployed'))) return dir;
|
|
64
|
+
} catch {
|
|
65
|
+
// 读不到就继续往上
|
|
66
|
+
}
|
|
67
|
+
const parent = path.dirname(dir);
|
|
68
|
+
if (parent === dir) break;
|
|
69
|
+
dir = parent;
|
|
70
|
+
}
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** 阶段目录:<项目根>/设定/raw/sources/<阶段> */
|
|
75
|
+
function stageDirOf(stage, projectRoot) {
|
|
76
|
+
// 显式指定的项目根优先;否则向上找 .fancy-deployed;都没有就退回旧行为
|
|
77
|
+
const root = projectRoot || findProjectRoot(__dirname) || path.join(__dirname, '..');
|
|
78
|
+
return path.join(root, '设定', 'raw', 'sources', stage);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function readJson(p) {
|
|
82
|
+
try {
|
|
83
|
+
return { data: JSON.parse(fs.readFileSync(p, 'utf-8')) };
|
|
84
|
+
} catch (e) {
|
|
85
|
+
return { error: e.message };
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** 在 JSON 里找出所有"数组型字段",并把每个元素当作一条记录 */
|
|
90
|
+
function collectRecords(data) {
|
|
91
|
+
const records = [];
|
|
92
|
+
if (!data || typeof data !== 'object' || Array.isArray(data)) return records;
|
|
93
|
+
for (const [key, val] of Object.entries(data)) {
|
|
94
|
+
if (!Array.isArray(val)) continue;
|
|
95
|
+
for (const it of val) {
|
|
96
|
+
if (it && typeof it === 'object') records.push({ group: key, item: it });
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return records;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** 记录的身份:id 或 ch(与摘要规则一致) */
|
|
103
|
+
function recordId(item) {
|
|
104
|
+
if (item.id !== undefined && item.id !== null && item.id !== '') return String(item.id);
|
|
105
|
+
if (item.ch !== undefined && item.ch !== null) return String(item.ch);
|
|
106
|
+
return '';
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function main() {
|
|
110
|
+
const args = parseArgs(process.argv);
|
|
111
|
+
|
|
112
|
+
const stage = args.stage;
|
|
113
|
+
const file = args.file;
|
|
114
|
+
// --project-root 显式指定项目根(没指定就向上找 .fancy-deployed)
|
|
115
|
+
const projectRoot = typeof args['project-root'] === 'string' ? args['project-root'] : null;
|
|
116
|
+
|
|
117
|
+
if (!stage || !STAGE_FILES[stage]) {
|
|
118
|
+
emit(2, {
|
|
119
|
+
status: 2,
|
|
120
|
+
error: `--stage 必须是 ${Object.keys(STAGE_FILES).join(' / ')} 之一`,
|
|
121
|
+
available_stages: Object.keys(STAGE_FILES),
|
|
122
|
+
});
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
if (!file || !STAGE_FILES[stage].includes(file)) {
|
|
126
|
+
emit(2, {
|
|
127
|
+
status: 2,
|
|
128
|
+
error: `--file 必须是 ${stage} 阶段的 ${STAGE_FILES[stage].join(' / ')} 之一`,
|
|
129
|
+
available_files: STAGE_FILES[stage],
|
|
130
|
+
});
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const filePath = path.join(stageDirOf(stage, projectRoot), file + '.json');
|
|
135
|
+
if (!fs.existsSync(filePath)) {
|
|
136
|
+
emit(2, { status: 2, error: `文件不存在: ${filePath}`, hint: '请先完成该阶段' });
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
const r = readJson(filePath);
|
|
140
|
+
if (r.error) {
|
|
141
|
+
emit(2, { status: 2, error: 'JSON 解析失败: ' + r.error, path: filePath });
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const records = collectRecords(r.data);
|
|
146
|
+
|
|
147
|
+
// --list:列出该文件里所有记录的分组与身份
|
|
148
|
+
if (args.list) {
|
|
149
|
+
const groups = {};
|
|
150
|
+
for (const rec of records) {
|
|
151
|
+
if (!groups[rec.group]) groups[rec.group] = [];
|
|
152
|
+
groups[rec.group].push(recordId(rec.item));
|
|
153
|
+
}
|
|
154
|
+
emit(0, { status: 0, stage, file, path: filePath, groups });
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const want = [];
|
|
159
|
+
if (args.ch !== undefined) want.push(String(args.ch));
|
|
160
|
+
if (args.id !== undefined) want.push(String(args.id));
|
|
161
|
+
if (args.ids !== undefined) {
|
|
162
|
+
for (const s of String(args.ids).split(',')) if (s.trim()) want.push(s.trim());
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (want.length === 0) {
|
|
166
|
+
emit(2, {
|
|
167
|
+
status: 2,
|
|
168
|
+
error: '需要 --ch / --id / --ids 之一,或用 --list 查看可用记录',
|
|
169
|
+
hint: '例如: --ch=12 或 --id=C001 或 --ids=FS042,FS043',
|
|
170
|
+
});
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const wantSet = new Set(want);
|
|
175
|
+
const matched = records.filter(rec => wantSet.has(recordId(rec.item)));
|
|
176
|
+
|
|
177
|
+
if (matched.length === 0) {
|
|
178
|
+
emit(1, {
|
|
179
|
+
status: 1,
|
|
180
|
+
stage, file, path: filePath,
|
|
181
|
+
matched: 0,
|
|
182
|
+
wanted: want,
|
|
183
|
+
items: [],
|
|
184
|
+
hint: '未找到匹配的记录。可用 --list 查看该文件的全部记录分组',
|
|
185
|
+
});
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
emit(0, {
|
|
190
|
+
status: 0,
|
|
191
|
+
stage, file, path: filePath,
|
|
192
|
+
matched: matched.length,
|
|
193
|
+
items: matched.map(rec => rec.item),
|
|
194
|
+
groups: matched.map(rec => rec.group),
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
main();
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* v2/baseline.js —— 00-baseline:固化选题、参考与公式版本。
|
|
3
|
+
*/
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import {
|
|
7
|
+
SCHEMA_VERSION,
|
|
8
|
+
ensureDir,
|
|
9
|
+
fileExists,
|
|
10
|
+
nowIso,
|
|
11
|
+
readJson,
|
|
12
|
+
stageDir,
|
|
13
|
+
writeJsonAtomic,
|
|
14
|
+
} from './core.js';
|
|
15
|
+
|
|
16
|
+
const INPUT_FIELDS = [
|
|
17
|
+
'book_name', 'genre', 'platform', 'positioning', 'one_line_pitch', 'target_chapters', 'target_words',
|
|
18
|
+
'core_conflict', 'reader_value', 'golden_finger', 'core_setting', 'selling_points',
|
|
19
|
+
'hard_constraints', 'anti_tropes', 'protagonist', 'world_setting',
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
export function buildBaselinePayload(topicData, formulasDoc, genreProfilesDoc) {
|
|
23
|
+
const topic = topicData || {};
|
|
24
|
+
const input = {
|
|
25
|
+
schema_version: SCHEMA_VERSION,
|
|
26
|
+
book_name: topic.book_name || topic.title || '未命名',
|
|
27
|
+
genre: topic.genre || '',
|
|
28
|
+
positioning: topic.positioning || '',
|
|
29
|
+
one_line_pitch: topic.one_line_pitch || '',
|
|
30
|
+
target_chapters: Number(topic.target_chapters) || 0,
|
|
31
|
+
target_words: Number(topic.target_words) || 0,
|
|
32
|
+
core_conflict: topic.core_conflict || '',
|
|
33
|
+
reader_value: topic.reader_value || '',
|
|
34
|
+
golden_finger: topic.golden_finger || '',
|
|
35
|
+
core_setting: topic.core_setting || '',
|
|
36
|
+
selling_points: Array.isArray(topic.selling_points) ? topic.selling_points : [],
|
|
37
|
+
hard_constraints: Array.isArray(topic.hard_constraints) ? topic.hard_constraints : [],
|
|
38
|
+
anti_tropes: Array.isArray(topic.anti_tropes) ? topic.anti_tropes : [],
|
|
39
|
+
protagonist: topic.protagonist || '',
|
|
40
|
+
world_setting: topic.world_setting || '',
|
|
41
|
+
created_at: nowIso(),
|
|
42
|
+
};
|
|
43
|
+
// 只保留已定义字段,避免把 undefined 写进 JSON
|
|
44
|
+
for (const key of Object.keys(input)) {
|
|
45
|
+
if (input[key] === undefined) delete input[key];
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
input,
|
|
49
|
+
references: {
|
|
50
|
+
schema_version: SCHEMA_VERSION,
|
|
51
|
+
references: Array.isArray(topic.references) ? topic.references : [],
|
|
52
|
+
benchmark: topic.benchmark || null,
|
|
53
|
+
note: '对标与参考决策。没有时保持空数组。',
|
|
54
|
+
},
|
|
55
|
+
formulas: {
|
|
56
|
+
_meta: {
|
|
57
|
+
schema_version: SCHEMA_VERSION,
|
|
58
|
+
source: 'quantity-formulas',
|
|
59
|
+
version: '2026-11-06',
|
|
60
|
+
read_only: true,
|
|
61
|
+
},
|
|
62
|
+
...formulasDoc,
|
|
63
|
+
},
|
|
64
|
+
genreProfiles: genreProfilesDoc || null,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* 确保 00-baseline 存在。已存在时不覆盖,除非 opts.force=true。
|
|
70
|
+
*/
|
|
71
|
+
export function ensureBaseline(projectRoot, topicData, formulasDoc, opts = {}) {
|
|
72
|
+
const dir = stageDir(projectRoot, '00-baseline');
|
|
73
|
+
ensureDir(dir);
|
|
74
|
+
const payload = buildBaselinePayload(topicData, formulasDoc, opts.genreProfilesDoc);
|
|
75
|
+
const files = ['input.json', 'references.json', 'formulas.json'];
|
|
76
|
+
if (payload.genreProfiles) files.push('genre-profiles.json');
|
|
77
|
+
const forceFiles = new Set(opts.forceFiles || []);
|
|
78
|
+
const written = [];
|
|
79
|
+
const pairs = {
|
|
80
|
+
'input.json': payload.input,
|
|
81
|
+
'references.json': payload.references,
|
|
82
|
+
'formulas.json': payload.formulas,
|
|
83
|
+
'genre-profiles.json': payload.genreProfiles,
|
|
84
|
+
};
|
|
85
|
+
for (const file of files) {
|
|
86
|
+
const target = path.join(dir, file);
|
|
87
|
+
if (!opts.force && !forceFiles.has(file) && fileExists(target)) continue;
|
|
88
|
+
writeJsonAtomic(target, pairs[file]);
|
|
89
|
+
written.push(file);
|
|
90
|
+
}
|
|
91
|
+
return { ok: true, dir, written };
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function loadBaseline(projectRoot) {
|
|
95
|
+
const dir = stageDir(projectRoot, '00-baseline');
|
|
96
|
+
return {
|
|
97
|
+
input: readJson(path.join(dir, 'input.json'), null),
|
|
98
|
+
references: readJson(path.join(dir, 'references.json'), null),
|
|
99
|
+
formulas: readJson(path.join(dir, 'formulas.json'), null),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function loadFormulasDoc(projectRoot, fallbackPath) {
|
|
104
|
+
// references/ 是插件每次阶段启动时刷新的副本;优先它,避免旧项目一直用
|
|
105
|
+
// 00-baseline 里冻结的老公式。
|
|
106
|
+
const deployed = readJson(path.join(projectRoot, 'references', 'formulas-skeleton.json'), null);
|
|
107
|
+
if (deployed && deployed.formulas) return deployed;
|
|
108
|
+
const local = loadBaseline(projectRoot).formulas;
|
|
109
|
+
if (local && local.formulas) return local;
|
|
110
|
+
if (fallbackPath && fs.existsSync(fallbackPath)) return readJson(fallbackPath, null);
|
|
111
|
+
return null;
|
|
112
|
+
}
|