@hyperwindmill/caretaker-cli 0.11.0

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.
Files changed (275) hide show
  1. package/LICENSE +110 -0
  2. package/README.md +25 -0
  3. package/dist/agents/dispatch.d.ts +35 -0
  4. package/dist/agents/dispatch.d.ts.map +1 -0
  5. package/dist/agents/dispatch.js +108 -0
  6. package/dist/agents/sync.d.ts +10 -0
  7. package/dist/agents/sync.d.ts.map +1 -0
  8. package/dist/agents/sync.js +95 -0
  9. package/dist/cli/index.d.ts +2 -0
  10. package/dist/cli/index.d.ts.map +1 -0
  11. package/dist/cli/index.js +50 -0
  12. package/dist/cli/run.d.ts +11 -0
  13. package/dist/cli/run.d.ts.map +1 -0
  14. package/dist/cli/run.js +89 -0
  15. package/dist/cli/web/fs.d.ts +3 -0
  16. package/dist/cli/web/fs.d.ts.map +1 -0
  17. package/dist/cli/web/fs.js +35 -0
  18. package/dist/cli/web/mcp_bridge.d.ts +7 -0
  19. package/dist/cli/web/mcp_bridge.d.ts.map +1 -0
  20. package/dist/cli/web/mcp_bridge.js +86 -0
  21. package/dist/cli/web/scheduler/heartbeat.d.ts +16 -0
  22. package/dist/cli/web/scheduler/heartbeat.d.ts.map +1 -0
  23. package/dist/cli/web/scheduler/heartbeat.js +181 -0
  24. package/dist/cli/web/scheduler/locks.d.ts +8 -0
  25. package/dist/cli/web/scheduler/locks.d.ts.map +1 -0
  26. package/dist/cli/web/scheduler/locks.js +7 -0
  27. package/dist/cli/web/scheduler/logs.d.ts +21 -0
  28. package/dist/cli/web/scheduler/logs.d.ts.map +1 -0
  29. package/dist/cli/web/scheduler/logs.js +62 -0
  30. package/dist/cli/web/scheduler/strategy.d.ts +6 -0
  31. package/dist/cli/web/scheduler/strategy.d.ts.map +1 -0
  32. package/dist/cli/web/scheduler/strategy.js +1 -0
  33. package/dist/cli/web/scheduler/task_review.d.ts +18 -0
  34. package/dist/cli/web/scheduler/task_review.d.ts.map +1 -0
  35. package/dist/cli/web/scheduler/task_review.js +77 -0
  36. package/dist/cli/web/scheduler/task_roles.d.ts +22 -0
  37. package/dist/cli/web/scheduler/task_roles.d.ts.map +1 -0
  38. package/dist/cli/web/scheduler/task_roles.js +70 -0
  39. package/dist/cli/web/scheduler/task_strategy.d.ts +2 -0
  40. package/dist/cli/web/scheduler/task_strategy.d.ts.map +1 -0
  41. package/dist/cli/web/scheduler/task_strategy.js +437 -0
  42. package/dist/cli/web/scheduler/telegram.d.ts +7 -0
  43. package/dist/cli/web/scheduler/telegram.d.ts.map +1 -0
  44. package/dist/cli/web/scheduler/telegram.js +393 -0
  45. package/dist/cli/web/scheduler.d.ts +15 -0
  46. package/dist/cli/web/scheduler.d.ts.map +1 -0
  47. package/dist/cli/web/scheduler.js +60 -0
  48. package/dist/cli/web/server.d.ts +38 -0
  49. package/dist/cli/web/server.d.ts.map +1 -0
  50. package/dist/cli/web/server.js +970 -0
  51. package/dist/commands/loader.d.ts +37 -0
  52. package/dist/commands/loader.d.ts.map +1 -0
  53. package/dist/commands/loader.js +110 -0
  54. package/dist/harness/claude_code_runner.d.ts +47 -0
  55. package/dist/harness/claude_code_runner.d.ts.map +1 -0
  56. package/dist/harness/claude_code_runner.js +325 -0
  57. package/dist/harness/claude_code_stream.d.ts +32 -0
  58. package/dist/harness/claude_code_stream.d.ts.map +1 -0
  59. package/dist/harness/claude_code_stream.js +121 -0
  60. package/dist/harness/context_files.d.ts +23 -0
  61. package/dist/harness/context_files.d.ts.map +1 -0
  62. package/dist/harness/context_files.js +126 -0
  63. package/dist/harness/history.d.ts +4 -0
  64. package/dist/harness/history.d.ts.map +1 -0
  65. package/dist/harness/history.js +120 -0
  66. package/dist/harness/index.d.ts +8 -0
  67. package/dist/harness/index.d.ts.map +1 -0
  68. package/dist/harness/index.js +8 -0
  69. package/dist/harness/loop.d.ts +73 -0
  70. package/dist/harness/loop.d.ts.map +1 -0
  71. package/dist/harness/loop.js +373 -0
  72. package/dist/harness/model_limits.d.ts +25 -0
  73. package/dist/harness/model_limits.d.ts.map +1 -0
  74. package/dist/harness/model_limits.js +67 -0
  75. package/dist/harness/models.d.ts +9 -0
  76. package/dist/harness/models.d.ts.map +1 -0
  77. package/dist/harness/models.js +38 -0
  78. package/dist/harness/prelude.d.ts +21 -0
  79. package/dist/harness/prelude.d.ts.map +1 -0
  80. package/dist/harness/prelude.js +41 -0
  81. package/dist/harness/provider.d.ts +87 -0
  82. package/dist/harness/provider.d.ts.map +1 -0
  83. package/dist/harness/provider.js +140 -0
  84. package/dist/harness/runtime_info.d.ts +7 -0
  85. package/dist/harness/runtime_info.d.ts.map +1 -0
  86. package/dist/harness/runtime_info.js +15 -0
  87. package/dist/harness/think_tag_splitter.d.ts +33 -0
  88. package/dist/harness/think_tag_splitter.d.ts.map +1 -0
  89. package/dist/harness/think_tag_splitter.js +70 -0
  90. package/dist/harness/title.d.ts +17 -0
  91. package/dist/harness/title.d.ts.map +1 -0
  92. package/dist/harness/title.js +75 -0
  93. package/dist/harness/tools/builtin/bash.d.ts +3 -0
  94. package/dist/harness/tools/builtin/bash.d.ts.map +1 -0
  95. package/dist/harness/tools/builtin/bash.js +137 -0
  96. package/dist/harness/tools/builtin/edit.d.ts +6 -0
  97. package/dist/harness/tools/builtin/edit.d.ts.map +1 -0
  98. package/dist/harness/tools/builtin/edit.js +85 -0
  99. package/dist/harness/tools/builtin/fetch.d.ts +3 -0
  100. package/dist/harness/tools/builtin/fetch.d.ts.map +1 -0
  101. package/dist/harness/tools/builtin/fetch.js +75 -0
  102. package/dist/harness/tools/builtin/get_agent_context.d.ts +3 -0
  103. package/dist/harness/tools/builtin/get_agent_context.d.ts.map +1 -0
  104. package/dist/harness/tools/builtin/get_agent_context.js +76 -0
  105. package/dist/harness/tools/builtin/glob.d.ts +3 -0
  106. package/dist/harness/tools/builtin/glob.d.ts.map +1 -0
  107. package/dist/harness/tools/builtin/glob.js +52 -0
  108. package/dist/harness/tools/builtin/grep.d.ts +3 -0
  109. package/dist/harness/tools/builtin/grep.d.ts.map +1 -0
  110. package/dist/harness/tools/builtin/grep.js +126 -0
  111. package/dist/harness/tools/builtin/index.d.ts +23 -0
  112. package/dist/harness/tools/builtin/index.d.ts.map +1 -0
  113. package/dist/harness/tools/builtin/index.js +74 -0
  114. package/dist/harness/tools/builtin/invoke_agent.d.ts +3 -0
  115. package/dist/harness/tools/builtin/invoke_agent.d.ts.map +1 -0
  116. package/dist/harness/tools/builtin/invoke_agent.js +106 -0
  117. package/dist/harness/tools/builtin/invoke_command.d.ts +3 -0
  118. package/dist/harness/tools/builtin/invoke_command.d.ts.map +1 -0
  119. package/dist/harness/tools/builtin/invoke_command.js +42 -0
  120. package/dist/harness/tools/builtin/list_agents.d.ts +3 -0
  121. package/dist/harness/tools/builtin/list_agents.d.ts.map +1 -0
  122. package/dist/harness/tools/builtin/list_agents.js +32 -0
  123. package/dist/harness/tools/builtin/list_commands.d.ts +3 -0
  124. package/dist/harness/tools/builtin/list_commands.d.ts.map +1 -0
  125. package/dist/harness/tools/builtin/list_commands.js +27 -0
  126. package/dist/harness/tools/builtin/list_skills.d.ts +3 -0
  127. package/dist/harness/tools/builtin/list_skills.d.ts.map +1 -0
  128. package/dist/harness/tools/builtin/list_skills.js +24 -0
  129. package/dist/harness/tools/builtin/multiedit.d.ts +3 -0
  130. package/dist/harness/tools/builtin/multiedit.d.ts.map +1 -0
  131. package/dist/harness/tools/builtin/multiedit.js +88 -0
  132. package/dist/harness/tools/builtin/read_attachment.d.ts +3 -0
  133. package/dist/harness/tools/builtin/read_attachment.d.ts.map +1 -0
  134. package/dist/harness/tools/builtin/read_attachment.js +128 -0
  135. package/dist/harness/tools/builtin/read_document.d.ts +37 -0
  136. package/dist/harness/tools/builtin/read_document.d.ts.map +1 -0
  137. package/dist/harness/tools/builtin/read_document.js +238 -0
  138. package/dist/harness/tools/builtin/read_file.d.ts +3 -0
  139. package/dist/harness/tools/builtin/read_file.d.ts.map +1 -0
  140. package/dist/harness/tools/builtin/read_file.js +141 -0
  141. package/dist/harness/tools/builtin/read_image.d.ts +3 -0
  142. package/dist/harness/tools/builtin/read_image.d.ts.map +1 -0
  143. package/dist/harness/tools/builtin/read_image.js +80 -0
  144. package/dist/harness/tools/builtin/read_skill.d.ts +3 -0
  145. package/dist/harness/tools/builtin/read_skill.d.ts.map +1 -0
  146. package/dist/harness/tools/builtin/read_skill.js +30 -0
  147. package/dist/harness/tools/builtin/shell-env.d.ts +55 -0
  148. package/dist/harness/tools/builtin/shell-env.d.ts.map +1 -0
  149. package/dist/harness/tools/builtin/shell-env.js +181 -0
  150. package/dist/harness/tools/builtin/task_tools.d.ts +21 -0
  151. package/dist/harness/tools/builtin/task_tools.d.ts.map +1 -0
  152. package/dist/harness/tools/builtin/task_tools.js +708 -0
  153. package/dist/harness/tools/builtin/write.d.ts +3 -0
  154. package/dist/harness/tools/builtin/write.d.ts.map +1 -0
  155. package/dist/harness/tools/builtin/write.js +56 -0
  156. package/dist/harness/tools/index.d.ts +6 -0
  157. package/dist/harness/tools/index.d.ts.map +1 -0
  158. package/dist/harness/tools/index.js +7 -0
  159. package/dist/harness/tools/instance.d.ts +3 -0
  160. package/dist/harness/tools/instance.d.ts.map +1 -0
  161. package/dist/harness/tools/instance.js +19 -0
  162. package/dist/harness/tools/registry.d.ts +21 -0
  163. package/dist/harness/tools/registry.d.ts.map +1 -0
  164. package/dist/harness/tools/registry.js +33 -0
  165. package/dist/harness/tools/resolve.d.ts +5 -0
  166. package/dist/harness/tools/resolve.d.ts.map +1 -0
  167. package/dist/harness/tools/resolve.js +60 -0
  168. package/dist/harness/tools/sandbox.d.ts +6 -0
  169. package/dist/harness/tools/sandbox.d.ts.map +1 -0
  170. package/dist/harness/tools/sandbox.js +23 -0
  171. package/dist/harness/tools/types.d.ts +80 -0
  172. package/dist/harness/tools/types.d.ts.map +1 -0
  173. package/dist/harness/tools/types.js +16 -0
  174. package/dist/index.d.ts +3 -0
  175. package/dist/index.d.ts.map +1 -0
  176. package/dist/index.js +46 -0
  177. package/dist/lib/encryption.d.ts +24 -0
  178. package/dist/lib/encryption.d.ts.map +1 -0
  179. package/dist/lib/encryption.js +163 -0
  180. package/dist/lib/open_url.d.ts +9 -0
  181. package/dist/lib/open_url.d.ts.map +1 -0
  182. package/dist/lib/open_url.js +23 -0
  183. package/dist/lib/task_git.d.ts +11 -0
  184. package/dist/lib/task_git.d.ts.map +1 -0
  185. package/dist/lib/task_git.js +100 -0
  186. package/dist/mcp/adapter.d.ts +9 -0
  187. package/dist/mcp/adapter.d.ts.map +1 -0
  188. package/dist/mcp/adapter.js +74 -0
  189. package/dist/mcp/client.d.ts +50 -0
  190. package/dist/mcp/client.d.ts.map +1 -0
  191. package/dist/mcp/client.js +243 -0
  192. package/dist/mcp/oauth.d.ts +30 -0
  193. package/dist/mcp/oauth.d.ts.map +1 -0
  194. package/dist/mcp/oauth.js +171 -0
  195. package/dist/mcp/oauth_callback.d.ts +9 -0
  196. package/dist/mcp/oauth_callback.d.ts.map +1 -0
  197. package/dist/mcp/oauth_callback.js +51 -0
  198. package/dist/mcp/oauth_store.d.ts +22 -0
  199. package/dist/mcp/oauth_store.d.ts.map +1 -0
  200. package/dist/mcp/oauth_store.js +40 -0
  201. package/dist/mcp/server_manager.d.ts +49 -0
  202. package/dist/mcp/server_manager.d.ts.map +1 -0
  203. package/dist/mcp/server_manager.js +271 -0
  204. package/dist/plugins/fetchers/git.d.ts +67 -0
  205. package/dist/plugins/fetchers/git.d.ts.map +1 -0
  206. package/dist/plugins/fetchers/git.js +130 -0
  207. package/dist/plugins/fetchers/path.d.ts +4 -0
  208. package/dist/plugins/fetchers/path.d.ts.map +1 -0
  209. package/dist/plugins/fetchers/path.js +22 -0
  210. package/dist/plugins/loader.d.ts +31 -0
  211. package/dist/plugins/loader.d.ts.map +1 -0
  212. package/dist/plugins/loader.js +146 -0
  213. package/dist/plugins/manifest.d.ts +56 -0
  214. package/dist/plugins/manifest.d.ts.map +1 -0
  215. package/dist/plugins/manifest.js +389 -0
  216. package/dist/plugins/refresh_on_start.d.ts +7 -0
  217. package/dist/plugins/refresh_on_start.d.ts.map +1 -0
  218. package/dist/plugins/refresh_on_start.js +35 -0
  219. package/dist/plugins/source_manager.d.ts +27 -0
  220. package/dist/plugins/source_manager.d.ts.map +1 -0
  221. package/dist/plugins/source_manager.js +211 -0
  222. package/dist/plugins/types.d.ts +41 -0
  223. package/dist/plugins/types.d.ts.map +1 -0
  224. package/dist/plugins/types.js +11 -0
  225. package/dist/session/context_usage.d.ts +13 -0
  226. package/dist/session/context_usage.d.ts.map +1 -0
  227. package/dist/session/context_usage.js +25 -0
  228. package/dist/session/index.d.ts +7 -0
  229. package/dist/session/index.d.ts.map +1 -0
  230. package/dist/session/index.js +5 -0
  231. package/dist/session/store.d.ts +68 -0
  232. package/dist/session/store.d.ts.map +1 -0
  233. package/dist/session/store.js +268 -0
  234. package/dist/session/types.d.ts +60 -0
  235. package/dist/session/types.d.ts.map +1 -0
  236. package/dist/session/types.js +11 -0
  237. package/dist/store/db.d.ts +64 -0
  238. package/dist/store/db.d.ts.map +1 -0
  239. package/dist/store/db.js +91 -0
  240. package/dist/store/json.d.ts +21 -0
  241. package/dist/store/json.d.ts.map +1 -0
  242. package/dist/store/json.js +135 -0
  243. package/dist/tui/agents.d.ts +4 -0
  244. package/dist/tui/agents.d.ts.map +1 -0
  245. package/dist/tui/agents.js +616 -0
  246. package/dist/tui/app.d.ts +2 -0
  247. package/dist/tui/app.d.ts.map +1 -0
  248. package/dist/tui/app.js +32 -0
  249. package/dist/tui/chat.d.ts +10 -0
  250. package/dist/tui/chat.d.ts.map +1 -0
  251. package/dist/tui/chat.js +258 -0
  252. package/dist/tui/logo.d.ts +2 -0
  253. package/dist/tui/logo.d.ts.map +1 -0
  254. package/dist/tui/logo.js +10 -0
  255. package/dist/tui/mcp_servers.d.ts +4 -0
  256. package/dist/tui/mcp_servers.d.ts.map +1 -0
  257. package/dist/tui/mcp_servers.js +287 -0
  258. package/dist/tui/plugins.d.ts +4 -0
  259. package/dist/tui/plugins.d.ts.map +1 -0
  260. package/dist/tui/plugins.js +234 -0
  261. package/dist/tui/providers.d.ts +4 -0
  262. package/dist/tui/providers.d.ts.map +1 -0
  263. package/dist/tui/providers.js +178 -0
  264. package/dist/tui/tool_picker_state.d.ts +9 -0
  265. package/dist/tui/tool_picker_state.d.ts.map +1 -0
  266. package/dist/tui/tool_picker_state.js +37 -0
  267. package/dist/types.d.ts +2 -0
  268. package/dist/types.d.ts.map +1 -0
  269. package/dist/types.js +1 -0
  270. package/dist/webview/index.html +22 -0
  271. package/dist/webview/standalone.css +2732 -0
  272. package/dist/webview/standalone.css.map +7 -0
  273. package/dist/webview/standalone.js +20641 -0
  274. package/dist/webview/standalone.js.map +7 -0
  275. package/package.json +120 -0
@@ -0,0 +1,91 @@
1
+ import { join } from 'node:path';
2
+ import { homedir } from 'node:os';
3
+ import { existsSync, mkdirSync } from 'node:fs';
4
+ import { Store } from '@morphql/store';
5
+ import { FolderAdapter } from '@morphql/store/node';
6
+ export function dataDir() {
7
+ return process.env.CARETAKER_HOME ?? join(homedir(), '.caretaker');
8
+ }
9
+ export function dbStoreDir() {
10
+ return join(dataDir(), 'store');
11
+ }
12
+ let dbInstance = null;
13
+ export function getDb() {
14
+ if (!dbInstance) {
15
+ const dir = dbStoreDir();
16
+ if (!existsSync(dir)) {
17
+ mkdirSync(dir, { recursive: true, mode: 0o700 });
18
+ }
19
+ dbInstance = new Store(new FolderAdapter(dir, { pretty: true }));
20
+ }
21
+ return dbInstance;
22
+ }
23
+ let queryQueue = Promise.resolve();
24
+ export async function runQuery(sql) {
25
+ const op = () => getDb().query(sql);
26
+ const resultPromise = queryQueue.then(op);
27
+ queryQueue = resultPromise.catch(() => { });
28
+ return resultPromise;
29
+ }
30
+ export async function getTaskById(id) {
31
+ try {
32
+ const taskRows = (await runQuery(`SELECT * FROM tasks WHERE id = ${id}`));
33
+ return taskRows[0] || null;
34
+ }
35
+ catch (err) {
36
+ return null;
37
+ }
38
+ }
39
+ export async function saveTask(task) {
40
+ await runQuery(`DELETE FROM tasks WHERE id = ${task.id}`);
41
+ await runQuery(`INSERT INTO tasks ${JSON.stringify(task)}`);
42
+ }
43
+ export async function createTask(task) {
44
+ const payload = {
45
+ ...task,
46
+ id: '$auto',
47
+ createdAt: new Date().toISOString(),
48
+ updatedAt: new Date().toISOString(),
49
+ };
50
+ await runQuery(`INSERT INTO tasks ${JSON.stringify(payload)}`);
51
+ // Retrieve the created task to get its auto-assigned ID
52
+ const allTasks = (await runQuery(`SELECT * FROM tasks`));
53
+ const created = allTasks.find((t) => t.projectId === task.projectId && t.title === task.title && t.objective === task.objective);
54
+ if (!created) {
55
+ throw new Error('Failed to retrieve newly created task');
56
+ }
57
+ return created;
58
+ }
59
+ export async function addTaskMessage(msg) {
60
+ const payload = {
61
+ ...msg,
62
+ id: '$auto',
63
+ createdAt: new Date().toISOString(),
64
+ };
65
+ await runQuery(`INSERT INTO task_messages ${JSON.stringify(payload)}`);
66
+ // Find the inserted message to get its auto-increment ID
67
+ const messages = (await runQuery(`SELECT * FROM task_messages WHERE taskId = ${msg.taskId}`));
68
+ const created = messages[messages.length - 1];
69
+ if (!created) {
70
+ throw new Error('Failed to retrieve newly created task message');
71
+ }
72
+ return created;
73
+ }
74
+ export async function updateTaskMessageContent(id, content, type) {
75
+ const cleaned = content
76
+ .replace(/\\/g, '\\\\')
77
+ .replace(/'/g, "\\'")
78
+ .slice(0, 50000);
79
+ if (type) {
80
+ await runQuery(`UPDATE task_messages SET content = '${cleaned}', messageType = '${type}' WHERE id = ${id}`);
81
+ }
82
+ else {
83
+ await runQuery(`UPDATE task_messages SET content = '${cleaned}' WHERE id = ${id}`);
84
+ }
85
+ }
86
+ // Permanently delete a task and all of its messages. Used by the delete
87
+ // action (real deletion from the store); archiving is a soft flag, not this.
88
+ export async function deleteTask(taskId) {
89
+ await runQuery(`DELETE FROM task_messages WHERE taskId = ${taskId}`);
90
+ await runQuery(`DELETE FROM tasks WHERE id = ${taskId}`);
91
+ }
@@ -0,0 +1,21 @@
1
+ import type { AgentConfig, CaretakerConfig, McpServersFile, PluginsFile } from '../types.js';
2
+ export declare function dataDir(): string;
3
+ export declare function configPath(): string;
4
+ export declare function agentsPath(): string;
5
+ export declare function pluginsPath(): string;
6
+ export declare function mcpServersPath(): string;
7
+ export declare const defaultConfig: CaretakerConfig;
8
+ export declare function loadConfig(): Promise<CaretakerConfig>;
9
+ export declare function saveConfig(c: CaretakerConfig): Promise<void>;
10
+ export declare function loadAgents(): Promise<AgentConfig[]>;
11
+ export declare function saveAgents(a: AgentConfig[]): Promise<void>;
12
+ export declare function loadPlugins(): Promise<PluginsFile>;
13
+ export declare function savePlugins(file: PluginsFile): Promise<void>;
14
+ export declare function loadMcpServers(): Promise<McpServersFile>;
15
+ export declare function saveMcpServers(file: McpServersFile): Promise<void>;
16
+ /**
17
+ * Execute a function within a non-reentrant serialization lock for mcp.json operations.
18
+ * Protects against lost updates when multiple async read-modify-write cycles overlap.
19
+ */
20
+ export declare function withMcpServersLock<T>(fn: () => Promise<T>): Promise<T>;
21
+ //# sourceMappingURL=json.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../../src/store/json.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAK7F,wBAAgB,OAAO,IAAI,MAAM,CAEhC;AACD,wBAAgB,UAAU,IAAI,MAAM,CAEnC;AACD,wBAAgB,UAAU,IAAI,MAAM,CAEnC;AACD,wBAAgB,WAAW,IAAI,MAAM,CAEpC;AACD,wBAAgB,cAAc,IAAI,MAAM,CAEvC;AAED,eAAO,MAAM,aAAa,EAAE,eAG3B,CAAC;AAqDF,wBAAsB,UAAU,IAAI,OAAO,CAAC,eAAe,CAAC,CAE3D;AAED,wBAAsB,UAAU,CAAC,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAWlE;AAED,wBAAsB,UAAU,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC,CAEzD;AAED,wBAAsB,UAAU,CAAC,CAAC,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAEhE;AAED,wBAAsB,WAAW,IAAI,OAAO,CAAC,WAAW,CAAC,CASxD;AAED,wBAAsB,WAAW,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAElE;AAMD,wBAAsB,cAAc,IAAI,OAAO,CAAC,cAAc,CAAC,CAO9D;AAED,wBAAsB,cAAc,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAExE;AAID;;;GAGG;AACH,wBAAsB,kBAAkB,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAO5E"}
@@ -0,0 +1,135 @@
1
+ import { homedir } from 'node:os';
2
+ import { join } from 'node:path';
3
+ import { mkdir, readFile, writeFile, chmod, rename } from 'node:fs/promises';
4
+ import { existsSync } from 'node:fs';
5
+ import { encrypt, isEncrypted } from '../lib/encryption.js';
6
+ // Path accessors are resolved at call time, not import time, so test runs
7
+ // that share a process can switch CARETAKER_HOME between suites.
8
+ export function dataDir() {
9
+ return process.env.CARETAKER_HOME ?? join(homedir(), '.caretaker');
10
+ }
11
+ export function configPath() {
12
+ return join(dataDir(), 'caretaker.json');
13
+ }
14
+ export function agentsPath() {
15
+ return join(dataDir(), 'agents.json');
16
+ }
17
+ export function pluginsPath() {
18
+ return join(dataDir(), 'plugins.json');
19
+ }
20
+ export function mcpServersPath() {
21
+ return join(dataDir(), 'mcp.json');
22
+ }
23
+ export const defaultConfig = {
24
+ port: 17777,
25
+ providers: [],
26
+ };
27
+ /** Returns a fresh empty PluginsFile. Callers that push into the result
28
+ * must not share mutation with each other — never use a shared const. */
29
+ function emptyPluginsFile() {
30
+ return { sources: [], plugins: [] };
31
+ }
32
+ async function ensureDataDir() {
33
+ const dir = dataDir();
34
+ await mkdir(dir, { recursive: true, mode: 0o700 });
35
+ await chmod(dir, 0o700);
36
+ }
37
+ async function readJsonOrDefault(path, fallback) {
38
+ if (!existsSync(path))
39
+ return fallback;
40
+ try {
41
+ const raw = await readFile(path, 'utf8');
42
+ if (!raw.trim())
43
+ return fallback;
44
+ return JSON.parse(raw);
45
+ }
46
+ catch (err) {
47
+ console.warn(`[store/json] failed to read or parse ${path}:`, err);
48
+ return fallback;
49
+ }
50
+ }
51
+ async function writeJson(path, data) {
52
+ await ensureDataDir();
53
+ const tmpPath = `${path}.tmp.${process.pid}.${Date.now()}`;
54
+ await writeFile(tmpPath, JSON.stringify(data, null, 2), 'utf8');
55
+ await chmod(tmpPath, 0o600);
56
+ // Windows: rename can fail transiently with EACCES/EPERM/EBUSY when the
57
+ // destination is briefly locked by AV/indexer/sync clients. Retry with
58
+ // exponential backoff so we never sacrifice atomicity to a falling-back
59
+ // direct write.
60
+ const maxAttempts = process.platform === 'win32' ? 5 : 1;
61
+ let lastErr;
62
+ for (let attempt = 1; attempt <= maxAttempts; attempt++) {
63
+ try {
64
+ await rename(tmpPath, path);
65
+ return;
66
+ }
67
+ catch (err) {
68
+ lastErr = err;
69
+ const code = err.code;
70
+ const retryable = code === 'EACCES' || code === 'EPERM' || code === 'EBUSY';
71
+ if (attempt === maxAttempts || !retryable)
72
+ break;
73
+ await new Promise((r) => setTimeout(r, 50 * 2 ** (attempt - 1)));
74
+ }
75
+ }
76
+ throw lastErr;
77
+ }
78
+ export async function loadConfig() {
79
+ return readJsonOrDefault(configPath(), defaultConfig);
80
+ }
81
+ export async function saveConfig(c) {
82
+ if (c.scheduler?.tasks) {
83
+ for (const task of c.scheduler.tasks) {
84
+ if (task.type === 'telegram' && task.telegramBotToken) {
85
+ if (!isEncrypted(task.telegramBotToken)) {
86
+ task.telegramBotToken = encrypt(task.telegramBotToken);
87
+ }
88
+ }
89
+ }
90
+ }
91
+ await writeJson(configPath(), c);
92
+ }
93
+ export async function loadAgents() {
94
+ return readJsonOrDefault(agentsPath(), []);
95
+ }
96
+ export async function saveAgents(a) {
97
+ await writeJson(agentsPath(), a);
98
+ }
99
+ export async function loadPlugins() {
100
+ const file = await readJsonOrDefault(pluginsPath(), emptyPluginsFile());
101
+ // Defensive shallow copy: never hand callers a reference into a default
102
+ // singleton — pushes into file.sources would otherwise persist into the
103
+ // next loadPlugins() return.
104
+ return {
105
+ sources: Array.isArray(file.sources) ? [...file.sources] : [],
106
+ plugins: Array.isArray(file.plugins) ? [...file.plugins] : [],
107
+ };
108
+ }
109
+ export async function savePlugins(file) {
110
+ await writeJson(pluginsPath(), file);
111
+ }
112
+ function emptyMcpServersFile() {
113
+ return { servers: [] };
114
+ }
115
+ export async function loadMcpServers() {
116
+ const file = await readJsonOrDefault(mcpServersPath(), emptyMcpServersFile());
117
+ // Same defensive copy as loadPlugins — auth headers are sensitive, and
118
+ // handing back a shared reference invites mutation bugs.
119
+ return {
120
+ servers: Array.isArray(file.servers) ? [...file.servers] : [],
121
+ };
122
+ }
123
+ export async function saveMcpServers(file) {
124
+ await writeJson(mcpServersPath(), file);
125
+ }
126
+ let mcpPromiseChain = Promise.resolve();
127
+ /**
128
+ * Execute a function within a non-reentrant serialization lock for mcp.json operations.
129
+ * Protects against lost updates when multiple async read-modify-write cycles overlap.
130
+ */
131
+ export async function withMcpServersLock(fn) {
132
+ const resultPromise = mcpPromiseChain.then(() => fn());
133
+ mcpPromiseChain = resultPromise.then(() => { }, () => { });
134
+ return resultPromise;
135
+ }
@@ -0,0 +1,4 @@
1
+ export default function Agents({ onBack }: {
2
+ onBack: () => void;
3
+ }): import("react/jsx-runtime").JSX.Element;
4
+ //# sourceMappingURL=agents.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agents.d.ts","sourceRoot":"","sources":["../../src/tui/agents.tsx"],"names":[],"mappings":"AAoCA,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,EAAE,MAAM,EAAE,EAAE;IAAE,MAAM,EAAE,MAAM,IAAI,CAAA;CAAE,2CAsXhE"}