@jsonstudio/llms 0.6.2172 → 0.6.2979

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 (362) hide show
  1. package/README.md +2 -0
  2. package/dist/conversion/compat/antigravity-session-signature.js +35 -1
  3. package/dist/conversion/compat/profiles/chat-gemini-cli.json +0 -7
  4. package/dist/conversion/compat/profiles/chat-gemini.json +0 -6
  5. package/dist/conversion/hub/core/detour-registry.d.ts +2 -0
  6. package/dist/conversion/hub/core/hub-context.d.ts +3 -1
  7. package/dist/conversion/hub/core/index.d.ts +1 -0
  8. package/dist/conversion/hub/core/stage-driver.js +2 -0
  9. package/dist/conversion/hub/format-adapters/anthropic-format-adapter.js +15 -4
  10. package/dist/conversion/hub/format-adapters/chat-format-adapter.js +15 -4
  11. package/dist/conversion/hub/format-adapters/gemini-format-adapter.js +15 -4
  12. package/dist/conversion/hub/format-adapters/responses-format-adapter.js +15 -4
  13. package/dist/conversion/hub/hub-feature.js +3 -2
  14. package/dist/conversion/hub/node-support.js +9 -4
  15. package/dist/conversion/hub/operation-table/operation-table-runner.js +10 -6
  16. package/dist/conversion/hub/operation-table/semantic-mappers/anthropic-mapper.js +2 -2
  17. package/dist/conversion/hub/operation-table/semantic-mappers/chat-mapper.js +10 -10
  18. package/dist/conversion/hub/operation-table/semantic-mappers/gemini-mapper.js +4 -8
  19. package/dist/conversion/hub/operation-table/semantic-mappers/responses-mapper.js +19 -65
  20. package/dist/conversion/hub/ops/operations.js +2 -121
  21. package/dist/conversion/hub/pipeline/compat/compat-engine.js +6 -0
  22. package/dist/conversion/hub/pipeline/compat/compat-pipeline-executor.d.ts +1 -1
  23. package/dist/conversion/hub/pipeline/compat/compat-pipeline-executor.js +33 -1042
  24. package/dist/conversion/hub/pipeline/compat/compat-profile-resolver.js +2 -0
  25. package/dist/conversion/hub/pipeline/compat/compat-profile-store.js +2 -0
  26. package/dist/conversion/hub/pipeline/compat/compat-types.d.ts +14 -17
  27. package/dist/conversion/hub/pipeline/compat/native-adapter-context.d.ts +3 -0
  28. package/dist/conversion/hub/pipeline/compat/native-adapter-context.js +39 -0
  29. package/dist/conversion/hub/pipeline/hub-pipeline.js +115 -262
  30. package/dist/conversion/hub/pipeline/session-identifiers.js +6 -196
  31. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage1_format_parse/index.d.ts +1 -2
  32. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage1_format_parse/index.js +37 -1
  33. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage2_semantic_map/index.js +12 -86
  34. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage2_semantic_map/semantic-lift.d.ts +14 -0
  35. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage2_semantic_map/semantic-lift.js +24 -0
  36. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/archive/shell-like-tool-call-normalization-fallback.d.ts +2 -0
  37. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/archive/shell-like-tool-call-normalization-fallback.js +157 -0
  38. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/context-capture-orchestration.d.ts +16 -0
  39. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/context-capture-orchestration.js +29 -0
  40. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/context-factories.js +3 -1
  41. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/index.d.ts +2 -15
  42. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/index.js +8 -595
  43. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/responses-context-snapshot.d.ts +8 -0
  44. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/responses-context-snapshot.js +28 -0
  45. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/tool-output-diagnostics.d.ts +2 -0
  46. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/tool-output-diagnostics.js +4 -0
  47. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/tool-output-snapshot.d.ts +10 -0
  48. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/tool-output-snapshot.js +12 -0
  49. package/dist/conversion/hub/pipeline/stages/req_outbound/req_outbound_stage1_semantic_map/context-merge.d.ts +3 -0
  50. package/dist/conversion/hub/pipeline/stages/req_outbound/req_outbound_stage1_semantic_map/context-merge.js +30 -0
  51. package/dist/conversion/hub/pipeline/stages/req_outbound/req_outbound_stage1_semantic_map/index.js +9 -129
  52. package/dist/conversion/hub/pipeline/stages/req_outbound/req_outbound_stage2_format_build/index.d.ts +1 -4
  53. package/dist/conversion/hub/pipeline/stages/req_outbound/req_outbound_stage2_format_build/index.js +9 -26
  54. package/dist/conversion/hub/pipeline/stages/req_outbound/req_outbound_stage3_compat/index.js +32 -14
  55. package/dist/conversion/hub/pipeline/stages/req_process/req_process_stage1_tool_governance/index.d.ts +2 -2
  56. package/dist/conversion/hub/pipeline/stages/req_process/req_process_stage1_tool_governance/index.js +48 -8
  57. package/dist/conversion/hub/pipeline/stages/req_process/req_process_stage2_route_select/index.js +18 -3
  58. package/dist/conversion/hub/pipeline/stages/resp_inbound/resp_inbound_stage1_sse_decode/index.js +10 -198
  59. package/dist/conversion/hub/pipeline/stages/resp_inbound/resp_inbound_stage1_sse_decode/stream-json-sniffer.d.ts +3 -0
  60. package/dist/conversion/hub/pipeline/stages/resp_inbound/resp_inbound_stage1_sse_decode/stream-json-sniffer.js +81 -0
  61. package/dist/conversion/hub/pipeline/stages/resp_inbound/resp_inbound_stage2_format_parse/index.d.ts +1 -2
  62. package/dist/conversion/hub/pipeline/stages/resp_inbound/resp_inbound_stage2_format_parse/index.js +36 -1
  63. package/dist/conversion/hub/pipeline/stages/resp_inbound/resp_inbound_stage3_semantic_map/index.js +3 -1
  64. package/dist/conversion/hub/pipeline/stages/resp_outbound/resp_outbound_stage1_client_remap/chat-process-semantics-bridge.d.ts +6 -0
  65. package/dist/conversion/hub/pipeline/stages/resp_outbound/resp_outbound_stage1_client_remap/chat-process-semantics-bridge.js +17 -0
  66. package/dist/conversion/hub/pipeline/stages/resp_outbound/resp_outbound_stage1_client_remap/client-remap-protocol-switch.d.ts +9 -0
  67. package/dist/conversion/hub/pipeline/stages/resp_outbound/resp_outbound_stage1_client_remap/client-remap-protocol-switch.js +28 -0
  68. package/dist/conversion/hub/pipeline/stages/resp_outbound/resp_outbound_stage1_client_remap/index.d.ts +1 -2
  69. package/dist/conversion/hub/pipeline/stages/resp_outbound/resp_outbound_stage1_client_remap/index.js +14 -102
  70. package/dist/conversion/hub/pipeline/stages/resp_outbound/resp_outbound_stage2_sse_stream/index.js +3 -1
  71. package/dist/conversion/hub/pipeline/stages/resp_process/resp_process_stage1_tool_governance/index.js +12 -10
  72. package/dist/conversion/hub/pipeline/stages/resp_process/resp_process_stage2_finalize/index.js +6 -5
  73. package/dist/conversion/hub/pipeline/stages/resp_process/resp_process_stage3_servertool_orchestration/index.d.ts +11 -1
  74. package/dist/conversion/hub/pipeline/stages/resp_process/resp_process_stage3_servertool_orchestration/index.js +10 -32
  75. package/dist/conversion/hub/pipeline/stages/utils.js +17 -1
  76. package/dist/conversion/hub/pipeline/target-utils.js +14 -91
  77. package/dist/conversion/hub/pipelines/inbound.js +3 -1
  78. package/dist/conversion/hub/pipelines/outbound.js +2 -0
  79. package/dist/conversion/hub/policy/policy-engine.js +9 -3
  80. package/dist/conversion/hub/policy/protocol-spec.js +20 -148
  81. package/dist/conversion/hub/process/chat-process-anthropic-alias.d.ts +2 -0
  82. package/dist/conversion/hub/process/chat-process-anthropic-alias.js +36 -0
  83. package/dist/conversion/hub/process/chat-process-clock-directive-parser.d.ts +5 -0
  84. package/dist/conversion/hub/process/chat-process-clock-directive-parser.js +48 -0
  85. package/dist/conversion/hub/process/chat-process-clock-directives.d.ts +24 -0
  86. package/dist/conversion/hub/process/chat-process-clock-directives.js +98 -0
  87. package/dist/conversion/hub/process/chat-process-clock-reminder-directives.d.ts +8 -0
  88. package/dist/conversion/hub/process/chat-process-clock-reminder-directives.js +42 -0
  89. package/dist/conversion/hub/process/chat-process-clock-reminder-finalize.d.ts +14 -0
  90. package/dist/conversion/hub/process/chat-process-clock-reminder-finalize.js +10 -0
  91. package/dist/conversion/hub/process/chat-process-clock-reminder-messages.d.ts +5 -0
  92. package/dist/conversion/hub/process/chat-process-clock-reminder-messages.js +10 -0
  93. package/dist/conversion/hub/process/chat-process-clock-reminder-orchestration.d.ts +30 -0
  94. package/dist/conversion/hub/process/chat-process-clock-reminder-orchestration.js +68 -0
  95. package/dist/conversion/hub/process/chat-process-clock-reminder-time-tag.d.ts +9 -0
  96. package/dist/conversion/hub/process/chat-process-clock-reminder-time-tag.js +18 -0
  97. package/dist/conversion/hub/process/chat-process-clock-reminders.d.ts +2 -0
  98. package/dist/conversion/hub/process/chat-process-clock-reminders.js +104 -0
  99. package/dist/conversion/hub/process/chat-process-clock-tool-schemas.d.ts +3 -0
  100. package/dist/conversion/hub/process/chat-process-clock-tool-schemas.js +233 -0
  101. package/dist/conversion/hub/process/chat-process-clock-tools.d.ts +6 -0
  102. package/dist/conversion/hub/process/chat-process-clock-tools.js +41 -0
  103. package/dist/conversion/hub/process/chat-process-continue-execution.d.ts +11 -0
  104. package/dist/conversion/hub/process/chat-process-continue-execution.js +82 -0
  105. package/dist/conversion/hub/process/chat-process-governance-context.d.ts +15 -0
  106. package/dist/conversion/hub/process/chat-process-governance-context.js +7 -0
  107. package/dist/conversion/hub/process/chat-process-governance-finalize.d.ts +16 -0
  108. package/dist/conversion/hub/process/chat-process-governance-finalize.js +11 -0
  109. package/dist/conversion/hub/process/chat-process-governance-orchestration.d.ts +9 -0
  110. package/dist/conversion/hub/process/chat-process-governance-orchestration.js +47 -0
  111. package/dist/conversion/hub/process/chat-process-governed-control-ops.d.ts +8 -0
  112. package/dist/conversion/hub/process/chat-process-governed-control-ops.js +5 -0
  113. package/dist/conversion/hub/process/chat-process-governed-filter-call.d.ts +12 -0
  114. package/dist/conversion/hub/process/chat-process-governed-filter-call.js +18 -0
  115. package/dist/conversion/hub/process/chat-process-governed-merge.d.ts +8 -0
  116. package/dist/conversion/hub/process/chat-process-governed-merge.js +11 -0
  117. package/dist/conversion/hub/process/chat-process-media.d.ts +3 -0
  118. package/dist/conversion/hub/process/chat-process-media.js +18 -0
  119. package/dist/conversion/hub/process/chat-process-node-result.d.ts +23 -0
  120. package/dist/conversion/hub/process/chat-process-node-result.js +24 -0
  121. package/dist/conversion/hub/process/chat-process-pending-tool-sync.d.ts +14 -0
  122. package/dist/conversion/hub/process/chat-process-pending-tool-sync.js +52 -0
  123. package/dist/conversion/hub/process/chat-process-post-governed-normalization.d.ts +8 -0
  124. package/dist/conversion/hub/process/chat-process-post-governed-normalization.js +16 -0
  125. package/dist/conversion/hub/process/chat-process-review.d.ts +2 -0
  126. package/dist/conversion/hub/process/chat-process-review.js +8 -0
  127. package/dist/conversion/hub/process/chat-process-servertool-orchestration.d.ts +8 -0
  128. package/dist/conversion/hub/process/chat-process-servertool-orchestration.js +22 -0
  129. package/dist/conversion/hub/process/chat-process-tool-normalization.d.ts +2 -0
  130. package/dist/conversion/hub/process/chat-process-tool-normalization.js +4 -0
  131. package/dist/conversion/hub/process/chat-process-web-search-intent.d.ts +12 -0
  132. package/dist/conversion/hub/process/chat-process-web-search-intent.js +13 -0
  133. package/dist/conversion/hub/process/chat-process-web-search-tool-schema.d.ts +3 -0
  134. package/dist/conversion/hub/process/chat-process-web-search-tool-schema.js +4 -0
  135. package/dist/conversion/hub/process/chat-process-web-search.d.ts +8 -0
  136. package/dist/conversion/hub/process/chat-process-web-search.js +26 -0
  137. package/dist/conversion/hub/process/chat-process.d.ts +2 -19
  138. package/dist/conversion/hub/process/chat-process.js +12 -1701
  139. package/dist/conversion/hub/process/client-inject-readiness.d.ts +1 -0
  140. package/dist/conversion/hub/process/client-inject-readiness.js +4 -0
  141. package/dist/conversion/hub/registry.js +5 -2
  142. package/dist/conversion/hub/response/chat-response-utils.js +5 -86
  143. package/dist/conversion/hub/response/provider-response.d.ts +9 -0
  144. package/dist/conversion/hub/response/provider-response.js +6 -21
  145. package/dist/conversion/hub/response/response-mappers.js +2 -26
  146. package/dist/conversion/hub/response/response-runtime.js +2 -93
  147. package/dist/conversion/hub/semantic-mappers/anthropic-mapper.d.ts +1 -0
  148. package/dist/conversion/hub/semantic-mappers/anthropic-mapper.js +1 -0
  149. package/dist/conversion/hub/semantic-mappers/chat-mapper.d.ts +1 -0
  150. package/dist/conversion/hub/semantic-mappers/chat-mapper.js +1 -0
  151. package/dist/conversion/hub/semantic-mappers/gemini-mapper.d.ts +1 -0
  152. package/dist/conversion/hub/semantic-mappers/gemini-mapper.js +1 -0
  153. package/dist/conversion/hub/semantic-mappers/responses-mapper.d.ts +1 -0
  154. package/dist/conversion/hub/semantic-mappers/responses-mapper.js +1 -0
  155. package/dist/conversion/hub/snapshot-recorder.js +10 -3
  156. package/dist/conversion/hub/standardized-bridge.js +11 -288
  157. package/dist/conversion/hub/tool-governance/engine.js +5 -0
  158. package/dist/conversion/hub/tool-governance/rules.js +10 -10
  159. package/dist/conversion/hub/tool-session-compat.d.ts +2 -2
  160. package/dist/conversion/hub/tool-session-compat.js +17 -231
  161. package/dist/conversion/hub/tool-surface/tool-surface-engine.js +5 -3
  162. package/dist/conversion/responses/responses-host-policy.js +2 -12
  163. package/dist/conversion/responses/responses-openai-bridge/response-payload.js +6 -82
  164. package/dist/conversion/responses/responses-openai-bridge/types.d.ts +1 -0
  165. package/dist/conversion/responses/responses-openai-bridge.js +21 -54
  166. package/dist/conversion/shared/anthropic-message-utils.js +151 -13
  167. package/dist/conversion/shared/args-mapping.js +2 -146
  168. package/dist/conversion/shared/bridge-actions.js +203 -718
  169. package/dist/conversion/shared/bridge-id-utils.js +5 -71
  170. package/dist/conversion/shared/bridge-instructions.js +2 -1
  171. package/dist/conversion/shared/bridge-message-types.d.ts +2 -0
  172. package/dist/conversion/shared/bridge-message-utils.js +1 -2
  173. package/dist/conversion/shared/bridge-metadata.d.ts +1 -0
  174. package/dist/conversion/shared/bridge-metadata.js +4 -0
  175. package/dist/conversion/shared/bridge-policies.js +5 -189
  176. package/dist/conversion/shared/chat-envelope-validator.js +2 -126
  177. package/dist/conversion/shared/chat-output-normalizer.js +2 -54
  178. package/dist/conversion/shared/compaction-detect.js +2 -57
  179. package/dist/conversion/shared/gemini-tool-utils.js +9 -524
  180. package/dist/conversion/shared/jsonish.js +3 -160
  181. package/dist/conversion/shared/mcp-injection.js +3 -169
  182. package/dist/conversion/shared/media.js +2 -7
  183. package/dist/conversion/shared/metadata-passthrough.js +9 -46
  184. package/dist/conversion/shared/openai-finalizer.js +2 -1
  185. package/dist/conversion/shared/openai-message-normalize.js +11 -283
  186. package/dist/conversion/shared/output-content-normalizer.js +9 -112
  187. package/dist/conversion/shared/payload-budget.js +2 -85
  188. package/dist/conversion/shared/protocol-state.js +11 -7
  189. package/dist/conversion/shared/reasoning-mapping.js +2 -6
  190. package/dist/conversion/shared/reasoning-normalizer.js +4 -1
  191. package/dist/conversion/shared/reasoning-tool-normalizer.js +14 -126
  192. package/dist/conversion/shared/reasoning-tool-parser.js +4 -87
  193. package/dist/conversion/shared/reasoning-utils.js +2 -6
  194. package/dist/conversion/shared/responses-conversation-store.js +4 -82
  195. package/dist/conversion/shared/responses-output-builder.js +11 -47
  196. package/dist/conversion/shared/responses-reasoning-registry.js +7 -1
  197. package/dist/conversion/shared/responses-request-adapter.d.ts +7 -1
  198. package/dist/conversion/shared/responses-request-adapter.js +14 -1
  199. package/dist/conversion/shared/responses-response-utils.js +6 -7
  200. package/dist/conversion/shared/responses-tool-utils.d.ts +1 -0
  201. package/dist/conversion/shared/responses-tool-utils.js +90 -14
  202. package/dist/conversion/shared/runtime-metadata.js +13 -5
  203. package/dist/conversion/shared/streaming-text-extractor.js +2 -7
  204. package/dist/conversion/shared/text-markup-normalizer/normalize.d.ts +1 -1
  205. package/dist/conversion/shared/text-markup-normalizer/normalize.js +43 -17
  206. package/dist/conversion/shared/text-markup-normalizer.d.ts +1 -0
  207. package/dist/conversion/shared/text-markup-normalizer.js +1 -0
  208. package/dist/conversion/shared/thought-signature-validator.js +3 -2
  209. package/dist/conversion/shared/tool-argument-repairer.js +2 -2
  210. package/dist/conversion/shared/tool-call-id-manager.js +5 -7
  211. package/dist/conversion/shared/tool-call-utils.js +3 -45
  212. package/dist/conversion/shared/tool-canonicalizer.js +25 -29
  213. package/dist/conversion/shared/tool-filter-pipeline.js +4 -99
  214. package/dist/conversion/shared/tool-governor.d.ts +6 -0
  215. package/dist/conversion/shared/tool-governor.js +43 -125
  216. package/dist/conversion/shared/tool-harvester.js +2 -8
  217. package/dist/conversion/shared/tool-mapping.js +2 -5
  218. package/dist/conversion/shared/tooling.d.ts +0 -4
  219. package/dist/conversion/shared/tooling.js +18 -0
  220. package/dist/native/router_hotpath_napi.node +0 -0
  221. package/dist/router/virtual-router/engine/provider-key/parse.d.ts +1 -6
  222. package/dist/router/virtual-router/engine/provider-key/parse.js +1 -43
  223. package/dist/router/virtual-router/engine/routing-state/store.js +48 -12
  224. package/dist/router/virtual-router/engine-logging.js +4 -3
  225. package/dist/router/virtual-router/engine-selection/alias-selection.js +45 -83
  226. package/dist/router/virtual-router/engine-selection/key-parsing.js +9 -23
  227. package/dist/router/virtual-router/engine-selection/native-chat-process-clock-directive-parser.d.ts +20 -0
  228. package/dist/router/virtual-router/engine-selection/native-chat-process-clock-directive-parser.js +163 -0
  229. package/dist/router/virtual-router/engine-selection/native-chat-process-clock-reminder-directives.d.ts +7 -0
  230. package/dist/router/virtual-router/engine-selection/native-chat-process-clock-reminder-directives.js +103 -0
  231. package/dist/router/virtual-router/engine-selection/native-chat-process-clock-reminder-orchestration-semantics.d.ts +10 -0
  232. package/dist/router/virtual-router/engine-selection/native-chat-process-clock-reminder-orchestration-semantics.js +110 -0
  233. package/dist/router/virtual-router/engine-selection/native-chat-process-clock-reminder-semantics.d.ts +8 -0
  234. package/dist/router/virtual-router/engine-selection/native-chat-process-clock-reminder-semantics.js +281 -0
  235. package/dist/router/virtual-router/engine-selection/native-chat-process-clock-reminder-time-tag-semantics.d.ts +1 -0
  236. package/dist/router/virtual-router/engine-selection/native-chat-process-clock-reminder-time-tag-semantics.js +25 -0
  237. package/dist/router/virtual-router/engine-selection/native-chat-process-clock-reminders-semantics.d.ts +4 -0
  238. package/dist/router/virtual-router/engine-selection/native-chat-process-clock-reminders-semantics.js +44 -0
  239. package/dist/router/virtual-router/engine-selection/native-chat-process-clock-tool-schema-semantics.d.ts +2 -0
  240. package/dist/router/virtual-router/engine-selection/native-chat-process-clock-tool-schema-semantics.js +62 -0
  241. package/dist/router/virtual-router/engine-selection/native-chat-process-governance-semantics.d.ts +40 -0
  242. package/dist/router/virtual-router/engine-selection/native-chat-process-governance-semantics.js +484 -0
  243. package/dist/router/virtual-router/engine-selection/native-chat-process-governed-filter-semantics.d.ts +9 -0
  244. package/dist/router/virtual-router/engine-selection/native-chat-process-governed-filter-semantics.js +64 -0
  245. package/dist/router/virtual-router/engine-selection/native-chat-process-node-result-semantics.d.ts +5 -0
  246. package/dist/router/virtual-router/engine-selection/native-chat-process-node-result-semantics.js +163 -0
  247. package/dist/router/virtual-router/engine-selection/native-chat-process-post-governed-normalization-semantics.d.ts +1 -0
  248. package/dist/router/virtual-router/engine-selection/native-chat-process-post-governed-normalization-semantics.js +49 -0
  249. package/dist/router/virtual-router/engine-selection/native-chat-process-servertool-orchestration-semantics.d.ts +30 -0
  250. package/dist/router/virtual-router/engine-selection/native-chat-process-servertool-orchestration-semantics.js +446 -0
  251. package/dist/router/virtual-router/engine-selection/native-chat-process-web-search-intent-semantics.d.ts +1 -0
  252. package/dist/router/virtual-router/engine-selection/native-chat-process-web-search-intent-semantics.js +49 -0
  253. package/dist/router/virtual-router/engine-selection/native-hub-bridge-action-semantics.d.ts +134 -0
  254. package/dist/router/virtual-router/engine-selection/native-hub-bridge-action-semantics.js +729 -0
  255. package/dist/router/virtual-router/engine-selection/native-hub-bridge-policy-semantics.d.ts +62 -0
  256. package/dist/router/virtual-router/engine-selection/native-hub-bridge-policy-semantics.js +338 -0
  257. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-edge-stage-semantics.d.ts +18 -0
  258. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-edge-stage-semantics.js +317 -0
  259. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-inbound-outbound-semantics.d.ts +22 -0
  260. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-inbound-outbound-semantics.js +426 -0
  261. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-orchestration-semantics.d.ts +57 -0
  262. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-orchestration-semantics.js +705 -0
  263. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-req-inbound-semantics.d.ts +46 -0
  264. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-req-inbound-semantics.js +503 -0
  265. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-req-outbound-semantics.d.ts +146 -0
  266. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-req-outbound-semantics.js +570 -0
  267. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-req-process-semantics.d.ts +25 -0
  268. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-req-process-semantics.js +148 -0
  269. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-resp-semantics.d.ts +25 -0
  270. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-resp-semantics.js +637 -0
  271. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-session-identifiers-semantics.d.ts +11 -0
  272. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-session-identifiers-semantics.js +207 -0
  273. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-target-semantics.d.ts +3 -0
  274. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-target-semantics.js +128 -0
  275. package/dist/router/virtual-router/engine-selection/native-router-hotpath-analysis.d.ts +57 -0
  276. package/dist/router/virtual-router/engine-selection/native-router-hotpath-analysis.js +217 -0
  277. package/dist/router/virtual-router/engine-selection/native-router-hotpath-loader.d.ts +5 -0
  278. package/dist/router/virtual-router/engine-selection/native-router-hotpath-loader.js +284 -0
  279. package/dist/router/virtual-router/engine-selection/native-router-hotpath-policy.d.ts +5 -0
  280. package/dist/router/virtual-router/engine-selection/native-router-hotpath-policy.js +18 -0
  281. package/dist/router/virtual-router/engine-selection/native-router-hotpath-quota-buckets.d.ts +25 -0
  282. package/dist/router/virtual-router/engine-selection/native-router-hotpath-quota-buckets.js +85 -0
  283. package/dist/router/virtual-router/engine-selection/native-router-hotpath.d.ts +59 -0
  284. package/dist/router/virtual-router/engine-selection/native-router-hotpath.js +117 -0
  285. package/dist/router/virtual-router/engine-selection/native-shared-conversion-semantics.d.ts +76 -0
  286. package/dist/router/virtual-router/engine-selection/native-shared-conversion-semantics.js +1166 -0
  287. package/dist/router/virtual-router/engine-selection/native-virtual-router-alias-selection-semantics.d.ts +16 -0
  288. package/dist/router/virtual-router/engine-selection/native-virtual-router-alias-selection-semantics.js +96 -0
  289. package/dist/router/virtual-router/engine-selection/native-virtual-router-stop-message-actions-semantics.d.ts +6 -0
  290. package/dist/router/virtual-router/engine-selection/native-virtual-router-stop-message-actions-semantics.js +85 -0
  291. package/dist/router/virtual-router/engine-selection/native-virtual-router-stop-message-semantics.d.ts +9 -0
  292. package/dist/router/virtual-router/engine-selection/native-virtual-router-stop-message-semantics.js +70 -0
  293. package/dist/router/virtual-router/engine-selection/native-virtual-router-stop-message-state-semantics.d.ts +2 -0
  294. package/dist/router/virtual-router/engine-selection/native-virtual-router-stop-message-state-semantics.js +76 -0
  295. package/dist/router/virtual-router/engine-selection/route-utils.js +1 -1
  296. package/dist/router/virtual-router/engine-selection/tier-selection-antigravity-session-lease.d.ts +10 -0
  297. package/dist/router/virtual-router/engine-selection/tier-selection-antigravity-session-lease.js +231 -0
  298. package/dist/router/virtual-router/engine-selection/tier-selection-antigravity-target-split.d.ts +4 -0
  299. package/dist/router/virtual-router/engine-selection/tier-selection-antigravity-target-split.js +43 -0
  300. package/dist/router/virtual-router/engine-selection/tier-selection-quota-integration.d.ts +27 -0
  301. package/dist/router/virtual-router/engine-selection/tier-selection-quota-integration.js +116 -0
  302. package/dist/router/virtual-router/engine-selection/tier-selection-select.d.ts +1 -1
  303. package/dist/router/virtual-router/engine-selection/tier-selection-select.js +29 -129
  304. package/dist/router/virtual-router/engine-selection/tier-selection.js +2 -265
  305. package/dist/router/virtual-router/engine.js +258 -249
  306. package/dist/router/virtual-router/features.js +2 -2
  307. package/dist/router/virtual-router/routing-instructions.d.ts +5 -7
  308. package/dist/router/virtual-router/routing-instructions.js +93 -66
  309. package/dist/router/virtual-router/routing-stop-message-actions.js +91 -112
  310. package/dist/router/virtual-router/routing-stop-message-parser.js +9 -132
  311. package/dist/router/virtual-router/routing-stop-message-state-codec.d.ts +1 -0
  312. package/dist/router/virtual-router/routing-stop-message-state-codec.js +58 -71
  313. package/dist/router/virtual-router/sticky-session-store.js +4 -2
  314. package/dist/router/virtual-router/stop-message-file-resolver.d.ts +1 -0
  315. package/dist/router/virtual-router/stop-message-file-resolver.js +10 -0
  316. package/dist/router/virtual-router/stop-message-state-sync.d.ts +1 -1
  317. package/dist/router/virtual-router/stop-message-state-sync.js +3 -7
  318. package/dist/router/virtual-router/token-counter.js +0 -9
  319. package/dist/router/virtual-router/types.d.ts +9 -7
  320. package/dist/servertool/clock/config.js +23 -51
  321. package/dist/servertool/clock/io.js +1 -0
  322. package/dist/servertool/clock/session-scope.d.ts +2 -2
  323. package/dist/servertool/clock/session-scope.js +5 -47
  324. package/dist/servertool/engine.d.ts +9 -0
  325. package/dist/servertool/engine.js +196 -79
  326. package/dist/servertool/handlers/antigravity-thought-signature-bootstrap.js +2 -2
  327. package/dist/servertool/handlers/clock.js +1 -1
  328. package/dist/servertool/handlers/continue-execution.js +8 -4
  329. package/dist/servertool/handlers/followup-request-builder.js +18 -1
  330. package/dist/servertool/handlers/gemini-empty-reply-continue.js +7 -1
  331. package/dist/servertool/handlers/review.js +180 -0
  332. package/dist/servertool/handlers/stop-message-auto/blocked-report.js +59 -1
  333. package/dist/servertool/handlers/stop-message-auto/iflow-followup.d.ts +23 -2
  334. package/dist/servertool/handlers/stop-message-auto/iflow-followup.js +397 -89
  335. package/dist/servertool/handlers/stop-message-auto/routing-state.d.ts +5 -15
  336. package/dist/servertool/handlers/stop-message-auto/routing-state.js +29 -55
  337. package/dist/servertool/handlers/stop-message-auto/runtime-utils.d.ts +6 -0
  338. package/dist/servertool/handlers/stop-message-auto/runtime-utils.js +35 -61
  339. package/dist/servertool/handlers/stop-message-auto.js +392 -76
  340. package/dist/servertool/server-side-tools.d.ts +1 -0
  341. package/dist/servertool/server-side-tools.js +90 -52
  342. package/dist/servertool/types.d.ts +17 -0
  343. package/dist/tools/apply-patch/patch-text/normalize.js +11 -0
  344. package/dist/tools/exec-command/validator.d.ts +4 -1
  345. package/dist/tools/exec-command/validator.js +87 -3
  346. package/dist/tools/tool-registry.d.ts +7 -1
  347. package/dist/tools/tool-registry.js +3 -2
  348. package/package.json +115 -7
  349. package/dist/servertool/handlers/stop-message-stage-policy/bd-runtime.d.ts +0 -18
  350. package/dist/servertool/handlers/stop-message-stage-policy/bd-runtime.js +0 -398
  351. package/dist/servertool/handlers/stop-message-stage-policy/decision.d.ts +0 -9
  352. package/dist/servertool/handlers/stop-message-stage-policy/decision.js +0 -127
  353. package/dist/servertool/handlers/stop-message-stage-policy/observation.d.ts +0 -2
  354. package/dist/servertool/handlers/stop-message-stage-policy/observation.js +0 -179
  355. package/dist/servertool/handlers/stop-message-stage-policy/templates.d.ts +0 -4
  356. package/dist/servertool/handlers/stop-message-stage-policy/templates.js +0 -96
  357. package/dist/servertool/handlers/stop-message-stage-policy/text-utils.d.ts +0 -9
  358. package/dist/servertool/handlers/stop-message-stage-policy/text-utils.js +0 -89
  359. package/dist/servertool/handlers/stop-message-stage-policy/types.d.ts +0 -59
  360. package/dist/servertool/handlers/stop-message-stage-policy.d.ts +0 -3
  361. package/dist/servertool/handlers/stop-message-stage-policy.js +0 -2
  362. /package/dist/servertool/handlers/{stop-message-stage-policy/types.js → review.d.ts} +0 -0
@@ -4,18 +4,14 @@ import { extractCapturedChatSeed } from './followup-request-builder.js';
4
4
  import { readRuntimeMetadata } from '../../conversion/shared/runtime-metadata.js';
5
5
  import { isStopEligibleForServerTool } from '../stop-gateway-context.js';
6
6
  import { attachStopMessageCompareContext } from '../stop-message-compare-context.js';
7
- import { extractStopMessageAutoResponseSnapshot, renderStopMessageAutoFollowupViaIflow } from './stop-message-auto/iflow-followup.js';
8
- import { getCapturedRequest, hasCompactionFlag, readServerToolFollowupFlowId, resolveClientConnectionState, resolveEntryEndpoint, resolveImplicitGeminiStopMessageSnapshot, resolveStopMessageFollowupProviderKey, resolveStopMessageFollowupToolContentMaxChars } from './stop-message-auto/runtime-utils.js';
7
+ import { extractStopMessageAutoResponseSnapshot, renderStopMessageAutoFollowupViaAi, resolveStopMessageAiApprovedMarker, resolveStopMessageAiDoneMarker } from './stop-message-auto/iflow-followup.js';
8
+ import { getCapturedRequest, hasCompactionFlag, persistStopMessageState, readServerToolFollowupFlowId, resolveBdWorkingDirectoryForRecord, resolveClientConnectionState, resolveDefaultStopMessageSnapshot, resolveEntryEndpoint, resolveImplicitGeminiStopMessageSnapshot, resolveStopMessageSessionScope, resolveStickyKey, resolveStopMessageFollowupProviderKey } from './stop-message-auto/runtime-utils.js';
9
+ import { loadRoutingInstructionStateSync } from '../../router/virtual-router/sticky-session-store.js';
10
+ import { clearStopMessageState, createStopMessageState, resolveStopMessageSnapshot } from './stop-message-auto/routing-state.js';
9
11
  export { extractBlockedReportFromMessagesForTests } from './stop-message-auto/blocked-report.js';
10
12
  const STOPMESSAGE_DEBUG = (process.env.ROUTECODEX_STOPMESSAGE_DEBUG || '').trim() === '1';
11
- const STOPMESSAGE_IMPLICIT_GEMINI = (process.env.ROUTECODEX_STOPMESSAGE_IMPLICIT_GEMINI || '').trim() === '1';
12
- const STOPMESSAGE_DEFAULT_ENABLED = (() => {
13
- const raw = process.env.ROUTECODEX_STOPMESSAGE_DEFAULT_ENABLED;
14
- if (typeof raw === 'string' && raw.trim().length > 0) {
15
- return raw.trim() !== '0';
16
- }
17
- return process.env.NODE_ENV !== 'test';
18
- })();
13
+ const STOPMESSAGE_IMPLICIT_GEMINI = false;
14
+ const STOPMESSAGE_DEFAULT_ENABLED = false;
19
15
  const STOPMESSAGE_DEFAULT_TEXT = (() => {
20
16
  const raw = process.env.ROUTECODEX_STOPMESSAGE_DEFAULT_TEXT;
21
17
  return typeof raw === 'string' && raw.trim().length > 0 ? raw.trim() : '继续执行';
@@ -40,14 +36,113 @@ function debugLog(message, extra) {
40
36
  }
41
37
  }
42
38
  const FLOW_ID = 'stop_message_flow';
39
+ function hasStopMessageDoneMarker(snapshot, marker) {
40
+ if (!snapshot || !marker) {
41
+ return false;
42
+ }
43
+ const normalizedMarker = marker.trim();
44
+ if (!normalizedMarker) {
45
+ return false;
46
+ }
47
+ const candidates = [snapshot.assistantText, snapshot.reasoningText, snapshot.responseExcerpt];
48
+ return candidates.some((value) => typeof value === 'string' && value.includes(normalizedMarker));
49
+ }
50
+ function hasStopMessageMarkerLine(text, marker) {
51
+ const content = typeof text === 'string' ? text.trim() : '';
52
+ const normalizedMarker = typeof marker === 'string' ? marker.trim() : '';
53
+ if (!content || !normalizedMarker) {
54
+ return false;
55
+ }
56
+ const escapedMarker = normalizedMarker.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
57
+ const markerLinePattern = new RegExp(`(^|\\n)\\s*${escapedMarker}\\s*(?=\\n|$)`);
58
+ return markerLinePattern.test(content);
59
+ }
60
+ function readStopMessageStageMode(raw) {
61
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw)) {
62
+ return undefined;
63
+ }
64
+ const value = raw.stopMessageStageMode;
65
+ if (typeof value !== 'string') {
66
+ return undefined;
67
+ }
68
+ const normalized = value.trim().toLowerCase();
69
+ if (normalized === 'on' || normalized === 'off' || normalized === 'auto') {
70
+ return normalized;
71
+ }
72
+ return undefined;
73
+ }
43
74
  const STOP_MESSAGE_EXECUTION_DIRECTIVE = [
44
75
  '执行策略(必须遵守):',
45
76
  '- 禁止输出口播式状态汇报(如“继续执行中”“我会继续”)。',
46
77
  '- 以当前上下文目标为准,优先推进可验证的工程动作,不要停留在任务管理操作。',
47
78
  '- 优先完成真实动作(改代码/补测试/运行验证),再做简短汇报。',
79
+ '- 禁止连续执行纯只读/纯汇报动作(如 cargo llvm-cov report、cat/head/tail/rg/git status);若上一轮没有代码修改证据,本轮必须先完成写动作(修改文件或新增测试)。',
80
+ '- 覆盖率命令仅用于“写动作之后的验证”,不得作为本轮唯一或首要动作。',
81
+ '- 若预计等待超过 2 分钟,必须调用 clock.schedule 设置定时,不得只口头说明等待。',
82
+ '- 若仅需汇报任务进度,必须按顺序:先调用 CONTINUE execution(continue_execution,参数示例 {"reason":"progress_update"}),再做 <=5 行简短汇报,然后立即继续执行。',
48
83
  '- 若遇阻塞,请按 JSON 输出结构化阻塞信息(type=blocked, summary, blocker, impact, next_action, evidence)。',
49
- '- 如果即将返回 finish_reason=stop 或协议等价 end_turn,先调用 continue_execution 工具,不要直接结束会话。'
84
+ '- 如果即将返回 finish_reason=stop 或协议等价 end_turn,先调用 continue_execution 工具,不要直接结束会话。',
85
+ '- 仅当总体目标完成时,才允许停止。'
50
86
  ].join('\n');
87
+ const STOP_MESSAGE_AI_HISTORY_MAX = 8;
88
+ const STOP_MESSAGE_EXECUTION_APPEND = '请直接继续执行,不要进行状态汇总;优先写动作(改代码/补测试),覆盖率命令只用于写动作后的验证,不得连续只做汇报/只读检查;仅在完成一个阶段性任务或已完成总体目标时再停止并回复。';
89
+ function readStopMessageAiSeedPrompt(state) {
90
+ if (!state || typeof state !== 'object' || Array.isArray(state)) {
91
+ return '';
92
+ }
93
+ const raw = state.stopMessageAiSeedPrompt;
94
+ return typeof raw === 'string' ? raw.trim() : '';
95
+ }
96
+ function readStopMessageAiHistory(state) {
97
+ if (!state || typeof state !== 'object' || Array.isArray(state)) {
98
+ return [];
99
+ }
100
+ const raw = state.stopMessageAiHistory;
101
+ if (!Array.isArray(raw)) {
102
+ return [];
103
+ }
104
+ const normalized = [];
105
+ for (const entry of raw) {
106
+ if (!entry || typeof entry !== 'object' || Array.isArray(entry)) {
107
+ continue;
108
+ }
109
+ const record = entry;
110
+ const item = {};
111
+ if (typeof record.ts === 'number' && Number.isFinite(record.ts)) {
112
+ item.ts = Math.floor(record.ts);
113
+ }
114
+ if (typeof record.round === 'number' && Number.isFinite(record.round)) {
115
+ item.round = Math.max(0, Math.floor(record.round));
116
+ }
117
+ for (const key of ['assistantText', 'reasoningText', 'responseExcerpt', 'followupText']) {
118
+ const value = record[key];
119
+ if (typeof value === 'string' && value.trim()) {
120
+ item[key] = value.trim();
121
+ }
122
+ }
123
+ if (Object.keys(item).length > 0) {
124
+ normalized.push(item);
125
+ }
126
+ }
127
+ return normalized.slice(-STOP_MESSAGE_AI_HISTORY_MAX);
128
+ }
129
+ function appendStopMessageAiHistory(history, item) {
130
+ const next = [...history, item].filter((entry) => entry && Object.keys(entry).length > 0);
131
+ return next.slice(-STOP_MESSAGE_AI_HISTORY_MAX);
132
+ }
133
+ function enforceStopMessageExecutionFollowupText(text, doneMarker) {
134
+ const rawBase = typeof text === 'string' && text.trim() ? text.trim() : '';
135
+ const marker = doneMarker && doneMarker.trim() ? doneMarker.trim() : '[STOPMESSAGE_DONE]';
136
+ const escapedMarker = marker.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
137
+ const markerLinePattern = new RegExp(`(^|\\n)\\s*${escapedMarker}\\s*(?=\\n|$)`, 'g');
138
+ const strippedBase = rawBase.replace(markerLinePattern, '$1').replace(/\n{3,}/g, '\n\n').trim();
139
+ const base = strippedBase || '继续执行';
140
+ let next = base;
141
+ if (!next.includes(STOP_MESSAGE_EXECUTION_APPEND)) {
142
+ next = `${next}\n\n${STOP_MESSAGE_EXECUTION_APPEND}`;
143
+ }
144
+ return next.trim();
145
+ }
51
146
  const handler = async (ctx) => {
52
147
  const record = ctx.adapterContext;
53
148
  const rt = readRuntimeMetadata(ctx.adapterContext);
@@ -111,33 +206,160 @@ const handler = async (ctx) => {
111
206
  return markSkip('skip_compaction_flag');
112
207
  }
113
208
  const connectionState = resolveClientConnectionState(record.clientConnectionState);
114
- const implicit = STOPMESSAGE_IMPLICIT_GEMINI
115
- ? resolveImplicitGeminiStopMessageSnapshot(ctx, record)
116
- : null;
117
- if (!STOPMESSAGE_DEFAULT_ENABLED && !implicit) {
118
- debugLog('skip_default_disabled');
119
- return markSkip('skip_default_disabled', { armed: false, mode: 'off' });
120
- }
121
- const text = ((typeof implicit?.text === 'string' && implicit.text.trim().length > 0
122
- ? implicit.text
123
- : STOPMESSAGE_DEFAULT_TEXT) || '继续执行').trim();
124
- const maxRepeats = typeof implicit?.maxRepeats === 'number' && Number.isFinite(implicit.maxRepeats) && implicit.maxRepeats > 0
125
- ? Math.floor(implicit.maxRepeats)
126
- : STOPMESSAGE_DEFAULT_MAX_REPEATS;
209
+ const strictSessionScope = resolveStopMessageSessionScope(record, rt);
210
+ if (!strictSessionScope) {
211
+ debugLog('skip_missing_session_scope');
212
+ return markSkip('skip_missing_session_scope');
213
+ }
214
+ const stickyKey = strictSessionScope || resolveStickyKey(record, rt);
215
+ let stickyState = stickyKey ? loadRoutingInstructionStateSync(stickyKey) : null;
216
+ let snapshot = resolveStopMessageSnapshot(stickyState);
217
+ if (!snapshot) {
218
+ snapshot = resolveStopMessageSnapshot(rt?.stopMessageState);
219
+ if (snapshot && stickyKey) {
220
+ stickyState = createStopMessageState(snapshot);
221
+ persistStopMessageState(stickyKey, stickyState);
222
+ }
223
+ }
224
+ const stickyMode = readStopMessageStageMode(stickyState);
225
+ const runtimeMode = readStopMessageStageMode(rt?.stopMessageState);
226
+ const explicitMode = stickyMode ?? runtimeMode;
227
+ if (!snapshot && explicitMode === 'off') {
228
+ debugLog('skip_explicit_mode_off', { stickyKey });
229
+ return markSkip('skip_explicit_mode_off', {
230
+ armed: true,
231
+ mode: 'off',
232
+ allowModeOnly: true,
233
+ textLength: 0,
234
+ maxRepeats: 0,
235
+ used: 0
236
+ });
237
+ }
238
+ if (!snapshot) {
239
+ const implicit = STOPMESSAGE_IMPLICIT_GEMINI
240
+ ? resolveImplicitGeminiStopMessageSnapshot(ctx, record)
241
+ : null;
242
+ const defaultSnapshot = STOPMESSAGE_DEFAULT_ENABLED
243
+ ? resolveDefaultStopMessageSnapshot(ctx, {
244
+ text: STOPMESSAGE_DEFAULT_TEXT,
245
+ maxRepeats: STOPMESSAGE_DEFAULT_MAX_REPEATS
246
+ })
247
+ : null;
248
+ const fallback = implicit
249
+ ? {
250
+ text: implicit.text,
251
+ maxRepeats: implicit.maxRepeats,
252
+ used: implicit.used,
253
+ source: implicit.source,
254
+ updatedAt: implicit.updatedAt,
255
+ lastUsedAt: implicit.lastUsedAt,
256
+ stageMode: 'on'
257
+ }
258
+ : defaultSnapshot
259
+ ? {
260
+ text: defaultSnapshot.text,
261
+ maxRepeats: defaultSnapshot.maxRepeats,
262
+ used: defaultSnapshot.used,
263
+ source: defaultSnapshot.source,
264
+ updatedAt: defaultSnapshot.updatedAt,
265
+ lastUsedAt: defaultSnapshot.lastUsedAt,
266
+ stageMode: 'on'
267
+ }
268
+ : null;
269
+ if (!fallback) {
270
+ if (!STOPMESSAGE_DEFAULT_ENABLED && !implicit) {
271
+ debugLog('skip_default_disabled');
272
+ return markSkip('skip_default_disabled', { armed: false, mode: 'off' });
273
+ }
274
+ debugLog('skip_no_stop_message_state');
275
+ return markSkip('skip_no_stop_message_state', { armed: false, mode: 'off' });
276
+ }
277
+ snapshot = fallback;
278
+ if (stickyKey) {
279
+ stickyState = createStopMessageState(snapshot);
280
+ persistStopMessageState(stickyKey, stickyState);
281
+ }
282
+ }
283
+ const mode = snapshot.stageMode ?? 'on';
284
+ if (mode === 'off') {
285
+ debugLog('skip_explicit_mode_off', { stickyKey });
286
+ return markSkip('skip_explicit_mode_off', {
287
+ armed: true,
288
+ mode: 'off',
289
+ allowModeOnly: true,
290
+ textLength: 0,
291
+ maxRepeats: 0,
292
+ used: 0
293
+ });
294
+ }
295
+ const text = typeof snapshot.text === 'string' ? snapshot.text.trim() : '';
296
+ const maxRepeats = typeof snapshot.maxRepeats === 'number' && Number.isFinite(snapshot.maxRepeats)
297
+ ? Math.max(1, Math.floor(snapshot.maxRepeats))
298
+ : 0;
299
+ const aiMode = snapshot.aiMode === 'on' ? 'on' : 'off';
300
+ const used = typeof snapshot.used === 'number' && Number.isFinite(snapshot.used)
301
+ ? Math.max(0, Math.floor(snapshot.used))
302
+ : 0;
127
303
  updateCompare({
128
304
  armed: true,
129
- mode: 'on',
130
- allowModeOnly: text.length === 0,
305
+ mode,
306
+ allowModeOnly: false,
131
307
  textLength: text.length,
132
- maxRepeats: Math.max(1, maxRepeats),
133
- used: 0
308
+ maxRepeats,
309
+ used
134
310
  });
311
+ if (used >= maxRepeats) {
312
+ if (stickyKey && stickyState) {
313
+ clearStopMessageState(stickyState, Date.now());
314
+ persistStopMessageState(stickyKey, stickyState);
315
+ }
316
+ debugLog('skip_reached_max_repeats', {
317
+ stickyKey,
318
+ used,
319
+ maxRepeats
320
+ });
321
+ return markSkip('skip_reached_max_repeats');
322
+ }
323
+ const injectReadyRaw = rt?.stopMessageClientInjectReady;
324
+ const injectReadyExplicitlyFalse = injectReadyRaw === false ||
325
+ (typeof injectReadyRaw === 'string' && injectReadyRaw.trim().toLowerCase() === 'false');
326
+ if (injectReadyExplicitlyFalse) {
327
+ const injectReason = typeof rt?.stopMessageClientInjectReason === 'string'
328
+ ? String(rt.stopMessageClientInjectReason).trim()
329
+ : '';
330
+ if (stickyKey) {
331
+ const nextState = stickyState ??
332
+ createStopMessageState({
333
+ text,
334
+ maxRepeats,
335
+ used,
336
+ ...(snapshot.source ? { source: snapshot.source } : {}),
337
+ ...(snapshot.updatedAt ? { updatedAt: snapshot.updatedAt } : {}),
338
+ ...(snapshot.lastUsedAt ? { lastUsedAt: snapshot.lastUsedAt } : {}),
339
+ ...(snapshot.stageMode ? { stageMode: snapshot.stageMode } : {}),
340
+ aiMode
341
+ });
342
+ clearStopMessageState(nextState, Date.now());
343
+ persistStopMessageState(stickyKey, nextState);
344
+ }
345
+ debugLog('skip_client_inject_unready', {
346
+ stickyKey,
347
+ injectReadyRaw: injectReadyRaw,
348
+ injectReason
349
+ });
350
+ const normalizedInjectReason = injectReason && /^[a-z0-9_:-]+$/i.test(injectReason) ? injectReason.toLowerCase() : 'unknown';
351
+ return markSkip(`skip_client_inject_unready_${normalizedInjectReason}`);
352
+ }
135
353
  const stopEligible = isStopEligibleForServerTool(ctx.base, ctx.adapterContext);
136
354
  updateCompare({ stopEligible });
137
355
  if (!stopEligible) {
138
356
  debugLog('skip_not_stop_finish_reason');
139
357
  return markSkip('skip_not_stop_finish_reason');
140
358
  }
359
+ const autoResponseSnapshot = extractStopMessageAutoResponseSnapshot(ctx.base, ctx.adapterContext);
360
+ const doneMarker = resolveStopMessageAiDoneMarker();
361
+ const approvedMarker = resolveStopMessageAiApprovedMarker();
362
+ const completionClaimedByMainModel = aiMode === 'on' && hasStopMessageDoneMarker(autoResponseSnapshot, doneMarker);
141
363
  const captured = getCapturedRequest(ctx.adapterContext);
142
364
  updateCompare({ hasCapturedRequest: Boolean(captured) });
143
365
  if (!captured) {
@@ -157,59 +379,152 @@ const handler = async (ctx) => {
157
379
  debugLog('skip_failed_build_followup');
158
380
  return markSkip('skip_failed_build_followup');
159
381
  }
160
- const used = 0;
161
- let followupText = text || '继续执行';
162
- const autoResponseSnapshot = extractStopMessageAutoResponseSnapshot(ctx.base, ctx.adapterContext);
163
- const iflowFollowupText = renderStopMessageAutoFollowupViaIflow({
164
- baseStopMessageText: text,
165
- candidateFollowupText: followupText,
166
- responseSnapshot: autoResponseSnapshot,
167
- requestId: typeof record.requestId === 'string'
168
- ? record.requestId.trim()
169
- : undefined,
170
- sessionId: typeof record.sessionId === 'string'
171
- ? record.sessionId.trim()
172
- : undefined,
173
- providerKey: resolveStopMessageFollowupProviderKey({ record, runtimeMetadata: rt }),
174
- model: typeof seed.model === 'string' ? seed.model : undefined,
175
- usedRepeats: used,
176
- maxRepeats
177
- });
178
- if (iflowFollowupText) {
179
- followupText = iflowFollowupText.trim();
180
- if (text && !followupText.includes(text)) {
181
- followupText = `${text}\n${followupText}`.trim();
382
+ const historyStateCandidate = stickyState ?? rt?.stopMessageState;
383
+ const existingSeedPrompt = readStopMessageAiSeedPrompt(historyStateCandidate);
384
+ const existingHistory = readStopMessageAiHistory(historyStateCandidate);
385
+ const fallbackCandidateFollowupText = existingSeedPrompt || text || '继续执行';
386
+ const isFirstPrompt = existingHistory.length === 0;
387
+ let followupText = '';
388
+ if (aiMode === 'on') {
389
+ const aiFollowupText = renderStopMessageAutoFollowupViaAi({
390
+ baseStopMessageText: text,
391
+ candidateFollowupText: fallbackCandidateFollowupText,
392
+ responseSnapshot: autoResponseSnapshot,
393
+ requestId: typeof record.requestId === 'string'
394
+ ? record.requestId.trim()
395
+ : undefined,
396
+ sessionId: typeof record.sessionId === 'string'
397
+ ? record.sessionId.trim()
398
+ : undefined,
399
+ workingDirectory: resolveBdWorkingDirectoryForRecord(record, rt),
400
+ providerKey: resolveStopMessageFollowupProviderKey({ record, runtimeMetadata: rt }),
401
+ model: typeof seed.model === 'string' ? seed.model : undefined,
402
+ usedRepeats: used,
403
+ maxRepeats,
404
+ doneMarker,
405
+ approvedMarker,
406
+ completionClaimed: completionClaimedByMainModel,
407
+ isFirstPrompt,
408
+ historyEntries: existingHistory
409
+ });
410
+ if (aiFollowupText) {
411
+ followupText = aiFollowupText.trim();
412
+ debugLog('ai_followup_applied', {
413
+ textLength: followupText.length
414
+ });
415
+ }
416
+ else {
417
+ followupText = '继续执行';
418
+ debugLog('ai_followup_fallback_to_continue_execution');
419
+ }
420
+ }
421
+ else {
422
+ followupText = fallbackCandidateFollowupText;
423
+ debugLog('fixed_followup_applied', { textLength: followupText.length });
424
+ }
425
+ if (hasStopMessageMarkerLine(followupText, approvedMarker)) {
426
+ if (stickyKey) {
427
+ const nextState = stickyState ??
428
+ createStopMessageState({
429
+ text,
430
+ maxRepeats,
431
+ used,
432
+ ...(snapshot.source ? { source: snapshot.source } : {}),
433
+ ...(snapshot.updatedAt ? { updatedAt: snapshot.updatedAt } : {}),
434
+ ...(snapshot.lastUsedAt ? { lastUsedAt: snapshot.lastUsedAt } : {}),
435
+ ...(snapshot.stageMode ? { stageMode: snapshot.stageMode } : {}),
436
+ aiMode
437
+ });
438
+ clearStopMessageState(nextState, Date.now());
439
+ persistStopMessageState(stickyKey, nextState);
182
440
  }
183
- debugLog('iflow_automessage_followup_applied', {
184
- textLength: followupText.length
441
+ const approvedInjectText = typeof followupText === 'string' && followupText.trim()
442
+ ? followupText.trim()
443
+ : approvedMarker;
444
+ debugLog('trigger_done_marker_approved', {
445
+ stickyKey,
446
+ doneMarker,
447
+ approvedMarker
185
448
  });
449
+ updateCompare({
450
+ decision: 'trigger',
451
+ reason: 'done_marker_approved'
452
+ });
453
+ return {
454
+ flowId: FLOW_ID,
455
+ finalize: async () => ({
456
+ chatResponse: ctx.base,
457
+ execution: {
458
+ flowId: FLOW_ID,
459
+ followup: {
460
+ requestIdSuffix: ':stop_followup',
461
+ metadata: {
462
+ ...(connectionState ? { clientConnectionState: connectionState } : {}),
463
+ clientInjectOnly: true,
464
+ clientInjectText: approvedInjectText,
465
+ clientInjectSource: 'servertool.stop_message.done'
466
+ }
467
+ }
468
+ }
469
+ })
470
+ };
471
+ }
472
+ if (aiMode === 'on') {
473
+ followupText = enforceStopMessageExecutionFollowupText(followupText || '继续执行', doneMarker);
186
474
  }
187
475
  else {
188
- followupText = '继续执行';
189
- debugLog('iflow_automessage_followup_fallback_to_continue_execution');
476
+ followupText = (followupText || '继续执行').trim();
190
477
  }
191
- if (!followupText) {
192
- debugLog('skip_empty_followup_text_after_stage');
193
- return markSkip('skip_empty_followup_text_after_stage');
478
+ const nextHistory = aiMode === 'on'
479
+ ? appendStopMessageAiHistory(existingHistory, {
480
+ ts: Date.now(),
481
+ round: used + 1,
482
+ ...(autoResponseSnapshot.assistantText ? { assistantText: autoResponseSnapshot.assistantText } : {}),
483
+ ...(autoResponseSnapshot.reasoningText ? { reasoningText: autoResponseSnapshot.reasoningText } : {}),
484
+ ...(autoResponseSnapshot.responseExcerpt ? { responseExcerpt: autoResponseSnapshot.responseExcerpt } : {}),
485
+ followupText
486
+ })
487
+ : [];
488
+ const nextUsed = used + 1;
489
+ updateCompare({ used: nextUsed });
490
+ if (stickyKey) {
491
+ const nextState = stickyState ??
492
+ createStopMessageState({
493
+ text,
494
+ maxRepeats,
495
+ used,
496
+ ...(snapshot.source ? { source: snapshot.source } : {}),
497
+ ...(snapshot.updatedAt ? { updatedAt: snapshot.updatedAt } : {}),
498
+ ...(snapshot.lastUsedAt ? { lastUsedAt: snapshot.lastUsedAt } : {}),
499
+ ...(snapshot.stageMode ? { stageMode: snapshot.stageMode } : {}),
500
+ aiMode,
501
+ aiSeedPrompt: fallbackCandidateFollowupText,
502
+ aiHistory: existingHistory
503
+ });
504
+ const now = Date.now();
505
+ if (nextUsed >= maxRepeats) {
506
+ clearStopMessageState(nextState, now);
507
+ }
508
+ else {
509
+ nextState.stopMessageText = text;
510
+ nextState.stopMessageMaxRepeats = maxRepeats;
511
+ nextState.stopMessageUsed = nextUsed;
512
+ nextState.stopMessageStageMode = mode;
513
+ nextState.stopMessageAiMode = aiMode;
514
+ nextState.stopMessageLastUsedAt = now;
515
+ nextState.stopMessageAiSeedPrompt = fallbackCandidateFollowupText;
516
+ nextState.stopMessageAiHistory =
517
+ aiMode === 'on' && nextHistory.length > 0
518
+ ? nextHistory.map((entry) => ({ ...entry }))
519
+ : undefined;
520
+ }
521
+ persistStopMessageState(stickyKey, nextState);
194
522
  }
195
- const followupProviderKey = resolveStopMessageFollowupProviderKey({ record, runtimeMetadata: rt });
196
- const followupToolContentMaxChars = resolveStopMessageFollowupToolContentMaxChars({
197
- providerKey: followupProviderKey,
198
- model: seed.model
199
- });
200
- const followupOps = [];
201
- if (typeof followupToolContentMaxChars === 'number' &&
202
- Number.isFinite(followupToolContentMaxChars) &&
203
- followupToolContentMaxChars > 0) {
204
- followupOps.push({ op: 'compact_tool_content', maxChars: Math.floor(followupToolContentMaxChars) });
205
- }
206
- followupOps.push({ op: 'ensure_standard_tools' });
207
- followupOps.push({ op: 'inject_system_text', text: STOP_MESSAGE_EXECUTION_DIRECTIVE });
208
- followupOps.push({ op: 'append_user_text', text: followupText });
209
523
  updateCompare({
210
524
  decision: 'trigger',
211
525
  reason: 'triggered'
212
526
  });
527
+ // stop_message uses clientInjectOnly path only (tmux injection), no servertool followup reenter
213
528
  return {
214
529
  flowId: FLOW_ID,
215
530
  finalize: async () => ({
@@ -218,11 +533,12 @@ const handler = async (ctx) => {
218
533
  flowId: FLOW_ID,
219
534
  followup: {
220
535
  requestIdSuffix: ':stop_followup',
221
- entryEndpoint,
222
- injection: {
223
- ops: followupOps
224
- },
225
- metadata: (connectionState ? { clientConnectionState: connectionState } : {})
536
+ metadata: {
537
+ ...(connectionState ? { clientConnectionState: connectionState } : {}),
538
+ clientInjectOnly: true,
539
+ clientInjectText: followupText,
540
+ clientInjectSource: 'servertool.stop_message'
541
+ }
226
542
  }
227
543
  }
228
544
  })
@@ -9,6 +9,7 @@ import './handlers/clock-auto.js';
9
9
  import './handlers/exec-command-guard.js';
10
10
  import './handlers/apply-patch-guard.js';
11
11
  import './handlers/continue-execution.js';
12
+ import './handlers/review.js';
12
13
  export declare function runServerSideToolEngine(options: ServerSideToolEngineOptions): Promise<ServerSideToolEngineResult>;
13
14
  export declare function extractToolCalls(chatResponse: JsonObject): ToolCall[];
14
15
  export declare function cloneJson<T>(value: T): T;