@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,704 @@
|
|
|
1
|
+
import"../../../shared/@ai-setting/roy-agent-core-fs0mn2jk.js";
|
|
2
|
+
// src/env/task/backend/task-store-backend.ts
|
|
3
|
+
var DELIVERABLE_OPERATION_PREFIX = "Deliverable: ";
|
|
4
|
+
function formatDeliverableForOperation(deliverableStoragePath) {
|
|
5
|
+
if (!deliverableStoragePath)
|
|
6
|
+
return;
|
|
7
|
+
return `${DELIVERABLE_OPERATION_PREFIX}${deliverableStoragePath}`;
|
|
8
|
+
}
|
|
9
|
+
var SCAN_ALL = 1e6;
|
|
10
|
+
|
|
11
|
+
class TaskStoreBackend {
|
|
12
|
+
port;
|
|
13
|
+
options;
|
|
14
|
+
constructor(port, options = {}) {
|
|
15
|
+
this.port = port;
|
|
16
|
+
this.options = options;
|
|
17
|
+
}
|
|
18
|
+
get defaultSessionId() {
|
|
19
|
+
return this.options.sessionId ?? "unknown";
|
|
20
|
+
}
|
|
21
|
+
async resolve(id) {
|
|
22
|
+
const asNum = toNumericHandle(id);
|
|
23
|
+
if (asNum !== undefined) {
|
|
24
|
+
if (typeof this.port.getTaskByNum === "function") {
|
|
25
|
+
return await this.port.getTaskByNum(asNum);
|
|
26
|
+
}
|
|
27
|
+
return (await this.scanAllTasks()).find((t) => t.id === asNum) ?? null;
|
|
28
|
+
}
|
|
29
|
+
return await this.port.getTask(String(id));
|
|
30
|
+
}
|
|
31
|
+
toTask(record) {
|
|
32
|
+
const { nativeId: _nativeId, ...task } = record;
|
|
33
|
+
return task;
|
|
34
|
+
}
|
|
35
|
+
toOperation(record) {
|
|
36
|
+
const { nativeId: _nativeId, ...operation } = record;
|
|
37
|
+
return operation;
|
|
38
|
+
}
|
|
39
|
+
async scanAllTasks() {
|
|
40
|
+
const res = await this.port.listTasks({
|
|
41
|
+
limit: SCAN_ALL,
|
|
42
|
+
offset: 0,
|
|
43
|
+
includeArchived: true
|
|
44
|
+
});
|
|
45
|
+
return res.tasks;
|
|
46
|
+
}
|
|
47
|
+
async createTask(input) {
|
|
48
|
+
const sessionId = input.sessionId ?? this.defaultSessionId;
|
|
49
|
+
let parentNum;
|
|
50
|
+
if (input.parent_task_id !== undefined && input.parent_task_id !== null) {
|
|
51
|
+
const parent = await this.resolve(input.parent_task_id);
|
|
52
|
+
if (!parent) {
|
|
53
|
+
throw new Error(`Parent task #${input.parent_task_id} not found.`);
|
|
54
|
+
}
|
|
55
|
+
parentNum = parent.id;
|
|
56
|
+
}
|
|
57
|
+
const created = await this.port.createTask({
|
|
58
|
+
title: input.title,
|
|
59
|
+
description: input.description,
|
|
60
|
+
priority: input.priority,
|
|
61
|
+
type: input.type,
|
|
62
|
+
goals_and_expected_deliverables: input.goals_and_expected_deliverables,
|
|
63
|
+
...parentNum !== undefined ? { parent_task_id: parentNum } : {},
|
|
64
|
+
due_date: input.due_date,
|
|
65
|
+
tags: input.tags,
|
|
66
|
+
project_path: input.project_path,
|
|
67
|
+
context: input.context,
|
|
68
|
+
sessionId
|
|
69
|
+
});
|
|
70
|
+
await this.createOperation({
|
|
71
|
+
taskId: created.id,
|
|
72
|
+
sessionId,
|
|
73
|
+
milestoneType: "create",
|
|
74
|
+
milestoneTitle: `Task created: ${created.title}`,
|
|
75
|
+
milestoneDescription: created.description ?? ""
|
|
76
|
+
});
|
|
77
|
+
return this.toTask(created);
|
|
78
|
+
}
|
|
79
|
+
async getTask(id) {
|
|
80
|
+
const record = await this.resolve(id);
|
|
81
|
+
return record ? this.toTask(record) : null;
|
|
82
|
+
}
|
|
83
|
+
async getTaskWithOperations(id) {
|
|
84
|
+
const task = await this.getTask(id);
|
|
85
|
+
if (!task)
|
|
86
|
+
return null;
|
|
87
|
+
const operations = await this.listOperations({ taskId: task.id, limit: SCAN_ALL, offset: 0 });
|
|
88
|
+
return { ...task, operations };
|
|
89
|
+
}
|
|
90
|
+
async listTasks(options = {}) {
|
|
91
|
+
const limit = options.limit ?? 20;
|
|
92
|
+
const offset = options.offset ?? 0;
|
|
93
|
+
let views = (await this.scanAllTasks()).map((t) => this.toTask(t));
|
|
94
|
+
views = this.applyFilters(views, options);
|
|
95
|
+
return { tasks: views.slice(offset, offset + limit), total: views.length };
|
|
96
|
+
}
|
|
97
|
+
async updateTask(id, input) {
|
|
98
|
+
const record = await this.resolve(id);
|
|
99
|
+
if (!record)
|
|
100
|
+
return null;
|
|
101
|
+
let parentNum;
|
|
102
|
+
if (input.parent_task_id !== undefined) {
|
|
103
|
+
if (input.parent_task_id === null) {
|
|
104
|
+
parentNum = null;
|
|
105
|
+
} else {
|
|
106
|
+
const parent = await this.resolve(input.parent_task_id);
|
|
107
|
+
if (!parent)
|
|
108
|
+
throw new Error(`Parent task #${input.parent_task_id} not found.`);
|
|
109
|
+
parentNum = parent.id;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
const updated = await this.port.updateTask(record.nativeId, {
|
|
113
|
+
title: input.title,
|
|
114
|
+
description: input.description,
|
|
115
|
+
status: input.status,
|
|
116
|
+
priority: input.priority,
|
|
117
|
+
type: input.type,
|
|
118
|
+
progress: input.progress,
|
|
119
|
+
current_status: input.current_status,
|
|
120
|
+
goals_and_expected_deliverables: input.goals_and_expected_deliverables,
|
|
121
|
+
due_date: input.due_date,
|
|
122
|
+
tags: input.tags,
|
|
123
|
+
project_path: input.project_path,
|
|
124
|
+
context: input.context,
|
|
125
|
+
...parentNum !== undefined ? { parent_task_id: parentNum } : {}
|
|
126
|
+
});
|
|
127
|
+
return updated ? this.toTask(updated) : null;
|
|
128
|
+
}
|
|
129
|
+
async deleteTask(id) {
|
|
130
|
+
const record = await this.resolve(id);
|
|
131
|
+
if (!record)
|
|
132
|
+
return false;
|
|
133
|
+
return await this.port.deleteTask(record.nativeId);
|
|
134
|
+
}
|
|
135
|
+
async completeTask(id, sessionId, deliverable) {
|
|
136
|
+
const record = await this.resolve(id);
|
|
137
|
+
if (!record)
|
|
138
|
+
return null;
|
|
139
|
+
if (record.type === "cycle") {
|
|
140
|
+
throw new Error(`Cannot complete cycle task: #${record.id} - ${record.title}. Cycle tasks are not meant to be completed.`);
|
|
141
|
+
}
|
|
142
|
+
const patch = { status: "completed", progress: 100 };
|
|
143
|
+
if (deliverable) {
|
|
144
|
+
patch.context = mergeDeliverableIntoContext(record.context, deliverable);
|
|
145
|
+
}
|
|
146
|
+
const updated = await this.port.updateTask(record.nativeId, patch);
|
|
147
|
+
if (!updated)
|
|
148
|
+
return null;
|
|
149
|
+
const formatted = formatDeliverableForOperation(deliverable);
|
|
150
|
+
await this.createOperation({
|
|
151
|
+
taskId: updated.id,
|
|
152
|
+
sessionId: sessionId ?? this.defaultSessionId,
|
|
153
|
+
milestoneType: "completed",
|
|
154
|
+
milestoneTitle: `Completed: ${updated.title}`,
|
|
155
|
+
milestoneDescription: formatted ?? "Task completed",
|
|
156
|
+
...deliverable ? { mdPath: deliverable } : {}
|
|
157
|
+
});
|
|
158
|
+
const reread = await this.resolve(record.nativeId);
|
|
159
|
+
return this.toTask(reread ?? updated);
|
|
160
|
+
}
|
|
161
|
+
async getTaskTree(id, depth = -1) {
|
|
162
|
+
const root = await this.resolve(id);
|
|
163
|
+
if (!root)
|
|
164
|
+
return [];
|
|
165
|
+
if (depth === 0)
|
|
166
|
+
return [];
|
|
167
|
+
const views = (await this.scanAllTasks()).map((t) => this.toTask(t));
|
|
168
|
+
const byParent = new Map;
|
|
169
|
+
for (const t of views) {
|
|
170
|
+
if (t.parent_task_id === undefined)
|
|
171
|
+
continue;
|
|
172
|
+
const bucket = byParent.get(t.parent_task_id) ?? [];
|
|
173
|
+
bucket.push(t);
|
|
174
|
+
byParent.set(t.parent_task_id, bucket);
|
|
175
|
+
}
|
|
176
|
+
const collected = [];
|
|
177
|
+
const seen = new Set([root.id]);
|
|
178
|
+
let frontier = [root.id];
|
|
179
|
+
let level = 0;
|
|
180
|
+
while (frontier.length > 0) {
|
|
181
|
+
if (depth !== -1 && level >= depth)
|
|
182
|
+
break;
|
|
183
|
+
const next = [];
|
|
184
|
+
for (const parentId of frontier) {
|
|
185
|
+
for (const child of byParent.get(parentId) ?? []) {
|
|
186
|
+
if (seen.has(child.id))
|
|
187
|
+
continue;
|
|
188
|
+
seen.add(child.id);
|
|
189
|
+
collected.push(child);
|
|
190
|
+
next.push(child.id);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
frontier = next;
|
|
194
|
+
level++;
|
|
195
|
+
}
|
|
196
|
+
return collected;
|
|
197
|
+
}
|
|
198
|
+
async searchTasksByKeywords(keywords, options = {}) {
|
|
199
|
+
const limit = options.limit ?? 20;
|
|
200
|
+
const offset = options.offset ?? 0;
|
|
201
|
+
let candidates = (await this.scanAllTasks()).map((t) => this.toTask(t));
|
|
202
|
+
candidates = this.applyFilters(candidates, options);
|
|
203
|
+
if (options.excludeTaskId !== undefined) {
|
|
204
|
+
candidates = candidates.filter((t) => t.id !== options.excludeTaskId);
|
|
205
|
+
}
|
|
206
|
+
const needles = keywords.map((k) => k.toLowerCase()).filter((k) => k.length > 0);
|
|
207
|
+
const hits = needles.length === 0 ? candidates : candidates.filter((t) => {
|
|
208
|
+
const haystack = [
|
|
209
|
+
t.title,
|
|
210
|
+
t.description,
|
|
211
|
+
t.goals_and_expected_deliverables,
|
|
212
|
+
t.current_status,
|
|
213
|
+
(t.tags ?? []).join(" "),
|
|
214
|
+
t.project_path
|
|
215
|
+
].join(" ").toLowerCase();
|
|
216
|
+
return needles.every((n) => haystack.includes(n));
|
|
217
|
+
});
|
|
218
|
+
return { tasks: hits.slice(offset, offset + limit), total: hits.length };
|
|
219
|
+
}
|
|
220
|
+
async createOperation(input) {
|
|
221
|
+
const task = await this.resolve(input.taskId);
|
|
222
|
+
if (!task)
|
|
223
|
+
throw new Error(`Task not found: ${input.taskId}`);
|
|
224
|
+
const milestoneType = input.milestoneType ?? input.actionType ?? "progress";
|
|
225
|
+
const milestoneTitle = input.milestoneTitle ?? input.actionTitle ?? "";
|
|
226
|
+
const milestoneDescription = input.milestoneDescription ?? input.actionDescription ?? "";
|
|
227
|
+
const created = await this.port.createOperation({
|
|
228
|
+
taskId: task.id,
|
|
229
|
+
taskNativeId: task.nativeId,
|
|
230
|
+
sessionId: input.sessionId ?? this.defaultSessionId,
|
|
231
|
+
milestoneType,
|
|
232
|
+
milestoneTitle,
|
|
233
|
+
milestoneDescription,
|
|
234
|
+
processDescription: input.processDescription ?? "",
|
|
235
|
+
...input.mdPath ? { mdPath: input.mdPath } : {}
|
|
236
|
+
});
|
|
237
|
+
return this.toOperation(created);
|
|
238
|
+
}
|
|
239
|
+
async listOperations(options = {}) {
|
|
240
|
+
const limit = options.limit ?? 100;
|
|
241
|
+
const offset = options.offset ?? 0;
|
|
242
|
+
const filterType = options.milestoneType ?? options.actionType;
|
|
243
|
+
if (options.taskId === undefined) {
|
|
244
|
+
return [];
|
|
245
|
+
}
|
|
246
|
+
const task = await this.resolve(options.taskId);
|
|
247
|
+
if (!task)
|
|
248
|
+
return [];
|
|
249
|
+
const res = await this.port.listOperations({
|
|
250
|
+
taskNativeId: task.nativeId,
|
|
251
|
+
limit: filterType ? SCAN_ALL : limit,
|
|
252
|
+
offset: filterType ? 0 : offset
|
|
253
|
+
});
|
|
254
|
+
let operations = res.operations.map((o) => this.toOperation(o));
|
|
255
|
+
if (filterType) {
|
|
256
|
+
operations = operations.filter((o) => o.milestoneType === filterType);
|
|
257
|
+
operations = operations.slice(offset, offset + limit);
|
|
258
|
+
}
|
|
259
|
+
return operations;
|
|
260
|
+
}
|
|
261
|
+
async getOperation(id) {
|
|
262
|
+
if (typeof this.port.getOperationByNum === "function") {
|
|
263
|
+
const op = await this.port.getOperationByNum(id);
|
|
264
|
+
return op ? this.toOperation(op) : null;
|
|
265
|
+
}
|
|
266
|
+
const tasks = await this.scanAllTasks();
|
|
267
|
+
for (const task of tasks) {
|
|
268
|
+
const res = await this.port.listOperations({ taskNativeId: task.nativeId, limit: SCAN_ALL });
|
|
269
|
+
const found = res.operations.find((o) => o.id === id);
|
|
270
|
+
if (found)
|
|
271
|
+
return this.toOperation(found);
|
|
272
|
+
}
|
|
273
|
+
return null;
|
|
274
|
+
}
|
|
275
|
+
async updateOperation(id, patch) {
|
|
276
|
+
const existing = await this.getOperation(id);
|
|
277
|
+
if (!existing)
|
|
278
|
+
return null;
|
|
279
|
+
if (typeof this.port.updateOperationByNum !== "function")
|
|
280
|
+
return existing;
|
|
281
|
+
const updated = await this.port.updateOperationByNum(id, {
|
|
282
|
+
sessionId: patch.sessionId ?? existing.sessionId,
|
|
283
|
+
milestoneType: patch.milestoneType ?? patch.actionType ?? existing.milestoneType,
|
|
284
|
+
milestoneTitle: patch.milestoneTitle ?? patch.actionTitle ?? existing.milestoneTitle,
|
|
285
|
+
milestoneDescription: patch.milestoneDescription ?? patch.actionDescription ?? existing.milestoneDescription,
|
|
286
|
+
processDescription: patch.processDescription ?? existing.processDescription,
|
|
287
|
+
...patch.mdPath !== undefined ? { mdPath: patch.mdPath } : {}
|
|
288
|
+
});
|
|
289
|
+
return updated ? this.toOperation(updated) : null;
|
|
290
|
+
}
|
|
291
|
+
async deleteOperation(id) {
|
|
292
|
+
if (typeof this.port.deleteOperationByNum !== "function")
|
|
293
|
+
return false;
|
|
294
|
+
return await this.port.deleteOperationByNum(id);
|
|
295
|
+
}
|
|
296
|
+
applyFilters(views, options) {
|
|
297
|
+
let out = views;
|
|
298
|
+
const excludeArchived = options.include_archived !== true && options.status !== "archived";
|
|
299
|
+
if (excludeArchived)
|
|
300
|
+
out = out.filter((t) => t.status !== "archived");
|
|
301
|
+
if (options.status !== undefined)
|
|
302
|
+
out = out.filter((t) => t.status === options.status);
|
|
303
|
+
if (options.priority !== undefined)
|
|
304
|
+
out = out.filter((t) => t.priority === options.priority);
|
|
305
|
+
if (options.type !== undefined)
|
|
306
|
+
out = out.filter((t) => t.type === options.type);
|
|
307
|
+
if (options.parent_task_id !== undefined) {
|
|
308
|
+
out = out.filter((t) => t.parent_task_id === options.parent_task_id);
|
|
309
|
+
}
|
|
310
|
+
if (options.depth !== undefined && options.depth >= 0) {
|
|
311
|
+
const allowed = allowedIdsByDepth(out, options.depth);
|
|
312
|
+
out = out.filter((t) => allowed.has(t.id));
|
|
313
|
+
}
|
|
314
|
+
return out;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
function toNumericHandle(id) {
|
|
318
|
+
if (typeof id === "number") {
|
|
319
|
+
return Number.isFinite(id) ? id : undefined;
|
|
320
|
+
}
|
|
321
|
+
return /^\d+$/.test(id) ? Number(id) : undefined;
|
|
322
|
+
}
|
|
323
|
+
function allowedIdsByDepth(views, depth) {
|
|
324
|
+
if (depth < 0)
|
|
325
|
+
return new Set(views.map((t) => t.id));
|
|
326
|
+
const ids = new Set(views.map((t) => t.id));
|
|
327
|
+
const byParent = new Map;
|
|
328
|
+
for (const t of views) {
|
|
329
|
+
const key = t.parent_task_id;
|
|
330
|
+
if (key === undefined || !ids.has(key))
|
|
331
|
+
continue;
|
|
332
|
+
const bucket = byParent.get(key) ?? [];
|
|
333
|
+
bucket.push(t);
|
|
334
|
+
byParent.set(key, bucket);
|
|
335
|
+
}
|
|
336
|
+
const allowed = new Set;
|
|
337
|
+
let frontier = views.filter((t) => t.parent_task_id === undefined || !ids.has(t.parent_task_id));
|
|
338
|
+
for (const t of frontier)
|
|
339
|
+
allowed.add(t.id);
|
|
340
|
+
for (let level = 1;level <= depth; level++) {
|
|
341
|
+
const next = [];
|
|
342
|
+
for (const parent of frontier) {
|
|
343
|
+
for (const child of byParent.get(parent.id) ?? []) {
|
|
344
|
+
if (allowed.has(child.id))
|
|
345
|
+
continue;
|
|
346
|
+
allowed.add(child.id);
|
|
347
|
+
next.push(child);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
if (next.length === 0)
|
|
351
|
+
break;
|
|
352
|
+
frontier = next;
|
|
353
|
+
}
|
|
354
|
+
return allowed;
|
|
355
|
+
}
|
|
356
|
+
function mergeDeliverableIntoContext(rawContext, deliverable) {
|
|
357
|
+
let parsed = {};
|
|
358
|
+
if (typeof rawContext === "string" && rawContext.trim().length > 0) {
|
|
359
|
+
try {
|
|
360
|
+
const candidate = JSON.parse(rawContext);
|
|
361
|
+
if (candidate && typeof candidate === "object" && !Array.isArray(candidate)) {
|
|
362
|
+
parsed = candidate;
|
|
363
|
+
}
|
|
364
|
+
} catch {}
|
|
365
|
+
}
|
|
366
|
+
parsed.deliverable_storage_path = deliverable;
|
|
367
|
+
return JSON.stringify(parsed);
|
|
368
|
+
}
|
|
369
|
+
// src/env/task/backend/sqlite-task-port.ts
|
|
370
|
+
function createSQLiteTaskPort(store) {
|
|
371
|
+
return {
|
|
372
|
+
hidesArchivedByDefault: true,
|
|
373
|
+
async createTask(input) {
|
|
374
|
+
const task = await store.createTask({
|
|
375
|
+
title: input.title,
|
|
376
|
+
description: input.description,
|
|
377
|
+
...input.priority !== undefined ? { priority: input.priority } : {},
|
|
378
|
+
...input.type !== undefined ? { type: input.type } : {},
|
|
379
|
+
...input.parent_task_id !== undefined ? { parent_task_id: input.parent_task_id } : {},
|
|
380
|
+
...input.goals_and_expected_deliverables !== undefined ? { goals_and_expected_deliverables: input.goals_and_expected_deliverables } : {},
|
|
381
|
+
...input.due_date !== undefined ? { due_date: input.due_date } : {},
|
|
382
|
+
...input.tags !== undefined ? { tags: input.tags } : {},
|
|
383
|
+
sessionId: input.sessionId ?? "unknown",
|
|
384
|
+
project_path: input.project_path,
|
|
385
|
+
context: input.context
|
|
386
|
+
});
|
|
387
|
+
return { ...task, nativeId: String(task.id) };
|
|
388
|
+
},
|
|
389
|
+
async getTask(nativeId) {
|
|
390
|
+
const num = Number(nativeId);
|
|
391
|
+
if (!Number.isFinite(num))
|
|
392
|
+
return null;
|
|
393
|
+
const task = await store.getTask(num);
|
|
394
|
+
return task ? { ...task, nativeId: String(task.id) } : null;
|
|
395
|
+
},
|
|
396
|
+
async getTaskByNum(num) {
|
|
397
|
+
const task = await store.getTask(num);
|
|
398
|
+
return task ? { ...task, nativeId: String(task.id) } : null;
|
|
399
|
+
},
|
|
400
|
+
async listTasks(options) {
|
|
401
|
+
const res = await store.listTasks({
|
|
402
|
+
limit: options?.limit ?? 20,
|
|
403
|
+
offset: options?.offset ?? 0,
|
|
404
|
+
...options?.includeArchived ? { include_archived: true } : {}
|
|
405
|
+
});
|
|
406
|
+
return {
|
|
407
|
+
tasks: res.tasks.map((t) => ({ ...t, nativeId: String(t.id) })),
|
|
408
|
+
total: res.total
|
|
409
|
+
};
|
|
410
|
+
},
|
|
411
|
+
async updateTask(nativeId, patch) {
|
|
412
|
+
const num = Number(nativeId);
|
|
413
|
+
if (!Number.isFinite(num))
|
|
414
|
+
return null;
|
|
415
|
+
const task = await store.updateTask(num, patch);
|
|
416
|
+
return task ? { ...task, nativeId: String(task.id) } : null;
|
|
417
|
+
},
|
|
418
|
+
async deleteTask(nativeId) {
|
|
419
|
+
const num = Number(nativeId);
|
|
420
|
+
if (!Number.isFinite(num))
|
|
421
|
+
return false;
|
|
422
|
+
return await store.deleteTask(num);
|
|
423
|
+
},
|
|
424
|
+
async createOperation(input) {
|
|
425
|
+
const op = await store.createOperation({
|
|
426
|
+
taskId: input.taskId,
|
|
427
|
+
sessionId: input.sessionId,
|
|
428
|
+
milestoneType: input.milestoneType,
|
|
429
|
+
milestoneTitle: input.milestoneTitle,
|
|
430
|
+
milestoneDescription: input.milestoneDescription,
|
|
431
|
+
processDescription: input.processDescription,
|
|
432
|
+
...input.mdPath ? { mdPath: input.mdPath } : {}
|
|
433
|
+
});
|
|
434
|
+
return { ...op, nativeId: String(op.id) };
|
|
435
|
+
},
|
|
436
|
+
async listOperations(options) {
|
|
437
|
+
const num = Number(options?.taskNativeId);
|
|
438
|
+
if (!Number.isFinite(num))
|
|
439
|
+
return { operations: [], total: 0 };
|
|
440
|
+
const all = await store.listOperations({ taskId: num, limit: 1e6, offset: 0 });
|
|
441
|
+
const offset = options?.offset ?? 0;
|
|
442
|
+
const limit = options?.limit ?? all.length;
|
|
443
|
+
return {
|
|
444
|
+
operations: all.slice(offset, offset + limit).map((o) => ({ ...o, nativeId: String(o.id) })),
|
|
445
|
+
total: all.length
|
|
446
|
+
};
|
|
447
|
+
},
|
|
448
|
+
async getOperationByNum(num) {
|
|
449
|
+
const op = await store.getOperation(num);
|
|
450
|
+
return op ? { ...op, nativeId: String(op.id) } : null;
|
|
451
|
+
},
|
|
452
|
+
async updateOperationByNum(num, patch) {
|
|
453
|
+
const op = await store.updateOperation(num, {
|
|
454
|
+
...patch.milestoneTitle !== undefined ? { milestoneTitle: patch.milestoneTitle } : {},
|
|
455
|
+
...patch.milestoneDescription !== undefined ? { milestoneDescription: patch.milestoneDescription } : {},
|
|
456
|
+
...patch.processDescription !== undefined ? { processDescription: patch.processDescription } : {}
|
|
457
|
+
});
|
|
458
|
+
return op ? { ...op, nativeId: String(op.id) } : null;
|
|
459
|
+
},
|
|
460
|
+
async deleteOperationByNum(num) {
|
|
461
|
+
return await store.deleteOperation(num);
|
|
462
|
+
}
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
// src/env/task/backend/roy-sidecar-task-port.ts
|
|
466
|
+
var DEFAULT_SCAN = 1e6;
|
|
467
|
+
function toSidecarPatch(patch) {
|
|
468
|
+
const out = {};
|
|
469
|
+
if (patch.type !== undefined)
|
|
470
|
+
out.type = patch.type;
|
|
471
|
+
if (patch.progress !== undefined)
|
|
472
|
+
out.progress = patch.progress;
|
|
473
|
+
if (patch.current_status !== undefined)
|
|
474
|
+
out.current_status = patch.current_status;
|
|
475
|
+
if (patch.goals_and_expected_deliverables !== undefined) {
|
|
476
|
+
out.goals_and_expected_deliverables = patch.goals_and_expected_deliverables;
|
|
477
|
+
}
|
|
478
|
+
if (patch.project_path !== undefined)
|
|
479
|
+
out.project_path = patch.project_path;
|
|
480
|
+
if (patch.context !== undefined)
|
|
481
|
+
out.context = patch.context;
|
|
482
|
+
if (patch.due_date !== undefined)
|
|
483
|
+
out.due_date = patch.due_date;
|
|
484
|
+
return out;
|
|
485
|
+
}
|
|
486
|
+
function toStoredTask(record, vocabulary, parentNum) {
|
|
487
|
+
if (typeof record.num !== "number") {
|
|
488
|
+
throw new Error(`store did not expose a numeric handle for task ${record.id}`);
|
|
489
|
+
}
|
|
490
|
+
const side = record.roy ?? {};
|
|
491
|
+
return {
|
|
492
|
+
id: record.num,
|
|
493
|
+
nativeId: record.id,
|
|
494
|
+
title: record.title,
|
|
495
|
+
description: record.description ?? "",
|
|
496
|
+
status: vocabulary.toRoyStatus(record.status),
|
|
497
|
+
priority: vocabulary.toRoyPriority(record.priority),
|
|
498
|
+
type: side.type ?? "normal",
|
|
499
|
+
progress: typeof side.progress === "number" ? side.progress : record.status === "done" ? 100 : 0,
|
|
500
|
+
current_status: side.current_status ?? "",
|
|
501
|
+
goals_and_expected_deliverables: side.goals_and_expected_deliverables ?? "",
|
|
502
|
+
...parentNum !== undefined ? { parent_task_id: parentNum } : {},
|
|
503
|
+
createdAt: record.created_at,
|
|
504
|
+
updatedAt: record.updated_at,
|
|
505
|
+
...side.due_date ? { due_date: side.due_date } : {},
|
|
506
|
+
tags: vocabulary.toRoyTags(record.tags),
|
|
507
|
+
project_path: side.project_path ?? "unknown",
|
|
508
|
+
context: side.context ?? "{}"
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
function toStoredOperation(record) {
|
|
512
|
+
const data = record.data ?? {};
|
|
513
|
+
const milestoneType = String(data.milestoneType ?? data.actionType ?? "progress");
|
|
514
|
+
const milestoneTitle = String(data.milestoneTitle ?? data.actionTitle ?? "");
|
|
515
|
+
const milestoneDescription = String(data.milestoneDescription ?? data.actionDescription ?? "");
|
|
516
|
+
const taskIdRaw = data.taskId ?? record.task_id;
|
|
517
|
+
const taskId = typeof taskIdRaw === "number" ? taskIdRaw : typeof taskIdRaw === "string" && /^\d+$/.test(taskIdRaw) ? Number(taskIdRaw) : 0;
|
|
518
|
+
return {
|
|
519
|
+
id: typeof record.num === "number" ? record.num : 0,
|
|
520
|
+
nativeId: record.id,
|
|
521
|
+
taskId,
|
|
522
|
+
sessionId: String(data.sessionId ?? record.task_id ?? "unknown"),
|
|
523
|
+
milestoneType,
|
|
524
|
+
milestoneTitle,
|
|
525
|
+
milestoneDescription,
|
|
526
|
+
processDescription: String(data.processDescription ?? ""),
|
|
527
|
+
timestamp: record.created_at,
|
|
528
|
+
...data.mdPath ? { mdPath: String(data.mdPath) } : {},
|
|
529
|
+
actionType: milestoneType,
|
|
530
|
+
actionTitle: milestoneTitle,
|
|
531
|
+
actionDescription: milestoneDescription
|
|
532
|
+
};
|
|
533
|
+
}
|
|
534
|
+
function createRoySidecarTaskPort(store, vocabulary, options = {}) {
|
|
535
|
+
const operationType = options.operationType ?? "roy.milestone";
|
|
536
|
+
const agent = options.agent ?? "roy";
|
|
537
|
+
const scanLimit = options.scanLimit ?? DEFAULT_SCAN;
|
|
538
|
+
async function parentNumMap() {
|
|
539
|
+
const all = await store.listTasks({ limit: scanLimit });
|
|
540
|
+
return new Map(all.tasks.filter((t) => typeof t.num === "number").map((t) => [t.id, t.num]));
|
|
541
|
+
}
|
|
542
|
+
async function resolveByNum(num) {
|
|
543
|
+
if (typeof store.getTaskByNum === "function")
|
|
544
|
+
return await store.getTaskByNum(num);
|
|
545
|
+
const all = await store.listTasks({ limit: scanLimit });
|
|
546
|
+
return all.tasks.find((t) => t.num === num) ?? null;
|
|
547
|
+
}
|
|
548
|
+
async function nativeIdOf(num) {
|
|
549
|
+
const nums = await parentNumMap();
|
|
550
|
+
const hit = [...nums.entries()].find(([, n]) => n === num);
|
|
551
|
+
if (!hit)
|
|
552
|
+
throw new Error(`parent task not found: ${num}`);
|
|
553
|
+
return hit[0];
|
|
554
|
+
}
|
|
555
|
+
return {
|
|
556
|
+
hidesArchivedByDefault: false,
|
|
557
|
+
async createTask(input) {
|
|
558
|
+
const parentId = input.parent_task_id !== undefined ? await nativeIdOf(input.parent_task_id) : null;
|
|
559
|
+
const sidecar = {
|
|
560
|
+
type: input.type ?? "normal",
|
|
561
|
+
progress: input.progress ?? 0,
|
|
562
|
+
current_status: input.current_status ?? "",
|
|
563
|
+
goals_and_expected_deliverables: input.goals_and_expected_deliverables ?? "",
|
|
564
|
+
project_path: input.project_path,
|
|
565
|
+
context: input.context,
|
|
566
|
+
...input.due_date ? { due_date: input.due_date } : {}
|
|
567
|
+
};
|
|
568
|
+
const created = await store.createTask({
|
|
569
|
+
title: input.title,
|
|
570
|
+
description: input.description,
|
|
571
|
+
priority: vocabulary.toStorePriority(input.priority),
|
|
572
|
+
owner: agent,
|
|
573
|
+
tags: vocabulary.toStoreTags(input.tags),
|
|
574
|
+
parent_id: parentId,
|
|
575
|
+
session_id: input.sessionId ?? "unknown",
|
|
576
|
+
roy: sidecar
|
|
577
|
+
});
|
|
578
|
+
return toStoredTask(created, vocabulary, input.parent_task_id);
|
|
579
|
+
},
|
|
580
|
+
async getTask(nativeId) {
|
|
581
|
+
const task = await store.getTask(nativeId);
|
|
582
|
+
if (!task)
|
|
583
|
+
return null;
|
|
584
|
+
const nums = await parentNumMap();
|
|
585
|
+
return toStoredTask(task, vocabulary, task.parent_id ? nums.get(task.parent_id) : undefined);
|
|
586
|
+
},
|
|
587
|
+
async getTaskByNum(num) {
|
|
588
|
+
const task = await resolveByNum(num);
|
|
589
|
+
if (!task)
|
|
590
|
+
return null;
|
|
591
|
+
const nums = await parentNumMap();
|
|
592
|
+
return toStoredTask(task, vocabulary, task.parent_id ? nums.get(task.parent_id) : undefined);
|
|
593
|
+
},
|
|
594
|
+
async listTasks(request) {
|
|
595
|
+
const res = await store.listTasks({
|
|
596
|
+
limit: request?.limit ?? 20,
|
|
597
|
+
offset: request?.offset ?? 0
|
|
598
|
+
});
|
|
599
|
+
const nums = await parentNumMap();
|
|
600
|
+
return {
|
|
601
|
+
tasks: res.tasks.map((t) => toStoredTask(t, vocabulary, t.parent_id ? nums.get(t.parent_id) : undefined)),
|
|
602
|
+
total: res.total
|
|
603
|
+
};
|
|
604
|
+
},
|
|
605
|
+
async updateTask(nativeId, patch) {
|
|
606
|
+
const sidePatch = toSidecarPatch(patch);
|
|
607
|
+
const updated = await store.updateTask(nativeId, {
|
|
608
|
+
...patch.title !== undefined ? { title: patch.title } : {},
|
|
609
|
+
...patch.description !== undefined ? { description: patch.description } : {},
|
|
610
|
+
...patch.status !== undefined ? { status: vocabulary.toStoreStatus(patch.status) } : {},
|
|
611
|
+
...patch.priority !== undefined ? { priority: vocabulary.toStorePriority(patch.priority) } : {},
|
|
612
|
+
...patch.tags !== undefined ? { tags: vocabulary.toStoreTags(patch.tags) } : {},
|
|
613
|
+
...Object.keys(sidePatch).length > 0 ? { roy: sidePatch } : {}
|
|
614
|
+
});
|
|
615
|
+
if (!updated)
|
|
616
|
+
return null;
|
|
617
|
+
let parentNum;
|
|
618
|
+
if (patch.parent_task_id !== undefined) {
|
|
619
|
+
const newParent = patch.parent_task_id === null ? null : await nativeIdOf(patch.parent_task_id);
|
|
620
|
+
if (typeof store.setParentId === "function") {
|
|
621
|
+
await store.setParentId(nativeId, newParent);
|
|
622
|
+
}
|
|
623
|
+
parentNum = patch.parent_task_id === null ? undefined : patch.parent_task_id;
|
|
624
|
+
}
|
|
625
|
+
const reread = await store.getTask(nativeId) ?? updated;
|
|
626
|
+
if (parentNum === undefined && reread.parent_id) {
|
|
627
|
+
const nums = await parentNumMap();
|
|
628
|
+
parentNum = nums.get(reread.parent_id);
|
|
629
|
+
}
|
|
630
|
+
return toStoredTask(reread, vocabulary, parentNum);
|
|
631
|
+
},
|
|
632
|
+
async deleteTask(nativeId) {
|
|
633
|
+
return await store.deleteTask(nativeId);
|
|
634
|
+
},
|
|
635
|
+
async createOperation(input) {
|
|
636
|
+
const op = await store.appendOperation({
|
|
637
|
+
task_id: input.taskNativeId ?? String(input.taskId),
|
|
638
|
+
type: operationType,
|
|
639
|
+
data: {
|
|
640
|
+
taskId: input.taskId,
|
|
641
|
+
sessionId: input.sessionId,
|
|
642
|
+
milestoneType: input.milestoneType,
|
|
643
|
+
milestoneTitle: input.milestoneTitle,
|
|
644
|
+
milestoneDescription: input.milestoneDescription,
|
|
645
|
+
processDescription: input.processDescription,
|
|
646
|
+
...input.mdPath ? { mdPath: input.mdPath } : {}
|
|
647
|
+
}
|
|
648
|
+
});
|
|
649
|
+
return toStoredOperation(op);
|
|
650
|
+
},
|
|
651
|
+
async listOperations(request) {
|
|
652
|
+
const res = await store.listOperations({
|
|
653
|
+
...request?.taskNativeId ? { task_id: request.taskNativeId } : {},
|
|
654
|
+
type: operationType,
|
|
655
|
+
limit: request?.limit ?? scanLimit,
|
|
656
|
+
offset: request?.offset ?? 0
|
|
657
|
+
});
|
|
658
|
+
return { operations: res.operations.map(toStoredOperation), total: res.total };
|
|
659
|
+
},
|
|
660
|
+
async getOperationByNum(num) {
|
|
661
|
+
if (typeof store.getOperationByNum !== "function")
|
|
662
|
+
return null;
|
|
663
|
+
const op = await store.getOperationByNum(num);
|
|
664
|
+
return op ? toStoredOperation(op) : null;
|
|
665
|
+
},
|
|
666
|
+
async updateOperationByNum(num, patch) {
|
|
667
|
+
if (typeof store.updateOperation !== "function")
|
|
668
|
+
return null;
|
|
669
|
+
if (typeof store.getOperationByNum !== "function")
|
|
670
|
+
return null;
|
|
671
|
+
const existing = await store.getOperationByNum(num);
|
|
672
|
+
if (!existing)
|
|
673
|
+
return null;
|
|
674
|
+
const previous = toStoredOperation(existing);
|
|
675
|
+
const updated = await store.updateOperation(num, {
|
|
676
|
+
data: {
|
|
677
|
+
taskId: previous.taskId,
|
|
678
|
+
sessionId: patch.sessionId ?? previous.sessionId,
|
|
679
|
+
milestoneType: patch.milestoneType ?? previous.milestoneType,
|
|
680
|
+
milestoneTitle: patch.milestoneTitle ?? previous.milestoneTitle,
|
|
681
|
+
milestoneDescription: patch.milestoneDescription ?? previous.milestoneDescription,
|
|
682
|
+
processDescription: patch.processDescription ?? previous.processDescription,
|
|
683
|
+
...patch.mdPath ?? previous.mdPath ? { mdPath: patch.mdPath ?? previous.mdPath } : {}
|
|
684
|
+
}
|
|
685
|
+
});
|
|
686
|
+
return updated ? toStoredOperation(updated) : null;
|
|
687
|
+
},
|
|
688
|
+
async deleteOperationByNum(num) {
|
|
689
|
+
if (typeof store.deleteOperation !== "function")
|
|
690
|
+
return false;
|
|
691
|
+
return await store.deleteOperation(num);
|
|
692
|
+
}
|
|
693
|
+
};
|
|
694
|
+
}
|
|
695
|
+
export {
|
|
696
|
+
toNumericHandle,
|
|
697
|
+
mergeDeliverableIntoContext,
|
|
698
|
+
formatDeliverableForOperation,
|
|
699
|
+
createSQLiteTaskPort,
|
|
700
|
+
createRoySidecarTaskPort,
|
|
701
|
+
allowedIdsByDepth,
|
|
702
|
+
TaskStoreBackend,
|
|
703
|
+
DELIVERABLE_OPERATION_PREFIX
|
|
704
|
+
};
|