@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,41 @@
1
+ import type { AgentSpec, CommandSpec, McpServerSpec, PluginManifestKind, SkillSpec } from '../types.js';
2
+ export interface FetchResult {
3
+ /** Filesystem root containing the source contents (cache dir for git, the
4
+ * user-supplied path for path). */
5
+ root: string;
6
+ /** Resolved commit sha for git sources; null for path sources. */
7
+ sha: string | null;
8
+ }
9
+ /** Output of the manifest discovery layer: a plugin found inside a source
10
+ * but not yet tied to an id or persisted. The source manager assigns
11
+ * `id` + `sourceId` to convert this into a PluginRecord. */
12
+ export interface DiscoveredPlugin {
13
+ name: string;
14
+ description: string | null;
15
+ manifestKind: PluginManifestKind;
16
+ /** Relative to the source root, never traverses outside. */
17
+ relPath: string;
18
+ rawManifest: unknown;
19
+ /** MCP servers declared by the plugin manifest, keyed by the
20
+ * plugin-scoped name (claude-code's `mcpServers` shape). The source
21
+ * manager mints one McpServerConfig row per entry tagged with this
22
+ * plugin's id, so deleting the plugin cascades to its MCP rows. */
23
+ mcpServers?: Record<string, McpServerSpec>;
24
+ /** Sub-agents declared under `<plugin-root>/agents/*.md`, keyed by the
25
+ * filename basename. One AgentConfig row per entry, tagged with this
26
+ * plugin's id. */
27
+ agents?: Record<string, AgentSpec>;
28
+ /** Slash commands declared under `<plugin-root>/commands/*.md`, keyed by
29
+ * the filename basename. Used at chat time to expand `/cmd args` into
30
+ * the body's `$N`/`$ARGUMENTS` template. */
31
+ commands?: Record<string, CommandSpec>;
32
+ /** Skills declared under `<plugin-root>/[**\/]SKILL.md`, keyed by scoped
33
+ * name (frontmatter `name`, or directory basename as fallback). One
34
+ * entry per file — a cc-plugin pack like superpowers contributes N
35
+ * entries, one per `skills/<name>/SKILL.md`. */
36
+ skills?: Record<string, SkillSpec>;
37
+ }
38
+ export declare class NoPluginsFoundError extends Error {
39
+ constructor(message?: string);
40
+ }
41
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/plugins/types.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,SAAS,EACT,WAAW,EACX,aAAa,EACb,kBAAkB,EAClB,SAAS,EACV,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,WAAW;IAC1B;wCACoC;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,kEAAkE;IAClE,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CACpB;AAED;;6DAE6D;AAC7D,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,YAAY,EAAE,kBAAkB,CAAC;IACjC,4DAA4D;IAC5D,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,OAAO,CAAC;IACrB;;;wEAGoE;IACpE,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAC3C;;uBAEmB;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IACnC;;iDAE6C;IAC7C,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IACvC;;;qDAGiD;IACjD,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;CACpC;AAED,qBAAa,mBAAoB,SAAQ,KAAK;gBAChC,OAAO,SAA4C;CAIhE"}
@@ -0,0 +1,11 @@
1
+ // Runtime-only types for the plugin subsystem. The persisted shapes
2
+ // (PluginSource, PluginRecord, PluginsFile) live in src/types.ts next to
3
+ // AgentConfig. This module owns the transient types: fetcher output, the
4
+ // discovery output (without ids — those are minted on persist), and the
5
+ // discovery error.
6
+ export class NoPluginsFoundError extends Error {
7
+ constructor(message = 'No manifest or SKILL.md found in source') {
8
+ super(message);
9
+ this.name = 'NoPluginsFoundError';
10
+ }
11
+ }
@@ -0,0 +1,13 @@
1
+ import type { AssistantUsage } from './types.js';
2
+ export type ContextUsage = {
3
+ lastTokens: number;
4
+ contextWindow: number | null;
5
+ percent: number | null;
6
+ };
7
+ type Row = {
8
+ role: string;
9
+ usage?: AssistantUsage | null;
10
+ };
11
+ export declare function computeContextUsage(rows: Row[], model: string | null): ContextUsage | null;
12
+ export {};
13
+ //# sourceMappingURL=context_usage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context_usage.d.ts","sourceRoot":"","sources":["../../src/session/context_usage.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,MAAM,MAAM,YAAY,GAAG;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB,CAAC;AAEF,KAAK,GAAG,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,cAAc,GAAG,IAAI,CAAA;CAAE,CAAC;AAE3D,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,YAAY,GAAG,IAAI,CAqB1F"}
@@ -0,0 +1,25 @@
1
+ import { resolveContextWindow } from '../harness/model_limits.js';
2
+ export function computeContextUsage(rows, model) {
3
+ for (let i = rows.length - 1; i >= 0; i--) {
4
+ const r = rows[i];
5
+ if (r.role !== 'assistant')
6
+ continue;
7
+ const u = r.usage;
8
+ if (!u || typeof u !== 'object')
9
+ continue;
10
+ const total = (u.input ?? 0) +
11
+ (u.output ?? 0) +
12
+ (u.cacheRead ?? 0) +
13
+ (u.cacheWrite ?? 0) +
14
+ (u.reasoning ?? 0);
15
+ if (total <= 0)
16
+ continue;
17
+ const window = model ? resolveContextWindow(model) : null;
18
+ return {
19
+ lastTokens: total,
20
+ contextWindow: window,
21
+ percent: window ? Math.round((total / window) * 100) : null,
22
+ };
23
+ }
24
+ return null;
25
+ }
@@ -0,0 +1,7 @@
1
+ export { createSession, appendMessage, readSession, listForAgent, updateTitle, deleteSession, userMessage, assistantMessage, toolMessage, dataDir, sessionsRoot, readAttachment, saveAttachment, attachmentsDir, } from './store.js';
2
+ export { computeContextUsage } from './context_usage.js';
3
+ export { initModelLimits } from '../harness/model_limits.js';
4
+ export type { ContextUsage } from './context_usage.js';
5
+ export type { CreateSessionInput, SessionListEntry } from './store.js';
6
+ export type { AssistantPart, AssistantUsage, MessageRecord, Session, SessionMetaRecord, ToolAttachmentRecord, } from './types.js';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/session/index.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,aAAa,EACb,aAAa,EACb,WAAW,EACX,YAAY,EACZ,WAAW,EACX,aAAa,EACb,WAAW,EACX,gBAAgB,EAChB,WAAW,EACX,OAAO,EACP,YAAY,EACZ,cAAc,EACd,cAAc,EACd,cAAc,GACf,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,YAAY,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,YAAY,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACvE,YAAY,EACV,aAAa,EACb,cAAc,EACd,aAAa,EACb,OAAO,EACP,iBAAiB,EACjB,oBAAoB,GACrB,MAAM,YAAY,CAAC"}
@@ -0,0 +1,5 @@
1
+ // Public API barrel for the JSONL session store. Same surface used by
2
+ // the TUI; exposed under `caretaker-cli/session` for external embedders.
3
+ export { createSession, appendMessage, readSession, listForAgent, updateTitle, deleteSession, userMessage, assistantMessage, toolMessage, dataDir, sessionsRoot, readAttachment, saveAttachment, attachmentsDir, } from './store.js';
4
+ export { computeContextUsage } from './context_usage.js';
5
+ export { initModelLimits } from '../harness/model_limits.js';
@@ -0,0 +1,68 @@
1
+ import type { AssistantPart, AssistantUsage, MessageRecord, Session, SessionMetaRecord, ToolAttachmentRecord } from './types.js';
2
+ export declare function dataDir(): string;
3
+ export declare function sessionsRoot(): string;
4
+ declare function agentDir(agentId: string): string;
5
+ declare function sessionPath(agentId: string, sessionId: string): string;
6
+ export interface CreateSessionInput {
7
+ agentId: string;
8
+ title: string;
9
+ /** Optional explicit id. Defaults to a fresh uuid. */
10
+ id?: string;
11
+ /** Optional explicit createdAt (ISO). Defaults to now. Useful for tests. */
12
+ createdAt?: string;
13
+ }
14
+ /** Create a new session: writes the initial meta line. Returns the meta. */
15
+ export declare function createSession(input: CreateSessionInput): Promise<SessionMetaRecord>;
16
+ /** Append a message record (user / assistant / tool) to an existing session. */
17
+ export declare function appendMessage(meta: Pick<SessionMetaRecord, 'agentId' | 'id'>, record: MessageRecord): Promise<void>;
18
+ /**
19
+ * Read a session in full. The latest `session_meta` record wins (so retitles
20
+ * appended without a rewrite are honored too — the rewrite path is the
21
+ * preferred one, but this keeps the reader robust).
22
+ *
23
+ * Lines that fail to parse or have an unknown `type`/`v` are skipped with
24
+ * a console warning; the rest of the file is still returned.
25
+ */
26
+ export declare function readSession(agentId: string, sessionId: string): Promise<Session>;
27
+ /** Index-style listing for an agent: latest meta only, sorted by mtime desc. */
28
+ export interface SessionListEntry {
29
+ meta: SessionMetaRecord;
30
+ updatedAt: Date;
31
+ }
32
+ export declare function listForAgent(agentId: string): Promise<SessionListEntry[]>;
33
+ /** Read just enough of a file to extract the first meta line. */
34
+ declare function readFirstMeta(path: string): Promise<SessionMetaRecord | null>;
35
+ /**
36
+ * Atomic title rewrite: read the whole file, replace the first meta line,
37
+ * write to a temp file and rename. The rename is atomic on POSIX; on Windows
38
+ * it's atomic when the target is on the same volume (which it always is here).
39
+ * Returns the new meta.
40
+ */
41
+ export declare function updateTitle(meta: Pick<SessionMetaRecord, 'agentId' | 'id'>, title: string): Promise<SessionMetaRecord>;
42
+ /** Persist the Claude Code session id by appending a fresh meta line
43
+ * (readSession picks the latest meta; listForAgent keeps using the first). */
44
+ export declare function updateClaudeSessionId(meta: Pick<SessionMetaRecord, 'agentId' | 'id'>, claudeSessionId: string): Promise<void>;
45
+ export declare function deleteSession(agentId: string, sessionId: string): Promise<void>;
46
+ export declare function userMessage(content: string, opts?: {
47
+ id?: string;
48
+ createdAt?: string;
49
+ attachments?: ToolAttachmentRecord[];
50
+ }): MessageRecord;
51
+ export declare function assistantMessage(parts: AssistantPart[], usage?: AssistantUsage, opts?: {
52
+ id?: string;
53
+ createdAt?: string;
54
+ }): MessageRecord;
55
+ export declare function attachmentsDir(sessionId: string): string;
56
+ export declare function saveAttachment(sessionId: string, data: Buffer, extension: string): Promise<string>;
57
+ export declare function readAttachment(sessionId: string, id: string): Promise<Buffer>;
58
+ export declare function toolMessage(toolCallId: string, content: string, attachments?: ToolAttachmentRecord[], opts?: {
59
+ id?: string;
60
+ createdAt?: string;
61
+ }): MessageRecord;
62
+ export declare const __forTesting: {
63
+ sessionPath: typeof sessionPath;
64
+ agentDir: typeof agentDir;
65
+ readFirstMeta: typeof readFirstMeta;
66
+ };
67
+ export {};
68
+ //# sourceMappingURL=store.d.ts.map
@@ -0,0 +1 @@
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AW,CACzB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,EACf,WAAW,CAAC,EAAE,oBAAoB,EAAE,EACpC,IAAI,CAAC,EAAE;IAAE,EAAE,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,GACzC,aAAa,CAWf;AAID,eAAO,MAAM,YAAY;;;;CAA2C,CAAC"}
@@ -0,0 +1,268 @@
1
+ // Session store backed by JSONL files, one per session.
2
+ // Layout: <dataDir>/sessions/<agentId>/<sessionId>.jsonl
3
+ //
4
+ // Append-only writes for new messages. Meta updates (retitle) rewrite the
5
+ // file atomically via temp+rename to keep "first line = current meta"
6
+ // invariant — this lets `listForAgent()` read a single line per session for
7
+ // the index view. Sort order in `listForAgent()` uses fs.stat.mtime, which
8
+ // is updated for free on every append, so we never have to rewrite the file
9
+ // just to bump a timestamp.
10
+ import { homedir } from 'node:os';
11
+ import { join } from 'node:path';
12
+ import { randomUUID } from 'node:crypto';
13
+ import { appendFile, chmod, mkdir, readdir, readFile, rename, rm, stat, writeFile, open, } from 'node:fs/promises';
14
+ import { existsSync } from 'node:fs';
15
+ export function dataDir() {
16
+ return process.env.CARETAKER_HOME ?? join(homedir(), '.caretaker');
17
+ }
18
+ export function sessionsRoot() {
19
+ return join(dataDir(), 'sessions');
20
+ }
21
+ function agentDir(agentId) {
22
+ return join(sessionsRoot(), agentId);
23
+ }
24
+ function sessionPath(agentId, sessionId) {
25
+ return join(agentDir(agentId), `${sessionId}.jsonl`);
26
+ }
27
+ async function ensureDir(path) {
28
+ await mkdir(path, { recursive: true, mode: 0o700 });
29
+ await chmod(path, 0o700);
30
+ }
31
+ function nowIso() {
32
+ return new Date().toISOString();
33
+ }
34
+ function serialize(record) {
35
+ return JSON.stringify(record) + '\n';
36
+ }
37
+ /** Concatenate text parts of an assistant turn into the canonical `content`
38
+ * string. Mirrors textConcat() in the server's chat_parts module. */
39
+ function textConcat(parts) {
40
+ return parts
41
+ .filter((p) => p.type === 'text')
42
+ .map((p) => p.text)
43
+ .join('');
44
+ }
45
+ /** Parse a single line. Returns null for blank or malformed lines (caller logs). */
46
+ function parseLine(line) {
47
+ const trimmed = line.trimEnd();
48
+ if (!trimmed)
49
+ return null;
50
+ try {
51
+ return JSON.parse(trimmed);
52
+ }
53
+ catch {
54
+ return null;
55
+ }
56
+ }
57
+ function isMeta(rec) {
58
+ return (!!rec &&
59
+ typeof rec === 'object' &&
60
+ rec.type === 'session_meta' &&
61
+ rec.v === 1);
62
+ }
63
+ function isMessage(rec) {
64
+ if (!rec || typeof rec !== 'object')
65
+ return false;
66
+ const o = rec;
67
+ if (o.v !== 1 || o.type !== 'message')
68
+ return false;
69
+ return o.role === 'user' || o.role === 'assistant' || o.role === 'tool';
70
+ }
71
+ /** Create a new session: writes the initial meta line. Returns the meta. */
72
+ export async function createSession(input) {
73
+ const meta = {
74
+ v: 1,
75
+ type: 'session_meta',
76
+ id: input.id ?? randomUUID(),
77
+ agentId: input.agentId,
78
+ title: input.title,
79
+ createdAt: input.createdAt ?? nowIso(),
80
+ };
81
+ await ensureDir(agentDir(input.agentId));
82
+ const path = sessionPath(input.agentId, meta.id);
83
+ // `wx` flag: fail if file already exists. Prevents accidental id collision overwriting an existing session.
84
+ await writeFile(path, serialize(meta), { mode: 0o600, flag: 'wx' });
85
+ return meta;
86
+ }
87
+ /** Append a message record (user / assistant / tool) to an existing session. */
88
+ export async function appendMessage(meta, record) {
89
+ const path = sessionPath(meta.agentId, meta.id);
90
+ // `appendFile` with default flag `a` is the right primitive: writes are
91
+ // atomic per-call on POSIX for payloads under PIPE_BUF (typically 4 KiB);
92
+ // larger payloads can interleave between concurrent writers, but the store
93
+ // is single-writer by design.
94
+ await appendFile(path, serialize(record), { mode: 0o600 });
95
+ }
96
+ /**
97
+ * Read a session in full. The latest `session_meta` record wins (so retitles
98
+ * appended without a rewrite are honored too — the rewrite path is the
99
+ * preferred one, but this keeps the reader robust).
100
+ *
101
+ * Lines that fail to parse or have an unknown `type`/`v` are skipped with
102
+ * a console warning; the rest of the file is still returned.
103
+ */
104
+ export async function readSession(agentId, sessionId) {
105
+ const path = sessionPath(agentId, sessionId);
106
+ const raw = await readFile(path, 'utf8');
107
+ const lines = raw.split('\n');
108
+ let meta = null;
109
+ const messages = [];
110
+ for (let i = 0; i < lines.length; i++) {
111
+ const parsed = parseLine(lines[i]);
112
+ if (parsed === null)
113
+ continue;
114
+ if (isMeta(parsed)) {
115
+ meta = parsed;
116
+ continue;
117
+ }
118
+ if (isMessage(parsed)) {
119
+ messages.push(parsed);
120
+ continue;
121
+ }
122
+ console.warn(`[session/store] skipping unknown record at ${path}:${i + 1}`);
123
+ }
124
+ if (!meta)
125
+ throw new Error(`session ${sessionId} for agent ${agentId} has no meta record`);
126
+ return { meta, messages };
127
+ }
128
+ export async function listForAgent(agentId) {
129
+ const dir = agentDir(agentId);
130
+ if (!existsSync(dir))
131
+ return [];
132
+ const files = (await readdir(dir)).filter((f) => f.endsWith('.jsonl'));
133
+ const entries = [];
134
+ for (const f of files) {
135
+ const path = join(dir, f);
136
+ try {
137
+ const meta = await readFirstMeta(path);
138
+ if (!meta)
139
+ continue;
140
+ const st = await stat(path);
141
+ entries.push({ meta, updatedAt: st.mtime });
142
+ }
143
+ catch (err) {
144
+ console.warn(`[session/store] failed to read ${path}:`, err);
145
+ }
146
+ }
147
+ entries.sort((a, b) => b.updatedAt.getTime() - a.updatedAt.getTime());
148
+ return entries;
149
+ }
150
+ /** Read just enough of a file to extract the first meta line. */
151
+ async function readFirstMeta(path) {
152
+ const fh = await open(path, 'r');
153
+ try {
154
+ // Read a single chunk; first line is typically <300 bytes for meta.
155
+ const buf = Buffer.alloc(4096);
156
+ const { bytesRead } = await fh.read(buf, 0, buf.length, 0);
157
+ if (bytesRead === 0)
158
+ return null;
159
+ const text = buf.subarray(0, bytesRead).toString('utf8');
160
+ const newline = text.indexOf('\n');
161
+ const firstLine = newline >= 0 ? text.slice(0, newline) : text;
162
+ const parsed = parseLine(firstLine);
163
+ return isMeta(parsed) ? parsed : null;
164
+ }
165
+ finally {
166
+ await fh.close();
167
+ }
168
+ }
169
+ /**
170
+ * Atomic title rewrite: read the whole file, replace the first meta line,
171
+ * write to a temp file and rename. The rename is atomic on POSIX; on Windows
172
+ * it's atomic when the target is on the same volume (which it always is here).
173
+ * Returns the new meta.
174
+ */
175
+ export async function updateTitle(meta, title) {
176
+ const path = sessionPath(meta.agentId, meta.id);
177
+ const raw = await readFile(path, 'utf8');
178
+ const lines = raw.split('\n');
179
+ // Find and update the first meta line. Trailing meta records (if any) are
180
+ // left as-is — readSession() walks all of them and the latest wins, but
181
+ // the canonical state is "first line = current meta", which we maintain.
182
+ let updated = false;
183
+ let newMeta = null;
184
+ for (let i = 0; i < lines.length; i++) {
185
+ const parsed = parseLine(lines[i]);
186
+ if (isMeta(parsed)) {
187
+ newMeta = { ...parsed, title };
188
+ lines[i] = JSON.stringify(newMeta);
189
+ updated = true;
190
+ break;
191
+ }
192
+ }
193
+ if (!updated || !newMeta)
194
+ throw new Error(`session ${meta.id} has no meta to update`);
195
+ const tmp = `${path}.tmp.${process.pid}.${Date.now()}`;
196
+ await writeFile(tmp, lines.join('\n'), { mode: 0o600 });
197
+ await rename(tmp, path);
198
+ return newMeta;
199
+ }
200
+ /** Persist the Claude Code session id by appending a fresh meta line
201
+ * (readSession picks the latest meta; listForAgent keeps using the first). */
202
+ export async function updateClaudeSessionId(meta, claudeSessionId) {
203
+ const current = await readSession(meta.agentId, meta.id);
204
+ const record = { ...current.meta, claudeSessionId };
205
+ const path = sessionPath(meta.agentId, meta.id);
206
+ await appendFile(path, serialize(record), { mode: 0o600 });
207
+ }
208
+ export async function deleteSession(agentId, sessionId) {
209
+ const path = sessionPath(agentId, sessionId);
210
+ await rm(path, { force: true });
211
+ const attDir = attachmentsDir(sessionId);
212
+ await rm(attDir, { recursive: true, force: true });
213
+ }
214
+ // ─── Message builders ───────────────────────────────────────────────────────
215
+ export function userMessage(content, opts) {
216
+ return {
217
+ v: 1,
218
+ type: 'message',
219
+ id: opts?.id ?? randomUUID(),
220
+ role: 'user',
221
+ content,
222
+ ...(opts?.attachments ? { attachments: opts.attachments } : {}),
223
+ createdAt: opts?.createdAt ?? nowIso(),
224
+ };
225
+ }
226
+ export function assistantMessage(parts, usage, opts) {
227
+ const content = textConcat(parts);
228
+ return {
229
+ v: 1,
230
+ type: 'message',
231
+ id: opts?.id ?? randomUUID(),
232
+ role: 'assistant',
233
+ content,
234
+ parts,
235
+ ...(usage ? { usage } : {}),
236
+ createdAt: opts?.createdAt ?? nowIso(),
237
+ };
238
+ }
239
+ export function attachmentsDir(sessionId) {
240
+ return join(dataDir(), 'attachments', sessionId);
241
+ }
242
+ export async function saveAttachment(sessionId, data, extension) {
243
+ const uuid = randomUUID();
244
+ const ext = extension.startsWith('.') ? extension : `.${extension}`;
245
+ const id = `${uuid}${ext}`;
246
+ const dir = attachmentsDir(sessionId);
247
+ await ensureDir(dir);
248
+ await writeFile(join(dir, id), data);
249
+ return id;
250
+ }
251
+ export async function readAttachment(sessionId, id) {
252
+ const path = join(attachmentsDir(sessionId), id);
253
+ return await readFile(path);
254
+ }
255
+ export function toolMessage(toolCallId, content, attachments, opts) {
256
+ return {
257
+ v: 1,
258
+ type: 'message',
259
+ id: opts?.id ?? randomUUID(),
260
+ role: 'tool',
261
+ toolCallId,
262
+ content,
263
+ ...(attachments ? { attachments } : {}),
264
+ createdAt: opts?.createdAt ?? nowIso(),
265
+ };
266
+ }
267
+ // ─── For tests / introspection ──────────────────────────────────────────────
268
+ export const __forTesting = { sessionPath, agentDir, readFirstMeta };
@@ -0,0 +1,60 @@
1
+ export type AssistantPart = {
2
+ type: 'text';
3
+ text: string;
4
+ } | {
5
+ type: 'thinking';
6
+ text: string;
7
+ } | {
8
+ type: 'tool_use';
9
+ id: string;
10
+ name: string;
11
+ args: unknown;
12
+ };
13
+ export type AssistantUsage = {
14
+ input: number;
15
+ output: number;
16
+ cacheRead?: number;
17
+ cacheWrite?: number;
18
+ reasoning?: number;
19
+ };
20
+ export interface SessionMetaRecord {
21
+ v: 1;
22
+ type: 'session_meta';
23
+ id: string;
24
+ agentId: string;
25
+ title: string;
26
+ createdAt: string;
27
+ /** Claude Code CLI session id for claude-code runner agents; the next
28
+ * turn resumes it via `claude -p --resume <id>`. */
29
+ claudeSessionId?: string;
30
+ }
31
+ export type Role = 'user' | 'assistant' | 'tool';
32
+ export interface ToolAttachmentRecord {
33
+ mime: string;
34
+ id: string;
35
+ name?: string;
36
+ }
37
+ export interface MessageRecord {
38
+ v: 1;
39
+ type: 'message';
40
+ id: string;
41
+ role: Role;
42
+ /** Canonical text content. For assistant rows: textConcat(parts) — the same
43
+ * invariant the server keeps in chat_messages.content. May be empty when
44
+ * an assistant turn produced only tool_use blocks. */
45
+ content: string;
46
+ /** Structured assistant blocks (text / thinking / tool_use). Assistant only. */
47
+ parts?: AssistantPart[];
48
+ /** Tool only — links the result back to its assistant tool_use id. */
49
+ toolCallId?: string;
50
+ /** Assistant only, openai-style only. */
51
+ usage?: AssistantUsage;
52
+ attachments?: ToolAttachmentRecord[];
53
+ createdAt: string;
54
+ }
55
+ export type SessionRecord = SessionMetaRecord | MessageRecord;
56
+ export interface Session {
57
+ meta: SessionMetaRecord;
58
+ messages: MessageRecord[];
59
+ }
60
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/session/types.ts"],"names":[],"mappings":"AAWA,MAAM,MAAM,aAAa,GACrB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC9B;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAClC;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC;AAElE,M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3B"}
@@ -0,0 +1,11 @@
1
+ // Persistent chat-session record types. Each session lives in a single JSONL
2
+ // file at <dataDir>/sessions/<agentId>/<sessionId>.jsonl. Records are
3
+ // append-only; meta updates (e.g. retitle) are emitted as a fresh meta line
4
+ // — the latest one wins on read. Schema version `v` is per-record so we can
5
+ // evolve individual record types without breaking forward-compat: an unknown
6
+ // `v` or `type` is skipped with a warning instead of failing the whole replay.
7
+ //
8
+ // MessageRecord mirrors the chat_messages row shape from caretaker server's
9
+ // schema (role + content + optional parts/toolCallId/usage), so the server's
10
+ // `mapRowsToChatMessages` logic can be ported here with minimal adaptation.
11
+ export {};
@@ -0,0 +1,64 @@
1
+ import { Store } from '@morphql/store';
2
+ export interface ChecklistItem {
3
+ id: string;
4
+ text: string;
5
+ status: 'pending' | 'in_progress' | 'done' | 'skipped';
6
+ order: number;
7
+ }
8
+ export interface Project {
9
+ id: number;
10
+ name: string;
11
+ description: string;
12
+ workingDir: string;
13
+ agentId: string;
14
+ active: boolean;
15
+ plannerAgentId?: string | null;
16
+ reviewerAgentId?: string | null;
17
+ planningEnabled?: boolean | null;
18
+ reviewEnabled?: boolean | null;
19
+ sddEnabled?: boolean | null;
20
+ }
21
+ export interface Task {
22
+ id: number;
23
+ projectId: number;
24
+ title: string;
25
+ objective: string;
26
+ checklist: ChecklistItem[];
27
+ status: 'draft' | 'planning' | 'active' | 'reviewing' | 'paused' | 'blocked' | 'done';
28
+ blockedReason: string | null;
29
+ noProgressCount: number;
30
+ maxNoProgress: number;
31
+ lockedAt: string | null;
32
+ branch?: string | null;
33
+ worktreePath?: string | null;
34
+ archived?: boolean;
35
+ agentId?: string | null;
36
+ plannerAgentId?: string | null;
37
+ reviewerAgentId?: string | null;
38
+ planningEnabled?: boolean | null;
39
+ reviewEnabled?: boolean | null;
40
+ sddEnabled?: boolean | null;
41
+ createdAt: string;
42
+ updatedAt: string;
43
+ }
44
+ export interface TaskMessage {
45
+ id: number;
46
+ taskId: number;
47
+ role: 'user' | 'assistant' | 'tool';
48
+ messageType: 'chat' | 'heartbeat' | 'heartbeat_live' | 'system' | 'block' | 'tool_call' | 'yield' | 'review' | 'plan';
49
+ content: string;
50
+ toolCallId?: string | null;
51
+ agentId?: string | null;
52
+ createdAt: string;
53
+ }
54
+ export declare function dataDir(): string;
55
+ export declare function dbStoreDir(): string;
56
+ export declare function getDb(): Store;
57
+ export declare function runQuery(sql: string): Promise<any>;
58
+ export declare function getTaskById(id: number): Promise<Task | null>;
59
+ export declare function saveTask(task: Task): Promise<void>;
60
+ export declare function createTask(task: Omit<Task, 'id' | 'createdAt' | 'updatedAt'>): Promise<Task>;
61
+ export declare function addTaskMessage(msg: Omit<TaskMessage, 'id' | 'createdAt'>): Promise<TaskMessage>;
62
+ export declare function updateTaskMessageContent(id: number, content: string, type?: TaskMessage['messageType']): Promise<void>;
63
+ export declare function deleteTask(taskId: number): Promise<void>;
64
+ //# sourceMappingURL=db.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../../src/store/db.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAGvC,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,SAAS,GAAG,aAAa,GAAG,MAAM,GAAG,SAAS,CAAC;IACvD,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,OAAO,CAAC;IAChB,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,eAAe,CAAC,EAAE,OAAO,GAA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