@zwbigi/ink-xy 0.1.2 → 0.1.4

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.
Files changed (598) hide show
  1. package/.next/BUILD_ID +1 -1
  2. package/.next/app-path-routes-manifest.json +2 -2
  3. package/.next/build-manifest.json +2 -2
  4. package/.next/server/app/_global-error.html +1 -1
  5. package/.next/server/app/_global-error.rsc +1 -1
  6. package/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  7. package/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  8. package/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  9. package/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  10. package/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  11. package/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  12. package/.next/server/app/_not-found.html +1 -1
  13. package/.next/server/app/_not-found.rsc +1 -1
  14. package/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
  15. package/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  16. package/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
  17. package/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  18. package/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  19. package/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  20. package/.next/server/app/api/inkos/route.js.nft.json +1 -1
  21. package/.next/server/app/api/skills/install/route.js.nft.json +1 -1
  22. package/.next/server/app/api/skills/search/route.js.nft.json +1 -1
  23. package/.next/server/app/index.html +1 -1
  24. package/.next/server/app/index.rsc +1 -1
  25. package/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
  26. package/.next/server/app/index.segments/_full.segment.rsc +1 -1
  27. package/.next/server/app/index.segments/_head.segment.rsc +1 -1
  28. package/.next/server/app/index.segments/_index.segment.rsc +1 -1
  29. package/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  30. package/.next/server/app-paths-manifest.json +2 -2
  31. package/.next/server/chunks/162.js +1 -1
  32. package/.next/server/middleware-build-manifest.js +1 -1
  33. package/.next/server/pages/404.html +1 -1
  34. package/.next/server/pages/500.html +1 -1
  35. package/.next/trace +4 -4
  36. package/.next/trace-build +1 -1
  37. package/bin/pi-web.js +4 -1
  38. package/inkos/.env.example +20 -0
  39. package/inkos/.node-version +1 -0
  40. package/inkos/.nvmrc +1 -0
  41. package/inkos/CHANGELOG.md +787 -0
  42. package/inkos/CONTRIBUTING.md +89 -0
  43. package/inkos/LICENSE +661 -0
  44. package/inkos/README.en.md +483 -0
  45. package/inkos/README.ja.md +461 -0
  46. package/inkos/README.md +272 -0
  47. package/inkos/assets/15qun.jpg +0 -0
  48. package/inkos/assets/41777702961_.pic.jpg +0 -0
  49. package/inkos/assets/inkos-short-demo-cover.png +0 -0
  50. package/inkos/assets/inkos-text.svg +40 -0
  51. package/inkos/assets/logo.svg +47 -0
  52. package/inkos/assets/screenshot-chapters.png +0 -0
  53. package/inkos/assets/screenshot-pipeline.png +0 -0
  54. package/inkos/assets/screenshot-state.png +0 -0
  55. package/inkos/assets/screenshot-terminal.png +0 -0
  56. package/inkos/assets/wechat-group-v8.jpg +0 -0
  57. package/inkos/package.json +42 -0
  58. package/inkos/packages/cli/package.json +74 -0
  59. package/inkos/packages/cli/src/__tests__/analytics.test.ts +154 -0
  60. package/inkos/packages/cli/src/__tests__/cli-integration.test.ts +1031 -0
  61. package/inkos/packages/cli/src/__tests__/daemon.test.ts +93 -0
  62. package/inkos/packages/cli/src/__tests__/doctor.test.ts +36 -0
  63. package/inkos/packages/cli/src/__tests__/interact-command.test.ts +142 -0
  64. package/inkos/packages/cli/src/__tests__/interaction-tools.test.ts +107 -0
  65. package/inkos/packages/cli/src/__tests__/llm-overrides.test.ts +25 -0
  66. package/inkos/packages/cli/src/__tests__/localization.test.ts +121 -0
  67. package/inkos/packages/cli/src/__tests__/progress-text.test.ts +92 -0
  68. package/inkos/packages/cli/src/__tests__/project-bootstrap.test.ts +71 -0
  69. package/inkos/packages/cli/src/__tests__/publish-package.test.ts +272 -0
  70. package/inkos/packages/cli/src/__tests__/revision-command.test.ts +82 -0
  71. package/inkos/packages/cli/src/__tests__/runtime-requirements.test.ts +89 -0
  72. package/inkos/packages/cli/src/__tests__/short-fiction-command.test.ts +48 -0
  73. package/inkos/packages/cli/src/__tests__/studio-runtime.test.ts +142 -0
  74. package/inkos/packages/cli/src/__tests__/studio.test.ts +87 -0
  75. package/inkos/packages/cli/src/__tests__/tui-activity-state.test.ts +20 -0
  76. package/inkos/packages/cli/src/__tests__/tui-agent-session.test.ts +213 -0
  77. package/inkos/packages/cli/src/__tests__/tui-chat-depth.test.ts +27 -0
  78. package/inkos/packages/cli/src/__tests__/tui-chat-draft.test.ts +44 -0
  79. package/inkos/packages/cli/src/__tests__/tui-command.test.ts +86 -0
  80. package/inkos/packages/cli/src/__tests__/tui-composer-caret.test.ts +46 -0
  81. package/inkos/packages/cli/src/__tests__/tui-composer-display.test.ts +40 -0
  82. package/inkos/packages/cli/src/__tests__/tui-dashboard.test.tsx +219 -0
  83. package/inkos/packages/cli/src/__tests__/tui-effects-i18n.test.ts +29 -0
  84. package/inkos/packages/cli/src/__tests__/tui-i18n.test.ts +22 -0
  85. package/inkos/packages/cli/src/__tests__/tui-input-chrome.test.ts +10 -0
  86. package/inkos/packages/cli/src/__tests__/tui-input-history.test.ts +40 -0
  87. package/inkos/packages/cli/src/__tests__/tui-layout.test.ts +55 -0
  88. package/inkos/packages/cli/src/__tests__/tui-local-commands.test.ts +47 -0
  89. package/inkos/packages/cli/src/__tests__/tui-session-store.test.ts +81 -0
  90. package/inkos/packages/cli/src/__tests__/tui-setup-i18n.test.ts +31 -0
  91. package/inkos/packages/cli/src/__tests__/tui-slash-autocomplete.test.ts +33 -0
  92. package/inkos/packages/cli/src/commands/agent.ts +65 -0
  93. package/inkos/packages/cli/src/commands/analytics.ts +77 -0
  94. package/inkos/packages/cli/src/commands/audit.ts +52 -0
  95. package/inkos/packages/cli/src/commands/book.ts +260 -0
  96. package/inkos/packages/cli/src/commands/compose.ts +50 -0
  97. package/inkos/packages/cli/src/commands/config.ts +328 -0
  98. package/inkos/packages/cli/src/commands/consolidate.ts +50 -0
  99. package/inkos/packages/cli/src/commands/daemon.ts +121 -0
  100. package/inkos/packages/cli/src/commands/detect.ts +125 -0
  101. package/inkos/packages/cli/src/commands/doctor.ts +391 -0
  102. package/inkos/packages/cli/src/commands/draft.ts +43 -0
  103. package/inkos/packages/cli/src/commands/eval.ts +217 -0
  104. package/inkos/packages/cli/src/commands/export.ts +45 -0
  105. package/inkos/packages/cli/src/commands/fanfic.ts +183 -0
  106. package/inkos/packages/cli/src/commands/genre.ts +160 -0
  107. package/inkos/packages/cli/src/commands/import.ts +158 -0
  108. package/inkos/packages/cli/src/commands/init.ts +47 -0
  109. package/inkos/packages/cli/src/commands/interact.ts +109 -0
  110. package/inkos/packages/cli/src/commands/plan.ts +54 -0
  111. package/inkos/packages/cli/src/commands/radar.ts +60 -0
  112. package/inkos/packages/cli/src/commands/review.ts +253 -0
  113. package/inkos/packages/cli/src/commands/revise.ts +58 -0
  114. package/inkos/packages/cli/src/commands/short-fiction.ts +294 -0
  115. package/inkos/packages/cli/src/commands/status.ts +138 -0
  116. package/inkos/packages/cli/src/commands/studio.ts +194 -0
  117. package/inkos/packages/cli/src/commands/style.ts +99 -0
  118. package/inkos/packages/cli/src/commands/tui.ts +18 -0
  119. package/inkos/packages/cli/src/commands/update.ts +45 -0
  120. package/inkos/packages/cli/src/commands/write.ts +324 -0
  121. package/inkos/packages/cli/src/index.ts +5 -0
  122. package/inkos/packages/cli/src/interaction/tools.ts +49 -0
  123. package/inkos/packages/cli/src/localization.ts +215 -0
  124. package/inkos/packages/cli/src/program.ts +106 -0
  125. package/inkos/packages/cli/src/progress-text.ts +85 -0
  126. package/inkos/packages/cli/src/project-bootstrap.ts +175 -0
  127. package/inkos/packages/cli/src/runtime-requirements.ts +135 -0
  128. package/inkos/packages/cli/src/tui/__tests__/markdown.test.ts +64 -0
  129. package/inkos/packages/cli/src/tui/activity-state.ts +41 -0
  130. package/inkos/packages/cli/src/tui/agent-input.ts +264 -0
  131. package/inkos/packages/cli/src/tui/ansi.ts +72 -0
  132. package/inkos/packages/cli/src/tui/app.ts +130 -0
  133. package/inkos/packages/cli/src/tui/chat-depth.ts +22 -0
  134. package/inkos/packages/cli/src/tui/chat-draft.ts +42 -0
  135. package/inkos/packages/cli/src/tui/composer-caret.ts +22 -0
  136. package/inkos/packages/cli/src/tui/composer-display.ts +26 -0
  137. package/inkos/packages/cli/src/tui/dashboard-model.ts +164 -0
  138. package/inkos/packages/cli/src/tui/dashboard.tsx +544 -0
  139. package/inkos/packages/cli/src/tui/effects.ts +542 -0
  140. package/inkos/packages/cli/src/tui/i18n.ts +278 -0
  141. package/inkos/packages/cli/src/tui/input-history.ts +69 -0
  142. package/inkos/packages/cli/src/tui/local-commands.ts +55 -0
  143. package/inkos/packages/cli/src/tui/markdown.ts +64 -0
  144. package/inkos/packages/cli/src/tui/session-store.ts +6 -0
  145. package/inkos/packages/cli/src/tui/setup.ts +397 -0
  146. package/inkos/packages/cli/src/tui/slash-autocomplete.ts +62 -0
  147. package/inkos/packages/cli/src/tui/theme.ts +17 -0
  148. package/inkos/packages/cli/src/utils.ts +222 -0
  149. package/inkos/packages/cli/tsconfig.json +9 -0
  150. package/inkos/packages/core/genres/cozy.md +43 -0
  151. package/inkos/packages/core/genres/cultivation.md +42 -0
  152. package/inkos/packages/core/genres/dungeon-core.md +40 -0
  153. package/inkos/packages/core/genres/horror.md +51 -0
  154. package/inkos/packages/core/genres/isekai.md +43 -0
  155. package/inkos/packages/core/genres/litrpg.md +43 -0
  156. package/inkos/packages/core/genres/other.md +24 -0
  157. package/inkos/packages/core/genres/progression.md +41 -0
  158. package/inkos/packages/core/genres/romantasy.md +45 -0
  159. package/inkos/packages/core/genres/sci-fi.md +42 -0
  160. package/inkos/packages/core/genres/system-apocalypse.md +40 -0
  161. package/inkos/packages/core/genres/tower-climber.md +41 -0
  162. package/inkos/packages/core/genres/urban.md +53 -0
  163. package/inkos/packages/core/genres/xianxia.md +46 -0
  164. package/inkos/packages/core/genres/xuanhuan.md +64 -0
  165. package/inkos/packages/core/package.json +61 -0
  166. package/inkos/packages/core/src/__tests__/agent-max-tokens-policy.test.ts +29 -0
  167. package/inkos/packages/core/src/__tests__/agent-session.test.ts +866 -0
  168. package/inkos/packages/core/src/__tests__/agent-system-prompt.test.ts +167 -0
  169. package/inkos/packages/core/src/__tests__/agent-tools-params.test.ts +197 -0
  170. package/inkos/packages/core/src/__tests__/agent-tools.test.ts +421 -0
  171. package/inkos/packages/core/src/__tests__/ai-tells.test.ts +90 -0
  172. package/inkos/packages/core/src/__tests__/architect-phase5-consolidated.test.ts +445 -0
  173. package/inkos/packages/core/src/__tests__/architect-phase5.test.ts +455 -0
  174. package/inkos/packages/core/src/__tests__/architect-phase7.test.ts +210 -0
  175. package/inkos/packages/core/src/__tests__/architect.test.ts +859 -0
  176. package/inkos/packages/core/src/__tests__/audit-parse.test.ts +78 -0
  177. package/inkos/packages/core/src/__tests__/book-id.test.ts +26 -0
  178. package/inkos/packages/core/src/__tests__/book-session-store.test.ts +447 -0
  179. package/inkos/packages/core/src/__tests__/book-session.test.ts +113 -0
  180. package/inkos/packages/core/src/__tests__/chapter-analyzer.test.ts +574 -0
  181. package/inkos/packages/core/src/__tests__/chapter-memo-parser.test.ts +247 -0
  182. package/inkos/packages/core/src/__tests__/chapter-persistence.test.ts +198 -0
  183. package/inkos/packages/core/src/__tests__/chapter-review-cycle.test.ts +294 -0
  184. package/inkos/packages/core/src/__tests__/chapter-splitter.test.ts +156 -0
  185. package/inkos/packages/core/src/__tests__/chapter-state-recovery.test.ts +235 -0
  186. package/inkos/packages/core/src/__tests__/chapter-truth-validation.test.ts +253 -0
  187. package/inkos/packages/core/src/__tests__/composer.test.ts +627 -0
  188. package/inkos/packages/core/src/__tests__/config-loader.test.ts +325 -0
  189. package/inkos/packages/core/src/__tests__/config-migration.test.ts +102 -0
  190. package/inkos/packages/core/src/__tests__/consolidator.test.ts +32 -0
  191. package/inkos/packages/core/src/__tests__/context-filter.test.ts +60 -0
  192. package/inkos/packages/core/src/__tests__/context-transform.test.ts +108 -0
  193. package/inkos/packages/core/src/__tests__/continuity.test.ts +391 -0
  194. package/inkos/packages/core/src/__tests__/detection-insights.test.ts +59 -0
  195. package/inkos/packages/core/src/__tests__/detector.test.ts +86 -0
  196. package/inkos/packages/core/src/__tests__/draft-directive-parser.test.ts +386 -0
  197. package/inkos/packages/core/src/__tests__/edit-controller.test.ts +190 -0
  198. package/inkos/packages/core/src/__tests__/effective-llm-config.test.ts +486 -0
  199. package/inkos/packages/core/src/__tests__/fanfic-dimensions.test.ts +58 -0
  200. package/inkos/packages/core/src/__tests__/fanfic-models.test.ts +69 -0
  201. package/inkos/packages/core/src/__tests__/governed-working-set.test.ts +155 -0
  202. package/inkos/packages/core/src/__tests__/hook-arbiter.test.ts +124 -0
  203. package/inkos/packages/core/src/__tests__/hook-governance.test.ts +228 -0
  204. package/inkos/packages/core/src/__tests__/hook-health.test.ts +166 -0
  205. package/inkos/packages/core/src/__tests__/hook-ledger-validator.test.ts +236 -0
  206. package/inkos/packages/core/src/__tests__/hook-promotion.test.ts +192 -0
  207. package/inkos/packages/core/src/__tests__/hook-stale-detection.test.ts +136 -0
  208. package/inkos/packages/core/src/__tests__/index-notify-lazy.test.ts +20 -0
  209. package/inkos/packages/core/src/__tests__/interaction-chat-tokens.test.ts +170 -0
  210. package/inkos/packages/core/src/__tests__/interaction-models.test.ts +155 -0
  211. package/inkos/packages/core/src/__tests__/interaction-nl-router.test.ts +223 -0
  212. package/inkos/packages/core/src/__tests__/interaction-runtime.test.ts +633 -0
  213. package/inkos/packages/core/src/__tests__/interaction-tools.test.ts +343 -0
  214. package/inkos/packages/core/src/__tests__/length-metrics.test.ts +82 -0
  215. package/inkos/packages/core/src/__tests__/length-normalizer.test.ts +331 -0
  216. package/inkos/packages/core/src/__tests__/list-models.test.ts +109 -0
  217. package/inkos/packages/core/src/__tests__/llm-env.test.ts +31 -0
  218. package/inkos/packages/core/src/__tests__/logger.test.ts +175 -0
  219. package/inkos/packages/core/src/__tests__/long-span-fatigue.test.ts +160 -0
  220. package/inkos/packages/core/src/__tests__/memory-retrieval.test.ts +1303 -0
  221. package/inkos/packages/core/src/__tests__/models.test.ts +918 -0
  222. package/inkos/packages/core/src/__tests__/outline-paths.test.ts +97 -0
  223. package/inkos/packages/core/src/__tests__/path-safety.test.ts +22 -0
  224. package/inkos/packages/core/src/__tests__/persisted-governed-plan.test.ts +134 -0
  225. package/inkos/packages/core/src/__tests__/phase5-cleanup.test.ts +393 -0
  226. package/inkos/packages/core/src/__tests__/phase5-hotfix.test.ts +288 -0
  227. package/inkos/packages/core/src/__tests__/phase7-hotfix.test.ts +614 -0
  228. package/inkos/packages/core/src/__tests__/pipeline-agent.test.ts +354 -0
  229. package/inkos/packages/core/src/__tests__/pipeline-runner-memory-sync.test.ts +317 -0
  230. package/inkos/packages/core/src/__tests__/pipeline-runner.test.ts +5200 -0
  231. package/inkos/packages/core/src/__tests__/planner-context.test.ts +137 -0
  232. package/inkos/packages/core/src/__tests__/planner-prompts-ratio.test.ts +11 -0
  233. package/inkos/packages/core/src/__tests__/planner-prompts.test.ts +171 -0
  234. package/inkos/packages/core/src/__tests__/planner.test.ts +362 -0
  235. package/inkos/packages/core/src/__tests__/planning-materials.test.ts +90 -0
  236. package/inkos/packages/core/src/__tests__/polisher.test.ts +189 -0
  237. package/inkos/packages/core/src/__tests__/post-write-validator.test.ts +291 -0
  238. package/inkos/packages/core/src/__tests__/probe.test.ts +77 -0
  239. package/inkos/packages/core/src/__tests__/project-interaction.test.ts +241 -0
  240. package/inkos/packages/core/src/__tests__/provider.test.ts +953 -0
  241. package/inkos/packages/core/src/__tests__/providers-group.test.ts +34 -0
  242. package/inkos/packages/core/src/__tests__/providers-lookup.test.ts +81 -0
  243. package/inkos/packages/core/src/__tests__/providers-schema.test.ts +158 -0
  244. package/inkos/packages/core/src/__tests__/proxy-fetch.test.ts +75 -0
  245. package/inkos/packages/core/src/__tests__/revise-foundation.test.ts +514 -0
  246. package/inkos/packages/core/src/__tests__/reviser.test.ts +859 -0
  247. package/inkos/packages/core/src/__tests__/runtime-state-store.test.ts +388 -0
  248. package/inkos/packages/core/src/__tests__/scheduler.test.ts +123 -0
  249. package/inkos/packages/core/src/__tests__/secrets-migration.test.ts +71 -0
  250. package/inkos/packages/core/src/__tests__/secrets.test.ts +95 -0
  251. package/inkos/packages/core/src/__tests__/sensitive-words.test.ts +88 -0
  252. package/inkos/packages/core/src/__tests__/service-presets-regression.test.ts +73 -0
  253. package/inkos/packages/core/src/__tests__/service-resolver-regression.test.ts +75 -0
  254. package/inkos/packages/core/src/__tests__/service-resolver.test.ts +228 -0
  255. package/inkos/packages/core/src/__tests__/session-transcript-restore.test.ts +1311 -0
  256. package/inkos/packages/core/src/__tests__/session-transcript.test.ts +195 -0
  257. package/inkos/packages/core/src/__tests__/settler-delta-parser.test.ts +133 -0
  258. package/inkos/packages/core/src/__tests__/short-fiction-public.test.ts +241 -0
  259. package/inkos/packages/core/src/__tests__/spot-fix-patches.test.ts +104 -0
  260. package/inkos/packages/core/src/__tests__/state-manager.test.ts +1298 -0
  261. package/inkos/packages/core/src/__tests__/state-projections.test.ts +130 -0
  262. package/inkos/packages/core/src/__tests__/state-reducer.test.ts +372 -0
  263. package/inkos/packages/core/src/__tests__/state-validator-agent.test.ts +165 -0
  264. package/inkos/packages/core/src/__tests__/state-validator.test.ts +122 -0
  265. package/inkos/packages/core/src/__tests__/style-analyzer.test.ts +61 -0
  266. package/inkos/packages/core/src/__tests__/temperature-constraints.test.ts +57 -0
  267. package/inkos/packages/core/src/__tests__/v13-hotfix-round4.test.ts +343 -0
  268. package/inkos/packages/core/src/__tests__/verify-service.test.ts +77 -0
  269. package/inkos/packages/core/src/__tests__/webhook.test.ts +91 -0
  270. package/inkos/packages/core/src/__tests__/writer-parser.test.ts +348 -0
  271. package/inkos/packages/core/src/__tests__/writer-prompts.test.ts +269 -0
  272. package/inkos/packages/core/src/__tests__/writer.test.ts +1360 -0
  273. package/inkos/packages/core/src/agent/agent-session.ts +737 -0
  274. package/inkos/packages/core/src/agent/agent-system-prompt.ts +199 -0
  275. package/inkos/packages/core/src/agent/agent-tools.ts +835 -0
  276. package/inkos/packages/core/src/agent/context-transform.ts +85 -0
  277. package/inkos/packages/core/src/agent/index.ts +14 -0
  278. package/inkos/packages/core/src/agents/ai-tells.ts +161 -0
  279. package/inkos/packages/core/src/agents/architect.ts +1291 -0
  280. package/inkos/packages/core/src/agents/base.ts +100 -0
  281. package/inkos/packages/core/src/agents/chapter-analyzer.ts +634 -0
  282. package/inkos/packages/core/src/agents/composer.ts +469 -0
  283. package/inkos/packages/core/src/agents/consolidator.ts +218 -0
  284. package/inkos/packages/core/src/agents/continuity.ts +824 -0
  285. package/inkos/packages/core/src/agents/detection-insights.ts +72 -0
  286. package/inkos/packages/core/src/agents/detector.ts +224 -0
  287. package/inkos/packages/core/src/agents/en-prompt-sections.ts +129 -0
  288. package/inkos/packages/core/src/agents/fanfic-canon-importer.ts +146 -0
  289. package/inkos/packages/core/src/agents/fanfic-dimensions.ts +87 -0
  290. package/inkos/packages/core/src/agents/fanfic-prompt-sections.ts +109 -0
  291. package/inkos/packages/core/src/agents/foundation-reviewer.ts +204 -0
  292. package/inkos/packages/core/src/agents/length-normalizer.ts +218 -0
  293. package/inkos/packages/core/src/agents/observer-prompts.ts +127 -0
  294. package/inkos/packages/core/src/agents/planner-context.ts +297 -0
  295. package/inkos/packages/core/src/agents/planner-prompts.ts +404 -0
  296. package/inkos/packages/core/src/agents/planner.ts +783 -0
  297. package/inkos/packages/core/src/agents/polisher.ts +153 -0
  298. package/inkos/packages/core/src/agents/post-write-validator.ts +873 -0
  299. package/inkos/packages/core/src/agents/radar-source.ts +123 -0
  300. package/inkos/packages/core/src/agents/radar.ts +120 -0
  301. package/inkos/packages/core/src/agents/reviser.ts +701 -0
  302. package/inkos/packages/core/src/agents/rules-reader.ts +155 -0
  303. package/inkos/packages/core/src/agents/sensitive-words.ts +142 -0
  304. package/inkos/packages/core/src/agents/settler-delta-parser.ts +53 -0
  305. package/inkos/packages/core/src/agents/settler-parser.ts +38 -0
  306. package/inkos/packages/core/src/agents/settler-prompts.ts +230 -0
  307. package/inkos/packages/core/src/agents/short-fiction.ts +429 -0
  308. package/inkos/packages/core/src/agents/state-validator.ts +322 -0
  309. package/inkos/packages/core/src/agents/style-analyzer.ts +93 -0
  310. package/inkos/packages/core/src/agents/writer-parser.ts +178 -0
  311. package/inkos/packages/core/src/agents/writer-prompts.ts +899 -0
  312. package/inkos/packages/core/src/agents/writer.ts +1450 -0
  313. package/inkos/packages/core/src/index.ts +392 -0
  314. package/inkos/packages/core/src/interaction/book-session-store.ts +226 -0
  315. package/inkos/packages/core/src/interaction/draft-directive-parser.ts +266 -0
  316. package/inkos/packages/core/src/interaction/edit-controller.ts +270 -0
  317. package/inkos/packages/core/src/interaction/events.ts +41 -0
  318. package/inkos/packages/core/src/interaction/export-artifact.ts +151 -0
  319. package/inkos/packages/core/src/interaction/intents.ts +63 -0
  320. package/inkos/packages/core/src/interaction/modes.ts +13 -0
  321. package/inkos/packages/core/src/interaction/nl-router.ts +258 -0
  322. package/inkos/packages/core/src/interaction/project-control.ts +150 -0
  323. package/inkos/packages/core/src/interaction/project-session-store.ts +81 -0
  324. package/inkos/packages/core/src/interaction/project-tools.ts +704 -0
  325. package/inkos/packages/core/src/interaction/request-router.ts +5 -0
  326. package/inkos/packages/core/src/interaction/runtime.ts +1167 -0
  327. package/inkos/packages/core/src/interaction/session-transcript-legacy.ts +113 -0
  328. package/inkos/packages/core/src/interaction/session-transcript-restore.ts +607 -0
  329. package/inkos/packages/core/src/interaction/session-transcript-schema.ts +76 -0
  330. package/inkos/packages/core/src/interaction/session-transcript.ts +189 -0
  331. package/inkos/packages/core/src/interaction/session.ts +226 -0
  332. package/inkos/packages/core/src/interaction/truth-authority.ts +45 -0
  333. package/inkos/packages/core/src/llm/config-migration.ts +58 -0
  334. package/inkos/packages/core/src/llm/cover-providers.ts +45 -0
  335. package/inkos/packages/core/src/llm/provider.ts +1331 -0
  336. package/inkos/packages/core/src/llm/providers/endpoints/ai360.ts +42 -0
  337. package/inkos/packages/core/src/llm/providers/endpoints/anthropic.ts +82 -0
  338. package/inkos/packages/core/src/llm/providers/endpoints/astronCodingPlan.ts +30 -0
  339. package/inkos/packages/core/src/llm/providers/endpoints/baichuan.ts +28 -0
  340. package/inkos/packages/core/src/llm/providers/endpoints/bailian.ts +65 -0
  341. package/inkos/packages/core/src/llm/providers/endpoints/bailianCodingPlan.ts +30 -0
  342. package/inkos/packages/core/src/llm/providers/endpoints/custom.ts +22 -0
  343. package/inkos/packages/core/src/llm/providers/endpoints/deepseek.ts +35 -0
  344. package/inkos/packages/core/src/llm/providers/endpoints/giteeai.ts +41 -0
  345. package/inkos/packages/core/src/llm/providers/endpoints/githubCopilot.ts +43 -0
  346. package/inkos/packages/core/src/llm/providers/endpoints/glmCodingPlan.ts +28 -0
  347. package/inkos/packages/core/src/llm/providers/endpoints/google.ts +51 -0
  348. package/inkos/packages/core/src/llm/providers/endpoints/hunyuan.ts +42 -0
  349. package/inkos/packages/core/src/llm/providers/endpoints/infiniai.ts +72 -0
  350. package/inkos/packages/core/src/llm/providers/endpoints/internlm.ts +28 -0
  351. package/inkos/packages/core/src/llm/providers/endpoints/kimiCode.ts +23 -0
  352. package/inkos/packages/core/src/llm/providers/endpoints/kimiCodingPlan.ts +24 -0
  353. package/inkos/packages/core/src/llm/providers/endpoints/kkaiapi.ts +56 -0
  354. package/inkos/packages/core/src/llm/providers/endpoints/longcat.ts +25 -0
  355. package/inkos/packages/core/src/llm/providers/endpoints/minimax.ts +39 -0
  356. package/inkos/packages/core/src/llm/providers/endpoints/minimaxCodingPlan.ts +28 -0
  357. package/inkos/packages/core/src/llm/providers/endpoints/mistral.ts +40 -0
  358. package/inkos/packages/core/src/llm/providers/endpoints/modelscope.ts +30 -0
  359. package/inkos/packages/core/src/llm/providers/endpoints/moonshot.ts +39 -0
  360. package/inkos/packages/core/src/llm/providers/endpoints/newapi.ts +21 -0
  361. package/inkos/packages/core/src/llm/providers/endpoints/ollama.ts +73 -0
  362. package/inkos/packages/core/src/llm/providers/endpoints/openai.ts +77 -0
  363. package/inkos/packages/core/src/llm/providers/endpoints/opencodeCodingPlan.ts +30 -0
  364. package/inkos/packages/core/src/llm/providers/endpoints/openrouter.ts +87 -0
  365. package/inkos/packages/core/src/llm/providers/endpoints/ppio.ts +86 -0
  366. package/inkos/packages/core/src/llm/providers/endpoints/qiniu.ts +32 -0
  367. package/inkos/packages/core/src/llm/providers/endpoints/sensenova.ts +45 -0
  368. package/inkos/packages/core/src/llm/providers/endpoints/siliconcloud.ts +126 -0
  369. package/inkos/packages/core/src/llm/providers/endpoints/spark.ts +33 -0
  370. package/inkos/packages/core/src/llm/providers/endpoints/stepfun.ts +35 -0
  371. package/inkos/packages/core/src/llm/providers/endpoints/tencentcloud.ts +25 -0
  372. package/inkos/packages/core/src/llm/providers/endpoints/volcengine.ts +52 -0
  373. package/inkos/packages/core/src/llm/providers/endpoints/volcengineCodingPlan.ts +42 -0
  374. package/inkos/packages/core/src/llm/providers/endpoints/wenxin.ts +106 -0
  375. package/inkos/packages/core/src/llm/providers/endpoints/xai.ts +34 -0
  376. package/inkos/packages/core/src/llm/providers/endpoints/xiaomimimo.ts +26 -0
  377. package/inkos/packages/core/src/llm/providers/endpoints/zeroone.ts +34 -0
  378. package/inkos/packages/core/src/llm/providers/endpoints/zhipu.ts +61 -0
  379. package/inkos/packages/core/src/llm/providers/index.ts +71 -0
  380. package/inkos/packages/core/src/llm/providers/lookup.ts +70 -0
  381. package/inkos/packages/core/src/llm/providers/probe.ts +35 -0
  382. package/inkos/packages/core/src/llm/providers/types.ts +89 -0
  383. package/inkos/packages/core/src/llm/providers/verify.ts +104 -0
  384. package/inkos/packages/core/src/llm/secrets.ts +77 -0
  385. package/inkos/packages/core/src/llm/service-presets.ts +215 -0
  386. package/inkos/packages/core/src/llm/service-resolver.ts +91 -0
  387. package/inkos/packages/core/src/models/book-rules.ts +126 -0
  388. package/inkos/packages/core/src/models/book.ts +70 -0
  389. package/inkos/packages/core/src/models/chapter.ts +42 -0
  390. package/inkos/packages/core/src/models/detection.ts +25 -0
  391. package/inkos/packages/core/src/models/genre-profile.ts +36 -0
  392. package/inkos/packages/core/src/models/input-governance.ts +99 -0
  393. package/inkos/packages/core/src/models/length-governance.ts +46 -0
  394. package/inkos/packages/core/src/models/project.ts +161 -0
  395. package/inkos/packages/core/src/models/runtime-state.ts +144 -0
  396. package/inkos/packages/core/src/models/state.ts +52 -0
  397. package/inkos/packages/core/src/models/style-profile.ts +15 -0
  398. package/inkos/packages/core/src/notify/dispatcher.ts +96 -0
  399. package/inkos/packages/core/src/notify/feishu.ts +34 -0
  400. package/inkos/packages/core/src/notify/telegram.ts +25 -0
  401. package/inkos/packages/core/src/notify/webhook.ts +58 -0
  402. package/inkos/packages/core/src/notify/wechat-work.ts +22 -0
  403. package/inkos/packages/core/src/pipeline/agent.ts +691 -0
  404. package/inkos/packages/core/src/pipeline/chapter-persistence.ts +79 -0
  405. package/inkos/packages/core/src/pipeline/chapter-review-cycle.ts +324 -0
  406. package/inkos/packages/core/src/pipeline/chapter-state-recovery.ts +236 -0
  407. package/inkos/packages/core/src/pipeline/chapter-truth-validation.ts +145 -0
  408. package/inkos/packages/core/src/pipeline/detection-runner.ts +164 -0
  409. package/inkos/packages/core/src/pipeline/persisted-governed-plan.ts +216 -0
  410. package/inkos/packages/core/src/pipeline/runner.ts +3438 -0
  411. package/inkos/packages/core/src/pipeline/scheduler.ts +411 -0
  412. package/inkos/packages/core/src/pipeline/short-fiction-runner.ts +801 -0
  413. package/inkos/packages/core/src/prompts/index.ts +1 -0
  414. package/inkos/packages/core/src/prompts/short-fiction.ts +273 -0
  415. package/inkos/packages/core/src/state/manager.ts +560 -0
  416. package/inkos/packages/core/src/state/memory-db.ts +359 -0
  417. package/inkos/packages/core/src/state/runtime-state-store.ts +164 -0
  418. package/inkos/packages/core/src/state/state-bootstrap.ts +657 -0
  419. package/inkos/packages/core/src/state/state-projections.ts +255 -0
  420. package/inkos/packages/core/src/state/state-reducer.ts +260 -0
  421. package/inkos/packages/core/src/state/state-validator.ts +117 -0
  422. package/inkos/packages/core/src/utils/analytics.ts +92 -0
  423. package/inkos/packages/core/src/utils/book-id.ts +31 -0
  424. package/inkos/packages/core/src/utils/cadence-policy.ts +46 -0
  425. package/inkos/packages/core/src/utils/chapter-cadence.ts +211 -0
  426. package/inkos/packages/core/src/utils/chapter-memo-parser.ts +157 -0
  427. package/inkos/packages/core/src/utils/chapter-splitter.ts +80 -0
  428. package/inkos/packages/core/src/utils/config-loader.ts +29 -0
  429. package/inkos/packages/core/src/utils/context-assembly.ts +98 -0
  430. package/inkos/packages/core/src/utils/context-filter.ts +190 -0
  431. package/inkos/packages/core/src/utils/effective-llm-config.ts +529 -0
  432. package/inkos/packages/core/src/utils/governed-context.ts +101 -0
  433. package/inkos/packages/core/src/utils/governed-working-set.ts +395 -0
  434. package/inkos/packages/core/src/utils/hook-arbiter.ts +332 -0
  435. package/inkos/packages/core/src/utils/hook-governance.ts +199 -0
  436. package/inkos/packages/core/src/utils/hook-health.ts +189 -0
  437. package/inkos/packages/core/src/utils/hook-ledger-validator.ts +277 -0
  438. package/inkos/packages/core/src/utils/hook-lifecycle.ts +224 -0
  439. package/inkos/packages/core/src/utils/hook-policy.ts +115 -0
  440. package/inkos/packages/core/src/utils/hook-promotion.ts +313 -0
  441. package/inkos/packages/core/src/utils/hook-stale-detection.ts +168 -0
  442. package/inkos/packages/core/src/utils/length-metrics.ts +123 -0
  443. package/inkos/packages/core/src/utils/llm-endpoint-auth.ts +40 -0
  444. package/inkos/packages/core/src/utils/llm-env.ts +74 -0
  445. package/inkos/packages/core/src/utils/logger.ts +123 -0
  446. package/inkos/packages/core/src/utils/long-span-fatigue.ts +545 -0
  447. package/inkos/packages/core/src/utils/memory-retrieval.ts +527 -0
  448. package/inkos/packages/core/src/utils/narrative-control.ts +177 -0
  449. package/inkos/packages/core/src/utils/outline-paths.ts +275 -0
  450. package/inkos/packages/core/src/utils/path-safety.ts +11 -0
  451. package/inkos/packages/core/src/utils/planning-materials.ts +185 -0
  452. package/inkos/packages/core/src/utils/pov-filter.ts +149 -0
  453. package/inkos/packages/core/src/utils/proxy-fetch.ts +44 -0
  454. package/inkos/packages/core/src/utils/runtime-writer.ts +41 -0
  455. package/inkos/packages/core/src/utils/spot-fix-patches.ts +189 -0
  456. package/inkos/packages/core/src/utils/story-markdown.ts +346 -0
  457. package/inkos/packages/core/src/utils/web-search.ts +82 -0
  458. package/inkos/packages/core/src/utils/writing-methodology.ts +164 -0
  459. package/inkos/packages/core/tsconfig.json +8 -0
  460. package/inkos/packages/core/vitest.config.ts +7 -0
  461. package/inkos/packages/studio/components.json +25 -0
  462. package/inkos/packages/studio/index.html +13 -0
  463. package/inkos/packages/studio/package.json +72 -0
  464. package/inkos/packages/studio/postcss.config.js +3 -0
  465. package/inkos/packages/studio/src/App.test.ts +25 -0
  466. package/inkos/packages/studio/src/App.tsx +280 -0
  467. package/inkos/packages/studio/src/api/__tests__/normalize-base-url.test.ts +40 -0
  468. package/inkos/packages/studio/src/api/book-create.test.ts +104 -0
  469. package/inkos/packages/studio/src/api/book-create.ts +94 -0
  470. package/inkos/packages/studio/src/api/errors.ts +17 -0
  471. package/inkos/packages/studio/src/api/index.ts +30 -0
  472. package/inkos/packages/studio/src/api/lib/run-store.ts +177 -0
  473. package/inkos/packages/studio/src/api/lib/sse.ts +50 -0
  474. package/inkos/packages/studio/src/api/phase5-hotfix.test.ts +335 -0
  475. package/inkos/packages/studio/src/api/safety.ts +6 -0
  476. package/inkos/packages/studio/src/api/server.test.ts +3162 -0
  477. package/inkos/packages/studio/src/api/server.ts +3666 -0
  478. package/inkos/packages/studio/src/api/v13-hotfix-round4.test.ts +226 -0
  479. package/inkos/packages/studio/src/app-state.test.ts +8 -0
  480. package/inkos/packages/studio/src/app-state.ts +1 -0
  481. package/inkos/packages/studio/src/components/ConfirmDialog.tsx +95 -0
  482. package/inkos/packages/studio/src/components/ServiceConfigSourceCard.tsx +139 -0
  483. package/inkos/packages/studio/src/components/ServiceQuickLinks.tsx +65 -0
  484. package/inkos/packages/studio/src/components/Sidebar.tsx +652 -0
  485. package/inkos/packages/studio/src/components/ai-elements/code-block.tsx +562 -0
  486. package/inkos/packages/studio/src/components/ai-elements/confirmation.tsx +174 -0
  487. package/inkos/packages/studio/src/components/ai-elements/message.tsx +360 -0
  488. package/inkos/packages/studio/src/components/ai-elements/prompt-input.tsx +1457 -0
  489. package/inkos/packages/studio/src/components/ai-elements/reasoning.tsx +226 -0
  490. package/inkos/packages/studio/src/components/ai-elements/shimmer.tsx +77 -0
  491. package/inkos/packages/studio/src/components/ai-elements/tool.tsx +173 -0
  492. package/inkos/packages/studio/src/components/chat/BookSidebar.tsx +291 -0
  493. package/inkos/packages/studio/src/components/chat/ChatMessage.tsx +39 -0
  494. package/inkos/packages/studio/src/components/chat/QuickActions.tsx +73 -0
  495. package/inkos/packages/studio/src/components/chat/ToolExecutionSteps.tsx +320 -0
  496. package/inkos/packages/studio/src/components/chat/__tests__/ToolExecutionSteps.test.ts +114 -0
  497. package/inkos/packages/studio/src/components/chat-utils.ts +56 -0
  498. package/inkos/packages/studio/src/components/chatbar-state.test.ts +69 -0
  499. package/inkos/packages/studio/src/components/sidebar/ChaptersSection.tsx +66 -0
  500. package/inkos/packages/studio/src/components/sidebar/CharacterSection.tsx +129 -0
  501. package/inkos/packages/studio/src/components/sidebar/FoundationSection.tsx +61 -0
  502. package/inkos/packages/studio/src/components/sidebar/ProgressSection.tsx +124 -0
  503. package/inkos/packages/studio/src/components/sidebar/SidebarCard.tsx +30 -0
  504. package/inkos/packages/studio/src/components/sidebar/SummarySection.tsx +89 -0
  505. package/inkos/packages/studio/src/components/ui/alert.tsx +76 -0
  506. package/inkos/packages/studio/src/components/ui/badge.tsx +52 -0
  507. package/inkos/packages/studio/src/components/ui/button-group.tsx +87 -0
  508. package/inkos/packages/studio/src/components/ui/button.tsx +58 -0
  509. package/inkos/packages/studio/src/components/ui/collapsible.tsx +19 -0
  510. package/inkos/packages/studio/src/components/ui/command.tsx +194 -0
  511. package/inkos/packages/studio/src/components/ui/dialog.tsx +158 -0
  512. package/inkos/packages/studio/src/components/ui/dropdown-menu.tsx +266 -0
  513. package/inkos/packages/studio/src/components/ui/hover-card.tsx +51 -0
  514. package/inkos/packages/studio/src/components/ui/input-group.tsx +158 -0
  515. package/inkos/packages/studio/src/components/ui/input.tsx +20 -0
  516. package/inkos/packages/studio/src/components/ui/select.tsx +199 -0
  517. package/inkos/packages/studio/src/components/ui/separator.tsx +23 -0
  518. package/inkos/packages/studio/src/components/ui/spinner.tsx +10 -0
  519. package/inkos/packages/studio/src/components/ui/textarea.tsx +18 -0
  520. package/inkos/packages/studio/src/components/ui/tooltip.tsx +66 -0
  521. package/inkos/packages/studio/src/constants/service-groups.ts +29 -0
  522. package/inkos/packages/studio/src/hooks/use-api.test.ts +93 -0
  523. package/inkos/packages/studio/src/hooks/use-api.ts +189 -0
  524. package/inkos/packages/studio/src/hooks/use-book-activity.test.ts +129 -0
  525. package/inkos/packages/studio/src/hooks/use-book-activity.ts +180 -0
  526. package/inkos/packages/studio/src/hooks/use-colors.ts +27 -0
  527. package/inkos/packages/studio/src/hooks/use-hash-route.test.ts +101 -0
  528. package/inkos/packages/studio/src/hooks/use-hash-route.ts +89 -0
  529. package/inkos/packages/studio/src/hooks/use-i18n.ts +289 -0
  530. package/inkos/packages/studio/src/hooks/use-session-events.ts +64 -0
  531. package/inkos/packages/studio/src/hooks/use-sse.test.ts +52 -0
  532. package/inkos/packages/studio/src/hooks/use-sse.ts +92 -0
  533. package/inkos/packages/studio/src/hooks/use-theme.test.ts +31 -0
  534. package/inkos/packages/studio/src/hooks/use-theme.ts +75 -0
  535. package/inkos/packages/studio/src/index.css +323 -0
  536. package/inkos/packages/studio/src/lib/error-copy.test.ts +34 -0
  537. package/inkos/packages/studio/src/lib/error-copy.ts +37 -0
  538. package/inkos/packages/studio/src/lib/utils.ts +6 -0
  539. package/inkos/packages/studio/src/main.tsx +10 -0
  540. package/inkos/packages/studio/src/pages/Analytics.tsx +80 -0
  541. package/inkos/packages/studio/src/pages/BookCreate.tsx +895 -0
  542. package/inkos/packages/studio/src/pages/BookDetail.tsx +652 -0
  543. package/inkos/packages/studio/src/pages/ChapterReader.tsx +266 -0
  544. package/inkos/packages/studio/src/pages/ChatPage.tsx +521 -0
  545. package/inkos/packages/studio/src/pages/DaemonControl.tsx +116 -0
  546. package/inkos/packages/studio/src/pages/Dashboard.tsx +379 -0
  547. package/inkos/packages/studio/src/pages/DoctorView.tsx +82 -0
  548. package/inkos/packages/studio/src/pages/GenreManager.tsx +464 -0
  549. package/inkos/packages/studio/src/pages/ImportManager.tsx +216 -0
  550. package/inkos/packages/studio/src/pages/LanguageSelector.tsx +74 -0
  551. package/inkos/packages/studio/src/pages/LogViewer.tsx +82 -0
  552. package/inkos/packages/studio/src/pages/RadarView.tsx +157 -0
  553. package/inkos/packages/studio/src/pages/ServiceDetailPage.tsx +393 -0
  554. package/inkos/packages/studio/src/pages/ServiceListPage.tsx +463 -0
  555. package/inkos/packages/studio/src/pages/StyleManager.tsx +225 -0
  556. package/inkos/packages/studio/src/pages/TruthFiles.tsx +194 -0
  557. package/inkos/packages/studio/src/pages/chat-page-state.test.ts +206 -0
  558. package/inkos/packages/studio/src/pages/chat-page-state.ts +112 -0
  559. package/inkos/packages/studio/src/pages/page-state.test.ts +258 -0
  560. package/inkos/packages/studio/src/pages/service-detail-state.test.ts +294 -0
  561. package/inkos/packages/studio/src/pages/service-detail-state.ts +234 -0
  562. package/inkos/packages/studio/src/pages/style-manager-state.test.ts +22 -0
  563. package/inkos/packages/studio/src/pages/truth-files-state.test.ts +61 -0
  564. package/inkos/packages/studio/src/shared/contracts.ts +143 -0
  565. package/inkos/packages/studio/src/store/chat/__tests__/message-parts.test.ts +172 -0
  566. package/inkos/packages/studio/src/store/chat/index.ts +3 -0
  567. package/inkos/packages/studio/src/store/chat/initialState.ts +8 -0
  568. package/inkos/packages/studio/src/store/chat/message-policy.test.ts +16 -0
  569. package/inkos/packages/studio/src/store/chat/message-policy.ts +5 -0
  570. package/inkos/packages/studio/src/store/chat/parts-builder.ts +187 -0
  571. package/inkos/packages/studio/src/store/chat/selectors.ts +13 -0
  572. package/inkos/packages/studio/src/store/chat/slices/create/action.ts +10 -0
  573. package/inkos/packages/studio/src/store/chat/slices/create/initialState.ts +9 -0
  574. package/inkos/packages/studio/src/store/chat/slices/message/action.ts +417 -0
  575. package/inkos/packages/studio/src/store/chat/slices/message/initialState.ts +10 -0
  576. package/inkos/packages/studio/src/store/chat/slices/message/runtime.test.ts +21 -0
  577. package/inkos/packages/studio/src/store/chat/slices/message/runtime.ts +233 -0
  578. package/inkos/packages/studio/src/store/chat/slices/message/stream-events.ts +272 -0
  579. package/inkos/packages/studio/src/store/chat/store.ts +11 -0
  580. package/inkos/packages/studio/src/store/chat/types.ts +169 -0
  581. package/inkos/packages/studio/src/store/service/index.ts +2 -0
  582. package/inkos/packages/studio/src/store/service/store.ts +123 -0
  583. package/inkos/packages/studio/src/store/service/types.ts +50 -0
  584. package/inkos/packages/studio/tsconfig.json +24 -0
  585. package/inkos/packages/studio/tsconfig.server.json +11 -0
  586. package/inkos/packages/studio/vite.config.ts +34 -0
  587. package/inkos/packages/studio/vitest.config.ts +14 -0
  588. package/inkos/pnpm-lock.yaml +9569 -0
  589. package/inkos/pnpm-workspace.yaml +2 -0
  590. package/inkos/scripts/prepare-package-for-publish.mjs +135 -0
  591. package/inkos/scripts/restore-package-json.mjs +31 -0
  592. package/inkos/scripts/set-package-versions.mjs +74 -0
  593. package/inkos/scripts/verify-no-workspace-protocol.mjs +140 -0
  594. package/inkos/skills/SKILL.md +654 -0
  595. package/inkos/tsconfig.json +19 -0
  596. package/package.json +4 -3
  597. /package/.next/static/{F2hMZMf1IyCVAWpkbtRz7 → -3vIrBZXdQ0rp7Wa3Kz40}/_buildManifest.js +0 -0
  598. /package/.next/static/{F2hMZMf1IyCVAWpkbtRz7 → -3vIrBZXdQ0rp7Wa3Kz40}/_ssgManifest.js +0 -0
@@ -0,0 +1,701 @@
1
+ import { BaseAgent } from "./base.js";
2
+ import type { GenreProfile } from "../models/genre-profile.js";
3
+ import type { BookRules } from "../models/book-rules.js";
4
+ import type { LengthSpec } from "../models/length-governance.js";
5
+ import type { AuditIssue } from "./continuity.js";
6
+ import type { ChapterIntent, ChapterMemo, ContextPackage, RuleStack } from "../models/input-governance.js";
7
+ import { readGenreProfile, readBookLanguage, readBookRules } from "./rules-reader.js";
8
+ import { countChapterLength } from "../utils/length-metrics.js";
9
+ import { buildGovernedMemoryEvidenceBlocks } from "../utils/governed-context.js";
10
+ import { filterSummaries } from "../utils/context-filter.js";
11
+ import {
12
+ buildGovernedCharacterMatrixWorkingSet,
13
+ buildGovernedHookWorkingSet,
14
+ mergeTableMarkdownByKey,
15
+ } from "../utils/governed-working-set.js";
16
+ import { applySpotFixPatches, parseSpotFixPatches } from "../utils/spot-fix-patches.js";
17
+ import {
18
+ buildNarrativeIntentBrief,
19
+ renderMemoAsNarrativeBlock,
20
+ renderNarrativeSelectedContext,
21
+ sanitizeNarrativeEvidenceBlock,
22
+ } from "../utils/narrative-control.js";
23
+ import { readFile } from "node:fs/promises";
24
+ import { join } from "node:path";
25
+ import {
26
+ readStoryFrame,
27
+ readVolumeMap,
28
+ readCharacterContext,
29
+ readCurrentStateWithFallback,
30
+ } from "../utils/outline-paths.js";
31
+
32
+ export type ReviseMode = "auto" | "polish" | "rewrite" | "rework" | "anti-detect" | "spot-fix";
33
+
34
+ export const DEFAULT_REVISE_MODE: ReviseMode = "auto";
35
+
36
+ export interface ReviseOutput {
37
+ readonly revisedContent: string;
38
+ readonly wordCount: number;
39
+ readonly fixedIssues: ReadonlyArray<string>;
40
+ readonly updatedState: string;
41
+ readonly updatedLedger: string;
42
+ readonly updatedHooks: string;
43
+ readonly tokenUsage?: {
44
+ readonly promptTokens: number;
45
+ readonly completionTokens: number;
46
+ readonly totalTokens: number;
47
+ };
48
+ }
49
+
50
+ type AutoOutputMode = "patch-only" | "rewrite-only" | "allow-full";
51
+
52
+ function buildTieredIssueList(
53
+ issues: ReadonlyArray<AuditIssue>,
54
+ isEnglish: boolean,
55
+ ): string {
56
+ const critical: string[] = [];
57
+ const high: string[] = [];
58
+ const medium: string[] = [];
59
+
60
+ for (const issue of issues) {
61
+ const line = `- ${issue.category}: ${issue.description}`;
62
+ if (issue.severity === "critical") {
63
+ critical.push(line);
64
+ } else if (issue.severity === "warning") {
65
+ high.push(line);
66
+ } else {
67
+ medium.push(line);
68
+ }
69
+ }
70
+
71
+ const parts: string[] = [];
72
+ if (critical.length > 0) {
73
+ parts.push(isEnglish
74
+ ? `## Critical — Must Fix\n${critical.join("\n")}`
75
+ : `## Critical(必须解决)\n${critical.join("\n")}`);
76
+ }
77
+ if (high.length > 0) {
78
+ parts.push(isEnglish
79
+ ? `## High — Should Improve\n${high.join("\n")}`
80
+ : `## High(应当改善)\n${high.join("\n")}`);
81
+ }
82
+ if (medium.length > 0) {
83
+ parts.push(isEnglish
84
+ ? `## Medium — Reference\n${medium.join("\n")}`
85
+ : `## Medium(参考建议)\n${medium.join("\n")}`);
86
+ }
87
+
88
+ return parts.join("\n\n");
89
+ }
90
+
91
+ const MODE_DESCRIPTIONS: Record<ReviseMode, string> = {
92
+ auto: "", // auto mode uses buildAutoSystemPrompt instead
93
+ polish: "润色:只改表达、节奏、段落呼吸,不改事实与剧情结论。禁止:增删段落、改变人名/地名/物品名、增加新情节或新对话、改变因果关系。只允许:替换用词、调整句序、修改标点节奏",
94
+ rewrite: "改写:允许重组问题段落、调整画面和叙述力度,但优先保留原文的绝大部分句段。除非问题跨越整章,否则禁止整章推倒重写;只能围绕问题段落及其直接上下文改写,同时保留核心事实与人物动机",
95
+ rework: "重写:可重构场景推进和冲突组织,但不改主设定和大事件结果",
96
+ "anti-detect": `反检测改写:在保持剧情不变的前提下,降低AI生成可检测性。
97
+
98
+ 改写手法(附正例):
99
+ 1. 打破句式规律:连续短句 → 长短交替,句式不可预测
100
+ 2. 口语化替代:✗"然而事情并没有那么简单" → ✓"哪有那么便宜的事"
101
+ 3. 减少"了"字密度:✗"他走了过去,拿了杯子" → ✓"他走过去,端起杯子"
102
+ 4. 转折词降频:✗"虽然…但是…" → ✓ 用角色内心吐槽或直接动作切换
103
+ 5. 情绪外化:✗"他感到愤怒" → ✓"他捏碎了茶杯,滚烫的茶水流过指缝"
104
+ 6. 删掉叙述者结论:✗"这一刻他终于明白了力量" → ✓ 只写行动,让读者自己感受
105
+ 7. 群像反应具体化:✗"全场震惊" → ✓"老陈的烟掉在裤子上,烫得他跳起来"
106
+ 8. 段落长度差异化:不再等长段落,有的段只有一句话,有的段七八行
107
+ 9. 消灭"不禁""仿佛""宛如"等AI标记词:换成具体感官描写`,
108
+ "spot-fix": "定点修复:只修改审稿意见指出的具体句子或段落,其余所有内容必须原封不动保留。修改范围限定在问题句子及其前后各一句。禁止改动无关段落",
109
+ };
110
+
111
+ export class ReviserAgent extends BaseAgent {
112
+ get name(): string {
113
+ return "reviser";
114
+ }
115
+
116
+ async reviseChapter(
117
+ bookDir: string,
118
+ chapterContent: string,
119
+ chapterNumber: number,
120
+ issues: ReadonlyArray<AuditIssue>,
121
+ mode: ReviseMode = DEFAULT_REVISE_MODE,
122
+ genre?: string,
123
+ options?: {
124
+ chapterIntent?: string;
125
+ chapterMemo?: ChapterMemo;
126
+ chapterIntentData?: ChapterIntent;
127
+ contextPackage?: ContextPackage;
128
+ ruleStack?: RuleStack;
129
+ lengthSpec?: LengthSpec;
130
+ },
131
+ ): Promise<ReviseOutput> {
132
+ const [currentState, ledger, hooks, styleGuideRaw, volumeOutline, storyBible, characterMatrix, chapterSummaries, parentCanon, fanficCanon] = await Promise.all([
133
+ // Phase 5 consolidation: derive initial state from roles + seed hooks
134
+ // when current_state.md is still the architect seed placeholder.
135
+ readCurrentStateWithFallback(bookDir, "(文件不存在)"),
136
+ this.readFileSafe(join(bookDir, "story/particle_ledger.md")),
137
+ this.readFileSafe(join(bookDir, "story/pending_hooks.md")),
138
+ this.readFileSafe(join(bookDir, "story/style_guide.md")),
139
+ readVolumeMap(bookDir, "(文件不存在)"),
140
+ readStoryFrame(bookDir, "(文件不存在)"),
141
+ readCharacterContext(bookDir, "(文件不存在)"),
142
+ this.readFileSafe(join(bookDir, "story/chapter_summaries.md")),
143
+ this.readFileSafe(join(bookDir, "story/parent_canon.md")),
144
+ this.readFileSafe(join(bookDir, "story/fanfic_canon.md")),
145
+ ]);
146
+
147
+ // Load genre profile and book rules
148
+ const genreId = genre ?? "other";
149
+ const [{ profile: gp }, bookLanguage] = await Promise.all([
150
+ readGenreProfile(this.ctx.projectRoot, genreId),
151
+ readBookLanguage(bookDir),
152
+ ]);
153
+ const parsedRules = await readBookRules(bookDir);
154
+ const bookRules = parsedRules?.rules ?? null;
155
+
156
+ // Fallback: use book_rules body when style_guide.md doesn't exist.
157
+ // Phase 5 hotfix 2: parsedRules.body is only populated for legacy
158
+ // book_rules.md sources — story_frame.md frontmatter yields an empty
159
+ // body, and an empty string is NOT a usable style guide. Treat
160
+ // missing/empty body as "no fallback available".
161
+ const legacyRulesBody = parsedRules?.body?.trim();
162
+ const styleGuide = styleGuideRaw !== "(文件不存在)"
163
+ ? styleGuideRaw
164
+ : (legacyRulesBody || "(无文风指南)");
165
+
166
+ const isEnglish = (bookLanguage ?? gp.language) === "en";
167
+ const resolvedLanguage = isEnglish ? "en" : "zh";
168
+
169
+ const issueList = mode === "auto"
170
+ ? buildTieredIssueList(issues, isEnglish)
171
+ : issues
172
+ .map((i) => `- [${i.severity}] ${i.category}: ${i.description}\n ${isEnglish ? "Suggestion" : "建议"}: ${i.suggestion}`)
173
+ .join("\n");
174
+
175
+ const numericalRule = gp.numericalSystem
176
+ ? (isEnglish
177
+ ? "\n3. Numerical errors must be fixed precisely — cross-check before and after"
178
+ : "\n3. 数值错误必须精确修正,前后对账")
179
+ : "";
180
+ const protagonistBlock = bookRules?.protagonist
181
+ ? (isEnglish
182
+ ? `\n\nProtagonist lock: ${bookRules.protagonist.name} — ${bookRules.protagonist.personalityLock.join(", ")}. Revisions must not violate the protagonist profile.`
183
+ : `\n\n主角人设锁定:${bookRules.protagonist.name},${bookRules.protagonist.personalityLock.join("、")}。修改不得违反人设。`)
184
+ : "";
185
+ // Length guardrail only used by legacy modes (manual CLI revise).
186
+ // Auto mode delegates length to normalize, not reviser.
187
+ const lengthGuardrail = mode !== "auto" && options?.lengthSpec
188
+ ? (isEnglish
189
+ ? "\n8. Keep the chapter word count within the target range; only allow minor deviation when fixing critical issues truly requires it"
190
+ : "\n8. 保持章节字数在目标区间内;只有在修复关键问题确实需要时才允许轻微偏离")
191
+ : "";
192
+ const langPrefix = isEnglish
193
+ ? `【LANGUAGE OVERRIDE】ALL output (FIXED_ISSUES, PATCHES, REVISED_CONTENT, UPDATED_STATE, UPDATED_HOOKS) MUST be in English.\n\n`
194
+ : "";
195
+ const governedMode = Boolean(options?.chapterIntent && options?.contextPackage && options?.ruleStack);
196
+ const hooksWorkingSet = governedMode && options?.contextPackage
197
+ ? buildGovernedHookWorkingSet({
198
+ hooksMarkdown: hooks,
199
+ contextPackage: options.contextPackage,
200
+ chapterNumber,
201
+ language: resolvedLanguage,
202
+ })
203
+ : hooks;
204
+ const chapterSummariesWorkingSet = governedMode
205
+ ? filterSummaries(chapterSummaries, chapterNumber)
206
+ : chapterSummaries;
207
+ const characterMatrixWorkingSet = governedMode
208
+ ? buildGovernedCharacterMatrixWorkingSet({
209
+ matrixMarkdown: characterMatrix,
210
+ chapterIntent: options?.chapterIntent ?? volumeOutline,
211
+ contextPackage: options!.contextPackage!,
212
+ protagonistName: bookRules?.protagonist?.name,
213
+ })
214
+ : characterMatrix;
215
+
216
+ const autoOutputMode = mode === "auto" ? resolveAutoOutputMode(issues) : "allow-full";
217
+ const systemPrompt = mode === "auto"
218
+ ? this.buildAutoSystemPrompt({ langPrefix, gp, protagonistBlock, numericalRule, lengthGuardrail, resolvedLanguage, lengthSpec: options?.lengthSpec, autoOutputMode })
219
+ : this.buildLegacySystemPrompt({ langPrefix, gp, protagonistBlock, numericalRule, lengthGuardrail, mode, resolvedLanguage });
220
+
221
+ const ledgerBlock = gp.numericalSystem
222
+ ? `\n## 资源账本\n${ledger}`
223
+ : "";
224
+ const governedMemoryBlocks = options?.contextPackage
225
+ ? buildGovernedMemoryEvidenceBlocks(options.contextPackage, resolvedLanguage)
226
+ : undefined;
227
+ const hookDebtBlock = governedMemoryBlocks?.hookDebtBlock ?? "";
228
+ const hooksBlock = governedMemoryBlocks?.hooksBlock
229
+ ?? `\n## 伏笔池\n${hooksWorkingSet}\n`;
230
+ const outlineBlock = volumeOutline !== "(文件不存在)"
231
+ ? `\n## 卷纲\n${volumeOutline}\n`
232
+ : "";
233
+ const bibleBlock = !governedMode && storyBible !== "(文件不存在)"
234
+ ? `\n## 世界观设定\n${storyBible}\n`
235
+ : "";
236
+ const matrixBlock = characterMatrixWorkingSet !== "(文件不存在)"
237
+ ? `\n## 角色交互矩阵\n${characterMatrixWorkingSet}\n`
238
+ : "";
239
+ const summariesBlock = governedMemoryBlocks?.summariesBlock
240
+ ?? (chapterSummariesWorkingSet !== "(文件不存在)"
241
+ ? `\n## 章节摘要\n${chapterSummariesWorkingSet}\n`
242
+ : "");
243
+ const volumeSummariesBlock = governedMemoryBlocks?.volumeSummariesBlock ?? "";
244
+
245
+ const hasParentCanon = parentCanon !== "(文件不存在)";
246
+ const hasFanficCanon = fanficCanon !== "(文件不存在)";
247
+
248
+ const canonBlock = hasParentCanon
249
+ ? `\n## 正传正典参照(修稿专用)\n本书为番外作品。修改时参照正典约束,不可改变正典事实。\n${parentCanon}\n`
250
+ : "";
251
+
252
+ const fanficCanonBlock = hasFanficCanon
253
+ ? `\n## 同人正典参照(修稿专用)\n本书为同人作品。修改时参照正典角色档案和世界规则,不可违反正典事实。角色对话必须保留原作语癖。\n${fanficCanon}\n`
254
+ : "";
255
+ const reducedControlBlock = options?.contextPackage && options.ruleStack
256
+ ? this.buildReducedControlBlock(options.chapterMemo, options.chapterIntentData, options.chapterIntent, options.contextPackage, options.ruleStack)
257
+ : "";
258
+ // Length guardrail only in legacy modes — auto mode delegates length to normalize.
259
+ const lengthGuidanceBlock = mode !== "auto" && options?.lengthSpec
260
+ ? `\n## 字数护栏\n目标字数:${options.lengthSpec.target}\n允许区间:${options.lengthSpec.softMin}-${options.lengthSpec.softMax}\n极限区间:${options.lengthSpec.hardMin}-${options.lengthSpec.hardMax}\n如果修正后超出允许区间,请优先压缩冗余解释、重复动作和弱信息句,不得新增支线或删掉核心事实。\n`
261
+ : "";
262
+ const styleGuideBlock = reducedControlBlock.length === 0
263
+ ? `\n## 文风指南\n${styleGuide}`
264
+ : "";
265
+
266
+ const userPrompt = `请修正第${chapterNumber}章。
267
+
268
+ ## 审稿问题
269
+ ${issueList}
270
+
271
+ ## 当前状态卡
272
+ ${currentState}
273
+ ${ledgerBlock}
274
+ ${sanitizeNarrativeEvidenceBlock(hookDebtBlock, resolvedLanguage) ?? ""}${sanitizeNarrativeEvidenceBlock(hooksBlock, resolvedLanguage) ?? ""}${sanitizeNarrativeEvidenceBlock(volumeSummariesBlock, resolvedLanguage) ?? ""}${reducedControlBlock || outlineBlock}${bibleBlock}${matrixBlock}${sanitizeNarrativeEvidenceBlock(summariesBlock, resolvedLanguage) ?? ""}${canonBlock}${fanficCanonBlock}${styleGuideBlock}${lengthGuidanceBlock}
275
+
276
+ ## 待修正章节
277
+ ${chapterContent}`;
278
+
279
+ const response = await this.chat(
280
+ [
281
+ { role: "system", content: systemPrompt },
282
+ { role: "user", content: userPrompt },
283
+ ],
284
+ { temperature: 0.3 },
285
+ );
286
+
287
+ const output = this.parseOutput(
288
+ response.content,
289
+ gp,
290
+ mode,
291
+ chapterContent,
292
+ autoOutputMode,
293
+ );
294
+ const mergedOutput = governedMode
295
+ ? {
296
+ ...output,
297
+ updatedHooks: mergeTableMarkdownByKey(hooks, output.updatedHooks, [0]),
298
+ }
299
+ : output;
300
+ const wordCount = options?.lengthSpec
301
+ ? countChapterLength(mergedOutput.revisedContent, options.lengthSpec.countingMode)
302
+ : mergedOutput.wordCount;
303
+ return { ...mergedOutput, wordCount, tokenUsage: response.usage };
304
+ }
305
+
306
+ private parseOutput(
307
+ content: string,
308
+ gp: GenreProfile,
309
+ mode: ReviseMode,
310
+ originalChapter: string,
311
+ autoOutputMode: AutoOutputMode = "allow-full",
312
+ ): ReviseOutput {
313
+ const extract = (tag: string): string => {
314
+ const regex = new RegExp(
315
+ `=== ${tag} ===\\s*([\\s\\S]*?)(?==== [A-Z_]+ ===|$)`,
316
+ );
317
+ const match = content.match(regex);
318
+ return match?.[1]?.trim() ?? "";
319
+ };
320
+
321
+ const fixedRaw = extract("FIXED_ISSUES");
322
+ const fixedIssues = fixedRaw
323
+ .split("\n")
324
+ .map((l) => l.trim())
325
+ .filter((l) => l.length > 0);
326
+
327
+ const makeResult = (revisedContent: string, applied: boolean): ReviseOutput => ({
328
+ revisedContent,
329
+ wordCount: revisedContent.length,
330
+ fixedIssues: applied ? fixedIssues : [],
331
+ updatedState: extract("UPDATED_STATE") || "(状态卡未更新)",
332
+ updatedLedger: gp.numericalSystem
333
+ ? (extract("UPDATED_LEDGER") || "(账本未更新)")
334
+ : "",
335
+ updatedHooks: extract("UPDATED_HOOKS") || "(伏笔池未更新)",
336
+ });
337
+
338
+ // Auto mode: route by issue type — structural issues require REVISED_CONTENT,
339
+ // local-only issues only accept PATCHES, mixed sets accept either.
340
+ if (mode === "auto") {
341
+ if (autoOutputMode === "patch-only") {
342
+ const patchesRaw = extract("PATCHES");
343
+ if (patchesRaw) {
344
+ const patches = parseSpotFixPatches(patchesRaw);
345
+ if (patches.length > 0) {
346
+ const patchResult = applySpotFixPatches(originalChapter, patches);
347
+ if (patchResult.applied && patchResult.appliedPatchCount / patches.length >= 0.5) {
348
+ return makeResult(patchResult.revisedContent, true);
349
+ }
350
+ }
351
+ }
352
+ return makeResult(originalChapter, false);
353
+ }
354
+
355
+ if (autoOutputMode === "rewrite-only") {
356
+ const revisedContent = extract("REVISED_CONTENT");
357
+ if (revisedContent) {
358
+ return makeResult(revisedContent, true);
359
+ }
360
+ // No rewrite produced — don't fall back to patches; structural issues
361
+ // cannot be safely patched. Return original unchanged.
362
+ return makeResult(originalChapter, false);
363
+ }
364
+
365
+ const revisedContent = extract("REVISED_CONTENT");
366
+ if (revisedContent) {
367
+ return makeResult(revisedContent, true);
368
+ }
369
+ const patchesRaw = extract("PATCHES");
370
+ if (patchesRaw) {
371
+ const patches = parseSpotFixPatches(patchesRaw);
372
+ if (patches.length > 0) {
373
+ const patchResult = applySpotFixPatches(originalChapter, patches);
374
+ if (patchResult.applied && patchResult.appliedPatchCount / patches.length >= 0.5) {
375
+ return makeResult(patchResult.revisedContent, true);
376
+ }
377
+ }
378
+ }
379
+ // Both empty — no fix
380
+ return makeResult(originalChapter, false);
381
+ }
382
+
383
+ // Legacy spot-fix mode: patches only
384
+ if (mode === "spot-fix") {
385
+ const patches = parseSpotFixPatches(extract("PATCHES"));
386
+ const patchResult = applySpotFixPatches(originalChapter, patches);
387
+ return makeResult(patchResult.revisedContent, patchResult.applied);
388
+ }
389
+
390
+ // Legacy rewrite/polish/rework/anti-detect: full content
391
+ const revisedContent = extract("REVISED_CONTENT");
392
+ return makeResult(revisedContent || originalChapter, revisedContent.length > 0);
393
+ }
394
+
395
+ private buildAutoSystemPrompt(params: {
396
+ langPrefix: string;
397
+ gp: GenreProfile;
398
+ protagonistBlock: string;
399
+ numericalRule: string;
400
+ lengthGuardrail: string;
401
+ resolvedLanguage: "zh" | "en";
402
+ lengthSpec?: LengthSpec;
403
+ autoOutputMode: AutoOutputMode;
404
+ }): string {
405
+ const { langPrefix, gp, protagonistBlock, numericalRule, resolvedLanguage, lengthSpec, autoOutputMode } = params;
406
+ // lengthGuardrail intentionally not used in auto mode — length constraint is embedded in REVISED_CONTENT description
407
+ const en = resolvedLanguage === "en";
408
+ const ledgerSection = gp.numericalSystem
409
+ ? (en ? "\n=== UPDATED_LEDGER ===\n(Full updated resource ledger)" : "\n=== UPDATED_LEDGER ===\n(更新后的完整资源账本)")
410
+ : "";
411
+ const rewriteLengthConstraint = lengthSpec
412
+ ? (en
413
+ ? `\n HARD CONSTRAINT: The revised chapter must stay within ${lengthSpec.softMin}-${lengthSpec.softMax} characters (target: ${lengthSpec.target}, ±25%). This is non-negotiable — do not exceed this range.`
414
+ : `\n 硬性约束:重写后的章节必须控制在 ${lengthSpec.softMin}-${lengthSpec.softMax} 字以内(目标 ${lengthSpec.target} 字,±25%)。这是不可突破的底线。`)
415
+ : "";
416
+
417
+ const routingDirectiveEn = autoOutputMode === "rewrite-only"
418
+ ? "\n\nROUTING: The reviewer's blocking issues are structural / semantic (character collapse, mainline drift, missing payoff, timeline break, unpaid hook, memo drift, etc.). You MUST output REVISED_CONTENT — do not emit PATCHES, they cannot fix this class of problem. If you cannot safely rewrite, say so in FIXED_ISSUES and leave REVISED_CONTENT empty."
419
+ : autoOutputMode === "patch-only"
420
+ ? "\n\nROUTING: The reviewer's blocking issues are local (wording, paragraph shape, fatigue word, information boundary, knowledge pollution). You MUST output PATCHES only — do not rewrite the whole chapter. If patches are not possible, leave PATCHES empty."
421
+ : "";
422
+ const routingDirectiveZh = autoOutputMode === "rewrite-only"
423
+ ? "\n\n分流指令:reviewer 报告的阻塞问题属于结构/语义错(人设崩、主线偏、爽点缺、时间线错、伏笔未收、memo 偏离等)。你必须输出 REVISED_CONTENT——禁止输出 PATCHES,这类问题不能靠补丁修复。如果无法安全重写,在 FIXED_ISSUES 里说明并留空 REVISED_CONTENT。"
424
+ : autoOutputMode === "patch-only"
425
+ ? "\n\n分流指令:reviewer 报告的阻塞问题属于局部错(措辞、段落形状、疲劳词、信息越界、知识污染)。你必须只输出 PATCHES——不要整章改写。如果做不出补丁,留空 PATCHES。"
426
+ : "";
427
+
428
+ return en
429
+ ? `${langPrefix}You are a professional ${gp.name} web-fiction revision editor. Fix the chapter according to the review notes.${protagonistBlock}${routingDirectiveEn}
430
+
431
+ PATCHES and REVISED_CONTENT serve different problems — choose by problem type, not preference:
432
+
433
+ PATCHES — for local text issues (wording, dialogue, AI-tell phrases, small continuity errors).
434
+ Each PATCH quotes the passage to change (a sentence, a paragraph, or multiple paragraphs) and provides a replacement. Untouched text stays exactly as-is.
435
+
436
+ REVISED_CONTENT — for whole-chapter issues (length compression, structural rewrite, pacing restructure, major plot realignment).
437
+ Outputs the full revised chapter. When Critical issues include length or structural problems, you must use REVISED_CONTENT — patches cannot compress or restructure a chapter.${rewriteLengthConstraint}
438
+
439
+ If Critical issues include both local and whole-chapter problems, use REVISED_CONTENT (it addresses everything in one pass).
440
+
441
+ Revision principles:
442
+ 1. Fix root causes — do not apply superficial polish${numericalRule}
443
+ 2. Hook status must stay in sync with the hooks board. If hook debt briefs are provided, preserve hook payoff scenes
444
+ 3. Do not alter the plot direction or core conflicts
445
+ 4. Preserve the original language style, rhythm, and pacing — do not compress transitional scenes or remove breathing room
446
+ 5. Emotion through action (never "he felt angry" — show it). Values through behavior, not slogans
447
+ 6. Different characters speak differently. No "everyone gasped in unison"
448
+ 7. Escalate: bad things stack, each worse than the last
449
+
450
+ Cycle-aware revision:
451
+ - If this chapter should be "aftermath" but is still escalating tension, rewrite the densest conflict passage into a change-showing passage — who lost what, whose attitude shifted, what the new normal is
452
+ - If this chapter should be "climax" but has no clear payoff, find the closest scene to a reward and amplify it — make the promised release exceed reader expectations
453
+ - Daily passages that don't serve the main line: rewrite as "bait" — add a detail pointing to the future, a hint, a character reaction that seeds curiosity
454
+
455
+ Output format:
456
+
457
+ === FIXED_ISSUES ===
458
+ (List each fix on its own line; if a safe local fix is not possible, explain here)
459
+
460
+ === PATCHES ===
461
+ (Output local patches if applicable. Omit this section entirely if using REVISED_CONTENT)
462
+ --- PATCH 1 ---
463
+ TARGET_TEXT:
464
+ (Exact quote from the original that identifies the passage to change)
465
+ REPLACEMENT_TEXT:
466
+ (Replacement text for this passage)
467
+ --- END PATCH ---
468
+
469
+ === REVISED_CONTENT ===
470
+ (Full revised chapter content — only when PATCHES cannot solve the problem. Omit this section if using PATCHES)
471
+
472
+ === UPDATED_STATE ===
473
+ (Full updated state card)
474
+ ${ledgerSection}
475
+ === UPDATED_HOOKS ===
476
+ (Full updated hooks board)`
477
+ : `${langPrefix}你是一位专业的${gp.name}网络小说修稿编辑。你的任务是根据审稿意见对章节进行修正。${protagonistBlock}${routingDirectiveZh}
478
+
479
+ PATCHES 和 REVISED_CONTENT 分别处理不同类型的问题——按问题类型选择,不是按偏好:
480
+
481
+ PATCHES——处理局部文字问题(措辞、对话、AI痕迹、小的连续性错误)。
482
+ 每个 PATCH 引用要修改的原文段落(一句、一段或多段皆可),给出替换文本。未涉及的内容保持原样。
483
+
484
+ REVISED_CONTENT——处理全章级问题(字数压缩、结构重组、节奏重排、重大剧情偏离)。
485
+ 输出修正后的完整正文。当 Critical 问题包含字数或结构性问题时,必须使用 REVISED_CONTENT——PATCHES 无法压缩或重构整章。${rewriteLengthConstraint}
486
+
487
+ 如果 Critical 同时包含局部问题和全章问题,使用 REVISED_CONTENT(一次性解决所有问题)。
488
+
489
+ 修稿原则:
490
+ 1. 修根因,不做表面润色${numericalRule}
491
+ 2. 伏笔状态必须与伏笔池同步。如果提供了 Hook Debt 简报,必须保留伏笔兑现段落
492
+ 3. 不改变剧情走向和核心冲突
493
+ 4. 保持原文的语言风格、节奏和呼吸——不要压缩过渡段、不要删掉减速段
494
+ 5. 情绪用动作外化(不写"他感到愤怒",写动作)。价值观通过行为传达
495
+ 6. 不同角色说话方式必须不同。禁止"众人齐声惊呼"
496
+ 7. 坏事叠坏事,每层比上一层过分
497
+
498
+ 小目标周期修稿指引:
499
+ - 如果本章应该是"后效"阶段但仍在加压,把最密集的冲突段落改写为展示改变的段落——谁失去了什么、谁的态度变了、新的常态是什么
500
+ - 如果本章应该是"爆发"阶段但没有明确兑现,找到最接近回报的场景并放大它——让承诺的释放超过读者预期
501
+ - 日常段落如果不服务主线,改写为"饵":加入一个指向未来的细节、一句暗示、一个角色反应
502
+
503
+ 输出格式:
504
+
505
+ === FIXED_ISSUES ===
506
+ (逐条说明修正了什么)
507
+
508
+ === PATCHES ===
509
+ (局部补丁——仅用于局部文字问题。有全章级问题时省略此区块)
510
+ --- PATCH 1 ---
511
+ TARGET_TEXT:
512
+ (从原文中精确引用要修改的段落)
513
+ REPLACEMENT_TEXT:
514
+ (替换后的文本)
515
+ --- END PATCH ---
516
+
517
+ === REVISED_CONTENT ===
518
+ (修正后的完整正文——用于字数/结构/节奏等全章级问题。仅局部问题时省略此区块)
519
+
520
+ === UPDATED_STATE ===
521
+ (更新后的完整状态卡)
522
+ ${ledgerSection}
523
+ === UPDATED_HOOKS ===
524
+ (更新后的完整伏笔池)`;
525
+ }
526
+
527
+ private buildLegacySystemPrompt(params: {
528
+ langPrefix: string;
529
+ gp: GenreProfile;
530
+ protagonistBlock: string;
531
+ numericalRule: string;
532
+ lengthGuardrail: string;
533
+ mode: ReviseMode;
534
+ resolvedLanguage: "zh" | "en";
535
+ }): string {
536
+ const { langPrefix, gp, protagonistBlock, numericalRule, lengthGuardrail, mode } = params;
537
+ const modeDesc = MODE_DESCRIPTIONS[mode];
538
+ const outputFormat = mode === "spot-fix"
539
+ ? `=== FIXED_ISSUES ===
540
+ (逐条说明修正了什么,一行一条;如果无法安全定点修复,也在这里说明)
541
+
542
+ === PATCHES ===
543
+ --- PATCH 1 ---
544
+ TARGET_TEXT:
545
+ (必须从原文中精确复制、且能唯一命中的原句或原段)
546
+ REPLACEMENT_TEXT:
547
+ (替换后的局部文本)
548
+ --- END PATCH ---
549
+
550
+ === UPDATED_STATE ===
551
+ (更新后的完整状态卡)
552
+ ${gp.numericalSystem ? "\n=== UPDATED_LEDGER ===\n(更新后的完整资源账本)" : ""}
553
+ === UPDATED_HOOKS ===
554
+ (更新后的完整伏笔池)`
555
+ : `=== FIXED_ISSUES ===
556
+ (逐条说明修正了什么,一行一条)
557
+
558
+ === REVISED_CONTENT ===
559
+ (修正后的完整正文)
560
+
561
+ === UPDATED_STATE ===
562
+ (更新后的完整状态卡)
563
+ ${gp.numericalSystem ? "\n=== UPDATED_LEDGER ===\n(更新后的完整资源账本)" : ""}
564
+ === UPDATED_HOOKS ===
565
+ (更新后的完整伏笔池)`;
566
+
567
+ return `${langPrefix}你是一位专业的${gp.name}网络小说修稿编辑。你的任务是根据审稿意见对章节进行修正。${protagonistBlock}
568
+
569
+ 修稿模式:${modeDesc}
570
+
571
+ 修稿原则:
572
+ 1. 按模式控制修改幅度
573
+ 2. 修根因,不做表面润色${numericalRule}
574
+ 4. 伏笔状态必须与伏笔池同步
575
+ 5. 不改变剧情走向和核心冲突
576
+ 6. 保持原文的语言风格和节奏
577
+ 7. 修改后同步更新状态卡${gp.numericalSystem ? "、账本" : ""}、伏笔池
578
+ ${lengthGuardrail}
579
+ ${mode === "spot-fix" ? "\n9. spot-fix 只能输出局部补丁,禁止输出整章改写;TARGET_TEXT 必须能在原文中唯一命中\n10. 如果需要大面积改写,说明无法安全 spot-fix,并让 PATCHES 留空" : ""}
580
+
581
+ 输出格式:
582
+
583
+ ${outputFormat}`;
584
+ }
585
+
586
+ private async readFileSafe(path: string): Promise<string> {
587
+ try {
588
+ return await readFile(path, "utf-8");
589
+ } catch {
590
+ return "(文件不存在)";
591
+ }
592
+ }
593
+
594
+ private buildReducedControlBlock(
595
+ memo: ChapterMemo | undefined,
596
+ intent: ChapterIntent | undefined,
597
+ chapterIntent: string | undefined,
598
+ contextPackage: ContextPackage,
599
+ ruleStack: RuleStack,
600
+ ): string {
601
+ const selectedContext = renderNarrativeSelectedContext(contextPackage.selectedContext, "zh")
602
+ .replace(/^### /gm, "- ");
603
+ const overrides = ruleStack.activeOverrides.length > 0
604
+ ? ruleStack.activeOverrides
605
+ .map((override) => `- ${override.from} -> ${override.to}: ${override.reason} (${override.target})`)
606
+ .join("\n")
607
+ : "- none";
608
+ // Prefer memo-based narrative block; fall back to legacy intent markdown
609
+ const narrativeBlock = memo
610
+ ? renderMemoAsNarrativeBlock(memo, intent, "zh")
611
+ : chapterIntent
612
+ ? buildNarrativeIntentBrief(chapterIntent, "zh")
613
+ : "(无)";
614
+
615
+ return `\n## 本章控制输入(由 Planner/Composer 编译)
616
+ ${narrativeBlock}
617
+
618
+ ### 已选上下文
619
+ ${selectedContext || "- none"}
620
+
621
+ ### 规则栈
622
+ - 硬护栏:${ruleStack.sections.hard.join("、") || "(无)"}
623
+ - 软约束:${ruleStack.sections.soft.join("、") || "(无)"}
624
+ - 诊断规则:${ruleStack.sections.diagnostic.join("、") || "(无)"}
625
+
626
+ ### 当前覆盖
627
+ ${overrides}\n`;
628
+ }
629
+ }
630
+
631
+ // Local-only categories: reviser produces line/paragraph patches. Fixing these
632
+ // with a full rewrite risks introducing new issues, so we force patch-only.
633
+ const LOCAL_ONLY_PATTERNS: ReadonlyArray<RegExp> = [
634
+ /Paragraph uniformity|段落等长/i,
635
+ /Hedge density|套话密度/i,
636
+ /Formulaic transitions|公式化转折/i,
637
+ /List-like structure|列表式结构/i,
638
+ /Cross-chapter repetition|跨章重复/i,
639
+ /AI-tell word density/i,
640
+ /Fatigue word|高疲劳词/i,
641
+ /Information Boundary Check|信息越界/i,
642
+ /Knowledge Base Pollution|知识库污染/i,
643
+ ];
644
+
645
+ // Structural/semantic categories: character collapse, mainline drift, conflict
646
+ // absence, timeline breaks, unpaid hooks, memo drift. These cannot be patched;
647
+ // the reviser must rewrite the chapter in full.
648
+ const STRUCTURAL_PATTERNS: ReadonlyArray<RegExp> = [
649
+ /OOC|人设|Character Fidelity|Character Matrix|Character.*Consistency/i,
650
+ /Mainline.*Drift|主线偏离|Outline Drift|大纲偏离|Chapter Memo Drift|章节备忘偏离/i,
651
+ /Conflict|冲突乏力|Payoff Dilution|爽点虚化/i,
652
+ /Timeline|时间线/i,
653
+ /Hook Check|伏笔检查|Hook.*Debt|伏笔.*债|未兑现/i,
654
+ /Power Scaling|战力崩坏|金手指/i,
655
+ /Pacing|节奏/i,
656
+ /POV Consistency|视角/i,
657
+ /Subplot Stagnation|支线停滞|Arc Flatline|弧线平坦/i,
658
+ /Relationship Dynamics|关系动态|情感表达/i,
659
+ /Incentive Chain|利益链/i,
660
+ /Canon Event|正典|Mainline Canon/i,
661
+ ];
662
+
663
+ function resolveAutoOutputMode(issues: ReadonlyArray<AuditIssue>): AutoOutputMode {
664
+ if (issues.length === 0) {
665
+ return "allow-full";
666
+ }
667
+
668
+ const isStructural = (issue: AuditIssue): boolean => {
669
+ const text = `${issue.category} ${issue.description}`;
670
+ return STRUCTURAL_PATTERNS.some((pattern) => pattern.test(text));
671
+ };
672
+ const isLocal = (issue: AuditIssue): boolean => {
673
+ const text = `${issue.category} ${issue.description}`;
674
+ return LOCAL_ONLY_PATTERNS.some((pattern) => pattern.test(text));
675
+ };
676
+
677
+ // Count blocking (critical + warning) structural vs local issues. Info-level
678
+ // findings are reviewer hints for the Polisher — they do not drive routing.
679
+ const blocking = issues.filter((issue) => issue.severity !== "info");
680
+ if (blocking.length === 0) {
681
+ return "patch-only"; // only hints / info — at most local polish
682
+ }
683
+
684
+ const structuralCount = blocking.filter(isStructural).length;
685
+ const localOnlyCount = blocking.filter(isLocal).length;
686
+
687
+ // Any structural issue forces a rewrite — patches cannot fix character
688
+ // collapse, mainline drift, missing payoff, or timeline breaks.
689
+ if (structuralCount > 0) {
690
+ return "rewrite-only";
691
+ }
692
+
693
+ // All blocking issues are in the local-only list → safe to patch.
694
+ if (localOnlyCount === blocking.length) {
695
+ return "patch-only";
696
+ }
697
+
698
+ // Mixed / unknown blocking issue set — let the reviser pick (usually ends
699
+ // up rewriting when critical, patching when warning).
700
+ return "allow-full";
701
+ }