@clinebot/core 0.0.33 → 0.0.35
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 +12 -8
- package/dist/ClineCore.d.ts +48 -29
- package/dist/ClineCore.d.ts.map +1 -1
- package/dist/auth/client.d.ts +19 -0
- package/dist/auth/client.d.ts.map +1 -1
- package/dist/auth/cline.d.ts.map +1 -1
- package/dist/auth/oca.d.ts.map +1 -1
- package/dist/auth/server.d.ts +32 -0
- package/dist/auth/server.d.ts.map +1 -1
- package/dist/auth/types.d.ts +29 -0
- package/dist/auth/types.d.ts.map +1 -1
- package/dist/extensions/config/agent-config-loader.d.ts +2 -2
- 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/user-instruction-config-loader.d.ts +2 -2
- package/dist/extensions/config/user-instruction-config-loader.d.ts.map +1 -1
- package/dist/extensions/index.d.ts +2 -1
- package/dist/extensions/index.d.ts.map +1 -1
- package/dist/extensions/plugin/plugin-config-loader.d.ts +2 -1
- package/dist/extensions/plugin/plugin-config-loader.d.ts.map +1 -1
- package/dist/extensions/plugin/plugin-load-report.d.ts +19 -0
- package/dist/extensions/plugin/plugin-load-report.d.ts.map +1 -0
- package/dist/extensions/plugin/plugin-loader.d.ts +6 -0
- package/dist/extensions/plugin/plugin-loader.d.ts.map +1 -1
- package/dist/extensions/plugin/plugin-sandbox.d.ts +2 -1
- package/dist/extensions/plugin/plugin-sandbox.d.ts.map +1 -1
- package/dist/extensions/plugin-sandbox-bootstrap.js +242 -242
- package/dist/extensions/tools/constants.d.ts.map +1 -0
- 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/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/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/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 +1 -2
- package/dist/extensions/tools/presets.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/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 +0 -2
- package/dist/hooks/hook-file-hooks.d.ts.map +1 -0
- package/dist/hooks/subprocess.d.ts +3 -130
- package/dist/hooks/subprocess.d.ts.map +1 -1
- package/dist/index.d.ts +38 -35
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +386 -384
- package/dist/runtime/history.d.ts +4 -0
- package/dist/runtime/history.d.ts.map +1 -0
- package/dist/runtime/host.d.ts +9 -0
- package/dist/runtime/host.d.ts.map +1 -0
- package/dist/{session → runtime}/rpc-runtime-ensure.d.ts +13 -1
- package/dist/{session → runtime}/rpc-runtime-ensure.d.ts.map +1 -1
- package/dist/{session → runtime}/rpc-spawn-lease.d.ts.map +1 -1
- package/dist/runtime/runtime-builder.d.ts +1 -1
- package/dist/runtime/runtime-builder.d.ts.map +1 -1
- package/dist/{session/session-manager.d.ts → runtime/runtime-host.d.ts} +55 -12
- 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 +2 -2
- package/dist/runtime/session-runtime.d.ts.map +1 -1
- package/dist/runtime/subprocess-sandbox.d.ts +2 -0
- package/dist/runtime/subprocess-sandbox.d.ts.map +1 -1
- package/dist/runtime/tool-approval.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/local-runtime-bootstrap.d.ts +41 -0
- package/dist/services/local-runtime-bootstrap.d.ts.map +1 -0
- package/dist/services/providers/local-provider-registry.d.ts.map +1 -0
- package/dist/services/providers/local-provider-service.d.ts.map +1 -0
- package/dist/{session → services}/session-artifacts.d.ts +2 -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/{telemetry → services/telemetry}/index.js +6 -6
- 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.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 +8 -6
- package/dist/session/persistence-service.d.ts.map +1 -1
- package/dist/session/rpc-session-service.d.ts +3 -0
- package/dist/session/rpc-session-service.d.ts.map +1 -1
- package/dist/session/session-service.d.ts +8 -9
- 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/sqlite-rpc-session-backend.d.ts.map +1 -1
- package/dist/{session/default-session-manager.d.ts → transports/local.d.ts} +24 -14
- package/dist/transports/local.d.ts.map +1 -0
- package/dist/transports/rpc.d.ts +51 -0
- package/dist/transports/rpc.d.ts.map +1 -0
- package/dist/transports/runtime-host-support.d.ts +21 -0
- package/dist/transports/runtime-host-support.d.ts.map +1 -0
- package/dist/types/chat-schema.d.ts.map +1 -0
- package/dist/types/config.d.ts +3 -2
- package/dist/types/config.d.ts.map +1 -1
- package/dist/{session/utils/types.d.ts → types/session.d.ts} +15 -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 +7 -6
- package/dist/types.d.ts.map +1 -1
- package/package.json +7 -12
- package/src/ClineCore.test.ts +95 -19
- package/src/ClineCore.ts +120 -50
- package/src/auth/client.test.ts +29 -0
- package/src/auth/client.ts +21 -0
- package/src/auth/cline.ts +3 -1
- package/src/auth/codex.ts +1 -1
- package/src/auth/oca.ts +3 -1
- package/src/auth/server.test.ts +287 -0
- package/src/auth/server.ts +50 -1
- package/src/auth/types.ts +29 -0
- package/src/extensions/config/agent-config-loader.test.ts +3 -3
- package/src/extensions/config/agent-config-loader.ts +1 -5
- 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/user-instruction-config-loader.ts +0 -4
- package/src/extensions/index.ts +6 -0
- package/src/extensions/plugin/plugin-config-loader.test.ts +39 -0
- package/src/extensions/plugin/plugin-config-loader.ts +18 -10
- package/src/extensions/plugin/plugin-load-report.ts +20 -0
- package/src/extensions/plugin/plugin-loader.test.ts +45 -0
- package/src/extensions/plugin/plugin-loader.ts +57 -3
- package/src/extensions/plugin/plugin-sandbox-bootstrap.ts +158 -86
- package/src/extensions/plugin/plugin-sandbox.test.ts +70 -0
- package/src/extensions/plugin/plugin-sandbox.ts +17 -6
- package/src/{tools → extensions/tools}/definitions.ts +1 -1
- package/src/extensions/tools/executors/file-read.test.ts +125 -0
- package/src/{tools → extensions/tools}/executors/file-read.ts +29 -4
- package/src/{tools → extensions/tools}/executors/search.ts +1 -1
- package/src/{tools → extensions/tools}/model-tool-routing.ts +1 -1
- package/src/{tools → extensions/tools}/presets.ts +2 -3
- package/src/extensions/tools/team/multi-agent.lifecycle.test.ts +455 -0
- package/src/{team → extensions/tools/team}/multi-agent.ts +80 -17
- package/src/{team → extensions/tools/team}/spawn-agent-tool.test.ts +0 -6
- 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.test.ts +146 -30
- package/src/{team → extensions/tools/team}/team-tools.ts +98 -69
- 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.test.ts +42 -7
- package/src/{runtime → hooks}/hook-file-hooks.ts +6 -11
- package/src/hooks/subprocess.ts +48 -257
- package/src/index.ts +178 -158
- package/src/runtime/history.test.ts +114 -0
- package/src/runtime/history.ts +237 -0
- package/src/runtime/host.test.ts +230 -0
- package/src/runtime/host.ts +362 -0
- package/src/runtime/rpc-runtime-ensure.test.ts +123 -0
- package/src/{session → runtime}/rpc-runtime-ensure.ts +165 -27
- package/src/{session → runtime}/rpc-spawn-lease.test.ts +33 -1
- package/src/{session → runtime}/rpc-spawn-lease.ts +54 -20
- package/src/runtime/runtime-builder.team-persistence.test.ts +6 -3
- package/src/runtime/runtime-builder.test.ts +101 -4
- package/src/runtime/runtime-builder.ts +125 -86
- package/src/runtime/runtime-host.ts +178 -0
- package/src/{session → runtime}/runtime-oauth-token-manager.ts +1 -1
- package/src/runtime/runtime-parity.test.ts +1 -1
- package/src/runtime/session-runtime.ts +2 -2
- package/src/runtime/subprocess-sandbox.ts +26 -23
- package/src/runtime/tool-approval.ts +13 -15
- package/src/{session/session-agent-events.ts → services/agent-events.ts} +7 -7
- package/src/services/config.ts +5 -0
- package/src/services/local-runtime-bootstrap.ts +280 -0
- package/src/{providers → services/providers}/local-provider-service.ts +4 -4
- package/src/{session → services}/session-artifacts.ts +23 -19
- package/src/{session/utils/helpers.test.ts → services/session-data.test.ts} +1 -1
- package/src/{session/utils/helpers.ts → services/session-data.ts} +76 -72
- 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.test.ts +1 -1
- package/src/{storage → services/storage}/provider-settings-legacy-migration.ts +2 -2
- package/src/{storage → services/storage}/provider-settings-manager.ts +2 -2
- 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.test.ts +30 -1
- package/src/{input → services/workspace}/file-indexer.ts +26 -2
- package/src/{input → services/workspace}/mention-enricher.test.ts +21 -0
- package/src/{input → services/workspace}/mention-enricher.ts +1 -1
- package/src/session/file-session-service.ts +9 -7
- package/src/session/index.ts +25 -17
- package/src/session/persistence-service.test.ts +121 -24
- package/src/session/persistence-service.ts +118 -102
- package/src/session/rpc-session-service.ts +9 -2
- package/src/session/session-service.team-persistence.test.ts +1 -1
- package/src/session/session-service.ts +32 -19
- package/src/session/session-team-coordination.ts +13 -6
- package/src/session/sqlite-rpc-session-backend.ts +4 -6
- package/src/session/workspace-manager.ts +1 -1
- package/src/{session/default-session-manager.e2e.test.ts → transports/local.e2e.test.ts} +13 -17
- package/src/{session/default-session-manager.test.ts → transports/local.test.ts} +316 -230
- package/src/{session/default-session-manager.ts → transports/local.ts} +138 -172
- package/src/transports/rpc.test.ts +82 -0
- package/src/transports/rpc.ts +665 -0
- package/src/transports/runtime-host-support.ts +86 -0
- package/src/types/config.ts +3 -2
- package/src/{session/utils/types.ts → types/session.ts} +18 -5
- package/src/types/sessions.ts +21 -0
- package/src/types/storage.ts +1 -6
- package/src/types.ts +25 -18
- package/dist/chat/chat-schema.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/runtime/team-runtime-registry.d.ts +0 -13
- package/dist/runtime/team-runtime-registry.d.ts.map +0 -1
- package/dist/session/default-session-manager.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.map +0 -1
- package/dist/session/session-telemetry.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.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/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/prompt/default-system.ts +0 -21
- package/src/runtime/team-runtime-registry.ts +0 -43
- package/src/session/session-config-builder.ts +0 -126
- 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/storage/artifact-store.ts +0 -1
- package/src/storage/session-store.ts +0 -1
- package/src/team/multi-agent.lifecycle.test.ts +0 -201
- package/src/tools/executors/file-read.test.ts +0 -49
- /package/dist/{tools → extensions/tools}/constants.d.ts +0 -0
- /package/dist/{tools → extensions/tools}/definitions.d.ts +0 -0
- /package/dist/{tools → extensions/tools}/executors/apply-patch-parser.d.ts +0 -0
- /package/dist/{tools → extensions/tools}/executors/apply-patch.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/search.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}/index.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/{team → extensions/tools/team}/team-tools.d.ts +0 -0
- /package/dist/{session → runtime}/rpc-spawn-lease.d.ts +0 -0
- /package/dist/{providers → services/providers}/local-provider-registry.d.ts +0 -0
- /package/dist/{providers → services/providers}/local-provider-service.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/dist/{session → services}/workspace-manifest.d.ts +0 -0
- /package/dist/{chat → types}/chat-schema.d.ts +0 -0
- /package/src/{tools → extensions/tools}/constants.ts +0 -0
- /package/src/{tools → extensions/tools}/definitions.test.ts +0 -0
- /package/src/{tools → extensions/tools}/executors/apply-patch-parser.ts +0 -0
- /package/src/{tools → extensions/tools}/executors/apply-patch.ts +0 -0
- /package/src/{tools → extensions/tools}/executors/bash.test.ts +0 -0
- /package/src/{tools → extensions/tools}/executors/bash.ts +0 -0
- /package/src/{tools → extensions/tools}/executors/editor.test.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/{tools → extensions/tools}/index.ts +0 -0
- /package/src/{tools → extensions/tools}/model-tool-routing.test.ts +0 -0
- /package/src/{tools → extensions/tools}/presets.test.ts +0 -0
- /package/src/{tools → extensions/tools}/schemas.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/{runtime → hooks}/checkpoint-hooks.test.ts +0 -0
- /package/src/{session → runtime}/runtime-oauth-token-manager.test.ts +0 -0
- /package/src/{providers → services/providers}/local-provider-registry.ts +0 -0
- /package/src/{providers → services/providers}/local-provider-service.test.ts +0 -0
- /package/src/{storage → services/storage}/index.ts +0 -0
- /package/src/{storage → services/storage}/provider-settings-manager.test.ts +0 -0
- /package/src/{telemetry → services/telemetry}/ITelemetryAdapter.ts +0 -0
- /package/src/{telemetry → services/telemetry}/OpenTelemetryAdapter.test.ts +0 -0
- /package/src/{telemetry → services/telemetry}/OpenTelemetryAdapter.ts +0 -0
- /package/src/{telemetry → services/telemetry}/OpenTelemetryProvider.test.ts +0 -0
- /package/src/{telemetry → services/telemetry}/OpenTelemetryProvider.ts +0 -0
- /package/src/{telemetry → services/telemetry}/TelemetryLoggerSink.test.ts +0 -0
- /package/src/{telemetry → services/telemetry}/TelemetryLoggerSink.ts +0 -0
- /package/src/{telemetry → services/telemetry}/TelemetryService.test.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.test.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}/file-indexer.d.ts +0 -0
- /package/src/{input → services/workspace}/index.ts +0 -0
- /package/src/{session → services}/workspace-manifest.ts +0 -0
- /package/src/{chat → types}/chat-schema.ts +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { existsSync, mkdtempSync, readFileSync, rmSync } from "node:fs";
|
|
2
2
|
import { tmpdir } from "node:os";
|
|
3
3
|
import { join } from "node:path";
|
|
4
|
-
import { afterEach, describe, expect, it } from "vitest";
|
|
5
|
-
import { SqliteSessionStore } from "../storage/sqlite-session-store";
|
|
4
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
5
|
+
import { SqliteSessionStore } from "../services/storage/sqlite-session-store";
|
|
6
6
|
import { SessionSource } from "../types/common";
|
|
7
7
|
import { CoreSessionService } from "./session-service";
|
|
8
8
|
|
|
@@ -20,12 +20,17 @@ describe("UnifiedSessionPersistenceService", () => {
|
|
|
20
20
|
});
|
|
21
21
|
|
|
22
22
|
it("reconciles dead running sessions into failed manifests with terminal markers", async () => {
|
|
23
|
-
const
|
|
24
|
-
|
|
23
|
+
const dbDir = mkdtempSync(join(tmpdir(), "stale-session-reconcile-db-"));
|
|
24
|
+
const sessionsDir = mkdtempSync(
|
|
25
|
+
join(tmpdir(), "stale-session-reconcile-sessions-"),
|
|
26
|
+
);
|
|
27
|
+
tempDirs.push(dbDir, sessionsDir);
|
|
25
28
|
|
|
26
|
-
const store = new SqliteSessionStore({ sessionsDir });
|
|
29
|
+
const store = new SqliteSessionStore({ sessionsDir: dbDir });
|
|
27
30
|
stores.push(store);
|
|
28
|
-
const service = new CoreSessionService(store
|
|
31
|
+
const service = new CoreSessionService(store, {
|
|
32
|
+
sessionArtifactsDir: sessionsDir,
|
|
33
|
+
});
|
|
29
34
|
const sessionId = "stale-root-session";
|
|
30
35
|
const artifacts = await service.createRootSessionWithArtifacts({
|
|
31
36
|
sessionId,
|
|
@@ -70,26 +75,24 @@ describe("UnifiedSessionPersistenceService", () => {
|
|
|
70
75
|
(manifest.metadata as Record<string, unknown>).terminal_marker_at,
|
|
71
76
|
).toBeTruthy();
|
|
72
77
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
'"hookName":"session_shutdown"'
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
'"reason":"failed_external_process_exit"',
|
|
80
|
-
);
|
|
81
|
-
expect(readFileSync(artifacts.transcriptPath, "utf8")).toContain(
|
|
82
|
-
"[shutdown] failed_external_process_exit",
|
|
83
|
-
);
|
|
78
|
+
const globalHookLog = process.env.CLINE_HOOKS_LOG_PATH ?? "";
|
|
79
|
+
if (globalHookLog && existsSync(globalHookLog)) {
|
|
80
|
+
const hookContent = readFileSync(globalHookLog, "utf8");
|
|
81
|
+
expect(hookContent).toContain('"hookName":"session_shutdown"');
|
|
82
|
+
expect(hookContent).toContain('"reason":"failed_external_process_exit"');
|
|
83
|
+
}
|
|
84
84
|
}, 15_000);
|
|
85
85
|
|
|
86
86
|
it("persists teammate task metadata in the file envelope and usage on messages", async () => {
|
|
87
|
+
const dbDir = mkdtempSync(join(tmpdir(), "team-task-messages-db-"));
|
|
87
88
|
const sessionsDir = mkdtempSync(join(tmpdir(), "team-task-messages-"));
|
|
88
|
-
tempDirs.push(sessionsDir);
|
|
89
|
+
tempDirs.push(dbDir, sessionsDir);
|
|
89
90
|
|
|
90
|
-
const store = new SqliteSessionStore({ sessionsDir });
|
|
91
|
+
const store = new SqliteSessionStore({ sessionsDir: dbDir });
|
|
91
92
|
stores.push(store);
|
|
92
|
-
const service = new CoreSessionService(store
|
|
93
|
+
const service = new CoreSessionService(store, {
|
|
94
|
+
sessionArtifactsDir: sessionsDir,
|
|
95
|
+
});
|
|
93
96
|
const rootSessionId = "root-session";
|
|
94
97
|
await service.createRootSessionWithArtifacts({
|
|
95
98
|
sessionId: rootSessionId,
|
|
@@ -194,10 +197,104 @@ describe("UnifiedSessionPersistenceService", () => {
|
|
|
194
197
|
cost: 0.123,
|
|
195
198
|
});
|
|
196
199
|
expect(row?.messagesPath).toBe(path);
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it("uploads messages after persisting them when a messages uploader is configured", async () => {
|
|
203
|
+
const dbDir = mkdtempSync(join(tmpdir(), "messages-upload-db-"));
|
|
204
|
+
const sessionsDir = mkdtempSync(join(tmpdir(), "messages-upload-"));
|
|
205
|
+
tempDirs.push(dbDir, sessionsDir);
|
|
206
|
+
|
|
207
|
+
const store = new SqliteSessionStore({ sessionsDir: dbDir });
|
|
208
|
+
stores.push(store);
|
|
209
|
+
const uploadMessagesFile = vi.fn(async () => {});
|
|
210
|
+
const service = new CoreSessionService(store, {
|
|
211
|
+
sessionArtifactsDir: sessionsDir,
|
|
212
|
+
messagesArtifactUploader: {
|
|
213
|
+
uploadMessagesFile,
|
|
214
|
+
},
|
|
215
|
+
});
|
|
216
|
+
const sessionId = "root-upload-session";
|
|
217
|
+
await service.createRootSessionWithArtifacts({
|
|
218
|
+
sessionId,
|
|
219
|
+
source: SessionSource.CLI,
|
|
220
|
+
pid: process.pid,
|
|
221
|
+
interactive: false,
|
|
222
|
+
provider: "anthropic",
|
|
223
|
+
model: "claude-sonnet-4-6",
|
|
224
|
+
cwd: "/tmp/project",
|
|
225
|
+
workspaceRoot: "/tmp/project",
|
|
226
|
+
enableTools: true,
|
|
227
|
+
enableSpawn: false,
|
|
228
|
+
enableTeams: false,
|
|
229
|
+
prompt: "hello",
|
|
230
|
+
metadata: {
|
|
231
|
+
blobUpload: true,
|
|
232
|
+
},
|
|
233
|
+
startedAt: "2026-04-10T19:00:00.000Z",
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
await service.persistSessionMessages(sessionId, [
|
|
237
|
+
{
|
|
238
|
+
role: "user",
|
|
239
|
+
content: "hello",
|
|
240
|
+
},
|
|
241
|
+
]);
|
|
242
|
+
|
|
243
|
+
expect(uploadMessagesFile).toHaveBeenCalledTimes(1);
|
|
244
|
+
expect(uploadMessagesFile).toHaveBeenCalledWith(
|
|
245
|
+
expect.objectContaining({
|
|
246
|
+
sessionId,
|
|
247
|
+
path: expect.stringContaining(`${sessionId}.messages.json`),
|
|
248
|
+
contents: expect.stringContaining('"role": "user"'),
|
|
249
|
+
row: expect.objectContaining({
|
|
250
|
+
sessionId,
|
|
251
|
+
metadata: {
|
|
252
|
+
blobUpload: true,
|
|
253
|
+
title: "hello",
|
|
254
|
+
},
|
|
255
|
+
}),
|
|
256
|
+
}),
|
|
200
257
|
);
|
|
201
|
-
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
it("deletes the full root session directory even when artifact paths are stale", async () => {
|
|
261
|
+
const dbDir = mkdtempSync(join(tmpdir(), "delete-root-session-dir-db-"));
|
|
262
|
+
const sessionsDir = mkdtempSync(join(tmpdir(), "delete-root-session-dir-"));
|
|
263
|
+
tempDirs.push(dbDir, sessionsDir);
|
|
264
|
+
|
|
265
|
+
const store = new SqliteSessionStore({ sessionsDir: dbDir });
|
|
266
|
+
stores.push(store);
|
|
267
|
+
const service = new CoreSessionService(store, {
|
|
268
|
+
sessionArtifactsDir: sessionsDir,
|
|
269
|
+
});
|
|
270
|
+
const sessionId = "root-session-delete";
|
|
271
|
+
const artifacts = await service.createRootSessionWithArtifacts({
|
|
272
|
+
sessionId,
|
|
273
|
+
source: SessionSource.CLI,
|
|
274
|
+
pid: process.pid,
|
|
275
|
+
interactive: false,
|
|
276
|
+
provider: "anthropic",
|
|
277
|
+
model: "claude-sonnet-4-6",
|
|
278
|
+
cwd: "/tmp/project",
|
|
279
|
+
workspaceRoot: "/tmp/project",
|
|
280
|
+
enableTools: true,
|
|
281
|
+
enableSpawn: false,
|
|
282
|
+
enableTeams: false,
|
|
283
|
+
prompt: "delete me",
|
|
284
|
+
startedAt: "2026-04-10T19:00:00.000Z",
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
store.run(`UPDATE sessions SET messages_path = NULL WHERE session_id = ?`, [
|
|
288
|
+
sessionId,
|
|
289
|
+
]);
|
|
290
|
+
|
|
291
|
+
expect(existsSync(artifacts.messagesPath)).toBe(true);
|
|
292
|
+
expect(existsSync(join(sessionsDir, sessionId))).toBe(true);
|
|
293
|
+
|
|
294
|
+
const result = await service.deleteSession(sessionId);
|
|
295
|
+
|
|
296
|
+
expect(result).toEqual({ deleted: true });
|
|
297
|
+
expect(existsSync(artifacts.messagesPath)).toBe(false);
|
|
298
|
+
expect(existsSync(join(sessionsDir, sessionId))).toBe(false);
|
|
202
299
|
});
|
|
203
300
|
});
|
|
@@ -1,33 +1,28 @@
|
|
|
1
1
|
import {
|
|
2
2
|
appendFileSync,
|
|
3
3
|
existsSync,
|
|
4
|
+
mkdirSync,
|
|
4
5
|
readFileSync,
|
|
5
6
|
writeFileSync,
|
|
6
7
|
} from "node:fs";
|
|
8
|
+
import { dirname, join } from "node:path";
|
|
7
9
|
import type * as LlmsProviders from "@clinebot/llms";
|
|
8
10
|
import type { AgentResult } from "@clinebot/shared";
|
|
9
11
|
import { resolveRootSessionId } from "@clinebot/shared";
|
|
12
|
+
import { ensureHookLogDir } from "@clinebot/shared/storage";
|
|
10
13
|
import { nanoid } from "nanoid";
|
|
11
14
|
import { z } from "zod";
|
|
15
|
+
import type {
|
|
16
|
+
SubAgentEndContext,
|
|
17
|
+
SubAgentStartContext,
|
|
18
|
+
} from "../extensions/tools/team";
|
|
12
19
|
import type { HookEventPayload } from "../hooks";
|
|
13
|
-
import
|
|
14
|
-
import { SessionSource, type SessionStatus } from "../types/common";
|
|
15
|
-
import { nowIso, SessionArtifacts, unlinkIfExists } from "./session-artifacts";
|
|
20
|
+
import { deleteCheckpointRefs } from "../hooks/checkpoint-hooks";
|
|
16
21
|
import {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
} from "
|
|
21
|
-
import {
|
|
22
|
-
type SessionManifest,
|
|
23
|
-
SessionManifestSchema,
|
|
24
|
-
} from "./session-manifest";
|
|
25
|
-
import type {
|
|
26
|
-
CreateRootSessionWithArtifactsInput,
|
|
27
|
-
RootSessionArtifacts,
|
|
28
|
-
SessionRow,
|
|
29
|
-
UpsertSubagentInput,
|
|
30
|
-
} from "./session-service";
|
|
22
|
+
nowIso,
|
|
23
|
+
SessionArtifacts,
|
|
24
|
+
unlinkIfExists,
|
|
25
|
+
} from "../services/session-artifacts";
|
|
31
26
|
import {
|
|
32
27
|
buildManifestFromRow,
|
|
33
28
|
buildMessagesFilePayload,
|
|
@@ -40,12 +35,29 @@ import {
|
|
|
40
35
|
withLatestAssistantTurnMetadata,
|
|
41
36
|
withOccRetry,
|
|
42
37
|
writeEmptyMessagesFile,
|
|
43
|
-
} from "
|
|
38
|
+
} from "../services/session-data";
|
|
39
|
+
import { SessionSource, type SessionStatus } from "../types/common";
|
|
44
40
|
import type {
|
|
45
41
|
PersistedSessionUpdateInput,
|
|
42
|
+
SessionMessagesArtifactUploader,
|
|
46
43
|
SessionPersistenceAdapter,
|
|
47
44
|
StoredMessageWithMetadata,
|
|
48
|
-
} from "
|
|
45
|
+
} from "../types/session";
|
|
46
|
+
import {
|
|
47
|
+
deriveSubsessionStatus,
|
|
48
|
+
makeSubSessionId,
|
|
49
|
+
makeTeamTaskSubSessionId,
|
|
50
|
+
} from "./session-graph";
|
|
51
|
+
import {
|
|
52
|
+
type SessionManifest,
|
|
53
|
+
SessionManifestSchema,
|
|
54
|
+
} from "./session-manifest";
|
|
55
|
+
import type {
|
|
56
|
+
CreateRootSessionWithArtifactsInput,
|
|
57
|
+
RootSessionArtifacts,
|
|
58
|
+
SessionRow,
|
|
59
|
+
UpsertSubagentInput,
|
|
60
|
+
} from "./session-service";
|
|
49
61
|
|
|
50
62
|
export type { PersistedSessionUpdateInput, SessionPersistenceAdapter };
|
|
51
63
|
|
|
@@ -67,12 +79,19 @@ export class UnifiedSessionPersistenceService {
|
|
|
67
79
|
string
|
|
68
80
|
>();
|
|
69
81
|
protected readonly artifacts: SessionArtifacts;
|
|
82
|
+
private readonly messagesArtifactUploader?: SessionMessagesArtifactUploader;
|
|
70
83
|
private static readonly STALE_REASON = "failed_external_process_exit";
|
|
71
84
|
private static readonly STALE_SOURCE = "stale_session_reconciler";
|
|
72
85
|
private static readonly TEAM_HEARTBEAT_LOG_INTERVAL_MS = 30_000;
|
|
73
86
|
|
|
74
|
-
constructor(
|
|
87
|
+
constructor(
|
|
88
|
+
private readonly adapter: SessionPersistenceAdapter,
|
|
89
|
+
options: {
|
|
90
|
+
messagesArtifactUploader?: SessionMessagesArtifactUploader;
|
|
91
|
+
} = {},
|
|
92
|
+
) {
|
|
75
93
|
this.artifacts = new SessionArtifacts(() => this.ensureSessionsDir());
|
|
94
|
+
this.messagesArtifactUploader = options.messagesArtifactUploader;
|
|
76
95
|
}
|
|
77
96
|
|
|
78
97
|
ensureSessionsDir(): string {
|
|
@@ -114,6 +133,7 @@ export class UnifiedSessionPersistenceService {
|
|
|
114
133
|
manifestPath: string,
|
|
115
134
|
manifest: SessionManifest,
|
|
116
135
|
): void {
|
|
136
|
+
mkdirSync(dirname(manifestPath), { recursive: true });
|
|
117
137
|
writeFileSync(
|
|
118
138
|
manifestPath,
|
|
119
139
|
`${JSON.stringify(SessionManifestSchema.parse(manifest), null, 2)}\n`,
|
|
@@ -151,7 +171,7 @@ export class UnifiedSessionPersistenceService {
|
|
|
151
171
|
|
|
152
172
|
private async resolveArtifactPath(
|
|
153
173
|
sessionId: string,
|
|
154
|
-
kind: "
|
|
174
|
+
kind: "messagesPath",
|
|
155
175
|
fallback: (id: string) => string,
|
|
156
176
|
): Promise<string> {
|
|
157
177
|
const row = await this.adapter.getSession(sessionId);
|
|
@@ -186,8 +206,6 @@ export class UnifiedSessionPersistenceService {
|
|
|
186
206
|
const providedId = input.sessionId.trim();
|
|
187
207
|
const sessionId =
|
|
188
208
|
providedId.length > 0 ? providedId : `${Date.now()}_${nanoid(5)}`;
|
|
189
|
-
const transcriptPath = this.artifacts.sessionTranscriptPath(sessionId);
|
|
190
|
-
const hookPath = this.artifacts.sessionHookPath(sessionId);
|
|
191
209
|
const messagesPath = this.artifacts.sessionMessagesPath(sessionId);
|
|
192
210
|
const manifestPath = this.artifacts.sessionManifestPath(sessionId);
|
|
193
211
|
|
|
@@ -241,15 +259,14 @@ export class UnifiedSessionPersistenceService {
|
|
|
241
259
|
isSubagent: false,
|
|
242
260
|
prompt: manifest.prompt ?? null,
|
|
243
261
|
metadata: sanitizeMetadata(manifest.metadata),
|
|
244
|
-
|
|
245
|
-
hookPath,
|
|
262
|
+
hookPath: "",
|
|
246
263
|
messagesPath,
|
|
247
264
|
updatedAt: nowIso(),
|
|
248
265
|
});
|
|
249
266
|
|
|
250
267
|
this.initializeMessagesFile(sessionId, messagesPath, startedAt);
|
|
251
268
|
this.writeManifestFile(manifestPath, manifest);
|
|
252
|
-
return { manifestPath,
|
|
269
|
+
return { manifestPath, messagesPath, manifest };
|
|
253
270
|
}
|
|
254
271
|
|
|
255
272
|
// ── Session status updates ────────────────────────────────────────
|
|
@@ -262,14 +279,14 @@ export class UnifiedSessionPersistenceService {
|
|
|
262
279
|
let endedAt: string | undefined;
|
|
263
280
|
const result = await withOccRetry(
|
|
264
281
|
() => this.adapter.getSession(sessionId),
|
|
265
|
-
async (
|
|
282
|
+
async (row) => {
|
|
266
283
|
endedAt = nowIso();
|
|
267
284
|
return this.adapter.updateSession({
|
|
268
285
|
sessionId,
|
|
269
286
|
status,
|
|
270
287
|
endedAt,
|
|
271
288
|
exitCode: typeof exitCode === "number" ? exitCode : null,
|
|
272
|
-
expectedStatusLock: statusLock,
|
|
289
|
+
expectedStatusLock: row.statusLock,
|
|
273
290
|
});
|
|
274
291
|
},
|
|
275
292
|
OCC_MAX_RETRIES,
|
|
@@ -387,8 +404,6 @@ export class UnifiedSessionPersistenceService {
|
|
|
387
404
|
conversationId?: string | null;
|
|
388
405
|
prompt: string;
|
|
389
406
|
startedAt: string;
|
|
390
|
-
transcriptPath: string;
|
|
391
|
-
hookPath: string;
|
|
392
407
|
messagesPath: string;
|
|
393
408
|
},
|
|
394
409
|
): SessionRow {
|
|
@@ -417,8 +432,7 @@ export class UnifiedSessionPersistenceService {
|
|
|
417
432
|
isSubagent: true,
|
|
418
433
|
prompt: opts.prompt,
|
|
419
434
|
metadata: resolveMetadataWithTitle({ prompt: opts.prompt }),
|
|
420
|
-
|
|
421
|
-
hookPath: opts.hookPath,
|
|
435
|
+
hookPath: "",
|
|
422
436
|
messagesPath: opts.messagesPath,
|
|
423
437
|
updatedAt: opts.startedAt,
|
|
424
438
|
};
|
|
@@ -516,31 +530,16 @@ export class UnifiedSessionPersistenceService {
|
|
|
516
530
|
subSessionId: string,
|
|
517
531
|
event: HookEventPayload,
|
|
518
532
|
): Promise<void> {
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
(id) => this.artifacts.sessionHookPath(id),
|
|
523
|
-
);
|
|
533
|
+
void subSessionId;
|
|
534
|
+
const envPath = process.env.CLINE_HOOKS_LOG_PATH?.trim() || undefined;
|
|
535
|
+
const logPath = envPath ?? join(ensureHookLogDir(), "hooks.jsonl");
|
|
524
536
|
appendFileSync(
|
|
525
|
-
|
|
537
|
+
logPath,
|
|
526
538
|
`${JSON.stringify({ ts: nowIso(), ...event })}\n`,
|
|
527
539
|
"utf8",
|
|
528
540
|
);
|
|
529
541
|
}
|
|
530
542
|
|
|
531
|
-
async appendSubagentTranscriptLine(
|
|
532
|
-
subSessionId: string,
|
|
533
|
-
line: string,
|
|
534
|
-
): Promise<void> {
|
|
535
|
-
if (!line.trim()) return;
|
|
536
|
-
const path = await this.resolveArtifactPath(
|
|
537
|
-
subSessionId,
|
|
538
|
-
"transcriptPath",
|
|
539
|
-
(id) => this.artifacts.sessionTranscriptPath(id),
|
|
540
|
-
);
|
|
541
|
-
appendFileSync(path, `${line}\n`, "utf8");
|
|
542
|
-
}
|
|
543
|
-
|
|
544
543
|
async persistSessionMessages(
|
|
545
544
|
sessionId: string,
|
|
546
545
|
messages: LlmsProviders.Message[],
|
|
@@ -560,7 +559,26 @@ export class UnifiedSessionPersistenceService {
|
|
|
560
559
|
messages: normalizedMessages,
|
|
561
560
|
systemPrompt,
|
|
562
561
|
});
|
|
563
|
-
|
|
562
|
+
const contents = `${JSON.stringify(payload, null, 2)}\n`;
|
|
563
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
564
|
+
writeFileSync(path, contents, "utf8");
|
|
565
|
+
if (!this.messagesArtifactUploader) {
|
|
566
|
+
return;
|
|
567
|
+
}
|
|
568
|
+
try {
|
|
569
|
+
const row = await this.adapter.getSession(sessionId);
|
|
570
|
+
await this.messagesArtifactUploader.uploadMessagesFile({
|
|
571
|
+
sessionId,
|
|
572
|
+
path,
|
|
573
|
+
contents,
|
|
574
|
+
row,
|
|
575
|
+
});
|
|
576
|
+
} catch (error) {
|
|
577
|
+
console.warn(
|
|
578
|
+
`Failed to upload persisted session messages for ${sessionId}`,
|
|
579
|
+
error,
|
|
580
|
+
);
|
|
581
|
+
}
|
|
564
582
|
}
|
|
565
583
|
|
|
566
584
|
// ── Subagent status ───────────────────────────────────────────────
|
|
@@ -620,8 +638,10 @@ export class UnifiedSessionPersistenceService {
|
|
|
620
638
|
|
|
621
639
|
const sessionId = makeTeamTaskSubSessionId(rootSessionId, agentId);
|
|
622
640
|
const startedAt = nowIso();
|
|
623
|
-
const {
|
|
624
|
-
|
|
641
|
+
const { messagesPath } = this.artifacts.subagentArtifactPaths(
|
|
642
|
+
sessionId,
|
|
643
|
+
agentId,
|
|
644
|
+
);
|
|
625
645
|
|
|
626
646
|
await this.adapter.upsertSession(
|
|
627
647
|
this.buildSubsessionRow(root, {
|
|
@@ -631,13 +651,10 @@ export class UnifiedSessionPersistenceService {
|
|
|
631
651
|
agentId,
|
|
632
652
|
prompt: message || `Team task for ${agentId}`,
|
|
633
653
|
startedAt,
|
|
634
|
-
transcriptPath,
|
|
635
|
-
hookPath,
|
|
636
654
|
messagesPath,
|
|
637
655
|
}),
|
|
638
656
|
);
|
|
639
657
|
this.initializeMessagesFile(sessionId, messagesPath, startedAt);
|
|
640
|
-
await this.appendSubagentTranscriptLine(sessionId, `[start] ${message}`);
|
|
641
658
|
|
|
642
659
|
const key = this.teamTaskQueueKey(rootSessionId, agentId);
|
|
643
660
|
const queue = this.teamTaskSessionsByAgent.get(key) ?? [];
|
|
@@ -649,7 +666,7 @@ export class UnifiedSessionPersistenceService {
|
|
|
649
666
|
rootSessionId: string,
|
|
650
667
|
agentId: string,
|
|
651
668
|
status: SessionStatus,
|
|
652
|
-
|
|
669
|
+
_summary?: string,
|
|
653
670
|
result?: AgentResult,
|
|
654
671
|
messages?: LlmsProviders.Message[],
|
|
655
672
|
): Promise<void> {
|
|
@@ -670,10 +687,6 @@ export class UnifiedSessionPersistenceService {
|
|
|
670
687
|
if (persistedMessages) {
|
|
671
688
|
await this.persistSessionMessages(sessionId, persistedMessages);
|
|
672
689
|
}
|
|
673
|
-
await this.appendSubagentTranscriptLine(
|
|
674
|
-
sessionId,
|
|
675
|
-
summary ?? `[done] ${status}`,
|
|
676
|
-
);
|
|
677
690
|
await this.applySubagentStatusBySessionId(sessionId, status);
|
|
678
691
|
this.teamTaskLastHeartbeatBySession.delete(sessionId);
|
|
679
692
|
this.teamTaskLastProgressLineBySession.delete(sessionId);
|
|
@@ -713,7 +726,6 @@ export class UnifiedSessionPersistenceService {
|
|
|
713
726
|
: `[progress] ${trimmed}`;
|
|
714
727
|
if (this.teamTaskLastProgressLineBySession.get(sessionId) === line) return;
|
|
715
728
|
this.teamTaskLastProgressLineBySession.set(sessionId, line);
|
|
716
|
-
await this.appendSubagentTranscriptLine(sessionId, line);
|
|
717
729
|
}
|
|
718
730
|
|
|
719
731
|
// ── SubAgent lifecycle ────────────────────────────────────────────
|
|
@@ -730,10 +742,6 @@ export class UnifiedSessionPersistenceService {
|
|
|
730
742
|
rootSessionId,
|
|
731
743
|
});
|
|
732
744
|
if (!subSessionId) return;
|
|
733
|
-
await this.appendSubagentTranscriptLine(
|
|
734
|
-
subSessionId,
|
|
735
|
-
`[start] ${context.input.task}`,
|
|
736
|
-
);
|
|
737
745
|
await this.applySubagentStatusBySessionId(subSessionId, "running");
|
|
738
746
|
}
|
|
739
747
|
|
|
@@ -751,15 +759,10 @@ export class UnifiedSessionPersistenceService {
|
|
|
751
759
|
if (!subSessionId) return;
|
|
752
760
|
|
|
753
761
|
if (context.error) {
|
|
754
|
-
await this.appendSubagentTranscriptLine(
|
|
755
|
-
subSessionId,
|
|
756
|
-
`[error] ${context.error.message}`,
|
|
757
|
-
);
|
|
758
762
|
await this.applySubagentStatusBySessionId(subSessionId, "failed");
|
|
759
763
|
return;
|
|
760
764
|
}
|
|
761
765
|
const reason = context.result?.finishReason ?? "completed";
|
|
762
|
-
await this.appendSubagentTranscriptLine(subSessionId, `[done] ${reason}`);
|
|
763
766
|
await this.applySubagentStatusBySessionId(
|
|
764
767
|
subSessionId,
|
|
765
768
|
reason === "aborted" ? "cancelled" : "completed",
|
|
@@ -825,24 +828,22 @@ export class UnifiedSessionPersistenceService {
|
|
|
825
828
|
const { path: manifestPath } = this.readManifestFile(latest.sessionId);
|
|
826
829
|
this.writeManifestFile(manifestPath, manifest);
|
|
827
830
|
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
);
|
|
845
|
-
|
|
831
|
+
{
|
|
832
|
+
const envPath = process.env.CLINE_HOOKS_LOG_PATH?.trim() || undefined;
|
|
833
|
+
const logPath = envPath ?? join(ensureHookLogDir(), "hooks.jsonl");
|
|
834
|
+
appendFileSync(
|
|
835
|
+
logPath,
|
|
836
|
+
`${JSON.stringify({
|
|
837
|
+
ts: detectedAt,
|
|
838
|
+
hookName: "session_shutdown",
|
|
839
|
+
reason,
|
|
840
|
+
sessionId: latest.sessionId,
|
|
841
|
+
pid: latest.pid,
|
|
842
|
+
source: UnifiedSessionPersistenceService.STALE_SOURCE,
|
|
843
|
+
})}\n`,
|
|
844
|
+
"utf8",
|
|
845
|
+
);
|
|
846
|
+
}
|
|
846
847
|
return {
|
|
847
848
|
...latest,
|
|
848
849
|
status: "failed",
|
|
@@ -907,22 +908,37 @@ export class UnifiedSessionPersistenceService {
|
|
|
907
908
|
parentSessionId: id,
|
|
908
909
|
});
|
|
909
910
|
await this.adapter.deleteSession(id, true);
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
911
|
+
await Promise.allSettled(
|
|
912
|
+
children.map(async (child) => {
|
|
913
|
+
await deleteCheckpointRefs(child.cwd, child.sessionId);
|
|
914
|
+
unlinkIfExists(child.messagesPath);
|
|
915
|
+
unlinkIfExists(
|
|
916
|
+
this.artifacts.sessionManifestPath(child.sessionId, false),
|
|
917
|
+
);
|
|
918
|
+
this.artifacts.removeSessionDirIfEmpty(child.sessionId);
|
|
919
|
+
}),
|
|
920
|
+
);
|
|
919
921
|
}
|
|
920
922
|
|
|
921
|
-
|
|
922
|
-
|
|
923
|
+
await deleteCheckpointRefs(row.cwd, id);
|
|
924
|
+
|
|
923
925
|
unlinkIfExists(row.messagesPath);
|
|
924
926
|
unlinkIfExists(this.artifacts.sessionManifestPath(id, false));
|
|
925
|
-
|
|
927
|
+
if (row.isSubagent) {
|
|
928
|
+
this.artifacts.removeSessionDirIfEmpty(id);
|
|
929
|
+
} else {
|
|
930
|
+
const candidateDirs = new Set<string>([
|
|
931
|
+
this.artifacts.sessionArtifactsDir(id),
|
|
932
|
+
]);
|
|
933
|
+
for (const path of [row.messagesPath]) {
|
|
934
|
+
if (typeof path === "string" && path.trim().length > 0) {
|
|
935
|
+
candidateDirs.add(dirname(path));
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
for (const dir of candidateDirs) {
|
|
939
|
+
this.artifacts.removeDir(dir);
|
|
940
|
+
}
|
|
941
|
+
}
|
|
926
942
|
return { deleted: true };
|
|
927
943
|
}
|
|
928
944
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { existsSync, mkdirSync } from "node:fs";
|
|
2
2
|
import { RpcSessionClient, type RpcSessionRow } from "@clinebot/rpc";
|
|
3
|
+
import type { SessionMessagesArtifactUploader } from "../types/session";
|
|
3
4
|
import type {
|
|
4
5
|
PersistedSessionUpdateInput,
|
|
5
6
|
SessionPersistenceAdapter,
|
|
@@ -79,19 +80,25 @@ class RpcSessionPersistenceAdapter implements SessionPersistenceAdapter {
|
|
|
79
80
|
export interface RpcCoreSessionServiceOptions {
|
|
80
81
|
address?: string;
|
|
81
82
|
sessionsDir: string;
|
|
83
|
+
messagesArtifactUploader?: SessionMessagesArtifactUploader;
|
|
82
84
|
}
|
|
83
85
|
|
|
84
86
|
export class RpcCoreSessionService extends UnifiedSessionPersistenceService {
|
|
85
87
|
private readonly sessionsDirPath: string;
|
|
86
88
|
private readonly client: RpcSessionClient;
|
|
89
|
+
public readonly address: string;
|
|
87
90
|
|
|
88
91
|
constructor(options: RpcCoreSessionServiceOptions) {
|
|
92
|
+
const address = options.address?.trim() || "127.0.0.1:4317";
|
|
89
93
|
const client = new RpcSessionClient({
|
|
90
|
-
address
|
|
94
|
+
address,
|
|
95
|
+
});
|
|
96
|
+
super(new RpcSessionPersistenceAdapter(client), {
|
|
97
|
+
messagesArtifactUploader: options.messagesArtifactUploader,
|
|
91
98
|
});
|
|
92
|
-
super(new RpcSessionPersistenceAdapter(client));
|
|
93
99
|
this.sessionsDirPath = options.sessionsDir;
|
|
94
100
|
this.client = client;
|
|
101
|
+
this.address = address;
|
|
95
102
|
}
|
|
96
103
|
|
|
97
104
|
override ensureSessionsDir(): string {
|
|
@@ -2,7 +2,7 @@ import { existsSync, mkdtempSync } from "node:fs";
|
|
|
2
2
|
import { tmpdir } from "node:os";
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import { describe, expect, it } from "vitest";
|
|
5
|
-
import { AgentTeamsRuntime } from "../team";
|
|
5
|
+
import { AgentTeamsRuntime } from "../extensions/tools/team";
|
|
6
6
|
import { FileTeamPersistenceStore } from "./session-service";
|
|
7
7
|
|
|
8
8
|
describe("FileTeamPersistenceStore", () => {
|