@clinebot/core 0.0.36 → 0.0.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ClineCore.d.ts +312 -3
- package/dist/ClineCore.d.ts.map +1 -1
- package/dist/account/cline-account-service.d.ts.map +1 -1
- package/dist/cron/cron-event-ingress.d.ts +38 -0
- package/dist/cron/cron-event-ingress.d.ts.map +1 -0
- package/dist/cron/cron-materializer.d.ts +36 -0
- package/dist/cron/cron-materializer.d.ts.map +1 -0
- package/dist/cron/cron-reconciler.d.ts +62 -0
- package/dist/cron/cron-reconciler.d.ts.map +1 -0
- package/dist/cron/cron-report-writer.d.ts +41 -0
- package/dist/cron/cron-report-writer.d.ts.map +1 -0
- package/dist/cron/cron-runner.d.ts +43 -0
- package/dist/cron/cron-runner.d.ts.map +1 -0
- package/dist/cron/cron-schema.d.ts +3 -0
- package/dist/cron/cron-schema.d.ts.map +1 -0
- package/dist/cron/cron-service.d.ts +57 -0
- package/dist/cron/cron-service.d.ts.map +1 -0
- package/dist/cron/cron-spec-parser.d.ts +27 -0
- package/dist/cron/cron-spec-parser.d.ts.map +1 -0
- package/dist/cron/cron-watcher.d.ts +23 -0
- package/dist/cron/cron-watcher.d.ts.map +1 -0
- package/dist/cron/scheduler.d.ts +3 -1
- package/dist/cron/scheduler.d.ts.map +1 -1
- package/dist/cron/sqlite-cron-store.d.ts +230 -0
- package/dist/cron/sqlite-cron-store.d.ts.map +1 -0
- package/dist/extensions/plugin/plugin-config-loader.d.ts +7 -1
- package/dist/extensions/plugin/plugin-config-loader.d.ts.map +1 -1
- package/dist/extensions/plugin/plugin-loader.d.ts +10 -6
- package/dist/extensions/plugin/plugin-loader.d.ts.map +1 -1
- package/dist/extensions/plugin/plugin-sandbox.d.ts +7 -1
- package/dist/extensions/plugin/plugin-sandbox.d.ts.map +1 -1
- package/dist/extensions/plugin-sandbox-bootstrap.js +236 -275
- package/dist/extensions/tools/constants.d.ts +1 -0
- package/dist/extensions/tools/constants.d.ts.map +1 -1
- package/dist/extensions/tools/definitions.d.ts +2 -3
- package/dist/extensions/tools/definitions.d.ts.map +1 -1
- package/dist/extensions/tools/executors/editor.d.ts.map +1 -1
- package/dist/extensions/tools/helpers.d.ts +1 -0
- package/dist/extensions/tools/helpers.d.ts.map +1 -1
- package/dist/extensions/tools/index.d.ts +1 -2
- package/dist/extensions/tools/index.d.ts.map +1 -1
- package/dist/extensions/tools/presets.d.ts +1 -1
- package/dist/extensions/tools/schemas.d.ts +25 -3
- package/dist/extensions/tools/schemas.d.ts.map +1 -1
- package/dist/extensions/tools/team/delegated-agent.d.ts +2 -2
- package/dist/extensions/tools/team/delegated-agent.d.ts.map +1 -1
- package/dist/extensions/tools/team/multi-agent.d.ts +7 -3
- package/dist/extensions/tools/team/multi-agent.d.ts.map +1 -1
- package/dist/extensions/tools/team/team-tools.d.ts.map +1 -1
- package/dist/extensions/tools/types.d.ts +0 -5
- package/dist/extensions/tools/types.d.ts.map +1 -1
- package/dist/hooks/hook-bridge.d.ts +118 -0
- package/dist/hooks/hook-bridge.d.ts.map +1 -0
- package/dist/hooks/hook-file-hooks.d.ts +2 -1
- package/dist/hooks/hook-file-hooks.d.ts.map +1 -1
- package/dist/hooks/hook-registry.d.ts +16 -0
- package/dist/hooks/hook-registry.d.ts.map +1 -0
- package/dist/hub/browser-websocket.d.ts.map +1 -1
- package/dist/hub/client.d.ts +7 -1
- package/dist/hub/client.d.ts.map +1 -1
- package/dist/hub/daemon-entry.js +721 -461
- package/dist/hub/daemon.d.ts.map +1 -1
- package/dist/hub/defaults.d.ts +8 -4
- package/dist/hub/defaults.d.ts.map +1 -1
- package/dist/hub/index.js +665 -415
- package/dist/hub/runtime-handlers.d.ts.map +1 -1
- package/dist/hub/server.d.ts +18 -0
- package/dist/hub/server.d.ts.map +1 -1
- package/dist/hub/session-client.d.ts +3 -0
- package/dist/hub/session-client.d.ts.map +1 -1
- package/dist/hub/start-shared-server.d.ts.map +1 -1
- package/dist/hub/ui-client.d.ts +1 -0
- package/dist/hub/ui-client.d.ts.map +1 -1
- package/dist/index.d.ts +9 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +756 -467
- package/dist/llms/cline-recommended-models.d.ts +20 -0
- package/dist/llms/cline-recommended-models.d.ts.map +1 -0
- package/dist/llms/handler-factory.d.ts +16 -0
- package/dist/llms/handler-factory.d.ts.map +1 -0
- package/dist/llms/provider-defaults.d.ts.map +1 -1
- package/dist/llms/provider-settings.d.ts +45 -2
- package/dist/llms/provider-settings.d.ts.map +1 -1
- package/dist/llms/runtime-registry.d.ts.map +1 -1
- package/dist/runtime/agent-config-adapter.d.ts +148 -0
- package/dist/runtime/agent-config-adapter.d.ts.map +1 -0
- package/dist/runtime/agent-runtime-config-builder.d.ts +96 -0
- package/dist/runtime/agent-runtime-config-builder.d.ts.map +1 -0
- package/dist/runtime/history.d.ts +6 -0
- package/dist/runtime/history.d.ts.map +1 -1
- package/dist/runtime/host.d.ts.map +1 -1
- package/dist/runtime/loop-detection.d.ts +59 -0
- package/dist/runtime/loop-detection.d.ts.map +1 -0
- package/dist/runtime/mistake-tracker.d.ts +69 -0
- package/dist/runtime/mistake-tracker.d.ts.map +1 -0
- package/dist/runtime/runtime-builder.d.ts.map +1 -1
- package/dist/runtime/runtime-event-adapter.d.ts +102 -0
- package/dist/runtime/runtime-event-adapter.d.ts.map +1 -0
- package/dist/runtime/runtime-host.d.ts +28 -3
- package/dist/runtime/runtime-host.d.ts.map +1 -1
- package/dist/runtime/session-runtime-orchestrator.d.ts +261 -0
- package/dist/runtime/session-runtime-orchestrator.d.ts.map +1 -0
- package/dist/runtime/session-runtime.d.ts +16 -3
- package/dist/runtime/session-runtime.d.ts.map +1 -1
- package/dist/runtime/user-input-builder.d.ts +24 -0
- package/dist/runtime/user-input-builder.d.ts.map +1 -0
- package/dist/services/index.js +28 -0
- package/dist/services/local-runtime-bootstrap.d.ts.map +1 -1
- package/dist/services/plugin-tools.d.ts.map +1 -1
- package/dist/services/providers/local-provider-registry.d.ts +197 -21
- package/dist/services/providers/local-provider-registry.d.ts.map +1 -1
- package/dist/services/providers/local-provider-service.d.ts +3 -1
- package/dist/services/providers/local-provider-service.d.ts.map +1 -1
- package/dist/services/session-data.d.ts.map +1 -1
- package/dist/services/session-telemetry.d.ts +7 -2
- package/dist/services/session-telemetry.d.ts.map +1 -1
- package/dist/services/storage/file-team-store.d.ts.map +1 -1
- package/dist/services/storage/provider-settings-legacy-migration.d.ts.map +1 -1
- package/dist/services/storage/provider-settings-manager.d.ts +1 -0
- package/dist/services/storage/provider-settings-manager.d.ts.map +1 -1
- package/dist/services/storage/sqlite-team-store.d.ts.map +1 -1
- package/dist/session/conversation-store.d.ts +30 -0
- package/dist/session/conversation-store.d.ts.map +1 -0
- package/dist/session/message-builder.d.ts +65 -0
- package/dist/session/message-builder.d.ts.map +1 -0
- package/dist/session/session-manifest.d.ts +1 -1
- package/dist/transports/hub.d.ts +14 -3
- package/dist/transports/hub.d.ts.map +1 -1
- package/dist/transports/local.d.ts +14 -4
- package/dist/transports/local.d.ts.map +1 -1
- package/dist/transports/remote.d.ts.map +1 -1
- package/dist/types/chat-schema.d.ts +5 -5
- package/dist/types/config.d.ts +9 -0
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/events.d.ts +7 -6
- package/dist/types/events.d.ts.map +1 -1
- package/dist/types/provider-settings.d.ts +2 -2
- package/dist/types/provider-settings.d.ts.map +1 -1
- package/dist/types/session.d.ts +5 -2
- package/dist/types/session.d.ts.map +1 -1
- package/dist/types.d.ts +4 -4
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/ClineCore.ts +691 -6
- package/src/account/cline-account-service.ts +44 -6
- package/src/cron/cron-event-ingress.ts +357 -0
- package/src/cron/cron-materializer.ts +97 -0
- package/src/cron/cron-reconciler.ts +241 -0
- package/src/cron/cron-report-writer.ts +153 -0
- package/src/cron/cron-runner.ts +495 -0
- package/src/cron/cron-schema.ts +127 -0
- package/src/cron/cron-service.ts +163 -0
- package/src/cron/cron-spec-parser.ts +489 -0
- package/src/cron/cron-watcher.ts +102 -0
- package/src/cron/index.ts +10 -0
- package/src/cron/scheduler.ts +141 -6
- package/src/cron/sqlite-cron-store.ts +1286 -0
- package/src/extensions/plugin/plugin-config-loader.ts +21 -1
- package/src/extensions/plugin/plugin-loader.ts +25 -9
- package/src/extensions/plugin/plugin-sandbox-bootstrap.ts +151 -1
- package/src/extensions/plugin/plugin-sandbox.ts +131 -7
- package/src/extensions/tools/constants.ts +2 -0
- package/src/extensions/tools/definitions.ts +31 -22
- package/src/extensions/tools/executors/editor.ts +4 -3
- package/src/extensions/tools/helpers.ts +24 -0
- package/src/extensions/tools/index.ts +1 -2
- package/src/extensions/tools/presets.ts +1 -1
- package/src/extensions/tools/schemas.ts +13 -18
- package/src/extensions/tools/team/delegated-agent.ts +8 -3
- package/src/extensions/tools/team/multi-agent.ts +135 -19
- package/src/extensions/tools/team/team-tools.ts +151 -91
- package/src/extensions/tools/types.ts +0 -6
- package/src/hooks/hook-bridge.ts +489 -0
- package/src/hooks/hook-file-hooks.ts +58 -3
- package/src/hooks/hook-registry.ts +257 -0
- package/src/hub/browser-websocket.ts +26 -4
- package/src/hub/client.ts +72 -13
- package/src/hub/daemon-entry.ts +35 -0
- package/src/hub/daemon.ts +117 -14
- package/src/hub/defaults.ts +39 -12
- package/src/hub/runtime-handlers.ts +4 -3
- package/src/hub/server.ts +506 -77
- package/src/hub/session-client.ts +43 -1
- package/src/hub/start-shared-server.ts +3 -0
- package/src/hub/ui-client.ts +4 -0
- package/src/index.ts +46 -1
- package/src/llms/cline-recommended-models.ts +167 -0
- package/src/llms/handler-factory.ts +56 -0
- package/src/llms/provider-defaults.ts +17 -1
- package/src/llms/provider-settings.ts +48 -1
- package/src/llms/runtime-registry.ts +1 -0
- package/src/runtime/agent-config-adapter.ts +636 -0
- package/src/runtime/agent-runtime-config-builder.ts +205 -0
- package/src/runtime/error-feedback.ts +142 -0
- package/src/runtime/history.ts +137 -0
- package/src/runtime/host.ts +22 -0
- package/src/runtime/loop-detection.ts +162 -0
- package/src/runtime/mistake-tracker.ts +221 -0
- package/src/runtime/runtime-builder.ts +61 -5
- package/src/runtime/runtime-event-adapter.ts +412 -0
- package/src/runtime/runtime-host.ts +45 -1
- package/src/runtime/session-runtime-orchestrator.ts +1253 -0
- package/src/runtime/session-runtime.ts +16 -2
- package/src/runtime/user-input-builder.ts +167 -0
- package/src/services/local-runtime-bootstrap.ts +128 -22
- package/src/services/plugin-tools.ts +1 -0
- package/src/services/providers/local-provider-registry.ts +273 -57
- package/src/services/providers/local-provider-service.ts +67 -7
- package/src/services/session-data.ts +16 -14
- package/src/services/session-telemetry.ts +6 -15
- package/src/services/storage/file-team-store.ts +1 -5
- package/src/services/storage/provider-settings-legacy-migration.ts +8 -47
- package/src/services/storage/provider-settings-manager.ts +16 -1
- package/src/services/storage/sqlite-team-store.ts +1 -5
- package/src/session/conversation-store.ts +77 -0
- package/src/session/message-builder.ts +941 -0
- package/src/transports/hub.ts +458 -33
- package/src/transports/local.ts +296 -65
- package/src/transports/remote.ts +1 -0
- package/src/types/config.ts +9 -0
- package/src/types/events.ts +8 -6
- package/src/types/index.ts +3 -0
- package/src/types/provider-settings.ts +8 -1
- package/src/types/session.ts +5 -2
- package/src/types.ts +15 -1
- package/dist/cron/index.d.ts +0 -6
- package/dist/cron/index.d.ts.map +0 -1
- package/dist/services/telemetry/index.js +0 -28
package/src/ClineCore.ts
CHANGED
|
@@ -1,16 +1,41 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
AgentConfig,
|
|
3
|
+
AgentExtensionAutomationContext,
|
|
4
|
+
AgentResult,
|
|
5
|
+
AutomationEventEnvelope,
|
|
3
6
|
BasicLogger,
|
|
7
|
+
ChatRunTurnRequest,
|
|
8
|
+
ChatStartSessionRequest,
|
|
9
|
+
ChatTurnResult,
|
|
10
|
+
ExtensionContext,
|
|
4
11
|
ITelemetryService,
|
|
5
12
|
ToolApprovalRequest,
|
|
6
13
|
ToolApprovalResult,
|
|
7
14
|
} from "@clinebot/shared";
|
|
15
|
+
import type {
|
|
16
|
+
CronEventIngressResult,
|
|
17
|
+
CronEventSuppression,
|
|
18
|
+
} from "./cron/cron-event-ingress";
|
|
19
|
+
import { CronService } from "./cron/cron-service";
|
|
20
|
+
import type { HubScheduleRuntimeHandlers } from "./cron/schedule-service";
|
|
21
|
+
import type {
|
|
22
|
+
CronEventLogRecord,
|
|
23
|
+
CronRunRecord,
|
|
24
|
+
CronSpecRecord,
|
|
25
|
+
} from "./cron/sqlite-cron-store";
|
|
8
26
|
import type { ToolExecutors } from "./extensions/tools";
|
|
9
|
-
import {
|
|
27
|
+
import { normalizeProviderId } from "./llms/provider-settings";
|
|
28
|
+
import type { SessionHistoryListOptions } from "./runtime/history";
|
|
29
|
+
import { listSessionHistory } from "./runtime/history";
|
|
10
30
|
import type { SessionBackend } from "./runtime/host";
|
|
11
31
|
import { createRuntimeHost } from "./runtime/host";
|
|
12
32
|
import type {
|
|
13
33
|
LocalRuntimeStartOptions,
|
|
34
|
+
PendingPromptMutationResult,
|
|
35
|
+
PendingPromptsAction,
|
|
36
|
+
PendingPromptsDeleteInput,
|
|
37
|
+
PendingPromptsListInput,
|
|
38
|
+
PendingPromptsUpdateInput,
|
|
14
39
|
RuntimeHost,
|
|
15
40
|
RuntimeHostMode,
|
|
16
41
|
RuntimeHostSubscribeOptions,
|
|
@@ -18,9 +43,12 @@ import type {
|
|
|
18
43
|
StartSessionResult,
|
|
19
44
|
} from "./runtime/runtime-host";
|
|
20
45
|
import { splitCoreSessionConfig } from "./runtime/runtime-host";
|
|
46
|
+
import { CORE_TELEMETRY_EVENTS } from "./services/telemetry/core-events";
|
|
47
|
+
import { SessionSource } from "./types/common";
|
|
21
48
|
import type { CoreSessionConfig } from "./types/config";
|
|
22
|
-
import type { CoreSessionEvent } from "./types/events";
|
|
49
|
+
import type { CoreSessionEvent, SessionPendingPrompt } from "./types/events";
|
|
23
50
|
import type { SessionMessagesArtifactUploader } from "./types/session";
|
|
51
|
+
import type { SessionHistoryRecord } from "./types/sessions";
|
|
24
52
|
|
|
25
53
|
export interface HubOptions {
|
|
26
54
|
endpoint?: string;
|
|
@@ -41,8 +69,84 @@ export interface RemoteOptions {
|
|
|
41
69
|
cwd?: string;
|
|
42
70
|
}
|
|
43
71
|
|
|
72
|
+
export interface ClineCoreAutomationOptions {
|
|
73
|
+
/** @deprecated Use `cronSpecsDir`. */
|
|
74
|
+
cronDir?: string;
|
|
75
|
+
cronSpecsDir?: string;
|
|
76
|
+
/** @deprecated Reports are written under the resolved cron specs directory. */
|
|
77
|
+
reportsDir?: string;
|
|
78
|
+
cronScope?: "global" | "user" | "workspace";
|
|
79
|
+
workspaceRoot?: string;
|
|
80
|
+
dbPath?: string;
|
|
81
|
+
pollIntervalMs?: number;
|
|
82
|
+
claimLeaseSeconds?: number;
|
|
83
|
+
globalMaxConcurrency?: number;
|
|
84
|
+
watcherDebounceMs?: number;
|
|
85
|
+
autoStart?: boolean;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export type ClineAutomationSpec = CronSpecRecord;
|
|
89
|
+
export type ClineAutomationRun = CronRunRecord;
|
|
90
|
+
export type ClineAutomationEventLog = CronEventLogRecord;
|
|
91
|
+
export type ClineAutomationEventSuppression = CronEventSuppression;
|
|
92
|
+
export type ClineAutomationRunStatus =
|
|
93
|
+
| "queued"
|
|
94
|
+
| "running"
|
|
95
|
+
| "done"
|
|
96
|
+
| "failed"
|
|
97
|
+
| "cancelled";
|
|
98
|
+
|
|
99
|
+
export interface ClineAutomationListSpecsOptions {
|
|
100
|
+
triggerKind?: "one_off" | "schedule" | "event";
|
|
101
|
+
enabled?: boolean;
|
|
102
|
+
parseStatus?: "valid" | "invalid";
|
|
103
|
+
includeRemoved?: boolean;
|
|
104
|
+
limit?: number;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export interface ClineAutomationListRunsOptions {
|
|
108
|
+
specId?: string;
|
|
109
|
+
status?: ClineAutomationRunStatus | ClineAutomationRunStatus[];
|
|
110
|
+
limit?: number;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export interface ClineAutomationListEventsOptions {
|
|
114
|
+
eventType?: string;
|
|
115
|
+
source?: string;
|
|
116
|
+
processingStatus?:
|
|
117
|
+
| "received"
|
|
118
|
+
| "unmatched"
|
|
119
|
+
| "queued"
|
|
120
|
+
| "suppressed"
|
|
121
|
+
| "failed";
|
|
122
|
+
limit?: number;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export interface ClineAutomationEventIngressResult {
|
|
126
|
+
event: ClineAutomationEventLog;
|
|
127
|
+
duplicate: boolean;
|
|
128
|
+
matchedSpecIds: string[];
|
|
129
|
+
queuedRuns: ClineAutomationRun[];
|
|
130
|
+
suppressions: ClineAutomationEventSuppression[];
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export interface ClineCoreAutomationApi {
|
|
134
|
+
start(): Promise<void>;
|
|
135
|
+
stop(): Promise<void>;
|
|
136
|
+
reconcileNow(): Promise<void>;
|
|
137
|
+
ingestEvent(event: any): ClineAutomationEventIngressResult;
|
|
138
|
+
listEvents(
|
|
139
|
+
options?: ClineAutomationListEventsOptions,
|
|
140
|
+
): ClineAutomationEventLog[];
|
|
141
|
+
getEvent(eventId: string): ClineAutomationEventLog | undefined;
|
|
142
|
+
listSpecs(options?: ClineAutomationListSpecsOptions): ClineAutomationSpec[];
|
|
143
|
+
listRuns(options?: ClineAutomationListRunsOptions): ClineAutomationRun[];
|
|
144
|
+
}
|
|
145
|
+
|
|
44
146
|
export type { RuntimeHostMode };
|
|
45
147
|
|
|
148
|
+
export type ClineCoreListHistoryOptions = SessionHistoryListOptions;
|
|
149
|
+
|
|
46
150
|
export interface ClineCoreStartInput
|
|
47
151
|
extends Omit<StartSessionInput, "config" | "localRuntime"> {
|
|
48
152
|
config: CoreSessionConfig;
|
|
@@ -112,6 +216,12 @@ export interface ClineCoreOptions {
|
|
|
112
216
|
* Consumers can use this to mirror session transcripts into remote storage.
|
|
113
217
|
*/
|
|
114
218
|
messagesArtifactUploader?: SessionMessagesArtifactUploader;
|
|
219
|
+
/**
|
|
220
|
+
* Enables file-based and event-driven automation through this ClineCore
|
|
221
|
+
* instance. When configured, callers use `cline.automation.*` instead of
|
|
222
|
+
* constructing cron services directly.
|
|
223
|
+
*/
|
|
224
|
+
automation?: boolean | ClineCoreAutomationOptions;
|
|
115
225
|
/**
|
|
116
226
|
* Custom `fetch` implementation forwarded to the AI gateway providers used
|
|
117
227
|
* by local sessions. When supplied, it is threaded into each
|
|
@@ -159,6 +269,102 @@ export interface StartSessionBootstrap {
|
|
|
159
269
|
dispose?(): Promise<void> | void;
|
|
160
270
|
}
|
|
161
271
|
|
|
272
|
+
function normalizeAutomationOptions(
|
|
273
|
+
options: ClineCoreOptions["automation"],
|
|
274
|
+
): ClineCoreAutomationOptions | undefined {
|
|
275
|
+
if (options === true) return {};
|
|
276
|
+
if (!options) return undefined;
|
|
277
|
+
return options;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
function normalizeAutomationCronScope(
|
|
281
|
+
scope: ClineCoreAutomationOptions["cronScope"],
|
|
282
|
+
): "global" | "workspace" | undefined {
|
|
283
|
+
if (scope === "user") return "global";
|
|
284
|
+
return scope;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function toChatTurnResult(result: AgentResult): ChatTurnResult {
|
|
288
|
+
return {
|
|
289
|
+
text: result.text,
|
|
290
|
+
usage: {
|
|
291
|
+
inputTokens: result.usage.inputTokens,
|
|
292
|
+
outputTokens: result.usage.outputTokens,
|
|
293
|
+
cacheReadTokens: result.usage.cacheReadTokens,
|
|
294
|
+
cacheWriteTokens: result.usage.cacheWriteTokens,
|
|
295
|
+
totalCost: result.usage.totalCost,
|
|
296
|
+
},
|
|
297
|
+
inputTokens: result.usage.inputTokens,
|
|
298
|
+
outputTokens: result.usage.outputTokens,
|
|
299
|
+
iterations: result.iterations,
|
|
300
|
+
finishReason: result.finishReason,
|
|
301
|
+
toolCalls: result.toolCalls.map((call) => ({
|
|
302
|
+
name: call.name,
|
|
303
|
+
input: call.input,
|
|
304
|
+
output: call.output,
|
|
305
|
+
error: call.error,
|
|
306
|
+
durationMs: call.durationMs,
|
|
307
|
+
})),
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function resolveMode(
|
|
312
|
+
request: ChatStartSessionRequest | ChatRunTurnRequest["config"],
|
|
313
|
+
): "act" | "plan" | "yolo" {
|
|
314
|
+
return request.mode === "plan"
|
|
315
|
+
? "plan"
|
|
316
|
+
: request.mode === "yolo"
|
|
317
|
+
? "yolo"
|
|
318
|
+
: "act";
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
class ClineCoreAutomationController implements ClineCoreAutomationApi {
|
|
322
|
+
constructor(private readonly getService: () => CronService) {}
|
|
323
|
+
|
|
324
|
+
async start(): Promise<void> {
|
|
325
|
+
await this.getService().start();
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
async stop(): Promise<void> {
|
|
329
|
+
await this.getService().stop();
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
async reconcileNow(): Promise<void> {
|
|
333
|
+
await this.getService().reconcileNow();
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
ingestEvent(
|
|
337
|
+
event: AutomationEventEnvelope,
|
|
338
|
+
): ClineAutomationEventIngressResult {
|
|
339
|
+
const result: CronEventIngressResult = this.getService().ingestEvent(event);
|
|
340
|
+
return {
|
|
341
|
+
event: result.event,
|
|
342
|
+
duplicate: result.duplicate,
|
|
343
|
+
matchedSpecIds: result.matchedSpecs.map((spec) => spec.specId),
|
|
344
|
+
queuedRuns: result.queuedRuns,
|
|
345
|
+
suppressions: result.suppressions,
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
listEvents(
|
|
350
|
+
options?: ClineAutomationListEventsOptions,
|
|
351
|
+
): ClineAutomationEventLog[] {
|
|
352
|
+
return this.getService().listEventLogs(options);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
getEvent(eventId: string): ClineAutomationEventLog | undefined {
|
|
356
|
+
return this.getService().getEventLog(eventId);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
listSpecs(options?: ClineAutomationListSpecsOptions): ClineAutomationSpec[] {
|
|
360
|
+
return this.getService().listSpecs(options);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
listRuns(options?: ClineAutomationListRunsOptions): ClineAutomationRun[] {
|
|
364
|
+
return this.getService().listRuns(options);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
162
368
|
/**
|
|
163
369
|
* The primary entry point for the Cline Core SDK.
|
|
164
370
|
*
|
|
@@ -173,9 +379,14 @@ export interface StartSessionBootstrap {
|
|
|
173
379
|
export class ClineCore implements RuntimeHost {
|
|
174
380
|
readonly clientName: string | undefined;
|
|
175
381
|
readonly runtimeAddress: string | undefined;
|
|
382
|
+
readonly automation: ClineCoreAutomationApi;
|
|
176
383
|
private readonly host: RuntimeHost;
|
|
177
384
|
private readonly prepare: ClineCoreOptions["prepare"] | undefined;
|
|
178
385
|
private readonly defaultToolExecutors: Partial<ToolExecutors> | undefined;
|
|
386
|
+
private readonly logger: BasicLogger | undefined;
|
|
387
|
+
private readonly telemetry: ITelemetryService | undefined;
|
|
388
|
+
private readonly distinctId: string | undefined;
|
|
389
|
+
private readonly automationService: CronService | undefined;
|
|
179
390
|
private readonly activeSessionBootstraps = new Map<
|
|
180
391
|
string,
|
|
181
392
|
StartSessionBootstrap
|
|
@@ -188,12 +399,47 @@ export class ClineCore implements RuntimeHost {
|
|
|
188
399
|
runtimeAddress: string | undefined,
|
|
189
400
|
prepare: ClineCoreOptions["prepare"],
|
|
190
401
|
defaultToolExecutors: Partial<ToolExecutors> | undefined,
|
|
402
|
+
logger: BasicLogger | undefined,
|
|
403
|
+
telemetry: ITelemetryService | undefined,
|
|
404
|
+
distinctId: string | undefined,
|
|
405
|
+
automationOptions:
|
|
406
|
+
| (ClineCoreAutomationOptions & { logger?: BasicLogger })
|
|
407
|
+
| undefined,
|
|
191
408
|
) {
|
|
192
409
|
this.clientName = clientName;
|
|
193
410
|
this.runtimeAddress = runtimeAddress;
|
|
194
411
|
this.host = host;
|
|
195
412
|
this.prepare = prepare;
|
|
196
413
|
this.defaultToolExecutors = defaultToolExecutors;
|
|
414
|
+
this.logger = logger;
|
|
415
|
+
this.telemetry = telemetry;
|
|
416
|
+
this.distinctId = distinctId;
|
|
417
|
+
this.automationService = automationOptions
|
|
418
|
+
? new CronService({
|
|
419
|
+
workspaceRoot: automationOptions.workspaceRoot ?? process.cwd(),
|
|
420
|
+
specs: {
|
|
421
|
+
cronSpecsDir:
|
|
422
|
+
automationOptions.cronSpecsDir ?? automationOptions.cronDir,
|
|
423
|
+
scope: normalizeAutomationCronScope(automationOptions.cronScope),
|
|
424
|
+
workspaceRoot: automationOptions.workspaceRoot,
|
|
425
|
+
},
|
|
426
|
+
runtimeHandlers: this.createAutomationRuntimeHandlers(host),
|
|
427
|
+
dbPath: automationOptions.dbPath,
|
|
428
|
+
logger: automationOptions.logger,
|
|
429
|
+
pollIntervalMs: automationOptions.pollIntervalMs,
|
|
430
|
+
claimLeaseSeconds: automationOptions.claimLeaseSeconds,
|
|
431
|
+
globalMaxConcurrency: automationOptions.globalMaxConcurrency,
|
|
432
|
+
watcherDebounceMs: automationOptions.watcherDebounceMs,
|
|
433
|
+
})
|
|
434
|
+
: undefined;
|
|
435
|
+
this.automation = new ClineCoreAutomationController(() => {
|
|
436
|
+
if (!this.automationService) {
|
|
437
|
+
throw new Error(
|
|
438
|
+
"ClineCore automation is not enabled. Pass `automation: true` or automation options to ClineCore.create().",
|
|
439
|
+
);
|
|
440
|
+
}
|
|
441
|
+
return this.automationService;
|
|
442
|
+
});
|
|
197
443
|
this.unsubscribeBootstrapCleanup = this.host.subscribe((event) => {
|
|
198
444
|
if (event.type !== "ended") {
|
|
199
445
|
return;
|
|
@@ -202,15 +448,155 @@ export class ClineCore implements RuntimeHost {
|
|
|
202
448
|
});
|
|
203
449
|
}
|
|
204
450
|
|
|
451
|
+
/**
|
|
452
|
+
* Creates a new ClineCore instance.
|
|
453
|
+
*
|
|
454
|
+
* This is the primary factory method for initializing the SDK. It sets up the runtime
|
|
455
|
+
* host (local, hub, or remote) based on the provided options and prepares the SDK for
|
|
456
|
+
* starting sessions.
|
|
457
|
+
*
|
|
458
|
+
* @param options Configuration options for the SDK instance
|
|
459
|
+
* @returns A promise that resolves to a new ClineCore instance
|
|
460
|
+
*
|
|
461
|
+
* @example
|
|
462
|
+
* ```ts
|
|
463
|
+
* const cline = await ClineCore.create({
|
|
464
|
+
* clientName: "my-app",
|
|
465
|
+
* backendMode: "local",
|
|
466
|
+
* });
|
|
467
|
+
* ```
|
|
468
|
+
*/
|
|
205
469
|
static async create(options: ClineCoreOptions = {}): Promise<ClineCore> {
|
|
206
470
|
const host = await createRuntimeHost(options);
|
|
207
|
-
|
|
471
|
+
const automationOptions = normalizeAutomationOptions(options.automation);
|
|
472
|
+
const core = new ClineCore(
|
|
208
473
|
host,
|
|
209
474
|
options.clientName,
|
|
210
475
|
host.runtimeAddress,
|
|
211
476
|
options.prepare,
|
|
212
477
|
options.defaultToolExecutors,
|
|
478
|
+
options.logger,
|
|
479
|
+
options.telemetry,
|
|
480
|
+
options.distinctId,
|
|
481
|
+
automationOptions
|
|
482
|
+
? { ...automationOptions, logger: options.logger }
|
|
483
|
+
: undefined,
|
|
213
484
|
);
|
|
485
|
+
if (automationOptions && automationOptions.autoStart !== false) {
|
|
486
|
+
await core.automation.start();
|
|
487
|
+
}
|
|
488
|
+
return core;
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
private createAutomationRuntimeHandlers(
|
|
492
|
+
host: RuntimeHost,
|
|
493
|
+
): HubScheduleRuntimeHandlers {
|
|
494
|
+
const core = this;
|
|
495
|
+
return {
|
|
496
|
+
async startSession(request) {
|
|
497
|
+
const cwd = (request.cwd?.trim() || request.workspaceRoot).trim();
|
|
498
|
+
const started = await host.start({
|
|
499
|
+
source: request.source?.trim() || SessionSource.CLI,
|
|
500
|
+
interactive: false,
|
|
501
|
+
config: {
|
|
502
|
+
providerId: normalizeProviderId(request.provider),
|
|
503
|
+
modelId: request.model,
|
|
504
|
+
apiKey: request.apiKey?.trim() || undefined,
|
|
505
|
+
cwd,
|
|
506
|
+
workspaceRoot: request.workspaceRoot,
|
|
507
|
+
systemPrompt: request.systemPrompt ?? "",
|
|
508
|
+
mode: resolveMode(request),
|
|
509
|
+
maxIterations: request.maxIterations,
|
|
510
|
+
enableTools: request.enableTools !== false,
|
|
511
|
+
enableSpawnAgent: request.enableSpawn !== false,
|
|
512
|
+
enableAgentTeams: request.enableTeams !== false,
|
|
513
|
+
disableMcpSettingsTools: request.disableMcpSettingsTools,
|
|
514
|
+
missionLogIntervalSteps: request.missionStepInterval,
|
|
515
|
+
missionLogIntervalMs: request.missionTimeIntervalMs,
|
|
516
|
+
},
|
|
517
|
+
toolPolicies: request.toolPolicies ?? {
|
|
518
|
+
"*": {
|
|
519
|
+
autoApprove: request.autoApproveTools !== false,
|
|
520
|
+
},
|
|
521
|
+
},
|
|
522
|
+
localRuntime: {
|
|
523
|
+
configOverrides: {
|
|
524
|
+
extensionContext: core.withAutomationExtensionContext(),
|
|
525
|
+
},
|
|
526
|
+
configExtensions: request.configExtensions,
|
|
527
|
+
},
|
|
528
|
+
});
|
|
529
|
+
return {
|
|
530
|
+
sessionId: started.sessionId,
|
|
531
|
+
startResult: {
|
|
532
|
+
sessionId: started.sessionId,
|
|
533
|
+
manifestPath: started.manifestPath,
|
|
534
|
+
messagesPath: started.messagesPath,
|
|
535
|
+
},
|
|
536
|
+
};
|
|
537
|
+
},
|
|
538
|
+
async sendSession(sessionId, request) {
|
|
539
|
+
const result = await host.send({
|
|
540
|
+
sessionId,
|
|
541
|
+
prompt: request.prompt,
|
|
542
|
+
userImages: request.attachments?.userImages,
|
|
543
|
+
userFiles: request.attachments?.userFiles?.map(
|
|
544
|
+
(file) => file.content,
|
|
545
|
+
),
|
|
546
|
+
delivery: request.delivery,
|
|
547
|
+
});
|
|
548
|
+
if (!result) {
|
|
549
|
+
throw new Error("ClineCore automation runtime returned no result");
|
|
550
|
+
}
|
|
551
|
+
return { result: toChatTurnResult(result) };
|
|
552
|
+
},
|
|
553
|
+
async abortSession(sessionId) {
|
|
554
|
+
await host.abort(sessionId, new Error("ClineCore automation abort"));
|
|
555
|
+
return { applied: true };
|
|
556
|
+
},
|
|
557
|
+
async stopSession(sessionId) {
|
|
558
|
+
await host.stop(sessionId);
|
|
559
|
+
return { applied: true };
|
|
560
|
+
},
|
|
561
|
+
};
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
private createAutomationPluginContext():
|
|
565
|
+
| AgentExtensionAutomationContext
|
|
566
|
+
| undefined {
|
|
567
|
+
if (!this.automationService) {
|
|
568
|
+
return undefined;
|
|
569
|
+
}
|
|
570
|
+
return {
|
|
571
|
+
ingestEvent: (event: AutomationEventEnvelope) => {
|
|
572
|
+
this.automation.ingestEvent(event);
|
|
573
|
+
},
|
|
574
|
+
};
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
private withAutomationExtensionContext(
|
|
578
|
+
context?: ExtensionContext,
|
|
579
|
+
): ExtensionContext | undefined {
|
|
580
|
+
const automation = this.createAutomationPluginContext();
|
|
581
|
+
const client =
|
|
582
|
+
context?.client ??
|
|
583
|
+
(this.clientName ? { name: this.clientName } : undefined);
|
|
584
|
+
const user =
|
|
585
|
+
context?.user ??
|
|
586
|
+
(this.distinctId ? { distinctId: this.distinctId } : undefined);
|
|
587
|
+
const logger = context?.logger ?? this.logger;
|
|
588
|
+
const telemetry = context?.telemetry ?? this.telemetry;
|
|
589
|
+
if (!automation && !client && !user && !logger && !telemetry) {
|
|
590
|
+
return context;
|
|
591
|
+
}
|
|
592
|
+
return {
|
|
593
|
+
...(context ?? {}),
|
|
594
|
+
...(client ? { client } : {}),
|
|
595
|
+
...(user ? { user } : {}),
|
|
596
|
+
...(logger ? { logger } : {}),
|
|
597
|
+
...(telemetry ? { telemetry } : {}),
|
|
598
|
+
...(automation ? { automation } : {}),
|
|
599
|
+
};
|
|
214
600
|
}
|
|
215
601
|
|
|
216
602
|
private async disposeSessionBootstrap(sessionId: string): Promise<void> {
|
|
@@ -245,7 +631,7 @@ export class ClineCore implements RuntimeHost {
|
|
|
245
631
|
|
|
246
632
|
private normalizeStartInput(input: ClineCoreStartInput): StartSessionInput {
|
|
247
633
|
const split = splitCoreSessionConfig(input.config);
|
|
248
|
-
|
|
634
|
+
let localRuntime: LocalRuntimeStartOptions | undefined =
|
|
249
635
|
split.localRuntime || input.localRuntime || this.defaultToolExecutors
|
|
250
636
|
? {
|
|
251
637
|
...(split.localRuntime ?? {}),
|
|
@@ -261,6 +647,18 @@ export class ClineCore implements RuntimeHost {
|
|
|
261
647
|
},
|
|
262
648
|
}
|
|
263
649
|
: undefined;
|
|
650
|
+
const automationExtensionContext = this.withAutomationExtensionContext(
|
|
651
|
+
localRuntime?.configOverrides?.extensionContext,
|
|
652
|
+
);
|
|
653
|
+
if (automationExtensionContext) {
|
|
654
|
+
localRuntime = {
|
|
655
|
+
...(localRuntime ?? {}),
|
|
656
|
+
configOverrides: {
|
|
657
|
+
...(localRuntime?.configOverrides ?? {}),
|
|
658
|
+
extensionContext: automationExtensionContext,
|
|
659
|
+
},
|
|
660
|
+
};
|
|
661
|
+
}
|
|
264
662
|
return {
|
|
265
663
|
...input,
|
|
266
664
|
...split,
|
|
@@ -268,7 +666,36 @@ export class ClineCore implements RuntimeHost {
|
|
|
268
666
|
};
|
|
269
667
|
}
|
|
270
668
|
|
|
669
|
+
/**
|
|
670
|
+
* Starts a new Cline session with the provided configuration.
|
|
671
|
+
*
|
|
672
|
+
* This method initializes and begins a new agent session. It handles session setup,
|
|
673
|
+
* runs any preparation hooks, and returns session metadata along with event streams.
|
|
674
|
+
* The session continues to run until explicitly stopped or aborted.
|
|
675
|
+
*
|
|
676
|
+
* @param input The session configuration and startup parameters
|
|
677
|
+
* @returns A promise that resolves to session metadata and event stream
|
|
678
|
+
*
|
|
679
|
+
* @example
|
|
680
|
+
* ```ts
|
|
681
|
+
* const result = await cline.start({
|
|
682
|
+
* config: {
|
|
683
|
+
* providerId: "anthropic",
|
|
684
|
+
* modelId: "claude-opus-4-1",
|
|
685
|
+
* },
|
|
686
|
+
* });
|
|
687
|
+
*
|
|
688
|
+
* // Subscribe to session events
|
|
689
|
+
* result.subscribe((event) => {
|
|
690
|
+
* console.log("Session event:", event);
|
|
691
|
+
* });
|
|
692
|
+
* ```
|
|
693
|
+
*/
|
|
271
694
|
start(input: StartSessionInput): Promise<StartSessionResult>;
|
|
695
|
+
/**
|
|
696
|
+
* Starts a new Cline session with extended core-specific configuration.
|
|
697
|
+
* This overload allows specifying local runtime options and config overrides.
|
|
698
|
+
*/
|
|
272
699
|
start(input: ClineCoreStartInput): Promise<StartSessionResult>;
|
|
273
700
|
async start(
|
|
274
701
|
input: StartSessionInput | ClineCoreStartInput,
|
|
@@ -290,22 +717,154 @@ export class ClineCore implements RuntimeHost {
|
|
|
290
717
|
await Promise.resolve(bootstrap.dispose?.());
|
|
291
718
|
}
|
|
292
719
|
}
|
|
720
|
+
this.emitSessionStartedTelemetry(preparedInput, result.sessionId);
|
|
293
721
|
return result;
|
|
294
722
|
} catch (error) {
|
|
295
723
|
await Promise.resolve(bootstrap?.dispose?.());
|
|
296
724
|
throw error;
|
|
297
725
|
}
|
|
298
726
|
}
|
|
727
|
+
|
|
728
|
+
private emitSessionStartedTelemetry(
|
|
729
|
+
input: ClineCoreStartInput,
|
|
730
|
+
sessionId: string,
|
|
731
|
+
): void {
|
|
732
|
+
// Per-session telemetry override (passed via `CoreSessionConfig.telemetry`)
|
|
733
|
+
// takes precedence over the instance-wide telemetry service configured
|
|
734
|
+
// on `ClineCore.create`. Either way we fire a single `session.started`
|
|
735
|
+
// event here so the signal is emitted for every backend (local, hub,
|
|
736
|
+
// remote), not just the in-process local transport.
|
|
737
|
+
const telemetry = input.config.telemetry ?? this.telemetry;
|
|
738
|
+
if (!telemetry) {
|
|
739
|
+
return;
|
|
740
|
+
}
|
|
741
|
+
telemetry.capture({
|
|
742
|
+
event: CORE_TELEMETRY_EVENTS.SESSION.STARTED,
|
|
743
|
+
properties: {
|
|
744
|
+
sessionId,
|
|
745
|
+
source: input.source ?? SessionSource.CORE,
|
|
746
|
+
providerId: input.config.providerId,
|
|
747
|
+
modelId: input.config.modelId,
|
|
748
|
+
enableTools: input.config.enableTools,
|
|
749
|
+
enableSpawnAgent: input.config.enableSpawnAgent,
|
|
750
|
+
enableAgentTeams: input.config.enableAgentTeams,
|
|
751
|
+
clientName: this.clientName,
|
|
752
|
+
runtimeAddress: this.runtimeAddress,
|
|
753
|
+
},
|
|
754
|
+
});
|
|
755
|
+
}
|
|
756
|
+
/**
|
|
757
|
+
* Sends a message or command to an active session.
|
|
758
|
+
*
|
|
759
|
+
* This method communicates with a running session, allowing you to send user messages,
|
|
760
|
+
* tool responses, or other session input while the session is in progress.
|
|
761
|
+
*
|
|
762
|
+
* @example
|
|
763
|
+
* ```ts
|
|
764
|
+
* await cline.send(sessionId, {
|
|
765
|
+
* type: "user_message",
|
|
766
|
+
* text: "Please implement the login feature",
|
|
767
|
+
* });
|
|
768
|
+
* ```
|
|
769
|
+
*/
|
|
299
770
|
send: RuntimeHost["send"] = (...args) => this.host.send(...args);
|
|
771
|
+
pendingPrompts(
|
|
772
|
+
action: "list",
|
|
773
|
+
input: PendingPromptsListInput,
|
|
774
|
+
): Promise<SessionPendingPrompt[]>;
|
|
775
|
+
pendingPrompts(
|
|
776
|
+
action: "update",
|
|
777
|
+
input: PendingPromptsUpdateInput,
|
|
778
|
+
): Promise<PendingPromptMutationResult>;
|
|
779
|
+
pendingPrompts(
|
|
780
|
+
action: "delete",
|
|
781
|
+
input: PendingPromptsDeleteInput,
|
|
782
|
+
): Promise<PendingPromptMutationResult>;
|
|
783
|
+
pendingPrompts(
|
|
784
|
+
action: PendingPromptsAction,
|
|
785
|
+
input:
|
|
786
|
+
| PendingPromptsListInput
|
|
787
|
+
| PendingPromptsUpdateInput
|
|
788
|
+
| PendingPromptsDeleteInput,
|
|
789
|
+
): Promise<SessionPendingPrompt[] | PendingPromptMutationResult> {
|
|
790
|
+
switch (action) {
|
|
791
|
+
case "list":
|
|
792
|
+
return this.host.pendingPrompts(
|
|
793
|
+
"list",
|
|
794
|
+
input as PendingPromptsListInput,
|
|
795
|
+
);
|
|
796
|
+
case "update":
|
|
797
|
+
return this.host.pendingPrompts(
|
|
798
|
+
"update",
|
|
799
|
+
input as PendingPromptsUpdateInput,
|
|
800
|
+
);
|
|
801
|
+
case "delete":
|
|
802
|
+
return this.host.pendingPrompts(
|
|
803
|
+
"delete",
|
|
804
|
+
input as PendingPromptsDeleteInput,
|
|
805
|
+
);
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
/**
|
|
809
|
+
* Retrieves accumulated token and cost usage for a session.
|
|
810
|
+
*
|
|
811
|
+
* Returns metrics about the session's resource consumption, including tokens used
|
|
812
|
+
* across different API providers and associated costs. Useful for monitoring and billing.
|
|
813
|
+
*
|
|
814
|
+
* @example
|
|
815
|
+
* ```ts
|
|
816
|
+
* const usage = await cline.getAccumulatedUsage(sessionId);
|
|
817
|
+
* console.log(`Total cost: $${usage.totalCost}`);
|
|
818
|
+
* ```
|
|
819
|
+
*/
|
|
300
820
|
getAccumulatedUsage: RuntimeHost["getAccumulatedUsage"] = (...args) =>
|
|
301
821
|
this.host.getAccumulatedUsage(...args);
|
|
822
|
+
/**
|
|
823
|
+
* Aborts an in-flight tool execution without stopping the session.
|
|
824
|
+
*
|
|
825
|
+
* Interrupts the current tool operation (e.g., file read, shell command) while keeping
|
|
826
|
+
* the session alive. The session can continue processing after the abort. Use this for
|
|
827
|
+
* cancelling long-running operations.
|
|
828
|
+
*
|
|
829
|
+
* @example
|
|
830
|
+
* ```ts
|
|
831
|
+
* // Stop the current operation but keep the session running
|
|
832
|
+
* await cline.abort(sessionId);
|
|
833
|
+
* ```
|
|
834
|
+
*/
|
|
302
835
|
abort: RuntimeHost["abort"] = (...args) => this.host.abort(...args);
|
|
836
|
+
/**
|
|
837
|
+
* Stops an active session gracefully.
|
|
838
|
+
*
|
|
839
|
+
* Terminates the session and cleans up associated resources. Unlike abort, this
|
|
840
|
+
* completely ends the session. The session cannot be resumed after stopping.
|
|
841
|
+
*
|
|
842
|
+
* @example
|
|
843
|
+
* ```ts
|
|
844
|
+
* // Cleanly shutdown the session
|
|
845
|
+
* await cline.stop(sessionId);
|
|
846
|
+
* ```
|
|
847
|
+
*/
|
|
303
848
|
stop: RuntimeHost["stop"] = async (sessionId) => {
|
|
304
849
|
await this.host.stop(sessionId);
|
|
305
850
|
await this.disposeSessionBootstrap(sessionId);
|
|
306
851
|
};
|
|
852
|
+
/**
|
|
853
|
+
* Disposes the ClineCore instance and all associated resources.
|
|
854
|
+
*
|
|
855
|
+
* Shuts down the runtime host, closes connections, and cleans up all active sessions
|
|
856
|
+
* and bootstraps. Call this when you're done using the SDK instance, typically at
|
|
857
|
+
* application shutdown. After calling dispose, the instance cannot be reused.
|
|
858
|
+
*
|
|
859
|
+
* @example
|
|
860
|
+
* ```ts
|
|
861
|
+
* // Clean up when done
|
|
862
|
+
* await cline.dispose();
|
|
863
|
+
* ```
|
|
864
|
+
*/
|
|
307
865
|
dispose: RuntimeHost["dispose"] = async (...args) => {
|
|
308
866
|
try {
|
|
867
|
+
await this.automationService?.dispose();
|
|
309
868
|
await this.host.dispose(...args);
|
|
310
869
|
} finally {
|
|
311
870
|
this.unsubscribeBootstrapCleanup();
|
|
@@ -315,9 +874,65 @@ export class ClineCore implements RuntimeHost {
|
|
|
315
874
|
);
|
|
316
875
|
}
|
|
317
876
|
};
|
|
877
|
+
/**
|
|
878
|
+
* Retrieves information about a specific session by ID.
|
|
879
|
+
*
|
|
880
|
+
* Fetches the current metadata and state of a session, including configuration,
|
|
881
|
+
* status, and other session details.
|
|
882
|
+
*
|
|
883
|
+
* @example
|
|
884
|
+
* ```ts
|
|
885
|
+
* const session = await cline.get(sessionId);
|
|
886
|
+
* console.log("Session status:", session?.status);
|
|
887
|
+
* ```
|
|
888
|
+
*/
|
|
318
889
|
get: RuntimeHost["get"] = (...args) => this.host.get(...args);
|
|
319
|
-
|
|
320
|
-
|
|
890
|
+
/**
|
|
891
|
+
* Lists recent sessions through the shared history-listing path.
|
|
892
|
+
*/
|
|
893
|
+
listHistory = async (
|
|
894
|
+
options: ClineCoreListHistoryOptions = {},
|
|
895
|
+
): Promise<SessionHistoryRecord[]> =>
|
|
896
|
+
await listSessionHistory(this.host, options);
|
|
897
|
+
/**
|
|
898
|
+
* Lists recent sessions with inferred history display metadata.
|
|
899
|
+
*
|
|
900
|
+
* Retrieves a paginated list of recent sessions, optionally limited by the
|
|
901
|
+
* provided count.
|
|
902
|
+
*
|
|
903
|
+
* @param limit Maximum number of sessions to return (defaults to 200)
|
|
904
|
+
* @returns A promise resolving to an array of session history records
|
|
905
|
+
*
|
|
906
|
+
* @example
|
|
907
|
+
* ```ts
|
|
908
|
+
* const sessions = await cline.list(50);
|
|
909
|
+
* sessions.forEach((session) => {
|
|
910
|
+
* console.log(`Session ${session.sessionId}: ${session.metadata?.title}`);
|
|
911
|
+
* });
|
|
912
|
+
* ```
|
|
913
|
+
*/
|
|
914
|
+
list = async (
|
|
915
|
+
limit = 200,
|
|
916
|
+
options: Omit<ClineCoreListHistoryOptions, "limit"> = {},
|
|
917
|
+
): Promise<SessionHistoryRecord[]> =>
|
|
918
|
+
await this.listHistory({ ...options, limit });
|
|
919
|
+
/**
|
|
920
|
+
* Permanently deletes a session and all its associated data.
|
|
921
|
+
*
|
|
922
|
+
* Removes the session from storage and cleans up any related resources. This is
|
|
923
|
+
* a destructive operation that cannot be undone.
|
|
924
|
+
*
|
|
925
|
+
* @param sessionId The ID of the session to delete
|
|
926
|
+
* @returns A promise that resolves to true if the session was deleted, false if not found
|
|
927
|
+
*
|
|
928
|
+
* @example
|
|
929
|
+
* ```ts
|
|
930
|
+
* const deleted = await cline.delete(sessionId);
|
|
931
|
+
* if (deleted) {
|
|
932
|
+
* console.log("Session deleted successfully");
|
|
933
|
+
* }
|
|
934
|
+
* ```
|
|
935
|
+
*/
|
|
321
936
|
delete: RuntimeHost["delete"] = async (sessionId) => {
|
|
322
937
|
const deleted = await this.host.delete(sessionId);
|
|
323
938
|
if (deleted) {
|
|
@@ -325,17 +940,87 @@ export class ClineCore implements RuntimeHost {
|
|
|
325
940
|
}
|
|
326
941
|
return deleted;
|
|
327
942
|
};
|
|
943
|
+
/**
|
|
944
|
+
* Updates an existing session's metadata.
|
|
945
|
+
*
|
|
946
|
+
* Modifies session properties like title or other mutable metadata while preserving
|
|
947
|
+
* message history and other session data.
|
|
948
|
+
*
|
|
949
|
+
* @example
|
|
950
|
+
* ```ts
|
|
951
|
+
* await cline.update(sessionId, {
|
|
952
|
+
* title: "Updated session title",
|
|
953
|
+
* });
|
|
954
|
+
* ```
|
|
955
|
+
*/
|
|
328
956
|
update: RuntimeHost["update"] = (...args) => this.host.update(...args);
|
|
957
|
+
/**
|
|
958
|
+
* Reads message history for a session.
|
|
959
|
+
*
|
|
960
|
+
* Retrieves the full message transcript for a specific session, including all
|
|
961
|
+
* user messages, agent responses, and tool interactions.
|
|
962
|
+
*
|
|
963
|
+
* @example
|
|
964
|
+
* ```ts
|
|
965
|
+
* const messages = await cline.readMessages(sessionId);
|
|
966
|
+
* messages.forEach((msg) => {
|
|
967
|
+
* console.log(`${msg.role}: ${msg.content}`);
|
|
968
|
+
* });
|
|
969
|
+
* ```
|
|
970
|
+
*/
|
|
329
971
|
readMessages: RuntimeHost["readMessages"] = (...args) =>
|
|
330
972
|
this.host.readMessages(...args);
|
|
973
|
+
/**
|
|
974
|
+
* Handles hook events from the runtime environment.
|
|
975
|
+
*
|
|
976
|
+
* Processes system or environment events (e.g., workspace changes, external signals)
|
|
977
|
+
* that may affect the current session. This is typically called by the host environment
|
|
978
|
+
* rather than directly by consumer code.
|
|
979
|
+
*
|
|
980
|
+
* @internal
|
|
981
|
+
*/
|
|
331
982
|
handleHookEvent: RuntimeHost["handleHookEvent"] = (...args) =>
|
|
332
983
|
this.host.handleHookEvent(...args);
|
|
984
|
+
/**
|
|
985
|
+
* Subscribes to session events.
|
|
986
|
+
*
|
|
987
|
+
* Registers a listener for all session events (messages, state changes, errors, etc.).
|
|
988
|
+
* Returns an unsubscribe function to stop listening.
|
|
989
|
+
*
|
|
990
|
+
* @param listener Callback function invoked for each event
|
|
991
|
+
* @param options Optional configuration for the subscription
|
|
992
|
+
* @returns An unsubscribe function
|
|
993
|
+
*
|
|
994
|
+
* @example
|
|
995
|
+
* ```ts
|
|
996
|
+
* const unsubscribe = cline.subscribe((event) => {
|
|
997
|
+
* if (event.type === "message") {
|
|
998
|
+
* console.log("New message:", event.payload.message);
|
|
999
|
+
* }
|
|
1000
|
+
* });
|
|
1001
|
+
*
|
|
1002
|
+
* // Later, stop listening
|
|
1003
|
+
* unsubscribe();
|
|
1004
|
+
* ```
|
|
1005
|
+
*/
|
|
333
1006
|
subscribe(
|
|
334
1007
|
listener: (event: CoreSessionEvent) => void,
|
|
335
1008
|
options?: RuntimeHostSubscribeOptions,
|
|
336
1009
|
): () => void {
|
|
337
1010
|
return this.host.subscribe(listener, options);
|
|
338
1011
|
}
|
|
1012
|
+
/**
|
|
1013
|
+
* Updates the AI model used by an active session.
|
|
1014
|
+
*
|
|
1015
|
+
* Switches the session to use a different AI model while maintaining the session state
|
|
1016
|
+
* and message history. This allows you to continue a conversation with a different model.
|
|
1017
|
+
*
|
|
1018
|
+
* @example
|
|
1019
|
+
* ```ts
|
|
1020
|
+
* // Switch to a different model mid-session
|
|
1021
|
+
* await cline.updateSessionModel(sessionId, "claude-opus-4-1");
|
|
1022
|
+
* ```
|
|
1023
|
+
*/
|
|
339
1024
|
updateSessionModel: RuntimeHost["updateSessionModel"] = (...args) =>
|
|
340
1025
|
this.host.updateSessionModel?.(...args) ?? Promise.resolve();
|
|
341
1026
|
}
|