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/plugin/index.cjs
DELETED
|
@@ -1,1907 +0,0 @@
|
|
|
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/index.ts
|
|
21
|
-
var plugin_exports = {};
|
|
22
|
-
__export(plugin_exports, {
|
|
23
|
-
appendToLedger: () => appendToLedger,
|
|
24
|
-
batchWriteObservations: () => batchWriteObservations,
|
|
25
|
-
buildFullContext: () => buildFullContext,
|
|
26
|
-
buildPreferenceContext: () => buildPreferenceContext,
|
|
27
|
-
buildSessionRecap: () => buildSessionRecap,
|
|
28
|
-
classifyText: () => classifyText,
|
|
29
|
-
default: () => plugin_default,
|
|
30
|
-
detectCategory: () => detectCategory,
|
|
31
|
-
ensureVaultStructure: () => ensureVaultStructure,
|
|
32
|
-
extractObservations: () => extractObservations,
|
|
33
|
-
extractSearchTerms: () => extractSearchTerms,
|
|
34
|
-
formatMemoriesForContext: () => formatMemoriesForContext,
|
|
35
|
-
formatSearchResults: () => formatSearchResults,
|
|
36
|
-
getAllSchemas: () => getAllSchemas,
|
|
37
|
-
getSchema: () => getSchema,
|
|
38
|
-
getSchemaNames: () => getSchemaNames,
|
|
39
|
-
getTemplateRegistry: () => getTemplateRegistry2,
|
|
40
|
-
initializeTemplateRegistry: () => initializeTemplateRegistry,
|
|
41
|
-
isObservable: () => isObservable,
|
|
42
|
-
processMessageForObservations: () => processMessageForObservations,
|
|
43
|
-
scanVaultFiles: () => scanVaultFiles,
|
|
44
|
-
writeObservation: () => writeObservation,
|
|
45
|
-
writeVaultFile: () => writeVaultFile
|
|
46
|
-
});
|
|
47
|
-
module.exports = __toCommonJS(plugin_exports);
|
|
48
|
-
var import_node_child_process = require("child_process");
|
|
49
|
-
var import_node_fs4 = require("fs");
|
|
50
|
-
var import_node_path4 = require("path");
|
|
51
|
-
var import_typebox = require("@sinclair/typebox");
|
|
52
|
-
|
|
53
|
-
// src/plugin/templates.ts
|
|
54
|
-
var import_node_fs = require("fs");
|
|
55
|
-
var import_node_path = require("path");
|
|
56
|
-
var DEFAULT_SCHEMAS = [
|
|
57
|
-
{
|
|
58
|
-
primitive: "memory_event",
|
|
59
|
-
description: "General memory event for observations",
|
|
60
|
-
fields: {
|
|
61
|
-
type: { type: "string", required: true, default: "memory_event" },
|
|
62
|
-
status: { type: "string", required: true, default: "recorded", enum: ["recorded", "superseded", "corrected"] },
|
|
63
|
-
created: { type: "datetime", required: true, default: "{{datetime}}" },
|
|
64
|
-
observed_at: { type: "datetime", required: true },
|
|
65
|
-
source: { type: "string", required: true, enum: ["openclaw", "claude-code", "replay", "manual-correction"] },
|
|
66
|
-
summary: { type: "string", required: true },
|
|
67
|
-
confidence: { type: "number" },
|
|
68
|
-
importance: { type: "number" }
|
|
69
|
-
},
|
|
70
|
-
keywords: ["preference", "like", "hate", "want", "need", "always", "never", "remember", "note"]
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
primitive: "person",
|
|
74
|
-
description: "People and relationship notes",
|
|
75
|
-
fields: {
|
|
76
|
-
title: { type: "string", required: true, default: "{{title}}" },
|
|
77
|
-
date: { type: "date", required: true, default: "{{date}}" },
|
|
78
|
-
type: { type: "string", required: true, default: "person" },
|
|
79
|
-
relationship: { type: "string", default: "contact" }
|
|
80
|
-
},
|
|
81
|
-
keywords: ["person", "contact", "colleague", "friend", "works at", "lives in", "email", "phone", "name is"]
|
|
82
|
-
},
|
|
83
|
-
{
|
|
84
|
-
primitive: "decision",
|
|
85
|
-
description: "Decision records",
|
|
86
|
-
fields: {
|
|
87
|
-
title: { type: "string", required: true, default: "{{title}}" },
|
|
88
|
-
date: { type: "date", required: true, default: "{{date}}" },
|
|
89
|
-
type: { type: "string", required: true, default: "decision" },
|
|
90
|
-
status: { type: "string", default: "decided", enum: ["proposed", "decided", "superseded"] }
|
|
91
|
-
},
|
|
92
|
-
keywords: ["decided", "decision", "chose", "will use", "go with", "ship", "approved", "rejected"]
|
|
93
|
-
},
|
|
94
|
-
{
|
|
95
|
-
primitive: "task",
|
|
96
|
-
description: "Task primitives",
|
|
97
|
-
fields: {
|
|
98
|
-
status: { type: "string", required: true, default: "open", enum: ["open", "in-progress", "blocked", "done"] },
|
|
99
|
-
created: { type: "datetime", required: true, default: "{{datetime}}" },
|
|
100
|
-
updated: { type: "datetime", required: true, default: "{{datetime}}" },
|
|
101
|
-
priority: { type: "string", enum: ["critical", "high", "medium", "low"] },
|
|
102
|
-
due: { type: "date" }
|
|
103
|
-
},
|
|
104
|
-
keywords: ["task", "todo", "need to", "should", "must", "deadline", "due", "by tomorrow", "by tonight"]
|
|
105
|
-
},
|
|
106
|
-
{
|
|
107
|
-
primitive: "project",
|
|
108
|
-
description: "Project definition documents",
|
|
109
|
-
fields: {
|
|
110
|
-
type: { type: "string", required: true, default: "project" },
|
|
111
|
-
status: { type: "string", required: true, default: "active", enum: ["active", "paused", "completed", "archived"] },
|
|
112
|
-
created: { type: "datetime", required: true, default: "{{datetime}}" },
|
|
113
|
-
updated: { type: "datetime", required: true, default: "{{datetime}}" }
|
|
114
|
-
},
|
|
115
|
-
keywords: ["project", "initiative", "working on", "building", "developing"]
|
|
116
|
-
},
|
|
117
|
-
{
|
|
118
|
-
primitive: "lesson",
|
|
119
|
-
description: "Lessons learned",
|
|
120
|
-
fields: {
|
|
121
|
-
title: { type: "string", required: true, default: "{{title}}" },
|
|
122
|
-
date: { type: "date", required: true, default: "{{date}}" },
|
|
123
|
-
type: { type: "string", required: true, default: "lesson" }
|
|
124
|
-
},
|
|
125
|
-
keywords: ["learned", "lesson", "insight", "realized", "discovered", "found out"]
|
|
126
|
-
}
|
|
127
|
-
];
|
|
128
|
-
function parseYamlFrontmatter(content) {
|
|
129
|
-
const match = content.match(/^---\n([\s\S]*?)\n---\n?([\s\S]*)$/);
|
|
130
|
-
if (!match) return null;
|
|
131
|
-
const yamlContent = match[1];
|
|
132
|
-
const body = match[2];
|
|
133
|
-
try {
|
|
134
|
-
const frontmatter = parseSimpleYaml(yamlContent);
|
|
135
|
-
return { frontmatter, body };
|
|
136
|
-
} catch {
|
|
137
|
-
return null;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
function parseSimpleYaml(yaml) {
|
|
141
|
-
const result = {};
|
|
142
|
-
const lines = yaml.split("\n");
|
|
143
|
-
let currentKey = "";
|
|
144
|
-
let currentIndent = 0;
|
|
145
|
-
let nestedObject = null;
|
|
146
|
-
let nestedKey = "";
|
|
147
|
-
for (const line of lines) {
|
|
148
|
-
if (!line.trim() || line.trim().startsWith("#")) continue;
|
|
149
|
-
const indent = line.search(/\S/);
|
|
150
|
-
const trimmed = line.trim();
|
|
151
|
-
if (trimmed.startsWith("- ")) {
|
|
152
|
-
const value = trimmed.slice(2).trim();
|
|
153
|
-
if (nestedObject && nestedKey) {
|
|
154
|
-
const arr = nestedObject[nestedKey];
|
|
155
|
-
if (Array.isArray(arr)) {
|
|
156
|
-
arr.push(parseYamlValue(value));
|
|
157
|
-
}
|
|
158
|
-
} else if (currentKey && result[currentKey]) {
|
|
159
|
-
const arr = result[currentKey];
|
|
160
|
-
if (Array.isArray(arr)) {
|
|
161
|
-
arr.push(parseYamlValue(value));
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
continue;
|
|
165
|
-
}
|
|
166
|
-
const colonIndex = trimmed.indexOf(":");
|
|
167
|
-
if (colonIndex === -1) continue;
|
|
168
|
-
const key = trimmed.slice(0, colonIndex).trim();
|
|
169
|
-
const valueStr = trimmed.slice(colonIndex + 1).trim();
|
|
170
|
-
if (indent === 0) {
|
|
171
|
-
if (valueStr === "" || valueStr === "|" || valueStr === ">") {
|
|
172
|
-
if (key === "fields") {
|
|
173
|
-
result[key] = {};
|
|
174
|
-
nestedObject = result[key];
|
|
175
|
-
nestedKey = "";
|
|
176
|
-
} else {
|
|
177
|
-
result[key] = {};
|
|
178
|
-
nestedObject = null;
|
|
179
|
-
}
|
|
180
|
-
} else {
|
|
181
|
-
result[key] = parseYamlValue(valueStr);
|
|
182
|
-
nestedObject = null;
|
|
183
|
-
}
|
|
184
|
-
currentKey = key;
|
|
185
|
-
currentIndent = indent;
|
|
186
|
-
} else if (nestedObject && indent > 0) {
|
|
187
|
-
if (valueStr === "" || valueStr === "|" || valueStr === ">") {
|
|
188
|
-
nestedObject[key] = {};
|
|
189
|
-
nestedKey = key;
|
|
190
|
-
} else if (nestedKey && indent > 2) {
|
|
191
|
-
const fieldObj = nestedObject[nestedKey];
|
|
192
|
-
if (fieldObj) {
|
|
193
|
-
if (key === "enum") {
|
|
194
|
-
fieldObj[key] = [];
|
|
195
|
-
} else {
|
|
196
|
-
fieldObj[key] = parseYamlValue(valueStr);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
} else {
|
|
200
|
-
nestedObject[key] = parseYamlValue(valueStr);
|
|
201
|
-
nestedKey = key;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
return result;
|
|
206
|
-
}
|
|
207
|
-
function parseYamlValue(value) {
|
|
208
|
-
if (value === "" || value === "null" || value === "~") return null;
|
|
209
|
-
if (value === "true") return true;
|
|
210
|
-
if (value === "false") return false;
|
|
211
|
-
if (/^-?\d+$/.test(value)) return parseInt(value, 10);
|
|
212
|
-
if (/^-?\d+\.\d+$/.test(value)) return parseFloat(value);
|
|
213
|
-
if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) {
|
|
214
|
-
return value.slice(1, -1);
|
|
215
|
-
}
|
|
216
|
-
return value;
|
|
217
|
-
}
|
|
218
|
-
var registry = null;
|
|
219
|
-
function getTemplateRegistry() {
|
|
220
|
-
if (!registry) {
|
|
221
|
-
registry = {
|
|
222
|
-
schemas: /* @__PURE__ */ new Map(),
|
|
223
|
-
keywordIndex: /* @__PURE__ */ new Map(),
|
|
224
|
-
initialized: false
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
return registry;
|
|
228
|
-
}
|
|
229
|
-
function initializeTemplateRegistry(templatesDir) {
|
|
230
|
-
const reg = getTemplateRegistry();
|
|
231
|
-
if (reg.initialized) {
|
|
232
|
-
return reg;
|
|
233
|
-
}
|
|
234
|
-
const dirsToTry = templatesDir ? [templatesDir] : [
|
|
235
|
-
(0, import_node_path.join)(process.cwd(), "templates"),
|
|
236
|
-
(0, import_node_path.join)(process.cwd(), "..", "..", "templates"),
|
|
237
|
-
(0, import_node_path.join)(process.env.HOME ?? ".", "clawvault", "templates"),
|
|
238
|
-
(0, import_node_path.join)(process.env.HOME ?? ".", ".clawvault", "templates")
|
|
239
|
-
];
|
|
240
|
-
let loaded = false;
|
|
241
|
-
for (const dir of dirsToTry) {
|
|
242
|
-
if ((0, import_node_fs.existsSync)(dir)) {
|
|
243
|
-
try {
|
|
244
|
-
loadTemplatesFromDirectory(dir, reg);
|
|
245
|
-
loaded = true;
|
|
246
|
-
break;
|
|
247
|
-
} catch {
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
if (!loaded || reg.schemas.size === 0) {
|
|
252
|
-
loadDefaultSchemas(reg);
|
|
253
|
-
}
|
|
254
|
-
buildKeywordIndex(reg);
|
|
255
|
-
reg.initialized = true;
|
|
256
|
-
return reg;
|
|
257
|
-
}
|
|
258
|
-
function loadTemplatesFromDirectory(dir, reg) {
|
|
259
|
-
const files = (0, import_node_fs.readdirSync)(dir).filter((f) => f.endsWith(".md"));
|
|
260
|
-
for (const file of files) {
|
|
261
|
-
const filePath = (0, import_node_path.join)(dir, file);
|
|
262
|
-
const content = (0, import_node_fs.readFileSync)(filePath, "utf-8");
|
|
263
|
-
const parsed = parseYamlFrontmatter(content);
|
|
264
|
-
if (!parsed?.frontmatter?.primitive) continue;
|
|
265
|
-
const schema = convertFrontmatterToSchema(parsed.frontmatter, parsed.body);
|
|
266
|
-
if (schema) {
|
|
267
|
-
reg.schemas.set(schema.primitive, schema);
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
function convertFrontmatterToSchema(fm, body) {
|
|
272
|
-
const primitive = fm.primitive;
|
|
273
|
-
if (!primitive) return null;
|
|
274
|
-
const fields = {};
|
|
275
|
-
const fmFields = fm.fields;
|
|
276
|
-
if (fmFields) {
|
|
277
|
-
for (const [fieldName, fieldDef] of Object.entries(fmFields)) {
|
|
278
|
-
if (typeof fieldDef === "object" && fieldDef !== null) {
|
|
279
|
-
const def = fieldDef;
|
|
280
|
-
fields[fieldName] = {
|
|
281
|
-
type: def.type || "string",
|
|
282
|
-
required: def.required,
|
|
283
|
-
default: def.default,
|
|
284
|
-
enum: def.enum,
|
|
285
|
-
description: def.description
|
|
286
|
-
};
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
const keywords = extractKeywordsFromSchema(primitive, fm.description, fields);
|
|
291
|
-
return {
|
|
292
|
-
primitive,
|
|
293
|
-
description: fm.description,
|
|
294
|
-
fields,
|
|
295
|
-
bodyTemplate: body,
|
|
296
|
-
keywords
|
|
297
|
-
};
|
|
298
|
-
}
|
|
299
|
-
function extractKeywordsFromSchema(primitive, description, fields) {
|
|
300
|
-
const keywords = [primitive];
|
|
301
|
-
keywords.push(primitive.replace(/-/g, " "));
|
|
302
|
-
keywords.push(primitive.replace(/_/g, " "));
|
|
303
|
-
switch (primitive) {
|
|
304
|
-
case "memory_event":
|
|
305
|
-
keywords.push("preference", "like", "hate", "want", "need", "always", "never", "remember", "note");
|
|
306
|
-
break;
|
|
307
|
-
case "person":
|
|
308
|
-
keywords.push("person", "contact", "colleague", "friend", "works at", "lives in", "email", "phone", "name is");
|
|
309
|
-
break;
|
|
310
|
-
case "decision":
|
|
311
|
-
keywords.push("decided", "decision", "chose", "will use", "go with", "ship", "approved", "rejected");
|
|
312
|
-
break;
|
|
313
|
-
case "task":
|
|
314
|
-
keywords.push("task", "todo", "need to", "should", "must", "deadline", "due", "by tomorrow", "by tonight");
|
|
315
|
-
break;
|
|
316
|
-
case "project":
|
|
317
|
-
keywords.push("project", "initiative", "working on", "building", "developing");
|
|
318
|
-
break;
|
|
319
|
-
case "lesson":
|
|
320
|
-
keywords.push("learned", "lesson", "insight", "realized", "discovered", "found out");
|
|
321
|
-
break;
|
|
322
|
-
case "trigger":
|
|
323
|
-
keywords.push("trigger", "schedule", "cron", "automated", "recurring");
|
|
324
|
-
break;
|
|
325
|
-
case "run":
|
|
326
|
-
keywords.push("run", "execution", "job", "started", "finished", "failed");
|
|
327
|
-
break;
|
|
328
|
-
case "checkpoint":
|
|
329
|
-
keywords.push("checkpoint", "snapshot", "state", "progress");
|
|
330
|
-
break;
|
|
331
|
-
case "handoff":
|
|
332
|
-
keywords.push("handoff", "transition", "context", "resume");
|
|
333
|
-
break;
|
|
334
|
-
case "daily-note":
|
|
335
|
-
case "daily":
|
|
336
|
-
keywords.push("daily", "today", "journal", "log");
|
|
337
|
-
break;
|
|
338
|
-
case "party":
|
|
339
|
-
keywords.push("party", "agent", "human", "runtime", "service");
|
|
340
|
-
break;
|
|
341
|
-
case "workspace":
|
|
342
|
-
keywords.push("workspace", "shared", "collaboration");
|
|
343
|
-
break;
|
|
344
|
-
}
|
|
345
|
-
if (fields.status?.enum) {
|
|
346
|
-
keywords.push(...fields.status.enum);
|
|
347
|
-
}
|
|
348
|
-
return [...new Set(keywords)];
|
|
349
|
-
}
|
|
350
|
-
function loadDefaultSchemas(reg) {
|
|
351
|
-
for (const schema of DEFAULT_SCHEMAS) {
|
|
352
|
-
reg.schemas.set(schema.primitive, schema);
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
function buildKeywordIndex(reg) {
|
|
356
|
-
reg.keywordIndex.clear();
|
|
357
|
-
for (const [primitive, schema] of reg.schemas) {
|
|
358
|
-
const keywords = schema.keywords ?? [primitive];
|
|
359
|
-
for (const keyword of keywords) {
|
|
360
|
-
const lower = keyword.toLowerCase();
|
|
361
|
-
const existing = reg.keywordIndex.get(lower) ?? [];
|
|
362
|
-
if (!existing.includes(primitive)) {
|
|
363
|
-
existing.push(primitive);
|
|
364
|
-
}
|
|
365
|
-
reg.keywordIndex.set(lower, existing);
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
function classifyText(text) {
|
|
370
|
-
const reg = getTemplateRegistry();
|
|
371
|
-
if (!reg.initialized) {
|
|
372
|
-
initializeTemplateRegistry();
|
|
373
|
-
}
|
|
374
|
-
const lower = text.toLowerCase();
|
|
375
|
-
const scores = /* @__PURE__ */ new Map();
|
|
376
|
-
for (const [keyword, primitives] of reg.keywordIndex) {
|
|
377
|
-
if (lower.includes(keyword)) {
|
|
378
|
-
for (const primitive of primitives) {
|
|
379
|
-
const existing = scores.get(primitive) ?? { score: 0, keywords: [] };
|
|
380
|
-
existing.score += getKeywordWeight(keyword, primitive);
|
|
381
|
-
existing.keywords.push(keyword);
|
|
382
|
-
scores.set(primitive, existing);
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
applyPatternScoring(lower, scores);
|
|
387
|
-
let bestPrimitive = "memory_event";
|
|
388
|
-
let bestScore = 0;
|
|
389
|
-
let bestKeywords = [];
|
|
390
|
-
for (const [primitive, data] of scores) {
|
|
391
|
-
if (data.score > bestScore) {
|
|
392
|
-
bestScore = data.score;
|
|
393
|
-
bestPrimitive = primitive;
|
|
394
|
-
bestKeywords = data.keywords;
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
const confidence = Math.min(1, bestScore / 5);
|
|
398
|
-
return {
|
|
399
|
-
primitiveType: bestPrimitive,
|
|
400
|
-
confidence,
|
|
401
|
-
matchedKeywords: [...new Set(bestKeywords)]
|
|
402
|
-
};
|
|
403
|
-
}
|
|
404
|
-
function getKeywordWeight(keyword, primitive) {
|
|
405
|
-
if (keyword === primitive || keyword === primitive.replace(/-/g, " ")) {
|
|
406
|
-
return 3;
|
|
407
|
-
}
|
|
408
|
-
const strongIndicators = {
|
|
409
|
-
person: ["works at", "lives in", "email", "phone", "name is"],
|
|
410
|
-
decision: ["decided", "chose", "will use", "go with"],
|
|
411
|
-
task: ["deadline", "due", "by tomorrow", "by tonight"],
|
|
412
|
-
memory_event: ["preference", "remember", "note"]
|
|
413
|
-
};
|
|
414
|
-
if (strongIndicators[primitive]?.includes(keyword)) {
|
|
415
|
-
return 2;
|
|
416
|
-
}
|
|
417
|
-
return 1;
|
|
418
|
-
}
|
|
419
|
-
function applyPatternScoring(text, scores) {
|
|
420
|
-
if (/\b(my .+ is|his .+ is|her .+ is|their .+ is)\b/i.test(text)) {
|
|
421
|
-
const existing = scores.get("person") ?? { score: 0, keywords: [] };
|
|
422
|
-
existing.score += 2;
|
|
423
|
-
existing.keywords.push("possessive pattern");
|
|
424
|
-
scores.set("person", existing);
|
|
425
|
-
}
|
|
426
|
-
if (/[\w.-]+@[\w.-]+\.\w+|\+\d{10,}/.test(text)) {
|
|
427
|
-
const existing = scores.get("person") ?? { score: 0, keywords: [] };
|
|
428
|
-
existing.score += 3;
|
|
429
|
-
existing.keywords.push("contact info");
|
|
430
|
-
scores.set("person", existing);
|
|
431
|
-
}
|
|
432
|
-
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)) {
|
|
433
|
-
const existing = scores.get("memory_event") ?? { score: 0, keywords: [] };
|
|
434
|
-
existing.score += 3;
|
|
435
|
-
existing.keywords.push("preference pattern");
|
|
436
|
-
scores.set("memory_event", existing);
|
|
437
|
-
}
|
|
438
|
-
if (/\b(we decided|let's go with|we're going|i chose|we'll use|ship it|do it)\b/i.test(text)) {
|
|
439
|
-
const existing = scores.get("decision") ?? { score: 0, keywords: [] };
|
|
440
|
-
existing.score += 3;
|
|
441
|
-
existing.keywords.push("decision pattern");
|
|
442
|
-
scores.set("decision", existing);
|
|
443
|
-
}
|
|
444
|
-
if (/\b(by tonight|by tomorrow|deadline|due date|by end of|ship by|ready by)\b/i.test(text)) {
|
|
445
|
-
const existing = scores.get("task") ?? { score: 0, keywords: [] };
|
|
446
|
-
existing.score += 2;
|
|
447
|
-
existing.keywords.push("deadline pattern");
|
|
448
|
-
scores.set("task", existing);
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
function getSchema(primitiveType) {
|
|
452
|
-
const reg = getTemplateRegistry();
|
|
453
|
-
if (!reg.initialized) {
|
|
454
|
-
initializeTemplateRegistry();
|
|
455
|
-
}
|
|
456
|
-
return reg.schemas.get(primitiveType);
|
|
457
|
-
}
|
|
458
|
-
function getAllSchemas() {
|
|
459
|
-
const reg = getTemplateRegistry();
|
|
460
|
-
if (!reg.initialized) {
|
|
461
|
-
initializeTemplateRegistry();
|
|
462
|
-
}
|
|
463
|
-
return Array.from(reg.schemas.values());
|
|
464
|
-
}
|
|
465
|
-
function getSchemaNames() {
|
|
466
|
-
const reg = getTemplateRegistry();
|
|
467
|
-
if (!reg.initialized) {
|
|
468
|
-
initializeTemplateRegistry();
|
|
469
|
-
}
|
|
470
|
-
return Array.from(reg.schemas.keys());
|
|
471
|
-
}
|
|
472
|
-
function generateFrontmatter(primitiveType, options = {}) {
|
|
473
|
-
const schema = getSchema(primitiveType);
|
|
474
|
-
if (!schema) {
|
|
475
|
-
return {
|
|
476
|
-
type: primitiveType,
|
|
477
|
-
created: (/* @__PURE__ */ new Date()).toISOString(),
|
|
478
|
-
updated: (/* @__PURE__ */ new Date()).toISOString()
|
|
479
|
-
};
|
|
480
|
-
}
|
|
481
|
-
const frontmatter = {};
|
|
482
|
-
const now = /* @__PURE__ */ new Date();
|
|
483
|
-
const dateStr = now.toISOString().split("T")[0];
|
|
484
|
-
const datetimeStr = now.toISOString();
|
|
485
|
-
for (const [fieldName, fieldDef] of Object.entries(schema.fields)) {
|
|
486
|
-
if (options.extraFields?.[fieldName] !== void 0) {
|
|
487
|
-
const value = options.extraFields[fieldName];
|
|
488
|
-
if (fieldDef.enum && !fieldDef.enum.includes(String(value))) {
|
|
489
|
-
frontmatter[fieldName] = fieldDef.default ?? fieldDef.enum[0];
|
|
490
|
-
} else {
|
|
491
|
-
frontmatter[fieldName] = value;
|
|
492
|
-
}
|
|
493
|
-
continue;
|
|
494
|
-
}
|
|
495
|
-
if (fieldDef.default !== void 0) {
|
|
496
|
-
let defaultValue = fieldDef.default;
|
|
497
|
-
if (typeof defaultValue === "string") {
|
|
498
|
-
defaultValue = defaultValue.replace("{{datetime}}", datetimeStr).replace("{{date}}", dateStr).replace("{{title}}", options.title ?? "Untitled");
|
|
499
|
-
}
|
|
500
|
-
frontmatter[fieldName] = defaultValue;
|
|
501
|
-
} else if (fieldDef.required) {
|
|
502
|
-
switch (fieldDef.type) {
|
|
503
|
-
case "datetime":
|
|
504
|
-
frontmatter[fieldName] = datetimeStr;
|
|
505
|
-
break;
|
|
506
|
-
case "date":
|
|
507
|
-
frontmatter[fieldName] = dateStr;
|
|
508
|
-
break;
|
|
509
|
-
case "string":
|
|
510
|
-
if (fieldDef.enum?.length) {
|
|
511
|
-
frontmatter[fieldName] = fieldDef.enum[0];
|
|
512
|
-
} else {
|
|
513
|
-
frontmatter[fieldName] = "";
|
|
514
|
-
}
|
|
515
|
-
break;
|
|
516
|
-
case "number":
|
|
517
|
-
frontmatter[fieldName] = 0;
|
|
518
|
-
break;
|
|
519
|
-
case "boolean":
|
|
520
|
-
frontmatter[fieldName] = false;
|
|
521
|
-
break;
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
if (options.source && schema.fields.source) {
|
|
526
|
-
frontmatter.source = options.source;
|
|
527
|
-
}
|
|
528
|
-
if (options.sessionId && schema.fields.session_id) {
|
|
529
|
-
frontmatter.session_id = options.sessionId;
|
|
530
|
-
}
|
|
531
|
-
return frontmatter;
|
|
532
|
-
}
|
|
533
|
-
function validateFrontmatter(primitiveType, frontmatter) {
|
|
534
|
-
const schema = getSchema(primitiveType);
|
|
535
|
-
if (!schema) {
|
|
536
|
-
return { valid: true, errors: [] };
|
|
537
|
-
}
|
|
538
|
-
const errors = [];
|
|
539
|
-
for (const [fieldName, fieldDef] of Object.entries(schema.fields)) {
|
|
540
|
-
const value = frontmatter[fieldName];
|
|
541
|
-
if (fieldDef.required && (value === void 0 || value === null || value === "")) {
|
|
542
|
-
errors.push(`Missing required field: ${fieldName}`);
|
|
543
|
-
continue;
|
|
544
|
-
}
|
|
545
|
-
if (value === void 0 || value === null) continue;
|
|
546
|
-
if (fieldDef.enum && !fieldDef.enum.includes(String(value))) {
|
|
547
|
-
errors.push(`Invalid value for ${fieldName}: "${value}". Must be one of: ${fieldDef.enum.join(", ")}`);
|
|
548
|
-
}
|
|
549
|
-
switch (fieldDef.type) {
|
|
550
|
-
case "number":
|
|
551
|
-
if (typeof value !== "number" && isNaN(Number(value))) {
|
|
552
|
-
errors.push(`Field ${fieldName} must be a number`);
|
|
553
|
-
}
|
|
554
|
-
break;
|
|
555
|
-
case "boolean":
|
|
556
|
-
if (typeof value !== "boolean" && value !== "true" && value !== "false") {
|
|
557
|
-
errors.push(`Field ${fieldName} must be a boolean`);
|
|
558
|
-
}
|
|
559
|
-
break;
|
|
560
|
-
case "datetime":
|
|
561
|
-
if (typeof value === "string" && isNaN(Date.parse(value))) {
|
|
562
|
-
errors.push(`Field ${fieldName} must be a valid datetime`);
|
|
563
|
-
}
|
|
564
|
-
break;
|
|
565
|
-
case "date":
|
|
566
|
-
if (typeof value === "string" && !/^\d{4}-\d{2}-\d{2}$/.test(value)) {
|
|
567
|
-
errors.push(`Field ${fieldName} must be a valid date (YYYY-MM-DD)`);
|
|
568
|
-
}
|
|
569
|
-
break;
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
return { valid: errors.length === 0, errors };
|
|
573
|
-
}
|
|
574
|
-
function serializeFrontmatter(frontmatter) {
|
|
575
|
-
const lines = ["---"];
|
|
576
|
-
for (const [key, value] of Object.entries(frontmatter)) {
|
|
577
|
-
if (value === void 0 || value === null) continue;
|
|
578
|
-
if (Array.isArray(value)) {
|
|
579
|
-
lines.push(`${key}:`);
|
|
580
|
-
for (const item of value) {
|
|
581
|
-
lines.push(` - ${item}`);
|
|
582
|
-
}
|
|
583
|
-
} else if (typeof value === "object") {
|
|
584
|
-
lines.push(`${key}: ${JSON.stringify(value)}`);
|
|
585
|
-
} else if (typeof value === "string" && value.includes("\n")) {
|
|
586
|
-
lines.push(`${key}: |`);
|
|
587
|
-
for (const line of value.split("\n")) {
|
|
588
|
-
lines.push(` ${line}`);
|
|
589
|
-
}
|
|
590
|
-
} else {
|
|
591
|
-
lines.push(`${key}: ${value}`);
|
|
592
|
-
}
|
|
593
|
-
}
|
|
594
|
-
lines.push("---");
|
|
595
|
-
return lines.join("\n");
|
|
596
|
-
}
|
|
597
|
-
|
|
598
|
-
// src/plugin/observe.ts
|
|
599
|
-
function isObservable(text) {
|
|
600
|
-
if (!text || text.length < 20 || text.length > 5e3) return false;
|
|
601
|
-
if (text.includes("<relevant-memories>")) return false;
|
|
602
|
-
if (text.startsWith("[System")) return false;
|
|
603
|
-
if (text.includes("HEARTBEAT")) return false;
|
|
604
|
-
if (text.startsWith("NO_REPLY")) return false;
|
|
605
|
-
if (text.startsWith("{") && text.includes('"')) return false;
|
|
606
|
-
const markdownDensity = (text.match(/[#*`\-|>]/g) || []).length / text.length;
|
|
607
|
-
if (markdownDensity > 0.15) return false;
|
|
608
|
-
return true;
|
|
609
|
-
}
|
|
610
|
-
var OBSERVATION_PATTERNS = [
|
|
611
|
-
// Preferences
|
|
612
|
-
{ pattern: /\b(i prefer|i like|i hate|i love|i want|i need|i always|i never|don't like|dont like)\b/i, weight: 2 },
|
|
613
|
-
// Decisions
|
|
614
|
-
{ pattern: /\b(we decided|let's go with|we're going|i chose|we'll use|ship it|do it|go with)\b/i, weight: 2 },
|
|
615
|
-
// Facts about people/things
|
|
616
|
-
{ pattern: /\b(my .+ is|his .+ is|her .+ is|their .+ is|works at|lives in|born in)\b/i, weight: 1.5 },
|
|
617
|
-
// Contact info
|
|
618
|
-
{ pattern: /[\w.-]+@[\w.-]+\.\w+|\+\d{10,}/i, weight: 2 },
|
|
619
|
-
// Explicit memory request
|
|
620
|
-
{ pattern: /\b(remember|don't forget|keep in mind|note that|important:)\b/i, weight: 2.5 },
|
|
621
|
-
// Deadlines/dates
|
|
622
|
-
{ pattern: /\b(by tonight|by tomorrow|deadline|due date|by end of|ship by|ready by)\b/i, weight: 1.5 },
|
|
623
|
-
// Lessons learned
|
|
624
|
-
{ pattern: /\b(i learned|we learned|lesson|realized|discovered|found out)\b/i, weight: 1.5 },
|
|
625
|
-
// Tasks
|
|
626
|
-
{ pattern: /\b(need to|should|must|have to|todo|task)\b/i, weight: 1 },
|
|
627
|
-
// Projects
|
|
628
|
-
{ pattern: /\b(working on|building|developing|project|initiative)\b/i, weight: 1 }
|
|
629
|
-
];
|
|
630
|
-
function extractObservations(text) {
|
|
631
|
-
const observations = [];
|
|
632
|
-
const sentences = splitIntoSentences(text);
|
|
633
|
-
const now = /* @__PURE__ */ new Date();
|
|
634
|
-
for (const sentence of sentences) {
|
|
635
|
-
if (sentence.length < 15) continue;
|
|
636
|
-
let totalWeight = 0;
|
|
637
|
-
for (const { pattern, weight } of OBSERVATION_PATTERNS) {
|
|
638
|
-
if (pattern.test(sentence)) {
|
|
639
|
-
totalWeight += weight;
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
if (totalWeight < 1) continue;
|
|
643
|
-
const classification = classifyText(sentence);
|
|
644
|
-
const category = deriveCategoryFromPrimitive(classification.primitiveType, sentence);
|
|
645
|
-
const tags = generateTags(classification, sentence);
|
|
646
|
-
observations.push({
|
|
647
|
-
text: sentence.trim(),
|
|
648
|
-
primitiveType: classification.primitiveType,
|
|
649
|
-
confidence: classification.confidence,
|
|
650
|
-
matchedKeywords: classification.matchedKeywords,
|
|
651
|
-
category,
|
|
652
|
-
tags,
|
|
653
|
-
extractedAt: now
|
|
654
|
-
});
|
|
655
|
-
}
|
|
656
|
-
return observations;
|
|
657
|
-
}
|
|
658
|
-
function splitIntoSentences(text) {
|
|
659
|
-
const raw = text.split(/(?<=[.!?\n])\s+/);
|
|
660
|
-
const sentences = [];
|
|
661
|
-
for (const s of raw) {
|
|
662
|
-
const trimmed = s.trim();
|
|
663
|
-
if (trimmed.length > 0) {
|
|
664
|
-
sentences.push(trimmed);
|
|
665
|
-
}
|
|
666
|
-
}
|
|
667
|
-
return sentences;
|
|
668
|
-
}
|
|
669
|
-
function deriveCategoryFromPrimitive(primitiveType, text) {
|
|
670
|
-
const lower = text.toLowerCase();
|
|
671
|
-
if (primitiveType === "memory_event") {
|
|
672
|
-
if (/prefer|like|love|hate|want|need|always|never/i.test(lower)) {
|
|
673
|
-
return "preference";
|
|
674
|
-
}
|
|
675
|
-
if (/remember|don't forget|keep in mind|note that/i.test(lower)) {
|
|
676
|
-
return "note";
|
|
677
|
-
}
|
|
678
|
-
return "fact";
|
|
679
|
-
}
|
|
680
|
-
const categoryMap = {
|
|
681
|
-
person: "entity",
|
|
682
|
-
decision: "decision",
|
|
683
|
-
task: "task",
|
|
684
|
-
project: "project",
|
|
685
|
-
lesson: "lesson",
|
|
686
|
-
trigger: "automation",
|
|
687
|
-
run: "execution",
|
|
688
|
-
checkpoint: "checkpoint",
|
|
689
|
-
handoff: "handoff",
|
|
690
|
-
"daily-note": "daily",
|
|
691
|
-
daily: "daily",
|
|
692
|
-
party: "entity",
|
|
693
|
-
workspace: "workspace"
|
|
694
|
-
};
|
|
695
|
-
return categoryMap[primitiveType] ?? "fact";
|
|
696
|
-
}
|
|
697
|
-
function generateTags(classification, text) {
|
|
698
|
-
const tags = [classification.primitiveType];
|
|
699
|
-
const lower = text.toLowerCase();
|
|
700
|
-
if (/prefer|like|love/i.test(lower)) tags.push("positive");
|
|
701
|
-
if (/hate|dislike|don't like/i.test(lower)) tags.push("negative");
|
|
702
|
-
if (/deadline|due|by tomorrow|by tonight/i.test(lower)) tags.push("time-sensitive");
|
|
703
|
-
if (/important|critical|urgent/i.test(lower)) tags.push("high-priority");
|
|
704
|
-
if (/email|phone|contact/i.test(lower)) tags.push("contact-info");
|
|
705
|
-
if (/decided|chose|approved/i.test(lower)) tags.push("finalized");
|
|
706
|
-
if (/proposed|considering|might/i.test(lower)) tags.push("tentative");
|
|
707
|
-
return [...new Set(tags)];
|
|
708
|
-
}
|
|
709
|
-
function processMessageForObservations(content, options = {}) {
|
|
710
|
-
if (!isObservable(content)) {
|
|
711
|
-
return {
|
|
712
|
-
observations: [],
|
|
713
|
-
skipped: 1,
|
|
714
|
-
reason: "Content not observable"
|
|
715
|
-
};
|
|
716
|
-
}
|
|
717
|
-
const observations = extractObservations(content);
|
|
718
|
-
const maxObservations = 5;
|
|
719
|
-
const limited = observations.slice(0, maxObservations);
|
|
720
|
-
const skipped = observations.length - limited.length;
|
|
721
|
-
return {
|
|
722
|
-
observations: limited,
|
|
723
|
-
skipped,
|
|
724
|
-
reason: skipped > 0 ? `Limited to ${maxObservations} observations` : void 0
|
|
725
|
-
};
|
|
726
|
-
}
|
|
727
|
-
function detectCategory(text) {
|
|
728
|
-
const classification = classifyText(text);
|
|
729
|
-
return deriveCategoryFromPrimitive(classification.primitiveType, text);
|
|
730
|
-
}
|
|
731
|
-
function extractSearchTerms(input) {
|
|
732
|
-
const noise = /\b(hey|hi|hello|um|uh|like|just|so|well|you know|i mean|basically|actually|really|very|pretty|quite|how does it feel|how do you|can you|could you|would you|do you|what do you think|tell me about)\b/gi;
|
|
733
|
-
let cleaned = input.replace(noise, " ").replace(/\s+/g, " ").trim();
|
|
734
|
-
if (cleaned.length < 5) cleaned = input.trim();
|
|
735
|
-
return cleaned;
|
|
736
|
-
}
|
|
737
|
-
|
|
738
|
-
// src/plugin/inject.ts
|
|
739
|
-
var import_node_fs2 = require("fs");
|
|
740
|
-
var import_node_path2 = require("path");
|
|
741
|
-
function parseYamlFrontmatter2(content) {
|
|
742
|
-
const match = content.match(/^---\n([\s\S]*?)\n---\n?([\s\S]*)$/);
|
|
743
|
-
if (!match) return null;
|
|
744
|
-
const yamlContent = match[1];
|
|
745
|
-
const body = match[2];
|
|
746
|
-
try {
|
|
747
|
-
const frontmatter = parseSimpleYaml2(yamlContent);
|
|
748
|
-
return { frontmatter, body };
|
|
749
|
-
} catch {
|
|
750
|
-
return null;
|
|
751
|
-
}
|
|
752
|
-
}
|
|
753
|
-
function parseSimpleYaml2(yaml) {
|
|
754
|
-
const result = {};
|
|
755
|
-
const lines = yaml.split("\n");
|
|
756
|
-
for (const line of lines) {
|
|
757
|
-
if (!line.trim() || line.trim().startsWith("#")) continue;
|
|
758
|
-
const colonIndex = line.indexOf(":");
|
|
759
|
-
if (colonIndex === -1) continue;
|
|
760
|
-
const key = line.slice(0, colonIndex).trim();
|
|
761
|
-
const valueStr = line.slice(colonIndex + 1).trim();
|
|
762
|
-
if (valueStr === "" || valueStr.startsWith("|") || valueStr.startsWith(">")) continue;
|
|
763
|
-
result[key] = parseYamlValue2(valueStr);
|
|
764
|
-
}
|
|
765
|
-
return result;
|
|
766
|
-
}
|
|
767
|
-
function parseYamlValue2(value) {
|
|
768
|
-
if (value === "" || value === "null" || value === "~") return null;
|
|
769
|
-
if (value === "true") return true;
|
|
770
|
-
if (value === "false") return false;
|
|
771
|
-
if (/^-?\d+$/.test(value)) return parseInt(value, 10);
|
|
772
|
-
if (/^-?\d+\.\d+$/.test(value)) return parseFloat(value);
|
|
773
|
-
if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) {
|
|
774
|
-
return value.slice(1, -1);
|
|
775
|
-
}
|
|
776
|
-
return value;
|
|
777
|
-
}
|
|
778
|
-
function scanVaultFiles(vaultPath, options = {}) {
|
|
779
|
-
const files = [];
|
|
780
|
-
const maxAge = options.maxAge ?? 7 * 24 * 60 * 60 * 1e3;
|
|
781
|
-
const limit = options.limit ?? 100;
|
|
782
|
-
const now = Date.now();
|
|
783
|
-
const cutoff = now - maxAge;
|
|
784
|
-
const dirsToScan = findVaultDirectories(vaultPath);
|
|
785
|
-
for (const dir of dirsToScan) {
|
|
786
|
-
if (!(0, import_node_fs2.existsSync)(dir)) continue;
|
|
787
|
-
try {
|
|
788
|
-
scanDirectory(dir, vaultPath, files, cutoff, options.primitiveTypes);
|
|
789
|
-
} catch {
|
|
790
|
-
}
|
|
791
|
-
}
|
|
792
|
-
files.sort((a, b) => b.modifiedAt.getTime() - a.modifiedAt.getTime());
|
|
793
|
-
return files.slice(0, limit);
|
|
794
|
-
}
|
|
795
|
-
function findVaultDirectories(vaultPath) {
|
|
796
|
-
const dirs = [];
|
|
797
|
-
dirs.push(vaultPath);
|
|
798
|
-
const commonDirs = [
|
|
799
|
-
"tasks",
|
|
800
|
-
"projects",
|
|
801
|
-
"decisions",
|
|
802
|
-
"people",
|
|
803
|
-
"persons",
|
|
804
|
-
"notes",
|
|
805
|
-
"daily",
|
|
806
|
-
"journal",
|
|
807
|
-
"ledger",
|
|
808
|
-
"memory",
|
|
809
|
-
"memories",
|
|
810
|
-
"observations",
|
|
811
|
-
"lessons",
|
|
812
|
-
"triggers",
|
|
813
|
-
"runs",
|
|
814
|
-
"checkpoints",
|
|
815
|
-
"handoffs",
|
|
816
|
-
"workspaces",
|
|
817
|
-
"parties"
|
|
818
|
-
];
|
|
819
|
-
for (const subdir of commonDirs) {
|
|
820
|
-
const fullPath = (0, import_node_path2.join)(vaultPath, subdir);
|
|
821
|
-
if ((0, import_node_fs2.existsSync)(fullPath)) {
|
|
822
|
-
dirs.push(fullPath);
|
|
823
|
-
}
|
|
824
|
-
}
|
|
825
|
-
try {
|
|
826
|
-
const entries = (0, import_node_fs2.readdirSync)(vaultPath, { withFileTypes: true });
|
|
827
|
-
for (const entry of entries) {
|
|
828
|
-
if (entry.isDirectory() && !entry.name.startsWith(".") && !entry.name.startsWith("_")) {
|
|
829
|
-
const fullPath = (0, import_node_path2.join)(vaultPath, entry.name);
|
|
830
|
-
if (!dirs.includes(fullPath)) {
|
|
831
|
-
dirs.push(fullPath);
|
|
832
|
-
}
|
|
833
|
-
}
|
|
834
|
-
}
|
|
835
|
-
} catch {
|
|
836
|
-
}
|
|
837
|
-
return dirs;
|
|
838
|
-
}
|
|
839
|
-
function scanDirectory(dir, vaultPath, files, cutoff, primitiveTypes) {
|
|
840
|
-
const entries = (0, import_node_fs2.readdirSync)(dir, { withFileTypes: true });
|
|
841
|
-
for (const entry of entries) {
|
|
842
|
-
if (entry.name.startsWith(".") || entry.name.startsWith("_")) continue;
|
|
843
|
-
const fullPath = (0, import_node_path2.join)(dir, entry.name);
|
|
844
|
-
if (entry.isDirectory()) {
|
|
845
|
-
const depth = fullPath.replace(vaultPath, "").split("/").length;
|
|
846
|
-
if (depth <= 3) {
|
|
847
|
-
scanDirectory(fullPath, vaultPath, files, cutoff, primitiveTypes);
|
|
848
|
-
}
|
|
849
|
-
} else if (entry.name.endsWith(".md")) {
|
|
850
|
-
try {
|
|
851
|
-
const stat = (0, import_node_fs2.statSync)(fullPath);
|
|
852
|
-
if (stat.mtimeMs < cutoff) continue;
|
|
853
|
-
const content = (0, import_node_fs2.readFileSync)(fullPath, "utf-8");
|
|
854
|
-
const parsed = parseYamlFrontmatter2(content);
|
|
855
|
-
if (!parsed) continue;
|
|
856
|
-
const primitiveType = detectPrimitiveType(parsed.frontmatter, fullPath);
|
|
857
|
-
if (primitiveTypes && !primitiveTypes.includes(primitiveType)) continue;
|
|
858
|
-
files.push({
|
|
859
|
-
path: fullPath,
|
|
860
|
-
relativePath: (0, import_node_path2.relative)(vaultPath, fullPath),
|
|
861
|
-
primitiveType,
|
|
862
|
-
frontmatter: parsed.frontmatter,
|
|
863
|
-
content: parsed.body,
|
|
864
|
-
modifiedAt: stat.mtime,
|
|
865
|
-
createdAt: stat.birthtime
|
|
866
|
-
});
|
|
867
|
-
} catch {
|
|
868
|
-
}
|
|
869
|
-
}
|
|
870
|
-
}
|
|
871
|
-
}
|
|
872
|
-
function detectPrimitiveType(frontmatter, filePath) {
|
|
873
|
-
if (frontmatter.primitive) return String(frontmatter.primitive);
|
|
874
|
-
if (frontmatter.type) return String(frontmatter.type);
|
|
875
|
-
const pathLower = filePath.toLowerCase();
|
|
876
|
-
if (pathLower.includes("/tasks/")) return "task";
|
|
877
|
-
if (pathLower.includes("/projects/")) return "project";
|
|
878
|
-
if (pathLower.includes("/decisions/")) return "decision";
|
|
879
|
-
if (pathLower.includes("/people/") || pathLower.includes("/persons/")) return "person";
|
|
880
|
-
if (pathLower.includes("/daily/") || pathLower.includes("/journal/")) return "daily-note";
|
|
881
|
-
if (pathLower.includes("/lessons/")) return "lesson";
|
|
882
|
-
if (pathLower.includes("/triggers/")) return "trigger";
|
|
883
|
-
if (pathLower.includes("/runs/")) return "run";
|
|
884
|
-
if (pathLower.includes("/checkpoints/")) return "checkpoint";
|
|
885
|
-
if (pathLower.includes("/handoffs/")) return "handoff";
|
|
886
|
-
if (pathLower.includes("/ledger/")) return "memory_event";
|
|
887
|
-
if (pathLower.includes("/memory/") || pathLower.includes("/memories/")) return "memory_event";
|
|
888
|
-
return "unknown";
|
|
889
|
-
}
|
|
890
|
-
function buildSessionRecap(vaultPath, options = {}) {
|
|
891
|
-
const maxAge = options.maxAge ?? 24 * 60 * 60 * 1e3;
|
|
892
|
-
const limit = options.limit ?? 20;
|
|
893
|
-
const includeContent = options.includeContent ?? false;
|
|
894
|
-
const files = scanVaultFiles(vaultPath, { maxAge, limit });
|
|
895
|
-
if (files.length === 0) {
|
|
896
|
-
return {
|
|
897
|
-
xml: "",
|
|
898
|
-
fileCount: 0,
|
|
899
|
-
primitiveGroups: {},
|
|
900
|
-
timeRange: null
|
|
901
|
-
};
|
|
902
|
-
}
|
|
903
|
-
const groups = {};
|
|
904
|
-
for (const file of files) {
|
|
905
|
-
const type = file.primitiveType;
|
|
906
|
-
if (!groups[type]) groups[type] = [];
|
|
907
|
-
groups[type].push(file);
|
|
908
|
-
}
|
|
909
|
-
const lines = ["<session-recap>"];
|
|
910
|
-
lines.push(`<summary>Found ${files.length} recent items across ${Object.keys(groups).length} categories</summary>`);
|
|
911
|
-
for (const [primitiveType, groupFiles] of Object.entries(groups)) {
|
|
912
|
-
lines.push(`<${primitiveType}-items count="${groupFiles.length}">`);
|
|
913
|
-
for (const file of groupFiles.slice(0, 5)) {
|
|
914
|
-
const title = file.frontmatter.title || file.frontmatter.summary || file.relativePath;
|
|
915
|
-
const status = file.frontmatter.status || "";
|
|
916
|
-
const modified = file.modifiedAt.toISOString().slice(0, 16).replace("T", " ");
|
|
917
|
-
lines.push(` <item path="${file.relativePath}" modified="${modified}"${status ? ` status="${status}"` : ""}>`);
|
|
918
|
-
lines.push(` <title>${escapeXml(String(title))}</title>`);
|
|
919
|
-
if (includeContent && file.content) {
|
|
920
|
-
const snippet = file.content.slice(0, 200).replace(/\n/g, " ").trim();
|
|
921
|
-
if (snippet) {
|
|
922
|
-
lines.push(` <snippet>${escapeXml(snippet)}</snippet>`);
|
|
923
|
-
}
|
|
924
|
-
}
|
|
925
|
-
lines.push(" </item>");
|
|
926
|
-
}
|
|
927
|
-
if (groupFiles.length > 5) {
|
|
928
|
-
lines.push(` <more count="${groupFiles.length - 5}" />`);
|
|
929
|
-
}
|
|
930
|
-
lines.push(`</${primitiveType}-items>`);
|
|
931
|
-
}
|
|
932
|
-
lines.push("</session-recap>");
|
|
933
|
-
const sortedByTime = [...files].sort((a, b) => a.modifiedAt.getTime() - b.modifiedAt.getTime());
|
|
934
|
-
const timeRange = {
|
|
935
|
-
oldest: sortedByTime[0].modifiedAt,
|
|
936
|
-
newest: sortedByTime[sortedByTime.length - 1].modifiedAt
|
|
937
|
-
};
|
|
938
|
-
const primitiveGroups = {};
|
|
939
|
-
for (const [type, groupFiles] of Object.entries(groups)) {
|
|
940
|
-
primitiveGroups[type] = groupFiles.length;
|
|
941
|
-
}
|
|
942
|
-
return {
|
|
943
|
-
xml: lines.join("\n"),
|
|
944
|
-
fileCount: files.length,
|
|
945
|
-
primitiveGroups,
|
|
946
|
-
timeRange
|
|
947
|
-
};
|
|
948
|
-
}
|
|
949
|
-
function buildPreferenceContext(vaultPath, options = {}) {
|
|
950
|
-
const maxAge = options.maxAge ?? 30 * 24 * 60 * 60 * 1e3;
|
|
951
|
-
const limit = options.limit ?? 50;
|
|
952
|
-
const files = scanVaultFiles(vaultPath, { maxAge, limit: limit * 2 });
|
|
953
|
-
const preferenceFiles = files.filter((file) => {
|
|
954
|
-
if (file.frontmatter.type === "preference") return true;
|
|
955
|
-
if (file.primitiveType === "memory_event" && file.frontmatter.type === "preference") return true;
|
|
956
|
-
const content = (file.content || "").toLowerCase();
|
|
957
|
-
if (/\b(prefer|like|love|hate|dislike|want|need|always|never)\b/.test(content)) {
|
|
958
|
-
return true;
|
|
959
|
-
}
|
|
960
|
-
return false;
|
|
961
|
-
}).slice(0, limit);
|
|
962
|
-
if (preferenceFiles.length === 0) {
|
|
963
|
-
return {
|
|
964
|
-
xml: "",
|
|
965
|
-
preferenceCount: 0,
|
|
966
|
-
categories: []
|
|
967
|
-
};
|
|
968
|
-
}
|
|
969
|
-
const categories = /* @__PURE__ */ new Set();
|
|
970
|
-
for (const file of preferenceFiles) {
|
|
971
|
-
if (file.frontmatter.category) {
|
|
972
|
-
categories.add(String(file.frontmatter.category));
|
|
973
|
-
}
|
|
974
|
-
}
|
|
975
|
-
const lines = ["<user-preferences>"];
|
|
976
|
-
for (const file of preferenceFiles) {
|
|
977
|
-
const summary = file.frontmatter.summary || file.frontmatter.title || extractPreferenceSummary(file.content);
|
|
978
|
-
if (!summary) continue;
|
|
979
|
-
const category = file.frontmatter.category || "general";
|
|
980
|
-
const sentiment = file.frontmatter.sentiment || inferSentiment(file.content);
|
|
981
|
-
lines.push(` <preference category="${escapeXml(String(category))}" sentiment="${sentiment}">`);
|
|
982
|
-
lines.push(` ${escapeXml(String(summary))}`);
|
|
983
|
-
lines.push(" </preference>");
|
|
984
|
-
}
|
|
985
|
-
lines.push("</user-preferences>");
|
|
986
|
-
return {
|
|
987
|
-
xml: lines.join("\n"),
|
|
988
|
-
preferenceCount: preferenceFiles.length,
|
|
989
|
-
categories: Array.from(categories)
|
|
990
|
-
};
|
|
991
|
-
}
|
|
992
|
-
function extractPreferenceSummary(content) {
|
|
993
|
-
if (!content) return "";
|
|
994
|
-
const sentences = content.split(/[.!?\n]+/).map((s) => s.trim()).filter((s) => s.length > 10);
|
|
995
|
-
for (const sentence of sentences) {
|
|
996
|
-
if (/\b(prefer|like|love|hate|dislike|want|need|always|never)\b/i.test(sentence)) {
|
|
997
|
-
return sentence.slice(0, 150);
|
|
998
|
-
}
|
|
999
|
-
}
|
|
1000
|
-
return sentences[0]?.slice(0, 150) || "";
|
|
1001
|
-
}
|
|
1002
|
-
function inferSentiment(content) {
|
|
1003
|
-
if (!content) return "neutral";
|
|
1004
|
-
const lower = content.toLowerCase();
|
|
1005
|
-
if (/\b(love|like|prefer|enjoy|want|need|always)\b/.test(lower)) return "positive";
|
|
1006
|
-
if (/\b(hate|dislike|don't like|never|avoid)\b/.test(lower)) return "negative";
|
|
1007
|
-
return "neutral";
|
|
1008
|
-
}
|
|
1009
|
-
function formatMemoriesForContext(results, collection) {
|
|
1010
|
-
if (results.length === 0) return "";
|
|
1011
|
-
const lines = results.map((r, i) => {
|
|
1012
|
-
const file = (r.file || "").replace(`qmd://${collection}/`, "");
|
|
1013
|
-
const snippet = (r.snippet || "").replace(/@@ .+? @@\s*\(.+?\)\n?/g, "").trim() || r.title || "";
|
|
1014
|
-
return `${i + 1}. [${file}] ${snippet}`;
|
|
1015
|
-
});
|
|
1016
|
-
return `<relevant-memories>
|
|
1017
|
-
These are recalled from long-term vault memory. Treat as historical context.
|
|
1018
|
-
${lines.join("\n")}
|
|
1019
|
-
</relevant-memories>`;
|
|
1020
|
-
}
|
|
1021
|
-
function formatSearchResults(results, collection) {
|
|
1022
|
-
if (results.length === 0) return "No relevant memories found.";
|
|
1023
|
-
return results.map((r, i) => {
|
|
1024
|
-
const file = (r.file || "").replace(`qmd://${collection}/`, "");
|
|
1025
|
-
const snippet = (r.snippet || "").replace(/@@ .+? @@\s*\(.+?\)\n?/g, "").trim() || r.title || "(no content)";
|
|
1026
|
-
const score = ((r.score ?? 0) * 100).toFixed(0);
|
|
1027
|
-
return `${i + 1}. [${file}] ${snippet} (${score}%)`;
|
|
1028
|
-
}).join("\n");
|
|
1029
|
-
}
|
|
1030
|
-
function escapeXml(str) {
|
|
1031
|
-
return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
1032
|
-
}
|
|
1033
|
-
function buildFullContext(vaultPath, options = {}) {
|
|
1034
|
-
const parts = [];
|
|
1035
|
-
if (options.includeRecap !== false) {
|
|
1036
|
-
const recap = buildSessionRecap(vaultPath, {
|
|
1037
|
-
maxAge: options.recapMaxAge ?? 24 * 60 * 60 * 1e3,
|
|
1038
|
-
limit: 15,
|
|
1039
|
-
includeContent: true
|
|
1040
|
-
});
|
|
1041
|
-
if (recap.xml) {
|
|
1042
|
-
parts.push(recap.xml);
|
|
1043
|
-
}
|
|
1044
|
-
}
|
|
1045
|
-
if (options.includePreferences !== false) {
|
|
1046
|
-
const prefs = buildPreferenceContext(vaultPath, {
|
|
1047
|
-
maxAge: options.preferenceMaxAge ?? 30 * 24 * 60 * 60 * 1e3,
|
|
1048
|
-
limit: 20
|
|
1049
|
-
});
|
|
1050
|
-
if (prefs.xml) {
|
|
1051
|
-
parts.push(prefs.xml);
|
|
1052
|
-
}
|
|
1053
|
-
}
|
|
1054
|
-
return parts.join("\n\n");
|
|
1055
|
-
}
|
|
1056
|
-
|
|
1057
|
-
// src/plugin/vault.ts
|
|
1058
|
-
var import_node_fs3 = require("fs");
|
|
1059
|
-
var import_node_path3 = require("path");
|
|
1060
|
-
function writeVaultFile(vaultPath, options) {
|
|
1061
|
-
const errors = [];
|
|
1062
|
-
const primitiveType = options.primitiveType ?? classifyText(options.content ?? options.title ?? "").primitiveType;
|
|
1063
|
-
const schema = getSchema(primitiveType);
|
|
1064
|
-
const frontmatter = generateFrontmatter(primitiveType, {
|
|
1065
|
-
title: options.title,
|
|
1066
|
-
extraFields: options.extraFields,
|
|
1067
|
-
source: options.source,
|
|
1068
|
-
sessionId: options.sessionId
|
|
1069
|
-
});
|
|
1070
|
-
const validation = validateFrontmatter(primitiveType, frontmatter);
|
|
1071
|
-
if (!validation.valid) {
|
|
1072
|
-
errors.push(...validation.errors);
|
|
1073
|
-
}
|
|
1074
|
-
const directory = options.directory ?? getDefaultDirectory(vaultPath, primitiveType);
|
|
1075
|
-
if (!(0, import_node_fs3.existsSync)(directory)) {
|
|
1076
|
-
(0, import_node_fs3.mkdirSync)(directory, { recursive: true });
|
|
1077
|
-
}
|
|
1078
|
-
const filename = options.filename ?? generateFilename(primitiveType, options.title, frontmatter);
|
|
1079
|
-
const filePath = (0, import_node_path3.join)(directory, filename);
|
|
1080
|
-
const fileExists = (0, import_node_fs3.existsSync)(filePath);
|
|
1081
|
-
if (fileExists && !options.overwrite) {
|
|
1082
|
-
return updateVaultFile(filePath, frontmatter, options.content, primitiveType, errors);
|
|
1083
|
-
}
|
|
1084
|
-
const fileContent = buildFileContent(frontmatter, options.content, schema);
|
|
1085
|
-
try {
|
|
1086
|
-
(0, import_node_fs3.writeFileSync)(filePath, fileContent, "utf-8");
|
|
1087
|
-
return {
|
|
1088
|
-
success: errors.length === 0,
|
|
1089
|
-
path: filePath,
|
|
1090
|
-
primitiveType,
|
|
1091
|
-
errors,
|
|
1092
|
-
created: true,
|
|
1093
|
-
updated: false
|
|
1094
|
-
};
|
|
1095
|
-
} catch (err) {
|
|
1096
|
-
errors.push(`Failed to write file: ${String(err)}`);
|
|
1097
|
-
return {
|
|
1098
|
-
success: false,
|
|
1099
|
-
path: filePath,
|
|
1100
|
-
primitiveType,
|
|
1101
|
-
errors,
|
|
1102
|
-
created: false,
|
|
1103
|
-
updated: false
|
|
1104
|
-
};
|
|
1105
|
-
}
|
|
1106
|
-
}
|
|
1107
|
-
function updateVaultFile(filePath, newFrontmatter, newContent, primitiveType, errors) {
|
|
1108
|
-
try {
|
|
1109
|
-
const existingContent = (0, import_node_fs3.readFileSync)(filePath, "utf-8");
|
|
1110
|
-
const parsed = parseExistingFile(existingContent);
|
|
1111
|
-
if (!parsed) {
|
|
1112
|
-
errors.push("Failed to parse existing file");
|
|
1113
|
-
return {
|
|
1114
|
-
success: false,
|
|
1115
|
-
path: filePath,
|
|
1116
|
-
primitiveType,
|
|
1117
|
-
errors,
|
|
1118
|
-
created: false,
|
|
1119
|
-
updated: false
|
|
1120
|
-
};
|
|
1121
|
-
}
|
|
1122
|
-
const mergedFrontmatter = {
|
|
1123
|
-
...parsed.frontmatter,
|
|
1124
|
-
...newFrontmatter,
|
|
1125
|
-
updated: (/* @__PURE__ */ new Date()).toISOString()
|
|
1126
|
-
};
|
|
1127
|
-
if (parsed.frontmatter.created) {
|
|
1128
|
-
mergedFrontmatter.created = parsed.frontmatter.created;
|
|
1129
|
-
}
|
|
1130
|
-
const content = newContent ?? parsed.body;
|
|
1131
|
-
const schema = getSchema(primitiveType);
|
|
1132
|
-
const fileContent = buildFileContent(mergedFrontmatter, content, schema);
|
|
1133
|
-
(0, import_node_fs3.writeFileSync)(filePath, fileContent, "utf-8");
|
|
1134
|
-
return {
|
|
1135
|
-
success: errors.length === 0,
|
|
1136
|
-
path: filePath,
|
|
1137
|
-
primitiveType,
|
|
1138
|
-
errors,
|
|
1139
|
-
created: false,
|
|
1140
|
-
updated: true
|
|
1141
|
-
};
|
|
1142
|
-
} catch (err) {
|
|
1143
|
-
errors.push(`Failed to update file: ${String(err)}`);
|
|
1144
|
-
return {
|
|
1145
|
-
success: false,
|
|
1146
|
-
path: filePath,
|
|
1147
|
-
primitiveType,
|
|
1148
|
-
errors,
|
|
1149
|
-
created: false,
|
|
1150
|
-
updated: false
|
|
1151
|
-
};
|
|
1152
|
-
}
|
|
1153
|
-
}
|
|
1154
|
-
function parseExistingFile(content) {
|
|
1155
|
-
const match = content.match(/^---\n([\s\S]*?)\n---\n?([\s\S]*)$/);
|
|
1156
|
-
if (!match) return null;
|
|
1157
|
-
try {
|
|
1158
|
-
const frontmatter = parseSimpleYaml3(match[1]);
|
|
1159
|
-
return { frontmatter, body: match[2] };
|
|
1160
|
-
} catch {
|
|
1161
|
-
return null;
|
|
1162
|
-
}
|
|
1163
|
-
}
|
|
1164
|
-
function parseSimpleYaml3(yaml) {
|
|
1165
|
-
const result = {};
|
|
1166
|
-
const lines = yaml.split("\n");
|
|
1167
|
-
for (const line of lines) {
|
|
1168
|
-
if (!line.trim() || line.trim().startsWith("#")) continue;
|
|
1169
|
-
const colonIndex = line.indexOf(":");
|
|
1170
|
-
if (colonIndex === -1) continue;
|
|
1171
|
-
const key = line.slice(0, colonIndex).trim();
|
|
1172
|
-
const valueStr = line.slice(colonIndex + 1).trim();
|
|
1173
|
-
if (valueStr === "" || valueStr.startsWith("|") || valueStr.startsWith(">")) continue;
|
|
1174
|
-
result[key] = parseYamlValue3(valueStr);
|
|
1175
|
-
}
|
|
1176
|
-
return result;
|
|
1177
|
-
}
|
|
1178
|
-
function parseYamlValue3(value) {
|
|
1179
|
-
if (value === "" || value === "null" || value === "~") return null;
|
|
1180
|
-
if (value === "true") return true;
|
|
1181
|
-
if (value === "false") return false;
|
|
1182
|
-
if (/^-?\d+$/.test(value)) return parseInt(value, 10);
|
|
1183
|
-
if (/^-?\d+\.\d+$/.test(value)) return parseFloat(value);
|
|
1184
|
-
if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) {
|
|
1185
|
-
return value.slice(1, -1);
|
|
1186
|
-
}
|
|
1187
|
-
return value;
|
|
1188
|
-
}
|
|
1189
|
-
function getDefaultDirectory(vaultPath, primitiveType) {
|
|
1190
|
-
const directoryMap = {
|
|
1191
|
-
task: "tasks",
|
|
1192
|
-
project: "projects",
|
|
1193
|
-
decision: "decisions",
|
|
1194
|
-
person: "people",
|
|
1195
|
-
lesson: "lessons",
|
|
1196
|
-
trigger: "triggers",
|
|
1197
|
-
run: "runs",
|
|
1198
|
-
checkpoint: "checkpoints",
|
|
1199
|
-
handoff: "handoffs",
|
|
1200
|
-
"daily-note": "daily",
|
|
1201
|
-
daily: "daily",
|
|
1202
|
-
party: "parties",
|
|
1203
|
-
workspace: "workspaces",
|
|
1204
|
-
memory_event: "memory"
|
|
1205
|
-
};
|
|
1206
|
-
const subdir = directoryMap[primitiveType] ?? "notes";
|
|
1207
|
-
return (0, import_node_path3.join)(vaultPath, subdir);
|
|
1208
|
-
}
|
|
1209
|
-
function generateFilename(primitiveType, title, frontmatter) {
|
|
1210
|
-
const now = /* @__PURE__ */ new Date();
|
|
1211
|
-
const dateStr = now.toISOString().split("T")[0];
|
|
1212
|
-
const timeStr = now.toISOString().slice(11, 19).replace(/:/g, "");
|
|
1213
|
-
if (title) {
|
|
1214
|
-
const slug = slugify(title);
|
|
1215
|
-
return `${dateStr}-${slug}.md`;
|
|
1216
|
-
}
|
|
1217
|
-
switch (primitiveType) {
|
|
1218
|
-
case "daily-note":
|
|
1219
|
-
case "daily":
|
|
1220
|
-
return `${dateStr}.md`;
|
|
1221
|
-
case "memory_event":
|
|
1222
|
-
return `${dateStr}-${timeStr}.md`;
|
|
1223
|
-
case "run":
|
|
1224
|
-
return `run-${dateStr}-${timeStr}.md`;
|
|
1225
|
-
case "checkpoint":
|
|
1226
|
-
return `checkpoint-${dateStr}-${timeStr}.md`;
|
|
1227
|
-
case "handoff":
|
|
1228
|
-
return `handoff-${dateStr}-${timeStr}.md`;
|
|
1229
|
-
default:
|
|
1230
|
-
return `${primitiveType}-${dateStr}-${timeStr}.md`;
|
|
1231
|
-
}
|
|
1232
|
-
}
|
|
1233
|
-
function slugify(text) {
|
|
1234
|
-
return text.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 50);
|
|
1235
|
-
}
|
|
1236
|
-
function buildFileContent(frontmatter, content, schema) {
|
|
1237
|
-
const parts = [];
|
|
1238
|
-
parts.push(serializeFrontmatter(frontmatter));
|
|
1239
|
-
parts.push("");
|
|
1240
|
-
const title = frontmatter.title || frontmatter.summary;
|
|
1241
|
-
if (title) {
|
|
1242
|
-
parts.push(`# ${title}`);
|
|
1243
|
-
parts.push("");
|
|
1244
|
-
}
|
|
1245
|
-
if (content) {
|
|
1246
|
-
parts.push(content);
|
|
1247
|
-
} else if (schema?.bodyTemplate) {
|
|
1248
|
-
let body = schema.bodyTemplate;
|
|
1249
|
-
body = body.replace(/\{\{title\}\}/g, String(title || "Untitled"));
|
|
1250
|
-
body = body.replace(/\{\{date\}\}/g, (/* @__PURE__ */ new Date()).toISOString().split("T")[0]);
|
|
1251
|
-
body = body.replace(/\{\{datetime\}\}/g, (/* @__PURE__ */ new Date()).toISOString());
|
|
1252
|
-
body = body.replace(/\{\{links_line\}\}/g, "");
|
|
1253
|
-
body = body.replace(/\{\{content\}\}/g, "");
|
|
1254
|
-
parts.push(body.trim());
|
|
1255
|
-
}
|
|
1256
|
-
return parts.join("\n");
|
|
1257
|
-
}
|
|
1258
|
-
function writeObservation(vaultPath, observation, options = {}) {
|
|
1259
|
-
return writeVaultFile(vaultPath, {
|
|
1260
|
-
primitiveType: observation.primitiveType,
|
|
1261
|
-
title: observation.text.slice(0, 80),
|
|
1262
|
-
content: observation.text,
|
|
1263
|
-
extraFields: {
|
|
1264
|
-
type: observation.primitiveType === "memory_event" ? observation.category : observation.primitiveType,
|
|
1265
|
-
confidence: observation.confidence,
|
|
1266
|
-
tags: observation.tags,
|
|
1267
|
-
observed_at: observation.extractedAt.toISOString()
|
|
1268
|
-
},
|
|
1269
|
-
source: options.source ?? "openclaw",
|
|
1270
|
-
sessionId: options.sessionId
|
|
1271
|
-
});
|
|
1272
|
-
}
|
|
1273
|
-
function appendToLedger(vaultPath, entry) {
|
|
1274
|
-
const dateStr = entry.timestamp.toISOString().slice(0, 10);
|
|
1275
|
-
const ledgerDir = (0, import_node_path3.join)(vaultPath, "ledger");
|
|
1276
|
-
if (!(0, import_node_fs3.existsSync)(ledgerDir)) {
|
|
1277
|
-
(0, import_node_fs3.mkdirSync)(ledgerDir, { recursive: true });
|
|
1278
|
-
}
|
|
1279
|
-
const ledgerFile = (0, import_node_path3.join)(ledgerDir, `${dateStr}.md`);
|
|
1280
|
-
const timeStr = entry.timestamp.toISOString().slice(11, 19);
|
|
1281
|
-
const parts = [`[${timeStr}]`];
|
|
1282
|
-
if (entry.category) parts.push(`[${entry.category}]`);
|
|
1283
|
-
if (entry.actor) parts.push(`(${entry.actor})`);
|
|
1284
|
-
parts.push(entry.content);
|
|
1285
|
-
const line = `
|
|
1286
|
-
- ${parts.join(" ")}`;
|
|
1287
|
-
if (!(0, import_node_fs3.existsSync)(ledgerFile)) {
|
|
1288
|
-
const frontmatter = serializeFrontmatter({
|
|
1289
|
-
type: "ledger",
|
|
1290
|
-
date: dateStr,
|
|
1291
|
-
created: entry.timestamp.toISOString()
|
|
1292
|
-
});
|
|
1293
|
-
(0, import_node_fs3.writeFileSync)(ledgerFile, `${frontmatter}
|
|
1294
|
-
|
|
1295
|
-
# Observation Ledger \u2014 ${dateStr}
|
|
1296
|
-
${line}`, "utf-8");
|
|
1297
|
-
} else {
|
|
1298
|
-
(0, import_node_fs3.appendFileSync)(ledgerFile, line, "utf-8");
|
|
1299
|
-
}
|
|
1300
|
-
}
|
|
1301
|
-
function appendObservationToLedger(vaultPath, observation, actor) {
|
|
1302
|
-
appendToLedger(vaultPath, {
|
|
1303
|
-
timestamp: observation.extractedAt,
|
|
1304
|
-
category: observation.category,
|
|
1305
|
-
actor,
|
|
1306
|
-
content: observation.text,
|
|
1307
|
-
primitiveType: observation.primitiveType,
|
|
1308
|
-
tags: observation.tags
|
|
1309
|
-
});
|
|
1310
|
-
}
|
|
1311
|
-
function batchWriteObservations(vaultPath, observations, options = {}) {
|
|
1312
|
-
const results = [];
|
|
1313
|
-
let successful = 0;
|
|
1314
|
-
let failed = 0;
|
|
1315
|
-
const writeLedger = options.writeLedger ?? true;
|
|
1316
|
-
const writeFiles = options.writeFiles ?? false;
|
|
1317
|
-
for (const observation of observations) {
|
|
1318
|
-
if (writeLedger) {
|
|
1319
|
-
try {
|
|
1320
|
-
appendObservationToLedger(vaultPath, observation, options.actor);
|
|
1321
|
-
} catch {
|
|
1322
|
-
}
|
|
1323
|
-
}
|
|
1324
|
-
if (writeFiles) {
|
|
1325
|
-
const result = writeObservation(vaultPath, observation, {
|
|
1326
|
-
source: options.source,
|
|
1327
|
-
sessionId: options.sessionId
|
|
1328
|
-
});
|
|
1329
|
-
results.push(result);
|
|
1330
|
-
if (result.success) {
|
|
1331
|
-
successful++;
|
|
1332
|
-
} else {
|
|
1333
|
-
failed++;
|
|
1334
|
-
}
|
|
1335
|
-
} else {
|
|
1336
|
-
successful++;
|
|
1337
|
-
results.push({
|
|
1338
|
-
success: true,
|
|
1339
|
-
path: (0, import_node_path3.join)(vaultPath, "ledger", `${observation.extractedAt.toISOString().slice(0, 10)}.md`),
|
|
1340
|
-
primitiveType: observation.primitiveType,
|
|
1341
|
-
errors: [],
|
|
1342
|
-
created: false,
|
|
1343
|
-
updated: true
|
|
1344
|
-
});
|
|
1345
|
-
}
|
|
1346
|
-
}
|
|
1347
|
-
return {
|
|
1348
|
-
total: observations.length,
|
|
1349
|
-
successful,
|
|
1350
|
-
failed,
|
|
1351
|
-
results
|
|
1352
|
-
};
|
|
1353
|
-
}
|
|
1354
|
-
function ensureVaultStructure(vaultPath) {
|
|
1355
|
-
const directories = [
|
|
1356
|
-
"tasks",
|
|
1357
|
-
"projects",
|
|
1358
|
-
"decisions",
|
|
1359
|
-
"people",
|
|
1360
|
-
"lessons",
|
|
1361
|
-
"memory",
|
|
1362
|
-
"ledger",
|
|
1363
|
-
"daily"
|
|
1364
|
-
];
|
|
1365
|
-
for (const dir of directories) {
|
|
1366
|
-
const fullPath = (0, import_node_path3.join)(vaultPath, dir);
|
|
1367
|
-
if (!(0, import_node_fs3.existsSync)(fullPath)) {
|
|
1368
|
-
(0, import_node_fs3.mkdirSync)(fullPath, { recursive: true });
|
|
1369
|
-
}
|
|
1370
|
-
}
|
|
1371
|
-
}
|
|
1372
|
-
|
|
1373
|
-
// src/plugin/index.ts
|
|
1374
|
-
function resolveVaultPath(cfg) {
|
|
1375
|
-
if (cfg?.vaultPath) return cfg.vaultPath;
|
|
1376
|
-
if (process.env.CLAWVAULT_PATH) return process.env.CLAWVAULT_PATH;
|
|
1377
|
-
const home = process.env.HOME ?? process.env.USERPROFILE ?? ".";
|
|
1378
|
-
for (const candidate of [`${home}/clawvault`, `${home}/.clawvault`]) {
|
|
1379
|
-
if ((0, import_node_fs4.existsSync)((0, import_node_path4.join)(candidate, ".clawvault.json"))) return candidate;
|
|
1380
|
-
}
|
|
1381
|
-
return `${home}/.clawvault`;
|
|
1382
|
-
}
|
|
1383
|
-
function getVaultConfig(vaultPath) {
|
|
1384
|
-
const configPath = (0, import_node_path4.join)(vaultPath, ".clawvault.json");
|
|
1385
|
-
if (!(0, import_node_fs4.existsSync)(configPath)) return null;
|
|
1386
|
-
try {
|
|
1387
|
-
return JSON.parse((0, import_node_fs4.readFileSync)(configPath, "utf-8"));
|
|
1388
|
-
} catch {
|
|
1389
|
-
return null;
|
|
1390
|
-
}
|
|
1391
|
-
}
|
|
1392
|
-
function qmdHybridSearch(query, collection, limit = 10) {
|
|
1393
|
-
const sanitized = query.replace(/['']/g, " ").replace(/[^\w\s\-.,?!]/g, " ").trim();
|
|
1394
|
-
if (!sanitized) return [];
|
|
1395
|
-
try {
|
|
1396
|
-
const result = (0, import_node_child_process.execFileSync)("qmd", [
|
|
1397
|
-
"query",
|
|
1398
|
-
sanitized,
|
|
1399
|
-
"-n",
|
|
1400
|
-
String(limit),
|
|
1401
|
-
"--json",
|
|
1402
|
-
"-c",
|
|
1403
|
-
collection
|
|
1404
|
-
], { encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"], maxBuffer: 10 * 1024 * 1024, timeout: 3e4 });
|
|
1405
|
-
const parsed = JSON.parse(result);
|
|
1406
|
-
if (Array.isArray(parsed) && parsed.length > 0) return parsed;
|
|
1407
|
-
} catch (err) {
|
|
1408
|
-
if (err?.stdout) {
|
|
1409
|
-
try {
|
|
1410
|
-
const parsed = JSON.parse(err.stdout);
|
|
1411
|
-
if (Array.isArray(parsed) && parsed.length > 0) return parsed;
|
|
1412
|
-
} catch {
|
|
1413
|
-
}
|
|
1414
|
-
}
|
|
1415
|
-
}
|
|
1416
|
-
try {
|
|
1417
|
-
const result = (0, import_node_child_process.execFileSync)("qmd", [
|
|
1418
|
-
"search",
|
|
1419
|
-
sanitized,
|
|
1420
|
-
"-n",
|
|
1421
|
-
String(limit),
|
|
1422
|
-
"--json",
|
|
1423
|
-
"-c",
|
|
1424
|
-
collection
|
|
1425
|
-
], { encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"], maxBuffer: 10 * 1024 * 1024, timeout: 15e3 });
|
|
1426
|
-
return JSON.parse(result);
|
|
1427
|
-
} catch (err) {
|
|
1428
|
-
if (err?.stdout) {
|
|
1429
|
-
try {
|
|
1430
|
-
return JSON.parse(err.stdout);
|
|
1431
|
-
} catch {
|
|
1432
|
-
}
|
|
1433
|
-
}
|
|
1434
|
-
return [];
|
|
1435
|
-
}
|
|
1436
|
-
}
|
|
1437
|
-
function observe(vaultPath, content, meta = {}) {
|
|
1438
|
-
try {
|
|
1439
|
-
const args = ["observe", "--content", content];
|
|
1440
|
-
if (meta.tags?.length) args.push("--tags", meta.tags.join(","));
|
|
1441
|
-
(0, import_node_child_process.execFile)("clawvault", args, { cwd: vaultPath, timeout: 15e3 }, () => {
|
|
1442
|
-
});
|
|
1443
|
-
} catch {
|
|
1444
|
-
}
|
|
1445
|
-
}
|
|
1446
|
-
function qmdUpdateAsync(collection) {
|
|
1447
|
-
try {
|
|
1448
|
-
(0, import_node_child_process.execFile)("qmd", ["update", "-c", collection], { timeout: 3e4 }, () => {
|
|
1449
|
-
});
|
|
1450
|
-
(0, import_node_child_process.execFile)("qmd", ["embed", "-c", collection], { timeout: 6e4 }, () => {
|
|
1451
|
-
});
|
|
1452
|
-
} catch {
|
|
1453
|
-
}
|
|
1454
|
-
}
|
|
1455
|
-
var templateRegistry = null;
|
|
1456
|
-
function getTemplateRegistry2() {
|
|
1457
|
-
return templateRegistry;
|
|
1458
|
-
}
|
|
1459
|
-
var clawvaultPlugin = {
|
|
1460
|
-
id: "clawvault",
|
|
1461
|
-
name: "ClawVault Memory",
|
|
1462
|
-
description: "Template-driven observational memory with hybrid search. Memories are captured automatically from conversations and classified against template schemas.",
|
|
1463
|
-
version: "2.2.0",
|
|
1464
|
-
kind: "memory",
|
|
1465
|
-
register(api) {
|
|
1466
|
-
const vaultPath = resolveVaultPath(api.pluginConfig);
|
|
1467
|
-
const collection = api.pluginConfig?.collection || "clawvault";
|
|
1468
|
-
const autoRecall = api.pluginConfig?.autoRecall !== false;
|
|
1469
|
-
const autoCapture = api.pluginConfig?.autoCapture !== false;
|
|
1470
|
-
const recallLimit = api.pluginConfig?.recallLimit || 5;
|
|
1471
|
-
const templatesDir = api.pluginConfig?.templatesDir ?? (0, import_node_path4.join)(vaultPath, "..", "..", "templates");
|
|
1472
|
-
templateRegistry = initializeTemplateRegistry(templatesDir);
|
|
1473
|
-
api.logger.info(`[clawvault] Template registry initialized with ${templateRegistry.schemas.size} schemas`);
|
|
1474
|
-
if (!(0, import_node_fs4.existsSync)((0, import_node_path4.join)(vaultPath, ".clawvault.json"))) {
|
|
1475
|
-
api.logger.warn(`[clawvault] Vault not found at ${vaultPath}`);
|
|
1476
|
-
return;
|
|
1477
|
-
}
|
|
1478
|
-
ensureVaultStructure(vaultPath);
|
|
1479
|
-
api.logger.info(`[clawvault] v2.2.0 vault=${vaultPath} collection=${collection} recall=${autoRecall} capture=${autoCapture}`);
|
|
1480
|
-
api.registerTool({
|
|
1481
|
-
name: "memory_search",
|
|
1482
|
-
label: "Memory Search",
|
|
1483
|
-
description: "Search through long-term memories using ClawVault. Supports preferences, temporal queries, and multi-session knowledge retrieval.",
|
|
1484
|
-
parameters: import_typebox.Type.Object({
|
|
1485
|
-
query: import_typebox.Type.String({ description: "Search query \u2014 natural language question or keyword search" }),
|
|
1486
|
-
limit: import_typebox.Type.Optional(import_typebox.Type.Number({ description: "Max results (default: 10)" })),
|
|
1487
|
-
queryType: import_typebox.Type.Optional(import_typebox.Type.Union([
|
|
1488
|
-
import_typebox.Type.Literal("preference"),
|
|
1489
|
-
import_typebox.Type.Literal("temporal"),
|
|
1490
|
-
import_typebox.Type.Literal("knowledge"),
|
|
1491
|
-
import_typebox.Type.Literal("general")
|
|
1492
|
-
], { description: "Force query type (auto-detected if omitted)" }))
|
|
1493
|
-
}),
|
|
1494
|
-
async execute(_id, params) {
|
|
1495
|
-
try {
|
|
1496
|
-
let searchQuery = params.query;
|
|
1497
|
-
if (params.queryType === "preference") searchQuery = `preference: ${searchQuery}`;
|
|
1498
|
-
else if (params.queryType === "temporal") searchQuery = `when: ${searchQuery}`;
|
|
1499
|
-
const limit = params.limit || 10;
|
|
1500
|
-
const results = qmdHybridSearch(searchQuery, collection, limit);
|
|
1501
|
-
if (results.length === 0) {
|
|
1502
|
-
return {
|
|
1503
|
-
content: [{ type: "text", text: "No relevant memories found." }],
|
|
1504
|
-
details: { count: 0, provider: "clawvault" }
|
|
1505
|
-
};
|
|
1506
|
-
}
|
|
1507
|
-
return {
|
|
1508
|
-
content: [{ type: "text", text: formatSearchResults(results, collection) }],
|
|
1509
|
-
details: { count: results.length, provider: "clawvault" }
|
|
1510
|
-
};
|
|
1511
|
-
} catch (err) {
|
|
1512
|
-
return {
|
|
1513
|
-
content: [{ type: "text", text: `Memory search error: ${String(err)}` }],
|
|
1514
|
-
isError: true
|
|
1515
|
-
};
|
|
1516
|
-
}
|
|
1517
|
-
}
|
|
1518
|
-
});
|
|
1519
|
-
api.registerTool({
|
|
1520
|
-
name: "memory_get",
|
|
1521
|
-
label: "Memory Get",
|
|
1522
|
-
description: "Get vault status or stored preferences.",
|
|
1523
|
-
parameters: import_typebox.Type.Object({
|
|
1524
|
-
action: import_typebox.Type.Union([
|
|
1525
|
-
import_typebox.Type.Literal("status"),
|
|
1526
|
-
import_typebox.Type.Literal("preferences")
|
|
1527
|
-
], { description: "What to retrieve" })
|
|
1528
|
-
}),
|
|
1529
|
-
async execute(_id, params) {
|
|
1530
|
-
try {
|
|
1531
|
-
if (params.action === "status") {
|
|
1532
|
-
const config = getVaultConfig(vaultPath);
|
|
1533
|
-
let docCount = 0;
|
|
1534
|
-
let vectorCount = 0;
|
|
1535
|
-
try {
|
|
1536
|
-
const stats = (0, import_node_child_process.execFileSync)("qmd", ["status", "--json", "-c", collection], {
|
|
1537
|
-
encoding: "utf-8",
|
|
1538
|
-
timeout: 5e3,
|
|
1539
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
1540
|
-
});
|
|
1541
|
-
const parsed = JSON.parse(stats);
|
|
1542
|
-
docCount = parsed.documents ?? parsed.doc_count ?? 0;
|
|
1543
|
-
vectorCount = parsed.vectors ?? parsed.vector_count ?? 0;
|
|
1544
|
-
} catch {
|
|
1545
|
-
}
|
|
1546
|
-
return {
|
|
1547
|
-
content: [{ type: "text", text: JSON.stringify({
|
|
1548
|
-
vault: vaultPath,
|
|
1549
|
-
name: config?.name || "clawvault",
|
|
1550
|
-
collection,
|
|
1551
|
-
documents: docCount,
|
|
1552
|
-
vectors: vectorCount,
|
|
1553
|
-
autoRecall,
|
|
1554
|
-
autoCapture,
|
|
1555
|
-
version: "2.2.0",
|
|
1556
|
-
templateSchemas: templateRegistry?.schemas.size ?? 0
|
|
1557
|
-
}, null, 2) }]
|
|
1558
|
-
};
|
|
1559
|
-
}
|
|
1560
|
-
const prefContext = buildPreferenceContext(vaultPath, { limit: 20 });
|
|
1561
|
-
if (prefContext.preferenceCount === 0) {
|
|
1562
|
-
const results = qmdHybridSearch("user preference likes dislikes prefers wants", collection, 20);
|
|
1563
|
-
const prefResults = results.filter(
|
|
1564
|
-
(r) => r.file?.includes("preference") || r.snippet?.toLowerCase().match(/prefer|like|want|hate|love|always|never/)
|
|
1565
|
-
);
|
|
1566
|
-
if (prefResults.length === 0) {
|
|
1567
|
-
return { content: [{ type: "text", text: "No preferences found in vault." }] };
|
|
1568
|
-
}
|
|
1569
|
-
const text = prefResults.map((r, i) => {
|
|
1570
|
-
const file = (r.file || "").replace(`qmd://${collection}/`, "");
|
|
1571
|
-
const snippet = (r.snippet || "").replace(/@@ .+? @@\s*\(.+?\)\n?/g, "").trim() || r.title;
|
|
1572
|
-
return `${i + 1}. [${file}] ${snippet}`;
|
|
1573
|
-
}).join("\n");
|
|
1574
|
-
return { content: [{ type: "text", text }] };
|
|
1575
|
-
}
|
|
1576
|
-
return { content: [{ type: "text", text: prefContext.xml }] };
|
|
1577
|
-
} catch (err) {
|
|
1578
|
-
return {
|
|
1579
|
-
content: [{ type: "text", text: `Memory get error: ${String(err)}` }],
|
|
1580
|
-
isError: true
|
|
1581
|
-
};
|
|
1582
|
-
}
|
|
1583
|
-
}
|
|
1584
|
-
});
|
|
1585
|
-
api.registerTool({
|
|
1586
|
-
name: "memory_store",
|
|
1587
|
-
label: "Memory Store",
|
|
1588
|
-
description: "Save important information in long-term memory. Use for preferences, facts, decisions, or anything worth remembering.",
|
|
1589
|
-
parameters: import_typebox.Type.Object({
|
|
1590
|
-
text: import_typebox.Type.String({ description: "Information to remember" }),
|
|
1591
|
-
category: import_typebox.Type.Optional(import_typebox.Type.Union([
|
|
1592
|
-
import_typebox.Type.Literal("preference"),
|
|
1593
|
-
import_typebox.Type.Literal("fact"),
|
|
1594
|
-
import_typebox.Type.Literal("decision"),
|
|
1595
|
-
import_typebox.Type.Literal("entity"),
|
|
1596
|
-
import_typebox.Type.Literal("event"),
|
|
1597
|
-
import_typebox.Type.Literal("other")
|
|
1598
|
-
], { description: "Memory category (auto-detected if omitted)" })),
|
|
1599
|
-
tags: import_typebox.Type.Optional(import_typebox.Type.Array(import_typebox.Type.String(), { description: "Tags for organization" }))
|
|
1600
|
-
}),
|
|
1601
|
-
async execute(_id, params) {
|
|
1602
|
-
try {
|
|
1603
|
-
const classification = classifyText(params.text);
|
|
1604
|
-
const category = params.category || detectCategory(params.text);
|
|
1605
|
-
const tags = params.tags || [category, ...classification.matchedKeywords.slice(0, 3)];
|
|
1606
|
-
const result = writeVaultFile(vaultPath, {
|
|
1607
|
-
primitiveType: classification.primitiveType,
|
|
1608
|
-
title: params.text.slice(0, 80),
|
|
1609
|
-
content: params.text,
|
|
1610
|
-
extraFields: {
|
|
1611
|
-
type: category,
|
|
1612
|
-
confidence: classification.confidence,
|
|
1613
|
-
tags
|
|
1614
|
-
},
|
|
1615
|
-
source: "openclaw"
|
|
1616
|
-
});
|
|
1617
|
-
appendToLedger(vaultPath, {
|
|
1618
|
-
timestamp: /* @__PURE__ */ new Date(),
|
|
1619
|
-
category,
|
|
1620
|
-
content: params.text,
|
|
1621
|
-
primitiveType: classification.primitiveType,
|
|
1622
|
-
tags
|
|
1623
|
-
});
|
|
1624
|
-
qmdUpdateAsync(collection);
|
|
1625
|
-
return {
|
|
1626
|
-
content: [{ type: "text", text: `Stored: "${params.text.slice(0, 100)}${params.text.length > 100 ? "..." : ""}" [${classification.primitiveType}/${category}]` }],
|
|
1627
|
-
details: {
|
|
1628
|
-
action: result.created ? "created" : "updated",
|
|
1629
|
-
category,
|
|
1630
|
-
primitiveType: classification.primitiveType,
|
|
1631
|
-
path: result.path
|
|
1632
|
-
}
|
|
1633
|
-
};
|
|
1634
|
-
} catch (err) {
|
|
1635
|
-
return {
|
|
1636
|
-
content: [{ type: "text", text: `Memory store error: ${String(err)}` }],
|
|
1637
|
-
isError: true
|
|
1638
|
-
};
|
|
1639
|
-
}
|
|
1640
|
-
}
|
|
1641
|
-
});
|
|
1642
|
-
api.registerTool({
|
|
1643
|
-
name: "memory_forget",
|
|
1644
|
-
label: "Memory Forget",
|
|
1645
|
-
description: "Delete specific memories from the vault.",
|
|
1646
|
-
parameters: import_typebox.Type.Object({
|
|
1647
|
-
query: import_typebox.Type.String({ description: "Search query to find the memory to delete" }),
|
|
1648
|
-
confirm: import_typebox.Type.Optional(import_typebox.Type.Boolean({ description: "Set true to confirm deletion of first match" }))
|
|
1649
|
-
}),
|
|
1650
|
-
async execute(_id, params) {
|
|
1651
|
-
try {
|
|
1652
|
-
const results = qmdHybridSearch(params.query, collection, 5);
|
|
1653
|
-
if (results.length === 0) {
|
|
1654
|
-
return {
|
|
1655
|
-
content: [{ type: "text", text: "No matching memories found." }],
|
|
1656
|
-
details: { found: 0 }
|
|
1657
|
-
};
|
|
1658
|
-
}
|
|
1659
|
-
if (!params.confirm) {
|
|
1660
|
-
const list = results.map((r, i) => {
|
|
1661
|
-
const file2 = (r.file || "").replace(`qmd://${collection}/`, "");
|
|
1662
|
-
const snippet = (r.snippet || "").replace(/@@ .+? @@\s*\(.+?\)\n?/g, "").trim().slice(0, 80);
|
|
1663
|
-
return `${i + 1}. [${file2}] ${snippet}`;
|
|
1664
|
-
}).join("\n");
|
|
1665
|
-
return {
|
|
1666
|
-
content: [{ type: "text", text: `Found ${results.length} candidates:
|
|
1667
|
-
${list}
|
|
1668
|
-
|
|
1669
|
-
Call again with confirm=true to delete the top match.` }],
|
|
1670
|
-
details: { action: "candidates", count: results.length }
|
|
1671
|
-
};
|
|
1672
|
-
}
|
|
1673
|
-
const target = results[0];
|
|
1674
|
-
const file = (target.file || "").replace(`qmd://${collection}/`, "");
|
|
1675
|
-
const fullPath = (0, import_node_path4.join)(vaultPath, file);
|
|
1676
|
-
if ((0, import_node_fs4.existsSync)(fullPath)) {
|
|
1677
|
-
const trashDir = (0, import_node_path4.join)(vaultPath, ".trash");
|
|
1678
|
-
if (!(0, import_node_fs4.existsSync)(trashDir)) (0, import_node_fs4.mkdirSync)(trashDir, { recursive: true });
|
|
1679
|
-
const trashPath = (0, import_node_path4.join)(trashDir, `${Date.now()}-${(0, import_node_path4.basename)(file)}`);
|
|
1680
|
-
const { renameSync } = require("fs");
|
|
1681
|
-
renameSync(fullPath, trashPath);
|
|
1682
|
-
qmdUpdateAsync(collection);
|
|
1683
|
-
return {
|
|
1684
|
-
content: [{ type: "text", text: `Forgotten: [${file}] (moved to .trash)` }],
|
|
1685
|
-
details: { action: "deleted", file, trashPath }
|
|
1686
|
-
};
|
|
1687
|
-
}
|
|
1688
|
-
return {
|
|
1689
|
-
content: [{ type: "text", text: `File not found on disk: ${file}` }],
|
|
1690
|
-
details: { action: "not_found", file }
|
|
1691
|
-
};
|
|
1692
|
-
} catch (err) {
|
|
1693
|
-
return {
|
|
1694
|
-
content: [{ type: "text", text: `Memory forget error: ${String(err)}` }],
|
|
1695
|
-
isError: true
|
|
1696
|
-
};
|
|
1697
|
-
}
|
|
1698
|
-
}
|
|
1699
|
-
});
|
|
1700
|
-
if (autoRecall) {
|
|
1701
|
-
api.on("before_agent_start", async (event) => {
|
|
1702
|
-
if (!event.prompt || event.prompt.length < 10) return;
|
|
1703
|
-
if (event.prompt.includes("HEARTBEAT") || event.prompt.startsWith("[System")) return;
|
|
1704
|
-
try {
|
|
1705
|
-
const contextParts = [];
|
|
1706
|
-
const recap = buildSessionRecap(vaultPath, {
|
|
1707
|
-
maxAge: 24 * 60 * 60 * 1e3,
|
|
1708
|
-
// 24 hours
|
|
1709
|
-
limit: 10,
|
|
1710
|
-
includeContent: true
|
|
1711
|
-
});
|
|
1712
|
-
if (recap.xml) {
|
|
1713
|
-
contextParts.push(recap.xml);
|
|
1714
|
-
}
|
|
1715
|
-
const searchTerms = extractSearchTerms(event.prompt);
|
|
1716
|
-
const results = qmdHybridSearch(searchTerms, collection, recallLimit);
|
|
1717
|
-
if (results.length > 0) {
|
|
1718
|
-
const topScore = results[0]?.score ?? 0;
|
|
1719
|
-
if (topScore >= 0.25) {
|
|
1720
|
-
contextParts.push(formatMemoriesForContext(results, collection));
|
|
1721
|
-
api.logger.info(`[clawvault] auto-recall: ${results.length} memories (top: ${(topScore * 100).toFixed(0)}%, query: "${searchTerms.slice(0, 60)}")`);
|
|
1722
|
-
}
|
|
1723
|
-
}
|
|
1724
|
-
if (contextParts.length === 0) return;
|
|
1725
|
-
return {
|
|
1726
|
-
prependContext: contextParts.join("\n\n")
|
|
1727
|
-
};
|
|
1728
|
-
} catch (err) {
|
|
1729
|
-
api.logger.warn(`[clawvault] auto-recall failed: ${String(err)}`);
|
|
1730
|
-
}
|
|
1731
|
-
}, { priority: 10 });
|
|
1732
|
-
}
|
|
1733
|
-
if (autoCapture) {
|
|
1734
|
-
api.on("message_received", async (event) => {
|
|
1735
|
-
if (!event.content || !isObservable(event.content)) return;
|
|
1736
|
-
try {
|
|
1737
|
-
const result = processMessageForObservations(event.content, {
|
|
1738
|
-
from: event.from,
|
|
1739
|
-
sessionId: event.sessionId
|
|
1740
|
-
});
|
|
1741
|
-
if (result.observations.length === 0) return;
|
|
1742
|
-
const writeResult = batchWriteObservations(vaultPath, result.observations, {
|
|
1743
|
-
source: "openclaw",
|
|
1744
|
-
sessionId: event.sessionId,
|
|
1745
|
-
actor: event.from || "user",
|
|
1746
|
-
writeLedger: true,
|
|
1747
|
-
writeFiles: false
|
|
1748
|
-
// Only write to ledger for speed
|
|
1749
|
-
});
|
|
1750
|
-
api.logger.info(`[clawvault] auto-captured ${writeResult.successful} observations from incoming message`);
|
|
1751
|
-
} catch (err) {
|
|
1752
|
-
api.logger.warn(`[clawvault] message capture failed: ${String(err)}`);
|
|
1753
|
-
}
|
|
1754
|
-
});
|
|
1755
|
-
api.on("agent_end", async (event) => {
|
|
1756
|
-
if (!event.success || !event.messages?.length) return;
|
|
1757
|
-
try {
|
|
1758
|
-
let captured = 0;
|
|
1759
|
-
for (const msg of event.messages) {
|
|
1760
|
-
if (!msg || typeof msg !== "object") continue;
|
|
1761
|
-
if (msg.role === "user") {
|
|
1762
|
-
const content = typeof msg.content === "string" ? msg.content : Array.isArray(msg.content) ? msg.content.filter((b) => b?.type === "text").map((b) => b.text).join(" ") : "";
|
|
1763
|
-
if (isObservable(content)) {
|
|
1764
|
-
const result = processMessageForObservations(content);
|
|
1765
|
-
for (const obs of result.observations) {
|
|
1766
|
-
observe(vaultPath, obs.text, { tags: obs.tags });
|
|
1767
|
-
captured++;
|
|
1768
|
-
}
|
|
1769
|
-
}
|
|
1770
|
-
}
|
|
1771
|
-
}
|
|
1772
|
-
if (captured > 0) {
|
|
1773
|
-
api.logger.info(`[clawvault] agent_end: captured ${captured} observations`);
|
|
1774
|
-
qmdUpdateAsync(collection);
|
|
1775
|
-
}
|
|
1776
|
-
} catch (err) {
|
|
1777
|
-
api.logger.warn(`[clawvault] agent_end capture failed: ${String(err)}`);
|
|
1778
|
-
}
|
|
1779
|
-
});
|
|
1780
|
-
}
|
|
1781
|
-
api.on("before_compaction", async () => {
|
|
1782
|
-
try {
|
|
1783
|
-
(0, import_node_child_process.execFileSync)("qmd", ["update", "-c", collection], {
|
|
1784
|
-
timeout: 15e3,
|
|
1785
|
-
encoding: "utf-8",
|
|
1786
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
1787
|
-
});
|
|
1788
|
-
api.logger.info("[clawvault] pre-compaction index update complete");
|
|
1789
|
-
} catch (err) {
|
|
1790
|
-
api.logger.warn(`[clawvault] pre-compaction update failed: ${String(err)}`);
|
|
1791
|
-
}
|
|
1792
|
-
});
|
|
1793
|
-
api.registerService({
|
|
1794
|
-
id: "clawvault",
|
|
1795
|
-
start: () => {
|
|
1796
|
-
api.logger.info(`[clawvault] service started \u2014 vault=${vaultPath}`);
|
|
1797
|
-
qmdUpdateAsync(collection);
|
|
1798
|
-
},
|
|
1799
|
-
stop: () => {
|
|
1800
|
-
api.logger.info("[clawvault] service stopped");
|
|
1801
|
-
}
|
|
1802
|
-
});
|
|
1803
|
-
api.registerCli(
|
|
1804
|
-
({ program }) => {
|
|
1805
|
-
const cmd = program.command("vault").description("ClawVault memory commands");
|
|
1806
|
-
cmd.command("status").action(() => {
|
|
1807
|
-
const config = getVaultConfig(vaultPath);
|
|
1808
|
-
console.log(JSON.stringify({
|
|
1809
|
-
vault: vaultPath,
|
|
1810
|
-
version: "2.2.0",
|
|
1811
|
-
templateSchemas: templateRegistry?.schemas.size ?? 0,
|
|
1812
|
-
...config
|
|
1813
|
-
}, null, 2));
|
|
1814
|
-
});
|
|
1815
|
-
cmd.command("search <query>").option("-n, --limit <n>", "Max results", "10").action((query, opts) => {
|
|
1816
|
-
const results = qmdHybridSearch(query, collection, parseInt(opts.limit));
|
|
1817
|
-
console.log(formatSearchResults(results, collection));
|
|
1818
|
-
});
|
|
1819
|
-
cmd.command("templates").action(() => {
|
|
1820
|
-
const schemas = getAllSchemas();
|
|
1821
|
-
console.log("Registered template schemas:");
|
|
1822
|
-
for (const schema of schemas) {
|
|
1823
|
-
console.log(` - ${schema.primitive}: ${schema.description || "(no description)"}`);
|
|
1824
|
-
console.log(` Fields: ${Object.keys(schema.fields).join(", ")}`);
|
|
1825
|
-
}
|
|
1826
|
-
});
|
|
1827
|
-
cmd.command("classify <text>").action((text) => {
|
|
1828
|
-
const result = classifyText(text);
|
|
1829
|
-
console.log(JSON.stringify(result, null, 2));
|
|
1830
|
-
});
|
|
1831
|
-
},
|
|
1832
|
-
{ commands: ["vault"] }
|
|
1833
|
-
);
|
|
1834
|
-
api.registerCommand({
|
|
1835
|
-
name: "vault",
|
|
1836
|
-
description: "ClawVault status and quick search",
|
|
1837
|
-
acceptsArgs: true,
|
|
1838
|
-
requireAuth: true,
|
|
1839
|
-
handler: (ctx) => {
|
|
1840
|
-
const args = (ctx.args || "").trim();
|
|
1841
|
-
if (!args || args === "status") {
|
|
1842
|
-
const config = getVaultConfig(vaultPath);
|
|
1843
|
-
let docCount = 0, vectorCount = 0;
|
|
1844
|
-
try {
|
|
1845
|
-
const stats = (0, import_node_child_process.execFileSync)("qmd", ["status", "--json", "-c", collection], {
|
|
1846
|
-
encoding: "utf-8",
|
|
1847
|
-
timeout: 5e3,
|
|
1848
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
1849
|
-
});
|
|
1850
|
-
const p = JSON.parse(stats);
|
|
1851
|
-
docCount = p.documents ?? p.doc_count ?? 0;
|
|
1852
|
-
vectorCount = p.vectors ?? p.vector_count ?? 0;
|
|
1853
|
-
} catch {
|
|
1854
|
-
}
|
|
1855
|
-
return {
|
|
1856
|
-
text: `\u{1F9E0} ClawVault v2.2.0
|
|
1857
|
-
Vault: ${vaultPath}
|
|
1858
|
-
Docs: ${docCount} | Vectors: ${vectorCount}
|
|
1859
|
-
Recall: ${autoRecall ? "\u2705" : "\u274C"} | Capture: ${autoCapture ? "\u2705" : "\u274C"}
|
|
1860
|
-
Templates: ${templateRegistry?.schemas.size ?? 0} schemas`
|
|
1861
|
-
};
|
|
1862
|
-
}
|
|
1863
|
-
if (args.startsWith("search ")) {
|
|
1864
|
-
const query = args.slice(7).trim();
|
|
1865
|
-
const results = qmdHybridSearch(query, collection, 5);
|
|
1866
|
-
return { text: formatSearchResults(results, collection) };
|
|
1867
|
-
}
|
|
1868
|
-
if (args === "templates") {
|
|
1869
|
-
const names = getSchemaNames();
|
|
1870
|
-
return { text: `Template schemas: ${names.join(", ")}` };
|
|
1871
|
-
}
|
|
1872
|
-
if (args === "recap") {
|
|
1873
|
-
const recap = buildSessionRecap(vaultPath, { limit: 10, includeContent: true });
|
|
1874
|
-
return { text: recap.xml || "No recent activity found." };
|
|
1875
|
-
}
|
|
1876
|
-
return { text: "Usage: /vault [status|search <query>|templates|recap]" };
|
|
1877
|
-
}
|
|
1878
|
-
});
|
|
1879
|
-
console.log(`[clawvault] v2.2.0 registered \u2014 vault=${vaultPath} templates=${templateRegistry?.schemas.size ?? 0}`);
|
|
1880
|
-
}
|
|
1881
|
-
};
|
|
1882
|
-
var plugin_default = clawvaultPlugin;
|
|
1883
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
1884
|
-
0 && (module.exports = {
|
|
1885
|
-
appendToLedger,
|
|
1886
|
-
batchWriteObservations,
|
|
1887
|
-
buildFullContext,
|
|
1888
|
-
buildPreferenceContext,
|
|
1889
|
-
buildSessionRecap,
|
|
1890
|
-
classifyText,
|
|
1891
|
-
detectCategory,
|
|
1892
|
-
ensureVaultStructure,
|
|
1893
|
-
extractObservations,
|
|
1894
|
-
extractSearchTerms,
|
|
1895
|
-
formatMemoriesForContext,
|
|
1896
|
-
formatSearchResults,
|
|
1897
|
-
getAllSchemas,
|
|
1898
|
-
getSchema,
|
|
1899
|
-
getSchemaNames,
|
|
1900
|
-
getTemplateRegistry,
|
|
1901
|
-
initializeTemplateRegistry,
|
|
1902
|
-
isObservable,
|
|
1903
|
-
processMessageForObservations,
|
|
1904
|
-
scanVaultFiles,
|
|
1905
|
-
writeObservation,
|
|
1906
|
-
writeVaultFile
|
|
1907
|
-
});
|