@clinebot/shared 0.0.8 → 0.0.9

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.
@@ -0,0 +1,29 @@
1
+ export {
2
+ AGENT_CONFIG_DIRECTORY_NAME,
3
+ CLINE_MCP_SETTINGS_FILE_NAME,
4
+ ensureHookLogDir,
5
+ ensureParentDir,
6
+ HOOKS_CONFIG_DIRECTORY_NAME,
7
+ RULES_CONFIG_DIRECTORY_NAME,
8
+ resolveAgentConfigSearchPaths,
9
+ resolveAgentsConfigDirPath,
10
+ resolveClineDataDir,
11
+ resolveDocumentsAgentConfigDirectoryPath,
12
+ resolveDocumentsClineDirectoryPath,
13
+ resolveDocumentsHooksDirectoryPath,
14
+ resolveDocumentsRulesDirectoryPath,
15
+ resolveDocumentsWorkflowsDirectoryPath,
16
+ resolveHooksConfigSearchPaths,
17
+ resolveMcpSettingsPath,
18
+ resolvePluginConfigSearchPaths,
19
+ resolveProviderSettingsPath,
20
+ resolveRulesConfigSearchPaths,
21
+ resolveSessionDataDir,
22
+ resolveSkillsConfigSearchPaths,
23
+ resolveTeamDataDir,
24
+ resolveWorkflowsConfigSearchPaths,
25
+ SKILLS_CONFIG_DIRECTORY_NAME,
26
+ setHomeDir,
27
+ setHomeDirIfUnset,
28
+ WORKFLOWS_CONFIG_DIRECTORY_NAME,
29
+ } from "./paths";
@@ -0,0 +1,202 @@
1
+ import { existsSync, mkdirSync } from "node:fs";
2
+ import { dirname, join } from "node:path";
3
+
4
+ export const AGENT_CONFIG_DIRECTORY_NAME = "agents";
5
+ export const HOOKS_CONFIG_DIRECTORY_NAME = "hooks";
6
+ export const SKILLS_CONFIG_DIRECTORY_NAME = "skills";
7
+ export const RULES_CONFIG_DIRECTORY_NAME = "rules";
8
+ export const WORKFLOWS_CONFIG_DIRECTORY_NAME = "workflows";
9
+ export const PLUGINS_DIRECTORY_NAME = "plugins";
10
+ export const CLINE_MCP_SETTINGS_FILE_NAME = "cline_mcp_settings.json";
11
+
12
+ let HOME_DIR = process?.env?.HOME || "~";
13
+ let HOME_DIR_SET_EXPLICITLY = false;
14
+
15
+ export function setHomeDir(dir: string) {
16
+ const trimmed = dir.trim();
17
+ if (!trimmed) {
18
+ return;
19
+ }
20
+ HOME_DIR = trimmed;
21
+ HOME_DIR_SET_EXPLICITLY = true;
22
+ }
23
+
24
+ export function setHomeDirIfUnset(dir: string) {
25
+ if (HOME_DIR_SET_EXPLICITLY) {
26
+ return;
27
+ }
28
+ const trimmed = dir.trim();
29
+ if (!trimmed) {
30
+ return;
31
+ }
32
+ HOME_DIR = trimmed;
33
+ }
34
+
35
+ export function resolveDocumentsClineDirectoryPath(): string {
36
+ return join(HOME_DIR, "Documents", "Cline");
37
+ }
38
+
39
+ export function resolveDocumentsAgentConfigDirectoryPath(): string {
40
+ return join(resolveDocumentsClineDirectoryPath(), "Agents");
41
+ }
42
+
43
+ export function resolveDocumentsHooksDirectoryPath(): string {
44
+ return join(resolveDocumentsClineDirectoryPath(), "Hooks");
45
+ }
46
+
47
+ export function resolveDocumentsRulesDirectoryPath(): string {
48
+ return join(resolveDocumentsClineDirectoryPath(), "Rules");
49
+ }
50
+
51
+ export function resolveDocumentsWorkflowsDirectoryPath(): string {
52
+ return join(resolveDocumentsClineDirectoryPath(), "Workflows");
53
+ }
54
+
55
+ export function resolveClineDataDir(): string {
56
+ const explicitDir = process.env.CLINE_DATA_DIR?.trim();
57
+ if (explicitDir) {
58
+ return explicitDir;
59
+ }
60
+ return join(HOME_DIR, ".cline", "data");
61
+ }
62
+
63
+ export function resolveSessionDataDir(): string {
64
+ const explicitDir = process.env.CLINE_SESSION_DATA_DIR?.trim();
65
+ if (explicitDir) {
66
+ return explicitDir;
67
+ }
68
+ return join(resolveClineDataDir(), "sessions");
69
+ }
70
+
71
+ export function resolveTeamDataDir(): string {
72
+ const explicitDir = process.env.CLINE_TEAM_DATA_DIR?.trim();
73
+ if (explicitDir) {
74
+ return explicitDir;
75
+ }
76
+ return join(resolveClineDataDir(), "teams");
77
+ }
78
+
79
+ export function resolveProviderSettingsPath(): string {
80
+ const explicitPath = process.env.CLINE_PROVIDER_SETTINGS_PATH?.trim();
81
+ if (explicitPath) {
82
+ return explicitPath;
83
+ }
84
+ return join(resolveClineDataDir(), "settings", "providers.json");
85
+ }
86
+
87
+ export function resolveMcpSettingsPath(): string {
88
+ const explicitPath = process.env.CLINE_MCP_SETTINGS_PATH?.trim();
89
+ if (explicitPath) {
90
+ return explicitPath;
91
+ }
92
+ return join(resolveClineDataDir(), "settings", CLINE_MCP_SETTINGS_FILE_NAME);
93
+ }
94
+
95
+ function dedupePaths(paths: ReadonlyArray<string>): string[] {
96
+ const seen = new Set<string>();
97
+ const deduped: string[] = [];
98
+ for (const candidate of paths) {
99
+ if (!candidate || seen.has(candidate)) {
100
+ continue;
101
+ }
102
+ seen.add(candidate);
103
+ deduped.push(candidate);
104
+ }
105
+ return deduped;
106
+ }
107
+
108
+ function getWorkspaceSkillDirectories(workspacePath?: string): string[] {
109
+ if (!workspacePath) {
110
+ return [];
111
+ }
112
+ return [
113
+ join(workspacePath, ".clinerules", SKILLS_CONFIG_DIRECTORY_NAME),
114
+ join(workspacePath, ".cline", SKILLS_CONFIG_DIRECTORY_NAME),
115
+ join(workspacePath, ".claude", SKILLS_CONFIG_DIRECTORY_NAME),
116
+ join(workspacePath, ".agents", SKILLS_CONFIG_DIRECTORY_NAME),
117
+ ];
118
+ }
119
+
120
+ export function resolveAgentsConfigDirPath(): string {
121
+ return join(resolveClineDataDir(), "settings", AGENT_CONFIG_DIRECTORY_NAME);
122
+ }
123
+
124
+ export function resolveAgentConfigSearchPaths(): string[] {
125
+ return [
126
+ resolveDocumentsAgentConfigDirectoryPath(),
127
+ resolveAgentsConfigDirPath(),
128
+ ];
129
+ }
130
+
131
+ export function resolveHooksConfigSearchPaths(
132
+ workspacePath?: string,
133
+ ): string[] {
134
+ return dedupePaths([
135
+ workspacePath
136
+ ? join(workspacePath, ".clinerules", HOOKS_CONFIG_DIRECTORY_NAME)
137
+ : "",
138
+ resolveDocumentsHooksDirectoryPath(),
139
+ ]);
140
+ }
141
+
142
+ export function resolveSkillsConfigSearchPaths(
143
+ workspacePath?: string,
144
+ ): string[] {
145
+ return dedupePaths([
146
+ ...getWorkspaceSkillDirectories(workspacePath),
147
+ join(resolveClineDataDir(), "settings", SKILLS_CONFIG_DIRECTORY_NAME),
148
+ join(HOME_DIR, ".cline", SKILLS_CONFIG_DIRECTORY_NAME),
149
+ join(HOME_DIR, ".agents", SKILLS_CONFIG_DIRECTORY_NAME),
150
+ ]);
151
+ }
152
+
153
+ export function resolveRulesConfigSearchPaths(
154
+ workspacePath?: string,
155
+ ): string[] {
156
+ return dedupePaths([
157
+ workspacePath ? join(workspacePath, ".clinerules") : "",
158
+ join(resolveClineDataDir(), "settings", RULES_CONFIG_DIRECTORY_NAME),
159
+ resolveDocumentsRulesDirectoryPath(),
160
+ ]);
161
+ }
162
+
163
+ export function resolveWorkflowsConfigSearchPaths(
164
+ workspacePath?: string,
165
+ ): string[] {
166
+ return dedupePaths([
167
+ workspacePath ? join(workspacePath, ".clinerules", "workflows") : "",
168
+ join(resolveClineDataDir(), "settings", WORKFLOWS_CONFIG_DIRECTORY_NAME),
169
+ resolveDocumentsWorkflowsDirectoryPath(),
170
+ ]);
171
+ }
172
+
173
+ export function resolvePluginConfigSearchPaths(
174
+ workspacePath?: string,
175
+ ): string[] {
176
+ return dedupePaths([
177
+ workspacePath
178
+ ? join(workspacePath, ".clinerules", PLUGINS_DIRECTORY_NAME)
179
+ : "",
180
+ join(HOME_DIR, ".cline", PLUGINS_DIRECTORY_NAME),
181
+ join(HOME_DIR, ".agents", PLUGINS_DIRECTORY_NAME),
182
+ ]);
183
+ }
184
+
185
+ export function ensureParentDir(filePath: string): void {
186
+ const parent = dirname(filePath);
187
+ if (!existsSync(parent)) {
188
+ mkdirSync(parent, { recursive: true });
189
+ }
190
+ }
191
+
192
+ export function ensureHookLogDir(filePath?: string): string {
193
+ if (filePath?.trim()) {
194
+ ensureParentDir(filePath);
195
+ return dirname(filePath);
196
+ }
197
+ const dir = join(resolveClineDataDir(), "hooks");
198
+ if (!existsSync(dir)) {
199
+ mkdirSync(dir, { recursive: true });
200
+ }
201
+ return dir;
202
+ }