clawvault 3.0.0 → 3.2.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 (291) hide show
  1. package/README.md +352 -20
  2. package/bin/clawvault.js +8 -2
  3. package/bin/command-registration.test.js +3 -1
  4. package/bin/command-runtime.js +9 -1
  5. package/bin/register-core-commands.js +23 -10
  6. package/bin/register-maintenance-commands.js +39 -3
  7. package/bin/register-query-commands.js +58 -29
  8. package/bin/register-task-commands.js +18 -1
  9. package/bin/register-task-commands.test.js +16 -0
  10. package/bin/register-vault-operations-commands.js +29 -1
  11. package/bin/register-workgraph-commands.js +1368 -0
  12. package/dashboard/lib/graph-diff.js +104 -0
  13. package/dashboard/lib/graph-diff.test.js +75 -0
  14. package/dashboard/lib/vault-parser.js +556 -0
  15. package/dashboard/lib/vault-parser.test.js +254 -0
  16. package/dashboard/public/app.js +796 -0
  17. package/dashboard/public/index.html +52 -0
  18. package/dashboard/public/styles.css +221 -0
  19. package/dashboard/server.js +374 -0
  20. package/dist/{chunk-F2JEUD4J.js → chunk-23YDQ3QU.js} +6 -8
  21. package/dist/{chunk-C7OK5WKP.js → chunk-2JQ3O2YL.js} +4 -4
  22. package/dist/{chunk-VR5NE7PZ.js → chunk-2RAZ4ZFE.js} +1 -1
  23. package/dist/chunk-2ZDO52B4.js +52 -0
  24. package/dist/{chunk-ZZA73MFY.js → chunk-33DOSHTA.js} +176 -36
  25. package/dist/chunk-33VSQP4J.js +37 -0
  26. package/dist/chunk-4BQTQMJP.js +93 -0
  27. package/dist/{chunk-GUKMRGM7.js → chunk-4OXMU5S2.js} +1 -1
  28. package/dist/{chunk-62YTUT6J.js → chunk-4PY655YM.js} +15 -3
  29. package/dist/chunk-6FH3IULF.js +352 -0
  30. package/dist/{chunk-3NSBOUT3.js → chunk-77Q5CSPJ.js} +404 -80
  31. package/dist/{chunk-4VQTUVH7.js → chunk-7YZWHM36.js} +52 -26
  32. package/dist/chunk-BSJ6RIT7.js +447 -0
  33. package/dist/chunk-BUEW6IIK.js +364 -0
  34. package/dist/{chunk-WGRQ6HDV.js → chunk-CLJTREDS.js} +74 -14
  35. package/dist/chunk-EK6S23ZB.js +469 -0
  36. package/dist/{chunk-LNJA2UGL.js → chunk-ESFLMDRB.js} +9 -86
  37. package/dist/{chunk-H34S76MB.js → chunk-ESVS6K2B.js} +6 -6
  38. package/dist/{chunk-WAZ3NLWL.js → chunk-F55HGNU4.js} +0 -47
  39. package/dist/{chunk-QK3UCXWL.js → chunk-FHFUXL6G.js} +2 -2
  40. package/dist/{chunk-YKTA5JOJ.js → chunk-GAOWA7GR.js} +212 -46
  41. package/dist/chunk-GGA32J2R.js +784 -0
  42. package/dist/chunk-GNJL4YGR.js +79 -0
  43. package/dist/chunk-MDIH26GC.js +183 -0
  44. package/dist/{chunk-LYHGEHXG.js → chunk-MFAWT5O5.js} +0 -1
  45. package/dist/chunk-MM6QGW3P.js +207 -0
  46. package/dist/{chunk-P5EPF6MB.js → chunk-MW5C6ZQA.js} +110 -13
  47. package/dist/chunk-NCKFNBHJ.js +257 -0
  48. package/dist/{chunk-QBLMXKF2.js → chunk-OIWVQYQF.js} +1 -1
  49. package/dist/{chunk-42MXU7A6.js → chunk-P62WHA27.js} +58 -47
  50. package/dist/chunk-PBACDKKP.js +66 -0
  51. package/dist/{chunk-VGLOTGAS.js → chunk-QSHD36LH.js} +2 -2
  52. package/dist/{chunk-OZ7RIXTO.js → chunk-QSRRMEYM.js} +2 -2
  53. package/dist/chunk-QVEERJSP.js +152 -0
  54. package/dist/{chunk-N2AXRYLC.js → chunk-QWQ3TIKS.js} +1 -1
  55. package/dist/{chunk-3DHXQHYG.js → chunk-R2MIW5G7.js} +1 -1
  56. package/dist/{chunk-SJSFRIYS.js → chunk-SLXOR3CC.js} +2 -2
  57. package/dist/chunk-SS4B7P7V.js +99 -0
  58. package/dist/{chunk-JY6FYXIT.js → chunk-STCQGCEQ.js} +6 -11
  59. package/dist/chunk-U4O6C46S.js +154 -0
  60. package/dist/{chunk-ITPEXLHA.js → chunk-URXDAUVH.js} +24 -5
  61. package/dist/chunk-VSL7KY3M.js +189 -0
  62. package/dist/{chunk-U55BGUAU.js → chunk-W4SPAEE7.js} +6 -6
  63. package/dist/chunk-WMGIIABP.js +15 -0
  64. package/dist/{chunk-3D6BCTP6.js → chunk-X3SPPUFG.js} +51 -39
  65. package/dist/{chunk-THRJVD4L.js → chunk-Y6VJKXGL.js} +1 -1
  66. package/dist/{chunk-ZVVFWOLW.js → chunk-ZN54U2OZ.js} +123 -10
  67. package/dist/cli/index.js +32 -25
  68. package/dist/commands/archive.js +3 -3
  69. package/dist/commands/backlog.js +3 -3
  70. package/dist/commands/blocked.js +3 -3
  71. package/dist/commands/canvas.d.ts +15 -0
  72. package/dist/commands/canvas.js +200 -0
  73. package/dist/commands/checkpoint.js +2 -2
  74. package/dist/commands/compat.js +2 -2
  75. package/dist/commands/context.js +8 -6
  76. package/dist/commands/doctor.d.ts +11 -7
  77. package/dist/commands/doctor.js +18 -16
  78. package/dist/commands/embed.js +5 -6
  79. package/dist/commands/entities.js +2 -2
  80. package/dist/commands/graph.js +4 -4
  81. package/dist/commands/inject.d.ts +1 -1
  82. package/dist/commands/inject.js +5 -6
  83. package/dist/commands/kanban.js +4 -4
  84. package/dist/commands/link.js +5 -5
  85. package/dist/commands/migrate-observations.js +4 -4
  86. package/dist/commands/observe.d.ts +0 -1
  87. package/dist/commands/observe.js +14 -13
  88. package/dist/commands/project.js +5 -5
  89. package/dist/commands/rebuild-embeddings.d.ts +21 -0
  90. package/dist/commands/rebuild-embeddings.js +91 -0
  91. package/dist/commands/rebuild.js +12 -11
  92. package/dist/commands/recover.js +3 -3
  93. package/dist/commands/reflect.js +6 -7
  94. package/dist/commands/repair-session.js +1 -1
  95. package/dist/commands/replay.js +14 -14
  96. package/dist/commands/session-recap.js +1 -1
  97. package/dist/commands/setup.d.ts +2 -90
  98. package/dist/commands/setup.js +3 -21
  99. package/dist/commands/shell-init.js +1 -1
  100. package/dist/commands/sleep.d.ts +1 -1
  101. package/dist/commands/sleep.js +20 -19
  102. package/dist/commands/status.d.ts +2 -0
  103. package/dist/commands/status.js +57 -35
  104. package/dist/commands/sync-bd.d.ts +10 -0
  105. package/dist/commands/sync-bd.js +10 -0
  106. package/dist/commands/tailscale.js +3 -3
  107. package/dist/commands/task.js +4 -4
  108. package/dist/commands/template.js +2 -2
  109. package/dist/commands/wake.d.ts +1 -1
  110. package/dist/commands/wake.js +11 -10
  111. package/dist/commands/workgraph.d.ts +124 -0
  112. package/dist/commands/workgraph.js +38 -0
  113. package/dist/index.d.ts +337 -191
  114. package/dist/index.js +387 -118
  115. package/dist/{inject-Bzi5E-By.d.cts → inject-DYUrDqQO.d.ts} +3 -3
  116. package/dist/ledger-B7g7jhqG.d.ts +44 -0
  117. package/dist/lib/auto-linker.js +2 -2
  118. package/dist/lib/canvas-layout.d.ts +100 -16
  119. package/dist/lib/canvas-layout.js +21 -78
  120. package/dist/lib/config.d.ts +27 -3
  121. package/dist/lib/config.js +4 -2
  122. package/dist/lib/entity-index.js +1 -1
  123. package/dist/lib/project-utils.js +4 -4
  124. package/dist/lib/session-repair.js +1 -1
  125. package/dist/lib/session-utils.js +1 -1
  126. package/dist/lib/tailscale.js +1 -1
  127. package/dist/lib/task-utils.js +3 -3
  128. package/dist/lib/template-engine.js +1 -1
  129. package/dist/lib/webdav.js +1 -1
  130. package/dist/onnxruntime_binding-5QEF3SUC.node +0 -0
  131. package/dist/onnxruntime_binding-BKPKNEGC.node +0 -0
  132. package/dist/onnxruntime_binding-FMOXGIUT.node +0 -0
  133. package/dist/onnxruntime_binding-OI2KMXC5.node +0 -0
  134. package/dist/onnxruntime_binding-UX44MLAZ.node +0 -0
  135. package/dist/onnxruntime_binding-Y2W7N7WY.node +0 -0
  136. package/dist/openclaw-plugin.d.ts +8 -0
  137. package/dist/openclaw-plugin.js +14 -0
  138. package/dist/registry-BR4326o0.d.ts +30 -0
  139. package/dist/store-CA-6sKCJ.d.ts +34 -0
  140. package/dist/thread-B9LhXNU0.d.ts +41 -0
  141. package/dist/transformers.node-A2ZRORSQ.js +46775 -0
  142. package/dist/{types-Y2_Um2Ls.d.cts → types-BbWJoC1c.d.ts} +1 -44
  143. package/dist/workgraph/index.d.ts +5 -0
  144. package/dist/workgraph/index.js +23 -0
  145. package/dist/workgraph/ledger.d.ts +2 -0
  146. package/dist/workgraph/ledger.js +25 -0
  147. package/dist/workgraph/registry.d.ts +2 -0
  148. package/dist/workgraph/registry.js +19 -0
  149. package/dist/workgraph/store.d.ts +2 -0
  150. package/dist/workgraph/store.js +25 -0
  151. package/dist/workgraph/thread.d.ts +2 -0
  152. package/dist/workgraph/thread.js +25 -0
  153. package/dist/workgraph/types.d.ts +54 -0
  154. package/dist/workgraph/types.js +7 -0
  155. package/hooks/clawvault/HOOK.md +34 -4
  156. package/hooks/clawvault/handler.js +760 -78
  157. package/hooks/clawvault/handler.test.js +235 -79
  158. package/hooks/clawvault/openclaw.plugin.json +72 -0
  159. package/openclaw.plugin.json +65 -38
  160. package/package.json +15 -18
  161. package/dist/chunk-3RG5ZIWI.js +0 -10
  162. package/dist/chunk-6U6MK36V.js +0 -205
  163. package/dist/chunk-7R7O6STJ.js +0 -88
  164. package/dist/chunk-CMB7UL7C.js +0 -327
  165. package/dist/chunk-DEFFDRVP.js +0 -938
  166. package/dist/chunk-E7MFQB6D.js +0 -163
  167. package/dist/chunk-GAJV4IGR.js +0 -82
  168. package/dist/chunk-GQSLDZTS.js +0 -560
  169. package/dist/chunk-K234IDRJ.js +0 -1073
  170. package/dist/chunk-MFM6K7PU.js +0 -374
  171. package/dist/chunk-MXSSG3QU.js +0 -42
  172. package/dist/chunk-PAH27GSN.js +0 -108
  173. package/dist/cli/index.cjs +0 -10033
  174. package/dist/cli/index.d.cts +0 -5
  175. package/dist/commands/archive.cjs +0 -287
  176. package/dist/commands/archive.d.cts +0 -11
  177. package/dist/commands/backlog.cjs +0 -721
  178. package/dist/commands/backlog.d.cts +0 -53
  179. package/dist/commands/blocked.cjs +0 -204
  180. package/dist/commands/blocked.d.cts +0 -26
  181. package/dist/commands/checkpoint.cjs +0 -244
  182. package/dist/commands/checkpoint.d.cts +0 -41
  183. package/dist/commands/compat.cjs +0 -369
  184. package/dist/commands/compat.d.cts +0 -28
  185. package/dist/commands/context.cjs +0 -2989
  186. package/dist/commands/context.d.cts +0 -2
  187. package/dist/commands/doctor.cjs +0 -3062
  188. package/dist/commands/doctor.d.cts +0 -21
  189. package/dist/commands/embed.cjs +0 -232
  190. package/dist/commands/embed.d.cts +0 -17
  191. package/dist/commands/entities.cjs +0 -141
  192. package/dist/commands/entities.d.cts +0 -7
  193. package/dist/commands/graph.cjs +0 -501
  194. package/dist/commands/graph.d.cts +0 -21
  195. package/dist/commands/inject.cjs +0 -1636
  196. package/dist/commands/inject.d.cts +0 -2
  197. package/dist/commands/kanban.cjs +0 -884
  198. package/dist/commands/kanban.d.cts +0 -63
  199. package/dist/commands/link.cjs +0 -965
  200. package/dist/commands/link.d.cts +0 -11
  201. package/dist/commands/migrate-observations.cjs +0 -362
  202. package/dist/commands/migrate-observations.d.cts +0 -19
  203. package/dist/commands/observe.cjs +0 -4099
  204. package/dist/commands/observe.d.cts +0 -23
  205. package/dist/commands/project.cjs +0 -1341
  206. package/dist/commands/project.d.cts +0 -85
  207. package/dist/commands/rebuild.cjs +0 -3136
  208. package/dist/commands/rebuild.d.cts +0 -11
  209. package/dist/commands/recover.cjs +0 -361
  210. package/dist/commands/recover.d.cts +0 -38
  211. package/dist/commands/reflect.cjs +0 -1008
  212. package/dist/commands/reflect.d.cts +0 -11
  213. package/dist/commands/repair-session.cjs +0 -457
  214. package/dist/commands/repair-session.d.cts +0 -38
  215. package/dist/commands/replay.cjs +0 -4103
  216. package/dist/commands/replay.d.cts +0 -16
  217. package/dist/commands/session-recap.cjs +0 -353
  218. package/dist/commands/session-recap.d.cts +0 -27
  219. package/dist/commands/setup.cjs +0 -1345
  220. package/dist/commands/setup.d.cts +0 -100
  221. package/dist/commands/shell-init.cjs +0 -75
  222. package/dist/commands/shell-init.d.cts +0 -7
  223. package/dist/commands/sleep.cjs +0 -6028
  224. package/dist/commands/sleep.d.cts +0 -36
  225. package/dist/commands/status.cjs +0 -2736
  226. package/dist/commands/status.d.cts +0 -52
  227. package/dist/commands/tailscale.cjs +0 -1532
  228. package/dist/commands/tailscale.d.cts +0 -52
  229. package/dist/commands/task.cjs +0 -1236
  230. package/dist/commands/task.d.cts +0 -97
  231. package/dist/commands/template.cjs +0 -457
  232. package/dist/commands/template.d.cts +0 -36
  233. package/dist/commands/wake.cjs +0 -2626
  234. package/dist/commands/wake.d.cts +0 -22
  235. package/dist/context-BUGaWpyL.d.cts +0 -46
  236. package/dist/index.cjs +0 -14526
  237. package/dist/index.d.cts +0 -858
  238. package/dist/inject-Bzi5E-By.d.ts +0 -137
  239. package/dist/lib/auto-linker.cjs +0 -176
  240. package/dist/lib/auto-linker.d.cts +0 -26
  241. package/dist/lib/canvas-layout.cjs +0 -136
  242. package/dist/lib/canvas-layout.d.cts +0 -31
  243. package/dist/lib/config.cjs +0 -78
  244. package/dist/lib/config.d.cts +0 -11
  245. package/dist/lib/entity-index.cjs +0 -84
  246. package/dist/lib/entity-index.d.cts +0 -26
  247. package/dist/lib/project-utils.cjs +0 -864
  248. package/dist/lib/project-utils.d.cts +0 -97
  249. package/dist/lib/session-repair.cjs +0 -239
  250. package/dist/lib/session-repair.d.cts +0 -110
  251. package/dist/lib/session-utils.cjs +0 -209
  252. package/dist/lib/session-utils.d.cts +0 -63
  253. package/dist/lib/tailscale.cjs +0 -1183
  254. package/dist/lib/tailscale.d.cts +0 -225
  255. package/dist/lib/task-utils.cjs +0 -1137
  256. package/dist/lib/task-utils.d.cts +0 -208
  257. package/dist/lib/template-engine.cjs +0 -47
  258. package/dist/lib/template-engine.d.cts +0 -11
  259. package/dist/lib/webdav.cjs +0 -568
  260. package/dist/lib/webdav.d.cts +0 -109
  261. package/dist/plugin/index.cjs +0 -1907
  262. package/dist/plugin/index.d.cts +0 -36
  263. package/dist/plugin/index.d.ts +0 -36
  264. package/dist/plugin/index.js +0 -572
  265. package/dist/plugin/inject.cjs +0 -356
  266. package/dist/plugin/inject.d.cts +0 -54
  267. package/dist/plugin/inject.d.ts +0 -54
  268. package/dist/plugin/inject.js +0 -17
  269. package/dist/plugin/observe.cjs +0 -631
  270. package/dist/plugin/observe.d.cts +0 -39
  271. package/dist/plugin/observe.d.ts +0 -39
  272. package/dist/plugin/observe.js +0 -18
  273. package/dist/plugin/templates.cjs +0 -593
  274. package/dist/plugin/templates.d.cts +0 -52
  275. package/dist/plugin/templates.d.ts +0 -52
  276. package/dist/plugin/templates.js +0 -25
  277. package/dist/plugin/types.cjs +0 -18
  278. package/dist/plugin/types.d.cts +0 -209
  279. package/dist/plugin/types.d.ts +0 -209
  280. package/dist/plugin/types.js +0 -0
  281. package/dist/plugin/vault.cjs +0 -927
  282. package/dist/plugin/vault.d.cts +0 -68
  283. package/dist/plugin/vault.d.ts +0 -68
  284. package/dist/plugin/vault.js +0 -22
  285. package/dist/types-Y2_Um2Ls.d.ts +0 -205
  286. package/templates/memory-event.md +0 -67
  287. package/templates/party.md +0 -63
  288. package/templates/primitive-registry.yaml +0 -551
  289. package/templates/run.md +0 -68
  290. package/templates/trigger.md +0 -68
  291. package/templates/workspace.md +0 -50
@@ -1,97 +0,0 @@
1
- import { Task } from './task-utils.cjs';
2
-
3
- /**
4
- * Project utilities for ClawVault project tracking
5
- * Handles project definition and activity file read/write/query operations
6
- */
7
-
8
- type ProjectStatus = 'active' | 'paused' | 'completed' | 'archived';
9
- interface ProjectFrontmatter {
10
- type: 'project';
11
- status: ProjectStatus;
12
- created: string;
13
- updated: string;
14
- owner?: string;
15
- team?: string[];
16
- client?: string;
17
- tags?: string[];
18
- description?: string;
19
- started?: string;
20
- deadline?: string;
21
- repo?: string;
22
- url?: string;
23
- completed?: string;
24
- reason?: string;
25
- }
26
- interface Project {
27
- slug: string;
28
- title: string;
29
- content: string;
30
- frontmatter: ProjectFrontmatter;
31
- }
32
- interface ProjectFilterOptions {
33
- status?: ProjectStatus;
34
- owner?: string;
35
- client?: string;
36
- tag?: string;
37
- }
38
- interface CreateProjectOptions {
39
- status?: ProjectStatus;
40
- owner?: string;
41
- team?: string[];
42
- client?: string;
43
- tags?: string[];
44
- description?: string;
45
- started?: string;
46
- deadline?: string;
47
- repo?: string;
48
- url?: string;
49
- completed?: string;
50
- reason?: string;
51
- content?: string;
52
- }
53
- interface UpdateProjectOptions {
54
- status?: ProjectStatus;
55
- owner?: string | null;
56
- team?: string[] | null;
57
- client?: string | null;
58
- tags?: string[] | null;
59
- description?: string | null;
60
- started?: string | null;
61
- deadline?: string | null;
62
- repo?: string | null;
63
- url?: string | null;
64
- completed?: string | null;
65
- reason?: string | null;
66
- }
67
- /**
68
- * List all project definition files in the vault.
69
- * Includes only root-level projects/*.md files with type: project frontmatter.
70
- */
71
- declare function listProjects(vaultPath: string, filters?: ProjectFilterOptions): Project[];
72
- /**
73
- * Read a project definition file from projects/{slug}.md
74
- */
75
- declare function readProject(vaultPath: string, slug: string): Project | null;
76
- /**
77
- * Create a new project definition at projects/{slug}.md
78
- */
79
- declare function createProject(vaultPath: string, title: string, options?: CreateProjectOptions): Project;
80
- /**
81
- * Update an existing project's frontmatter
82
- */
83
- declare function updateProject(vaultPath: string, slug: string, updates: UpdateProjectOptions): Project;
84
- /**
85
- * Archive a project with optional reason and completion date
86
- */
87
- declare function archiveProject(vaultPath: string, slug: string, reason?: string): Project;
88
- /**
89
- * List tasks linked to a project by task.frontmatter.project === project slug
90
- */
91
- declare function getProjectTasks(vaultPath: string, slug: string): Task[];
92
- /**
93
- * List files in projects/{slug}/ sorted by date (newest first)
94
- */
95
- declare function getProjectActivity(vaultPath: string, slug: string): string[];
96
-
97
- export { type CreateProjectOptions, type Project, type ProjectFilterOptions, type ProjectFrontmatter, type ProjectStatus, type UpdateProjectOptions, archiveProject, createProject, getProjectActivity, getProjectTasks, listProjects, readProject, updateProject };
@@ -1,239 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/lib/session-repair.ts
31
- var session_repair_exports = {};
32
- __export(session_repair_exports, {
33
- analyzeSession: () => analyzeSession,
34
- computeParentRelinks: () => computeParentRelinks,
35
- extractToolUses: () => extractToolUses,
36
- findCorruptedEntries: () => findCorruptedEntries,
37
- parseTranscript: () => parseTranscript,
38
- repairSession: () => repairSession
39
- });
40
- module.exports = __toCommonJS(session_repair_exports);
41
- var fs = __toESM(require("fs"), 1);
42
- function parseTranscript(filePath) {
43
- const content = fs.readFileSync(filePath, "utf-8");
44
- const lines = content.split("\n").filter((line) => line.trim());
45
- const entries = [];
46
- for (let i = 0; i < lines.length; i++) {
47
- const raw = lines[i];
48
- try {
49
- const entry = JSON.parse(raw);
50
- entries.push({ line: i + 1, entry, raw });
51
- } catch {
52
- console.warn(`Warning: Could not parse line ${i + 1}`);
53
- }
54
- }
55
- return entries;
56
- }
57
- function extractToolUses(entries) {
58
- const toolUses = /* @__PURE__ */ new Map();
59
- for (const { line, entry } of entries) {
60
- if (entry.type !== "message") continue;
61
- if (entry.message?.role !== "assistant") continue;
62
- const isAborted = entry.message.stopReason === "aborted";
63
- const content = entry.message.content || [];
64
- for (const block of content) {
65
- if (block.type === "toolCall" || block.type === "tool_use" || block.type === "functionCall") {
66
- if (block.id) {
67
- const isPartial = !!block.partialJson;
68
- toolUses.set(block.id, {
69
- id: block.id,
70
- lineNumber: line,
71
- entryId: entry.id,
72
- isAborted: isAborted || isPartial,
73
- isPartial,
74
- name: block.name
75
- });
76
- }
77
- }
78
- }
79
- }
80
- return toolUses;
81
- }
82
- function findCorruptedEntries(entries, toolUses) {
83
- const corrupted = [];
84
- const entriesToRemove = /* @__PURE__ */ new Set();
85
- for (const [toolId, info] of toolUses) {
86
- if (info.isAborted) {
87
- corrupted.push({
88
- lineNumber: info.lineNumber,
89
- entryId: info.entryId,
90
- type: "aborted_tool_use",
91
- toolUseId: toolId,
92
- description: `Aborted tool_use${info.name ? ` (${info.name})` : ""} with id: ${toolId}`
93
- });
94
- entriesToRemove.add(info.entryId);
95
- }
96
- }
97
- for (const { line, entry } of entries) {
98
- if (entry.type !== "message") continue;
99
- if (entry.message?.role !== "toolResult") continue;
100
- const content = entry.message.content || [];
101
- let toolCallId;
102
- const msg = entry.message;
103
- toolCallId = msg.toolCallId || msg.toolUseId;
104
- if (!toolCallId) {
105
- for (const block of content) {
106
- if (block.toolCallId || block.toolUseId) {
107
- toolCallId = block.toolCallId || block.toolUseId;
108
- break;
109
- }
110
- }
111
- }
112
- if (!toolCallId) continue;
113
- const toolUse = toolUses.get(toolCallId);
114
- if (!toolUse || toolUse.isAborted) {
115
- corrupted.push({
116
- lineNumber: line,
117
- entryId: entry.id,
118
- type: "orphaned_tool_result",
119
- toolUseId: toolCallId,
120
- description: toolUse ? `Orphaned tool_result references aborted tool_use: ${toolCallId}` : `Orphaned tool_result references non-existent tool_use: ${toolCallId}`
121
- });
122
- entriesToRemove.add(entry.id);
123
- }
124
- }
125
- return { corrupted, entriesToRemove };
126
- }
127
- function computeParentRelinks(entries, entriesToRemove) {
128
- const relinks = [];
129
- const entryParents = /* @__PURE__ */ new Map();
130
- for (const { entry } of entries) {
131
- entryParents.set(entry.id, entry.parentId);
132
- }
133
- for (const { line, entry } of entries) {
134
- if (entriesToRemove.has(entry.id)) continue;
135
- if (!entry.parentId) continue;
136
- if (!entriesToRemove.has(entry.parentId)) continue;
137
- let newParentId = entry.parentId;
138
- while (newParentId && entriesToRemove.has(newParentId)) {
139
- newParentId = entryParents.get(newParentId) || null;
140
- }
141
- if (newParentId !== entry.parentId) {
142
- relinks.push({
143
- lineNumber: line,
144
- entryId: entry.id,
145
- oldParentId: entry.parentId,
146
- newParentId: newParentId || "null"
147
- });
148
- }
149
- }
150
- return relinks;
151
- }
152
- function analyzeSession(filePath) {
153
- const entries = parseTranscript(filePath);
154
- const sessionEntry = entries.find((e) => e.entry.type === "session");
155
- const sessionId = sessionEntry?.entry.id || "unknown";
156
- const toolUses = extractToolUses(entries);
157
- const { corrupted, entriesToRemove } = findCorruptedEntries(entries, toolUses);
158
- const parentRelinks = computeParentRelinks(entries, entriesToRemove);
159
- return {
160
- sessionId,
161
- totalLines: entries.length,
162
- corruptedEntries: corrupted,
163
- parentRelinks,
164
- removedCount: entriesToRemove.size,
165
- relinkedCount: parentRelinks.length,
166
- repaired: false
167
- };
168
- }
169
- function repairSession(filePath, options = {}) {
170
- const { backup = true, dryRun = false } = options;
171
- const entries = parseTranscript(filePath);
172
- const sessionEntry = entries.find((e) => e.entry.type === "session");
173
- const sessionId = sessionEntry?.entry.id || "unknown";
174
- const toolUses = extractToolUses(entries);
175
- const { corrupted, entriesToRemove } = findCorruptedEntries(entries, toolUses);
176
- const parentRelinks = computeParentRelinks(entries, entriesToRemove);
177
- if (corrupted.length === 0) {
178
- return {
179
- sessionId,
180
- totalLines: entries.length,
181
- corruptedEntries: [],
182
- parentRelinks: [],
183
- removedCount: 0,
184
- relinkedCount: 0,
185
- repaired: false
186
- };
187
- }
188
- if (dryRun) {
189
- return {
190
- sessionId,
191
- totalLines: entries.length,
192
- corruptedEntries: corrupted,
193
- parentRelinks,
194
- removedCount: entriesToRemove.size,
195
- relinkedCount: parentRelinks.length,
196
- repaired: false
197
- };
198
- }
199
- let backupPath;
200
- if (backup) {
201
- const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "").replace("T", "-").slice(0, 15);
202
- backupPath = `${filePath}.backup-${timestamp}`;
203
- fs.copyFileSync(filePath, backupPath);
204
- }
205
- const relinkMap = /* @__PURE__ */ new Map();
206
- for (const relink of parentRelinks) {
207
- relinkMap.set(relink.entryId, relink.newParentId === "null" ? null : relink.newParentId);
208
- }
209
- const repairedLines = [];
210
- for (const { entry, raw } of entries) {
211
- if (entriesToRemove.has(entry.id)) continue;
212
- if (relinkMap.has(entry.id)) {
213
- const newEntry = { ...entry, parentId: relinkMap.get(entry.id) };
214
- repairedLines.push(JSON.stringify(newEntry));
215
- } else {
216
- repairedLines.push(raw);
217
- }
218
- }
219
- fs.writeFileSync(filePath, repairedLines.join("\n") + "\n");
220
- return {
221
- sessionId,
222
- totalLines: entries.length,
223
- corruptedEntries: corrupted,
224
- parentRelinks,
225
- removedCount: entriesToRemove.size,
226
- relinkedCount: parentRelinks.length,
227
- backupPath,
228
- repaired: true
229
- };
230
- }
231
- // Annotate the CommonJS export names for ESM import in node:
232
- 0 && (module.exports = {
233
- analyzeSession,
234
- computeParentRelinks,
235
- extractToolUses,
236
- findCorruptedEntries,
237
- parseTranscript,
238
- repairSession
239
- });
@@ -1,110 +0,0 @@
1
- /**
2
- * Session transcript repair logic
3
- *
4
- * Repairs corrupted OpenClaw session transcripts by:
5
- * 1. Finding aborted tool_use blocks (stopReason: "aborted", partialJson present)
6
- * 2. Finding orphaned tool_result messages that reference non-existent tool_use IDs
7
- * 3. Removing both the aborted entries and orphaned results
8
- * 4. Relinking parent chain references
9
- */
10
- interface TranscriptEntry {
11
- type: 'session' | 'message' | 'compaction' | 'custom' | 'thinking_level_change' | string;
12
- id: string;
13
- parentId: string | null;
14
- timestamp: string;
15
- message?: {
16
- role: 'user' | 'assistant' | 'toolResult' | 'system';
17
- content: Array<{
18
- type: string;
19
- id?: string;
20
- name?: string;
21
- arguments?: unknown;
22
- toolCallId?: string;
23
- toolUseId?: string;
24
- partialJson?: string;
25
- text?: string;
26
- }>;
27
- stopReason?: string;
28
- errorMessage?: string;
29
- };
30
- summary?: string;
31
- customType?: string;
32
- data?: unknown;
33
- thinkingLevel?: string;
34
- }
35
- interface ToolUseInfo {
36
- id: string;
37
- lineNumber: number;
38
- entryId: string;
39
- isAborted: boolean;
40
- isPartial: boolean;
41
- name?: string;
42
- }
43
- interface CorruptedEntry {
44
- lineNumber: number;
45
- entryId: string;
46
- type: 'aborted_tool_use' | 'orphaned_tool_result';
47
- toolUseId: string;
48
- description: string;
49
- }
50
- interface ParentRelink {
51
- lineNumber: number;
52
- entryId: string;
53
- oldParentId: string;
54
- newParentId: string;
55
- }
56
- interface RepairResult {
57
- sessionId: string;
58
- totalLines: number;
59
- corruptedEntries: CorruptedEntry[];
60
- parentRelinks: ParentRelink[];
61
- removedCount: number;
62
- relinkedCount: number;
63
- backupPath?: string;
64
- repaired: boolean;
65
- }
66
- /**
67
- * Parse a JSONL file into transcript entries with line numbers
68
- */
69
- declare function parseTranscript(filePath: string): Array<{
70
- line: number;
71
- entry: TranscriptEntry;
72
- raw: string;
73
- }>;
74
- /**
75
- * Extract all tool_use IDs from assistant messages
76
- */
77
- declare function extractToolUses(entries: Array<{
78
- line: number;
79
- entry: TranscriptEntry;
80
- }>): Map<string, ToolUseInfo>;
81
- /**
82
- * Find orphaned tool_result messages that reference non-existent or aborted tool_use IDs
83
- */
84
- declare function findCorruptedEntries(entries: Array<{
85
- line: number;
86
- entry: TranscriptEntry;
87
- }>, toolUses: Map<string, ToolUseInfo>): {
88
- corrupted: CorruptedEntry[];
89
- entriesToRemove: Set<string>;
90
- };
91
- /**
92
- * Compute parent chain relinks after removing entries
93
- */
94
- declare function computeParentRelinks(entries: Array<{
95
- line: number;
96
- entry: TranscriptEntry;
97
- }>, entriesToRemove: Set<string>): ParentRelink[];
98
- /**
99
- * Analyze a session transcript for corruption without modifying it
100
- */
101
- declare function analyzeSession(filePath: string): RepairResult;
102
- /**
103
- * Repair a session transcript
104
- */
105
- declare function repairSession(filePath: string, options?: {
106
- backup?: boolean;
107
- dryRun?: boolean;
108
- }): RepairResult;
109
-
110
- export { type CorruptedEntry, type ParentRelink, type RepairResult, type ToolUseInfo, type TranscriptEntry, analyzeSession, computeParentRelinks, extractToolUses, findCorruptedEntries, parseTranscript, repairSession };
@@ -1,209 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/lib/session-utils.ts
31
- var session_utils_exports = {};
32
- __export(session_utils_exports, {
33
- backupSession: () => backupSession,
34
- findMainSession: () => findMainSession,
35
- findSessionById: () => findSessionById,
36
- getOpenClawAgentsDir: () => getOpenClawAgentsDir,
37
- getOpenClawDir: () => getOpenClawDir,
38
- getSessionFilePath: () => getSessionFilePath,
39
- getSessionsDir: () => getSessionsDir,
40
- getSessionsJsonPath: () => getSessionsJsonPath,
41
- listAgents: () => listAgents,
42
- listSessions: () => listSessions,
43
- loadSessionsStore: () => loadSessionsStore
44
- });
45
- module.exports = __toCommonJS(session_utils_exports);
46
- var fs = __toESM(require("fs"), 1);
47
- var path = __toESM(require("path"), 1);
48
- var os = __toESM(require("os"), 1);
49
- function validateEnvPath(envValue) {
50
- if (!envValue) return null;
51
- const trimmed = envValue.trim();
52
- if (!trimmed) return null;
53
- const resolved = path.resolve(trimmed);
54
- if (!path.isAbsolute(resolved)) return null;
55
- return resolved;
56
- }
57
- function getOpenClawDir() {
58
- const customHome = validateEnvPath(process.env.OPENCLAW_HOME);
59
- if (customHome) {
60
- return customHome;
61
- }
62
- return path.join(os.homedir(), ".openclaw");
63
- }
64
- function getOpenClawAgentsDir() {
65
- const stateDir = validateEnvPath(process.env.OPENCLAW_STATE_DIR);
66
- if (stateDir) {
67
- return path.join(stateDir, "agents");
68
- }
69
- return path.join(getOpenClawDir(), "agents");
70
- }
71
- function getSessionsDir(agentId) {
72
- return path.join(getOpenClawAgentsDir(), agentId, "sessions");
73
- }
74
- function getSessionsJsonPath(agentId) {
75
- return path.join(getSessionsDir(agentId), "sessions.json");
76
- }
77
- function getSessionFilePath(agentId, sessionId) {
78
- return path.join(getSessionsDir(agentId), `${sessionId}.jsonl`);
79
- }
80
- function listAgents() {
81
- const agentsDir = getOpenClawAgentsDir();
82
- try {
83
- if (!fs.existsSync(agentsDir)) {
84
- return [];
85
- }
86
- const stat = fs.statSync(agentsDir);
87
- if (!stat.isDirectory()) {
88
- return [];
89
- }
90
- return fs.readdirSync(agentsDir).filter((name) => {
91
- try {
92
- const sessionsDir = getSessionsDir(name);
93
- return fs.existsSync(sessionsDir) && fs.statSync(sessionsDir).isDirectory();
94
- } catch {
95
- return false;
96
- }
97
- });
98
- } catch {
99
- return [];
100
- }
101
- }
102
- function loadSessionsStore(agentId) {
103
- const sessionsJsonPath = getSessionsJsonPath(agentId);
104
- if (!fs.existsSync(sessionsJsonPath)) {
105
- return null;
106
- }
107
- try {
108
- const content = fs.readFileSync(sessionsJsonPath, "utf-8");
109
- return JSON.parse(content);
110
- } catch {
111
- return null;
112
- }
113
- }
114
- function findMainSession(agentId) {
115
- const store = loadSessionsStore(agentId);
116
- if (!store) return null;
117
- const mainKey = `agent:${agentId}:main`;
118
- const entry = store[mainKey];
119
- if (entry?.sessionId) {
120
- const filePath = getSessionFilePath(agentId, entry.sessionId);
121
- if (fs.existsSync(filePath)) {
122
- return {
123
- sessionId: entry.sessionId,
124
- sessionKey: mainKey,
125
- agentId,
126
- filePath,
127
- updatedAt: entry.updatedAt
128
- };
129
- }
130
- }
131
- return null;
132
- }
133
- function findSessionById(agentId, sessionId) {
134
- const filePath = getSessionFilePath(agentId, sessionId);
135
- if (!fs.existsSync(filePath)) {
136
- return null;
137
- }
138
- const store = loadSessionsStore(agentId);
139
- let sessionKey;
140
- let updatedAt;
141
- if (store) {
142
- for (const [key, entry] of Object.entries(store)) {
143
- if (entry.sessionId === sessionId) {
144
- sessionKey = key;
145
- updatedAt = entry.updatedAt;
146
- break;
147
- }
148
- }
149
- }
150
- return {
151
- sessionId,
152
- sessionKey: sessionKey || `agent:${agentId}:unknown`,
153
- agentId,
154
- filePath,
155
- updatedAt
156
- };
157
- }
158
- function listSessions(agentId) {
159
- const sessionsDir = getSessionsDir(agentId);
160
- if (!fs.existsSync(sessionsDir)) {
161
- return [];
162
- }
163
- const store = loadSessionsStore(agentId);
164
- const sessions = [];
165
- const files = fs.readdirSync(sessionsDir).filter((f) => f.endsWith(".jsonl") && !f.includes(".backup") && !f.includes(".deleted") && !f.includes(".corrupted"));
166
- for (const file of files) {
167
- const sessionId = file.replace(".jsonl", "");
168
- const filePath = path.join(sessionsDir, file);
169
- let sessionKey = `agent:${agentId}:unknown`;
170
- let updatedAt;
171
- if (store) {
172
- for (const [key, entry] of Object.entries(store)) {
173
- if (entry.sessionId === sessionId) {
174
- sessionKey = key;
175
- updatedAt = entry.updatedAt;
176
- break;
177
- }
178
- }
179
- }
180
- sessions.push({
181
- sessionId,
182
- sessionKey,
183
- agentId,
184
- filePath,
185
- updatedAt
186
- });
187
- }
188
- return sessions.sort((a, b) => (b.updatedAt || 0) - (a.updatedAt || 0));
189
- }
190
- function backupSession(filePath) {
191
- const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "").replace("T", "-").slice(0, 15);
192
- const backupPath = `${filePath}.backup-${timestamp}`;
193
- fs.copyFileSync(filePath, backupPath);
194
- return backupPath;
195
- }
196
- // Annotate the CommonJS export names for ESM import in node:
197
- 0 && (module.exports = {
198
- backupSession,
199
- findMainSession,
200
- findSessionById,
201
- getOpenClawAgentsDir,
202
- getOpenClawDir,
203
- getSessionFilePath,
204
- getSessionsDir,
205
- getSessionsJsonPath,
206
- listAgents,
207
- listSessions,
208
- loadSessionsStore
209
- });