pi-proactive 0.0.0-stage → 0.2.0-beta.3

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 (1430) hide show
  1. package/CHANGELOG.md +148 -0
  2. package/LICENSE +54 -0
  3. package/README.md +709 -2
  4. package/build/cli.mjs +121 -0
  5. package/build/extensions/proactive.js +2508 -0
  6. package/build/src/activity.js +130 -0
  7. package/build/src/commands.js +572 -0
  8. package/build/src/config.js +990 -0
  9. package/build/src/content.js +198 -0
  10. package/build/src/daemon-config.js +709 -0
  11. package/build/src/daemon-contact.js +103 -0
  12. package/build/src/daemon-host.js +84 -0
  13. package/build/src/daemon.js +892 -0
  14. package/build/src/dedupe.js +187 -0
  15. package/build/src/envelope.js +283 -0
  16. package/build/src/guard.js +74 -0
  17. package/build/src/health.js +818 -0
  18. package/build/src/idle.js +388 -0
  19. package/build/src/lineage.js +465 -0
  20. package/build/src/mailbox.js +984 -0
  21. package/build/src/notify.js +183 -0
  22. package/build/src/outbox.js +26 -0
  23. package/build/src/peer-spawn.js +383 -0
  24. package/build/src/peer.js +1002 -0
  25. package/build/src/progress-eta.js +134 -0
  26. package/build/src/registry.js +583 -0
  27. package/build/src/scheduler.js +301 -0
  28. package/build/src/socket.js +496 -0
  29. package/build/src/task-store.js +438 -0
  30. package/build/src/thread.js +196 -0
  31. package/build/src/trigger.js +501 -0
  32. package/build/src/trust-loop.js +321 -0
  33. package/build/src/trust-metrics.js +236 -0
  34. package/build/src/trust-notify.js +73 -0
  35. package/build/src/trust-policy.js +58 -0
  36. package/build/src/trust-registry.js +323 -0
  37. package/build/src/types.js +1 -0
  38. package/daemon/launchd.plist +48 -0
  39. package/daemon/pi-proactive-daemon.service +29 -0
  40. package/daemon/run-daemon.sh +84 -0
  41. package/node_modules/typebox/build/compile/code.d.mts +12 -0
  42. package/node_modules/typebox/build/compile/code.mjs +65 -0
  43. package/node_modules/typebox/build/compile/compile.d.mts +6 -0
  44. package/node_modules/typebox/build/compile/compile.mjs +12 -0
  45. package/node_modules/typebox/build/compile/index.d.mts +8 -0
  46. package/node_modules/typebox/build/compile/index.mjs +14 -0
  47. package/node_modules/typebox/build/compile/validator.d.mts +35 -0
  48. package/node_modules/typebox/build/compile/validator.mjs +91 -0
  49. package/node_modules/typebox/build/error/errors.d.mts +208 -0
  50. package/node_modules/typebox/build/error/errors.mjs +18 -0
  51. package/node_modules/typebox/build/error/index.d.mts +1 -0
  52. package/node_modules/typebox/build/error/index.mjs +1 -0
  53. package/node_modules/typebox/build/format/_registry.d.mts +15 -0
  54. package/node_modules/typebox/build/format/_registry.mjs +96 -0
  55. package/node_modules/typebox/build/format/date.d.mts +6 -0
  56. package/node_modules/typebox/build/format/date.mjs +19 -0
  57. package/node_modules/typebox/build/format/date_time.d.mts +6 -0
  58. package/node_modules/typebox/build/format/date_time.mjs +11 -0
  59. package/node_modules/typebox/build/format/duration.d.mts +5 -0
  60. package/node_modules/typebox/build/format/duration.mjs +8 -0
  61. package/node_modules/typebox/build/format/email.d.mts +5 -0
  62. package/node_modules/typebox/build/format/email.mjs +8 -0
  63. package/node_modules/typebox/build/format/format.d.mts +22 -0
  64. package/node_modules/typebox/build/format/format.mjs +22 -0
  65. package/node_modules/typebox/build/format/hostname.d.mts +7 -0
  66. package/node_modules/typebox/build/format/hostname.mjs +10 -0
  67. package/node_modules/typebox/build/format/idn_email.d.mts +5 -0
  68. package/node_modules/typebox/build/format/idn_email.mjs +8 -0
  69. package/node_modules/typebox/build/format/idn_hostname.d.mts +8 -0
  70. package/node_modules/typebox/build/format/idn_hostname.mjs +11 -0
  71. package/node_modules/typebox/build/format/idna/format/bidi.d.mts +3 -0
  72. package/node_modules/typebox/build/format/idna/format/bidi.mjs +98 -0
  73. package/node_modules/typebox/build/format/idna/format/puny.d.mts +3 -0
  74. package/node_modules/typebox/build/format/idna/format/puny.mjs +144 -0
  75. package/node_modules/typebox/build/format/idna/hostname.d.mts +1 -0
  76. package/node_modules/typebox/build/format/idna/hostname.mjs +16 -0
  77. package/node_modules/typebox/build/format/idna/idn-hostname.d.mts +1 -0
  78. package/node_modules/typebox/build/format/idna/idn-hostname.mjs +43 -0
  79. package/node_modules/typebox/build/format/idna/index.d.mts +2 -0
  80. package/node_modules/typebox/build/format/idna/index.mjs +2 -0
  81. package/node_modules/typebox/build/format/idna/label/ascii.d.mts +1 -0
  82. package/node_modules/typebox/build/format/idna/label/ascii.mjs +9 -0
  83. package/node_modules/typebox/build/format/idna/label/puny.d.mts +1 -0
  84. package/node_modules/typebox/build/format/idna/label/puny.mjs +28 -0
  85. package/node_modules/typebox/build/format/idna/label/unicode.d.mts +1 -0
  86. package/node_modules/typebox/build/format/idna/label/unicode.mjs +106 -0
  87. package/node_modules/typebox/build/format/idna/pattern/pattern.d.mts +30 -0
  88. package/node_modules/typebox/build/format/idna/pattern/pattern.mjs +70 -0
  89. package/node_modules/typebox/build/format/index.d.mts +4 -0
  90. package/node_modules/typebox/build/format/index.mjs +4 -0
  91. package/node_modules/typebox/build/format/ipv4.d.mts +5 -0
  92. package/node_modules/typebox/build/format/ipv4.mjs +8 -0
  93. package/node_modules/typebox/build/format/ipv6.d.mts +5 -0
  94. package/node_modules/typebox/build/format/ipv6.mjs +8 -0
  95. package/node_modules/typebox/build/format/iri.d.mts +5 -0
  96. package/node_modules/typebox/build/format/iri.mjs +35 -0
  97. package/node_modules/typebox/build/format/iri_reference.d.mts +5 -0
  98. package/node_modules/typebox/build/format/iri_reference.mjs +14 -0
  99. package/node_modules/typebox/build/format/json_pointer.d.mts +6 -0
  100. package/node_modules/typebox/build/format/json_pointer.mjs +9 -0
  101. package/node_modules/typebox/build/format/json_pointer_uri_fragment.d.mts +6 -0
  102. package/node_modules/typebox/build/format/json_pointer_uri_fragment.mjs +9 -0
  103. package/node_modules/typebox/build/format/regex.d.mts +5 -0
  104. package/node_modules/typebox/build/format/regex.mjs +13 -0
  105. package/node_modules/typebox/build/format/relative_json_pointer.d.mts +6 -0
  106. package/node_modules/typebox/build/format/relative_json_pointer.mjs +9 -0
  107. package/node_modules/typebox/build/format/time.d.mts +5 -0
  108. package/node_modules/typebox/build/format/time.mjs +32 -0
  109. package/node_modules/typebox/build/format/uri.d.mts +5 -0
  110. package/node_modules/typebox/build/format/uri.mjs +8 -0
  111. package/node_modules/typebox/build/format/uri_reference.d.mts +5 -0
  112. package/node_modules/typebox/build/format/uri_reference.mjs +8 -0
  113. package/node_modules/typebox/build/format/uri_template.d.mts +5 -0
  114. package/node_modules/typebox/build/format/uri_template.mjs +9 -0
  115. package/node_modules/typebox/build/format/url.d.mts +6 -0
  116. package/node_modules/typebox/build/format/url.mjs +8 -0
  117. package/node_modules/typebox/build/format/uuid.d.mts +6 -0
  118. package/node_modules/typebox/build/format/uuid.mjs +9 -0
  119. package/node_modules/typebox/build/guard/emit.d.mts +56 -0
  120. package/node_modules/typebox/build/guard/emit.mjs +191 -0
  121. package/node_modules/typebox/build/guard/globals.d.mts +35 -0
  122. package/node_modules/typebox/build/guard/globals.mjs +90 -0
  123. package/node_modules/typebox/build/guard/guard.d.mts +71 -0
  124. package/node_modules/typebox/build/guard/guard.mjs +221 -0
  125. package/node_modules/typebox/build/guard/index.d.mts +6 -0
  126. package/node_modules/typebox/build/guard/index.mjs +6 -0
  127. package/node_modules/typebox/build/guard/native.d.mts +20 -0
  128. package/node_modules/typebox/build/guard/native.mjs +60 -0
  129. package/node_modules/typebox/build/guard/string.d.mts +6 -0
  130. package/node_modules/typebox/build/guard/string.mjs +168 -0
  131. package/node_modules/typebox/build/index.d.mts +8 -0
  132. package/node_modules/typebox/build/index.mjs +14 -0
  133. package/node_modules/typebox/build/schema/build.d.mts +39 -0
  134. package/node_modules/typebox/build/schema/build.mjs +118 -0
  135. package/node_modules/typebox/build/schema/check.d.mts +6 -0
  136. package/node_modules/typebox/build/schema/check.mjs +14 -0
  137. package/node_modules/typebox/build/schema/compile.d.mts +23 -0
  138. package/node_modules/typebox/build/schema/compile.mjs +46 -0
  139. package/node_modules/typebox/build/schema/engine/_context.d.mts +30 -0
  140. package/node_modules/typebox/build/schema/engine/_context.mjs +124 -0
  141. package/node_modules/typebox/build/schema/engine/_exact_optional.d.mts +3 -0
  142. package/node_modules/typebox/build/schema/engine/_exact_optional.mjs +20 -0
  143. package/node_modules/typebox/build/schema/engine/_externals.d.mts +7 -0
  144. package/node_modules/typebox/build/schema/engine/_externals.mjs +25 -0
  145. package/node_modules/typebox/build/schema/engine/_functions.d.mts +6 -0
  146. package/node_modules/typebox/build/schema/engine/_functions.mjs +65 -0
  147. package/node_modules/typebox/build/schema/engine/_reducer.d.mts +4 -0
  148. package/node_modules/typebox/build/schema/engine/_reducer.mjs +45 -0
  149. package/node_modules/typebox/build/schema/engine/_refine.d.mts +6 -0
  150. package/node_modules/typebox/build/schema/engine/_refine.mjs +29 -0
  151. package/node_modules/typebox/build/schema/engine/_regexp.d.mts +2 -0
  152. package/node_modules/typebox/build/schema/engine/_regexp.mjs +4 -0
  153. package/node_modules/typebox/build/schema/engine/_stack.d.mts +22 -0
  154. package/node_modules/typebox/build/schema/engine/_stack.mjs +209 -0
  155. package/node_modules/typebox/build/schema/engine/_unique.d.mts +2 -0
  156. package/node_modules/typebox/build/schema/engine/_unique.mjs +5 -0
  157. package/node_modules/typebox/build/schema/engine/additionalItems.d.mts +6 -0
  158. package/node_modules/typebox/build/schema/engine/additionalItems.mjs +60 -0
  159. package/node_modules/typebox/build/schema/engine/additionalProperties.d.mts +9 -0
  160. package/node_modules/typebox/build/schema/engine/additionalProperties.mjs +123 -0
  161. package/node_modules/typebox/build/schema/engine/allOf.d.mts +6 -0
  162. package/node_modules/typebox/build/schema/engine/allOf.mjs +47 -0
  163. package/node_modules/typebox/build/schema/engine/anyOf.d.mts +6 -0
  164. package/node_modules/typebox/build/schema/engine/anyOf.mjs +52 -0
  165. package/node_modules/typebox/build/schema/engine/boolean.d.mts +5 -0
  166. package/node_modules/typebox/build/schema/engine/boolean.mjs +25 -0
  167. package/node_modules/typebox/build/schema/engine/const.d.mts +6 -0
  168. package/node_modules/typebox/build/schema/engine/const.mjs +30 -0
  169. package/node_modules/typebox/build/schema/engine/contains.d.mts +6 -0
  170. package/node_modules/typebox/build/schema/engine/contains.mjs +54 -0
  171. package/node_modules/typebox/build/schema/engine/dependencies.d.mts +6 -0
  172. package/node_modules/typebox/build/schema/engine/dependencies.mjs +45 -0
  173. package/node_modules/typebox/build/schema/engine/dependentRequired.d.mts +6 -0
  174. package/node_modules/typebox/build/schema/engine/dependentRequired.mjs +40 -0
  175. package/node_modules/typebox/build/schema/engine/dependentSchemas.d.mts +6 -0
  176. package/node_modules/typebox/build/schema/engine/dependentSchemas.mjs +38 -0
  177. package/node_modules/typebox/build/schema/engine/dynamicRef.d.mts +6 -0
  178. package/node_modules/typebox/build/schema/engine/dynamicRef.mjs +25 -0
  179. package/node_modules/typebox/build/schema/engine/enum.d.mts +6 -0
  180. package/node_modules/typebox/build/schema/engine/enum.mjs +33 -0
  181. package/node_modules/typebox/build/schema/engine/exclusiveMaximum.d.mts +6 -0
  182. package/node_modules/typebox/build/schema/engine/exclusiveMaximum.mjs +25 -0
  183. package/node_modules/typebox/build/schema/engine/exclusiveMinimum.d.mts +6 -0
  184. package/node_modules/typebox/build/schema/engine/exclusiveMinimum.mjs +25 -0
  185. package/node_modules/typebox/build/schema/engine/format.d.mts +6 -0
  186. package/node_modules/typebox/build/schema/engine/format.mjs +26 -0
  187. package/node_modules/typebox/build/schema/engine/if.d.mts +6 -0
  188. package/node_modules/typebox/build/schema/engine/if.mjs +47 -0
  189. package/node_modules/typebox/build/schema/engine/index.d.mts +48 -0
  190. package/node_modules/typebox/build/schema/engine/index.mjs +54 -0
  191. package/node_modules/typebox/build/schema/engine/items.d.mts +6 -0
  192. package/node_modules/typebox/build/schema/engine/items.mjs +88 -0
  193. package/node_modules/typebox/build/schema/engine/maxContains.d.mts +6 -0
  194. package/node_modules/typebox/build/schema/engine/maxContains.mjs +42 -0
  195. package/node_modules/typebox/build/schema/engine/maxItems.d.mts +6 -0
  196. package/node_modules/typebox/build/schema/engine/maxItems.mjs +25 -0
  197. package/node_modules/typebox/build/schema/engine/maxLength.d.mts +6 -0
  198. package/node_modules/typebox/build/schema/engine/maxLength.mjs +25 -0
  199. package/node_modules/typebox/build/schema/engine/maxProperties.d.mts +6 -0
  200. package/node_modules/typebox/build/schema/engine/maxProperties.mjs +25 -0
  201. package/node_modules/typebox/build/schema/engine/maximum.d.mts +6 -0
  202. package/node_modules/typebox/build/schema/engine/maximum.mjs +25 -0
  203. package/node_modules/typebox/build/schema/engine/minContains.d.mts +6 -0
  204. package/node_modules/typebox/build/schema/engine/minContains.mjs +51 -0
  205. package/node_modules/typebox/build/schema/engine/minItems.d.mts +6 -0
  206. package/node_modules/typebox/build/schema/engine/minItems.mjs +25 -0
  207. package/node_modules/typebox/build/schema/engine/minLength.d.mts +6 -0
  208. package/node_modules/typebox/build/schema/engine/minLength.mjs +25 -0
  209. package/node_modules/typebox/build/schema/engine/minProperties.d.mts +6 -0
  210. package/node_modules/typebox/build/schema/engine/minProperties.mjs +25 -0
  211. package/node_modules/typebox/build/schema/engine/minimum.d.mts +6 -0
  212. package/node_modules/typebox/build/schema/engine/minimum.mjs +25 -0
  213. package/node_modules/typebox/build/schema/engine/multipleOf.d.mts +6 -0
  214. package/node_modules/typebox/build/schema/engine/multipleOf.mjs +25 -0
  215. package/node_modules/typebox/build/schema/engine/not.d.mts +6 -0
  216. package/node_modules/typebox/build/schema/engine/not.mjs +39 -0
  217. package/node_modules/typebox/build/schema/engine/oneOf.d.mts +6 -0
  218. package/node_modules/typebox/build/schema/engine/oneOf.mjs +59 -0
  219. package/node_modules/typebox/build/schema/engine/pattern.d.mts +6 -0
  220. package/node_modules/typebox/build/schema/engine/pattern.mjs +29 -0
  221. package/node_modules/typebox/build/schema/engine/patternProperties.d.mts +6 -0
  222. package/node_modules/typebox/build/schema/engine/patternProperties.mjs +45 -0
  223. package/node_modules/typebox/build/schema/engine/prefixItems.d.mts +6 -0
  224. package/node_modules/typebox/build/schema/engine/prefixItems.mjs +35 -0
  225. package/node_modules/typebox/build/schema/engine/properties.d.mts +6 -0
  226. package/node_modules/typebox/build/schema/engine/properties.mjs +75 -0
  227. package/node_modules/typebox/build/schema/engine/propertyNames.d.mts +6 -0
  228. package/node_modules/typebox/build/schema/engine/propertyNames.mjs +37 -0
  229. package/node_modules/typebox/build/schema/engine/recursiveRef.d.mts +6 -0
  230. package/node_modules/typebox/build/schema/engine/recursiveRef.mjs +25 -0
  231. package/node_modules/typebox/build/schema/engine/ref.d.mts +6 -0
  232. package/node_modules/typebox/build/schema/engine/ref.mjs +52 -0
  233. package/node_modules/typebox/build/schema/engine/required.d.mts +6 -0
  234. package/node_modules/typebox/build/schema/engine/required.mjs +32 -0
  235. package/node_modules/typebox/build/schema/engine/schema.d.mts +9 -0
  236. package/node_modules/typebox/build/schema/engine/schema.mjs +362 -0
  237. package/node_modules/typebox/build/schema/engine/type.d.mts +6 -0
  238. package/node_modules/typebox/build/schema/engine/type.mjs +70 -0
  239. package/node_modules/typebox/build/schema/engine/unevaluatedItems.d.mts +6 -0
  240. package/node_modules/typebox/build/schema/engine/unevaluatedItems.mjs +51 -0
  241. package/node_modules/typebox/build/schema/engine/unevaluatedProperties.d.mts +6 -0
  242. package/node_modules/typebox/build/schema/engine/unevaluatedProperties.mjs +51 -0
  243. package/node_modules/typebox/build/schema/engine/uniqueItems.d.mts +6 -0
  244. package/node_modules/typebox/build/schema/engine/uniqueItems.mjs +51 -0
  245. package/node_modules/typebox/build/schema/errors.d.mts +6 -0
  246. package/node_modules/typebox/build/schema/errors.mjs +18 -0
  247. package/node_modules/typebox/build/schema/index.d.mts +3 -0
  248. package/node_modules/typebox/build/schema/index.mjs +9 -0
  249. package/node_modules/typebox/build/schema/intern/index.d.mts +1 -0
  250. package/node_modules/typebox/build/schema/intern/index.mjs +1 -0
  251. package/node_modules/typebox/build/schema/intern/intern.d.mts +14 -0
  252. package/node_modules/typebox/build/schema/intern/intern.mjs +259 -0
  253. package/node_modules/typebox/build/schema/parse.d.mts +14 -0
  254. package/node_modules/typebox/build/schema/parse.mjs +32 -0
  255. package/node_modules/typebox/build/schema/pointer/index.d.mts +2 -0
  256. package/node_modules/typebox/build/schema/pointer/index.mjs +2 -0
  257. package/node_modules/typebox/build/schema/pointer/pointer.d.mts +10 -0
  258. package/node_modules/typebox/build/schema/pointer/pointer.mjs +106 -0
  259. package/node_modules/typebox/build/schema/pointer/pointer_get.d.mts +9 -0
  260. package/node_modules/typebox/build/schema/pointer/pointer_get.mjs +2 -0
  261. package/node_modules/typebox/build/schema/resolve/index.d.mts +1 -0
  262. package/node_modules/typebox/build/schema/resolve/index.mjs +1 -0
  263. package/node_modules/typebox/build/schema/resolve/resolve.d.mts +35 -0
  264. package/node_modules/typebox/build/schema/resolve/resolve.mjs +327 -0
  265. package/node_modules/typebox/build/schema/schema.d.mts +11 -0
  266. package/node_modules/typebox/build/schema/schema.mjs +11 -0
  267. package/node_modules/typebox/build/schema/static/_canonical.d.mts +7 -0
  268. package/node_modules/typebox/build/schema/static/_canonical.mjs +2 -0
  269. package/node_modules/typebox/build/schema/static/_comparer.d.mts +6 -0
  270. package/node_modules/typebox/build/schema/static/_comparer.mjs +2 -0
  271. package/node_modules/typebox/build/schema/static/_elements.d.mts +18 -0
  272. package/node_modules/typebox/build/schema/static/_elements.mjs +2 -0
  273. package/node_modules/typebox/build/schema/static/additionalProperties.d.mts +7 -0
  274. package/node_modules/typebox/build/schema/static/additionalProperties.mjs +3 -0
  275. package/node_modules/typebox/build/schema/static/allOf.d.mts +3 -0
  276. package/node_modules/typebox/build/schema/static/allOf.mjs +2 -0
  277. package/node_modules/typebox/build/schema/static/anyOf.d.mts +3 -0
  278. package/node_modules/typebox/build/schema/static/anyOf.mjs +2 -0
  279. package/node_modules/typebox/build/schema/static/const.d.mts +1 -0
  280. package/node_modules/typebox/build/schema/static/const.mjs +2 -0
  281. package/node_modules/typebox/build/schema/static/enum.d.mts +1 -0
  282. package/node_modules/typebox/build/schema/static/enum.mjs +2 -0
  283. package/node_modules/typebox/build/schema/static/if.d.mts +15 -0
  284. package/node_modules/typebox/build/schema/static/if.mjs +2 -0
  285. package/node_modules/typebox/build/schema/static/index.d.mts +1 -0
  286. package/node_modules/typebox/build/schema/static/index.mjs +1 -0
  287. package/node_modules/typebox/build/schema/static/items.d.mts +7 -0
  288. package/node_modules/typebox/build/schema/static/items.mjs +2 -0
  289. package/node_modules/typebox/build/schema/static/oneOf.d.mts +3 -0
  290. package/node_modules/typebox/build/schema/static/oneOf.mjs +2 -0
  291. package/node_modules/typebox/build/schema/static/patternProperties.d.mts +7 -0
  292. package/node_modules/typebox/build/schema/static/patternProperties.mjs +2 -0
  293. package/node_modules/typebox/build/schema/static/prefixItems.d.mts +3 -0
  294. package/node_modules/typebox/build/schema/static/prefixItems.mjs +2 -0
  295. package/node_modules/typebox/build/schema/static/properties.d.mts +32 -0
  296. package/node_modules/typebox/build/schema/static/properties.mjs +2 -0
  297. package/node_modules/typebox/build/schema/static/propertyNames.d.mts +5 -0
  298. package/node_modules/typebox/build/schema/static/propertyNames.mjs +3 -0
  299. package/node_modules/typebox/build/schema/static/ref.d.mts +8 -0
  300. package/node_modules/typebox/build/schema/static/ref.mjs +3 -0
  301. package/node_modules/typebox/build/schema/static/required.d.mts +3 -0
  302. package/node_modules/typebox/build/schema/static/required.mjs +3 -0
  303. package/node_modules/typebox/build/schema/static/schema.d.mts +59 -0
  304. package/node_modules/typebox/build/schema/static/schema.mjs +2 -0
  305. package/node_modules/typebox/build/schema/static/static.d.mts +4 -0
  306. package/node_modules/typebox/build/schema/static/static.mjs +3 -0
  307. package/node_modules/typebox/build/schema/static/type.d.mts +4 -0
  308. package/node_modules/typebox/build/schema/static/type.mjs +3 -0
  309. package/node_modules/typebox/build/schema/static/unevaluatedProperties.d.mts +7 -0
  310. package/node_modules/typebox/build/schema/static/unevaluatedProperties.mjs +3 -0
  311. package/node_modules/typebox/build/schema/types/_refine.d.mts +13 -0
  312. package/node_modules/typebox/build/schema/types/_refine.mjs +18 -0
  313. package/node_modules/typebox/build/schema/types/additionalItems.d.mts +9 -0
  314. package/node_modules/typebox/build/schema/types/additionalItems.mjs +14 -0
  315. package/node_modules/typebox/build/schema/types/additionalProperties.d.mts +9 -0
  316. package/node_modules/typebox/build/schema/types/additionalProperties.mjs +14 -0
  317. package/node_modules/typebox/build/schema/types/allOf.d.mts +9 -0
  318. package/node_modules/typebox/build/schema/types/allOf.mjs +15 -0
  319. package/node_modules/typebox/build/schema/types/anchor.d.mts +8 -0
  320. package/node_modules/typebox/build/schema/types/anchor.mjs +12 -0
  321. package/node_modules/typebox/build/schema/types/anyOf.d.mts +9 -0
  322. package/node_modules/typebox/build/schema/types/anyOf.mjs +15 -0
  323. package/node_modules/typebox/build/schema/types/const.d.mts +9 -0
  324. package/node_modules/typebox/build/schema/types/const.mjs +12 -0
  325. package/node_modules/typebox/build/schema/types/contains.d.mts +9 -0
  326. package/node_modules/typebox/build/schema/types/contains.mjs +14 -0
  327. package/node_modules/typebox/build/schema/types/default.d.mts +9 -0
  328. package/node_modules/typebox/build/schema/types/default.mjs +12 -0
  329. package/node_modules/typebox/build/schema/types/defs.d.mts +6 -0
  330. package/node_modules/typebox/build/schema/types/defs.mjs +12 -0
  331. package/node_modules/typebox/build/schema/types/dependencies.d.mts +11 -0
  332. package/node_modules/typebox/build/schema/types/dependencies.mjs +16 -0
  333. package/node_modules/typebox/build/schema/types/dependentRequired.d.mts +9 -0
  334. package/node_modules/typebox/build/schema/types/dependentRequired.mjs +15 -0
  335. package/node_modules/typebox/build/schema/types/dependentSchemas.d.mts +9 -0
  336. package/node_modules/typebox/build/schema/types/dependentSchemas.mjs +15 -0
  337. package/node_modules/typebox/build/schema/types/dynamicAnchor.d.mts +8 -0
  338. package/node_modules/typebox/build/schema/types/dynamicAnchor.mjs +12 -0
  339. package/node_modules/typebox/build/schema/types/dynamicRef.d.mts +8 -0
  340. package/node_modules/typebox/build/schema/types/dynamicRef.mjs +12 -0
  341. package/node_modules/typebox/build/schema/types/else.d.mts +9 -0
  342. package/node_modules/typebox/build/schema/types/else.mjs +14 -0
  343. package/node_modules/typebox/build/schema/types/enum.d.mts +9 -0
  344. package/node_modules/typebox/build/schema/types/enum.mjs +13 -0
  345. package/node_modules/typebox/build/schema/types/exclusiveMaximum.d.mts +9 -0
  346. package/node_modules/typebox/build/schema/types/exclusiveMaximum.mjs +13 -0
  347. package/node_modules/typebox/build/schema/types/exclusiveMinimum.d.mts +9 -0
  348. package/node_modules/typebox/build/schema/types/exclusiveMinimum.mjs +13 -0
  349. package/node_modules/typebox/build/schema/types/format.d.mts +9 -0
  350. package/node_modules/typebox/build/schema/types/format.mjs +13 -0
  351. package/node_modules/typebox/build/schema/types/id.d.mts +9 -0
  352. package/node_modules/typebox/build/schema/types/id.mjs +13 -0
  353. package/node_modules/typebox/build/schema/types/if.d.mts +9 -0
  354. package/node_modules/typebox/build/schema/types/if.mjs +14 -0
  355. package/node_modules/typebox/build/schema/types/index.d.mts +51 -0
  356. package/node_modules/typebox/build/schema/types/index.mjs +57 -0
  357. package/node_modules/typebox/build/schema/types/items.d.mts +19 -0
  358. package/node_modules/typebox/build/schema/types/items.mjs +26 -0
  359. package/node_modules/typebox/build/schema/types/maxContains.d.mts +9 -0
  360. package/node_modules/typebox/build/schema/types/maxContains.mjs +13 -0
  361. package/node_modules/typebox/build/schema/types/maxItems.d.mts +9 -0
  362. package/node_modules/typebox/build/schema/types/maxItems.mjs +13 -0
  363. package/node_modules/typebox/build/schema/types/maxLength.d.mts +9 -0
  364. package/node_modules/typebox/build/schema/types/maxLength.mjs +13 -0
  365. package/node_modules/typebox/build/schema/types/maxProperties.d.mts +9 -0
  366. package/node_modules/typebox/build/schema/types/maxProperties.mjs +13 -0
  367. package/node_modules/typebox/build/schema/types/maximum.d.mts +9 -0
  368. package/node_modules/typebox/build/schema/types/maximum.mjs +13 -0
  369. package/node_modules/typebox/build/schema/types/minContains.d.mts +9 -0
  370. package/node_modules/typebox/build/schema/types/minContains.mjs +13 -0
  371. package/node_modules/typebox/build/schema/types/minItems.d.mts +9 -0
  372. package/node_modules/typebox/build/schema/types/minItems.mjs +13 -0
  373. package/node_modules/typebox/build/schema/types/minLength.d.mts +9 -0
  374. package/node_modules/typebox/build/schema/types/minLength.mjs +13 -0
  375. package/node_modules/typebox/build/schema/types/minProperties.d.mts +9 -0
  376. package/node_modules/typebox/build/schema/types/minProperties.mjs +13 -0
  377. package/node_modules/typebox/build/schema/types/minimum.d.mts +9 -0
  378. package/node_modules/typebox/build/schema/types/minimum.mjs +13 -0
  379. package/node_modules/typebox/build/schema/types/multipleOf.d.mts +9 -0
  380. package/node_modules/typebox/build/schema/types/multipleOf.mjs +13 -0
  381. package/node_modules/typebox/build/schema/types/not.d.mts +9 -0
  382. package/node_modules/typebox/build/schema/types/not.mjs +14 -0
  383. package/node_modules/typebox/build/schema/types/oneOf.d.mts +9 -0
  384. package/node_modules/typebox/build/schema/types/oneOf.mjs +15 -0
  385. package/node_modules/typebox/build/schema/types/pattern.d.mts +9 -0
  386. package/node_modules/typebox/build/schema/types/pattern.mjs +14 -0
  387. package/node_modules/typebox/build/schema/types/patternProperties.d.mts +9 -0
  388. package/node_modules/typebox/build/schema/types/patternProperties.mjs +15 -0
  389. package/node_modules/typebox/build/schema/types/prefixItems.d.mts +8 -0
  390. package/node_modules/typebox/build/schema/types/prefixItems.mjs +14 -0
  391. package/node_modules/typebox/build/schema/types/properties.d.mts +9 -0
  392. package/node_modules/typebox/build/schema/types/properties.mjs +15 -0
  393. package/node_modules/typebox/build/schema/types/propertyNames.d.mts +9 -0
  394. package/node_modules/typebox/build/schema/types/propertyNames.mjs +15 -0
  395. package/node_modules/typebox/build/schema/types/recursiveAnchor.d.mts +12 -0
  396. package/node_modules/typebox/build/schema/types/recursiveAnchor.mjs +19 -0
  397. package/node_modules/typebox/build/schema/types/recursiveRef.d.mts +8 -0
  398. package/node_modules/typebox/build/schema/types/recursiveRef.mjs +12 -0
  399. package/node_modules/typebox/build/schema/types/ref.d.mts +9 -0
  400. package/node_modules/typebox/build/schema/types/ref.mjs +13 -0
  401. package/node_modules/typebox/build/schema/types/required.d.mts +9 -0
  402. package/node_modules/typebox/build/schema/types/required.mjs +14 -0
  403. package/node_modules/typebox/build/schema/types/schema.d.mts +9 -0
  404. package/node_modules/typebox/build/schema/types/schema.mjs +14 -0
  405. package/node_modules/typebox/build/schema/types/then.d.mts +9 -0
  406. package/node_modules/typebox/build/schema/types/then.mjs +14 -0
  407. package/node_modules/typebox/build/schema/types/type.d.mts +9 -0
  408. package/node_modules/typebox/build/schema/types/type.mjs +15 -0
  409. package/node_modules/typebox/build/schema/types/unevaluatedItems.d.mts +9 -0
  410. package/node_modules/typebox/build/schema/types/unevaluatedItems.mjs +14 -0
  411. package/node_modules/typebox/build/schema/types/unevaluatedProperties.d.mts +9 -0
  412. package/node_modules/typebox/build/schema/types/unevaluatedProperties.mjs +14 -0
  413. package/node_modules/typebox/build/schema/types/uniqueItems.d.mts +9 -0
  414. package/node_modules/typebox/build/schema/types/uniqueItems.mjs +13 -0
  415. package/node_modules/typebox/build/system/arguments/arguments.d.mts +5 -0
  416. package/node_modules/typebox/build/system/arguments/arguments.mjs +9 -0
  417. package/node_modules/typebox/build/system/arguments/index.d.mts +1 -0
  418. package/node_modules/typebox/build/system/arguments/index.mjs +1 -0
  419. package/node_modules/typebox/build/system/environment/environment.d.mts +1 -0
  420. package/node_modules/typebox/build/system/environment/environment.mjs +1 -0
  421. package/node_modules/typebox/build/system/environment/evaluate.d.mts +9 -0
  422. package/node_modules/typebox/build/system/environment/evaluate.mjs +37 -0
  423. package/node_modules/typebox/build/system/environment/index.d.mts +1 -0
  424. package/node_modules/typebox/build/system/environment/index.mjs +1 -0
  425. package/node_modules/typebox/build/system/hashing/hash.d.mts +4 -0
  426. package/node_modules/typebox/build/system/hashing/hash.mjs +232 -0
  427. package/node_modules/typebox/build/system/hashing/index.d.mts +1 -0
  428. package/node_modules/typebox/build/system/hashing/index.mjs +1 -0
  429. package/node_modules/typebox/build/system/index.d.mts +4 -0
  430. package/node_modules/typebox/build/system/index.mjs +4 -0
  431. package/node_modules/typebox/build/system/locale/_config.d.mts +7 -0
  432. package/node_modules/typebox/build/system/locale/_config.mjs +15 -0
  433. package/node_modules/typebox/build/system/locale/_locale.d.mts +40 -0
  434. package/node_modules/typebox/build/system/locale/_locale.mjs +40 -0
  435. package/node_modules/typebox/build/system/locale/ar_001.d.mts +3 -0
  436. package/node_modules/typebox/build/system/locale/ar_001.mjs +40 -0
  437. package/node_modules/typebox/build/system/locale/bn_BD.d.mts +3 -0
  438. package/node_modules/typebox/build/system/locale/bn_BD.mjs +40 -0
  439. package/node_modules/typebox/build/system/locale/cs_CZ.d.mts +3 -0
  440. package/node_modules/typebox/build/system/locale/cs_CZ.mjs +40 -0
  441. package/node_modules/typebox/build/system/locale/de_DE.d.mts +3 -0
  442. package/node_modules/typebox/build/system/locale/de_DE.mjs +40 -0
  443. package/node_modules/typebox/build/system/locale/el_GR.d.mts +3 -0
  444. package/node_modules/typebox/build/system/locale/el_GR.mjs +40 -0
  445. package/node_modules/typebox/build/system/locale/en_US.d.mts +3 -0
  446. package/node_modules/typebox/build/system/locale/en_US.mjs +39 -0
  447. package/node_modules/typebox/build/system/locale/es_419.d.mts +3 -0
  448. package/node_modules/typebox/build/system/locale/es_419.mjs +40 -0
  449. package/node_modules/typebox/build/system/locale/es_AR.d.mts +3 -0
  450. package/node_modules/typebox/build/system/locale/es_AR.mjs +40 -0
  451. package/node_modules/typebox/build/system/locale/es_ES.d.mts +3 -0
  452. package/node_modules/typebox/build/system/locale/es_ES.mjs +40 -0
  453. package/node_modules/typebox/build/system/locale/es_MX.d.mts +3 -0
  454. package/node_modules/typebox/build/system/locale/es_MX.mjs +40 -0
  455. package/node_modules/typebox/build/system/locale/fa_IR.d.mts +3 -0
  456. package/node_modules/typebox/build/system/locale/fa_IR.mjs +40 -0
  457. package/node_modules/typebox/build/system/locale/fil_PH.d.mts +3 -0
  458. package/node_modules/typebox/build/system/locale/fil_PH.mjs +40 -0
  459. package/node_modules/typebox/build/system/locale/fr_CA.d.mts +3 -0
  460. package/node_modules/typebox/build/system/locale/fr_CA.mjs +40 -0
  461. package/node_modules/typebox/build/system/locale/fr_FR.d.mts +3 -0
  462. package/node_modules/typebox/build/system/locale/fr_FR.mjs +40 -0
  463. package/node_modules/typebox/build/system/locale/ha_NG.d.mts +3 -0
  464. package/node_modules/typebox/build/system/locale/ha_NG.mjs +40 -0
  465. package/node_modules/typebox/build/system/locale/hi_IN.d.mts +3 -0
  466. package/node_modules/typebox/build/system/locale/hi_IN.mjs +40 -0
  467. package/node_modules/typebox/build/system/locale/hu_HU.d.mts +3 -0
  468. package/node_modules/typebox/build/system/locale/hu_HU.mjs +40 -0
  469. package/node_modules/typebox/build/system/locale/id_ID.d.mts +3 -0
  470. package/node_modules/typebox/build/system/locale/id_ID.mjs +40 -0
  471. package/node_modules/typebox/build/system/locale/index.d.mts +1 -0
  472. package/node_modules/typebox/build/system/locale/index.mjs +1 -0
  473. package/node_modules/typebox/build/system/locale/it_IT.d.mts +3 -0
  474. package/node_modules/typebox/build/system/locale/it_IT.mjs +40 -0
  475. package/node_modules/typebox/build/system/locale/ja_JP.d.mts +3 -0
  476. package/node_modules/typebox/build/system/locale/ja_JP.mjs +40 -0
  477. package/node_modules/typebox/build/system/locale/ko_KR.d.mts +3 -0
  478. package/node_modules/typebox/build/system/locale/ko_KR.mjs +40 -0
  479. package/node_modules/typebox/build/system/locale/ms_MY.d.mts +3 -0
  480. package/node_modules/typebox/build/system/locale/ms_MY.mjs +40 -0
  481. package/node_modules/typebox/build/system/locale/nl_NL.d.mts +3 -0
  482. package/node_modules/typebox/build/system/locale/nl_NL.mjs +40 -0
  483. package/node_modules/typebox/build/system/locale/pl_PL.d.mts +3 -0
  484. package/node_modules/typebox/build/system/locale/pl_PL.mjs +40 -0
  485. package/node_modules/typebox/build/system/locale/pt_BR.d.mts +3 -0
  486. package/node_modules/typebox/build/system/locale/pt_BR.mjs +40 -0
  487. package/node_modules/typebox/build/system/locale/pt_PT.d.mts +3 -0
  488. package/node_modules/typebox/build/system/locale/pt_PT.mjs +40 -0
  489. package/node_modules/typebox/build/system/locale/ro_RO.d.mts +3 -0
  490. package/node_modules/typebox/build/system/locale/ro_RO.mjs +40 -0
  491. package/node_modules/typebox/build/system/locale/ru_RU.d.mts +3 -0
  492. package/node_modules/typebox/build/system/locale/ru_RU.mjs +40 -0
  493. package/node_modules/typebox/build/system/locale/sv_SE.d.mts +3 -0
  494. package/node_modules/typebox/build/system/locale/sv_SE.mjs +40 -0
  495. package/node_modules/typebox/build/system/locale/sw_TZ.d.mts +3 -0
  496. package/node_modules/typebox/build/system/locale/sw_TZ.mjs +40 -0
  497. package/node_modules/typebox/build/system/locale/th_TH.d.mts +3 -0
  498. package/node_modules/typebox/build/system/locale/th_TH.mjs +40 -0
  499. package/node_modules/typebox/build/system/locale/tr_TR.d.mts +3 -0
  500. package/node_modules/typebox/build/system/locale/tr_TR.mjs +40 -0
  501. package/node_modules/typebox/build/system/locale/uk_UA.d.mts +3 -0
  502. package/node_modules/typebox/build/system/locale/uk_UA.mjs +40 -0
  503. package/node_modules/typebox/build/system/locale/ur_PK.d.mts +3 -0
  504. package/node_modules/typebox/build/system/locale/ur_PK.mjs +40 -0
  505. package/node_modules/typebox/build/system/locale/vi_VN.d.mts +3 -0
  506. package/node_modules/typebox/build/system/locale/vi_VN.mjs +40 -0
  507. package/node_modules/typebox/build/system/locale/yo_NG.d.mts +3 -0
  508. package/node_modules/typebox/build/system/locale/yo_NG.mjs +40 -0
  509. package/node_modules/typebox/build/system/locale/zh_Hans.d.mts +3 -0
  510. package/node_modules/typebox/build/system/locale/zh_Hans.mjs +40 -0
  511. package/node_modules/typebox/build/system/locale/zh_Hant.d.mts +3 -0
  512. package/node_modules/typebox/build/system/locale/zh_Hant.mjs +40 -0
  513. package/node_modules/typebox/build/system/memory/assign.d.mts +14 -0
  514. package/node_modules/typebox/build/system/memory/assign.mjs +12 -0
  515. package/node_modules/typebox/build/system/memory/clone.d.mts +5 -0
  516. package/node_modules/typebox/build/system/memory/clone.mjs +113 -0
  517. package/node_modules/typebox/build/system/memory/create.d.mts +8 -0
  518. package/node_modules/typebox/build/system/memory/create.mjs +29 -0
  519. package/node_modules/typebox/build/system/memory/discard.d.mts +4 -0
  520. package/node_modules/typebox/build/system/memory/discard.mjs +18 -0
  521. package/node_modules/typebox/build/system/memory/freeze.d.mts +4 -0
  522. package/node_modules/typebox/build/system/memory/freeze.mjs +6 -0
  523. package/node_modules/typebox/build/system/memory/index.d.mts +1 -0
  524. package/node_modules/typebox/build/system/memory/index.mjs +1 -0
  525. package/node_modules/typebox/build/system/memory/memory.d.mts +6 -0
  526. package/node_modules/typebox/build/system/memory/memory.mjs +7 -0
  527. package/node_modules/typebox/build/system/memory/metrics.d.mts +14 -0
  528. package/node_modules/typebox/build/system/memory/metrics.mjs +8 -0
  529. package/node_modules/typebox/build/system/memory/update.d.mts +7 -0
  530. package/node_modules/typebox/build/system/memory/update.mjs +33 -0
  531. package/node_modules/typebox/build/system/settings/index.d.mts +1 -0
  532. package/node_modules/typebox/build/system/settings/index.mjs +1 -0
  533. package/node_modules/typebox/build/system/settings/settings.d.mts +80 -0
  534. package/node_modules/typebox/build/system/settings/settings.mjs +36 -0
  535. package/node_modules/typebox/build/system/system.d.mts +6 -0
  536. package/node_modules/typebox/build/system/system.mjs +6 -0
  537. package/node_modules/typebox/build/system/unreachable/index.d.mts +1 -0
  538. package/node_modules/typebox/build/system/unreachable/index.mjs +1 -0
  539. package/node_modules/typebox/build/system/unreachable/unreachable.d.mts +3 -0
  540. package/node_modules/typebox/build/system/unreachable/unreachable.mjs +6 -0
  541. package/node_modules/typebox/build/type/action/_add_immutable.d.mts +11 -0
  542. package/node_modules/typebox/build/type/action/_add_immutable.mjs +11 -0
  543. package/node_modules/typebox/build/type/action/_add_optional.d.mts +11 -0
  544. package/node_modules/typebox/build/type/action/_add_optional.mjs +11 -0
  545. package/node_modules/typebox/build/type/action/_add_readonly.d.mts +11 -0
  546. package/node_modules/typebox/build/type/action/_add_readonly.mjs +11 -0
  547. package/node_modules/typebox/build/type/action/_remove_immutable.d.mts +11 -0
  548. package/node_modules/typebox/build/type/action/_remove_immutable.mjs +11 -0
  549. package/node_modules/typebox/build/type/action/_remove_optional.d.mts +11 -0
  550. package/node_modules/typebox/build/type/action/_remove_optional.mjs +11 -0
  551. package/node_modules/typebox/build/type/action/_remove_readonly.d.mts +11 -0
  552. package/node_modules/typebox/build/type/action/_remove_readonly.mjs +11 -0
  553. package/node_modules/typebox/build/type/action/capitalize.d.mts +11 -0
  554. package/node_modules/typebox/build/type/action/capitalize.mjs +11 -0
  555. package/node_modules/typebox/build/type/action/conditional.d.mts +12 -0
  556. package/node_modules/typebox/build/type/action/conditional.mjs +13 -0
  557. package/node_modules/typebox/build/type/action/constructor_parameters.d.mts +11 -0
  558. package/node_modules/typebox/build/type/action/constructor_parameters.mjs +11 -0
  559. package/node_modules/typebox/build/type/action/evaluate.d.mts +11 -0
  560. package/node_modules/typebox/build/type/action/evaluate.mjs +11 -0
  561. package/node_modules/typebox/build/type/action/exclude.d.mts +11 -0
  562. package/node_modules/typebox/build/type/action/exclude.mjs +11 -0
  563. package/node_modules/typebox/build/type/action/extract.d.mts +11 -0
  564. package/node_modules/typebox/build/type/action/extract.mjs +11 -0
  565. package/node_modules/typebox/build/type/action/index.d.mts +30 -0
  566. package/node_modules/typebox/build/type/action/index.mjs +30 -0
  567. package/node_modules/typebox/build/type/action/indexed.d.mts +14 -0
  568. package/node_modules/typebox/build/type/action/indexed.mjs +14 -0
  569. package/node_modules/typebox/build/type/action/instance_type.d.mts +11 -0
  570. package/node_modules/typebox/build/type/action/instance_type.mjs +11 -0
  571. package/node_modules/typebox/build/type/action/interface.d.mts +14 -0
  572. package/node_modules/typebox/build/type/action/interface.mjs +22 -0
  573. package/node_modules/typebox/build/type/action/keyof.d.mts +11 -0
  574. package/node_modules/typebox/build/type/action/keyof.mjs +11 -0
  575. package/node_modules/typebox/build/type/action/lowercase.d.mts +11 -0
  576. package/node_modules/typebox/build/type/action/lowercase.mjs +11 -0
  577. package/node_modules/typebox/build/type/action/mapped.d.mts +13 -0
  578. package/node_modules/typebox/build/type/action/mapped.mjs +13 -0
  579. package/node_modules/typebox/build/type/action/module.d.mts +13 -0
  580. package/node_modules/typebox/build/type/action/module.mjs +13 -0
  581. package/node_modules/typebox/build/type/action/non_nullable.d.mts +11 -0
  582. package/node_modules/typebox/build/type/action/non_nullable.mjs +11 -0
  583. package/node_modules/typebox/build/type/action/omit.d.mts +14 -0
  584. package/node_modules/typebox/build/type/action/omit.mjs +14 -0
  585. package/node_modules/typebox/build/type/action/parameters.d.mts +11 -0
  586. package/node_modules/typebox/build/type/action/parameters.mjs +11 -0
  587. package/node_modules/typebox/build/type/action/partial.d.mts +11 -0
  588. package/node_modules/typebox/build/type/action/partial.mjs +11 -0
  589. package/node_modules/typebox/build/type/action/pick.d.mts +14 -0
  590. package/node_modules/typebox/build/type/action/pick.mjs +14 -0
  591. package/node_modules/typebox/build/type/action/readonly_object.d.mts +16 -0
  592. package/node_modules/typebox/build/type/action/readonly_object.mjs +19 -0
  593. package/node_modules/typebox/build/type/action/required.d.mts +11 -0
  594. package/node_modules/typebox/build/type/action/required.mjs +11 -0
  595. package/node_modules/typebox/build/type/action/return_type.d.mts +11 -0
  596. package/node_modules/typebox/build/type/action/return_type.mjs +11 -0
  597. package/node_modules/typebox/build/type/action/uncapitalize.d.mts +11 -0
  598. package/node_modules/typebox/build/type/action/uncapitalize.mjs +11 -0
  599. package/node_modules/typebox/build/type/action/uppercase.d.mts +11 -0
  600. package/node_modules/typebox/build/type/action/uppercase.mjs +11 -0
  601. package/node_modules/typebox/build/type/action/with.d.mts +11 -0
  602. package/node_modules/typebox/build/type/action/with.mjs +11 -0
  603. package/node_modules/typebox/build/type/engine/call/distribute_arguments.d.mts +20 -0
  604. package/node_modules/typebox/build/type/engine/call/distribute_arguments.mjs +66 -0
  605. package/node_modules/typebox/build/type/engine/call/instantiate.d.mts +21 -0
  606. package/node_modules/typebox/build/type/engine/call/instantiate.mjs +79 -0
  607. package/node_modules/typebox/build/type/engine/call/resolve_arguments.d.mts +13 -0
  608. package/node_modules/typebox/build/type/engine/call/resolve_arguments.mjs +33 -0
  609. package/node_modules/typebox/build/type/engine/call/resolve_target.d.mts +25 -0
  610. package/node_modules/typebox/build/type/engine/call/resolve_target.mjs +27 -0
  611. package/node_modules/typebox/build/type/engine/conditional/index.d.mts +1 -0
  612. package/node_modules/typebox/build/type/engine/conditional/index.mjs +1 -0
  613. package/node_modules/typebox/build/type/engine/conditional/instantiate.d.mts +12 -0
  614. package/node_modules/typebox/build/type/engine/conditional/instantiate.mjs +23 -0
  615. package/node_modules/typebox/build/type/engine/constructor_parameters/index.d.mts +1 -0
  616. package/node_modules/typebox/build/type/engine/constructor_parameters/index.mjs +1 -0
  617. package/node_modules/typebox/build/type/engine/constructor_parameters/instantiate.d.mts +14 -0
  618. package/node_modules/typebox/build/type/engine/constructor_parameters/instantiate.mjs +25 -0
  619. package/node_modules/typebox/build/type/engine/cyclic/candidates.d.mts +8 -0
  620. package/node_modules/typebox/build/type/engine/cyclic/candidates.mjs +16 -0
  621. package/node_modules/typebox/build/type/engine/cyclic/check.d.mts +21 -0
  622. package/node_modules/typebox/build/type/engine/cyclic/check.mjs +45 -0
  623. package/node_modules/typebox/build/type/engine/cyclic/dependencies.d.mts +22 -0
  624. package/node_modules/typebox/build/type/engine/cyclic/dependencies.mjs +47 -0
  625. package/node_modules/typebox/build/type/engine/cyclic/extends.d.mts +28 -0
  626. package/node_modules/typebox/build/type/engine/cyclic/extends.mjs +47 -0
  627. package/node_modules/typebox/build/type/engine/cyclic/index.d.mts +6 -0
  628. package/node_modules/typebox/build/type/engine/cyclic/index.mjs +6 -0
  629. package/node_modules/typebox/build/type/engine/cyclic/instantiate.d.mts +17 -0
  630. package/node_modules/typebox/build/type/engine/cyclic/instantiate.mjs +31 -0
  631. package/node_modules/typebox/build/type/engine/cyclic/target.d.mts +10 -0
  632. package/node_modules/typebox/build/type/engine/cyclic/target.mjs +16 -0
  633. package/node_modules/typebox/build/type/engine/enum/index.d.mts +1 -0
  634. package/node_modules/typebox/build/type/engine/enum/index.mjs +1 -0
  635. package/node_modules/typebox/build/type/engine/enum/typescript_enum_to_enum_values.d.mts +8 -0
  636. package/node_modules/typebox/build/type/engine/enum/typescript_enum_to_enum_values.mjs +9 -0
  637. package/node_modules/typebox/build/type/engine/evaluate/broaden.d.mts +15 -0
  638. package/node_modules/typebox/build/type/engine/evaluate/broaden.mjs +37 -0
  639. package/node_modules/typebox/build/type/engine/evaluate/compare.d.mts +11 -0
  640. package/node_modules/typebox/build/type/engine/evaluate/compare.mjs +18 -0
  641. package/node_modules/typebox/build/type/engine/evaluate/composite.d.mts +37 -0
  642. package/node_modules/typebox/build/type/engine/evaluate/composite.mjs +60 -0
  643. package/node_modules/typebox/build/type/engine/evaluate/distribute.d.mts +12 -0
  644. package/node_modules/typebox/build/type/engine/evaluate/distribute.mjs +33 -0
  645. package/node_modules/typebox/build/type/engine/evaluate/evaluate.d.mts +26 -0
  646. package/node_modules/typebox/build/type/engine/evaluate/evaluate.mjs +56 -0
  647. package/node_modules/typebox/build/type/engine/evaluate/flatten.d.mts +6 -0
  648. package/node_modules/typebox/build/type/engine/evaluate/flatten.mjs +10 -0
  649. package/node_modules/typebox/build/type/engine/evaluate/index.d.mts +8 -0
  650. package/node_modules/typebox/build/type/engine/evaluate/index.mjs +8 -0
  651. package/node_modules/typebox/build/type/engine/evaluate/instantiate.d.mts +8 -0
  652. package/node_modules/typebox/build/type/engine/evaluate/instantiate.mjs +12 -0
  653. package/node_modules/typebox/build/type/engine/evaluate/narrow.d.mts +20 -0
  654. package/node_modules/typebox/build/type/engine/evaluate/narrow.mjs +31 -0
  655. package/node_modules/typebox/build/type/engine/exclude/index.d.mts +1 -0
  656. package/node_modules/typebox/build/type/engine/exclude/index.mjs +1 -0
  657. package/node_modules/typebox/build/type/engine/exclude/instantiate.d.mts +9 -0
  658. package/node_modules/typebox/build/type/engine/exclude/instantiate.mjs +16 -0
  659. package/node_modules/typebox/build/type/engine/exclude/operation.d.mts +10 -0
  660. package/node_modules/typebox/build/type/engine/exclude/operation.mjs +22 -0
  661. package/node_modules/typebox/build/type/engine/extract/index.d.mts +1 -0
  662. package/node_modules/typebox/build/type/engine/extract/index.mjs +1 -0
  663. package/node_modules/typebox/build/type/engine/extract/instantiate.d.mts +9 -0
  664. package/node_modules/typebox/build/type/engine/extract/instantiate.mjs +16 -0
  665. package/node_modules/typebox/build/type/engine/extract/operation.d.mts +10 -0
  666. package/node_modules/typebox/build/type/engine/extract/operation.mjs +22 -0
  667. package/node_modules/typebox/build/type/engine/helpers/index.d.mts +3 -0
  668. package/node_modules/typebox/build/type/engine/helpers/index.mjs +3 -0
  669. package/node_modules/typebox/build/type/engine/helpers/keys.d.mts +3 -0
  670. package/node_modules/typebox/build/type/engine/helpers/keys.mjs +8 -0
  671. package/node_modules/typebox/build/type/engine/helpers/keys_to_indexer.d.mts +7 -0
  672. package/node_modules/typebox/build/type/engine/helpers/keys_to_indexer.mjs +15 -0
  673. package/node_modules/typebox/build/type/engine/helpers/union.d.mts +7 -0
  674. package/node_modules/typebox/build/type/engine/helpers/union.mjs +3 -0
  675. package/node_modules/typebox/build/type/engine/immutable/instantiate_add.d.mts +10 -0
  676. package/node_modules/typebox/build/type/engine/immutable/instantiate_add.mjs +14 -0
  677. package/node_modules/typebox/build/type/engine/immutable/instantiate_remove.d.mts +10 -0
  678. package/node_modules/typebox/build/type/engine/immutable/instantiate_remove.mjs +14 -0
  679. package/node_modules/typebox/build/type/engine/index.d.mts +31 -0
  680. package/node_modules/typebox/build/type/engine/index.mjs +37 -0
  681. package/node_modules/typebox/build/type/engine/indexable/from_cyclic.d.mts +6 -0
  682. package/node_modules/typebox/build/type/engine/indexable/from_cyclic.mjs +8 -0
  683. package/node_modules/typebox/build/type/engine/indexable/from_dependent.d.mts +5 -0
  684. package/node_modules/typebox/build/type/engine/indexable/from_dependent.mjs +8 -0
  685. package/node_modules/typebox/build/type/engine/indexable/from_enum.d.mts +6 -0
  686. package/node_modules/typebox/build/type/engine/indexable/from_enum.mjs +8 -0
  687. package/node_modules/typebox/build/type/engine/indexable/from_intersect.d.mts +5 -0
  688. package/node_modules/typebox/build/type/engine/indexable/from_intersect.mjs +8 -0
  689. package/node_modules/typebox/build/type/engine/indexable/from_literal.d.mts +3 -0
  690. package/node_modules/typebox/build/type/engine/indexable/from_literal.mjs +5 -0
  691. package/node_modules/typebox/build/type/engine/indexable/from_template_literal.d.mts +5 -0
  692. package/node_modules/typebox/build/type/engine/indexable/from_template_literal.mjs +8 -0
  693. package/node_modules/typebox/build/type/engine/indexable/from_type.d.mts +19 -0
  694. package/node_modules/typebox/build/type/engine/indexable/from_type.mjs +25 -0
  695. package/node_modules/typebox/build/type/engine/indexable/from_union.d.mts +4 -0
  696. package/node_modules/typebox/build/type/engine/indexable/from_union.mjs +7 -0
  697. package/node_modules/typebox/build/type/engine/indexable/to_indexable.d.mts +9 -0
  698. package/node_modules/typebox/build/type/engine/indexable/to_indexable.mjs +14 -0
  699. package/node_modules/typebox/build/type/engine/indexable/to_indexable_keys.d.mts +10 -0
  700. package/node_modules/typebox/build/type/engine/indexable/to_indexable_keys.mjs +12 -0
  701. package/node_modules/typebox/build/type/engine/indexed/array_indexer.d.mts +12 -0
  702. package/node_modules/typebox/build/type/engine/indexed/array_indexer.mjs +18 -0
  703. package/node_modules/typebox/build/type/engine/indexed/from_array.d.mts +15 -0
  704. package/node_modules/typebox/build/type/engine/indexed/from_array.mjs +35 -0
  705. package/node_modules/typebox/build/type/engine/indexed/from_object.d.mts +16 -0
  706. package/node_modules/typebox/build/type/engine/indexed/from_object.mjs +40 -0
  707. package/node_modules/typebox/build/type/engine/indexed/from_tuple.d.mts +13 -0
  708. package/node_modules/typebox/build/type/engine/indexed/from_tuple.mjs +35 -0
  709. package/node_modules/typebox/build/type/engine/indexed/from_type.d.mts +11 -0
  710. package/node_modules/typebox/build/type/engine/indexed/from_type.mjs +14 -0
  711. package/node_modules/typebox/build/type/engine/indexed/index.d.mts +1 -0
  712. package/node_modules/typebox/build/type/engine/indexed/index.mjs +1 -0
  713. package/node_modules/typebox/build/type/engine/indexed/instantiate.d.mts +16 -0
  714. package/node_modules/typebox/build/type/engine/indexed/instantiate.mjs +28 -0
  715. package/node_modules/typebox/build/type/engine/instance_type/index.d.mts +1 -0
  716. package/node_modules/typebox/build/type/engine/instance_type/index.mjs +1 -0
  717. package/node_modules/typebox/build/type/engine/instance_type/instantiate.d.mts +12 -0
  718. package/node_modules/typebox/build/type/engine/instance_type/instantiate.mjs +21 -0
  719. package/node_modules/typebox/build/type/engine/instantiate.d.mts +178 -0
  720. package/node_modules/typebox/build/type/engine/instantiate.mjs +158 -0
  721. package/node_modules/typebox/build/type/engine/interface/index.d.mts +1 -0
  722. package/node_modules/typebox/build/type/engine/interface/index.mjs +1 -0
  723. package/node_modules/typebox/build/type/engine/interface/instantiate.d.mts +15 -0
  724. package/node_modules/typebox/build/type/engine/interface/instantiate.mjs +23 -0
  725. package/node_modules/typebox/build/type/engine/intrinsics/from_literal.d.mts +5 -0
  726. package/node_modules/typebox/build/type/engine/intrinsics/from_literal.mjs +9 -0
  727. package/node_modules/typebox/build/type/engine/intrinsics/from_template_literal.d.mts +6 -0
  728. package/node_modules/typebox/build/type/engine/intrinsics/from_template_literal.mjs +8 -0
  729. package/node_modules/typebox/build/type/engine/intrinsics/from_type.d.mts +10 -0
  730. package/node_modules/typebox/build/type/engine/intrinsics/from_type.mjs +13 -0
  731. package/node_modules/typebox/build/type/engine/intrinsics/from_union.d.mts +6 -0
  732. package/node_modules/typebox/build/type/engine/intrinsics/from_union.mjs +7 -0
  733. package/node_modules/typebox/build/type/engine/intrinsics/index.d.mts +1 -0
  734. package/node_modules/typebox/build/type/engine/intrinsics/index.mjs +1 -0
  735. package/node_modules/typebox/build/type/engine/intrinsics/instantiate.d.mts +38 -0
  736. package/node_modules/typebox/build/type/engine/intrinsics/instantiate.mjs +52 -0
  737. package/node_modules/typebox/build/type/engine/intrinsics/mapping.d.mts +9 -0
  738. package/node_modules/typebox/build/type/engine/intrinsics/mapping.mjs +4 -0
  739. package/node_modules/typebox/build/type/engine/keyof/from_any.d.mts +6 -0
  740. package/node_modules/typebox/build/type/engine/keyof/from_any.mjs +8 -0
  741. package/node_modules/typebox/build/type/engine/keyof/from_array.d.mts +4 -0
  742. package/node_modules/typebox/build/type/engine/keyof/from_array.mjs +5 -0
  743. package/node_modules/typebox/build/type/engine/keyof/from_object.d.mts +10 -0
  744. package/node_modules/typebox/build/type/engine/keyof/from_object.mjs +20 -0
  745. package/node_modules/typebox/build/type/engine/keyof/from_record.d.mts +4 -0
  746. package/node_modules/typebox/build/type/engine/keyof/from_record.mjs +5 -0
  747. package/node_modules/typebox/build/type/engine/keyof/from_tuple.d.mts +5 -0
  748. package/node_modules/typebox/build/type/engine/keyof/from_tuple.mjs +7 -0
  749. package/node_modules/typebox/build/type/engine/keyof/from_type.d.mts +15 -0
  750. package/node_modules/typebox/build/type/engine/keyof/from_type.mjs +23 -0
  751. package/node_modules/typebox/build/type/engine/keyof/index.d.mts +1 -0
  752. package/node_modules/typebox/build/type/engine/keyof/index.mjs +1 -0
  753. package/node_modules/typebox/build/type/engine/keyof/instantiate.d.mts +16 -0
  754. package/node_modules/typebox/build/type/engine/keyof/instantiate.mjs +29 -0
  755. package/node_modules/typebox/build/type/engine/mapped/index.d.mts +1 -0
  756. package/node_modules/typebox/build/type/engine/mapped/index.mjs +1 -0
  757. package/node_modules/typebox/build/type/engine/mapped/instantiate.d.mts +10 -0
  758. package/node_modules/typebox/build/type/engine/mapped/instantiate.mjs +15 -0
  759. package/node_modules/typebox/build/type/engine/mapped/mapped_operation.d.mts +22 -0
  760. package/node_modules/typebox/build/type/engine/mapped/mapped_operation.mjs +42 -0
  761. package/node_modules/typebox/build/type/engine/mapped/mapped_variants.d.mts +17 -0
  762. package/node_modules/typebox/build/type/engine/mapped/mapped_variants.mjs +39 -0
  763. package/node_modules/typebox/build/type/engine/module/index.d.mts +1 -0
  764. package/node_modules/typebox/build/type/engine/module/index.mjs +1 -0
  765. package/node_modules/typebox/build/type/engine/module/instantiate.d.mts +19 -0
  766. package/node_modules/typebox/build/type/engine/module/instantiate.mjs +36 -0
  767. package/node_modules/typebox/build/type/engine/non_nullable/index.d.mts +1 -0
  768. package/node_modules/typebox/build/type/engine/non_nullable/index.mjs +1 -0
  769. package/node_modules/typebox/build/type/engine/non_nullable/instantiate.d.mts +14 -0
  770. package/node_modules/typebox/build/type/engine/non_nullable/instantiate.mjs +22 -0
  771. package/node_modules/typebox/build/type/engine/object/collapse.d.mts +12 -0
  772. package/node_modules/typebox/build/type/engine/object/collapse.mjs +14 -0
  773. package/node_modules/typebox/build/type/engine/object/from_cyclic.d.mts +6 -0
  774. package/node_modules/typebox/build/type/engine/object/from_cyclic.mjs +8 -0
  775. package/node_modules/typebox/build/type/engine/object/from_dependent.d.mts +5 -0
  776. package/node_modules/typebox/build/type/engine/object/from_dependent.mjs +8 -0
  777. package/node_modules/typebox/build/type/engine/object/from_intersect.d.mts +17 -0
  778. package/node_modules/typebox/build/type/engine/object/from_intersect.mjs +22 -0
  779. package/node_modules/typebox/build/type/engine/object/from_object.d.mts +3 -0
  780. package/node_modules/typebox/build/type/engine/object/from_object.mjs +4 -0
  781. package/node_modules/typebox/build/type/engine/object/from_tuple.d.mts +6 -0
  782. package/node_modules/typebox/build/type/engine/object/from_tuple.mjs +9 -0
  783. package/node_modules/typebox/build/type/engine/object/from_type.d.mts +16 -0
  784. package/node_modules/typebox/build/type/engine/object/from_type.mjs +23 -0
  785. package/node_modules/typebox/build/type/engine/object/from_union.d.mts +12 -0
  786. package/node_modules/typebox/build/type/engine/object/from_union.mjs +19 -0
  787. package/node_modules/typebox/build/type/engine/object/index.d.mts +1 -0
  788. package/node_modules/typebox/build/type/engine/object/index.mjs +1 -0
  789. package/node_modules/typebox/build/type/engine/omit/from_type.d.mts +12 -0
  790. package/node_modules/typebox/build/type/engine/omit/from_type.mjs +18 -0
  791. package/node_modules/typebox/build/type/engine/omit/index.d.mts +1 -0
  792. package/node_modules/typebox/build/type/engine/omit/index.mjs +1 -0
  793. package/node_modules/typebox/build/type/engine/omit/instantiate.d.mts +9 -0
  794. package/node_modules/typebox/build/type/engine/omit/instantiate.mjs +16 -0
  795. package/node_modules/typebox/build/type/engine/optional/instantiate_add.d.mts +10 -0
  796. package/node_modules/typebox/build/type/engine/optional/instantiate_add.mjs +14 -0
  797. package/node_modules/typebox/build/type/engine/optional/instantiate_remove.d.mts +10 -0
  798. package/node_modules/typebox/build/type/engine/optional/instantiate_remove.mjs +14 -0
  799. package/node_modules/typebox/build/type/engine/parameters/index.d.mts +1 -0
  800. package/node_modules/typebox/build/type/engine/parameters/index.mjs +1 -0
  801. package/node_modules/typebox/build/type/engine/parameters/instantiate.d.mts +14 -0
  802. package/node_modules/typebox/build/type/engine/parameters/instantiate.mjs +25 -0
  803. package/node_modules/typebox/build/type/engine/partial/from_cyclic.d.mts +10 -0
  804. package/node_modules/typebox/build/type/engine/partial/from_cyclic.mjs +11 -0
  805. package/node_modules/typebox/build/type/engine/partial/from_dependent.d.mts +5 -0
  806. package/node_modules/typebox/build/type/engine/partial/from_dependent.mjs +8 -0
  807. package/node_modules/typebox/build/type/engine/partial/from_intersect.d.mts +5 -0
  808. package/node_modules/typebox/build/type/engine/partial/from_intersect.mjs +8 -0
  809. package/node_modules/typebox/build/type/engine/partial/from_object.d.mts +8 -0
  810. package/node_modules/typebox/build/type/engine/partial/from_object.mjs +11 -0
  811. package/node_modules/typebox/build/type/engine/partial/from_type.d.mts +14 -0
  812. package/node_modules/typebox/build/type/engine/partial/from_type.mjs +20 -0
  813. package/node_modules/typebox/build/type/engine/partial/from_union.d.mts +5 -0
  814. package/node_modules/typebox/build/type/engine/partial/from_union.mjs +7 -0
  815. package/node_modules/typebox/build/type/engine/partial/index.d.mts +1 -0
  816. package/node_modules/typebox/build/type/engine/partial/index.mjs +1 -0
  817. package/node_modules/typebox/build/type/engine/partial/instantiate.d.mts +9 -0
  818. package/node_modules/typebox/build/type/engine/partial/instantiate.mjs +15 -0
  819. package/node_modules/typebox/build/type/engine/patterns/index.d.mts +2 -0
  820. package/node_modules/typebox/build/type/engine/patterns/index.mjs +2 -0
  821. package/node_modules/typebox/build/type/engine/patterns/pattern.d.mts +6 -0
  822. package/node_modules/typebox/build/type/engine/patterns/pattern.mjs +11 -0
  823. package/node_modules/typebox/build/type/engine/patterns/template.d.mts +7 -0
  824. package/node_modules/typebox/build/type/engine/patterns/template.mjs +20 -0
  825. package/node_modules/typebox/build/type/engine/pick/from_type.d.mts +13 -0
  826. package/node_modules/typebox/build/type/engine/pick/from_type.mjs +20 -0
  827. package/node_modules/typebox/build/type/engine/pick/index.d.mts +1 -0
  828. package/node_modules/typebox/build/type/engine/pick/index.mjs +1 -0
  829. package/node_modules/typebox/build/type/engine/pick/instantiate.d.mts +9 -0
  830. package/node_modules/typebox/build/type/engine/pick/instantiate.mjs +16 -0
  831. package/node_modules/typebox/build/type/engine/priority/index.d.mts +1 -0
  832. package/node_modules/typebox/build/type/engine/priority/index.mjs +1 -0
  833. package/node_modules/typebox/build/type/engine/priority/priority.d.mts +20 -0
  834. package/node_modules/typebox/build/type/engine/priority/priority.mjs +27 -0
  835. package/node_modules/typebox/build/type/engine/readonly/instantiate_add.d.mts +10 -0
  836. package/node_modules/typebox/build/type/engine/readonly/instantiate_add.mjs +14 -0
  837. package/node_modules/typebox/build/type/engine/readonly/instantiate_remove.d.mts +10 -0
  838. package/node_modules/typebox/build/type/engine/readonly/instantiate_remove.mjs +14 -0
  839. package/node_modules/typebox/build/type/engine/readonly_object/from_array.d.mts +5 -0
  840. package/node_modules/typebox/build/type/engine/readonly_object/from_array.mjs +7 -0
  841. package/node_modules/typebox/build/type/engine/readonly_object/from_cyclic.d.mts +10 -0
  842. package/node_modules/typebox/build/type/engine/readonly_object/from_cyclic.mjs +11 -0
  843. package/node_modules/typebox/build/type/engine/readonly_object/from_dependent.d.mts +5 -0
  844. package/node_modules/typebox/build/type/engine/readonly_object/from_dependent.mjs +8 -0
  845. package/node_modules/typebox/build/type/engine/readonly_object/from_intersect.d.mts +5 -0
  846. package/node_modules/typebox/build/type/engine/readonly_object/from_intersect.mjs +8 -0
  847. package/node_modules/typebox/build/type/engine/readonly_object/from_object.d.mts +8 -0
  848. package/node_modules/typebox/build/type/engine/readonly_object/from_object.mjs +11 -0
  849. package/node_modules/typebox/build/type/engine/readonly_object/from_tuple.d.mts +5 -0
  850. package/node_modules/typebox/build/type/engine/readonly_object/from_tuple.mjs +7 -0
  851. package/node_modules/typebox/build/type/engine/readonly_object/from_type.d.mts +18 -0
  852. package/node_modules/typebox/build/type/engine/readonly_object/from_type.mjs +25 -0
  853. package/node_modules/typebox/build/type/engine/readonly_object/from_union.d.mts +5 -0
  854. package/node_modules/typebox/build/type/engine/readonly_object/from_union.mjs +7 -0
  855. package/node_modules/typebox/build/type/engine/readonly_object/index.d.mts +1 -0
  856. package/node_modules/typebox/build/type/engine/readonly_object/index.mjs +1 -0
  857. package/node_modules/typebox/build/type/engine/readonly_object/instantiate.d.mts +9 -0
  858. package/node_modules/typebox/build/type/engine/readonly_object/instantiate.mjs +15 -0
  859. package/node_modules/typebox/build/type/engine/record/from_key.d.mts +24 -0
  860. package/node_modules/typebox/build/type/engine/record/from_key.mjs +40 -0
  861. package/node_modules/typebox/build/type/engine/record/from_key_any.d.mts +4 -0
  862. package/node_modules/typebox/build/type/engine/record/from_key_any.mjs +6 -0
  863. package/node_modules/typebox/build/type/engine/record/from_key_boolean.d.mts +7 -0
  864. package/node_modules/typebox/build/type/engine/record/from_key_boolean.mjs +5 -0
  865. package/node_modules/typebox/build/type/engine/record/from_key_enum.d.mts +6 -0
  866. package/node_modules/typebox/build/type/engine/record/from_key_enum.mjs +8 -0
  867. package/node_modules/typebox/build/type/engine/record/from_key_integer.d.mts +5 -0
  868. package/node_modules/typebox/build/type/engine/record/from_key_integer.mjs +7 -0
  869. package/node_modules/typebox/build/type/engine/record/from_key_intersect.d.mts +5 -0
  870. package/node_modules/typebox/build/type/engine/record/from_key_intersect.mjs +8 -0
  871. package/node_modules/typebox/build/type/engine/record/from_key_literal.d.mts +11 -0
  872. package/node_modules/typebox/build/type/engine/record/from_key_literal.mjs +10 -0
  873. package/node_modules/typebox/build/type/engine/record/from_key_number.d.mts +5 -0
  874. package/node_modules/typebox/build/type/engine/record/from_key_number.mjs +7 -0
  875. package/node_modules/typebox/build/type/engine/record/from_key_string.d.mts +5 -0
  876. package/node_modules/typebox/build/type/engine/record/from_key_string.mjs +12 -0
  877. package/node_modules/typebox/build/type/engine/record/from_key_template_literal.d.mts +8 -0
  878. package/node_modules/typebox/build/type/engine/record/from_key_template_literal.mjs +12 -0
  879. package/node_modules/typebox/build/type/engine/record/from_key_union.d.mts +20 -0
  880. package/node_modules/typebox/build/type/engine/record/from_key_union.mjs +39 -0
  881. package/node_modules/typebox/build/type/engine/record/index.d.mts +1 -0
  882. package/node_modules/typebox/build/type/engine/record/index.mjs +1 -0
  883. package/node_modules/typebox/build/type/engine/record/instantiate.d.mts +9 -0
  884. package/node_modules/typebox/build/type/engine/record/instantiate.mjs +17 -0
  885. package/node_modules/typebox/build/type/engine/record/record_create.d.mts +3 -0
  886. package/node_modules/typebox/build/type/engine/record/record_create.mjs +7 -0
  887. package/node_modules/typebox/build/type/engine/ref/index.d.mts +1 -0
  888. package/node_modules/typebox/build/type/engine/ref/index.mjs +1 -0
  889. package/node_modules/typebox/build/type/engine/ref/instantiate.d.mts +6 -0
  890. package/node_modules/typebox/build/type/engine/ref/instantiate.mjs +10 -0
  891. package/node_modules/typebox/build/type/engine/required/from_cyclic.d.mts +10 -0
  892. package/node_modules/typebox/build/type/engine/required/from_cyclic.mjs +11 -0
  893. package/node_modules/typebox/build/type/engine/required/from_dependent.d.mts +5 -0
  894. package/node_modules/typebox/build/type/engine/required/from_dependent.mjs +8 -0
  895. package/node_modules/typebox/build/type/engine/required/from_intersect.d.mts +5 -0
  896. package/node_modules/typebox/build/type/engine/required/from_intersect.mjs +8 -0
  897. package/node_modules/typebox/build/type/engine/required/from_object.d.mts +8 -0
  898. package/node_modules/typebox/build/type/engine/required/from_object.mjs +11 -0
  899. package/node_modules/typebox/build/type/engine/required/from_type.d.mts +14 -0
  900. package/node_modules/typebox/build/type/engine/required/from_type.mjs +20 -0
  901. package/node_modules/typebox/build/type/engine/required/from_union.d.mts +5 -0
  902. package/node_modules/typebox/build/type/engine/required/from_union.mjs +7 -0
  903. package/node_modules/typebox/build/type/engine/required/index.d.mts +1 -0
  904. package/node_modules/typebox/build/type/engine/required/index.mjs +1 -0
  905. package/node_modules/typebox/build/type/engine/required/instantiate.d.mts +9 -0
  906. package/node_modules/typebox/build/type/engine/required/instantiate.mjs +15 -0
  907. package/node_modules/typebox/build/type/engine/rest/index.d.mts +1 -0
  908. package/node_modules/typebox/build/type/engine/rest/index.mjs +1 -0
  909. package/node_modules/typebox/build/type/engine/rest/spread.d.mts +12 -0
  910. package/node_modules/typebox/build/type/engine/rest/spread.mjs +19 -0
  911. package/node_modules/typebox/build/type/engine/return_type/index.d.mts +1 -0
  912. package/node_modules/typebox/build/type/engine/return_type/index.mjs +1 -0
  913. package/node_modules/typebox/build/type/engine/return_type/instantiate.d.mts +12 -0
  914. package/node_modules/typebox/build/type/engine/return_type/instantiate.mjs +21 -0
  915. package/node_modules/typebox/build/type/engine/template_literal/create.d.mts +1 -0
  916. package/node_modules/typebox/build/type/engine/template_literal/create.mjs +5 -0
  917. package/node_modules/typebox/build/type/engine/template_literal/decode.d.mts +30 -0
  918. package/node_modules/typebox/build/type/engine/template_literal/decode.mjs +81 -0
  919. package/node_modules/typebox/build/type/engine/template_literal/encode.d.mts +33 -0
  920. package/node_modules/typebox/build/type/engine/template_literal/encode.mjs +81 -0
  921. package/node_modules/typebox/build/type/engine/template_literal/index.d.mts +6 -0
  922. package/node_modules/typebox/build/type/engine/template_literal/index.mjs +6 -0
  923. package/node_modules/typebox/build/type/engine/template_literal/instantiate.d.mts +9 -0
  924. package/node_modules/typebox/build/type/engine/template_literal/instantiate.mjs +15 -0
  925. package/node_modules/typebox/build/type/engine/template_literal/is_finite.d.mts +12 -0
  926. package/node_modules/typebox/build/type/engine/template_literal/is_finite.mjs +26 -0
  927. package/node_modules/typebox/build/type/engine/template_literal/is_pattern.d.mts +6 -0
  928. package/node_modules/typebox/build/type/engine/template_literal/is_pattern.mjs +10 -0
  929. package/node_modules/typebox/build/type/engine/template_literal/static.d.mts +18 -0
  930. package/node_modules/typebox/build/type/engine/template_literal/static.mjs +2 -0
  931. package/node_modules/typebox/build/type/engine/this/expand_this.d.mts +16 -0
  932. package/node_modules/typebox/build/type/engine/this/expand_this.mjs +26 -0
  933. package/node_modules/typebox/build/type/engine/tuple/to_object.d.mts +12 -0
  934. package/node_modules/typebox/build/type/engine/tuple/to_object.mjs +14 -0
  935. package/node_modules/typebox/build/type/engine/with/index.d.mts +1 -0
  936. package/node_modules/typebox/build/type/engine/with/index.mjs +1 -0
  937. package/node_modules/typebox/build/type/engine/with/instantiate.d.mts +8 -0
  938. package/node_modules/typebox/build/type/engine/with/instantiate.mjs +14 -0
  939. package/node_modules/typebox/build/type/extends/any.d.mts +9 -0
  940. package/node_modules/typebox/build/type/extends/any.mjs +12 -0
  941. package/node_modules/typebox/build/type/extends/array.d.mts +20 -0
  942. package/node_modules/typebox/build/type/extends/array.mjs +21 -0
  943. package/node_modules/typebox/build/type/extends/bigint.d.mts +7 -0
  944. package/node_modules/typebox/build/type/extends/bigint.mjs +9 -0
  945. package/node_modules/typebox/build/type/extends/boolean.d.mts +7 -0
  946. package/node_modules/typebox/build/type/extends/boolean.mjs +9 -0
  947. package/node_modules/typebox/build/type/extends/constructor.d.mts +10 -0
  948. package/node_modules/typebox/build/type/extends/constructor.mjs +17 -0
  949. package/node_modules/typebox/build/type/extends/dependent.d.mts +6 -0
  950. package/node_modules/typebox/build/type/extends/dependent.mjs +6 -0
  951. package/node_modules/typebox/build/type/extends/enum.d.mts +7 -0
  952. package/node_modules/typebox/build/type/extends/enum.mjs +7 -0
  953. package/node_modules/typebox/build/type/extends/extends.d.mts +13 -0
  954. package/node_modules/typebox/build/type/extends/extends.mjs +17 -0
  955. package/node_modules/typebox/build/type/extends/extends_left.d.mts +53 -0
  956. package/node_modules/typebox/build/type/extends/extends_left.mjs +80 -0
  957. package/node_modules/typebox/build/type/extends/extends_right.d.mts +27 -0
  958. package/node_modules/typebox/build/type/extends/extends_right.mjs +49 -0
  959. package/node_modules/typebox/build/type/extends/function.d.mts +10 -0
  960. package/node_modules/typebox/build/type/extends/function.mjs +17 -0
  961. package/node_modules/typebox/build/type/extends/index.d.mts +2 -0
  962. package/node_modules/typebox/build/type/extends/index.mjs +2 -0
  963. package/node_modules/typebox/build/type/extends/inference.d.mts +34 -0
  964. package/node_modules/typebox/build/type/extends/inference.mjs +62 -0
  965. package/node_modules/typebox/build/type/extends/integer.d.mts +8 -0
  966. package/node_modules/typebox/build/type/extends/integer.mjs +10 -0
  967. package/node_modules/typebox/build/type/extends/intersect.d.mts +6 -0
  968. package/node_modules/typebox/build/type/extends/intersect.mjs +15 -0
  969. package/node_modules/typebox/build/type/extends/literal.d.mts +18 -0
  970. package/node_modules/typebox/build/type/extends/literal.mjs +44 -0
  971. package/node_modules/typebox/build/type/extends/never.d.mts +8 -0
  972. package/node_modules/typebox/build/type/extends/never.mjs +9 -0
  973. package/node_modules/typebox/build/type/extends/null.d.mts +7 -0
  974. package/node_modules/typebox/build/type/extends/null.mjs +9 -0
  975. package/node_modules/typebox/build/type/extends/number.d.mts +7 -0
  976. package/node_modules/typebox/build/type/extends/number.mjs +9 -0
  977. package/node_modules/typebox/build/type/extends/object.d.mts +32 -0
  978. package/node_modules/typebox/build/type/extends/object.mjs +109 -0
  979. package/node_modules/typebox/build/type/extends/parameters.d.mts +15 -0
  980. package/node_modules/typebox/build/type/extends/parameters.mjs +28 -0
  981. package/node_modules/typebox/build/type/extends/record.d.mts +13 -0
  982. package/node_modules/typebox/build/type/extends/record.mjs +23 -0
  983. package/node_modules/typebox/build/type/extends/result.d.mts +24 -0
  984. package/node_modules/typebox/build/type/extends/result.mjs +36 -0
  985. package/node_modules/typebox/build/type/extends/return_type.d.mts +7 -0
  986. package/node_modules/typebox/build/type/extends/return_type.mjs +9 -0
  987. package/node_modules/typebox/build/type/extends/string.d.mts +7 -0
  988. package/node_modules/typebox/build/type/extends/string.mjs +9 -0
  989. package/node_modules/typebox/build/type/extends/symbol.d.mts +7 -0
  990. package/node_modules/typebox/build/type/extends/symbol.mjs +9 -0
  991. package/node_modules/typebox/build/type/extends/template_literal.d.mts +6 -0
  992. package/node_modules/typebox/build/type/extends/template_literal.mjs +7 -0
  993. package/node_modules/typebox/build/type/extends/tuple.d.mts +22 -0
  994. package/node_modules/typebox/build/type/extends/tuple.mjs +61 -0
  995. package/node_modules/typebox/build/type/extends/undefined.d.mts +8 -0
  996. package/node_modules/typebox/build/type/extends/undefined.mjs +10 -0
  997. package/node_modules/typebox/build/type/extends/union.d.mts +11 -0
  998. package/node_modules/typebox/build/type/extends/union.mjs +24 -0
  999. package/node_modules/typebox/build/type/extends/unknown.d.mts +9 -0
  1000. package/node_modules/typebox/build/type/extends/unknown.mjs +12 -0
  1001. package/node_modules/typebox/build/type/extends/void.d.mts +7 -0
  1002. package/node_modules/typebox/build/type/extends/void.mjs +9 -0
  1003. package/node_modules/typebox/build/type/index.d.mts +5 -0
  1004. package/node_modules/typebox/build/type/index.mjs +5 -0
  1005. package/node_modules/typebox/build/type/script/index.d.mts +1 -0
  1006. package/node_modules/typebox/build/type/script/index.mjs +1 -0
  1007. package/node_modules/typebox/build/type/script/mapping.d.mts +356 -0
  1008. package/node_modules/typebox/build/type/script/mapping.mjs +528 -0
  1009. package/node_modules/typebox/build/type/script/parser.d.mts +256 -0
  1010. package/node_modules/typebox/build/type/script/parser.mjs +140 -0
  1011. package/node_modules/typebox/build/type/script/script.d.mts +16 -0
  1012. package/node_modules/typebox/build/type/script/script.mjs +22 -0
  1013. package/node_modules/typebox/build/type/script/token/bigint.d.mts +8 -0
  1014. package/node_modules/typebox/build/type/script/token/bigint.mjs +14 -0
  1015. package/node_modules/typebox/build/type/script/token/const.d.mts +11 -0
  1016. package/node_modules/typebox/build/type/script/token/const.mjs +18 -0
  1017. package/node_modules/typebox/build/type/script/token/ident.d.mts +16 -0
  1018. package/node_modules/typebox/build/type/script/token/ident.mjs +26 -0
  1019. package/node_modules/typebox/build/type/script/token/index.d.mts +12 -0
  1020. package/node_modules/typebox/build/type/script/token/index.mjs +12 -0
  1021. package/node_modules/typebox/build/type/script/token/integer.d.mts +11 -0
  1022. package/node_modules/typebox/build/type/script/token/integer.mjs +19 -0
  1023. package/node_modules/typebox/build/type/script/token/internal/char.d.mts +75 -0
  1024. package/node_modules/typebox/build/type/script/token/internal/char.mjs +26 -0
  1025. package/node_modules/typebox/build/type/script/token/internal/guard.d.mts +1 -0
  1026. package/node_modules/typebox/build/type/script/token/internal/guard.mjs +15 -0
  1027. package/node_modules/typebox/build/type/script/token/internal/many.d.mts +7 -0
  1028. package/node_modules/typebox/build/type/script/token/internal/many.mjs +14 -0
  1029. package/node_modules/typebox/build/type/script/token/internal/match.d.mts +6 -0
  1030. package/node_modules/typebox/build/type/script/token/internal/match.mjs +11 -0
  1031. package/node_modules/typebox/build/type/script/token/internal/optional.d.mts +5 -0
  1032. package/node_modules/typebox/build/type/script/token/internal/optional.mjs +9 -0
  1033. package/node_modules/typebox/build/type/script/token/internal/take.d.mts +6 -0
  1034. package/node_modules/typebox/build/type/script/token/internal/take.mjs +30 -0
  1035. package/node_modules/typebox/build/type/script/token/internal/trim.d.mts +19 -0
  1036. package/node_modules/typebox/build/type/script/token/internal/trim.mjs +34 -0
  1037. package/node_modules/typebox/build/type/script/token/number.d.mts +11 -0
  1038. package/node_modules/typebox/build/type/script/token/number.mjs +19 -0
  1039. package/node_modules/typebox/build/type/script/token/rest.d.mts +4 -0
  1040. package/node_modules/typebox/build/type/script/token/rest.mjs +9 -0
  1041. package/node_modules/typebox/build/type/script/token/span.d.mts +11 -0
  1042. package/node_modules/typebox/build/type/script/token/span.mjs +24 -0
  1043. package/node_modules/typebox/build/type/script/token/string.d.mts +11 -0
  1044. package/node_modules/typebox/build/type/script/token/string.mjs +20 -0
  1045. package/node_modules/typebox/build/type/script/token/unsigned_integer.d.mts +16 -0
  1046. package/node_modules/typebox/build/type/script/token/unsigned_integer.mjs +26 -0
  1047. package/node_modules/typebox/build/type/script/token/unsigned_number.d.mts +17 -0
  1048. package/node_modules/typebox/build/type/script/token/unsigned_number.mjs +38 -0
  1049. package/node_modules/typebox/build/type/script/token/until.d.mts +7 -0
  1050. package/node_modules/typebox/build/type/script/token/until.mjs +21 -0
  1051. package/node_modules/typebox/build/type/script/token/until_1.d.mts +5 -0
  1052. package/node_modules/typebox/build/type/script/token/until_1.mjs +12 -0
  1053. package/node_modules/typebox/build/type/types/_codec.d.mts +30 -0
  1054. package/node_modules/typebox/build/type/types/_codec.mjs +60 -0
  1055. package/node_modules/typebox/build/type/types/_immutable.d.mts +9 -0
  1056. package/node_modules/typebox/build/type/types/_immutable.mjs +18 -0
  1057. package/node_modules/typebox/build/type/types/_optional.d.mts +9 -0
  1058. package/node_modules/typebox/build/type/types/_optional.mjs +18 -0
  1059. package/node_modules/typebox/build/type/types/_readonly.d.mts +9 -0
  1060. package/node_modules/typebox/build/type/types/_readonly.mjs +18 -0
  1061. package/node_modules/typebox/build/type/types/_refine.d.mts +24 -0
  1062. package/node_modules/typebox/build/type/types/_refine.mjs +36 -0
  1063. package/node_modules/typebox/build/type/types/any.d.mts +10 -0
  1064. package/node_modules/typebox/build/type/types/any.mjs +18 -0
  1065. package/node_modules/typebox/build/type/types/array.d.mts +18 -0
  1066. package/node_modules/typebox/build/type/types/array.mjs +25 -0
  1067. package/node_modules/typebox/build/type/types/bigint.d.mts +12 -0
  1068. package/node_modules/typebox/build/type/types/bigint.mjs +21 -0
  1069. package/node_modules/typebox/build/type/types/boolean.d.mts +11 -0
  1070. package/node_modules/typebox/build/type/types/boolean.mjs +17 -0
  1071. package/node_modules/typebox/build/type/types/call.d.mts +16 -0
  1072. package/node_modules/typebox/build/type/types/call.mjs +23 -0
  1073. package/node_modules/typebox/build/type/types/constructor.d.mts +18 -0
  1074. package/node_modules/typebox/build/type/types/constructor.mjs +24 -0
  1075. package/node_modules/typebox/build/type/types/cyclic.d.mts +16 -0
  1076. package/node_modules/typebox/build/type/types/cyclic.mjs +29 -0
  1077. package/node_modules/typebox/build/type/types/deferred.d.mts +13 -0
  1078. package/node_modules/typebox/build/type/types/deferred.mjs +16 -0
  1079. package/node_modules/typebox/build/type/types/dependent.d.mts +17 -0
  1080. package/node_modules/typebox/build/type/types/dependent.mjs +24 -0
  1081. package/node_modules/typebox/build/type/types/enum.d.mts +18 -0
  1082. package/node_modules/typebox/build/type/types/enum.mjs +22 -0
  1083. package/node_modules/typebox/build/type/types/function.d.mts +21 -0
  1084. package/node_modules/typebox/build/type/types/function.mjs +25 -0
  1085. package/node_modules/typebox/build/type/types/generic.d.mts +13 -0
  1086. package/node_modules/typebox/build/type/types/generic.mjs +17 -0
  1087. package/node_modules/typebox/build/type/types/identifier.d.mts +11 -0
  1088. package/node_modules/typebox/build/type/types/identifier.mjs +17 -0
  1089. package/node_modules/typebox/build/type/types/index.d.mts +45 -0
  1090. package/node_modules/typebox/build/type/types/index.mjs +51 -0
  1091. package/node_modules/typebox/build/type/types/infer.d.mts +15 -0
  1092. package/node_modules/typebox/build/type/types/infer.mjs +20 -0
  1093. package/node_modules/typebox/build/type/types/integer.d.mts +12 -0
  1094. package/node_modules/typebox/build/type/types/integer.mjs +21 -0
  1095. package/node_modules/typebox/build/type/types/intersect.d.mts +15 -0
  1096. package/node_modules/typebox/build/type/types/intersect.mjs +24 -0
  1097. package/node_modules/typebox/build/type/types/literal.d.mts +31 -0
  1098. package/node_modules/typebox/build/type/types/literal.mjs +62 -0
  1099. package/node_modules/typebox/build/type/types/never.d.mts +12 -0
  1100. package/node_modules/typebox/build/type/types/never.mjs +22 -0
  1101. package/node_modules/typebox/build/type/types/null.d.mts +11 -0
  1102. package/node_modules/typebox/build/type/types/null.mjs +17 -0
  1103. package/node_modules/typebox/build/type/types/number.d.mts +12 -0
  1104. package/node_modules/typebox/build/type/types/number.mjs +21 -0
  1105. package/node_modules/typebox/build/type/types/object.d.mts +18 -0
  1106. package/node_modules/typebox/build/type/types/object.mjs +28 -0
  1107. package/node_modules/typebox/build/type/types/parameter.d.mts +17 -0
  1108. package/node_modules/typebox/build/type/types/parameter.mjs +21 -0
  1109. package/node_modules/typebox/build/type/types/properties.d.mts +43 -0
  1110. package/node_modules/typebox/build/type/types/properties.mjs +15 -0
  1111. package/node_modules/typebox/build/type/types/record.d.mts +52 -0
  1112. package/node_modules/typebox/build/type/types/record.mjs +66 -0
  1113. package/node_modules/typebox/build/type/types/ref.d.mts +19 -0
  1114. package/node_modules/typebox/build/type/types/ref.mjs +18 -0
  1115. package/node_modules/typebox/build/type/types/rest.d.mts +11 -0
  1116. package/node_modules/typebox/build/type/types/rest.mjs +17 -0
  1117. package/node_modules/typebox/build/type/types/schema.d.mts +176 -0
  1118. package/node_modules/typebox/build/type/types/schema.mjs +15 -0
  1119. package/node_modules/typebox/build/type/types/static.d.mts +45 -0
  1120. package/node_modules/typebox/build/type/types/static.mjs +3 -0
  1121. package/node_modules/typebox/build/type/types/string.d.mts +12 -0
  1122. package/node_modules/typebox/build/type/types/string.mjs +22 -0
  1123. package/node_modules/typebox/build/type/types/symbol.d.mts +11 -0
  1124. package/node_modules/typebox/build/type/types/symbol.mjs +17 -0
  1125. package/node_modules/typebox/build/type/types/template_literal.d.mts +28 -0
  1126. package/node_modules/typebox/build/type/types/template_literal.mjs +37 -0
  1127. package/node_modules/typebox/build/type/types/this.d.mts +14 -0
  1128. package/node_modules/typebox/build/type/types/this.mjs +17 -0
  1129. package/node_modules/typebox/build/type/types/tuple.d.mts +38 -0
  1130. package/node_modules/typebox/build/type/types/tuple.mjs +25 -0
  1131. package/node_modules/typebox/build/type/types/undefined.d.mts +11 -0
  1132. package/node_modules/typebox/build/type/types/undefined.mjs +17 -0
  1133. package/node_modules/typebox/build/type/types/union.d.mts +15 -0
  1134. package/node_modules/typebox/build/type/types/union.mjs +24 -0
  1135. package/node_modules/typebox/build/type/types/unknown.d.mts +10 -0
  1136. package/node_modules/typebox/build/type/types/unknown.mjs +17 -0
  1137. package/node_modules/typebox/build/type/types/unsafe.d.mts +10 -0
  1138. package/node_modules/typebox/build/type/types/unsafe.mjs +20 -0
  1139. package/node_modules/typebox/build/type/types/void.d.mts +11 -0
  1140. package/node_modules/typebox/build/type/types/void.mjs +17 -0
  1141. package/node_modules/typebox/build/typebox.d.mts +69 -0
  1142. package/node_modules/typebox/build/typebox.mjs +85 -0
  1143. package/node_modules/typebox/build/value/assert/assert.d.mts +14 -0
  1144. package/node_modules/typebox/build/value/assert/assert.mjs +28 -0
  1145. package/node_modules/typebox/build/value/assert/index.d.mts +1 -0
  1146. package/node_modules/typebox/build/value/assert/index.mjs +1 -0
  1147. package/node_modules/typebox/build/value/check/check.d.mts +5 -0
  1148. package/node_modules/typebox/build/value/check/check.mjs +11 -0
  1149. package/node_modules/typebox/build/value/check/index.d.mts +1 -0
  1150. package/node_modules/typebox/build/value/check/index.mjs +1 -0
  1151. package/node_modules/typebox/build/value/clean/additional.d.mts +2 -0
  1152. package/node_modules/typebox/build/value/clean/additional.mjs +6 -0
  1153. package/node_modules/typebox/build/value/clean/clean.d.mts +15 -0
  1154. package/node_modules/typebox/build/value/clean/clean.mjs +17 -0
  1155. package/node_modules/typebox/build/value/clean/from_array.d.mts +2 -0
  1156. package/node_modules/typebox/build/value/clean/from_array.mjs +8 -0
  1157. package/node_modules/typebox/build/value/clean/from_cyclic.d.mts +2 -0
  1158. package/node_modules/typebox/build/value/clean/from_cyclic.mjs +6 -0
  1159. package/node_modules/typebox/build/value/clean/from_intersect.d.mts +2 -0
  1160. package/node_modules/typebox/build/value/clean/from_intersect.mjs +26 -0
  1161. package/node_modules/typebox/build/value/clean/from_object.d.mts +2 -0
  1162. package/node_modules/typebox/build/value/clean/from_object.mjs +31 -0
  1163. package/node_modules/typebox/build/value/clean/from_record.d.mts +2 -0
  1164. package/node_modules/typebox/build/value/clean/from_record.mjs +32 -0
  1165. package/node_modules/typebox/build/value/clean/from_ref.d.mts +2 -0
  1166. package/node_modules/typebox/build/value/clean/from_ref.mjs +8 -0
  1167. package/node_modules/typebox/build/value/clean/from_tuple.d.mts +2 -0
  1168. package/node_modules/typebox/build/value/clean/from_tuple.mjs +14 -0
  1169. package/node_modules/typebox/build/value/clean/from_type.d.mts +2 -0
  1170. package/node_modules/typebox/build/value/clean/from_type.mjs +21 -0
  1171. package/node_modules/typebox/build/value/clean/from_union.d.mts +2 -0
  1172. package/node_modules/typebox/build/value/clean/from_union.mjs +12 -0
  1173. package/node_modules/typebox/build/value/clean/index.d.mts +1 -0
  1174. package/node_modules/typebox/build/value/clean/index.mjs +1 -0
  1175. package/node_modules/typebox/build/value/clone/clone.d.mts +5 -0
  1176. package/node_modules/typebox/build/value/clone/clone.mjs +12 -0
  1177. package/node_modules/typebox/build/value/clone/index.d.mts +1 -0
  1178. package/node_modules/typebox/build/value/clone/index.mjs +1 -0
  1179. package/node_modules/typebox/build/value/codec/callback.d.mts +2 -0
  1180. package/node_modules/typebox/build/value/codec/callback.mjs +25 -0
  1181. package/node_modules/typebox/build/value/codec/decode.d.mts +12 -0
  1182. package/node_modules/typebox/build/value/codec/decode.mjs +52 -0
  1183. package/node_modules/typebox/build/value/codec/encode.d.mts +12 -0
  1184. package/node_modules/typebox/build/value/codec/encode.mjs +52 -0
  1185. package/node_modules/typebox/build/value/codec/from_array.d.mts +2 -0
  1186. package/node_modules/typebox/build/value/codec/from_array.mjs +35 -0
  1187. package/node_modules/typebox/build/value/codec/from_cyclic.d.mts +2 -0
  1188. package/node_modules/typebox/build/value/codec/from_cyclic.mjs +8 -0
  1189. package/node_modules/typebox/build/value/codec/from_intersect.d.mts +2 -0
  1190. package/node_modules/typebox/build/value/codec/from_intersect.mjs +58 -0
  1191. package/node_modules/typebox/build/value/codec/from_object.d.mts +2 -0
  1192. package/node_modules/typebox/build/value/codec/from_object.mjs +42 -0
  1193. package/node_modules/typebox/build/value/codec/from_record.d.mts +2 -0
  1194. package/node_modules/typebox/build/value/codec/from_record.mjs +39 -0
  1195. package/node_modules/typebox/build/value/codec/from_ref.d.mts +2 -0
  1196. package/node_modules/typebox/build/value/codec/from_ref.mjs +31 -0
  1197. package/node_modules/typebox/build/value/codec/from_tuple.d.mts +2 -0
  1198. package/node_modules/typebox/build/value/codec/from_tuple.mjs +32 -0
  1199. package/node_modules/typebox/build/value/codec/from_type.d.mts +2 -0
  1200. package/node_modules/typebox/build/value/codec/from_type.mjs +22 -0
  1201. package/node_modules/typebox/build/value/codec/from_union.d.mts +2 -0
  1202. package/node_modules/typebox/build/value/codec/from_union.mjs +39 -0
  1203. package/node_modules/typebox/build/value/codec/has.d.mts +5 -0
  1204. package/node_modules/typebox/build/value/codec/has.mjs +93 -0
  1205. package/node_modules/typebox/build/value/codec/index.d.mts +3 -0
  1206. package/node_modules/typebox/build/value/codec/index.mjs +3 -0
  1207. package/node_modules/typebox/build/value/convert/convert.d.mts +13 -0
  1208. package/node_modules/typebox/build/value/convert/convert.mjs +15 -0
  1209. package/node_modules/typebox/build/value/convert/from_additional.d.mts +6 -0
  1210. package/node_modules/typebox/build/value/convert/from_additional.mjs +18 -0
  1211. package/node_modules/typebox/build/value/convert/from_array.d.mts +2 -0
  1212. package/node_modules/typebox/build/value/convert/from_array.mjs +7 -0
  1213. package/node_modules/typebox/build/value/convert/from_bigint.d.mts +2 -0
  1214. package/node_modules/typebox/build/value/convert/from_bigint.mjs +6 -0
  1215. package/node_modules/typebox/build/value/convert/from_boolean.d.mts +2 -0
  1216. package/node_modules/typebox/build/value/convert/from_boolean.mjs +6 -0
  1217. package/node_modules/typebox/build/value/convert/from_cyclic.d.mts +2 -0
  1218. package/node_modules/typebox/build/value/convert/from_cyclic.mjs +6 -0
  1219. package/node_modules/typebox/build/value/convert/from_enum.d.mts +2 -0
  1220. package/node_modules/typebox/build/value/convert/from_enum.mjs +6 -0
  1221. package/node_modules/typebox/build/value/convert/from_integer.d.mts +2 -0
  1222. package/node_modules/typebox/build/value/convert/from_integer.mjs +6 -0
  1223. package/node_modules/typebox/build/value/convert/from_intersect.d.mts +2 -0
  1224. package/node_modules/typebox/build/value/convert/from_intersect.mjs +8 -0
  1225. package/node_modules/typebox/build/value/convert/from_literal.d.mts +2 -0
  1226. package/node_modules/typebox/build/value/convert/from_literal.mjs +44 -0
  1227. package/node_modules/typebox/build/value/convert/from_null.d.mts +2 -0
  1228. package/node_modules/typebox/build/value/convert/from_null.mjs +6 -0
  1229. package/node_modules/typebox/build/value/convert/from_number.d.mts +2 -0
  1230. package/node_modules/typebox/build/value/convert/from_number.mjs +6 -0
  1231. package/node_modules/typebox/build/value/convert/from_object.d.mts +2 -0
  1232. package/node_modules/typebox/build/value/convert/from_object.mjs +28 -0
  1233. package/node_modules/typebox/build/value/convert/from_record.d.mts +2 -0
  1234. package/node_modules/typebox/build/value/convert/from_record.mjs +23 -0
  1235. package/node_modules/typebox/build/value/convert/from_ref.d.mts +2 -0
  1236. package/node_modules/typebox/build/value/convert/from_ref.mjs +8 -0
  1237. package/node_modules/typebox/build/value/convert/from_string.d.mts +2 -0
  1238. package/node_modules/typebox/build/value/convert/from_string.mjs +6 -0
  1239. package/node_modules/typebox/build/value/convert/from_template_literal.d.mts +2 -0
  1240. package/node_modules/typebox/build/value/convert/from_template_literal.mjs +6 -0
  1241. package/node_modules/typebox/build/value/convert/from_tuple.d.mts +2 -0
  1242. package/node_modules/typebox/build/value/convert/from_tuple.mjs +11 -0
  1243. package/node_modules/typebox/build/value/convert/from_type.d.mts +2 -0
  1244. package/node_modules/typebox/build/value/convert/from_type.mjs +43 -0
  1245. package/node_modules/typebox/build/value/convert/from_undefined.d.mts +2 -0
  1246. package/node_modules/typebox/build/value/convert/from_undefined.mjs +6 -0
  1247. package/node_modules/typebox/build/value/convert/from_union.d.mts +2 -0
  1248. package/node_modules/typebox/build/value/convert/from_union.mjs +13 -0
  1249. package/node_modules/typebox/build/value/convert/from_void.d.mts +2 -0
  1250. package/node_modules/typebox/build/value/convert/from_void.mjs +6 -0
  1251. package/node_modules/typebox/build/value/convert/index.d.mts +1 -0
  1252. package/node_modules/typebox/build/value/convert/index.mjs +1 -0
  1253. package/node_modules/typebox/build/value/convert/try/index.d.mts +1 -0
  1254. package/node_modules/typebox/build/value/convert/try/index.mjs +1 -0
  1255. package/node_modules/typebox/build/value/convert/try/try.d.mts +8 -0
  1256. package/node_modules/typebox/build/value/convert/try/try.mjs +8 -0
  1257. package/node_modules/typebox/build/value/convert/try/try_array.d.mts +2 -0
  1258. package/node_modules/typebox/build/value/convert/try/try_array.mjs +6 -0
  1259. package/node_modules/typebox/build/value/convert/try/try_bigint.d.mts +2 -0
  1260. package/node_modules/typebox/build/value/convert/try/try_bigint.mjs +45 -0
  1261. package/node_modules/typebox/build/value/convert/try/try_boolean.d.mts +2 -0
  1262. package/node_modules/typebox/build/value/convert/try/try_boolean.mjs +41 -0
  1263. package/node_modules/typebox/build/value/convert/try/try_null.d.mts +2 -0
  1264. package/node_modules/typebox/build/value/convert/try/try_null.mjs +44 -0
  1265. package/node_modules/typebox/build/value/convert/try/try_number.d.mts +2 -0
  1266. package/node_modules/typebox/build/value/convert/try/try_number.mjs +44 -0
  1267. package/node_modules/typebox/build/value/convert/try/try_result.d.mts +8 -0
  1268. package/node_modules/typebox/build/value/convert/try/try_result.mjs +17 -0
  1269. package/node_modules/typebox/build/value/convert/try/try_string.d.mts +2 -0
  1270. package/node_modules/typebox/build/value/convert/try/try_string.mjs +12 -0
  1271. package/node_modules/typebox/build/value/convert/try/try_undefined.d.mts +2 -0
  1272. package/node_modules/typebox/build/value/convert/try/try_undefined.mjs +44 -0
  1273. package/node_modules/typebox/build/value/create/create.d.mts +5 -0
  1274. package/node_modules/typebox/build/value/create/create.mjs +11 -0
  1275. package/node_modules/typebox/build/value/create/error.d.mts +5 -0
  1276. package/node_modules/typebox/build/value/create/error.mjs +7 -0
  1277. package/node_modules/typebox/build/value/create/from_array.d.mts +2 -0
  1278. package/node_modules/typebox/build/value/create/from_array.mjs +10 -0
  1279. package/node_modules/typebox/build/value/create/from_bigint.d.mts +2 -0
  1280. package/node_modules/typebox/build/value/create/from_bigint.mjs +7 -0
  1281. package/node_modules/typebox/build/value/create/from_boolean.d.mts +2 -0
  1282. package/node_modules/typebox/build/value/create/from_boolean.mjs +4 -0
  1283. package/node_modules/typebox/build/value/create/from_constructor.d.mts +2 -0
  1284. package/node_modules/typebox/build/value/create/from_constructor.mjs +10 -0
  1285. package/node_modules/typebox/build/value/create/from_cyclic.d.mts +2 -0
  1286. package/node_modules/typebox/build/value/create/from_cyclic.mjs +6 -0
  1287. package/node_modules/typebox/build/value/create/from_default.d.mts +3 -0
  1288. package/node_modules/typebox/build/value/create/from_default.mjs +10 -0
  1289. package/node_modules/typebox/build/value/create/from_enum.d.mts +2 -0
  1290. package/node_modules/typebox/build/value/create/from_enum.mjs +6 -0
  1291. package/node_modules/typebox/build/value/create/from_function.d.mts +2 -0
  1292. package/node_modules/typebox/build/value/create/from_function.mjs +6 -0
  1293. package/node_modules/typebox/build/value/create/from_integer.d.mts +2 -0
  1294. package/node_modules/typebox/build/value/create/from_integer.mjs +8 -0
  1295. package/node_modules/typebox/build/value/create/from_intersect.d.mts +2 -0
  1296. package/node_modules/typebox/build/value/create/from_intersect.mjs +8 -0
  1297. package/node_modules/typebox/build/value/create/from_literal.d.mts +2 -0
  1298. package/node_modules/typebox/build/value/create/from_literal.mjs +4 -0
  1299. package/node_modules/typebox/build/value/create/from_never.d.mts +2 -0
  1300. package/node_modules/typebox/build/value/create/from_never.mjs +5 -0
  1301. package/node_modules/typebox/build/value/create/from_null.d.mts +2 -0
  1302. package/node_modules/typebox/build/value/create/from_null.mjs +4 -0
  1303. package/node_modules/typebox/build/value/create/from_number.d.mts +2 -0
  1304. package/node_modules/typebox/build/value/create/from_number.mjs +8 -0
  1305. package/node_modules/typebox/build/value/create/from_object.d.mts +2 -0
  1306. package/node_modules/typebox/build/value/create/from_object.mjs +9 -0
  1307. package/node_modules/typebox/build/value/create/from_record.d.mts +2 -0
  1308. package/node_modules/typebox/build/value/create/from_record.mjs +8 -0
  1309. package/node_modules/typebox/build/value/create/from_ref.d.mts +2 -0
  1310. package/node_modules/typebox/build/value/create/from_ref.mjs +9 -0
  1311. package/node_modules/typebox/build/value/create/from_string.d.mts +2 -0
  1312. package/node_modules/typebox/build/value/create/from_string.mjs +9 -0
  1313. package/node_modules/typebox/build/value/create/from_symbol.d.mts +2 -0
  1314. package/node_modules/typebox/build/value/create/from_symbol.mjs +4 -0
  1315. package/node_modules/typebox/build/value/create/from_template_literal.d.mts +2 -0
  1316. package/node_modules/typebox/build/value/create/from_template_literal.mjs +11 -0
  1317. package/node_modules/typebox/build/value/create/from_tuple.d.mts +2 -0
  1318. package/node_modules/typebox/build/value/create/from_tuple.mjs +5 -0
  1319. package/node_modules/typebox/build/value/create/from_type.d.mts +2 -0
  1320. package/node_modules/typebox/build/value/create/from_type.mjs +61 -0
  1321. package/node_modules/typebox/build/value/create/from_undefined.d.mts +2 -0
  1322. package/node_modules/typebox/build/value/create/from_undefined.mjs +4 -0
  1323. package/node_modules/typebox/build/value/create/from_union.d.mts +2 -0
  1324. package/node_modules/typebox/build/value/create/from_union.mjs +9 -0
  1325. package/node_modules/typebox/build/value/create/from_void.d.mts +2 -0
  1326. package/node_modules/typebox/build/value/create/from_void.mjs +4 -0
  1327. package/node_modules/typebox/build/value/create/index.d.mts +2 -0
  1328. package/node_modules/typebox/build/value/create/index.mjs +2 -0
  1329. package/node_modules/typebox/build/value/default/default.d.mts +13 -0
  1330. package/node_modules/typebox/build/value/default/default.mjs +15 -0
  1331. package/node_modules/typebox/build/value/default/from_array.d.mts +2 -0
  1332. package/node_modules/typebox/build/value/default/from_array.mjs +12 -0
  1333. package/node_modules/typebox/build/value/default/from_cyclic.d.mts +2 -0
  1334. package/node_modules/typebox/build/value/default/from_cyclic.mjs +7 -0
  1335. package/node_modules/typebox/build/value/default/from_default.d.mts +3 -0
  1336. package/node_modules/typebox/build/value/default/from_default.mjs +13 -0
  1337. package/node_modules/typebox/build/value/default/from_intersect.d.mts +2 -0
  1338. package/node_modules/typebox/build/value/default/from_intersect.mjs +9 -0
  1339. package/node_modules/typebox/build/value/default/from_object.d.mts +2 -0
  1340. package/node_modules/typebox/build/value/default/from_object.mjs +32 -0
  1341. package/node_modules/typebox/build/value/default/from_record.d.mts +2 -0
  1342. package/node_modules/typebox/build/value/default/from_record.mjs +26 -0
  1343. package/node_modules/typebox/build/value/default/from_ref.d.mts +2 -0
  1344. package/node_modules/typebox/build/value/default/from_ref.mjs +9 -0
  1345. package/node_modules/typebox/build/value/default/from_tuple.d.mts +2 -0
  1346. package/node_modules/typebox/build/value/default/from_tuple.mjs +14 -0
  1347. package/node_modules/typebox/build/value/default/from_type.d.mts +2 -0
  1348. package/node_modules/typebox/build/value/default/from_type.mjs +25 -0
  1349. package/node_modules/typebox/build/value/default/from_union.d.mts +2 -0
  1350. package/node_modules/typebox/build/value/default/from_union.mjs +14 -0
  1351. package/node_modules/typebox/build/value/default/index.d.mts +1 -0
  1352. package/node_modules/typebox/build/value/default/index.mjs +1 -0
  1353. package/node_modules/typebox/build/value/delta/diff.d.mts +10 -0
  1354. package/node_modules/typebox/build/value/delta/diff.mjs +135 -0
  1355. package/node_modules/typebox/build/value/delta/edit.d.mts +24 -0
  1356. package/node_modules/typebox/build/value/delta/edit.mjs +17 -0
  1357. package/node_modules/typebox/build/value/delta/index.d.mts +3 -0
  1358. package/node_modules/typebox/build/value/delta/index.mjs +3 -0
  1359. package/node_modules/typebox/build/value/delta/patch.d.mts +8 -0
  1360. package/node_modules/typebox/build/value/delta/patch.mjs +42 -0
  1361. package/node_modules/typebox/build/value/equal/equal.d.mts +2 -0
  1362. package/node_modules/typebox/build/value/equal/equal.mjs +6 -0
  1363. package/node_modules/typebox/build/value/equal/index.d.mts +1 -0
  1364. package/node_modules/typebox/build/value/equal/index.mjs +1 -0
  1365. package/node_modules/typebox/build/value/errors/errors.d.mts +6 -0
  1366. package/node_modules/typebox/build/value/errors/errors.mjs +12 -0
  1367. package/node_modules/typebox/build/value/errors/index.d.mts +1 -0
  1368. package/node_modules/typebox/build/value/errors/index.mjs +1 -0
  1369. package/node_modules/typebox/build/value/hash/hash.d.mts +6 -0
  1370. package/node_modules/typebox/build/value/hash/hash.mjs +10 -0
  1371. package/node_modules/typebox/build/value/hash/index.d.mts +1 -0
  1372. package/node_modules/typebox/build/value/hash/index.mjs +1 -0
  1373. package/node_modules/typebox/build/value/index.d.mts +20 -0
  1374. package/node_modules/typebox/build/value/index.mjs +29 -0
  1375. package/node_modules/typebox/build/value/parse/index.d.mts +1 -0
  1376. package/node_modules/typebox/build/value/parse/index.mjs +1 -0
  1377. package/node_modules/typebox/build/value/parse/parse.d.mts +11 -0
  1378. package/node_modules/typebox/build/value/parse/parse.mjs +47 -0
  1379. package/node_modules/typebox/build/value/pipeline/index.d.mts +1 -0
  1380. package/node_modules/typebox/build/value/pipeline/index.mjs +1 -0
  1381. package/node_modules/typebox/build/value/pipeline/pipeline.d.mts +10 -0
  1382. package/node_modules/typebox/build/value/pipeline/pipeline.mjs +15 -0
  1383. package/node_modules/typebox/build/value/pointer/index.d.mts +1 -0
  1384. package/node_modules/typebox/build/value/pointer/index.mjs +1 -0
  1385. package/node_modules/typebox/build/value/repair/error.d.mts +7 -0
  1386. package/node_modules/typebox/build/value/repair/error.mjs +8 -0
  1387. package/node_modules/typebox/build/value/repair/from_array.d.mts +2 -0
  1388. package/node_modules/typebox/build/value/repair/from_array.mjs +39 -0
  1389. package/node_modules/typebox/build/value/repair/from_enum.d.mts +2 -0
  1390. package/node_modules/typebox/build/value/repair/from_enum.mjs +6 -0
  1391. package/node_modules/typebox/build/value/repair/from_intersect.d.mts +2 -0
  1392. package/node_modules/typebox/build/value/repair/from_intersect.mjs +8 -0
  1393. package/node_modules/typebox/build/value/repair/from_object.d.mts +2 -0
  1394. package/node_modules/typebox/build/value/repair/from_object.mjs +33 -0
  1395. package/node_modules/typebox/build/value/repair/from_record.d.mts +2 -0
  1396. package/node_modules/typebox/build/value/repair/from_record.mjs +33 -0
  1397. package/node_modules/typebox/build/value/repair/from_ref.d.mts +2 -0
  1398. package/node_modules/typebox/build/value/repair/from_ref.mjs +9 -0
  1399. package/node_modules/typebox/build/value/repair/from_template_literal.d.mts +2 -0
  1400. package/node_modules/typebox/build/value/repair/from_template_literal.mjs +7 -0
  1401. package/node_modules/typebox/build/value/repair/from_tuple.d.mts +2 -0
  1402. package/node_modules/typebox/build/value/repair/from_tuple.mjs +12 -0
  1403. package/node_modules/typebox/build/value/repair/from_type.d.mts +2 -0
  1404. package/node_modules/typebox/build/value/repair/from_type.mjs +88 -0
  1405. package/node_modules/typebox/build/value/repair/from_union.d.mts +2 -0
  1406. package/node_modules/typebox/build/value/repair/from_union.mjs +24 -0
  1407. package/node_modules/typebox/build/value/repair/from_unknown.d.mts +2 -0
  1408. package/node_modules/typebox/build/value/repair/from_unknown.mjs +12 -0
  1409. package/node_modules/typebox/build/value/repair/index.d.mts +1 -0
  1410. package/node_modules/typebox/build/value/repair/index.mjs +1 -0
  1411. package/node_modules/typebox/build/value/repair/repair.d.mts +17 -0
  1412. package/node_modules/typebox/build/value/repair/repair.mjs +20 -0
  1413. package/node_modules/typebox/build/value/shared/index.d.mts +3 -0
  1414. package/node_modules/typebox/build/value/shared/index.mjs +4 -0
  1415. package/node_modules/typebox/build/value/shared/optional_undefined.d.mts +2 -0
  1416. package/node_modules/typebox/build/value/shared/optional_undefined.mjs +15 -0
  1417. package/node_modules/typebox/build/value/shared/union_priority_sort.d.mts +7 -0
  1418. package/node_modules/typebox/build/value/shared/union_priority_sort.mjs +72 -0
  1419. package/node_modules/typebox/build/value/shared/union_score_select.d.mts +3 -0
  1420. package/node_modules/typebox/build/value/shared/union_score_select.mjs +51 -0
  1421. package/node_modules/typebox/build/value/value.d.mts +15 -0
  1422. package/node_modules/typebox/build/value/value.mjs +15 -0
  1423. package/node_modules/typebox/license +23 -0
  1424. package/node_modules/typebox/package.json +87 -0
  1425. package/node_modules/typebox/readme.md +371 -0
  1426. package/package.json +59 -4
  1427. package/skills/pi-proactive/SKILL.md +185 -0
  1428. package/tools/cli.mjs +121 -0
  1429. package/tools/daemon-install.sh +397 -0
  1430. package/tools/daemon-uninstall.sh +226 -0
@@ -0,0 +1,2508 @@
1
+ /**
2
+ * pi-proactive extension entry (M3 集成层:生命周期 / 唯一 tick / 命令面 / 任务表接线).
3
+ *
4
+ * 接线清单:
5
+ * - `session_start` → 重新捕获 ctx/pi → 构造 TaskStore(resolveAgentDir())与 Scheduler
6
+ * (注入 store/trigger/guard/agentId)→ 起**唯一** 1s tick;
7
+ * - tick(唯一定时器)→ `await scheduler.tick()` + 空闲判定/触发;
8
+ * - `session_shutdown` → 幂等清理(tick 停止、scheduler 停止、状态栏清除、终端输入退订);
9
+ * - 代理活动事件(`agent_start`/`agent_end`/`tool_execution_*`/`message_end`)→ 刷新
10
+ * 「最近任何活动」空闲基线(IDLEFIX);`input` 事件只认真人输入(扩展注入不刷新基线)。
11
+ * - 命令面 `/proactive`:status | on | off | test | tasks | cancel <id> | idle on|off。
12
+ *
13
+ * 跨进程协作(M4i 接线):
14
+ * - `session_start` → 注册表注册(agentId/cwd/capabilities/transport)+ socket 通道 + 邮箱 + 30s 心跳;
15
+ * - 1s tick(**不 await**)→ 邮箱扫描(后台)→ 认领 → 按 intent 走 Trigger 投递(来源 `proactive:peer`);
16
+ * - socket 通道 → 同一条入站路径(与邮箱**共用同一个 SeenSet** → 同一 id 只处理一次);
17
+ * - 模型工具 `message_agent` → 解析对端 → 跨进程投递 → 回执如实区分 8 种状态;
18
+ * - `kind:"ask"` → 模型回答后回送 `kind:"reply"`(correlationId 原样带回、threadId 继承)。
19
+ *
20
+ * 约束:
21
+ * - **唯一 tick**:不起第二个定时器 —— 调度由本文件的 1s tick 驱动 `scheduler.tick()`;
22
+ * - **不重叠弹窗**:一次 fireIdle 未完成(Promise pending)时不再发起下一次;
23
+ * - **来源前缀**:入口只传裸 body,前缀唯一由 `src/trigger.ts` 添加(避免双前缀);
24
+ * - **异常隔离**:tick / 命令处理 / 调度回调全部 try/catch(宿主 uncaughtException → process.exit(1))。
25
+ */
26
+ import { randomUUID } from "node:crypto";
27
+ import os from "node:os";
28
+ import path from "node:path";
29
+ import { Type } from "typebox";
30
+ import { PROACTIVE_FILE_MODE, chmodQuiet, defaultConfig, ensureDir, hardenProactivePermissions, loadConfig, resolveAgentDir, saveEnabled, ConfigValidationError } from "../src/config.js";
31
+ import { ActivityTracker } from "../src/activity.js";
32
+ import { Guard } from "../src/guard.js";
33
+ import { Trigger } from "../src/trigger.js";
34
+ import { Lineage } from "../src/lineage.js";
35
+ import { collectHealth } from "../src/health.js";
36
+ import { effectiveIdleDetect, evaluateIdle, fireIdle } from "../src/idle.js";
37
+ import { Scheduler } from "../src/scheduler.js";
38
+ import { TaskStore } from "../src/task-store.js";
39
+ import { AskLedger, PeerLifecycle, PeerResponder, PeerWatch, TIMEOUT_NOTICE_MARKER, buildDrainReplies, buildTellEnvelope, humanOriginLabel, parseTellCommand, resolveTellTarget, resolveTrustedHumanSenders, } from "../src/peer.js";
40
+ import { shutdownSpawnedPeers, spawnPeer, } from "../src/peer-spawn.js";
41
+ import { DEFAULT_MAX_ROUNDS, ThreadStore } from "../src/thread.js";
42
+ import { createStrictSenderPolicy, makeAgentId, makeSessionAgentId, Registry } from "../src/registry.js";
43
+ import { SeenSet } from "../src/dedupe.js";
44
+ import { Mailbox, gcStaleTemporaries } from "../src/mailbox.js";
45
+ import { createEnvelope, nextHop } from "../src/envelope.js";
46
+ import { writeToMailbox } from "../src/outbox.js";
47
+ import { deliverCrossProcess, startSocketServer, } from "../src/socket.js";
48
+ import { createScheduledTask, dispatchProactiveCommand, errText, formatHumanGatedNotice, formatIdleDecision, formatScheduleResult, queryPeerDirectory, SUBCOMMANDS, } from "../src/commands.js";
49
+ const TICK_MS = 1000;
50
+ /**
51
+ * 本机 GC 周期(ms):规范 §6 阈值表「每次启动 + 每 1 小时」。
52
+ *
53
+ * GC 的**责任方 = `<proactiveDir>` 持有者**(即本进程)。
54
+ */
55
+ const GC_INTERVAL_MS = 3_600_000;
56
+ /** 上次 GC 的时刻(ms;0 = 还没跑过)。 */
57
+ let lastGcAt = 0;
58
+ /**
59
+ * 归档/注册表条目的**保留窗口**(ms):规范 §6 阈值表
60
+ * 「expired/ corrupt/ failed/ processed/ · 每 24 小时 · 年龄 > 7 天 → 删除」。
61
+ */
62
+ const ARCHIVE_RETENTION_MS = 7 * 24 * 3_600_000;
63
+ export function runGc(agentDir, store, deps) {
64
+ const registry = deps?.registry ?? peerRegistry;
65
+ const mailbox = deps?.mailbox ?? peerMailbox;
66
+ try {
67
+ const removed = gcStaleTemporaries(agentDir);
68
+ if (removed.length > 0)
69
+ console.error(`[proactive] GC:回收 ${removed.length} 个残留 tmp`);
70
+ }
71
+ catch (err) {
72
+ console.error("[proactive] GC(残留 tmp)失败:", err);
73
+ }
74
+ try {
75
+ const claims = store?.sweepStaleClaims() ?? 0;
76
+ if (claims > 0)
77
+ console.error(`[proactive] GC:回收 ${claims} 个失效的任务认领`);
78
+ }
79
+ catch (err) {
80
+ console.error("[proactive] GC(任务认领)失败:", err);
81
+ }
82
+ // P-D7:注册表条目的增长上限(不在场且超期 → 删除;在线条目绝不删)。
83
+ try {
84
+ const entries = registry?.sweepStaleEntries() ?? 0;
85
+ if (entries > 0)
86
+ console.error(`[proactive] GC:回收 ${entries} 个不在场的注册表条目`);
87
+ }
88
+ catch (err) {
89
+ console.error("[proactive] GC(注册表条目)失败:", err);
90
+ }
91
+ // P-D7:归档目录(expired/ corrupt/ failed/ processed/)的清理责任方 ——
92
+ // `Mailbox.cleanup()` 此前在生产代码里**从未被调用**(磁盘无限增长)。
93
+ try {
94
+ const cleaned = mailbox?.cleanup({ olderThanMs: ARCHIVE_RETENTION_MS });
95
+ if (cleaned && cleaned.removed > 0) {
96
+ console.error(`[proactive] GC:清理 ${cleaned.removed} 个归档文件(> 7 天)`);
97
+ }
98
+ }
99
+ catch (err) {
100
+ console.error("[proactive] GC(归档清理)失败:", err);
101
+ }
102
+ }
103
+ const STATUS_KEY = "proactive";
104
+ /** 状态栏节流:内容未变时最多每 5s 更新一次(避免每秒刷一条 setStatus 噪声)。 */
105
+ const STATUS_THROTTLE_MS = 5000;
106
+ /**
107
+ * agentId:`<name>#<host>#<sessionId>`(**会话稳定** —— 跨进程重启不变)。
108
+ *
109
+ * 形态说明:
110
+ * - 有 `sessionId`(宿主 `ctx.sessionManager.getSessionId()`)→ `<name>#<host>#<sessionId>`
111
+ * —— 跨进程重启**不变**、会话之间**唯一** → 「对端离线时消息落盘待其上线」才成立(V-03 F1);
112
+ * - 没有 `sessionId`(宿主未提供)→ 退回 `<name>#<host>#<pid>`(进程级唯一,能力退化但不报错)。
113
+ *
114
+ * 不得再用常量 `"local"` —— 否则同机多会话共享同一身份 → `scope:"session"` 的旧任务(无 `ownerSessionId`)
115
+ * 会被多个会话各投递一次(V-02 Major-2)。`PI_PROACTIVE_AGENT_ID` 保留为显式覆盖(测试 / 调试用)。
116
+ *
117
+ * agentId 现在只用于 **peer 寻址 / global 任务认领 / 旧任务兜底**;
118
+ * `scope:"session"` 的归属以**会话**(`ownerSessionId`)为准。
119
+ */
120
+ /**
121
+ * 本会话在注册表里的**注册名**。
122
+ *
123
+ * 缺省 = 当前工作目录的 basename(既有行为)。
124
+ * `PI_PROACTIVE_AGENT_NAME` 可覆盖 —— **被创建的对端用它拿到一个专属名字**
125
+ * (否则同一 cwd 起的两个会话同名 → 按名字寻址有歧义,见协议 §2.3)。
126
+ */
127
+ export function resolveAgentName(env = process.env) {
128
+ const override = env.PI_PROACTIVE_AGENT_NAME;
129
+ if (override !== undefined && override !== "")
130
+ return override;
131
+ return path.basename(process.cwd());
132
+ }
133
+ /**
134
+ * 本会话的**角色**(KK-10 作用域):`coordinator`(协调者,会主动 watch)/
135
+ * `worker`(执行者,只被 watch、不主动问)/ 缺省 = 不限定角色。
136
+ */
137
+ export function resolvePeerRole(env = process.env) {
138
+ const raw = env.PI_PROACTIVE_ROLE;
139
+ if (raw === "coordinator")
140
+ return "coordinator";
141
+ if (raw === "worker")
142
+ return "worker";
143
+ return undefined;
144
+ }
145
+ /**
146
+ * 本会话的 **watch 名单**(KK-10 作用域):`PI_PROACTIVE_WATCH_PEERS=<agentId,...>`。
147
+ *
148
+ * 名单**随会话**(不是全局配置)→ 问询量从 O(N²) 降回 O(实际配对数)。
149
+ * 缺省 / 空 = 不限定(保持既有行为)。
150
+ */
151
+ export function resolveWatchList(env = process.env) {
152
+ const raw = env.PI_PROACTIVE_WATCH_PEERS;
153
+ if (raw === undefined || raw === "")
154
+ return [];
155
+ return raw
156
+ .split(",")
157
+ .map((x) => x.trim())
158
+ .filter((x) => x !== "");
159
+ }
160
+ export function resolveAgentId(env = process.env, pid = process.pid, sessionId) {
161
+ if (env.PI_PROACTIVE_AGENT_ID)
162
+ return env.PI_PROACTIVE_AGENT_ID;
163
+ const name = resolveAgentName(env);
164
+ const host = os.hostname();
165
+ return sessionId ? makeSessionAgentId(name, host, sessionId) : makeAgentId(name, host, pid);
166
+ }
167
+ /**
168
+ * 本进程的 agentId。
169
+ *
170
+ * **可变**:宿主只有到了 `session_start` 才给得出 `sessionId` → 那时才按会话重算
171
+ * (跨进程重启稳定的会话形态)。在此之前是 pid 形态(退化但不报错)。
172
+ */
173
+ let AGENT_ID = resolveAgentId();
174
+ /**
175
+ * 取当前会话 id(跨进程重启稳定)。
176
+ *
177
+ * 宿主不提供 `sessionManager` 或调用失败 → 返回 `undefined`(此时新建任务不带 `ownerSessionId`,
178
+ * 调度器退回按进程归属兜底;日志如实记录,不静默吞掉)。
179
+ */
180
+ export function resolveSessionId(ctx) {
181
+ try {
182
+ const id = ctx?.sessionManager?.getSessionId?.();
183
+ return typeof id === "string" && id !== "" ? id : undefined;
184
+ }
185
+ catch (err) {
186
+ console.error("[proactive] 取 sessionId 失败:", err);
187
+ return undefined;
188
+ }
189
+ }
190
+ let currentCtx;
191
+ let currentPi;
192
+ let currentTrigger;
193
+ /** 统一事件流(血缘):「因」(触发原因)+「果」(结果记账),per-agent 只追加 JSONL。 */
194
+ let currentLineage;
195
+ /** 最近一次「由主动投递引发的回合」的来源(供派生任务绑定 `triggeredBy`)。 */
196
+ let currentTurnSource;
197
+ let currentStore;
198
+ let currentScheduler;
199
+ /** 当前会话 id(宿主 `ctx.sessionManager.getSessionId()`)→ **跨进程重启稳定**(session 作用域归属依据)。 */
200
+ let currentSessionId;
201
+ let config = safeConfig();
202
+ let tracker = new ActivityTracker({ idleDetect: config.idleDetect });
203
+ let guard = new Guard(config);
204
+ /**
205
+ * 代理是否正在工作(模型回合进行中)—— IDLEFIX:触发前必须确认「代理已交回控制权」。
206
+ *
207
+ * 与宿主 `ctx.isIdle()` 取**或**:宿主信号是权威,但它的语义由宿主版本决定;
208
+ * 我们自己数回合/工具链 → 即使宿主的忙闲信号偏窄,**长工具链**也不会被漏判成空闲。
209
+ */
210
+ let agentRunActive = false;
211
+ /** 正在执行的工具数(长工具链)—— 同上。 */
212
+ let activeToolCount = 0;
213
+ /** 上一次写入状态栏的内容指纹(`enabled|reason`)与时刻(用于节流)。 */
214
+ let lastStatusKey = "";
215
+ let lastStatusAt = 0;
216
+ let tickTimer;
217
+ /** 正在进行的空闲触发(Promise pending)—— 用于避免 askUser 弹窗叠加。 */
218
+ let idleFirePending;
219
+ // ---- 跨进程协作(M4i) ----
220
+ /** 跨进程消息的来源标记(模型据此区分「来自对端 agent」与本地触发)。 */
221
+ export const PEER_CUSTOM_TYPE = "proactive:peer";
222
+ /** 心跳周期(ms):30s(**不是 1s** —— 心跳太密会无谓写盘)。 */
223
+ const HEARTBEAT_MS = 30_000;
224
+ /**
225
+ * 等待模型回答(ask → reply 闭环)的**上界**(ms):10 分钟。
226
+ *
227
+ * Major-2:过期**不等于丢弃** —— ① 请求方会收到一条「等待超时」通知(过期必须对请求方可见);
228
+ * ② 迟到的回答**仍会回信**(正文标注「已超过等待时限」)→ 闭环在「回答来得慢」这一正常场景下
229
+ * 也不静默断裂。上界仍有(10 分钟)→ 不会无限期挂起陈旧提问。
230
+ */
231
+ const PEER_ANSWER_TIMEOUT_MS = 600_000;
232
+ /**
233
+ * 自注入消息的**标记串**(P-4)。
234
+ *
235
+ * 宿主把自定义消息转成 role:"user" 的普通用户消息(**没有 customType**)→ 只能靠内容识别
236
+ * 「是不是自己注入的」。旧实现用**正文子串**(正文是否包含对端提问正文)→ 用户随后说了同样正文
237
+ * (如对端问「继续」、用户说「继续做第 3 步」)就被误判成自注入 → 回信**漏标【歧义归因】**。
238
+ *
239
+ * 可靠做法:注入时在内容里放一个**不可混淆的标记串**(每次注入一个随机 uuid),
240
+ * 识别时**精确匹配该标记本身**(而不是匹配用户可能的正文)。
241
+ */
242
+ const INJECTION_MARKER_PREFIX = "[proactive-inject:";
243
+ /** 最近若干次注入的标记串(有界:只留最近 16 条)。 */
244
+ const injectionMarkers = [];
245
+ /**
246
+ * 已被宿主「input(source:"extension")」事件**认领**的标记串(X7 · R-2)。
247
+ *
248
+ * 含义:宿主把我们的自定义消息转成了 role:"user" 的普通用户消息(**丢了 customType**),
249
+ * 并且**先**发了一次 `input` 事件(source="extension")→ 这条消息**确定是我们注入的**。
250
+ * 这是「自己注入的消息」与「用户原样复制了整段转录」之间**唯一可区分的信号**:
251
+ * - 认领过的标记串 → 随后出现的同文本消息 = **我们的回声**(不得当成用户发言);
252
+ * - 没被认领的标记串 → 出现在用户消息里 = **用户复制**(当成用户发言 → 宁可多标歧义)。
253
+ */
254
+ const claimedInjectionMarkers = new Set();
255
+ /** peer watch 扫描周期(ms):注册表读盘不必每秒做。 */
256
+ const PEER_WATCH_INTERVAL_MS = 30_000;
257
+ /** 本 agent 的注册表(在场 / 忙闲 / 心跳)。 */
258
+ let peerRegistry;
259
+ /** 本 agent 的收件箱(文件邮箱)。 */
260
+ let peerMailbox;
261
+ /** socket 通道句柄。 */
262
+ let peerSocket;
263
+ /** socket 通道启动中的 promise(shutdown 时必须等它落地再关,否则会漏掉句柄)。 */
264
+ let peerSocketStarting;
265
+ /** 心跳定时器(独立于 1s tick → 不阻塞 tick)。 */
266
+ let heartbeatTimer;
267
+ /** 邮箱扫描是否正在进行(防重入)。 */
268
+ let peerScanBusy = false;
269
+ /**
270
+ * 逐条 reply 归因器(M5a):入站 `ask` 登记 pending → 模型回答归因 → 回信。
271
+ * **按 pending 逐条归因**,不再用「取下一条 assistant 文本」的队列(那会把用户自己的回合当回答)。
272
+ */
273
+ let peerResponder;
274
+ /**
275
+ * ASKLOOP:提问方的 ask 账本(已发出的 ask → 回信配对 → 结局 → **决定还问不问**)。
276
+ *
277
+ * 语义闭环在**收讫侧**(KK-7):没有「已答 / 未答 / 不可达」状态时,提问方只会一直问
278
+ * (实测 196 问 / 3 答)。频率护栏只是最后一道防线,**替代不了**语义闭环。
279
+ */
280
+ let askLedger;
281
+ /** peer 生命周期状态机(创建 → 就绪 → 可交互 → 排空 → 死亡;墓碑记下线时间与原因)。 */
282
+ let peerLifecycle;
283
+ /** peer watch(跨会话空闲协作):空闲 peer 询问进度。 */
284
+ let peerWatch;
285
+ /** 线程日志存储缓存(线程键 → ThreadStore)。 */
286
+ const threadStores = new Map();
287
+ /** peer watch 扫描节流(ms):注册表读盘不必每秒做。 */
288
+ let lastPeerWatchAt = 0;
289
+ /**
290
+ * 最近一次**配置校验错误**(拼错的配置项 → 必须让用户看见,不得静默忽略)。
291
+ *
292
+ * 通道限制:配置加载发生在宿主给出 `ctx` 之前 → 先存起来,
293
+ * 由 `session_start`(拿得到 `ctx.ui.notify`)呈现给用户(stderr 亦有一份)。
294
+ */
295
+ let pendingConfigError;
296
+ function safeConfig() {
297
+ try {
298
+ pendingConfigError = undefined;
299
+ return loadConfig();
300
+ }
301
+ catch (err) {
302
+ if (err instanceof ConfigValidationError) {
303
+ // M8:未知配置项 → **报错并指名**(键名 + 文件路径 + 建议值)。
304
+ pendingConfigError = err.message;
305
+ console.error(err.message);
306
+ }
307
+ else {
308
+ console.error("[proactive] 配置加载失败:", err);
309
+ }
310
+ return defaultConfig();
311
+ }
312
+ }
313
+ /**
314
+ * 记一次**代理活动**(模型回合 / 工具调用 / 助手消息落定)→ 刷新「最近任何活动」空闲基线。
315
+ *
316
+ * 为什么必须记(IDLEFIX,依据 `pi-proactive/docs/idle-ground-truth.md` §6.2 前提 1):
317
+ * 原先空闲基线只被「用户输入」刷新 → 代理连续干活 12 分钟会被记成「用户已经 12 分钟没说话」
318
+ * → 工作刚结束就误触发(实测:工作期误触发率 20.07% → 3.01%)。
319
+ *
320
+ * 失败不得冒泡(宿主 uncaughtException → process.exit(1))。
321
+ */
322
+ function markAgentActivity() {
323
+ try {
324
+ tracker.mark("agent");
325
+ }
326
+ catch {
327
+ /* ignore: 活动标记失败不得影响宿主 */
328
+ }
329
+ }
330
+ /** 幂等清理:重复调用不抛错。 */
331
+ function stopTick() {
332
+ if (tickTimer !== undefined) {
333
+ clearInterval(tickTimer);
334
+ tickTimer = undefined;
335
+ }
336
+ }
337
+ const scheduleTaskParameters = Type.Object({
338
+ prompt: Type.String({ description: "任务提示词" }),
339
+ intent: Type.Optional(Type.Union([Type.Literal("wake"), Type.Literal("interrupt"), Type.Literal("queue"), Type.Literal("notify")], {
340
+ description: "投递意图,默认 wake",
341
+ })),
342
+ askUser: Type.Optional(Type.Boolean({ description: "触发时是否向用户提问(仅本地)" })),
343
+ when: Type.Optional(Type.String({ description: "触发时间:时长(10m)/ 时刻(18:30)/ ISO 8601;缺省按 10m 处理" })),
344
+ });
345
+ /**
346
+ * 模型工具面(NATURAL):**按能力域分组**的 4 个域工具(不是 13 个细碎工具)。
347
+ *
348
+ * 参数名与命令面一致(`when` / `content` / `id` / `peer` / `scope` / `limit` / `name` / `all` …),
349
+ * `action` 的取值就是命令面的子命令名 → 语义同源、可机检。
350
+ */
351
+ /** 查询域:查对端 / 看历史 / 看状态 / 看任务 / 只读体检 / 看手册 / 查配置清单。 */
352
+ const proactiveQueryParameters = Type.Object({
353
+ action: Type.Union([
354
+ Type.Literal("peers"),
355
+ Type.Literal("history"),
356
+ Type.Literal("status"),
357
+ Type.Literal("tasks"),
358
+ Type.Literal("doctor"),
359
+ Type.Literal("help"),
360
+ Type.Literal("config"),
361
+ ], { description: "查询动作(与 /proactive 子命令同名)" }),
362
+ name: Type.Optional(Type.String({ description: "peers:名字子串过滤" })),
363
+ all: Type.Optional(Type.Boolean({ description: "peers:是否包含离线对端" })),
364
+ idle: Type.Optional(Type.Boolean({ description: "peers:只看空闲对端" })),
365
+ detail: Type.Optional(Type.String({ description: "peers:只看这一个 agentId" })),
366
+ scope: Type.Optional(Type.Union([Type.Literal("peer"), Type.Literal("me")], { description: "history:范围(对端 / 我)" })),
367
+ peer: Type.Optional(Type.String({ description: "history:按对端 agentId 过滤" })),
368
+ limit: Type.Optional(Type.String({ description: "history:条数(1-200 的整数)" })),
369
+ json: Type.Optional(Type.Boolean({ description: "doctor / config:输出 JSON" })),
370
+ });
371
+ /**
372
+ * 进度 / ETA 查询(任务卡 ETA · E3)。
373
+ *
374
+ * 与人侧 `/proactive progress` **同源同口径**:同一个分派(`dispatchProactiveCommand`)→
375
+ * 同一份快照 → 两侧正文逐字一致。
376
+ */
377
+ const progressQueryParameters = Type.Object({});
378
+ /** 排程域:定时 / 定点 / 周期 / 取消。 */
379
+ const proactiveScheduleParameters = Type.Object({
380
+ action: Type.Union([Type.Literal("in"), Type.Literal("at"), Type.Literal("every"), Type.Literal("cancel")], { description: "排程动作(与 /proactive 子命令同名)" }),
381
+ when: Type.Optional(Type.String({ description: "in/at/every:触发时间(时长 10m / 时刻 18:30)" })),
382
+ content: Type.Optional(Type.String({ description: "in/at/every:任务内容" })),
383
+ id: Type.Optional(Type.String({ description: "cancel:任务 id" })),
384
+ });
385
+ /** 对端协作域:给对端下指令(tell)/ 创建对端(spawn,受存活上限)。 */
386
+ const proactivePeerParameters = Type.Object({
387
+ action: Type.Union([Type.Literal("tell"), Type.Literal("spawn")], { description: "对端动作(与 /proactive 子命令同名)" }),
388
+ peer: Type.Optional(Type.String({ description: "tell:目标对端(名字或 agentId)" })),
389
+ content: Type.Optional(Type.String({ description: "tell:指令内容" })),
390
+ kind: Type.Optional(Type.Union([Type.Literal("ask"), Type.Literal("task"), Type.Literal("notify")], {
391
+ description: "tell:指令类型(缺省 ask)",
392
+ })),
393
+ subject: Type.Optional(Type.String({ description: "tell:标题" })),
394
+ thread: Type.Optional(Type.String({ description: "tell:线程 id" })),
395
+ name: Type.Optional(Type.String({ description: "spawn:对端名字" })),
396
+ });
397
+ /**
398
+ * 管理域:总开关 / 空闲触发 / 自检。
399
+ *
400
+ * **全部属 human-gated**:工具可调用,但只回报「需人工确认」+ 可复制的人工指令,
401
+ * **不自行改全局开关**(brief-v4 §9.1:入口可达性 100%,执行自治按权限阶梯)。
402
+ */
403
+ const proactiveManageParameters = Type.Object({
404
+ action: Type.Union([Type.Literal("on"), Type.Literal("off"), Type.Literal("idle"), Type.Literal("test")], { description: "管理动作(与 /proactive 子命令同名)" }),
405
+ state: Type.Optional(Type.Union([Type.Literal("on"), Type.Literal("off")], { description: "idle:开 / 关" })),
406
+ });
407
+ /**
408
+ * 命令面 / 模型工具面共用的运行期上下文(**同源接线的唯一注入点**)。
409
+ *
410
+ * 两处(`/proactive …` 命令与模型工具)都拿它去调 `dispatchProactiveCommand` →
411
+ * 同一能力只有一份实现;这里只负责「把运行期依赖递进去」,**不含任何业务判定**。
412
+ */
413
+ function commandContext() {
414
+ return {
415
+ agentId: AGENT_ID,
416
+ ...(currentSessionId === undefined ? {} : { sessionId: currentSessionId }),
417
+ runtimeMode: currentCtx?.mode ?? "rpc",
418
+ getConfig: () => config,
419
+ setConfig: (next) => {
420
+ // peerWatch 是运行期字段(toggleEnabled 返回的是窄类型)→ 显式带回。
421
+ config = { ...next, peerWatch: config.peerWatch };
422
+ },
423
+ snapshot: () => tracker.snapshot(),
424
+ setIdleDetect: (detect) => {
425
+ if (currentCtx)
426
+ tracker.setIdleDetect(detect);
427
+ },
428
+ evaluateIdle: () => evaluateIdle({ config, tracker, guard, runtimeMode: currentCtx?.mode }),
429
+ store: currentStore,
430
+ registry: peerRegistry,
431
+ lineage: currentLineage,
432
+ inFlightForPeer,
433
+ recentEventsHint,
434
+ helpText: formatHelp,
435
+ collectHealth: () => collectHealth(resolveAgentDir()),
436
+ persistEnabled: (on) => saveEnabled(on),
437
+ spawnPeerSession: async (name) => {
438
+ const result = await spawnPeer({
439
+ ...(name === undefined ? {} : { name }),
440
+ ...(peerRegistry === undefined ? {} : { registry: peerRegistry }),
441
+ onLog: (m) => console.error(`[proactive] ${m}`),
442
+ });
443
+ if (!result.ok) {
444
+ return {
445
+ ok: false,
446
+ phase: result.phase,
447
+ reason: result.reason,
448
+ ...(result.error === undefined ? {} : { error: result.error }),
449
+ };
450
+ }
451
+ peerLifecycle?.transition(result.peer.agentId, result.peer.state);
452
+ return { ok: true, name: result.peer.name, agentId: result.peer.agentId, state: result.peer.state };
453
+ },
454
+ tellPeer: (args) => runTell(args),
455
+ selfTest: () => runSelfTest(),
456
+ };
457
+ }
458
+ /**
459
+ * 模型工具 → **命令面同一个分派**(NATURAL 同源硬要求)。
460
+ *
461
+ * 工具参数先拼成**命令面同名的参数**,再交给 `dispatchProactiveCommand` →
462
+ * 工具与命令跑的是同一段实现,产出逐字相同的结果(不可能漂移)。
463
+ */
464
+ async function dispatchTool(args, details) {
465
+ try {
466
+ const out = await dispatchProactiveCommand(args, commandContext(), { origin: "model" });
467
+ return {
468
+ content: [{ type: "text", text: out.text }],
469
+ // `command` = 实际下发给分派的命令串(与命令面同形 → 可对照「工具走了哪条命令」)。
470
+ details: { ...details, level: out.level, command: args },
471
+ };
472
+ }
473
+ catch (err) {
474
+ const msg = `proactive: ${errText(err)}`;
475
+ return { content: [{ type: "text", text: msg }], details: { ...details, level: "error", error: msg } };
476
+ }
477
+ }
478
+ /**
479
+ * human-gated 能力的闸门说明(**单一真源**:与能力目录里的能力 id 逐字一致)。
480
+ *
481
+ * 口径(brief-v4 §9.1):模型入口**可达**(工具可调用),但**不得自主执行** →
482
+ * 只回报「需人工确认」+ 一条可复制的人工指令。
483
+ */
484
+ function humanGatedNotice(action, state) {
485
+ switch (action) {
486
+ case "on":
487
+ return {
488
+ capabilityId: "global-toggle",
489
+ humanCommand: "/proactive on",
490
+ reason: "主动性总开关是全局开关,属人工闸门(模型不得擅自改变用户的全局开关)。",
491
+ };
492
+ case "off":
493
+ return {
494
+ capabilityId: "global-toggle",
495
+ humanCommand: "/proactive off",
496
+ reason: "主动性总开关是全局开关,属人工闸门(模型不得擅自改变用户的全局开关)。",
497
+ };
498
+ case "idle":
499
+ return {
500
+ capabilityId: "idle-trigger-toggle",
501
+ humanCommand: `/proactive idle ${state ?? "on|off"}`,
502
+ reason: "空闲触发开关会改变打扰用户的时机,属人工闸门。",
503
+ };
504
+ default:
505
+ return {
506
+ capabilityId: "self-test",
507
+ humanCommand: "/proactive test",
508
+ reason: "自检会向用户会话强制投递一条消息,属诊断类人工闸门。",
509
+ };
510
+ }
511
+ }
512
+ /** human-gated 工具的回执(**不改任何全局状态**,只给人工指令)。 */
513
+ function manageTool(action, state) {
514
+ const notice = humanGatedNotice(action, state);
515
+ return {
516
+ content: [{ type: "text", text: formatHumanGatedNotice(notice) }],
517
+ details: { action, humanGated: true, humanCommand: notice.humanCommand, capabilityId: notice.capabilityId },
518
+ };
519
+ }
520
+ export default function proactiveExtension(pi) {
521
+ pi.registerTool({
522
+ name: "schedule_task",
523
+ label: "Schedule Task",
524
+ description: "预约一个稍后触发的任务(真正落库到任务表,到点由调度器投递)。" +
525
+ "when 支持时长(10m)、时刻(18:30)或 ISO 时间;缺省按 10m 处理。",
526
+ parameters: scheduleTaskParameters,
527
+ async execute(_toolCallId, params, _signal, _onUpdate, _ctx) {
528
+ const store = currentStore;
529
+ if (!store) {
530
+ const msg = "proactive: session_start 尚未触发,任务表未初始化,未创建任务。";
531
+ return { content: [{ type: "text", text: msg }], details: { created: false, error: msg } };
532
+ }
533
+ // **同源**:与命令面 `/proactive in|at|every` 共用 `createScheduledTask`(同一段解析/校验/落库)。
534
+ const result = createScheduledTask({
535
+ store,
536
+ config,
537
+ agentId: AGENT_ID,
538
+ // 会话归属(跨进程重启稳定);宿主未提供 sessionId 时留空 → 退回进程归属兜底。
539
+ ...(currentSessionId === undefined ? {} : { sessionId: currentSessionId }),
540
+ form: "auto",
541
+ when: params.when,
542
+ content: params.prompt,
543
+ ...(params.intent === undefined ? {} : { intent: params.intent }),
544
+ // **不**继承 idleTrigger.askUser(M5c RP-11 M-2):定时任务默认 askUser=false
545
+ // (定时投递不该弹框问用户);只有模型显式登记 askUser:true 才问。
546
+ ...(params.askUser === undefined ? {} : { askUser: params.askUser }),
547
+ source: "model",
548
+ // **任务与触发源绑定(果)**:本次回合由哪一次主动投递引发?
549
+ // 没有主动投递引发(用户自己让模型排期)→ 不带该字段。
550
+ ...(currentTurnSource !== undefined ? { triggeredBy: currentTurnSource.eventId } : {}),
551
+ });
552
+ if (!result.ok) {
553
+ const msg = `proactive: ${result.error}`;
554
+ return { content: [{ type: "text", text: msg }], details: { created: false, error: msg } };
555
+ }
556
+ const task = result.task;
557
+ const text = formatScheduleResult(task, result.now, result.info);
558
+ return {
559
+ content: [{ type: "text", text }],
560
+ details: { created: true, taskId: task.id, dueAt: task.dueAt, schedule: task.schedule },
561
+ };
562
+ },
563
+ });
564
+ pi.registerTool({
565
+ name: "message_agent",
566
+ label: "Message Agent",
567
+ description: "给另一个正在运行的 agent 会话发消息(跨进程协作)。" +
568
+ "对端在线时走 socket 直达;不在线时消息落盘到对端邮箱,待其上线后处理。",
569
+ parameters: messageAgentParameters,
570
+ async execute(_toolCallId, params, _signal, _onUpdate, _ctx) {
571
+ const registry = peerRegistry;
572
+ if (!registry) {
573
+ const msg = "proactive: 跨进程协作未初始化(session_start 尚未触发),未发送。";
574
+ return { content: [{ type: "text", text: msg }], details: { status: "error", error: msg } };
575
+ }
576
+ // 目标寻址:**在线优先,离线也能解析**(注册表保留离线条目)→ 离线时消息落盘待其上线。
577
+ let targetAgentId;
578
+ try {
579
+ targetAgentId = registry.resolve(params.to).agentId;
580
+ }
581
+ catch (err) {
582
+ // 解析失败:名字从未注册过(无从知道它的邮箱目录)→ 如实报错(**不是** rejected:
583
+ // 信封本身合法,rejected 只留给「信封非法」)。
584
+ // 若调用方给的是完整 agentId(含 "#")→ 直接按该地址落盘,等对方上线即可取走。
585
+ if (params.to.includes("#")) {
586
+ targetAgentId = params.to;
587
+ }
588
+ else {
589
+ const msg = `proactive: 找不到目标 agent「${params.to}」:${errText(err)}`;
590
+ return { content: [{ type: "text", text: msg }], details: { status: "error", error: msg } };
591
+ }
592
+ }
593
+ let envelope;
594
+ try {
595
+ // ASKLOOP:提问(kind=ask)**显式带 correlationId** → 被问方拿得到回信句柄,
596
+ // 回信原样带回它 → 提问方能把回信配回这条提问(闭环 + 结局记账)。
597
+ const kind = params.kind ?? "notify";
598
+ const correlationId = kind === "ask" ? `ask-${randomUUID()}` : undefined;
599
+ envelope = createEnvelope({
600
+ from: AGENT_ID,
601
+ to: targetAgentId,
602
+ kind,
603
+ intent: params.intent ?? "wake",
604
+ subject: params.subject,
605
+ body: params.body,
606
+ threadId: params.threadId,
607
+ ...(correlationId === undefined ? {} : { correlationId }),
608
+ });
609
+ }
610
+ catch (err) {
611
+ const msg = `proactive: 消息参数非法:${errText(err)}`;
612
+ return { content: [{ type: "text", text: msg }], details: { status: "rejected", error: msg } };
613
+ }
614
+ const ack = await deliverToPeer(targetAgentId, envelope);
615
+ // ASKLOOP:提问纳入账本 → 收到回信即记结局(answered / unanswered / unreachable)。
616
+ if (envelope.kind === "ask" && envelope.correlationId !== undefined) {
617
+ if (ack.status === "accepted" || ack.status === "duplicate") {
618
+ askLedger?.recordAsk({
619
+ peer: targetAgentId,
620
+ correlationId: envelope.correlationId,
621
+ threadKey: envelope.threadId,
622
+ });
623
+ }
624
+ else {
625
+ const event = askLedger?.noteUnreachable({
626
+ peer: targetAgentId,
627
+ correlationId: envelope.correlationId,
628
+ threadKey: envelope.threadId,
629
+ reason: `提问未送达(回执 ${ack.status})`,
630
+ });
631
+ if (event)
632
+ recordAskOutcome(event, envelope);
633
+ }
634
+ }
635
+ return {
636
+ content: [{ type: "text", text: receiptText(ack) }],
637
+ details: { status: ack.status, id: ack.id, path: ack.path, target: targetAgentId },
638
+ };
639
+ },
640
+ });
641
+ pi.registerTool({
642
+ name: "list_peers",
643
+ label: "List Peers",
644
+ description: "列出本机可见的其它 agent 对端(名字 / agentId / 在场状态 / 心跳龄 / 能力标签 / 在途任务数 / 传输方式)," +
645
+ "可按名字、状态、能力过滤。**只读**:不产生任何对外行为。" +
646
+ "发消息前先查它(先查后发),别盲发 —— 离线对端现在打扰它不合适。",
647
+ parameters: listPeersParameters,
648
+ async execute(_toolCallId, params, _signal, _onUpdate, _ctx) {
649
+ // 只读 → 协作层没起来也能查(注册表是落盘事实源,`resolveAgentDir()` 与协作层同一目录)。
650
+ const registry = peerRegistry ?? new Registry({ agentDir: resolveAgentDir() });
651
+ // **同源**:与命令面 `/proactive peers --…` 共用 `queryPeerDirectory`(同一套过滤与字段)。
652
+ const { directory, text } = queryPeerDirectory({
653
+ registry,
654
+ selfAgentId: AGENT_ID,
655
+ inFlight: inFlightForPeer,
656
+ query: {
657
+ ...(params.name === undefined ? {} : { name: params.name }),
658
+ ...(params.status === undefined ? {} : { status: params.status }),
659
+ ...(params.capability === undefined ? {} : { capability: params.capability }),
660
+ ...(params.includeOffline === undefined ? {} : { includeOffline: params.includeOffline }),
661
+ },
662
+ });
663
+ return {
664
+ content: [{ type: "text", text }],
665
+ details: {
666
+ peers: directory.peers,
667
+ ambiguous: directory.ambiguous,
668
+ includeOffline: directory.includeOffline,
669
+ },
670
+ };
671
+ },
672
+ });
673
+ // ---- 模型工具面(NATURAL):4 个域工具,全部走**命令面同一个分派** ----
674
+ // 工具参数先拼成命令面同名的参数 → `dispatchProactiveCommand` → 与命令逐字同结果。
675
+ pi.registerTool({
676
+ name: "proactive_query",
677
+ label: "Proactive Query",
678
+ description: "查询域:查对端(peers)/ 看主动行为历史(history)/ 看状态(status)/ 看任务(tasks)/ 只读体检(doctor)/ 看命令手册(help)/ 查配置清单(config)。" +
679
+ "**只读**:不产生任何对外行为。",
680
+ parameters: proactiveQueryParameters,
681
+ async execute(_toolCallId, params, _signal, _onUpdate, _ctx) {
682
+ const parts = [params.action];
683
+ if (params.action === "peers") {
684
+ if (params.all === true)
685
+ parts.push("--all");
686
+ if (params.idle === true)
687
+ parts.push("--idle");
688
+ if (params.name !== undefined)
689
+ parts.push("--name", params.name);
690
+ if (params.detail !== undefined)
691
+ parts.push("--detail", params.detail);
692
+ }
693
+ else if (params.action === "history") {
694
+ if (params.scope !== undefined)
695
+ parts.push(params.scope);
696
+ if (params.peer !== undefined)
697
+ parts.push(params.peer);
698
+ // 只接受十进制整数(命令面的 history 也只认数字位置参数)。
699
+ if (params.limit !== undefined && /^\d+$/.test(params.limit))
700
+ parts.push(params.limit);
701
+ }
702
+ else if ((params.action === "doctor" || params.action === "config") && params.json === true) {
703
+ parts.push("--json");
704
+ }
705
+ return dispatchTool(parts.join(" "), { action: params.action });
706
+ },
707
+ });
708
+ pi.registerTool({
709
+ name: "progress_query",
710
+ label: "Progress Query",
711
+ description: "查项目进度与 ETA:返回**区间 + 置信度 + 归因 + 阻塞项**(不给单点数字)。" +
712
+ "口径唯一(scripts/progress-clock.py),与人侧 `/proactive progress` 同源同口径、逐字一致。" +
713
+ "**只读**:不产生任何对外行为。",
714
+ parameters: progressQueryParameters,
715
+ async execute(_toolCallId, _params, _signal, _onUpdate, _ctx) {
716
+ // **同源**:与人侧 `/proactive progress` 走同一个分派 → 同一份快照 → 逐字一致。
717
+ return dispatchTool("progress", { capability: "progress-eta" });
718
+ },
719
+ });
720
+ pi.registerTool({
721
+ name: "proactive_schedule",
722
+ label: "Proactive Schedule",
723
+ description: "排程域:定时(in)/ 定点(at)/ 周期(every)/ 取消(cancel)。" +
724
+ "落到真实任务表,到点由调度器投递;与命令面 `/proactive in|at|every|cancel` 同源。",
725
+ parameters: proactiveScheduleParameters,
726
+ async execute(_toolCallId, params, _signal, _onUpdate, _ctx) {
727
+ const parts = [params.action];
728
+ if (params.action === "cancel") {
729
+ if (params.id !== undefined)
730
+ parts.push(params.id);
731
+ }
732
+ else {
733
+ if (params.when !== undefined)
734
+ parts.push(params.when);
735
+ if (params.content !== undefined)
736
+ parts.push(params.content);
737
+ }
738
+ return dispatchTool(parts.join(" "), { action: params.action });
739
+ },
740
+ });
741
+ pi.registerTool({
742
+ name: "proactive_peer",
743
+ label: "Proactive Peer",
744
+ description: "对端协作域:给对端下指令(tell)/ 创建对端会话(spawn,受同时存活数上限)。" +
745
+ "tell 的目标解析与回执三态与命令面 `/proactive tell` 完全同源。",
746
+ parameters: proactivePeerParameters,
747
+ async execute(_toolCallId, params, _signal, _onUpdate, _ctx) {
748
+ const parts = [params.action];
749
+ if (params.action === "tell") {
750
+ if (params.peer !== undefined)
751
+ parts.push(params.peer);
752
+ if (params.kind !== undefined)
753
+ parts.push("--kind", params.kind);
754
+ if (params.subject !== undefined)
755
+ parts.push("--subject", params.subject);
756
+ if (params.thread !== undefined)
757
+ parts.push("--thread", params.thread);
758
+ if (params.content !== undefined)
759
+ parts.push(params.content);
760
+ }
761
+ else if (params.name !== undefined) {
762
+ parts.push(params.name);
763
+ }
764
+ return dispatchTool(parts.join(" "), { action: params.action });
765
+ },
766
+ });
767
+ pi.registerTool({
768
+ name: "proactive_manage",
769
+ label: "Proactive Manage",
770
+ description: "管理域:主动性总开关(on/off)、空闲触发开关(idle)、自检(test)。" +
771
+ "这些能力属 human-gated:调用只会回报「需人工确认」并给出可复制的人工指令,**不会**自行改动全局开关。",
772
+ parameters: proactiveManageParameters,
773
+ async execute(_toolCallId, params, _signal, _onUpdate, _ctx) {
774
+ return manageTool(params.action, params.state);
775
+ },
776
+ });
777
+ pi.registerCommand("proactive", {
778
+ description: `proactive 主动机制:${SUBCOMMANDS}`,
779
+ handler: async (args, cmdCtx) => {
780
+ const parts = (args ?? "").trim().split(/\s+/).filter(Boolean);
781
+ const sub = parts[0] ?? "status";
782
+ // 执行扩展命令 = 用户在终端上操作 → 刷新空闲基线
783
+ // (否则用户正在敲命令却被判为「已离开」并被主动打扰;V-02 Minor-1)。
784
+ try {
785
+ tracker.mark("user");
786
+ }
787
+ catch {
788
+ // ignore: 活动标记失败不得影响命令处理
789
+ }
790
+ // 命令面子命令 → **能力 id**(与 `docs/project/capability-catalog.json` 逐字一致)。
791
+ //
792
+ // 为什么需要这张表:能力是**语义**,命令/工具只是入口;这张表是「命令面 ↔ 能力目录」的
793
+ // 连接点(命令失败时日志点名是哪条能力坏了 → 可归因),门禁 G15 核对
794
+ // 「分派支持的子命令 ↔ 本表 ↔ 能力目录」三方一致(→ 目录与实现不会各说各话)。
795
+ const capabilityId = (() => {
796
+ switch (sub) {
797
+ case "status":
798
+ return "session-status";
799
+ case "on":
800
+ case "off":
801
+ return "global-toggle";
802
+ case "peers":
803
+ return "peer-directory";
804
+ case "spawn":
805
+ return "peer-spawn";
806
+ case "tell":
807
+ return "peer-message";
808
+ case "test":
809
+ return "self-test";
810
+ case "tasks":
811
+ return "task-list";
812
+ case "cancel":
813
+ return "task-cancel";
814
+ case "in":
815
+ case "at":
816
+ case "every":
817
+ return "task-schedule";
818
+ case "idle":
819
+ return "idle-trigger-toggle";
820
+ case "history":
821
+ return "activity-history";
822
+ case "doctor":
823
+ return "health-diagnose";
824
+ case "progress":
825
+ return "progress-eta";
826
+ case "help":
827
+ return "manual-help";
828
+ case "config":
829
+ return "config-inspect";
830
+ default:
831
+ return "unknown";
832
+ }
833
+ })();
834
+ try {
835
+ // **同一个分派**(NATURAL 同源硬要求):模型工具面也走这里 →
836
+ // 同一能力只有一份实现,命令与工具不可能漂移。
837
+ const out = await dispatchProactiveCommand(args, commandContext());
838
+ if (out.level === "error")
839
+ cmdCtx.ui.notify(out.text, "error");
840
+ else
841
+ cmdCtx.ui.notify(out.text);
842
+ }
843
+ catch (err) {
844
+ console.error(`[proactive] 命令失败(能力 ${capabilityId}):`, err);
845
+ cmdCtx.ui.notify(`proactive: ${errText(err)}`, "error");
846
+ }
847
+ },
848
+ });
849
+ // ---- 代理活动(IDLEFIX):模型回合 / 工具调用 → 刷新「最近任何活动」空闲基线 ----
850
+ //
851
+ // 空闲判定改用「距最近**任何**活动」的基线(见 `src/activity.ts`):
852
+ // 代理在干活时不能被当成「用户离开了」。
853
+ // 同一批事件还给出「代理是否已交回控制权」的独立信号(回合进行中 / 工具链未结束)。
854
+ pi.on("agent_start", () => {
855
+ agentRunActive = true;
856
+ markAgentActivity();
857
+ });
858
+ pi.on("agent_end", () => {
859
+ agentRunActive = false;
860
+ markAgentActivity();
861
+ // 回合结束 → 本回合不再算「由主动投递引发」(下一回合新建的任务不再绑定 triggeredBy)。
862
+ currentTurnSource = undefined;
863
+ });
864
+ pi.on("tool_execution_start", () => {
865
+ activeToolCount += 1;
866
+ markAgentActivity();
867
+ });
868
+ pi.on("tool_execution_end", () => {
869
+ activeToolCount = Math.max(0, activeToolCount - 1);
870
+ markAgentActivity();
871
+ });
872
+ // 模型回答回流(ask → reply 闭环):**逐条归因**(M5a)——
873
+ // 有 pending 才归因(无 pending → 丢弃,绝不把用户自己的回合当回答);
874
+ // 多个 pending 时归给最早未决并如实标注「歧义归因」。
875
+ pi.on("message_end", (event) => {
876
+ try {
877
+ // 代理活动(IDLEFIX):助手消息落定 = 代理刚干完活 → 刷新「最近任何活动」基线。
878
+ // (放在 peerResponder 早退之前:没有对端会话时也该记。)
879
+ if (messageRole(event.message) === "assistant") {
880
+ markAgentActivity();
881
+ // **结果记账(果)**:模型在窗口内产生新消息 → 这次主动推进「被采纳」。
882
+ try {
883
+ currentLineage?.noteResponse("model");
884
+ }
885
+ catch (err) {
886
+ console.error("[proactive] 记事件流失败:", err);
887
+ }
888
+ }
889
+ const responder = peerResponder;
890
+ if (!responder)
891
+ return;
892
+ // **用户发言**(Major-3):提问登记之后用户又说了话 → 这之后的回答**无法判别**
893
+ // 是在回答对端还是在回答用户 → 归因必须标为歧义(不得当作确定答案回过去)。
894
+ if (messageRole(event.message) === "user") {
895
+ if (!isInjectedPeerMessage(event.message)) {
896
+ // 正文里带注入标记串 → 用户可能**原样复制**了注入正文(R-2):
897
+ // 无法区分「自注入的回显」与「用户复制」→ **宁可多标歧义**,也不漏标。
898
+ if (containsInjectionMarker(event.message)) {
899
+ console.error("[proactive] 用户消息里含注入标记串(疑似原样复制了注入正文)→ 按「用户发言」处理(宁可多标歧义)");
900
+ }
901
+ responder.noteUserInput(Date.now());
902
+ }
903
+ return;
904
+ }
905
+ const text = extractAssistantText(event.message);
906
+ if (!text)
907
+ return;
908
+ const plan = responder.onAssistantText(text);
909
+ if (!plan)
910
+ return;
911
+ void sendPeerReply(plan);
912
+ }
913
+ catch (err) {
914
+ console.error("[proactive] 处理 message_end 失败:", err);
915
+ }
916
+ });
917
+ // 空闲基线(IDLEFIX):真人输入刷新**用户基线**与「最近任何活动」基线;
918
+ // 代理活动(回合/工具调用,见上)只刷新「最近任何活动」基线;
919
+ // **扩展注入的消息(含本插件自己的投递)不刷新任何基线** —— 防自锁。
920
+ pi.on("input", (event) => {
921
+ try {
922
+ // 用户在终端里说话 → 之后的回答归因存疑(Major-3)。
923
+ // **只认真人输入**:`source === "extension"` 是扩展自己注入的消息(本插件注入的
924
+ // peer 提问就走这条路)→ 不得当成「用户发言」,否则每条回信都会被误标为歧义。
925
+ const source = event?.source;
926
+ if (source === "extension") {
927
+ // **扩展注入的消息不是用户输入**(IDLEFIX):
928
+ // 既不刷新用户基线,也不刷新「最近任何活动」基线 ——
929
+ // 否则插件会被**自己的投递**无限推迟下一次触发(自锁)。
930
+ // `mark("self")` 语义 = 「插件自投递」→ 两个基线都不刷新。
931
+ tracker.mark("self");
932
+ // **这是我们注入的消息**(宿主把自定义消息转成了 role:"user")→
933
+ // 认领它的标记串 → 随后出现的同文本消息 = 我们的回声(不得当成用户发言);
934
+ // 用户**原样复制**同一段文本时标记串已被一次性消费 → 判为「用户发言」(R-2)。
935
+ claimInjectionMarker(event?.text);
936
+ }
937
+ else {
938
+ // 真人输入 → 刷新用户基线与「最近任何活动」基线。
939
+ tracker.mark("user");
940
+ peerResponder?.noteUserInput(Date.now());
941
+ // **结果记账(果)**:真人输入(不是扩展注入)→ 用户对这次主动推进有回应。
942
+ try {
943
+ currentLineage?.noteResponse("user");
944
+ }
945
+ catch (err) {
946
+ console.error("[proactive] 记事件流失败:", err);
947
+ }
948
+ }
949
+ }
950
+ catch {
951
+ // ignore: activity tracking must never break input handling
952
+ }
953
+ });
954
+ pi.on("session_start", async (_event, ctx) => {
955
+ try {
956
+ // pi/ctx go stale after session replacement or reload -> re-capture them here.
957
+ currentPi = pi;
958
+ currentCtx = ctx;
959
+ config = safeConfig();
960
+ // 「代理是否已交回控制权」= 宿主忙闲 **或** 我们自己的回合/工具链计数。
961
+ // 宿主 `ctx.isIdle()`(本机 pi 1.3.0)覆盖整个 agent run(含工具执行),
962
+ // 我们再叠一层自己的计数 → 宿主语义变窄时长工具链仍不会漏判。
963
+ agentRunActive = false;
964
+ activeToolCount = 0;
965
+ tracker = new ActivityTracker({
966
+ idleDetect: config.idleDetect,
967
+ isBusy: () => !ctx.isIdle() || agentRunActive || activeToolCount > 0,
968
+ });
969
+ guard = new Guard(config);
970
+ currentSessionId = resolveSessionId(ctx);
971
+ if (currentSessionId === undefined) {
972
+ console.error("[proactive] 宿主未提供 sessionId → session 作用域任务退回按进程归属兜底");
973
+ }
974
+ // agentId 按**会话**派生(跨进程重启稳定)——必须在此处(拿到 sessionId 之后)重算。
975
+ AGENT_ID = resolveAgentId(process.env, process.pid, currentSessionId);
976
+ // 统一事件流(血缘):per-agent 只追加 JSONL(<agentDir>/proactive/lineage/<agentId>.jsonl)。
977
+ currentLineage = new Lineage({ agentDir: resolveAgentDir(), agentId: AGENT_ID });
978
+ currentTurnSource = undefined;
979
+ currentTrigger = new Trigger({
980
+ pi,
981
+ ctx,
982
+ guard,
983
+ config,
984
+ agentId: AGENT_ID,
985
+ lineage: currentLineage,
986
+ // 投递成功 → 记住这次投递(派生任务据此绑定 triggeredBy)。
987
+ onDelivered: (info) => {
988
+ currentTurnSource = info;
989
+ },
990
+ });
991
+ currentStore = new TaskStore({
992
+ agentDir: resolveAgentDir(),
993
+ agentId: AGENT_ID,
994
+ // P-D5:未知版本等「用户必须知道」的事件 → **用户可见通道**(宿主 ui.notify),
995
+ // 不能只在 stderr 打一行(宿主通常不展示 stderr → 用户的排期静默停止而无人知晓)。
996
+ notify: (message) => {
997
+ try {
998
+ ctx.ui.notify(message, "error");
999
+ }
1000
+ catch {
1001
+ // 用户可见通道不可用 → 提示已留在 store 的降级队列(stderr 亦有一份)
1002
+ }
1003
+ },
1004
+ });
1005
+ // 本机 GC(启动一次):残留 tmp(P-D2)+ 失效的 global 任务认领(P-D9)。
1006
+ lastGcAt = Date.now();
1007
+ runGc(resolveAgentDir(), currentStore);
1008
+ // 调度由本文件的唯一 tick 驱动(scheduler.tick()),**不**再起第二个定时器。
1009
+ currentScheduler = new Scheduler({
1010
+ store: currentStore,
1011
+ // **触发原因落盘(因)**:排期投递的 cause = schedule + 任务依据。
1012
+ trigger: withTriggerCause(currentTrigger, "schedule", (msg) => scheduleBasis(msg.id)),
1013
+ guard,
1014
+ agentId: AGENT_ID,
1015
+ // session 作用域归属按**会话**(跨进程重启稳定),不再按进程(pid)。
1016
+ sessionId: currentSessionId,
1017
+ // 主动性总开关贯穿调度器:enabled=false 时不投递任何到期任务(V-02 Major-1)。
1018
+ enabled: () => config.enabled,
1019
+ });
1020
+ // A:空闲检测档位(非 TUI 降级为 input-only);只有 terminal 档才订阅终端输入。
1021
+ const detect = effectiveIdleDetect(config.idleDetect, ctx.mode);
1022
+ tracker.setIdleDetect(detect);
1023
+ if (detect === "terminal") {
1024
+ tracker.attachTerminalInput(ctx.ui.onTerminalInput(() => {
1025
+ tracker.handleTerminalInput();
1026
+ return undefined;
1027
+ }));
1028
+ }
1029
+ // 跨进程协作层(注册表 + socket 通道 + 邮箱 + 心跳);失败不阻断会话。
1030
+ await stopPeerLayer();
1031
+ await startPeerLayer(resolveAgentDir());
1032
+ // P-D7:协作层就绪后再跑一次 GC —— 注册表条目清理与归档清理需要它们存在。
1033
+ lastGcAt = Date.now();
1034
+ runGc(resolveAgentDir(), currentStore);
1035
+ stopTick();
1036
+ tickTimer = setInterval(() => {
1037
+ void tick();
1038
+ }, TICK_MS);
1039
+ void tick();
1040
+ }
1041
+ catch (err) {
1042
+ console.error("[proactive] session_start 失败:", err);
1043
+ }
1044
+ });
1045
+ pi.on("session_shutdown", async () => {
1046
+ try {
1047
+ stopTick();
1048
+ agentRunActive = false;
1049
+ activeToolCount = 0;
1050
+ // **drain**(优雅退出前把在途 ask 逐条回「我下线了」)—— 必须在关通道之前。
1051
+ await drainPeerLayer();
1052
+ await stopPeerLayer();
1053
+ // **不留孤儿**:被创建的对端会话逐个终止并等待退出。
1054
+ const stopped = await shutdownSpawnedPeers();
1055
+ if (stopped > 0)
1056
+ console.error(`[proactive] 已终止 ${stopped} 个被创建的对端进程(不留孤儿)`);
1057
+ currentScheduler?.stop();
1058
+ currentScheduler = undefined;
1059
+ currentTrigger = undefined;
1060
+ currentLineage = undefined;
1061
+ currentTurnSource = undefined;
1062
+ currentStore = undefined;
1063
+ currentSessionId = undefined;
1064
+ // 退订终端输入(setIdleDetect("off") 会解除订阅)。
1065
+ tracker.setIdleDetect("off");
1066
+ currentCtx?.ui.setStatus(STATUS_KEY, undefined);
1067
+ currentCtx = undefined;
1068
+ currentPi = undefined;
1069
+ }
1070
+ catch (err) {
1071
+ console.error("[proactive] session_shutdown 失败:", err);
1072
+ }
1073
+ });
1074
+ }
1075
+ /**
1076
+ * 唯一 tick:调度 + 空闲判定/触发。
1077
+ *
1078
+ * 异常整体隔离(宿主对未捕获异常直接 `process.exit(1)`)。
1079
+ */
1080
+ async function tick() {
1081
+ try {
1082
+ const ctx = currentCtx;
1083
+ if (!ctx)
1084
+ return;
1085
+ // 主动性总开关关闭(/proactive off)→ 定时投递与空闲触发**均不发生**(V-02 Major-1)。
1086
+ const enabled = config.enabled;
1087
+ // 本机 GC(启动 + 每 1 小时,规范 §6 阈值表):残留 tmp(P-D2)+ 失效任务认领(P-D9)。
1088
+ const gcNow = Date.now();
1089
+ if (gcNow - lastGcAt >= GC_INTERVAL_MS) {
1090
+ lastGcAt = gcNow;
1091
+ runGc(resolveAgentDir(), currentStore);
1092
+ }
1093
+ // 调度(到期任务投递)—— 调度器内部自带异常隔离。
1094
+ if (enabled)
1095
+ await currentScheduler?.tick();
1096
+ // 结算判定窗口(到窗口末仍无回应 → outcome=ignored;判定只由事件流里的时间事实推出)。
1097
+ try {
1098
+ currentLineage?.sweep(Date.now());
1099
+ }
1100
+ catch (err) {
1101
+ console.error("[proactive] 结算判定窗口失败:", err);
1102
+ }
1103
+ // 入站邮箱扫描:**后台**执行(不 await)—— 扫描 + 投递是重活,不得阻塞 1s tick。
1104
+ void runPeerScan();
1105
+ // 空闲触发:一次未完成时不再发起下一次(否则 askUser 弹窗会叠加)。
1106
+ const trigger = currentTrigger;
1107
+ if (enabled && trigger && idleFirePending === undefined) {
1108
+ idleFirePending = fireIdle({
1109
+ config,
1110
+ tracker,
1111
+ guard,
1112
+ // **决策落账**:每次决策(含不触发)都进事件流 → `/proactive history` 可见。
1113
+ lineage: currentLineage,
1114
+ // **触发原因落盘(因)**:空闲投递的 cause = idle + 判定依据(已空闲时长 / 阈值 / 档位)。
1115
+ // 用上面已收窄的局部 `trigger`(`currentTrigger` 是可变模块变量,TS 无法在此收窄)
1116
+ trigger: withTriggerCause(trigger, "idle", () => idleBasis()),
1117
+ agentId: AGENT_ID,
1118
+ runtimeMode: ctx.mode,
1119
+ })
1120
+ .then((result) => {
1121
+ // 用**最终** outcome 更新状态栏。
1122
+ setStatus(ctx, result.decision);
1123
+ })
1124
+ .catch((err) => {
1125
+ console.error("[proactive] fireIdle 失败:", err);
1126
+ })
1127
+ .finally(() => {
1128
+ idleFirePending = undefined;
1129
+ });
1130
+ }
1131
+ // 未触发时用判定原因填状态栏。
1132
+ setStatus(ctx, evaluateIdle({ config, tracker, guard, runtimeMode: ctx.mode }));
1133
+ }
1134
+ catch (err) {
1135
+ console.error("[proactive] tick 失败:", err);
1136
+ }
1137
+ }
1138
+ /** 写状态栏(失败不得冒泡)。 */
1139
+ function setStatus(ctx, decision) {
1140
+ try {
1141
+ const text = `proactive ${config.enabled ? "on" : "off"} · ${formatIdleDecision(decision)}`;
1142
+ // 关键状态变化(开关 / 判定原因)立即更新;否则节流到 ≥5s 一次
1143
+ // (V-02 Minor-3:每秒一条 setStatus 打到 stdout 是噪声)。
1144
+ const key = `${config.enabled}|${decision.reason}`;
1145
+ const now = Date.now();
1146
+ if (key === lastStatusKey && now - lastStatusAt < STATUS_THROTTLE_MS)
1147
+ return;
1148
+ lastStatusKey = key;
1149
+ lastStatusAt = now;
1150
+ ctx.ui.setStatus(STATUS_KEY, text);
1151
+ }
1152
+ catch {
1153
+ // ignore: 状态栏失败不得让宿主崩溃
1154
+ }
1155
+ }
1156
+ /**
1157
+ * `/proactive test`:强制投递一次自检消息。
1158
+ *
1159
+ * 强制语义:不看 `config.enabled`(`/proactive off` 之后也要能自检),也不受冷却/频率上限阻塞
1160
+ * (用一份宽松的护栏配置另建 Trigger;静默时段仍然尊重)。
1161
+ */
1162
+ async function runSelfTest() {
1163
+ if (!currentPi || !currentCtx || !currentTrigger) {
1164
+ return { text: "proactive: session_start 尚未触发,无法投递", level: "error" };
1165
+ }
1166
+ const forcedConfig = {
1167
+ ...config,
1168
+ limits: { ...config.limits, minGapMs: 0, maxPerHour: 1000 },
1169
+ };
1170
+ const forced = new Trigger({
1171
+ pi: currentPi,
1172
+ ctx: currentCtx,
1173
+ guard: new Guard(forcedConfig),
1174
+ config: forcedConfig,
1175
+ agentId: AGENT_ID,
1176
+ lineage: currentLineage,
1177
+ });
1178
+ const envelope = {
1179
+ id: randomUUID(),
1180
+ from: AGENT_ID,
1181
+ to: AGENT_ID,
1182
+ kind: "notify",
1183
+ intent: "wake",
1184
+ subject: "proactive test",
1185
+ body: "自检消息:投递链路测试",
1186
+ hop: 0,
1187
+ maxHops: 3,
1188
+ ttlMs: 60_000,
1189
+ priority: "normal",
1190
+ createdAt: Date.now(),
1191
+ };
1192
+ const outcome = await forced.deliverToModel(envelope, "wake", { cause: { type: "manual" } });
1193
+ return { text: `proactive: ${testOutcomeText(outcome)}`, level: "info" };
1194
+ }
1195
+ /** 自检结果文案(依据 Trigger 的最终 outcome)。 */
1196
+ function testOutcomeText(outcome) {
1197
+ switch (outcome) {
1198
+ case "delivered":
1199
+ return "已强制投递一次测试消息(intent=wake;强制投递:不受 /proactive on/off 开关与冷却/频率上限影响)";
1200
+ case "notified":
1201
+ return "已强制通知一次测试消息(未启动模型回合;强制投递:不受 /proactive on/off 开关与冷却/频率上限影响)";
1202
+ case "deferred":
1203
+ return "测试消息被护栏推迟(静默时段)——本次未投递";
1204
+ case "dropped":
1205
+ return "测试消息被护栏丢弃(超出频率上限)——本次未投递";
1206
+ default:
1207
+ return "测试消息投递失败(详见插件日志)";
1208
+ }
1209
+ }
1210
+ // ================================================================ 跨进程协作(M4i)
1211
+ /**
1212
+ * 启动跨进程协作层:注册表 + socket 通道 + 文件邮箱 + 心跳。
1213
+ *
1214
+ * - **单一 SeenSet**:socket 通道与邮箱**共用同一个**去重集合
1215
+ * (`processed/<agentId>/seen.json`)→ 同一 id 经两条路径到达也只处理一次;
1216
+ * - socket 端点被占用(另一个进程还在)→ 记日志并降级为「文件邮箱」传输,不阻断会话;
1217
+ * - 所有异常都在内部隔离(宿主 uncaughtException → process.exit(1))。
1218
+ */
1219
+ async function startPeerLayer(agentDir) {
1220
+ try {
1221
+ const seen = new SeenSet({ agentDir, agentId: AGENT_ID });
1222
+ peerRegistry = new Registry({ agentDir });
1223
+ // **P0 权限收紧(启动时一次)**:既有落盘面(目录 0700 / 文件 0600)在此收紧 ——
1224
+ // umask 只削弱、**既有文件不会自动改** → 必须显式 chmod。失败**不静默**(逐条上报)。
1225
+ try {
1226
+ const hardened = hardenProactivePermissions(agentDir);
1227
+ if (hardened.failures.length > 0) {
1228
+ console.error(`[proactive] 落盘面权限收紧失败 ${hardened.failures.length} 项(见上方逐条报错)—— 落盘面仍可能对同 UID 其它进程可见`);
1229
+ }
1230
+ }
1231
+ catch (err) {
1232
+ console.error("[proactive] 落盘面权限收紧异常(不静默):", err);
1233
+ }
1234
+ peerRegistry.register({
1235
+ agentId: AGENT_ID,
1236
+ name: resolveAgentName(),
1237
+ pid: process.pid,
1238
+ host: os.hostname(),
1239
+ cwd: process.cwd(),
1240
+ sessionId: currentSessionId,
1241
+ capabilities: ["message_agent"],
1242
+ transport: "socket",
1243
+ });
1244
+ // **P1 来源校验(默认严格、不可关闭、不可放宽)**:`from` 不可自填即采信 ——
1245
+ // 未在注册表登记 / 主机不符的发送方 → 拒收(不投递)+ 可审计归档。
1246
+ // **strict 档**(具名 `createStrictSenderPolicy()`):注册表白名单 + 主机一致 —— 产品层不可关闭、
1247
+ // 不可放宽。旧名 `createRegistrySenderPolicy()` 是**同一个函数的别名**(协议正文 §8.1 证据 2
1248
+ // 的实现位置指针指向本文件里的这个名字)→ 别名与具名档必须保持同一语义。
1249
+ const senderPolicy = createStrictSenderPolicy({ agentDir, registry: peerRegistry });
1250
+ peerMailbox = new Mailbox({ agentDir, agentId: AGENT_ID, seen, senderPolicy });
1251
+ // 姿态可见:启动时明确告知「来源校验已启用」(用户/运维可据此判断部署是否受保护)。
1252
+ console.error("[proactive] 来源校验:已启用(注册表逐字命中 + 主机一致)—— 未注册或跨主机的发送方一律拒收");
1253
+ // 逐条 reply 归因器(入站 ask 登记 pending → 模型回答归因 → 回信)。
1254
+ peerResponder = new PeerResponder({ agentId: AGENT_ID, expectReplyWithinMs: PEER_ANSWER_TIMEOUT_MS });
1255
+ // 提问方的 ask 账本(ASKLOOP):已问 / 已答 / 未答 / 不可达 + 停止追问的状态机。
1256
+ askLedger = new AskLedger({ waitMs: PEER_ANSWER_TIMEOUT_MS });
1257
+ // peer watch(跨会话空闲协作):默认关闭(不装上就不打扰别人)。
1258
+ // **作用域**(KK-10):配置是全局共享的 → 每个会话都 watch 对方 → 问询量 O(N²)。
1259
+ // 两个**随会话**的旋钮把问询量降回 O(实际配对数):
1260
+ // ① `PI_PROACTIVE_ROLE=worker` → 本会话**只被 watch、不主动问**(执行者);
1261
+ // ② `PI_PROACTIVE_WATCH_PEERS=<agentId,...>` → 本会话**只问名单里的对端**(协调者)。
1262
+ // 两者都缺省 = 保持既有行为(由 `enabled` + `afterIdleMs` 决定)。
1263
+ peerWatch = new PeerWatch({
1264
+ enabled: config.peerWatch.enabled,
1265
+ afterIdleMs: config.peerWatch.afterIdleMs,
1266
+ selfAgentId: AGENT_ID,
1267
+ role: resolvePeerRole(),
1268
+ watchList: resolveWatchList(),
1269
+ });
1270
+ // peer 生命周期状态机(创建 / 死亡 / 墓碑)。
1271
+ peerLifecycle = new PeerLifecycle();
1272
+ threadStores.clear();
1273
+ peerSocketStarting = startSocketServer({
1274
+ agentId: AGENT_ID,
1275
+ agentDir,
1276
+ seen,
1277
+ // **P1 来源校验**(与邮箱路径同一策略、同一口径)。
1278
+ senderPolicy,
1279
+ // onMessage 只回 void/Promise<void>:投递结果由内部处理,ack 不承担业务语义。
1280
+ onMessage: async (envelope) => {
1281
+ const outcome = await deliverPeerEnvelope(envelope);
1282
+ if (outcome === "deferred" || outcome === "dropped" || outcome === "failed") {
1283
+ // **未投递 → 绝不回 accepted(谎报「已送达」)**(Blocker-1):
1284
+ // ① 先落盘到本机收件箱(**不丢消息** → 之后由邮箱扫描重试);
1285
+ // ② 再抛错 → socket 回执如实变成 error(对端据此知道「尚未送达」)。
1286
+ const file = writeToMailbox(AGENT_ID, envelope, { agentDir });
1287
+ throw new Error(`入站消息未投递(${outcome}),已落盘待重试:${file}`);
1288
+ }
1289
+ },
1290
+ })
1291
+ .then((handle) => {
1292
+ peerSocket = handle;
1293
+ // P-D11:socket 端点 0600、端点目录 0700(规范 P0:同机其它进程不该接入)。
1294
+ try {
1295
+ ensureDir(path.dirname(handle.path));
1296
+ chmodQuiet(handle.path, PROACTIVE_FILE_MODE);
1297
+ }
1298
+ catch {
1299
+ // 权限收紧失败不阻断通道
1300
+ }
1301
+ return handle;
1302
+ })
1303
+ .catch((err) => {
1304
+ console.error("[proactive] socket 通道启动失败(降级为文件邮箱):", err);
1305
+ // 传输方式如实改写:在线通道不可用 → 只剩文件邮箱。
1306
+ try {
1307
+ peerRegistry?.register({
1308
+ agentId: AGENT_ID,
1309
+ name: resolveAgentName(),
1310
+ pid: process.pid,
1311
+ host: os.hostname(),
1312
+ cwd: process.cwd(),
1313
+ sessionId: currentSessionId,
1314
+ capabilities: ["message_agent"],
1315
+ transport: "file",
1316
+ });
1317
+ }
1318
+ catch {
1319
+ // 忽略:注册失败不影响会话
1320
+ }
1321
+ return undefined;
1322
+ });
1323
+ heartbeatTimer = setInterval(() => {
1324
+ try {
1325
+ peerRegistry?.heartbeat(AGENT_ID, {
1326
+ status: currentCtx?.isIdle() ? "idle" : "busy",
1327
+ });
1328
+ }
1329
+ catch (err) {
1330
+ console.error("[proactive] 心跳失败:", err);
1331
+ }
1332
+ try {
1333
+ // ASKLOOP:未获回答的 ask 超时 → 结局 unanswered(并推进停止追问的状态机)。
1334
+ for (const event of askLedger?.expire(Date.now()) ?? []) {
1335
+ recordAskOutcome(event);
1336
+ }
1337
+ }
1338
+ catch (err) {
1339
+ console.error("[proactive] ask 账本超时扫描失败:", err);
1340
+ }
1341
+ try {
1342
+ // **死亡检测**:对端心跳过期(= 崩溃)→ 在途 ask **立即**回执「对端已死亡」
1343
+ // (结局记 `unreachable`)→ **不再追问**该对端 → 注册表写下**墓碑**
1344
+ // (下线时间 + 原因;条目保留,清理仍走既有 GC 阈值)。
1345
+ detectDeadPeers();
1346
+ }
1347
+ catch (err) {
1348
+ console.error("[proactive] 死亡检测失败:", err);
1349
+ }
1350
+ try {
1351
+ // 过期 pending(Major-2):过期 ≠ 丢弃 —— 通知请求方(过期必须可见),
1352
+ // 且过期项被保留 → 迟到的回答仍会回信。
1353
+ void expirePeerPending()
1354
+ .then((n) => {
1355
+ if (n > 0)
1356
+ console.error(`[proactive] ${n} 条 pending 已过期(已通知请求方;迟到回答仍会回信)`);
1357
+ })
1358
+ .catch((err) => {
1359
+ console.error("[proactive] 清理过期 pending 失败:", err);
1360
+ });
1361
+ }
1362
+ catch (err) {
1363
+ console.error("[proactive] 清理过期 pending 失败:", err);
1364
+ }
1365
+ // peer watch(跨会话空闲协作):与心跳同周期(30s),不新增定时器。
1366
+ const now = Date.now();
1367
+ if (now - lastPeerWatchAt >= PEER_WATCH_INTERVAL_MS) {
1368
+ lastPeerWatchAt = now;
1369
+ void runPeerWatch();
1370
+ }
1371
+ }, HEARTBEAT_MS);
1372
+ }
1373
+ catch (err) {
1374
+ console.error("[proactive] 跨进程协作层启动失败:", err);
1375
+ }
1376
+ }
1377
+ /**
1378
+ * **死亡检测**:对端心跳过期(= 崩溃,没走到 `unregister()`)→
1379
+ * ① 注册表写下**墓碑**(下线时间 + 原因;条目**保留** → 离线寻址成立,
1380
+ * 清理仍走既有 GC 阈值 `sweepStaleEntries()`,**不造第二套保留策略**);
1381
+ * ② 在途 ask **立即**回执「对端已死亡」(AskLedger 记 `unreachable`);
1382
+ * ③ **不再追问**该对端(账本状态 → `stopped`,直到它重新开始工作)。
1383
+ */
1384
+ function detectDeadPeers() {
1385
+ const registry = peerRegistry;
1386
+ if (registry === undefined)
1387
+ return;
1388
+ const candidates = new Set();
1389
+ for (const entry of peerLifecycle?.list() ?? [])
1390
+ candidates.add(entry.agentId);
1391
+ for (const peer of askLedger?.outstandingPeers() ?? [])
1392
+ candidates.add(peer);
1393
+ if (candidates.size === 0)
1394
+ return;
1395
+ for (const entry of peerLifecycle?.detectDead(registry, [...candidates]) ?? []) {
1396
+ const reason = entry.offlineReason ?? "心跳过期(可能崩溃)";
1397
+ try {
1398
+ registry.markDead(entry.agentId, reason, entry.offlineAt);
1399
+ }
1400
+ catch (err) {
1401
+ console.error("[proactive] 写墓碑失败:", err);
1402
+ }
1403
+ const events = askLedger?.notePeerDead(entry.agentId, { reason: `对端已死亡(${reason})` }) ?? [];
1404
+ for (const event of events)
1405
+ recordAskOutcome(event);
1406
+ console.error(`[proactive] 对端已死亡 ${entry.agentId}:${reason}` +
1407
+ `${events.length > 0 ? `(${events.length} 条在途提问已记 unreachable,不再追问)` : ""}`);
1408
+ }
1409
+ }
1410
+ /**
1411
+ * **drain**:优雅退出前把在途 ask **逐条**回「我下线了」。
1412
+ *
1413
+ * 两条腿:
1414
+ * 1. **我欠答的 ask**(别人问我、我还没答)→ 给提问方回一条带 `PEER_OFFLINE_MARKER`
1415
+ * 的回信 → 提问方据此记 `unreachable`(对方下线 ≠ 得到答案)。
1416
+ * 2. **我发出的、还在等的 ask** → 结局记 `unreachable`(本会话下线 → 这条提问不会有答案了)。
1417
+ *
1418
+ * 必须在**关闭 socket 之前**做(回信要靠通道投递出去)。
1419
+ */
1420
+ async function drainPeerLayer() {
1421
+ try {
1422
+ const pending = peerResponder?.pendingList() ?? [];
1423
+ for (const reply of buildDrainReplies(pending, AGENT_ID)) {
1424
+ try {
1425
+ const ack = await deliverToPeer(reply.to, reply);
1426
+ console.error(`[proactive] drain:已回「我下线了」给 ${reply.to}(回执 ${ack.status})`);
1427
+ }
1428
+ catch (err) {
1429
+ console.error(`[proactive] drain:回「我下线了」给 ${reply.to} 失败:`, err);
1430
+ }
1431
+ }
1432
+ }
1433
+ catch (err) {
1434
+ console.error("[proactive] drain(回在途 ask)失败:", err);
1435
+ }
1436
+ try {
1437
+ for (const peer of askLedger?.outstandingPeers() ?? []) {
1438
+ for (const event of askLedger?.notePeerDead(peer, { reason: "本会话下线(提问未得到回答)" }) ?? []) {
1439
+ recordAskOutcome(event);
1440
+ }
1441
+ }
1442
+ }
1443
+ catch (err) {
1444
+ console.error("[proactive] drain(结清在途提问)失败:", err);
1445
+ }
1446
+ }
1447
+ /**
1448
+ * 停止跨进程协作层(幂等):注销 + 关 socket + 停心跳 + 释放等待者。
1449
+ *
1450
+ * **必须 await**:socket 端点文件在 close 之后才会消失 —— 不等它关闭就重新 startPeerLayer
1451
+ * 会撞上「端点已被占用」(同一 agentId → 同一端点路径)→ 会话重启后跨进程通道静默降级。
1452
+ */
1453
+ async function stopPeerLayer() {
1454
+ if (heartbeatTimer !== undefined) {
1455
+ clearInterval(heartbeatTimer);
1456
+ heartbeatTimer = undefined;
1457
+ }
1458
+ try {
1459
+ // 优雅退出:**保留**注册条目并标 status:"offline"(不删除)——
1460
+ // 删了对端再发消息就变成「未找到 agent」→ 离线排队失效(V-03 F1)。
1461
+ peerRegistry?.unregister(AGENT_ID);
1462
+ }
1463
+ catch (err) {
1464
+ console.error("[proactive] 注销失败:", err);
1465
+ }
1466
+ // socket 启动是异步的:等它落地再关(否则会漏掉句柄 → 端点文件与 fd 残留)。
1467
+ const starting = peerSocketStarting;
1468
+ peerSocketStarting = undefined;
1469
+ const handle = peerSocket;
1470
+ peerSocket = undefined;
1471
+ try {
1472
+ const h = handle ?? (await starting);
1473
+ await h?.close();
1474
+ // 启动 promise 的 then 回调可能又把旧句柄写回 peerSocket → 这里清干净。
1475
+ if (peerSocket === h)
1476
+ peerSocket = undefined;
1477
+ }
1478
+ catch (err) {
1479
+ console.error("[proactive] 关闭 socket 通道失败:", err);
1480
+ }
1481
+ peerResponder = undefined;
1482
+ askLedger = undefined;
1483
+ peerWatch = undefined;
1484
+ peerLifecycle = undefined;
1485
+ peerMailbox = undefined;
1486
+ peerRegistry = undefined;
1487
+ }
1488
+ /**
1489
+ * 记一条 ask 的**结局**(ASKLOOP · 规范 §6.5)。
1490
+ *
1491
+ * 落点:**与统一事件流同一套**——
1492
+ * - 线程日志(既有落盘面,不是新面):`type:"outcome"` + `cause`/`outcome`/`peer`/`elapsedMs`;
1493
+ * - 转录审计(`appendEntry`):人侧可见;
1494
+ * - stderr 一行:日志里可查。
1495
+ *
1496
+ * 字段名与统一事件流同族(`at`≈`ts`、`type`、`cause`、相关 id)→ 统一事件流落地后
1497
+ * 同一套读方即可消费,**不需要另造第二个面**。
1498
+ */
1499
+ export function recordAskOutcome(event, env) {
1500
+ try {
1501
+ if (env !== undefined) {
1502
+ const threadKey = event.threadId ?? threadKeyOf(env);
1503
+ threadStoreFor(env, threadKey).append({
1504
+ type: "outcome",
1505
+ at: event.at,
1506
+ cause: event.cause,
1507
+ outcome: event.outcome,
1508
+ correlationId: event.correlationId,
1509
+ peer: event.peer,
1510
+ elapsedMs: event.elapsedMs,
1511
+ ...(event.reason === undefined ? {} : { text: event.reason }),
1512
+ });
1513
+ }
1514
+ currentPi?.appendEntry(PEER_CUSTOM_TYPE, {
1515
+ stage: "outcome",
1516
+ outcome: event.outcome,
1517
+ cause: event.cause,
1518
+ correlationId: event.correlationId,
1519
+ peer: event.peer,
1520
+ elapsedMs: event.elapsedMs,
1521
+ ...(event.reason === undefined ? {} : { reason: event.reason }),
1522
+ agentId: AGENT_ID,
1523
+ at: event.at,
1524
+ });
1525
+ console.error(`[proactive] ask 结局 ${event.outcome}(对端 ${event.peer},耗时 ${event.elapsedMs}ms)${event.reason === undefined ? "" : `:${event.reason}`}`);
1526
+ }
1527
+ catch (err) {
1528
+ console.error("[proactive] 记录 ask 结局失败:", err);
1529
+ }
1530
+ }
1531
+ /**
1532
+ * 过期 pending 的处理(Major-2)。
1533
+ *
1534
+ * - 过期**不等于丢弃**:请求方必须收到一条「等待超时」通知 —— 否则闭环静默断裂、请求方零信号;
1535
+ * - 迟到的回答**仍会回信**(`PeerResponder` 保留过期 pending → 正文标注「已超过等待时限」)。
1536
+ *
1537
+ * @param now 时钟(测试可注入未来时刻;缺省 = 真实时间)。
1538
+ * @returns 本次过期的条数。
1539
+ */
1540
+ export async function expirePeerPending(now) {
1541
+ const responder = peerResponder;
1542
+ if (!responder)
1543
+ return 0;
1544
+ const expired = responder.expireStale(now);
1545
+ for (const pending of expired) {
1546
+ const minutes = Math.round(PEER_ANSWER_TIMEOUT_MS / 60_000);
1547
+ const notice = createEnvelope({
1548
+ from: AGENT_ID,
1549
+ to: pending.requester,
1550
+ kind: "reply",
1551
+ intent: "queue",
1552
+ subject: pending.subject ? `Re: ${pending.subject}` : undefined,
1553
+ body: `${TIMEOUT_NOTICE_MARKER}本机未在 ${minutes} 分钟内回答该提问(提问已过等待上界)。若稍后仍会回答,将另行回信。`,
1554
+ threadId: pending.threadId,
1555
+ correlationId: pending.correlationId,
1556
+ });
1557
+ // 线程记一条 note(**不**计入轮次 —— 它不是回答)。
1558
+ const threadKey = pendingThreadKeys.get(pendingKeyOf(pending));
1559
+ if (threadKey)
1560
+ appendThreadEvent(notice, "note", notice.body, threadKey);
1561
+ try {
1562
+ const ack = await deliverToPeer(pending.requester, notice);
1563
+ console.error(`[proactive] 提问等待超时(${pending.requester}):${describeAck(ack.status, ack.error ?? ack.path, ack.queuedReason)}`);
1564
+ }
1565
+ catch (err) {
1566
+ console.error("[proactive] 发送等待超时通知失败:", err);
1567
+ }
1568
+ }
1569
+ return expired.length;
1570
+ }
1571
+ /**
1572
+ * 扫描本 agent 的邮箱并投递(**后台**执行,不阻塞 1s tick)。
1573
+ *
1574
+ * 语义:scan → claim(互斥)→ 按 intent 投递 → 成功 complete / 失败 release(可重试)。
1575
+ * `deferred`(静默时段)与 `failed` 视为「本次没处理成」→ 退回收件箱重试。
1576
+ */
1577
+ export async function runPeerScan() {
1578
+ if (peerScanBusy)
1579
+ return;
1580
+ const mailbox = peerMailbox;
1581
+ if (!mailbox)
1582
+ return;
1583
+ peerScanBusy = true;
1584
+ try {
1585
+ for (const envelope of mailbox.scan()) {
1586
+ const claim = mailbox.claim(envelope);
1587
+ if (!claim.claimed)
1588
+ continue;
1589
+ try {
1590
+ const outcome = await deliverPeerEnvelope(envelope);
1591
+ // **未投递(含 dropped)→ release(退回收件箱重试),绝不 complete**(Blocker-1):
1592
+ // complete = 归档为「已处理」→ 入站协作消息会凭空消失(永不重试)。
1593
+ // X5:release 必须**带退避** —— 否则 1s tick 会把它每秒重新认领、重新投递、再次失败
1594
+ // → 重试风暴(协调者实测:defer 形态 4 轮扫描 = 4 次重试;failed 形态无时间上界)。
1595
+ // `deferred`/`dropped` 是**节流**(不计入失败上限);`failed` 是错误(计入上限,
1596
+ // 超过上限由邮箱归档到终态目录 `failed/`,不丢、可审计)。
1597
+ if (outcome === "deferred" || outcome === "dropped" || outcome === "failed") {
1598
+ mailbox.release(envelope, { reason: outcome === "failed" ? "failed" : "throttled" });
1599
+ continue;
1600
+ }
1601
+ mailbox.complete(envelope);
1602
+ }
1603
+ catch (err) {
1604
+ console.error("[proactive] 入站信封处理失败,退回邮箱重试:", err);
1605
+ // 处理异常 = 投递失败 → 计入失败重试上限(超限归档到 failed/),并带退避。
1606
+ mailbox.release(envelope, { reason: "failed" });
1607
+ }
1608
+ }
1609
+ }
1610
+ catch (err) {
1611
+ console.error("[proactive] 邮箱扫描失败:", err);
1612
+ }
1613
+ finally {
1614
+ peerScanBusy = false;
1615
+ }
1616
+ }
1617
+ /**
1618
+ * 单条入站信封的投递(socket 与邮箱**共用**这条路径)。
1619
+ *
1620
+ * - 来源标记 `proactive:peer`;
1621
+ * - `kind:"ask"` → 投递后在**后台**等模型回答并回送 `kind:"reply"`
1622
+ * (**不**阻塞 ack:socket 回执超时只有 2s,等模型会把回执拖成 timeout → 重复投递)。
1623
+ */
1624
+ async function deliverPeerEnvelope(envelope) {
1625
+ const trigger = currentTrigger;
1626
+ if (!trigger) {
1627
+ console.error("[proactive] 入站信封无处投递(session_start 尚未触发)");
1628
+ return "failed";
1629
+ }
1630
+ // 收件方校验:端点/收件箱是按 agent 分的,但信封的 `to` 才是权威地址 ——
1631
+ // 不是给我的(且不是广播)→ 不投模型,只归档(outcome 用 notified:零 token、不占额度)。
1632
+ if (envelope.to !== AGENT_ID && envelope.to !== "broadcast") {
1633
+ console.warn(`[proactive] 入站信封地址不匹配(to=${envelope.to}),不投模型`);
1634
+ return "notified";
1635
+ }
1636
+ // 收到对端的 reply → 该链路的 hop 计数归零(链路闭合,可再次询问)。
1637
+ if (envelope.kind === "reply") {
1638
+ peerWatch?.resetHop(envelope.from);
1639
+ // ASKLOOP:**收讫即停** —— 配对未决 ask → 记结局(answered / unanswered)→ 不再追问。
1640
+ const outcomeEvent = askLedger?.onReply(envelope) ?? null;
1641
+ if (outcomeEvent) {
1642
+ recordAskOutcome(outcomeEvent, envelope);
1643
+ // 人侧发起的提问 → 回信**落到人眼前**(不等模型转述;模型侧同时收到注入)。
1644
+ if (outcomeEvent.humanOrigin === true)
1645
+ notifyHumanReply(envelope);
1646
+ }
1647
+ else {
1648
+ // 配不上 → **不臆造**对应关系(迟到的回答 / 对不上号的回信):只留日志。
1649
+ console.error("[proactive] 收到无法配对的回信(迟到或对不上号),不产生结局记录");
1650
+ }
1651
+ }
1652
+ // **自注入标记**(P-4):注入内容里放一个不可混淆的标记串 → 之后能精确认出
1653
+ // 「这条 role:user 消息是自己注入的」,而不用「正文是否包含对端提问正文」这类启发式。
1654
+ const injectionMarker = createInjectionMarker();
1655
+ // **人类发起标记**(人侧发指令):如实标注这条是不是**人类直接下达**的。
1656
+ // 「信不信」由收信侧的受信集合决定:受信 → 已验证;不受信 → 只说「对端声称」(不给特权)。
1657
+ const originLabel = humanOriginLabel(envelope, resolveTrustedHumanSenders());
1658
+ const marked = {
1659
+ ...envelope,
1660
+ customType: PEER_CUSTOM_TYPE,
1661
+ body: `${originLabel === undefined ? "" : `${originLabel}\n`}${envelope.body}\n${injectionMarker}`,
1662
+ };
1663
+ rememberInjectionMarker(injectionMarker);
1664
+ // **入站协作消息旁路「本机主动触发」的频率闸门**(Blocker-1):
1665
+ // 护栏管的是「我主动打扰用户」的额度;对端**主动发来**的协作消息不受它约束。
1666
+ // 记账点仍在 Trigger 内(契约 §5「记账点唯一」)—— 调用方不得自行 check/record。
1667
+ const outcome = await trigger.deliverToModel(marked, envelope.intent, {
1668
+ inboundPeer: true,
1669
+ // **触发原因落盘(因)**:对端请求的 cause = peer-request + 对端 id。
1670
+ cause: { type: "peer-request", peer: envelope.from },
1671
+ });
1672
+ if (envelope.kind === "ask" && outcome === "delivered") {
1673
+ // 登记 pending **必须在投递成功之后**(投递失败/被推迟 → 没有回答可归因)。
1674
+ // 登记表满 → 记日志、不回信(不臆造一条对应关系)。
1675
+ // 线程记账:ask **收到**(已成功投递给模型)记一条。
1676
+ appendThreadEvent(envelope, "ask", envelope.body);
1677
+ const pending = peerResponder?.onAsk(envelope) ?? null;
1678
+ if (!pending) {
1679
+ console.error("[proactive] pending 登记表已满或不可用,本次 ask 不回信(不臆造对应关系)");
1680
+ }
1681
+ else {
1682
+ // 记住「这条 pending 的线程键」→ 回信落在同一线程(Minor-2:ask 没带 id 时也成立)。
1683
+ // 键 = threadId(缺失才回退 correlationId)—— 不得用 correlationId 作键(P-5)。
1684
+ pendingThreadKeys.set(pendingKeyOf(pending), threadKeyOf(envelope));
1685
+ // 有界:只保留最近若干条(长期会话不得内存无界增长)。
1686
+ while (pendingThreadKeys.size > 256) {
1687
+ const oldest = pendingThreadKeys.keys().next();
1688
+ if (oldest.done)
1689
+ break;
1690
+ pendingThreadKeys.delete(oldest.value);
1691
+ }
1692
+ }
1693
+ }
1694
+ return outcome;
1695
+ }
1696
+ /**
1697
+ * 线程键:优先 `threadId`;没有就用 `correlationId`;再没有用信封 id。
1698
+ *
1699
+ * 目的:保证「一条 ask 与它的 reply 落在同一个线程文件里」——否则轮次上限会各算各的,
1700
+ * 环路防护(shouldStop)就形同虚设。
1701
+ */
1702
+ function threadKeyOf(env) {
1703
+ if (env.threadId)
1704
+ return env.threadId;
1705
+ if (env.correlationId)
1706
+ return env.correlationId;
1707
+ // **稳定兜底**(Minor-2):既没 threadId 也没 correlationId 时,按**协作对**(无序)成键
1708
+ // → 同一对端之间的往返落在同一线程 → 轮次上限(防 A→B→A 环路)不再失效。
1709
+ return `pair:${[env.from, env.to].sort().join("~")}`;
1710
+ }
1711
+ /**
1712
+ * pending → 线程键(回信必须落在 ask 的同一线程;ask 没带 id 时靠它兜底)。
1713
+ *
1714
+ * **键 = threadId(缺失时才回退 correlationId)**(P-5):
1715
+ * 用 correlationId 作键时,同一 correlationId 但不同 threadId 的两条 ask 会互相覆盖
1716
+ * → 先到的 pending 的回信被记到**后者的线程**(轮次虚增 + 另一线程漏计)。
1717
+ */
1718
+ const pendingThreadKeys = new Map();
1719
+ /** pending 的映射键:优先 threadId,缺失才回退 correlationId(P-5)。 */
1720
+ function pendingKeyOf(pending) {
1721
+ return pending.threadId ?? pending.correlationId;
1722
+ }
1723
+ /** 回信的线程键:优先用「这条 pending 登记时的线程键」,否则退回信封自身推导。 */
1724
+ function threadKeyOfPlan(plan) {
1725
+ return pendingThreadKeys.get(pendingKeyOf(plan.pending)) ?? threadKeyOf(plan.reply);
1726
+ }
1727
+ /**
1728
+ * 线程日志存储(按线程键缓存;线程文件路径
1729
+ * `<agentDir>/proactive/threads/<agentSegment(AGENT_ID)>/<threadKey>.jsonl`)。
1730
+ *
1731
+ * **agentId 段是必需的**(G-R1):规格 §6.4「各接收方独立」—— 本 agent 只数**自己**记下的回信,
1732
+ * 不得把同机其它 agent 的回信算进自己的轮次。
1733
+ */
1734
+ function threadStoreFor(env, threadKey) {
1735
+ const key = threadKey ?? threadKeyOf(env);
1736
+ let store = threadStores.get(key);
1737
+ if (!store) {
1738
+ store = new ThreadStore({ agentDir: resolveAgentDir(), agentId: AGENT_ID, threadId: key });
1739
+ threadStores.set(key, store);
1740
+ }
1741
+ return store;
1742
+ }
1743
+ /** 线程记账:ask 收到 / reply 发出各记一条(追加式日志)。 */
1744
+ function appendThreadEvent(env, type, text, threadKey) {
1745
+ try {
1746
+ threadStoreFor(env, threadKey).append({ type, from: env.from, correlationId: env.correlationId ?? env.id, text });
1747
+ }
1748
+ catch (err) {
1749
+ console.error("[proactive] 线程记账失败:", err);
1750
+ }
1751
+ }
1752
+ /** 线程轮次是否已达上限(达上限 → 不再发信,防 A→B→A 环路)。 */
1753
+ function threadExhausted(env, threadKey) {
1754
+ try {
1755
+ return threadStoreFor(env, threadKey).shouldStop(DEFAULT_MAX_ROUNDS);
1756
+ }
1757
+ catch (err) {
1758
+ console.error("[proactive] 线程轮次检查失败(按未达上限处理):", err);
1759
+ return false;
1760
+ }
1761
+ }
1762
+ /**
1763
+ * peer watch 一轮:找空闲且新鲜的 peer → 询问进度(每个 peer 每个周期最多一次)。
1764
+ *
1765
+ * 环路防护:发送前用 `nextHop()` 递增 hop 并对照 `maxHops` —— **超过上限拒绝发送**
1766
+ * (A→B→A 环路);收到该 peer 的回复后 hop 归零(链路闭合)。
1767
+ */
1768
+ export async function runPeerWatch() {
1769
+ const registry = peerRegistry;
1770
+ const watch = peerWatch;
1771
+ if (!registry || !watch || !watch.enabled)
1772
+ return;
1773
+ const now = Date.now();
1774
+ let peers;
1775
+ try {
1776
+ peers = registry.list();
1777
+ }
1778
+ catch (err) {
1779
+ console.error("[proactive] peer watch 读注册表失败:", err);
1780
+ return;
1781
+ }
1782
+ watch.observe(peers);
1783
+ // 对端**重新进入忙碌**(开始新工作)→ 复位「已答 / 已停止」→ 可以再问(ASKLOOP 状态机)。
1784
+ for (const p of peers) {
1785
+ if (p.status === "busy")
1786
+ askLedger?.notePeerBusy(p.agentId);
1787
+ }
1788
+ for (const target of watch.targets(peers)) {
1789
+ if (target.agentId === AGENT_ID)
1790
+ continue;
1791
+ // 语义闭环(KK-7):已答 / 等待中 / 退避中 / 已停止 → **不再追问**。
1792
+ // 频率护栏只是最后一道防线,替代不了这一步。
1793
+ if (askLedger !== undefined && !askLedger.canAsk(target.agentId, now))
1794
+ continue;
1795
+ // hop 计数:链路每问一次 +1;超过 maxHops → 拒绝发送(防 A→B→A 环路)。
1796
+ // **显式带 correlationId**(ASKLOOP):回信必须原样带回它 → 提问方才能把回信配回这条提问。
1797
+ const correlationId = `ask-${randomUUID()}`;
1798
+ const envelope = createEnvelope({
1799
+ from: AGENT_ID,
1800
+ to: target.agentId,
1801
+ kind: "ask",
1802
+ intent: "queue",
1803
+ subject: "进度询问",
1804
+ body: "在忙什么?需要帮忙吗?",
1805
+ threadId: `peer-watch:${target.agentId}`,
1806
+ correlationId,
1807
+ });
1808
+ const hopResult = nextHop({ ...envelope, hop: watch.hopFor(target.agentId) });
1809
+ if (!hopResult.ok) {
1810
+ console.error(`[proactive] peer watch 链路 hop 超限,拒绝询问 ${target.agentId}:${hopResult.error}`);
1811
+ continue;
1812
+ }
1813
+ try {
1814
+ const ack = await deliverToPeer(target.agentId, hopResult.envelope);
1815
+ watch.markAsked(target.agentId);
1816
+ watch.noteHop(target.agentId);
1817
+ if (ack.status === "accepted" || ack.status === "duplicate") {
1818
+ // 对端收下了 → 登记未决 ask(等它的回信 → 结局 answered / unanswered)。
1819
+ askLedger?.recordAsk({
1820
+ peer: target.agentId,
1821
+ correlationId,
1822
+ threadKey: envelope.threadId,
1823
+ askedAt: now,
1824
+ });
1825
+ }
1826
+ else {
1827
+ // **没送达** → 结局 unreachable(不是 unanswered:它压根没被回答的机会)。
1828
+ const event = askLedger?.noteUnreachable({
1829
+ peer: target.agentId,
1830
+ correlationId,
1831
+ threadKey: envelope.threadId,
1832
+ reason: `提问未送达(回执 ${ack.status})`,
1833
+ at: now,
1834
+ });
1835
+ if (event)
1836
+ recordAskOutcome(event, envelope);
1837
+ }
1838
+ console.error(`[proactive] peer watch 询问 ${target.agentId}:${describeAck(ack.status, ack.error ?? ack.path, ack.queuedReason)}`);
1839
+ }
1840
+ catch (err) {
1841
+ console.error("[proactive] peer watch 询问失败:", err);
1842
+ }
1843
+ }
1844
+ }
1845
+ /**
1846
+ * 回执状态 → **如实**的中文说明(M5c §2.1.3)。
1847
+ *
1848
+ * 关键:`queued` **不是**「已送达」—— 它表示 socket 不可达、消息已降级落盘到对端邮箱,
1849
+ * 尚未送达。写错会让人以为对端已经收到。
1850
+ */
1851
+ export function describeAck(status, detail, queuedReason) {
1852
+ switch (status) {
1853
+ case "accepted":
1854
+ return "已送达(对端已确认接收)";
1855
+ case "duplicate":
1856
+ return "对端判重,未重复处理";
1857
+ case "queued":
1858
+ return queuedReason === "peer-error"
1859
+ ? `对端在线但本轮未接收,已落盘待其后续重试,尚未送达${detail ? `(${detail})` : ""}`
1860
+ : `已落盘到对端邮箱(对端当前不在线),尚未送达${detail ? `(${detail})` : ""}`;
1861
+ case "rejected":
1862
+ return `被拒绝${detail ? `(${detail})` : ""}`;
1863
+ case "expired":
1864
+ return "已过期(TTL 到了,未投递)";
1865
+ case "unreachable":
1866
+ return `对端不可达${detail ? `(${detail})` : ""}`;
1867
+ case "timeout":
1868
+ return `投递超时${detail ? `(${detail})` : ""}`;
1869
+ default:
1870
+ return `投递出错${detail ? `(${detail})` : ""}`;
1871
+ }
1872
+ }
1873
+ /**
1874
+ * 出站投递(**唯一入口**):`deliverCrossProcess` + 「失败不谎报」的兜底。
1875
+ *
1876
+ * - `accepted` / `duplicate` / `queued` → 对端已收到 / 已落盘待其上线 → 如实返回;
1877
+ * - `error`(对端处理时抛错 / 对端进程崩了)→ **落盘到对端邮箱**并改写为 `queued`
1878
+ * (消息真的还在 → 回执说「已落盘待处理」,而不是谎报「已送达」)。
1879
+ */
1880
+ async function deliverToPeer(targetAgentId, envelope) {
1881
+ const agentDir = resolveAgentDir();
1882
+ const ack = await deliverCrossProcess({ targetAgentId, envelope, agentDir });
1883
+ if (ack.status !== "error") {
1884
+ // `deliverCrossProcess` 只在「socket 不可达 / ack 超时」时返回 queued → 对端**离线**待上线。
1885
+ return ack.status === "queued" ? { ...ack, queuedReason: "offline" } : ack;
1886
+ }
1887
+ try {
1888
+ const file = writeToMailbox(targetAgentId, envelope, { agentDir });
1889
+ // 对端**在线**但本轮没接收(处理失败 / 被推迟)→ 落盘待其后续重试
1890
+ // (≠「对方上线后才会收到」—— P-6)。
1891
+ return { status: "queued", id: envelope.id, path: file, error: ack.error, queuedReason: "peer-error" };
1892
+ }
1893
+ catch (err) {
1894
+ console.error("[proactive] 投递失败且落盘兜底也失败(消息可能丢失):", err);
1895
+ return { ...ack, queuedReason: "peer-error" };
1896
+ }
1897
+ }
1898
+ /**
1899
+ * 回信(`kind:"reply"`):把归因结果发给原 `from`。
1900
+ *
1901
+ * - 回信 `intent` = `"queue"`(**后续,不是插话**:ADR-3「默认 followUp 不打断」);
1902
+ * - 线程轮次已达上限 → 不再发(环路防护),只记日志;
1903
+ * - 歧义归因 → 正文如实标注「歧义归因」(不假装确定)。
1904
+ */
1905
+ async function sendPeerReply(plan) {
1906
+ try {
1907
+ const reply = plan.reply;
1908
+ // 回信必须落在**问它的那条**线程里(ask 没带 id 时靠 pending → 线程键映射兜底)。
1909
+ const threadKey = threadKeyOfPlan(plan);
1910
+ if (threadExhausted(reply, threadKey)) {
1911
+ // 达上限 → **必须通知请求方**(P-1):不得静默拒发(请求方会永远等下去)。
1912
+ await notifyThreadCap(reply, plan, threadKey);
1913
+ return;
1914
+ }
1915
+ const ack = await deliverToPeer(reply.to, reply);
1916
+ if (ack.status === "accepted" || ack.status === "duplicate" || ack.status === "queued") {
1917
+ // **投递成功才记账**(Minor-4):投递失败不记 reply 事件 → 轮次计数不虚增。
1918
+ appendThreadEvent(reply, "reply", reply.body, threadKey);
1919
+ }
1920
+ else {
1921
+ console.error(`[proactive] 回信未投递成功(不记线程 reply 事件):${ack.status} ${ack.error ?? ""}`);
1922
+ // 两条通道都失败 → 回信**彻底丢失** → 必须让请求方知道(P-7:不得静默丢失)。
1923
+ await notifyReplyDeliveryFailure(reply, plan, ack, threadKey);
1924
+ }
1925
+ pendingThreadKeys.delete(pendingKeyOf(plan.pending));
1926
+ if (plan.ambiguous) {
1927
+ console.error("[proactive] 回信归因存在歧义,正文已如实标注");
1928
+ }
1929
+ // 回执如实区分状态(§2.1.3):`queued` 绝不写成「已送达」。
1930
+ console.error(`[proactive] 回信 ${reply.to}:${describeAck(ack.status, ack.error ?? ack.path, ack.queuedReason)}`);
1931
+ }
1932
+ catch (err) {
1933
+ console.error("[proactive] 回信失败:", err);
1934
+ }
1935
+ }
1936
+ /**
1937
+ * 「已达线程轮次上限」说明的固定标记(线程日志里据此**去重**)。
1938
+ *
1939
+ * 去重判据必须是**持久化**的(线程日志的 note 事件)→ 进程重启后也不会重复通知同一线程。
1940
+ */
1941
+ const CAP_NOTICE_TAG = "【已达线程轮次上限】";
1942
+ /** 上限说明**未送达**时的追加标记(未送达 → 不算「已通知」→ 允许下次再通知一次)。 */
1943
+ const CAP_NOTICE_UNDELIVERED = "(本条说明未送达";
1944
+ /**
1945
+ * 去重键里的**请求方**标记(写进线程日志的 note 正文 → 持久化判据能区分「谁已被交代」)。
1946
+ *
1947
+ * X8:去重粒度 = **(线程, 请求方)** —— 同一线程上**不同请求方**各自必须被交代;
1948
+ * 只按线程去重 → 共用一条线程兜底的其它请求方**彻底不知情**(正是要消灭的「静默吞掉」)。
1949
+ */
1950
+ function capRequesterMark(requester) {
1951
+ return `【请求方:${requester}】`;
1952
+ }
1953
+ /** 去重键 = (线程键, 请求方) —— 同线程同请求方只通知一次;不同请求方各自一条。 */
1954
+ function capNoticeKey(threadKey, requester) {
1955
+ return `${threadKey}\u0000${requester}`;
1956
+ }
1957
+ /**
1958
+ * 本进程内已成功通知过的 **(线程, 请求方)** 键(防并发重复通知;持久化判据见 `threadCapNotified`)。
1959
+ *
1960
+ * X8:粒度是 **(线程, 请求方)**,不是仅线程 —— 同一条线程上**不同请求方**各自必须被交代。
1961
+ */
1962
+ const capNotifiedKeys = new Set();
1963
+ /**
1964
+ * 这个 **(线程, 请求方)** 是否**已经成功通知过**「已达上限」?
1965
+ *
1966
+ * 判据 = 线程日志里存在一条 note,正文含上限标记 + **该请求方的标记**,且**不含**「未送达」标记
1967
+ * → 跨进程重启也成立(不是内存态);且**别的请求方**的通知不会误判成「这个请求方已被交代」。
1968
+ */
1969
+ function threadCapNotified(env, threadKey, requester) {
1970
+ const mark = capRequesterMark(requester);
1971
+ try {
1972
+ return threadStoreFor(env, threadKey)
1973
+ .history()
1974
+ .some((e) => e.type === "note" &&
1975
+ (e.text ?? "").includes(CAP_NOTICE_TAG) &&
1976
+ (e.text ?? "").includes(mark) &&
1977
+ !(e.text ?? "").includes(CAP_NOTICE_UNDELIVERED));
1978
+ }
1979
+ catch (err) {
1980
+ console.error("[proactive] 线程上限通知去重检查失败(按未通知处理):", err);
1981
+ return false;
1982
+ }
1983
+ }
1984
+ /**
1985
+ * 线程轮次已达上限 → **通知请求方**(P-1 / X7)。
1986
+ *
1987
+ * 为什么要通知:轮次上限是**环路防护**,但「不再回信」若**静默**发生,请求方会一直等下去
1988
+ * (复验报告 P-1:连发 9 条提问 → 只有 4 条回信 + 零通知)。
1989
+ *
1990
+ * 通道(X7 修法):**socket 优先 + 邮箱兜底**
1991
+ * - 请求方**在线** → socket 直投(当场收到);
1992
+ * - 请求方**离线** → 落盘到**请求方自己的 agentId 目录**(`<agentDir>/proactive/mailbox/<请求方>/`,
1993
+ * 语义与「落盘待上线」一致)→ 请求方上线后由它的邮箱扫描取回。
1994
+ * 旧实现**只走 socket** → 请求方离线时 5 条通知**全部投递失败** → 它发出的 9 条提问里
1995
+ * **5 条静默无解释**(与基准 B8「达上限后请求方可知」冲突)。
1996
+ *
1997
+ * **去重**(X8):去重粒度 = **(线程, 请求方)** —— 同一请求方在同一线程上只通知一次
1998
+ * (否则请求方邮箱里会堆一串重复说明);**不同请求方各自必须收到交代**
1999
+ * (只按线程去重 → 共用线程兜底的其它请求方彻底不知情 = 静默吞掉)。
2000
+ */
2001
+ async function notifyThreadCap(reply, plan, threadKey) {
2002
+ // **去重键 = (线程, 请求方)**(X8):同线程同请求方只通知一次;
2003
+ // **别的请求方不受影响** → 每个请求方都被交代(回信或通知二选一)。
2004
+ const requester = reply.to;
2005
+ const noticeKey = capNoticeKey(threadKey, requester);
2006
+ if (capNotifiedKeys.has(noticeKey) || threadCapNotified(reply, threadKey, requester)) {
2007
+ console.error(`[proactive] 线程轮次已达上限(${DEFAULT_MAX_ROUNDS} 轮往返),已通知过该请求方 ${requester}(同线程同请求方不再重复通知)`);
2008
+ return;
2009
+ }
2010
+ // 先占位(防并发重复通知);未送达时撤销 → 允许下次再通知。
2011
+ capNotifiedKeys.add(noticeKey);
2012
+ const store = threadStoreFor(reply, threadKey);
2013
+ const rounds = store.rounds();
2014
+ const body = `${CAP_NOTICE_TAG}本线程已完成 ${rounds} 轮往返(已回信 ${rounds} 条),达到上限(${DEFAULT_MAX_ROUNDS} 轮)后,` +
2015
+ `**本线程后续提问一律不再回信**(这些提问不会再有回答,不是还在等待)。` +
2016
+ `你在本线程的后续提问由本条一并交代,不再单独通知。` +
2017
+ `若需继续,请另起一个话题(新的 threadId)。`;
2018
+ const notice = createEnvelope({
2019
+ from: AGENT_ID,
2020
+ to: reply.to,
2021
+ kind: "notify",
2022
+ intent: "queue",
2023
+ subject: "已达线程轮次上限",
2024
+ body,
2025
+ threadId: plan.pending.threadId,
2026
+ correlationId: plan.pending.correlationId,
2027
+ });
2028
+ try {
2029
+ // **socket 优先 + 邮箱兜底**(`deliverToPeer`:socket 不可达 → 落盘到对端邮箱 → queued)。
2030
+ const ack = await deliverToPeer(reply.to, notice);
2031
+ const delivered = ack.status === "accepted" || ack.status === "duplicate" || ack.status === "queued";
2032
+ // 线程记一条 note(**不**计入轮次 —— 它不是回答;也是去重的持久化判据)。
2033
+ // 送达时带上**请求方标记** → 持久化判据能区分「谁已被交代」(X8)。
2034
+ appendThreadEvent(notice, "note", delivered ? `${body}${capRequesterMark(requester)}` : `${body}${CAP_NOTICE_UNDELIVERED}:${ack.status})`, threadKey);
2035
+ if (!delivered)
2036
+ capNotifiedKeys.delete(noticeKey);
2037
+ console.error(`[proactive] 线程轮次已达上限(${DEFAULT_MAX_ROUNDS} 轮往返),` +
2038
+ `${delivered ? "已通知请求方" : "**未能**通知请求方"}:${describeAck(ack.status, ack.error ?? ack.path, ack.queuedReason)}`);
2039
+ }
2040
+ catch (err) {
2041
+ capNotifiedKeys.delete(noticeKey);
2042
+ appendThreadEvent(notice, "note", `${body}${CAP_NOTICE_UNDELIVERED}:${err instanceof Error ? err.message : String(err)})`, threadKey);
2043
+ console.error("[proactive] 线程轮次已达上限,通知请求方失败:", err);
2044
+ }
2045
+ }
2046
+ /**
2047
+ * 回信**彻底**投递失败(socket + 落盘兜底都失败)→ 通知请求方(P-7)。
2048
+ *
2049
+ * 否则:回信永久丢失(无重试、无落盘、无通知),请求方永远等不到回答且**不知情**。
2050
+ * 通知本身也走 `deliverToPeer`(socket 优先、落盘兜底);连通知都送不出去时:
2051
+ * stderr + 线程 note 留痕(**不**冒充已送达)。
2052
+ */
2053
+ async function notifyReplyDeliveryFailure(reply, plan, ack, threadKey) {
2054
+ const reason = `${ack.status}${ack.error ? `:${ack.error}` : ""}`;
2055
+ const body = `【回信未能送达】本机对本次提问的回答未能投送给请求方(${reason})。请勿继续等待这条回答。`;
2056
+ const notice = createEnvelope({
2057
+ from: AGENT_ID,
2058
+ to: reply.to,
2059
+ kind: "notify",
2060
+ intent: "queue",
2061
+ subject: "回信未能送达",
2062
+ body,
2063
+ threadId: plan.pending.threadId,
2064
+ correlationId: plan.pending.correlationId,
2065
+ });
2066
+ appendThreadEvent(notice, "note", body, threadKey);
2067
+ try {
2068
+ const nack = await deliverToPeer(reply.to, notice);
2069
+ console.error(`[proactive] 回信送达失败通知(${reason}):${describeAck(nack.status, nack.error ?? nack.path, nack.queuedReason)}`);
2070
+ }
2071
+ catch (err) {
2072
+ console.error("[proactive] 回信送达失败通知发送失败(消息可能丢失):", err);
2073
+ }
2074
+ }
2075
+ /** 宿主消息的角色(`assistant` / `user` / 其它)。 */
2076
+ function messageRole(message) {
2077
+ if (typeof message !== "object" || message === null)
2078
+ return undefined;
2079
+ const m = message;
2080
+ return typeof m.role === "string" ? m.role : undefined;
2081
+ }
2082
+ /** 从宿主消息里取全部文本块(拼接)。 */
2083
+ function messageText(message) {
2084
+ if (typeof message !== "object" || message === null)
2085
+ return "";
2086
+ const m = message;
2087
+ if (!Array.isArray(m.content))
2088
+ return "";
2089
+ const parts = [];
2090
+ for (const block of m.content) {
2091
+ if (typeof block !== "object" || block === null)
2092
+ continue;
2093
+ const b = block;
2094
+ if (b.type === "text" && typeof b.text === "string")
2095
+ parts.push(b.text);
2096
+ }
2097
+ return parts.join("\n");
2098
+ }
2099
+ /**
2100
+ * 这条宿主消息是不是**本插件自己注入**的 peer 消息?
2101
+ *
2102
+ * **只认来源标记**(`customType === "proactive:peer"`)—— 这是宿主侧**唯一可靠**的依据
2103
+ * (宿主把自定义消息存成 role:"custom" 的消息,customType 原样保留)。
2104
+ *
2105
+ * X7(R-2):**删掉任何基于正文内容的兜底识别**。
2106
+ * 旧实现在这里用「正文含注入标记串」来识别「这是我们注入的」→ 用户把注入正文
2107
+ * **原样复制**到自己的输入里(含标记串)时也被判成「自注入」→ 不记「用户发言」→
2108
+ * 之后的回答被当成确定答案回给对端 → 回信**漏标【歧义归因】**。
2109
+ * 现在:**正文里带标记串 = 可能是用户复制** → 按「用户发言」处理
2110
+ * (无法区分时**宁可多标歧义**,也不漏标)。
2111
+ */
2112
+ function isInjectedPeerMessage(message) {
2113
+ if (typeof message !== "object" || message === null)
2114
+ return false;
2115
+ const m = message;
2116
+ // ① **来源标记**(宿主保留 customType)—— 唯一可靠的「这是我们注入的」依据。
2117
+ if (m.customType === PEER_CUSTOM_TYPE)
2118
+ return true;
2119
+ // ② **兜底形态**(宿主把自定义消息转成 role:"user"、丢了 customType):
2120
+ // 该消息的标记串必须**已被 input(source:"extension") 事件认领** → 才是我们的回声。
2121
+ // 没被认领 → 用户可能**原样复制**了注入正文 → 按「用户发言」处理(宁可多标歧义)。
2122
+ const text = messageText(message);
2123
+ if (text === "")
2124
+ return false;
2125
+ const marker = injectionMarkers.find((mk) => mk !== "" && text.includes(mk));
2126
+ if (marker === undefined)
2127
+ return false;
2128
+ if (!claimedInjectionMarkers.has(marker))
2129
+ return false;
2130
+ claimedInjectionMarkers.delete(marker); // 一次性:认领只对**这一条**回声有效
2131
+ return true;
2132
+ }
2133
+ /**
2134
+ * 这条消息里有没有**我们自己注入**的标记串?(**精确匹配标记串**本身 —— 不用任何正文启发式。)
2135
+ *
2136
+ * 用途**只有一个**:识别「用户把注入正文原样复制了回来」→ 记一条审计日志。
2137
+ * 它**不**用于判定「这是我们注入的」(那会漏标歧义,见 `isInjectedPeerMessage`)。
2138
+ */
2139
+ function containsInjectionMarker(message) {
2140
+ const text = messageText(message);
2141
+ if (text === "")
2142
+ return false;
2143
+ return injectionMarkers.some((marker) => marker !== "" && text.includes(marker));
2144
+ }
2145
+ /**
2146
+ * 认领一次注入:宿主用 `input(source:"extension")` 事件告诉我们「这条是我们注入的」。
2147
+ *
2148
+ * 只认领**正文里精确出现**的标记串(不用任何启发式);认领是**一次性**的
2149
+ * (下一次同样的标记串出现 = 用户复制 → 按用户发言处理)。
2150
+ */
2151
+ function claimInjectionMarker(text) {
2152
+ if (typeof text !== "string" || text === "")
2153
+ return;
2154
+ for (const marker of injectionMarkers) {
2155
+ if (marker !== "" && text.includes(marker))
2156
+ claimedInjectionMarkers.add(marker);
2157
+ }
2158
+ // 有界:长期会话不得内存无界增长(认领后一直没等到回声的最老认领作废)。
2159
+ while (claimedInjectionMarkers.size > 32) {
2160
+ const oldest = claimedInjectionMarkers.values().next();
2161
+ if (oldest.done)
2162
+ break;
2163
+ claimedInjectionMarkers.delete(oldest.value);
2164
+ }
2165
+ }
2166
+ /** 造一个本次注入用的标记串(每次不同 → 不可混淆、不可被用户的正文碰巧命中)。 */
2167
+ function createInjectionMarker() {
2168
+ return `${INJECTION_MARKER_PREFIX}${randomUUID()}]`;
2169
+ }
2170
+ /** 记住一次注入的标记串(有界:只留最近若干条)。 */
2171
+ function rememberInjectionMarker(marker) {
2172
+ if (marker === "")
2173
+ return;
2174
+ injectionMarkers.push(marker);
2175
+ while (injectionMarkers.length > 16)
2176
+ injectionMarkers.shift();
2177
+ }
2178
+ /** 从宿主消息里取 assistant 的文本(拿不到就返回 undefined)。 */
2179
+ function extractAssistantText(message) {
2180
+ if (typeof message !== "object" || message === null)
2181
+ return undefined;
2182
+ const m = message;
2183
+ if (m.role !== "assistant" || !Array.isArray(m.content))
2184
+ return undefined;
2185
+ const parts = [];
2186
+ for (const block of m.content) {
2187
+ if (typeof block !== "object" || block === null)
2188
+ continue;
2189
+ const b = block;
2190
+ if (b.type === "text" && typeof b.text === "string")
2191
+ parts.push(b.text);
2192
+ }
2193
+ const text = parts.join("\n").trim();
2194
+ return text === "" ? undefined : text;
2195
+ }
2196
+ /**
2197
+ * `/proactive help` 的正文(MANUAL:产品内的人类面向手册入口)。
2198
+ *
2199
+ * 一屏内给出:① 命令表(**含 help 自身**)② 配置键速查(指向 README 详表)
2200
+ * ③ 限制与最常见的 3 个故障 ④ 详细文档路径。
2201
+ *
2202
+ * 为什么要**逐字**写「没有 `/proactive notify` 这个命令」:
2203
+ * 模型与用户都会拿 `kind:"notify"` 去臆造一个同名子命令 → 敲了被拒 → 误判为装坏了。
2204
+ * 这里把幽灵命令**点名消解**。
2205
+ */
2206
+ function formatHelp() {
2207
+ return [
2208
+ "proactive 命令速查(/proactive help)",
2209
+ "",
2210
+ "【命令】",
2211
+ " status 总览:开关 / 空闲判定 / 护栏限制 + 本轮为什么(没)触发",
2212
+ " on | off 主动性总开关(定时投递 + 空闲触发;已落盘,重启仍生效)",
2213
+ " idle on | off 只开关空闲触发(内存态,重启回到配置文件里的设置)",
2214
+ " peers 在线 peer(名字 / agentId / 忙闲 / 心跳)",
2215
+ " peers --all 含离线对端(带下线时间与下线原因)",
2216
+ " peers --idle 只看空闲的对端",
2217
+ " peers --name <子串> 按名字子串过滤(同名多个 → 列出全部候选,不替你挑)",
2218
+ " peers --detail <id> 单个对端详情(字段与 list_peers 逐字一致)",
2219
+ " spawn [名字] 创建一个对端会话(子进程 pi --mode rpc;本会话退出时一并终止)",
2220
+ " tasks 待触发任务(id / 类型 / 到期 / intent)",
2221
+ " cancel <id> 取消指定任务",
2222
+ " in <时长> <内容> 排期一次(30s / 10m / 2h / 1d;纯数字按秒计)",
2223
+ " at <HH:MM> <内容> 排期一次到某时刻(今天该时刻已过则顺延到明天)",
2224
+ " every <时长> <内容> 排期重复",
2225
+ " test 强制走一次投递链路自检(不受总开关与冷却影响)",
2226
+ " doctor [--json] 只读体检:插件面各面状态 + 判据 + 处置建议(不打扰、不耗额度)",
2227
+ " progress 项目进度 + ETA:区间 + 置信度 + 归因 + 阻塞项(不给单点数字)",
2228
+ " tell <peer> <内容> 人侧给对端 agent 下指令(--kind ask|task|notify;缺省 ask)",
2229
+ " help 本页",
2230
+ "",
2231
+ "【配置键速查】(详表见 <安装目录>/README.md「配置」)",
2232
+ " enabled 主动性总开关(默认 true)",
2233
+ " idleDetect 空闲检测档位:terminal / input-only / off(默认 off)",
2234
+ " idleTrigger.enabled 空闲触发开关(默认 false)",
2235
+ " idleTrigger.afterMs 空闲多久后触发(默认 600000 = 10 分钟)",
2236
+ " idleTrigger.intent 空闲触发的投递意图:wake / interrupt / queue / notify",
2237
+ " askTimeoutMs 向用户提问的超时(默认 120000 = 2 分钟)",
2238
+ " limits.minGapMs 两次主动触发的最短间隔(默认 300000 = 5 分钟)",
2239
+ " limits.maxPerHour 每小时主动次数上限(默认 6)",
2240
+ " limits.quietHours 静默时段 {from,to}(未设置 = 不静默)",
2241
+ " peerWatch.enabled 空闲时主动询问其它 peer(默认 false)",
2242
+ " PI_PROACTIVE_ROLE 会话角色:coordinator(协调者,会主动问)/ worker(执行者,只被问)",
2243
+ " PI_PROACTIVE_WATCH_PEERS 随会话的 watch 名单(agentId, 逗号分隔;空 = 不限定)",
2244
+ " 配置文件:<agent-dir>/proactive/config.json",
2245
+ " (<agent-dir> = $PI_CODING_AGENT_DIR,未设置时是 ~/.pi/agent)",
2246
+ "",
2247
+ "【限制与最常见的 3 个故障】",
2248
+ " 1) 不触发:① 空闲触发默认是关的 → /proactive idle on(内存态);",
2249
+ " ② idleDetect 默认 off → 设 terminal(仅 TUI)或 input-only;",
2250
+ " ③ 总开关是关的 → /proactive on;④ 距上次主动不足 5 分钟(冷却)或本小时次数已用满;",
2251
+ " ⑤ 处于静默时段;⑥ 代理正在忙。逐条对照 /proactive status 末尾的判定说明。",
2252
+ " 2) 消息 queued:只表示「已写进对端邮箱」,**尚未送达**;对端上线后才会收到 →",
2253
+ " 不要重复发送,改查 /proactive peers 或等回执。",
2254
+ " 3) 装完命令不存在:命令由扩展注册 → 必须在加载了本扩展的会话里用;",
2255
+ " 装包后新开一个会话(或 /reload)再试。",
2256
+ ' 另外:没有 `/proactive notify` 这个命令 —— notify 是**消息语义**(kind:"notify"),',
2257
+ " 不是子命令;**人侧给对端下指令**用 `/proactive tell <peer> <内容>`",
2258
+ ' (tell 的 --kind 决定这条指令的语义:ask=要回话 / task=派活 / notify=知会);',
2259
+ " /proactive quiet 同样未实现;/proactive history [peer|me] [条数] 已实现(查主动行为记录)。",
2260
+ "",
2261
+ "【详细文档】",
2262
+ " <安装目录>/README.md 安装 / 命令 / 模型工具 / 配置详表 / 故障排查(随包分发)",
2263
+ " pi-proactive-ops.md 运维与故障处置手册(与内测包同目录分发;",
2264
+ " 仓库内路径 docs/ops/pi-proactive-ops.md)",
2265
+ ].join("\n");
2266
+ }
2267
+ /** 投递回执文案:8 种状态逐一区分,**不把 queued 说成已送达**。 */
2268
+ function receiptText(ack) {
2269
+ switch (ack.status) {
2270
+ case "accepted":
2271
+ return "已送达:对端在线并已接收(accepted)。";
2272
+ case "duplicate":
2273
+ return "对端已处理过这条消息(duplicate)——未重复投递。";
2274
+ case "queued":
2275
+ // P-6:必须**区分**「对端离线待上线」与「对端在线但本轮未投递(被推迟 / 失败)」——
2276
+ // 后者说「对方上线后才会收到」是**不实描述**(对端明明在线,且这条消息可能永远不投递)。
2277
+ return ack.queuedReason === "peer-error"
2278
+ ? `已落盘待重试(queued)——对端**在线**但本轮未接收(原因:${ack.error ?? "未知"}),` +
2279
+ `消息已写入对端邮箱待其后续重试,**尚未送达**。${ack.path ? `落盘路径:${ack.path}` : ""}`
2280
+ : `已落盘待对方上线(queued)——消息已写入对端邮箱,对方上线后才会收到,**尚未送达**。${ack.path ? `落盘路径:${ack.path}` : ""}`;
2281
+ case "rejected":
2282
+ return `被拒绝(rejected):${ack.error ?? "未知原因"}`;
2283
+ case "expired":
2284
+ return "消息已过期(expired)——对方不会再处理。";
2285
+ case "error":
2286
+ return `投递失败(error):${ack.error ?? "未知原因"}`;
2287
+ case "unreachable":
2288
+ return `对端不可达(unreachable):${ack.error ?? "端点不存在或无进程监听"}`;
2289
+ case "timeout":
2290
+ return `等待回执超时(timeout):${ack.error ?? "对端未在时限内回执"}`;
2291
+ default:
2292
+ return `未知回执状态:${String(ack.status)}`;
2293
+ }
2294
+ }
2295
+ /**
2296
+ * **人侧发指令**(`/proactive tell`)的交付物。
2297
+ *
2298
+ * 范围(刻意**只做「发指令 + 看回信」**):不做编排 / 任务图 / 自动分发。
2299
+ *
2300
+ * 走的通道 = **既有唯一出站入口** `deliverToPeer`(**不另造投递通道**)。
2301
+ * 信封的 `from` = 本会话 agentId → 收信侧 strict 校验(注册表逐字命中 + 主机一致)照旧通过;
2302
+ * `customType` = `proactive:human` → 收信侧**能识别**这条是人类直接下达的。
2303
+ */
2304
+ // G12 三件套(人侧发指令这条腿):
2305
+ // - 可观察出口 = `tellReceiptText`(回执经 `cmdCtx.ui.notify` 呈现给人);
2306
+ // - 归因 = `parseTellCommand`(人敲的命令与参数)+ `resolveTellTarget`(发给谁:注册表解析);
2307
+ // - 结果判定 = ack 状态本身(送达 / 落盘待上线 / 未送达,见 tellReceiptText 的三档)。
2308
+ //
2309
+ // @capability: human-tell
2310
+ // @observable: tellReceiptText
2311
+ // @attribution: parseTellCommand resolveTellTarget
2312
+ // @outcome: accepted duplicate queued rejected error
2313
+ // @checked: test:pi-proactive/tests/human-to-peer.test.ts#端到端:/proactive tell
2314
+ async function runTell(args) {
2315
+ const parsed = parseTellCommand(args);
2316
+ if (!parsed.ok) {
2317
+ return { text: `proactive: ${parsed.error}`, level: "error" };
2318
+ }
2319
+ const registry = peerRegistry;
2320
+ if (!registry) {
2321
+ return { text: "proactive: 跨进程协作未初始化(session_start 尚未触发),未发送。", level: "error" };
2322
+ }
2323
+ const command = parsed.command;
2324
+ // 目标解析:**同名歧义 → 拒绝 + 列出候选**(人侧不替人挑一个)。
2325
+ const entries = registry.listAll().map((e) => ({
2326
+ agentId: e.agentId,
2327
+ name: e.name,
2328
+ status: e.status,
2329
+ lastSeen: e.lastSeen,
2330
+ }));
2331
+ const resolution = resolveTellTarget(entries, command.target);
2332
+ if (!resolution.ok) {
2333
+ return { text: `proactive: ${resolution.error}`, level: "error" };
2334
+ }
2335
+ const targetAgentId = resolution.agentId;
2336
+ const envelope = buildTellEnvelope({
2337
+ from: AGENT_ID,
2338
+ to: targetAgentId,
2339
+ body: command.body,
2340
+ kind: command.kind,
2341
+ threadId: command.threadId,
2342
+ subject: command.subject,
2343
+ });
2344
+ // 唯一出站入口(既有):在线直达 socket;不在线 → 落盘到对端邮箱(queued,**尚未送达**)。
2345
+ const ack = await deliverToPeer(targetAgentId, envelope);
2346
+ // 提问记账:回信要能配回来(与模型侧 message_agent 同口径)。
2347
+ if (envelope.kind === "ask" && envelope.correlationId !== undefined) {
2348
+ if (ack.status === "accepted" || ack.status === "duplicate") {
2349
+ askLedger?.recordAsk({
2350
+ peer: targetAgentId,
2351
+ correlationId: envelope.correlationId,
2352
+ threadKey: envelope.threadId,
2353
+ humanOrigin: true,
2354
+ });
2355
+ }
2356
+ else {
2357
+ const event = askLedger?.noteUnreachable({
2358
+ peer: targetAgentId,
2359
+ correlationId: envelope.correlationId,
2360
+ threadKey: envelope.threadId,
2361
+ reason: `提问未送达(回执 ${ack.status})`,
2362
+ });
2363
+ if (event)
2364
+ recordAskOutcome(event, envelope);
2365
+ }
2366
+ }
2367
+ const peerOnline = registry.list().some((e) => e.agentId === targetAgentId);
2368
+ return { text: tellReceiptText(ack, peerOnline), level: "info" };
2369
+ }
2370
+ /**
2371
+ * 人侧发指令的回信 → **人可见**的通知(不等模型转述)。
2372
+ *
2373
+ * 为什么多这一条:模型侧可能忽略这条 reply(不回话、不复述)→ 人就看不到答案。
2374
+ * 这里直接通知人一次;正文太长只取前 200 字(完整内容仍在注入给模型的那条里)。
2375
+ */
2376
+ function notifyHumanReply(envelope) {
2377
+ try {
2378
+ const body = envelope.body.trim();
2379
+ const head = body.length > 200 ? `${body.slice(0, 200)}…` : body;
2380
+ currentCtx?.ui.notify(`对端 ${envelope.from} 回信(你下发的指令):${head}`);
2381
+ }
2382
+ catch (err) {
2383
+ console.error("[proactive] 人类指令回信通知失败:", err);
2384
+ }
2385
+ }
2386
+ /**
2387
+ * 人侧发指令的回执(**三态分明**,queued 绝不被说成「已送达」):
2388
+ *
2389
+ * 1. **已送达**(accepted / duplicate)—— 对端在线并已接收(**尚未回答**);
2390
+ * 2. **已落盘待其上线**(queued)—— 对端当前不在线 → 消息在对端邮箱,**尚未送达**;
2391
+ * 3. **未送达**(rejected / error 等)—— 既没到对端,也没落到对端邮箱。
2392
+ *
2393
+ * 「对端当前不在线」这句来自**注册表**(事实源),不是猜的。
2394
+ */
2395
+ function tellReceiptText(ack, peerOnline) {
2396
+ const lines = [receiptText(ack)];
2397
+ if (ack.status === "accepted" || ack.status === "duplicate") {
2398
+ lines.push("这条是人类直接下达的指令:对端已收到,**尚未回答**;回答到达后会落到本会话。");
2399
+ return lines.join("\n");
2400
+ }
2401
+ if (ack.status === "queued") {
2402
+ if (!peerOnline) {
2403
+ lines.push("对端当前**不可达**(注册表里不在线)——指令已落盘待其上线,**尚未送达**。");
2404
+ }
2405
+ else {
2406
+ lines.push("对端在线但本轮未接收——指令已落盘待其重试,**尚未送达**。");
2407
+ }
2408
+ return lines.join("\n");
2409
+ }
2410
+ lines.push("**未送达**:这条指令既没到对端,也没落到对端邮箱。");
2411
+ return lines.join("\n");
2412
+ }
2413
+ /** `message_agent` 工具的参数 schema。 */
2414
+ const messageAgentParameters = Type.Object({
2415
+ to: Type.String({ description: "目标 agent 的名字或 agentId" }),
2416
+ kind: Type.Optional(Type.Union([
2417
+ Type.Literal("notify"),
2418
+ Type.Literal("ask"),
2419
+ Type.Literal("task"),
2420
+ Type.Literal("reply"),
2421
+ Type.Literal("broadcast"),
2422
+ ], { description: "消息语义(对方要不要回我);缺省 notify" })),
2423
+ subject: Type.Optional(Type.String({ description: "标题" })),
2424
+ body: Type.String({ description: "正文" }),
2425
+ intent: Type.Optional(Type.Union([Type.Literal("wake"), Type.Literal("interrupt"), Type.Literal("queue"), Type.Literal("notify")], {
2426
+ description: "投递意图(怎么投给对方);缺省 wake",
2427
+ })),
2428
+ threadId: Type.Optional(Type.String({ description: "话题 / 会话 id(可选)" })),
2429
+ });
2430
+ /** `list_peers` 工具的参数 schema。 */
2431
+ const listPeersParameters = Type.Object({
2432
+ name: Type.Optional(Type.String({
2433
+ description: "名字子串(大小写敏感;也命中 agentId)。同名歧义时返回与 message_agent 报错完全一致的候选",
2434
+ })),
2435
+ status: Type.Optional(Type.Union([Type.Literal("online"), Type.Literal("idle"), Type.Literal("busy"), Type.Literal("offline")], {
2436
+ description: "按在场状态过滤(online = 在线 = 空闲 ∪ 忙碌)",
2437
+ })),
2438
+ capability: Type.Optional(Type.String({ description: "按能力标签过滤(如 message_agent)" })),
2439
+ includeOffline: Type.Optional(Type.Boolean({ description: "是否包含离线对端(缺省 false = 只给在线)" })),
2440
+ });
2441
+ /**
2442
+ * 与某个对端**尚未闭环**的 ask 交互数(= `list_peers` 里的「在途任务数」)。
2443
+ *
2444
+ * 口径:① 本机发给它、还没收到结局的 ask(ASKLOOP 账本);② 它发给本机、还没被回答的 ask。
2445
+ */
2446
+ function inFlightForPeer(peerAgentId) {
2447
+ let n = askLedger?.outstandingFor(peerAgentId) ?? 0;
2448
+ for (const pending of peerResponder?.pendingList() ?? []) {
2449
+ if (pending.requester === peerAgentId)
2450
+ n += 1;
2451
+ }
2452
+ return n;
2453
+ }
2454
+ /**
2455
+ * 给投递器套一层「触发原因」(cause + 判定依据)——**不改投递语义**,只补血缘。
2456
+ *
2457
+ * 为什么要套一层:`src/idle.ts` 与 `src/scheduler.ts` 是冻结模块(不得改动),
2458
+ * 它们调用 `deliverToModel` 时不带 cause → 「因」只能由本层补上。
2459
+ */
2460
+ function withTriggerCause(trigger, cause, basis) {
2461
+ return {
2462
+ deliverToModel: async (msg, intent, opts) => trigger.deliverToModel(msg, intent, {
2463
+ ...opts,
2464
+ cause: { type: cause, ...(basis !== undefined ? { basis: basis(msg) } : {}) },
2465
+ }),
2466
+ };
2467
+ }
2468
+ /** 空闲触发的判定依据:已空闲多久 / 阈值 / 生效档位(只放可复核的量)。 */
2469
+ function idleBasis() {
2470
+ try {
2471
+ return {
2472
+ idleForMs: tracker.snapshot().idleForMs,
2473
+ thresholdMs: config.idleTrigger.afterMs,
2474
+ detect: effectiveIdleDetect(config.idleDetect, currentCtx?.mode),
2475
+ };
2476
+ }
2477
+ catch {
2478
+ return {};
2479
+ }
2480
+ }
2481
+ /** 排期触发的判定依据:任务 id / 到期时刻 / 周期。 */
2482
+ function scheduleBasis(taskId) {
2483
+ const basis = { taskId };
2484
+ try {
2485
+ const task = currentStore?.list().find((t) => t.id === taskId);
2486
+ if (task !== undefined) {
2487
+ basis.dueAt = task.dueAt;
2488
+ if (task.intervalMs !== undefined)
2489
+ basis.intervalMs = task.intervalMs;
2490
+ }
2491
+ }
2492
+ catch {
2493
+ // 读任务表失败不得影响投递(判定依据缺项即可)
2494
+ }
2495
+ return basis;
2496
+ }
2497
+ /** `/proactive status` 里的一行「最近事件」指路。 */
2498
+ function recentEventsHint() {
2499
+ const log = currentLineage;
2500
+ if (!log)
2501
+ return "最近事件:事件流未初始化(session_start 尚未触发)";
2502
+ const events = log.history({ limit: 1 });
2503
+ if (events.length === 0)
2504
+ return "最近事件:暂无记录(用 /proactive history 查看)";
2505
+ const e = events[events.length - 1];
2506
+ const result = e.result !== undefined ? ` · 结果=${e.result}` : "";
2507
+ return `最近事件:${e.type} · cause=${e.cause}${result}(用 /proactive history 查看全部)`;
2508
+ }