@clinebot/core 0.0.37 → 0.0.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -1
- package/dist/ClineCore.d.ts +18 -214
- package/dist/account/cline-account-service.d.ts +0 -1
- package/dist/account/index.d.ts +0 -1
- package/dist/account/rpc.d.ts +0 -1
- package/dist/account/types.d.ts +0 -1
- package/dist/auth/bounded-ttl-cache.d.ts +0 -1
- package/dist/auth/client.d.ts +0 -1
- package/dist/auth/cline.d.ts +0 -5
- package/dist/auth/codex.d.ts +0 -1
- package/dist/auth/oca.d.ts +0 -1
- package/dist/auth/server.d.ts +0 -1
- package/dist/auth/types.d.ts +0 -1
- package/dist/auth/utils.d.ts +0 -1
- package/dist/cline-core/automation.d.ts +34 -0
- package/dist/cline-core/runtime-services.d.ts +5 -0
- package/dist/cline-core/start-input.d.ts +10 -0
- package/dist/cline-core/telemetry.d.ts +10 -0
- package/dist/cline-core/types.d.ts +221 -0
- package/dist/cron/{cron-event-ingress.d.ts → events/cron-event-ingress.d.ts} +1 -2
- package/dist/cron/{cron-report-writer.d.ts → reports/cron-report-writer.d.ts} +1 -2
- package/dist/cron/{cron-materializer.d.ts → runner/cron-materializer.d.ts} +1 -2
- package/dist/cron/{cron-runner.d.ts → runner/cron-runner.d.ts} +6 -4
- package/dist/cron/{resource-limiter.d.ts → runner/resource-limiter.d.ts} +0 -1
- package/dist/cron/schedule/scheduler.d.ts +12 -0
- package/dist/cron/{cron-service.d.ts → service/cron-service.d.ts} +4 -5
- package/dist/cron/{schedule-command-service.d.ts → service/schedule-command-service.d.ts} +0 -1
- package/dist/cron/{schedule-service.d.ts → service/schedule-service.d.ts} +20 -22
- package/dist/cron/{cron-reconciler.d.ts → specs/cron-reconciler.d.ts} +1 -2
- package/dist/cron/{cron-spec-parser.d.ts → specs/cron-spec-parser.d.ts} +0 -1
- package/dist/cron/{cron-watcher.d.ts → specs/cron-watcher.d.ts} +0 -1
- package/dist/cron/{cron-schema.d.ts → store/cron-schema.d.ts} +0 -1
- package/dist/cron/{sqlite-cron-store.d.ts → store/sqlite-cron-store.d.ts} +12 -2
- package/dist/extensions/config/index.d.ts +4 -7
- package/dist/extensions/config/runtime-commands.d.ts +0 -1
- package/dist/extensions/config/skill-frontmatter-toggle.d.ts +11 -0
- package/dist/extensions/config/unified-config-file-watcher.d.ts +0 -1
- package/dist/extensions/config/user-instruction-config-loader.d.ts +0 -1
- package/dist/extensions/config/user-instruction-plugin.d.ts +25 -0
- package/dist/extensions/config/user-instruction-service.d.ts +23 -0
- package/dist/extensions/context/agentic-compaction.d.ts +0 -1
- package/dist/extensions/context/basic-compaction.d.ts +0 -1
- package/dist/extensions/context/compaction-shared.d.ts +0 -1
- package/dist/extensions/context/compaction.d.ts +0 -1
- package/dist/extensions/index.d.ts +0 -1
- package/dist/extensions/mcp/client.d.ts +0 -1
- package/dist/extensions/mcp/config-loader.d.ts +0 -1
- package/dist/extensions/mcp/index.d.ts +0 -1
- package/dist/extensions/mcp/manager.d.ts +0 -1
- package/dist/extensions/mcp/name-transform.d.ts +0 -1
- package/dist/extensions/mcp/policies.d.ts +0 -1
- package/dist/extensions/mcp/tools.d.ts +2 -3
- package/dist/extensions/mcp/types.d.ts +3 -4
- package/dist/extensions/plugin/plugin-config-loader.d.ts +0 -1
- package/dist/extensions/plugin/plugin-load-report.d.ts +0 -1
- package/dist/extensions/plugin/plugin-loader.d.ts +0 -1
- package/dist/extensions/plugin/plugin-module-import.d.ts +0 -1
- package/dist/extensions/plugin/plugin-sandbox.d.ts +0 -1
- package/dist/extensions/plugin/plugin-targeting.d.ts +0 -1
- package/dist/extensions/plugin-sandbox-bootstrap.js +1 -446
- package/dist/extensions/tools/constants.d.ts +0 -1
- package/dist/extensions/tools/definitions.d.ts +13 -14
- package/dist/extensions/tools/executors/apply-patch-parser.d.ts +0 -1
- package/dist/extensions/tools/executors/apply-patch.d.ts +0 -1
- package/dist/extensions/tools/executors/bash.d.ts +0 -1
- package/dist/extensions/tools/executors/editor.d.ts +0 -1
- package/dist/extensions/tools/executors/file-read.d.ts +0 -1
- package/dist/extensions/tools/executors/index.d.ts +0 -1
- package/dist/extensions/tools/executors/search.d.ts +0 -1
- package/dist/extensions/tools/executors/web-fetch.d.ts +0 -1
- package/dist/extensions/tools/helpers.d.ts +0 -1
- package/dist/extensions/tools/index.d.ts +2 -3
- package/dist/extensions/tools/model-tool-routing.d.ts +0 -1
- package/dist/extensions/tools/presets.d.ts +4 -5
- package/dist/extensions/tools/runtime.d.ts +0 -1
- package/dist/extensions/tools/schemas.d.ts +0 -1
- package/dist/extensions/tools/team/delegated-agent.d.ts +3 -4
- package/dist/extensions/tools/team/index.d.ts +0 -1
- package/dist/extensions/tools/team/multi-agent.d.ts +1 -2
- package/dist/extensions/tools/team/projections.d.ts +0 -1
- package/dist/extensions/tools/team/runtime.d.ts +0 -1
- package/dist/extensions/tools/team/spawn-agent-tool.d.ts +4 -5
- package/dist/extensions/tools/team/subagent-prompts.d.ts +0 -1
- package/dist/extensions/tools/team/team-tools.d.ts +7 -8
- package/dist/extensions/tools/types.d.ts +11 -12
- package/dist/hooks/checkpoint-hooks.d.ts +9 -2
- package/dist/hooks/hook-extension.d.ts +2 -0
- package/dist/{extensions/config/hooks-config-loader.d.ts → hooks/hook-file-config.d.ts} +1 -2
- package/dist/hooks/hook-file-hooks.d.ts +2 -2
- package/dist/hooks/index.d.ts +3 -1
- package/dist/hooks/subprocess-runner.d.ts +0 -1
- package/dist/hooks/subprocess.d.ts +0 -1
- package/dist/hub/{connect.d.ts → client/connect.d.ts} +1 -2
- package/dist/hub/{client.d.ts → client/index.d.ts} +41 -4
- package/dist/hub/{session-client.d.ts → client/session-client.d.ts} +41 -13
- package/dist/hub/{ui-client.d.ts → client/ui-client.d.ts} +1 -1
- package/dist/hub/daemon/entry.d.ts +1 -0
- package/dist/hub/daemon/entry.js +720 -0
- package/dist/hub/{daemon.d.ts → daemon/index.d.ts} +6 -3
- package/dist/hub/{runtime-handlers.d.ts → daemon/runtime-handlers.d.ts} +3 -2
- package/dist/hub/{start-shared-server.d.ts → daemon/start-shared-server.d.ts} +1 -2
- package/dist/hub/{defaults.d.ts → discovery/defaults.d.ts} +0 -1
- package/dist/hub/{discovery.d.ts → discovery/index.d.ts} +2 -1
- package/dist/hub/{workspace.d.ts → discovery/workspace.d.ts} +1 -2
- package/dist/hub/index.d.ts +28 -11
- package/dist/hub/index.js +484 -1061
- package/dist/hub/runtime-host/hub-runtime-host.d.ts +73 -0
- package/dist/{transports/remote.d.ts → hub/runtime-host/remote-runtime-host.d.ts} +1 -2
- package/dist/hub/{browser-websocket.d.ts → server/browser-websocket.d.ts} +1 -2
- package/dist/hub/{transport.d.ts → server/command-transport.d.ts} +0 -1
- package/dist/hub/server/handlers/approval-handlers.d.ts +17 -0
- package/dist/hub/server/handlers/capability-handlers.d.ts +12 -0
- package/dist/hub/server/handlers/client-handlers.d.ts +6 -0
- package/dist/hub/server/handlers/context.d.ts +56 -0
- package/dist/hub/server/handlers/run-handlers.d.ts +5 -0
- package/dist/hub/server/handlers/session-event-projector.d.ts +7 -0
- package/dist/hub/server/handlers/session-handlers.d.ts +20 -0
- package/dist/hub/server/hub-client-contributions.d.ts +19 -0
- package/dist/hub/server/hub-notifications.d.ts +7 -0
- package/dist/hub/server/hub-schedule-events.d.ts +2 -0
- package/dist/hub/server/hub-server-logging.d.ts +2 -0
- package/dist/hub/server/hub-server-options.d.ts +55 -0
- package/dist/hub/server/hub-server-transport.d.ts +34 -0
- package/dist/hub/server/hub-session-records.d.ts +8 -0
- package/dist/hub/server/hub-websocket-server.d.ts +6 -0
- package/dist/hub/server/index.d.ts +4 -0
- package/dist/hub/{native-transport.d.ts → server/native-transport.d.ts} +1 -2
- package/dist/index.d.ts +51 -41
- package/dist/index.js +214 -872
- package/dist/runtime/capabilities/index.d.ts +2 -0
- package/dist/runtime/capabilities/normalize-runtime-capabilities.d.ts +2 -0
- package/dist/runtime/capabilities/runtime-capabilities.d.ts +6 -0
- package/dist/runtime/config/agent-message-codec.d.ts +6 -0
- package/dist/runtime/{agent-runtime-config-builder.d.ts → config/agent-runtime-config-builder.d.ts} +12 -21
- package/dist/runtime/host/history.d.ts +18 -0
- package/dist/runtime/{host.d.ts → host/host.d.ts} +3 -4
- package/dist/runtime/host/local/agent-event-bridge.d.ts +29 -0
- package/dist/runtime/host/local/session-record.d.ts +6 -0
- package/dist/runtime/host/local/session-service-invoker.d.ts +4 -0
- package/dist/runtime/host/local/spawn-tool.d.ts +15 -0
- package/dist/runtime/host/local/user-files.d.ts +1 -0
- package/dist/runtime/host/local-runtime-host.d.ts +118 -0
- package/dist/{transports → runtime/host}/runtime-host-support.d.ts +3 -5
- package/dist/runtime/{runtime-host.d.ts → host/runtime-host.d.ts} +66 -31
- package/dist/runtime/{runtime-builder.d.ts → orchestration/runtime-builder.d.ts} +0 -1
- package/dist/runtime/{runtime-event-adapter.d.ts → orchestration/runtime-event-adapter.d.ts} +0 -1
- package/dist/runtime/{runtime-oauth-token-manager.d.ts → orchestration/runtime-oauth-token-manager.d.ts} +1 -2
- package/dist/runtime/{session-runtime-orchestrator.d.ts → orchestration/session-runtime-orchestrator.d.ts} +20 -63
- package/dist/runtime/{session-runtime.d.ts → orchestration/session-runtime.d.ts} +14 -12
- package/dist/runtime/{user-input-builder.d.ts → orchestration/user-input-builder.d.ts} +2 -11
- package/dist/runtime/{loop-detection.d.ts → safety/loop-detection.d.ts} +0 -1
- package/dist/runtime/{mistake-tracker.d.ts → safety/mistake-tracker.d.ts} +0 -1
- package/dist/runtime/{rules.d.ts → safety/rules.d.ts} +1 -2
- package/dist/runtime/{subprocess-sandbox.d.ts → tools/subprocess-sandbox.d.ts} +15 -1
- package/dist/runtime/{tool-approval.d.ts → tools/tool-approval.d.ts} +0 -1
- package/dist/runtime/turn-queue/pending-prompt-service.d.ts +64 -0
- package/dist/services/agent-events.d.ts +1 -2
- package/dist/services/config.d.ts +0 -1
- package/dist/services/global-settings.d.ts +27 -5
- package/dist/{llms → services/llms}/cline-recommended-models.d.ts +1 -2
- package/dist/{llms → services/llms}/configured-provider-registry.d.ts +0 -1
- package/dist/services/llms/handler-factory.d.ts +3 -0
- package/dist/{llms → services/llms}/provider-defaults.d.ts +2 -1
- package/dist/{llms → services/llms}/provider-settings.d.ts +5 -3
- package/dist/{llms → services/llms}/runtime-config.d.ts +0 -1
- package/dist/{llms → services/llms}/runtime-registry.d.ts +0 -1
- package/dist/{llms → services/llms}/runtime-types.d.ts +0 -1
- package/dist/services/local-runtime-bootstrap.d.ts +7 -9
- package/dist/services/plugin-tools.d.ts +0 -1
- package/dist/services/providers/local-provider-registry.d.ts +9 -10
- package/dist/services/providers/local-provider-service.d.ts +36 -3
- package/dist/services/providers/model-source.d.ts +3 -0
- package/dist/services/session-artifacts.d.ts +0 -1
- package/dist/services/session-data.d.ts +2 -3
- package/dist/services/session-telemetry.d.ts +0 -1
- package/dist/services/storage/file-team-store.d.ts +0 -1
- package/dist/services/storage/provider-settings-legacy-migration.d.ts +0 -1
- package/dist/services/storage/provider-settings-manager.d.ts +3 -4
- package/dist/services/storage/sqlite-session-store.d.ts +0 -1
- package/dist/services/storage/sqlite-team-store.d.ts +0 -1
- package/dist/services/storage/team-store.d.ts +0 -1
- package/dist/services/telemetry/ITelemetryAdapter.d.ts +0 -1
- package/dist/services/telemetry/OpenTelemetryAdapter.d.ts +0 -1
- package/dist/services/telemetry/OpenTelemetryProvider.d.ts +32 -1
- package/dist/services/telemetry/TelemetryLoggerSink.d.ts +0 -1
- package/dist/services/telemetry/TelemetryService.d.ts +0 -1
- package/dist/services/telemetry/core-events.d.ts +46 -3
- package/dist/services/telemetry/distinct-id.d.ts +0 -1
- package/dist/services/telemetry/index.d.ts +1 -2
- package/dist/services/telemetry/index.js +1 -0
- package/dist/services/usage.d.ts +10 -2
- package/dist/services/workspace/file-indexer.d.ts +0 -1
- package/dist/services/workspace/index.d.ts +0 -1
- package/dist/services/workspace/mention-enricher.d.ts +0 -1
- package/dist/{session → services/workspace}/workspace-manager.d.ts +0 -1
- package/dist/services/{workspace-manifest.d.ts → workspace/workspace-manifest.d.ts} +20 -5
- package/dist/services/workspace/workspace-telemetry.d.ts +18 -0
- package/dist/session/checkpoint-restore.d.ts +20 -0
- package/dist/session/{session-graph.d.ts → models/session-graph.d.ts} +2 -3
- package/dist/session/{session-manifest.d.ts → models/session-manifest.d.ts} +0 -1
- package/dist/session/{session-row.d.ts → models/session-row.d.ts} +2 -3
- package/dist/session/{file-session-service.d.ts → services/file-session-service.d.ts} +1 -2
- package/dist/session/{message-builder.d.ts → services/message-builder.d.ts} +7 -16
- package/dist/session/{persistence-service.d.ts → services/persistence-service.d.ts} +10 -11
- package/dist/session/{session-service.d.ts → services/session-service.d.ts} +4 -5
- package/dist/session/session-snapshot.d.ts +57 -0
- package/dist/session/session-versioning-service.d.ts +48 -0
- package/dist/session/{conversation-store.d.ts → stores/conversation-store.d.ts} +0 -1
- package/dist/session/{session-manifest-store.d.ts → stores/session-manifest-store.d.ts} +3 -4
- package/dist/session/{team-persistence-store.d.ts → stores/team-persistence-store.d.ts} +2 -3
- package/dist/session/team/index.d.ts +2 -0
- package/dist/session/{subagent-session-manager.d.ts → team/team-child-session-manager.d.ts} +7 -8
- package/dist/session/{session-team-coordination.d.ts → team/team-session-coordinator.d.ts} +3 -4
- package/dist/settings/index.d.ts +2 -0
- package/dist/settings/settings-service.d.ts +6 -0
- package/dist/settings/types.d.ts +42 -0
- package/dist/types/chat-schema.d.ts +24 -7
- package/dist/types/common.d.ts +0 -1
- package/dist/types/config.d.ts +2 -3
- package/dist/types/events.d.ts +8 -1
- package/dist/types/provider-settings.d.ts +2 -3
- package/dist/types/session.d.ts +22 -6
- package/dist/types/sessions.d.ts +0 -1
- package/dist/types/storage.d.ts +0 -1
- package/dist/types.d.ts +17 -14
- package/dist/version.d.ts +0 -1
- package/package.json +16 -12
- package/dist/ClineCore.d.ts.map +0 -1
- package/dist/account/cline-account-service.d.ts.map +0 -1
- package/dist/account/index.d.ts.map +0 -1
- package/dist/account/rpc.d.ts.map +0 -1
- package/dist/account/types.d.ts.map +0 -1
- package/dist/auth/bounded-ttl-cache.d.ts.map +0 -1
- package/dist/auth/client.d.ts.map +0 -1
- package/dist/auth/cline.d.ts.map +0 -1
- package/dist/auth/codex.d.ts.map +0 -1
- package/dist/auth/oca.d.ts.map +0 -1
- package/dist/auth/server.d.ts.map +0 -1
- package/dist/auth/types.d.ts.map +0 -1
- package/dist/auth/utils.d.ts.map +0 -1
- package/dist/cron/cron-event-ingress.d.ts.map +0 -1
- package/dist/cron/cron-materializer.d.ts.map +0 -1
- package/dist/cron/cron-reconciler.d.ts.map +0 -1
- package/dist/cron/cron-report-writer.d.ts.map +0 -1
- package/dist/cron/cron-runner.d.ts.map +0 -1
- package/dist/cron/cron-schema.d.ts.map +0 -1
- package/dist/cron/cron-service.d.ts.map +0 -1
- package/dist/cron/cron-spec-parser.d.ts.map +0 -1
- package/dist/cron/cron-watcher.d.ts.map +0 -1
- package/dist/cron/resource-limiter.d.ts.map +0 -1
- package/dist/cron/schedule-command-service.d.ts.map +0 -1
- package/dist/cron/schedule-service.d.ts.map +0 -1
- package/dist/cron/scheduler.d.ts +0 -68
- package/dist/cron/scheduler.d.ts.map +0 -1
- package/dist/cron/sqlite-cron-store.d.ts.map +0 -1
- package/dist/cron/sqlite-schedule-store.d.ts +0 -52
- package/dist/cron/sqlite-schedule-store.d.ts.map +0 -1
- package/dist/extensions/config/agent-config-loader.d.ts +0 -20
- package/dist/extensions/config/agent-config-loader.d.ts.map +0 -1
- package/dist/extensions/config/agent-config-parser.d.ts +0 -29
- package/dist/extensions/config/agent-config-parser.d.ts.map +0 -1
- package/dist/extensions/config/hooks-config-loader.d.ts.map +0 -1
- package/dist/extensions/config/index.d.ts.map +0 -1
- package/dist/extensions/config/runtime-commands.d.ts.map +0 -1
- package/dist/extensions/config/unified-config-file-watcher.d.ts.map +0 -1
- package/dist/extensions/config/user-instruction-config-loader.d.ts.map +0 -1
- package/dist/extensions/context/agentic-compaction.d.ts.map +0 -1
- package/dist/extensions/context/basic-compaction.d.ts.map +0 -1
- package/dist/extensions/context/compaction-shared.d.ts.map +0 -1
- package/dist/extensions/context/compaction.d.ts.map +0 -1
- package/dist/extensions/index.d.ts.map +0 -1
- package/dist/extensions/mcp/client.d.ts.map +0 -1
- package/dist/extensions/mcp/config-loader.d.ts.map +0 -1
- package/dist/extensions/mcp/index.d.ts.map +0 -1
- package/dist/extensions/mcp/manager.d.ts.map +0 -1
- package/dist/extensions/mcp/name-transform.d.ts.map +0 -1
- package/dist/extensions/mcp/policies.d.ts.map +0 -1
- package/dist/extensions/mcp/tools.d.ts.map +0 -1
- package/dist/extensions/mcp/types.d.ts.map +0 -1
- package/dist/extensions/plugin/plugin-config-loader.d.ts.map +0 -1
- package/dist/extensions/plugin/plugin-load-report.d.ts.map +0 -1
- package/dist/extensions/plugin/plugin-loader.d.ts.map +0 -1
- package/dist/extensions/plugin/plugin-module-import.d.ts.map +0 -1
- package/dist/extensions/plugin/plugin-sandbox.d.ts.map +0 -1
- package/dist/extensions/plugin/plugin-targeting.d.ts.map +0 -1
- package/dist/extensions/tools/constants.d.ts.map +0 -1
- package/dist/extensions/tools/definitions.d.ts.map +0 -1
- package/dist/extensions/tools/executors/apply-patch-parser.d.ts.map +0 -1
- package/dist/extensions/tools/executors/apply-patch.d.ts.map +0 -1
- package/dist/extensions/tools/executors/bash.d.ts.map +0 -1
- package/dist/extensions/tools/executors/editor.d.ts.map +0 -1
- package/dist/extensions/tools/executors/file-read.d.ts.map +0 -1
- package/dist/extensions/tools/executors/index.d.ts.map +0 -1
- package/dist/extensions/tools/executors/search.d.ts.map +0 -1
- package/dist/extensions/tools/executors/web-fetch.d.ts.map +0 -1
- package/dist/extensions/tools/helpers.d.ts.map +0 -1
- package/dist/extensions/tools/index.d.ts.map +0 -1
- package/dist/extensions/tools/model-tool-routing.d.ts.map +0 -1
- package/dist/extensions/tools/presets.d.ts.map +0 -1
- package/dist/extensions/tools/runtime.d.ts.map +0 -1
- package/dist/extensions/tools/schemas.d.ts.map +0 -1
- package/dist/extensions/tools/team/delegated-agent.d.ts.map +0 -1
- package/dist/extensions/tools/team/index.d.ts.map +0 -1
- package/dist/extensions/tools/team/multi-agent.d.ts.map +0 -1
- package/dist/extensions/tools/team/projections.d.ts.map +0 -1
- package/dist/extensions/tools/team/runtime.d.ts.map +0 -1
- package/dist/extensions/tools/team/spawn-agent-tool.d.ts.map +0 -1
- package/dist/extensions/tools/team/subagent-prompts.d.ts.map +0 -1
- package/dist/extensions/tools/team/team-tools.d.ts.map +0 -1
- package/dist/extensions/tools/types.d.ts.map +0 -1
- package/dist/hooks/checkpoint-hooks.d.ts.map +0 -1
- package/dist/hooks/hook-bridge.d.ts +0 -118
- package/dist/hooks/hook-bridge.d.ts.map +0 -1
- package/dist/hooks/hook-file-hooks.d.ts.map +0 -1
- package/dist/hooks/hook-registry.d.ts +0 -16
- package/dist/hooks/hook-registry.d.ts.map +0 -1
- package/dist/hooks/index.d.ts.map +0 -1
- package/dist/hooks/subprocess-runner.d.ts.map +0 -1
- package/dist/hooks/subprocess.d.ts.map +0 -1
- package/dist/hub/browser-websocket.d.ts.map +0 -1
- package/dist/hub/client.d.ts.map +0 -1
- package/dist/hub/connect.d.ts.map +0 -1
- package/dist/hub/daemon-entry.d.ts +0 -2
- package/dist/hub/daemon-entry.d.ts.map +0 -1
- package/dist/hub/daemon-entry.js +0 -1305
- package/dist/hub/daemon.d.ts.map +0 -1
- package/dist/hub/defaults.d.ts.map +0 -1
- package/dist/hub/discovery.d.ts.map +0 -1
- package/dist/hub/index.d.ts.map +0 -1
- package/dist/hub/native-transport.d.ts.map +0 -1
- package/dist/hub/runtime-handlers.d.ts.map +0 -1
- package/dist/hub/server.d.ts +0 -104
- package/dist/hub/server.d.ts.map +0 -1
- package/dist/hub/session-client.d.ts.map +0 -1
- package/dist/hub/start-shared-server.d.ts.map +0 -1
- package/dist/hub/transport.d.ts.map +0 -1
- package/dist/hub/ui-client.d.ts.map +0 -1
- package/dist/hub/workspace.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/llms/cline-recommended-models.d.ts.map +0 -1
- package/dist/llms/configured-provider-registry.d.ts.map +0 -1
- package/dist/llms/handler-factory.d.ts +0 -16
- package/dist/llms/handler-factory.d.ts.map +0 -1
- package/dist/llms/provider-defaults.d.ts.map +0 -1
- package/dist/llms/provider-settings.d.ts.map +0 -1
- package/dist/llms/runtime-config.d.ts.map +0 -1
- package/dist/llms/runtime-registry.d.ts.map +0 -1
- package/dist/llms/runtime-types.d.ts.map +0 -1
- package/dist/runtime/agent-config-adapter.d.ts +0 -148
- package/dist/runtime/agent-config-adapter.d.ts.map +0 -1
- package/dist/runtime/agent-runtime-config-builder.d.ts.map +0 -1
- package/dist/runtime/history.d.ts +0 -10
- package/dist/runtime/history.d.ts.map +0 -1
- package/dist/runtime/host.d.ts.map +0 -1
- package/dist/runtime/loop-detection.d.ts.map +0 -1
- package/dist/runtime/mistake-tracker.d.ts.map +0 -1
- package/dist/runtime/rules.d.ts.map +0 -1
- package/dist/runtime/runtime-builder.d.ts.map +0 -1
- package/dist/runtime/runtime-event-adapter.d.ts.map +0 -1
- package/dist/runtime/runtime-host.d.ts.map +0 -1
- package/dist/runtime/runtime-oauth-token-manager.d.ts.map +0 -1
- package/dist/runtime/session-runtime-orchestrator.d.ts.map +0 -1
- package/dist/runtime/session-runtime.d.ts.map +0 -1
- package/dist/runtime/subprocess-sandbox.d.ts.map +0 -1
- package/dist/runtime/tool-approval.d.ts.map +0 -1
- package/dist/runtime/user-input-builder.d.ts.map +0 -1
- package/dist/services/agent-events.d.ts.map +0 -1
- package/dist/services/config.d.ts.map +0 -1
- package/dist/services/global-settings.d.ts.map +0 -1
- package/dist/services/index.js +0 -28
- package/dist/services/local-runtime-bootstrap.d.ts.map +0 -1
- package/dist/services/plugin-tools.d.ts.map +0 -1
- package/dist/services/providers/local-provider-registry.d.ts.map +0 -1
- package/dist/services/providers/local-provider-service.d.ts.map +0 -1
- package/dist/services/session-artifacts.d.ts.map +0 -1
- package/dist/services/session-data.d.ts.map +0 -1
- package/dist/services/session-telemetry.d.ts.map +0 -1
- package/dist/services/storage/file-team-store.d.ts.map +0 -1
- package/dist/services/storage/provider-settings-legacy-migration.d.ts.map +0 -1
- package/dist/services/storage/provider-settings-manager.d.ts.map +0 -1
- package/dist/services/storage/sqlite-session-store.d.ts.map +0 -1
- package/dist/services/storage/sqlite-team-store.d.ts.map +0 -1
- package/dist/services/storage/team-store.d.ts.map +0 -1
- package/dist/services/telemetry/ITelemetryAdapter.d.ts.map +0 -1
- package/dist/services/telemetry/OpenTelemetryAdapter.d.ts.map +0 -1
- package/dist/services/telemetry/OpenTelemetryProvider.d.ts.map +0 -1
- package/dist/services/telemetry/TelemetryLoggerSink.d.ts.map +0 -1
- package/dist/services/telemetry/TelemetryService.d.ts.map +0 -1
- package/dist/services/telemetry/core-events.d.ts.map +0 -1
- package/dist/services/telemetry/distinct-id.d.ts.map +0 -1
- package/dist/services/telemetry/index.d.ts.map +0 -1
- package/dist/services/usage.d.ts.map +0 -1
- package/dist/services/workspace/file-indexer.d.ts.map +0 -1
- package/dist/services/workspace/index.d.ts.map +0 -1
- package/dist/services/workspace/mention-enricher.d.ts.map +0 -1
- package/dist/services/workspace-manifest.d.ts.map +0 -1
- package/dist/session/conversation-store.d.ts.map +0 -1
- package/dist/session/file-session-service.d.ts.map +0 -1
- package/dist/session/message-builder.d.ts.map +0 -1
- package/dist/session/persistence-service.d.ts.map +0 -1
- package/dist/session/session-graph.d.ts.map +0 -1
- package/dist/session/session-manifest-store.d.ts.map +0 -1
- package/dist/session/session-manifest.d.ts.map +0 -1
- package/dist/session/session-row.d.ts.map +0 -1
- package/dist/session/session-service.d.ts.map +0 -1
- package/dist/session/session-team-coordination.d.ts.map +0 -1
- package/dist/session/subagent-session-manager.d.ts.map +0 -1
- package/dist/session/team-persistence-store.d.ts.map +0 -1
- package/dist/session/workspace-manager.d.ts.map +0 -1
- package/dist/transports/hub.d.ts +0 -58
- package/dist/transports/hub.d.ts.map +0 -1
- package/dist/transports/local.d.ts +0 -119
- package/dist/transports/local.d.ts.map +0 -1
- package/dist/transports/remote.d.ts.map +0 -1
- package/dist/transports/runtime-host-support.d.ts.map +0 -1
- package/dist/types/chat-schema.d.ts.map +0 -1
- package/dist/types/common.d.ts.map +0 -1
- package/dist/types/config.d.ts.map +0 -1
- package/dist/types/events.d.ts.map +0 -1
- package/dist/types/provider-settings.d.ts.map +0 -1
- package/dist/types/session.d.ts.map +0 -1
- package/dist/types/sessions.d.ts.map +0 -1
- package/dist/types/storage.d.ts.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/version.d.ts.map +0 -1
- package/src/ClineCore.ts +0 -1026
- package/src/account/cline-account-service.ts +0 -338
- package/src/account/index.ts +0 -24
- package/src/account/rpc.ts +0 -185
- package/src/account/types.ts +0 -108
- package/src/auth/bounded-ttl-cache.ts +0 -53
- package/src/auth/client.ts +0 -46
- package/src/auth/cline.ts +0 -724
- package/src/auth/codex.ts +0 -491
- package/src/auth/oca.ts +0 -588
- package/src/auth/server.ts +0 -265
- package/src/auth/types.ts +0 -110
- package/src/auth/utils.ts +0 -247
- package/src/cron/cron-event-ingress.ts +0 -357
- package/src/cron/cron-materializer.ts +0 -97
- package/src/cron/cron-reconciler.ts +0 -241
- package/src/cron/cron-report-writer.ts +0 -153
- package/src/cron/cron-runner.ts +0 -495
- package/src/cron/cron-schema.ts +0 -127
- package/src/cron/cron-service.ts +0 -163
- package/src/cron/cron-spec-parser.ts +0 -489
- package/src/cron/cron-watcher.ts +0 -102
- package/src/cron/index.ts +0 -15
- package/src/cron/resource-limiter.ts +0 -46
- package/src/cron/schedule-command-service.ts +0 -193
- package/src/cron/schedule-service.ts +0 -703
- package/src/cron/scheduler.ts +0 -772
- package/src/cron/sqlite-cron-store.ts +0 -1286
- package/src/cron/sqlite-schedule-store.ts +0 -708
- package/src/extensions/config/agent-config-loader.ts +0 -114
- package/src/extensions/config/agent-config-parser.ts +0 -198
- package/src/extensions/config/hooks-config-loader.ts +0 -117
- package/src/extensions/config/index.ts +0 -77
- package/src/extensions/config/runtime-commands.ts +0 -82
- package/src/extensions/config/unified-config-file-watcher.ts +0 -496
- package/src/extensions/config/user-instruction-config-loader.ts +0 -549
- package/src/extensions/context/agentic-compaction.ts +0 -131
- package/src/extensions/context/basic-compaction.ts +0 -300
- package/src/extensions/context/compaction-shared.ts +0 -459
- package/src/extensions/context/compaction.ts +0 -226
- package/src/extensions/index.ts +0 -18
- package/src/extensions/mcp/client.ts +0 -420
- package/src/extensions/mcp/config-loader.ts +0 -219
- package/src/extensions/mcp/index.ts +0 -42
- package/src/extensions/mcp/manager.ts +0 -260
- package/src/extensions/mcp/name-transform.ts +0 -33
- package/src/extensions/mcp/policies.ts +0 -47
- package/src/extensions/mcp/tools.ts +0 -47
- package/src/extensions/mcp/types.ts +0 -116
- package/src/extensions/plugin/plugin-config-loader.ts +0 -140
- package/src/extensions/plugin/plugin-load-report.ts +0 -20
- package/src/extensions/plugin/plugin-loader.ts +0 -220
- package/src/extensions/plugin/plugin-module-import.ts +0 -276
- package/src/extensions/plugin/plugin-sandbox-bootstrap.ts +0 -662
- package/src/extensions/plugin/plugin-sandbox.ts +0 -586
- package/src/extensions/plugin/plugin-targeting.ts +0 -32
- package/src/extensions/tools/constants.ts +0 -37
- package/src/extensions/tools/definitions.ts +0 -738
- package/src/extensions/tools/executors/apply-patch-parser.ts +0 -520
- package/src/extensions/tools/executors/apply-patch.ts +0 -348
- package/src/extensions/tools/executors/bash.ts +0 -207
- package/src/extensions/tools/executors/editor.ts +0 -220
- package/src/extensions/tools/executors/file-read.ts +0 -135
- package/src/extensions/tools/executors/index.ts +0 -87
- package/src/extensions/tools/executors/search.ts +0 -470
- package/src/extensions/tools/executors/web-fetch.ts +0 -259
- package/src/extensions/tools/helpers.ts +0 -154
- package/src/extensions/tools/index.ts +0 -183
- package/src/extensions/tools/model-tool-routing.ts +0 -134
- package/src/extensions/tools/presets.ts +0 -190
- package/src/extensions/tools/runtime.ts +0 -261
- package/src/extensions/tools/schemas.ts +0 -343
- package/src/extensions/tools/team/delegated-agent.ts +0 -136
- package/src/extensions/tools/team/index.ts +0 -5
- package/src/extensions/tools/team/multi-agent.ts +0 -1845
- package/src/extensions/tools/team/projections.ts +0 -283
- package/src/extensions/tools/team/runtime.ts +0 -54
- package/src/extensions/tools/team/spawn-agent-tool.ts +0 -201
- package/src/extensions/tools/team/subagent-prompts.ts +0 -41
- package/src/extensions/tools/team/team-tools.ts +0 -902
- package/src/extensions/tools/types.ts +0 -354
- package/src/hooks/checkpoint-hooks.ts +0 -238
- package/src/hooks/hook-bridge.ts +0 -489
- package/src/hooks/hook-file-hooks.ts +0 -934
- package/src/hooks/hook-registry.ts +0 -257
- package/src/hooks/index.ts +0 -18
- package/src/hooks/subprocess-runner.ts +0 -196
- package/src/hooks/subprocess.ts +0 -469
- package/src/hub/browser-websocket.ts +0 -159
- package/src/hub/client.ts +0 -633
- package/src/hub/connect.ts +0 -156
- package/src/hub/daemon-entry.ts +0 -122
- package/src/hub/daemon.ts +0 -284
- package/src/hub/defaults.ts +0 -70
- package/src/hub/discovery.ts +0 -247
- package/src/hub/index.ts +0 -14
- package/src/hub/native-transport.ts +0 -31
- package/src/hub/runtime-handlers.ts +0 -141
- package/src/hub/server.ts +0 -2317
- package/src/hub/session-client.ts +0 -502
- package/src/hub/start-shared-server.ts +0 -61
- package/src/hub/transport.ts +0 -14
- package/src/hub/ui-client.ts +0 -126
- package/src/hub/workspace.ts +0 -19
- package/src/index.ts +0 -688
- package/src/llms/cline-recommended-models.ts +0 -167
- package/src/llms/configured-provider-registry.ts +0 -193
- package/src/llms/handler-factory.ts +0 -56
- package/src/llms/provider-defaults.ts +0 -653
- package/src/llms/provider-settings.ts +0 -310
- package/src/llms/runtime-config.ts +0 -43
- package/src/llms/runtime-registry.ts +0 -172
- package/src/llms/runtime-types.ts +0 -121
- package/src/runtime/agent-config-adapter.ts +0 -636
- package/src/runtime/agent-runtime-config-builder.ts +0 -205
- package/src/runtime/error-feedback.ts +0 -142
- package/src/runtime/history.ts +0 -374
- package/src/runtime/host.ts +0 -222
- package/src/runtime/index.ts +0 -23
- package/src/runtime/loop-detection.ts +0 -162
- package/src/runtime/mistake-tracker.ts +0 -221
- package/src/runtime/rules.ts +0 -49
- package/src/runtime/runtime-builder.ts +0 -814
- package/src/runtime/runtime-event-adapter.ts +0 -412
- package/src/runtime/runtime-host.ts +0 -250
- package/src/runtime/runtime-oauth-token-manager.ts +0 -268
- package/src/runtime/session-runtime-orchestrator.ts +0 -1253
- package/src/runtime/session-runtime.ts +0 -69
- package/src/runtime/subprocess-sandbox.ts +0 -255
- package/src/runtime/tool-approval.ts +0 -102
- package/src/runtime/user-input-builder.ts +0 -167
- package/src/services/agent-events.ts +0 -256
- package/src/services/config.ts +0 -5
- package/src/services/global-settings.ts +0 -122
- package/src/services/local-runtime-bootstrap.ts +0 -424
- package/src/services/plugin-tools.ts +0 -86
- package/src/services/providers/local-provider-registry.ts +0 -456
- package/src/services/providers/local-provider-service.ts +0 -772
- package/src/services/session-artifacts.ts +0 -138
- package/src/services/session-data.ts +0 -398
- package/src/services/session-telemetry.ts +0 -89
- package/src/services/storage/artifact-store.ts +0 -1
- package/src/services/storage/file-team-store.ts +0 -250
- package/src/services/storage/index.ts +0 -11
- package/src/services/storage/provider-settings-legacy-migration.ts +0 -789
- package/src/services/storage/provider-settings-manager.ts +0 -167
- package/src/services/storage/session-store.ts +0 -1
- package/src/services/storage/sqlite-session-store.ts +0 -270
- package/src/services/storage/sqlite-team-store.ts +0 -537
- package/src/services/storage/team-store.ts +0 -36
- package/src/services/telemetry/ITelemetryAdapter.ts +0 -94
- package/src/services/telemetry/OpenTelemetryAdapter.ts +0 -348
- package/src/services/telemetry/OpenTelemetryProvider.ts +0 -415
- package/src/services/telemetry/TelemetryLoggerSink.ts +0 -121
- package/src/services/telemetry/TelemetryService.ts +0 -139
- package/src/services/telemetry/core-events.ts +0 -400
- package/src/services/telemetry/distinct-id.ts +0 -58
- package/src/services/telemetry/index.ts +0 -20
- package/src/services/usage.ts +0 -32
- package/src/services/workspace/file-indexer.ts +0 -351
- package/src/services/workspace/index.ts +0 -7
- package/src/services/workspace/mention-enricher.ts +0 -122
- package/src/services/workspace-manifest.ts +0 -72
- package/src/session/conversation-store.ts +0 -77
- package/src/session/file-session-service.ts +0 -282
- package/src/session/index.ts +0 -32
- package/src/session/message-builder.ts +0 -941
- package/src/session/persistence-service.ts +0 -559
- package/src/session/session-graph.ts +0 -92
- package/src/session/session-manifest-store.ts +0 -158
- package/src/session/session-manifest.ts +0 -29
- package/src/session/session-row.ts +0 -199
- package/src/session/session-service.ts +0 -324
- package/src/session/session-team-coordination.ts +0 -240
- package/src/session/subagent-session-manager.ts +0 -397
- package/src/session/team-persistence-store.ts +0 -176
- package/src/session/workspace-manager.ts +0 -100
- package/src/transports/hub.ts +0 -1081
- package/src/transports/local.ts +0 -1826
- package/src/transports/remote.ts +0 -27
- package/src/transports/runtime-host-support.ts +0 -140
- package/src/types/chat-schema.ts +0 -81
- package/src/types/common.ts +0 -26
- package/src/types/config.ts +0 -220
- package/src/types/events.ts +0 -80
- package/src/types/index.ts +0 -26
- package/src/types/provider-settings.ts +0 -54
- package/src/types/session.ts +0 -111
- package/src/types/sessions.ts +0 -37
- package/src/types/storage.ts +0 -56
- package/src/types.ts +0 -167
- package/src/version.ts +0 -3
|
@@ -1,703 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from "node:crypto";
|
|
2
|
-
import type {
|
|
3
|
-
BasicLogger,
|
|
4
|
-
ChatRunTurnRequest,
|
|
5
|
-
ChatStartSessionArtifacts,
|
|
6
|
-
ChatStartSessionRequest,
|
|
7
|
-
HubScheduleCreateInput,
|
|
8
|
-
HubScheduleUpdateInput,
|
|
9
|
-
ScheduleExecutionRecord,
|
|
10
|
-
ScheduleExecutionStatus,
|
|
11
|
-
ScheduleRecord,
|
|
12
|
-
} from "@clinebot/shared";
|
|
13
|
-
import { nowIso } from "@clinebot/shared/db";
|
|
14
|
-
import { ResourceLimiter } from "./resource-limiter";
|
|
15
|
-
import { validateCronPattern } from "./scheduler";
|
|
16
|
-
import {
|
|
17
|
-
type ListScheduleExecutionsOptions,
|
|
18
|
-
type ListSchedulesOptions,
|
|
19
|
-
type ScheduleClaimRecord,
|
|
20
|
-
type ScheduleExecutionStats,
|
|
21
|
-
SqliteHubScheduleStore,
|
|
22
|
-
} from "./sqlite-schedule-store";
|
|
23
|
-
|
|
24
|
-
function toErrorMessage(error: unknown): string {
|
|
25
|
-
return error instanceof Error ? error.message : String(error);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
type HubScheduleTurnResult = {
|
|
29
|
-
text: string;
|
|
30
|
-
usage?: {
|
|
31
|
-
inputTokens?: number;
|
|
32
|
-
outputTokens?: number;
|
|
33
|
-
cacheReadTokens?: number;
|
|
34
|
-
cacheWriteTokens?: number;
|
|
35
|
-
totalCost?: number;
|
|
36
|
-
};
|
|
37
|
-
inputTokens?: number;
|
|
38
|
-
outputTokens?: number;
|
|
39
|
-
iterations?: number;
|
|
40
|
-
finishReason?: string;
|
|
41
|
-
messages?: unknown[];
|
|
42
|
-
toolCalls?: Array<{
|
|
43
|
-
name: string;
|
|
44
|
-
input?: unknown;
|
|
45
|
-
output?: unknown;
|
|
46
|
-
error?: string;
|
|
47
|
-
durationMs?: number;
|
|
48
|
-
}>;
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
function parseTurnMetrics(result: HubScheduleTurnResult): {
|
|
52
|
-
iterations?: number;
|
|
53
|
-
tokensUsed?: number;
|
|
54
|
-
costUsd?: number;
|
|
55
|
-
} {
|
|
56
|
-
const inputTokens =
|
|
57
|
-
typeof result.inputTokens === "number" ? result.inputTokens : undefined;
|
|
58
|
-
const outputTokens =
|
|
59
|
-
typeof result.outputTokens === "number" ? result.outputTokens : undefined;
|
|
60
|
-
return {
|
|
61
|
-
iterations:
|
|
62
|
-
typeof result.iterations === "number" ? result.iterations : undefined,
|
|
63
|
-
tokensUsed:
|
|
64
|
-
inputTokens !== undefined && outputTokens !== undefined
|
|
65
|
-
? inputTokens + outputTokens
|
|
66
|
-
: undefined,
|
|
67
|
-
costUsd:
|
|
68
|
-
typeof result.usage?.totalCost === "number"
|
|
69
|
-
? result.usage.totalCost
|
|
70
|
-
: undefined,
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
interface AggregatedTurnMetrics {
|
|
75
|
-
iterations?: number;
|
|
76
|
-
tokensUsed?: number;
|
|
77
|
-
costUsd?: number;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function addTurnMetrics(
|
|
81
|
-
current: AggregatedTurnMetrics,
|
|
82
|
-
result: HubScheduleTurnResult,
|
|
83
|
-
): AggregatedTurnMetrics {
|
|
84
|
-
const next = { ...current };
|
|
85
|
-
const metrics = parseTurnMetrics(result);
|
|
86
|
-
if (typeof metrics.iterations === "number") {
|
|
87
|
-
next.iterations = (next.iterations ?? 0) + metrics.iterations;
|
|
88
|
-
}
|
|
89
|
-
if (typeof metrics.tokensUsed === "number") {
|
|
90
|
-
next.tokensUsed = (next.tokensUsed ?? 0) + metrics.tokensUsed;
|
|
91
|
-
}
|
|
92
|
-
if (typeof metrics.costUsd === "number") {
|
|
93
|
-
next.costUsd = (next.costUsd ?? 0) + metrics.costUsd;
|
|
94
|
-
}
|
|
95
|
-
return next;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function optionsOrDefault(value: number | undefined, fallback: number): number {
|
|
99
|
-
return typeof value === "number" && Number.isFinite(value) ? value : fallback;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
function asPositiveSeconds(value: unknown, fallback: number): number {
|
|
103
|
-
if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) {
|
|
104
|
-
return fallback;
|
|
105
|
-
}
|
|
106
|
-
return Math.max(1, Math.floor(value));
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
const DEFAULT_AUTONOMOUS_IDLE_TIMEOUT_SECONDS = 60;
|
|
110
|
-
const DEFAULT_AUTONOMOUS_POLL_INTERVAL_SECONDS = 5;
|
|
111
|
-
const AUTONOMOUS_IDLE_NOOP_TOKEN = "<idle-noop/>";
|
|
112
|
-
|
|
113
|
-
export interface ScheduleAutonomousOptions {
|
|
114
|
-
enabled?: boolean;
|
|
115
|
-
idleTimeoutSeconds?: number;
|
|
116
|
-
pollIntervalSeconds?: number;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
function getAutonomousOptions(
|
|
120
|
-
schedule: ScheduleRecord,
|
|
121
|
-
): ScheduleAutonomousOptions | undefined {
|
|
122
|
-
const metadata = schedule.metadata;
|
|
123
|
-
if (!metadata || typeof metadata !== "object") {
|
|
124
|
-
return undefined;
|
|
125
|
-
}
|
|
126
|
-
const raw =
|
|
127
|
-
metadata.autonomous &&
|
|
128
|
-
typeof metadata.autonomous === "object" &&
|
|
129
|
-
!Array.isArray(metadata.autonomous)
|
|
130
|
-
? (metadata.autonomous as Record<string, unknown>)
|
|
131
|
-
: undefined;
|
|
132
|
-
if (!raw || raw.enabled !== true) {
|
|
133
|
-
return undefined;
|
|
134
|
-
}
|
|
135
|
-
return {
|
|
136
|
-
enabled: true,
|
|
137
|
-
idleTimeoutSeconds: asPositiveSeconds(
|
|
138
|
-
raw.idleTimeoutSeconds,
|
|
139
|
-
DEFAULT_AUTONOMOUS_IDLE_TIMEOUT_SECONDS,
|
|
140
|
-
),
|
|
141
|
-
pollIntervalSeconds: asPositiveSeconds(
|
|
142
|
-
raw.pollIntervalSeconds,
|
|
143
|
-
DEFAULT_AUTONOMOUS_POLL_INTERVAL_SECONDS,
|
|
144
|
-
),
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
function buildSchedulePrompt(
|
|
149
|
-
schedule: ScheduleRecord,
|
|
150
|
-
autonomous: ScheduleAutonomousOptions | undefined,
|
|
151
|
-
): string {
|
|
152
|
-
if (!autonomous?.enabled) {
|
|
153
|
-
return schedule.prompt;
|
|
154
|
-
}
|
|
155
|
-
return `${schedule.prompt}
|
|
156
|
-
|
|
157
|
-
When you finish the immediate scheduled work, remain available for autonomous follow-up. During idle polling, inspect team mailbox and team tasks. Use team_task with action="list" to find ready unassigned work, claim it with team_task and action="claim", and resume execution when work exists. Reply exactly ${AUTONOMOUS_IDLE_NOOP_TOKEN} only when the poll finds no actionable work.`;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
function buildAutonomousPollPrompt(
|
|
161
|
-
autonomous: ScheduleAutonomousOptions,
|
|
162
|
-
): string {
|
|
163
|
-
return `Autonomous idle poll. Check team_read_mailbox for unread messages and use team_task with action="list" to find ready unassigned tasks. Claim and execute one task if actionable work exists. If there is nothing to do right now, reply exactly ${AUTONOMOUS_IDLE_NOOP_TOKEN} and nothing else. Poll cadence is ${autonomous.pollIntervalSeconds}s and the idle shutdown window is ${autonomous.idleTimeoutSeconds}s.`;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
function isAutonomousNoop(result: HubScheduleTurnResult): boolean {
|
|
167
|
-
return result.text?.trim() === AUTONOMOUS_IDLE_NOOP_TOKEN;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
function sleep(ms: number): Promise<void> {
|
|
171
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
class TimeoutError extends Error {
|
|
175
|
-
constructor(message: string) {
|
|
176
|
-
super(message);
|
|
177
|
-
this.name = "TimeoutError";
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
async function withTimeout<T>(
|
|
182
|
-
promise: Promise<T>,
|
|
183
|
-
timeoutMs: number,
|
|
184
|
-
): Promise<T> {
|
|
185
|
-
if (timeoutMs <= 0) {
|
|
186
|
-
return await promise;
|
|
187
|
-
}
|
|
188
|
-
let timeoutHandle: ReturnType<typeof setTimeout> | undefined;
|
|
189
|
-
const timeoutPromise = new Promise<never>((_, reject) => {
|
|
190
|
-
timeoutHandle = setTimeout(() => {
|
|
191
|
-
reject(new TimeoutError("scheduled execution timed out"));
|
|
192
|
-
}, timeoutMs);
|
|
193
|
-
});
|
|
194
|
-
try {
|
|
195
|
-
return await Promise.race([promise, timeoutPromise]);
|
|
196
|
-
} finally {
|
|
197
|
-
if (timeoutHandle) {
|
|
198
|
-
clearTimeout(timeoutHandle);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
export interface HubScheduleRuntimeHandlers {
|
|
204
|
-
startSession(request: ChatStartSessionRequest): Promise<{
|
|
205
|
-
sessionId: string;
|
|
206
|
-
startResult?: ChatStartSessionArtifacts;
|
|
207
|
-
}>;
|
|
208
|
-
sendSession(
|
|
209
|
-
sessionId: string,
|
|
210
|
-
request: ChatRunTurnRequest,
|
|
211
|
-
): Promise<{
|
|
212
|
-
result: HubScheduleTurnResult;
|
|
213
|
-
}>;
|
|
214
|
-
abortSession(sessionId: string): Promise<{ applied: boolean }>;
|
|
215
|
-
stopSession(sessionId: string): Promise<{ applied: boolean }>;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
export interface ActiveScheduledExecution {
|
|
219
|
-
executionId: string;
|
|
220
|
-
scheduleId: string;
|
|
221
|
-
sessionId: string;
|
|
222
|
-
startedAt: string;
|
|
223
|
-
timeoutAt?: string;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
export interface HubScheduleServiceOptions {
|
|
227
|
-
runtimeHandlers: HubScheduleRuntimeHandlers;
|
|
228
|
-
eventPublisher?: (eventType: string, payload: unknown) => void;
|
|
229
|
-
logger?: BasicLogger;
|
|
230
|
-
sessionsDbPath?: string;
|
|
231
|
-
pollIntervalMs?: number;
|
|
232
|
-
globalMaxConcurrency?: number;
|
|
233
|
-
claimLeaseSeconds?: number;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
export class HubScheduleService {
|
|
237
|
-
private readonly store: SqliteHubScheduleStore;
|
|
238
|
-
private readonly resourceLimiter: ResourceLimiter;
|
|
239
|
-
private readonly options: HubScheduleServiceOptions;
|
|
240
|
-
private readonly claimLeaseMs: number;
|
|
241
|
-
private readonly activeExecutions = new Map<
|
|
242
|
-
string,
|
|
243
|
-
ActiveScheduledExecution
|
|
244
|
-
>();
|
|
245
|
-
private timer: ReturnType<typeof setInterval> | undefined;
|
|
246
|
-
private started = false;
|
|
247
|
-
private ticking = false;
|
|
248
|
-
private disposed = false;
|
|
249
|
-
|
|
250
|
-
constructor(options: HubScheduleServiceOptions) {
|
|
251
|
-
this.options = options;
|
|
252
|
-
this.store = new SqliteHubScheduleStore({
|
|
253
|
-
sessionsDbPath: options.sessionsDbPath,
|
|
254
|
-
});
|
|
255
|
-
this.resourceLimiter = new ResourceLimiter(
|
|
256
|
-
options.globalMaxConcurrency ?? 10,
|
|
257
|
-
);
|
|
258
|
-
this.claimLeaseMs = Math.max(
|
|
259
|
-
5_000,
|
|
260
|
-
optionsOrDefault(options.claimLeaseSeconds, 90) * 1000,
|
|
261
|
-
);
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
public async start(): Promise<void> {
|
|
265
|
-
if (this.disposed) {
|
|
266
|
-
throw new Error("HubScheduleService has been disposed");
|
|
267
|
-
}
|
|
268
|
-
if (this.started) {
|
|
269
|
-
return;
|
|
270
|
-
}
|
|
271
|
-
this.started = true;
|
|
272
|
-
const intervalMs = Math.max(
|
|
273
|
-
5_000,
|
|
274
|
-
optionsOrDefault(this.options.pollIntervalMs, 30_000),
|
|
275
|
-
);
|
|
276
|
-
this.options.logger?.log("hub.schedule.started", {
|
|
277
|
-
pollIntervalMs: intervalMs,
|
|
278
|
-
});
|
|
279
|
-
await this.tick();
|
|
280
|
-
this.timer = setInterval(() => {
|
|
281
|
-
void this.tick();
|
|
282
|
-
}, intervalMs);
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
public async stop(): Promise<void> {
|
|
286
|
-
const wasStarted = this.started;
|
|
287
|
-
this.started = false;
|
|
288
|
-
if (this.timer) {
|
|
289
|
-
clearInterval(this.timer);
|
|
290
|
-
this.timer = undefined;
|
|
291
|
-
}
|
|
292
|
-
if (wasStarted) {
|
|
293
|
-
this.options.logger?.log("hub.schedule.stopped", {});
|
|
294
|
-
}
|
|
295
|
-
const active = Array.from(this.activeExecutions.values());
|
|
296
|
-
await Promise.all(
|
|
297
|
-
active.map(async (execution) => {
|
|
298
|
-
try {
|
|
299
|
-
await this.options.runtimeHandlers.abortSession(execution.sessionId);
|
|
300
|
-
} catch {
|
|
301
|
-
// best effort
|
|
302
|
-
}
|
|
303
|
-
}),
|
|
304
|
-
);
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
public async dispose(): Promise<void> {
|
|
308
|
-
if (this.disposed) {
|
|
309
|
-
return;
|
|
310
|
-
}
|
|
311
|
-
this.disposed = true;
|
|
312
|
-
await this.stop();
|
|
313
|
-
this.store.close();
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
public createSchedule(input: HubScheduleCreateInput): ScheduleRecord {
|
|
317
|
-
validateCronPattern(input.cronPattern);
|
|
318
|
-
if (!input.workspaceRoot?.trim()) {
|
|
319
|
-
throw new Error("workspaceRoot is required for schedules");
|
|
320
|
-
}
|
|
321
|
-
return this.store.createSchedule(input);
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
public getSchedule(scheduleId: string): ScheduleRecord | undefined {
|
|
325
|
-
return this.store.getSchedule(scheduleId);
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
public listSchedules(options: ListSchedulesOptions = {}): ScheduleRecord[] {
|
|
329
|
-
return this.store.listSchedules(options);
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
public updateSchedule(
|
|
333
|
-
scheduleId: string,
|
|
334
|
-
updates: HubScheduleUpdateInput,
|
|
335
|
-
): ScheduleRecord | undefined {
|
|
336
|
-
if (updates.cronPattern !== undefined) {
|
|
337
|
-
validateCronPattern(updates.cronPattern);
|
|
338
|
-
}
|
|
339
|
-
const current = this.store.getSchedule(scheduleId);
|
|
340
|
-
if (!current) {
|
|
341
|
-
return undefined;
|
|
342
|
-
}
|
|
343
|
-
const nextWorkspaceRoot =
|
|
344
|
-
updates.workspaceRoot !== undefined
|
|
345
|
-
? updates.workspaceRoot.trim()
|
|
346
|
-
: current.workspaceRoot;
|
|
347
|
-
const nextEnabled = updates.enabled ?? current.enabled;
|
|
348
|
-
if (nextEnabled && !nextWorkspaceRoot) {
|
|
349
|
-
throw new Error("workspaceRoot is required for enabled schedules");
|
|
350
|
-
}
|
|
351
|
-
return this.store.updateSchedule(scheduleId, {
|
|
352
|
-
...updates,
|
|
353
|
-
scheduleId,
|
|
354
|
-
});
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
public deleteSchedule(scheduleId: string): boolean {
|
|
358
|
-
return this.store.deleteSchedule(scheduleId);
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
public pauseSchedule(scheduleId: string): ScheduleRecord | undefined {
|
|
362
|
-
return this.updateSchedule(scheduleId, { scheduleId, enabled: false });
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
public resumeSchedule(scheduleId: string): ScheduleRecord | undefined {
|
|
366
|
-
return this.updateSchedule(scheduleId, { scheduleId, enabled: true });
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
public async triggerScheduleNow(
|
|
370
|
-
scheduleId: string,
|
|
371
|
-
): Promise<ScheduleExecutionRecord | undefined> {
|
|
372
|
-
const schedule = this.store.getSchedule(scheduleId);
|
|
373
|
-
if (!schedule) {
|
|
374
|
-
return undefined;
|
|
375
|
-
}
|
|
376
|
-
return await this.executeSchedule(schedule, nowIso(), "manual");
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
public listScheduleExecutions(
|
|
380
|
-
options: ListScheduleExecutionsOptions,
|
|
381
|
-
): ScheduleExecutionRecord[] {
|
|
382
|
-
return this.store.listExecutions(options);
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
public getScheduleStats(scheduleId: string): ScheduleExecutionStats {
|
|
386
|
-
return this.store.getExecutionStats(scheduleId);
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
public getActiveExecutions(): ActiveScheduledExecution[] {
|
|
390
|
-
return Array.from(this.activeExecutions.values());
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
public getUpcomingRuns(limit = 20): Array<{
|
|
394
|
-
scheduleId: string;
|
|
395
|
-
name: string;
|
|
396
|
-
nextRunAt: string;
|
|
397
|
-
}> {
|
|
398
|
-
return this.store.listUpcomingRuns(limit);
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
private async tick(): Promise<void> {
|
|
402
|
-
if (this.ticking) {
|
|
403
|
-
return;
|
|
404
|
-
}
|
|
405
|
-
this.ticking = true;
|
|
406
|
-
try {
|
|
407
|
-
const claims = this.store.claimDueSchedules(nowIso(), this.claimLeaseMs);
|
|
408
|
-
await Promise.allSettled(
|
|
409
|
-
claims.map((claim) => this.executeClaimedSchedule(claim)),
|
|
410
|
-
);
|
|
411
|
-
} catch (error) {
|
|
412
|
-
const logger = this.options.logger;
|
|
413
|
-
if (logger) {
|
|
414
|
-
if (logger.error) {
|
|
415
|
-
logger.error("hub.schedule.tick.failed", { error });
|
|
416
|
-
} else {
|
|
417
|
-
logger.log("hub.schedule.tick.failed", {
|
|
418
|
-
error,
|
|
419
|
-
severity: "error",
|
|
420
|
-
});
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
} finally {
|
|
424
|
-
this.ticking = false;
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
private async executeClaimedSchedule(
|
|
429
|
-
claim: ScheduleClaimRecord,
|
|
430
|
-
): Promise<void> {
|
|
431
|
-
const releaseLeaseHeartbeat = this.startClaimLeaseHeartbeat(claim);
|
|
432
|
-
try {
|
|
433
|
-
const result = await this.executeSchedule(
|
|
434
|
-
claim.schedule,
|
|
435
|
-
new Date(claim.triggeredAt).toISOString(),
|
|
436
|
-
"scheduled",
|
|
437
|
-
);
|
|
438
|
-
const completedAt = result.startedAt ?? claim.triggeredAt;
|
|
439
|
-
this.store.completeScheduleClaim(
|
|
440
|
-
claim.schedule.scheduleId,
|
|
441
|
-
claim.claimToken,
|
|
442
|
-
new Date(completedAt).toISOString(),
|
|
443
|
-
);
|
|
444
|
-
} finally {
|
|
445
|
-
releaseLeaseHeartbeat();
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
private startClaimLeaseHeartbeat(claim: ScheduleClaimRecord): () => void {
|
|
450
|
-
const heartbeatMs = Math.max(1_000, Math.floor(this.claimLeaseMs / 2));
|
|
451
|
-
const interval = setInterval(() => {
|
|
452
|
-
const leaseUntilAt = new Date(
|
|
453
|
-
Date.now() + this.claimLeaseMs,
|
|
454
|
-
).toISOString();
|
|
455
|
-
const renewed = this.store.renewScheduleClaim(
|
|
456
|
-
claim.schedule.scheduleId,
|
|
457
|
-
claim.claimToken,
|
|
458
|
-
leaseUntilAt,
|
|
459
|
-
);
|
|
460
|
-
if (!renewed) {
|
|
461
|
-
clearInterval(interval);
|
|
462
|
-
}
|
|
463
|
-
}, heartbeatMs);
|
|
464
|
-
return () => clearInterval(interval);
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
private buildStartRequest(schedule: ScheduleRecord): ChatStartSessionRequest {
|
|
468
|
-
const workspaceRoot = schedule.workspaceRoot.trim();
|
|
469
|
-
const provider = schedule.modelSelection?.providerId?.trim();
|
|
470
|
-
const model = schedule.modelSelection?.modelId?.trim();
|
|
471
|
-
if (!workspaceRoot) {
|
|
472
|
-
throw new Error("schedule requires workspaceRoot");
|
|
473
|
-
}
|
|
474
|
-
if (!provider || !model) {
|
|
475
|
-
throw new Error(
|
|
476
|
-
"schedule requires modelSelection.providerId and modelSelection.modelId",
|
|
477
|
-
);
|
|
478
|
-
}
|
|
479
|
-
return {
|
|
480
|
-
workspaceRoot,
|
|
481
|
-
cwd: schedule.cwd?.trim() || workspaceRoot,
|
|
482
|
-
provider,
|
|
483
|
-
model,
|
|
484
|
-
mode:
|
|
485
|
-
schedule.mode === "plan"
|
|
486
|
-
? "plan"
|
|
487
|
-
: schedule.mode === "yolo"
|
|
488
|
-
? "yolo"
|
|
489
|
-
: "act",
|
|
490
|
-
systemPrompt: schedule.systemPrompt,
|
|
491
|
-
maxIterations: schedule.maxIterations,
|
|
492
|
-
enableTools: schedule.runtimeOptions?.enableTools ?? true,
|
|
493
|
-
enableSpawn: schedule.runtimeOptions?.enableSpawn ?? true,
|
|
494
|
-
enableTeams: schedule.runtimeOptions?.enableTeams ?? true,
|
|
495
|
-
autoApproveTools: schedule.runtimeOptions?.autoApproveTools ?? true,
|
|
496
|
-
};
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
private async executeSchedule(
|
|
500
|
-
schedule: ScheduleRecord,
|
|
501
|
-
triggeredAt: string,
|
|
502
|
-
trigger: "scheduled" | "manual",
|
|
503
|
-
): Promise<ScheduleExecutionRecord> {
|
|
504
|
-
const executionId = `exec_${randomUUID()}`;
|
|
505
|
-
const triggeredAtMs = new Date(triggeredAt).getTime();
|
|
506
|
-
const pending: ScheduleExecutionRecord = {
|
|
507
|
-
executionId,
|
|
508
|
-
scheduleId: schedule.scheduleId,
|
|
509
|
-
triggeredAt: triggeredAtMs,
|
|
510
|
-
status: "pending",
|
|
511
|
-
};
|
|
512
|
-
this.store.recordExecution(pending);
|
|
513
|
-
|
|
514
|
-
const acquired = this.resourceLimiter.acquire(
|
|
515
|
-
schedule.scheduleId,
|
|
516
|
-
executionId,
|
|
517
|
-
schedule.maxParallel ?? 1,
|
|
518
|
-
);
|
|
519
|
-
if (!acquired) {
|
|
520
|
-
const skipped: ScheduleExecutionRecord = {
|
|
521
|
-
...pending,
|
|
522
|
-
status: "failed",
|
|
523
|
-
endedAt: Date.now(),
|
|
524
|
-
errorMessage: "concurrency limit reached",
|
|
525
|
-
};
|
|
526
|
-
this.store.recordExecution(skipped);
|
|
527
|
-
return skipped;
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
let sessionId: string | undefined;
|
|
531
|
-
let startedAt: number | undefined;
|
|
532
|
-
let timeoutAt: string | undefined;
|
|
533
|
-
let executionDeadlineMs: number | undefined;
|
|
534
|
-
|
|
535
|
-
try {
|
|
536
|
-
const startRequest = this.buildStartRequest(schedule);
|
|
537
|
-
const startResponse =
|
|
538
|
-
await this.options.runtimeHandlers.startSession(startRequest);
|
|
539
|
-
sessionId = startResponse.sessionId.trim();
|
|
540
|
-
if (!sessionId) {
|
|
541
|
-
throw new Error("runtime start returned empty sessionId");
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
startedAt = Date.now();
|
|
545
|
-
timeoutAt =
|
|
546
|
-
typeof schedule.timeoutSeconds === "number" &&
|
|
547
|
-
schedule.timeoutSeconds > 0
|
|
548
|
-
? new Date(startedAt + schedule.timeoutSeconds * 1000).toISOString()
|
|
549
|
-
: undefined;
|
|
550
|
-
executionDeadlineMs = timeoutAt
|
|
551
|
-
? new Date(timeoutAt).getTime()
|
|
552
|
-
: undefined;
|
|
553
|
-
|
|
554
|
-
const runningState: ScheduleExecutionRecord = {
|
|
555
|
-
...pending,
|
|
556
|
-
sessionId,
|
|
557
|
-
startedAt,
|
|
558
|
-
status: "running",
|
|
559
|
-
};
|
|
560
|
-
this.store.recordExecution(runningState);
|
|
561
|
-
this.activeExecutions.set(executionId, {
|
|
562
|
-
executionId,
|
|
563
|
-
scheduleId: schedule.scheduleId,
|
|
564
|
-
sessionId,
|
|
565
|
-
startedAt: new Date(startedAt).toISOString(),
|
|
566
|
-
timeoutAt,
|
|
567
|
-
});
|
|
568
|
-
this.publishEvent("schedule.execution.started", {
|
|
569
|
-
scheduleId: schedule.scheduleId,
|
|
570
|
-
executionId,
|
|
571
|
-
sessionId,
|
|
572
|
-
trigger,
|
|
573
|
-
triggeredAt,
|
|
574
|
-
});
|
|
575
|
-
|
|
576
|
-
const turnRequest: ChatRunTurnRequest = {
|
|
577
|
-
config: startRequest,
|
|
578
|
-
prompt: buildSchedulePrompt(schedule, getAutonomousOptions(schedule)),
|
|
579
|
-
};
|
|
580
|
-
const sendTurn = async (
|
|
581
|
-
request: ChatRunTurnRequest,
|
|
582
|
-
): Promise<HubScheduleTurnResult> => {
|
|
583
|
-
const sendPromise = this.options.runtimeHandlers.sendSession(
|
|
584
|
-
sessionId!,
|
|
585
|
-
request,
|
|
586
|
-
);
|
|
587
|
-
const timeoutMs = executionDeadlineMs
|
|
588
|
-
? Math.max(1, executionDeadlineMs - Date.now())
|
|
589
|
-
: 0;
|
|
590
|
-
const sendResult = await withTimeout(sendPromise, timeoutMs);
|
|
591
|
-
return sendResult.result;
|
|
592
|
-
};
|
|
593
|
-
|
|
594
|
-
let metrics = addTurnMetrics({}, await sendTurn(turnRequest));
|
|
595
|
-
const autonomous = getAutonomousOptions(schedule);
|
|
596
|
-
if (autonomous?.enabled) {
|
|
597
|
-
metrics = await this.runAutonomousIdleLoop({
|
|
598
|
-
sessionId,
|
|
599
|
-
startRequest,
|
|
600
|
-
autonomous,
|
|
601
|
-
metrics,
|
|
602
|
-
sendTurn,
|
|
603
|
-
executionDeadlineMs,
|
|
604
|
-
});
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
const completed: ScheduleExecutionRecord = {
|
|
608
|
-
...runningState,
|
|
609
|
-
status: "success",
|
|
610
|
-
endedAt: Date.now(),
|
|
611
|
-
iterations: metrics.iterations,
|
|
612
|
-
tokensUsed: metrics.tokensUsed,
|
|
613
|
-
costUsd: metrics.costUsd,
|
|
614
|
-
};
|
|
615
|
-
this.store.recordExecution(completed);
|
|
616
|
-
this.publishEvent("schedule.execution.completed", {
|
|
617
|
-
scheduleId: schedule.scheduleId,
|
|
618
|
-
executionId,
|
|
619
|
-
sessionId,
|
|
620
|
-
status: completed.status,
|
|
621
|
-
durationMs:
|
|
622
|
-
completed.startedAt && completed.endedAt
|
|
623
|
-
? completed.endedAt - completed.startedAt
|
|
624
|
-
: undefined,
|
|
625
|
-
});
|
|
626
|
-
return completed;
|
|
627
|
-
} catch (error) {
|
|
628
|
-
const status: ScheduleExecutionStatus =
|
|
629
|
-
error instanceof TimeoutError ? "timeout" : "failed";
|
|
630
|
-
if (sessionId && status === "timeout") {
|
|
631
|
-
try {
|
|
632
|
-
await this.options.runtimeHandlers.abortSession(sessionId);
|
|
633
|
-
} catch {
|
|
634
|
-
// best effort
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
const failed: ScheduleExecutionRecord = {
|
|
638
|
-
executionId,
|
|
639
|
-
scheduleId: schedule.scheduleId,
|
|
640
|
-
sessionId,
|
|
641
|
-
triggeredAt: triggeredAtMs,
|
|
642
|
-
startedAt,
|
|
643
|
-
endedAt: Date.now(),
|
|
644
|
-
status,
|
|
645
|
-
errorMessage: toErrorMessage(error),
|
|
646
|
-
};
|
|
647
|
-
this.store.recordExecution(failed);
|
|
648
|
-
this.publishEvent("schedule.execution.completed", {
|
|
649
|
-
scheduleId: schedule.scheduleId,
|
|
650
|
-
executionId,
|
|
651
|
-
sessionId,
|
|
652
|
-
status: failed.status,
|
|
653
|
-
errorMessage: failed.errorMessage,
|
|
654
|
-
});
|
|
655
|
-
return failed;
|
|
656
|
-
} finally {
|
|
657
|
-
if (sessionId) {
|
|
658
|
-
try {
|
|
659
|
-
await this.options.runtimeHandlers.stopSession(sessionId);
|
|
660
|
-
} catch {
|
|
661
|
-
// best effort
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
this.activeExecutions.delete(executionId);
|
|
665
|
-
this.resourceLimiter.release(schedule.scheduleId, executionId);
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
private publishEvent(eventType: string, payload: unknown): void {
|
|
670
|
-
this.options.eventPublisher?.(eventType, payload);
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
private async runAutonomousIdleLoop(options: {
|
|
674
|
-
sessionId: string;
|
|
675
|
-
startRequest: ChatStartSessionRequest;
|
|
676
|
-
autonomous: ScheduleAutonomousOptions;
|
|
677
|
-
metrics: AggregatedTurnMetrics;
|
|
678
|
-
sendTurn: (request: ChatRunTurnRequest) => Promise<HubScheduleTurnResult>;
|
|
679
|
-
executionDeadlineMs?: number;
|
|
680
|
-
}): Promise<AggregatedTurnMetrics> {
|
|
681
|
-
let metrics = options.metrics;
|
|
682
|
-
const idleDeadline =
|
|
683
|
-
Date.now() + options.autonomous.idleTimeoutSeconds! * 1000;
|
|
684
|
-
while (Date.now() < idleDeadline) {
|
|
685
|
-
if (
|
|
686
|
-
options.executionDeadlineMs !== undefined &&
|
|
687
|
-
Date.now() >= options.executionDeadlineMs
|
|
688
|
-
) {
|
|
689
|
-
throw new TimeoutError("scheduled execution timed out");
|
|
690
|
-
}
|
|
691
|
-
await sleep(options.autonomous.pollIntervalSeconds! * 1000);
|
|
692
|
-
const result = await options.sendTurn({
|
|
693
|
-
config: options.startRequest,
|
|
694
|
-
prompt: buildAutonomousPollPrompt(options.autonomous),
|
|
695
|
-
});
|
|
696
|
-
metrics = addTurnMetrics(metrics, result);
|
|
697
|
-
if (isAutonomousNoop(result)) {
|
|
698
|
-
break;
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
return metrics;
|
|
702
|
-
}
|
|
703
|
-
}
|