@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.
- package/README.md +1 -1
- package/lib/agent-prompt/resolver.d.ts.map +1 -1
- package/lib/agent-prompt/resolver.js +4 -4
- package/lib/agent-prompt/resolver.js.map +1 -1
- package/lib/ai-event-bus.d.ts.map +1 -1
- package/lib/ai-event-bus.js +20 -31
- package/lib/ai-event-bus.js.map +1 -1
- package/lib/ai-event-subscriber.d.ts +1 -1
- package/lib/ai-event-subscriber.d.ts.map +1 -1
- package/lib/ai-event-subscriber.js +1 -1
- package/lib/ai-event-subscriber.js.map +1 -1
- package/lib/assistant/home-mcp-bridge.d.ts +1 -1
- package/lib/assistant/home-mcp-bridge.d.ts.map +1 -1
- package/lib/assistant/home-policy.d.ts +2 -2
- package/lib/assistant/home-policy.d.ts.map +1 -1
- package/lib/assistant/home-policy.js +28 -10
- package/lib/assistant/home-policy.js.map +1 -1
- package/lib/assistant/home-tools.js +14 -14
- package/lib/assistant/home-tools.js.map +1 -1
- package/lib/assistant/index.d.ts +1 -1
- package/lib/assistant/index.js +1 -1
- package/lib/assistant/legacy-convert.d.ts +3 -8
- package/lib/assistant/legacy-convert.d.ts.map +1 -1
- package/lib/assistant/legacy-convert.js +8 -8
- package/lib/assistant/legacy-convert.js.map +1 -1
- package/lib/assistant/notification-router.js +6 -6
- package/lib/assistant/notification-router.js.map +1 -1
- package/lib/assistant/types.d.ts +1 -1
- package/lib/assistant/types.d.ts.map +1 -1
- package/lib/builtin/activate-skill-tool.d.ts +2 -2
- package/lib/builtin/activate-skill-tool.d.ts.map +1 -1
- package/lib/builtin/activate-skill-tool.js +1 -1
- package/lib/builtin/activate-skill-tool.js.map +1 -1
- package/lib/builtin/analyze-media-tool.d.ts +2 -2
- package/lib/builtin/analyze-media-tool.d.ts.map +1 -1
- package/lib/builtin/analyze-media-tool.js +3 -3
- package/lib/builtin/analyze-media-tool.js.map +1 -1
- package/lib/builtin/ask-user-tool.d.ts +4 -4
- package/lib/builtin/ask-user-tool.d.ts.map +1 -1
- package/lib/builtin/ask-user-tool.js +16 -16
- package/lib/builtin/ask-user-tool.js.map +1 -1
- package/lib/builtin/bash-tool.d.ts +2 -2
- package/lib/builtin/bash-tool.d.ts.map +1 -1
- package/lib/builtin/bash-tool.js +8 -3
- package/lib/builtin/bash-tool.js.map +1 -1
- package/lib/builtin/builtin-base-tool.d.ts +2 -2
- package/lib/builtin/builtin-base-tool.d.ts.map +1 -1
- package/lib/builtin/edit-file-tool.d.ts +2 -2
- package/lib/builtin/edit-file-tool.d.ts.map +1 -1
- package/lib/builtin/edit-file-tool.js +6 -6
- package/lib/builtin/edit-file-tool.js.map +1 -1
- package/lib/builtin/glob-tool.d.ts +2 -2
- package/lib/builtin/glob-tool.d.ts.map +1 -1
- package/lib/builtin/glob-tool.js +3 -3
- package/lib/builtin/glob-tool.js.map +1 -1
- package/lib/builtin/grep-tool.d.ts +2 -2
- package/lib/builtin/grep-tool.d.ts.map +1 -1
- package/lib/builtin/grep-tool.js +3 -3
- package/lib/builtin/grep-tool.js.map +1 -1
- package/lib/builtin/install-skill-tool.d.ts +2 -2
- package/lib/builtin/install-skill-tool.d.ts.map +1 -1
- package/lib/builtin/install-skill-tool.js +1 -1
- package/lib/builtin/install-skill-tool.js.map +1 -1
- package/lib/builtin/knowledge-search-tool.d.ts +6 -0
- package/lib/builtin/knowledge-search-tool.d.ts.map +1 -0
- package/lib/builtin/knowledge-search-tool.js +184 -0
- package/lib/builtin/knowledge-search-tool.js.map +1 -0
- package/lib/builtin/list-dir-tool.d.ts +2 -2
- package/lib/builtin/list-dir-tool.d.ts.map +1 -1
- package/lib/builtin/list-dir-tool.js +3 -3
- package/lib/builtin/list-dir-tool.js.map +1 -1
- package/lib/builtin/memory-search-tool.d.ts.map +1 -1
- package/lib/builtin/memory-search-tool.js +5 -11
- package/lib/builtin/memory-search-tool.js.map +1 -1
- package/lib/builtin/memory-upsert-tool.d.ts.map +1 -1
- package/lib/builtin/memory-upsert-tool.js +10 -16
- package/lib/builtin/memory-upsert-tool.js.map +1 -1
- package/lib/builtin/orchestration-tools.d.ts +3 -2
- package/lib/builtin/orchestration-tools.d.ts.map +1 -1
- package/lib/builtin/orchestration-tools.js +5 -11
- package/lib/builtin/orchestration-tools.js.map +1 -1
- package/lib/builtin/read-file-tool.d.ts +2 -2
- package/lib/builtin/read-file-tool.d.ts.map +1 -1
- package/lib/builtin/read-file-tool.js +4 -4
- package/lib/builtin/read-file-tool.js.map +1 -1
- package/lib/builtin/run-spec-dry-run-tool.d.ts +1 -4
- package/lib/builtin/run-spec-dry-run-tool.d.ts.map +1 -1
- package/lib/builtin/run-spec-dry-run-tool.js.map +1 -1
- package/lib/builtin/run-validation-spec-tool.d.ts +1 -4
- package/lib/builtin/run-validation-spec-tool.d.ts.map +1 -1
- package/lib/builtin/run-validation-spec-tool.js.map +1 -1
- package/lib/builtin/spawn-task-tool.d.ts +7 -6
- package/lib/builtin/spawn-task-tool.d.ts.map +1 -1
- package/lib/builtin/spawn-task-tool.js +10 -17
- package/lib/builtin/spawn-task-tool.js.map +1 -1
- package/lib/builtin/todo-read-tool.d.ts +2 -2
- package/lib/builtin/todo-read-tool.d.ts.map +1 -1
- package/lib/builtin/todo-read-tool.js +1 -1
- package/lib/builtin/todo-read-tool.js.map +1 -1
- package/lib/builtin/todo-write-tool.d.ts +2 -2
- package/lib/builtin/todo-write-tool.d.ts.map +1 -1
- package/lib/builtin/todo-write-tool.js +1 -1
- package/lib/builtin/todo-write-tool.js.map +1 -1
- package/lib/builtin/web-fetch-tool.d.ts +4 -2
- package/lib/builtin/web-fetch-tool.d.ts.map +1 -1
- package/lib/builtin/web-fetch-tool.js +55 -10
- package/lib/builtin/web-fetch-tool.js.map +1 -1
- package/lib/builtin/web-search-locale.d.ts +4 -4
- package/lib/builtin/web-search-locale.d.ts.map +1 -1
- package/lib/builtin/web-search-locale.js +4 -3
- package/lib/builtin/web-search-locale.js.map +1 -1
- package/lib/builtin/web-search-tool.d.ts +3 -3
- package/lib/builtin/web-search-tool.d.ts.map +1 -1
- package/lib/builtin/web-search-tool.js +3 -3
- package/lib/builtin/web-search-tool.js.map +1 -1
- package/lib/builtin/write-file-tool.d.ts +2 -2
- package/lib/builtin/write-file-tool.d.ts.map +1 -1
- package/lib/builtin/write-file-tool.js +6 -6
- package/lib/builtin/write-file-tool.js.map +1 -1
- package/lib/builtin-tools.d.ts +2 -0
- package/lib/builtin-tools.d.ts.map +1 -1
- package/lib/builtin-tools.js +4 -0
- package/lib/builtin-tools.js.map +1 -1
- package/lib/common-adapter-tools.js +3 -3
- package/lib/common-adapter-tools.js.map +1 -1
- package/lib/config/fix-ai-config.d.ts +9 -0
- package/lib/config/fix-ai-config.d.ts.map +1 -0
- package/lib/config/fix-ai-config.js +69 -0
- package/lib/config/fix-ai-config.js.map +1 -0
- package/lib/config/index.d.ts +5 -0
- package/lib/config/index.d.ts.map +1 -0
- package/lib/config/index.js +5 -0
- package/lib/config/index.js.map +1 -0
- package/lib/config/normalize-ai-config.d.ts +1 -1
- package/lib/config/normalize-ai-config.d.ts.map +1 -1
- package/lib/config/provider-instance.d.ts +1 -1
- package/lib/config/provider-instance.d.ts.map +1 -1
- package/lib/config/provider-instance.js +1 -1
- package/lib/config/provider-instance.js.map +1 -1
- package/lib/config/types.d.ts +2 -2
- package/lib/config/types.d.ts.map +1 -1
- package/lib/create-agent-session.d.ts +1 -1
- package/lib/create-agent-session.d.ts.map +1 -1
- package/lib/cron-engine.d.ts.map +1 -1
- package/lib/cron-engine.js +4 -4
- package/lib/cron-engine.js.map +1 -1
- package/lib/deferred-worker-runner.d.ts +3 -3
- package/lib/deferred-worker-runner.d.ts.map +1 -1
- package/lib/deferred-worker-runner.js +3 -3
- package/lib/discovery/tools.d.ts +1 -1
- package/lib/discovery/tools.d.ts.map +1 -1
- package/lib/discovery/tools.js +21 -6
- package/lib/discovery/tools.js.map +1 -1
- package/lib/hooks.d.ts +1 -1
- package/lib/hooks.d.ts.map +1 -1
- package/lib/hooks.js +1 -1
- package/lib/hooks.js.map +1 -1
- package/lib/index.d.ts +5 -22
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +3 -11
- package/lib/index.js.map +1 -1
- package/lib/init/activate-ai-database-storage.d.ts +1 -1
- package/lib/init/activate-ai-database-storage.d.ts.map +1 -1
- package/lib/init/activate-ai-database-storage.js +12 -8
- package/lib/init/activate-ai-database-storage.js.map +1 -1
- package/lib/init/create-zhin-agent.d.ts.map +1 -1
- package/lib/init/create-zhin-agent.js +38 -15
- package/lib/init/create-zhin-agent.js.map +1 -1
- package/lib/init/introspection-args.d.ts +1 -1
- package/lib/init/introspection-args.js +1 -1
- package/lib/init/introspection-args.js.map +1 -1
- package/lib/init/introspection-collectors.d.ts +2 -2
- package/lib/init/introspection-collectors.d.ts.map +1 -1
- package/lib/init/introspection-collectors.js +4 -4
- package/lib/init/introspection-collectors.js.map +1 -1
- package/lib/init/introspection-commands-format.d.ts +3 -3
- package/lib/init/introspection-commands-format.d.ts.map +1 -1
- package/lib/init/introspection-commands-format.js +6 -6
- package/lib/init/introspection-commands-format.js.map +1 -1
- package/lib/init/introspection-rest.d.ts +2 -2
- package/lib/init/introspection-rest.d.ts.map +1 -1
- package/lib/init/introspection-rest.js +4 -4
- package/lib/init/introspection-rest.js.map +1 -1
- package/lib/init/management-command-guard.d.ts +3 -3
- package/lib/init/management-command-guard.d.ts.map +1 -1
- package/lib/init/management-command-guard.js +3 -3
- package/lib/init/management-command-guard.js.map +1 -1
- package/lib/init/message-media.d.ts +4 -3
- package/lib/init/message-media.d.ts.map +1 -1
- package/lib/init/message-media.js +1 -1
- package/lib/init/message-media.js.map +1 -1
- package/lib/init/register-ai-trigger.d.ts.map +1 -1
- package/lib/init/register-ai-trigger.js +43 -58
- package/lib/init/register-ai-trigger.js.map +1 -1
- package/lib/init/register-builtin-tools.d.ts.map +1 -1
- package/lib/init/register-builtin-tools.js +6 -3
- package/lib/init/register-builtin-tools.js.map +1 -1
- package/lib/init/register-db-upgrade.d.ts.map +1 -1
- package/lib/init/register-db-upgrade.js +2 -0
- package/lib/init/register-db-upgrade.js.map +1 -1
- package/lib/init/register-group-session-passive.d.ts.map +1 -1
- package/lib/init/register-group-session-passive.js +5 -10
- package/lib/init/register-group-session-passive.js.map +1 -1
- package/lib/init/register-introspection-commands.js +7 -7
- package/lib/init/register-introspection-commands.js.map +1 -1
- package/lib/init/register-management-tools.d.ts.map +1 -1
- package/lib/init/register-management-tools.js +8 -29
- package/lib/init/register-management-tools.js.map +1 -1
- package/lib/init/register-owner-approve-commands.js +13 -13
- package/lib/init/register-owner-approve-commands.js.map +1 -1
- package/lib/init/register-typing-indicator.d.ts +3 -3
- package/lib/init/register-typing-indicator.js +41 -41
- package/lib/init/register-typing-indicator.js.map +1 -1
- package/lib/init/upgrade-agent-db-schema.d.ts.map +1 -1
- package/lib/init/upgrade-agent-db-schema.js +5 -4
- package/lib/init/upgrade-agent-db-schema.js.map +1 -1
- package/lib/init/upgrade-endpoint-id-schema.d.ts +12 -0
- package/lib/init/upgrade-endpoint-id-schema.d.ts.map +1 -0
- package/lib/init/upgrade-endpoint-id-schema.js +58 -0
- package/lib/init/upgrade-endpoint-id-schema.js.map +1 -0
- package/lib/mcp-client/connection.d.ts.map +1 -1
- package/lib/mcp-client/connection.js +38 -2
- package/lib/mcp-client/connection.js.map +1 -1
- package/lib/media/constants.d.ts +1 -1
- package/lib/media/constants.d.ts.map +1 -1
- package/lib/media/constants.js +1 -1
- package/lib/media/constants.js.map +1 -1
- package/lib/media/deliver-subagent-result.d.ts.map +1 -1
- package/lib/media/deliver-subagent-result.js +6 -5
- package/lib/media/deliver-subagent-result.js.map +1 -1
- package/lib/memory-layers.d.ts +3 -3
- package/lib/memory-layers.d.ts.map +1 -1
- package/lib/memory-layers.js +3 -3
- package/lib/memory-layers.js.map +1 -1
- package/lib/orchestrator/agent-dispatcher.d.ts +1 -1
- package/lib/orchestrator/agent-dispatcher.d.ts.map +1 -1
- package/lib/orchestrator/delegation-processor.d.ts.map +1 -1
- package/lib/orchestrator/delegation-processor.js +8 -8
- package/lib/orchestrator/delegation-processor.js.map +1 -1
- package/lib/orchestrator/hook-registry.js.map +1 -1
- package/lib/orchestrator/mission-milestone-notify.d.ts +3 -3
- package/lib/orchestrator/mission-milestone-notify.d.ts.map +1 -1
- package/lib/orchestrator/mission-milestone-notify.js +15 -10
- package/lib/orchestrator/mission-milestone-notify.js.map +1 -1
- package/lib/orchestrator/mission-runner.d.ts +2 -3
- package/lib/orchestrator/mission-runner.d.ts.map +1 -1
- package/lib/orchestrator/mission-runner.js +13 -11
- package/lib/orchestrator/mission-runner.js.map +1 -1
- package/lib/orchestrator/orchestration-repository.d.ts +6 -0
- package/lib/orchestrator/orchestration-repository.d.ts.map +1 -1
- package/lib/orchestrator/orchestration-repository.js +30 -0
- package/lib/orchestrator/orchestration-repository.js.map +1 -1
- package/lib/orchestrator/owner-confirm-orchestration.d.ts +3 -3
- package/lib/orchestrator/owner-confirm-orchestration.d.ts.map +1 -1
- package/lib/orchestrator/owner-confirm-orchestration.js +5 -5
- package/lib/orchestrator/owner-confirm-orchestration.js.map +1 -1
- package/lib/orchestrator/remote-agent-registry.d.ts +1 -1
- package/lib/orchestrator/remote-agent-registry.d.ts.map +1 -1
- package/lib/orchestrator/tool-registry.d.ts +4 -5
- package/lib/orchestrator/tool-registry.d.ts.map +1 -1
- package/lib/orchestrator/tool-registry.js +7 -11
- package/lib/orchestrator/tool-registry.js.map +1 -1
- package/lib/orchestrator/tool-selection.d.ts +7 -6
- package/lib/orchestrator/tool-selection.d.ts.map +1 -1
- package/lib/orchestrator/tool-selection.js +47 -38
- package/lib/orchestrator/tool-selection.js.map +1 -1
- package/lib/orchestrator/types.d.ts +3 -6
- package/lib/orchestrator/types.d.ts.map +1 -1
- package/lib/routing/route-matcher.d.ts +1 -1
- package/lib/routing/route-matcher.d.ts.map +1 -1
- package/lib/routing/route-matcher.js +3 -3
- package/lib/routing/route-matcher.js.map +1 -1
- package/lib/routing/runtime-binding.d.ts +1 -1
- package/lib/routing/runtime-binding.d.ts.map +1 -1
- package/lib/security/audit-logger.d.ts +4 -3
- package/lib/security/audit-logger.d.ts.map +1 -1
- package/lib/security/audit-logger.js +14 -4
- package/lib/security/audit-logger.js.map +1 -1
- package/lib/security/comm-message-context.d.ts +20 -0
- package/lib/security/comm-message-context.d.ts.map +1 -0
- package/lib/security/comm-message-context.js +19 -0
- package/lib/security/comm-message-context.js.map +1 -0
- package/lib/security/dangerous-tool-policy.d.ts +4 -4
- package/lib/security/dangerous-tool-policy.d.ts.map +1 -1
- package/lib/security/dangerous-tool-policy.js +43 -33
- package/lib/security/dangerous-tool-policy.js.map +1 -1
- package/lib/security/exec-policy.d.ts +1 -1
- package/lib/security/exec-policy.d.ts.map +1 -1
- package/lib/security/exec-policy.js +56 -9
- package/lib/security/exec-policy.js.map +1 -1
- package/lib/security/file-role-policy.d.ts +1 -1
- package/lib/security/file-role-policy.d.ts.map +1 -1
- package/lib/security/file-role-policy.js +4 -5
- package/lib/security/file-role-policy.js.map +1 -1
- package/lib/security/index.d.ts +3 -47
- package/lib/security/index.d.ts.map +1 -1
- package/lib/security/index.js +3 -68
- package/lib/security/index.js.map +1 -1
- package/lib/security/owner-approve-always-store.d.ts +18 -16
- package/lib/security/owner-approve-always-store.d.ts.map +1 -1
- package/lib/security/owner-approve-always-store.js +133 -118
- package/lib/security/owner-approve-always-store.js.map +1 -1
- package/lib/security/sandbox-docker.d.ts +28 -0
- package/lib/security/sandbox-docker.d.ts.map +1 -0
- package/lib/security/sandbox-docker.js +177 -0
- package/lib/security/sandbox-docker.js.map +1 -0
- package/lib/security/sandbox.d.ts +9 -0
- package/lib/security/sandbox.d.ts.map +1 -1
- package/lib/security/sandbox.js +215 -14
- package/lib/security/sandbox.js.map +1 -1
- package/lib/service.d.ts +4 -5
- package/lib/service.d.ts.map +1 -1
- package/lib/service.js +8 -9
- package/lib/service.js.map +1 -1
- package/lib/stability/memory-pressure.d.ts +31 -0
- package/lib/stability/memory-pressure.d.ts.map +1 -0
- package/lib/stability/memory-pressure.js +104 -0
- package/lib/stability/memory-pressure.js.map +1 -0
- package/lib/stability/registry-cleanup.d.ts +5 -0
- package/lib/stability/registry-cleanup.d.ts.map +1 -0
- package/lib/stability/registry-cleanup.js +20 -0
- package/lib/stability/registry-cleanup.js.map +1 -0
- package/lib/subagent-ai-events.d.ts +2 -2
- package/lib/subagent-ai-events.d.ts.map +1 -1
- package/lib/subagent-ai-events.js +5 -22
- package/lib/subagent-ai-events.js.map +1 -1
- package/lib/subagent-goal-notify.d.ts +4 -4
- package/lib/subagent-goal-notify.d.ts.map +1 -1
- package/lib/subagent-goal-notify.js +6 -5
- package/lib/subagent-goal-notify.js.map +1 -1
- package/lib/subagent.d.ts +10 -14
- package/lib/subagent.d.ts.map +1 -1
- package/lib/subagent.js +5 -11
- package/lib/subagent.js.map +1 -1
- package/lib/task-executor.d.ts +1 -0
- package/lib/task-executor.d.ts.map +1 -1
- package/lib/task-executor.js +17 -9
- package/lib/task-executor.js.map +1 -1
- package/lib/typing-indicator/adapter-integration.d.ts +22 -22
- package/lib/typing-indicator/adapter-integration.d.ts.map +1 -1
- package/lib/typing-indicator/adapter-integration.js +47 -47
- package/lib/typing-indicator/adapter-integration.js.map +1 -1
- package/lib/typing-indicator/index.d.ts +2 -2
- package/lib/typing-indicator/index.d.ts.map +1 -1
- package/lib/typing-indicator/index.js +1 -1
- package/lib/typing-indicator/index.js.map +1 -1
- package/lib/typing-indicator/integration.d.ts +8 -8
- package/lib/typing-indicator/integration.d.ts.map +1 -1
- package/lib/typing-indicator/integration.js +14 -14
- package/lib/typing-indicator/integration.js.map +1 -1
- package/lib/zhin-agent/agent-loop-standalone.d.ts +2 -2
- package/lib/zhin-agent/agent-loop-standalone.d.ts.map +1 -1
- package/lib/zhin-agent/agent-loop-standalone.js +5 -5
- package/lib/zhin-agent/agent-loop-standalone.js.map +1 -1
- package/lib/zhin-agent/agent-loop-turn.d.ts +4 -4
- package/lib/zhin-agent/agent-loop-turn.d.ts.map +1 -1
- package/lib/zhin-agent/agent-loop-turn.js +8 -8
- package/lib/zhin-agent/agent-loop-turn.js.map +1 -1
- package/lib/zhin-agent/builtin-tools.d.ts +1 -1
- package/lib/zhin-agent/builtin-tools.d.ts.map +1 -1
- package/lib/zhin-agent/compaction-runtime.d.ts +6 -2
- package/lib/zhin-agent/compaction-runtime.d.ts.map +1 -1
- package/lib/zhin-agent/compaction-runtime.js +25 -1
- package/lib/zhin-agent/compaction-runtime.js.map +1 -1
- package/lib/zhin-agent/config.d.ts +25 -0
- package/lib/zhin-agent/config.d.ts.map +1 -1
- package/lib/zhin-agent/config.js.map +1 -1
- package/lib/zhin-agent/deferred-delivery.d.ts +3 -3
- package/lib/zhin-agent/deferred-delivery.d.ts.map +1 -1
- package/lib/zhin-agent/deferred-delivery.js +5 -5
- package/lib/zhin-agent/deferred-delivery.js.map +1 -1
- package/lib/zhin-agent/event-emitter.d.ts +2 -2
- package/lib/zhin-agent/event-emitter.d.ts.map +1 -1
- package/lib/zhin-agent/event-emitter.js +7 -7
- package/lib/zhin-agent/event-emitter.js.map +1 -1
- package/lib/zhin-agent/index.d.ts +29 -28
- package/lib/zhin-agent/index.d.ts.map +1 -1
- package/lib/zhin-agent/index.js +114 -162
- package/lib/zhin-agent/index.js.map +1 -1
- package/lib/zhin-agent/interfaces.d.ts +63 -0
- package/lib/zhin-agent/interfaces.d.ts.map +1 -0
- package/lib/zhin-agent/interfaces.js +8 -0
- package/lib/zhin-agent/interfaces.js.map +1 -0
- package/lib/zhin-agent/model-resolver.d.ts.map +1 -1
- package/lib/zhin-agent/model-resolver.js +2 -0
- package/lib/zhin-agent/model-resolver.js.map +1 -1
- package/lib/zhin-agent/persist-deferred-context.d.ts +2 -2
- package/lib/zhin-agent/persist-deferred-context.d.ts.map +1 -1
- package/lib/zhin-agent/persist-deferred-context.js +3 -9
- package/lib/zhin-agent/persist-deferred-context.js.map +1 -1
- package/lib/zhin-agent/prompt-assembly.d.ts +7 -7
- package/lib/zhin-agent/prompt-assembly.d.ts.map +1 -1
- package/lib/zhin-agent/prompt-assembly.js +11 -11
- package/lib/zhin-agent/prompt-assembly.js.map +1 -1
- package/lib/zhin-agent/prompt-controller.d.ts +3 -3
- package/lib/zhin-agent/prompt-controller.d.ts.map +1 -1
- package/lib/zhin-agent/prompt-controller.js +2 -2
- package/lib/zhin-agent/prompt-controller.js.map +1 -1
- package/lib/zhin-agent/prompt.d.ts +10 -10
- package/lib/zhin-agent/prompt.d.ts.map +1 -1
- package/lib/zhin-agent/prompt.js +62 -55
- package/lib/zhin-agent/prompt.js.map +1 -1
- package/lib/zhin-agent/session-io.d.ts +10 -10
- package/lib/zhin-agent/session-io.d.ts.map +1 -1
- package/lib/zhin-agent/session-io.js +47 -33
- package/lib/zhin-agent/session-io.js.map +1 -1
- package/lib/zhin-agent/session-tree-commands.d.ts +3 -3
- package/lib/zhin-agent/session-tree-commands.d.ts.map +1 -1
- package/lib/zhin-agent/session-tree-commands.js +7 -19
- package/lib/zhin-agent/session-tree-commands.js.map +1 -1
- package/lib/zhin-agent/task-continuation.d.ts +4 -4
- package/lib/zhin-agent/task-continuation.d.ts.map +1 -1
- package/lib/zhin-agent/task-continuation.js.map +1 -1
- package/lib/zhin-agent/tool-orchestration.d.ts +3 -3
- package/lib/zhin-agent/tool-orchestration.d.ts.map +1 -1
- package/lib/zhin-agent/tool-orchestration.js +9 -15
- package/lib/zhin-agent/tool-orchestration.js.map +1 -1
- package/lib/zhin-agent/tool-runtime.d.ts +2 -2
- package/lib/zhin-agent/tool-runtime.d.ts.map +1 -1
- package/lib/zhin-agent/tool-runtime.js +2 -2
- package/lib/zhin-agent/tool-runtime.js.map +1 -1
- package/lib/zhin-agent/tool-search-orchestrator.d.ts +2 -2
- package/lib/zhin-agent/tool-search-orchestrator.d.ts.map +1 -1
- package/lib/zhin-agent/tool-search-orchestrator.js +9 -9
- package/lib/zhin-agent/tool-search-orchestrator.js.map +1 -1
- package/lib/zhin-agent/turn-pipeline.d.ts +4 -3
- package/lib/zhin-agent/turn-pipeline.d.ts.map +1 -1
- package/lib/zhin-agent/turn-pipeline.js +37 -59
- package/lib/zhin-agent/turn-pipeline.js.map +1 -1
- package/lib/zhin-agent/turn-user-message.d.ts +2 -2
- package/lib/zhin-agent/turn-user-message.d.ts.map +1 -1
- package/lib/zhin-agent/turn-user-message.js +2 -2
- package/lib/zhin-agent/turn-user-message.js.map +1 -1
- package/lib/zhin-agent/web-search-locale-attach.d.ts +2 -2
- package/lib/zhin-agent/web-search-locale-attach.d.ts.map +1 -1
- package/lib/zhin-agent/web-search-locale-attach.js +5 -4
- package/lib/zhin-agent/web-search-locale-attach.js.map +1 -1
- package/lib/zhin-agent/zhin-agent-private.d.ts +7 -7
- package/lib/zhin-agent/zhin-agent-private.d.ts.map +1 -1
- package/package.json +15 -5
- package/lib/monitoring/index.d.ts +0 -79
- package/lib/monitoring/index.d.ts.map +0 -1
- package/lib/monitoring/index.js +0 -197
- package/lib/monitoring/index.js.map +0 -1
- package/lib/monitoring/metrics.d.ts +0 -260
- package/lib/monitoring/metrics.d.ts.map +0 -1
- package/lib/monitoring/metrics.js +0 -550
- package/lib/monitoring/metrics.js.map +0 -1
- package/lib/security/bash-tool-context.d.ts +0 -20
- package/lib/security/bash-tool-context.d.ts.map +0 -1
- package/lib/security/bash-tool-context.js +0 -19
- package/lib/security/bash-tool-context.js.map +0 -1
- package/lib/security/budget-limiter.d.ts +0 -161
- package/lib/security/budget-limiter.d.ts.map +0 -1
- package/lib/security/budget-limiter.js +0 -392
- package/lib/security/budget-limiter.js.map +0 -1
- package/lib/security/network-policy.d.ts +0 -98
- package/lib/security/network-policy.d.ts.map +0 -1
- package/lib/security/network-policy.js +0 -305
- package/lib/security/network-policy.js.map +0 -1
- package/lib/security/security-config.example.d.ts +0 -33
- package/lib/security/security-config.example.d.ts.map +0 -1
- package/lib/security/security-config.example.js +0 -166
- package/lib/security/security-config.example.js.map +0 -1
package/lib/security/index.js
CHANGED
|
@@ -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 './
|
|
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
|
|
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
|
|
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
|
|
16
|
-
export declare function resolveToolRequesterRole(plugin: Plugin,
|
|
17
|
-
export declare function
|
|
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,
|
|
20
|
-
export declare function setBashAlways(plugin: Plugin,
|
|
21
|
-
export declare function addOwnerApproveAlways(plugin: Plugin,
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
48
|
-
export declare function formatBashApproveList(plugin: Plugin,
|
|
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,
|
|
50
|
+
export declare function listOwnerApproveAlways(plugin: Plugin, commMessage: Message): string[];
|
|
51
51
|
export declare function isIcqqSensitiveSubcommand(fullSubCommand: string): boolean;
|
|
52
|
-
export declare function
|
|
53
|
-
export declare function
|
|
54
|
-
export declare function
|
|
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,
|
|
1
|
+
{"version":3,"file":"owner-approve-always-store.d.ts","sourceRoot":"","sources":["../../src/security/owner-approve-always-store.ts"],"names":[],"mappings":"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"}
|
|
@@ -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,
|
|
43
|
+
return { version: STORE_VERSION, endpoints: {} };
|
|
43
44
|
}
|
|
44
|
-
function normalizeBotKey(adapter,
|
|
45
|
-
return `${adapter}|${
|
|
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,
|
|
56
|
+
const [adapter, endpointId, ownerId, scope] = parts;
|
|
56
57
|
if (scope === 'orchestration:bash') {
|
|
57
|
-
const k = normalizeBotKey(adapter,
|
|
58
|
-
if (!out.
|
|
59
|
-
out.
|
|
60
|
-
out.
|
|
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.
|
|
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.
|
|
75
|
-
const ent = v2.
|
|
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
|
|
105
|
+
export function getEndpointMaster(plugin, commMessage) {
|
|
105
106
|
const root = plugin.root ?? plugin;
|
|
106
|
-
const adapter = root.inject(
|
|
107
|
-
const
|
|
108
|
-
const 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
|
|
123
|
+
function getEndpointTrustedIds(plugin, commMessage) {
|
|
123
124
|
const root = plugin.root ?? plugin;
|
|
124
|
-
const adapter = root.inject(
|
|
125
|
-
const
|
|
126
|
-
const
|
|
127
|
-
return normalizeIdList(
|
|
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,
|
|
130
|
-
|
|
131
|
-
|
|
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 (
|
|
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,
|
|
149
|
-
if (!
|
|
160
|
+
function getEntry(plugin, commMessage) {
|
|
161
|
+
if (!commMessage.$adapter || !commMessage.$endpoint)
|
|
150
162
|
return undefined;
|
|
151
|
-
const ownerId =
|
|
163
|
+
const ownerId = getEndpointMaster(plugin, commMessage);
|
|
152
164
|
if (ownerId == null)
|
|
153
165
|
return undefined;
|
|
154
|
-
const key = normalizeBotKey(
|
|
166
|
+
const key = normalizeBotKey(String(commMessage.$adapter), commMessage.$endpoint, ownerId);
|
|
155
167
|
const data = readStore();
|
|
156
|
-
return data.
|
|
168
|
+
return data.endpoints[key];
|
|
157
169
|
}
|
|
158
|
-
function ensureEntry(plugin,
|
|
159
|
-
if (!
|
|
170
|
+
function ensureEntry(plugin, commMessage) {
|
|
171
|
+
if (!commMessage.$adapter || !commMessage.$endpoint)
|
|
160
172
|
return { bashRules: [] };
|
|
161
|
-
const ownerId =
|
|
173
|
+
const ownerId = getEndpointMaster(plugin, commMessage);
|
|
162
174
|
if (ownerId == null)
|
|
163
175
|
return { bashRules: [] };
|
|
164
|
-
const key = normalizeBotKey(
|
|
176
|
+
const key = normalizeBotKey(String(commMessage.$adapter), commMessage.$endpoint, ownerId);
|
|
165
177
|
const data = readStore();
|
|
166
|
-
if (!data.
|
|
167
|
-
data.
|
|
178
|
+
if (!data.endpoints[key]) {
|
|
179
|
+
data.endpoints[key] = { bashRules: [] };
|
|
168
180
|
writeStore(data);
|
|
169
181
|
}
|
|
170
|
-
return data.
|
|
182
|
+
return data.endpoints[key];
|
|
171
183
|
}
|
|
172
|
-
export function
|
|
184
|
+
export function getOwnerCommMessageOrUndefined(plugin, message) {
|
|
173
185
|
if (message.$channel?.type !== 'private')
|
|
174
186
|
return undefined;
|
|
175
|
-
const
|
|
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
|
|
190
|
+
return message;
|
|
189
191
|
}
|
|
190
192
|
/** 编排层:是否已「永久放行」bash 的 Owner 硬确认(ZHIN_NEEDS_OWNER 路径) */
|
|
191
|
-
export function hasOwnerApproveAlways(plugin,
|
|
193
|
+
export function hasOwnerApproveAlways(plugin, commMessage, toolName) {
|
|
192
194
|
if (toolName !== OWNER_APPROVE_ALWAYS_TOOL)
|
|
193
195
|
return false;
|
|
194
|
-
if (!
|
|
196
|
+
if (!commMessage.$adapter || !commMessage.$endpoint)
|
|
195
197
|
return false;
|
|
196
|
-
const ent = getEntry(plugin,
|
|
198
|
+
const ent = getEntry(plugin, commMessage);
|
|
197
199
|
return !!ent?.bashAlways;
|
|
198
200
|
}
|
|
199
|
-
export function setBashAlways(plugin,
|
|
200
|
-
if (!
|
|
201
|
+
export function setBashAlways(plugin, commMessage, value) {
|
|
202
|
+
if (!commMessage.$adapter || !commMessage.$endpoint)
|
|
201
203
|
return;
|
|
202
|
-
const ownerId =
|
|
204
|
+
const ownerId = getEndpointMaster(plugin, commMessage);
|
|
203
205
|
if (ownerId == null)
|
|
204
206
|
return;
|
|
205
|
-
const key = normalizeBotKey(
|
|
207
|
+
const key = normalizeBotKey(String(commMessage.$adapter), commMessage.$endpoint, ownerId);
|
|
206
208
|
const data = readStore();
|
|
207
|
-
const prev = data.
|
|
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.
|
|
217
|
+
data.endpoints[key] = ent;
|
|
216
218
|
writeStore(data);
|
|
217
219
|
}
|
|
218
|
-
export function addOwnerApproveAlways(plugin,
|
|
219
|
-
if (!
|
|
220
|
-
return { ok: false, error: '缺少 platform /
|
|
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 (
|
|
226
|
-
return { ok: false, error: '当前
|
|
227
|
+
if (getEndpointMaster(plugin, commMessage) == null) {
|
|
228
|
+
return { ok: false, error: '当前 Endpoint 未配置 owner' };
|
|
227
229
|
}
|
|
228
|
-
setBashAlways(plugin,
|
|
230
|
+
setBashAlways(plugin, commMessage, true);
|
|
229
231
|
return { ok: true };
|
|
230
232
|
}
|
|
231
|
-
export function removeOwnerApproveAlways(plugin,
|
|
232
|
-
if (!
|
|
233
|
-
return { ok: false, error: '缺少 platform /
|
|
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 (
|
|
239
|
-
return { ok: false, error: '当前
|
|
240
|
+
if (getEndpointMaster(plugin, commMessage) == null) {
|
|
241
|
+
return { ok: false, error: '当前 Endpoint 未配置 owner' };
|
|
240
242
|
}
|
|
241
|
-
const ent = getEntry(plugin,
|
|
243
|
+
const ent = getEntry(plugin, commMessage);
|
|
242
244
|
if (!ent?.bashAlways) {
|
|
243
245
|
return { ok: false, error: '当前未对 bash 设置永久放行。' };
|
|
244
246
|
}
|
|
245
|
-
setBashAlways(plugin,
|
|
247
|
+
setBashAlways(plugin, commMessage, false);
|
|
246
248
|
return { ok: true };
|
|
247
249
|
}
|
|
248
|
-
export function addBashApproveRule(plugin,
|
|
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 (!
|
|
261
|
-
return { ok: false, error: '缺少 platform/
|
|
261
|
+
if (!commMessage.$adapter || !commMessage.$endpoint || getEndpointMaster(plugin, commMessage) == null) {
|
|
262
|
+
return { ok: false, error: '缺少 platform/endpointId 或未配置 owner。' };
|
|
262
263
|
}
|
|
263
|
-
const ownerId =
|
|
264
|
-
const key = normalizeBotKey(
|
|
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.
|
|
267
|
-
if (data.
|
|
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.
|
|
272
|
+
data.endpoints[key] = ent;
|
|
272
273
|
writeStore(data);
|
|
273
274
|
return { ok: true, id };
|
|
274
275
|
}
|
|
275
|
-
export function removeBashApproveRule(plugin,
|
|
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 (!
|
|
280
|
-
return { ok: false, error: '缺少 platform/
|
|
280
|
+
if (!commMessage.$adapter || !commMessage.$endpoint || getEndpointMaster(plugin, commMessage) == null) {
|
|
281
|
+
return { ok: false, error: '缺少 platform/endpointId 或未配置 owner。' };
|
|
281
282
|
}
|
|
282
|
-
const ownerId =
|
|
283
|
-
const key = normalizeBotKey(
|
|
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.
|
|
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.
|
|
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,
|
|
299
|
-
if (!
|
|
299
|
+
export function matchesBashOwnerExecBypass(plugin, commMessage, commandLine) {
|
|
300
|
+
if (!commMessage.$adapter || !commMessage.$endpoint)
|
|
300
301
|
return false;
|
|
301
|
-
const ent = getEntry(plugin,
|
|
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,
|
|
322
|
-
const ent = getEntry(plugin,
|
|
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,
|
|
337
|
-
const ent = getEntry(plugin,
|
|
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,
|
|
354
|
-
return `${adapter}|${
|
|
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,
|
|
371
|
+
export function setPendingOrchestrationTool(plugin, commMessage, toolName) {
|
|
357
372
|
if (toolName !== OWNER_APPROVE_ALWAYS_TOOL)
|
|
358
373
|
return;
|
|
359
|
-
if (!
|
|
374
|
+
if (!commMessage.$adapter || !commMessage.$endpoint)
|
|
360
375
|
return;
|
|
361
|
-
const ownerId =
|
|
376
|
+
const ownerId = getEndpointMaster(plugin, commMessage);
|
|
362
377
|
if (ownerId == null)
|
|
363
378
|
return;
|
|
364
|
-
pendingOrchestration.set(pendingKey(
|
|
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,
|
|
370
|
-
if (!
|
|
384
|
+
export function clearPendingOrchestrationTool(plugin, commMessage) {
|
|
385
|
+
if (!commMessage.$adapter || !commMessage.$endpoint)
|
|
371
386
|
return;
|
|
372
|
-
const ownerId =
|
|
387
|
+
const ownerId = getEndpointMaster(plugin, commMessage);
|
|
373
388
|
if (ownerId == null)
|
|
374
389
|
return;
|
|
375
|
-
pendingOrchestration.delete(pendingKey(
|
|
390
|
+
pendingOrchestration.delete(pendingKey(String(commMessage.$adapter), commMessage.$endpoint, ownerId));
|
|
376
391
|
}
|
|
377
|
-
export function getPendingOrchestrationTool(plugin,
|
|
378
|
-
if (!
|
|
392
|
+
export function getPendingOrchestrationTool(plugin, commMessage) {
|
|
393
|
+
if (!commMessage.$adapter || !commMessage.$endpoint)
|
|
379
394
|
return undefined;
|
|
380
|
-
const ownerId =
|
|
395
|
+
const ownerId = getEndpointMaster(plugin, commMessage);
|
|
381
396
|
if (ownerId == null)
|
|
382
397
|
return undefined;
|
|
383
|
-
const key = pendingKey(
|
|
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)
|