@clinebot/core 0.0.21 → 0.0.23
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,280 @@
|
|
|
1
|
+
import {
|
|
2
|
+
existsSync,
|
|
3
|
+
mkdirSync,
|
|
4
|
+
readFileSync,
|
|
5
|
+
renameSync,
|
|
6
|
+
writeFileSync,
|
|
7
|
+
} from "node:fs";
|
|
8
|
+
import { join } from "node:path";
|
|
9
|
+
import { resolveSessionDataDir } from "@clinebot/shared/storage";
|
|
10
|
+
import type { SessionRow } from "./session-service";
|
|
11
|
+
import type {
|
|
12
|
+
PersistedSessionUpdateInput,
|
|
13
|
+
SessionPersistenceAdapter,
|
|
14
|
+
} from "./unified-session-persistence-service";
|
|
15
|
+
import { UnifiedSessionPersistenceService } from "./unified-session-persistence-service";
|
|
16
|
+
|
|
17
|
+
interface FileSessionIndex {
|
|
18
|
+
version: 1;
|
|
19
|
+
sessions: Record<string, SessionRow>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
interface FileSpawnRequest {
|
|
23
|
+
id: number;
|
|
24
|
+
rootSessionId: string;
|
|
25
|
+
parentAgentId: string;
|
|
26
|
+
task?: string;
|
|
27
|
+
systemPrompt?: string;
|
|
28
|
+
createdAt: string;
|
|
29
|
+
consumedAt?: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface FileSpawnQueue {
|
|
33
|
+
version: 1;
|
|
34
|
+
nextId: number;
|
|
35
|
+
requests: FileSpawnRequest[];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function nowIso(): string {
|
|
39
|
+
return new Date().toISOString();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function atomicWriteJson(path: string, value: unknown): void {
|
|
43
|
+
const tempPath = `${path}.tmp`;
|
|
44
|
+
writeFileSync(tempPath, `${JSON.stringify(value, null, 2)}\n`, "utf8");
|
|
45
|
+
renameSync(tempPath, path);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function defaultSessionsDir(): string {
|
|
49
|
+
return resolveSessionDataDir();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
class FileSessionPersistenceAdapter implements SessionPersistenceAdapter {
|
|
53
|
+
constructor(
|
|
54
|
+
private readonly sessionsDirPath: string = defaultSessionsDir(),
|
|
55
|
+
) {}
|
|
56
|
+
|
|
57
|
+
ensureSessionsDir(): string {
|
|
58
|
+
if (!existsSync(this.sessionsDirPath)) {
|
|
59
|
+
mkdirSync(this.sessionsDirPath, { recursive: true });
|
|
60
|
+
}
|
|
61
|
+
return this.sessionsDirPath;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
private indexPath(): string {
|
|
65
|
+
return join(this.ensureSessionsDir(), "sessions.index.json");
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
private spawnQueuePath(): string {
|
|
69
|
+
return join(this.ensureSessionsDir(), "subagent-spawn-queue.json");
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
private readIndex(): FileSessionIndex {
|
|
73
|
+
const path = this.indexPath();
|
|
74
|
+
if (!existsSync(path)) {
|
|
75
|
+
return { version: 1, sessions: {} };
|
|
76
|
+
}
|
|
77
|
+
try {
|
|
78
|
+
const parsed = JSON.parse(readFileSync(path, "utf8")) as FileSessionIndex;
|
|
79
|
+
if (parsed?.version === 1 && parsed.sessions) {
|
|
80
|
+
return parsed;
|
|
81
|
+
}
|
|
82
|
+
} catch {
|
|
83
|
+
// Ignore invalid persistence and fall back to an empty index.
|
|
84
|
+
}
|
|
85
|
+
return { version: 1, sessions: {} };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
private writeIndex(index: FileSessionIndex): void {
|
|
89
|
+
atomicWriteJson(this.indexPath(), index);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
private readQueue(): FileSpawnQueue {
|
|
93
|
+
const path = this.spawnQueuePath();
|
|
94
|
+
if (!existsSync(path)) {
|
|
95
|
+
return { version: 1, nextId: 1, requests: [] };
|
|
96
|
+
}
|
|
97
|
+
try {
|
|
98
|
+
const parsed = JSON.parse(readFileSync(path, "utf8")) as FileSpawnQueue;
|
|
99
|
+
if (
|
|
100
|
+
parsed?.version === 1 &&
|
|
101
|
+
typeof parsed.nextId === "number" &&
|
|
102
|
+
Array.isArray(parsed.requests)
|
|
103
|
+
) {
|
|
104
|
+
return parsed;
|
|
105
|
+
}
|
|
106
|
+
} catch {
|
|
107
|
+
// Ignore invalid persistence and fall back to an empty queue.
|
|
108
|
+
}
|
|
109
|
+
return { version: 1, nextId: 1, requests: [] };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
private writeQueue(queue: FileSpawnQueue): void {
|
|
113
|
+
atomicWriteJson(this.spawnQueuePath(), queue);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
async upsertSession(row: SessionRow): Promise<void> {
|
|
117
|
+
const index = this.readIndex();
|
|
118
|
+
index.sessions[row.sessionId] = row;
|
|
119
|
+
this.writeIndex(index);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
async getSession(sessionId: string): Promise<SessionRow | undefined> {
|
|
123
|
+
return this.readIndex().sessions[sessionId];
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
async listSessions(options: {
|
|
127
|
+
limit: number;
|
|
128
|
+
parentSessionId?: string;
|
|
129
|
+
status?: string;
|
|
130
|
+
}): Promise<SessionRow[]> {
|
|
131
|
+
return Object.values(this.readIndex().sessions)
|
|
132
|
+
.filter((row) =>
|
|
133
|
+
options.parentSessionId !== undefined
|
|
134
|
+
? row.parentSessionId === options.parentSessionId
|
|
135
|
+
: true,
|
|
136
|
+
)
|
|
137
|
+
.filter((row) =>
|
|
138
|
+
options.status !== undefined ? row.status === options.status : true,
|
|
139
|
+
)
|
|
140
|
+
.sort((a, b) => b.startedAt.localeCompare(a.startedAt))
|
|
141
|
+
.slice(0, options.limit);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
async updateSession(
|
|
145
|
+
input: PersistedSessionUpdateInput,
|
|
146
|
+
): Promise<{ updated: boolean; statusLock: number }> {
|
|
147
|
+
const index = this.readIndex();
|
|
148
|
+
const existing = index.sessions[input.sessionId];
|
|
149
|
+
if (!existing) {
|
|
150
|
+
return { updated: false, statusLock: 0 };
|
|
151
|
+
}
|
|
152
|
+
if (
|
|
153
|
+
input.expectedStatusLock !== undefined &&
|
|
154
|
+
existing.statusLock !== input.expectedStatusLock
|
|
155
|
+
) {
|
|
156
|
+
return { updated: false, statusLock: existing.statusLock };
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const nextStatusLock =
|
|
160
|
+
input.expectedStatusLock !== undefined
|
|
161
|
+
? input.expectedStatusLock + 1
|
|
162
|
+
: existing.statusLock;
|
|
163
|
+
const next: SessionRow = {
|
|
164
|
+
...existing,
|
|
165
|
+
status: input.status ?? existing.status,
|
|
166
|
+
endedAt:
|
|
167
|
+
input.endedAt !== undefined
|
|
168
|
+
? input.endedAt
|
|
169
|
+
: (existing.endedAt ?? null),
|
|
170
|
+
exitCode:
|
|
171
|
+
input.exitCode !== undefined
|
|
172
|
+
? input.exitCode
|
|
173
|
+
: (existing.exitCode ?? null),
|
|
174
|
+
prompt:
|
|
175
|
+
input.prompt !== undefined ? input.prompt : (existing.prompt ?? null),
|
|
176
|
+
metadata:
|
|
177
|
+
input.metadata !== undefined
|
|
178
|
+
? (input.metadata ?? null)
|
|
179
|
+
: (existing.metadata ?? null),
|
|
180
|
+
parentSessionId:
|
|
181
|
+
input.parentSessionId !== undefined
|
|
182
|
+
? (input.parentSessionId ?? null)
|
|
183
|
+
: (existing.parentSessionId ?? null),
|
|
184
|
+
parentAgentId:
|
|
185
|
+
input.parentAgentId !== undefined
|
|
186
|
+
? (input.parentAgentId ?? null)
|
|
187
|
+
: (existing.parentAgentId ?? null),
|
|
188
|
+
agentId:
|
|
189
|
+
input.agentId !== undefined
|
|
190
|
+
? (input.agentId ?? null)
|
|
191
|
+
: (existing.agentId ?? null),
|
|
192
|
+
conversationId:
|
|
193
|
+
input.conversationId !== undefined
|
|
194
|
+
? (input.conversationId ?? null)
|
|
195
|
+
: (existing.conversationId ?? null),
|
|
196
|
+
statusLock: nextStatusLock,
|
|
197
|
+
isSubagent:
|
|
198
|
+
input.setRunning || input.parentSessionId !== undefined
|
|
199
|
+
? true
|
|
200
|
+
: existing.isSubagent,
|
|
201
|
+
updatedAt: nowIso(),
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
if (input.setRunning) {
|
|
205
|
+
next.status = "running";
|
|
206
|
+
next.endedAt = null;
|
|
207
|
+
next.exitCode = null;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
index.sessions[input.sessionId] = next;
|
|
211
|
+
this.writeIndex(index);
|
|
212
|
+
return { updated: true, statusLock: next.statusLock };
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
async deleteSession(sessionId: string, cascade: boolean): Promise<boolean> {
|
|
216
|
+
const index = this.readIndex();
|
|
217
|
+
const existing = index.sessions[sessionId];
|
|
218
|
+
if (!existing) {
|
|
219
|
+
return false;
|
|
220
|
+
}
|
|
221
|
+
delete index.sessions[sessionId];
|
|
222
|
+
if (cascade) {
|
|
223
|
+
for (const row of Object.values(index.sessions)) {
|
|
224
|
+
if (row.parentSessionId === sessionId) {
|
|
225
|
+
delete index.sessions[row.sessionId];
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
this.writeIndex(index);
|
|
230
|
+
return true;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
async enqueueSpawnRequest(input: {
|
|
234
|
+
rootSessionId: string;
|
|
235
|
+
parentAgentId: string;
|
|
236
|
+
task?: string;
|
|
237
|
+
systemPrompt?: string;
|
|
238
|
+
}): Promise<void> {
|
|
239
|
+
const queue = this.readQueue();
|
|
240
|
+
queue.requests.push({
|
|
241
|
+
id: queue.nextId,
|
|
242
|
+
rootSessionId: input.rootSessionId,
|
|
243
|
+
parentAgentId: input.parentAgentId,
|
|
244
|
+
task: input.task,
|
|
245
|
+
systemPrompt: input.systemPrompt,
|
|
246
|
+
createdAt: nowIso(),
|
|
247
|
+
});
|
|
248
|
+
queue.nextId += 1;
|
|
249
|
+
this.writeQueue(queue);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
async claimSpawnRequest(
|
|
253
|
+
rootSessionId: string,
|
|
254
|
+
parentAgentId: string,
|
|
255
|
+
): Promise<string | undefined> {
|
|
256
|
+
const queue = this.readQueue();
|
|
257
|
+
const request = queue.requests.find(
|
|
258
|
+
(item) =>
|
|
259
|
+
item.rootSessionId === rootSessionId &&
|
|
260
|
+
item.parentAgentId === parentAgentId &&
|
|
261
|
+
!item.consumedAt,
|
|
262
|
+
);
|
|
263
|
+
if (!request) {
|
|
264
|
+
return undefined;
|
|
265
|
+
}
|
|
266
|
+
request.consumedAt = nowIso();
|
|
267
|
+
this.writeQueue(queue);
|
|
268
|
+
return request.task;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
export class FileSessionService extends UnifiedSessionPersistenceService {
|
|
273
|
+
constructor(sessionsDir?: string) {
|
|
274
|
+
super(new FileSessionPersistenceAdapter(sessionsDir));
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
override ensureSessionsDir(): string {
|
|
278
|
+
return super.ensureSessionsDir();
|
|
279
|
+
}
|
|
280
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export type {
|
|
2
|
+
ClineCore,
|
|
3
|
+
ClineCoreOptions,
|
|
4
|
+
} from "../ClineCore";
|
|
5
|
+
export { DefaultSessionManager } from "./default-session-manager";
|
|
6
|
+
export { RpcCoreSessionService } from "./rpc-session-service";
|
|
7
|
+
export {
|
|
8
|
+
deriveSubsessionStatus,
|
|
9
|
+
makeSubSessionId,
|
|
10
|
+
makeTeamTaskSubSessionId,
|
|
11
|
+
sanitizeSessionToken,
|
|
12
|
+
} from "./session-graph";
|
|
13
|
+
export type {
|
|
14
|
+
SessionBackend,
|
|
15
|
+
SessionHost,
|
|
16
|
+
} from "./session-host";
|
|
17
|
+
export { createSessionHost, resolveSessionBackend } from "./session-host";
|
|
18
|
+
export type {
|
|
19
|
+
SendSessionInput,
|
|
20
|
+
SessionAccumulatedUsage,
|
|
21
|
+
SessionManager,
|
|
22
|
+
StartSessionInput,
|
|
23
|
+
StartSessionResult,
|
|
24
|
+
} from "./session-manager";
|
|
25
|
+
export type { SessionManifest } from "./session-manifest";
|
|
26
|
+
export type {
|
|
27
|
+
CreateRootSessionWithArtifactsInput,
|
|
28
|
+
RootSessionArtifacts,
|
|
29
|
+
} from "./session-service";
|
|
30
|
+
export { CoreSessionService } from "./session-service";
|
|
31
|
+
export type {
|
|
32
|
+
WorkspaceManager,
|
|
33
|
+
WorkspaceManagerEvent,
|
|
34
|
+
} from "./workspace-manager";
|
|
35
|
+
export { InMemoryWorkspaceManager } from "./workspace-manager";
|
|
36
|
+
export type { WorkspaceManifest } from "./workspace-manifest";
|
|
37
|
+
export {
|
|
38
|
+
buildWorkspaceMetadata,
|
|
39
|
+
emptyWorkspaceManifest,
|
|
40
|
+
generateWorkspaceInfo,
|
|
41
|
+
normalizeWorkspacePath,
|
|
42
|
+
upsertWorkspaceInfo,
|
|
43
|
+
WorkspaceInfoSchema,
|
|
44
|
+
WorkspaceManifestSchema,
|
|
45
|
+
} from "./workspace-manifest";
|