@zhin.js/agent 0.2.0 → 0.3.0

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 (464) hide show
  1. package/README.md +1 -1
  2. package/lib/agent-prompt/resolver.d.ts.map +1 -1
  3. package/lib/agent-prompt/resolver.js +4 -4
  4. package/lib/agent-prompt/resolver.js.map +1 -1
  5. package/lib/ai-event-bus.d.ts.map +1 -1
  6. package/lib/ai-event-bus.js +20 -31
  7. package/lib/ai-event-bus.js.map +1 -1
  8. package/lib/ai-event-subscriber.d.ts +1 -1
  9. package/lib/ai-event-subscriber.d.ts.map +1 -1
  10. package/lib/ai-event-subscriber.js +1 -1
  11. package/lib/ai-event-subscriber.js.map +1 -1
  12. package/lib/assistant/home-mcp-bridge.d.ts +1 -1
  13. package/lib/assistant/home-mcp-bridge.d.ts.map +1 -1
  14. package/lib/assistant/home-policy.d.ts +2 -2
  15. package/lib/assistant/home-policy.d.ts.map +1 -1
  16. package/lib/assistant/home-policy.js +28 -10
  17. package/lib/assistant/home-policy.js.map +1 -1
  18. package/lib/assistant/home-tools.js +14 -14
  19. package/lib/assistant/home-tools.js.map +1 -1
  20. package/lib/assistant/index.d.ts +1 -1
  21. package/lib/assistant/index.js +1 -1
  22. package/lib/assistant/legacy-convert.d.ts +3 -8
  23. package/lib/assistant/legacy-convert.d.ts.map +1 -1
  24. package/lib/assistant/legacy-convert.js +8 -8
  25. package/lib/assistant/legacy-convert.js.map +1 -1
  26. package/lib/assistant/notification-router.js +6 -6
  27. package/lib/assistant/notification-router.js.map +1 -1
  28. package/lib/assistant/types.d.ts +1 -1
  29. package/lib/assistant/types.d.ts.map +1 -1
  30. package/lib/builtin/activate-skill-tool.d.ts +2 -2
  31. package/lib/builtin/activate-skill-tool.d.ts.map +1 -1
  32. package/lib/builtin/activate-skill-tool.js +1 -1
  33. package/lib/builtin/activate-skill-tool.js.map +1 -1
  34. package/lib/builtin/analyze-media-tool.d.ts +2 -2
  35. package/lib/builtin/analyze-media-tool.d.ts.map +1 -1
  36. package/lib/builtin/analyze-media-tool.js +3 -3
  37. package/lib/builtin/analyze-media-tool.js.map +1 -1
  38. package/lib/builtin/ask-user-tool.d.ts +4 -4
  39. package/lib/builtin/ask-user-tool.d.ts.map +1 -1
  40. package/lib/builtin/ask-user-tool.js +16 -16
  41. package/lib/builtin/ask-user-tool.js.map +1 -1
  42. package/lib/builtin/bash-tool.d.ts +2 -2
  43. package/lib/builtin/bash-tool.d.ts.map +1 -1
  44. package/lib/builtin/bash-tool.js +8 -3
  45. package/lib/builtin/bash-tool.js.map +1 -1
  46. package/lib/builtin/builtin-base-tool.d.ts +2 -2
  47. package/lib/builtin/builtin-base-tool.d.ts.map +1 -1
  48. package/lib/builtin/edit-file-tool.d.ts +2 -2
  49. package/lib/builtin/edit-file-tool.d.ts.map +1 -1
  50. package/lib/builtin/edit-file-tool.js +6 -6
  51. package/lib/builtin/edit-file-tool.js.map +1 -1
  52. package/lib/builtin/glob-tool.d.ts +2 -2
  53. package/lib/builtin/glob-tool.d.ts.map +1 -1
  54. package/lib/builtin/glob-tool.js +3 -3
  55. package/lib/builtin/glob-tool.js.map +1 -1
  56. package/lib/builtin/grep-tool.d.ts +2 -2
  57. package/lib/builtin/grep-tool.d.ts.map +1 -1
  58. package/lib/builtin/grep-tool.js +3 -3
  59. package/lib/builtin/grep-tool.js.map +1 -1
  60. package/lib/builtin/install-skill-tool.d.ts +2 -2
  61. package/lib/builtin/install-skill-tool.d.ts.map +1 -1
  62. package/lib/builtin/install-skill-tool.js +1 -1
  63. package/lib/builtin/install-skill-tool.js.map +1 -1
  64. package/lib/builtin/knowledge-search-tool.d.ts +6 -0
  65. package/lib/builtin/knowledge-search-tool.d.ts.map +1 -0
  66. package/lib/builtin/knowledge-search-tool.js +184 -0
  67. package/lib/builtin/knowledge-search-tool.js.map +1 -0
  68. package/lib/builtin/list-dir-tool.d.ts +2 -2
  69. package/lib/builtin/list-dir-tool.d.ts.map +1 -1
  70. package/lib/builtin/list-dir-tool.js +3 -3
  71. package/lib/builtin/list-dir-tool.js.map +1 -1
  72. package/lib/builtin/memory-search-tool.d.ts.map +1 -1
  73. package/lib/builtin/memory-search-tool.js +5 -11
  74. package/lib/builtin/memory-search-tool.js.map +1 -1
  75. package/lib/builtin/memory-upsert-tool.d.ts.map +1 -1
  76. package/lib/builtin/memory-upsert-tool.js +10 -16
  77. package/lib/builtin/memory-upsert-tool.js.map +1 -1
  78. package/lib/builtin/orchestration-tools.d.ts +3 -2
  79. package/lib/builtin/orchestration-tools.d.ts.map +1 -1
  80. package/lib/builtin/orchestration-tools.js +5 -11
  81. package/lib/builtin/orchestration-tools.js.map +1 -1
  82. package/lib/builtin/read-file-tool.d.ts +2 -2
  83. package/lib/builtin/read-file-tool.d.ts.map +1 -1
  84. package/lib/builtin/read-file-tool.js +4 -4
  85. package/lib/builtin/read-file-tool.js.map +1 -1
  86. package/lib/builtin/run-spec-dry-run-tool.d.ts +1 -4
  87. package/lib/builtin/run-spec-dry-run-tool.d.ts.map +1 -1
  88. package/lib/builtin/run-spec-dry-run-tool.js.map +1 -1
  89. package/lib/builtin/run-validation-spec-tool.d.ts +1 -4
  90. package/lib/builtin/run-validation-spec-tool.d.ts.map +1 -1
  91. package/lib/builtin/run-validation-spec-tool.js.map +1 -1
  92. package/lib/builtin/spawn-task-tool.d.ts +7 -6
  93. package/lib/builtin/spawn-task-tool.d.ts.map +1 -1
  94. package/lib/builtin/spawn-task-tool.js +10 -17
  95. package/lib/builtin/spawn-task-tool.js.map +1 -1
  96. package/lib/builtin/todo-read-tool.d.ts +2 -2
  97. package/lib/builtin/todo-read-tool.d.ts.map +1 -1
  98. package/lib/builtin/todo-read-tool.js +1 -1
  99. package/lib/builtin/todo-read-tool.js.map +1 -1
  100. package/lib/builtin/todo-write-tool.d.ts +2 -2
  101. package/lib/builtin/todo-write-tool.d.ts.map +1 -1
  102. package/lib/builtin/todo-write-tool.js +1 -1
  103. package/lib/builtin/todo-write-tool.js.map +1 -1
  104. package/lib/builtin/web-fetch-tool.d.ts +4 -2
  105. package/lib/builtin/web-fetch-tool.d.ts.map +1 -1
  106. package/lib/builtin/web-fetch-tool.js +55 -10
  107. package/lib/builtin/web-fetch-tool.js.map +1 -1
  108. package/lib/builtin/web-search-locale.d.ts +4 -4
  109. package/lib/builtin/web-search-locale.d.ts.map +1 -1
  110. package/lib/builtin/web-search-locale.js +4 -3
  111. package/lib/builtin/web-search-locale.js.map +1 -1
  112. package/lib/builtin/web-search-tool.d.ts +3 -3
  113. package/lib/builtin/web-search-tool.d.ts.map +1 -1
  114. package/lib/builtin/web-search-tool.js +3 -3
  115. package/lib/builtin/web-search-tool.js.map +1 -1
  116. package/lib/builtin/write-file-tool.d.ts +2 -2
  117. package/lib/builtin/write-file-tool.d.ts.map +1 -1
  118. package/lib/builtin/write-file-tool.js +6 -6
  119. package/lib/builtin/write-file-tool.js.map +1 -1
  120. package/lib/builtin-tools.d.ts +2 -0
  121. package/lib/builtin-tools.d.ts.map +1 -1
  122. package/lib/builtin-tools.js +4 -0
  123. package/lib/builtin-tools.js.map +1 -1
  124. package/lib/common-adapter-tools.js +3 -3
  125. package/lib/common-adapter-tools.js.map +1 -1
  126. package/lib/config/fix-ai-config.d.ts +9 -0
  127. package/lib/config/fix-ai-config.d.ts.map +1 -0
  128. package/lib/config/fix-ai-config.js +69 -0
  129. package/lib/config/fix-ai-config.js.map +1 -0
  130. package/lib/config/index.d.ts +5 -0
  131. package/lib/config/index.d.ts.map +1 -0
  132. package/lib/config/index.js +5 -0
  133. package/lib/config/index.js.map +1 -0
  134. package/lib/config/normalize-ai-config.d.ts +1 -1
  135. package/lib/config/normalize-ai-config.d.ts.map +1 -1
  136. package/lib/config/provider-instance.d.ts +1 -1
  137. package/lib/config/provider-instance.d.ts.map +1 -1
  138. package/lib/config/provider-instance.js +1 -1
  139. package/lib/config/provider-instance.js.map +1 -1
  140. package/lib/config/types.d.ts +2 -2
  141. package/lib/config/types.d.ts.map +1 -1
  142. package/lib/create-agent-session.d.ts +1 -1
  143. package/lib/create-agent-session.d.ts.map +1 -1
  144. package/lib/cron-engine.d.ts.map +1 -1
  145. package/lib/cron-engine.js +4 -4
  146. package/lib/cron-engine.js.map +1 -1
  147. package/lib/deferred-worker-runner.d.ts +3 -3
  148. package/lib/deferred-worker-runner.d.ts.map +1 -1
  149. package/lib/deferred-worker-runner.js +3 -3
  150. package/lib/discovery/tools.d.ts +1 -1
  151. package/lib/discovery/tools.d.ts.map +1 -1
  152. package/lib/discovery/tools.js +21 -6
  153. package/lib/discovery/tools.js.map +1 -1
  154. package/lib/hooks.d.ts +1 -1
  155. package/lib/hooks.d.ts.map +1 -1
  156. package/lib/hooks.js +1 -1
  157. package/lib/hooks.js.map +1 -1
  158. package/lib/index.d.ts +5 -22
  159. package/lib/index.d.ts.map +1 -1
  160. package/lib/index.js +3 -11
  161. package/lib/index.js.map +1 -1
  162. package/lib/init/activate-ai-database-storage.d.ts +1 -1
  163. package/lib/init/activate-ai-database-storage.d.ts.map +1 -1
  164. package/lib/init/activate-ai-database-storage.js +12 -8
  165. package/lib/init/activate-ai-database-storage.js.map +1 -1
  166. package/lib/init/create-zhin-agent.d.ts.map +1 -1
  167. package/lib/init/create-zhin-agent.js +38 -15
  168. package/lib/init/create-zhin-agent.js.map +1 -1
  169. package/lib/init/introspection-args.d.ts +1 -1
  170. package/lib/init/introspection-args.js +1 -1
  171. package/lib/init/introspection-args.js.map +1 -1
  172. package/lib/init/introspection-collectors.d.ts +2 -2
  173. package/lib/init/introspection-collectors.d.ts.map +1 -1
  174. package/lib/init/introspection-collectors.js +4 -4
  175. package/lib/init/introspection-collectors.js.map +1 -1
  176. package/lib/init/introspection-commands-format.d.ts +3 -3
  177. package/lib/init/introspection-commands-format.d.ts.map +1 -1
  178. package/lib/init/introspection-commands-format.js +6 -6
  179. package/lib/init/introspection-commands-format.js.map +1 -1
  180. package/lib/init/introspection-rest.d.ts +2 -2
  181. package/lib/init/introspection-rest.d.ts.map +1 -1
  182. package/lib/init/introspection-rest.js +4 -4
  183. package/lib/init/introspection-rest.js.map +1 -1
  184. package/lib/init/management-command-guard.d.ts +3 -3
  185. package/lib/init/management-command-guard.d.ts.map +1 -1
  186. package/lib/init/management-command-guard.js +3 -3
  187. package/lib/init/management-command-guard.js.map +1 -1
  188. package/lib/init/message-media.d.ts +4 -3
  189. package/lib/init/message-media.d.ts.map +1 -1
  190. package/lib/init/message-media.js +1 -1
  191. package/lib/init/message-media.js.map +1 -1
  192. package/lib/init/register-ai-trigger.d.ts.map +1 -1
  193. package/lib/init/register-ai-trigger.js +43 -58
  194. package/lib/init/register-ai-trigger.js.map +1 -1
  195. package/lib/init/register-builtin-tools.d.ts.map +1 -1
  196. package/lib/init/register-builtin-tools.js +6 -3
  197. package/lib/init/register-builtin-tools.js.map +1 -1
  198. package/lib/init/register-db-upgrade.d.ts.map +1 -1
  199. package/lib/init/register-db-upgrade.js +2 -0
  200. package/lib/init/register-db-upgrade.js.map +1 -1
  201. package/lib/init/register-group-session-passive.d.ts.map +1 -1
  202. package/lib/init/register-group-session-passive.js +5 -10
  203. package/lib/init/register-group-session-passive.js.map +1 -1
  204. package/lib/init/register-introspection-commands.js +7 -7
  205. package/lib/init/register-introspection-commands.js.map +1 -1
  206. package/lib/init/register-management-tools.d.ts.map +1 -1
  207. package/lib/init/register-management-tools.js +8 -29
  208. package/lib/init/register-management-tools.js.map +1 -1
  209. package/lib/init/register-owner-approve-commands.js +13 -13
  210. package/lib/init/register-owner-approve-commands.js.map +1 -1
  211. package/lib/init/register-typing-indicator.d.ts +3 -3
  212. package/lib/init/register-typing-indicator.js +41 -41
  213. package/lib/init/register-typing-indicator.js.map +1 -1
  214. package/lib/init/upgrade-agent-db-schema.d.ts.map +1 -1
  215. package/lib/init/upgrade-agent-db-schema.js +5 -4
  216. package/lib/init/upgrade-agent-db-schema.js.map +1 -1
  217. package/lib/init/upgrade-endpoint-id-schema.d.ts +12 -0
  218. package/lib/init/upgrade-endpoint-id-schema.d.ts.map +1 -0
  219. package/lib/init/upgrade-endpoint-id-schema.js +58 -0
  220. package/lib/init/upgrade-endpoint-id-schema.js.map +1 -0
  221. package/lib/mcp-client/connection.d.ts.map +1 -1
  222. package/lib/mcp-client/connection.js +38 -2
  223. package/lib/mcp-client/connection.js.map +1 -1
  224. package/lib/media/constants.d.ts +1 -1
  225. package/lib/media/constants.d.ts.map +1 -1
  226. package/lib/media/constants.js +1 -1
  227. package/lib/media/constants.js.map +1 -1
  228. package/lib/media/deliver-subagent-result.d.ts.map +1 -1
  229. package/lib/media/deliver-subagent-result.js +6 -5
  230. package/lib/media/deliver-subagent-result.js.map +1 -1
  231. package/lib/memory-layers.d.ts +3 -3
  232. package/lib/memory-layers.d.ts.map +1 -1
  233. package/lib/memory-layers.js +3 -3
  234. package/lib/memory-layers.js.map +1 -1
  235. package/lib/orchestrator/agent-dispatcher.d.ts +1 -1
  236. package/lib/orchestrator/agent-dispatcher.d.ts.map +1 -1
  237. package/lib/orchestrator/delegation-processor.d.ts.map +1 -1
  238. package/lib/orchestrator/delegation-processor.js +8 -8
  239. package/lib/orchestrator/delegation-processor.js.map +1 -1
  240. package/lib/orchestrator/hook-registry.js.map +1 -1
  241. package/lib/orchestrator/mission-milestone-notify.d.ts +3 -3
  242. package/lib/orchestrator/mission-milestone-notify.d.ts.map +1 -1
  243. package/lib/orchestrator/mission-milestone-notify.js +15 -10
  244. package/lib/orchestrator/mission-milestone-notify.js.map +1 -1
  245. package/lib/orchestrator/mission-runner.d.ts +2 -3
  246. package/lib/orchestrator/mission-runner.d.ts.map +1 -1
  247. package/lib/orchestrator/mission-runner.js +13 -11
  248. package/lib/orchestrator/mission-runner.js.map +1 -1
  249. package/lib/orchestrator/orchestration-repository.d.ts +6 -0
  250. package/lib/orchestrator/orchestration-repository.d.ts.map +1 -1
  251. package/lib/orchestrator/orchestration-repository.js +30 -0
  252. package/lib/orchestrator/orchestration-repository.js.map +1 -1
  253. package/lib/orchestrator/owner-confirm-orchestration.d.ts +3 -3
  254. package/lib/orchestrator/owner-confirm-orchestration.d.ts.map +1 -1
  255. package/lib/orchestrator/owner-confirm-orchestration.js +5 -5
  256. package/lib/orchestrator/owner-confirm-orchestration.js.map +1 -1
  257. package/lib/orchestrator/remote-agent-registry.d.ts +1 -1
  258. package/lib/orchestrator/remote-agent-registry.d.ts.map +1 -1
  259. package/lib/orchestrator/tool-registry.d.ts +4 -5
  260. package/lib/orchestrator/tool-registry.d.ts.map +1 -1
  261. package/lib/orchestrator/tool-registry.js +7 -11
  262. package/lib/orchestrator/tool-registry.js.map +1 -1
  263. package/lib/orchestrator/tool-selection.d.ts +7 -6
  264. package/lib/orchestrator/tool-selection.d.ts.map +1 -1
  265. package/lib/orchestrator/tool-selection.js +47 -38
  266. package/lib/orchestrator/tool-selection.js.map +1 -1
  267. package/lib/orchestrator/types.d.ts +3 -6
  268. package/lib/orchestrator/types.d.ts.map +1 -1
  269. package/lib/routing/route-matcher.d.ts +1 -1
  270. package/lib/routing/route-matcher.d.ts.map +1 -1
  271. package/lib/routing/route-matcher.js +3 -3
  272. package/lib/routing/route-matcher.js.map +1 -1
  273. package/lib/routing/runtime-binding.d.ts +1 -1
  274. package/lib/routing/runtime-binding.d.ts.map +1 -1
  275. package/lib/security/audit-logger.d.ts +4 -3
  276. package/lib/security/audit-logger.d.ts.map +1 -1
  277. package/lib/security/audit-logger.js +14 -4
  278. package/lib/security/audit-logger.js.map +1 -1
  279. package/lib/security/comm-message-context.d.ts +20 -0
  280. package/lib/security/comm-message-context.d.ts.map +1 -0
  281. package/lib/security/comm-message-context.js +19 -0
  282. package/lib/security/comm-message-context.js.map +1 -0
  283. package/lib/security/dangerous-tool-policy.d.ts +4 -4
  284. package/lib/security/dangerous-tool-policy.d.ts.map +1 -1
  285. package/lib/security/dangerous-tool-policy.js +43 -33
  286. package/lib/security/dangerous-tool-policy.js.map +1 -1
  287. package/lib/security/exec-policy.d.ts +1 -1
  288. package/lib/security/exec-policy.d.ts.map +1 -1
  289. package/lib/security/exec-policy.js +56 -9
  290. package/lib/security/exec-policy.js.map +1 -1
  291. package/lib/security/file-role-policy.d.ts +1 -1
  292. package/lib/security/file-role-policy.d.ts.map +1 -1
  293. package/lib/security/file-role-policy.js +4 -5
  294. package/lib/security/file-role-policy.js.map +1 -1
  295. package/lib/security/index.d.ts +3 -47
  296. package/lib/security/index.d.ts.map +1 -1
  297. package/lib/security/index.js +3 -68
  298. package/lib/security/index.js.map +1 -1
  299. package/lib/security/owner-approve-always-store.d.ts +18 -16
  300. package/lib/security/owner-approve-always-store.d.ts.map +1 -1
  301. package/lib/security/owner-approve-always-store.js +133 -118
  302. package/lib/security/owner-approve-always-store.js.map +1 -1
  303. package/lib/security/sandbox-docker.d.ts +28 -0
  304. package/lib/security/sandbox-docker.d.ts.map +1 -0
  305. package/lib/security/sandbox-docker.js +177 -0
  306. package/lib/security/sandbox-docker.js.map +1 -0
  307. package/lib/security/sandbox.d.ts +9 -0
  308. package/lib/security/sandbox.d.ts.map +1 -1
  309. package/lib/security/sandbox.js +215 -14
  310. package/lib/security/sandbox.js.map +1 -1
  311. package/lib/service.d.ts +4 -5
  312. package/lib/service.d.ts.map +1 -1
  313. package/lib/service.js +8 -9
  314. package/lib/service.js.map +1 -1
  315. package/lib/stability/memory-pressure.d.ts +31 -0
  316. package/lib/stability/memory-pressure.d.ts.map +1 -0
  317. package/lib/stability/memory-pressure.js +104 -0
  318. package/lib/stability/memory-pressure.js.map +1 -0
  319. package/lib/stability/registry-cleanup.d.ts +5 -0
  320. package/lib/stability/registry-cleanup.d.ts.map +1 -0
  321. package/lib/stability/registry-cleanup.js +20 -0
  322. package/lib/stability/registry-cleanup.js.map +1 -0
  323. package/lib/subagent-ai-events.d.ts +2 -2
  324. package/lib/subagent-ai-events.d.ts.map +1 -1
  325. package/lib/subagent-ai-events.js +5 -22
  326. package/lib/subagent-ai-events.js.map +1 -1
  327. package/lib/subagent-goal-notify.d.ts +4 -4
  328. package/lib/subagent-goal-notify.d.ts.map +1 -1
  329. package/lib/subagent-goal-notify.js +6 -5
  330. package/lib/subagent-goal-notify.js.map +1 -1
  331. package/lib/subagent.d.ts +10 -14
  332. package/lib/subagent.d.ts.map +1 -1
  333. package/lib/subagent.js +5 -11
  334. package/lib/subagent.js.map +1 -1
  335. package/lib/task-executor.d.ts +1 -0
  336. package/lib/task-executor.d.ts.map +1 -1
  337. package/lib/task-executor.js +17 -9
  338. package/lib/task-executor.js.map +1 -1
  339. package/lib/typing-indicator/adapter-integration.d.ts +22 -22
  340. package/lib/typing-indicator/adapter-integration.d.ts.map +1 -1
  341. package/lib/typing-indicator/adapter-integration.js +47 -47
  342. package/lib/typing-indicator/adapter-integration.js.map +1 -1
  343. package/lib/typing-indicator/index.d.ts +2 -2
  344. package/lib/typing-indicator/index.d.ts.map +1 -1
  345. package/lib/typing-indicator/index.js +1 -1
  346. package/lib/typing-indicator/index.js.map +1 -1
  347. package/lib/typing-indicator/integration.d.ts +8 -8
  348. package/lib/typing-indicator/integration.d.ts.map +1 -1
  349. package/lib/typing-indicator/integration.js +14 -14
  350. package/lib/typing-indicator/integration.js.map +1 -1
  351. package/lib/zhin-agent/agent-loop-standalone.d.ts +2 -2
  352. package/lib/zhin-agent/agent-loop-standalone.d.ts.map +1 -1
  353. package/lib/zhin-agent/agent-loop-standalone.js +5 -5
  354. package/lib/zhin-agent/agent-loop-standalone.js.map +1 -1
  355. package/lib/zhin-agent/agent-loop-turn.d.ts +4 -4
  356. package/lib/zhin-agent/agent-loop-turn.d.ts.map +1 -1
  357. package/lib/zhin-agent/agent-loop-turn.js +8 -8
  358. package/lib/zhin-agent/agent-loop-turn.js.map +1 -1
  359. package/lib/zhin-agent/builtin-tools.d.ts +1 -1
  360. package/lib/zhin-agent/builtin-tools.d.ts.map +1 -1
  361. package/lib/zhin-agent/compaction-runtime.d.ts +6 -2
  362. package/lib/zhin-agent/compaction-runtime.d.ts.map +1 -1
  363. package/lib/zhin-agent/compaction-runtime.js +25 -1
  364. package/lib/zhin-agent/compaction-runtime.js.map +1 -1
  365. package/lib/zhin-agent/config.d.ts +25 -0
  366. package/lib/zhin-agent/config.d.ts.map +1 -1
  367. package/lib/zhin-agent/config.js.map +1 -1
  368. package/lib/zhin-agent/deferred-delivery.d.ts +3 -3
  369. package/lib/zhin-agent/deferred-delivery.d.ts.map +1 -1
  370. package/lib/zhin-agent/deferred-delivery.js +5 -5
  371. package/lib/zhin-agent/deferred-delivery.js.map +1 -1
  372. package/lib/zhin-agent/event-emitter.d.ts +2 -2
  373. package/lib/zhin-agent/event-emitter.d.ts.map +1 -1
  374. package/lib/zhin-agent/event-emitter.js +7 -7
  375. package/lib/zhin-agent/event-emitter.js.map +1 -1
  376. package/lib/zhin-agent/index.d.ts +29 -28
  377. package/lib/zhin-agent/index.d.ts.map +1 -1
  378. package/lib/zhin-agent/index.js +114 -162
  379. package/lib/zhin-agent/index.js.map +1 -1
  380. package/lib/zhin-agent/interfaces.d.ts +63 -0
  381. package/lib/zhin-agent/interfaces.d.ts.map +1 -0
  382. package/lib/zhin-agent/interfaces.js +8 -0
  383. package/lib/zhin-agent/interfaces.js.map +1 -0
  384. package/lib/zhin-agent/model-resolver.d.ts.map +1 -1
  385. package/lib/zhin-agent/model-resolver.js +2 -0
  386. package/lib/zhin-agent/model-resolver.js.map +1 -1
  387. package/lib/zhin-agent/persist-deferred-context.d.ts +2 -2
  388. package/lib/zhin-agent/persist-deferred-context.d.ts.map +1 -1
  389. package/lib/zhin-agent/persist-deferred-context.js +3 -9
  390. package/lib/zhin-agent/persist-deferred-context.js.map +1 -1
  391. package/lib/zhin-agent/prompt-assembly.d.ts +7 -7
  392. package/lib/zhin-agent/prompt-assembly.d.ts.map +1 -1
  393. package/lib/zhin-agent/prompt-assembly.js +11 -11
  394. package/lib/zhin-agent/prompt-assembly.js.map +1 -1
  395. package/lib/zhin-agent/prompt-controller.d.ts +3 -3
  396. package/lib/zhin-agent/prompt-controller.d.ts.map +1 -1
  397. package/lib/zhin-agent/prompt-controller.js +2 -2
  398. package/lib/zhin-agent/prompt-controller.js.map +1 -1
  399. package/lib/zhin-agent/prompt.d.ts +10 -10
  400. package/lib/zhin-agent/prompt.d.ts.map +1 -1
  401. package/lib/zhin-agent/prompt.js +62 -55
  402. package/lib/zhin-agent/prompt.js.map +1 -1
  403. package/lib/zhin-agent/session-io.d.ts +10 -10
  404. package/lib/zhin-agent/session-io.d.ts.map +1 -1
  405. package/lib/zhin-agent/session-io.js +47 -33
  406. package/lib/zhin-agent/session-io.js.map +1 -1
  407. package/lib/zhin-agent/session-tree-commands.d.ts +3 -3
  408. package/lib/zhin-agent/session-tree-commands.d.ts.map +1 -1
  409. package/lib/zhin-agent/session-tree-commands.js +7 -19
  410. package/lib/zhin-agent/session-tree-commands.js.map +1 -1
  411. package/lib/zhin-agent/task-continuation.d.ts +4 -4
  412. package/lib/zhin-agent/task-continuation.d.ts.map +1 -1
  413. package/lib/zhin-agent/task-continuation.js.map +1 -1
  414. package/lib/zhin-agent/tool-orchestration.d.ts +3 -3
  415. package/lib/zhin-agent/tool-orchestration.d.ts.map +1 -1
  416. package/lib/zhin-agent/tool-orchestration.js +9 -15
  417. package/lib/zhin-agent/tool-orchestration.js.map +1 -1
  418. package/lib/zhin-agent/tool-runtime.d.ts +2 -2
  419. package/lib/zhin-agent/tool-runtime.d.ts.map +1 -1
  420. package/lib/zhin-agent/tool-runtime.js +2 -2
  421. package/lib/zhin-agent/tool-runtime.js.map +1 -1
  422. package/lib/zhin-agent/tool-search-orchestrator.d.ts +2 -2
  423. package/lib/zhin-agent/tool-search-orchestrator.d.ts.map +1 -1
  424. package/lib/zhin-agent/tool-search-orchestrator.js +9 -9
  425. package/lib/zhin-agent/tool-search-orchestrator.js.map +1 -1
  426. package/lib/zhin-agent/turn-pipeline.d.ts +4 -3
  427. package/lib/zhin-agent/turn-pipeline.d.ts.map +1 -1
  428. package/lib/zhin-agent/turn-pipeline.js +37 -59
  429. package/lib/zhin-agent/turn-pipeline.js.map +1 -1
  430. package/lib/zhin-agent/turn-user-message.d.ts +2 -2
  431. package/lib/zhin-agent/turn-user-message.d.ts.map +1 -1
  432. package/lib/zhin-agent/turn-user-message.js +2 -2
  433. package/lib/zhin-agent/turn-user-message.js.map +1 -1
  434. package/lib/zhin-agent/web-search-locale-attach.d.ts +2 -2
  435. package/lib/zhin-agent/web-search-locale-attach.d.ts.map +1 -1
  436. package/lib/zhin-agent/web-search-locale-attach.js +5 -4
  437. package/lib/zhin-agent/web-search-locale-attach.js.map +1 -1
  438. package/lib/zhin-agent/zhin-agent-private.d.ts +7 -7
  439. package/lib/zhin-agent/zhin-agent-private.d.ts.map +1 -1
  440. package/package.json +15 -5
  441. package/lib/monitoring/index.d.ts +0 -79
  442. package/lib/monitoring/index.d.ts.map +0 -1
  443. package/lib/monitoring/index.js +0 -197
  444. package/lib/monitoring/index.js.map +0 -1
  445. package/lib/monitoring/metrics.d.ts +0 -260
  446. package/lib/monitoring/metrics.d.ts.map +0 -1
  447. package/lib/monitoring/metrics.js +0 -550
  448. package/lib/monitoring/metrics.js.map +0 -1
  449. package/lib/security/bash-tool-context.d.ts +0 -20
  450. package/lib/security/bash-tool-context.d.ts.map +0 -1
  451. package/lib/security/bash-tool-context.js +0 -19
  452. package/lib/security/bash-tool-context.js.map +0 -1
  453. package/lib/security/budget-limiter.d.ts +0 -161
  454. package/lib/security/budget-limiter.d.ts.map +0 -1
  455. package/lib/security/budget-limiter.js +0 -392
  456. package/lib/security/budget-limiter.js.map +0 -1
  457. package/lib/security/network-policy.d.ts +0 -98
  458. package/lib/security/network-policy.d.ts.map +0 -1
  459. package/lib/security/network-policy.js +0 -305
  460. package/lib/security/network-policy.js.map +0 -1
  461. package/lib/security/security-config.example.d.ts +0 -33
  462. package/lib/security/security-config.example.d.ts.map +0 -1
  463. package/lib/security/security-config.example.js +0 -166
  464. package/lib/security/security-config.example.js.map +0 -1
@@ -4,85 +4,20 @@
4
4
  * 提供多层安全防护:
5
5
  * - 执行策略(exec-policy):命令执行安全
6
6
  * - 文件策略(file-policy):文件访问安全
7
- * - 网络策略(network-policy):网络访问安全
8
- * - 预算限制(budget-limiter):资源使用限制
9
7
  * - 审计日志(audit-logger):安全事件追踪
10
8
  * - 沙箱环境(sandbox):进程隔离和资源限制
11
- * - 增强沙箱(sandbox-enhanced):更细粒度的安全控制
12
- * - 异常检测(anomaly-detection):行为模式分析和异常检测
9
+ * - 增强沙箱(sandbox-enhanced):更细粒度的安全控制(experimental)
10
+ * - 异常检测(anomaly-detection):行为模式分析和异常检测(experimental)
13
11
  */
14
12
  // ── 核心安全策略 ──────────────────────────────────────────────────────
15
13
  export * from './file-policy.js';
16
14
  export * from './exec-policy.js';
17
- export * from './network-policy.js';
18
- export * from './budget-limiter.js';
19
15
  export * from './audit-logger.js';
20
- export * from './bash-tool-context.js';
16
+ export * from './comm-message-context.js';
21
17
  export * from './owner-approve-always-store.js';
22
18
  export * from './sandbox.js';
23
19
  export * from './sandbox-enhanced.js';
24
20
  export * from './anomaly-detection.js';
25
21
  export * from './file-role-policy.js';
26
22
  export * from './dangerous-tool-policy.js';
27
- import { initAuditLogger, getAuditLogger, closeAuditLogger } from './audit-logger.js';
28
- import { initNetworkPolicy, getNetworkPolicy, resetNetworkPolicy } from './network-policy.js';
29
- import { initBudgetLimiter, getBudgetLimiter, resetBudgetLimiter } from './budget-limiter.js';
30
- /**
31
- * 初始化所有安全策略
32
- */
33
- export function initSecurityPolicies(config = {}) {
34
- const auditLogger = initAuditLogger(config.audit || {});
35
- const networkPolicy = initNetworkPolicy(config.network || {});
36
- const budgetLimiter = initBudgetLimiter(config.budget || {});
37
- return { auditLogger, networkPolicy, budgetLimiter };
38
- }
39
- /**
40
- * 重置所有安全策略(用于测试隔离)
41
- */
42
- export function resetSecurityPolicies() {
43
- try {
44
- closeAuditLogger();
45
- }
46
- catch { /* ignore */ }
47
- try {
48
- resetNetworkPolicy();
49
- }
50
- catch { /* ignore */ }
51
- try {
52
- resetBudgetLimiter();
53
- }
54
- catch { /* ignore */ }
55
- }
56
- /**
57
- * 获取安全策略状态
58
- */
59
- export function getSecurityPolicyStatus() {
60
- try {
61
- const audit = getAuditLogger();
62
- const network = getNetworkPolicy();
63
- const budget = getBudgetLimiter();
64
- return {
65
- audit: {
66
- enabled: audit.getConfig().enabled,
67
- eventCount: audit.getStats().totalEvents,
68
- },
69
- network: {
70
- enabled: network.getConfig().enabled,
71
- rulesCount: (network.getConfig().allowedDomains?.length || 0) +
72
- (network.getConfig().blockedDomains?.length || 0),
73
- },
74
- budget: {
75
- enabled: budget.getConfig().enabled,
76
- activeSessions: 0,
77
- },
78
- };
79
- }
80
- catch {
81
- return {
82
- audit: { enabled: false, eventCount: 0 },
83
- network: { enabled: false, rulesCount: 0 },
84
- budget: { enabled: false, activeSessions: 0 },
85
- };
86
- }
87
- }
88
23
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/security/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,mEAAmE;AAEnE,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,iCAAiC,CAAC;AAChD,cAAc,cAAc,CAAC;AAC7B,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAK3C,OAAO,EAAe,eAAe,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAEnG,OAAO,EAAiB,iBAAiB,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAE7G,OAAO,EAAiB,iBAAiB,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAQ7G;;GAEG;AACH,MAAM,UAA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Ac,EAAE,MAAM,IAAI,CAAC,CAAC;aAC7D;YACD,MAAM,EAAE;gBACN,OAAO,EAAE,MAAM,CAAC,SAAS,EAAE,CAAC,OAAO;gBACnC,cAAc,EAAE,CAAC;aAClB;SACF,CAAC;IACJ,CAAC;IAAC,MAAM,CAAC;QACP,OAAO;YACL,KAAK,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,EAAE;YACxC,OAAO,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,EAAE;YAC1C,MAAM,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,CAAC,EAAE;SAC9C,CAAC;IACJ,CAAC;AACH,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/security/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,mEAAmE;AAEnE,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iCAAiC,CAAC;AAChD,cAAc,cAAc,CAAC;AAC7B,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC"}
@@ -1,4 +1,4 @@
1
- import type { Message, Plugin, ToolContext } from '@zhin.js/core';
1
+ import type { Message, Plugin } from '@zhin.js/core';
2
2
  export declare const OWNER_APPROVE_ALWAYS_TOOL: "bash";
3
3
  export type ToolRequesterRole = 'master' | 'trusted' | 'other' | 'unknown';
4
4
  /** 需 Owner 审批的 icqq 子命令(正则匹配整段子命令文本,大小写不敏感) */
@@ -12,44 +12,46 @@ export interface BashApprovalBotEntry {
12
12
  bashAlways?: boolean;
13
13
  bashRules: BashRuleEntry[];
14
14
  }
15
- export declare function getBotMaster(plugin: Plugin, ctx: ToolContext): string | undefined;
16
- export declare function resolveToolRequesterRole(plugin: Plugin, ctx: ToolContext): ToolRequesterRole;
17
- export declare function getOwnerToolContextOrUndefined(plugin: Plugin, message: Message<any>): ToolContext | undefined;
15
+ export declare function getEndpointMaster(plugin: Plugin, commMessage: Message): string | undefined;
16
+ export declare function resolveToolRequesterRole(plugin: Plugin, commMessage: Message): ToolRequesterRole;
17
+ export declare function getOwnerCommMessageOrUndefined(plugin: Plugin, message: Message): Message | undefined;
18
18
  /** 编排层:是否已「永久放行」bash 的 Owner 硬确认(ZHIN_NEEDS_OWNER 路径) */
19
- export declare function hasOwnerApproveAlways(plugin: Plugin, ctx: ToolContext, toolName: string): boolean;
20
- export declare function setBashAlways(plugin: Plugin, ctx: ToolContext, value: boolean): void;
21
- export declare function addOwnerApproveAlways(plugin: Plugin, ctx: ToolContext, toolName: string): {
19
+ export declare function hasOwnerApproveAlways(plugin: Plugin, commMessage: Message, toolName: string): boolean;
20
+ export declare function setBashAlways(plugin: Plugin, commMessage: Message, value: boolean): void;
21
+ export declare function addOwnerApproveAlways(plugin: Plugin, commMessage: Message, toolName: string): {
22
22
  ok: true;
23
23
  } | {
24
24
  ok: false;
25
25
  error: string;
26
26
  };
27
- export declare function removeOwnerApproveAlways(plugin: Plugin, ctx: ToolContext, toolName: string): {
27
+ export declare function removeOwnerApproveAlways(plugin: Plugin, commMessage: Message, toolName: string): {
28
28
  ok: true;
29
29
  } | {
30
30
  ok: false;
31
31
  error: string;
32
32
  };
33
- export declare function addBashApproveRule(plugin: Plugin, ctx: ToolContext, pattern: string): {
33
+ export declare function addBashApproveRule(plugin: Plugin, commMessage: Message, pattern: string): {
34
34
  ok: true;
35
35
  id: string;
36
36
  } | {
37
37
  ok: false;
38
38
  error: string;
39
39
  };
40
- export declare function removeBashApproveRule(plugin: Plugin, ctx: ToolContext, ruleId: string): {
40
+ export declare function removeBashApproveRule(plugin: Plugin, commMessage: Message, ruleId: string): {
41
41
  ok: true;
42
42
  } | {
43
43
  ok: false;
44
44
  error: string;
45
45
  };
46
46
  /** exec 策略:bashAlways 或任一 bashRules 匹配 commandLine */
47
- export declare function matchesBashOwnerExecBypass(plugin: Plugin, ctx: ToolContext, commandLine: string): boolean;
48
- export declare function formatBashApproveList(plugin: Plugin, ctx: ToolContext): string;
47
+ export declare function matchesBashOwnerExecBypass(plugin: Plugin, commMessage: Message, commandLine: string): boolean;
48
+ export declare function formatBashApproveList(plugin: Plugin, commMessage: Message): string;
49
49
  /** 兼容旧单测:返回 bash 与 rule 摘要行 */
50
- export declare function listOwnerApproveAlways(plugin: Plugin, ctx: ToolContext): string[];
50
+ export declare function listOwnerApproveAlways(plugin: Plugin, commMessage: Message): string[];
51
51
  export declare function isIcqqSensitiveSubcommand(fullSubCommand: string): boolean;
52
- export declare function setPendingOrchestrationTool(plugin: Plugin, ctx: ToolContext, toolName: string): void;
53
- export declare function clearPendingOrchestrationTool(plugin: Plugin, ctx: ToolContext): void;
54
- export declare function getPendingOrchestrationTool(plugin: Plugin, ctx: ToolContext): string | undefined;
52
+ export declare function getPendingOrchestrationCount(): number;
53
+ export declare function evictPendingOrchestrationIfOverPressure(): number;
54
+ export declare function setPendingOrchestrationTool(plugin: Plugin, commMessage: Message, toolName: string): void;
55
+ export declare function clearPendingOrchestrationTool(plugin: Plugin, commMessage: Message): void;
56
+ export declare function getPendingOrchestrationTool(plugin: Plugin, commMessage: Message): string | undefined;
55
57
  //# sourceMappingURL=owner-approve-always-store.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"owner-approve-always-store.d.ts","sourceRoot":"","sources":["../../src/security/owner-approve-always-store.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAW,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG3E,eAAO,MAAM,yBAAyB,EAAG,MAAe,CAAC;AAEzD,MAAM,MAAM,iBAAiB,GAAG,QAAQ,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,CAAC;AAK3E,+CAA+C;AAC/C,eAAO,MAAM,iCAAiC,EAAE,SAAS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EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CASxG;AAED,wBAAgB,6BAA6B,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,GAAG,IAAI,CAKxF;AAED,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAepG"}
@@ -9,6 +9,7 @@
9
9
  import * as crypto from 'node:crypto';
10
10
  import * as fs from 'node:fs';
11
11
  import * as path from 'node:path';
12
+ import { hasSenderRole, resolveSubjectRoles, senderRolesFromMessage } from '@zhin.js/core';
12
13
  import { getDataDir } from '../discovery/utils.js';
13
14
  export const OWNER_APPROVE_ALWAYS_TOOL = 'bash';
14
15
  const STORE_FILE = 'owner-approve-always.json';
@@ -39,10 +40,10 @@ function storePath() {
39
40
  return path.join(getDataDir(), STORE_FILE);
40
41
  }
41
42
  function emptyV2() {
42
- return { version: STORE_VERSION, bots: {} };
43
+ return { version: STORE_VERSION, endpoints: {} };
43
44
  }
44
- function normalizeBotKey(adapter, botId, ownerId) {
45
- return `${adapter}|${botId}|${ownerId}`;
45
+ function normalizeBotKey(adapter, endpointId, ownerId) {
46
+ return `${adapter}|${endpointId}|${ownerId}`;
46
47
  }
47
48
  function migrateV1ToV2(data) {
48
49
  const out = emptyV2();
@@ -52,12 +53,12 @@ function migrateV1ToV2(data) {
52
53
  const parts = e.split('|');
53
54
  if (parts.length !== 4)
54
55
  continue;
55
- const [adapter, botId, ownerId, scope] = parts;
56
+ const [adapter, endpointId, ownerId, scope] = parts;
56
57
  if (scope === 'orchestration:bash') {
57
- const k = normalizeBotKey(adapter, botId, ownerId);
58
- if (!out.bots[k])
59
- out.bots[k] = { bashRules: [] };
60
- out.bots[k].bashAlways = true;
58
+ const k = normalizeBotKey(adapter, endpointId, ownerId);
59
+ if (!out.endpoints[k])
60
+ out.endpoints[k] = { bashRules: [] };
61
+ out.endpoints[k].bashAlways = true;
61
62
  }
62
63
  }
63
64
  return out;
@@ -69,10 +70,10 @@ function readStore() {
69
70
  const data = JSON.parse(raw);
70
71
  if (!data || typeof data !== 'object')
71
72
  return emptyV2();
72
- if (data.version === STORE_VERSION && data.bots && typeof data.bots === 'object') {
73
+ if (data.version === STORE_VERSION && data.endpoints && typeof data.endpoints === 'object') {
73
74
  const v2 = data;
74
- for (const k of Object.keys(v2.bots)) {
75
- const ent = v2.bots[k];
75
+ for (const k of Object.keys(v2.endpoints)) {
76
+ const ent = v2.endpoints[k];
76
77
  if (!ent.bashRules)
77
78
  ent.bashRules = [];
78
79
  }
@@ -101,11 +102,11 @@ function writeStore(data) {
101
102
  fs.writeFileSync(tmp, body, 'utf-8');
102
103
  fs.renameSync(tmp, p);
103
104
  }
104
- export function getBotMaster(plugin, ctx) {
105
+ export function getEndpointMaster(plugin, commMessage) {
105
106
  const root = plugin.root ?? plugin;
106
- const adapter = root.inject(ctx.platform);
107
- const bot = adapter?.bots?.get(ctx.botId);
108
- const master = bot?.$config?.master;
107
+ const adapter = root.inject(commMessage.$adapter);
108
+ const endpoint = adapter?.endpoints?.get(commMessage.$endpoint);
109
+ const master = endpoint?.$config?.master;
109
110
  return master != null ? String(master) : undefined;
110
111
  }
111
112
  function normalizeIdList(input) {
@@ -119,92 +120,93 @@ function normalizeIdList(input) {
119
120
  }
120
121
  return [];
121
122
  }
122
- function getBotTrustedIds(plugin, ctx) {
123
+ function getEndpointTrustedIds(plugin, commMessage) {
123
124
  const root = plugin.root ?? plugin;
124
- const adapter = root.inject(ctx.platform);
125
- const bot = adapter?.bots?.get(ctx.botId);
126
- const botConfig = bot?.$config ?? {};
127
- return normalizeIdList(botConfig.trusted);
125
+ const adapter = root.inject(commMessage.$adapter);
126
+ const endpoint = adapter?.endpoints?.get(commMessage.$endpoint);
127
+ const endpointConfig = endpoint?.$config ?? {};
128
+ return normalizeIdList(endpointConfig.trusted);
128
129
  }
129
- export function resolveToolRequesterRole(plugin, ctx) {
130
- if (ctx.roles?.length) {
131
- if (ctx.roles.includes('master'))
130
+ export function resolveToolRequesterRole(plugin, commMessage) {
131
+ const roles = senderRolesFromMessage(commMessage);
132
+ if (commMessage.$sender.isMaster !== undefined || commMessage.$sender.isTrusted !== undefined) {
133
+ if (hasSenderRole(roles, 'master'))
132
134
  return 'master';
133
- if (ctx.roles.includes('trusted'))
135
+ if (hasSenderRole(roles, 'trusted'))
136
+ return 'trusted';
137
+ return 'other';
138
+ }
139
+ try {
140
+ const resolved = resolveSubjectRoles(plugin.root ?? plugin, commMessage);
141
+ if (hasSenderRole(resolved.roles, 'master'))
142
+ return 'master';
143
+ if (hasSenderRole(resolved.roles, 'trusted'))
144
+ return 'trusted';
145
+ return 'other';
146
+ }
147
+ catch {
148
+ if (!commMessage.$adapter || !commMessage.$endpoint || !commMessage.$sender?.id)
149
+ return 'unknown';
150
+ const senderId = String(commMessage.$sender.id);
151
+ const masterId = getEndpointMaster(plugin, commMessage);
152
+ if (masterId && senderId === String(masterId))
153
+ return 'master';
154
+ const trusted = getEndpointTrustedIds(plugin, commMessage);
155
+ if (trusted.includes(senderId))
134
156
  return 'trusted';
135
157
  return 'other';
136
158
  }
137
- if (!ctx.platform || !ctx.botId || !ctx.senderId)
138
- return 'unknown';
139
- const senderId = String(ctx.senderId);
140
- const masterId = getBotMaster(plugin, ctx);
141
- if (masterId && senderId === String(masterId))
142
- return 'master';
143
- const trusted = getBotTrustedIds(plugin, ctx);
144
- if (trusted.includes(senderId))
145
- return 'trusted';
146
- return 'other';
147
159
  }
148
- function getEntry(plugin, ctx) {
149
- if (!ctx.platform || !ctx.botId)
160
+ function getEntry(plugin, commMessage) {
161
+ if (!commMessage.$adapter || !commMessage.$endpoint)
150
162
  return undefined;
151
- const ownerId = getBotMaster(plugin, ctx);
163
+ const ownerId = getEndpointMaster(plugin, commMessage);
152
164
  if (ownerId == null)
153
165
  return undefined;
154
- const key = normalizeBotKey(ctx.platform, ctx.botId, ownerId);
166
+ const key = normalizeBotKey(String(commMessage.$adapter), commMessage.$endpoint, ownerId);
155
167
  const data = readStore();
156
- return data.bots[key];
168
+ return data.endpoints[key];
157
169
  }
158
- function ensureEntry(plugin, ctx) {
159
- if (!ctx.platform || !ctx.botId)
170
+ function ensureEntry(plugin, commMessage) {
171
+ if (!commMessage.$adapter || !commMessage.$endpoint)
160
172
  return { bashRules: [] };
161
- const ownerId = getBotMaster(plugin, ctx);
173
+ const ownerId = getEndpointMaster(plugin, commMessage);
162
174
  if (ownerId == null)
163
175
  return { bashRules: [] };
164
- const key = normalizeBotKey(ctx.platform, ctx.botId, ownerId);
176
+ const key = normalizeBotKey(String(commMessage.$adapter), commMessage.$endpoint, ownerId);
165
177
  const data = readStore();
166
- if (!data.bots[key]) {
167
- data.bots[key] = { bashRules: [] };
178
+ if (!data.endpoints[key]) {
179
+ data.endpoints[key] = { bashRules: [] };
168
180
  writeStore(data);
169
181
  }
170
- return data.bots[key];
182
+ return data.endpoints[key];
171
183
  }
172
- export function getOwnerToolContextOrUndefined(plugin, message) {
184
+ export function getOwnerCommMessageOrUndefined(plugin, message) {
173
185
  if (message.$channel?.type !== 'private')
174
186
  return undefined;
175
- const ctx = {
176
- platform: message.$adapter,
177
- botId: message.$bot,
178
- sceneId: message.$channel?.id ?? message.$sender.id,
179
- senderId: message.$sender.id,
180
- message,
181
- scope: 'private',
182
- roles: ['master'],
183
- fileRole: 'owner',
184
- };
185
- const ownerId = getBotMaster(plugin, ctx);
187
+ const ownerId = getEndpointMaster(plugin, message);
186
188
  if (ownerId == null || String(message.$sender.id) !== String(ownerId))
187
189
  return undefined;
188
- return ctx;
190
+ return message;
189
191
  }
190
192
  /** 编排层:是否已「永久放行」bash 的 Owner 硬确认(ZHIN_NEEDS_OWNER 路径) */
191
- export function hasOwnerApproveAlways(plugin, ctx, toolName) {
193
+ export function hasOwnerApproveAlways(plugin, commMessage, toolName) {
192
194
  if (toolName !== OWNER_APPROVE_ALWAYS_TOOL)
193
195
  return false;
194
- if (!ctx.platform || !ctx.botId)
196
+ if (!commMessage.$adapter || !commMessage.$endpoint)
195
197
  return false;
196
- const ent = getEntry(plugin, ctx);
198
+ const ent = getEntry(plugin, commMessage);
197
199
  return !!ent?.bashAlways;
198
200
  }
199
- export function setBashAlways(plugin, ctx, value) {
200
- if (!ctx.platform || !ctx.botId)
201
+ export function setBashAlways(plugin, commMessage, value) {
202
+ if (!commMessage.$adapter || !commMessage.$endpoint)
201
203
  return;
202
- const ownerId = getBotMaster(plugin, ctx);
204
+ const ownerId = getEndpointMaster(plugin, commMessage);
203
205
  if (ownerId == null)
204
206
  return;
205
- const key = normalizeBotKey(ctx.platform, ctx.botId, ownerId);
207
+ const key = normalizeBotKey(String(commMessage.$adapter), commMessage.$endpoint, ownerId);
206
208
  const data = readStore();
207
- const prev = data.bots[key] ?? { bashRules: [] };
209
+ const prev = data.endpoints[key] ?? { bashRules: [] };
208
210
  const ent = { bashRules: prev.bashRules ?? [] };
209
211
  if (prev.bashAlways !== undefined)
210
212
  ent.bashAlways = prev.bashAlways;
@@ -212,77 +214,76 @@ export function setBashAlways(plugin, ctx, value) {
212
214
  ent.bashAlways = true;
213
215
  else
214
216
  delete ent.bashAlways;
215
- data.bots[key] = ent;
217
+ data.endpoints[key] = ent;
216
218
  writeStore(data);
217
219
  }
218
- export function addOwnerApproveAlways(plugin, ctx, toolName) {
219
- if (!ctx.platform || !ctx.botId) {
220
- return { ok: false, error: '缺少 platform / botId' };
220
+ export function addOwnerApproveAlways(plugin, commMessage, toolName) {
221
+ if (!commMessage.$adapter || !commMessage.$endpoint) {
222
+ return { ok: false, error: '缺少 platform / endpointId' };
221
223
  }
222
224
  if (toolName.trim().toLowerCase() !== OWNER_APPROVE_ALWAYS_TOOL) {
223
225
  return { ok: false, error: '永久放行仅支持 bash(shell 安全确认)。' };
224
226
  }
225
- if (getBotMaster(plugin, ctx) == null) {
226
- return { ok: false, error: '当前 Bot 未配置 owner' };
227
+ if (getEndpointMaster(plugin, commMessage) == null) {
228
+ return { ok: false, error: '当前 Endpoint 未配置 owner' };
227
229
  }
228
- setBashAlways(plugin, ctx, true);
230
+ setBashAlways(plugin, commMessage, true);
229
231
  return { ok: true };
230
232
  }
231
- export function removeOwnerApproveAlways(plugin, ctx, toolName) {
232
- if (!ctx.platform || !ctx.botId) {
233
- return { ok: false, error: '缺少 platform / botId' };
233
+ export function removeOwnerApproveAlways(plugin, commMessage, toolName) {
234
+ if (!commMessage.$adapter || !commMessage.$endpoint) {
235
+ return { ok: false, error: '缺少 platform / endpointId' };
234
236
  }
235
237
  if (toolName.trim().toLowerCase() !== OWNER_APPROVE_ALWAYS_TOOL) {
236
238
  return { ok: false, error: '仅可撤销 bash 的永久放行。' };
237
239
  }
238
- if (getBotMaster(plugin, ctx) == null) {
239
- return { ok: false, error: '当前 Bot 未配置 owner' };
240
+ if (getEndpointMaster(plugin, commMessage) == null) {
241
+ return { ok: false, error: '当前 Endpoint 未配置 owner' };
240
242
  }
241
- const ent = getEntry(plugin, ctx);
243
+ const ent = getEntry(plugin, commMessage);
242
244
  if (!ent?.bashAlways) {
243
245
  return { ok: false, error: '当前未对 bash 设置永久放行。' };
244
246
  }
245
- setBashAlways(plugin, ctx, false);
247
+ setBashAlways(plugin, commMessage, false);
246
248
  return { ok: true };
247
249
  }
248
- export function addBashApproveRule(plugin, ctx, pattern) {
250
+ export function addBashApproveRule(plugin, commMessage, pattern) {
249
251
  const trimmed = pattern.trim();
250
252
  if (!trimmed) {
251
253
  return { ok: false, error: '正则不能为空。' };
252
254
  }
253
255
  try {
254
- // eslint-disable-next-line no-new
255
256
  new RegExp(trimmed);
256
257
  }
257
258
  catch (e) {
258
259
  return { ok: false, error: `无效正则: ${e instanceof Error ? e.message : String(e)}` };
259
260
  }
260
- if (!ctx.platform || !ctx.botId || getBotMaster(plugin, ctx) == null) {
261
- return { ok: false, error: '缺少 platform/botId 或未配置 owner。' };
261
+ if (!commMessage.$adapter || !commMessage.$endpoint || getEndpointMaster(plugin, commMessage) == null) {
262
+ return { ok: false, error: '缺少 platform/endpointId 或未配置 owner。' };
262
263
  }
263
- const ownerId = getBotMaster(plugin, ctx);
264
- const key = normalizeBotKey(ctx.platform, ctx.botId, ownerId);
264
+ const ownerId = getEndpointMaster(plugin, commMessage);
265
+ const key = normalizeBotKey(String(commMessage.$adapter), commMessage.$endpoint, ownerId);
265
266
  const data = readStore();
266
- const ent = { ...(data.bots[key] ?? { bashRules: [] }), bashRules: [...(data.bots[key]?.bashRules ?? [])] };
267
- if (data.bots[key]?.bashAlways)
267
+ const ent = { ...(data.endpoints[key] ?? { bashRules: [] }), bashRules: [...(data.endpoints[key]?.bashRules ?? [])] };
268
+ if (data.endpoints[key]?.bashAlways)
268
269
  ent.bashAlways = true;
269
270
  const id = crypto.randomUUID();
270
271
  ent.bashRules.push({ id, pattern: trimmed, createdAt: Date.now() });
271
- data.bots[key] = ent;
272
+ data.endpoints[key] = ent;
272
273
  writeStore(data);
273
274
  return { ok: true, id };
274
275
  }
275
- export function removeBashApproveRule(plugin, ctx, ruleId) {
276
+ export function removeBashApproveRule(plugin, commMessage, ruleId) {
276
277
  const id = ruleId.trim();
277
278
  if (!id)
278
279
  return { ok: false, error: '请提供规则 id。' };
279
- if (!ctx.platform || !ctx.botId || getBotMaster(plugin, ctx) == null) {
280
- return { ok: false, error: '缺少 platform/botId 或未配置 owner。' };
280
+ if (!commMessage.$adapter || !commMessage.$endpoint || getEndpointMaster(plugin, commMessage) == null) {
281
+ return { ok: false, error: '缺少 platform/endpointId 或未配置 owner。' };
281
282
  }
282
- const ownerId = getBotMaster(plugin, ctx);
283
- const key = normalizeBotKey(ctx.platform, ctx.botId, ownerId);
283
+ const ownerId = getEndpointMaster(plugin, commMessage);
284
+ const key = normalizeBotKey(String(commMessage.$adapter), commMessage.$endpoint, ownerId);
284
285
  const data = readStore();
285
- const ent = data.bots[key];
286
+ const ent = data.endpoints[key];
286
287
  if (!ent?.bashRules?.length)
287
288
  return { ok: false, error: '当前无自定义规则。' };
288
289
  const next = ent.bashRules.filter((r) => r.id !== id && !r.id.startsWith(id));
@@ -290,15 +291,15 @@ export function removeBashApproveRule(plugin, ctx, ruleId) {
290
291
  return { ok: false, error: `未找到 id 前缀或全名为「${id}」的规则。` };
291
292
  }
292
293
  ent.bashRules = next;
293
- data.bots[key] = ent;
294
+ data.endpoints[key] = ent;
294
295
  writeStore(data);
295
296
  return { ok: true };
296
297
  }
297
298
  /** exec 策略:bashAlways 或任一 bashRules 匹配 commandLine */
298
- export function matchesBashOwnerExecBypass(plugin, ctx, commandLine) {
299
- if (!ctx.platform || !ctx.botId)
299
+ export function matchesBashOwnerExecBypass(plugin, commMessage, commandLine) {
300
+ if (!commMessage.$adapter || !commMessage.$endpoint)
300
301
  return false;
301
- const ent = getEntry(plugin, ctx);
302
+ const ent = getEntry(plugin, commMessage);
302
303
  if (!ent)
303
304
  return false;
304
305
  if (ent.bashAlways)
@@ -318,8 +319,8 @@ export function matchesBashOwnerExecBypass(plugin, ctx, commandLine) {
318
319
  }
319
320
  return false;
320
321
  }
321
- export function formatBashApproveList(plugin, ctx) {
322
- const ent = getEntry(plugin, ctx);
322
+ export function formatBashApproveList(plugin, commMessage) {
323
+ const ent = getEntry(plugin, commMessage);
323
324
  const always = ent?.bashAlways ? '是' : '否';
324
325
  const rules = ent?.bashRules ?? [];
325
326
  if (!ent || (!ent.bashAlways && rules.length === 0)) {
@@ -333,8 +334,8 @@ export function formatBashApproveList(plugin, ctx) {
333
334
  return lines.join('\n');
334
335
  }
335
336
  /** 兼容旧单测:返回 bash 与 rule 摘要行 */
336
- export function listOwnerApproveAlways(plugin, ctx) {
337
- const ent = getEntry(plugin, ctx);
337
+ export function listOwnerApproveAlways(plugin, commMessage) {
338
+ const ent = getEntry(plugin, commMessage);
338
339
  const out = [];
339
340
  if (ent?.bashAlways)
340
341
  out.push(OWNER_APPROVE_ALWAYS_TOOL);
@@ -350,37 +351,51 @@ export function isIcqqSensitiveSubcommand(fullSubCommand) {
350
351
  return ICQQ_SENSITIVE_SUBCOMMAND_REGEXES.some((re) => re.test(line));
351
352
  }
352
353
  const pendingOrchestration = new Map();
353
- function pendingKey(adapter, botId, ownerId) {
354
- return `${adapter}|${botId}|${ownerId}`;
354
+ function pendingKey(adapter, endpointId, ownerId) {
355
+ return `${adapter}|${endpointId}|${ownerId}`;
356
+ }
357
+ export function getPendingOrchestrationCount() {
358
+ return pendingOrchestration.size;
359
+ }
360
+ export function evictPendingOrchestrationIfOverPressure() {
361
+ const now = Date.now();
362
+ let removed = 0;
363
+ for (const [key, value] of pendingOrchestration) {
364
+ if (now > value.expiresAt) {
365
+ pendingOrchestration.delete(key);
366
+ removed++;
367
+ }
368
+ }
369
+ return removed;
355
370
  }
356
- export function setPendingOrchestrationTool(plugin, ctx, toolName) {
371
+ export function setPendingOrchestrationTool(plugin, commMessage, toolName) {
357
372
  if (toolName !== OWNER_APPROVE_ALWAYS_TOOL)
358
373
  return;
359
- if (!ctx.platform || !ctx.botId)
374
+ if (!commMessage.$adapter || !commMessage.$endpoint)
360
375
  return;
361
- const ownerId = getBotMaster(plugin, ctx);
376
+ const ownerId = getEndpointMaster(plugin, commMessage);
362
377
  if (ownerId == null)
363
378
  return;
364
- pendingOrchestration.set(pendingKey(ctx.platform, ctx.botId, ownerId), {
379
+ pendingOrchestration.set(pendingKey(String(commMessage.$adapter), commMessage.$endpoint, ownerId), {
365
380
  toolName: OWNER_APPROVE_ALWAYS_TOOL,
366
381
  expiresAt: Date.now() + 15 * 60 * 1000,
367
382
  });
368
383
  }
369
- export function clearPendingOrchestrationTool(plugin, ctx) {
370
- if (!ctx.platform || !ctx.botId)
384
+ export function clearPendingOrchestrationTool(plugin, commMessage) {
385
+ if (!commMessage.$adapter || !commMessage.$endpoint)
371
386
  return;
372
- const ownerId = getBotMaster(plugin, ctx);
387
+ const ownerId = getEndpointMaster(plugin, commMessage);
373
388
  if (ownerId == null)
374
389
  return;
375
- pendingOrchestration.delete(pendingKey(ctx.platform, ctx.botId, ownerId));
390
+ pendingOrchestration.delete(pendingKey(String(commMessage.$adapter), commMessage.$endpoint, ownerId));
376
391
  }
377
- export function getPendingOrchestrationTool(plugin, ctx) {
378
- if (!ctx.platform || !ctx.botId)
392
+ export function getPendingOrchestrationTool(plugin, commMessage) {
393
+ if (!commMessage.$adapter || !commMessage.$endpoint)
379
394
  return undefined;
380
- const ownerId = getBotMaster(plugin, ctx);
395
+ const ownerId = getEndpointMaster(plugin, commMessage);
381
396
  if (ownerId == null)
382
397
  return undefined;
383
- const key = pendingKey(ctx.platform, ctx.botId, ownerId);
398
+ const key = pendingKey(String(commMessage.$adapter), commMessage.$endpoint, ownerId);
384
399
  const p = pendingOrchestration.get(key);
385
400
  if (!p || p.toolName !== OWNER_APPROVE_ALWAYS_TOOL) {
386
401
  if (p)