@memfork/cli 0.1.29 → 0.1.31

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.
@@ -15,6 +15,8 @@ import http from "node:http";
15
15
  import fs from "node:fs";
16
16
  import path from "node:path";
17
17
  import { readProjectConfig, readCredentials, MEMWAL_CONSTANTS } from "../config.js";
18
+ import { MemWal } from "@mysten-incubation/memwal";
19
+ import { branchNamespace } from "@memfork/core";
18
20
  const MIME = {
19
21
  ".html": "text/html; charset=utf-8",
20
22
  ".js": "application/javascript",
@@ -55,21 +57,44 @@ async function handleApiConfig(res) {
55
57
  hasMemwal: !!(stored?.memwalKey && stored?.memwalAccountId),
56
58
  });
57
59
  }
58
- async function memwalSearch(relayer, key, accountId, namespace, limit = 200) {
59
- const upstream = await fetch(`${relayer}/api/search`, {
60
- method: "POST",
61
- headers: {
62
- "Content-Type": "application/json",
63
- "Authorization": `Bearer ${key}`,
64
- "x-memwal-account-id": accountId,
65
- },
66
- body: JSON.stringify({ query: "", namespace, limit }),
67
- signal: AbortSignal.timeout(8_000),
60
+ /**
61
+ * Recall entries from a MemWal namespace using the SDK (signed requests).
62
+ *
63
+ * The MemWal HTTP API requires a cryptographically signed request; a plain
64
+ * Bearer token is rejected. We use the SDK directly so auth is handled
65
+ * correctly. We issue three broad queries that cover all CommitPayload
66
+ * blobs and merge/deduplicate by blob_id.
67
+ */
68
+ async function memwalRecall(relayer, key, accountId, namespace, limit = 200) {
69
+ const mw = MemWal.create({
70
+ key,
71
+ accountId,
72
+ serverUrl: relayer,
73
+ namespace,
68
74
  });
69
- if (!upstream.ok)
70
- return [];
71
- const data = await upstream.json();
72
- return (data["results"] ?? data["entries"] ?? []);
75
+ // Three broad queries that collectively cover all CommitPayload blobs.
76
+ const queries = [
77
+ "commit facts delta project memory",
78
+ "branch convention decision preference setup",
79
+ "error handling architecture pattern configuration",
80
+ ];
81
+ const perQuery = Math.ceil(limit / queries.length);
82
+ const seen = new Set();
83
+ const merged = [];
84
+ await Promise.allSettled(queries.map(async (query) => {
85
+ try {
86
+ const result = await mw.recall({ query, limit: perQuery });
87
+ for (const r of result.results) {
88
+ const blobId = String(r.blob_id ?? "");
89
+ if (blobId && !seen.has(blobId)) {
90
+ seen.add(blobId);
91
+ merged.push({ blob_id: blobId, text: String(r.text ?? ""), distance: r.distance });
92
+ }
93
+ }
94
+ }
95
+ catch { /* one query failing shouldn't break the others */ }
96
+ }));
97
+ return merged;
73
98
  }
74
99
  async function handleApiFacts(res, url) {
75
100
  const branch = url.searchParams.get("branch") ?? "main";
@@ -83,10 +108,9 @@ async function handleApiFacts(res, url) {
83
108
  return;
84
109
  }
85
110
  const relayer = stored.memwalRelayer ?? MEMWAL_CONSTANTS[network].relayer;
86
- const treeHex = treeId.startsWith("0x") ? treeId.slice(2) : treeId;
87
- const namespace = `memforks/${treeHex}/${branch}`;
111
+ const namespace = branchNamespace(treeId, branch);
88
112
  try {
89
- const facts = await memwalSearch(relayer, stored.memwalKey, stored.memwalAccountId, namespace);
113
+ const facts = await memwalRecall(relayer, stored.memwalKey, stored.memwalAccountId, namespace);
90
114
  json(res, { facts });
91
115
  }
92
116
  catch (e) {
@@ -116,14 +140,12 @@ async function handleApiHistory(res, url) {
116
140
  return;
117
141
  }
118
142
  const relayer = stored.memwalRelayer ?? MEMWAL_CONSTANTS[network].relayer;
119
- const treeHexH = treeId.startsWith("0x") ? treeId.slice(2) : treeId;
120
- const namespace = `memforks/${treeHexH}/${branch}`;
143
+ const namespace = branchNamespace(treeId, branch);
121
144
  try {
122
- const results = await memwalSearch(relayer, stored.memwalKey, stored.memwalAccountId, namespace, limit);
145
+ const results = await memwalRecall(relayer, stored.memwalKey, stored.memwalAccountId, namespace, limit);
123
146
  const commits = results.flatMap((entry) => {
124
- const e = entry;
125
- const blobId = String(e["blob_id"] ?? "");
126
- const text = String(e["text"] ?? "");
147
+ const blobId = entry.blob_id;
148
+ const text = entry.text;
127
149
  // Try to parse the stored text as a CommitPayload JSON.
128
150
  let payload = null;
129
151
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@memfork/cli",
3
- "version": "0.1.29",
3
+ "version": "0.1.31",
4
4
  "description": "MemForks CLI — init, commit, recall, merge, install plugins",
5
5
  "repository": {
6
6
  "type": "git",