@clinebot/core 0.0.34 → 0.0.36
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 +13 -10
- package/dist/ClineCore.d.ts +96 -63
- package/dist/ClineCore.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/index.d.ts +6 -0
- package/dist/cron/index.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 +66 -0
- package/dist/cron/scheduler.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 +6 -5
- package/dist/extensions/config/agent-config-loader.d.ts.map +1 -1
- package/dist/extensions/config/agent-config-parser.d.ts +1 -1
- package/dist/extensions/config/agent-config-parser.d.ts.map +1 -1
- package/dist/extensions/config/hooks-config-loader.d.ts +2 -2
- package/dist/extensions/config/hooks-config-loader.d.ts.map +1 -1
- package/dist/extensions/config/index.d.ts +3 -3
- package/dist/extensions/config/index.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 +3 -2
- 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 +9 -2
- package/dist/extensions/plugin/plugin-config-loader.d.ts.map +1 -1
- package/dist/extensions/plugin/plugin-loader.d.ts +5 -3
- 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 +15 -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 +253 -253
- package/dist/extensions/tools/constants.d.ts.map +1 -0
- package/dist/{tools → extensions/tools}/definitions.d.ts +1 -1
- package/dist/extensions/tools/definitions.d.ts.map +1 -0
- package/dist/extensions/tools/executors/apply-patch-parser.d.ts.map +1 -0
- package/dist/{tools → extensions/tools}/executors/apply-patch.d.ts +3 -1
- package/dist/extensions/tools/executors/apply-patch.d.ts.map +1 -0
- package/dist/extensions/tools/executors/bash.d.ts.map +1 -0
- package/dist/extensions/tools/executors/editor.d.ts.map +1 -0
- package/dist/extensions/tools/executors/file-read.d.ts.map +1 -0
- package/dist/extensions/tools/executors/index.d.ts.map +1 -0
- package/dist/{tools → extensions/tools}/executors/search.d.ts +1 -1
- package/dist/extensions/tools/executors/search.d.ts.map +1 -0
- package/dist/extensions/tools/executors/web-fetch.d.ts.map +1 -0
- package/dist/extensions/tools/helpers.d.ts.map +1 -0
- package/dist/{tools → extensions/tools}/index.d.ts +2 -0
- package/dist/extensions/tools/index.d.ts.map +1 -0
- package/dist/{tools → extensions/tools}/model-tool-routing.d.ts +1 -1
- package/dist/extensions/tools/model-tool-routing.d.ts.map +1 -0
- package/dist/{tools → extensions/tools}/presets.d.ts +26 -44
- package/dist/extensions/tools/presets.d.ts.map +1 -0
- 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.map +1 -0
- package/dist/extensions/tools/team/delegated-agent.d.ts.map +1 -0
- package/dist/extensions/tools/team/index.d.ts.map +1 -0
- package/dist/{team → extensions/tools/team}/multi-agent.d.ts +1 -3
- package/dist/extensions/tools/team/multi-agent.d.ts.map +1 -0
- package/dist/extensions/tools/team/projections.d.ts.map +1 -0
- package/dist/extensions/tools/team/runtime.d.ts.map +1 -0
- package/dist/{team → extensions/tools/team}/spawn-agent-tool.d.ts +0 -1
- package/dist/extensions/tools/team/spawn-agent-tool.d.ts.map +1 -0
- package/dist/extensions/tools/team/subagent-prompts.d.ts.map +1 -0
- package/dist/{team → extensions/tools/team}/team-tools.d.ts +1 -0
- package/dist/extensions/tools/team/team-tools.d.ts.map +1 -0
- package/dist/{tools → extensions/tools}/types.d.ts +4 -3
- package/dist/extensions/tools/types.d.ts.map +1 -0
- package/dist/{runtime → hooks}/checkpoint-hooks.d.ts +7 -0
- package/dist/hooks/checkpoint-hooks.d.ts.map +1 -0
- package/dist/{runtime → hooks}/hook-file-hooks.d.ts +4 -3
- package/dist/hooks/hook-file-hooks.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 +10 -130
- 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 +45 -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 +1045 -0
- package/dist/hub/daemon.d.ts +5 -0
- package/dist/hub/daemon.d.ts.map +1 -0
- package/dist/hub/defaults.d.ts +13 -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 +1044 -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 +86 -0
- package/dist/hub/server.d.ts.map +1 -0
- package/dist/hub/session-client.d.ts +87 -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 +44 -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 +52 -39
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +557 -533
- package/dist/llms/configured-provider-registry.d.ts +28 -0
- package/dist/llms/configured-provider-registry.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 +202 -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/history.d.ts +4 -0
- package/dist/runtime/history.d.ts.map +1 -0
- package/dist/runtime/host.d.ts +8 -0
- package/dist/runtime/host.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-host.d.ts +103 -0
- package/dist/runtime/runtime-host.d.ts.map +1 -0
- package/dist/{session → runtime}/runtime-oauth-token-manager.d.ts +1 -1
- package/dist/{session → runtime}/runtime-oauth-token-manager.d.ts.map +1 -1
- package/dist/runtime/session-runtime.d.ts +3 -21
- package/dist/runtime/session-runtime.d.ts.map +1 -1
- package/dist/{session/session-agent-events.d.ts → services/agent-events.d.ts} +4 -4
- package/dist/services/agent-events.d.ts.map +1 -0
- package/dist/services/config.d.ts +3 -0
- package/dist/services/config.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/local-runtime-bootstrap.d.ts +47 -0
- package/dist/services/local-runtime-bootstrap.d.ts.map +1 -0
- package/dist/services/plugin-tools.d.ts +16 -0
- package/dist/services/plugin-tools.d.ts.map +1 -0
- package/dist/{providers → services/providers}/local-provider-registry.d.ts +4 -4
- package/dist/services/providers/local-provider-registry.d.ts.map +1 -0
- package/dist/{providers → services/providers}/local-provider-service.d.ts +13 -13
- package/dist/services/providers/local-provider-service.d.ts.map +1 -0
- package/dist/{session → services}/session-artifacts.d.ts +0 -4
- package/dist/services/session-artifacts.d.ts.map +1 -0
- package/dist/{session/utils/helpers.d.ts → services/session-data.d.ts} +19 -27
- package/dist/services/session-data.d.ts.map +1 -0
- package/dist/{session → services}/session-telemetry.d.ts +2 -2
- package/dist/services/session-telemetry.d.ts.map +1 -0
- package/dist/{storage → services/storage}/file-team-store.d.ts +2 -2
- package/dist/services/storage/file-team-store.d.ts.map +1 -0
- package/dist/{storage → services/storage}/provider-settings-legacy-migration.d.ts +1 -1
- package/dist/services/storage/provider-settings-legacy-migration.d.ts.map +1 -0
- package/dist/{storage → services/storage}/provider-settings-manager.d.ts +1 -1
- package/dist/services/storage/provider-settings-manager.d.ts.map +1 -0
- package/dist/{storage → services/storage}/sqlite-session-store.d.ts +3 -3
- package/dist/services/storage/sqlite-session-store.d.ts.map +1 -0
- package/dist/{storage → services/storage}/sqlite-team-store.d.ts +2 -2
- package/dist/services/storage/sqlite-team-store.d.ts.map +1 -0
- package/dist/{storage → services/storage}/team-store.d.ts +1 -1
- package/dist/services/storage/team-store.d.ts.map +1 -0
- package/dist/services/telemetry/ITelemetryAdapter.d.ts.map +1 -0
- package/dist/services/telemetry/OpenTelemetryAdapter.d.ts.map +1 -0
- package/dist/services/telemetry/OpenTelemetryProvider.d.ts.map +1 -0
- package/dist/services/telemetry/TelemetryLoggerSink.d.ts.map +1 -0
- package/dist/services/telemetry/TelemetryService.d.ts.map +1 -0
- package/dist/services/telemetry/core-events.d.ts.map +1 -0
- package/dist/services/telemetry/distinct-id.d.ts.map +1 -0
- package/dist/services/telemetry/index.d.ts.map +1 -0
- package/dist/services/telemetry/index.js +28 -0
- package/dist/{session/utils → services}/usage.d.ts +1 -1
- package/dist/services/usage.d.ts.map +1 -0
- package/dist/services/workspace/file-indexer.d.ts.map +1 -0
- package/dist/services/workspace/index.d.ts.map +1 -0
- package/dist/services/workspace/mention-enricher.d.ts.map +1 -0
- package/dist/services/workspace-manifest.d.ts +16 -0
- package/dist/services/workspace-manifest.d.ts.map +1 -0
- package/dist/session/file-session-service.d.ts +4 -1
- package/dist/session/file-session-service.d.ts.map +1 -1
- package/dist/session/persistence-service.d.ts +15 -25
- 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-row.d.ts +93 -0
- package/dist/session/session-row.d.ts.map +1 -0
- package/dist/session/session-service.d.ts +8 -109
- package/dist/session/session-service.d.ts.map +1 -1
- package/dist/session/session-team-coordination.d.ts +4 -4
- package/dist/session/session-team-coordination.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 +47 -0
- package/dist/transports/hub.d.ts.map +1 -0
- package/dist/{session/default-session-manager.d.ts → transports/local.d.ts} +30 -16
- package/dist/transports/local.d.ts.map +1 -0
- 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 +22 -0
- package/dist/transports/runtime-host-support.d.ts.map +1 -0
- package/dist/{chat → types}/chat-schema.d.ts +10 -12
- package/dist/types/chat-schema.d.ts.map +1 -0
- package/dist/types/config.d.ts +10 -9
- package/dist/types/config.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/{session/utils/types.d.ts → types/session.d.ts} +16 -6
- package/dist/types/session.d.ts.map +1 -0
- package/dist/types/sessions.d.ts +19 -0
- package/dist/types/sessions.d.ts.map +1 -1
- package/dist/types/storage.d.ts +1 -3
- package/dist/types/storage.d.ts.map +1 -1
- package/dist/types.d.ts +14 -6
- package/dist/types.d.ts.map +1 -1
- package/package.json +22 -13
- package/src/ClineCore.ts +183 -85
- package/src/account/index.ts +3 -3
- package/src/account/rpc.ts +12 -12
- package/src/auth/cline.ts +1 -1
- package/src/auth/codex.ts +1 -1
- package/src/auth/oca.ts +1 -1
- package/src/cron/index.ts +5 -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 +637 -0
- package/src/cron/sqlite-schedule-store.ts +708 -0
- package/src/extensions/config/agent-config-loader.ts +18 -12
- package/src/extensions/config/agent-config-parser.ts +1 -1
- package/src/extensions/config/hooks-config-loader.ts +1 -2
- package/src/extensions/config/index.ts +0 -4
- package/src/extensions/config/runtime-commands.ts +6 -0
- package/src/extensions/config/user-instruction-config-loader.ts +1 -4
- 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 +17 -2
- package/src/extensions/plugin/plugin-loader.ts +48 -4
- package/src/extensions/plugin/plugin-module-import.ts +0 -2
- package/src/extensions/plugin/plugin-sandbox-bootstrap.ts +93 -39
- package/src/extensions/plugin/plugin-sandbox.ts +47 -27
- package/src/extensions/plugin/plugin-targeting.ts +32 -0
- package/src/{tools → extensions/tools}/definitions.ts +31 -50
- package/src/{tools → extensions/tools}/executors/apply-patch.ts +69 -80
- package/src/{tools → extensions/tools}/executors/file-read.ts +29 -4
- package/src/{tools → extensions/tools}/executors/search.ts +196 -4
- package/src/{tools → extensions/tools}/index.ts +10 -0
- package/src/{tools → extensions/tools}/model-tool-routing.ts +1 -1
- package/src/{tools → extensions/tools}/presets.ts +31 -47
- package/src/extensions/tools/runtime.ts +261 -0
- package/src/{tools → extensions/tools}/schemas.ts +4 -2
- package/src/{team → extensions/tools/team}/multi-agent.ts +80 -17
- package/src/{team → extensions/tools/team}/spawn-agent-tool.ts +1 -7
- package/src/{team → extensions/tools/team}/subagent-prompts.ts +2 -2
- package/src/{team → extensions/tools/team}/team-tools.ts +84 -53
- package/src/{tools → extensions/tools}/types.ts +5 -3
- package/src/{runtime → hooks}/checkpoint-hooks.ts +27 -0
- package/src/{runtime → hooks}/hook-file-hooks.ts +14 -13
- package/src/hooks/index.ts +0 -7
- package/src/hooks/subprocess-runner.ts +1 -1
- package/src/hooks/subprocess.ts +57 -257
- package/src/hub/browser-websocket.ts +137 -0
- package/src/hub/client.ts +574 -0
- package/src/hub/connect.ts +156 -0
- package/src/hub/daemon-entry.ts +87 -0
- package/src/hub/daemon.ts +181 -0
- package/src/hub/defaults.ts +43 -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 +140 -0
- package/src/hub/server.ts +1888 -0
- package/src/hub/session-client.ts +460 -0
- package/src/hub/start-shared-server.ts +58 -0
- package/src/hub/transport.ts +14 -0
- package/src/hub/ui-client.ts +122 -0
- package/src/hub/workspace.ts +19 -0
- package/src/index.ts +264 -199
- package/src/llms/configured-provider-registry.ts +193 -0
- package/src/llms/provider-defaults.ts +637 -0
- package/src/llms/provider-settings.ts +263 -0
- package/src/llms/runtime-config.ts +43 -0
- package/src/llms/runtime-registry.ts +171 -0
- package/src/llms/runtime-types.ts +121 -0
- package/src/runtime/history.ts +237 -0
- package/src/runtime/host.ts +200 -0
- package/src/runtime/index.ts +1 -0
- package/src/runtime/rules.ts +12 -0
- package/src/runtime/runtime-builder.ts +37 -29
- package/src/runtime/runtime-host.ts +206 -0
- package/src/{session → runtime}/runtime-oauth-token-manager.ts +12 -16
- package/src/runtime/session-runtime.ts +2 -26
- package/src/{session/session-agent-events.ts → services/agent-events.ts} +7 -7
- package/src/services/config.ts +5 -0
- package/src/services/global-settings.ts +122 -0
- package/src/services/local-runtime-bootstrap.ts +318 -0
- package/src/services/plugin-tools.ts +85 -0
- package/src/{providers → services/providers}/local-provider-registry.ts +6 -6
- package/src/{providers → services/providers}/local-provider-service.ts +46 -41
- package/src/{session → services}/session-artifacts.ts +7 -19
- package/src/{session/utils/helpers.ts → services/session-data.ts} +90 -80
- package/src/{session → services}/session-telemetry.ts +7 -9
- package/src/services/storage/artifact-store.ts +1 -0
- package/src/{storage → services/storage}/file-team-store.ts +2 -2
- package/src/{storage → services/storage}/provider-settings-legacy-migration.ts +6 -4
- package/src/{storage → services/storage}/provider-settings-manager.ts +3 -3
- package/src/services/storage/session-store.ts +1 -0
- package/src/{storage → services/storage}/sqlite-session-store.ts +7 -12
- package/src/{storage → services/storage}/sqlite-team-store.ts +4 -4
- package/src/{storage → services/storage}/team-store.ts +1 -1
- package/src/{session/utils → services}/usage.ts +1 -1
- package/src/{input → services/workspace}/file-indexer.ts +26 -2
- package/src/{input → services/workspace}/mention-enricher.ts +1 -1
- package/src/{session → services}/workspace-manifest.ts +18 -0
- package/src/session/file-session-service.ts +10 -8
- package/src/session/index.ts +10 -23
- package/src/session/persistence-service.ts +144 -528
- package/src/session/session-manifest-store.ts +158 -0
- package/src/session/session-row.ts +199 -0
- package/src/session/session-service.ts +43 -389
- package/src/session/session-team-coordination.ts +14 -7
- package/src/session/subagent-session-manager.ts +397 -0
- package/src/session/team-persistence-store.ts +176 -0
- package/src/session/workspace-manager.ts +1 -1
- package/src/transports/hub.ts +656 -0
- package/src/{session/default-session-manager.ts → transports/local.ts} +263 -200
- package/src/transports/remote.ts +26 -0
- package/src/transports/runtime-host-support.ts +140 -0
- package/src/{chat → types}/chat-schema.ts +4 -5
- package/src/types/config.ts +10 -9
- package/src/types/provider-settings.ts +11 -7
- package/src/{session/utils/types.ts → types/session.ts} +16 -5
- package/src/types/sessions.ts +21 -0
- package/src/types/storage.ts +1 -6
- package/src/types.ts +52 -19
- package/dist/chat/chat-schema.d.ts.map +0 -1
- package/dist/hooks/persistent.d.ts +0 -64
- package/dist/hooks/persistent.d.ts.map +0 -1
- package/dist/input/file-indexer.d.ts.map +0 -1
- package/dist/input/index.d.ts.map +0 -1
- package/dist/input/mention-enricher.d.ts.map +0 -1
- package/dist/prompt/default-system.d.ts +0 -2
- package/dist/prompt/default-system.d.ts.map +0 -1
- package/dist/providers/local-provider-registry.d.ts.map +0 -1
- package/dist/providers/local-provider-service.d.ts.map +0 -1
- package/dist/runtime/checkpoint-hooks.d.ts.map +0 -1
- package/dist/runtime/hook-file-hooks.d.ts.map +0 -1
- package/dist/session/default-session-manager.d.ts.map +0 -1
- package/dist/session/rpc-runtime-ensure.d.ts +0 -53
- package/dist/session/rpc-runtime-ensure.d.ts.map +0 -1
- package/dist/session/rpc-session-service.d.ts +0 -13
- package/dist/session/rpc-session-service.d.ts.map +0 -1
- package/dist/session/rpc-spawn-lease.d.ts +0 -8
- package/dist/session/rpc-spawn-lease.d.ts.map +0 -1
- package/dist/session/session-agent-events.d.ts.map +0 -1
- package/dist/session/session-artifacts.d.ts.map +0 -1
- package/dist/session/session-config-builder.d.ts +0 -16
- package/dist/session/session-config-builder.d.ts.map +0 -1
- package/dist/session/session-host.d.ts +0 -15
- package/dist/session/session-host.d.ts.map +0 -1
- package/dist/session/session-manager.d.ts +0 -62
- package/dist/session/session-manager.d.ts.map +0 -1
- package/dist/session/session-telemetry.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/session/utils/helpers.d.ts.map +0 -1
- package/dist/session/utils/types.d.ts.map +0 -1
- package/dist/session/utils/usage.d.ts.map +0 -1
- package/dist/session/workspace-manifest.d.ts +0 -5
- package/dist/session/workspace-manifest.d.ts.map +0 -1
- package/dist/storage/file-team-store.d.ts.map +0 -1
- package/dist/storage/provider-settings-legacy-migration.d.ts.map +0 -1
- package/dist/storage/provider-settings-manager.d.ts.map +0 -1
- package/dist/storage/sqlite-session-store.d.ts.map +0 -1
- package/dist/storage/sqlite-team-store.d.ts.map +0 -1
- package/dist/storage/team-store.d.ts.map +0 -1
- package/dist/team/delegated-agent.d.ts.map +0 -1
- package/dist/team/index.d.ts.map +0 -1
- package/dist/team/multi-agent.d.ts.map +0 -1
- package/dist/team/projections.d.ts.map +0 -1
- package/dist/team/runtime.d.ts.map +0 -1
- package/dist/team/spawn-agent-tool.d.ts.map +0 -1
- package/dist/team/subagent-prompts.d.ts.map +0 -1
- package/dist/team/team-tools.d.ts.map +0 -1
- package/dist/telemetry/ITelemetryAdapter.d.ts.map +0 -1
- package/dist/telemetry/OpenTelemetryAdapter.d.ts.map +0 -1
- package/dist/telemetry/OpenTelemetryProvider.d.ts.map +0 -1
- package/dist/telemetry/TelemetryLoggerSink.d.ts.map +0 -1
- package/dist/telemetry/TelemetryService.d.ts.map +0 -1
- package/dist/telemetry/core-events.d.ts.map +0 -1
- package/dist/telemetry/distinct-id.d.ts.map +0 -1
- package/dist/telemetry/index.d.ts.map +0 -1
- package/dist/telemetry/index.js +0 -15
- package/dist/tools/constants.d.ts.map +0 -1
- package/dist/tools/definitions.d.ts.map +0 -1
- package/dist/tools/executors/apply-patch-parser.d.ts.map +0 -1
- package/dist/tools/executors/apply-patch.d.ts.map +0 -1
- package/dist/tools/executors/bash.d.ts.map +0 -1
- package/dist/tools/executors/editor.d.ts.map +0 -1
- package/dist/tools/executors/file-read.d.ts.map +0 -1
- package/dist/tools/executors/index.d.ts.map +0 -1
- package/dist/tools/executors/search.d.ts.map +0 -1
- package/dist/tools/executors/web-fetch.d.ts.map +0 -1
- package/dist/tools/helpers.d.ts.map +0 -1
- package/dist/tools/index.d.ts.map +0 -1
- package/dist/tools/model-tool-routing.d.ts.map +0 -1
- package/dist/tools/presets.d.ts.map +0 -1
- package/dist/tools/schemas.d.ts.map +0 -1
- package/dist/tools/types.d.ts.map +0 -1
- package/src/ClineCore.test.ts +0 -150
- 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 -182
- package/src/extensions/plugin/plugin-loader.test.ts +0 -292
- package/src/extensions/plugin/plugin-sandbox.test.ts +0 -423
- package/src/hooks/persistent.ts +0 -661
- package/src/input/file-indexer.d.ts +0 -11
- package/src/input/file-indexer.test.ts +0 -127
- package/src/input/mention-enricher.test.ts +0 -85
- package/src/prompt/default-system.ts +0 -21
- package/src/providers/local-provider-service.test.ts +0 -1062
- package/src/runtime/checkpoint-hooks.test.ts +0 -168
- package/src/runtime/hook-file-hooks.test.ts +0 -311
- package/src/runtime/runtime-builder.team-persistence.test.ts +0 -242
- package/src/runtime/runtime-builder.test.ts +0 -616
- package/src/runtime/runtime-parity.test.ts +0 -143
- package/src/session/default-session-manager.e2e.test.ts +0 -384
- package/src/session/default-session-manager.test.ts +0 -2473
- package/src/session/persistence-service.test.ts +0 -241
- package/src/session/rpc-runtime-ensure.ts +0 -521
- package/src/session/rpc-session-service.ts +0 -107
- package/src/session/rpc-spawn-lease.test.ts +0 -49
- package/src/session/rpc-spawn-lease.ts +0 -122
- package/src/session/runtime-oauth-token-manager.test.ts +0 -137
- package/src/session/session-config-builder.ts +0 -172
- package/src/session/session-host.test.ts +0 -89
- package/src/session/session-host.ts +0 -213
- package/src/session/session-manager.ts +0 -74
- package/src/session/session-service.team-persistence.test.ts +0 -48
- package/src/session/sqlite-rpc-session-backend.ts +0 -303
- package/src/session/utils/helpers.test.ts +0 -160
- package/src/storage/artifact-store.ts +0 -1
- package/src/storage/provider-settings-legacy-migration.test.ts +0 -424
- package/src/storage/provider-settings-manager.test.ts +0 -191
- package/src/storage/session-store.ts +0 -1
- package/src/team/multi-agent.lifecycle.test.ts +0 -201
- package/src/team/spawn-agent-tool.test.ts +0 -387
- package/src/team/team-tools.test.ts +0 -906
- package/src/telemetry/OpenTelemetryAdapter.test.ts +0 -157
- package/src/telemetry/OpenTelemetryProvider.test.ts +0 -326
- package/src/telemetry/TelemetryLoggerSink.test.ts +0 -42
- package/src/telemetry/TelemetryService.test.ts +0 -134
- package/src/telemetry/distinct-id.test.ts +0 -57
- package/src/tools/definitions.test.ts +0 -780
- package/src/tools/executors/bash.test.ts +0 -87
- package/src/tools/executors/editor.test.ts +0 -35
- package/src/tools/executors/file-read.test.ts +0 -49
- package/src/tools/model-tool-routing.test.ts +0 -86
- package/src/tools/presets.test.ts +0 -70
- /package/dist/{tools → extensions/tools}/constants.d.ts +0 -0
- /package/dist/{tools → extensions/tools}/executors/apply-patch-parser.d.ts +0 -0
- /package/dist/{tools → extensions/tools}/executors/bash.d.ts +0 -0
- /package/dist/{tools → extensions/tools}/executors/editor.d.ts +0 -0
- /package/dist/{tools → extensions/tools}/executors/file-read.d.ts +0 -0
- /package/dist/{tools → extensions/tools}/executors/index.d.ts +0 -0
- /package/dist/{tools → extensions/tools}/executors/web-fetch.d.ts +0 -0
- /package/dist/{tools → extensions/tools}/helpers.d.ts +0 -0
- /package/dist/{tools → extensions/tools}/schemas.d.ts +0 -0
- /package/dist/{team → extensions/tools/team}/delegated-agent.d.ts +0 -0
- /package/dist/{team → extensions/tools/team}/index.d.ts +0 -0
- /package/dist/{team → extensions/tools/team}/projections.d.ts +0 -0
- /package/dist/{team → extensions/tools/team}/runtime.d.ts +0 -0
- /package/dist/{team → extensions/tools/team}/subagent-prompts.d.ts +0 -0
- /package/dist/{telemetry → services/telemetry}/ITelemetryAdapter.d.ts +0 -0
- /package/dist/{telemetry → services/telemetry}/OpenTelemetryAdapter.d.ts +0 -0
- /package/dist/{telemetry → services/telemetry}/OpenTelemetryProvider.d.ts +0 -0
- /package/dist/{telemetry → services/telemetry}/TelemetryLoggerSink.d.ts +0 -0
- /package/dist/{telemetry → services/telemetry}/TelemetryService.d.ts +0 -0
- /package/dist/{telemetry → services/telemetry}/core-events.d.ts +0 -0
- /package/dist/{telemetry → services/telemetry}/distinct-id.d.ts +0 -0
- /package/dist/{telemetry → services/telemetry}/index.d.ts +0 -0
- /package/dist/{input → services/workspace}/file-indexer.d.ts +0 -0
- /package/dist/{input → services/workspace}/index.d.ts +0 -0
- /package/dist/{input → services/workspace}/mention-enricher.d.ts +0 -0
- /package/src/{tools → extensions/tools}/constants.ts +0 -0
- /package/src/{tools → extensions/tools}/executors/apply-patch-parser.ts +0 -0
- /package/src/{tools → extensions/tools}/executors/bash.ts +0 -0
- /package/src/{tools → extensions/tools}/executors/editor.ts +0 -0
- /package/src/{tools → extensions/tools}/executors/index.ts +0 -0
- /package/src/{tools → extensions/tools}/executors/web-fetch.ts +0 -0
- /package/src/{tools → extensions/tools}/helpers.ts +0 -0
- /package/src/{team → extensions/tools/team}/delegated-agent.ts +0 -0
- /package/src/{team → extensions/tools/team}/index.ts +0 -0
- /package/src/{team → extensions/tools/team}/projections.ts +0 -0
- /package/src/{team → extensions/tools/team}/runtime.ts +0 -0
- /package/src/{storage → services/storage}/index.ts +0 -0
- /package/src/{telemetry → services/telemetry}/ITelemetryAdapter.ts +0 -0
- /package/src/{telemetry → services/telemetry}/OpenTelemetryAdapter.ts +0 -0
- /package/src/{telemetry → services/telemetry}/OpenTelemetryProvider.ts +0 -0
- /package/src/{telemetry → services/telemetry}/TelemetryLoggerSink.ts +0 -0
- /package/src/{telemetry → services/telemetry}/TelemetryService.ts +0 -0
- /package/src/{telemetry → services/telemetry}/core-events.ts +0 -0
- /package/src/{telemetry → services/telemetry}/distinct-id.ts +0 -0
- /package/src/{telemetry → services/telemetry}/index.ts +0 -0
- /package/src/{input → services/workspace}/index.ts +0 -0
|
@@ -1,521 +0,0 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
|
-
import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
3
|
-
import { createServer } from "node:net";
|
|
4
|
-
import { dirname, join, resolve } from "node:path";
|
|
5
|
-
import {
|
|
6
|
-
getRpcServerHealth,
|
|
7
|
-
RPC_BUILD_VERSION,
|
|
8
|
-
RPC_PROTOCOL_VERSION,
|
|
9
|
-
RpcSessionClient,
|
|
10
|
-
requestRpcServerShutdown,
|
|
11
|
-
} from "@clinebot/rpc";
|
|
12
|
-
import { resolveClineDataDir } from "@clinebot/shared/storage";
|
|
13
|
-
import { CORE_BUILD_VERSION } from "../version";
|
|
14
|
-
|
|
15
|
-
const RPC_STARTUP_LOCK_MAX_AGE_MS = 30_000;
|
|
16
|
-
const RPC_STARTUP_LOCK_WAIT_MS = 15_000;
|
|
17
|
-
const RPC_STARTUP_LOCK_POLL_MS = 100;
|
|
18
|
-
export const RPC_STARTUP_LOCK_BYPASS_ENV = "CLINE_RPC_STARTUP_LOCK_HELD";
|
|
19
|
-
export const RPC_OWNER_ID_ENV = "CLINE_RPC_OWNER_ID";
|
|
20
|
-
export const RPC_BUILD_ID_ENV = "CLINE_RPC_BUILD_ID";
|
|
21
|
-
export const RPC_DISCOVERY_PATH_ENV = "CLINE_RPC_DISCOVERY_PATH";
|
|
22
|
-
|
|
23
|
-
type RpcStartupLockRecord = {
|
|
24
|
-
pid: number;
|
|
25
|
-
address: string;
|
|
26
|
-
acquiredAt: string;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export type RpcDiscoveryRecord = {
|
|
30
|
-
ownerId: string;
|
|
31
|
-
buildId: string;
|
|
32
|
-
entryPath?: string;
|
|
33
|
-
address: string;
|
|
34
|
-
pid?: number;
|
|
35
|
-
serverId?: string;
|
|
36
|
-
startedAt?: string;
|
|
37
|
-
protocolVersion: string;
|
|
38
|
-
updatedAt: string;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export type RpcOwnerContext = {
|
|
42
|
-
ownerId: string;
|
|
43
|
-
buildId: string;
|
|
44
|
-
entryPath?: string;
|
|
45
|
-
discoveryPath: string;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
export type ResolveRpcRuntimeResult = {
|
|
49
|
-
address: string;
|
|
50
|
-
action: "reuse" | "new-port" | "started";
|
|
51
|
-
owner: RpcOwnerContext;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
export type EnsureRpcRuntimeOptions = {
|
|
55
|
-
owner?: RpcOwnerContext;
|
|
56
|
-
resolveOwner?: () => RpcOwnerContext;
|
|
57
|
-
spawnIfNeeded: (
|
|
58
|
-
address: string,
|
|
59
|
-
owner: RpcOwnerContext,
|
|
60
|
-
) => void | Promise<void>;
|
|
61
|
-
readinessCheck?: (address: string) => Promise<boolean>;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
export type ResolveRpcOwnerContextOptions = {
|
|
65
|
-
discoveryPath?: string;
|
|
66
|
-
hostBuildKey?: string;
|
|
67
|
-
identityPath?: string;
|
|
68
|
-
ownerBasis?: string;
|
|
69
|
-
ownerId?: string;
|
|
70
|
-
ownerPrefix?: string;
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
const sleep = (ms: number) => new Promise<void>((r) => setTimeout(r, ms));
|
|
74
|
-
|
|
75
|
-
function sanitizeKey(value: string): string {
|
|
76
|
-
return value.replace(/[^a-zA-Z0-9_.-]+/g, "_");
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function hashValue(value: string): string {
|
|
80
|
-
return createHash("sha256").update(value).digest("hex").slice(0, 12);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function errorCode(error: unknown): string {
|
|
84
|
-
return error && typeof error === "object" && "code" in error
|
|
85
|
-
? String((error as { code?: unknown }).code)
|
|
86
|
-
: "";
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function parseRpcAddress(address: string): { host: string; port: number } {
|
|
90
|
-
const trimmed = address.trim();
|
|
91
|
-
const idx = trimmed.lastIndexOf(":");
|
|
92
|
-
if (idx <= 0 || idx >= trimmed.length - 1) {
|
|
93
|
-
throw new Error(`invalid rpc address: ${address}`);
|
|
94
|
-
}
|
|
95
|
-
const host = trimmed.slice(0, idx);
|
|
96
|
-
const port = Number.parseInt(trimmed.slice(idx + 1), 10);
|
|
97
|
-
if (!Number.isInteger(port) || port <= 0 || port > 65535) {
|
|
98
|
-
throw new Error(`invalid rpc port in address: ${address}`);
|
|
99
|
-
}
|
|
100
|
-
return { host, port };
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
function defaultIdentityPath(): string | undefined {
|
|
104
|
-
const entryArg = process.argv[1]?.trim();
|
|
105
|
-
if (!entryArg) return undefined;
|
|
106
|
-
return resolve(process.cwd(), entryArg);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export function resolveRpcRuntimeBuildKey(hostBuildKey?: string): string {
|
|
110
|
-
const base = `core=${CORE_BUILD_VERSION}:rpc=${RPC_BUILD_VERSION}`;
|
|
111
|
-
return hostBuildKey?.trim() ? `${base}:host=${hostBuildKey.trim()}` : base;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export function resolveRpcOwnerContext(
|
|
115
|
-
options: ResolveRpcOwnerContextOptions = {},
|
|
116
|
-
): RpcOwnerContext {
|
|
117
|
-
const entryPath = options.identityPath?.trim() || defaultIdentityPath();
|
|
118
|
-
const defaultOwnerBasis =
|
|
119
|
-
options.ownerBasis?.trim() ||
|
|
120
|
-
(entryPath ? `${entryPath}` : `pid:${process.pid}:cwd:${process.cwd()}`);
|
|
121
|
-
const ownerPrefix = options.ownerPrefix?.trim() || "rpc";
|
|
122
|
-
const ownerId =
|
|
123
|
-
options.ownerId?.trim() ||
|
|
124
|
-
process.env[RPC_OWNER_ID_ENV]?.trim() ||
|
|
125
|
-
`${ownerPrefix}-${hashValue(defaultOwnerBasis)}`;
|
|
126
|
-
const defaultBuildBasis = `${defaultOwnerBasis}:${resolveRpcRuntimeBuildKey(options.hostBuildKey)}`;
|
|
127
|
-
const buildId =
|
|
128
|
-
process.env[RPC_BUILD_ID_ENV]?.trim() ||
|
|
129
|
-
`build-${hashValue(defaultBuildBasis)}`;
|
|
130
|
-
const discoveryPath =
|
|
131
|
-
options.discoveryPath?.trim() ||
|
|
132
|
-
process.env[RPC_DISCOVERY_PATH_ENV]?.trim() ||
|
|
133
|
-
join(
|
|
134
|
-
resolveClineDataDir(),
|
|
135
|
-
"rpc",
|
|
136
|
-
"owners",
|
|
137
|
-
`${sanitizeKey(ownerId)}.json`,
|
|
138
|
-
);
|
|
139
|
-
return { ownerId, buildId, entryPath, discoveryPath };
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
async function readRpcDiscovery(
|
|
143
|
-
owner: RpcOwnerContext,
|
|
144
|
-
): Promise<RpcDiscoveryRecord | undefined> {
|
|
145
|
-
try {
|
|
146
|
-
const parsed = JSON.parse(
|
|
147
|
-
await readFile(owner.discoveryPath, "utf8"),
|
|
148
|
-
) as Partial<RpcDiscoveryRecord>;
|
|
149
|
-
if (
|
|
150
|
-
typeof parsed.ownerId !== "string" ||
|
|
151
|
-
typeof parsed.buildId !== "string" ||
|
|
152
|
-
typeof parsed.address !== "string" ||
|
|
153
|
-
typeof parsed.protocolVersion !== "string"
|
|
154
|
-
) {
|
|
155
|
-
return undefined;
|
|
156
|
-
}
|
|
157
|
-
return {
|
|
158
|
-
ownerId: parsed.ownerId,
|
|
159
|
-
buildId: parsed.buildId,
|
|
160
|
-
address: parsed.address,
|
|
161
|
-
protocolVersion: parsed.protocolVersion,
|
|
162
|
-
updatedAt:
|
|
163
|
-
typeof parsed.updatedAt === "string"
|
|
164
|
-
? parsed.updatedAt
|
|
165
|
-
: new Date().toISOString(),
|
|
166
|
-
entryPath:
|
|
167
|
-
typeof parsed.entryPath === "string" ? parsed.entryPath : undefined,
|
|
168
|
-
pid: typeof parsed.pid === "number" ? parsed.pid : undefined,
|
|
169
|
-
serverId:
|
|
170
|
-
typeof parsed.serverId === "string" ? parsed.serverId : undefined,
|
|
171
|
-
startedAt:
|
|
172
|
-
typeof parsed.startedAt === "string" ? parsed.startedAt : undefined,
|
|
173
|
-
};
|
|
174
|
-
} catch {
|
|
175
|
-
return undefined;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
export async function recordRpcDiscovery(
|
|
180
|
-
owner: RpcOwnerContext,
|
|
181
|
-
record: Omit<RpcDiscoveryRecord, "ownerId" | "buildId" | "updatedAt">,
|
|
182
|
-
): Promise<void> {
|
|
183
|
-
await mkdir(dirname(owner.discoveryPath), { recursive: true });
|
|
184
|
-
await writeFile(
|
|
185
|
-
owner.discoveryPath,
|
|
186
|
-
JSON.stringify(
|
|
187
|
-
{
|
|
188
|
-
ownerId: owner.ownerId,
|
|
189
|
-
buildId: owner.buildId,
|
|
190
|
-
updatedAt: new Date().toISOString(),
|
|
191
|
-
...record,
|
|
192
|
-
} satisfies RpcDiscoveryRecord,
|
|
193
|
-
null,
|
|
194
|
-
2,
|
|
195
|
-
),
|
|
196
|
-
"utf8",
|
|
197
|
-
);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
async function clearRpcDiscovery(owner: RpcOwnerContext): Promise<void> {
|
|
201
|
-
await rm(owner.discoveryPath, { force: true }).catch(() => undefined);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
export async function clearRpcDiscoveryIfAddressMatches(
|
|
205
|
-
owner: RpcOwnerContext,
|
|
206
|
-
address: string,
|
|
207
|
-
): Promise<void> {
|
|
208
|
-
const current = await readRpcDiscovery(owner);
|
|
209
|
-
if (current?.address === address) await clearRpcDiscovery(owner);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
function isHealthCompatible(
|
|
213
|
-
health: Awaited<ReturnType<typeof getRpcServerHealth>> | undefined,
|
|
214
|
-
): boolean {
|
|
215
|
-
const serverVersion = health?.rpcVersion?.trim() || "";
|
|
216
|
-
return !!serverVersion && serverVersion === RPC_PROTOCOL_VERSION;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
function isUnimplementedError(error: unknown): boolean {
|
|
220
|
-
if (Number(errorCode(error)) === 12) return true;
|
|
221
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
222
|
-
return message.toUpperCase().includes("UNIMPLEMENTED");
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
function isAuthenticationError(error: unknown): boolean {
|
|
226
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
227
|
-
return /missing authentication header|401\b|unauthenticated|unauthorized/i.test(
|
|
228
|
-
message,
|
|
229
|
-
);
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
function isProbeBlocked(error: unknown): boolean {
|
|
233
|
-
return isUnimplementedError(error) || isAuthenticationError(error);
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
async function hasRuntimeMethods(address: string): Promise<boolean> {
|
|
237
|
-
const client = new RpcSessionClient({ address });
|
|
238
|
-
try {
|
|
239
|
-
try {
|
|
240
|
-
await client.stopRuntimeSession("__rpc_probe__");
|
|
241
|
-
} catch (error) {
|
|
242
|
-
if (isProbeBlocked(error)) return false;
|
|
243
|
-
}
|
|
244
|
-
return true;
|
|
245
|
-
} catch (error) {
|
|
246
|
-
return !isProbeBlocked(error);
|
|
247
|
-
} finally {
|
|
248
|
-
client.close();
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
export async function isCompatibleRuntime(address: string): Promise<boolean> {
|
|
253
|
-
const health = await getRpcServerHealth(address);
|
|
254
|
-
return (
|
|
255
|
-
!!health?.running &&
|
|
256
|
-
isHealthCompatible(health) &&
|
|
257
|
-
(await hasRuntimeMethods(address))
|
|
258
|
-
);
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
async function isPortFree(host: string, port: number): Promise<boolean> {
|
|
262
|
-
return new Promise<boolean>((resolve) => {
|
|
263
|
-
const server = createServer();
|
|
264
|
-
server.once("error", () => resolve(false));
|
|
265
|
-
server.once("listening", () => server.close(() => resolve(true)));
|
|
266
|
-
server.listen({ host, port });
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
async function findAvailableAddress(baseAddress: string): Promise<string> {
|
|
271
|
-
const { host, port } = parseRpcAddress(baseAddress);
|
|
272
|
-
for (let offset = 1; offset <= 40; offset += 1) {
|
|
273
|
-
const candidate = port + offset;
|
|
274
|
-
if (candidate > 65535) break;
|
|
275
|
-
if (await isPortFree(host, candidate)) return `${host}:${candidate}`;
|
|
276
|
-
}
|
|
277
|
-
throw new Error(`no available rpc port near ${baseAddress}`);
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
function getRpcStartupLockDir(address: string): string {
|
|
281
|
-
const normalized = address.trim().replace(/[^a-zA-Z0-9_.-]+/g, "_");
|
|
282
|
-
return join(resolveClineDataDir(), "locks", `rpc-start-${normalized}.lock`);
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
function isPidAlive(pid: number | undefined): boolean {
|
|
286
|
-
if (!Number.isInteger(pid) || !pid || pid <= 0) return false;
|
|
287
|
-
try {
|
|
288
|
-
process.kill(pid, 0);
|
|
289
|
-
return true;
|
|
290
|
-
} catch (error) {
|
|
291
|
-
return errorCode(error) === "EPERM";
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
async function writeRpcStartupLockRecord(
|
|
296
|
-
lockDir: string,
|
|
297
|
-
address: string,
|
|
298
|
-
): Promise<void> {
|
|
299
|
-
const record: RpcStartupLockRecord = {
|
|
300
|
-
pid: process.pid,
|
|
301
|
-
address,
|
|
302
|
-
acquiredAt: new Date().toISOString(),
|
|
303
|
-
};
|
|
304
|
-
await writeFile(
|
|
305
|
-
join(lockDir, "owner.json"),
|
|
306
|
-
JSON.stringify(record, null, 2),
|
|
307
|
-
"utf8",
|
|
308
|
-
);
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
async function readRpcStartupLockRecord(
|
|
312
|
-
lockDir: string,
|
|
313
|
-
): Promise<RpcStartupLockRecord | undefined> {
|
|
314
|
-
try {
|
|
315
|
-
const parsed = JSON.parse(
|
|
316
|
-
await readFile(join(lockDir, "owner.json"), "utf8"),
|
|
317
|
-
) as Partial<RpcStartupLockRecord>;
|
|
318
|
-
if (
|
|
319
|
-
typeof parsed.pid !== "number" ||
|
|
320
|
-
typeof parsed.address !== "string" ||
|
|
321
|
-
typeof parsed.acquiredAt !== "string"
|
|
322
|
-
) {
|
|
323
|
-
return undefined;
|
|
324
|
-
}
|
|
325
|
-
return {
|
|
326
|
-
pid: parsed.pid,
|
|
327
|
-
address: parsed.address,
|
|
328
|
-
acquiredAt: parsed.acquiredAt,
|
|
329
|
-
};
|
|
330
|
-
} catch {
|
|
331
|
-
return undefined;
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
async function removeRpcStartupLockDir(lockDir: string): Promise<void> {
|
|
336
|
-
await rm(lockDir, { recursive: true, force: true }).catch(() => {});
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
export async function withRpcStartupLock<T>(
|
|
340
|
-
address: string,
|
|
341
|
-
action: () => Promise<T>,
|
|
342
|
-
): Promise<T> {
|
|
343
|
-
if (process.env[RPC_STARTUP_LOCK_BYPASS_ENV] === "1") {
|
|
344
|
-
return await action();
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
const lockDir = getRpcStartupLockDir(address);
|
|
348
|
-
const startedAt = Date.now();
|
|
349
|
-
await mkdir(dirname(lockDir), { recursive: true });
|
|
350
|
-
|
|
351
|
-
while (true) {
|
|
352
|
-
try {
|
|
353
|
-
await mkdir(lockDir, { recursive: false });
|
|
354
|
-
await writeRpcStartupLockRecord(lockDir, address);
|
|
355
|
-
try {
|
|
356
|
-
return await action();
|
|
357
|
-
} finally {
|
|
358
|
-
await removeRpcStartupLockDir(lockDir);
|
|
359
|
-
}
|
|
360
|
-
} catch (error) {
|
|
361
|
-
if (errorCode(error) !== "EEXIST") throw error;
|
|
362
|
-
|
|
363
|
-
const existing = await readRpcStartupLockRecord(lockDir);
|
|
364
|
-
const acquiredAtMs = existing
|
|
365
|
-
? new Date(existing.acquiredAt).getTime()
|
|
366
|
-
: Number.NaN;
|
|
367
|
-
const isStale =
|
|
368
|
-
!existing ||
|
|
369
|
-
!Number.isFinite(acquiredAtMs) ||
|
|
370
|
-
Date.now() - acquiredAtMs > RPC_STARTUP_LOCK_MAX_AGE_MS ||
|
|
371
|
-
!isPidAlive(existing.pid);
|
|
372
|
-
if (isStale) {
|
|
373
|
-
await removeRpcStartupLockDir(lockDir);
|
|
374
|
-
continue;
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
if (Date.now() - startedAt >= RPC_STARTUP_LOCK_WAIT_MS) {
|
|
378
|
-
throw new Error(
|
|
379
|
-
`timed out waiting for rpc startup lock at ${address} (owner pid=${existing.pid})`,
|
|
380
|
-
);
|
|
381
|
-
}
|
|
382
|
-
await sleep(RPC_STARTUP_LOCK_POLL_MS);
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
async function tryShutdownOwnedServer(
|
|
388
|
-
owner: RpcOwnerContext,
|
|
389
|
-
discovery: RpcDiscoveryRecord | undefined,
|
|
390
|
-
): Promise<void> {
|
|
391
|
-
const address = discovery?.address?.trim();
|
|
392
|
-
if (!address) {
|
|
393
|
-
await clearRpcDiscovery(owner);
|
|
394
|
-
return;
|
|
395
|
-
}
|
|
396
|
-
const shutdown = await requestRpcServerShutdown(address).catch(
|
|
397
|
-
() => undefined,
|
|
398
|
-
);
|
|
399
|
-
if (shutdown?.accepted) {
|
|
400
|
-
for (let i = 0; i < 20; i += 1) {
|
|
401
|
-
if (!(await getRpcServerHealth(address))?.running) {
|
|
402
|
-
await clearRpcDiscovery(owner);
|
|
403
|
-
return;
|
|
404
|
-
}
|
|
405
|
-
await sleep(100);
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
if (!(await getRpcServerHealth(address))?.running) {
|
|
409
|
-
await clearRpcDiscovery(owner);
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
export async function resolveEnsuredRpcRuntime(
|
|
414
|
-
requestedAddress: string,
|
|
415
|
-
options: {
|
|
416
|
-
owner?: RpcOwnerContext;
|
|
417
|
-
resolveOwner?: () => RpcOwnerContext;
|
|
418
|
-
} = {},
|
|
419
|
-
): Promise<ResolveRpcRuntimeResult> {
|
|
420
|
-
const owner =
|
|
421
|
-
options.owner ?? options.resolveOwner?.() ?? resolveRpcOwnerContext();
|
|
422
|
-
return await withRpcStartupLock(requestedAddress, async () => {
|
|
423
|
-
const discovery = await readRpcDiscovery(owner);
|
|
424
|
-
if (discovery?.address) {
|
|
425
|
-
const discoveredHealth = await getRpcServerHealth(discovery.address);
|
|
426
|
-
if (
|
|
427
|
-
discoveredHealth?.running &&
|
|
428
|
-
discovery.buildId === owner.buildId &&
|
|
429
|
-
discovery.protocolVersion === RPC_PROTOCOL_VERSION &&
|
|
430
|
-
isHealthCompatible(discoveredHealth) &&
|
|
431
|
-
(await hasRuntimeMethods(discovery.address))
|
|
432
|
-
) {
|
|
433
|
-
return {
|
|
434
|
-
address: discovery.address,
|
|
435
|
-
action: "reuse",
|
|
436
|
-
owner,
|
|
437
|
-
} satisfies ResolveRpcRuntimeResult;
|
|
438
|
-
}
|
|
439
|
-
await tryShutdownOwnedServer(owner, discovery);
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
const requestedHealth = await getRpcServerHealth(requestedAddress);
|
|
443
|
-
const { host, port } = parseRpcAddress(requestedAddress);
|
|
444
|
-
|
|
445
|
-
if (!requestedHealth?.running) {
|
|
446
|
-
if (await isPortFree(host, port)) {
|
|
447
|
-
return {
|
|
448
|
-
address: requestedAddress,
|
|
449
|
-
action: "started",
|
|
450
|
-
owner,
|
|
451
|
-
} satisfies ResolveRpcRuntimeResult;
|
|
452
|
-
}
|
|
453
|
-
return {
|
|
454
|
-
address: await findAvailableAddress(requestedAddress),
|
|
455
|
-
action: "new-port",
|
|
456
|
-
owner,
|
|
457
|
-
} satisfies ResolveRpcRuntimeResult;
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
if (
|
|
461
|
-
isHealthCompatible(requestedHealth) &&
|
|
462
|
-
(await hasRuntimeMethods(requestedAddress))
|
|
463
|
-
) {
|
|
464
|
-
if (!discovery) {
|
|
465
|
-
return {
|
|
466
|
-
address: requestedAddress,
|
|
467
|
-
action: "reuse",
|
|
468
|
-
owner,
|
|
469
|
-
} satisfies ResolveRpcRuntimeResult;
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
return {
|
|
474
|
-
address: await findAvailableAddress(requestedAddress),
|
|
475
|
-
action: "new-port",
|
|
476
|
-
owner,
|
|
477
|
-
} satisfies ResolveRpcRuntimeResult;
|
|
478
|
-
});
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
export async function waitForCompatibleRpcRuntime(
|
|
482
|
-
address: string,
|
|
483
|
-
readinessCheck: (address: string) => Promise<boolean> = isCompatibleRuntime,
|
|
484
|
-
): Promise<boolean> {
|
|
485
|
-
for (let attempt = 0; attempt < 60; attempt += 1) {
|
|
486
|
-
if (await readinessCheck(address)) return true;
|
|
487
|
-
await sleep(100);
|
|
488
|
-
}
|
|
489
|
-
return false;
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
export async function ensureRpcRuntimeAddress(
|
|
493
|
-
requestedAddress: string,
|
|
494
|
-
options: EnsureRpcRuntimeOptions,
|
|
495
|
-
): Promise<ResolveRpcRuntimeResult> {
|
|
496
|
-
const resolved = await resolveEnsuredRpcRuntime(requestedAddress, {
|
|
497
|
-
owner: options.owner,
|
|
498
|
-
resolveOwner: options.resolveOwner,
|
|
499
|
-
});
|
|
500
|
-
if (resolved.action !== "reuse") {
|
|
501
|
-
await options.spawnIfNeeded(resolved.address, resolved.owner);
|
|
502
|
-
}
|
|
503
|
-
if (
|
|
504
|
-
!(await waitForCompatibleRpcRuntime(
|
|
505
|
-
resolved.address,
|
|
506
|
-
options.readinessCheck,
|
|
507
|
-
))
|
|
508
|
-
) {
|
|
509
|
-
throw new Error(`failed to ensure rpc runtime at ${resolved.address}`);
|
|
510
|
-
}
|
|
511
|
-
const health = await getRpcServerHealth(resolved.address);
|
|
512
|
-
await recordRpcDiscovery(resolved.owner, {
|
|
513
|
-
address: resolved.address,
|
|
514
|
-
pid: undefined,
|
|
515
|
-
serverId: health?.serverId,
|
|
516
|
-
startedAt: health?.startedAt,
|
|
517
|
-
protocolVersion: RPC_PROTOCOL_VERSION,
|
|
518
|
-
entryPath: resolved.owner.entryPath,
|
|
519
|
-
});
|
|
520
|
-
return resolved;
|
|
521
|
-
}
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { existsSync, mkdirSync } from "node:fs";
|
|
2
|
-
import { RpcSessionClient, type RpcSessionRow } from "@clinebot/rpc";
|
|
3
|
-
import type {
|
|
4
|
-
PersistedSessionUpdateInput,
|
|
5
|
-
SessionPersistenceAdapter,
|
|
6
|
-
} from "./persistence-service";
|
|
7
|
-
import { UnifiedSessionPersistenceService } from "./persistence-service";
|
|
8
|
-
import type { SessionRow } from "./session-service";
|
|
9
|
-
|
|
10
|
-
// ── Adapter ──────────────────────────────────────────────────────────
|
|
11
|
-
|
|
12
|
-
class RpcSessionPersistenceAdapter implements SessionPersistenceAdapter {
|
|
13
|
-
constructor(private readonly client: RpcSessionClient) {}
|
|
14
|
-
|
|
15
|
-
ensureSessionsDir(): string {
|
|
16
|
-
return "";
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
async upsertSession(row: SessionRow): Promise<void> {
|
|
20
|
-
await this.client.upsertSession(row as RpcSessionRow);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
async getSession(sessionId: string): Promise<SessionRow | undefined> {
|
|
24
|
-
const row = await this.client.getSession(sessionId);
|
|
25
|
-
return (row as SessionRow | undefined) ?? undefined;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
async listSessions(options: {
|
|
29
|
-
limit: number;
|
|
30
|
-
parentSessionId?: string;
|
|
31
|
-
status?: string;
|
|
32
|
-
}): Promise<SessionRow[]> {
|
|
33
|
-
const rows = await this.client.listSessions(options);
|
|
34
|
-
return rows as SessionRow[];
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
async updateSession(
|
|
38
|
-
input: PersistedSessionUpdateInput,
|
|
39
|
-
): Promise<{ updated: boolean; statusLock: number }> {
|
|
40
|
-
return this.client.updateSession({
|
|
41
|
-
sessionId: input.sessionId,
|
|
42
|
-
status: input.status,
|
|
43
|
-
endedAt: input.endedAt,
|
|
44
|
-
exitCode: input.exitCode,
|
|
45
|
-
prompt: input.prompt,
|
|
46
|
-
metadata: input.metadata,
|
|
47
|
-
parentSessionId: input.parentSessionId,
|
|
48
|
-
parentAgentId: input.parentAgentId,
|
|
49
|
-
agentId: input.agentId,
|
|
50
|
-
conversationId: input.conversationId,
|
|
51
|
-
expectedStatusLock: input.expectedStatusLock,
|
|
52
|
-
setRunning: input.setRunning,
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
async deleteSession(sessionId: string, cascade: boolean): Promise<boolean> {
|
|
57
|
-
return this.client.deleteSession(sessionId, cascade);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
async enqueueSpawnRequest(input: {
|
|
61
|
-
rootSessionId: string;
|
|
62
|
-
parentAgentId: string;
|
|
63
|
-
task?: string;
|
|
64
|
-
systemPrompt?: string;
|
|
65
|
-
}): Promise<void> {
|
|
66
|
-
await this.client.enqueueSpawnRequest(input);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
async claimSpawnRequest(
|
|
70
|
-
rootSessionId: string,
|
|
71
|
-
parentAgentId: string,
|
|
72
|
-
): Promise<string | undefined> {
|
|
73
|
-
return this.client.claimSpawnRequest(rootSessionId, parentAgentId);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// ── Service ──────────────────────────────────────────────────────────
|
|
78
|
-
|
|
79
|
-
export interface RpcCoreSessionServiceOptions {
|
|
80
|
-
address?: string;
|
|
81
|
-
sessionsDir: string;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export class RpcCoreSessionService extends UnifiedSessionPersistenceService {
|
|
85
|
-
private readonly sessionsDirPath: string;
|
|
86
|
-
private readonly client: RpcSessionClient;
|
|
87
|
-
|
|
88
|
-
constructor(options: RpcCoreSessionServiceOptions) {
|
|
89
|
-
const client = new RpcSessionClient({
|
|
90
|
-
address: options.address?.trim() || "127.0.0.1:4317",
|
|
91
|
-
});
|
|
92
|
-
super(new RpcSessionPersistenceAdapter(client));
|
|
93
|
-
this.sessionsDirPath = options.sessionsDir;
|
|
94
|
-
this.client = client;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
override ensureSessionsDir(): string {
|
|
98
|
-
if (!existsSync(this.sessionsDirPath)) {
|
|
99
|
-
mkdirSync(this.sessionsDirPath, { recursive: true });
|
|
100
|
-
}
|
|
101
|
-
return this.sessionsDirPath;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
close(): void {
|
|
105
|
-
this.client.close();
|
|
106
|
-
}
|
|
107
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { mkdtempSync, rmSync } from "node:fs";
|
|
2
|
-
import os from "node:os";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import { afterEach, describe, expect, it } from "vitest";
|
|
5
|
-
import { tryAcquireRpcSpawnLease } from "./rpc-spawn-lease";
|
|
6
|
-
|
|
7
|
-
describe("tryAcquireRpcSpawnLease", () => {
|
|
8
|
-
const tempDirs: string[] = [];
|
|
9
|
-
|
|
10
|
-
afterEach(() => {
|
|
11
|
-
delete process.env.CLINE_DATA_DIR;
|
|
12
|
-
for (const dir of tempDirs.splice(0)) {
|
|
13
|
-
rmSync(dir, { recursive: true, force: true });
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it("allows only one active lease per address", () => {
|
|
18
|
-
const dataDir = mkdtempSync(path.join(os.tmpdir(), "rpc-spawn-lease-"));
|
|
19
|
-
tempDirs.push(dataDir);
|
|
20
|
-
process.env.CLINE_DATA_DIR = dataDir;
|
|
21
|
-
|
|
22
|
-
const first = tryAcquireRpcSpawnLease("127.0.0.1:4317");
|
|
23
|
-
const second = tryAcquireRpcSpawnLease("127.0.0.1:4317");
|
|
24
|
-
|
|
25
|
-
expect(first).toBeDefined();
|
|
26
|
-
expect(second).toBeUndefined();
|
|
27
|
-
|
|
28
|
-
first?.release();
|
|
29
|
-
|
|
30
|
-
const third = tryAcquireRpcSpawnLease("127.0.0.1:4317");
|
|
31
|
-
expect(third).toBeDefined();
|
|
32
|
-
third?.release();
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it("lets different addresses acquire independent leases", () => {
|
|
36
|
-
const dataDir = mkdtempSync(path.join(os.tmpdir(), "rpc-spawn-lease-"));
|
|
37
|
-
tempDirs.push(dataDir);
|
|
38
|
-
process.env.CLINE_DATA_DIR = dataDir;
|
|
39
|
-
|
|
40
|
-
const first = tryAcquireRpcSpawnLease("127.0.0.1:4317");
|
|
41
|
-
const second = tryAcquireRpcSpawnLease("127.0.0.1:4318");
|
|
42
|
-
|
|
43
|
-
expect(first).toBeDefined();
|
|
44
|
-
expect(second).toBeDefined();
|
|
45
|
-
|
|
46
|
-
first?.release();
|
|
47
|
-
second?.release();
|
|
48
|
-
});
|
|
49
|
-
});
|