@ai-setting/roy-agent-core 1.7.51 → 1.7.53
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/dist/config/config-component.d.ts +346 -0
- package/dist/config/config-parser.d.ts +45 -0
- package/dist/config/env-key.d.ts +97 -0
- package/dist/config/env-source.d.ts +113 -0
- package/dist/config/file-source.d.ts +90 -0
- package/dist/config/index.d.ts +4 -0
- package/dist/config/protocol-resolver.d.ts +94 -0
- package/dist/env/agent/agent-component.d.ts +646 -0
- package/dist/env/agent/agent-config-registration.d.ts +18 -0
- package/dist/env/agent/agent-registry.d.ts +500 -0
- package/dist/env/agent/index.d.ts +9 -0
- package/dist/env/agent/summary-agent.d.ts +44 -0
- package/dist/env/agent/types.d.ts +503 -0
- package/dist/env/commands/commands-component.d.ts +97 -0
- package/dist/env/commands/commands-config-registration.d.ts +19 -0
- package/dist/env/commands/index.d.ts +7 -0
- package/dist/env/commands/parser.d.ts +18 -0
- package/dist/env/commands/types.d.ts +133 -0
- package/dist/env/component.d.ts +186 -0
- package/dist/env/constants.d.ts +112 -0
- package/dist/env/context/env-context.d.ts +420 -0
- package/dist/env/context/env-event.d.ts +144 -0
- package/dist/env/context/index.d.ts +13 -0
- package/dist/env/debug/debug-component.d.ts +160 -0
- package/dist/env/debug/formatters/index.d.ts +8 -0
- package/dist/env/debug/formatters/repl-formatter.d.ts +80 -0
- package/dist/env/debug/formatters/trace-formatter.d.ts +43 -0
- package/dist/env/debug/formatters/tree-formatter.d.ts +72 -0
- package/dist/env/debug/index.d.ts +15 -0
- package/dist/env/debug/index.js +1 -1
- package/dist/env/debug/parser/regex-parser.d.ts +49 -0
- package/dist/env/debug/parser/span-builder.d.ts +79 -0
- package/dist/env/debug/reader/log-reader.d.ts +55 -0
- package/dist/env/debug/reader/span-db-reader.d.ts +70 -0
- package/dist/env/debug/types.d.ts +145 -0
- package/dist/env/environment.d.ts +185 -0
- package/dist/env/errors.d.ts +120 -0
- package/dist/env/event-source/bounty-cli-handler.d.ts +42 -0
- package/dist/env/event-source/bounty-im-handler.d.ts +232 -0
- package/dist/env/event-source/event-source-component.d.ts +177 -0
- package/dist/env/event-source/event-source-config-registration.d.ts +18 -0
- package/dist/env/event-source/event-source-handlers.d.ts +486 -0
- package/dist/env/event-source/event-store.d.ts +110 -0
- package/dist/env/event-source/idempotency-key.d.ts +19 -0
- package/dist/env/event-source/index.d.ts +15 -0
- package/dist/env/event-source/index.js +4 -4
- package/dist/env/event-source/timer-handler.d.ts +74 -0
- package/dist/env/event-source/types.d.ts +803 -0
- package/dist/env/hook/global-hook-manager.d.ts +73 -0
- package/dist/env/hook/hook-manager.d.ts +139 -0
- package/dist/env/hook/index.d.ts +9 -0
- package/dist/env/hook/types.d.ts +107 -0
- package/dist/env/index.d.ts +24 -0
- package/dist/env/index.js +6 -6
- package/dist/env/interface.d.ts +156 -0
- package/dist/env/lark-mention-utils.d.ts +59 -0
- package/dist/env/llm/adapter-ai-sdk.d.ts +10 -0
- package/dist/env/llm/adapter-pi-ai.d.ts +39 -0
- package/dist/env/llm/adapter.d.ts +80 -0
- package/dist/env/llm/factory.d.ts +13 -0
- package/dist/env/llm/hooks.d.ts +150 -0
- package/dist/env/llm/index.d.ts +16 -0
- package/dist/env/llm/invoke.d.ts +264 -0
- package/dist/env/llm/llm-cache.d.ts +38 -0
- package/dist/env/llm/llm.d.ts +238 -0
- package/dist/env/llm/opencode-session.d.ts +79 -0
- package/dist/env/llm/provider.d.ts +40 -0
- package/dist/env/llm/tool-args-parser.d.ts +77 -0
- package/dist/env/llm/tool-schema.d.ts +54 -0
- package/dist/env/llm/transform.d.ts +57 -0
- package/dist/env/llm/types.d.ts +818 -0
- package/dist/env/log-trace/decorator.d.ts +88 -0
- package/dist/env/log-trace/index.d.ts +14 -0
- package/dist/env/log-trace/log-trace-component.d.ts +268 -0
- package/dist/env/log-trace/log-trace-config-registration.d.ts +25 -0
- package/dist/env/log-trace/logger.d.ts +83 -0
- package/dist/env/log-trace/opentelemetry/cli-propagation.d.ts +105 -0
- package/dist/env/log-trace/opentelemetry/mod.d.ts +24 -0
- package/dist/env/log-trace/opentelemetry/propagation-env.d.ts +81 -0
- package/dist/env/log-trace/opentelemetry/propagation.d.ts +79 -0
- package/dist/env/log-trace/opentelemetry/tracer-provider.d.ts +157 -0
- package/dist/env/log-trace/span-storage.d.ts +37 -0
- package/dist/env/log-trace/trace-context.d.ts +28 -0
- package/dist/env/log-trace/types.d.ts +127 -0
- package/dist/env/mcp/command-resolver.d.ts +12 -0
- package/dist/env/mcp/config.d.ts +103 -0
- package/dist/env/mcp/index.d.ts +13 -0
- package/dist/env/mcp/loader.d.ts +78 -0
- package/dist/env/mcp/mcp-component.d.ts +54 -0
- package/dist/env/mcp/mcp-config-registration.d.ts +19 -0
- package/dist/env/mcp/npm-prefix/index.d.ts +17 -0
- package/dist/env/mcp/scanner.d.ts +38 -0
- package/dist/env/mcp/tool/adapter.d.ts +32 -0
- package/dist/env/mcp/tool/index.d.ts +4 -0
- package/dist/env/mcp/types.d.ts +131 -0
- package/dist/env/memory/built-in/index.d.ts +41 -0
- package/dist/env/memory/built-in/recall-memory.d.ts +29 -0
- package/dist/env/memory/built-in/record-memory.d.ts +44 -0
- package/dist/env/memory/index.d.ts +10 -0
- package/dist/env/memory/memory-component.d.ts +114 -0
- package/dist/env/memory/memory-config-registration.d.ts +18 -0
- package/dist/env/memory/memory-config.d.ts +18 -0
- package/dist/env/memory/plugin/index.d.ts +16 -0
- package/dist/env/memory/plugin/memory-agent.d.ts +126 -0
- package/dist/env/memory/plugin/memory-manager.d.ts +71 -0
- package/dist/env/memory/plugin/memory-plugin.d.ts +103 -0
- package/dist/env/memory/plugin/recall-memory.d.ts +16 -0
- package/dist/env/memory/plugin/types.d.ts +75 -0
- package/dist/env/memory/tools/memory-agent-tools.d.ts +109 -0
- package/dist/env/memory/types.d.ts +80 -0
- package/dist/env/paths.d.ts +46 -0
- package/dist/env/plugin/bounty-cli-notification-channel.d.ts +60 -0
- package/dist/env/plugin/event-bus-notification-channel.d.ts +50 -0
- package/dist/env/plugin/index.d.ts +13 -0
- package/dist/env/plugin/lark-cli-notification-channel.d.ts +61 -0
- package/dist/env/plugin/notification-channel.d.ts +143 -0
- package/dist/env/plugin/plugin-component.d.ts +232 -0
- package/dist/env/plugin/types.d.ts +146 -0
- package/dist/env/prompt/index.d.ts +7 -0
- package/dist/env/prompt/prompt-component.d.ts +194 -0
- package/dist/env/prompt/prompt-config-registration.d.ts +18 -0
- package/dist/env/prompt/prompt-store.d.ts +26 -0
- package/dist/env/prompt/prompts-index.d.ts +146 -0
- package/dist/env/prompt/renderer.d.ts +21 -0
- package/dist/env/prompt/types.d.ts +176 -0
- package/dist/env/session/hooks.d.ts +14 -0
- package/dist/env/session/index.d.ts +19 -0
- package/dist/env/session/search-query-parser.d.ts +41 -0
- package/dist/env/session/session-component.d.ts +464 -0
- package/dist/env/session/session-config-registration.d.ts +18 -0
- package/dist/env/session/session-id.d.ts +26 -0
- package/dist/env/session/session-message-converter.d.ts +142 -0
- package/dist/env/session/session-store.d.ts +188 -0
- package/dist/env/session/storage/index.d.ts +5 -0
- package/dist/env/session/storage/memory.d.ts +119 -0
- package/dist/env/session/storage/sqlite.d.ts +108 -0
- package/dist/env/session/types.d.ts +705 -0
- package/dist/env/session-tree-stopper.d.ts +79 -0
- package/dist/env/skill/config.d.ts +13 -0
- package/dist/env/skill/index.d.ts +6 -0
- package/dist/env/skill/parser.d.ts +9 -0
- package/dist/env/skill/scanner.d.ts +25 -0
- package/dist/env/skill/skill-component.d.ts +89 -0
- package/dist/env/skill/skill-config-registration.d.ts +18 -0
- package/dist/env/skill/tool/index.d.ts +1 -0
- package/dist/env/skill/tool/skill-tool.d.ts +15 -0
- package/dist/env/skill/types.d.ts +61 -0
- package/dist/env/task/backend/index.d.ts +24 -0
- package/dist/env/task/backend/index.js +704 -0
- package/dist/env/task/backend/roy-sidecar-task-port.d.ts +148 -0
- package/dist/env/task/backend/sqlite-task-port.d.ts +28 -0
- package/dist/env/task/backend/task-store-backend.d.ts +107 -0
- package/dist/env/task/backend/types.d.ts +293 -0
- package/dist/env/task/delegate/bg-task-id-storage.d.ts +9 -0
- package/dist/env/task/delegate/delegate-tool.d.ts +681 -0
- package/dist/env/task/delegate/index.d.ts +8 -0
- package/dist/env/task/delegate/process-registry.d.ts +58 -0
- package/dist/env/task/delegate/stop-tool.d.ts +12 -0
- package/dist/env/task/delegate/subagent-resolver.d.ts +25 -0
- package/dist/env/task/events/index.d.ts +7 -0
- package/dist/env/task/events/task-event-payloads.d.ts +101 -0
- package/dist/env/task/events/task-event-types.d.ts +23 -0
- package/dist/env/task/hooks/contexts.d.ts +191 -0
- package/dist/env/task/hooks/index.d.ts +7 -0
- package/dist/env/task/hooks/task-hook-points.d.ts +42 -0
- package/dist/env/task/index.d.ts +7 -0
- package/dist/env/task/plugins/auto-task-plugin.d.ts +38 -0
- package/dist/env/task/plugins/card-chat-routing.d.ts +135 -0
- package/dist/env/task/plugins/fake-user-message-helper.d.ts +90 -0
- package/dist/env/task/plugins/index.d.ts +8 -0
- package/dist/env/task/plugins/index.js +2 -2
- package/dist/env/task/plugins/lark-card-action-handler.d.ts +166 -0
- package/dist/env/task/plugins/lark-card-patch-notifier.d.ts +651 -0
- package/dist/env/task/plugins/lark-cli-task-notify-plugin.d.ts +248 -0
- package/dist/env/task/plugins/max-iteration-reminder-plugin.d.ts +112 -0
- package/dist/env/task/plugins/per-task-group-chat-plugin.d.ts +561 -0
- package/dist/env/task/plugins/task-tag-plugin.d.ts +70 -0
- package/dist/env/task/plugins/workflow-extractor-agent.d.ts +43 -0
- package/dist/env/task/registry-hook-installer.d.ts +43 -0
- package/dist/env/task/storage/index.d.ts +5 -0
- package/dist/env/task/storage/migrations/001_add_project_path_context.d.ts +14 -0
- package/dist/env/task/storage/migrations/002_add_task_type.d.ts +14 -0
- package/dist/env/task/storage/migrations/003_add_process_description.d.ts +20 -0
- package/dist/env/task/storage/migrations/004_rename_action_to_milestone.d.ts +37 -0
- package/dist/env/task/storage/migrations/005_convert_blob_description_to_text.d.ts +51 -0
- package/dist/env/task/storage/sqlite-task-store.d.ts +241 -0
- package/dist/env/task/tag-service.d.ts +138 -0
- package/dist/env/task/task-child-context.d.ts +70 -0
- package/dist/env/task/task-component.d.ts +270 -0
- package/dist/env/task/task-config-registration.d.ts +19 -0
- package/dist/env/task/task-creation-registry.d.ts +181 -0
- package/dist/env/task/task-reuse-context.d.ts +52 -0
- package/dist/env/task/task-reuse-registry.d.ts +31 -0
- package/dist/env/task/tools/batch-archive-tool.d.ts +9 -0
- package/dist/env/task/tools/batch-delete-tool.d.ts +9 -0
- package/dist/env/task/tools/complete-tool.d.ts +12 -0
- package/dist/env/task/tools/create-tool.d.ts +6 -0
- package/dist/env/task/tools/delete-tool.d.ts +6 -0
- package/dist/env/task/tools/get-tool.d.ts +6 -0
- package/dist/env/task/tools/index.d.ts +13 -0
- package/dist/env/task/tools/list-tool.d.ts +6 -0
- package/dist/env/task/tools/operation/create-tool.d.ts +12 -0
- package/dist/env/task/tools/operation/delete-tool.d.ts +6 -0
- package/dist/env/task/tools/operation/get-tool.d.ts +6 -0
- package/dist/env/task/tools/operation/index.d.ts +8 -0
- package/dist/env/task/tools/operation/list-tool.d.ts +6 -0
- package/dist/env/task/tools/operation/operation-types.d.ts +225 -0
- package/dist/env/task/tools/operation/update-tool.d.ts +6 -0
- package/dist/env/task/tools/search-tool.d.ts +9 -0
- package/dist/env/task/tools/task-tree-tool.d.ts +65 -0
- package/dist/env/task/tools/task-types.d.ts +255 -0
- package/dist/env/task/tools/update-tool.d.ts +6 -0
- package/dist/env/task/types.d.ts +290 -0
- package/dist/env/tool/built-in/bash-effect.d.ts +36 -0
- package/dist/env/tool/built-in/bash.d.ts +16 -0
- package/dist/env/tool/built-in/echo.d.ts +7 -0
- package/dist/env/tool/built-in/edit-file.d.ts +6 -0
- package/dist/env/tool/built-in/glob.d.ts +6 -0
- package/dist/env/tool/built-in/grep.d.ts +6 -0
- package/dist/env/tool/built-in/index.d.ts +39 -0
- package/dist/env/tool/built-in/query-background-process-tool.d.ts +113 -0
- package/dist/env/tool/built-in/read-file.d.ts +5 -0
- package/dist/env/tool/built-in/understand-image.d.ts +59 -0
- package/dist/env/tool/built-in/write-file.d.ts +5 -0
- package/dist/env/tool/index.d.ts +16 -0
- package/dist/env/tool/registry.d.ts +61 -0
- package/dist/env/tool/tool-component.d.ts +242 -0
- package/dist/env/tool/tool-config-registration.d.ts +18 -0
- package/dist/env/tool/types.d.ts +274 -0
- package/dist/env/tool/validator.d.ts +14 -0
- package/dist/env/types.d.ts +184 -0
- package/dist/env/workflow/decorators/decorator-node.d.ts +76 -0
- package/dist/env/workflow/decorators/edge.d.ts +42 -0
- package/dist/env/workflow/decorators/index.d.ts +13 -0
- package/dist/env/workflow/decorators/node-as.d.ts +40 -0
- package/dist/env/workflow/decorators/workflow.d.ts +30 -0
- package/dist/env/workflow/engine/dag-manager.d.ts +176 -0
- package/dist/env/workflow/engine/engine.d.ts +375 -0
- package/dist/env/workflow/engine/event-bus.d.ts +54 -0
- package/dist/env/workflow/engine/executor.d.ts +122 -0
- package/dist/env/workflow/engine/index.d.ts +15 -0
- package/dist/env/workflow/engine/node-registry.d.ts +159 -0
- package/dist/env/workflow/engine/scheduler.d.ts +164 -0
- package/dist/env/workflow/extractor/workflow-converter.d.ts +55 -0
- package/dist/env/workflow/fixtures.d.ts +401 -0
- package/dist/env/workflow/hooks/index.d.ts +4 -0
- package/dist/env/workflow/hooks/workflow-hook-points.d.ts +161 -0
- package/dist/env/workflow/index.d.ts +30 -0
- package/dist/env/workflow/index.js +1 -1
- package/dist/env/workflow/metadata/keys.d.ts +6 -0
- package/dist/env/workflow/nodes/agent-component-adapter.d.ts +175 -0
- package/dist/env/workflow/nodes/agent-node.d.ts +206 -0
- package/dist/env/workflow/nodes/ask-user-node.d.ts +66 -0
- package/dist/env/workflow/nodes/condition-node.d.ts +39 -0
- package/dist/env/workflow/nodes/index.d.ts +8 -0
- package/dist/env/workflow/nodes/merge-node.d.ts +40 -0
- package/dist/env/workflow/nodes/python-call-node.d.ts +95 -0
- package/dist/env/workflow/nodes/skill-node.d.ts +29 -0
- package/dist/env/workflow/nodes/tool-node.d.ts +58 -0
- package/dist/env/workflow/nodes/workflow-node.d.ts +118 -0
- package/dist/env/workflow/plugins/index.d.ts +6 -0
- package/dist/env/workflow/plugins/index.js +2 -2
- package/dist/env/workflow/plugins/lark-cli-workflow-notify-plugin.d.ts +107 -0
- package/dist/env/workflow/plugins/workflow-json-output-plugin.d.ts +166 -0
- package/dist/env/workflow/runtime/runtime-cancellation-scope.d.ts +121 -0
- package/dist/env/workflow/service/index.d.ts +9 -0
- package/dist/env/workflow/service/registry.d.ts +37 -0
- package/dist/env/workflow/service/workflow-service.d.ts +422 -0
- package/dist/env/workflow/storage/index.d.ts +11 -0
- package/dist/env/workflow/storage/mock-repositories.d.ts +106 -0
- package/dist/env/workflow/storage/safe-json.d.ts +62 -0
- package/dist/env/workflow/storage/sqlite.d.ts +57 -0
- package/dist/env/workflow/storage/tag-repo.d.ts +65 -0
- package/dist/env/workflow/storage/workflow-repo.d.ts +161 -0
- package/dist/env/workflow/tools/ask-user-tool.d.ts +35 -0
- package/dist/env/workflow/tools/index.d.ts +16 -0
- package/dist/env/workflow/tools/run-workflow.d.ts +130 -0
- package/dist/env/workflow/tools/submit-json-output-tool.d.ts +38 -0
- package/dist/env/workflow/tools/workflow-add-tool.d.ts +47 -0
- package/dist/env/workflow/tools/workflow-get-tool.d.ts +29 -0
- package/dist/env/workflow/tools/workflow-list-tool.d.ts +55 -0
- package/dist/env/workflow/tools/workflow-run-status-tool.d.ts +26 -0
- package/dist/env/workflow/tools/workflow-run-stop-tool.d.ts +29 -0
- package/dist/env/workflow/tools/workflow-search-tool.d.ts +33 -0
- package/dist/env/workflow/tools/workflow-tag-list-tool.d.ts +59 -0
- package/dist/env/workflow/tools/workflow-validate-tool.d.ts +60 -0
- package/dist/env/workflow/types/context.d.ts +17 -0
- package/dist/env/workflow/types/decorators-types.d.ts +182 -0
- package/dist/env/workflow/types/edge.d.ts +33 -0
- package/dist/env/workflow/types/event.d.ts +869 -0
- package/dist/env/workflow/types/index.d.ts +16 -0
- package/dist/env/workflow/types/run.d.ts +235 -0
- package/dist/env/workflow/types/workflow-error.d.ts +79 -0
- package/dist/env/workflow/types/workflow-hil.d.ts +57 -0
- package/dist/env/workflow/types/workflow-message.d.ts +193 -0
- package/dist/env/workflow/types/workflow-session.d.ts +17 -0
- package/dist/env/workflow/types/workflow.d.ts +654 -0
- package/dist/env/workflow/types_compat.d.ts +10 -0
- package/dist/env/workflow/utils/agent-session-metadata.d.ts +35 -0
- package/dist/env/workflow/utils/build-agent-node-output.d.ts +11 -0
- package/dist/env/workflow/utils/create-workflow.d.ts +35 -0
- package/dist/env/workflow/utils/dependency-prescan.d.ts +67 -0
- package/dist/env/workflow/utils/execution-state.d.ts +46 -0
- package/dist/env/workflow/utils/extract-agent-json-output.d.ts +6 -0
- package/dist/env/workflow/utils/index.d.ts +14 -0
- package/dist/env/workflow/utils/json-schema-to-zod.d.ts +23 -0
- package/dist/env/workflow/utils/node-id-utils.d.ts +20 -0
- package/dist/env/workflow/utils/node-output-contracts.d.ts +137 -0
- package/dist/env/workflow/utils/node-registry-helper.d.ts +36 -0
- package/dist/env/workflow/utils/output-schema-hint.d.ts +7 -0
- package/dist/env/workflow/utils/parse-agent-output-config.d.ts +9 -0
- package/dist/env/workflow/utils/recovery-validator.d.ts +30 -0
- package/dist/env/workflow/utils/sensitive-redact.d.ts +37 -0
- package/dist/env/workflow/utils/session-parser.d.ts +23 -0
- package/dist/env/workflow/utils/session-recovery.d.ts +122 -0
- package/dist/env/workflow/utils/template-contract-validator.d.ts +87 -0
- package/dist/env/workflow/utils/template-resolver.d.ts +285 -0
- package/dist/env/workflow/utils/validate-workflow-definition.d.ts +57 -0
- package/dist/env/workflow/utils/validation-rules.d.ts +103 -0
- package/dist/env/workflow/utils/workflow-message-metadata.d.ts +20 -0
- package/dist/env/workflow/utils/workflow-sanitize.d.ts +51 -0
- package/dist/env/workflow/workflow-component.d.ts +138 -0
- package/dist/index.d.ts +59 -0
- package/dist/index.js +7 -7
- package/dist/shared/@ai-setting/{roy-agent-core-9faekt5n.js → roy-agent-core-4sx6sdb2.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-wxsgay02.js → roy-agent-core-brwzs8wf.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-kyasfzeh.js → roy-agent-core-hch2geta.js} +45 -14
- package/dist/shared/@ai-setting/{roy-agent-core-zd077w51.js → roy-agent-core-j8e92gj8.js} +43 -1
- package/dist/shared/@ai-setting/{roy-agent-core-wwytg8rv.js → roy-agent-core-ph5qbqcx.js} +566 -78
- package/dist/util/process/process-tree-killer.d.ts +67 -0
- package/dist/utils/id.d.ts +11 -0
- package/dist/utils/loose-json.d.ts +30 -0
- package/dist/utils/media.d.ts +70 -0
- package/dist/utils/temp-file-manager/index.d.ts +99 -0
- package/package.json +4 -2
- /package/dist/shared/@ai-setting/{roy-agent-core-s214vmmd.js → roy-agent-core-4vpk40ss.js} +0 -0
- /package/dist/shared/@ai-setting/{roy-agent-core-0cfaqnz9.js → roy-agent-core-k25gv86p.js} +0 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Per-task ProcessRegistry
|
|
3
|
+
*
|
|
4
|
+
* 每个 delegate_task 持有一个 ProcessRegistry,跟踪该 task 派生的子进程 PID。
|
|
5
|
+
* bash 工具 spawn 子进程后立即 register,子进程 `exit` 时立即 unregister。
|
|
6
|
+
* 当 task 超时/stop 时,调用 killAll() 遍历所有剩余 PID,调用 killProcessTree。
|
|
7
|
+
*
|
|
8
|
+
* AsyncLocalStorage 隔离:
|
|
9
|
+
* - runWithProcessRegistryAsync(reg, fn) 把 reg 推到 ALS 栈,进入 fn
|
|
10
|
+
* - getCurrentProcessRegistry() 在 fn 内返回 reg,外部返回 undefined
|
|
11
|
+
* - 这样 bash 工具不感知任务边界,只需要 "我这里有个当前 registry 吗?有就注册"
|
|
12
|
+
*
|
|
13
|
+
* 设计原则:
|
|
14
|
+
* - 不影响非 delegate_task 场景(ALS 拿不到 registry 时 bash 不注册,行为零变化)
|
|
15
|
+
* - 不误杀其他 delegate_task(每个 task 一个独立 registry)
|
|
16
|
+
* - killAll 带验证+重试:每个 PID 最多杀 3 次,间隔 500ms,杀不掉记录 error 日志
|
|
17
|
+
*/
|
|
18
|
+
export declare class ProcessRegistry {
|
|
19
|
+
private readonly pids;
|
|
20
|
+
/**
|
|
21
|
+
* 注册一个 PID 到当前 registry。
|
|
22
|
+
* - 重复 register 同一 PID:幂等
|
|
23
|
+
* - 非正整数 / NaN:静默忽略(避免脏数据)
|
|
24
|
+
*/
|
|
25
|
+
register(pid: number): void;
|
|
26
|
+
/**
|
|
27
|
+
* 反注册一个 PID(子进程 exit 时调用)。
|
|
28
|
+
* 不存在时不报错(幂等)。
|
|
29
|
+
*/
|
|
30
|
+
unregister(pid: number): void;
|
|
31
|
+
/** 当前注册的 PID 数量(测试 + debug 用途) */
|
|
32
|
+
size(): number;
|
|
33
|
+
/**
|
|
34
|
+
* 杀掉所有仍注册在本 registry 的进程树(POSIX 杀进程组 / Windows taskkill /T)。
|
|
35
|
+
*
|
|
36
|
+
* 验证 + 重试机制:
|
|
37
|
+
* - 每次 kill 后等待 500ms,验证进程是否真的被干掉
|
|
38
|
+
* - 没干掉则重试,最多 3 次
|
|
39
|
+
* - 3 次还干不掉:记录 error 日志
|
|
40
|
+
*
|
|
41
|
+
* Task #2245 — BL-4:保留 `stillAlive` PID 以便后续强杀可重试。
|
|
42
|
+
* - 旧实现:成功杀掉的 PID 仍被无差别 `clear()`,与 stillAlive 一起丢失。
|
|
43
|
+
* - 新实现:仅 `delete` 真正被杀死的 PID,stillAlive PID 保留供下次重试。
|
|
44
|
+
* - 调用方(如 forceStopAll)可以多次调用 killAll 重试残留 PID。
|
|
45
|
+
* - 内部不 throw — 单个 PID 的 ESRCH/EPERM 不会阻断其他 PID 的清理。
|
|
46
|
+
*/
|
|
47
|
+
killAll(): Promise<void>;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* 在异步作用域内暴露给定的 ProcessRegistry。
|
|
51
|
+
* 适合用在 executeWithAbort 包裹 env.handle_query 之处。
|
|
52
|
+
*/
|
|
53
|
+
export declare function runWithProcessRegistryAsync<T>(registry: ProcessRegistry, fn: () => Promise<T>): Promise<T>;
|
|
54
|
+
/**
|
|
55
|
+
* 当前 ALS 栈顶的 ProcessRegistry(如果存在)。
|
|
56
|
+
* 在 bash 工具中调用:若返回 undefined 则退化为不注册(保持非 delegate_task 场景的行为)。
|
|
57
|
+
*/
|
|
58
|
+
export declare function getCurrentProcessRegistry(): ProcessRegistry | undefined;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview stop_task Tool
|
|
3
|
+
*
|
|
4
|
+
* 基于 agent-core 的 stop_task 实现
|
|
5
|
+
* 参考: packages/core/src/core/environment/expend/task/stop-task-tool.ts
|
|
6
|
+
*
|
|
7
|
+
* 功能:
|
|
8
|
+
* - 停止正在运行的后台任务
|
|
9
|
+
*/
|
|
10
|
+
import type { Tool } from "../../tool/types";
|
|
11
|
+
import type { BackgroundTaskManager } from "./delegate-tool";
|
|
12
|
+
export declare function createStopTool(taskManager: BackgroundTaskManager): Tool;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Subagent resolution — built-in specs + AgentRegistry
|
|
3
|
+
*/
|
|
4
|
+
import { AgentRegistry } from "../../agent/agent-registry";
|
|
5
|
+
import type { SubAgentSpec } from "./delegate-tool";
|
|
6
|
+
export interface ResolvedSubAgentConfig {
|
|
7
|
+
subagentType: string;
|
|
8
|
+
description: string;
|
|
9
|
+
basePrompt: string;
|
|
10
|
+
allowedTools?: string[];
|
|
11
|
+
deniedTools: string[];
|
|
12
|
+
fromRegistry: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare function isKnownSubagentType(subagentType: string, registry?: AgentRegistry): boolean;
|
|
15
|
+
export declare function resolveSubAgentConfig(subagentType: string, options?: {
|
|
16
|
+
registry?: AgentRegistry;
|
|
17
|
+
getBuiltIn?: (id: string) => SubAgentSpec | undefined;
|
|
18
|
+
}): Promise<ResolvedSubAgentConfig | undefined>;
|
|
19
|
+
/**
|
|
20
|
+
* 获取可用的 subagent 描述列表
|
|
21
|
+
*
|
|
22
|
+
* @param registry AgentRegistry 实例,用于获取自定义 agents
|
|
23
|
+
* @returns 格式化的 agent 描述列表(英文,与 delegate_task tool description 一致)
|
|
24
|
+
*/
|
|
25
|
+
export declare function listKnownSubagentDescriptions(registry?: AgentRegistry): string;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Task Event Payloads
|
|
3
|
+
*
|
|
4
|
+
* 定义所有 Task 相关事件的 Payload 结构
|
|
5
|
+
*/
|
|
6
|
+
import type { Task, TaskOperation } from "../types";
|
|
7
|
+
/**
|
|
8
|
+
* task.created 事件负载
|
|
9
|
+
*/
|
|
10
|
+
export interface TaskCreatedPayload {
|
|
11
|
+
task: Task;
|
|
12
|
+
sessionId: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* task.updated 事件负载
|
|
16
|
+
*/
|
|
17
|
+
export interface TaskUpdatedPayload {
|
|
18
|
+
task: Task;
|
|
19
|
+
changes: Partial<Task>;
|
|
20
|
+
sessionId: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* task.completed 事件负载
|
|
24
|
+
*/
|
|
25
|
+
export interface TaskCompletedPayload {
|
|
26
|
+
task: Task;
|
|
27
|
+
sessionId: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* task.deleted 事件负载
|
|
31
|
+
*/
|
|
32
|
+
export interface TaskDeletedPayload {
|
|
33
|
+
taskId: number;
|
|
34
|
+
sessionId: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* task.operation_added 事件负载
|
|
38
|
+
*/
|
|
39
|
+
export interface TaskOperationAddedPayload {
|
|
40
|
+
operation: TaskOperation;
|
|
41
|
+
taskId: number;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* task.delegated 事件负载
|
|
45
|
+
*/
|
|
46
|
+
export interface TaskDelegatedPayload {
|
|
47
|
+
taskId: number;
|
|
48
|
+
backgroundTaskId: string;
|
|
49
|
+
subSessionId: string;
|
|
50
|
+
parentSessionId: string;
|
|
51
|
+
description: string;
|
|
52
|
+
subagentType: string;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* task.background.started 事件负载
|
|
56
|
+
*/
|
|
57
|
+
export interface BackgroundTaskStartedPayload {
|
|
58
|
+
taskId: string;
|
|
59
|
+
subSessionId: string;
|
|
60
|
+
parentSessionId: string;
|
|
61
|
+
description: string;
|
|
62
|
+
subagentType: string;
|
|
63
|
+
associatedTaskId?: number;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* task.background.progress 事件负载
|
|
67
|
+
*/
|
|
68
|
+
export interface BackgroundTaskProgressPayload {
|
|
69
|
+
taskId: string;
|
|
70
|
+
subSessionId: string;
|
|
71
|
+
parentSessionId: string;
|
|
72
|
+
status: string;
|
|
73
|
+
progress?: number;
|
|
74
|
+
progressMessage?: string;
|
|
75
|
+
description?: string;
|
|
76
|
+
subagentType?: string;
|
|
77
|
+
associatedTaskId?: number;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* task.background.completed/failed/timeout/stopped 事件负载
|
|
81
|
+
*/
|
|
82
|
+
export interface BackgroundTaskCompletedPayload {
|
|
83
|
+
taskId: string;
|
|
84
|
+
subSessionId: string;
|
|
85
|
+
parentSessionId: string;
|
|
86
|
+
status: "completed" | "failed" | "timeout" | "stopped";
|
|
87
|
+
result?: string;
|
|
88
|
+
error?: string;
|
|
89
|
+
executionTimeMs: number;
|
|
90
|
+
associatedTaskId?: number;
|
|
91
|
+
description?: string;
|
|
92
|
+
subagentType?: string;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* 所有 Task Entity 事件负载的联合类型
|
|
96
|
+
*/
|
|
97
|
+
export type TaskEntityEventPayload = TaskCreatedPayload | TaskUpdatedPayload | TaskCompletedPayload | TaskDeletedPayload | TaskOperationAddedPayload | TaskDelegatedPayload;
|
|
98
|
+
/**
|
|
99
|
+
* 所有 Background Task 事件负载的联合类型
|
|
100
|
+
*/
|
|
101
|
+
export type BackgroundTaskEventPayload = BackgroundTaskStartedPayload | BackgroundTaskProgressPayload | BackgroundTaskCompletedPayload;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Task Entity Event Types
|
|
3
|
+
*
|
|
4
|
+
* 定义 TaskComponent 相关的 EnvEvent 类型
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Task Entity 事件类型枚举
|
|
8
|
+
*/
|
|
9
|
+
export declare const TaskEntityEventTypes: {
|
|
10
|
+
/** Task 创建 */
|
|
11
|
+
readonly CREATED: "task.created";
|
|
12
|
+
/** Task 更新 */
|
|
13
|
+
readonly UPDATED: "task.updated";
|
|
14
|
+
/** Task 完成 */
|
|
15
|
+
readonly COMPLETED: "task.completed";
|
|
16
|
+
/** Task 删除 */
|
|
17
|
+
readonly DELETED: "task.deleted";
|
|
18
|
+
/** Operation 记录添加 */
|
|
19
|
+
readonly OPERATION_ADDED: "task.operation_added";
|
|
20
|
+
/** Task 被委托 */
|
|
21
|
+
readonly DELEGATED: "task.delegated";
|
|
22
|
+
};
|
|
23
|
+
export type TaskEntityEventType = (typeof TaskEntityEventTypes)[keyof typeof TaskEntityEventTypes];
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Task Hook Contexts - Hook 上下文类型定义
|
|
3
|
+
*/
|
|
4
|
+
import type { CreateTaskOptions, UpdateTaskOptions, Task, TaskOperation, CreateOperationOptions } from "../types";
|
|
5
|
+
import type { TagService } from "../tag-service";
|
|
6
|
+
import type { DelegateToolResult } from "../delegate/delegate-tool";
|
|
7
|
+
/**
|
|
8
|
+
* Task Create Hook Context
|
|
9
|
+
*
|
|
10
|
+
* 触发时机:createTask() 方法调用后,实际创建前
|
|
11
|
+
*
|
|
12
|
+
* Plugin 可直接修改 options 来干预创建行为
|
|
13
|
+
*/
|
|
14
|
+
export interface TaskCreateContext {
|
|
15
|
+
/** 创建选项(Plugin 可直接修改) */
|
|
16
|
+
options: CreateTaskOptions;
|
|
17
|
+
/** Session ID */
|
|
18
|
+
sessionId: string;
|
|
19
|
+
/** Tag 服务引用 */
|
|
20
|
+
tagService: TagService;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Task Create Result Hook Context
|
|
24
|
+
*
|
|
25
|
+
* 触发时机:Task 创建成功后
|
|
26
|
+
*
|
|
27
|
+
* Plugin 可在此 Hook 中:
|
|
28
|
+
* - 同步 Tag 到数据库
|
|
29
|
+
* - 创建关联资源
|
|
30
|
+
* - 发送通知
|
|
31
|
+
*/
|
|
32
|
+
export interface TaskCreateResultContext {
|
|
33
|
+
/** 创建后的 Task(已包含生成 ID) */
|
|
34
|
+
task: Task;
|
|
35
|
+
/** Session ID */
|
|
36
|
+
sessionId: string;
|
|
37
|
+
/** Tag 服务引用 */
|
|
38
|
+
tagService: TagService;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Task Update Hook Context
|
|
42
|
+
*
|
|
43
|
+
* 触发时机:updateTask() 方法调用后,实际更新前
|
|
44
|
+
*
|
|
45
|
+
* Plugin 可直接修改 options 来干预更新行为
|
|
46
|
+
*/
|
|
47
|
+
export interface TaskUpdateContext {
|
|
48
|
+
/** Task ID */
|
|
49
|
+
id: number;
|
|
50
|
+
/** 更新选项(Plugin 可直接修改) */
|
|
51
|
+
options: UpdateTaskOptions;
|
|
52
|
+
/** Tag 服务引用 */
|
|
53
|
+
tagService: TagService;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Task Update Result Hook Context
|
|
57
|
+
*
|
|
58
|
+
* 触发时机:Task 更新成功后
|
|
59
|
+
*/
|
|
60
|
+
export interface TaskUpdateResultContext {
|
|
61
|
+
/** 更新后的 Task */
|
|
62
|
+
task: Task;
|
|
63
|
+
/** 变更的字段 */
|
|
64
|
+
changes: Partial<UpdateTaskOptions>;
|
|
65
|
+
/** Tag 服务引用 */
|
|
66
|
+
tagService: TagService;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Task Delete Hook Context
|
|
70
|
+
*
|
|
71
|
+
* 触发时机:deleteTask() 方法调用后,实际删除前
|
|
72
|
+
*/
|
|
73
|
+
export interface TaskDeleteContext {
|
|
74
|
+
/** Task ID */
|
|
75
|
+
id: number;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Task Delete Result Hook Context
|
|
79
|
+
*
|
|
80
|
+
* 触发时机:Task 删除成功后
|
|
81
|
+
*
|
|
82
|
+
* 注意:删除成功后无法获取 Task 的详细信息
|
|
83
|
+
*/
|
|
84
|
+
export interface TaskDeleteResultContext {
|
|
85
|
+
/** 被删除的 Task ID */
|
|
86
|
+
id: number;
|
|
87
|
+
/** 是否成功删除 */
|
|
88
|
+
deleted: boolean;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Delegate Before Hook Context
|
|
92
|
+
*
|
|
93
|
+
* 触发时机:delegate_task 工具执行前
|
|
94
|
+
*
|
|
95
|
+
* Plugin 可直接修改 prompt 来注入上下文
|
|
96
|
+
*/
|
|
97
|
+
export interface TaskDelegateContext {
|
|
98
|
+
/** 关联的 Task ID */
|
|
99
|
+
taskId?: number;
|
|
100
|
+
/** 执行提示词(Plugin 可直接修改以注入上下文) */
|
|
101
|
+
prompt: string;
|
|
102
|
+
/** SubAgent 类型 */
|
|
103
|
+
subagentType: string;
|
|
104
|
+
/** 超时时间 */
|
|
105
|
+
timeout?: number;
|
|
106
|
+
/** 清理策略 */
|
|
107
|
+
cleanup?: "delete" | "keep";
|
|
108
|
+
/** 执行原因 */
|
|
109
|
+
reason?: string;
|
|
110
|
+
/** Tag 服务引用 */
|
|
111
|
+
tagService: TagService;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Delegate After Hook Context
|
|
115
|
+
*
|
|
116
|
+
* 触发时机:delegate_task 工具执行后
|
|
117
|
+
*/
|
|
118
|
+
export interface TaskDelegateResultContext {
|
|
119
|
+
/** 关联的 Task ID */
|
|
120
|
+
taskId?: number;
|
|
121
|
+
/** 执行结果 */
|
|
122
|
+
result: DelegateToolResult;
|
|
123
|
+
/** Tag 服务引用 */
|
|
124
|
+
tagService: TagService;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Terminal Status Set — 触发 AFTER_COMPLETE 的 status 集合
|
|
128
|
+
*
|
|
129
|
+
* 仅 `completed` 是用户预期的"任务完成"事件,但 `failed` / `cancelled` /
|
|
130
|
+
* `timeout` 也算 task 终结(不应继续等待结果)。
|
|
131
|
+
*/
|
|
132
|
+
export declare const TASK_COMPLETE_TERMINAL_STATUSES: readonly ["completed", "failed", "cancelled", "timeout"];
|
|
133
|
+
export type TaskCompleteTerminalStatus = typeof TASK_COMPLETE_TERMINAL_STATUSES[number];
|
|
134
|
+
/**
|
|
135
|
+
* Task Complete Result Hook Context
|
|
136
|
+
*
|
|
137
|
+
* 触发时机:task 进入 terminal status (completed / failed / cancelled / timeout)
|
|
138
|
+
*
|
|
139
|
+
* 与 AFTER_UPDATE 的区别:AFTER_UPDATE 在每次 update 后触发,AFTER_COMPLETE 仅在
|
|
140
|
+
* status 进入 terminal 集合内时触发,语义更精确。
|
|
141
|
+
*/
|
|
142
|
+
export interface TaskCompleteResultContext {
|
|
143
|
+
/** Task 更新后的最终状态 */
|
|
144
|
+
task: Task;
|
|
145
|
+
/** 触发完成的 status 变更 (例如 { status: "completed" }) */
|
|
146
|
+
changes: Partial<UpdateTaskOptions>;
|
|
147
|
+
/** 进入的 terminal status */
|
|
148
|
+
terminalStatus: TaskCompleteTerminalStatus;
|
|
149
|
+
/** 触发 session ID (例如发起 complete task 的 agent session) */
|
|
150
|
+
sessionId: string;
|
|
151
|
+
/** Tag 服务引用 */
|
|
152
|
+
tagService: TagService;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Operation Create Hook Context
|
|
156
|
+
*
|
|
157
|
+
* 触发时机:createOperation() 方法调用后,实际创建前
|
|
158
|
+
*
|
|
159
|
+
* Plugin 可直接修改 options 来干预操作记录创建
|
|
160
|
+
*/
|
|
161
|
+
export interface TaskOperationCreateContext {
|
|
162
|
+
/** 创建选项(Plugin 可直接修改) */
|
|
163
|
+
options: CreateOperationOptions;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Operation Create Result Hook Context
|
|
167
|
+
*
|
|
168
|
+
* 触发时机:操作记录创建成功后
|
|
169
|
+
*/
|
|
170
|
+
export interface TaskOperationCreateResultContext {
|
|
171
|
+
/** 创建后的操作记录 */
|
|
172
|
+
operation: TaskOperation;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* TaskHookContextMap - Hook 点与 Context 类型的映射
|
|
176
|
+
*
|
|
177
|
+
* 用于 Hook 执行时类型安全的 Context 获取
|
|
178
|
+
*/
|
|
179
|
+
export interface TaskHookContextMap {
|
|
180
|
+
"task:before.create": TaskCreateContext;
|
|
181
|
+
"task:after.create": TaskCreateResultContext;
|
|
182
|
+
"task:before.update": TaskUpdateContext;
|
|
183
|
+
"task:after.update": TaskUpdateResultContext;
|
|
184
|
+
"task:before.delete": TaskDeleteContext;
|
|
185
|
+
"task:after.delete": TaskDeleteResultContext;
|
|
186
|
+
"task:after.complete": TaskCompleteResultContext;
|
|
187
|
+
"task:delegate:before": TaskDelegateContext;
|
|
188
|
+
"task:delegate:after": TaskDelegateResultContext;
|
|
189
|
+
"task:operation:before.create": TaskOperationCreateContext;
|
|
190
|
+
"task:operation:after.create": TaskOperationCreateResultContext;
|
|
191
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Task Hooks Module
|
|
3
|
+
*
|
|
4
|
+
* 提供 Task Component 的 Hook 机制
|
|
5
|
+
*/
|
|
6
|
+
export { TaskHookPoints, type TaskHookPoint } from "./task-hook-points";
|
|
7
|
+
export type { TaskCreateContext, TaskCreateResultContext, TaskUpdateContext, TaskUpdateResultContext, TaskDeleteContext, TaskDeleteResultContext, TaskDelegateContext, TaskDelegateResultContext, TaskOperationCreateContext, TaskOperationCreateResultContext, TaskHookContextMap, } from "./contexts";
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Task Hook Points - Hook 点常量定义
|
|
3
|
+
*
|
|
4
|
+
* 定义 Task Component 生命周期中的所有 Hook 点
|
|
5
|
+
*/
|
|
6
|
+
export declare const TaskHookPoints: {
|
|
7
|
+
/** 创建 Task 前 - 可干预 options */
|
|
8
|
+
readonly BEFORE_CREATE: "task:before.create";
|
|
9
|
+
/** 创建 Task 后 - 观察或触发副作用 */
|
|
10
|
+
readonly AFTER_CREATE: "task:after.create";
|
|
11
|
+
/** 更新 Task 前 - 可干预 options */
|
|
12
|
+
readonly BEFORE_UPDATE: "task:before.update";
|
|
13
|
+
/** 更新 Task 后 - 观察变更 */
|
|
14
|
+
readonly AFTER_UPDATE: "task:after.update";
|
|
15
|
+
/** 删除 Task 前 - 观察 */
|
|
16
|
+
readonly BEFORE_DELETE: "task:before.delete";
|
|
17
|
+
/** 删除 Task 后 - 清理关联资源 */
|
|
18
|
+
readonly AFTER_DELETE: "task:after.delete";
|
|
19
|
+
/**
|
|
20
|
+
* Task 完成 hook —— 仅当任务状态变为 terminal (completed / failed / cancelled / timeout)
|
|
21
|
+
* 时触发。语义级别比 AFTER_UPDATE 更精确,plugin 可用于实现"任务完成时"的副作用
|
|
22
|
+
* (例如发送通知、刷新看板、上传结果等)。
|
|
23
|
+
*
|
|
24
|
+
* 注意:AFTER_COMPLETE 与 AFTER_UPDATE 不互斥。
|
|
25
|
+
* - AFTER_UPDATE 在每一次 update 成功后触发,包括 status 变更、progress 变更等
|
|
26
|
+
* - AFTER_COMPLETE 仅在 status 进入 terminal 状态时触发
|
|
27
|
+
* 一个更新操作可能同时触发两个 hook。
|
|
28
|
+
*/
|
|
29
|
+
readonly AFTER_COMPLETE: "task:after.complete";
|
|
30
|
+
/** 委派任务前 - 可干预 prompt、参数 */
|
|
31
|
+
readonly DELEGATE_BEFORE: "task:delegate:before";
|
|
32
|
+
/** 委派任务后 - 观察结果 */
|
|
33
|
+
readonly DELEGATE_AFTER: "task:delegate:after";
|
|
34
|
+
/** 创建操作记录前 - 可干预 options */
|
|
35
|
+
readonly OPERATION_BEFORE_CREATE: "task:operation:before.create";
|
|
36
|
+
/** 创建操作记录后 - 观察或触发副作用 */
|
|
37
|
+
readonly OPERATION_AFTER_CREATE: "task:operation:after.create";
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Task Hook 点类型
|
|
41
|
+
*/
|
|
42
|
+
export type TaskHookPoint = typeof TaskHookPoints[keyof typeof TaskHookPoints];
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview AutoTaskPlugin v5.2 — uses shared meta-protocol helper
|
|
3
|
+
*
|
|
4
|
+
* 在 ReAct 循环达到 iteration 阈值(默认 20)时,在 agent:after.tool hook 中:
|
|
5
|
+
* 1. 检测 iteration === threshold && agent.name === agentName
|
|
6
|
+
* 2. per-query 去重(通过 traceId)
|
|
7
|
+
* 3. 调用 `enqueueToAddFakeUserMessage(ctx.toolResult, msg, "delegate")`:
|
|
8
|
+
* 设置 hookCtx.toolResult.result.metadata.toAddFakeUserMessage = {role:"user", ...}
|
|
9
|
+
* 与 MaxIterReminderPlugin 共享同一字段,确定性合并
|
|
10
|
+
* 4. React 循环在 pushMessage(tool result) 之后读取此 metadata 并 push user message
|
|
11
|
+
* 5. 保证 messages 顺序:[assistant(tool_calls), tool(result), user(reminder)] ✅
|
|
12
|
+
* 满足 AI SDK 要求 tool_call 与 tool_result 必须相邻
|
|
13
|
+
*
|
|
14
|
+
* v5.2 相比 v5.1 的核心改进(Task #2580 round 2):
|
|
15
|
+
* - ✅ 不再直接设置 `metadata.toAddFakeUserMessage = msg`(可能覆盖其他 plugin)
|
|
16
|
+
* - ✅ 改用共享 helper `enqueueToAddFakeUserMessage`,确定性合并多个 reminder
|
|
17
|
+
* - ✅ 在同一边界(如 threshold === maxIter-1)与 MaxIterReminderPlugin 协同工作
|
|
18
|
+
*/
|
|
19
|
+
import type { Plugin } from "../../agent/types";
|
|
20
|
+
export interface AutoTaskPluginConfig {
|
|
21
|
+
/**
|
|
22
|
+
* ReAct iteration 阈值(达到该 iteration 时触发提醒;默认 20)
|
|
23
|
+
*
|
|
24
|
+
* 如果你的场景是「永不提醒」,请传 `threshold: Infinity`(或在注册时关闭插件)。
|
|
25
|
+
*/
|
|
26
|
+
threshold?: number;
|
|
27
|
+
/** 仅在该 agent name 下触发(默认 "default") */
|
|
28
|
+
agentName?: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* 创建 AutoTaskPlugin v5.2
|
|
32
|
+
*
|
|
33
|
+
* 在 agent:after.tool hook 中,检测 iteration 达到阈值时:
|
|
34
|
+
* 1. 通过共享 helper 设置 hookCtx.toolResult.result.metadata.toAddFakeUserMessage
|
|
35
|
+
* 2. React 循环在 pushMessage(tool result) 之后读取此 metadata 并 push user message
|
|
36
|
+
* 3. 下一轮 LLM 调用会看到 user reminder,agent 自主决定调用 delegate_task
|
|
37
|
+
*/
|
|
38
|
+
export declare function createAutoTaskPlugin(config?: AutoTaskPluginConfig): Plugin;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview 任务卡片「该发到哪个群」的路由决策(Task #4230 follow-up)
|
|
3
|
+
*
|
|
4
|
+
* ## 背景(真实 bug,2026-10-15)
|
|
5
|
+
*
|
|
6
|
+
* Task #4226 的进展卡片被发进了 **「Task 3999 - 多模态ontology提取跟进」** 群。
|
|
7
|
+
* 根因链:
|
|
8
|
+
* 1. 触发消息来自 `oc_d083fc…`(= **task #3999 的跟进群**);
|
|
9
|
+
* 2. `LarkCliTaskNotifyHook` 的 `replyChannel.chatId` 优先(Task #4220 修复:
|
|
10
|
+
* 让 user 在触发群看到卡片)→ 卡片落到 `oc_d083fc…`;
|
|
11
|
+
* 3. #4226 是 sub-task(parent #2066),`PerTaskGroupChatPlugin` 默认跳过建群
|
|
12
|
+
* → #4226 从来没有自己的群。
|
|
13
|
+
*
|
|
14
|
+
* 结果:#3999 的专属群里出现了一张讲 #4226 的卡片 —— 跨任务污染。
|
|
15
|
+
*
|
|
16
|
+
* ## 决策规则(用户确认)
|
|
17
|
+
*
|
|
18
|
+
* - **触发群优先**(保持"在哪聊就在哪看到卡片")
|
|
19
|
+
* - **但跳过「别 task 的专属群」**:若触发群被判定为某个**非本 task lineage**
|
|
20
|
+
* 的 task 的专属群 → 卡片改发到本 task 自己的群(lineage 无群时新建)
|
|
21
|
+
* - 改投时在触发群补一条**链接卡片**(不是普通消息),让 user 知道卡片去哪了
|
|
22
|
+
*
|
|
23
|
+
* ## 「专属群」判定信号(多重信号,高精度优先)
|
|
24
|
+
*
|
|
25
|
+
* - `chat-binding`:session 的 chat↔task 绑定(PerTaskGroupChatPlugin 建群时写入)
|
|
26
|
+
* - `larkPerTaskChatId`:task.context 里插件写入的专属群字段
|
|
27
|
+
* - `followup_chat`:`*followup_chat_id` / `*_group_chat_id` 之类字段(老任务手工建的跟进群)
|
|
28
|
+
* - `chat-name`:群名里的 `Task 3999` / `#3999` 模式(对没留字段的手工群兜底)
|
|
29
|
+
*
|
|
30
|
+
* 注意:**不算** `feishu_chat_id` / `chat_id` 这类"会话群"字段 —— 它们表示
|
|
31
|
+
* "这个 task 曾在哪个群聊过",把普通会话群误判成专属群会让新任务的卡片被
|
|
32
|
+
* 错误地赶去新建群(假阳性比假阴性更烦人)。
|
|
33
|
+
*
|
|
34
|
+
* 本模块是**纯函数**(不碰 IO),IO(DB 反查 / lark-cli 取群名)由调用方
|
|
35
|
+
* (EventSource handler)注入,便于单测覆盖所有分支。
|
|
36
|
+
*/
|
|
37
|
+
/** 群名里隐含的 task id("Task 3999 - xxx" / "#3999 TMO 提取跟进") */
|
|
38
|
+
export declare const GROUP_NAME_TASK_ID_RE: RegExp;
|
|
39
|
+
/** 会把 chatId 记进 context 的字段名(用于 DB LIKE 反查) */
|
|
40
|
+
export declare const CTX_FIELD_LARK_PER_TASK_CHAT_ID = "larkPerTaskChatId";
|
|
41
|
+
/** 一个群可能的归属证据(多重信号并集) */
|
|
42
|
+
export interface ChatOwnership {
|
|
43
|
+
chatId: string;
|
|
44
|
+
/**
|
|
45
|
+
* 该群归属的 task id(可能多个:历史脏数据 / 多个 task 共用过一个群)
|
|
46
|
+
*
|
|
47
|
+
* 空数组 = 没有证据表明它是任何 task 的专属群。
|
|
48
|
+
*/
|
|
49
|
+
ownerTaskIds: number[];
|
|
50
|
+
/** 证据来源(诊断用):chat-binding / larkPerTaskChatId / followup_chat_id / chat-name */
|
|
51
|
+
sources: string[];
|
|
52
|
+
/** 群名(DB 记录或实时查询;可能没有) */
|
|
53
|
+
chatName?: string;
|
|
54
|
+
/** 是否被判为"专属群"(至少有一条**专属**证据) */
|
|
55
|
+
dedicated: boolean;
|
|
56
|
+
}
|
|
57
|
+
export type CardChatSource = "trigger-chat" | "own-group" | "ancestor-group" | "new-group" | "fallback-to-trigger" | "none";
|
|
58
|
+
export interface CardChatDecision {
|
|
59
|
+
chatId?: string;
|
|
60
|
+
profile?: string;
|
|
61
|
+
/** 目标群名(新建群时由 ensureGroupChat 回填,用于改投链接卡片渲染) */
|
|
62
|
+
chatName?: string;
|
|
63
|
+
source: CardChatSource;
|
|
64
|
+
/** 因触发群是"别 task 的专属群"而改投时记录(用于回补链接卡片) */
|
|
65
|
+
reroutedFrom?: {
|
|
66
|
+
chatId: string;
|
|
67
|
+
ownerTaskIds: number[];
|
|
68
|
+
sources: string[];
|
|
69
|
+
};
|
|
70
|
+
/** 人类可读的决策原因(写进 span / debug 日志) */
|
|
71
|
+
reason: string;
|
|
72
|
+
}
|
|
73
|
+
/** 从 task.context JSON 解析专属群 id(larkPerTaskChatId) */
|
|
74
|
+
export declare function extractPerTaskChatId(contextStr?: string): string | undefined;
|
|
75
|
+
/** 从 task.context JSON 解析专属群名(larkPerTaskChatName) */
|
|
76
|
+
export declare function extractPerTaskChatName(contextStr?: string): string | undefined;
|
|
77
|
+
/** 从 task.context JSON 解析专属群 profile(larkPerTaskChatProfile) */
|
|
78
|
+
export declare function extractPerTaskChatProfile(contextStr?: string): string | undefined;
|
|
79
|
+
/** 从 task.context JSON 解析记录下来的群名(含 `#3999` / `Task 3999` 模式) */
|
|
80
|
+
export declare function extractRecordedChatNames(contextStr?: string): string[];
|
|
81
|
+
/**
|
|
82
|
+
* 分析「某个 task 的 context 是否主张自己拥有 chatId」
|
|
83
|
+
*
|
|
84
|
+
* 只认**专属**信号;`feishu_chat_id` / `chat_id` 这类会话群字段会被忽略
|
|
85
|
+
* (否则会把普通会话群误判成专属群)。
|
|
86
|
+
*/
|
|
87
|
+
export declare function analyzeContextOwnership(contextStr: string | undefined, chatId: string): {
|
|
88
|
+
owned: boolean;
|
|
89
|
+
sources: string[];
|
|
90
|
+
impliedTaskIds: number[];
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* 由多个 task(DB 反查命中)的 context 汇总出 `ChatOwnership`
|
|
94
|
+
*
|
|
95
|
+
* @param chatId 目标群
|
|
96
|
+
* @param candidates DB 反查命中的 task(id + context)
|
|
97
|
+
* @param extra 额外信号(chat↔task 绑定 / 实时群名),由调用方提供
|
|
98
|
+
*/
|
|
99
|
+
export declare function mergeChatOwnership(chatId: string, candidates: Array<{
|
|
100
|
+
id: number;
|
|
101
|
+
context?: string;
|
|
102
|
+
}>, extra?: {
|
|
103
|
+
boundTaskId?: number | null;
|
|
104
|
+
/** 该群的真实群名(若调用方查到了) */
|
|
105
|
+
chatName?: string;
|
|
106
|
+
}): ChatOwnership;
|
|
107
|
+
/**
|
|
108
|
+
* 决定卡片该发到哪个群
|
|
109
|
+
*
|
|
110
|
+
* @param input.lineageIds 本 task 的 lineage(自己 + 所有祖先)task id
|
|
111
|
+
* @param input.lineageChat lineage 上找到的专属群(自己优先,其次最近祖先)
|
|
112
|
+
* @param input.triggerOwnership 触发群的归属分析(未做分析时传 undefined)
|
|
113
|
+
*/
|
|
114
|
+
export declare function decideCardChatTarget(input: {
|
|
115
|
+
taskId?: number;
|
|
116
|
+
lineageIds: number[];
|
|
117
|
+
lineageChat?: {
|
|
118
|
+
chatId: string;
|
|
119
|
+
profile?: string;
|
|
120
|
+
isSelf: boolean;
|
|
121
|
+
};
|
|
122
|
+
triggerChatId?: string;
|
|
123
|
+
triggerProfile?: string;
|
|
124
|
+
triggerOwnership?: ChatOwnership;
|
|
125
|
+
/**
|
|
126
|
+
* ★ Task #4331:是否允许"new-group"路径(即触发群是别人的群 + 本 task 无群时建专属群)
|
|
127
|
+
*
|
|
128
|
+
* 默认 false(用户新要求:默认不建群)
|
|
129
|
+
* - true:保留 #4230 的老行为(建专属群),用于向后兼容显式开启的场景
|
|
130
|
+
* - false:触发群是别人的群 + 本 task 无群 → 退回触发群(不建群)
|
|
131
|
+
*
|
|
132
|
+
* 不影响其他 source(trigger-chat / own-group / ancestor-group / none)的决策。
|
|
133
|
+
*/
|
|
134
|
+
allowNewGroup?: boolean;
|
|
135
|
+
}): CardChatDecision;
|