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