@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,824 @@
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 { FanficMode } from "../models/book.js";
5
+ import type { ChapterMemo, ContextPackage, RuleStack } from "../models/input-governance.js";
6
+ import { readGenreProfile, readBookLanguage, readBookRules } from "./rules-reader.js";
7
+ import { getFanficDimensionConfig, FANFIC_DIMENSIONS } from "./fanfic-dimensions.js";
8
+ import { readFile, readdir } from "node:fs/promises";
9
+ import { filterHooks, filterSummaries, filterSubplots, filterEmotionalArcs, filterCharacterMatrix } from "../utils/context-filter.js";
10
+ import { buildGovernedMemoryEvidenceBlocks } from "../utils/governed-context.js";
11
+ import {
12
+ readVolumeMap,
13
+ readCharacterContext,
14
+ readCurrentStateWithFallback,
15
+ } from "../utils/outline-paths.js";
16
+ import { join } from "node:path";
17
+
18
+ export interface AuditResult {
19
+ readonly passed: boolean;
20
+ readonly issues: ReadonlyArray<AuditIssue>;
21
+ readonly summary: string;
22
+ /** 0-100 overall quality score. Present when the auditor supports scoring. */
23
+ readonly overallScore?: number;
24
+ readonly tokenUsage?: {
25
+ readonly promptTokens: number;
26
+ readonly completionTokens: number;
27
+ readonly totalTokens: number;
28
+ };
29
+ }
30
+
31
+ export interface AuditIssue {
32
+ readonly severity: "critical" | "warning" | "info";
33
+ readonly category: string;
34
+ readonly description: string;
35
+ readonly suggestion: string;
36
+ }
37
+
38
+ type PromptLanguage = "zh" | "en";
39
+
40
+ const DIMENSION_LABELS: Record<number, { readonly zh: string; readonly en: string }> = {
41
+ 1: { zh: "OOC检查", en: "OOC Check" },
42
+ 2: { zh: "时间线检查", en: "Timeline Check" },
43
+ 3: { zh: "设定冲突", en: "Lore Conflict Check" },
44
+ 4: { zh: "战力崩坏", en: "Power Scaling Check" },
45
+ 5: { zh: "数值检查", en: "Numerical Consistency Check" },
46
+ 6: { zh: "伏笔检查", en: "Hook Check" },
47
+ 7: { zh: "节奏检查", en: "Pacing Check" },
48
+ 8: { zh: "文风检查", en: "Style Check" },
49
+ 9: { zh: "信息越界", en: "Information Boundary Check" },
50
+ 10: { zh: "词汇疲劳", en: "Lexical Fatigue Check" },
51
+ 11: { zh: "利益链断裂", en: "Incentive Chain Check" },
52
+ 12: { zh: "年代考据", en: "Era Accuracy Check" },
53
+ 13: { zh: "配角降智", en: "Side Character Competence Check" },
54
+ 14: { zh: "配角工具人化", en: "Side Character Instrumentalization Check" },
55
+ 15: { zh: "爽点虚化", en: "Payoff Dilution Check" },
56
+ 16: { zh: "台词失真", en: "Dialogue Authenticity Check" },
57
+ 17: { zh: "流水账", en: "Chronicle Drift Check" },
58
+ 18: { zh: "知识库污染", en: "Knowledge Base Pollution Check" },
59
+ 19: { zh: "视角一致性", en: "POV Consistency Check" },
60
+ 20: { zh: "段落等长", en: "Paragraph Uniformity Check" },
61
+ 21: { zh: "套话密度", en: "Cliche Density Check" },
62
+ 22: { zh: "公式化转折", en: "Formulaic Twist Check" },
63
+ 23: { zh: "列表式结构", en: "List-like Structure Check" },
64
+ 24: { zh: "支线停滞", en: "Subplot Stagnation Check" },
65
+ 25: { zh: "弧线平坦", en: "Arc Flatline Check" },
66
+ 26: { zh: "节奏单调", en: "Pacing Monotony Check" },
67
+ 27: { zh: "敏感词检查", en: "Sensitive Content Check" },
68
+ 28: { zh: "正传事件冲突", en: "Mainline Canon Event Conflict" },
69
+ 29: { zh: "未来信息泄露", en: "Future Knowledge Leak Check" },
70
+ 30: { zh: "世界规则跨书一致性", en: "Cross-Book World Rule Check" },
71
+ 31: { zh: "番外伏笔隔离", en: "Spinoff Hook Isolation Check" },
72
+ 32: { zh: "读者期待管理", en: "Reader Expectation Check" },
73
+ 33: { zh: "章节备忘偏离", en: "Chapter Memo Drift Check" },
74
+ 34: { zh: "角色还原度", en: "Character Fidelity Check" },
75
+ 35: { zh: "世界规则遵守", en: "World Rule Compliance Check" },
76
+ 36: { zh: "关系动态", en: "Relationship Dynamics Check" },
77
+ 37: { zh: "正典事件一致性", en: "Canon Event Consistency Check" },
78
+ };
79
+
80
+ function containsChinese(text: string): boolean {
81
+ return /[\u4e00-\u9fff]/u.test(text);
82
+ }
83
+
84
+ function resolveGenreLabel(genreId: string, profileName: string, language: PromptLanguage): string {
85
+ if (language === "zh" || !containsChinese(profileName)) {
86
+ return profileName;
87
+ }
88
+
89
+ if (genreId === "other") {
90
+ return "general";
91
+ }
92
+
93
+ return genreId.replace(/[_-]+/g, " ");
94
+ }
95
+
96
+ function dimensionName(id: number, language: PromptLanguage): string | undefined {
97
+ return DIMENSION_LABELS[id]?.[language];
98
+ }
99
+
100
+ function joinLocalized(items: ReadonlyArray<string>, language: PromptLanguage): string {
101
+ return items.join(language === "en" ? ", " : "、");
102
+ }
103
+
104
+ function formatFanficSeverityNote(
105
+ severity: "critical" | "warning" | "info",
106
+ language: PromptLanguage,
107
+ ): string {
108
+ if (language === "en") {
109
+ return severity === "critical"
110
+ ? "Strict check."
111
+ : severity === "info"
112
+ ? "Log only; do not fail the chapter."
113
+ : "Warning level.";
114
+ }
115
+
116
+ return severity === "critical"
117
+ ? "(严格检查)"
118
+ : severity === "info"
119
+ ? "(仅记录,不判定失败)"
120
+ : "(警告级别)";
121
+ }
122
+
123
+ function buildDimensionNote(
124
+ id: number,
125
+ language: PromptLanguage,
126
+ gp: GenreProfile,
127
+ bookRules: BookRules | null,
128
+ fanficMode: FanficMode | undefined,
129
+ fanficConfig: ReturnType<typeof getFanficDimensionConfig> | undefined,
130
+ ): string {
131
+ const words = bookRules?.fatigueWordsOverride && bookRules.fatigueWordsOverride.length > 0
132
+ ? bookRules.fatigueWordsOverride
133
+ : gp.fatigueWords;
134
+
135
+ if (fanficConfig?.notes.has(id) && language === "zh") {
136
+ return fanficConfig.notes.get(id)!;
137
+ }
138
+
139
+ if (id === 1 && fanficMode === "ooc") {
140
+ return language === "en"
141
+ ? "In OOC mode, personality drift can be intentional; record only, do not fail. Evaluate against the character dossiers in fanfic_canon.md."
142
+ : "OOC模式下角色可偏离性格底色,此维度仅记录不判定失败。参照 fanfic_canon.md 角色档案评估偏离程度。";
143
+ }
144
+
145
+ if (id === 1 && fanficMode === "canon") {
146
+ return language === "en"
147
+ ? "Canon-faithful fanfic: characters must stay close to their original personality core. Evaluate against fanfic_canon.md character dossiers."
148
+ : "原作向同人:角色必须严格遵守性格底色。参照 fanfic_canon.md 角色档案中的性格底色和行为模式。";
149
+ }
150
+
151
+ if (id === 10 && words.length > 0) {
152
+ return language === "en"
153
+ ? `Fatigue words: ${words.join(", ")}. Also check AI tell markers (仿佛/不禁/宛如/竟然/忽然/猛地); warn when any appears more than once per 3,000 words.`
154
+ : `高疲劳词:${words.join("、")}。同时检查AI标记词(仿佛/不禁/宛如/竟然/忽然/猛地)密度,每3000字超过1次即warning`;
155
+ }
156
+
157
+ if (id === 15 && gp.satisfactionTypes.length > 0) {
158
+ return language === "en"
159
+ ? `Payoff types: ${gp.satisfactionTypes.join(", ")}`
160
+ : `爽点类型:${gp.satisfactionTypes.join("、")}`;
161
+ }
162
+
163
+ if (id === 12 && bookRules?.eraConstraints) {
164
+ const era = bookRules.eraConstraints;
165
+ const parts = [era.period, era.region].filter(Boolean);
166
+ if (parts.length > 0) {
167
+ return language === "en"
168
+ ? `Era: ${parts.join(", ")}`
169
+ : `年代:${parts.join(",")}`;
170
+ }
171
+ }
172
+
173
+ // v10: Enhanced dimension notes with writing methodology awareness
174
+ if (id === 7) {
175
+ return language === "en"
176
+ ? "Check pacing rhythm: Do the recent 3-5 chapters form a complete mini-goal cycle (build-up → escalation → climax → aftermath)? If 5+ consecutive chapters pass without a climax (payoff/reward/reversal), flag as pacing stagnation. If the previous chapter was a climax/big reversal, does this chapter show change (relationships shifted, status changed, costs paid)? If it jumps straight to new build-up without showing impact, flag as 'post-climax impact missing'. Daily/transition scenes must carry at least one task: plant a hook, advance a relationship, set up contrast, or prepare the next cycle."
177
+ : "检查节奏波形:最近 3-5 章是否形成了完整的「蓄压→升级→爆发→后效」周期?如果连续 5 章没有爆发(兑现/回报/翻转),标记为节奏停滞。如果上一章是爆发/高潮/大反转,本章是否写出了改变?如果直接跳到新蓄压而没有展示前一波爆发的影响,标记为「高潮后影响缺失」。非冲突章节中的日常/过渡/对话段落,是否至少承担了一项任务:埋伏笔、推关系、建立反差、准备下一轮蓄压。纯水日常标记为流水账风险。";
178
+ }
179
+
180
+ if (id === 15) {
181
+ const base = gp.satisfactionTypes.length > 0
182
+ ? (language === "en" ? `Payoff types: ${gp.satisfactionTypes.join(", ")}. ` : `爽点类型:${gp.satisfactionTypes.join("、")}。`)
183
+ : "";
184
+ return language === "en"
185
+ ? `${base}Check desire engine: Has the chapter created an emotional gap (reader wants release) OR delivered a payoff that exceeds expectations? A payoff that only satisfies 70% of built-up anticipation counts as diluted. If this chapter is in the aftermath phase of a mini-goal cycle, verify that consequences are shown — not just emotional reactions, but concrete changes to status, relationships, or resources.`
186
+ : `${base}检查欲望驱动:本章是否制造了情绪缺口(读者渴望释放)或完成了超出预期的兑现?只满足读者70%期待的兑现等于爽点虚化。如果本章处于小目标周期的后效阶段,检查是否展示了具体改变——不只是情绪反应,而是地位、关系或资源的实际变化。`;
187
+ }
188
+
189
+ if (id === 25) {
190
+ return language === "en"
191
+ ? "Cross-check character behavior against the 3-question test: (1) Why does the character do this? (2) Does it match their established profile? (3) Would a reader who only read prior chapters find it jarring? Also check if character's emotional state progresses or stagnates."
192
+ : "人设三问检查:(1)角色为什么这么做?(2)符合之前建立的人设吗?(3)只看过前面章节的读者会觉得突兀吗?同时检查角色情绪弧线是否在推进还是停滞。";
193
+ }
194
+
195
+ switch (id) {
196
+ case 6:
197
+ // Phase 7 — hook-debt escalation. Reviewer now reads pending_hooks.md
198
+ // not just for "is this hook undelivered" but for causal/temporal
199
+ // debt escalation. The ledger's status column carries "过期 (距=…/半衰=…)"
200
+ // and "受阻于 …" markers emitted by the stale/blocked detector; this
201
+ // dimension tells the reviewer how to escalate them.
202
+ return language === "en"
203
+ ? `Hook-debt escalation (Phase 7 + hotfixes 2/3). Read the pending_hooks.md ledger and escalate based on the stale / blocked / core_hook / depends_on / promoted columns, NOT only on "undelivered hook present":
204
+
205
+ • Critical severity only applies to hooks with promoted=true in the ledger. A stale/blocked non-promoted hook stays at info — the promotion flag is the gate that keeps reviewer noise down, because architect-seed emits many non-load-bearing seeds.
206
+ • A promoted core_hook=true hook that has been stale for over 10 chapters → escalate from warning to critical. The book has only 3-7 core hooks; letting one drift that long is the lead symptom of narrative rot (cf. new.txt L1569).
207
+ • A promoted hook whose status cell contains "blocked on X (blocked Y chapters)" with Y >= 6 → warning. The literal "blocked Y chapters" token comes straight from the ledger — read it, don't guess. Call out the upstream hook id so the planner can route the resolution.
208
+ • At volume end (final chapter of any volume per volume_map) a promoted core_hook that is still open or stale without explicit "carried over to volume N+1" planning → critical.
209
+ • Any non-promoted stale hook → info-level log; do not fail the chapter on it, but note it so the planner can schedule cleanup.
210
+
211
+ Quote the exact hook_id in description and include the stale / blocked marker text verbatim. Structure check only — do not judge hook prose quality.`
212
+ : `Phase 7 hook-debt 升级规则(含 hotfix 2/3)。阅读 pending_hooks.md 伏笔池时不要只看"有没有悬而未决的伏笔",要读状态列中的 stale / blocked 标记、core_hook 列、depends_on 列、以及升级列:
213
+
214
+ • critical 级别仅适用于升级=是(promoted=true)的伏笔。非升级的 stale/blocked 伏笔一律保持 info——升级标志是降噪的开关,因为架构师阶段会产出大量非承重的伏笔种子。
215
+ • 升级=是且 core_hook=是 的伏笔过期超过 10 章未回收 → warning 升级为 critical。全书只有 3-7 条核心伏笔,任何一条漂移这么久都是烂尾前兆(对应 new.txt L1569"严禁烂尾逻辑")。
216
+ • 升级=是的受阻伏笔,状态列中"受阻于 X (已阻 Y 章)"且 Y ≥ 6 → warning。"已阻 Y 章"这个字面 token 直接读自账本,不要猜。描述中要写出具体的上游 hook_id,让 planner 能安排落地路径。
217
+ • 卷尾(volume_map 中任一卷的末章)仍有升级=是的主线伏笔处于 open 或 stale 且没有显式"延至下一卷"规划 → critical。
218
+ • 升级=否的 stale 伏笔 → info 级记录,不判本章失败,但保留以便 planner 安排清理。
219
+
220
+ description 中要明确引用 hook_id,并把状态列中 stale / blocked 的原文标记字面抄进去。本维度只审结构,不评价伏笔文笔。`;
221
+ case 19:
222
+ return language === "en"
223
+ ? "Check whether POV shifts are signaled clearly and stay consistent with the configured viewpoint."
224
+ : "检查视角切换是否有过渡、是否与设定视角一致";
225
+ case 24:
226
+ return language === "en"
227
+ ? "Cross-check subplot_board and chapter_summaries: flag any subplot that stays dormant long enough to feel abandoned, or a recent run where every subplot is only restated instead of genuinely moving."
228
+ : "对照 subplot_board 和 chapter_summaries:标记那些沉寂到接近被遗忘的支线,或近期连续只被重复提及、没有真实推进的支线。";
229
+ case 25:
230
+ return language === "en"
231
+ ? "Cross-check emotional_arcs and chapter_summaries: flag any major character whose emotional line holds one pressure shape across a run instead of taking new pressure, release, reversal, or reinterpretation. Distinguish unchanged circumstances from unchanged inner movement."
232
+ : "对照 emotional_arcs 和 chapter_summaries:标记主要角色在一段时间内始终停留在同一种情绪压力形态、没有新压力、释放、转折或重估的情况。注意区分'处境未变'和'内心未变'。";
233
+ case 26:
234
+ return language === "en"
235
+ ? "Cross-check chapter_summaries for chapter-type distribution: warn when the recent sequence stays in the same mode long enough to flatten rhythm, or when payoff / release beats disappear for too long. Explicitly list the recent type sequence."
236
+ : "对照 chapter_summaries 的章节类型分布:当近期章节长时间停留在同一种模式、把节奏压平,或回收/释放/高潮章节缺席过久时给出 warning。请明确列出最近章节的类型序列。";
237
+ case 28:
238
+ return language === "en"
239
+ ? "Check whether spinoff events contradict the mainline canon constraints."
240
+ : "检查番外事件是否与正典约束表矛盾";
241
+ case 29:
242
+ return language === "en"
243
+ ? "Check whether characters reference information that should only be revealed after the divergence point (see the information-boundary table)."
244
+ : "检查角色是否引用了分歧点之后才揭示的信息(参照信息边界表)";
245
+ case 30:
246
+ return language === "en"
247
+ ? "Check whether the spinoff violates mainline world rules (power system, geography, factions)."
248
+ : "检查番外是否违反正传世界规则(力量体系、地理、阵营)";
249
+ case 31:
250
+ return language === "en"
251
+ ? "Check whether the spinoff resolves mainline hooks without authorization (warning level)."
252
+ : "检查番外是否越权回收正传伏笔(warning级别)";
253
+ case 32:
254
+ return language === "en"
255
+ ? "Check whether the ending renews curiosity, whether promised payoffs are landing on the cadence their hooks imply, whether pressure gets any release, and whether reader expectation gaps are accumulating faster than they are being satisfied. If a climax just occurred, check whether the aftermath chapters show concrete change before starting a new cycle."
256
+ : "检查:章尾是否重新点燃好奇心,已经承诺的回收是否按伏笔自身节奏落地,压力是否得到释放,读者期待缺口是在持续累积还是在被满足。如果刚经历高潮,检查后效章节是否在开启新周期前展示了具体改变。";
257
+ case 33:
258
+ return language === "en"
259
+ ? "Cross-check the chapter_memo provided with the chapter. Does the final prose deliver the memo's goal and leave a visible trace for every one of the 7 sections it contains (tasks, pay-offs / held-back cards, daily/transition function map, three-question check, end-of-chapter concrete changes, hard-don'ts)? Missing or contradicted sections -> critical. Note: a sparse memo (breather chapter, goal + skeleton body only) is legitimate — only flag drift against sections that the memo actually populates. Never flag the memo itself for being sparse."
260
+ : "对照随章提供的 chapter_memo。成稿是否兑现了 memo 中的 goal,并在 7 段正文(当前任务 / 该兑现·暂不掀 / 日常过渡功能 / 关键抉择三连问 / 章尾必须发生的改变 / 不要做 等)中留下可见落地痕迹?任何段落缺失或被写反 → critical。提醒:稀疏 memo 合法(喘息章 memo 可以只有 goal + 骨架 body),只检查 memo 实际写出的段落,不能因为 memo 稀疏就判 incomplete。";
261
+ case 34:
262
+ case 35:
263
+ case 36:
264
+ case 37: {
265
+ if (!fanficConfig) return "";
266
+ const severity = fanficConfig.severityOverrides.get(id) ?? "warning";
267
+ const baseNote = language === "en"
268
+ ? {
269
+ 34: "Check whether dialogue tics, speaking style, and behavior remain consistent with the character dossiers in fanfic_canon.md. Deviations need clear situational motivation.",
270
+ 35: "Check whether the chapter violates world rules documented in fanfic_canon.md (geography, power system, faction relations).",
271
+ 36: "Check whether relationship beats remain plausible and aligned with, or meaningfully develop from, the key relationships documented in fanfic_canon.md.",
272
+ 37: "Check whether the chapter contradicts the key event timeline in fanfic_canon.md.",
273
+ }[id]
274
+ : FANFIC_DIMENSIONS.find((dimension) => dimension.id === id)?.baseNote;
275
+
276
+ return baseNote
277
+ ? `${baseNote} ${formatFanficSeverityNote(severity, language)}`
278
+ : "";
279
+ }
280
+ default:
281
+ return "";
282
+ }
283
+ }
284
+
285
+ function buildDimensionList(
286
+ gp: GenreProfile,
287
+ bookRules: BookRules | null,
288
+ language: PromptLanguage,
289
+ hasParentCanon = false,
290
+ fanficMode?: FanficMode,
291
+ ): ReadonlyArray<{ readonly id: number; readonly name: string; readonly note: string }> {
292
+ const activeIds = new Set(gp.auditDimensions);
293
+
294
+ // Add book-level additional dimensions (supports both numeric IDs and name strings)
295
+ if (bookRules?.additionalAuditDimensions) {
296
+ // Build reverse lookup: name → id
297
+ const nameToId = new Map<string, number>();
298
+ for (const [id, labels] of Object.entries(DIMENSION_LABELS)) {
299
+ nameToId.set(labels.zh, Number(id));
300
+ nameToId.set(labels.en, Number(id));
301
+ }
302
+
303
+ for (const d of bookRules.additionalAuditDimensions) {
304
+ if (typeof d === "number") {
305
+ activeIds.add(d);
306
+ } else if (typeof d === "string") {
307
+ // Try exact match first, then substring match
308
+ const exactId = nameToId.get(d);
309
+ if (exactId !== undefined) {
310
+ activeIds.add(exactId);
311
+ } else {
312
+ // Fuzzy: find dimension whose name contains the string
313
+ for (const [name, id] of nameToId) {
314
+ if (name.includes(d) || d.includes(name)) {
315
+ activeIds.add(id);
316
+ break;
317
+ }
318
+ }
319
+ }
320
+ }
321
+ }
322
+ }
323
+
324
+ // Always-active dimensions
325
+ activeIds.add(32); // 读者期待管理 — universal
326
+ activeIds.add(33); // 章节备忘偏离 — universal (replaces legacy volume-outline drift)
327
+
328
+ // Conditional overrides
329
+ if (gp.eraResearch || bookRules?.eraConstraints?.enabled) {
330
+ activeIds.add(12);
331
+ }
332
+
333
+ // Spinoff dimensions — activated when parent_canon.md exists (but NOT in fanfic mode)
334
+ if (hasParentCanon && !fanficMode) {
335
+ activeIds.add(28); // 正传事件冲突
336
+ activeIds.add(29); // 未来信息泄露
337
+ activeIds.add(30); // 世界规则跨书一致性
338
+ activeIds.add(31); // 番外伏笔隔离
339
+ }
340
+
341
+ // Fanfic dimensions — replace spinoff dims with fanfic-specific checks
342
+ let fanficConfig: ReturnType<typeof getFanficDimensionConfig> | undefined;
343
+ if (fanficMode) {
344
+ fanficConfig = getFanficDimensionConfig(fanficMode, bookRules?.allowedDeviations);
345
+ for (const id of fanficConfig.activeIds) {
346
+ activeIds.add(id);
347
+ }
348
+ for (const id of fanficConfig.deactivatedIds) {
349
+ activeIds.delete(id);
350
+ }
351
+ }
352
+
353
+ const dims: Array<{ id: number; name: string; note: string }> = [];
354
+
355
+ for (const id of [...activeIds].sort((a, b) => a - b)) {
356
+ const name = dimensionName(id, language);
357
+ if (!name) continue;
358
+
359
+ const note = buildDimensionNote(id, language, gp, bookRules, fanficMode, fanficConfig);
360
+
361
+ dims.push({ id, name, note });
362
+ }
363
+
364
+ return dims;
365
+ }
366
+
367
+ export class ContinuityAuditor extends BaseAgent {
368
+ get name(): string {
369
+ return "continuity-auditor";
370
+ }
371
+
372
+ async auditChapter(
373
+ bookDir: string,
374
+ chapterContent: string,
375
+ chapterNumber: number,
376
+ genre?: string,
377
+ options?: {
378
+ temperature?: number;
379
+ chapterIntent?: string;
380
+ chapterMemo?: ChapterMemo;
381
+ contextPackage?: ContextPackage;
382
+ ruleStack?: RuleStack;
383
+ truthFileOverrides?: {
384
+ currentState?: string;
385
+ ledger?: string;
386
+ hooks?: string;
387
+ };
388
+ },
389
+ ): Promise<AuditResult> {
390
+ const [diskCurrentState, diskLedger, diskHooks, styleGuideRaw, subplotBoard, emotionalArcs, characterMatrix, chapterSummaries, parentCanon, fanficCanon, volumeOutline] =
391
+ await Promise.all([
392
+ // Phase 5 consolidation: derive initial state from roles + seed hooks
393
+ // when current_state.md is still the architect seed placeholder.
394
+ readCurrentStateWithFallback(bookDir, "(文件不存在)"),
395
+ this.readFileSafe(join(bookDir, "story/particle_ledger.md")),
396
+ this.readFileSafe(join(bookDir, "story/pending_hooks.md")),
397
+ this.readFileSafe(join(bookDir, "story/style_guide.md")),
398
+ this.readFileSafe(join(bookDir, "story/subplot_board.md")),
399
+ this.readFileSafe(join(bookDir, "story/emotional_arcs.md")),
400
+ readCharacterContext(bookDir, "(文件不存在)"),
401
+ this.readFileSafe(join(bookDir, "story/chapter_summaries.md")),
402
+ this.readFileSafe(join(bookDir, "story/parent_canon.md")),
403
+ this.readFileSafe(join(bookDir, "story/fanfic_canon.md")),
404
+ readVolumeMap(bookDir, "(文件不存在)"),
405
+ ]);
406
+ const currentState = options?.truthFileOverrides?.currentState ?? diskCurrentState;
407
+ const ledger = options?.truthFileOverrides?.ledger ?? diskLedger;
408
+ const hooks = options?.truthFileOverrides?.hooks ?? diskHooks;
409
+
410
+ const hasParentCanon = parentCanon !== "(文件不存在)";
411
+ const hasFanficCanon = fanficCanon !== "(文件不存在)";
412
+
413
+ // Load last chapter full text for fine-grained continuity checking
414
+ const previousChapter = await this.loadPreviousChapter(bookDir, chapterNumber);
415
+
416
+ // Load genre profile and book rules
417
+ const genreId = genre ?? "other";
418
+ const [{ profile: gp }, bookLanguage] = await Promise.all([
419
+ readGenreProfile(this.ctx.projectRoot, genreId),
420
+ readBookLanguage(bookDir),
421
+ ]);
422
+ const parsedRules = await readBookRules(bookDir);
423
+ const bookRules = parsedRules?.rules ?? null;
424
+
425
+ // Fallback: use book_rules body when style_guide.md doesn't exist.
426
+ // Phase 5 hotfix 2: parsedRules.body is only populated for legacy
427
+ // book_rules.md sources — story_frame.md frontmatter yields an empty
428
+ // body, and an empty string is NOT a usable style guide. Treat
429
+ // missing/empty body as "no fallback available".
430
+ const legacyRulesBody = parsedRules?.body?.trim();
431
+ const styleGuide = styleGuideRaw !== "(文件不存在)"
432
+ ? styleGuideRaw
433
+ : (legacyRulesBody || "(无文风指南)");
434
+
435
+ const resolvedLanguage = bookLanguage ?? gp.language;
436
+ const isEnglish = resolvedLanguage === "en";
437
+ const fanficMode = hasFanficCanon ? (bookRules?.fanficMode as FanficMode | undefined) : undefined;
438
+ const dimensions = buildDimensionList(gp, bookRules, resolvedLanguage, hasParentCanon, fanficMode);
439
+ const dimList = dimensions
440
+ .map((d) => `${d.id}. ${d.name}${d.note ? (isEnglish ? ` (${d.note})` : `(${d.note})`) : ""}`)
441
+ .join("\n");
442
+ const genreLabel = resolveGenreLabel(genreId, gp.name, resolvedLanguage);
443
+
444
+ const protagonistBlock = bookRules?.protagonist
445
+ ? isEnglish
446
+ ? `\n\nProtagonist lock: ${bookRules.protagonist.name}; personality locks: ${joinLocalized(bookRules.protagonist.personalityLock, resolvedLanguage)}; behavioral constraints: ${joinLocalized(bookRules.protagonist.behavioralConstraints, resolvedLanguage)}.`
447
+ : `\n主角人设锁定:${bookRules.protagonist.name},${bookRules.protagonist.personalityLock.join("、")},行为约束:${bookRules.protagonist.behavioralConstraints.join("、")}`
448
+ : "";
449
+
450
+ const searchNote = gp.eraResearch
451
+ ? isEnglish
452
+ ? "\n\nYou have web-search capability (search_web / fetch_url). For real-world eras, people, events, geography, or policies, you must verify with search_web instead of relying on memory. Cross-check at least 2 sources."
453
+ : "\n\n你有联网搜索能力(search_web / fetch_url)。对于涉及真实年代、人物、事件、地理、政策的内容,你必须用search_web核实,不可凭记忆判断。至少对比2个来源交叉验证。"
454
+ : "";
455
+
456
+ const systemPrompt = isEnglish
457
+ ? `You are a strict ${genreLabel} web-fiction structural editor. Audit the chapter for completion and structure, not for prose craft. ALL OUTPUT MUST BE IN ENGLISH.${protagonistBlock}${searchNote}
458
+
459
+ ## Reviewer Scope (hard constraints)
460
+
461
+ You audit completion and structure only. Your job is to decide whether the chapter delivers the plan, keeps characters and timelines intact, and moves the book forward. Wording, sentence rhythm, paragraph shape, punctuation, imagery, and other prose-surface choices are NOT yours — those belong to the Polisher pass that runs after you. If you notice prose-surface issues, you may flag them with severity "info" so the Polisher can see them, but they do not count toward passed / overall_score and they must never be critical.
462
+
463
+ You audit twelve structural reader-pain patterns: dragging / flat openings, blurry worldbuilding disconnected from reality, contradictory character setup, tangled POV, mainline drift or stagnation, weak conflict with missing payoff, pacing loss of control and abrupt transitions, character inconsistency across the arc, thin/one-note characters without contrast, stiff emotion expression and abrupt relationship jumps, imbalanced cheats/power gifts, and settings that never land in concrete action. Alongside these, keep the engineering dimensions listed below (OOC, timeline coherence, information boundary, hook debt, cross-chapter repetition, lexical fatigue, length band, title fatigue, paragraph shape).
464
+
465
+ Sparse chapter_memo is legitimate. Breather / aftermath / transition chapters may ship a memo that only contains goal + a skeleton body — do NOT flag such memos as incomplete, and do NOT penalise the chapter for lacking content against sections the memo itself does not populate. Judge drift only against what the memo actually says.
466
+
467
+ If the chapter memo, rule stack, or supplied context specifies content proportions between lines (politics/romance, career/relationship, case/character, etc.), audit whether those lines appear as actual scenes, dialogue, action, or relationship movement. A line that is only summarized in one sentence counts as missing. Mark it critical only when the memo explicitly required it for this chapter.
468
+
469
+ Audit dimensions:
470
+ ${dimList}
471
+
472
+ Output format MUST be JSON:
473
+ {
474
+ "passed": true/false,
475
+ "overall_score": 0-100,
476
+ "issues": [
477
+ {
478
+ "severity": "critical|warning|info",
479
+ "category": "dimension name",
480
+ "description": "specific issue description",
481
+ "suggestion": "fix suggestion"
482
+ }
483
+ ],
484
+ "summary": "one-sentence audit conclusion"
485
+ }
486
+
487
+ passed is false ONLY when critical-severity issues exist.
488
+
489
+ overall_score calibration:
490
+ - 95-100: Publishable as-is, no noticeable issues
491
+ - 85-94: Minor blemishes but smooth reading, the reader won't break immersion
492
+ - 75-84: Noticeable problems but the story backbone holds, needs revision but not urgent
493
+ - 65-74: Multiple issues hurt the reading experience, pacing or continuity has gaps
494
+ - < 65: Structural breakdown, needs major rewrite
495
+ Score holistically — do not let a single minor issue tank the score.`
496
+ : `你是一位严格的${gp.name}网络小说结构审稿编辑。你只审完成度 + 结构,不审文笔。${protagonistBlock}${searchNote}
497
+
498
+ ## 审稿边界(硬约束)
499
+
500
+ 你不审文笔、不审排版、不审句式——这些归 Polisher。你发现的文笔问题只能以 severity="info" 标注供 Polisher 参考,不计入 reviewer 的 passed/overall_score,也绝不可标为 critical。
501
+
502
+ 你审 12 条结构类雷点:开篇拖沓/平淡、世界观模糊脱现实、人设矛盾、视角杂乱、主线偏离/停滞、冲突乏力爽点缺失、节奏失控过渡生硬、人设前后矛盾、人物单薄无反差、情感表达生硬/关系突兀、金手指失衡、设定无落地。同时保留工程维度(OOC、timeline 一致、信息越界、hook-debt、跨章重复、词汇疲劳、章节字数、标题疲劳、段落形状)。
503
+
504
+ 稀疏 memo 是合法状态。喘息章 / 后效章 / 过渡章的 memo 可以只有 goal + 骨架 body——此类 memo 不判 incomplete,也不能因为 memo 没写的段落就扣成稿的分。只按 memo 实际写出来的内容判偏离。
505
+
506
+ 如果章节备忘、规则栈或输入上下文明确指定多条剧情线的比例(权谋/感情、事业/恋爱、案件/人物等),要审它们是否真正落成了场景、对话、行动或关系变化。只用一句总结带过的线,视为缺失。只有当 memo 明确要求本章必须推进该线时,才标 critical。
507
+
508
+ 审查维度:
509
+ ${dimList}
510
+
511
+ 输出格式必须为 JSON:
512
+ {
513
+ "passed": true/false,
514
+ "overall_score": 0-100,
515
+ "issues": [
516
+ {
517
+ "severity": "critical|warning|info",
518
+ "category": "审查维度名称",
519
+ "description": "具体问题描述",
520
+ "suggestion": "修改建议"
521
+ }
522
+ ],
523
+ "summary": "一句话总结审查结论"
524
+ }
525
+
526
+ 只有当存在 critical 级别问题时,passed 才为 false。
527
+
528
+ overall_score 评分校准:
529
+ - 95-100:可直接发布,无明显问题
530
+ - 85-94:有小瑕疵但整体流畅可读,读者不会出戏
531
+ - 75-84:有明显问题但故事主干完整,需要修但不紧急
532
+ - 65-74:多处影响阅读体验的问题,节奏或连续性有断裂
533
+ - < 65:结构性问题,需要大幅重写
534
+ 综合评分,不要因为单一小问题大幅拉低分数。`;
535
+
536
+ const ledgerBlock = gp.numericalSystem
537
+ ? isEnglish
538
+ ? `\n## Resource Ledger\n${ledger}`
539
+ : `\n## 资源账本\n${ledger}`
540
+ : "";
541
+
542
+ // Smart context filtering for auditor — same logic as writer
543
+ const bookRulesForFilter = parsedRules?.rules ?? null;
544
+ const filteredSubplots = filterSubplots(subplotBoard);
545
+ const filteredArcs = filterEmotionalArcs(emotionalArcs, chapterNumber);
546
+ const filteredMatrix = filterCharacterMatrix(characterMatrix, volumeOutline, bookRulesForFilter?.protagonist?.name);
547
+ const filteredSummaries = filterSummaries(chapterSummaries, chapterNumber);
548
+ const filteredHooks = filterHooks(hooks);
549
+
550
+ const governedMemoryBlocks = options?.contextPackage
551
+ ? buildGovernedMemoryEvidenceBlocks(options.contextPackage, resolvedLanguage)
552
+ : undefined;
553
+
554
+ const hooksBlock = governedMemoryBlocks?.hooksBlock
555
+ ?? (filteredHooks !== "(文件不存在)"
556
+ ? isEnglish
557
+ ? `\n## Pending Hooks\n${filteredHooks}\n`
558
+ : `\n## 伏笔池\n${filteredHooks}\n`
559
+ : "");
560
+ const subplotBlock = filteredSubplots !== "(文件不存在)"
561
+ ? isEnglish
562
+ ? `\n## Subplot Board\n${filteredSubplots}\n`
563
+ : `\n## 支线进度板\n${filteredSubplots}\n`
564
+ : "";
565
+ const emotionalBlock = filteredArcs !== "(文件不存在)"
566
+ ? isEnglish
567
+ ? `\n## Emotional Arcs\n${filteredArcs}\n`
568
+ : `\n## 情感弧线\n${filteredArcs}\n`
569
+ : "";
570
+ const matrixBlock = filteredMatrix !== "(文件不存在)"
571
+ ? isEnglish
572
+ ? `\n## Character Interaction Matrix\n${filteredMatrix}\n`
573
+ : `\n## 角色交互矩阵\n${filteredMatrix}\n`
574
+ : "";
575
+ const summariesBlock = governedMemoryBlocks?.summariesBlock
576
+ ?? (filteredSummaries !== "(文件不存在)"
577
+ ? isEnglish
578
+ ? `\n## Chapter Summaries (for pacing checks)\n${filteredSummaries}\n`
579
+ : `\n## 章节摘要(用于节奏检查)\n${filteredSummaries}\n`
580
+ : "");
581
+ const volumeSummariesBlock = governedMemoryBlocks?.volumeSummariesBlock ?? "";
582
+
583
+ const canonBlock = hasParentCanon
584
+ ? isEnglish
585
+ ? `\n## Mainline Canon Reference (for spinoff audit)\n${parentCanon}\n`
586
+ : `\n## 正传正典参照(番外审查专用)\n${parentCanon}\n`
587
+ : "";
588
+
589
+ const fanficCanonBlock = hasFanficCanon
590
+ ? isEnglish
591
+ ? `\n## Fanfic Canon Reference (for fanfic audit)\n${fanficCanon}\n`
592
+ : `\n## 同人正典参照(同人审查专用)\n${fanficCanon}\n`
593
+ : "";
594
+
595
+ const memoBlock = options?.chapterMemo
596
+ ? isEnglish
597
+ ? `\n## Chapter Memo (for memo drift checks)\nGoal: ${options.chapterMemo.goal}\n\n${options.chapterMemo.body}\n`
598
+ : `\n## 章节备忘(用于 memo 偏离检测)\ngoal:${options.chapterMemo.goal}\n\n${options.chapterMemo.body}\n`
599
+ : "";
600
+ const reducedControlBlock = options?.chapterIntent && options.contextPackage && options.ruleStack
601
+ ? this.buildReducedControlBlock(options.chapterIntent, options.contextPackage, options.ruleStack, resolvedLanguage)
602
+ : "";
603
+ const styleGuideBlock = reducedControlBlock.length === 0
604
+ ? isEnglish
605
+ ? `\n## Style Guide\n${styleGuide}`
606
+ : `\n## 文风指南\n${styleGuide}`
607
+ : "";
608
+
609
+ const prevChapterBlock = previousChapter
610
+ ? isEnglish
611
+ ? `\n## Previous Chapter Full Text (for transition checks)\n${previousChapter}\n`
612
+ : `\n## 上一章全文(用于衔接检查)\n${previousChapter}\n`
613
+ : "";
614
+
615
+ const userPrompt = isEnglish
616
+ ? `Review chapter ${chapterNumber}.
617
+
618
+ ## Current State Card
619
+ ${currentState}
620
+ ${ledgerBlock}
621
+ ${hooksBlock}${volumeSummariesBlock}${subplotBlock}${emotionalBlock}${matrixBlock}${summariesBlock}${canonBlock}${fanficCanonBlock}${reducedControlBlock}${memoBlock}${prevChapterBlock}${styleGuideBlock}
622
+
623
+ ## Chapter Content Under Review
624
+ ${chapterContent}`
625
+ : `请审查第${chapterNumber}章。
626
+
627
+ ## 当前状态卡
628
+ ${currentState}
629
+ ${ledgerBlock}
630
+ ${hooksBlock}${volumeSummariesBlock}${subplotBlock}${emotionalBlock}${matrixBlock}${summariesBlock}${canonBlock}${fanficCanonBlock}${reducedControlBlock}${memoBlock}${prevChapterBlock}${styleGuideBlock}
631
+
632
+ ## 待审章节内容
633
+ ${chapterContent}`;
634
+
635
+ const chatMessages = [
636
+ { role: "system" as const, content: systemPrompt },
637
+ { role: "user" as const, content: userPrompt },
638
+ ];
639
+ const chatOptions = { temperature: options?.temperature ?? 0.3 };
640
+
641
+ // Use web search for fact verification when eraResearch is enabled
642
+ const response = gp.eraResearch
643
+ ? await this.chatWithSearch(chatMessages, chatOptions)
644
+ : await this.chat(chatMessages, chatOptions);
645
+
646
+ const result = this.parseAuditResult(response.content, resolvedLanguage);
647
+ return { ...result, tokenUsage: response.usage };
648
+ }
649
+
650
+ private parseAuditResult(content: string, language: PromptLanguage): AuditResult {
651
+ // Try multiple JSON extraction strategies (handles small/local models)
652
+
653
+ // Strategy 1: Find balanced JSON object (not greedy)
654
+ const balanced = this.extractBalancedJson(content);
655
+ if (balanced) {
656
+ const result = this.tryParseAuditJson(balanced, language);
657
+ if (result) return result;
658
+ }
659
+
660
+ // Strategy 2: Try the whole content as JSON (some models output pure JSON)
661
+ const trimmed = content.trim();
662
+ if (trimmed.startsWith("{")) {
663
+ const result = this.tryParseAuditJson(trimmed, language);
664
+ if (result) return result;
665
+ }
666
+
667
+ // Strategy 3: Look for ```json code blocks
668
+ const codeBlockMatch = content.match(/```(?:json)?\s*\n?([\s\S]*?)\n?```/);
669
+ if (codeBlockMatch) {
670
+ const result = this.tryParseAuditJson(codeBlockMatch[1]!.trim(), language);
671
+ if (result) return result;
672
+ }
673
+
674
+ // Strategy 4: Try to extract individual fields via regex (last resort fallback)
675
+ const passedMatch = content.match(/"passed"\s*:\s*(true|false)/);
676
+ const issuesMatch = content.match(/"issues"\s*:\s*\[([\s\S]*?)\]/);
677
+ const summaryMatch = content.match(/"summary"\s*:\s*"([^"]*)"/);
678
+ if (passedMatch) {
679
+ const issues: AuditIssue[] = [];
680
+ if (issuesMatch) {
681
+ // Try to parse individual issue objects
682
+ const issuePattern = /\{[^{}]*"severity"\s*:\s*"[^"]*"[^{}]*\}/g;
683
+ let match: RegExpExecArray | null;
684
+ while ((match = issuePattern.exec(issuesMatch[1]!)) !== null) {
685
+ try {
686
+ const issue = JSON.parse(match[0]);
687
+ issues.push({
688
+ severity: issue.severity ?? "warning",
689
+ category: issue.category ?? (language === "en" ? "Uncategorized" : "未分类"),
690
+ description: issue.description ?? "",
691
+ suggestion: issue.suggestion ?? "",
692
+ });
693
+ } catch {
694
+ // skip malformed individual issue
695
+ }
696
+ }
697
+ }
698
+ return {
699
+ passed: passedMatch[1] === "true",
700
+ issues,
701
+ summary: summaryMatch?.[1] ?? "",
702
+ };
703
+ }
704
+
705
+ return {
706
+ passed: false,
707
+ issues: [{
708
+ severity: "critical",
709
+ category: language === "en" ? "System Error" : "系统错误",
710
+ description: language === "en"
711
+ ? "Audit output format was invalid and could not be parsed as JSON."
712
+ : "审稿输出格式异常,无法解析为 JSON",
713
+ suggestion: language === "en"
714
+ ? "The model may not support reliable structured output. Try a stronger model or inspect the API response format."
715
+ : "可能是模型不支持结构化输出。尝试换一个更大的模型,或检查 API 返回格式。",
716
+ }],
717
+ summary: language === "en" ? "Audit output parsing failed" : "审稿输出解析失败",
718
+ };
719
+ }
720
+
721
+ private buildReducedControlBlock(
722
+ chapterIntent: string,
723
+ contextPackage: ContextPackage,
724
+ ruleStack: RuleStack,
725
+ language: PromptLanguage,
726
+ ): string {
727
+ const selectedContext = contextPackage.selectedContext
728
+ .map((entry) => `- ${entry.source}: ${entry.reason}${entry.excerpt ? ` | ${entry.excerpt}` : ""}`)
729
+ .join("\n");
730
+ const overrides = ruleStack.activeOverrides.length > 0
731
+ ? ruleStack.activeOverrides
732
+ .map((override) => `- ${override.from} -> ${override.to}: ${override.reason} (${override.target})`)
733
+ .join("\n")
734
+ : "- none";
735
+
736
+ return language === "en"
737
+ ? `\n## Chapter Control Inputs (compiled by Planner/Composer)
738
+ ${chapterIntent}
739
+
740
+ ### Selected Context
741
+ ${selectedContext || "- none"}
742
+
743
+ ### Rule Stack
744
+ - Hard guardrails: ${ruleStack.sections.hard.join(", ") || "(none)"}
745
+ - Soft constraints: ${ruleStack.sections.soft.join(", ") || "(none)"}
746
+ - Diagnostic rules: ${ruleStack.sections.diagnostic.join(", ") || "(none)"}
747
+
748
+ ### Active Overrides
749
+ ${overrides}\n`
750
+ : `\n## 本章控制输入(由 Planner/Composer 编译)
751
+ ${chapterIntent}
752
+
753
+ ### 已选上下文
754
+ ${selectedContext || "- none"}
755
+
756
+ ### 规则栈
757
+ - 硬护栏:${ruleStack.sections.hard.join("、") || "(无)"}
758
+ - 软约束:${ruleStack.sections.soft.join("、") || "(无)"}
759
+ - 诊断规则:${ruleStack.sections.diagnostic.join("、") || "(无)"}
760
+
761
+ ### 当前覆盖
762
+ ${overrides}\n`;
763
+ }
764
+
765
+ private extractBalancedJson(text: string): string | null {
766
+ const start = text.indexOf("{");
767
+ if (start === -1) return null;
768
+ let depth = 0;
769
+ for (let i = start; i < text.length; i++) {
770
+ if (text[i] === "{") depth++;
771
+ if (text[i] === "}") depth--;
772
+ if (depth === 0) return text.slice(start, i + 1);
773
+ }
774
+ return null;
775
+ }
776
+
777
+ private tryParseAuditJson(json: string, language: PromptLanguage = "zh"): AuditResult | null {
778
+ try {
779
+ const parsed = JSON.parse(json);
780
+ if (typeof parsed.passed !== "boolean" && parsed.passed !== undefined) return null;
781
+ const rawScore = parsed.overall_score ?? parsed.overallScore;
782
+ const overallScore = typeof rawScore === "number" && Number.isFinite(rawScore)
783
+ ? Math.round(Math.max(0, Math.min(100, rawScore)))
784
+ : undefined;
785
+ return {
786
+ passed: Boolean(parsed.passed ?? false),
787
+ issues: Array.isArray(parsed.issues)
788
+ ? parsed.issues.map((i: Record<string, unknown>) => ({
789
+ severity: (i.severity as string) ?? "warning",
790
+ category: (i.category as string) ?? (language === "en" ? "Uncategorized" : "未分类"),
791
+ description: (i.description as string) ?? "",
792
+ suggestion: (i.suggestion as string) ?? "",
793
+ }))
794
+ : [],
795
+ summary: String(parsed.summary ?? ""),
796
+ overallScore,
797
+ };
798
+ } catch {
799
+ return null;
800
+ }
801
+ }
802
+
803
+ private async loadPreviousChapter(bookDir: string, currentChapter: number): Promise<string> {
804
+ if (currentChapter <= 1) return "";
805
+ const chaptersDir = join(bookDir, "chapters");
806
+ try {
807
+ const files = await readdir(chaptersDir);
808
+ const paddedPrev = String(currentChapter - 1).padStart(4, "0");
809
+ const prevFile = files.find((f) => f.startsWith(paddedPrev) && f.endsWith(".md"));
810
+ if (!prevFile) return "";
811
+ return await readFile(join(chaptersDir, prevFile), "utf-8");
812
+ } catch {
813
+ return "";
814
+ }
815
+ }
816
+
817
+ private async readFileSafe(path: string): Promise<string> {
818
+ try {
819
+ return await readFile(path, "utf-8");
820
+ } catch {
821
+ return "(文件不存在)";
822
+ }
823
+ }
824
+ }