@clinebot/core 0.0.20 → 0.0.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/account/cline-account-service.d.ts +3 -2
- package/dist/account/cline-account-service.d.ts.map +1 -0
- package/dist/account/index.d.ts +1 -0
- package/dist/account/index.d.ts.map +1 -0
- package/dist/account/rpc.d.ts +1 -0
- package/dist/account/rpc.d.ts.map +1 -0
- package/dist/account/types.d.ts +1 -0
- package/dist/account/types.d.ts.map +1 -0
- package/dist/agents/agent-config-loader.d.ts +1 -0
- package/dist/agents/agent-config-loader.d.ts.map +1 -0
- package/dist/agents/agent-config-parser.d.ts +1 -0
- package/dist/agents/agent-config-parser.d.ts.map +1 -0
- package/dist/agents/hooks-config-loader.d.ts +1 -0
- package/dist/agents/hooks-config-loader.d.ts.map +1 -0
- package/dist/agents/index.d.ts +1 -0
- package/dist/agents/index.d.ts.map +1 -0
- package/dist/agents/plugin-config-loader.d.ts +1 -0
- package/dist/agents/plugin-config-loader.d.ts.map +1 -0
- package/dist/agents/plugin-loader.d.ts +1 -0
- package/dist/agents/plugin-loader.d.ts.map +1 -0
- package/dist/agents/plugin-sandbox.d.ts +1 -0
- package/dist/agents/plugin-sandbox.d.ts.map +1 -0
- package/dist/agents/unified-config-file-watcher.d.ts +1 -0
- package/dist/agents/unified-config-file-watcher.d.ts.map +1 -0
- package/dist/agents/user-instruction-config-loader.d.ts +1 -0
- package/dist/agents/user-instruction-config-loader.d.ts.map +1 -0
- package/dist/auth/client.d.ts +1 -0
- package/dist/auth/client.d.ts.map +1 -0
- package/dist/auth/cline.d.ts +1 -0
- package/dist/auth/cline.d.ts.map +1 -0
- package/dist/auth/codex.d.ts +1 -0
- package/dist/auth/codex.d.ts.map +1 -0
- package/dist/auth/oca.d.ts +1 -0
- package/dist/auth/oca.d.ts.map +1 -0
- package/dist/auth/server.d.ts +1 -0
- package/dist/auth/server.d.ts.map +1 -0
- package/dist/auth/types.d.ts +1 -0
- package/dist/auth/types.d.ts.map +1 -0
- package/dist/auth/utils.d.ts +1 -0
- package/dist/auth/utils.d.ts.map +1 -0
- package/dist/chat/chat-schema.d.ts +13 -12
- package/dist/chat/chat-schema.d.ts.map +1 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -0
- package/dist/index.node.d.ts +2 -0
- package/dist/index.node.d.ts.map +1 -0
- package/dist/index.node.js +303 -302
- package/dist/input/file-indexer.d.ts +1 -0
- package/dist/input/file-indexer.d.ts.map +1 -0
- package/dist/input/index.d.ts +1 -0
- package/dist/input/index.d.ts.map +1 -0
- package/dist/input/mention-enricher.d.ts +1 -0
- package/dist/input/mention-enricher.d.ts.map +1 -0
- package/dist/mcp/config-loader.d.ts +1 -0
- package/dist/mcp/config-loader.d.ts.map +1 -0
- package/dist/mcp/index.d.ts +1 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/manager.d.ts +1 -0
- package/dist/mcp/manager.d.ts.map +1 -0
- package/dist/mcp/types.d.ts +1 -0
- package/dist/mcp/types.d.ts.map +1 -0
- package/dist/providers/local-provider-registry.d.ts +36 -0
- package/dist/providers/local-provider-registry.d.ts.map +1 -0
- package/dist/providers/local-provider-service.d.ts +2 -1
- package/dist/providers/local-provider-service.d.ts.map +1 -0
- package/dist/runtime/commands.d.ts +1 -0
- package/dist/runtime/commands.d.ts.map +1 -0
- package/dist/runtime/hook-file-hooks.d.ts +1 -0
- package/dist/runtime/hook-file-hooks.d.ts.map +1 -0
- package/dist/runtime/rules.d.ts +1 -0
- package/dist/runtime/rules.d.ts.map +1 -0
- package/dist/runtime/runtime-builder.d.ts +1 -0
- package/dist/runtime/runtime-builder.d.ts.map +1 -0
- package/dist/runtime/sandbox/subprocess-sandbox.d.ts +1 -0
- package/dist/runtime/sandbox/subprocess-sandbox.d.ts.map +1 -0
- package/dist/runtime/session-runtime.d.ts +2 -0
- package/dist/runtime/session-runtime.d.ts.map +1 -0
- package/dist/runtime/skills.d.ts +1 -0
- package/dist/runtime/skills.d.ts.map +1 -0
- package/dist/runtime/tool-approval.d.ts +1 -0
- package/dist/runtime/tool-approval.d.ts.map +1 -0
- package/dist/runtime/workflows.d.ts +1 -0
- package/dist/runtime/workflows.d.ts.map +1 -0
- package/dist/session/default-session-manager.d.ts +4 -0
- package/dist/session/default-session-manager.d.ts.map +1 -0
- package/dist/session/file-session-service.d.ts +1 -0
- package/dist/session/file-session-service.d.ts.map +1 -0
- package/dist/session/rpc-session-service.d.ts +1 -0
- package/dist/session/rpc-session-service.d.ts.map +1 -0
- package/dist/session/rpc-spawn-lease.d.ts +1 -0
- package/dist/session/rpc-spawn-lease.d.ts.map +1 -0
- package/dist/session/runtime-oauth-token-manager.d.ts +1 -0
- package/dist/session/runtime-oauth-token-manager.d.ts.map +1 -0
- package/dist/session/session-agent-events.d.ts +20 -1
- package/dist/session/session-agent-events.d.ts.map +1 -0
- package/dist/session/session-artifacts.d.ts +1 -0
- package/dist/session/session-artifacts.d.ts.map +1 -0
- package/dist/session/session-config-builder.d.ts +1 -0
- package/dist/session/session-config-builder.d.ts.map +1 -0
- package/dist/session/session-graph.d.ts +1 -0
- package/dist/session/session-graph.d.ts.map +1 -0
- package/dist/session/session-host.d.ts +1 -0
- package/dist/session/session-host.d.ts.map +1 -0
- package/dist/session/session-manager.d.ts +1 -0
- package/dist/session/session-manager.d.ts.map +1 -0
- package/dist/session/session-manifest.d.ts +2 -1
- package/dist/session/session-manifest.d.ts.map +1 -0
- package/dist/session/session-service.d.ts +1 -0
- package/dist/session/session-service.d.ts.map +1 -0
- package/dist/session/session-team-coordination.d.ts +1 -0
- package/dist/session/session-team-coordination.d.ts.map +1 -0
- package/dist/session/session-telemetry.d.ts +3 -1
- package/dist/session/session-telemetry.d.ts.map +1 -0
- package/dist/session/sqlite-rpc-session-backend.d.ts +1 -0
- package/dist/session/sqlite-rpc-session-backend.d.ts.map +1 -0
- package/dist/session/unified-session-persistence-service.d.ts +1 -0
- package/dist/session/unified-session-persistence-service.d.ts.map +1 -0
- package/dist/session/utils/helpers.d.ts +1 -0
- package/dist/session/utils/helpers.d.ts.map +1 -0
- package/dist/session/utils/types.d.ts +1 -0
- package/dist/session/utils/types.d.ts.map +1 -0
- package/dist/session/utils/usage.d.ts +1 -0
- package/dist/session/utils/usage.d.ts.map +1 -0
- package/dist/session/workspace-manager.d.ts +1 -0
- package/dist/session/workspace-manager.d.ts.map +1 -0
- package/dist/session/workspace-manifest.d.ts +1 -0
- package/dist/session/workspace-manifest.d.ts.map +1 -0
- package/dist/storage/file-team-store.d.ts +1 -0
- package/dist/storage/file-team-store.d.ts.map +1 -0
- package/dist/storage/provider-settings-legacy-migration.d.ts +1 -0
- package/dist/storage/provider-settings-legacy-migration.d.ts.map +1 -0
- package/dist/storage/provider-settings-manager.d.ts +1 -0
- package/dist/storage/provider-settings-manager.d.ts.map +1 -0
- package/dist/storage/sqlite-session-store.d.ts +1 -0
- package/dist/storage/sqlite-session-store.d.ts.map +1 -0
- package/dist/storage/sqlite-team-store.d.ts +1 -0
- package/dist/storage/sqlite-team-store.d.ts.map +1 -0
- package/dist/storage/team-store.d.ts +1 -0
- package/dist/storage/team-store.d.ts.map +1 -0
- package/dist/team/index.d.ts +1 -0
- package/dist/team/index.d.ts.map +1 -0
- package/dist/team/projections.d.ts +1 -0
- package/dist/team/projections.d.ts.map +1 -0
- package/dist/telemetry/ITelemetryAdapter.d.ts +1 -0
- package/dist/telemetry/ITelemetryAdapter.d.ts.map +1 -0
- package/dist/telemetry/LoggerTelemetryAdapter.d.ts +1 -0
- package/dist/telemetry/LoggerTelemetryAdapter.d.ts.map +1 -0
- package/dist/telemetry/OpenTelemetryAdapter.d.ts +1 -0
- package/dist/telemetry/OpenTelemetryAdapter.d.ts.map +1 -0
- package/dist/telemetry/OpenTelemetryProvider.d.ts +1 -0
- package/dist/telemetry/OpenTelemetryProvider.d.ts.map +1 -0
- package/dist/telemetry/TelemetryService.d.ts +1 -0
- package/dist/telemetry/TelemetryService.d.ts.map +1 -0
- package/dist/telemetry/core-events.d.ts +55 -22
- package/dist/telemetry/core-events.d.ts.map +1 -0
- package/dist/telemetry/opentelemetry.d.ts +1 -0
- package/dist/telemetry/opentelemetry.d.ts.map +1 -0
- package/dist/tools/constants.d.ts +1 -0
- package/dist/tools/constants.d.ts.map +1 -0
- package/dist/tools/definitions.d.ts +8 -1
- package/dist/tools/definitions.d.ts.map +1 -0
- package/dist/tools/executors/apply-patch-parser.d.ts +1 -0
- package/dist/tools/executors/apply-patch-parser.d.ts.map +1 -0
- package/dist/tools/executors/apply-patch.d.ts +1 -0
- package/dist/tools/executors/apply-patch.d.ts.map +1 -0
- package/dist/tools/executors/bash.d.ts +2 -1
- package/dist/tools/executors/bash.d.ts.map +1 -0
- package/dist/tools/executors/editor.d.ts +1 -0
- package/dist/tools/executors/editor.d.ts.map +1 -0
- package/dist/tools/executors/file-read.d.ts +1 -0
- package/dist/tools/executors/file-read.d.ts.map +1 -0
- package/dist/tools/executors/index.d.ts +14 -7
- package/dist/tools/executors/index.d.ts.map +1 -0
- package/dist/tools/executors/search.d.ts +1 -0
- package/dist/tools/executors/search.d.ts.map +1 -0
- package/dist/tools/executors/web-fetch.d.ts +1 -0
- package/dist/tools/executors/web-fetch.d.ts.map +1 -0
- package/dist/tools/helpers.d.ts +15 -0
- package/dist/tools/helpers.d.ts.map +1 -0
- package/dist/tools/index.d.ts +2 -1
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/model-tool-routing.d.ts +1 -0
- package/dist/tools/model-tool-routing.d.ts.map +1 -0
- package/dist/tools/presets.d.ts +1 -0
- package/dist/tools/presets.d.ts.map +1 -0
- package/dist/tools/schemas.d.ts +41 -0
- package/dist/tools/schemas.d.ts.map +1 -0
- package/dist/tools/types.d.ts +3 -2
- package/dist/tools/types.d.ts.map +1 -0
- package/dist/types/common.d.ts +1 -0
- package/dist/types/common.d.ts.map +1 -0
- package/dist/types/config.d.ts +1 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/events.d.ts +1 -0
- package/dist/types/events.d.ts.map +1 -0
- package/dist/types/provider-settings.d.ts +1 -0
- package/dist/types/provider-settings.d.ts.map +1 -0
- package/dist/types/sessions.d.ts +1 -0
- package/dist/types/sessions.d.ts.map +1 -0
- package/dist/types/storage.d.ts +1 -0
- package/dist/types/storage.d.ts.map +1 -0
- package/dist/types/workspace.d.ts +1 -0
- package/dist/types/workspace.d.ts.map +1 -0
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +6 -4
- package/src/account/cline-account-service.test.ts +0 -101
- package/src/account/cline-account-service.ts +0 -287
- package/src/account/index.ts +0 -22
- package/src/account/rpc.test.ts +0 -62
- package/src/account/rpc.ts +0 -172
- package/src/account/types.ts +0 -98
- package/src/agents/agent-config-loader.test.ts +0 -236
- package/src/agents/agent-config-loader.ts +0 -108
- package/src/agents/agent-config-parser.ts +0 -198
- package/src/agents/hooks-config-loader.test.ts +0 -20
- package/src/agents/hooks-config-loader.ts +0 -118
- package/src/agents/index.ts +0 -85
- package/src/agents/plugin-config-loader.test.ts +0 -140
- package/src/agents/plugin-config-loader.ts +0 -97
- package/src/agents/plugin-loader.test.ts +0 -228
- package/src/agents/plugin-loader.ts +0 -172
- package/src/agents/plugin-sandbox-bootstrap.ts +0 -445
- package/src/agents/plugin-sandbox.test.ts +0 -317
- package/src/agents/plugin-sandbox.ts +0 -341
- package/src/agents/unified-config-file-watcher.test.ts +0 -196
- package/src/agents/unified-config-file-watcher.ts +0 -483
- package/src/agents/user-instruction-config-loader.test.ts +0 -158
- package/src/agents/user-instruction-config-loader.ts +0 -438
- package/src/auth/client.test.ts +0 -40
- package/src/auth/client.ts +0 -25
- package/src/auth/cline.test.ts +0 -130
- package/src/auth/cline.ts +0 -420
- package/src/auth/codex.test.ts +0 -170
- package/src/auth/codex.ts +0 -491
- package/src/auth/oca.test.ts +0 -215
- package/src/auth/oca.ts +0 -573
- package/src/auth/server.ts +0 -216
- package/src/auth/types.ts +0 -81
- package/src/auth/utils.test.ts +0 -128
- package/src/auth/utils.ts +0 -247
- package/src/chat/chat-schema.ts +0 -82
- package/src/index.node.ts +0 -285
- package/src/index.ts +0 -211
- package/src/input/file-indexer.d.ts +0 -11
- package/src/input/file-indexer.test.ts +0 -127
- package/src/input/file-indexer.ts +0 -327
- package/src/input/index.ts +0 -7
- package/src/input/mention-enricher.test.ts +0 -85
- package/src/input/mention-enricher.ts +0 -122
- package/src/mcp/config-loader.test.ts +0 -238
- package/src/mcp/config-loader.ts +0 -219
- package/src/mcp/index.ts +0 -26
- package/src/mcp/manager.test.ts +0 -106
- package/src/mcp/manager.ts +0 -262
- package/src/mcp/types.ts +0 -88
- package/src/providers/local-provider-service.ts +0 -608
- package/src/runtime/commands.test.ts +0 -98
- package/src/runtime/commands.ts +0 -83
- package/src/runtime/hook-file-hooks.test.ts +0 -237
- package/src/runtime/hook-file-hooks.ts +0 -859
- package/src/runtime/index.ts +0 -37
- package/src/runtime/rules.ts +0 -34
- package/src/runtime/runtime-builder.team-persistence.test.ts +0 -202
- package/src/runtime/runtime-builder.test.ts +0 -371
- package/src/runtime/runtime-builder.ts +0 -589
- package/src/runtime/runtime-parity.test.ts +0 -143
- package/src/runtime/sandbox/subprocess-sandbox.ts +0 -231
- package/src/runtime/session-runtime.ts +0 -46
- package/src/runtime/skills.ts +0 -44
- package/src/runtime/tool-approval.ts +0 -104
- package/src/runtime/workflows.test.ts +0 -119
- package/src/runtime/workflows.ts +0 -45
- package/src/session/default-session-manager.e2e.test.ts +0 -384
- package/src/session/default-session-manager.test.ts +0 -1741
- package/src/session/default-session-manager.ts +0 -1233
- package/src/session/file-session-service.ts +0 -280
- package/src/session/index.ts +0 -42
- 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/runtime-oauth-token-manager.ts +0 -272
- package/src/session/session-agent-events.ts +0 -159
- package/src/session/session-artifacts.ts +0 -106
- package/src/session/session-config-builder.ts +0 -113
- package/src/session/session-graph.ts +0 -92
- package/src/session/session-host.test.ts +0 -29
- package/src/session/session-host.ts +0 -242
- package/src/session/session-manager.ts +0 -69
- package/src/session/session-manifest.ts +0 -29
- package/src/session/session-service.team-persistence.test.ts +0 -48
- package/src/session/session-service.ts +0 -673
- package/src/session/session-team-coordination.ts +0 -229
- package/src/session/session-telemetry.ts +0 -95
- package/src/session/sqlite-rpc-session-backend.ts +0 -303
- package/src/session/unified-session-persistence-service.test.ts +0 -85
- package/src/session/unified-session-persistence-service.ts +0 -996
- package/src/session/utils/helpers.ts +0 -139
- package/src/session/utils/types.ts +0 -57
- package/src/session/utils/usage.ts +0 -32
- package/src/session/workspace-manager.ts +0 -98
- package/src/session/workspace-manifest.ts +0 -100
- package/src/storage/artifact-store.ts +0 -1
- package/src/storage/file-team-store.ts +0 -257
- package/src/storage/index.ts +0 -11
- package/src/storage/provider-settings-legacy-migration.test.ts +0 -307
- package/src/storage/provider-settings-legacy-migration.ts +0 -689
- package/src/storage/provider-settings-manager.test.ts +0 -145
- package/src/storage/provider-settings-manager.ts +0 -150
- package/src/storage/session-store.ts +0 -1
- package/src/storage/sqlite-session-store.ts +0 -275
- package/src/storage/sqlite-team-store.ts +0 -454
- package/src/storage/team-store.ts +0 -40
- package/src/team/index.ts +0 -4
- package/src/team/projections.ts +0 -285
- package/src/telemetry/ITelemetryAdapter.ts +0 -94
- package/src/telemetry/LoggerTelemetryAdapter.test.ts +0 -42
- package/src/telemetry/LoggerTelemetryAdapter.ts +0 -114
- package/src/telemetry/OpenTelemetryAdapter.test.ts +0 -157
- package/src/telemetry/OpenTelemetryAdapter.ts +0 -348
- package/src/telemetry/OpenTelemetryProvider.test.ts +0 -113
- package/src/telemetry/OpenTelemetryProvider.ts +0 -322
- package/src/telemetry/TelemetryService.test.ts +0 -134
- package/src/telemetry/TelemetryService.ts +0 -141
- package/src/telemetry/core-events.ts +0 -344
- package/src/telemetry/opentelemetry.ts +0 -20
- package/src/tools/constants.ts +0 -35
- package/src/tools/definitions.test.ts +0 -658
- package/src/tools/definitions.ts +0 -726
- package/src/tools/executors/apply-patch-parser.ts +0 -520
- package/src/tools/executors/apply-patch.ts +0 -359
- package/src/tools/executors/bash.ts +0 -205
- package/src/tools/executors/editor.test.ts +0 -35
- package/src/tools/executors/editor.ts +0 -219
- package/src/tools/executors/file-read.test.ts +0 -49
- package/src/tools/executors/file-read.ts +0 -110
- package/src/tools/executors/index.ts +0 -75
- package/src/tools/executors/search.ts +0 -278
- package/src/tools/executors/web-fetch.ts +0 -259
- package/src/tools/index.ts +0 -168
- package/src/tools/model-tool-routing.test.ts +0 -86
- package/src/tools/model-tool-routing.ts +0 -132
- package/src/tools/presets.test.ts +0 -62
- package/src/tools/presets.ts +0 -168
- package/src/tools/schemas.ts +0 -284
- package/src/tools/types.ts +0 -328
- package/src/types/common.ts +0 -14
- package/src/types/config.ts +0 -84
- package/src/types/events.ts +0 -74
- package/src/types/index.ts +0 -24
- package/src/types/provider-settings.ts +0 -43
- package/src/types/sessions.ts +0 -16
- package/src/types/storage.ts +0 -64
- package/src/types/workspace.ts +0 -7
- package/src/types.ts +0 -128
package/src/runtime/workflows.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import type { UserInstructionConfigWatcher } from "../agents";
|
|
2
|
-
import {
|
|
3
|
-
listAvailableRuntimeCommandsForKindFromWatcher,
|
|
4
|
-
resolveRuntimeSlashCommandFromWatcher,
|
|
5
|
-
} from "./commands";
|
|
6
|
-
|
|
7
|
-
export type AvailableWorkflow = {
|
|
8
|
-
id: string;
|
|
9
|
-
name: string;
|
|
10
|
-
instructions: string;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
function matchesLeadingSlashCommand(input: string, name: string): boolean {
|
|
14
|
-
const match = input.match(/^\/(\S+)/);
|
|
15
|
-
return match?.[1] === name;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function listAvailableWorkflowsFromWatcher(
|
|
19
|
-
watcher: UserInstructionConfigWatcher,
|
|
20
|
-
): AvailableWorkflow[] {
|
|
21
|
-
return listAvailableRuntimeCommandsForKindFromWatcher(
|
|
22
|
-
watcher,
|
|
23
|
-
"workflow",
|
|
24
|
-
).map((workflow) => ({
|
|
25
|
-
id: workflow.id,
|
|
26
|
-
name: workflow.name,
|
|
27
|
-
instructions: workflow.instructions,
|
|
28
|
-
}));
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Expands a leading slash command (e.g. "/release") to workflow instructions.
|
|
33
|
-
* If the input starts with "/<workflow-name>", that prefix is replaced and the
|
|
34
|
-
* remaining input is preserved unchanged.
|
|
35
|
-
*/
|
|
36
|
-
export function resolveWorkflowSlashCommandFromWatcher(
|
|
37
|
-
input: string,
|
|
38
|
-
watcher: UserInstructionConfigWatcher,
|
|
39
|
-
): string {
|
|
40
|
-
const resolved = resolveRuntimeSlashCommandFromWatcher(input, watcher);
|
|
41
|
-
const matched = listAvailableWorkflowsFromWatcher(watcher).some((workflow) =>
|
|
42
|
-
matchesLeadingSlashCommand(input, workflow.name),
|
|
43
|
-
);
|
|
44
|
-
return matched ? resolved : input;
|
|
45
|
-
}
|
|
@@ -1,384 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
existsSync,
|
|
3
|
-
mkdirSync,
|
|
4
|
-
mkdtempSync,
|
|
5
|
-
readFileSync,
|
|
6
|
-
rmSync,
|
|
7
|
-
unlinkSync,
|
|
8
|
-
writeFileSync,
|
|
9
|
-
} from "node:fs";
|
|
10
|
-
import { tmpdir } from "node:os";
|
|
11
|
-
import { join } from "node:path";
|
|
12
|
-
import type { AgentResult } from "@clinebot/agents";
|
|
13
|
-
import type { LlmsProviders } from "@clinebot/llms";
|
|
14
|
-
import { setClineDir, setHomeDir } from "@clinebot/shared/storage";
|
|
15
|
-
import { nanoid } from "nanoid";
|
|
16
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
17
|
-
import type { SessionSource, SessionStatus } from "../types/common";
|
|
18
|
-
import { DefaultSessionManager } from "./default-session-manager";
|
|
19
|
-
import type { SessionManifest } from "./session-manifest";
|
|
20
|
-
import type { RootSessionArtifacts, SessionRow } from "./session-service";
|
|
21
|
-
|
|
22
|
-
function nowIso(): string {
|
|
23
|
-
return new Date().toISOString();
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function createResult(overrides: Partial<AgentResult> = {}): AgentResult {
|
|
27
|
-
return {
|
|
28
|
-
text: "ok",
|
|
29
|
-
iterations: 1,
|
|
30
|
-
finishReason: "completed",
|
|
31
|
-
usage: {
|
|
32
|
-
inputTokens: 1,
|
|
33
|
-
outputTokens: 2,
|
|
34
|
-
totalCost: 0,
|
|
35
|
-
},
|
|
36
|
-
messages: [],
|
|
37
|
-
toolCalls: [],
|
|
38
|
-
durationMs: 1,
|
|
39
|
-
model: {
|
|
40
|
-
id: "mock-model",
|
|
41
|
-
provider: "mock-provider",
|
|
42
|
-
},
|
|
43
|
-
startedAt: new Date("2026-01-01T00:00:00.000Z"),
|
|
44
|
-
endedAt: new Date("2026-01-01T00:00:01.000Z"),
|
|
45
|
-
...overrides,
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
class LocalFileSessionService {
|
|
50
|
-
private readonly rows = new Map<string, SessionRow>();
|
|
51
|
-
|
|
52
|
-
constructor(private readonly sessionsDir: string) {}
|
|
53
|
-
|
|
54
|
-
ensureSessionsDir(): string {
|
|
55
|
-
mkdirSync(this.sessionsDir, { recursive: true });
|
|
56
|
-
return this.sessionsDir;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
createRootSessionWithArtifacts(input: {
|
|
60
|
-
sessionId: string;
|
|
61
|
-
source: SessionSource;
|
|
62
|
-
pid: number;
|
|
63
|
-
interactive: boolean;
|
|
64
|
-
provider: string;
|
|
65
|
-
model: string;
|
|
66
|
-
cwd: string;
|
|
67
|
-
workspaceRoot: string;
|
|
68
|
-
teamName?: string;
|
|
69
|
-
enableTools: boolean;
|
|
70
|
-
enableSpawn: boolean;
|
|
71
|
-
enableTeams: boolean;
|
|
72
|
-
prompt?: string;
|
|
73
|
-
startedAt?: string;
|
|
74
|
-
}): RootSessionArtifacts {
|
|
75
|
-
const startedAt = input.startedAt ?? nowIso();
|
|
76
|
-
const sessionId = input.sessionId.trim() || `${Date.now()}_${nanoid(5)}`;
|
|
77
|
-
const sessionPath = join(this.sessionsDir, sessionId);
|
|
78
|
-
mkdirSync(sessionPath, { recursive: true });
|
|
79
|
-
|
|
80
|
-
const manifestPath = join(sessionPath, `${sessionId}.json`);
|
|
81
|
-
const transcriptPath = join(sessionPath, `${sessionId}.log`);
|
|
82
|
-
const hookPath = join(sessionPath, `${sessionId}.hooks.jsonl`);
|
|
83
|
-
const messagesPath = join(sessionPath, `${sessionId}.messages.json`);
|
|
84
|
-
const prompt = input.prompt?.trim() || undefined;
|
|
85
|
-
const manifest: SessionManifest = {
|
|
86
|
-
version: 1,
|
|
87
|
-
session_id: sessionId,
|
|
88
|
-
source: input.source,
|
|
89
|
-
pid: input.pid,
|
|
90
|
-
started_at: startedAt,
|
|
91
|
-
status: "running",
|
|
92
|
-
interactive: input.interactive,
|
|
93
|
-
provider: input.provider,
|
|
94
|
-
model: input.model,
|
|
95
|
-
cwd: input.cwd,
|
|
96
|
-
workspace_root: input.workspaceRoot,
|
|
97
|
-
team_name: input.teamName,
|
|
98
|
-
enable_tools: input.enableTools,
|
|
99
|
-
enable_spawn: input.enableSpawn,
|
|
100
|
-
enable_teams: input.enableTeams,
|
|
101
|
-
prompt,
|
|
102
|
-
messages_path: messagesPath,
|
|
103
|
-
};
|
|
104
|
-
writeFileSync(
|
|
105
|
-
manifestPath,
|
|
106
|
-
`${JSON.stringify(manifest, null, 2)}\n`,
|
|
107
|
-
"utf8",
|
|
108
|
-
);
|
|
109
|
-
writeFileSync(transcriptPath, "", "utf8");
|
|
110
|
-
writeFileSync(hookPath, "", "utf8");
|
|
111
|
-
writeFileSync(
|
|
112
|
-
messagesPath,
|
|
113
|
-
`${JSON.stringify({ version: 1, updated_at: startedAt, messages: [] }, null, 2)}\n`,
|
|
114
|
-
"utf8",
|
|
115
|
-
);
|
|
116
|
-
|
|
117
|
-
this.rows.set(sessionId, {
|
|
118
|
-
sessionId,
|
|
119
|
-
source: input.source,
|
|
120
|
-
pid: input.pid,
|
|
121
|
-
startedAt,
|
|
122
|
-
endedAt: null,
|
|
123
|
-
exitCode: null,
|
|
124
|
-
status: "running",
|
|
125
|
-
statusLock: 0,
|
|
126
|
-
interactive: input.interactive,
|
|
127
|
-
provider: input.provider,
|
|
128
|
-
model: input.model,
|
|
129
|
-
cwd: input.cwd,
|
|
130
|
-
workspaceRoot: input.workspaceRoot,
|
|
131
|
-
teamName: input.teamName ?? null,
|
|
132
|
-
enableTools: input.enableTools,
|
|
133
|
-
enableSpawn: input.enableSpawn,
|
|
134
|
-
enableTeams: input.enableTeams,
|
|
135
|
-
parentSessionId: null,
|
|
136
|
-
parentAgentId: null,
|
|
137
|
-
agentId: null,
|
|
138
|
-
conversationId: null,
|
|
139
|
-
isSubagent: false,
|
|
140
|
-
prompt: prompt ?? null,
|
|
141
|
-
transcriptPath,
|
|
142
|
-
hookPath,
|
|
143
|
-
messagesPath,
|
|
144
|
-
updatedAt: startedAt,
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
return {
|
|
148
|
-
manifestPath,
|
|
149
|
-
transcriptPath,
|
|
150
|
-
hookPath,
|
|
151
|
-
messagesPath,
|
|
152
|
-
manifest,
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
persistSessionMessages(
|
|
157
|
-
sessionId: string,
|
|
158
|
-
messages: LlmsProviders.Message[],
|
|
159
|
-
systemPrompt?: string,
|
|
160
|
-
): void {
|
|
161
|
-
const row = this.rows.get(sessionId);
|
|
162
|
-
if (!row?.messagesPath) {
|
|
163
|
-
throw new Error(`session not found: ${sessionId}`);
|
|
164
|
-
}
|
|
165
|
-
const payload: {
|
|
166
|
-
version: number;
|
|
167
|
-
updated_at: string;
|
|
168
|
-
systemPrompt?: string;
|
|
169
|
-
messages: LlmsProviders.Message[];
|
|
170
|
-
} = { version: 1, updated_at: nowIso(), messages };
|
|
171
|
-
if (systemPrompt !== undefined && systemPrompt !== "") {
|
|
172
|
-
payload.systemPrompt = systemPrompt;
|
|
173
|
-
}
|
|
174
|
-
writeFileSync(
|
|
175
|
-
row.messagesPath,
|
|
176
|
-
`${JSON.stringify(payload, null, 2)}\n`,
|
|
177
|
-
"utf8",
|
|
178
|
-
);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
updateSessionStatus(
|
|
182
|
-
sessionId: string,
|
|
183
|
-
status: SessionStatus,
|
|
184
|
-
exitCode?: number | null,
|
|
185
|
-
): { updated: boolean; endedAt?: string } {
|
|
186
|
-
const row = this.rows.get(sessionId);
|
|
187
|
-
if (!row) {
|
|
188
|
-
return { updated: false };
|
|
189
|
-
}
|
|
190
|
-
const endedAt = nowIso();
|
|
191
|
-
row.status = status;
|
|
192
|
-
row.endedAt = endedAt;
|
|
193
|
-
row.exitCode = typeof exitCode === "number" ? exitCode : null;
|
|
194
|
-
row.updatedAt = endedAt;
|
|
195
|
-
row.statusLock = row.statusLock + 1;
|
|
196
|
-
return { updated: true, endedAt };
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
writeSessionManifest(manifestPath: string, manifest: SessionManifest): void {
|
|
200
|
-
writeFileSync(
|
|
201
|
-
manifestPath,
|
|
202
|
-
`${JSON.stringify(manifest, null, 2)}\n`,
|
|
203
|
-
"utf8",
|
|
204
|
-
);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
listSessions(limit = 200): SessionRow[] {
|
|
208
|
-
return Array.from(this.rows.values()).slice(0, limit);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
deleteSession(sessionId: string): { deleted: boolean } {
|
|
212
|
-
const row = this.rows.get(sessionId);
|
|
213
|
-
if (!row) {
|
|
214
|
-
return { deleted: false };
|
|
215
|
-
}
|
|
216
|
-
this.rows.delete(sessionId);
|
|
217
|
-
unlinkSync(row.transcriptPath);
|
|
218
|
-
unlinkSync(row.hookPath);
|
|
219
|
-
unlinkSync(row.messagesPath ?? "");
|
|
220
|
-
unlinkSync(join(this.sessionsDir, sessionId, `${sessionId}.json`));
|
|
221
|
-
return { deleted: true };
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
describe("DefaultSessionManager e2e", () => {
|
|
226
|
-
const envSnapshot = {
|
|
227
|
-
HOME: process.env.HOME,
|
|
228
|
-
CLINE_DIR: process.env.CLINE_DIR,
|
|
229
|
-
};
|
|
230
|
-
const tempDirs: string[] = [];
|
|
231
|
-
let isolatedHomeDir = "";
|
|
232
|
-
|
|
233
|
-
beforeEach(() => {
|
|
234
|
-
isolatedHomeDir = mkdtempSync(join(tmpdir(), "core-session-home-"));
|
|
235
|
-
process.env.HOME = isolatedHomeDir;
|
|
236
|
-
process.env.CLINE_DIR = join(isolatedHomeDir, ".cline");
|
|
237
|
-
setHomeDir(isolatedHomeDir);
|
|
238
|
-
setClineDir(process.env.CLINE_DIR);
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
afterEach(() => {
|
|
242
|
-
process.env.HOME = envSnapshot.HOME;
|
|
243
|
-
process.env.CLINE_DIR = envSnapshot.CLINE_DIR;
|
|
244
|
-
setHomeDir(envSnapshot.HOME ?? "~");
|
|
245
|
-
setClineDir(envSnapshot.CLINE_DIR ?? join("~", ".cline"));
|
|
246
|
-
for (const dir of tempDirs.splice(0)) {
|
|
247
|
-
rmSync(dir, { recursive: true, force: true });
|
|
248
|
-
}
|
|
249
|
-
rmSync(isolatedHomeDir, { recursive: true, force: true });
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
it("runs an interactive lifecycle with real artifact files", async () => {
|
|
253
|
-
const sessionsDir = mkdtempSync(join(tmpdir(), "core-e2e-sessions-"));
|
|
254
|
-
tempDirs.push(sessionsDir);
|
|
255
|
-
|
|
256
|
-
const sessionService = new LocalFileSessionService(sessionsDir);
|
|
257
|
-
const runtimeShutdown = vi.fn();
|
|
258
|
-
const runtimeBuilder = {
|
|
259
|
-
build: vi.fn().mockReturnValue({
|
|
260
|
-
tools: [],
|
|
261
|
-
shutdown: runtimeShutdown,
|
|
262
|
-
}),
|
|
263
|
-
};
|
|
264
|
-
|
|
265
|
-
let messages: LlmsProviders.Message[] = [];
|
|
266
|
-
let turn = 0;
|
|
267
|
-
const run = vi.fn(async (prompt: string) => {
|
|
268
|
-
turn += 1;
|
|
269
|
-
messages = [
|
|
270
|
-
...messages,
|
|
271
|
-
{
|
|
272
|
-
role: "user",
|
|
273
|
-
content: [{ type: "text", text: prompt }],
|
|
274
|
-
},
|
|
275
|
-
{
|
|
276
|
-
role: "assistant",
|
|
277
|
-
content: [{ type: "text", text: `reply:${turn}:${prompt}` }],
|
|
278
|
-
},
|
|
279
|
-
] as LlmsProviders.Message[];
|
|
280
|
-
return createResult({
|
|
281
|
-
text: `reply:${turn}:${prompt}`,
|
|
282
|
-
messages: [...messages],
|
|
283
|
-
});
|
|
284
|
-
});
|
|
285
|
-
const continueFn = vi.fn(async (prompt: string) => {
|
|
286
|
-
turn += 1;
|
|
287
|
-
messages = [
|
|
288
|
-
...messages,
|
|
289
|
-
{
|
|
290
|
-
role: "user",
|
|
291
|
-
content: [{ type: "text", text: prompt }],
|
|
292
|
-
},
|
|
293
|
-
{
|
|
294
|
-
role: "assistant",
|
|
295
|
-
content: [{ type: "text", text: `reply:${turn}:${prompt}` }],
|
|
296
|
-
},
|
|
297
|
-
] as LlmsProviders.Message[];
|
|
298
|
-
return createResult({
|
|
299
|
-
text: `reply:${turn}:${prompt}`,
|
|
300
|
-
messages: [...messages],
|
|
301
|
-
});
|
|
302
|
-
});
|
|
303
|
-
const agentShutdown = vi.fn().mockResolvedValue(undefined);
|
|
304
|
-
|
|
305
|
-
const manager = new DefaultSessionManager({
|
|
306
|
-
distinctId: `test-${nanoid(5)}`,
|
|
307
|
-
sessionService: sessionService as never,
|
|
308
|
-
runtimeBuilder: runtimeBuilder as never,
|
|
309
|
-
createAgent: () =>
|
|
310
|
-
({
|
|
311
|
-
run,
|
|
312
|
-
continue: continueFn,
|
|
313
|
-
abort: vi.fn(),
|
|
314
|
-
restore: vi.fn((baseline: LlmsProviders.Message[]) => {
|
|
315
|
-
messages = [...baseline];
|
|
316
|
-
}),
|
|
317
|
-
updateConnection: vi.fn(),
|
|
318
|
-
shutdown: agentShutdown,
|
|
319
|
-
getMessages: vi.fn(() => [...messages]),
|
|
320
|
-
messages: [],
|
|
321
|
-
}) as never,
|
|
322
|
-
});
|
|
323
|
-
|
|
324
|
-
const started = await manager.start({
|
|
325
|
-
interactive: true,
|
|
326
|
-
config: {
|
|
327
|
-
providerId: "anthropic",
|
|
328
|
-
modelId: "claude-sonnet-4-6",
|
|
329
|
-
apiKey: "test-key",
|
|
330
|
-
cwd: sessionsDir,
|
|
331
|
-
systemPrompt: "You are a test agent",
|
|
332
|
-
enableTools: false,
|
|
333
|
-
enableSpawnAgent: false,
|
|
334
|
-
enableAgentTeams: false,
|
|
335
|
-
},
|
|
336
|
-
});
|
|
337
|
-
|
|
338
|
-
expect(started.sessionId.length).toBeGreaterThan(0);
|
|
339
|
-
expect(existsSync(started.manifestPath)).toBe(false);
|
|
340
|
-
expect(existsSync(started.messagesPath)).toBe(false);
|
|
341
|
-
|
|
342
|
-
const first = await manager.send({
|
|
343
|
-
sessionId: started.sessionId,
|
|
344
|
-
prompt: "first prompt",
|
|
345
|
-
});
|
|
346
|
-
const second = await manager.send({
|
|
347
|
-
sessionId: started.sessionId,
|
|
348
|
-
prompt: "second prompt",
|
|
349
|
-
});
|
|
350
|
-
expect(existsSync(started.manifestPath)).toBe(true);
|
|
351
|
-
expect(existsSync(started.messagesPath)).toBe(true);
|
|
352
|
-
|
|
353
|
-
expect(first?.text).toContain("first prompt");
|
|
354
|
-
expect(second?.text).toContain("second prompt");
|
|
355
|
-
expect(run).toHaveBeenCalledTimes(1);
|
|
356
|
-
expect(continueFn).toHaveBeenCalledTimes(1);
|
|
357
|
-
|
|
358
|
-
const persistedMessages = await manager.readMessages(started.sessionId);
|
|
359
|
-
expect(persistedMessages.length).toBeGreaterThan(0);
|
|
360
|
-
expect(JSON.stringify(persistedMessages)).toContain("second prompt");
|
|
361
|
-
|
|
362
|
-
const listed = await manager.list(20);
|
|
363
|
-
expect(
|
|
364
|
-
listed.some((session) => session.sessionId === started.sessionId),
|
|
365
|
-
).toBe(true);
|
|
366
|
-
|
|
367
|
-
await manager.stop(started.sessionId);
|
|
368
|
-
const stopped = await manager.get(started.sessionId);
|
|
369
|
-
expect(stopped?.status).toBe("cancelled");
|
|
370
|
-
expect(stopped?.exitCode).toBe(0);
|
|
371
|
-
expect(agentShutdown).toHaveBeenCalledTimes(1);
|
|
372
|
-
expect(runtimeShutdown).toHaveBeenCalledTimes(1);
|
|
373
|
-
const parsedManifest = JSON.parse(
|
|
374
|
-
readFileSync(started.manifestPath, "utf8"),
|
|
375
|
-
) as SessionManifest;
|
|
376
|
-
expect(parsedManifest.status).toBe("cancelled");
|
|
377
|
-
|
|
378
|
-
const deleted = await manager.delete(started.sessionId);
|
|
379
|
-
expect(deleted).toBe(true);
|
|
380
|
-
expect(await manager.get(started.sessionId)).toBeUndefined();
|
|
381
|
-
expect(existsSync(started.manifestPath)).toBe(false);
|
|
382
|
-
expect(existsSync(started.messagesPath)).toBe(false);
|
|
383
|
-
});
|
|
384
|
-
});
|