@clinebot/core 0.0.22 → 0.0.24
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 +110 -0
- package/dist/ClineCore.d.ts.map +1 -0
- package/dist/account/cline-account-service.d.ts +2 -1
- package/dist/account/cline-account-service.d.ts.map +1 -1
- package/dist/account/index.d.ts +1 -1
- package/dist/account/index.d.ts.map +1 -1
- package/dist/account/rpc.d.ts +3 -1
- package/dist/account/rpc.d.ts.map +1 -1
- package/dist/account/types.d.ts +3 -0
- package/dist/account/types.d.ts.map +1 -1
- package/dist/agents/plugin-loader.d.ts.map +1 -1
- package/dist/agents/plugin-sandbox-bootstrap.js +17 -17
- package/dist/auth/client.d.ts +1 -1
- package/dist/auth/client.d.ts.map +1 -1
- package/dist/auth/cline.d.ts +1 -1
- package/dist/auth/cline.d.ts.map +1 -1
- package/dist/auth/codex.d.ts +1 -1
- package/dist/auth/codex.d.ts.map +1 -1
- package/dist/auth/oca.d.ts +1 -1
- package/dist/auth/oca.d.ts.map +1 -1
- package/dist/auth/utils.d.ts +2 -2
- package/dist/auth/utils.d.ts.map +1 -1
- package/dist/index.d.ts +50 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +949 -0
- package/dist/providers/local-provider-service.d.ts +4 -4
- package/dist/providers/local-provider-service.d.ts.map +1 -1
- package/dist/runtime/runtime-builder.d.ts +1 -0
- package/dist/runtime/runtime-builder.d.ts.map +1 -1
- package/dist/runtime/session-runtime.d.ts +2 -1
- package/dist/runtime/session-runtime.d.ts.map +1 -1
- package/dist/runtime/team-runtime-registry.d.ts +13 -0
- package/dist/runtime/team-runtime-registry.d.ts.map +1 -0
- package/dist/session/default-session-manager.d.ts +2 -2
- package/dist/session/default-session-manager.d.ts.map +1 -1
- package/dist/session/rpc-runtime-ensure.d.ts +53 -0
- package/dist/session/rpc-runtime-ensure.d.ts.map +1 -0
- package/dist/session/session-config-builder.d.ts +2 -3
- package/dist/session/session-config-builder.d.ts.map +1 -1
- package/dist/session/session-host.d.ts +8 -18
- package/dist/session/session-host.d.ts.map +1 -1
- package/dist/session/session-manager.d.ts +1 -1
- package/dist/session/session-manager.d.ts.map +1 -1
- package/dist/session/session-manifest.d.ts +1 -2
- package/dist/session/session-manifest.d.ts.map +1 -1
- package/dist/session/unified-session-persistence-service.d.ts +2 -2
- package/dist/session/unified-session-persistence-service.d.ts.map +1 -1
- package/dist/session/utils/helpers.d.ts +1 -1
- package/dist/session/utils/helpers.d.ts.map +1 -1
- package/dist/session/utils/types.d.ts +1 -1
- package/dist/session/utils/types.d.ts.map +1 -1
- package/dist/storage/provider-settings-legacy-migration.d.ts.map +1 -1
- package/dist/telemetry/OpenTelemetryProvider.d.ts.map +1 -1
- package/dist/telemetry/distinct-id.d.ts +2 -0
- package/dist/telemetry/distinct-id.d.ts.map +1 -0
- package/dist/telemetry/{opentelemetry.d.ts → index.d.ts} +1 -1
- package/dist/telemetry/index.d.ts.map +1 -0
- package/dist/telemetry/index.js +28 -0
- package/dist/tools/constants.d.ts +1 -1
- package/dist/tools/constants.d.ts.map +1 -1
- package/dist/tools/definitions.d.ts +3 -3
- package/dist/tools/definitions.d.ts.map +1 -1
- package/dist/tools/executors/apply-patch.d.ts +1 -1
- package/dist/tools/executors/apply-patch.d.ts.map +1 -1
- package/dist/tools/executors/bash.d.ts +1 -1
- package/dist/tools/executors/bash.d.ts.map +1 -1
- package/dist/tools/executors/editor.d.ts +1 -1
- package/dist/tools/executors/editor.d.ts.map +1 -1
- package/dist/tools/executors/file-read.d.ts +1 -1
- package/dist/tools/executors/file-read.d.ts.map +1 -1
- package/dist/tools/executors/index.d.ts +14 -14
- package/dist/tools/executors/index.d.ts.map +1 -1
- package/dist/tools/executors/search.d.ts +1 -1
- package/dist/tools/executors/search.d.ts.map +1 -1
- package/dist/tools/executors/web-fetch.d.ts +1 -1
- package/dist/tools/executors/web-fetch.d.ts.map +1 -1
- package/dist/tools/helpers.d.ts +1 -1
- package/dist/tools/helpers.d.ts.map +1 -1
- package/dist/tools/index.d.ts +10 -10
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/model-tool-routing.d.ts +1 -1
- package/dist/tools/model-tool-routing.d.ts.map +1 -1
- package/dist/tools/presets.d.ts +1 -1
- package/dist/tools/presets.d.ts.map +1 -1
- package/dist/types/common.d.ts +17 -8
- package/dist/types/common.d.ts.map +1 -1
- package/dist/types/config.d.ts +4 -3
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/provider-settings.d.ts +1 -1
- package/dist/types/provider-settings.d.ts.map +1 -1
- package/dist/types.d.ts +5 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/package.json +44 -38
- package/src/ClineCore.ts +137 -0
- package/src/account/cline-account-service.test.ts +101 -0
- package/src/account/cline-account-service.ts +300 -0
- package/src/account/featurebase-token.test.ts +175 -0
- package/src/account/index.ts +23 -0
- package/src/account/rpc.test.ts +63 -0
- package/src/account/rpc.ts +185 -0
- package/src/account/types.ts +102 -0
- package/src/agents/agent-config-loader.test.ts +236 -0
- package/src/agents/agent-config-loader.ts +108 -0
- package/src/agents/agent-config-parser.ts +198 -0
- package/src/agents/hooks-config-loader.test.ts +20 -0
- package/src/agents/hooks-config-loader.ts +118 -0
- package/src/agents/index.ts +85 -0
- package/src/agents/plugin-config-loader.test.ts +140 -0
- package/src/agents/plugin-config-loader.ts +97 -0
- package/src/agents/plugin-loader.test.ts +210 -0
- package/src/agents/plugin-loader.ts +175 -0
- package/src/agents/plugin-sandbox-bootstrap.ts +448 -0
- package/src/agents/plugin-sandbox.test.ts +296 -0
- package/src/agents/plugin-sandbox.ts +341 -0
- package/src/agents/unified-config-file-watcher.test.ts +196 -0
- package/src/agents/unified-config-file-watcher.ts +483 -0
- package/src/agents/user-instruction-config-loader.test.ts +158 -0
- package/src/agents/user-instruction-config-loader.ts +438 -0
- package/src/auth/client.test.ts +40 -0
- package/src/auth/client.ts +25 -0
- package/src/auth/cline.test.ts +130 -0
- package/src/auth/cline.ts +420 -0
- package/src/auth/codex.test.ts +170 -0
- package/src/auth/codex.ts +491 -0
- package/src/auth/oca.test.ts +215 -0
- package/src/auth/oca.ts +573 -0
- package/src/auth/server.ts +216 -0
- package/src/auth/types.ts +81 -0
- package/src/auth/utils.test.ts +128 -0
- package/src/auth/utils.ts +247 -0
- package/src/chat/chat-schema.ts +82 -0
- package/src/index.ts +479 -0
- package/src/input/file-indexer.d.ts +11 -0
- package/src/input/file-indexer.test.ts +127 -0
- package/src/input/file-indexer.ts +327 -0
- package/src/input/index.ts +7 -0
- package/src/input/mention-enricher.test.ts +85 -0
- package/src/input/mention-enricher.ts +122 -0
- package/src/mcp/config-loader.test.ts +238 -0
- package/src/mcp/config-loader.ts +219 -0
- package/src/mcp/index.ts +26 -0
- package/src/mcp/manager.test.ts +106 -0
- package/src/mcp/manager.ts +262 -0
- package/src/mcp/types.ts +88 -0
- package/src/providers/local-provider-registry.ts +232 -0
- package/src/providers/local-provider-service.test.ts +783 -0
- package/src/providers/local-provider-service.ts +471 -0
- package/src/runtime/commands.test.ts +98 -0
- package/src/runtime/commands.ts +83 -0
- package/src/runtime/hook-file-hooks.test.ts +237 -0
- package/src/runtime/hook-file-hooks.ts +859 -0
- package/src/runtime/index.ts +37 -0
- package/src/runtime/rules.ts +34 -0
- package/src/runtime/runtime-builder.team-persistence.test.ts +245 -0
- package/src/runtime/runtime-builder.test.ts +371 -0
- package/src/runtime/runtime-builder.ts +631 -0
- package/src/runtime/runtime-parity.test.ts +143 -0
- package/src/runtime/sandbox/subprocess-sandbox.ts +231 -0
- package/src/runtime/session-runtime.ts +49 -0
- package/src/runtime/skills.ts +44 -0
- package/src/runtime/team-runtime-registry.ts +46 -0
- package/src/runtime/tool-approval.ts +104 -0
- package/src/runtime/workflows.test.ts +119 -0
- package/src/runtime/workflows.ts +45 -0
- package/src/session/default-session-manager.e2e.test.ts +384 -0
- package/src/session/default-session-manager.test.ts +1931 -0
- package/src/session/default-session-manager.ts +1422 -0
- package/src/session/file-session-service.ts +280 -0
- package/src/session/index.ts +45 -0
- package/src/session/rpc-runtime-ensure.ts +521 -0
- package/src/session/rpc-session-service.ts +107 -0
- package/src/session/rpc-spawn-lease.test.ts +49 -0
- package/src/session/rpc-spawn-lease.ts +122 -0
- package/src/session/runtime-oauth-token-manager.test.ts +137 -0
- package/src/session/runtime-oauth-token-manager.ts +272 -0
- package/src/session/session-agent-events.ts +248 -0
- package/src/session/session-artifacts.ts +106 -0
- package/src/session/session-config-builder.ts +113 -0
- package/src/session/session-graph.ts +92 -0
- package/src/session/session-host.test.ts +89 -0
- package/src/session/session-host.ts +205 -0
- package/src/session/session-manager.ts +69 -0
- package/src/session/session-manifest.ts +29 -0
- package/src/session/session-service.team-persistence.test.ts +48 -0
- package/src/session/session-service.ts +673 -0
- package/src/session/session-team-coordination.ts +229 -0
- package/src/session/session-telemetry.ts +100 -0
- package/src/session/sqlite-rpc-session-backend.ts +303 -0
- package/src/session/unified-session-persistence-service.test.ts +85 -0
- package/src/session/unified-session-persistence-service.ts +994 -0
- package/src/session/utils/helpers.ts +139 -0
- package/src/session/utils/types.ts +57 -0
- package/src/session/utils/usage.ts +32 -0
- package/src/session/workspace-manager.ts +98 -0
- package/src/session/workspace-manifest.ts +100 -0
- package/src/storage/artifact-store.ts +1 -0
- package/src/storage/file-team-store.ts +257 -0
- package/src/storage/index.ts +11 -0
- package/src/storage/provider-settings-legacy-migration.test.ts +424 -0
- package/src/storage/provider-settings-legacy-migration.ts +826 -0
- package/src/storage/provider-settings-manager.test.ts +191 -0
- package/src/storage/provider-settings-manager.ts +152 -0
- package/src/storage/session-store.ts +1 -0
- package/src/storage/sqlite-session-store.ts +275 -0
- package/src/storage/sqlite-team-store.ts +454 -0
- package/src/storage/team-store.ts +40 -0
- package/src/team/index.ts +4 -0
- package/src/team/projections.ts +285 -0
- package/src/telemetry/ITelemetryAdapter.ts +94 -0
- package/src/telemetry/LoggerTelemetryAdapter.test.ts +42 -0
- package/src/telemetry/LoggerTelemetryAdapter.ts +114 -0
- package/src/telemetry/OpenTelemetryAdapter.test.ts +157 -0
- package/src/telemetry/OpenTelemetryAdapter.ts +348 -0
- package/src/telemetry/OpenTelemetryProvider.test.ts +113 -0
- package/src/telemetry/OpenTelemetryProvider.ts +325 -0
- package/src/telemetry/TelemetryService.test.ts +134 -0
- package/src/telemetry/TelemetryService.ts +141 -0
- package/src/telemetry/core-events.ts +400 -0
- package/src/telemetry/distinct-id.test.ts +57 -0
- package/src/telemetry/distinct-id.ts +58 -0
- package/src/telemetry/index.ts +20 -0
- package/src/tools/constants.ts +35 -0
- package/src/tools/definitions.test.ts +704 -0
- package/src/tools/definitions.ts +709 -0
- package/src/tools/executors/apply-patch-parser.ts +520 -0
- package/src/tools/executors/apply-patch.ts +359 -0
- package/src/tools/executors/bash.test.ts +87 -0
- package/src/tools/executors/bash.ts +207 -0
- package/src/tools/executors/editor.test.ts +35 -0
- package/src/tools/executors/editor.ts +219 -0
- package/src/tools/executors/file-read.test.ts +49 -0
- package/src/tools/executors/file-read.ts +110 -0
- package/src/tools/executors/index.ts +87 -0
- package/src/tools/executors/search.ts +278 -0
- package/src/tools/executors/web-fetch.ts +259 -0
- package/src/tools/helpers.ts +130 -0
- package/src/tools/index.ts +169 -0
- package/src/tools/model-tool-routing.test.ts +86 -0
- package/src/tools/model-tool-routing.ts +132 -0
- package/src/tools/presets.test.ts +62 -0
- package/src/tools/presets.ts +168 -0
- package/src/tools/schemas.ts +327 -0
- package/src/tools/types.ts +329 -0
- package/src/types/common.ts +26 -0
- package/src/types/config.ts +86 -0
- package/src/types/events.ts +74 -0
- package/src/types/index.ts +24 -0
- package/src/types/provider-settings.ts +43 -0
- package/src/types/sessions.ts +16 -0
- package/src/types/storage.ts +64 -0
- package/src/types/workspace.ts +7 -0
- package/src/types.ts +132 -0
- package/src/version.ts +3 -0
- package/dist/index.node.d.ts +0 -47
- package/dist/index.node.d.ts.map +0 -1
- package/dist/index.node.js +0 -948
- package/dist/telemetry/opentelemetry.d.ts.map +0 -1
- package/dist/telemetry/opentelemetry.js +0 -27
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import { resolve } from "node:path";
|
|
4
|
+
import { getRpcServerDefaultAddress, getRpcServerHealth } from "@clinebot/rpc";
|
|
5
|
+
import { resolveSessionDataDir } from "@clinebot/shared/storage";
|
|
6
|
+
import type { ClineCoreOptions } from "../ClineCore";
|
|
7
|
+
import { SqliteSessionStore } from "../storage/sqlite-session-store";
|
|
8
|
+
import { resolveCoreDistinctId } from "../telemetry/distinct-id";
|
|
9
|
+
import { DefaultSessionManager } from "./default-session-manager";
|
|
10
|
+
import { FileSessionService } from "./file-session-service";
|
|
11
|
+
import {
|
|
12
|
+
ensureRpcRuntimeAddress,
|
|
13
|
+
resolveRpcOwnerContext,
|
|
14
|
+
} from "./rpc-runtime-ensure";
|
|
15
|
+
import { RpcCoreSessionService } from "./rpc-session-service";
|
|
16
|
+
import { tryAcquireRpcSpawnLease } from "./rpc-spawn-lease";
|
|
17
|
+
import type { SessionManager } from "./session-manager";
|
|
18
|
+
import { CoreSessionService } from "./session-service";
|
|
19
|
+
|
|
20
|
+
const DEFAULT_RPC_ADDRESS =
|
|
21
|
+
process.env.CLINE_RPC_ADDRESS?.trim() || getRpcServerDefaultAddress();
|
|
22
|
+
|
|
23
|
+
export type SessionBackend =
|
|
24
|
+
| RpcCoreSessionService
|
|
25
|
+
| CoreSessionService
|
|
26
|
+
| FileSessionService;
|
|
27
|
+
|
|
28
|
+
export type SessionHost = SessionManager;
|
|
29
|
+
|
|
30
|
+
let cachedBackend: SessionBackend | undefined;
|
|
31
|
+
let backendInitPromise: Promise<SessionBackend> | undefined;
|
|
32
|
+
|
|
33
|
+
async function reconcileDeadSessionsIfSupported(
|
|
34
|
+
backend: SessionBackend,
|
|
35
|
+
): Promise<void> {
|
|
36
|
+
const service = backend as SessionBackend & {
|
|
37
|
+
reconcileDeadSessions?: (limit?: number) => Promise<number>;
|
|
38
|
+
};
|
|
39
|
+
await service.reconcileDeadSessions?.().catch(() => {});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function startRpcServerInBackground(address: string): void {
|
|
43
|
+
const lease = tryAcquireRpcSpawnLease(address);
|
|
44
|
+
if (!lease) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const launcher = process.execPath;
|
|
48
|
+
const entryArg = process.argv[1]?.trim();
|
|
49
|
+
if (!entryArg) {
|
|
50
|
+
lease.release();
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const entry = resolve(process.cwd(), entryArg);
|
|
54
|
+
if (!existsSync(entry)) {
|
|
55
|
+
lease.release();
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const conditionsArg = process.execArgv.find((arg) =>
|
|
59
|
+
arg.startsWith("--conditions="),
|
|
60
|
+
);
|
|
61
|
+
const args = [
|
|
62
|
+
...(conditionsArg ? [conditionsArg] : []),
|
|
63
|
+
entry,
|
|
64
|
+
"rpc",
|
|
65
|
+
"start",
|
|
66
|
+
"--address",
|
|
67
|
+
address,
|
|
68
|
+
];
|
|
69
|
+
|
|
70
|
+
const child = spawn(launcher, args, {
|
|
71
|
+
detached: true,
|
|
72
|
+
stdio: "ignore",
|
|
73
|
+
env: {
|
|
74
|
+
...process.env,
|
|
75
|
+
CLINE_NO_INTERACTIVE: "1",
|
|
76
|
+
},
|
|
77
|
+
cwd: process.cwd(),
|
|
78
|
+
});
|
|
79
|
+
child.unref();
|
|
80
|
+
setTimeout(() => lease.release(), 10_000).unref();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async function tryConnectRpcBackend(
|
|
84
|
+
address: string,
|
|
85
|
+
): Promise<RpcCoreSessionService | undefined> {
|
|
86
|
+
try {
|
|
87
|
+
const health = await getRpcServerHealth(address);
|
|
88
|
+
if (!health) {
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
return new RpcCoreSessionService({
|
|
92
|
+
address,
|
|
93
|
+
sessionsDir: resolveSessionDataDir(),
|
|
94
|
+
});
|
|
95
|
+
} catch {
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function createLocalBackend(): SessionBackend {
|
|
101
|
+
try {
|
|
102
|
+
const store = new SqliteSessionStore();
|
|
103
|
+
store.init();
|
|
104
|
+
return new CoreSessionService(store);
|
|
105
|
+
} catch (error) {
|
|
106
|
+
console.warn(
|
|
107
|
+
"SQLite session persistence unavailable, falling back to file-based session storage.",
|
|
108
|
+
error,
|
|
109
|
+
);
|
|
110
|
+
return new FileSessionService();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export async function resolveSessionBackend(
|
|
115
|
+
options: ClineCoreOptions,
|
|
116
|
+
): Promise<SessionBackend> {
|
|
117
|
+
if (cachedBackend) {
|
|
118
|
+
return cachedBackend;
|
|
119
|
+
}
|
|
120
|
+
if (backendInitPromise) {
|
|
121
|
+
return await backendInitPromise;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const mode = options.backendMode ?? "auto";
|
|
125
|
+
const requestedAddress = options.rpc?.address?.trim() || DEFAULT_RPC_ADDRESS;
|
|
126
|
+
const attempts = Math.max(1, options.rpc?.connectAttempts ?? 5);
|
|
127
|
+
const delayMs = Math.max(0, options.rpc?.connectDelayMs ?? 100);
|
|
128
|
+
const autoStartRpc = options.rpc?.autoStart !== false;
|
|
129
|
+
|
|
130
|
+
backendInitPromise = (async () => {
|
|
131
|
+
if (mode === "local") {
|
|
132
|
+
cachedBackend = createLocalBackend();
|
|
133
|
+
await reconcileDeadSessionsIfSupported(cachedBackend);
|
|
134
|
+
return cachedBackend;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
let address = requestedAddress;
|
|
138
|
+
const existingRpcBackend = await tryConnectRpcBackend(address);
|
|
139
|
+
if (existingRpcBackend) {
|
|
140
|
+
cachedBackend = existingRpcBackend;
|
|
141
|
+
await reconcileDeadSessionsIfSupported(cachedBackend);
|
|
142
|
+
return cachedBackend;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (mode === "rpc") {
|
|
146
|
+
throw new Error(`RPC backend unavailable at ${address}`);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (autoStartRpc) {
|
|
150
|
+
try {
|
|
151
|
+
const ensured = await ensureRpcRuntimeAddress(address, {
|
|
152
|
+
resolveOwner: () => resolveRpcOwnerContext({ ownerPrefix: "core" }),
|
|
153
|
+
spawnIfNeeded: (rpcAddress) => {
|
|
154
|
+
startRpcServerInBackground(rpcAddress);
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
address = ensured.address;
|
|
158
|
+
} catch {
|
|
159
|
+
// Ignore launch failures and fall back to local backend.
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
for (let attempt = 0; attempt < attempts; attempt += 1) {
|
|
163
|
+
const rpcBackend = await tryConnectRpcBackend(address);
|
|
164
|
+
if (rpcBackend) {
|
|
165
|
+
cachedBackend = rpcBackend;
|
|
166
|
+
await reconcileDeadSessionsIfSupported(cachedBackend);
|
|
167
|
+
return cachedBackend;
|
|
168
|
+
}
|
|
169
|
+
if (delayMs > 0) {
|
|
170
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
cachedBackend = createLocalBackend();
|
|
176
|
+
await reconcileDeadSessionsIfSupported(cachedBackend);
|
|
177
|
+
return cachedBackend;
|
|
178
|
+
})().finally(() => {
|
|
179
|
+
backendInitPromise = undefined;
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
return await backendInitPromise;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* NOTE Internal only - replaced with ClineCore.create() for public API.
|
|
187
|
+
* Creates a SessionHost instance based on the provided options.
|
|
188
|
+
* This will attempt to connect to an RPC session service if configured, and fall back to a local session service if not.
|
|
189
|
+
*/
|
|
190
|
+
export async function createSessionHost(
|
|
191
|
+
options: ClineCoreOptions,
|
|
192
|
+
): Promise<SessionHost> {
|
|
193
|
+
const distinctId = resolveCoreDistinctId(options.distinctId);
|
|
194
|
+
options.telemetry?.setDistinctId(distinctId);
|
|
195
|
+
const backend =
|
|
196
|
+
options.sessionService ?? (await resolveSessionBackend(options));
|
|
197
|
+
return new DefaultSessionManager({
|
|
198
|
+
sessionService: backend,
|
|
199
|
+
defaultToolExecutors: options.defaultToolExecutors,
|
|
200
|
+
telemetry: options.telemetry,
|
|
201
|
+
toolPolicies: options.toolPolicies,
|
|
202
|
+
requestToolApproval: options.requestToolApproval,
|
|
203
|
+
distinctId,
|
|
204
|
+
});
|
|
205
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { AgentResult } from "@clinebot/agents";
|
|
2
|
+
import type * as LlmsProviders from "@clinebot/llms/providers";
|
|
3
|
+
import type { SessionSource } from "../types/common";
|
|
4
|
+
import type { CoreSessionConfig } from "../types/config";
|
|
5
|
+
import type { CoreSessionEvent } from "../types/events";
|
|
6
|
+
import type { SessionRecord } from "../types/sessions";
|
|
7
|
+
import type { SessionManifest } from "./session-manifest";
|
|
8
|
+
|
|
9
|
+
export interface StartSessionInput {
|
|
10
|
+
config: CoreSessionConfig;
|
|
11
|
+
source?: SessionSource;
|
|
12
|
+
prompt?: string;
|
|
13
|
+
interactive?: boolean;
|
|
14
|
+
initialMessages?: LlmsProviders.Message[];
|
|
15
|
+
userImages?: string[];
|
|
16
|
+
userFiles?: string[];
|
|
17
|
+
userInstructionWatcher?: import("../agents").UserInstructionConfigWatcher;
|
|
18
|
+
onTeamRestored?: () => void;
|
|
19
|
+
defaultToolExecutors?: Partial<import("../tools").ToolExecutors>;
|
|
20
|
+
toolPolicies?: import("@clinebot/agents").AgentConfig["toolPolicies"];
|
|
21
|
+
requestToolApproval?: (
|
|
22
|
+
request: import("@clinebot/agents").ToolApprovalRequest,
|
|
23
|
+
) => Promise<import("@clinebot/agents").ToolApprovalResult>;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface StartSessionResult {
|
|
27
|
+
sessionId: string;
|
|
28
|
+
manifest: SessionManifest;
|
|
29
|
+
manifestPath: string;
|
|
30
|
+
transcriptPath: string;
|
|
31
|
+
hookPath: string;
|
|
32
|
+
messagesPath: string;
|
|
33
|
+
result?: AgentResult;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface SendSessionInput {
|
|
37
|
+
sessionId: string;
|
|
38
|
+
prompt: string;
|
|
39
|
+
userImages?: string[];
|
|
40
|
+
userFiles?: string[];
|
|
41
|
+
delivery?: "queue" | "steer";
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface SessionAccumulatedUsage {
|
|
45
|
+
inputTokens: number;
|
|
46
|
+
outputTokens: number;
|
|
47
|
+
cacheReadTokens: number;
|
|
48
|
+
cacheWriteTokens: number;
|
|
49
|
+
totalCost: number;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface SessionManager {
|
|
53
|
+
start(input: StartSessionInput): Promise<StartSessionResult>;
|
|
54
|
+
send(input: SendSessionInput): Promise<AgentResult | undefined>;
|
|
55
|
+
getAccumulatedUsage(
|
|
56
|
+
sessionId: string,
|
|
57
|
+
): Promise<SessionAccumulatedUsage | undefined>;
|
|
58
|
+
abort(sessionId: string, reason?: unknown): Promise<void>;
|
|
59
|
+
stop(sessionId: string): Promise<void>;
|
|
60
|
+
dispose(reason?: string): Promise<void>;
|
|
61
|
+
get(sessionId: string): Promise<SessionRecord | undefined>;
|
|
62
|
+
list(limit?: number): Promise<SessionRecord[]>;
|
|
63
|
+
delete(sessionId: string): Promise<boolean>;
|
|
64
|
+
readMessages(sessionId: string): Promise<LlmsProviders.Message[]>;
|
|
65
|
+
readTranscript(sessionId: string, maxChars?: number): Promise<string>;
|
|
66
|
+
readHooks(sessionId: string, limit?: number): Promise<unknown[]>;
|
|
67
|
+
subscribe(listener: (event: CoreSessionEvent) => void): () => void;
|
|
68
|
+
updateSessionModel?(sessionId: string, modelId: string): Promise<void>;
|
|
69
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { SESSION_STATUSES } from "../types/common";
|
|
3
|
+
|
|
4
|
+
const SessionStatusSchema = z.enum(SESSION_STATUSES);
|
|
5
|
+
|
|
6
|
+
export const SessionManifestSchema = z.object({
|
|
7
|
+
version: z.literal(1),
|
|
8
|
+
session_id: z.string().min(1),
|
|
9
|
+
source: z.string().min(1),
|
|
10
|
+
pid: z.number().int(),
|
|
11
|
+
started_at: z.string().min(1),
|
|
12
|
+
ended_at: z.string().min(1).optional(),
|
|
13
|
+
exit_code: z.number().int().nullable().optional(),
|
|
14
|
+
status: SessionStatusSchema,
|
|
15
|
+
interactive: z.boolean(),
|
|
16
|
+
provider: z.string().min(1),
|
|
17
|
+
model: z.string().min(1),
|
|
18
|
+
cwd: z.string().min(1),
|
|
19
|
+
workspace_root: z.string().min(1),
|
|
20
|
+
team_name: z.string().min(1).optional(),
|
|
21
|
+
enable_tools: z.boolean(),
|
|
22
|
+
enable_spawn: z.boolean(),
|
|
23
|
+
enable_teams: z.boolean(),
|
|
24
|
+
prompt: z.string().optional(),
|
|
25
|
+
metadata: z.record(z.string(), z.unknown()).optional(),
|
|
26
|
+
messages_path: z.string().min(1).optional(),
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
export type SessionManifest = z.infer<typeof SessionManifestSchema>;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { existsSync, mkdtempSync } from "node:fs";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { AgentTeamsRuntime } from "@clinebot/agents";
|
|
5
|
+
import { describe, expect, it } from "vitest";
|
|
6
|
+
import { FileTeamPersistenceStore } from "./session-service";
|
|
7
|
+
|
|
8
|
+
describe("FileTeamPersistenceStore", () => {
|
|
9
|
+
it("does not create state.json for an empty runtime", () => {
|
|
10
|
+
const baseDir = mkdtempSync(join(tmpdir(), "team-store-"));
|
|
11
|
+
const store = new FileTeamPersistenceStore({
|
|
12
|
+
teamName: "agent-team-nmnn9",
|
|
13
|
+
baseDir,
|
|
14
|
+
});
|
|
15
|
+
const runtime = new AgentTeamsRuntime({ teamName: "agent-team-nmnn9" });
|
|
16
|
+
|
|
17
|
+
store.persist(runtime);
|
|
18
|
+
|
|
19
|
+
expect(
|
|
20
|
+
existsSync(join(baseDir, "agent-team-nmnn9", "state.json")),
|
|
21
|
+
).toBeFalsy();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("removes persisted state when runtime becomes empty again", () => {
|
|
25
|
+
const baseDir = mkdtempSync(join(tmpdir(), "team-store-"));
|
|
26
|
+
const store = new FileTeamPersistenceStore({
|
|
27
|
+
teamName: "agent-team-cleanup",
|
|
28
|
+
baseDir,
|
|
29
|
+
});
|
|
30
|
+
const runtime = new AgentTeamsRuntime({ teamName: "agent-team-cleanup" });
|
|
31
|
+
|
|
32
|
+
store.upsertTeammateSpec({
|
|
33
|
+
agentId: "worker",
|
|
34
|
+
rolePrompt: "Implement tasks",
|
|
35
|
+
});
|
|
36
|
+
store.persist(runtime);
|
|
37
|
+
expect(
|
|
38
|
+
existsSync(join(baseDir, "agent-team-cleanup", "state.json")),
|
|
39
|
+
).toBeTruthy();
|
|
40
|
+
|
|
41
|
+
store.removeTeammateSpec("worker");
|
|
42
|
+
runtime.cleanup();
|
|
43
|
+
store.persist(runtime);
|
|
44
|
+
expect(
|
|
45
|
+
existsSync(join(baseDir, "agent-team-cleanup", "state.json")),
|
|
46
|
+
).toBeFalsy();
|
|
47
|
+
});
|
|
48
|
+
});
|