clawvault 2.6.1 → 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-HIHOUSXS.js → chunk-E7MFQB6D.js} +59 -18
  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-T76H47ZS.js → chunk-H34S76MB.js} +6 -6
  24. package/dist/{chunk-R6SXNSFD.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-3BTHWPMB.js → chunk-SJSFRIYS.js} +1 -1
  34. package/dist/{chunk-4VRIMU4O.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 +10 -9
  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-MAKNAHAW.js +0 -375
  225. package/dist/chunk-MDIH26GC.js +0 -183
  226. package/dist/chunk-MGDEINGP.js +0 -99
  227. package/dist/chunk-RVYA52PY.js +0 -363
  228. package/dist/chunk-TLGBDTYT.js +0 -33
  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,560 @@
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
+ };
@@ -2,7 +2,7 @@ import {
2
2
  listTasks,
3
3
  readTask,
4
4
  updateTask
5
- } from "./chunk-QWQ3TIKS.js";
5
+ } from "./chunk-N2AXRYLC.js";
6
6
 
7
7
  // src/commands/kanban.ts
8
8
  import * as fs from "fs";
@@ -1,14 +1,14 @@
1
- import {
2
- normalizeObservationContent,
3
- parseObservationMarkdown
4
- } from "./chunk-FHFUXL6G.js";
5
1
  import {
6
2
  requestLlmCompletion,
7
3
  resolveLlmProvider
8
- } from "./chunk-HIHOUSXS.js";
4
+ } from "./chunk-E7MFQB6D.js";
9
5
  import {
10
6
  archiveObservations
11
7
  } from "./chunk-MQUJNOHK.js";
8
+ import {
9
+ normalizeObservationContent,
10
+ parseObservationMarkdown
11
+ } from "./chunk-QK3UCXWL.js";
12
12
  import {
13
13
  formatIsoWeekKey,
14
14
  getIsoWeek,
@@ -213,7 +213,7 @@ function promoteWeekRecords(records) {
213
213
  return promoted;
214
214
  }
215
215
  async function maybeGenerateLlmReflection(weekKey, sections) {
216
- const provider = resolveLlmProvider();
216
+ const provider = await resolveLlmProvider();
217
217
  if (!provider) {
218
218
  return null;
219
219
  }
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  runReflection
3
- } from "./chunk-T76H47ZS.js";
3
+ } from "./chunk-H34S76MB.js";
4
4
  import {
5
5
  Observer
6
- } from "./chunk-Q2J5YTUF.js";
6
+ } from "./chunk-3NSBOUT3.js";
7
7
  import {
8
8
  resolveVaultPath
9
9
  } from "./chunk-MXSSG3QU.js";
@@ -135,7 +135,8 @@ function pushMessage(destination, conversationId, record) {
135
135
  if (!text) {
136
136
  return;
137
137
  }
138
- const role = typeof record.role === "string" ? record.role.trim().toLowerCase() : void 0;
138
+ const rawRole = typeof record.role === "string" ? record.role : typeof record.sender === "string" ? record.sender : void 0;
139
+ const role = rawRole ? rawRole.trim().toLowerCase() : void 0;
139
140
  destination.push({
140
141
  source: "claude",
141
142
  conversationId,
@@ -151,8 +152,9 @@ function normalizeClaudeExport(input) {
151
152
  if (!item || typeof item !== "object") continue;
152
153
  const record = item;
153
154
  const conversationId = typeof record.id === "string" ? record.id : typeof record.uuid === "string" ? record.uuid : void 0;
154
- if (Array.isArray(record.messages)) {
155
- for (const message of record.messages) {
155
+ const recordMessages = Array.isArray(record.messages) ? record.messages : Array.isArray(record.chat_messages) ? record.chat_messages : void 0;
156
+ if (recordMessages) {
157
+ for (const message of recordMessages) {
156
158
  if (!message || typeof message !== "object") continue;
157
159
  pushMessage(messages, conversationId, message);
158
160
  }
@@ -170,6 +172,9 @@ function normalizeClaudeExport(input) {
170
172
  if (Array.isArray(root.messages)) {
171
173
  return normalizeClaudeExport([{ id: root.id, messages: root.messages }]);
172
174
  }
175
+ if (Array.isArray(root.chat_messages)) {
176
+ return normalizeClaudeExport([{ id: root.id, chat_messages: root.chat_messages }]);
177
+ }
173
178
  }
174
179
  return messages;
175
180
  }