clawvault 3.1.0 → 3.2.1

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 (273) hide show
  1. package/README.md +422 -141
  2. package/bin/clawvault.js +10 -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 -28
  6. package/bin/register-maintenance-commands.js +39 -3
  7. package/bin/register-query-commands.js +58 -29
  8. package/bin/register-tailscale-commands.js +106 -0
  9. package/bin/register-task-commands.js +18 -1
  10. package/bin/register-task-commands.test.js +16 -0
  11. package/bin/register-vault-operations-commands.js +29 -1
  12. package/bin/register-workgraph-commands.js +451 -0
  13. package/dashboard/lib/graph-diff.js +104 -0
  14. package/dashboard/lib/graph-diff.test.js +75 -0
  15. package/dashboard/lib/vault-parser.js +556 -0
  16. package/dashboard/lib/vault-parser.test.js +254 -0
  17. package/dashboard/public/app.js +796 -0
  18. package/dashboard/public/index.html +52 -0
  19. package/dashboard/public/styles.css +221 -0
  20. package/dashboard/server.js +374 -0
  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-F2JEUD4J.js → chunk-4ITRXIVT.js} +5 -7
  24. package/dist/{chunk-GUKMRGM7.js → chunk-4OXMU5S2.js} +1 -1
  25. package/dist/chunk-5PJ4STIC.js +465 -0
  26. package/dist/{chunk-62YTUT6J.js → chunk-AZYOKJYC.js} +2 -2
  27. package/dist/chunk-BSJ6RIT7.js +447 -0
  28. package/dist/chunk-ECRZL5XR.js +50 -0
  29. package/dist/chunk-ERNE2FZ5.js +189 -0
  30. package/dist/{chunk-WAZ3NLWL.js → chunk-F55HGNU4.js} +0 -47
  31. package/dist/{chunk-VGLOTGAS.js → chunk-FAKNOB7Y.js} +2 -2
  32. package/dist/{chunk-QK3UCXWL.js → chunk-FHFUXL6G.js} +2 -2
  33. package/dist/chunk-GNJL4YGR.js +79 -0
  34. package/dist/chunk-HR4KN6S2.js +152 -0
  35. package/dist/{chunk-OZ7RIXTO.js → chunk-IIOU45CK.js} +1 -1
  36. package/dist/chunk-IJBFGPCS.js +33 -0
  37. package/dist/chunk-IVRIKYFE.js +520 -0
  38. package/dist/chunk-K7PNYS45.js +93 -0
  39. package/dist/chunk-MDIH26GC.js +183 -0
  40. package/dist/{chunk-LYHGEHXG.js → chunk-MFAWT5O5.js} +0 -1
  41. package/dist/{chunk-H34S76MB.js → chunk-MNPUYCHQ.js} +6 -6
  42. package/dist/chunk-NTOPJI7W.js +207 -0
  43. package/dist/{chunk-QBLMXKF2.js → chunk-OIWVQYQF.js} +1 -1
  44. package/dist/chunk-PG56HX5T.js +154 -0
  45. package/dist/{chunk-LNJA2UGL.js → chunk-PI4WMLMG.js} +7 -84
  46. package/dist/chunk-QMHPQYUV.js +363 -0
  47. package/dist/{chunk-H62BP7RI.js → chunk-QPDDIHXE.js} +209 -43
  48. package/dist/{chunk-N2AXRYLC.js → chunk-QWQ3TIKS.js} +1 -1
  49. package/dist/{chunk-3DHXQHYG.js → chunk-R2MIW5G7.js} +1 -1
  50. package/dist/{chunk-SJSFRIYS.js → chunk-S5OJEGFG.js} +2 -2
  51. package/dist/chunk-SS4B7P7V.js +99 -0
  52. package/dist/chunk-TIGW564L.js +628 -0
  53. package/dist/chunk-U67V476Y.js +35 -0
  54. package/dist/{chunk-JY6FYXIT.js → chunk-UCQAOZHW.js} +6 -11
  55. package/dist/{chunk-ITPEXLHA.js → chunk-URXDAUVH.js} +24 -5
  56. package/dist/chunk-WIOLLGAD.js +190 -0
  57. package/dist/{chunk-3WRJEKN4.js → chunk-WJVWINEM.js} +72 -8
  58. package/dist/chunk-WMGIIABP.js +15 -0
  59. package/dist/{chunk-33UGEQRT.js → chunk-X3SPPUFG.js} +151 -64
  60. package/dist/{chunk-3NSBOUT3.js → chunk-Y3TIJEBP.js} +314 -79
  61. package/dist/chunk-Y6VJKXGL.js +373 -0
  62. package/dist/{chunk-LI4O6NVK.js → chunk-YDWHS4LJ.js} +49 -9
  63. package/dist/{chunk-U55BGUAU.js → chunk-YNIPYN4F.js} +5 -5
  64. package/dist/chunk-YXQCA6B7.js +226 -0
  65. package/dist/cli/index.js +26 -22
  66. package/dist/commands/archive.js +3 -3
  67. package/dist/commands/backlog.js +3 -3
  68. package/dist/commands/blocked.js +3 -3
  69. package/dist/commands/canvas.d.ts +15 -0
  70. package/dist/commands/canvas.js +200 -0
  71. package/dist/commands/checkpoint.js +2 -2
  72. package/dist/commands/compat.js +2 -2
  73. package/dist/commands/context.js +7 -5
  74. package/dist/commands/doctor.d.ts +11 -7
  75. package/dist/commands/doctor.js +16 -14
  76. package/dist/commands/embed.js +5 -6
  77. package/dist/commands/entities.js +2 -2
  78. package/dist/commands/graph.js +3 -3
  79. package/dist/commands/inject.d.ts +1 -1
  80. package/dist/commands/inject.js +4 -5
  81. package/dist/commands/kanban.js +4 -4
  82. package/dist/commands/link.js +2 -2
  83. package/dist/commands/migrate-observations.js +4 -4
  84. package/dist/commands/observe.d.ts +0 -1
  85. package/dist/commands/observe.js +13 -12
  86. package/dist/commands/project.js +5 -5
  87. package/dist/commands/rebuild-embeddings.d.ts +21 -0
  88. package/dist/commands/rebuild-embeddings.js +91 -0
  89. package/dist/commands/rebuild.js +12 -11
  90. package/dist/commands/recover.js +3 -3
  91. package/dist/commands/reflect.js +6 -7
  92. package/dist/commands/repair-session.js +1 -1
  93. package/dist/commands/replay.js +14 -14
  94. package/dist/commands/session-recap.js +1 -1
  95. package/dist/commands/setup.d.ts +2 -89
  96. package/dist/commands/setup.js +3 -21
  97. package/dist/commands/shell-init.js +1 -1
  98. package/dist/commands/sleep.d.ts +1 -1
  99. package/dist/commands/sleep.js +18 -17
  100. package/dist/commands/status.d.ts +2 -0
  101. package/dist/commands/status.js +40 -30
  102. package/dist/commands/sync-bd.d.ts +10 -0
  103. package/dist/commands/sync-bd.js +10 -0
  104. package/dist/commands/tailscale.d.ts +52 -0
  105. package/dist/commands/tailscale.js +26 -0
  106. package/dist/commands/task.js +4 -4
  107. package/dist/commands/template.js +2 -2
  108. package/dist/commands/wake.d.ts +1 -1
  109. package/dist/commands/wake.js +11 -10
  110. package/dist/index.d.ts +334 -191
  111. package/dist/index.js +432 -108
  112. package/dist/{inject-Bzi5E-By.d.ts → inject-DYUrDqQO.d.ts} +3 -3
  113. package/dist/ledger-B7g7jhqG.d.ts +44 -0
  114. package/dist/lib/auto-linker.js +1 -1
  115. package/dist/lib/canvas-layout.d.ts +115 -0
  116. package/dist/lib/canvas-layout.js +35 -0
  117. package/dist/lib/config.d.ts +27 -3
  118. package/dist/lib/config.js +4 -2
  119. package/dist/lib/entity-index.js +1 -1
  120. package/dist/lib/project-utils.js +4 -4
  121. package/dist/lib/session-repair.js +1 -1
  122. package/dist/lib/session-utils.js +1 -1
  123. package/dist/lib/tailscale.d.ts +225 -0
  124. package/dist/lib/tailscale.js +50 -0
  125. package/dist/lib/task-utils.js +3 -3
  126. package/dist/lib/template-engine.js +1 -1
  127. package/dist/lib/webdav.d.ts +109 -0
  128. package/dist/lib/webdav.js +35 -0
  129. package/dist/plugin/index.d.ts +344 -28
  130. package/dist/plugin/index.js +3919 -227
  131. package/dist/registry-BR4326o0.d.ts +30 -0
  132. package/dist/store-CA-6sKCJ.d.ts +34 -0
  133. package/dist/thread-B9LhXNU0.d.ts +41 -0
  134. package/dist/{types-Y2_Um2Ls.d.ts → types-BbWJoC1c.d.ts} +1 -44
  135. package/dist/workgraph/index.d.ts +5 -0
  136. package/dist/workgraph/index.js +23 -0
  137. package/dist/workgraph/ledger.d.ts +2 -0
  138. package/dist/workgraph/ledger.js +25 -0
  139. package/dist/workgraph/registry.d.ts +2 -0
  140. package/dist/workgraph/registry.js +19 -0
  141. package/dist/workgraph/store.d.ts +2 -0
  142. package/dist/workgraph/store.js +25 -0
  143. package/dist/workgraph/thread.d.ts +2 -0
  144. package/dist/workgraph/thread.js +25 -0
  145. package/dist/workgraph/types.d.ts +54 -0
  146. package/dist/workgraph/types.js +7 -0
  147. package/hooks/clawvault/HOOK.md +113 -0
  148. package/hooks/clawvault/handler.js +1559 -0
  149. package/hooks/clawvault/handler.test.js +510 -0
  150. package/hooks/clawvault/openclaw.plugin.json +72 -0
  151. package/openclaw.plugin.json +235 -30
  152. package/package.json +20 -20
  153. package/dist/chunk-3RG5ZIWI.js +0 -10
  154. package/dist/chunk-3ZIH425O.js +0 -871
  155. package/dist/chunk-6U6MK36V.js +0 -205
  156. package/dist/chunk-CMB7UL7C.js +0 -327
  157. package/dist/chunk-D2H45LON.js +0 -1074
  158. package/dist/chunk-E7MFQB6D.js +0 -163
  159. package/dist/chunk-GQSLDZTS.js +0 -560
  160. package/dist/chunk-MFM6K7PU.js +0 -374
  161. package/dist/chunk-MXSSG3QU.js +0 -42
  162. package/dist/chunk-OCGVIN3L.js +0 -88
  163. package/dist/chunk-PAH27GSN.js +0 -108
  164. package/dist/chunk-YCUNCH2I.js +0 -78
  165. package/dist/cli/index.cjs +0 -8584
  166. package/dist/cli/index.d.cts +0 -5
  167. package/dist/commands/archive.cjs +0 -287
  168. package/dist/commands/archive.d.cts +0 -11
  169. package/dist/commands/backlog.cjs +0 -721
  170. package/dist/commands/backlog.d.cts +0 -53
  171. package/dist/commands/blocked.cjs +0 -204
  172. package/dist/commands/blocked.d.cts +0 -26
  173. package/dist/commands/checkpoint.cjs +0 -244
  174. package/dist/commands/checkpoint.d.cts +0 -41
  175. package/dist/commands/compat.cjs +0 -294
  176. package/dist/commands/compat.d.cts +0 -28
  177. package/dist/commands/context.cjs +0 -2990
  178. package/dist/commands/context.d.cts +0 -2
  179. package/dist/commands/doctor.cjs +0 -2986
  180. package/dist/commands/doctor.d.cts +0 -21
  181. package/dist/commands/embed.cjs +0 -232
  182. package/dist/commands/embed.d.cts +0 -17
  183. package/dist/commands/entities.cjs +0 -141
  184. package/dist/commands/entities.d.cts +0 -7
  185. package/dist/commands/graph.cjs +0 -501
  186. package/dist/commands/graph.d.cts +0 -21
  187. package/dist/commands/inject.cjs +0 -1636
  188. package/dist/commands/inject.d.cts +0 -2
  189. package/dist/commands/kanban.cjs +0 -884
  190. package/dist/commands/kanban.d.cts +0 -63
  191. package/dist/commands/link.cjs +0 -965
  192. package/dist/commands/link.d.cts +0 -11
  193. package/dist/commands/migrate-observations.cjs +0 -362
  194. package/dist/commands/migrate-observations.d.cts +0 -19
  195. package/dist/commands/observe.cjs +0 -4099
  196. package/dist/commands/observe.d.cts +0 -23
  197. package/dist/commands/project.cjs +0 -1341
  198. package/dist/commands/project.d.cts +0 -85
  199. package/dist/commands/rebuild.cjs +0 -3136
  200. package/dist/commands/rebuild.d.cts +0 -11
  201. package/dist/commands/recover.cjs +0 -361
  202. package/dist/commands/recover.d.cts +0 -38
  203. package/dist/commands/reflect.cjs +0 -1008
  204. package/dist/commands/reflect.d.cts +0 -11
  205. package/dist/commands/repair-session.cjs +0 -457
  206. package/dist/commands/repair-session.d.cts +0 -38
  207. package/dist/commands/replay.cjs +0 -4103
  208. package/dist/commands/replay.d.cts +0 -16
  209. package/dist/commands/session-recap.cjs +0 -353
  210. package/dist/commands/session-recap.d.cts +0 -27
  211. package/dist/commands/setup.cjs +0 -1278
  212. package/dist/commands/setup.d.cts +0 -99
  213. package/dist/commands/shell-init.cjs +0 -75
  214. package/dist/commands/shell-init.d.cts +0 -7
  215. package/dist/commands/sleep.cjs +0 -6029
  216. package/dist/commands/sleep.d.cts +0 -36
  217. package/dist/commands/status.cjs +0 -2737
  218. package/dist/commands/status.d.cts +0 -52
  219. package/dist/commands/task.cjs +0 -1236
  220. package/dist/commands/task.d.cts +0 -97
  221. package/dist/commands/template.cjs +0 -457
  222. package/dist/commands/template.d.cts +0 -36
  223. package/dist/commands/wake.cjs +0 -2627
  224. package/dist/commands/wake.d.cts +0 -22
  225. package/dist/context-BUGaWpyL.d.cts +0 -46
  226. package/dist/index.cjs +0 -12373
  227. package/dist/index.d.cts +0 -854
  228. package/dist/inject-Bzi5E-By.d.cts +0 -137
  229. package/dist/lib/auto-linker.cjs +0 -176
  230. package/dist/lib/auto-linker.d.cts +0 -26
  231. package/dist/lib/config.cjs +0 -78
  232. package/dist/lib/config.d.cts +0 -11
  233. package/dist/lib/entity-index.cjs +0 -84
  234. package/dist/lib/entity-index.d.cts +0 -26
  235. package/dist/lib/project-utils.cjs +0 -864
  236. package/dist/lib/project-utils.d.cts +0 -97
  237. package/dist/lib/session-repair.cjs +0 -239
  238. package/dist/lib/session-repair.d.cts +0 -110
  239. package/dist/lib/session-utils.cjs +0 -209
  240. package/dist/lib/session-utils.d.cts +0 -63
  241. package/dist/lib/task-utils.cjs +0 -1137
  242. package/dist/lib/task-utils.d.cts +0 -208
  243. package/dist/lib/template-engine.cjs +0 -47
  244. package/dist/lib/template-engine.d.cts +0 -11
  245. package/dist/plugin/index.cjs +0 -1907
  246. package/dist/plugin/index.d.cts +0 -36
  247. package/dist/plugin/inject.cjs +0 -356
  248. package/dist/plugin/inject.d.cts +0 -54
  249. package/dist/plugin/inject.d.ts +0 -54
  250. package/dist/plugin/inject.js +0 -17
  251. package/dist/plugin/observe.cjs +0 -631
  252. package/dist/plugin/observe.d.cts +0 -39
  253. package/dist/plugin/observe.d.ts +0 -39
  254. package/dist/plugin/observe.js +0 -18
  255. package/dist/plugin/templates.cjs +0 -593
  256. package/dist/plugin/templates.d.cts +0 -52
  257. package/dist/plugin/templates.d.ts +0 -52
  258. package/dist/plugin/templates.js +0 -25
  259. package/dist/plugin/types.cjs +0 -18
  260. package/dist/plugin/types.d.cts +0 -209
  261. package/dist/plugin/types.d.ts +0 -209
  262. package/dist/plugin/types.js +0 -0
  263. package/dist/plugin/vault.cjs +0 -927
  264. package/dist/plugin/vault.d.cts +0 -68
  265. package/dist/plugin/vault.d.ts +0 -68
  266. package/dist/plugin/vault.js +0 -22
  267. package/dist/types-Y2_Um2Ls.d.cts +0 -205
  268. package/templates/memory-event.md +0 -67
  269. package/templates/party.md +0 -63
  270. package/templates/primitive-registry.yaml +0 -551
  271. package/templates/run.md +0 -68
  272. package/templates/trigger.md +0 -68
  273. package/templates/workspace.md +0 -50
@@ -1,560 +0,0 @@
1
- // src/plugin/templates.ts
2
- import { existsSync, readdirSync, readFileSync } from "fs";
3
- import { join } from "path";
4
- var DEFAULT_SCHEMAS = [
5
- {
6
- primitive: "memory_event",
7
- description: "General memory event for observations",
8
- fields: {
9
- type: { type: "string", required: true, default: "memory_event" },
10
- status: { type: "string", required: true, default: "recorded", enum: ["recorded", "superseded", "corrected"] },
11
- created: { type: "datetime", required: true, default: "{{datetime}}" },
12
- observed_at: { type: "datetime", required: true },
13
- source: { type: "string", required: true, enum: ["openclaw", "claude-code", "replay", "manual-correction"] },
14
- summary: { type: "string", required: true },
15
- confidence: { type: "number" },
16
- importance: { type: "number" }
17
- },
18
- keywords: ["preference", "like", "hate", "want", "need", "always", "never", "remember", "note"]
19
- },
20
- {
21
- primitive: "person",
22
- description: "People and relationship notes",
23
- fields: {
24
- title: { type: "string", required: true, default: "{{title}}" },
25
- date: { type: "date", required: true, default: "{{date}}" },
26
- type: { type: "string", required: true, default: "person" },
27
- relationship: { type: "string", default: "contact" }
28
- },
29
- keywords: ["person", "contact", "colleague", "friend", "works at", "lives in", "email", "phone", "name is"]
30
- },
31
- {
32
- primitive: "decision",
33
- description: "Decision records",
34
- fields: {
35
- title: { type: "string", required: true, default: "{{title}}" },
36
- date: { type: "date", required: true, default: "{{date}}" },
37
- type: { type: "string", required: true, default: "decision" },
38
- status: { type: "string", default: "decided", enum: ["proposed", "decided", "superseded"] }
39
- },
40
- keywords: ["decided", "decision", "chose", "will use", "go with", "ship", "approved", "rejected"]
41
- },
42
- {
43
- primitive: "task",
44
- description: "Task primitives",
45
- fields: {
46
- status: { type: "string", required: true, default: "open", enum: ["open", "in-progress", "blocked", "done"] },
47
- created: { type: "datetime", required: true, default: "{{datetime}}" },
48
- updated: { type: "datetime", required: true, default: "{{datetime}}" },
49
- priority: { type: "string", enum: ["critical", "high", "medium", "low"] },
50
- due: { type: "date" }
51
- },
52
- keywords: ["task", "todo", "need to", "should", "must", "deadline", "due", "by tomorrow", "by tonight"]
53
- },
54
- {
55
- primitive: "project",
56
- description: "Project definition documents",
57
- fields: {
58
- type: { type: "string", required: true, default: "project" },
59
- status: { type: "string", required: true, default: "active", enum: ["active", "paused", "completed", "archived"] },
60
- created: { type: "datetime", required: true, default: "{{datetime}}" },
61
- updated: { type: "datetime", required: true, default: "{{datetime}}" }
62
- },
63
- keywords: ["project", "initiative", "working on", "building", "developing"]
64
- },
65
- {
66
- primitive: "lesson",
67
- description: "Lessons learned",
68
- fields: {
69
- title: { type: "string", required: true, default: "{{title}}" },
70
- date: { type: "date", required: true, default: "{{date}}" },
71
- type: { type: "string", required: true, default: "lesson" }
72
- },
73
- keywords: ["learned", "lesson", "insight", "realized", "discovered", "found out"]
74
- }
75
- ];
76
- function parseYamlFrontmatter(content) {
77
- const match = content.match(/^---\n([\s\S]*?)\n---\n?([\s\S]*)$/);
78
- if (!match) return null;
79
- const yamlContent = match[1];
80
- const body = match[2];
81
- try {
82
- const frontmatter = parseSimpleYaml(yamlContent);
83
- return { frontmatter, body };
84
- } catch {
85
- return null;
86
- }
87
- }
88
- function parseSimpleYaml(yaml) {
89
- const result = {};
90
- const lines = yaml.split("\n");
91
- let currentKey = "";
92
- let currentIndent = 0;
93
- let nestedObject = null;
94
- let nestedKey = "";
95
- for (const line of lines) {
96
- if (!line.trim() || line.trim().startsWith("#")) continue;
97
- const indent = line.search(/\S/);
98
- const trimmed = line.trim();
99
- if (trimmed.startsWith("- ")) {
100
- const value = trimmed.slice(2).trim();
101
- if (nestedObject && nestedKey) {
102
- const arr = nestedObject[nestedKey];
103
- if (Array.isArray(arr)) {
104
- arr.push(parseYamlValue(value));
105
- }
106
- } else if (currentKey && result[currentKey]) {
107
- const arr = result[currentKey];
108
- if (Array.isArray(arr)) {
109
- arr.push(parseYamlValue(value));
110
- }
111
- }
112
- continue;
113
- }
114
- const colonIndex = trimmed.indexOf(":");
115
- if (colonIndex === -1) continue;
116
- const key = trimmed.slice(0, colonIndex).trim();
117
- const valueStr = trimmed.slice(colonIndex + 1).trim();
118
- if (indent === 0) {
119
- if (valueStr === "" || valueStr === "|" || valueStr === ">") {
120
- if (key === "fields") {
121
- result[key] = {};
122
- nestedObject = result[key];
123
- nestedKey = "";
124
- } else {
125
- result[key] = {};
126
- nestedObject = null;
127
- }
128
- } else {
129
- result[key] = parseYamlValue(valueStr);
130
- nestedObject = null;
131
- }
132
- currentKey = key;
133
- currentIndent = indent;
134
- } else if (nestedObject && indent > 0) {
135
- if (valueStr === "" || valueStr === "|" || valueStr === ">") {
136
- nestedObject[key] = {};
137
- nestedKey = key;
138
- } else if (nestedKey && indent > 2) {
139
- const fieldObj = nestedObject[nestedKey];
140
- if (fieldObj) {
141
- if (key === "enum") {
142
- fieldObj[key] = [];
143
- } else {
144
- fieldObj[key] = parseYamlValue(valueStr);
145
- }
146
- }
147
- } else {
148
- nestedObject[key] = parseYamlValue(valueStr);
149
- nestedKey = key;
150
- }
151
- }
152
- }
153
- return result;
154
- }
155
- function parseYamlValue(value) {
156
- if (value === "" || value === "null" || value === "~") return null;
157
- if (value === "true") return true;
158
- if (value === "false") return false;
159
- if (/^-?\d+$/.test(value)) return parseInt(value, 10);
160
- if (/^-?\d+\.\d+$/.test(value)) return parseFloat(value);
161
- if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) {
162
- return value.slice(1, -1);
163
- }
164
- return value;
165
- }
166
- var registry = null;
167
- function getTemplateRegistry() {
168
- if (!registry) {
169
- registry = {
170
- schemas: /* @__PURE__ */ new Map(),
171
- keywordIndex: /* @__PURE__ */ new Map(),
172
- initialized: false
173
- };
174
- }
175
- return registry;
176
- }
177
- function initializeTemplateRegistry(templatesDir) {
178
- const reg = getTemplateRegistry();
179
- if (reg.initialized) {
180
- return reg;
181
- }
182
- const dirsToTry = templatesDir ? [templatesDir] : [
183
- join(process.cwd(), "templates"),
184
- join(process.cwd(), "..", "..", "templates"),
185
- join(process.env.HOME ?? ".", "clawvault", "templates"),
186
- join(process.env.HOME ?? ".", ".clawvault", "templates")
187
- ];
188
- let loaded = false;
189
- for (const dir of dirsToTry) {
190
- if (existsSync(dir)) {
191
- try {
192
- loadTemplatesFromDirectory(dir, reg);
193
- loaded = true;
194
- break;
195
- } catch {
196
- }
197
- }
198
- }
199
- if (!loaded || reg.schemas.size === 0) {
200
- loadDefaultSchemas(reg);
201
- }
202
- buildKeywordIndex(reg);
203
- reg.initialized = true;
204
- return reg;
205
- }
206
- function loadTemplatesFromDirectory(dir, reg) {
207
- const files = readdirSync(dir).filter((f) => f.endsWith(".md"));
208
- for (const file of files) {
209
- const filePath = join(dir, file);
210
- const content = readFileSync(filePath, "utf-8");
211
- const parsed = parseYamlFrontmatter(content);
212
- if (!parsed?.frontmatter?.primitive) continue;
213
- const schema = convertFrontmatterToSchema(parsed.frontmatter, parsed.body);
214
- if (schema) {
215
- reg.schemas.set(schema.primitive, schema);
216
- }
217
- }
218
- }
219
- function convertFrontmatterToSchema(fm, body) {
220
- const primitive = fm.primitive;
221
- if (!primitive) return null;
222
- const fields = {};
223
- const fmFields = fm.fields;
224
- if (fmFields) {
225
- for (const [fieldName, fieldDef] of Object.entries(fmFields)) {
226
- if (typeof fieldDef === "object" && fieldDef !== null) {
227
- const def = fieldDef;
228
- fields[fieldName] = {
229
- type: def.type || "string",
230
- required: def.required,
231
- default: def.default,
232
- enum: def.enum,
233
- description: def.description
234
- };
235
- }
236
- }
237
- }
238
- const keywords = extractKeywordsFromSchema(primitive, fm.description, fields);
239
- return {
240
- primitive,
241
- description: fm.description,
242
- fields,
243
- bodyTemplate: body,
244
- keywords
245
- };
246
- }
247
- function extractKeywordsFromSchema(primitive, description, fields) {
248
- const keywords = [primitive];
249
- keywords.push(primitive.replace(/-/g, " "));
250
- keywords.push(primitive.replace(/_/g, " "));
251
- switch (primitive) {
252
- case "memory_event":
253
- keywords.push("preference", "like", "hate", "want", "need", "always", "never", "remember", "note");
254
- break;
255
- case "person":
256
- keywords.push("person", "contact", "colleague", "friend", "works at", "lives in", "email", "phone", "name is");
257
- break;
258
- case "decision":
259
- keywords.push("decided", "decision", "chose", "will use", "go with", "ship", "approved", "rejected");
260
- break;
261
- case "task":
262
- keywords.push("task", "todo", "need to", "should", "must", "deadline", "due", "by tomorrow", "by tonight");
263
- break;
264
- case "project":
265
- keywords.push("project", "initiative", "working on", "building", "developing");
266
- break;
267
- case "lesson":
268
- keywords.push("learned", "lesson", "insight", "realized", "discovered", "found out");
269
- break;
270
- case "trigger":
271
- keywords.push("trigger", "schedule", "cron", "automated", "recurring");
272
- break;
273
- case "run":
274
- keywords.push("run", "execution", "job", "started", "finished", "failed");
275
- break;
276
- case "checkpoint":
277
- keywords.push("checkpoint", "snapshot", "state", "progress");
278
- break;
279
- case "handoff":
280
- keywords.push("handoff", "transition", "context", "resume");
281
- break;
282
- case "daily-note":
283
- case "daily":
284
- keywords.push("daily", "today", "journal", "log");
285
- break;
286
- case "party":
287
- keywords.push("party", "agent", "human", "runtime", "service");
288
- break;
289
- case "workspace":
290
- keywords.push("workspace", "shared", "collaboration");
291
- break;
292
- }
293
- if (fields.status?.enum) {
294
- keywords.push(...fields.status.enum);
295
- }
296
- return [...new Set(keywords)];
297
- }
298
- function loadDefaultSchemas(reg) {
299
- for (const schema of DEFAULT_SCHEMAS) {
300
- reg.schemas.set(schema.primitive, schema);
301
- }
302
- }
303
- function buildKeywordIndex(reg) {
304
- reg.keywordIndex.clear();
305
- for (const [primitive, schema] of reg.schemas) {
306
- const keywords = schema.keywords ?? [primitive];
307
- for (const keyword of keywords) {
308
- const lower = keyword.toLowerCase();
309
- const existing = reg.keywordIndex.get(lower) ?? [];
310
- if (!existing.includes(primitive)) {
311
- existing.push(primitive);
312
- }
313
- reg.keywordIndex.set(lower, existing);
314
- }
315
- }
316
- }
317
- function classifyText(text) {
318
- const reg = getTemplateRegistry();
319
- if (!reg.initialized) {
320
- initializeTemplateRegistry();
321
- }
322
- const lower = text.toLowerCase();
323
- const scores = /* @__PURE__ */ new Map();
324
- for (const [keyword, primitives] of reg.keywordIndex) {
325
- if (lower.includes(keyword)) {
326
- for (const primitive of primitives) {
327
- const existing = scores.get(primitive) ?? { score: 0, keywords: [] };
328
- existing.score += getKeywordWeight(keyword, primitive);
329
- existing.keywords.push(keyword);
330
- scores.set(primitive, existing);
331
- }
332
- }
333
- }
334
- applyPatternScoring(lower, scores);
335
- let bestPrimitive = "memory_event";
336
- let bestScore = 0;
337
- let bestKeywords = [];
338
- for (const [primitive, data] of scores) {
339
- if (data.score > bestScore) {
340
- bestScore = data.score;
341
- bestPrimitive = primitive;
342
- bestKeywords = data.keywords;
343
- }
344
- }
345
- const confidence = Math.min(1, bestScore / 5);
346
- return {
347
- primitiveType: bestPrimitive,
348
- confidence,
349
- matchedKeywords: [...new Set(bestKeywords)]
350
- };
351
- }
352
- function getKeywordWeight(keyword, primitive) {
353
- if (keyword === primitive || keyword === primitive.replace(/-/g, " ")) {
354
- return 3;
355
- }
356
- const strongIndicators = {
357
- person: ["works at", "lives in", "email", "phone", "name is"],
358
- decision: ["decided", "chose", "will use", "go with"],
359
- task: ["deadline", "due", "by tomorrow", "by tonight"],
360
- memory_event: ["preference", "remember", "note"]
361
- };
362
- if (strongIndicators[primitive]?.includes(keyword)) {
363
- return 2;
364
- }
365
- return 1;
366
- }
367
- function applyPatternScoring(text, scores) {
368
- if (/\b(my .+ is|his .+ is|her .+ is|their .+ is)\b/i.test(text)) {
369
- const existing = scores.get("person") ?? { score: 0, keywords: [] };
370
- existing.score += 2;
371
- existing.keywords.push("possessive pattern");
372
- scores.set("person", existing);
373
- }
374
- if (/[\w.-]+@[\w.-]+\.\w+|\+\d{10,}/.test(text)) {
375
- const existing = scores.get("person") ?? { score: 0, keywords: [] };
376
- existing.score += 3;
377
- existing.keywords.push("contact info");
378
- scores.set("person", existing);
379
- }
380
- if (/\b(i prefer|i like|i hate|i love|i want|i need|i always|i never|don't like|dont like)\b/i.test(text)) {
381
- const existing = scores.get("memory_event") ?? { score: 0, keywords: [] };
382
- existing.score += 3;
383
- existing.keywords.push("preference pattern");
384
- scores.set("memory_event", existing);
385
- }
386
- if (/\b(we decided|let's go with|we're going|i chose|we'll use|ship it|do it)\b/i.test(text)) {
387
- const existing = scores.get("decision") ?? { score: 0, keywords: [] };
388
- existing.score += 3;
389
- existing.keywords.push("decision pattern");
390
- scores.set("decision", existing);
391
- }
392
- if (/\b(by tonight|by tomorrow|deadline|due date|by end of|ship by|ready by)\b/i.test(text)) {
393
- const existing = scores.get("task") ?? { score: 0, keywords: [] };
394
- existing.score += 2;
395
- existing.keywords.push("deadline pattern");
396
- scores.set("task", existing);
397
- }
398
- }
399
- function getSchema(primitiveType) {
400
- const reg = getTemplateRegistry();
401
- if (!reg.initialized) {
402
- initializeTemplateRegistry();
403
- }
404
- return reg.schemas.get(primitiveType);
405
- }
406
- function getAllSchemas() {
407
- const reg = getTemplateRegistry();
408
- if (!reg.initialized) {
409
- initializeTemplateRegistry();
410
- }
411
- return Array.from(reg.schemas.values());
412
- }
413
- function getSchemaNames() {
414
- const reg = getTemplateRegistry();
415
- if (!reg.initialized) {
416
- initializeTemplateRegistry();
417
- }
418
- return Array.from(reg.schemas.keys());
419
- }
420
- function generateFrontmatter(primitiveType, options = {}) {
421
- const schema = getSchema(primitiveType);
422
- if (!schema) {
423
- return {
424
- type: primitiveType,
425
- created: (/* @__PURE__ */ new Date()).toISOString(),
426
- updated: (/* @__PURE__ */ new Date()).toISOString()
427
- };
428
- }
429
- const frontmatter = {};
430
- const now = /* @__PURE__ */ new Date();
431
- const dateStr = now.toISOString().split("T")[0];
432
- const datetimeStr = now.toISOString();
433
- for (const [fieldName, fieldDef] of Object.entries(schema.fields)) {
434
- if (options.extraFields?.[fieldName] !== void 0) {
435
- const value = options.extraFields[fieldName];
436
- if (fieldDef.enum && !fieldDef.enum.includes(String(value))) {
437
- frontmatter[fieldName] = fieldDef.default ?? fieldDef.enum[0];
438
- } else {
439
- frontmatter[fieldName] = value;
440
- }
441
- continue;
442
- }
443
- if (fieldDef.default !== void 0) {
444
- let defaultValue = fieldDef.default;
445
- if (typeof defaultValue === "string") {
446
- defaultValue = defaultValue.replace("{{datetime}}", datetimeStr).replace("{{date}}", dateStr).replace("{{title}}", options.title ?? "Untitled");
447
- }
448
- frontmatter[fieldName] = defaultValue;
449
- } else if (fieldDef.required) {
450
- switch (fieldDef.type) {
451
- case "datetime":
452
- frontmatter[fieldName] = datetimeStr;
453
- break;
454
- case "date":
455
- frontmatter[fieldName] = dateStr;
456
- break;
457
- case "string":
458
- if (fieldDef.enum?.length) {
459
- frontmatter[fieldName] = fieldDef.enum[0];
460
- } else {
461
- frontmatter[fieldName] = "";
462
- }
463
- break;
464
- case "number":
465
- frontmatter[fieldName] = 0;
466
- break;
467
- case "boolean":
468
- frontmatter[fieldName] = false;
469
- break;
470
- }
471
- }
472
- }
473
- if (options.source && schema.fields.source) {
474
- frontmatter.source = options.source;
475
- }
476
- if (options.sessionId && schema.fields.session_id) {
477
- frontmatter.session_id = options.sessionId;
478
- }
479
- return frontmatter;
480
- }
481
- function validateFrontmatter(primitiveType, frontmatter) {
482
- const schema = getSchema(primitiveType);
483
- if (!schema) {
484
- return { valid: true, errors: [] };
485
- }
486
- const errors = [];
487
- for (const [fieldName, fieldDef] of Object.entries(schema.fields)) {
488
- const value = frontmatter[fieldName];
489
- if (fieldDef.required && (value === void 0 || value === null || value === "")) {
490
- errors.push(`Missing required field: ${fieldName}`);
491
- continue;
492
- }
493
- if (value === void 0 || value === null) continue;
494
- if (fieldDef.enum && !fieldDef.enum.includes(String(value))) {
495
- errors.push(`Invalid value for ${fieldName}: "${value}". Must be one of: ${fieldDef.enum.join(", ")}`);
496
- }
497
- switch (fieldDef.type) {
498
- case "number":
499
- if (typeof value !== "number" && isNaN(Number(value))) {
500
- errors.push(`Field ${fieldName} must be a number`);
501
- }
502
- break;
503
- case "boolean":
504
- if (typeof value !== "boolean" && value !== "true" && value !== "false") {
505
- errors.push(`Field ${fieldName} must be a boolean`);
506
- }
507
- break;
508
- case "datetime":
509
- if (typeof value === "string" && isNaN(Date.parse(value))) {
510
- errors.push(`Field ${fieldName} must be a valid datetime`);
511
- }
512
- break;
513
- case "date":
514
- if (typeof value === "string" && !/^\d{4}-\d{2}-\d{2}$/.test(value)) {
515
- errors.push(`Field ${fieldName} must be a valid date (YYYY-MM-DD)`);
516
- }
517
- break;
518
- }
519
- }
520
- return { valid: errors.length === 0, errors };
521
- }
522
- function serializeFrontmatter(frontmatter) {
523
- const lines = ["---"];
524
- for (const [key, value] of Object.entries(frontmatter)) {
525
- if (value === void 0 || value === null) continue;
526
- if (Array.isArray(value)) {
527
- lines.push(`${key}:`);
528
- for (const item of value) {
529
- lines.push(` - ${item}`);
530
- }
531
- } else if (typeof value === "object") {
532
- lines.push(`${key}: ${JSON.stringify(value)}`);
533
- } else if (typeof value === "string" && value.includes("\n")) {
534
- lines.push(`${key}: |`);
535
- for (const line of value.split("\n")) {
536
- lines.push(` ${line}`);
537
- }
538
- } else {
539
- lines.push(`${key}: ${value}`);
540
- }
541
- }
542
- lines.push("---");
543
- return lines.join("\n");
544
- }
545
- function resetTemplateRegistry() {
546
- registry = null;
547
- }
548
-
549
- export {
550
- getTemplateRegistry,
551
- initializeTemplateRegistry,
552
- classifyText,
553
- getSchema,
554
- getAllSchemas,
555
- getSchemaNames,
556
- generateFrontmatter,
557
- validateFrontmatter,
558
- serializeFrontmatter,
559
- resetTemplateRegistry
560
- };