@clinebot/core 0.0.35 → 0.0.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -2
- package/dist/ClineCore.d.ts +362 -39
- package/dist/ClineCore.d.ts.map +1 -1
- package/dist/account/cline-account-service.d.ts.map +1 -1
- package/dist/account/index.d.ts +1 -1
- package/dist/account/index.d.ts.map +1 -1
- package/dist/account/rpc.d.ts +6 -6
- package/dist/account/rpc.d.ts.map +1 -1
- package/dist/cron/cron-event-ingress.d.ts +38 -0
- package/dist/cron/cron-event-ingress.d.ts.map +1 -0
- package/dist/cron/cron-materializer.d.ts +36 -0
- package/dist/cron/cron-materializer.d.ts.map +1 -0
- package/dist/cron/cron-reconciler.d.ts +62 -0
- package/dist/cron/cron-reconciler.d.ts.map +1 -0
- package/dist/cron/cron-report-writer.d.ts +41 -0
- package/dist/cron/cron-report-writer.d.ts.map +1 -0
- package/dist/cron/cron-runner.d.ts +43 -0
- package/dist/cron/cron-runner.d.ts.map +1 -0
- package/dist/cron/cron-schema.d.ts +3 -0
- package/dist/cron/cron-schema.d.ts.map +1 -0
- package/dist/cron/cron-service.d.ts +57 -0
- package/dist/cron/cron-service.d.ts.map +1 -0
- package/dist/cron/cron-spec-parser.d.ts +27 -0
- package/dist/cron/cron-spec-parser.d.ts.map +1 -0
- package/dist/cron/cron-watcher.d.ts +23 -0
- package/dist/cron/cron-watcher.d.ts.map +1 -0
- package/dist/cron/resource-limiter.d.ts +9 -0
- package/dist/cron/resource-limiter.d.ts.map +1 -0
- package/dist/cron/schedule-command-service.d.ts +10 -0
- package/dist/cron/schedule-command-service.d.ts.map +1 -0
- package/dist/cron/schedule-service.d.ts +100 -0
- package/dist/cron/schedule-service.d.ts.map +1 -0
- package/dist/cron/scheduler.d.ts +68 -0
- package/dist/cron/scheduler.d.ts.map +1 -0
- package/dist/cron/sqlite-cron-store.d.ts +230 -0
- package/dist/cron/sqlite-cron-store.d.ts.map +1 -0
- package/dist/cron/sqlite-schedule-store.d.ts +52 -0
- package/dist/cron/sqlite-schedule-store.d.ts.map +1 -0
- package/dist/extensions/config/agent-config-loader.d.ts +4 -3
- package/dist/extensions/config/agent-config-loader.d.ts.map +1 -1
- package/dist/extensions/config/runtime-commands.d.ts +1 -0
- package/dist/extensions/config/runtime-commands.d.ts.map +1 -1
- package/dist/extensions/config/user-instruction-config-loader.d.ts +1 -0
- package/dist/extensions/config/user-instruction-config-loader.d.ts.map +1 -1
- package/dist/extensions/context/agentic-compaction.d.ts +2 -2
- package/dist/extensions/context/agentic-compaction.d.ts.map +1 -1
- package/dist/extensions/context/compaction-shared.d.ts +5 -4
- package/dist/extensions/context/compaction-shared.d.ts.map +1 -1
- package/dist/extensions/context/compaction.d.ts.map +1 -1
- package/dist/extensions/plugin/plugin-config-loader.d.ts +15 -2
- package/dist/extensions/plugin/plugin-config-loader.d.ts.map +1 -1
- package/dist/extensions/plugin/plugin-loader.d.ts +13 -7
- package/dist/extensions/plugin/plugin-loader.d.ts.map +1 -1
- package/dist/extensions/plugin/plugin-module-import.d.ts.map +1 -1
- package/dist/extensions/plugin/plugin-sandbox.d.ts +21 -2
- package/dist/extensions/plugin/plugin-sandbox.d.ts.map +1 -1
- package/dist/extensions/plugin/plugin-targeting.d.ts +7 -0
- package/dist/extensions/plugin/plugin-targeting.d.ts.map +1 -0
- package/dist/extensions/plugin-sandbox-bootstrap.js +237 -276
- package/dist/extensions/tools/constants.d.ts +1 -0
- package/dist/extensions/tools/constants.d.ts.map +1 -1
- package/dist/extensions/tools/definitions.d.ts +3 -4
- package/dist/extensions/tools/definitions.d.ts.map +1 -1
- package/dist/extensions/tools/executors/apply-patch.d.ts +3 -1
- package/dist/extensions/tools/executors/apply-patch.d.ts.map +1 -1
- package/dist/extensions/tools/executors/editor.d.ts.map +1 -1
- package/dist/extensions/tools/executors/search.d.ts +1 -1
- package/dist/extensions/tools/executors/search.d.ts.map +1 -1
- package/dist/extensions/tools/helpers.d.ts +1 -0
- package/dist/extensions/tools/helpers.d.ts.map +1 -1
- package/dist/extensions/tools/index.d.ts +3 -2
- package/dist/extensions/tools/index.d.ts.map +1 -1
- package/dist/extensions/tools/presets.d.ts +27 -44
- package/dist/extensions/tools/presets.d.ts.map +1 -1
- package/dist/extensions/tools/runtime.d.ts +25 -0
- package/dist/extensions/tools/runtime.d.ts.map +1 -0
- package/dist/extensions/tools/schemas.d.ts +25 -3
- package/dist/extensions/tools/schemas.d.ts.map +1 -1
- package/dist/extensions/tools/team/delegated-agent.d.ts +2 -2
- package/dist/extensions/tools/team/delegated-agent.d.ts.map +1 -1
- package/dist/extensions/tools/team/multi-agent.d.ts +7 -3
- package/dist/extensions/tools/team/multi-agent.d.ts.map +1 -1
- package/dist/extensions/tools/team/team-tools.d.ts +1 -0
- package/dist/extensions/tools/team/team-tools.d.ts.map +1 -1
- package/dist/extensions/tools/types.d.ts +0 -5
- package/dist/extensions/tools/types.d.ts.map +1 -1
- package/dist/hooks/hook-bridge.d.ts +118 -0
- package/dist/hooks/hook-bridge.d.ts.map +1 -0
- package/dist/hooks/hook-file-hooks.d.ts +6 -2
- package/dist/hooks/hook-file-hooks.d.ts.map +1 -1
- package/dist/hooks/hook-registry.d.ts +16 -0
- package/dist/hooks/hook-registry.d.ts.map +1 -0
- package/dist/hooks/index.d.ts +0 -1
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/subprocess.d.ts +8 -1
- package/dist/hooks/subprocess.d.ts.map +1 -1
- package/dist/hub/browser-websocket.d.ts +18 -0
- package/dist/hub/browser-websocket.d.ts.map +1 -0
- package/dist/hub/client.d.ts +51 -0
- package/dist/hub/client.d.ts.map +1 -0
- package/dist/hub/connect.d.ts +15 -0
- package/dist/hub/connect.d.ts.map +1 -0
- package/dist/hub/daemon-entry.d.ts +2 -0
- package/dist/hub/daemon-entry.d.ts.map +1 -0
- package/dist/hub/daemon-entry.js +1305 -0
- package/dist/hub/daemon.d.ts +5 -0
- package/dist/hub/daemon.d.ts.map +1 -0
- package/dist/hub/defaults.d.ts +17 -0
- package/dist/hub/defaults.d.ts.map +1 -0
- package/dist/hub/discovery.d.ts +29 -0
- package/dist/hub/discovery.d.ts.map +1 -0
- package/dist/hub/index.d.ts +15 -0
- package/dist/hub/index.d.ts.map +1 -0
- package/dist/hub/index.js +1294 -0
- package/dist/hub/native-transport.d.ts +17 -0
- package/dist/hub/native-transport.d.ts.map +1 -0
- package/dist/hub/runtime-handlers.d.ts +11 -0
- package/dist/hub/runtime-handlers.d.ts.map +1 -0
- package/dist/hub/server.d.ts +104 -0
- package/dist/hub/server.d.ts.map +1 -0
- package/dist/hub/session-client.d.ts +90 -0
- package/dist/hub/session-client.d.ts.map +1 -0
- package/dist/hub/start-shared-server.d.ts +19 -0
- package/dist/hub/start-shared-server.d.ts.map +1 -0
- package/dist/hub/transport.d.ts +8 -0
- package/dist/hub/transport.d.ts.map +1 -0
- package/dist/hub/ui-client.d.ts +45 -0
- package/dist/hub/ui-client.d.ts.map +1 -0
- package/dist/hub/workspace.d.ts +4 -0
- package/dist/hub/workspace.d.ts.map +1 -0
- package/dist/index.d.ts +29 -16
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +782 -471
- package/dist/llms/cline-recommended-models.d.ts +20 -0
- package/dist/llms/cline-recommended-models.d.ts.map +1 -0
- package/dist/llms/configured-provider-registry.d.ts +28 -0
- package/dist/llms/configured-provider-registry.d.ts.map +1 -0
- package/dist/llms/handler-factory.d.ts +16 -0
- package/dist/llms/handler-factory.d.ts.map +1 -0
- package/dist/llms/provider-defaults.d.ts +27 -0
- package/dist/llms/provider-defaults.d.ts.map +1 -0
- package/dist/llms/provider-settings.d.ts +245 -0
- package/dist/llms/provider-settings.d.ts.map +1 -0
- package/dist/llms/runtime-config.d.ts +4 -0
- package/dist/llms/runtime-config.d.ts.map +1 -0
- package/dist/llms/runtime-registry.d.ts +20 -0
- package/dist/llms/runtime-registry.d.ts.map +1 -0
- package/dist/llms/runtime-types.d.ts +85 -0
- package/dist/llms/runtime-types.d.ts.map +1 -0
- package/dist/runtime/agent-config-adapter.d.ts +148 -0
- package/dist/runtime/agent-config-adapter.d.ts.map +1 -0
- package/dist/runtime/agent-runtime-config-builder.d.ts +96 -0
- package/dist/runtime/agent-runtime-config-builder.d.ts.map +1 -0
- package/dist/runtime/history.d.ts +6 -0
- package/dist/runtime/history.d.ts.map +1 -1
- package/dist/runtime/host.d.ts +1 -2
- package/dist/runtime/host.d.ts.map +1 -1
- package/dist/runtime/loop-detection.d.ts +59 -0
- package/dist/runtime/loop-detection.d.ts.map +1 -0
- package/dist/runtime/mistake-tracker.d.ts +69 -0
- package/dist/runtime/mistake-tracker.d.ts.map +1 -0
- package/dist/runtime/rules.d.ts +1 -0
- package/dist/runtime/rules.d.ts.map +1 -1
- package/dist/runtime/runtime-builder.d.ts.map +1 -1
- package/dist/runtime/runtime-event-adapter.d.ts +102 -0
- package/dist/runtime/runtime-event-adapter.d.ts.map +1 -0
- package/dist/runtime/runtime-host.d.ts +49 -26
- package/dist/runtime/runtime-host.d.ts.map +1 -1
- package/dist/runtime/runtime-oauth-token-manager.d.ts.map +1 -1
- package/dist/runtime/session-runtime-orchestrator.d.ts +261 -0
- package/dist/runtime/session-runtime-orchestrator.d.ts.map +1 -0
- package/dist/runtime/session-runtime.d.ts +16 -21
- package/dist/runtime/session-runtime.d.ts.map +1 -1
- package/dist/runtime/user-input-builder.d.ts +24 -0
- package/dist/runtime/user-input-builder.d.ts.map +1 -0
- package/dist/services/global-settings.d.ts +12 -0
- package/dist/services/global-settings.d.ts.map +1 -0
- package/dist/services/index.js +28 -0
- package/dist/services/local-runtime-bootstrap.d.ts +9 -3
- package/dist/services/local-runtime-bootstrap.d.ts.map +1 -1
- package/dist/services/plugin-tools.d.ts +16 -0
- package/dist/services/plugin-tools.d.ts.map +1 -0
- package/dist/services/providers/local-provider-registry.d.ts +199 -23
- package/dist/services/providers/local-provider-registry.d.ts.map +1 -1
- package/dist/services/providers/local-provider-service.d.ts +15 -13
- package/dist/services/providers/local-provider-service.d.ts.map +1 -1
- package/dist/services/session-data.d.ts +1 -1
- package/dist/services/session-data.d.ts.map +1 -1
- package/dist/services/session-telemetry.d.ts +7 -2
- package/dist/services/session-telemetry.d.ts.map +1 -1
- package/dist/services/storage/file-team-store.d.ts.map +1 -1
- package/dist/services/storage/provider-settings-legacy-migration.d.ts +1 -1
- package/dist/services/storage/provider-settings-legacy-migration.d.ts.map +1 -1
- package/dist/services/storage/provider-settings-manager.d.ts +1 -0
- package/dist/services/storage/provider-settings-manager.d.ts.map +1 -1
- package/dist/services/storage/sqlite-team-store.d.ts.map +1 -1
- package/dist/services/workspace-manifest.d.ts +11 -0
- package/dist/services/workspace-manifest.d.ts.map +1 -1
- package/dist/session/conversation-store.d.ts +30 -0
- package/dist/session/conversation-store.d.ts.map +1 -0
- package/dist/session/message-builder.d.ts +65 -0
- package/dist/session/message-builder.d.ts.map +1 -0
- package/dist/session/persistence-service.d.ts +11 -23
- package/dist/session/persistence-service.d.ts.map +1 -1
- package/dist/session/session-manifest-store.d.ts +22 -0
- package/dist/session/session-manifest-store.d.ts.map +1 -0
- package/dist/session/session-manifest.d.ts +1 -1
- package/dist/session/session-row.d.ts +93 -0
- package/dist/session/session-row.d.ts.map +1 -0
- package/dist/session/session-service.d.ts +2 -102
- package/dist/session/session-service.d.ts.map +1 -1
- package/dist/session/subagent-session-manager.d.ts +36 -0
- package/dist/session/subagent-session-manager.d.ts.map +1 -0
- package/dist/session/team-persistence-store.d.ts +24 -0
- package/dist/session/team-persistence-store.d.ts.map +1 -0
- package/dist/transports/hub.d.ts +58 -0
- package/dist/transports/hub.d.ts.map +1 -0
- package/dist/transports/local.d.ts +23 -9
- package/dist/transports/local.d.ts.map +1 -1
- package/dist/transports/remote.d.ts +10 -0
- package/dist/transports/remote.d.ts.map +1 -0
- package/dist/transports/runtime-host-support.d.ts +3 -2
- package/dist/transports/runtime-host-support.d.ts.map +1 -1
- package/dist/types/chat-schema.d.ts +15 -17
- package/dist/types/chat-schema.d.ts.map +1 -1
- package/dist/types/config.d.ts +17 -7
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/events.d.ts +7 -6
- package/dist/types/events.d.ts.map +1 -1
- package/dist/types/provider-settings.d.ts +4 -5
- package/dist/types/provider-settings.d.ts.map +1 -1
- package/dist/types/session.d.ts +7 -3
- package/dist/types/session.d.ts.map +1 -1
- package/dist/types.d.ts +11 -4
- package/dist/types.d.ts.map +1 -1
- package/package.json +20 -6
- package/src/ClineCore.ts +757 -44
- package/src/account/cline-account-service.ts +44 -6
- package/src/account/index.ts +3 -3
- package/src/account/rpc.ts +12 -12
- package/src/cron/cron-event-ingress.ts +357 -0
- package/src/cron/cron-materializer.ts +97 -0
- package/src/cron/cron-reconciler.ts +241 -0
- package/src/cron/cron-report-writer.ts +153 -0
- package/src/cron/cron-runner.ts +495 -0
- package/src/cron/cron-schema.ts +127 -0
- package/src/cron/cron-service.ts +163 -0
- package/src/cron/cron-spec-parser.ts +489 -0
- package/src/cron/cron-watcher.ts +102 -0
- package/src/cron/index.ts +15 -0
- package/src/cron/resource-limiter.ts +46 -0
- package/src/cron/schedule-command-service.ts +193 -0
- package/src/cron/schedule-service.ts +703 -0
- package/src/cron/scheduler.ts +772 -0
- package/src/cron/sqlite-cron-store.ts +1286 -0
- package/src/cron/sqlite-schedule-store.ts +708 -0
- package/src/extensions/config/agent-config-loader.ts +17 -7
- package/src/extensions/config/runtime-commands.ts +6 -0
- package/src/extensions/config/user-instruction-config-loader.ts +1 -0
- package/src/extensions/context/agentic-compaction.ts +3 -3
- package/src/extensions/context/basic-compaction.ts +2 -2
- package/src/extensions/context/compaction-shared.ts +5 -4
- package/src/extensions/context/compaction.ts +3 -3
- package/src/extensions/plugin/plugin-config-loader.ts +37 -2
- package/src/extensions/plugin/plugin-loader.ts +69 -9
- package/src/extensions/plugin/plugin-module-import.ts +0 -2
- package/src/extensions/plugin/plugin-sandbox-bootstrap.ts +243 -39
- package/src/extensions/plugin/plugin-sandbox.ts +173 -29
- package/src/extensions/plugin/plugin-targeting.ts +32 -0
- package/src/extensions/tools/constants.ts +2 -0
- package/src/extensions/tools/definitions.ts +61 -71
- package/src/extensions/tools/executors/apply-patch.ts +69 -80
- package/src/extensions/tools/executors/editor.ts +4 -3
- package/src/extensions/tools/executors/search.ts +195 -3
- package/src/extensions/tools/helpers.ts +24 -0
- package/src/extensions/tools/index.ts +11 -2
- package/src/extensions/tools/presets.ts +32 -47
- package/src/extensions/tools/runtime.ts +261 -0
- package/src/extensions/tools/schemas.ts +17 -20
- package/src/extensions/tools/team/delegated-agent.ts +8 -3
- package/src/extensions/tools/team/multi-agent.ts +135 -19
- package/src/extensions/tools/team/team-tools.ts +172 -91
- package/src/extensions/tools/types.ts +0 -6
- package/src/hooks/hook-bridge.ts +489 -0
- package/src/hooks/hook-file-hooks.ts +66 -5
- package/src/hooks/hook-registry.ts +257 -0
- package/src/hooks/index.ts +0 -7
- package/src/hooks/subprocess-runner.ts +1 -1
- package/src/hooks/subprocess.ts +9 -0
- package/src/hub/browser-websocket.ts +159 -0
- package/src/hub/client.ts +633 -0
- package/src/hub/connect.ts +156 -0
- package/src/hub/daemon-entry.ts +122 -0
- package/src/hub/daemon.ts +284 -0
- package/src/hub/defaults.ts +70 -0
- package/src/hub/discovery.ts +247 -0
- package/src/hub/index.ts +14 -0
- package/src/hub/native-transport.ts +31 -0
- package/src/hub/runtime-handlers.ts +141 -0
- package/src/hub/server.ts +2317 -0
- package/src/hub/session-client.ts +502 -0
- package/src/hub/start-shared-server.ts +61 -0
- package/src/hub/transport.ts +14 -0
- package/src/hub/ui-client.ts +126 -0
- package/src/hub/workspace.ts +19 -0
- package/src/index.ts +169 -68
- package/src/llms/cline-recommended-models.ts +167 -0
- package/src/llms/configured-provider-registry.ts +193 -0
- package/src/llms/handler-factory.ts +56 -0
- package/src/llms/provider-defaults.ts +653 -0
- package/src/llms/provider-settings.ts +310 -0
- package/src/llms/runtime-config.ts +43 -0
- package/src/llms/runtime-registry.ts +172 -0
- package/src/llms/runtime-types.ts +121 -0
- package/src/runtime/agent-config-adapter.ts +636 -0
- package/src/runtime/agent-runtime-config-builder.ts +205 -0
- package/src/runtime/error-feedback.ts +142 -0
- package/src/runtime/history.ts +137 -0
- package/src/runtime/host.ts +127 -267
- package/src/runtime/index.ts +1 -0
- package/src/runtime/loop-detection.ts +162 -0
- package/src/runtime/mistake-tracker.ts +221 -0
- package/src/runtime/rules.ts +12 -0
- package/src/runtime/runtime-builder.ts +85 -13
- package/src/runtime/runtime-event-adapter.ts +412 -0
- package/src/runtime/runtime-host.ts +134 -62
- package/src/runtime/runtime-oauth-token-manager.ts +11 -15
- package/src/runtime/session-runtime-orchestrator.ts +1253 -0
- package/src/runtime/session-runtime.ts +16 -26
- package/src/runtime/user-input-builder.ts +167 -0
- package/src/services/global-settings.ts +122 -0
- package/src/services/local-runtime-bootstrap.ts +175 -31
- package/src/services/plugin-tools.ts +86 -0
- package/src/services/providers/local-provider-registry.ts +277 -61
- package/src/services/providers/local-provider-service.ts +109 -44
- package/src/services/session-data.ts +18 -10
- package/src/services/session-telemetry.ts +6 -15
- package/src/services/storage/file-team-store.ts +1 -5
- package/src/services/storage/provider-settings-legacy-migration.ts +14 -51
- package/src/services/storage/provider-settings-manager.ts +17 -2
- package/src/services/storage/sqlite-team-store.ts +1 -5
- package/src/services/workspace-manifest.ts +18 -0
- package/src/session/conversation-store.ts +77 -0
- package/src/session/file-session-service.ts +1 -1
- package/src/session/index.ts +6 -27
- package/src/session/message-builder.ts +941 -0
- package/src/session/persistence-service.ts +119 -504
- package/src/session/session-manifest-store.ts +158 -0
- package/src/session/session-row.ts +199 -0
- package/src/session/session-service.ts +17 -376
- package/src/session/session-team-coordination.ts +1 -1
- package/src/session/subagent-session-manager.ts +397 -0
- package/src/session/team-persistence-store.ts +176 -0
- package/src/transports/hub.ts +1081 -0
- package/src/transports/local.ts +419 -93
- package/src/transports/remote.ts +27 -0
- package/src/transports/runtime-host-support.ts +63 -9
- package/src/types/chat-schema.ts +4 -5
- package/src/types/config.ts +17 -7
- package/src/types/events.ts +8 -6
- package/src/types/index.ts +3 -0
- package/src/types/provider-settings.ts +18 -7
- package/src/types/session.ts +7 -6
- package/src/types.ts +42 -2
- package/dist/hooks/persistent.d.ts +0 -64
- package/dist/hooks/persistent.d.ts.map +0 -1
- package/dist/runtime/rpc-runtime-ensure.d.ts +0 -65
- package/dist/runtime/rpc-runtime-ensure.d.ts.map +0 -1
- package/dist/runtime/rpc-spawn-lease.d.ts +0 -8
- package/dist/runtime/rpc-spawn-lease.d.ts.map +0 -1
- package/dist/services/telemetry/index.js +0 -15
- package/dist/session/rpc-session-service.d.ts +0 -16
- package/dist/session/rpc-session-service.d.ts.map +0 -1
- package/dist/session/sqlite-rpc-session-backend.d.ts +0 -31
- package/dist/session/sqlite-rpc-session-backend.d.ts.map +0 -1
- package/dist/transports/rpc.d.ts +0 -51
- package/dist/transports/rpc.d.ts.map +0 -1
- package/src/ClineCore.test.ts +0 -226
- package/src/account/cline-account-service.test.ts +0 -185
- package/src/account/featurebase-token.test.ts +0 -175
- package/src/account/rpc.test.ts +0 -63
- package/src/auth/bounded-ttl-cache.test.ts +0 -38
- package/src/auth/client.test.ts +0 -69
- package/src/auth/cline.test.ts +0 -267
- package/src/auth/codex.test.ts +0 -170
- package/src/auth/oca.test.ts +0 -340
- package/src/auth/server.test.ts +0 -287
- package/src/auth/utils.test.ts +0 -128
- package/src/extensions/config/agent-config-loader.test.ts +0 -236
- package/src/extensions/config/hooks-config-loader.test.ts +0 -20
- package/src/extensions/config/runtime-commands.test.ts +0 -115
- package/src/extensions/config/unified-config-file-watcher.test.ts +0 -196
- package/src/extensions/config/user-instruction-config-loader.test.ts +0 -246
- package/src/extensions/context/compaction.test.ts +0 -483
- package/src/extensions/mcp/config-loader.test.ts +0 -238
- package/src/extensions/mcp/manager.test.ts +0 -105
- package/src/extensions/plugin/plugin-config-loader.test.ts +0 -184
- package/src/extensions/plugin/plugin-loader.test.ts +0 -292
- package/src/extensions/plugin/plugin-sandbox.test.ts +0 -423
- package/src/extensions/tools/definitions.test.ts +0 -780
- package/src/extensions/tools/executors/bash.test.ts +0 -87
- package/src/extensions/tools/executors/editor.test.ts +0 -35
- package/src/extensions/tools/executors/file-read.test.ts +0 -125
- package/src/extensions/tools/model-tool-routing.test.ts +0 -86
- package/src/extensions/tools/presets.test.ts +0 -70
- package/src/extensions/tools/team/multi-agent.lifecycle.test.ts +0 -455
- package/src/extensions/tools/team/spawn-agent-tool.test.ts +0 -381
- package/src/extensions/tools/team/team-tools.test.ts +0 -918
- package/src/hooks/checkpoint-hooks.test.ts +0 -168
- package/src/hooks/hook-file-hooks.test.ts +0 -311
- package/src/hooks/persistent.ts +0 -661
- package/src/runtime/history.test.ts +0 -114
- package/src/runtime/host.test.ts +0 -230
- package/src/runtime/rpc-runtime-ensure.test.ts +0 -123
- package/src/runtime/rpc-runtime-ensure.ts +0 -659
- package/src/runtime/rpc-spawn-lease.test.ts +0 -81
- package/src/runtime/rpc-spawn-lease.ts +0 -156
- package/src/runtime/runtime-builder.team-persistence.test.ts +0 -245
- package/src/runtime/runtime-builder.test.ts +0 -615
- package/src/runtime/runtime-oauth-token-manager.test.ts +0 -137
- package/src/runtime/runtime-parity.test.ts +0 -143
- package/src/services/providers/local-provider-service.test.ts +0 -1062
- package/src/services/session-data.test.ts +0 -160
- package/src/services/storage/provider-settings-legacy-migration.test.ts +0 -424
- package/src/services/storage/provider-settings-manager.test.ts +0 -191
- package/src/services/telemetry/OpenTelemetryAdapter.test.ts +0 -157
- package/src/services/telemetry/OpenTelemetryProvider.test.ts +0 -326
- package/src/services/telemetry/TelemetryLoggerSink.test.ts +0 -42
- package/src/services/telemetry/TelemetryService.test.ts +0 -134
- package/src/services/telemetry/distinct-id.test.ts +0 -57
- package/src/services/workspace/file-indexer.d.ts +0 -11
- package/src/services/workspace/file-indexer.test.ts +0 -156
- package/src/services/workspace/mention-enricher.test.ts +0 -106
- package/src/session/persistence-service.test.ts +0 -300
- package/src/session/rpc-session-service.ts +0 -114
- package/src/session/session-service.team-persistence.test.ts +0 -48
- package/src/session/sqlite-rpc-session-backend.ts +0 -301
- package/src/transports/local.e2e.test.ts +0 -380
- package/src/transports/local.test.ts +0 -2559
- package/src/transports/rpc.test.ts +0 -82
- package/src/transports/rpc.ts +0 -665
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import type { CoreAgentMode } from "../../types/config";
|
|
2
|
+
import {
|
|
3
|
+
DEFAULT_MODEL_TOOL_ROUTING_RULES,
|
|
4
|
+
resolveToolRoutingConfig,
|
|
5
|
+
} from "./model-tool-routing";
|
|
6
|
+
import { resolveToolPresetName, ToolPresets } from "./presets";
|
|
7
|
+
import { createSpawnAgentTool } from "./team/spawn-agent-tool";
|
|
8
|
+
import { TEAM_TOOL_NAMES } from "./team/team-tools";
|
|
9
|
+
import type { DefaultToolsConfig } from "./types";
|
|
10
|
+
|
|
11
|
+
export interface ToolCatalogEntry {
|
|
12
|
+
id: string;
|
|
13
|
+
description: string;
|
|
14
|
+
defaultEnabled: boolean;
|
|
15
|
+
headlessToolNames: string[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface BuiltinToolAvailabilityContext {
|
|
19
|
+
mode?: CoreAgentMode;
|
|
20
|
+
providerId?: string;
|
|
21
|
+
modelId?: string;
|
|
22
|
+
enableSpawnAgent?: boolean;
|
|
23
|
+
enableAgentTeams?: boolean;
|
|
24
|
+
disabledToolIds?: ReadonlySet<string>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
type RuntimeToolCatalogEntry = Omit<ToolCatalogEntry, "defaultEnabled">;
|
|
28
|
+
|
|
29
|
+
const BASE_TOOL_CATALOG: readonly RuntimeToolCatalogEntry[] = [
|
|
30
|
+
{
|
|
31
|
+
id: "read_files",
|
|
32
|
+
description:
|
|
33
|
+
"Read the full content of text or image files at the provided absolute paths, or return only an inclusive one-based line range when start_line/end_line are provided.",
|
|
34
|
+
headlessToolNames: ["read_files"],
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
id: "search_codebase",
|
|
38
|
+
description:
|
|
39
|
+
"Perform regex pattern searches across the codebase for code patterns, definitions, imports, and other text matches.",
|
|
40
|
+
headlessToolNames: ["search_codebase"],
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
id: "run_commands",
|
|
44
|
+
description:
|
|
45
|
+
"Run shell commands from the root of the workspace for listing files, checking git status, builds, tests, and similar tasks.",
|
|
46
|
+
headlessToolNames: ["run_commands"],
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
id: "editor",
|
|
50
|
+
description:
|
|
51
|
+
"Make controlled filesystem edits on text files with create, replace, and insert operations.",
|
|
52
|
+
headlessToolNames: ["editor"],
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
id: "fetch_web_content",
|
|
56
|
+
description:
|
|
57
|
+
"Fetch URL content and analyze it with a prompt describing what to extract.",
|
|
58
|
+
headlessToolNames: ["fetch_web_content"],
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
id: "skills",
|
|
62
|
+
description:
|
|
63
|
+
"Execute a configured skill within the main conversation when a matching skill exists for the task.",
|
|
64
|
+
headlessToolNames: ["skills"],
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
id: "ask_question",
|
|
68
|
+
description:
|
|
69
|
+
"Ask the user a single clarifying question with 2-5 selectable options.",
|
|
70
|
+
headlessToolNames: ["ask_question"],
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
id: "spawn_agent",
|
|
74
|
+
description: createSpawnAgentTool({ configProvider: {} as never })
|
|
75
|
+
.description,
|
|
76
|
+
headlessToolNames: ["spawn_agent"],
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
id: "teams",
|
|
80
|
+
description:
|
|
81
|
+
"Enable team collaboration tools for teammate management, task coordination, mailbox messaging, mission logs, and outcomes.",
|
|
82
|
+
headlessToolNames: [...TEAM_TOOL_NAMES],
|
|
83
|
+
},
|
|
84
|
+
] as const;
|
|
85
|
+
|
|
86
|
+
const TOOL_NAME_TO_FLAG: Partial<
|
|
87
|
+
Record<
|
|
88
|
+
string,
|
|
89
|
+
keyof Pick<
|
|
90
|
+
DefaultToolsConfig,
|
|
91
|
+
| "enableReadFiles"
|
|
92
|
+
| "enableSearch"
|
|
93
|
+
| "enableBash"
|
|
94
|
+
| "enableWebFetch"
|
|
95
|
+
| "enableApplyPatch"
|
|
96
|
+
| "enableEditor"
|
|
97
|
+
| "enableSkills"
|
|
98
|
+
| "enableAskQuestion"
|
|
99
|
+
| "enableSubmitAndExit"
|
|
100
|
+
>
|
|
101
|
+
>
|
|
102
|
+
> = {
|
|
103
|
+
read_files: "enableReadFiles",
|
|
104
|
+
search_codebase: "enableSearch",
|
|
105
|
+
run_commands: "enableBash",
|
|
106
|
+
fetch_web_content: "enableWebFetch",
|
|
107
|
+
apply_patch: "enableApplyPatch",
|
|
108
|
+
editor: "enableEditor",
|
|
109
|
+
skills: "enableSkills",
|
|
110
|
+
ask_question: "enableAskQuestion",
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
function resolveContextMode(
|
|
114
|
+
mode?: BuiltinToolAvailabilityContext["mode"],
|
|
115
|
+
): CoreAgentMode {
|
|
116
|
+
return mode === "plan" || mode === "yolo" ? mode : "act";
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
type ResolvedToolFlags = Pick<
|
|
120
|
+
DefaultToolsConfig,
|
|
121
|
+
| "enableReadFiles"
|
|
122
|
+
| "enableSearch"
|
|
123
|
+
| "enableBash"
|
|
124
|
+
| "enableWebFetch"
|
|
125
|
+
| "enableApplyPatch"
|
|
126
|
+
| "enableEditor"
|
|
127
|
+
| "enableSkills"
|
|
128
|
+
| "enableAskQuestion"
|
|
129
|
+
| "enableSubmitAndExit"
|
|
130
|
+
> & {
|
|
131
|
+
enableSpawnAgent?: boolean;
|
|
132
|
+
enableAgentTeams?: boolean;
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
function resolvePresetFlags(context: BuiltinToolAvailabilityContext): {
|
|
136
|
+
mode: CoreAgentMode;
|
|
137
|
+
flags: ResolvedToolFlags;
|
|
138
|
+
} {
|
|
139
|
+
const mode = resolveContextMode(context.mode);
|
|
140
|
+
const preset = ToolPresets[resolveToolPresetName({ mode })];
|
|
141
|
+
const routed = resolveToolRoutingConfig(
|
|
142
|
+
context.providerId ?? "",
|
|
143
|
+
context.modelId ?? "",
|
|
144
|
+
mode,
|
|
145
|
+
DEFAULT_MODEL_TOOL_ROUTING_RULES,
|
|
146
|
+
);
|
|
147
|
+
return {
|
|
148
|
+
mode,
|
|
149
|
+
flags: {
|
|
150
|
+
...preset,
|
|
151
|
+
...routed,
|
|
152
|
+
...(typeof context.enableSpawnAgent === "boolean"
|
|
153
|
+
? { enableSpawnAgent: context.enableSpawnAgent }
|
|
154
|
+
: {}),
|
|
155
|
+
...(typeof context.enableAgentTeams === "boolean"
|
|
156
|
+
? { enableAgentTeams: context.enableAgentTeams }
|
|
157
|
+
: {}),
|
|
158
|
+
},
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function isEntryEnabledByDefault(
|
|
163
|
+
entryId: string,
|
|
164
|
+
context: BuiltinToolAvailabilityContext,
|
|
165
|
+
): boolean {
|
|
166
|
+
if (context.disabledToolIds?.has(entryId)) {
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const { flags } = resolvePresetFlags(context);
|
|
171
|
+
if (entryId === "spawn_agent") {
|
|
172
|
+
return flags.enableSpawnAgent === true;
|
|
173
|
+
}
|
|
174
|
+
if (entryId === "teams") {
|
|
175
|
+
return flags.enableAgentTeams === true;
|
|
176
|
+
}
|
|
177
|
+
if (entryId === "editor") {
|
|
178
|
+
return flags.enableEditor === true || flags.enableApplyPatch === true;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const flag = TOOL_NAME_TO_FLAG[entryId];
|
|
182
|
+
return flag ? flags[flag] === true : false;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function buildCatalogEntry(
|
|
186
|
+
entry: RuntimeToolCatalogEntry,
|
|
187
|
+
context: BuiltinToolAvailabilityContext,
|
|
188
|
+
): ToolCatalogEntry {
|
|
189
|
+
if (entry.id === "editor") {
|
|
190
|
+
const { flags } = resolvePresetFlags(context);
|
|
191
|
+
const usesApplyPatch =
|
|
192
|
+
flags.enableApplyPatch === true && flags.enableEditor !== true;
|
|
193
|
+
return {
|
|
194
|
+
...entry,
|
|
195
|
+
defaultEnabled: isEntryEnabledByDefault(entry.id, context),
|
|
196
|
+
headlessToolNames: [usesApplyPatch ? "apply_patch" : "editor"],
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return {
|
|
201
|
+
...entry,
|
|
202
|
+
defaultEnabled: isEntryEnabledByDefault(entry.id, context),
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export function getCoreBuiltinToolCatalog(
|
|
207
|
+
context: BuiltinToolAvailabilityContext = {},
|
|
208
|
+
): ToolCatalogEntry[] {
|
|
209
|
+
return BASE_TOOL_CATALOG.map((entry) => buildCatalogEntry(entry, context));
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export function getCoreDefaultEnabledToolIds(
|
|
213
|
+
context: BuiltinToolAvailabilityContext = {},
|
|
214
|
+
): string[] {
|
|
215
|
+
return getCoreBuiltinToolCatalog(context)
|
|
216
|
+
.filter((entry) => entry.defaultEnabled)
|
|
217
|
+
.map((entry) => entry.id);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export function resolveCoreSelectedToolIds(input: {
|
|
221
|
+
enabled: boolean;
|
|
222
|
+
allowlist?: string[];
|
|
223
|
+
availabilityContext?: BuiltinToolAvailabilityContext;
|
|
224
|
+
}): Set<string> {
|
|
225
|
+
if (!input.enabled) {
|
|
226
|
+
return new Set();
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const catalog = getCoreBuiltinToolCatalog(input.availabilityContext);
|
|
230
|
+
const known = new Set(catalog.map((entry) => entry.id));
|
|
231
|
+
if (!input.allowlist || input.allowlist.length === 0) {
|
|
232
|
+
return new Set(
|
|
233
|
+
catalog.filter((entry) => entry.defaultEnabled).map((entry) => entry.id),
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
for (const id of input.allowlist) {
|
|
238
|
+
if (!known.has(id)) {
|
|
239
|
+
throw new Error(
|
|
240
|
+
`Unknown tool "${id}". Available tools: ${catalog.map((entry) => entry.id).join(", ")}`,
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
return new Set(input.allowlist);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export function getCoreHeadlessToolNames(
|
|
248
|
+
selectedToolIds: ReadonlySet<string>,
|
|
249
|
+
context: BuiltinToolAvailabilityContext = {},
|
|
250
|
+
): string[] {
|
|
251
|
+
return getCoreBuiltinToolCatalog(context)
|
|
252
|
+
.filter((entry) => selectedToolIds.has(entry.id))
|
|
253
|
+
.flatMap((entry) => entry.headlessToolNames);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export function getCoreAcpToolNames(
|
|
257
|
+
selectedToolIds: ReadonlySet<string>,
|
|
258
|
+
context: BuiltinToolAvailabilityContext = {},
|
|
259
|
+
): string[] {
|
|
260
|
+
return getCoreHeadlessToolNames(selectedToolIds, context);
|
|
261
|
+
}
|
|
@@ -37,14 +37,7 @@ export const ReadFileLineRangeSchema = z
|
|
|
37
37
|
"Optional one-based ending line number to read through; use null or omit for the end of the file",
|
|
38
38
|
),
|
|
39
39
|
})
|
|
40
|
-
.
|
|
41
|
-
({ start_line, end_line }) =>
|
|
42
|
-
start_line == null || end_line == null || start_line <= end_line,
|
|
43
|
-
{
|
|
44
|
-
message: "start_line must be less than or equal to end_line",
|
|
45
|
-
path: ["end_line"],
|
|
46
|
-
},
|
|
47
|
-
);
|
|
40
|
+
.describe("Optional inclusive one-based file line range");
|
|
48
41
|
|
|
49
42
|
export const ReadFileRequestSchema = z
|
|
50
43
|
.object({
|
|
@@ -52,13 +45,8 @@ export const ReadFileRequestSchema = z
|
|
|
52
45
|
start_line: ReadFileLineRangeSchema.shape.start_line,
|
|
53
46
|
end_line: ReadFileLineRangeSchema.shape.end_line,
|
|
54
47
|
})
|
|
55
|
-
.
|
|
56
|
-
|
|
57
|
-
start_line == null || end_line == null || start_line <= end_line,
|
|
58
|
-
{
|
|
59
|
-
message: "start_line must be less than or equal to end_line",
|
|
60
|
-
path: ["end_line"],
|
|
61
|
-
},
|
|
48
|
+
.describe(
|
|
49
|
+
"A file read request with optional inclusive one-based line bounds",
|
|
62
50
|
);
|
|
63
51
|
|
|
64
52
|
/**
|
|
@@ -84,6 +72,9 @@ export const ReadFilesInputUnionSchema = z.union([
|
|
|
84
72
|
z.object({ files: ReadFileRequestSchema }),
|
|
85
73
|
z.object({ file_paths: z.array(AbsolutePath) }),
|
|
86
74
|
z.object({ file_paths: z.string() }),
|
|
75
|
+
z.object({ paths: z.array(z.union([AbsolutePath, ReadFileRequestSchema])) }),
|
|
76
|
+
z.object({ paths: ReadFileRequestSchema }),
|
|
77
|
+
z.object({ paths: z.string() }),
|
|
87
78
|
]);
|
|
88
79
|
|
|
89
80
|
/**
|
|
@@ -126,6 +117,8 @@ export const RunCommandsInputSchema = z.object({
|
|
|
126
117
|
export const RunCommandsInputUnionSchema = z.union([
|
|
127
118
|
RunCommandsInputSchema,
|
|
128
119
|
z.object({ commands: CommandInputSchema }),
|
|
120
|
+
z.object({ command: CommandInputSchema }),
|
|
121
|
+
z.object({ cmd: CommandInputSchema }),
|
|
129
122
|
z.array(z.string()),
|
|
130
123
|
z.string(),
|
|
131
124
|
]);
|
|
@@ -163,10 +156,12 @@ export const StructuredCommandsInputUnionSchema = z.union([
|
|
|
163
156
|
RunCommandsInputSchema,
|
|
164
157
|
StructuredCommandsInputSchema,
|
|
165
158
|
z.object({ commands: StructuredCommandEntrySchema }),
|
|
166
|
-
z.array(z.string()),
|
|
167
159
|
z.array(StructuredCommandInputSchema),
|
|
168
|
-
z.string(),
|
|
169
160
|
StructuredCommandInputSchema,
|
|
161
|
+
z.object({ command: CommandInputSchema }),
|
|
162
|
+
z.object({ cmd: CommandInputSchema }),
|
|
163
|
+
z.array(z.string()),
|
|
164
|
+
z.string(),
|
|
170
165
|
]);
|
|
171
166
|
|
|
172
167
|
/**
|
|
@@ -213,7 +208,7 @@ export const EditFileInputSchema = z
|
|
|
213
208
|
.nullable()
|
|
214
209
|
.optional()
|
|
215
210
|
.describe(
|
|
216
|
-
"Optional one-based line
|
|
211
|
+
"Optional positive one-based boundary line. When provided, the tool inserts new_text before that line instead of performing a replacement edit; use line_count + 1 to append at EOF.",
|
|
217
212
|
),
|
|
218
213
|
})
|
|
219
214
|
.describe(
|
|
@@ -228,10 +223,12 @@ export const ApplyPatchInputSchema = z
|
|
|
228
223
|
input: z
|
|
229
224
|
.string()
|
|
230
225
|
.min(1)
|
|
231
|
-
.describe(
|
|
226
|
+
.describe(
|
|
227
|
+
"The freeform apply_patch payload in the canonical patch grammar (e.g *** Begin Patch, *** Update File:, @@, and *** End Patch).",
|
|
228
|
+
),
|
|
232
229
|
})
|
|
233
230
|
.describe(
|
|
234
|
-
"Modify or create a text file by applying patches. Prefer
|
|
231
|
+
"Modify or create a text file by applying patches using the canonical apply_patch diff grammar. Prefer sending the patch body directly rather than wrapping it in shell syntax. IMPORTANT: large patches can time out, so use small chunks and multiple calls when possible.",
|
|
235
232
|
);
|
|
236
233
|
export const ApplyPatchInputUnionSchema = z.union([
|
|
237
234
|
ApplyPatchInputSchema,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Agent } from "@clinebot/agents";
|
|
2
1
|
import type {
|
|
3
2
|
AgentConfig,
|
|
4
3
|
AgentEvent,
|
|
@@ -10,6 +9,7 @@ import type {
|
|
|
10
9
|
ToolApprovalRequest,
|
|
11
10
|
ToolApprovalResult,
|
|
12
11
|
} from "@clinebot/shared";
|
|
12
|
+
import { SessionRuntime } from "../../../runtime/session-runtime-orchestrator";
|
|
13
13
|
import {
|
|
14
14
|
buildSubAgentSystemPrompt,
|
|
15
15
|
buildTeammateSystemPrompt,
|
|
@@ -126,6 +126,11 @@ export function buildDelegatedAgentConfig(
|
|
|
126
126
|
|
|
127
127
|
export function createDelegatedAgent(
|
|
128
128
|
options: BuildDelegatedAgentConfigOptions,
|
|
129
|
-
):
|
|
130
|
-
|
|
129
|
+
): SessionRuntime {
|
|
130
|
+
const config = buildDelegatedAgentConfig(options);
|
|
131
|
+
const session = new SessionRuntime(config);
|
|
132
|
+
if (config.onEvent) {
|
|
133
|
+
session.subscribeEvents(config.onEvent);
|
|
134
|
+
}
|
|
135
|
+
return session;
|
|
131
136
|
}
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
* Utilities for orchestrating multiple agents working together.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import { type Agent, createAgent } from "@clinebot/agents";
|
|
8
7
|
import {
|
|
9
8
|
type AgentConfig,
|
|
10
9
|
type AgentEvent,
|
|
@@ -33,6 +32,7 @@ import {
|
|
|
33
32
|
type TeamTaskStatus,
|
|
34
33
|
} from "@clinebot/shared";
|
|
35
34
|
import { nanoid } from "nanoid";
|
|
35
|
+
import { SessionRuntime } from "../../../runtime/session-runtime-orchestrator";
|
|
36
36
|
|
|
37
37
|
// Re-export shared types for backward compatibility
|
|
38
38
|
export {
|
|
@@ -155,14 +155,26 @@ function isAbortLikeError(error: unknown): boolean {
|
|
|
155
155
|
);
|
|
156
156
|
}
|
|
157
157
|
|
|
158
|
+
function isIntentionalShutdownAbort(
|
|
159
|
+
member: TeamMemberState | undefined,
|
|
160
|
+
error: unknown,
|
|
161
|
+
): boolean {
|
|
162
|
+
return member?.status === "stopped" && isAbortLikeError(error);
|
|
163
|
+
}
|
|
164
|
+
|
|
158
165
|
// =============================================================================
|
|
159
166
|
// AgentTeam
|
|
160
167
|
// =============================================================================
|
|
161
168
|
|
|
162
169
|
const TEAMMATE_API_TIMEOUT_MS = 10 * 60 * 1000; // 10 minutes
|
|
170
|
+
const RECOVERED_QUEUED_ACTIVITY = "recovered_queued";
|
|
171
|
+
|
|
172
|
+
function buildRecoveredRunMessage(run: TeamRunRecord): string {
|
|
173
|
+
return `This is an automatic recovery of interrupted team run ${run.id}. The previous process stopped before completion. Continue the task safely, inspect the current workspace state before making changes, and avoid duplicating completed work.\n\n${run.message}`;
|
|
174
|
+
}
|
|
163
175
|
|
|
164
176
|
export class AgentTeam {
|
|
165
|
-
private agents: Map<string,
|
|
177
|
+
private agents: Map<string, SessionRuntime> = new Map();
|
|
166
178
|
private configs: Map<string, TeamMemberConfig> = new Map();
|
|
167
179
|
private onTeamEvent?: (event: TeamEvent) => void;
|
|
168
180
|
|
|
@@ -196,7 +208,10 @@ export class AgentTeam {
|
|
|
196
208
|
},
|
|
197
209
|
};
|
|
198
210
|
|
|
199
|
-
const agent =
|
|
211
|
+
const agent = new SessionRuntime(wrappedConfig);
|
|
212
|
+
if (wrappedConfig.onEvent) {
|
|
213
|
+
agent.subscribeEvents(wrappedConfig.onEvent);
|
|
214
|
+
}
|
|
200
215
|
this.agents.set(id, agent);
|
|
201
216
|
this.configs.set(id, config);
|
|
202
217
|
}
|
|
@@ -206,7 +221,7 @@ export class AgentTeam {
|
|
|
206
221
|
return this.agents.delete(id);
|
|
207
222
|
}
|
|
208
223
|
|
|
209
|
-
getAgent(id: string):
|
|
224
|
+
getAgent(id: string): SessionRuntime | undefined {
|
|
210
225
|
return this.agents.get(id);
|
|
211
226
|
}
|
|
212
227
|
|
|
@@ -497,7 +512,7 @@ export function createWorkerReviewerTeam(configs: {
|
|
|
497
512
|
// =============================================================================
|
|
498
513
|
|
|
499
514
|
interface TeamMemberState extends TeamMemberSnapshot {
|
|
500
|
-
agent?:
|
|
515
|
+
agent?: SessionRuntime;
|
|
501
516
|
runningCount: number;
|
|
502
517
|
lastMissionStep: number;
|
|
503
518
|
lastMissionAt: number;
|
|
@@ -522,6 +537,7 @@ export class AgentTeamsRuntime {
|
|
|
522
537
|
private readonly runs: Map<string, TeamRunRecord & { result?: AgentResult }> =
|
|
523
538
|
new Map();
|
|
524
539
|
private readonly runQueue: string[] = [];
|
|
540
|
+
private queuedRunDispatchTimer: ReturnType<typeof setTimeout> | undefined;
|
|
525
541
|
private readonly outcomes: Map<string, TeamOutcome> = new Map();
|
|
526
542
|
private readonly outcomeFragments: Map<string, TeamOutcomeFragment> =
|
|
527
543
|
new Map();
|
|
@@ -707,6 +723,7 @@ export class AgentTeamsRuntime {
|
|
|
707
723
|
}
|
|
708
724
|
|
|
709
725
|
hydrateState(state: TeamRuntimeState): void {
|
|
726
|
+
this.clearQueuedRunDispatchTimer();
|
|
710
727
|
this.tasks.clear();
|
|
711
728
|
for (const task of state.tasks) {
|
|
712
729
|
this.tasks.set(task.id, { ...task });
|
|
@@ -851,7 +868,10 @@ export class AgentTeamsRuntime {
|
|
|
851
868
|
},
|
|
852
869
|
};
|
|
853
870
|
|
|
854
|
-
const agent =
|
|
871
|
+
const agent = new SessionRuntime(wrappedConfig);
|
|
872
|
+
if (wrappedConfig.onEvent) {
|
|
873
|
+
agent.subscribeEvents(wrappedConfig.onEvent);
|
|
874
|
+
}
|
|
855
875
|
const teammate: TeamMemberState = {
|
|
856
876
|
agentId,
|
|
857
877
|
role: "teammate",
|
|
@@ -1038,12 +1058,14 @@ export class AgentTeamsRuntime {
|
|
|
1038
1058
|
error: err,
|
|
1039
1059
|
messages: member.agent.getMessages(),
|
|
1040
1060
|
});
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1061
|
+
if (!isIntentionalShutdownAbort(member, err)) {
|
|
1062
|
+
this.appendMissionLog({
|
|
1063
|
+
agentId,
|
|
1064
|
+
taskId: options?.taskId,
|
|
1065
|
+
kind: "error",
|
|
1066
|
+
summary: err.message,
|
|
1067
|
+
});
|
|
1068
|
+
}
|
|
1047
1069
|
throw err;
|
|
1048
1070
|
} finally {
|
|
1049
1071
|
member.runningCount--;
|
|
@@ -1091,11 +1113,19 @@ export class AgentTeamsRuntime {
|
|
|
1091
1113
|
}
|
|
1092
1114
|
|
|
1093
1115
|
private dispatchQueuedRuns(): void {
|
|
1116
|
+
this.clearQueuedRunDispatchTimer();
|
|
1117
|
+
let nextDelayedAttemptAt: Date | undefined;
|
|
1094
1118
|
while (
|
|
1095
1119
|
this.countActiveRuns() < this.maxConcurrentRuns &&
|
|
1096
1120
|
this.runQueue.length > 0
|
|
1097
1121
|
) {
|
|
1098
|
-
const
|
|
1122
|
+
const nextRun = this.selectNextDispatchableQueuedRun();
|
|
1123
|
+
nextDelayedAttemptAt = nextRun.nextDelayedAttemptAt;
|
|
1124
|
+
const nextRunIndex = nextRun.index;
|
|
1125
|
+
if (nextRunIndex < 0) {
|
|
1126
|
+
this.scheduleQueuedRunDispatch(nextDelayedAttemptAt);
|
|
1127
|
+
return;
|
|
1128
|
+
}
|
|
1099
1129
|
const [runId] = this.runQueue.splice(nextRunIndex, 1);
|
|
1100
1130
|
const run = runId ? this.runs.get(runId) : undefined;
|
|
1101
1131
|
if (!run || run.status !== "queued") {
|
|
@@ -1103,22 +1133,53 @@ export class AgentTeamsRuntime {
|
|
|
1103
1133
|
}
|
|
1104
1134
|
void this.executeQueuedRun(run);
|
|
1105
1135
|
}
|
|
1136
|
+
this.scheduleQueuedRunDispatch(nextDelayedAttemptAt);
|
|
1106
1137
|
}
|
|
1107
1138
|
|
|
1108
|
-
private
|
|
1109
|
-
|
|
1139
|
+
private selectNextDispatchableQueuedRun(): {
|
|
1140
|
+
index: number;
|
|
1141
|
+
nextDelayedAttemptAt?: Date;
|
|
1142
|
+
} {
|
|
1143
|
+
let selectedIndex = -1;
|
|
1110
1144
|
let bestPriority = Number.NEGATIVE_INFINITY;
|
|
1145
|
+
let nextDelayedAttemptAt: Date | undefined;
|
|
1146
|
+
const now = Date.now();
|
|
1111
1147
|
for (let index = 0; index < this.runQueue.length; index++) {
|
|
1112
1148
|
const run = this.runs.get(this.runQueue[index]);
|
|
1113
1149
|
if (!run || run.status !== "queued") {
|
|
1114
1150
|
continue;
|
|
1115
1151
|
}
|
|
1152
|
+
if (run.nextAttemptAt && run.nextAttemptAt.getTime() > now) {
|
|
1153
|
+
if (!nextDelayedAttemptAt || run.nextAttemptAt < nextDelayedAttemptAt) {
|
|
1154
|
+
nextDelayedAttemptAt = run.nextAttemptAt;
|
|
1155
|
+
}
|
|
1156
|
+
continue;
|
|
1157
|
+
}
|
|
1116
1158
|
if (run.priority > bestPriority) {
|
|
1117
1159
|
bestPriority = run.priority;
|
|
1118
1160
|
selectedIndex = index;
|
|
1119
1161
|
}
|
|
1120
1162
|
}
|
|
1121
|
-
return selectedIndex;
|
|
1163
|
+
return { index: selectedIndex, nextDelayedAttemptAt };
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1166
|
+
private scheduleQueuedRunDispatch(nextAttemptAt: Date | undefined): void {
|
|
1167
|
+
if (!nextAttemptAt) {
|
|
1168
|
+
return;
|
|
1169
|
+
}
|
|
1170
|
+
const delayMs = Math.max(0, nextAttemptAt.getTime() - Date.now());
|
|
1171
|
+
this.queuedRunDispatchTimer = setTimeout(() => {
|
|
1172
|
+
this.queuedRunDispatchTimer = undefined;
|
|
1173
|
+
this.dispatchQueuedRuns();
|
|
1174
|
+
}, delayMs);
|
|
1175
|
+
}
|
|
1176
|
+
|
|
1177
|
+
private clearQueuedRunDispatchTimer(): void {
|
|
1178
|
+
if (!this.queuedRunDispatchTimer) {
|
|
1179
|
+
return;
|
|
1180
|
+
}
|
|
1181
|
+
clearTimeout(this.queuedRunDispatchTimer);
|
|
1182
|
+
this.queuedRunDispatchTimer = undefined;
|
|
1122
1183
|
}
|
|
1123
1184
|
|
|
1124
1185
|
private countActiveRuns(): number {
|
|
@@ -1134,6 +1195,8 @@ export class AgentTeamsRuntime {
|
|
|
1134
1195
|
private async executeQueuedRun(
|
|
1135
1196
|
run: TeamRunRecord & { result?: AgentResult },
|
|
1136
1197
|
): Promise<void> {
|
|
1198
|
+
const recoveredRun = run.currentActivity === RECOVERED_QUEUED_ACTIVITY;
|
|
1199
|
+
run.nextAttemptAt = undefined;
|
|
1137
1200
|
run.status = "running";
|
|
1138
1201
|
run.startedAt = new Date();
|
|
1139
1202
|
run.heartbeatAt = new Date();
|
|
@@ -1148,7 +1211,10 @@ export class AgentTeamsRuntime {
|
|
|
1148
1211
|
}, 2000);
|
|
1149
1212
|
|
|
1150
1213
|
try {
|
|
1151
|
-
const
|
|
1214
|
+
const runMessage = recoveredRun
|
|
1215
|
+
? buildRecoveredRunMessage(run)
|
|
1216
|
+
: run.message;
|
|
1217
|
+
const result = await this.routeToTeammate(run.agentId, runMessage, {
|
|
1152
1218
|
taskId: run.taskId,
|
|
1153
1219
|
continueConversation: run.continueConversation,
|
|
1154
1220
|
});
|
|
@@ -1164,7 +1230,16 @@ export class AgentTeamsRuntime {
|
|
|
1164
1230
|
: String(error ?? "Unknown error");
|
|
1165
1231
|
run.error = message;
|
|
1166
1232
|
run.endedAt = new Date();
|
|
1167
|
-
|
|
1233
|
+
const member = this.members.get(run.agentId);
|
|
1234
|
+
if (isIntentionalShutdownAbort(member, error)) {
|
|
1235
|
+
run.status = "cancelled";
|
|
1236
|
+
run.currentActivity = "cancelled";
|
|
1237
|
+
this.emitEvent({
|
|
1238
|
+
type: TeamMessageType.RunCancelled,
|
|
1239
|
+
run: { ...run },
|
|
1240
|
+
reason: message,
|
|
1241
|
+
});
|
|
1242
|
+
} else if (run.retryCount < run.maxRetries) {
|
|
1168
1243
|
run.retryCount++;
|
|
1169
1244
|
run.status = "queued";
|
|
1170
1245
|
run.nextAttemptAt = new Date(
|
|
@@ -1215,7 +1290,7 @@ export class AgentTeamsRuntime {
|
|
|
1215
1290
|
if (!run) {
|
|
1216
1291
|
throw new Error(`Run "${runId}" was not found`);
|
|
1217
1292
|
}
|
|
1218
|
-
while (run.status === "running") {
|
|
1293
|
+
while (run.status === "queued" || run.status === "running") {
|
|
1219
1294
|
await sleep(pollIntervalMs);
|
|
1220
1295
|
}
|
|
1221
1296
|
return { ...run };
|
|
@@ -1256,6 +1331,45 @@ export class AgentTeamsRuntime {
|
|
|
1256
1331
|
return { ...run };
|
|
1257
1332
|
}
|
|
1258
1333
|
|
|
1334
|
+
recoverActiveRuns(reason = "runtime_recovered"): TeamRunRecord[] {
|
|
1335
|
+
const recovered: TeamRunRecord[] = [];
|
|
1336
|
+
for (const run of this.runs.values()) {
|
|
1337
|
+
if (!["queued", "running"].includes(run.status)) {
|
|
1338
|
+
continue;
|
|
1339
|
+
}
|
|
1340
|
+
|
|
1341
|
+
const member = this.members.get(run.agentId);
|
|
1342
|
+
if (!member || member.role !== "teammate" || !member.agent) {
|
|
1343
|
+
run.status = "interrupted";
|
|
1344
|
+
run.error = "teammate_unavailable_after_recovery";
|
|
1345
|
+
run.endedAt = new Date();
|
|
1346
|
+
run.currentActivity = "interrupted";
|
|
1347
|
+
this.emitEvent({
|
|
1348
|
+
type: TeamMessageType.RunInterrupted,
|
|
1349
|
+
run: { ...run },
|
|
1350
|
+
reason: run.error,
|
|
1351
|
+
});
|
|
1352
|
+
continue;
|
|
1353
|
+
}
|
|
1354
|
+
|
|
1355
|
+
const now = new Date();
|
|
1356
|
+
run.status = "queued";
|
|
1357
|
+
run.error = undefined;
|
|
1358
|
+
run.endedAt = undefined;
|
|
1359
|
+
run.heartbeatAt = now;
|
|
1360
|
+
run.lastProgressAt = now;
|
|
1361
|
+
run.lastProgressMessage = reason;
|
|
1362
|
+
run.currentActivity = RECOVERED_QUEUED_ACTIVITY;
|
|
1363
|
+
if (!this.runQueue.includes(run.id)) {
|
|
1364
|
+
this.runQueue.push(run.id);
|
|
1365
|
+
}
|
|
1366
|
+
recovered.push({ ...run });
|
|
1367
|
+
this.emitEvent({ type: TeamMessageType.RunQueued, run: { ...run } });
|
|
1368
|
+
}
|
|
1369
|
+
this.dispatchQueuedRuns();
|
|
1370
|
+
return recovered;
|
|
1371
|
+
}
|
|
1372
|
+
|
|
1259
1373
|
markStaleRunsInterrupted(reason = "runtime_recovered"): TeamRunRecord[] {
|
|
1260
1374
|
const interrupted: TeamRunRecord[] = [];
|
|
1261
1375
|
for (const run of this.runs.values()) {
|
|
@@ -1274,6 +1388,7 @@ export class AgentTeamsRuntime {
|
|
|
1274
1388
|
});
|
|
1275
1389
|
}
|
|
1276
1390
|
this.runQueue.length = 0;
|
|
1391
|
+
this.clearQueuedRunDispatchTimer();
|
|
1277
1392
|
return interrupted;
|
|
1278
1393
|
}
|
|
1279
1394
|
|
|
@@ -1513,6 +1628,7 @@ export class AgentTeamsRuntime {
|
|
|
1513
1628
|
this.missionLog.length = 0;
|
|
1514
1629
|
this.runs.clear();
|
|
1515
1630
|
this.runQueue.length = 0;
|
|
1631
|
+
this.clearQueuedRunDispatchTimer();
|
|
1516
1632
|
this.outcomes.clear();
|
|
1517
1633
|
this.outcomeFragments.clear();
|
|
1518
1634
|
|