clawvault 3.2.1 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. package/README.md +56 -16
  2. package/bin/clawvault.js +0 -2
  3. package/bin/command-registration.test.js +13 -1
  4. package/bin/help-contract.test.js +14 -0
  5. package/bin/register-core-commands.js +88 -0
  6. package/bin/register-core-commands.test.js +80 -0
  7. package/bin/register-maintenance-commands.js +57 -6
  8. package/bin/register-query-commands.js +10 -28
  9. package/bin/test-helpers/cli-command-fixtures.js +1 -0
  10. package/dist/chunk-2PKBIKDH.js +130 -0
  11. package/dist/{chunk-U67V476Y.js → chunk-2ZDO52B4.js} +18 -1
  12. package/dist/{chunk-ZZA73MFY.js → chunk-33DOSHTA.js} +176 -36
  13. package/dist/{chunk-AZYOKJYC.js → chunk-4PY655YM.js} +13 -1
  14. package/dist/{chunk-2JQ3O2YL.js → chunk-5EFSWZO6.js} +3 -3
  15. package/dist/{chunk-Y3TIJEBP.js → chunk-7SWP5FKU.js} +34 -613
  16. package/dist/{chunk-4VQTUVH7.js → chunk-7YZWHM36.js} +52 -26
  17. package/dist/{chunk-URXDAUVH.js → chunk-AXSJIFOJ.js} +174 -1
  18. package/dist/{chunk-4ITRXIVT.js → chunk-BLQXXX7Q.js} +6 -6
  19. package/dist/chunk-CSHO3PJB.js +684 -0
  20. package/dist/{chunk-S5OJEGFG.js → chunk-DOIUYIXV.js} +2 -2
  21. package/dist/{chunk-YXQCA6B7.js → chunk-DVOUSOR3.js} +112 -7
  22. package/dist/{chunk-YDWHS4LJ.js → chunk-ECGJYWNA.js} +205 -33
  23. package/dist/{chunk-QMHPQYUV.js → chunk-EL6UBSX5.js} +7 -6
  24. package/dist/chunk-FZ5I2NF7.js +352 -0
  25. package/dist/{chunk-WJVWINEM.js → chunk-GFCHWMGD.js} +55 -6
  26. package/dist/{chunk-GNJL4YGR.js → chunk-GJO3CFUN.js} +30 -6
  27. package/dist/chunk-H3JZIB5O.js +322 -0
  28. package/dist/chunk-HEHO7SMV.js +51 -0
  29. package/dist/{chunk-UCQAOZHW.js → chunk-HGDDW24U.js} +3 -3
  30. package/dist/chunk-J3YUXVID.js +907 -0
  31. package/dist/{chunk-Y6VJKXGL.js → chunk-KCYWJDDW.js} +1 -1
  32. package/dist/{chunk-P5EPF6MB.js → chunk-MW5C6ZQA.js} +110 -13
  33. package/dist/{chunk-YNIPYN4F.js → chunk-OFOCU2V4.js} +6 -5
  34. package/dist/{chunk-42MXU7A6.js → chunk-P62WHA27.js} +58 -47
  35. package/dist/chunk-PTWPPVC7.js +972 -0
  36. package/dist/{chunk-FAKNOB7Y.js → chunk-QFWERBDP.js} +2 -2
  37. package/dist/{chunk-IIOU45CK.js → chunk-S7N7HI5E.js} +2 -2
  38. package/dist/{chunk-ECRZL5XR.js → chunk-T7E764W3.js} +23 -7
  39. package/dist/chunk-TDWFBDAQ.js +1016 -0
  40. package/dist/{chunk-MNPUYCHQ.js → chunk-TWMI3SNN.js} +6 -5
  41. package/dist/{chunk-2RAZ4ZFE.js → chunk-VBILES4B.js} +1 -1
  42. package/dist/{chunk-PI4WMLMG.js → chunk-VXAGOLDP.js} +1 -1
  43. package/dist/chunk-YCUVAOFC.js +158 -0
  44. package/dist/{chunk-SS4B7P7V.js → chunk-YIDV4VV2.js} +1 -1
  45. package/dist/chunk-ZKWPCBYT.js +600 -0
  46. package/dist/cli/index.js +27 -21
  47. package/dist/commands/archive.js +3 -3
  48. package/dist/commands/backlog.js +1 -1
  49. package/dist/commands/benchmark.d.ts +12 -0
  50. package/dist/commands/benchmark.js +12 -0
  51. package/dist/commands/blocked.js +1 -1
  52. package/dist/commands/canvas.js +2 -2
  53. package/dist/commands/checkpoint.js +1 -1
  54. package/dist/commands/compat.js +1 -1
  55. package/dist/commands/context.js +8 -7
  56. package/dist/commands/doctor.d.ts +8 -3
  57. package/dist/commands/doctor.js +8 -22
  58. package/dist/commands/embed.js +6 -5
  59. package/dist/commands/entities.js +2 -2
  60. package/dist/commands/graph.js +4 -4
  61. package/dist/commands/inbox.d.ts +23 -0
  62. package/dist/commands/inbox.js +11 -0
  63. package/dist/commands/inject.d.ts +1 -1
  64. package/dist/commands/inject.js +5 -5
  65. package/dist/commands/kanban.js +1 -1
  66. package/dist/commands/link.js +9 -9
  67. package/dist/commands/maintain.d.ts +32 -0
  68. package/dist/commands/maintain.js +12 -0
  69. package/dist/commands/migrate-observations.js +3 -3
  70. package/dist/commands/observe.js +11 -10
  71. package/dist/commands/project.js +2 -2
  72. package/dist/commands/rebuild-embeddings.js +48 -17
  73. package/dist/commands/rebuild.js +9 -8
  74. package/dist/commands/recover.js +1 -1
  75. package/dist/commands/reflect.js +6 -6
  76. package/dist/commands/repair-session.js +1 -1
  77. package/dist/commands/replay.js +10 -9
  78. package/dist/commands/session-recap.js +1 -1
  79. package/dist/commands/setup.js +4 -3
  80. package/dist/commands/shell-init.js +1 -1
  81. package/dist/commands/sleep.d.ts +1 -1
  82. package/dist/commands/sleep.js +20 -18
  83. package/dist/commands/status.js +40 -26
  84. package/dist/commands/sync-bd.js +3 -3
  85. package/dist/commands/tailscale.js +3 -3
  86. package/dist/commands/task.js +1 -1
  87. package/dist/commands/template.js +1 -1
  88. package/dist/commands/wake.d.ts +1 -1
  89. package/dist/commands/wake.js +10 -9
  90. package/dist/index.d.ts +175 -16
  91. package/dist/index.js +277 -108
  92. package/dist/{inject-DYUrDqQO.d.ts → inject-DEb_jpLi.d.ts} +3 -1
  93. package/dist/lib/auto-linker.js +2 -2
  94. package/dist/lib/canvas-layout.js +1 -1
  95. package/dist/lib/config.js +2 -2
  96. package/dist/lib/entity-index.js +1 -1
  97. package/dist/lib/project-utils.js +2 -2
  98. package/dist/lib/session-repair.js +1 -1
  99. package/dist/lib/session-utils.js +1 -1
  100. package/dist/lib/tailscale.js +1 -1
  101. package/dist/lib/task-utils.js +1 -1
  102. package/dist/lib/template-engine.js +1 -1
  103. package/dist/lib/webdav.js +1 -1
  104. package/dist/onnxruntime_binding-5QEF3SUC.node +0 -0
  105. package/dist/onnxruntime_binding-BKPKNEGC.node +0 -0
  106. package/dist/onnxruntime_binding-FMOXGIUT.node +0 -0
  107. package/dist/onnxruntime_binding-OI2KMXC5.node +0 -0
  108. package/dist/onnxruntime_binding-UX44MLAZ.node +0 -0
  109. package/dist/onnxruntime_binding-Y2W7N7WY.node +0 -0
  110. package/dist/openclaw-plugin.d.ts +8 -0
  111. package/dist/openclaw-plugin.js +14 -0
  112. package/dist/transformers.node-A2ZRORSQ.js +46775 -0
  113. package/dist/{types-BbWJoC1c.d.ts → types-DslKvCaj.d.ts} +51 -1
  114. package/hooks/clawvault/HOOK.md +25 -8
  115. package/hooks/clawvault/handler.js +215 -78
  116. package/hooks/clawvault/handler.test.js +109 -43
  117. package/hooks/clawvault/integrity.js +112 -0
  118. package/hooks/clawvault/integrity.test.js +32 -0
  119. package/hooks/clawvault/openclaw.plugin.json +133 -15
  120. package/openclaw.plugin.json +131 -203
  121. package/package.json +10 -7
  122. package/bin/register-workgraph-commands.js +0 -451
  123. package/dist/chunk-5PJ4STIC.js +0 -465
  124. package/dist/chunk-ERNE2FZ5.js +0 -189
  125. package/dist/chunk-HR4KN6S2.js +0 -152
  126. package/dist/chunk-IJBFGPCS.js +0 -33
  127. package/dist/chunk-K7PNYS45.js +0 -93
  128. package/dist/chunk-NTOPJI7W.js +0 -207
  129. package/dist/chunk-PG56HX5T.js +0 -154
  130. package/dist/chunk-QPDDIHXE.js +0 -501
  131. package/dist/chunk-WIOLLGAD.js +0 -190
  132. package/dist/chunk-WMGIIABP.js +0 -15
  133. package/dist/ledger-B7g7jhqG.d.ts +0 -44
  134. package/dist/plugin/index.d.ts +0 -352
  135. package/dist/plugin/index.js +0 -4264
  136. package/dist/registry-BR4326o0.d.ts +0 -30
  137. package/dist/store-CA-6sKCJ.d.ts +0 -34
  138. package/dist/thread-B9LhXNU0.d.ts +0 -41
  139. package/dist/workgraph/index.d.ts +0 -5
  140. package/dist/workgraph/index.js +0 -23
  141. package/dist/workgraph/ledger.d.ts +0 -2
  142. package/dist/workgraph/ledger.js +0 -25
  143. package/dist/workgraph/registry.d.ts +0 -2
  144. package/dist/workgraph/registry.js +0 -19
  145. package/dist/workgraph/store.d.ts +0 -2
  146. package/dist/workgraph/store.js +0 -25
  147. package/dist/workgraph/thread.d.ts +0 -2
  148. package/dist/workgraph/thread.js +0 -25
  149. package/dist/workgraph/types.d.ts +0 -54
  150. package/dist/workgraph/types.js +0 -7
@@ -1,465 +0,0 @@
1
- // src/lib/search.ts
2
- import { execFileSync, spawnSync } from "child_process";
3
- import * as fs from "fs";
4
- import * as path from "path";
5
- var QMD_INSTALL_URL = "https://github.com/tobi/qmd";
6
- var QMD_INSTALL_COMMAND = "bun install -g github:tobi/qmd";
7
- var QMD_INDEX_ENV_VAR = "CLAWVAULT_QMD_INDEX";
8
- var QMD_ERROR_MESSAGES = {
9
- NOT_INSTALLED: {
10
- code: "NOT_INSTALLED",
11
- message: "qmd is not installed",
12
- hint: `Install qmd to enable ClawVault search and indexing:
13
- ${QMD_INSTALL_COMMAND}
14
-
15
- For more information: ${QMD_INSTALL_URL}`
16
- },
17
- NOT_CONFIGURED: {
18
- code: "NOT_CONFIGURED",
19
- message: "qmd collection is not configured",
20
- hint: "Run `clawvault doctor` to diagnose configuration issues, or `clawvault migrate` to fix common setup problems."
21
- },
22
- COLLECTION_NOT_FOUND: {
23
- code: "COLLECTION_NOT_FOUND",
24
- message: "qmd collection not found",
25
- hint: "The configured qmd collection does not exist. Run `clawvault migrate` to recreate it, or `qmd collection add <name> <path>` manually."
26
- },
27
- EXECUTION_FAILED: {
28
- code: "EXECUTION_FAILED",
29
- message: "qmd command failed",
30
- hint: "Run `clawvault doctor` to diagnose qmd issues."
31
- }
32
- };
33
- var QmdUnavailableError = class extends Error {
34
- code;
35
- hint;
36
- constructor(code = "NOT_INSTALLED", additionalContext) {
37
- const details = QMD_ERROR_MESSAGES[code];
38
- const fullMessage = additionalContext ? `${details.message}: ${additionalContext}` : details.message;
39
- super(fullMessage);
40
- this.name = "QmdUnavailableError";
41
- this.code = code;
42
- this.hint = details.hint;
43
- }
44
- toUserMessage() {
45
- return `Error: ${this.message}
46
-
47
- ${this.hint}`;
48
- }
49
- };
50
- function getQmdErrorDetails(code) {
51
- return QMD_ERROR_MESSAGES[code];
52
- }
53
- var QmdConfigurationError = class extends Error {
54
- constructor(message, hint) {
55
- super(message);
56
- this.hint = hint;
57
- this.name = "QmdConfigurationError";
58
- }
59
- };
60
- function ensureJsonArgs(args) {
61
- return args.includes("--json") ? args : [...args, "--json"];
62
- }
63
- function resolveQmdIndexName(indexName) {
64
- const explicit = indexName?.trim();
65
- if (explicit) {
66
- return explicit;
67
- }
68
- const fromEnv = process.env[QMD_INDEX_ENV_VAR]?.trim();
69
- return fromEnv || void 0;
70
- }
71
- function withQmdIndexArgs(args, indexName) {
72
- if (args.includes("--index")) {
73
- return [...args];
74
- }
75
- const resolvedIndexName = resolveQmdIndexName(indexName);
76
- if (!resolvedIndexName) {
77
- return [...args];
78
- }
79
- return ["--index", resolvedIndexName, ...args];
80
- }
81
- function tryParseJson(raw) {
82
- try {
83
- return JSON.parse(raw);
84
- } catch {
85
- return null;
86
- }
87
- }
88
- function extractJsonPayload(raw) {
89
- const start = raw.search(/[\[{]/);
90
- if (start === -1) return null;
91
- const end = Math.max(raw.lastIndexOf("]"), raw.lastIndexOf("}"));
92
- if (end <= start) return null;
93
- return raw.slice(start, end + 1);
94
- }
95
- function stripQmdNoise(raw) {
96
- return raw.split("\n").filter((line) => {
97
- const t = line.trim();
98
- if (!t) return true;
99
- if (t.startsWith("[node-llama-cpp]")) return false;
100
- if (t.startsWith("Expanding query")) return false;
101
- if (t.startsWith("Searching ") && t.endsWith("queries...")) return false;
102
- if (/^[├└─│]/.test(t)) return false;
103
- return true;
104
- }).join("\n");
105
- }
106
- function parseQmdOutput(raw) {
107
- const trimmed = stripQmdNoise(raw).trim();
108
- if (!trimmed) return [];
109
- const direct = tryParseJson(trimmed);
110
- const extracted = direct ? null : extractJsonPayload(trimmed);
111
- const parsed = direct ?? (extracted ? tryParseJson(extracted) : null);
112
- if (!parsed) {
113
- throw new Error("qmd returned non-JSON output. Ensure qmd supports --json.");
114
- }
115
- if (Array.isArray(parsed)) {
116
- return parsed;
117
- }
118
- if (parsed && typeof parsed === "object") {
119
- const candidate = parsed.results ?? parsed.items ?? parsed.data;
120
- if (Array.isArray(candidate)) {
121
- return candidate;
122
- }
123
- }
124
- throw new Error("qmd returned an unexpected JSON shape.");
125
- }
126
- function ensureQmdAvailable() {
127
- if (!hasQmd()) {
128
- throw new QmdUnavailableError("NOT_INSTALLED");
129
- }
130
- }
131
- function detectQmdError(output, args) {
132
- const lowerOutput = output.toLowerCase();
133
- if (lowerOutput.includes("missing required arguments") || lowerOutput.includes("unknown option")) {
134
- return new QmdConfigurationError(
135
- 'qmd does not support the search command with the expected arguments. This may indicate an incompatible qmd version or a different tool named "qmd".',
136
- `Ensure you have the correct qmd installed: ${QMD_INSTALL_COMMAND}`
137
- );
138
- }
139
- if (lowerOutput.includes("collection not found") || lowerOutput.includes("no collection")) {
140
- const collectionArg = args.findIndex((a) => a === "-c");
141
- const collectionName = collectionArg >= 0 && args[collectionArg + 1] ? args[collectionArg + 1] : "unknown";
142
- return new QmdConfigurationError(
143
- `qmd collection "${collectionName}" not found.`,
144
- 'Run `qmd update -c <collection>` to create the collection, or check your vault\'s .clawvault.json "name" field.'
145
- );
146
- }
147
- if (lowerOutput.includes("no index") || lowerOutput.includes("index not found")) {
148
- return new QmdConfigurationError(
149
- "qmd index not found. The vault may not be indexed yet.",
150
- "Run `clawvault rebuild` or `qmd update` to build the search index."
151
- );
152
- }
153
- if (lowerOutput.includes("embedding") && (lowerOutput.includes("not found") || lowerOutput.includes("missing"))) {
154
- return new QmdConfigurationError(
155
- "qmd embeddings not found. Vector search requires embeddings to be generated.",
156
- "Run `clawvault embed` or `qmd embed` to generate embeddings for semantic search."
157
- );
158
- }
159
- return null;
160
- }
161
- function execQmd(args, indexName) {
162
- ensureQmdAvailable();
163
- const finalArgs = withQmdIndexArgs(ensureJsonArgs(args), indexName);
164
- try {
165
- const result = execFileSync("qmd", finalArgs, {
166
- encoding: "utf-8",
167
- stdio: ["ignore", "pipe", "pipe"],
168
- maxBuffer: 10 * 1024 * 1024
169
- // 10MB
170
- });
171
- return parseQmdOutput(result);
172
- } catch (err) {
173
- if (err?.code === "ENOENT") {
174
- throw new QmdUnavailableError("NOT_INSTALLED");
175
- }
176
- const output = [err?.stdout, err?.stderr].filter(Boolean).join("\n");
177
- const detectedError = detectQmdError(output, finalArgs);
178
- if (detectedError) {
179
- throw detectedError;
180
- }
181
- if (output) {
182
- try {
183
- return parseQmdOutput(output);
184
- } catch {
185
- }
186
- if (output.includes("collection not found") || output.includes("no such collection")) {
187
- throw new QmdUnavailableError("COLLECTION_NOT_FOUND", output.trim());
188
- }
189
- }
190
- const errorDetail = err?.message || "unknown error";
191
- throw new QmdUnavailableError("EXECUTION_FAILED", errorDetail);
192
- }
193
- }
194
- function hasQmd() {
195
- const result = spawnSync("qmd", ["--version"], { stdio: "ignore" });
196
- return !result.error;
197
- }
198
- function qmdUpdate(collection, indexName) {
199
- ensureQmdAvailable();
200
- const args = ["update"];
201
- if (collection) {
202
- args.push("-c", collection);
203
- }
204
- execFileSync("qmd", withQmdIndexArgs(args, indexName), { stdio: "inherit" });
205
- }
206
- function qmdEmbed(collection, indexName) {
207
- ensureQmdAvailable();
208
- const args = ["embed"];
209
- if (collection) {
210
- args.push("-c", collection);
211
- }
212
- execFileSync("qmd", withQmdIndexArgs(args, indexName), { stdio: "inherit" });
213
- }
214
- var SearchEngine = class {
215
- documents = /* @__PURE__ */ new Map();
216
- collection = "";
217
- vaultPath = "";
218
- collectionRoot = "";
219
- qmdIndexName;
220
- /**
221
- * Set the collection name (usually vault name)
222
- */
223
- setCollection(name) {
224
- this.collection = name;
225
- }
226
- /**
227
- * Get the current collection name
228
- */
229
- getCollection() {
230
- return this.collection;
231
- }
232
- /**
233
- * Set the vault path for file resolution
234
- */
235
- setVaultPath(vaultPath) {
236
- this.vaultPath = vaultPath;
237
- }
238
- /**
239
- * Set the collection root for qmd:// URI resolution
240
- */
241
- setCollectionRoot(root) {
242
- this.collectionRoot = path.resolve(root);
243
- }
244
- /**
245
- * Set qmd index name (defaults to qmd global default when omitted)
246
- */
247
- setIndexName(indexName) {
248
- this.qmdIndexName = indexName;
249
- }
250
- /**
251
- * Add or update a document in the local cache
252
- * Note: qmd indexing happens via qmd update command
253
- */
254
- addDocument(doc) {
255
- this.documents.set(doc.id, doc);
256
- }
257
- /**
258
- * Remove a document from the local cache
259
- */
260
- removeDocument(id) {
261
- this.documents.delete(id);
262
- }
263
- /**
264
- * No-op for qmd - indexing is managed externally
265
- */
266
- rebuildIDF() {
267
- }
268
- /**
269
- * BM25 search via qmd
270
- */
271
- search(query, options = {}) {
272
- return this.runQmdQuery("search", query, options);
273
- }
274
- /**
275
- * Vector/semantic search via qmd vsearch
276
- */
277
- vsearch(query, options = {}) {
278
- return this.runQmdQuery("vsearch", query, options);
279
- }
280
- /**
281
- * Combined search with query expansion (qmd query command)
282
- */
283
- query(query, options = {}) {
284
- return this.runQmdQuery("query", query, options);
285
- }
286
- runQmdQuery(command, query, options) {
287
- const {
288
- limit = 10,
289
- minScore = 0,
290
- category,
291
- tags,
292
- fullContent = false,
293
- temporalBoost = false
294
- } = options;
295
- if (!query.trim()) return [];
296
- const args = [
297
- command,
298
- query,
299
- "-n",
300
- String(limit * 2),
301
- "--json"
302
- ];
303
- if (this.collection) {
304
- args.push("-c", this.collection);
305
- }
306
- const qmdResults = execQmd(args, this.qmdIndexName);
307
- return this.convertResults(qmdResults, {
308
- limit,
309
- minScore,
310
- category,
311
- tags,
312
- fullContent,
313
- temporalBoost
314
- });
315
- }
316
- /**
317
- * Convert qmd results to ClawVault SearchResult format
318
- */
319
- convertResults(qmdResults, options) {
320
- const { limit = 10, minScore = 0, category, tags, fullContent = false, temporalBoost = false } = options;
321
- const results = [];
322
- const maxScore = qmdResults[0]?.score || 1;
323
- for (const qr of qmdResults) {
324
- const filePath = this.qmdUriToPath(qr.file);
325
- const relativePath = this.vaultPath ? path.relative(this.vaultPath, filePath) : filePath;
326
- const normalizedRelativePath = relativePath.replace(/\\/g, "/");
327
- if (normalizedRelativePath.startsWith("ledger/archive/") || normalizedRelativePath.includes("/ledger/archive/")) {
328
- continue;
329
- }
330
- const docId = normalizedRelativePath.replace(/\.md$/, "");
331
- let doc = this.documents.get(docId) ?? this.documents.get(docId.split("/").join(path.sep));
332
- const modifiedAt = this.resolveModifiedAt(doc, filePath);
333
- const parts = normalizedRelativePath.split("/");
334
- const docCategory = parts.length > 1 ? parts[0] : "root";
335
- if (category && docCategory !== category) continue;
336
- if (tags && tags.length > 0 && doc) {
337
- const docTags = new Set(doc.tags);
338
- if (!tags.some((t) => docTags.has(t))) continue;
339
- }
340
- const normalizedScore = maxScore > 0 ? qr.score / maxScore : 0;
341
- const finalScore = temporalBoost ? normalizedScore * this.getRecencyFactor(modifiedAt) : normalizedScore;
342
- if (finalScore < minScore) continue;
343
- if (!doc) {
344
- doc = {
345
- id: docId,
346
- path: filePath,
347
- category: docCategory,
348
- title: qr.title || path.basename(relativePath, ".md"),
349
- content: "",
350
- // Content loaded separately if needed
351
- frontmatter: {},
352
- links: [],
353
- tags: [],
354
- modified: modifiedAt
355
- };
356
- }
357
- results.push({
358
- document: fullContent ? doc : { ...doc, content: "" },
359
- score: finalScore,
360
- snippet: this.cleanSnippet(qr.snippet),
361
- matchedTerms: []
362
- // qmd doesn't provide this
363
- });
364
- }
365
- return results.sort((a, b) => b.score - a.score).slice(0, limit);
366
- }
367
- resolveModifiedAt(doc, filePath) {
368
- if (doc) return doc.modified;
369
- try {
370
- return fs.statSync(filePath).mtime;
371
- } catch {
372
- return /* @__PURE__ */ new Date(0);
373
- }
374
- }
375
- getRecencyFactor(modifiedAt) {
376
- const ageMs = Math.max(0, Date.now() - modifiedAt.getTime());
377
- const ageDays = ageMs / (24 * 60 * 60 * 1e3);
378
- if (ageDays < 1) return 1;
379
- if (ageDays <= 7) return 0.9;
380
- return 0.7;
381
- }
382
- /**
383
- * Convert qmd:// URI to file path
384
- */
385
- qmdUriToPath(uri) {
386
- if (uri.startsWith("qmd://")) {
387
- const withoutScheme = uri.slice(6);
388
- const slashIndex = withoutScheme.indexOf("/");
389
- if (slashIndex > -1) {
390
- const relativePath = withoutScheme.slice(slashIndex + 1);
391
- const root = this.collectionRoot || this.vaultPath;
392
- if (root) {
393
- return path.join(root, relativePath);
394
- }
395
- return relativePath;
396
- }
397
- }
398
- return uri;
399
- }
400
- /**
401
- * Clean up qmd snippet format
402
- */
403
- cleanSnippet(snippet) {
404
- if (!snippet) return "";
405
- return snippet.replace(/@@ [-+]?\d+,?\d* @@ \([^)]+\)/g, "").trim().split("\n").slice(0, 3).join("\n").slice(0, 300);
406
- }
407
- /**
408
- * Get all cached documents
409
- */
410
- getAllDocuments() {
411
- return [...this.documents.values()];
412
- }
413
- /**
414
- * Get document count
415
- */
416
- get size() {
417
- return this.documents.size;
418
- }
419
- /**
420
- * Clear the local document cache
421
- */
422
- clear() {
423
- this.documents.clear();
424
- }
425
- /**
426
- * Export documents for persistence
427
- */
428
- export() {
429
- return {
430
- documents: [...this.documents.values()]
431
- };
432
- }
433
- /**
434
- * Import from persisted data
435
- */
436
- import(data) {
437
- this.clear();
438
- for (const doc of data.documents) {
439
- this.addDocument(doc);
440
- }
441
- }
442
- };
443
- function extractWikiLinks(content) {
444
- const matches = content.match(/\[\[([^\]]+)\]\]/g) || [];
445
- return matches.map((m) => m.slice(2, -2).toLowerCase());
446
- }
447
- function extractTags(content) {
448
- const matches = content.match(/#[\w-]+/g) || [];
449
- return [...new Set(matches.map((m) => m.slice(1).toLowerCase()))];
450
- }
451
-
452
- export {
453
- QMD_INSTALL_URL,
454
- QMD_INSTALL_COMMAND,
455
- QmdUnavailableError,
456
- getQmdErrorDetails,
457
- QmdConfigurationError,
458
- withQmdIndexArgs,
459
- hasQmd,
460
- qmdUpdate,
461
- qmdEmbed,
462
- SearchEngine,
463
- extractWikiLinks,
464
- extractTags
465
- };
@@ -1,189 +0,0 @@
1
- import {
2
- create,
3
- read,
4
- update
5
- } from "./chunk-HR4KN6S2.js";
6
- import {
7
- append,
8
- currentOwner
9
- } from "./chunk-K7PNYS45.js";
10
- import {
11
- THREAD_STATUS_TRANSITIONS
12
- } from "./chunk-WMGIIABP.js";
13
- import {
14
- __export
15
- } from "./chunk-U67V476Y.js";
16
-
17
- // src/workgraph/thread.ts
18
- var thread_exports = {};
19
- __export(thread_exports, {
20
- block: () => block,
21
- cancel: () => cancel,
22
- claim: () => claim,
23
- createThread: () => createThread,
24
- decompose: () => decompose,
25
- done: () => done,
26
- release: () => release,
27
- unblock: () => unblock
28
- });
29
- function createThread(vaultPath, title, goal, actor, opts = {}) {
30
- return create(vaultPath, "thread", {
31
- title,
32
- goal,
33
- status: "open",
34
- priority: opts.priority ?? "medium",
35
- deps: opts.deps ?? [],
36
- parent: opts.parent,
37
- context_refs: opts.context_refs ?? [],
38
- tags: opts.tags ?? []
39
- }, `## Goal
40
-
41
- ${goal}
42
- `, actor);
43
- }
44
- function claim(vaultPath, threadPath, actor) {
45
- const thread = read(vaultPath, threadPath);
46
- if (!thread) throw new Error(`Thread not found: ${threadPath}`);
47
- const status = thread.fields.status;
48
- if (status !== "open") {
49
- throw new Error(`Cannot claim thread in "${status}" state. Only "open" threads can be claimed.`);
50
- }
51
- const owner = currentOwner(vaultPath, threadPath);
52
- if (owner) {
53
- throw new Error(`Thread already claimed by "${owner}". Wait for release or use a different thread.`);
54
- }
55
- append(vaultPath, actor, "claim", threadPath, "thread");
56
- return update(vaultPath, threadPath, {
57
- status: "active",
58
- owner: actor
59
- }, void 0, actor);
60
- }
61
- function release(vaultPath, threadPath, actor, reason) {
62
- const thread = read(vaultPath, threadPath);
63
- if (!thread) throw new Error(`Thread not found: ${threadPath}`);
64
- assertOwner(vaultPath, threadPath, actor);
65
- append(
66
- vaultPath,
67
- actor,
68
- "release",
69
- threadPath,
70
- "thread",
71
- reason ? { reason } : void 0
72
- );
73
- return update(vaultPath, threadPath, {
74
- status: "open",
75
- owner: null
76
- }, void 0, actor);
77
- }
78
- function block(vaultPath, threadPath, actor, blockedBy, reason) {
79
- const thread = read(vaultPath, threadPath);
80
- if (!thread) throw new Error(`Thread not found: ${threadPath}`);
81
- assertTransition(thread.fields.status, "blocked");
82
- append(vaultPath, actor, "block", threadPath, "thread", {
83
- blocked_by: blockedBy,
84
- ...reason ? { reason } : {}
85
- });
86
- const currentDeps = thread.fields.deps ?? [];
87
- const updatedDeps = currentDeps.includes(blockedBy) ? currentDeps : [...currentDeps, blockedBy];
88
- return update(vaultPath, threadPath, {
89
- status: "blocked",
90
- deps: updatedDeps
91
- }, void 0, actor);
92
- }
93
- function unblock(vaultPath, threadPath, actor) {
94
- const thread = read(vaultPath, threadPath);
95
- if (!thread) throw new Error(`Thread not found: ${threadPath}`);
96
- assertTransition(thread.fields.status, "active");
97
- append(vaultPath, actor, "unblock", threadPath, "thread");
98
- return update(vaultPath, threadPath, {
99
- status: "active"
100
- }, void 0, actor);
101
- }
102
- function done(vaultPath, threadPath, actor, output) {
103
- const thread = read(vaultPath, threadPath);
104
- if (!thread) throw new Error(`Thread not found: ${threadPath}`);
105
- assertTransition(thread.fields.status, "done");
106
- assertOwner(vaultPath, threadPath, actor);
107
- append(
108
- vaultPath,
109
- actor,
110
- "done",
111
- threadPath,
112
- "thread",
113
- output ? { output } : void 0
114
- );
115
- const newBody = output ? `${thread.body}
116
-
117
- ## Output
118
-
119
- ${output}
120
- ` : thread.body;
121
- return update(vaultPath, threadPath, {
122
- status: "done"
123
- }, newBody, actor);
124
- }
125
- function cancel(vaultPath, threadPath, actor, reason) {
126
- const thread = read(vaultPath, threadPath);
127
- if (!thread) throw new Error(`Thread not found: ${threadPath}`);
128
- assertTransition(thread.fields.status, "cancelled");
129
- append(
130
- vaultPath,
131
- actor,
132
- "cancel",
133
- threadPath,
134
- "thread",
135
- reason ? { reason } : void 0
136
- );
137
- return update(vaultPath, threadPath, {
138
- status: "cancelled",
139
- owner: null
140
- }, void 0, actor);
141
- }
142
- function decompose(vaultPath, parentPath, subthreads, actor) {
143
- const parent = read(vaultPath, parentPath);
144
- if (!parent) throw new Error(`Thread not found: ${parentPath}`);
145
- const created = [];
146
- for (const sub of subthreads) {
147
- const inst = createThread(vaultPath, sub.title, sub.goal, actor, {
148
- parent: parentPath,
149
- deps: sub.deps
150
- });
151
- created.push(inst);
152
- }
153
- const childRefs = created.map((c) => `[[${c.path}]]`);
154
- const decomposeNote = `
155
-
156
- ## Sub-threads
157
-
158
- ${childRefs.map((r) => `- ${r}`).join("\n")}
159
- `;
160
- update(vaultPath, parentPath, {}, parent.body + decomposeNote, actor);
161
- append(vaultPath, actor, "decompose", parentPath, "thread", {
162
- children: created.map((c) => c.path)
163
- });
164
- return created;
165
- }
166
- function assertTransition(from, to) {
167
- const allowed = THREAD_STATUS_TRANSITIONS[from];
168
- if (!allowed?.includes(to)) {
169
- throw new Error(`Invalid transition: "${from}" \u2192 "${to}". Allowed: ${allowed?.join(", ") ?? "none"}`);
170
- }
171
- }
172
- function assertOwner(vaultPath, threadPath, actor) {
173
- const owner = currentOwner(vaultPath, threadPath);
174
- if (owner && owner !== actor) {
175
- throw new Error(`Thread is owned by "${owner}", not "${actor}". Only the owner can perform this action.`);
176
- }
177
- }
178
-
179
- export {
180
- createThread,
181
- claim,
182
- release,
183
- block,
184
- unblock,
185
- done,
186
- cancel,
187
- decompose,
188
- thread_exports
189
- };