clawvault 2.6.0 → 3.0.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 (232) hide show
  1. package/bin/command-registration.test.js +1 -3
  2. package/bin/register-core-commands.js +10 -23
  3. package/bin/register-maintenance-commands.js +3 -20
  4. package/bin/register-query-commands.js +23 -0
  5. package/bin/register-task-commands.js +1 -18
  6. package/bin/register-task-commands.test.js +0 -16
  7. package/bin/register-vault-operations-commands.js +1 -29
  8. package/dist/{chunk-QVMXF7FY.js → chunk-3D6BCTP6.js} +39 -1
  9. package/dist/{chunk-R2MIW5G7.js → chunk-3DHXQHYG.js} +1 -1
  10. package/dist/{chunk-Q2J5YTUF.js → chunk-3NSBOUT3.js} +73 -36
  11. package/dist/chunk-3RG5ZIWI.js +10 -0
  12. package/dist/{chunk-AZYOKJYC.js → chunk-62YTUT6J.js} +2 -2
  13. package/dist/chunk-6U6MK36V.js +205 -0
  14. package/dist/{chunk-4QYGFWRM.js → chunk-7R7O6STJ.js} +4 -4
  15. package/dist/{chunk-VXEOHTSL.js → chunk-C7OK5WKP.js} +4 -4
  16. package/dist/chunk-CMB7UL7C.js +327 -0
  17. package/dist/chunk-DEFFDRVP.js +938 -0
  18. package/dist/{chunk-K3CDT7IH.js → chunk-E7MFQB6D.js} +61 -20
  19. package/dist/{chunk-ME37YNW3.js → chunk-F2JEUD4J.js} +6 -4
  20. package/dist/chunk-GAJV4IGR.js +82 -0
  21. package/dist/chunk-GQSLDZTS.js +560 -0
  22. package/dist/{chunk-4OXMU5S2.js → chunk-GUKMRGM7.js} +1 -1
  23. package/dist/{chunk-YOSEUUNB.js → chunk-H34S76MB.js} +6 -6
  24. package/dist/{chunk-4TE4JMLA.js → chunk-JY6FYXIT.js} +10 -5
  25. package/dist/chunk-K234IDRJ.js +1073 -0
  26. package/dist/{chunk-IEVLHNLU.js → chunk-LNJA2UGL.js} +86 -9
  27. package/dist/{chunk-MFAWT5O5.js → chunk-LYHGEHXG.js} +1 -0
  28. package/dist/chunk-MFM6K7PU.js +374 -0
  29. package/dist/{chunk-QWQ3TIKS.js → chunk-N2AXRYLC.js} +1 -1
  30. package/dist/chunk-PAH27GSN.js +108 -0
  31. package/dist/{chunk-OIWVQYQF.js → chunk-QBLMXKF2.js} +1 -1
  32. package/dist/{chunk-FHFUXL6G.js → chunk-QK3UCXWL.js} +2 -2
  33. package/dist/{chunk-2YDBJS7M.js → chunk-SJSFRIYS.js} +1 -1
  34. package/dist/{chunk-GSD4ALSI.js → chunk-U55BGUAU.js} +2 -2
  35. package/dist/{chunk-PBEE567J.js → chunk-VGLOTGAS.js} +1 -1
  36. package/dist/{chunk-F55HGNU4.js → chunk-WAZ3NLWL.js} +47 -0
  37. package/dist/{chunk-KL4NAOMO.js → chunk-WGRQ6HDV.js} +1 -1
  38. package/dist/{chunk-UEOUADMO.js → chunk-YKTA5JOJ.js} +13 -10
  39. package/dist/{chunk-XAVB4GB4.js → chunk-ZVVFWOLW.js} +4 -4
  40. package/dist/cli/index.cjs +10033 -0
  41. package/dist/cli/index.d.cts +5 -0
  42. package/dist/cli/index.js +20 -18
  43. package/dist/commands/archive.cjs +287 -0
  44. package/dist/commands/archive.d.cts +11 -0
  45. package/dist/commands/archive.js +1 -0
  46. package/dist/commands/backlog.cjs +721 -0
  47. package/dist/commands/backlog.d.cts +53 -0
  48. package/dist/commands/backlog.js +3 -2
  49. package/dist/commands/blocked.cjs +204 -0
  50. package/dist/commands/blocked.d.cts +26 -0
  51. package/dist/commands/blocked.js +3 -2
  52. package/dist/commands/checkpoint.cjs +244 -0
  53. package/dist/commands/checkpoint.d.cts +41 -0
  54. package/dist/commands/checkpoint.js +2 -1
  55. package/dist/commands/compat.cjs +369 -0
  56. package/dist/commands/compat.d.cts +28 -0
  57. package/dist/commands/compat.js +2 -1
  58. package/dist/commands/context.cjs +2989 -0
  59. package/dist/commands/context.d.cts +2 -0
  60. package/dist/commands/context.js +5 -4
  61. package/dist/commands/doctor.cjs +3062 -0
  62. package/dist/commands/doctor.d.cts +21 -0
  63. package/dist/commands/doctor.d.ts +6 -1
  64. package/dist/commands/doctor.js +13 -11
  65. package/dist/commands/embed.cjs +232 -0
  66. package/dist/commands/embed.d.cts +17 -0
  67. package/dist/commands/embed.js +5 -2
  68. package/dist/commands/entities.cjs +141 -0
  69. package/dist/commands/entities.d.cts +7 -0
  70. package/dist/commands/entities.js +1 -0
  71. package/dist/commands/graph.cjs +501 -0
  72. package/dist/commands/graph.d.cts +21 -0
  73. package/dist/commands/graph.js +1 -0
  74. package/dist/commands/inject.cjs +1636 -0
  75. package/dist/commands/inject.d.cts +2 -0
  76. package/dist/commands/inject.d.ts +1 -1
  77. package/dist/commands/inject.js +4 -2
  78. package/dist/commands/kanban.cjs +884 -0
  79. package/dist/commands/kanban.d.cts +63 -0
  80. package/dist/commands/kanban.js +4 -3
  81. package/dist/commands/link.cjs +965 -0
  82. package/dist/commands/link.d.cts +11 -0
  83. package/dist/commands/link.js +1 -0
  84. package/dist/commands/migrate-observations.cjs +362 -0
  85. package/dist/commands/migrate-observations.d.cts +19 -0
  86. package/dist/commands/migrate-observations.js +3 -2
  87. package/dist/commands/observe.cjs +4099 -0
  88. package/dist/commands/observe.d.cts +23 -0
  89. package/dist/commands/observe.d.ts +1 -0
  90. package/dist/commands/observe.js +11 -9
  91. package/dist/commands/project.cjs +1341 -0
  92. package/dist/commands/project.d.cts +85 -0
  93. package/dist/commands/project.js +5 -4
  94. package/dist/commands/rebuild.cjs +3136 -0
  95. package/dist/commands/rebuild.d.cts +11 -0
  96. package/dist/commands/rebuild.js +10 -8
  97. package/dist/commands/recover.cjs +361 -0
  98. package/dist/commands/recover.d.cts +38 -0
  99. package/dist/commands/recover.js +3 -2
  100. package/dist/commands/reflect.cjs +1008 -0
  101. package/dist/commands/reflect.d.cts +11 -0
  102. package/dist/commands/reflect.js +6 -4
  103. package/dist/commands/repair-session.cjs +457 -0
  104. package/dist/commands/repair-session.d.cts +38 -0
  105. package/dist/commands/repair-session.js +1 -0
  106. package/dist/commands/replay.cjs +4103 -0
  107. package/dist/commands/replay.d.cts +16 -0
  108. package/dist/commands/replay.js +12 -10
  109. package/dist/commands/session-recap.cjs +353 -0
  110. package/dist/commands/session-recap.d.cts +27 -0
  111. package/dist/commands/session-recap.js +1 -0
  112. package/dist/commands/setup.cjs +1345 -0
  113. package/dist/commands/setup.d.cts +100 -0
  114. package/dist/commands/setup.d.ts +90 -2
  115. package/dist/commands/setup.js +21 -2
  116. package/dist/commands/shell-init.cjs +75 -0
  117. package/dist/commands/shell-init.d.cts +7 -0
  118. package/dist/commands/shell-init.js +2 -0
  119. package/dist/commands/sleep.cjs +6028 -0
  120. package/dist/commands/sleep.d.cts +36 -0
  121. package/dist/commands/sleep.d.ts +1 -1
  122. package/dist/commands/sleep.js +17 -15
  123. package/dist/commands/status.cjs +2736 -0
  124. package/dist/commands/status.d.cts +52 -0
  125. package/dist/commands/status.js +12 -10
  126. package/dist/commands/tailscale.cjs +1532 -0
  127. package/dist/commands/tailscale.d.cts +52 -0
  128. package/dist/commands/tailscale.js +1 -0
  129. package/dist/commands/task.cjs +1236 -0
  130. package/dist/commands/task.d.cts +97 -0
  131. package/dist/commands/task.js +4 -3
  132. package/dist/commands/template.cjs +457 -0
  133. package/dist/commands/template.d.cts +36 -0
  134. package/dist/commands/template.js +2 -1
  135. package/dist/commands/wake.cjs +2626 -0
  136. package/dist/commands/wake.d.cts +22 -0
  137. package/dist/commands/wake.d.ts +1 -1
  138. package/dist/commands/wake.js +12 -11
  139. package/dist/context-BUGaWpyL.d.cts +46 -0
  140. package/dist/index.cjs +14526 -0
  141. package/dist/index.d.cts +858 -0
  142. package/dist/index.d.ts +192 -7
  143. package/dist/index.js +101 -75
  144. package/dist/{inject-x65KXWPk.d.ts → inject-Bzi5E-By.d.cts} +1 -1
  145. package/dist/inject-Bzi5E-By.d.ts +137 -0
  146. package/dist/lib/auto-linker.cjs +176 -0
  147. package/dist/lib/auto-linker.d.cts +26 -0
  148. package/dist/lib/auto-linker.js +1 -0
  149. package/dist/lib/canvas-layout.cjs +136 -0
  150. package/dist/lib/canvas-layout.d.cts +31 -0
  151. package/dist/lib/canvas-layout.d.ts +16 -100
  152. package/dist/lib/canvas-layout.js +78 -20
  153. package/dist/lib/config.cjs +78 -0
  154. package/dist/lib/config.d.cts +11 -0
  155. package/dist/lib/config.js +1 -0
  156. package/dist/lib/entity-index.cjs +84 -0
  157. package/dist/lib/entity-index.d.cts +26 -0
  158. package/dist/lib/entity-index.js +1 -0
  159. package/dist/lib/project-utils.cjs +864 -0
  160. package/dist/lib/project-utils.d.cts +97 -0
  161. package/dist/lib/project-utils.js +4 -3
  162. package/dist/lib/session-repair.cjs +239 -0
  163. package/dist/lib/session-repair.d.cts +110 -0
  164. package/dist/lib/session-repair.js +1 -0
  165. package/dist/lib/session-utils.cjs +209 -0
  166. package/dist/lib/session-utils.d.cts +63 -0
  167. package/dist/lib/session-utils.js +1 -0
  168. package/dist/lib/tailscale.cjs +1183 -0
  169. package/dist/lib/tailscale.d.cts +225 -0
  170. package/dist/lib/tailscale.js +1 -0
  171. package/dist/lib/task-utils.cjs +1137 -0
  172. package/dist/lib/task-utils.d.cts +208 -0
  173. package/dist/lib/task-utils.js +3 -2
  174. package/dist/lib/template-engine.cjs +47 -0
  175. package/dist/lib/template-engine.d.cts +11 -0
  176. package/dist/lib/template-engine.js +1 -0
  177. package/dist/lib/webdav.cjs +568 -0
  178. package/dist/lib/webdav.d.cts +109 -0
  179. package/dist/lib/webdav.js +1 -0
  180. package/dist/plugin/index.cjs +1907 -0
  181. package/dist/plugin/index.d.cts +36 -0
  182. package/dist/plugin/index.d.ts +36 -0
  183. package/dist/plugin/index.js +572 -0
  184. package/dist/plugin/inject.cjs +356 -0
  185. package/dist/plugin/inject.d.cts +54 -0
  186. package/dist/plugin/inject.d.ts +54 -0
  187. package/dist/plugin/inject.js +17 -0
  188. package/dist/plugin/observe.cjs +631 -0
  189. package/dist/plugin/observe.d.cts +39 -0
  190. package/dist/plugin/observe.d.ts +39 -0
  191. package/dist/plugin/observe.js +18 -0
  192. package/dist/plugin/templates.cjs +593 -0
  193. package/dist/plugin/templates.d.cts +52 -0
  194. package/dist/plugin/templates.d.ts +52 -0
  195. package/dist/plugin/templates.js +25 -0
  196. package/dist/plugin/types.cjs +18 -0
  197. package/dist/plugin/types.d.cts +209 -0
  198. package/dist/plugin/types.d.ts +209 -0
  199. package/dist/plugin/types.js +0 -0
  200. package/dist/plugin/vault.cjs +927 -0
  201. package/dist/plugin/vault.d.cts +68 -0
  202. package/dist/plugin/vault.d.ts +68 -0
  203. package/dist/plugin/vault.js +22 -0
  204. package/dist/{types-C74wgGL1.d.ts → types-Y2_Um2Ls.d.cts} +44 -1
  205. package/dist/types-Y2_Um2Ls.d.ts +205 -0
  206. package/hooks/clawvault/handler.js +70 -7
  207. package/hooks/clawvault/handler.test.js +91 -0
  208. package/openclaw.plugin.json +56 -0
  209. package/package.json +17 -7
  210. package/templates/memory-event.md +67 -0
  211. package/templates/party.md +63 -0
  212. package/templates/primitive-registry.yaml +551 -0
  213. package/templates/run.md +68 -0
  214. package/templates/trigger.md +68 -0
  215. package/templates/workspace.md +50 -0
  216. package/dashboard/lib/graph-diff.js +0 -104
  217. package/dashboard/lib/graph-diff.test.js +0 -75
  218. package/dashboard/lib/vault-parser.js +0 -556
  219. package/dashboard/lib/vault-parser.test.js +0 -254
  220. package/dashboard/public/app.js +0 -796
  221. package/dashboard/public/index.html +0 -52
  222. package/dashboard/public/styles.css +0 -221
  223. package/dashboard/server.js +0 -374
  224. package/dist/chunk-HA5M6KJB.js +0 -33
  225. package/dist/chunk-MAKNAHAW.js +0 -375
  226. package/dist/chunk-MDIH26GC.js +0 -183
  227. package/dist/chunk-MGDEINGP.js +0 -99
  228. package/dist/chunk-RVYA52PY.js +0 -363
  229. package/dist/commands/canvas.d.ts +0 -15
  230. package/dist/commands/canvas.js +0 -199
  231. package/dist/commands/sync-bd.d.ts +0 -10
  232. package/dist/commands/sync-bd.js +0 -9
@@ -0,0 +1,927 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/plugin/vault.ts
21
+ var vault_exports = {};
22
+ __export(vault_exports, {
23
+ appendObservationToLedger: () => appendObservationToLedger,
24
+ appendToLedger: () => appendToLedger,
25
+ batchWriteObservations: () => batchWriteObservations,
26
+ ensureVaultStructure: () => ensureVaultStructure,
27
+ getVaultStats: () => getVaultStats,
28
+ writeObservation: () => writeObservation,
29
+ writeObservations: () => writeObservations,
30
+ writeVaultFile: () => writeVaultFile
31
+ });
32
+ module.exports = __toCommonJS(vault_exports);
33
+ var import_node_fs2 = require("fs");
34
+ var import_node_path2 = require("path");
35
+
36
+ // src/plugin/templates.ts
37
+ var import_node_fs = require("fs");
38
+ var import_node_path = require("path");
39
+ var DEFAULT_SCHEMAS = [
40
+ {
41
+ primitive: "memory_event",
42
+ description: "General memory event for observations",
43
+ fields: {
44
+ type: { type: "string", required: true, default: "memory_event" },
45
+ status: { type: "string", required: true, default: "recorded", enum: ["recorded", "superseded", "corrected"] },
46
+ created: { type: "datetime", required: true, default: "{{datetime}}" },
47
+ observed_at: { type: "datetime", required: true },
48
+ source: { type: "string", required: true, enum: ["openclaw", "claude-code", "replay", "manual-correction"] },
49
+ summary: { type: "string", required: true },
50
+ confidence: { type: "number" },
51
+ importance: { type: "number" }
52
+ },
53
+ keywords: ["preference", "like", "hate", "want", "need", "always", "never", "remember", "note"]
54
+ },
55
+ {
56
+ primitive: "person",
57
+ description: "People and relationship notes",
58
+ fields: {
59
+ title: { type: "string", required: true, default: "{{title}}" },
60
+ date: { type: "date", required: true, default: "{{date}}" },
61
+ type: { type: "string", required: true, default: "person" },
62
+ relationship: { type: "string", default: "contact" }
63
+ },
64
+ keywords: ["person", "contact", "colleague", "friend", "works at", "lives in", "email", "phone", "name is"]
65
+ },
66
+ {
67
+ primitive: "decision",
68
+ description: "Decision records",
69
+ fields: {
70
+ title: { type: "string", required: true, default: "{{title}}" },
71
+ date: { type: "date", required: true, default: "{{date}}" },
72
+ type: { type: "string", required: true, default: "decision" },
73
+ status: { type: "string", default: "decided", enum: ["proposed", "decided", "superseded"] }
74
+ },
75
+ keywords: ["decided", "decision", "chose", "will use", "go with", "ship", "approved", "rejected"]
76
+ },
77
+ {
78
+ primitive: "task",
79
+ description: "Task primitives",
80
+ fields: {
81
+ status: { type: "string", required: true, default: "open", enum: ["open", "in-progress", "blocked", "done"] },
82
+ created: { type: "datetime", required: true, default: "{{datetime}}" },
83
+ updated: { type: "datetime", required: true, default: "{{datetime}}" },
84
+ priority: { type: "string", enum: ["critical", "high", "medium", "low"] },
85
+ due: { type: "date" }
86
+ },
87
+ keywords: ["task", "todo", "need to", "should", "must", "deadline", "due", "by tomorrow", "by tonight"]
88
+ },
89
+ {
90
+ primitive: "project",
91
+ description: "Project definition documents",
92
+ fields: {
93
+ type: { type: "string", required: true, default: "project" },
94
+ status: { type: "string", required: true, default: "active", enum: ["active", "paused", "completed", "archived"] },
95
+ created: { type: "datetime", required: true, default: "{{datetime}}" },
96
+ updated: { type: "datetime", required: true, default: "{{datetime}}" }
97
+ },
98
+ keywords: ["project", "initiative", "working on", "building", "developing"]
99
+ },
100
+ {
101
+ primitive: "lesson",
102
+ description: "Lessons learned",
103
+ fields: {
104
+ title: { type: "string", required: true, default: "{{title}}" },
105
+ date: { type: "date", required: true, default: "{{date}}" },
106
+ type: { type: "string", required: true, default: "lesson" }
107
+ },
108
+ keywords: ["learned", "lesson", "insight", "realized", "discovered", "found out"]
109
+ }
110
+ ];
111
+ function parseYamlFrontmatter(content) {
112
+ const match = content.match(/^---\n([\s\S]*?)\n---\n?([\s\S]*)$/);
113
+ if (!match) return null;
114
+ const yamlContent = match[1];
115
+ const body = match[2];
116
+ try {
117
+ const frontmatter = parseSimpleYaml(yamlContent);
118
+ return { frontmatter, body };
119
+ } catch {
120
+ return null;
121
+ }
122
+ }
123
+ function parseSimpleYaml(yaml) {
124
+ const result = {};
125
+ const lines = yaml.split("\n");
126
+ let currentKey = "";
127
+ let currentIndent = 0;
128
+ let nestedObject = null;
129
+ let nestedKey = "";
130
+ for (const line of lines) {
131
+ if (!line.trim() || line.trim().startsWith("#")) continue;
132
+ const indent = line.search(/\S/);
133
+ const trimmed = line.trim();
134
+ if (trimmed.startsWith("- ")) {
135
+ const value = trimmed.slice(2).trim();
136
+ if (nestedObject && nestedKey) {
137
+ const arr = nestedObject[nestedKey];
138
+ if (Array.isArray(arr)) {
139
+ arr.push(parseYamlValue(value));
140
+ }
141
+ } else if (currentKey && result[currentKey]) {
142
+ const arr = result[currentKey];
143
+ if (Array.isArray(arr)) {
144
+ arr.push(parseYamlValue(value));
145
+ }
146
+ }
147
+ continue;
148
+ }
149
+ const colonIndex = trimmed.indexOf(":");
150
+ if (colonIndex === -1) continue;
151
+ const key = trimmed.slice(0, colonIndex).trim();
152
+ const valueStr = trimmed.slice(colonIndex + 1).trim();
153
+ if (indent === 0) {
154
+ if (valueStr === "" || valueStr === "|" || valueStr === ">") {
155
+ if (key === "fields") {
156
+ result[key] = {};
157
+ nestedObject = result[key];
158
+ nestedKey = "";
159
+ } else {
160
+ result[key] = {};
161
+ nestedObject = null;
162
+ }
163
+ } else {
164
+ result[key] = parseYamlValue(valueStr);
165
+ nestedObject = null;
166
+ }
167
+ currentKey = key;
168
+ currentIndent = indent;
169
+ } else if (nestedObject && indent > 0) {
170
+ if (valueStr === "" || valueStr === "|" || valueStr === ">") {
171
+ nestedObject[key] = {};
172
+ nestedKey = key;
173
+ } else if (nestedKey && indent > 2) {
174
+ const fieldObj = nestedObject[nestedKey];
175
+ if (fieldObj) {
176
+ if (key === "enum") {
177
+ fieldObj[key] = [];
178
+ } else {
179
+ fieldObj[key] = parseYamlValue(valueStr);
180
+ }
181
+ }
182
+ } else {
183
+ nestedObject[key] = parseYamlValue(valueStr);
184
+ nestedKey = key;
185
+ }
186
+ }
187
+ }
188
+ return result;
189
+ }
190
+ function parseYamlValue(value) {
191
+ if (value === "" || value === "null" || value === "~") return null;
192
+ if (value === "true") return true;
193
+ if (value === "false") return false;
194
+ if (/^-?\d+$/.test(value)) return parseInt(value, 10);
195
+ if (/^-?\d+\.\d+$/.test(value)) return parseFloat(value);
196
+ if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) {
197
+ return value.slice(1, -1);
198
+ }
199
+ return value;
200
+ }
201
+ var registry = null;
202
+ function getTemplateRegistry() {
203
+ if (!registry) {
204
+ registry = {
205
+ schemas: /* @__PURE__ */ new Map(),
206
+ keywordIndex: /* @__PURE__ */ new Map(),
207
+ initialized: false
208
+ };
209
+ }
210
+ return registry;
211
+ }
212
+ function initializeTemplateRegistry(templatesDir) {
213
+ const reg = getTemplateRegistry();
214
+ if (reg.initialized) {
215
+ return reg;
216
+ }
217
+ const dirsToTry = templatesDir ? [templatesDir] : [
218
+ (0, import_node_path.join)(process.cwd(), "templates"),
219
+ (0, import_node_path.join)(process.cwd(), "..", "..", "templates"),
220
+ (0, import_node_path.join)(process.env.HOME ?? ".", "clawvault", "templates"),
221
+ (0, import_node_path.join)(process.env.HOME ?? ".", ".clawvault", "templates")
222
+ ];
223
+ let loaded = false;
224
+ for (const dir of dirsToTry) {
225
+ if ((0, import_node_fs.existsSync)(dir)) {
226
+ try {
227
+ loadTemplatesFromDirectory(dir, reg);
228
+ loaded = true;
229
+ break;
230
+ } catch {
231
+ }
232
+ }
233
+ }
234
+ if (!loaded || reg.schemas.size === 0) {
235
+ loadDefaultSchemas(reg);
236
+ }
237
+ buildKeywordIndex(reg);
238
+ reg.initialized = true;
239
+ return reg;
240
+ }
241
+ function loadTemplatesFromDirectory(dir, reg) {
242
+ const files = (0, import_node_fs.readdirSync)(dir).filter((f) => f.endsWith(".md"));
243
+ for (const file of files) {
244
+ const filePath = (0, import_node_path.join)(dir, file);
245
+ const content = (0, import_node_fs.readFileSync)(filePath, "utf-8");
246
+ const parsed = parseYamlFrontmatter(content);
247
+ if (!parsed?.frontmatter?.primitive) continue;
248
+ const schema = convertFrontmatterToSchema(parsed.frontmatter, parsed.body);
249
+ if (schema) {
250
+ reg.schemas.set(schema.primitive, schema);
251
+ }
252
+ }
253
+ }
254
+ function convertFrontmatterToSchema(fm, body) {
255
+ const primitive = fm.primitive;
256
+ if (!primitive) return null;
257
+ const fields = {};
258
+ const fmFields = fm.fields;
259
+ if (fmFields) {
260
+ for (const [fieldName, fieldDef] of Object.entries(fmFields)) {
261
+ if (typeof fieldDef === "object" && fieldDef !== null) {
262
+ const def = fieldDef;
263
+ fields[fieldName] = {
264
+ type: def.type || "string",
265
+ required: def.required,
266
+ default: def.default,
267
+ enum: def.enum,
268
+ description: def.description
269
+ };
270
+ }
271
+ }
272
+ }
273
+ const keywords = extractKeywordsFromSchema(primitive, fm.description, fields);
274
+ return {
275
+ primitive,
276
+ description: fm.description,
277
+ fields,
278
+ bodyTemplate: body,
279
+ keywords
280
+ };
281
+ }
282
+ function extractKeywordsFromSchema(primitive, description, fields) {
283
+ const keywords = [primitive];
284
+ keywords.push(primitive.replace(/-/g, " "));
285
+ keywords.push(primitive.replace(/_/g, " "));
286
+ switch (primitive) {
287
+ case "memory_event":
288
+ keywords.push("preference", "like", "hate", "want", "need", "always", "never", "remember", "note");
289
+ break;
290
+ case "person":
291
+ keywords.push("person", "contact", "colleague", "friend", "works at", "lives in", "email", "phone", "name is");
292
+ break;
293
+ case "decision":
294
+ keywords.push("decided", "decision", "chose", "will use", "go with", "ship", "approved", "rejected");
295
+ break;
296
+ case "task":
297
+ keywords.push("task", "todo", "need to", "should", "must", "deadline", "due", "by tomorrow", "by tonight");
298
+ break;
299
+ case "project":
300
+ keywords.push("project", "initiative", "working on", "building", "developing");
301
+ break;
302
+ case "lesson":
303
+ keywords.push("learned", "lesson", "insight", "realized", "discovered", "found out");
304
+ break;
305
+ case "trigger":
306
+ keywords.push("trigger", "schedule", "cron", "automated", "recurring");
307
+ break;
308
+ case "run":
309
+ keywords.push("run", "execution", "job", "started", "finished", "failed");
310
+ break;
311
+ case "checkpoint":
312
+ keywords.push("checkpoint", "snapshot", "state", "progress");
313
+ break;
314
+ case "handoff":
315
+ keywords.push("handoff", "transition", "context", "resume");
316
+ break;
317
+ case "daily-note":
318
+ case "daily":
319
+ keywords.push("daily", "today", "journal", "log");
320
+ break;
321
+ case "party":
322
+ keywords.push("party", "agent", "human", "runtime", "service");
323
+ break;
324
+ case "workspace":
325
+ keywords.push("workspace", "shared", "collaboration");
326
+ break;
327
+ }
328
+ if (fields.status?.enum) {
329
+ keywords.push(...fields.status.enum);
330
+ }
331
+ return [...new Set(keywords)];
332
+ }
333
+ function loadDefaultSchemas(reg) {
334
+ for (const schema of DEFAULT_SCHEMAS) {
335
+ reg.schemas.set(schema.primitive, schema);
336
+ }
337
+ }
338
+ function buildKeywordIndex(reg) {
339
+ reg.keywordIndex.clear();
340
+ for (const [primitive, schema] of reg.schemas) {
341
+ const keywords = schema.keywords ?? [primitive];
342
+ for (const keyword of keywords) {
343
+ const lower = keyword.toLowerCase();
344
+ const existing = reg.keywordIndex.get(lower) ?? [];
345
+ if (!existing.includes(primitive)) {
346
+ existing.push(primitive);
347
+ }
348
+ reg.keywordIndex.set(lower, existing);
349
+ }
350
+ }
351
+ }
352
+ function classifyText(text) {
353
+ const reg = getTemplateRegistry();
354
+ if (!reg.initialized) {
355
+ initializeTemplateRegistry();
356
+ }
357
+ const lower = text.toLowerCase();
358
+ const scores = /* @__PURE__ */ new Map();
359
+ for (const [keyword, primitives] of reg.keywordIndex) {
360
+ if (lower.includes(keyword)) {
361
+ for (const primitive of primitives) {
362
+ const existing = scores.get(primitive) ?? { score: 0, keywords: [] };
363
+ existing.score += getKeywordWeight(keyword, primitive);
364
+ existing.keywords.push(keyword);
365
+ scores.set(primitive, existing);
366
+ }
367
+ }
368
+ }
369
+ applyPatternScoring(lower, scores);
370
+ let bestPrimitive = "memory_event";
371
+ let bestScore = 0;
372
+ let bestKeywords = [];
373
+ for (const [primitive, data] of scores) {
374
+ if (data.score > bestScore) {
375
+ bestScore = data.score;
376
+ bestPrimitive = primitive;
377
+ bestKeywords = data.keywords;
378
+ }
379
+ }
380
+ const confidence = Math.min(1, bestScore / 5);
381
+ return {
382
+ primitiveType: bestPrimitive,
383
+ confidence,
384
+ matchedKeywords: [...new Set(bestKeywords)]
385
+ };
386
+ }
387
+ function getKeywordWeight(keyword, primitive) {
388
+ if (keyword === primitive || keyword === primitive.replace(/-/g, " ")) {
389
+ return 3;
390
+ }
391
+ const strongIndicators = {
392
+ person: ["works at", "lives in", "email", "phone", "name is"],
393
+ decision: ["decided", "chose", "will use", "go with"],
394
+ task: ["deadline", "due", "by tomorrow", "by tonight"],
395
+ memory_event: ["preference", "remember", "note"]
396
+ };
397
+ if (strongIndicators[primitive]?.includes(keyword)) {
398
+ return 2;
399
+ }
400
+ return 1;
401
+ }
402
+ function applyPatternScoring(text, scores) {
403
+ if (/\b(my .+ is|his .+ is|her .+ is|their .+ is)\b/i.test(text)) {
404
+ const existing = scores.get("person") ?? { score: 0, keywords: [] };
405
+ existing.score += 2;
406
+ existing.keywords.push("possessive pattern");
407
+ scores.set("person", existing);
408
+ }
409
+ if (/[\w.-]+@[\w.-]+\.\w+|\+\d{10,}/.test(text)) {
410
+ const existing = scores.get("person") ?? { score: 0, keywords: [] };
411
+ existing.score += 3;
412
+ existing.keywords.push("contact info");
413
+ scores.set("person", existing);
414
+ }
415
+ 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)) {
416
+ const existing = scores.get("memory_event") ?? { score: 0, keywords: [] };
417
+ existing.score += 3;
418
+ existing.keywords.push("preference pattern");
419
+ scores.set("memory_event", existing);
420
+ }
421
+ if (/\b(we decided|let's go with|we're going|i chose|we'll use|ship it|do it)\b/i.test(text)) {
422
+ const existing = scores.get("decision") ?? { score: 0, keywords: [] };
423
+ existing.score += 3;
424
+ existing.keywords.push("decision pattern");
425
+ scores.set("decision", existing);
426
+ }
427
+ if (/\b(by tonight|by tomorrow|deadline|due date|by end of|ship by|ready by)\b/i.test(text)) {
428
+ const existing = scores.get("task") ?? { score: 0, keywords: [] };
429
+ existing.score += 2;
430
+ existing.keywords.push("deadline pattern");
431
+ scores.set("task", existing);
432
+ }
433
+ }
434
+ function getSchema(primitiveType) {
435
+ const reg = getTemplateRegistry();
436
+ if (!reg.initialized) {
437
+ initializeTemplateRegistry();
438
+ }
439
+ return reg.schemas.get(primitiveType);
440
+ }
441
+ function generateFrontmatter(primitiveType, options = {}) {
442
+ const schema = getSchema(primitiveType);
443
+ if (!schema) {
444
+ return {
445
+ type: primitiveType,
446
+ created: (/* @__PURE__ */ new Date()).toISOString(),
447
+ updated: (/* @__PURE__ */ new Date()).toISOString()
448
+ };
449
+ }
450
+ const frontmatter = {};
451
+ const now = /* @__PURE__ */ new Date();
452
+ const dateStr = now.toISOString().split("T")[0];
453
+ const datetimeStr = now.toISOString();
454
+ for (const [fieldName, fieldDef] of Object.entries(schema.fields)) {
455
+ if (options.extraFields?.[fieldName] !== void 0) {
456
+ const value = options.extraFields[fieldName];
457
+ if (fieldDef.enum && !fieldDef.enum.includes(String(value))) {
458
+ frontmatter[fieldName] = fieldDef.default ?? fieldDef.enum[0];
459
+ } else {
460
+ frontmatter[fieldName] = value;
461
+ }
462
+ continue;
463
+ }
464
+ if (fieldDef.default !== void 0) {
465
+ let defaultValue = fieldDef.default;
466
+ if (typeof defaultValue === "string") {
467
+ defaultValue = defaultValue.replace("{{datetime}}", datetimeStr).replace("{{date}}", dateStr).replace("{{title}}", options.title ?? "Untitled");
468
+ }
469
+ frontmatter[fieldName] = defaultValue;
470
+ } else if (fieldDef.required) {
471
+ switch (fieldDef.type) {
472
+ case "datetime":
473
+ frontmatter[fieldName] = datetimeStr;
474
+ break;
475
+ case "date":
476
+ frontmatter[fieldName] = dateStr;
477
+ break;
478
+ case "string":
479
+ if (fieldDef.enum?.length) {
480
+ frontmatter[fieldName] = fieldDef.enum[0];
481
+ } else {
482
+ frontmatter[fieldName] = "";
483
+ }
484
+ break;
485
+ case "number":
486
+ frontmatter[fieldName] = 0;
487
+ break;
488
+ case "boolean":
489
+ frontmatter[fieldName] = false;
490
+ break;
491
+ }
492
+ }
493
+ }
494
+ if (options.source && schema.fields.source) {
495
+ frontmatter.source = options.source;
496
+ }
497
+ if (options.sessionId && schema.fields.session_id) {
498
+ frontmatter.session_id = options.sessionId;
499
+ }
500
+ return frontmatter;
501
+ }
502
+ function validateFrontmatter(primitiveType, frontmatter) {
503
+ const schema = getSchema(primitiveType);
504
+ if (!schema) {
505
+ return { valid: true, errors: [] };
506
+ }
507
+ const errors = [];
508
+ for (const [fieldName, fieldDef] of Object.entries(schema.fields)) {
509
+ const value = frontmatter[fieldName];
510
+ if (fieldDef.required && (value === void 0 || value === null || value === "")) {
511
+ errors.push(`Missing required field: ${fieldName}`);
512
+ continue;
513
+ }
514
+ if (value === void 0 || value === null) continue;
515
+ if (fieldDef.enum && !fieldDef.enum.includes(String(value))) {
516
+ errors.push(`Invalid value for ${fieldName}: "${value}". Must be one of: ${fieldDef.enum.join(", ")}`);
517
+ }
518
+ switch (fieldDef.type) {
519
+ case "number":
520
+ if (typeof value !== "number" && isNaN(Number(value))) {
521
+ errors.push(`Field ${fieldName} must be a number`);
522
+ }
523
+ break;
524
+ case "boolean":
525
+ if (typeof value !== "boolean" && value !== "true" && value !== "false") {
526
+ errors.push(`Field ${fieldName} must be a boolean`);
527
+ }
528
+ break;
529
+ case "datetime":
530
+ if (typeof value === "string" && isNaN(Date.parse(value))) {
531
+ errors.push(`Field ${fieldName} must be a valid datetime`);
532
+ }
533
+ break;
534
+ case "date":
535
+ if (typeof value === "string" && !/^\d{4}-\d{2}-\d{2}$/.test(value)) {
536
+ errors.push(`Field ${fieldName} must be a valid date (YYYY-MM-DD)`);
537
+ }
538
+ break;
539
+ }
540
+ }
541
+ return { valid: errors.length === 0, errors };
542
+ }
543
+ function serializeFrontmatter(frontmatter) {
544
+ const lines = ["---"];
545
+ for (const [key, value] of Object.entries(frontmatter)) {
546
+ if (value === void 0 || value === null) continue;
547
+ if (Array.isArray(value)) {
548
+ lines.push(`${key}:`);
549
+ for (const item of value) {
550
+ lines.push(` - ${item}`);
551
+ }
552
+ } else if (typeof value === "object") {
553
+ lines.push(`${key}: ${JSON.stringify(value)}`);
554
+ } else if (typeof value === "string" && value.includes("\n")) {
555
+ lines.push(`${key}: |`);
556
+ for (const line of value.split("\n")) {
557
+ lines.push(` ${line}`);
558
+ }
559
+ } else {
560
+ lines.push(`${key}: ${value}`);
561
+ }
562
+ }
563
+ lines.push("---");
564
+ return lines.join("\n");
565
+ }
566
+
567
+ // src/plugin/vault.ts
568
+ function writeVaultFile(vaultPath, options) {
569
+ const errors = [];
570
+ const primitiveType = options.primitiveType ?? classifyText(options.content ?? options.title ?? "").primitiveType;
571
+ const schema = getSchema(primitiveType);
572
+ const frontmatter = generateFrontmatter(primitiveType, {
573
+ title: options.title,
574
+ extraFields: options.extraFields,
575
+ source: options.source,
576
+ sessionId: options.sessionId
577
+ });
578
+ const validation = validateFrontmatter(primitiveType, frontmatter);
579
+ if (!validation.valid) {
580
+ errors.push(...validation.errors);
581
+ }
582
+ const directory = options.directory ?? getDefaultDirectory(vaultPath, primitiveType);
583
+ if (!(0, import_node_fs2.existsSync)(directory)) {
584
+ (0, import_node_fs2.mkdirSync)(directory, { recursive: true });
585
+ }
586
+ const filename = options.filename ?? generateFilename(primitiveType, options.title, frontmatter);
587
+ const filePath = (0, import_node_path2.join)(directory, filename);
588
+ const fileExists = (0, import_node_fs2.existsSync)(filePath);
589
+ if (fileExists && !options.overwrite) {
590
+ return updateVaultFile(filePath, frontmatter, options.content, primitiveType, errors);
591
+ }
592
+ const fileContent = buildFileContent(frontmatter, options.content, schema);
593
+ try {
594
+ (0, import_node_fs2.writeFileSync)(filePath, fileContent, "utf-8");
595
+ return {
596
+ success: errors.length === 0,
597
+ path: filePath,
598
+ primitiveType,
599
+ errors,
600
+ created: true,
601
+ updated: false
602
+ };
603
+ } catch (err) {
604
+ errors.push(`Failed to write file: ${String(err)}`);
605
+ return {
606
+ success: false,
607
+ path: filePath,
608
+ primitiveType,
609
+ errors,
610
+ created: false,
611
+ updated: false
612
+ };
613
+ }
614
+ }
615
+ function updateVaultFile(filePath, newFrontmatter, newContent, primitiveType, errors) {
616
+ try {
617
+ const existingContent = (0, import_node_fs2.readFileSync)(filePath, "utf-8");
618
+ const parsed = parseExistingFile(existingContent);
619
+ if (!parsed) {
620
+ errors.push("Failed to parse existing file");
621
+ return {
622
+ success: false,
623
+ path: filePath,
624
+ primitiveType,
625
+ errors,
626
+ created: false,
627
+ updated: false
628
+ };
629
+ }
630
+ const mergedFrontmatter = {
631
+ ...parsed.frontmatter,
632
+ ...newFrontmatter,
633
+ updated: (/* @__PURE__ */ new Date()).toISOString()
634
+ };
635
+ if (parsed.frontmatter.created) {
636
+ mergedFrontmatter.created = parsed.frontmatter.created;
637
+ }
638
+ const content = newContent ?? parsed.body;
639
+ const schema = getSchema(primitiveType);
640
+ const fileContent = buildFileContent(mergedFrontmatter, content, schema);
641
+ (0, import_node_fs2.writeFileSync)(filePath, fileContent, "utf-8");
642
+ return {
643
+ success: errors.length === 0,
644
+ path: filePath,
645
+ primitiveType,
646
+ errors,
647
+ created: false,
648
+ updated: true
649
+ };
650
+ } catch (err) {
651
+ errors.push(`Failed to update file: ${String(err)}`);
652
+ return {
653
+ success: false,
654
+ path: filePath,
655
+ primitiveType,
656
+ errors,
657
+ created: false,
658
+ updated: false
659
+ };
660
+ }
661
+ }
662
+ function parseExistingFile(content) {
663
+ const match = content.match(/^---\n([\s\S]*?)\n---\n?([\s\S]*)$/);
664
+ if (!match) return null;
665
+ try {
666
+ const frontmatter = parseSimpleYaml2(match[1]);
667
+ return { frontmatter, body: match[2] };
668
+ } catch {
669
+ return null;
670
+ }
671
+ }
672
+ function parseSimpleYaml2(yaml) {
673
+ const result = {};
674
+ const lines = yaml.split("\n");
675
+ for (const line of lines) {
676
+ if (!line.trim() || line.trim().startsWith("#")) continue;
677
+ const colonIndex = line.indexOf(":");
678
+ if (colonIndex === -1) continue;
679
+ const key = line.slice(0, colonIndex).trim();
680
+ const valueStr = line.slice(colonIndex + 1).trim();
681
+ if (valueStr === "" || valueStr.startsWith("|") || valueStr.startsWith(">")) continue;
682
+ result[key] = parseYamlValue2(valueStr);
683
+ }
684
+ return result;
685
+ }
686
+ function parseYamlValue2(value) {
687
+ if (value === "" || value === "null" || value === "~") return null;
688
+ if (value === "true") return true;
689
+ if (value === "false") return false;
690
+ if (/^-?\d+$/.test(value)) return parseInt(value, 10);
691
+ if (/^-?\d+\.\d+$/.test(value)) return parseFloat(value);
692
+ if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) {
693
+ return value.slice(1, -1);
694
+ }
695
+ return value;
696
+ }
697
+ function getDefaultDirectory(vaultPath, primitiveType) {
698
+ const directoryMap = {
699
+ task: "tasks",
700
+ project: "projects",
701
+ decision: "decisions",
702
+ person: "people",
703
+ lesson: "lessons",
704
+ trigger: "triggers",
705
+ run: "runs",
706
+ checkpoint: "checkpoints",
707
+ handoff: "handoffs",
708
+ "daily-note": "daily",
709
+ daily: "daily",
710
+ party: "parties",
711
+ workspace: "workspaces",
712
+ memory_event: "memory"
713
+ };
714
+ const subdir = directoryMap[primitiveType] ?? "notes";
715
+ return (0, import_node_path2.join)(vaultPath, subdir);
716
+ }
717
+ function generateFilename(primitiveType, title, frontmatter) {
718
+ const now = /* @__PURE__ */ new Date();
719
+ const dateStr = now.toISOString().split("T")[0];
720
+ const timeStr = now.toISOString().slice(11, 19).replace(/:/g, "");
721
+ if (title) {
722
+ const slug = slugify(title);
723
+ return `${dateStr}-${slug}.md`;
724
+ }
725
+ switch (primitiveType) {
726
+ case "daily-note":
727
+ case "daily":
728
+ return `${dateStr}.md`;
729
+ case "memory_event":
730
+ return `${dateStr}-${timeStr}.md`;
731
+ case "run":
732
+ return `run-${dateStr}-${timeStr}.md`;
733
+ case "checkpoint":
734
+ return `checkpoint-${dateStr}-${timeStr}.md`;
735
+ case "handoff":
736
+ return `handoff-${dateStr}-${timeStr}.md`;
737
+ default:
738
+ return `${primitiveType}-${dateStr}-${timeStr}.md`;
739
+ }
740
+ }
741
+ function slugify(text) {
742
+ return text.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 50);
743
+ }
744
+ function buildFileContent(frontmatter, content, schema) {
745
+ const parts = [];
746
+ parts.push(serializeFrontmatter(frontmatter));
747
+ parts.push("");
748
+ const title = frontmatter.title || frontmatter.summary;
749
+ if (title) {
750
+ parts.push(`# ${title}`);
751
+ parts.push("");
752
+ }
753
+ if (content) {
754
+ parts.push(content);
755
+ } else if (schema?.bodyTemplate) {
756
+ let body = schema.bodyTemplate;
757
+ body = body.replace(/\{\{title\}\}/g, String(title || "Untitled"));
758
+ body = body.replace(/\{\{date\}\}/g, (/* @__PURE__ */ new Date()).toISOString().split("T")[0]);
759
+ body = body.replace(/\{\{datetime\}\}/g, (/* @__PURE__ */ new Date()).toISOString());
760
+ body = body.replace(/\{\{links_line\}\}/g, "");
761
+ body = body.replace(/\{\{content\}\}/g, "");
762
+ parts.push(body.trim());
763
+ }
764
+ return parts.join("\n");
765
+ }
766
+ function writeObservation(vaultPath, observation, options = {}) {
767
+ return writeVaultFile(vaultPath, {
768
+ primitiveType: observation.primitiveType,
769
+ title: observation.text.slice(0, 80),
770
+ content: observation.text,
771
+ extraFields: {
772
+ type: observation.primitiveType === "memory_event" ? observation.category : observation.primitiveType,
773
+ confidence: observation.confidence,
774
+ tags: observation.tags,
775
+ observed_at: observation.extractedAt.toISOString()
776
+ },
777
+ source: options.source ?? "openclaw",
778
+ sessionId: options.sessionId
779
+ });
780
+ }
781
+ function writeObservations(vaultPath, observations, options = {}) {
782
+ return observations.map((obs) => writeObservation(vaultPath, obs, options));
783
+ }
784
+ function appendToLedger(vaultPath, entry) {
785
+ const dateStr = entry.timestamp.toISOString().slice(0, 10);
786
+ const ledgerDir = (0, import_node_path2.join)(vaultPath, "ledger");
787
+ if (!(0, import_node_fs2.existsSync)(ledgerDir)) {
788
+ (0, import_node_fs2.mkdirSync)(ledgerDir, { recursive: true });
789
+ }
790
+ const ledgerFile = (0, import_node_path2.join)(ledgerDir, `${dateStr}.md`);
791
+ const timeStr = entry.timestamp.toISOString().slice(11, 19);
792
+ const parts = [`[${timeStr}]`];
793
+ if (entry.category) parts.push(`[${entry.category}]`);
794
+ if (entry.actor) parts.push(`(${entry.actor})`);
795
+ parts.push(entry.content);
796
+ const line = `
797
+ - ${parts.join(" ")}`;
798
+ if (!(0, import_node_fs2.existsSync)(ledgerFile)) {
799
+ const frontmatter = serializeFrontmatter({
800
+ type: "ledger",
801
+ date: dateStr,
802
+ created: entry.timestamp.toISOString()
803
+ });
804
+ (0, import_node_fs2.writeFileSync)(ledgerFile, `${frontmatter}
805
+
806
+ # Observation Ledger \u2014 ${dateStr}
807
+ ${line}`, "utf-8");
808
+ } else {
809
+ (0, import_node_fs2.appendFileSync)(ledgerFile, line, "utf-8");
810
+ }
811
+ }
812
+ function appendObservationToLedger(vaultPath, observation, actor) {
813
+ appendToLedger(vaultPath, {
814
+ timestamp: observation.extractedAt,
815
+ category: observation.category,
816
+ actor,
817
+ content: observation.text,
818
+ primitiveType: observation.primitiveType,
819
+ tags: observation.tags
820
+ });
821
+ }
822
+ function batchWriteObservations(vaultPath, observations, options = {}) {
823
+ const results = [];
824
+ let successful = 0;
825
+ let failed = 0;
826
+ const writeLedger = options.writeLedger ?? true;
827
+ const writeFiles = options.writeFiles ?? false;
828
+ for (const observation of observations) {
829
+ if (writeLedger) {
830
+ try {
831
+ appendObservationToLedger(vaultPath, observation, options.actor);
832
+ } catch {
833
+ }
834
+ }
835
+ if (writeFiles) {
836
+ const result = writeObservation(vaultPath, observation, {
837
+ source: options.source,
838
+ sessionId: options.sessionId
839
+ });
840
+ results.push(result);
841
+ if (result.success) {
842
+ successful++;
843
+ } else {
844
+ failed++;
845
+ }
846
+ } else {
847
+ successful++;
848
+ results.push({
849
+ success: true,
850
+ path: (0, import_node_path2.join)(vaultPath, "ledger", `${observation.extractedAt.toISOString().slice(0, 10)}.md`),
851
+ primitiveType: observation.primitiveType,
852
+ errors: [],
853
+ created: false,
854
+ updated: true
855
+ });
856
+ }
857
+ }
858
+ return {
859
+ total: observations.length,
860
+ successful,
861
+ failed,
862
+ results
863
+ };
864
+ }
865
+ function ensureVaultStructure(vaultPath) {
866
+ const directories = [
867
+ "tasks",
868
+ "projects",
869
+ "decisions",
870
+ "people",
871
+ "lessons",
872
+ "memory",
873
+ "ledger",
874
+ "daily"
875
+ ];
876
+ for (const dir of directories) {
877
+ const fullPath = (0, import_node_path2.join)(vaultPath, dir);
878
+ if (!(0, import_node_fs2.existsSync)(fullPath)) {
879
+ (0, import_node_fs2.mkdirSync)(fullPath, { recursive: true });
880
+ }
881
+ }
882
+ }
883
+ function getVaultStats(vaultPath) {
884
+ const directories = [];
885
+ const primitiveTypes = {};
886
+ let fileCount = 0;
887
+ const { readdirSync: readdirSync2, statSync } = require("fs");
888
+ function scanDir(dir, depth = 0) {
889
+ if (depth > 2) return;
890
+ try {
891
+ const entries = readdirSync2(dir, { withFileTypes: true });
892
+ for (const entry of entries) {
893
+ if (entry.name.startsWith(".") || entry.name.startsWith("_")) continue;
894
+ const fullPath = (0, import_node_path2.join)(dir, entry.name);
895
+ if (entry.isDirectory()) {
896
+ directories.push(fullPath.replace(vaultPath + "/", ""));
897
+ scanDir(fullPath, depth + 1);
898
+ } else if (entry.name.endsWith(".md")) {
899
+ fileCount++;
900
+ try {
901
+ const content = (0, import_node_fs2.readFileSync)(fullPath, "utf-8");
902
+ const match = content.match(/^---\n[\s\S]*?type:\s*(\S+)/);
903
+ if (match) {
904
+ const type = match[1];
905
+ primitiveTypes[type] = (primitiveTypes[type] ?? 0) + 1;
906
+ }
907
+ } catch {
908
+ }
909
+ }
910
+ }
911
+ } catch {
912
+ }
913
+ }
914
+ scanDir(vaultPath);
915
+ return { directories, fileCount, primitiveTypes };
916
+ }
917
+ // Annotate the CommonJS export names for ESM import in node:
918
+ 0 && (module.exports = {
919
+ appendObservationToLedger,
920
+ appendToLedger,
921
+ batchWriteObservations,
922
+ ensureVaultStructure,
923
+ getVaultStats,
924
+ writeObservation,
925
+ writeObservations,
926
+ writeVaultFile
927
+ });