clawvault 3.0.0 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +352 -20
- package/bin/clawvault.js +8 -2
- package/bin/command-registration.test.js +3 -1
- package/bin/command-runtime.js +9 -1
- package/bin/register-core-commands.js +23 -10
- package/bin/register-maintenance-commands.js +39 -3
- package/bin/register-query-commands.js +58 -29
- package/bin/register-task-commands.js +18 -1
- package/bin/register-task-commands.test.js +16 -0
- package/bin/register-vault-operations-commands.js +29 -1
- package/bin/register-workgraph-commands.js +1368 -0
- package/dashboard/lib/graph-diff.js +104 -0
- package/dashboard/lib/graph-diff.test.js +75 -0
- package/dashboard/lib/vault-parser.js +556 -0
- package/dashboard/lib/vault-parser.test.js +254 -0
- package/dashboard/public/app.js +796 -0
- package/dashboard/public/index.html +52 -0
- package/dashboard/public/styles.css +221 -0
- package/dashboard/server.js +374 -0
- package/dist/{chunk-F2JEUD4J.js → chunk-23YDQ3QU.js} +6 -8
- package/dist/{chunk-C7OK5WKP.js → chunk-2JQ3O2YL.js} +4 -4
- package/dist/{chunk-VR5NE7PZ.js → chunk-2RAZ4ZFE.js} +1 -1
- package/dist/chunk-2ZDO52B4.js +52 -0
- package/dist/{chunk-ZZA73MFY.js → chunk-33DOSHTA.js} +176 -36
- package/dist/chunk-33VSQP4J.js +37 -0
- package/dist/chunk-4BQTQMJP.js +93 -0
- package/dist/{chunk-GUKMRGM7.js → chunk-4OXMU5S2.js} +1 -1
- package/dist/{chunk-62YTUT6J.js → chunk-4PY655YM.js} +15 -3
- package/dist/chunk-6FH3IULF.js +352 -0
- package/dist/{chunk-3NSBOUT3.js → chunk-77Q5CSPJ.js} +404 -80
- package/dist/{chunk-4VQTUVH7.js → chunk-7YZWHM36.js} +52 -26
- package/dist/chunk-BSJ6RIT7.js +447 -0
- package/dist/chunk-BUEW6IIK.js +364 -0
- package/dist/{chunk-WGRQ6HDV.js → chunk-CLJTREDS.js} +74 -14
- package/dist/chunk-EK6S23ZB.js +469 -0
- package/dist/{chunk-LNJA2UGL.js → chunk-ESFLMDRB.js} +9 -86
- package/dist/{chunk-H34S76MB.js → chunk-ESVS6K2B.js} +6 -6
- package/dist/{chunk-WAZ3NLWL.js → chunk-F55HGNU4.js} +0 -47
- package/dist/{chunk-QK3UCXWL.js → chunk-FHFUXL6G.js} +2 -2
- package/dist/{chunk-YKTA5JOJ.js → chunk-GAOWA7GR.js} +212 -46
- package/dist/chunk-GGA32J2R.js +784 -0
- package/dist/chunk-GNJL4YGR.js +79 -0
- package/dist/chunk-MDIH26GC.js +183 -0
- package/dist/{chunk-LYHGEHXG.js → chunk-MFAWT5O5.js} +0 -1
- package/dist/chunk-MM6QGW3P.js +207 -0
- package/dist/{chunk-P5EPF6MB.js → chunk-MW5C6ZQA.js} +110 -13
- package/dist/chunk-NCKFNBHJ.js +257 -0
- package/dist/{chunk-QBLMXKF2.js → chunk-OIWVQYQF.js} +1 -1
- package/dist/{chunk-42MXU7A6.js → chunk-P62WHA27.js} +58 -47
- package/dist/chunk-PBACDKKP.js +66 -0
- package/dist/{chunk-VGLOTGAS.js → chunk-QSHD36LH.js} +2 -2
- package/dist/{chunk-OZ7RIXTO.js → chunk-QSRRMEYM.js} +2 -2
- package/dist/chunk-QVEERJSP.js +152 -0
- package/dist/{chunk-N2AXRYLC.js → chunk-QWQ3TIKS.js} +1 -1
- package/dist/{chunk-3DHXQHYG.js → chunk-R2MIW5G7.js} +1 -1
- package/dist/{chunk-SJSFRIYS.js → chunk-SLXOR3CC.js} +2 -2
- package/dist/chunk-SS4B7P7V.js +99 -0
- package/dist/{chunk-JY6FYXIT.js → chunk-STCQGCEQ.js} +6 -11
- package/dist/chunk-U4O6C46S.js +154 -0
- package/dist/{chunk-ITPEXLHA.js → chunk-URXDAUVH.js} +24 -5
- package/dist/chunk-VSL7KY3M.js +189 -0
- package/dist/{chunk-U55BGUAU.js → chunk-W4SPAEE7.js} +6 -6
- package/dist/chunk-WMGIIABP.js +15 -0
- package/dist/{chunk-3D6BCTP6.js → chunk-X3SPPUFG.js} +51 -39
- package/dist/{chunk-THRJVD4L.js → chunk-Y6VJKXGL.js} +1 -1
- package/dist/{chunk-ZVVFWOLW.js → chunk-ZN54U2OZ.js} +123 -10
- package/dist/cli/index.js +32 -25
- package/dist/commands/archive.js +3 -3
- package/dist/commands/backlog.js +3 -3
- package/dist/commands/blocked.js +3 -3
- package/dist/commands/canvas.d.ts +15 -0
- package/dist/commands/canvas.js +200 -0
- package/dist/commands/checkpoint.js +2 -2
- package/dist/commands/compat.js +2 -2
- package/dist/commands/context.js +8 -6
- package/dist/commands/doctor.d.ts +11 -7
- package/dist/commands/doctor.js +18 -16
- package/dist/commands/embed.js +5 -6
- package/dist/commands/entities.js +2 -2
- package/dist/commands/graph.js +4 -4
- package/dist/commands/inject.d.ts +1 -1
- package/dist/commands/inject.js +5 -6
- package/dist/commands/kanban.js +4 -4
- package/dist/commands/link.js +5 -5
- package/dist/commands/migrate-observations.js +4 -4
- package/dist/commands/observe.d.ts +0 -1
- package/dist/commands/observe.js +14 -13
- package/dist/commands/project.js +5 -5
- package/dist/commands/rebuild-embeddings.d.ts +21 -0
- package/dist/commands/rebuild-embeddings.js +91 -0
- package/dist/commands/rebuild.js +12 -11
- package/dist/commands/recover.js +3 -3
- package/dist/commands/reflect.js +6 -7
- package/dist/commands/repair-session.js +1 -1
- package/dist/commands/replay.js +14 -14
- package/dist/commands/session-recap.js +1 -1
- package/dist/commands/setup.d.ts +2 -90
- package/dist/commands/setup.js +3 -21
- package/dist/commands/shell-init.js +1 -1
- package/dist/commands/sleep.d.ts +1 -1
- package/dist/commands/sleep.js +20 -19
- package/dist/commands/status.d.ts +2 -0
- package/dist/commands/status.js +57 -35
- package/dist/commands/sync-bd.d.ts +10 -0
- package/dist/commands/sync-bd.js +10 -0
- package/dist/commands/tailscale.js +3 -3
- package/dist/commands/task.js +4 -4
- package/dist/commands/template.js +2 -2
- package/dist/commands/wake.d.ts +1 -1
- package/dist/commands/wake.js +11 -10
- package/dist/commands/workgraph.d.ts +124 -0
- package/dist/commands/workgraph.js +38 -0
- package/dist/index.d.ts +337 -191
- package/dist/index.js +387 -118
- package/dist/{inject-Bzi5E-By.d.cts → inject-DYUrDqQO.d.ts} +3 -3
- package/dist/ledger-B7g7jhqG.d.ts +44 -0
- package/dist/lib/auto-linker.js +2 -2
- package/dist/lib/canvas-layout.d.ts +100 -16
- package/dist/lib/canvas-layout.js +21 -78
- package/dist/lib/config.d.ts +27 -3
- package/dist/lib/config.js +4 -2
- package/dist/lib/entity-index.js +1 -1
- package/dist/lib/project-utils.js +4 -4
- package/dist/lib/session-repair.js +1 -1
- package/dist/lib/session-utils.js +1 -1
- package/dist/lib/tailscale.js +1 -1
- package/dist/lib/task-utils.js +3 -3
- package/dist/lib/template-engine.js +1 -1
- package/dist/lib/webdav.js +1 -1
- package/dist/onnxruntime_binding-5QEF3SUC.node +0 -0
- package/dist/onnxruntime_binding-BKPKNEGC.node +0 -0
- package/dist/onnxruntime_binding-FMOXGIUT.node +0 -0
- package/dist/onnxruntime_binding-OI2KMXC5.node +0 -0
- package/dist/onnxruntime_binding-UX44MLAZ.node +0 -0
- package/dist/onnxruntime_binding-Y2W7N7WY.node +0 -0
- package/dist/openclaw-plugin.d.ts +8 -0
- package/dist/openclaw-plugin.js +14 -0
- package/dist/registry-BR4326o0.d.ts +30 -0
- package/dist/store-CA-6sKCJ.d.ts +34 -0
- package/dist/thread-B9LhXNU0.d.ts +41 -0
- package/dist/transformers.node-A2ZRORSQ.js +46775 -0
- package/dist/{types-Y2_Um2Ls.d.cts → types-BbWJoC1c.d.ts} +1 -44
- package/dist/workgraph/index.d.ts +5 -0
- package/dist/workgraph/index.js +23 -0
- package/dist/workgraph/ledger.d.ts +2 -0
- package/dist/workgraph/ledger.js +25 -0
- package/dist/workgraph/registry.d.ts +2 -0
- package/dist/workgraph/registry.js +19 -0
- package/dist/workgraph/store.d.ts +2 -0
- package/dist/workgraph/store.js +25 -0
- package/dist/workgraph/thread.d.ts +2 -0
- package/dist/workgraph/thread.js +25 -0
- package/dist/workgraph/types.d.ts +54 -0
- package/dist/workgraph/types.js +7 -0
- package/hooks/clawvault/HOOK.md +34 -4
- package/hooks/clawvault/handler.js +760 -78
- package/hooks/clawvault/handler.test.js +235 -79
- package/hooks/clawvault/openclaw.plugin.json +72 -0
- package/openclaw.plugin.json +65 -38
- package/package.json +15 -18
- package/dist/chunk-3RG5ZIWI.js +0 -10
- package/dist/chunk-6U6MK36V.js +0 -205
- package/dist/chunk-7R7O6STJ.js +0 -88
- package/dist/chunk-CMB7UL7C.js +0 -327
- package/dist/chunk-DEFFDRVP.js +0 -938
- package/dist/chunk-E7MFQB6D.js +0 -163
- package/dist/chunk-GAJV4IGR.js +0 -82
- package/dist/chunk-GQSLDZTS.js +0 -560
- package/dist/chunk-K234IDRJ.js +0 -1073
- package/dist/chunk-MFM6K7PU.js +0 -374
- package/dist/chunk-MXSSG3QU.js +0 -42
- package/dist/chunk-PAH27GSN.js +0 -108
- package/dist/cli/index.cjs +0 -10033
- package/dist/cli/index.d.cts +0 -5
- package/dist/commands/archive.cjs +0 -287
- package/dist/commands/archive.d.cts +0 -11
- package/dist/commands/backlog.cjs +0 -721
- package/dist/commands/backlog.d.cts +0 -53
- package/dist/commands/blocked.cjs +0 -204
- package/dist/commands/blocked.d.cts +0 -26
- package/dist/commands/checkpoint.cjs +0 -244
- package/dist/commands/checkpoint.d.cts +0 -41
- package/dist/commands/compat.cjs +0 -369
- package/dist/commands/compat.d.cts +0 -28
- package/dist/commands/context.cjs +0 -2989
- package/dist/commands/context.d.cts +0 -2
- package/dist/commands/doctor.cjs +0 -3062
- package/dist/commands/doctor.d.cts +0 -21
- package/dist/commands/embed.cjs +0 -232
- package/dist/commands/embed.d.cts +0 -17
- package/dist/commands/entities.cjs +0 -141
- package/dist/commands/entities.d.cts +0 -7
- package/dist/commands/graph.cjs +0 -501
- package/dist/commands/graph.d.cts +0 -21
- package/dist/commands/inject.cjs +0 -1636
- package/dist/commands/inject.d.cts +0 -2
- package/dist/commands/kanban.cjs +0 -884
- package/dist/commands/kanban.d.cts +0 -63
- package/dist/commands/link.cjs +0 -965
- package/dist/commands/link.d.cts +0 -11
- package/dist/commands/migrate-observations.cjs +0 -362
- package/dist/commands/migrate-observations.d.cts +0 -19
- package/dist/commands/observe.cjs +0 -4099
- package/dist/commands/observe.d.cts +0 -23
- package/dist/commands/project.cjs +0 -1341
- package/dist/commands/project.d.cts +0 -85
- package/dist/commands/rebuild.cjs +0 -3136
- package/dist/commands/rebuild.d.cts +0 -11
- package/dist/commands/recover.cjs +0 -361
- package/dist/commands/recover.d.cts +0 -38
- package/dist/commands/reflect.cjs +0 -1008
- package/dist/commands/reflect.d.cts +0 -11
- package/dist/commands/repair-session.cjs +0 -457
- package/dist/commands/repair-session.d.cts +0 -38
- package/dist/commands/replay.cjs +0 -4103
- package/dist/commands/replay.d.cts +0 -16
- package/dist/commands/session-recap.cjs +0 -353
- package/dist/commands/session-recap.d.cts +0 -27
- package/dist/commands/setup.cjs +0 -1345
- package/dist/commands/setup.d.cts +0 -100
- package/dist/commands/shell-init.cjs +0 -75
- package/dist/commands/shell-init.d.cts +0 -7
- package/dist/commands/sleep.cjs +0 -6028
- package/dist/commands/sleep.d.cts +0 -36
- package/dist/commands/status.cjs +0 -2736
- package/dist/commands/status.d.cts +0 -52
- package/dist/commands/tailscale.cjs +0 -1532
- package/dist/commands/tailscale.d.cts +0 -52
- package/dist/commands/task.cjs +0 -1236
- package/dist/commands/task.d.cts +0 -97
- package/dist/commands/template.cjs +0 -457
- package/dist/commands/template.d.cts +0 -36
- package/dist/commands/wake.cjs +0 -2626
- package/dist/commands/wake.d.cts +0 -22
- package/dist/context-BUGaWpyL.d.cts +0 -46
- package/dist/index.cjs +0 -14526
- package/dist/index.d.cts +0 -858
- package/dist/inject-Bzi5E-By.d.ts +0 -137
- package/dist/lib/auto-linker.cjs +0 -176
- package/dist/lib/auto-linker.d.cts +0 -26
- package/dist/lib/canvas-layout.cjs +0 -136
- package/dist/lib/canvas-layout.d.cts +0 -31
- package/dist/lib/config.cjs +0 -78
- package/dist/lib/config.d.cts +0 -11
- package/dist/lib/entity-index.cjs +0 -84
- package/dist/lib/entity-index.d.cts +0 -26
- package/dist/lib/project-utils.cjs +0 -864
- package/dist/lib/project-utils.d.cts +0 -97
- package/dist/lib/session-repair.cjs +0 -239
- package/dist/lib/session-repair.d.cts +0 -110
- package/dist/lib/session-utils.cjs +0 -209
- package/dist/lib/session-utils.d.cts +0 -63
- package/dist/lib/tailscale.cjs +0 -1183
- package/dist/lib/tailscale.d.cts +0 -225
- package/dist/lib/task-utils.cjs +0 -1137
- package/dist/lib/task-utils.d.cts +0 -208
- package/dist/lib/template-engine.cjs +0 -47
- package/dist/lib/template-engine.d.cts +0 -11
- package/dist/lib/webdav.cjs +0 -568
- package/dist/lib/webdav.d.cts +0 -109
- package/dist/plugin/index.cjs +0 -1907
- package/dist/plugin/index.d.cts +0 -36
- package/dist/plugin/index.d.ts +0 -36
- package/dist/plugin/index.js +0 -572
- package/dist/plugin/inject.cjs +0 -356
- package/dist/plugin/inject.d.cts +0 -54
- package/dist/plugin/inject.d.ts +0 -54
- package/dist/plugin/inject.js +0 -17
- package/dist/plugin/observe.cjs +0 -631
- package/dist/plugin/observe.d.cts +0 -39
- package/dist/plugin/observe.d.ts +0 -39
- package/dist/plugin/observe.js +0 -18
- package/dist/plugin/templates.cjs +0 -593
- package/dist/plugin/templates.d.cts +0 -52
- package/dist/plugin/templates.d.ts +0 -52
- package/dist/plugin/templates.js +0 -25
- package/dist/plugin/types.cjs +0 -18
- package/dist/plugin/types.d.cts +0 -209
- package/dist/plugin/types.d.ts +0 -209
- package/dist/plugin/types.js +0 -0
- package/dist/plugin/vault.cjs +0 -927
- package/dist/plugin/vault.d.cts +0 -68
- package/dist/plugin/vault.d.ts +0 -68
- package/dist/plugin/vault.js +0 -22
- package/dist/types-Y2_Um2Ls.d.ts +0 -205
- package/templates/memory-event.md +0 -67
- package/templates/party.md +0 -63
- package/templates/primitive-registry.yaml +0 -551
- package/templates/run.md +0 -68
- package/templates/trigger.md +0 -68
- package/templates/workspace.md +0 -50
package/dist/chunk-GQSLDZTS.js
DELETED
|
@@ -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
|
-
};
|