@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,1311 @@
1
+ import { describe, expect, it, beforeEach, afterEach } from "vitest";
2
+ import { mkdtemp, rm } from "node:fs/promises";
3
+ import { join } from "node:path";
4
+ import { tmpdir } from "node:os";
5
+ import { appendTranscriptEvent } from "../interaction/session-transcript.js";
6
+ import {
7
+ adaptRestoredAgentMessagesForModel,
8
+ deriveBookSessionFromTranscript,
9
+ restoreAgentMessagesFromTranscript,
10
+ TOOL_RESULT_BRIDGE_TEXT,
11
+ } from "../interaction/session-transcript-restore.js";
12
+ import type { MessageEvent } from "../interaction/session-transcript-schema.js";
13
+
14
+ const usage = {
15
+ input: 0,
16
+ output: 0,
17
+ cacheRead: 0,
18
+ cacheWrite: 0,
19
+ totalTokens: 0,
20
+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
21
+ };
22
+
23
+ describe("session transcript restore", () => {
24
+ let projectRoot: string;
25
+
26
+ beforeEach(async () => {
27
+ projectRoot = await mkdtemp(join(tmpdir(), "inkos-restore-"));
28
+ });
29
+
30
+ afterEach(async () => {
31
+ await rm(projectRoot, { recursive: true, force: true });
32
+ });
33
+
34
+ it("只恢复已 committed request 内的 message", async () => {
35
+ await appendTranscriptEvent(projectRoot, {
36
+ type: "request_started",
37
+ version: 1,
38
+ sessionId: "s1",
39
+ requestId: "r1",
40
+ seq: 1,
41
+ timestamp: 1,
42
+ input: "hi",
43
+ });
44
+ await appendTranscriptEvent(projectRoot, {
45
+ type: "message",
46
+ version: 1,
47
+ sessionId: "s1",
48
+ requestId: "r1",
49
+ uuid: "u1",
50
+ parentUuid: null,
51
+ seq: 2,
52
+ role: "user",
53
+ timestamp: 2,
54
+ message: { role: "user", content: "hi", timestamp: 2 },
55
+ } as MessageEvent);
56
+ await appendTranscriptEvent(projectRoot, {
57
+ type: "request_committed",
58
+ version: 1,
59
+ sessionId: "s1",
60
+ requestId: "r1",
61
+ seq: 3,
62
+ timestamp: 3,
63
+ });
64
+ await appendTranscriptEvent(projectRoot, {
65
+ type: "request_started",
66
+ version: 1,
67
+ sessionId: "s1",
68
+ requestId: "r2",
69
+ seq: 4,
70
+ timestamp: 4,
71
+ input: "lost",
72
+ });
73
+ await appendTranscriptEvent(projectRoot, {
74
+ type: "message",
75
+ version: 1,
76
+ sessionId: "s1",
77
+ requestId: "r2",
78
+ uuid: "u2",
79
+ parentUuid: "u1",
80
+ seq: 5,
81
+ role: "user",
82
+ timestamp: 5,
83
+ message: { role: "user", content: "lost", timestamp: 5 },
84
+ } as MessageEvent);
85
+
86
+ const restored = await restoreAgentMessagesFromTranscript(projectRoot, "s1");
87
+
88
+ expect(restored).toHaveLength(1);
89
+ expect(restored[0]).toMatchObject({ role: "user", content: "hi" });
90
+ });
91
+
92
+ it("保留 committed toolResult 和 assistant thinking signature", async () => {
93
+ await appendTranscriptEvent(projectRoot, {
94
+ type: "request_started",
95
+ version: 1,
96
+ sessionId: "s1",
97
+ requestId: "r1",
98
+ seq: 1,
99
+ timestamp: 1,
100
+ input: "tool",
101
+ });
102
+ await appendTranscriptEvent(projectRoot, {
103
+ type: "message",
104
+ version: 1,
105
+ sessionId: "s1",
106
+ requestId: "r1",
107
+ uuid: "a1",
108
+ parentUuid: null,
109
+ seq: 2,
110
+ role: "assistant",
111
+ timestamp: 2,
112
+ toolCallId: "tool-1",
113
+ message: {
114
+ role: "assistant",
115
+ content: [
116
+ { type: "thinking", thinking: "需要查资料", signature: "sig" },
117
+ { type: "toolCall", id: "tool-1", name: "read", arguments: { path: "a.md" } },
118
+ ],
119
+ api: "anthropic-messages",
120
+ provider: "anthropic",
121
+ model: "claude",
122
+ usage,
123
+ stopReason: "tool_use",
124
+ timestamp: 2,
125
+ },
126
+ } as MessageEvent);
127
+ await appendTranscriptEvent(projectRoot, {
128
+ type: "message",
129
+ version: 1,
130
+ sessionId: "s1",
131
+ requestId: "r1",
132
+ uuid: "t1",
133
+ parentUuid: "a1",
134
+ seq: 3,
135
+ role: "toolResult",
136
+ timestamp: 3,
137
+ toolCallId: "tool-1",
138
+ sourceToolAssistantUuid: "a1",
139
+ message: {
140
+ role: "toolResult",
141
+ toolCallId: "tool-1",
142
+ toolName: "read",
143
+ content: [{ type: "text", text: "资料" }],
144
+ details: { path: "a.md" },
145
+ isError: false,
146
+ timestamp: 3,
147
+ },
148
+ } as MessageEvent);
149
+ await appendTranscriptEvent(projectRoot, {
150
+ type: "request_committed",
151
+ version: 1,
152
+ sessionId: "s1",
153
+ requestId: "r1",
154
+ seq: 4,
155
+ timestamp: 4,
156
+ });
157
+
158
+ const restored = await restoreAgentMessagesFromTranscript(projectRoot, "s1");
159
+
160
+ expect(restored).toHaveLength(2);
161
+ expect(restored[0]).toMatchObject({
162
+ role: "assistant",
163
+ content: [
164
+ { type: "thinking", thinking: "需要查资料", signature: "sig" },
165
+ { type: "toolCall", id: "tool-1" },
166
+ ],
167
+ });
168
+ expect(restored[1]).toMatchObject({ role: "toolResult", toolCallId: "tool-1", toolName: "read" });
169
+ expect(JSON.stringify(restored)).not.toContain(TOOL_RESULT_BRIDGE_TEXT);
170
+ });
171
+
172
+ it("恢复中断工具轮次时只清理空 assistant,不在 raw restore 阶段补 bridge", async () => {
173
+ await appendTranscriptEvent(projectRoot, {
174
+ type: "request_started",
175
+ version: 1,
176
+ sessionId: "s1",
177
+ requestId: "r1",
178
+ seq: 1,
179
+ timestamp: 1,
180
+ input: "tool",
181
+ });
182
+ await appendTranscriptEvent(projectRoot, {
183
+ type: "message",
184
+ version: 1,
185
+ sessionId: "s1",
186
+ requestId: "r1",
187
+ uuid: "u1",
188
+ parentUuid: null,
189
+ seq: 2,
190
+ role: "user",
191
+ timestamp: 2,
192
+ message: { role: "user", content: "tool", timestamp: 2 },
193
+ } as MessageEvent);
194
+ await appendTranscriptEvent(projectRoot, {
195
+ type: "message",
196
+ version: 1,
197
+ sessionId: "s1",
198
+ requestId: "r1",
199
+ uuid: "a1",
200
+ parentUuid: "u1",
201
+ seq: 3,
202
+ role: "assistant",
203
+ timestamp: 3,
204
+ toolCallId: "tool-1",
205
+ message: {
206
+ role: "assistant",
207
+ content: [{ type: "toolCall", id: "tool-1", name: "read", arguments: { path: "a.md" } }],
208
+ api: "openai-completions",
209
+ provider: "google",
210
+ model: "gemini-pro-latest",
211
+ usage,
212
+ stopReason: "toolUse",
213
+ timestamp: 3,
214
+ },
215
+ } as MessageEvent);
216
+ await appendTranscriptEvent(projectRoot, {
217
+ type: "message",
218
+ version: 1,
219
+ sessionId: "s1",
220
+ requestId: "r1",
221
+ uuid: "t1",
222
+ parentUuid: "a1",
223
+ seq: 4,
224
+ role: "toolResult",
225
+ timestamp: 4,
226
+ toolCallId: "tool-1",
227
+ sourceToolAssistantUuid: "a1",
228
+ message: {
229
+ role: "toolResult",
230
+ toolCallId: "tool-1",
231
+ toolName: "read",
232
+ content: [{ type: "text", text: "资料" }],
233
+ isError: false,
234
+ timestamp: 4,
235
+ },
236
+ } as MessageEvent);
237
+ await appendTranscriptEvent(projectRoot, {
238
+ type: "message",
239
+ version: 1,
240
+ sessionId: "s1",
241
+ requestId: "r1",
242
+ uuid: "a2",
243
+ parentUuid: "t1",
244
+ seq: 5,
245
+ role: "assistant",
246
+ timestamp: 5,
247
+ message: {
248
+ role: "assistant",
249
+ content: [],
250
+ api: "openai-completions",
251
+ provider: "google",
252
+ model: "gemini-pro-latest",
253
+ usage,
254
+ stopReason: "error",
255
+ errorMessage: "400 status code",
256
+ timestamp: 5,
257
+ },
258
+ } as MessageEvent);
259
+ await appendTranscriptEvent(projectRoot, {
260
+ type: "request_committed",
261
+ version: 1,
262
+ sessionId: "s1",
263
+ requestId: "r1",
264
+ seq: 6,
265
+ timestamp: 6,
266
+ });
267
+ await appendTranscriptEvent(projectRoot, {
268
+ type: "request_started",
269
+ version: 1,
270
+ sessionId: "s1",
271
+ requestId: "r2",
272
+ seq: 7,
273
+ timestamp: 7,
274
+ input: "继续",
275
+ });
276
+ await appendTranscriptEvent(projectRoot, {
277
+ type: "message",
278
+ version: 1,
279
+ sessionId: "s1",
280
+ requestId: "r2",
281
+ uuid: "u2",
282
+ parentUuid: "a2",
283
+ seq: 8,
284
+ role: "user",
285
+ timestamp: 8,
286
+ message: { role: "user", content: "继续", timestamp: 8 },
287
+ } as MessageEvent);
288
+ await appendTranscriptEvent(projectRoot, {
289
+ type: "request_committed",
290
+ version: 1,
291
+ sessionId: "s1",
292
+ requestId: "r2",
293
+ seq: 9,
294
+ timestamp: 9,
295
+ });
296
+
297
+ const restored = await restoreAgentMessagesFromTranscript(projectRoot, "s1");
298
+
299
+ expect(restored.map((message) => message.role)).toEqual([
300
+ "user",
301
+ "assistant",
302
+ "toolResult",
303
+ "user",
304
+ ]);
305
+ expect(JSON.stringify(restored)).not.toContain(TOOL_RESULT_BRIDGE_TEXT);
306
+ });
307
+
308
+ it("移除最后 assistant message 的 trailing thinking block", async () => {
309
+ await appendTranscriptEvent(projectRoot, {
310
+ type: "request_started",
311
+ version: 1,
312
+ sessionId: "s1",
313
+ requestId: "r1",
314
+ seq: 1,
315
+ timestamp: 1,
316
+ input: "hi",
317
+ });
318
+ await appendTranscriptEvent(projectRoot, {
319
+ type: "message",
320
+ version: 1,
321
+ sessionId: "s1",
322
+ requestId: "r1",
323
+ uuid: "a1",
324
+ parentUuid: null,
325
+ seq: 2,
326
+ role: "assistant",
327
+ timestamp: 2,
328
+ message: {
329
+ role: "assistant",
330
+ content: [
331
+ { type: "text", text: "回答" },
332
+ { type: "thinking", thinking: "尾部", signature: "sig" },
333
+ ],
334
+ api: "anthropic-messages",
335
+ provider: "anthropic",
336
+ model: "claude",
337
+ usage,
338
+ stopReason: "stop",
339
+ timestamp: 2,
340
+ },
341
+ } as MessageEvent);
342
+ await appendTranscriptEvent(projectRoot, {
343
+ type: "request_committed",
344
+ version: 1,
345
+ sessionId: "s1",
346
+ requestId: "r1",
347
+ seq: 3,
348
+ timestamp: 3,
349
+ });
350
+
351
+ const restored = await restoreAgentMessagesFromTranscript(projectRoot, "s1");
352
+
353
+ expect((restored[0] as any).content).toEqual([{ type: "text", text: "回答" }]);
354
+ });
355
+
356
+ it("跨模型恢复时移除 provider-specific thinking,但保留正文", () => {
357
+ const messages = [
358
+ {
359
+ role: "assistant",
360
+ content: [
361
+ { type: "thinking", thinking: "DeepSeek reasoning", thinkingSignature: "reasoning_content" },
362
+ { type: "text", text: "可见回答" },
363
+ ],
364
+ api: "openai-completions",
365
+ provider: "openai",
366
+ model: "deepseek-v4-pro",
367
+ usage,
368
+ stopReason: "stop",
369
+ timestamp: 1,
370
+ },
371
+ ] as any;
372
+
373
+ const adapted = adaptRestoredAgentMessagesForModel(messages, {
374
+ api: "openai-completions",
375
+ provider: "openai",
376
+ id: "gemini-pro-latest",
377
+ });
378
+
379
+ expect((adapted[0] as any).content).toEqual([{ type: "text", text: "可见回答" }]);
380
+ });
381
+
382
+ it("同模型恢复时保留 thinking continuity", () => {
383
+ const messages = [
384
+ {
385
+ role: "assistant",
386
+ content: [
387
+ { type: "thinking", thinking: "DeepSeek reasoning", thinkingSignature: "reasoning_content" },
388
+ { type: "text", text: "可见回答" },
389
+ ],
390
+ api: "openai-completions",
391
+ provider: "openai",
392
+ model: "deepseek-v4-pro",
393
+ usage,
394
+ stopReason: "stop",
395
+ timestamp: 1,
396
+ },
397
+ ] as any;
398
+
399
+ const adapted = adaptRestoredAgentMessagesForModel(messages, {
400
+ api: "openai-completions",
401
+ provider: "openai",
402
+ id: "deepseek-v4-pro",
403
+ });
404
+
405
+ expect((adapted[0] as any).content).toEqual(messages[0].content);
406
+ });
407
+
408
+ it("同模型恢复时保留 reasoning_content 和原生 toolResult 连续性", () => {
409
+ const messages = [
410
+ {
411
+ role: "assistant",
412
+ content: [
413
+ { type: "thinking", thinking: "Need a file", thinkingSignature: "reasoning_content" },
414
+ { type: "toolCall", id: "tool-1", name: "read", arguments: { path: "story.md" } },
415
+ ],
416
+ api: "openai-completions",
417
+ provider: "openai",
418
+ model: "deepseek-v4-pro",
419
+ usage,
420
+ stopReason: "toolUse",
421
+ timestamp: 1,
422
+ },
423
+ {
424
+ role: "toolResult",
425
+ toolCallId: "tool-1",
426
+ toolName: "read",
427
+ content: [{ type: "text", text: "资料" }],
428
+ isError: false,
429
+ timestamp: 2,
430
+ },
431
+ ] as any;
432
+
433
+ const adapted = adaptRestoredAgentMessagesForModel(messages, {
434
+ api: "openai-completions",
435
+ provider: "openai",
436
+ id: "deepseek-v4-pro",
437
+ });
438
+
439
+ expect(adapted).toEqual(messages);
440
+ });
441
+
442
+ it("does not add synthetic toolResult bridge when target model does not require it", () => {
443
+ const messages = [
444
+ {
445
+ role: "assistant",
446
+ content: [{ type: "toolCall", id: "tool-1", name: "read", arguments: {} }],
447
+ api: "anthropic-messages",
448
+ provider: "anthropic",
449
+ model: "claude",
450
+ usage,
451
+ stopReason: "toolUse",
452
+ timestamp: 1,
453
+ },
454
+ {
455
+ role: "toolResult",
456
+ toolCallId: "tool-1",
457
+ toolName: "read",
458
+ content: [{ type: "text", text: "result" }],
459
+ isError: false,
460
+ timestamp: 2,
461
+ },
462
+ ] as any[];
463
+
464
+ const adapted = adaptRestoredAgentMessagesForModel(messages, {
465
+ api: "anthropic-messages",
466
+ provider: "anthropic",
467
+ id: "claude",
468
+ });
469
+
470
+ expect(JSON.stringify(adapted)).not.toContain(TOOL_RESULT_BRIDGE_TEXT);
471
+ });
472
+
473
+ it("adds synthetic toolResult bridge when target model compat requires it", () => {
474
+ const messages = [
475
+ {
476
+ role: "assistant",
477
+ content: [{ type: "toolCall", id: "tool-1", name: "read", arguments: {} }],
478
+ api: "openai-completions",
479
+ provider: "openai",
480
+ model: "deepseek-v4-pro",
481
+ usage,
482
+ stopReason: "toolUse",
483
+ timestamp: 1,
484
+ },
485
+ {
486
+ role: "toolResult",
487
+ toolCallId: "tool-1",
488
+ toolName: "read",
489
+ content: [{ type: "text", text: "result" }],
490
+ isError: false,
491
+ timestamp: 2,
492
+ },
493
+ ] as any[];
494
+
495
+ const adapted = adaptRestoredAgentMessagesForModel(messages, {
496
+ api: "openai-completions",
497
+ provider: "openai",
498
+ id: "deepseek-v4-pro",
499
+ compat: { requiresAssistantAfterToolResult: true },
500
+ });
501
+
502
+ expect(JSON.stringify(adapted)).toContain(TOOL_RESULT_BRIDGE_TEXT);
503
+ });
504
+
505
+ it("跨模型恢复时把原生工具回合降级为 user 文本", () => {
506
+ const messages = [
507
+ {
508
+ role: "assistant",
509
+ content: [
510
+ { type: "toolCall", id: "tool-1", name: "read", arguments: { path: "story.md" } },
511
+ ],
512
+ api: "openai-completions",
513
+ provider: "openai",
514
+ model: "gemini-pro-latest",
515
+ usage,
516
+ stopReason: "toolUse",
517
+ timestamp: 1,
518
+ },
519
+ {
520
+ role: "toolResult",
521
+ toolCallId: "tool-1",
522
+ toolName: "read",
523
+ content: [{ type: "text", text: "资料" }],
524
+ isError: false,
525
+ timestamp: 2,
526
+ },
527
+ {
528
+ role: "assistant",
529
+ content: [{ type: "text", text: "I have processed the tool results." }],
530
+ api: "openai-completions",
531
+ provider: "inkos",
532
+ model: "synthetic-tool-result-bridge",
533
+ usage,
534
+ stopReason: "stop",
535
+ timestamp: 3,
536
+ },
537
+ ] as any;
538
+
539
+ const adapted = adaptRestoredAgentMessagesForModel(messages, {
540
+ api: "openai-completions",
541
+ provider: "openai",
542
+ id: "deepseek-v4-pro",
543
+ });
544
+
545
+ expect(JSON.stringify(adapted)).not.toContain("\"toolCall\"");
546
+ expect(adapted.some((message: any) => message.role === "toolResult")).toBe(false);
547
+ expect(adapted).toEqual([
548
+ expect.objectContaining({
549
+ role: "user",
550
+ content: expect.stringContaining("[Tool results]"),
551
+ }),
552
+ ]);
553
+ expect(JSON.stringify(adapted)).toContain("read");
554
+ expect(JSON.stringify(adapted)).toContain("tool-1");
555
+ expect(JSON.stringify(adapted)).toContain("资料");
556
+ expect(JSON.stringify(adapted)).not.toContain("I have processed the tool results.");
557
+ });
558
+
559
+ it("native Google 同协议恢复时保留 thinking signature 和原生工具回合", () => {
560
+ const messages = [
561
+ {
562
+ role: "assistant",
563
+ content: [
564
+ { type: "thinking", thinking: "plan", thinkingSignature: "google-signature" },
565
+ { type: "toolCall", id: "tool-1", name: "ls", arguments: { subdir: "story/roles" } },
566
+ ],
567
+ api: "google-generative-ai",
568
+ provider: "google",
569
+ model: "gemini-pro-latest",
570
+ usage,
571
+ stopReason: "toolUse",
572
+ timestamp: 1,
573
+ },
574
+ {
575
+ role: "toolResult",
576
+ toolCallId: "tool-1",
577
+ toolName: "ls",
578
+ content: [{ type: "text", text: "主要角色/\n次要角色/" }],
579
+ isError: false,
580
+ timestamp: 2,
581
+ },
582
+ ] as any;
583
+
584
+ const adapted = adaptRestoredAgentMessagesForModel(messages, {
585
+ api: "google-generative-ai",
586
+ provider: "google",
587
+ id: "gemini-pro-latest",
588
+ });
589
+
590
+ expect(adapted).toEqual(messages);
591
+ expect(JSON.stringify(adapted)).toContain("google-signature");
592
+ });
593
+
594
+ it("切到 native Google 时把旧 OpenAI-compatible Gemini 工具回合文本化", () => {
595
+ const messages = [
596
+ {
597
+ role: "assistant",
598
+ content: [{ type: "toolCall", id: "tool-1", name: "ls", arguments: { subdir: "story/roles" } }],
599
+ api: "openai-completions",
600
+ provider: "openai",
601
+ model: "gemini-pro-latest",
602
+ usage,
603
+ stopReason: "toolUse",
604
+ timestamp: 1,
605
+ },
606
+ {
607
+ role: "toolResult",
608
+ toolCallId: "tool-1",
609
+ toolName: "ls",
610
+ content: [{ type: "text", text: "主要角色/" }],
611
+ isError: false,
612
+ timestamp: 2,
613
+ },
614
+ ] as any;
615
+
616
+ const adapted = adaptRestoredAgentMessagesForModel(messages, {
617
+ api: "google-generative-ai",
618
+ provider: "google",
619
+ id: "gemini-pro-latest",
620
+ });
621
+
622
+ const body = JSON.stringify(adapted);
623
+ expect(body).not.toContain("\"toolCall\"");
624
+ expect(adapted.some((message: any) => message.role === "toolResult")).toBe(false);
625
+ expect(adapted).toEqual([
626
+ expect.objectContaining({
627
+ role: "user",
628
+ content: expect.stringContaining("[Tool results]"),
629
+ }),
630
+ ]);
631
+ expect(body).toContain("ls");
632
+ expect(body).toContain("主要角色");
633
+ });
634
+
635
+ it("切到 native Google 时丢弃 DeepSeek reasoning_content 并文本化工具结果", () => {
636
+ const messages = [
637
+ {
638
+ role: "assistant",
639
+ content: [
640
+ { type: "thinking", thinking: "deepseek reasoning", thinkingSignature: "reasoning_content" },
641
+ { type: "text", text: "先看角色。" },
642
+ { type: "toolCall", id: "tool-1", name: "read", arguments: { path: "story/roles/林默.md" } },
643
+ ],
644
+ api: "openai-completions",
645
+ provider: "openai",
646
+ model: "deepseek-v4-pro",
647
+ usage,
648
+ stopReason: "toolUse",
649
+ timestamp: 1,
650
+ },
651
+ {
652
+ role: "toolResult",
653
+ toolCallId: "tool-1",
654
+ toolName: "read",
655
+ content: [{ type: "text", text: "林默资料" }],
656
+ isError: false,
657
+ timestamp: 2,
658
+ },
659
+ ] as any;
660
+
661
+ const adapted = adaptRestoredAgentMessagesForModel(messages, {
662
+ api: "google-generative-ai",
663
+ provider: "google",
664
+ id: "gemini-pro-latest",
665
+ });
666
+
667
+ const body = JSON.stringify(adapted);
668
+ expect(body).not.toContain("reasoning_content");
669
+ expect(body).not.toContain("deepseek reasoning");
670
+ expect(body).not.toContain("\"toolCall\"");
671
+ expect(body).toContain("先看角色。");
672
+ expect(body).toContain("[Tool results]");
673
+ expect(body).toContain("林默资料");
674
+ });
675
+
676
+ it("派生 BookSession 时跳过没有正文的 assistant tool-use message", async () => {
677
+ await appendTranscriptEvent(projectRoot, {
678
+ type: "session_created",
679
+ version: 1,
680
+ sessionId: "s1",
681
+ seq: 1,
682
+ timestamp: 1,
683
+ bookId: null,
684
+ title: null,
685
+ createdAt: 1,
686
+ updatedAt: 1,
687
+ });
688
+ await appendTranscriptEvent(projectRoot, {
689
+ type: "request_started",
690
+ version: 1,
691
+ sessionId: "s1",
692
+ requestId: "r1",
693
+ seq: 2,
694
+ timestamp: 2,
695
+ input: "你好",
696
+ });
697
+ await appendTranscriptEvent(projectRoot, {
698
+ type: "message",
699
+ version: 1,
700
+ sessionId: "s1",
701
+ requestId: "r1",
702
+ uuid: "u1",
703
+ parentUuid: null,
704
+ seq: 3,
705
+ role: "user",
706
+ timestamp: 3,
707
+ message: { role: "user", content: "你好", timestamp: 3 },
708
+ } as MessageEvent);
709
+ await appendTranscriptEvent(projectRoot, {
710
+ type: "message",
711
+ version: 1,
712
+ sessionId: "s1",
713
+ requestId: "r1",
714
+ uuid: "a1",
715
+ parentUuid: "u1",
716
+ seq: 4,
717
+ role: "assistant",
718
+ timestamp: 4,
719
+ message: {
720
+ role: "assistant",
721
+ content: [
722
+ { type: "thinking", thinking: "内部推理" },
723
+ { type: "toolCall", id: "read-1", name: "read", arguments: { path: "books/a.md" } },
724
+ ],
725
+ api: "openai-completions",
726
+ provider: "google",
727
+ model: "gemini-pro-latest",
728
+ usage,
729
+ stopReason: "toolUse",
730
+ timestamp: 4,
731
+ },
732
+ } as MessageEvent);
733
+ await appendTranscriptEvent(projectRoot, {
734
+ type: "request_committed",
735
+ version: 1,
736
+ sessionId: "s1",
737
+ requestId: "r1",
738
+ seq: 5,
739
+ timestamp: 5,
740
+ });
741
+
742
+ const session = await deriveBookSessionFromTranscript(projectRoot, "s1");
743
+
744
+ expect(session?.messages).toEqual([{ role: "user", content: "你好", timestamp: 3 }]);
745
+ });
746
+
747
+ it("从 transcript 派生 BookSession UI 视图", async () => {
748
+ await appendTranscriptEvent(projectRoot, {
749
+ type: "session_created",
750
+ version: 1,
751
+ sessionId: "s1",
752
+ seq: 1,
753
+ timestamp: 1,
754
+ bookId: "book-a",
755
+ title: null,
756
+ createdAt: 1,
757
+ updatedAt: 1,
758
+ });
759
+ await appendTranscriptEvent(projectRoot, {
760
+ type: "request_started",
761
+ version: 1,
762
+ sessionId: "s1",
763
+ requestId: "r1",
764
+ seq: 2,
765
+ timestamp: 2,
766
+ input: "第一条问题",
767
+ });
768
+ await appendTranscriptEvent(projectRoot, {
769
+ type: "message",
770
+ version: 1,
771
+ sessionId: "s1",
772
+ requestId: "r1",
773
+ uuid: "u1",
774
+ parentUuid: null,
775
+ seq: 3,
776
+ role: "user",
777
+ timestamp: 3,
778
+ message: { role: "user", content: "第一条问题", timestamp: 3 },
779
+ } as MessageEvent);
780
+ await appendTranscriptEvent(projectRoot, {
781
+ type: "message",
782
+ version: 1,
783
+ sessionId: "s1",
784
+ requestId: "r1",
785
+ uuid: "a1",
786
+ parentUuid: "u1",
787
+ seq: 4,
788
+ role: "assistant",
789
+ timestamp: 4,
790
+ message: {
791
+ role: "assistant",
792
+ content: [
793
+ { type: "thinking", thinking: "思考" },
794
+ { type: "text", text: "回答" },
795
+ ],
796
+ api: "anthropic-messages",
797
+ provider: "anthropic",
798
+ model: "claude",
799
+ usage,
800
+ stopReason: "stop",
801
+ timestamp: 4,
802
+ },
803
+ } as MessageEvent);
804
+ await appendTranscriptEvent(projectRoot, {
805
+ type: "request_committed",
806
+ version: 1,
807
+ sessionId: "s1",
808
+ requestId: "r1",
809
+ seq: 5,
810
+ timestamp: 5,
811
+ });
812
+
813
+ const session = await deriveBookSessionFromTranscript(projectRoot, "s1");
814
+
815
+ expect(session).toMatchObject({
816
+ sessionId: "s1",
817
+ bookId: "book-a",
818
+ title: "第一条问题",
819
+ messages: [
820
+ { role: "user", content: "第一条问题" },
821
+ { role: "assistant", content: "回答", thinking: "思考" },
822
+ ],
823
+ });
824
+ });
825
+
826
+ it("从 transcript 派生 BookSession UI 工具执行记录", async () => {
827
+ await appendTranscriptEvent(projectRoot, {
828
+ type: "session_created",
829
+ version: 1,
830
+ sessionId: "s1",
831
+ seq: 1,
832
+ timestamp: 1,
833
+ bookId: "book-a",
834
+ title: null,
835
+ createdAt: 1,
836
+ updatedAt: 1,
837
+ });
838
+ await appendTranscriptEvent(projectRoot, {
839
+ type: "request_started",
840
+ version: 1,
841
+ sessionId: "s1",
842
+ requestId: "r1",
843
+ seq: 2,
844
+ timestamp: 2,
845
+ input: "查看角色目录",
846
+ });
847
+ await appendTranscriptEvent(projectRoot, {
848
+ type: "message",
849
+ version: 1,
850
+ sessionId: "s1",
851
+ requestId: "r1",
852
+ uuid: "u1",
853
+ parentUuid: null,
854
+ seq: 3,
855
+ role: "user",
856
+ timestamp: 3,
857
+ message: { role: "user", content: "查看角色目录", timestamp: 3 },
858
+ } as MessageEvent);
859
+ await appendTranscriptEvent(projectRoot, {
860
+ type: "message",
861
+ version: 1,
862
+ sessionId: "s1",
863
+ requestId: "r1",
864
+ uuid: "a1",
865
+ parentUuid: "u1",
866
+ seq: 4,
867
+ role: "assistant",
868
+ timestamp: 4,
869
+ toolCallId: "ls-1",
870
+ message: {
871
+ role: "assistant",
872
+ content: [
873
+ { type: "thinking", thinking: "先列目录" },
874
+ { type: "toolCall", id: "ls-1", name: "ls", arguments: { bookId: "book-a", subdir: "story/roles" } },
875
+ ],
876
+ api: "google-generative-ai",
877
+ provider: "google",
878
+ model: "gemini-pro-latest",
879
+ usage,
880
+ stopReason: "toolUse",
881
+ timestamp: 4,
882
+ },
883
+ } as MessageEvent);
884
+ await appendTranscriptEvent(projectRoot, {
885
+ type: "message",
886
+ version: 1,
887
+ sessionId: "s1",
888
+ requestId: "r1",
889
+ uuid: "t1",
890
+ parentUuid: "a1",
891
+ seq: 5,
892
+ role: "toolResult",
893
+ timestamp: 5,
894
+ toolCallId: "ls-1",
895
+ sourceToolAssistantUuid: "a1",
896
+ message: {
897
+ role: "toolResult",
898
+ toolCallId: "ls-1",
899
+ toolName: "ls",
900
+ content: [{ type: "text", text: "主要角色/\n次要角色/" }],
901
+ details: { path: "books/book-a/story/roles" },
902
+ isError: false,
903
+ timestamp: 5,
904
+ },
905
+ } as MessageEvent);
906
+ await appendTranscriptEvent(projectRoot, {
907
+ type: "message",
908
+ version: 1,
909
+ sessionId: "s1",
910
+ requestId: "r1",
911
+ uuid: "a2",
912
+ parentUuid: "t1",
913
+ seq: 6,
914
+ role: "assistant",
915
+ timestamp: 6,
916
+ message: {
917
+ role: "assistant",
918
+ content: [{ type: "text", text: "角色目录已查看。" }],
919
+ api: "google-generative-ai",
920
+ provider: "google",
921
+ model: "gemini-pro-latest",
922
+ usage,
923
+ stopReason: "stop",
924
+ timestamp: 6,
925
+ },
926
+ } as MessageEvent);
927
+ await appendTranscriptEvent(projectRoot, {
928
+ type: "request_committed",
929
+ version: 1,
930
+ sessionId: "s1",
931
+ requestId: "r1",
932
+ seq: 7,
933
+ timestamp: 7,
934
+ });
935
+
936
+ const session = await deriveBookSessionFromTranscript(projectRoot, "s1");
937
+
938
+ expect(session?.messages).toMatchObject([
939
+ { role: "user", content: "查看角色目录" },
940
+ {
941
+ role: "assistant",
942
+ content: "角色目录已查看。",
943
+ thinking: "先列目录",
944
+ toolExecutions: [{
945
+ id: "ls-1",
946
+ tool: "ls",
947
+ label: "列目录",
948
+ status: "completed",
949
+ args: { bookId: "book-a", subdir: "story/roles" },
950
+ result: "主要角色/\n次要角色/",
951
+ details: { path: "books/book-a/story/roles" },
952
+ startedAt: 4,
953
+ completedAt: 5,
954
+ }],
955
+ },
956
+ ]);
957
+ });
958
+
959
+ it("keeps UI message order by transcript seq instead of message timestamp", async () => {
960
+ await appendTranscriptEvent(projectRoot, {
961
+ type: "session_created",
962
+ version: 1,
963
+ sessionId: "s1",
964
+ seq: 1,
965
+ timestamp: 1,
966
+ bookId: "book-a",
967
+ title: null,
968
+ createdAt: 1,
969
+ updatedAt: 1,
970
+ });
971
+ await appendTranscriptEvent(projectRoot, {
972
+ type: "request_started",
973
+ version: 1,
974
+ sessionId: "s1",
975
+ requestId: "r1",
976
+ seq: 2,
977
+ timestamp: 2,
978
+ input: "先问",
979
+ });
980
+ await appendTranscriptEvent(projectRoot, {
981
+ type: "message",
982
+ version: 1,
983
+ sessionId: "s1",
984
+ requestId: "r1",
985
+ uuid: "u1",
986
+ parentUuid: null,
987
+ seq: 3,
988
+ role: "user",
989
+ timestamp: 100,
990
+ message: { role: "user", content: "先问", timestamp: 100 },
991
+ } as MessageEvent);
992
+ await appendTranscriptEvent(projectRoot, {
993
+ type: "message",
994
+ version: 1,
995
+ sessionId: "s1",
996
+ requestId: "r1",
997
+ uuid: "a1",
998
+ parentUuid: "u1",
999
+ seq: 4,
1000
+ role: "assistant",
1001
+ timestamp: 50,
1002
+ message: {
1003
+ role: "assistant",
1004
+ content: [{ type: "text", text: "后答" }],
1005
+ api: "anthropic-messages",
1006
+ provider: "anthropic",
1007
+ model: "claude",
1008
+ usage,
1009
+ stopReason: "stop",
1010
+ timestamp: 50,
1011
+ },
1012
+ } as MessageEvent);
1013
+ await appendTranscriptEvent(projectRoot, {
1014
+ type: "request_committed",
1015
+ version: 1,
1016
+ sessionId: "s1",
1017
+ requestId: "r1",
1018
+ seq: 5,
1019
+ timestamp: 5,
1020
+ });
1021
+
1022
+ const session = await deriveBookSessionFromTranscript(projectRoot, "s1");
1023
+
1024
+ expect(session?.messages.map((message) => message.content)).toEqual(["先问", "后答"]);
1025
+ });
1026
+
1027
+ it("does not carry pending tool executions or thinking across request boundaries", async () => {
1028
+ await appendTranscriptEvent(projectRoot, {
1029
+ type: "session_created",
1030
+ version: 1,
1031
+ sessionId: "s1",
1032
+ seq: 1,
1033
+ timestamp: 1,
1034
+ bookId: "book-a",
1035
+ title: null,
1036
+ createdAt: 1,
1037
+ updatedAt: 1,
1038
+ });
1039
+ await appendTranscriptEvent(projectRoot, {
1040
+ type: "request_started",
1041
+ version: 1,
1042
+ sessionId: "s1",
1043
+ requestId: "r1",
1044
+ seq: 2,
1045
+ timestamp: 2,
1046
+ input: "列目录",
1047
+ });
1048
+ await appendTranscriptEvent(projectRoot, {
1049
+ type: "message",
1050
+ version: 1,
1051
+ sessionId: "s1",
1052
+ requestId: "r1",
1053
+ uuid: "u1",
1054
+ parentUuid: null,
1055
+ seq: 3,
1056
+ role: "user",
1057
+ timestamp: 3,
1058
+ message: { role: "user", content: "列目录", timestamp: 3 },
1059
+ } as MessageEvent);
1060
+ await appendTranscriptEvent(projectRoot, {
1061
+ type: "message",
1062
+ version: 1,
1063
+ sessionId: "s1",
1064
+ requestId: "r1",
1065
+ uuid: "a1",
1066
+ parentUuid: "u1",
1067
+ seq: 4,
1068
+ role: "assistant",
1069
+ timestamp: 4,
1070
+ toolCallId: "ls-1",
1071
+ message: {
1072
+ role: "assistant",
1073
+ content: [
1074
+ { type: "thinking", thinking: "第一轮工具前思考" },
1075
+ { type: "toolCall", id: "ls-1", name: "ls", arguments: { subdir: "story" } },
1076
+ ],
1077
+ api: "anthropic-messages",
1078
+ provider: "anthropic",
1079
+ model: "claude",
1080
+ usage,
1081
+ stopReason: "toolUse",
1082
+ timestamp: 4,
1083
+ },
1084
+ } as MessageEvent);
1085
+ await appendTranscriptEvent(projectRoot, {
1086
+ type: "message",
1087
+ version: 1,
1088
+ sessionId: "s1",
1089
+ requestId: "r1",
1090
+ uuid: "t1",
1091
+ parentUuid: "a1",
1092
+ seq: 5,
1093
+ role: "toolResult",
1094
+ timestamp: 5,
1095
+ toolCallId: "ls-1",
1096
+ sourceToolAssistantUuid: "a1",
1097
+ message: {
1098
+ role: "toolResult",
1099
+ toolCallId: "ls-1",
1100
+ toolName: "ls",
1101
+ content: [{ type: "text", text: "roles/" }],
1102
+ isError: false,
1103
+ timestamp: 5,
1104
+ },
1105
+ } as MessageEvent);
1106
+ await appendTranscriptEvent(projectRoot, {
1107
+ type: "request_committed",
1108
+ version: 1,
1109
+ sessionId: "s1",
1110
+ requestId: "r1",
1111
+ seq: 6,
1112
+ timestamp: 6,
1113
+ });
1114
+ await appendTranscriptEvent(projectRoot, {
1115
+ type: "request_started",
1116
+ version: 1,
1117
+ sessionId: "s1",
1118
+ requestId: "r2",
1119
+ seq: 7,
1120
+ timestamp: 7,
1121
+ input: "继续",
1122
+ });
1123
+ await appendTranscriptEvent(projectRoot, {
1124
+ type: "message",
1125
+ version: 1,
1126
+ sessionId: "s1",
1127
+ requestId: "r2",
1128
+ uuid: "u2",
1129
+ parentUuid: null,
1130
+ seq: 8,
1131
+ role: "user",
1132
+ timestamp: 8,
1133
+ message: { role: "user", content: "继续", timestamp: 8 },
1134
+ } as MessageEvent);
1135
+ await appendTranscriptEvent(projectRoot, {
1136
+ type: "message",
1137
+ version: 1,
1138
+ sessionId: "s1",
1139
+ requestId: "r2",
1140
+ uuid: "a2",
1141
+ parentUuid: "u2",
1142
+ seq: 9,
1143
+ role: "assistant",
1144
+ timestamp: 9,
1145
+ message: {
1146
+ role: "assistant",
1147
+ content: [{ type: "text", text: "第二轮回答" }],
1148
+ api: "anthropic-messages",
1149
+ provider: "anthropic",
1150
+ model: "claude",
1151
+ usage,
1152
+ stopReason: "stop",
1153
+ timestamp: 9,
1154
+ },
1155
+ } as MessageEvent);
1156
+ await appendTranscriptEvent(projectRoot, {
1157
+ type: "request_committed",
1158
+ version: 1,
1159
+ sessionId: "s1",
1160
+ requestId: "r2",
1161
+ seq: 10,
1162
+ timestamp: 10,
1163
+ });
1164
+
1165
+ const session = await deriveBookSessionFromTranscript(projectRoot, "s1");
1166
+ const secondAssistant = session?.messages.find((message) => message.content === "第二轮回答");
1167
+
1168
+ expect(secondAssistant).toMatchObject({ role: "assistant", content: "第二轮回答" });
1169
+ expect(secondAssistant).not.toHaveProperty("thinking");
1170
+ expect(secondAssistant).not.toHaveProperty("toolExecutions");
1171
+ });
1172
+
1173
+ it("does not resolve tool results with tool calls from a previous request", async () => {
1174
+ await appendTranscriptEvent(projectRoot, {
1175
+ type: "session_created",
1176
+ version: 1,
1177
+ sessionId: "s1",
1178
+ seq: 1,
1179
+ timestamp: 1,
1180
+ bookId: "book-a",
1181
+ title: null,
1182
+ createdAt: 1,
1183
+ updatedAt: 1,
1184
+ });
1185
+ await appendTranscriptEvent(projectRoot, {
1186
+ type: "request_started",
1187
+ version: 1,
1188
+ sessionId: "s1",
1189
+ requestId: "r1",
1190
+ seq: 2,
1191
+ timestamp: 2,
1192
+ input: "第一轮",
1193
+ });
1194
+ await appendTranscriptEvent(projectRoot, {
1195
+ type: "message",
1196
+ version: 1,
1197
+ sessionId: "s1",
1198
+ requestId: "r1",
1199
+ uuid: "a1",
1200
+ parentUuid: null,
1201
+ seq: 3,
1202
+ role: "assistant",
1203
+ timestamp: 3,
1204
+ toolCallId: "shared-tool",
1205
+ message: {
1206
+ role: "assistant",
1207
+ content: [
1208
+ { type: "toolCall", id: "shared-tool", name: "ls", arguments: { subdir: "story/roles" } },
1209
+ ],
1210
+ api: "anthropic-messages",
1211
+ provider: "anthropic",
1212
+ model: "claude",
1213
+ usage,
1214
+ stopReason: "toolUse",
1215
+ timestamp: 3,
1216
+ },
1217
+ } as MessageEvent);
1218
+ await appendTranscriptEvent(projectRoot, {
1219
+ type: "request_committed",
1220
+ version: 1,
1221
+ sessionId: "s1",
1222
+ requestId: "r1",
1223
+ seq: 4,
1224
+ timestamp: 4,
1225
+ });
1226
+ await appendTranscriptEvent(projectRoot, {
1227
+ type: "request_started",
1228
+ version: 1,
1229
+ sessionId: "s1",
1230
+ requestId: "r2",
1231
+ seq: 5,
1232
+ timestamp: 5,
1233
+ input: "第二轮",
1234
+ });
1235
+ await appendTranscriptEvent(projectRoot, {
1236
+ type: "message",
1237
+ version: 1,
1238
+ sessionId: "s1",
1239
+ requestId: "r2",
1240
+ uuid: "u2",
1241
+ parentUuid: null,
1242
+ seq: 6,
1243
+ role: "user",
1244
+ timestamp: 6,
1245
+ message: { role: "user", content: "第二轮", timestamp: 6 },
1246
+ } as MessageEvent);
1247
+ await appendTranscriptEvent(projectRoot, {
1248
+ type: "message",
1249
+ version: 1,
1250
+ sessionId: "s1",
1251
+ requestId: "r2",
1252
+ uuid: "t2",
1253
+ parentUuid: "u2",
1254
+ seq: 7,
1255
+ role: "toolResult",
1256
+ timestamp: 7,
1257
+ toolCallId: "shared-tool",
1258
+ message: {
1259
+ role: "toolResult",
1260
+ toolCallId: "shared-tool",
1261
+ toolName: "ls",
1262
+ content: [{ type: "text", text: "chapters/" }],
1263
+ isError: false,
1264
+ timestamp: 7,
1265
+ },
1266
+ } as MessageEvent);
1267
+ await appendTranscriptEvent(projectRoot, {
1268
+ type: "message",
1269
+ version: 1,
1270
+ sessionId: "s1",
1271
+ requestId: "r2",
1272
+ uuid: "a2",
1273
+ parentUuid: "t2",
1274
+ seq: 8,
1275
+ role: "assistant",
1276
+ timestamp: 8,
1277
+ message: {
1278
+ role: "assistant",
1279
+ content: [{ type: "text", text: "第二轮回答" }],
1280
+ api: "anthropic-messages",
1281
+ provider: "anthropic",
1282
+ model: "claude",
1283
+ usage,
1284
+ stopReason: "stop",
1285
+ timestamp: 8,
1286
+ },
1287
+ } as MessageEvent);
1288
+ await appendTranscriptEvent(projectRoot, {
1289
+ type: "request_committed",
1290
+ version: 1,
1291
+ sessionId: "s1",
1292
+ requestId: "r2",
1293
+ seq: 9,
1294
+ timestamp: 9,
1295
+ });
1296
+
1297
+ const session = await deriveBookSessionFromTranscript(projectRoot, "s1");
1298
+ const secondAssistant = session?.messages.find((message) => message.content === "第二轮回答");
1299
+
1300
+ expect(secondAssistant?.toolExecutions).toEqual([
1301
+ expect.objectContaining({
1302
+ id: "shared-tool",
1303
+ tool: "ls",
1304
+ result: "chapters/",
1305
+ startedAt: 7,
1306
+ completedAt: 7,
1307
+ }),
1308
+ ]);
1309
+ expect(secondAssistant?.toolExecutions?.[0]).not.toHaveProperty("args");
1310
+ });
1311
+ });