@clinebot/shared 0.0.20 → 0.0.22
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/index.browser.d.ts +4 -1
- package/dist/index.browser.js +21 -21
- package/dist/index.d.ts +4 -1
- package/dist/index.js +27 -27
- package/dist/parse/shell.d.ts +2 -0
- package/dist/parse/string.d.ts +1 -0
- package/dist/session/index.d.ts +1 -0
- package/dist/storage/index.js +1 -1
- package/package.json +2 -3
- package/src/auth/constants.ts +0 -41
- package/src/connectors/adapters.ts +0 -152
- package/src/connectors/events.ts +0 -73
- package/src/db/index.ts +0 -14
- package/src/db/sqlite-db.ts +0 -329
- package/src/index.browser.ts +0 -187
- package/src/index.ts +0 -187
- package/src/llms/model-id.ts +0 -154
- package/src/llms/tools.ts +0 -137
- package/src/logging/logger.ts +0 -9
- package/src/parse/json.ts +0 -43
- package/src/parse/time.ts +0 -21
- package/src/parse/zod.ts +0 -23
- package/src/prompt/format.ts +0 -22
- package/src/remote-config/constants.ts +0 -5
- package/src/remote-config/schema.test.ts +0 -1004
- package/src/remote-config/schema.ts +0 -263
- package/src/rpc/index.ts +0 -4
- package/src/rpc/runtime.ts +0 -317
- package/src/rpc/team-progress.ts +0 -71
- package/src/services/telemetry-config.ts +0 -55
- package/src/services/telemetry.ts +0 -141
- package/src/session/hook-context.ts +0 -54
- package/src/session/records.ts +0 -40
- package/src/session/runtime-config.ts +0 -24
- package/src/session/runtime-env.ts +0 -8
- package/src/storage/index.ts +0 -37
- package/src/storage/paths.test.ts +0 -99
- package/src/storage/paths.ts +0 -400
- package/src/vcr.ts +0 -717
package/src/storage/paths.ts
DELETED
|
@@ -1,400 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
existsSync,
|
|
3
|
-
mkdirSync,
|
|
4
|
-
readdirSync,
|
|
5
|
-
readFileSync,
|
|
6
|
-
statSync,
|
|
7
|
-
} from "node:fs";
|
|
8
|
-
import { dirname, join, resolve } from "node:path";
|
|
9
|
-
|
|
10
|
-
export const AGENT_CONFIG_DIRECTORY_NAME = "agents";
|
|
11
|
-
export const HOOKS_CONFIG_DIRECTORY_NAME = "hooks";
|
|
12
|
-
export const SKILLS_CONFIG_DIRECTORY_NAME = "skills";
|
|
13
|
-
export const RULES_CONFIG_DIRECTORY_NAME = "rules";
|
|
14
|
-
export const WORKFLOWS_CONFIG_DIRECTORY_NAME = "workflows";
|
|
15
|
-
export const PLUGINS_DIRECTORY_NAME = "plugins";
|
|
16
|
-
export const CLINE_MCP_SETTINGS_FILE_NAME = "cline_mcp_settings.json";
|
|
17
|
-
|
|
18
|
-
let HOME_DIR = process?.env?.HOME || "~";
|
|
19
|
-
let HOME_DIR_SET_EXPLICITLY = false;
|
|
20
|
-
|
|
21
|
-
export function setHomeDir(dir: string) {
|
|
22
|
-
const trimmed = dir.trim();
|
|
23
|
-
if (!trimmed) {
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
HOME_DIR = trimmed;
|
|
27
|
-
HOME_DIR_SET_EXPLICITLY = true;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function setHomeDirIfUnset(dir: string) {
|
|
31
|
-
if (HOME_DIR_SET_EXPLICITLY) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
const trimmed = dir.trim();
|
|
35
|
-
if (!trimmed) {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
HOME_DIR = trimmed;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
let CLINE_DIR: string | undefined;
|
|
42
|
-
let CLINE_DIR_SET_EXPLICITLY = false;
|
|
43
|
-
|
|
44
|
-
export function setClineDir(dir: string): void {
|
|
45
|
-
const trimmed = dir.trim();
|
|
46
|
-
if (!trimmed) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
CLINE_DIR = trimmed;
|
|
50
|
-
CLINE_DIR_SET_EXPLICITLY = true;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export function setClineDirIfUnset(dir: string): void {
|
|
54
|
-
if (CLINE_DIR_SET_EXPLICITLY) {
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
const trimmed = dir.trim();
|
|
58
|
-
if (!trimmed) {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
CLINE_DIR = trimmed;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export function resolveClineDir(): string {
|
|
65
|
-
if (CLINE_DIR) {
|
|
66
|
-
return CLINE_DIR;
|
|
67
|
-
}
|
|
68
|
-
const envDir = process.env.CLINE_DIR?.trim();
|
|
69
|
-
if (envDir) {
|
|
70
|
-
return envDir;
|
|
71
|
-
}
|
|
72
|
-
return join(HOME_DIR, ".cline");
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export function resolveDocumentsClineDirectoryPath(): string {
|
|
76
|
-
return join(HOME_DIR, "Documents", "Cline");
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export function resolveDocumentsAgentConfigDirectoryPath(): string {
|
|
80
|
-
return join(resolveDocumentsClineDirectoryPath(), "Agents");
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export function resolveDocumentsHooksDirectoryPath(): string {
|
|
84
|
-
return join(resolveDocumentsClineDirectoryPath(), "Hooks");
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export function resolveDocumentsRulesDirectoryPath(): string {
|
|
88
|
-
return join(resolveDocumentsClineDirectoryPath(), "Rules");
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export function resolveDocumentsWorkflowsDirectoryPath(): string {
|
|
92
|
-
return join(resolveDocumentsClineDirectoryPath(), "Workflows");
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export function resolveDocumentsPluginsDirectoryPath(): string {
|
|
96
|
-
return join(HOME_DIR, "Documents", "Plugins");
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export function resolveClineDataDir(): string {
|
|
100
|
-
const explicitDir = process.env.CLINE_DATA_DIR?.trim();
|
|
101
|
-
if (explicitDir) {
|
|
102
|
-
return explicitDir;
|
|
103
|
-
}
|
|
104
|
-
return join(resolveClineDir(), "data");
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export function resolveSessionDataDir(): string {
|
|
108
|
-
const explicitDir = process.env.CLINE_SESSION_DATA_DIR?.trim();
|
|
109
|
-
if (explicitDir) {
|
|
110
|
-
return explicitDir;
|
|
111
|
-
}
|
|
112
|
-
return join(resolveClineDataDir(), "sessions");
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
export function resolveTeamDataDir(): string {
|
|
116
|
-
const explicitDir = process.env.CLINE_TEAM_DATA_DIR?.trim();
|
|
117
|
-
if (explicitDir) {
|
|
118
|
-
return explicitDir;
|
|
119
|
-
}
|
|
120
|
-
return join(resolveClineDataDir(), "teams");
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
export function resolveProviderSettingsPath(): string {
|
|
124
|
-
const explicitPath = process.env.CLINE_PROVIDER_SETTINGS_PATH?.trim();
|
|
125
|
-
if (explicitPath) {
|
|
126
|
-
return explicitPath;
|
|
127
|
-
}
|
|
128
|
-
return join(resolveClineDataDir(), "settings", "providers.json");
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export function resolveMcpSettingsPath(): string {
|
|
132
|
-
const explicitPath = process.env.CLINE_MCP_SETTINGS_PATH?.trim();
|
|
133
|
-
if (explicitPath) {
|
|
134
|
-
return explicitPath;
|
|
135
|
-
}
|
|
136
|
-
return join(resolveClineDataDir(), "settings", CLINE_MCP_SETTINGS_FILE_NAME);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
function dedupePaths(paths: ReadonlyArray<string>): string[] {
|
|
140
|
-
const seen = new Set<string>();
|
|
141
|
-
const deduped: string[] = [];
|
|
142
|
-
for (const candidate of paths) {
|
|
143
|
-
if (!candidate || seen.has(candidate)) {
|
|
144
|
-
continue;
|
|
145
|
-
}
|
|
146
|
-
seen.add(candidate);
|
|
147
|
-
deduped.push(candidate);
|
|
148
|
-
}
|
|
149
|
-
return deduped;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
function getWorkspaceSkillDirectories(workspacePath?: string): string[] {
|
|
153
|
-
if (!workspacePath) {
|
|
154
|
-
return [];
|
|
155
|
-
}
|
|
156
|
-
return [
|
|
157
|
-
join(workspacePath, ".clinerules", SKILLS_CONFIG_DIRECTORY_NAME),
|
|
158
|
-
join(workspacePath, ".cline", SKILLS_CONFIG_DIRECTORY_NAME),
|
|
159
|
-
join(workspacePath, ".claude", SKILLS_CONFIG_DIRECTORY_NAME),
|
|
160
|
-
join(workspacePath, ".agents", SKILLS_CONFIG_DIRECTORY_NAME),
|
|
161
|
-
];
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
export function resolveAgentsConfigDirPath(): string {
|
|
165
|
-
return join(resolveClineDataDir(), "settings", AGENT_CONFIG_DIRECTORY_NAME);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
export function resolveAgentConfigSearchPaths(): string[] {
|
|
169
|
-
return [
|
|
170
|
-
resolveDocumentsAgentConfigDirectoryPath(),
|
|
171
|
-
resolveAgentsConfigDirPath(),
|
|
172
|
-
];
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
export function resolveHooksConfigSearchPaths(
|
|
176
|
-
workspacePath?: string,
|
|
177
|
-
): string[] {
|
|
178
|
-
return dedupePaths([
|
|
179
|
-
workspacePath
|
|
180
|
-
? join(workspacePath, ".clinerules", HOOKS_CONFIG_DIRECTORY_NAME)
|
|
181
|
-
: "",
|
|
182
|
-
resolveDocumentsHooksDirectoryPath(),
|
|
183
|
-
]);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
export function resolveSkillsConfigSearchPaths(
|
|
187
|
-
workspacePath?: string,
|
|
188
|
-
): string[] {
|
|
189
|
-
return dedupePaths([
|
|
190
|
-
...getWorkspaceSkillDirectories(workspacePath),
|
|
191
|
-
join(resolveClineDataDir(), "settings", SKILLS_CONFIG_DIRECTORY_NAME),
|
|
192
|
-
join(resolveClineDir(), SKILLS_CONFIG_DIRECTORY_NAME),
|
|
193
|
-
join(HOME_DIR, ".agents", SKILLS_CONFIG_DIRECTORY_NAME),
|
|
194
|
-
]);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
export function resolveRulesConfigSearchPaths(
|
|
198
|
-
workspacePath?: string,
|
|
199
|
-
): string[] {
|
|
200
|
-
return dedupePaths([
|
|
201
|
-
workspacePath ? join(workspacePath, ".clinerules") : "",
|
|
202
|
-
join(resolveClineDataDir(), "settings", RULES_CONFIG_DIRECTORY_NAME),
|
|
203
|
-
resolveDocumentsRulesDirectoryPath(),
|
|
204
|
-
]);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
export function resolveWorkflowsConfigSearchPaths(
|
|
208
|
-
workspacePath?: string,
|
|
209
|
-
): string[] {
|
|
210
|
-
return dedupePaths([
|
|
211
|
-
workspacePath ? join(workspacePath, ".clinerules", "workflows") : "",
|
|
212
|
-
join(resolveClineDataDir(), "settings", WORKFLOWS_CONFIG_DIRECTORY_NAME),
|
|
213
|
-
resolveDocumentsWorkflowsDirectoryPath(),
|
|
214
|
-
]);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
export function resolvePluginConfigSearchPaths(
|
|
218
|
-
workspacePath?: string,
|
|
219
|
-
): string[] {
|
|
220
|
-
return dedupePaths([
|
|
221
|
-
workspacePath
|
|
222
|
-
? join(workspacePath, ".clinerules", PLUGINS_DIRECTORY_NAME)
|
|
223
|
-
: "",
|
|
224
|
-
join(resolveClineDir(), PLUGINS_DIRECTORY_NAME),
|
|
225
|
-
resolveDocumentsPluginsDirectoryPath(),
|
|
226
|
-
]);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
const PLUGIN_MODULE_EXTENSIONS = new Set([
|
|
230
|
-
".js",
|
|
231
|
-
".mjs",
|
|
232
|
-
".cjs",
|
|
233
|
-
".ts",
|
|
234
|
-
".mts",
|
|
235
|
-
".cts",
|
|
236
|
-
]);
|
|
237
|
-
const PLUGIN_PACKAGE_JSON_FILE_NAME = "package.json";
|
|
238
|
-
const PLUGIN_DIRECTORY_INDEX_CANDIDATES = [
|
|
239
|
-
"index.ts",
|
|
240
|
-
"index.mts",
|
|
241
|
-
"index.cts",
|
|
242
|
-
"index.js",
|
|
243
|
-
"index.mjs",
|
|
244
|
-
"index.cjs",
|
|
245
|
-
];
|
|
246
|
-
|
|
247
|
-
interface PluginPackageManifest {
|
|
248
|
-
plugins?: unknown;
|
|
249
|
-
extensions?: unknown;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
export function isPluginModulePath(path: string): boolean {
|
|
253
|
-
const dot = path.lastIndexOf(".");
|
|
254
|
-
if (dot === -1) {
|
|
255
|
-
return false;
|
|
256
|
-
}
|
|
257
|
-
return PLUGIN_MODULE_EXTENSIONS.has(path.slice(dot));
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
function readPluginPackageManifest(
|
|
261
|
-
packageJsonPath: string,
|
|
262
|
-
): PluginPackageManifest | null {
|
|
263
|
-
try {
|
|
264
|
-
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8")) as {
|
|
265
|
-
cline?: PluginPackageManifest;
|
|
266
|
-
};
|
|
267
|
-
if (!packageJson.cline || typeof packageJson.cline !== "object") {
|
|
268
|
-
return null;
|
|
269
|
-
}
|
|
270
|
-
return packageJson.cline;
|
|
271
|
-
} catch {
|
|
272
|
-
return null;
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
function getManifestPluginEntries(
|
|
277
|
-
manifest: PluginPackageManifest | null,
|
|
278
|
-
): string[] {
|
|
279
|
-
const entries = manifest?.plugins ?? manifest?.extensions;
|
|
280
|
-
if (!Array.isArray(entries)) {
|
|
281
|
-
return [];
|
|
282
|
-
}
|
|
283
|
-
return entries.filter((entry): entry is string => typeof entry === "string");
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
export function resolvePluginModuleEntries(
|
|
287
|
-
directoryPath: string,
|
|
288
|
-
): string[] | null {
|
|
289
|
-
const root = resolve(directoryPath);
|
|
290
|
-
if (!existsSync(root) || !statSync(root).isDirectory()) {
|
|
291
|
-
return null;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
const packageJsonPath = join(root, PLUGIN_PACKAGE_JSON_FILE_NAME);
|
|
295
|
-
if (existsSync(packageJsonPath)) {
|
|
296
|
-
const manifest = readPluginPackageManifest(packageJsonPath);
|
|
297
|
-
const entries = getManifestPluginEntries(manifest)
|
|
298
|
-
.map((entry) => resolve(root, entry))
|
|
299
|
-
.filter(
|
|
300
|
-
(entryPath) =>
|
|
301
|
-
existsSync(entryPath) &&
|
|
302
|
-
statSync(entryPath).isFile() &&
|
|
303
|
-
isPluginModulePath(entryPath),
|
|
304
|
-
);
|
|
305
|
-
if (entries.length > 0) {
|
|
306
|
-
return entries;
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
for (const candidate of PLUGIN_DIRECTORY_INDEX_CANDIDATES) {
|
|
311
|
-
const entryPath = join(root, candidate);
|
|
312
|
-
if (existsSync(entryPath) && statSync(entryPath).isFile()) {
|
|
313
|
-
return [entryPath];
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
return null;
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
export function discoverPluginModulePaths(directoryPath: string): string[] {
|
|
321
|
-
const root = resolve(directoryPath);
|
|
322
|
-
if (!existsSync(root)) {
|
|
323
|
-
return [];
|
|
324
|
-
}
|
|
325
|
-
const discovered: string[] = [];
|
|
326
|
-
const stack = [root];
|
|
327
|
-
while (stack.length > 0) {
|
|
328
|
-
const current = stack.pop();
|
|
329
|
-
if (!current) {
|
|
330
|
-
continue;
|
|
331
|
-
}
|
|
332
|
-
for (const entry of readdirSync(current, { withFileTypes: true })) {
|
|
333
|
-
const candidate = join(current, entry.name);
|
|
334
|
-
if (entry.isDirectory()) {
|
|
335
|
-
stack.push(candidate);
|
|
336
|
-
continue;
|
|
337
|
-
}
|
|
338
|
-
if (entry.name.startsWith(".")) {
|
|
339
|
-
continue;
|
|
340
|
-
}
|
|
341
|
-
if (entry.isFile() && isPluginModulePath(candidate)) {
|
|
342
|
-
discovered.push(candidate);
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
return discovered.sort((a, b) => a.localeCompare(b));
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
export function resolveConfiguredPluginModulePaths(
|
|
350
|
-
pluginPaths: ReadonlyArray<string>,
|
|
351
|
-
cwd: string,
|
|
352
|
-
): string[] {
|
|
353
|
-
const resolvedPaths: string[] = [];
|
|
354
|
-
for (const pluginPath of pluginPaths) {
|
|
355
|
-
const trimmed = pluginPath.trim();
|
|
356
|
-
if (!trimmed) {
|
|
357
|
-
continue;
|
|
358
|
-
}
|
|
359
|
-
const absolutePath = resolve(cwd, trimmed);
|
|
360
|
-
if (!existsSync(absolutePath)) {
|
|
361
|
-
throw new Error(`Plugin path does not exist: ${absolutePath}`);
|
|
362
|
-
}
|
|
363
|
-
const stats = statSync(absolutePath);
|
|
364
|
-
if (stats.isDirectory()) {
|
|
365
|
-
const entries = resolvePluginModuleEntries(absolutePath);
|
|
366
|
-
if (entries) {
|
|
367
|
-
resolvedPaths.push(...entries);
|
|
368
|
-
continue;
|
|
369
|
-
}
|
|
370
|
-
resolvedPaths.push(...discoverPluginModulePaths(absolutePath));
|
|
371
|
-
continue;
|
|
372
|
-
}
|
|
373
|
-
if (!isPluginModulePath(absolutePath)) {
|
|
374
|
-
throw new Error(
|
|
375
|
-
`Plugin file must use a supported extension (${[...PLUGIN_MODULE_EXTENSIONS].join(", ")}): ${absolutePath}`,
|
|
376
|
-
);
|
|
377
|
-
}
|
|
378
|
-
resolvedPaths.push(absolutePath);
|
|
379
|
-
}
|
|
380
|
-
return resolvedPaths;
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
export function ensureParentDir(filePath: string): void {
|
|
384
|
-
const parent = dirname(filePath);
|
|
385
|
-
if (!existsSync(parent)) {
|
|
386
|
-
mkdirSync(parent, { recursive: true });
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
export function ensureHookLogDir(filePath?: string): string {
|
|
391
|
-
if (filePath?.trim()) {
|
|
392
|
-
ensureParentDir(filePath);
|
|
393
|
-
return dirname(filePath);
|
|
394
|
-
}
|
|
395
|
-
const dir = join(resolveClineDataDir(), "hooks");
|
|
396
|
-
if (!existsSync(dir)) {
|
|
397
|
-
mkdirSync(dir, { recursive: true });
|
|
398
|
-
}
|
|
399
|
-
return dir;
|
|
400
|
-
}
|