@frogmoo/dsh-supermemory 0.0.0-stage → 1.4.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/CHANGELOG.md +442 -0
- package/INSTALL.md +193 -0
- package/LICENSE +21 -0
- package/README.md +220 -2
- package/cordis.patch.yml +9 -0
- package/lib/capability-T5x_17iK.js +2971 -0
- package/lib/client.js +4217 -0
- package/lib/clip-kqqR05NC.js +279 -0
- package/lib/export-XY8Bfglx.js +144 -0
- package/lib/filemap-CsF4oYtT.js +166 -0
- package/lib/group-CkFv7052.js +313 -0
- package/lib/hub-sessions-pzURuUmH.js +1010 -0
- package/lib/memory-collections-DaSVGbrR.js +686 -0
- package/lib/model-Z4_-9sAj.js +735 -0
- package/lib/rolldown-runtime-BJohB4LM.js +13 -0
- package/lib/skill-forge-DHxPo_w6.js +2348 -0
- package/lib/store-DD2L3GDr.js +531 -0
- package/lib/supermemory.js +15015 -0
- package/lib/toolize-B9Mbl7sp.js +426 -0
- package/package.json +67 -4
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import { t as newId } from "./store-DD2L3GDr.js";
|
|
2
|
+
// src/topicsets.ts
|
|
3
|
+
async function createTopicSet(store, input) {
|
|
4
|
+
const now = Date.now();
|
|
5
|
+
const topicSetId = newId("ts");
|
|
6
|
+
const record = {
|
|
7
|
+
workspaceKey: input.workspaceKey,
|
|
8
|
+
title: input.title,
|
|
9
|
+
summary: input.summary ?? "",
|
|
10
|
+
keywords: input.keywords ?? [],
|
|
11
|
+
status: "active",
|
|
12
|
+
defaultModel: input.defaultModel,
|
|
13
|
+
members: [],
|
|
14
|
+
shapeFingerprint: "",
|
|
15
|
+
shapeGeneratedAt: 0,
|
|
16
|
+
createdAt: now,
|
|
17
|
+
updatedAt: now,
|
|
18
|
+
lastActiveAt: now
|
|
19
|
+
};
|
|
20
|
+
await store.topicsets.put(topicSetId, record);
|
|
21
|
+
return topicSetId;
|
|
22
|
+
}
|
|
23
|
+
function getTopicSet(store, topicSetId) {
|
|
24
|
+
return store.topicsets.get(topicSetId);
|
|
25
|
+
}
|
|
26
|
+
function listTopicSets(store, workspaceKey) {
|
|
27
|
+
const out = [];
|
|
28
|
+
for (const entry of store.topicsets.entries()) if (entry[1].workspaceKey === workspaceKey && entry[1].status === "active") out.push(entry);
|
|
29
|
+
out.sort((a, b) => b[1].lastActiveAt - a[1].lastActiveAt);
|
|
30
|
+
return out;
|
|
31
|
+
}
|
|
32
|
+
/** Topic-set ids of one workspace (episodes/dispatches join through them). */
|
|
33
|
+
function topicSetIdsOf(store, workspaceKey) {
|
|
34
|
+
const ids = /* @__PURE__ */ new Set();
|
|
35
|
+
for (const [id, record] of store.topicsets.entries()) if (record.workspaceKey === workspaceKey) ids.add(id);
|
|
36
|
+
return ids;
|
|
37
|
+
}
|
|
38
|
+
async function touchTopicSet(store, topicSetId) {
|
|
39
|
+
if (!store.topicsets.get(topicSetId)) return;
|
|
40
|
+
await store.topicsets.update(topicSetId, (record) => ({
|
|
41
|
+
...record,
|
|
42
|
+
lastActiveAt: Date.now(),
|
|
43
|
+
updatedAt: Date.now()
|
|
44
|
+
})).catch(() => {});
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* R19 需求⑥: write the LLM-generated title + tags + body back to one set.
|
|
48
|
+
*
|
|
49
|
+
* The title is only overwritten when the generator produced a non-empty one;
|
|
50
|
+
* an absent field keeps the current value, so a partially parsed model answer
|
|
51
|
+
* can never blank the index. `fingerprint`/`generatedAt` are recorded only on a
|
|
52
|
+
* successful generation (see topic-shape.ts) — the caller decides that.
|
|
53
|
+
*/
|
|
54
|
+
async function updateTopicSetShape(store, topicSetId, shape) {
|
|
55
|
+
await store.topicsets.update(topicSetId, (record) => ({
|
|
56
|
+
...record,
|
|
57
|
+
...shape.title ? { title: shape.title } : {},
|
|
58
|
+
...shape.summary !== void 0 ? { summary: shape.summary } : {},
|
|
59
|
+
...shape.keywords !== void 0 ? { keywords: shape.keywords } : {},
|
|
60
|
+
...shape.fingerprint !== void 0 ? { shapeFingerprint: shape.fingerprint } : {},
|
|
61
|
+
...shape.generatedAt !== void 0 ? { shapeGeneratedAt: shape.generatedAt } : {},
|
|
62
|
+
updatedAt: Date.now()
|
|
63
|
+
})).catch(() => {});
|
|
64
|
+
}
|
|
65
|
+
async function updateTopicSetSummary(store, topicSetId, summary, keywords) {
|
|
66
|
+
await store.topicsets.update(topicSetId, (record) => ({
|
|
67
|
+
...record,
|
|
68
|
+
summary,
|
|
69
|
+
...keywords ? { keywords } : {},
|
|
70
|
+
updatedAt: Date.now()
|
|
71
|
+
})).catch(() => {});
|
|
72
|
+
}
|
|
73
|
+
async function setTopicSetModel(store, topicSetId, model) {
|
|
74
|
+
await store.topicsets.update(topicSetId, (record) => ({
|
|
75
|
+
...record,
|
|
76
|
+
defaultModel: model,
|
|
77
|
+
updatedAt: Date.now()
|
|
78
|
+
})).catch(() => {});
|
|
79
|
+
}
|
|
80
|
+
async function addMember(store, topicSetId, member) {
|
|
81
|
+
await store.topicsets.update(topicSetId, (record) => {
|
|
82
|
+
if (record.members.some((m) => m.sessionId === member.sessionId)) return record;
|
|
83
|
+
const now = Date.now();
|
|
84
|
+
return {
|
|
85
|
+
...record,
|
|
86
|
+
members: [...record.members, {
|
|
87
|
+
sessionId: member.sessionId,
|
|
88
|
+
kind: member.kind,
|
|
89
|
+
title: member.title ?? "",
|
|
90
|
+
summary: "",
|
|
91
|
+
status: "live",
|
|
92
|
+
model: member.model,
|
|
93
|
+
modelOverridden: false,
|
|
94
|
+
lastActiveAt: now
|
|
95
|
+
}],
|
|
96
|
+
lastActiveAt: now,
|
|
97
|
+
updatedAt: now
|
|
98
|
+
};
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
async function updateMember(store, topicSetId, sessionId, patch) {
|
|
102
|
+
await store.topicsets.update(topicSetId, (record) => ({
|
|
103
|
+
...record,
|
|
104
|
+
members: record.members.map((m) => m.sessionId === sessionId ? {
|
|
105
|
+
...m,
|
|
106
|
+
...patch,
|
|
107
|
+
lastActiveAt: Date.now()
|
|
108
|
+
} : m),
|
|
109
|
+
updatedAt: Date.now()
|
|
110
|
+
})).catch(() => {});
|
|
111
|
+
}
|
|
112
|
+
/** Routing table: one row per session. */
|
|
113
|
+
function getRouting(store, sessionId) {
|
|
114
|
+
return store.routing.get(sessionId);
|
|
115
|
+
}
|
|
116
|
+
async function setRouting(store, sessionId, patch) {
|
|
117
|
+
const existing = store.routing.get(sessionId);
|
|
118
|
+
const next = {
|
|
119
|
+
activeTopicSetId: patch.activeTopicSetId !== void 0 ? patch.activeTopicSetId : existing?.activeTopicSetId,
|
|
120
|
+
driftCount: patch.driftCount !== void 0 ? patch.driftCount : existing?.driftCount ?? 0,
|
|
121
|
+
updatedAt: Date.now()
|
|
122
|
+
};
|
|
123
|
+
await store.routing.put(sessionId, next);
|
|
124
|
+
}
|
|
125
|
+
/** Members of one topic set that look relevant to a task (rule: keyword overlap). */
|
|
126
|
+
function rankMembers(topicSet, taskTokens) {
|
|
127
|
+
return [...topicSet.members].sort((a, b) => {
|
|
128
|
+
const score = (m) => {
|
|
129
|
+
const bag = new Set([m.title, m.summary].join(" ").toLowerCase().split(/[\s,,。.;;::]+/).filter(Boolean));
|
|
130
|
+
let hits = 0;
|
|
131
|
+
for (const token of taskTokens) if (bag.has(token)) hits++;
|
|
132
|
+
return hits;
|
|
133
|
+
};
|
|
134
|
+
return score(b) - score(a) || b.lastActiveAt - a.lastActiveAt;
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
// src/clip.ts
|
|
138
|
+
/**
|
|
139
|
+
* Budget-aware clipping for every model-facing injection (R47 需求②).
|
|
140
|
+
*
|
|
141
|
+
* The old rule was a raw `text.slice(0, cap)` at each call site: the injected
|
|
142
|
+
* card could stop mid-sentence, mid-tag or mid-id with no sign that anything
|
|
143
|
+
* was missing — the hub then answered from half a conclusion and had no way to
|
|
144
|
+
* know (or to recover) the rest. That is what this module replaces.
|
|
145
|
+
*
|
|
146
|
+
* Contract:
|
|
147
|
+
* - **Key fields are never clipped here.** Titles, tags, ids and versions are
|
|
148
|
+
* short by construction (title.ts / retrieval.ts caps) and are rendered
|
|
149
|
+
* whole by the caller; only BODIES are budgeted.
|
|
150
|
+
* - A body that exceeds its budget is cut at a **sentence/paragraph
|
|
151
|
+
* boundary** (never mid-sentence) and carries an explicit note naming the
|
|
152
|
+
* original size, the omitted size and how to re-fetch the rest
|
|
153
|
+
* (`memory_recall <query>`), so a cut is visible and recoverable.
|
|
154
|
+
* - Every helper keeps its output within the given budget (the note counts
|
|
155
|
+
* toward it) and never throws.
|
|
156
|
+
*
|
|
157
|
+
* Host-side check (R47 需求④): the DSH host does NOT truncate injected text —
|
|
158
|
+
* dsh-agent's own pre-step consumer appends whole messages
|
|
159
|
+
* (dsh-agent/src/model-selection.ts:170) and the only host cap found is
|
|
160
|
+
* `boundContextSummary` (dsh-llm/src/message.ts:122, 120 chars, marked with …)
|
|
161
|
+
* on a notice's one-line `summary`, which SuperMemory notices stay under.
|
|
162
|
+
* @module supermemory/clip
|
|
163
|
+
*/
|
|
164
|
+
/** Sentence/paragraph terminators (CJK + latin). The terminator is kept. */
|
|
165
|
+
const SENTENCE_END = /* @__PURE__ */ new Set([
|
|
166
|
+
"。",
|
|
167
|
+
"!",
|
|
168
|
+
"?",
|
|
169
|
+
"!",
|
|
170
|
+
"?",
|
|
171
|
+
";",
|
|
172
|
+
";",
|
|
173
|
+
"\n",
|
|
174
|
+
"…"
|
|
175
|
+
]);
|
|
176
|
+
/** Latin clause separators, used only when a sentence has no terminator. */
|
|
177
|
+
const CLAUSE_END = /* @__PURE__ */ new Set([
|
|
178
|
+
",",
|
|
179
|
+
",",
|
|
180
|
+
"、",
|
|
181
|
+
":",
|
|
182
|
+
":",
|
|
183
|
+
"—"
|
|
184
|
+
]);
|
|
185
|
+
/**
|
|
186
|
+
* Cut at the last sentence boundary within `max` characters.
|
|
187
|
+
*
|
|
188
|
+
* Search window: from `minRatio` of the budget to its end (default 40%). A
|
|
189
|
+
* boundary before that window is ignored, so one long preamble cannot swallow
|
|
190
|
+
* the whole budget; `clipMarked` raises the ratio (0.6) because a short label
|
|
191
|
+
* (a 40-char task name) must stay recognisable. When the text has no terminator
|
|
192
|
+
* at all (one huge sentence), fall back to a clause separator, then to
|
|
193
|
+
* whitespace (latin word edge), and only then to a hard cut — which the
|
|
194
|
+
* caller's note or "…" marker still makes visible. Surrogates stay intact.
|
|
195
|
+
*/
|
|
196
|
+
function clipAtBoundary(text, max, minRatio = .4) {
|
|
197
|
+
const source = String(text ?? "");
|
|
198
|
+
const chars = Array.from(source);
|
|
199
|
+
const budget = Math.floor(max);
|
|
200
|
+
if (!Number.isFinite(budget) || budget <= 0) return "";
|
|
201
|
+
if (chars.length <= budget) return source;
|
|
202
|
+
const ratio = Math.min(.9, Math.max(0, Number(minRatio) || 0));
|
|
203
|
+
const window = chars.slice(0, budget);
|
|
204
|
+
const searchFrom = Math.max(0, Math.ceil(window.length * ratio) - 1);
|
|
205
|
+
const lastIndexOf = (set) => {
|
|
206
|
+
for (let index = window.length - 1; index >= searchFrom; index -= 1) if (set.has(window[index])) return index + 1;
|
|
207
|
+
return -1;
|
|
208
|
+
};
|
|
209
|
+
let cut = lastIndexOf(SENTENCE_END);
|
|
210
|
+
if (cut < 0) cut = lastIndexOf(CLAUSE_END);
|
|
211
|
+
if (cut < 0) {
|
|
212
|
+
for (let index = window.length - 1; index >= searchFrom; index -= 1) if (/\s/.test(window[index])) {
|
|
213
|
+
cut = index + 1;
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
if (cut < 0) cut = window.length;
|
|
218
|
+
return window.slice(0, cut).join("");
|
|
219
|
+
}
|
|
220
|
+
/** Character count in code points (what every budget below counts). */
|
|
221
|
+
function charCount(text) {
|
|
222
|
+
return Array.from(String(text ?? "")).length;
|
|
223
|
+
}
|
|
224
|
+
/** The default omission note: visible, sized, and re-fetchable.
|
|
225
|
+
*
|
|
226
|
+
* `hint`: `undefined` = the default `memory_recall` clue; `''` = no clue
|
|
227
|
+
* (a stored field, where re-fetching makes no sense); anything else is quoted
|
|
228
|
+
* verbatim after the sizes.
|
|
229
|
+
*/
|
|
230
|
+
function omissionNote(total, omitted, hint) {
|
|
231
|
+
return `…(原文 ${total} 字,已省略 ${omitted} 字${hint === void 0 ? ",可用 memory_recall 复取" : hint ? `,${hint}` : ""})`;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Clip one body to `max` characters (note included) at a sentence boundary.
|
|
235
|
+
*
|
|
236
|
+
* `hint` overrides the re-fetch clue (e.g. `复取:memory_recall 「标题」`).
|
|
237
|
+
* The result never exceeds `max` characters: the note is measured and the body
|
|
238
|
+
* re-clipped until the pair fits (at most a few iterations — the note's length
|
|
239
|
+
* only moves by digit count). Below ~48 characters the note itself does not
|
|
240
|
+
* fit and the caller should drop the record instead of calling this.
|
|
241
|
+
*/
|
|
242
|
+
function clipWithNote(text, max, hint) {
|
|
243
|
+
const source = String(text ?? "");
|
|
244
|
+
const budget = Math.floor(max);
|
|
245
|
+
if (!Number.isFinite(budget) || budget <= 0) return "";
|
|
246
|
+
const total = Array.from(source).length;
|
|
247
|
+
if (total <= budget) return source;
|
|
248
|
+
let bodyBudget = Math.max(1, budget - 48);
|
|
249
|
+
for (let attempt = 0; attempt < 6; attempt += 1) {
|
|
250
|
+
const kept = clipAtBoundary(source, bodyBudget);
|
|
251
|
+
const combined = `${kept} ${omissionNote(total, total - Array.from(kept).length, hint)}`;
|
|
252
|
+
const combinedLength = Array.from(combined).length;
|
|
253
|
+
if (combinedLength <= budget) return combined;
|
|
254
|
+
bodyBudget = Math.max(1, bodyBudget - (combinedLength - budget));
|
|
255
|
+
}
|
|
256
|
+
return Array.from(source).slice(0, budget).join("");
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* The card-level degradation note: how many records were dropped and how to
|
|
260
|
+
* see them. Appended as the last line of an over-budget card.
|
|
261
|
+
*/
|
|
262
|
+
function dropNote(dropped, hint) {
|
|
263
|
+
if (dropped <= 0) return "";
|
|
264
|
+
return `…(已省略 ${dropped} 项${hint ? `,${hint}` : ",可用 memory_recall 复取"})`;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* A compact marked clip for LABELS and other short fields: boundary-aware cut
|
|
268
|
+
* plus a bare `…`. Used where the verbose {@link clipWithNote} note would
|
|
269
|
+
* overwhelm the field itself (a 40-char task label, a 20-char branch name).
|
|
270
|
+
*/
|
|
271
|
+
function clipMarked(text, max) {
|
|
272
|
+
const source = String(text ?? "");
|
|
273
|
+
const budget = Math.floor(max);
|
|
274
|
+
if (!Number.isFinite(budget) || budget <= 0) return "";
|
|
275
|
+
if (Array.from(source).length <= budget) return source;
|
|
276
|
+
if (budget === 1) return "…";
|
|
277
|
+
return `${clipAtBoundary(source, budget - 1, .6)}…`;
|
|
278
|
+
}
|
|
279
|
+
export { updateTopicSetShape as _, dropNote as a, getRouting as c, rankMembers as d, setRouting as f, updateMember as g, touchTopicSet as h, clipWithNote as i, getTopicSet as l, topicSetIdsOf as m, clipAtBoundary as n, addMember as o, setTopicSetModel as p, clipMarked as r, createTopicSet as s, charCount as t, listTopicSets as u, updateTopicSetSummary as v };
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-BJohB4LM.js";
|
|
2
|
+
import { t as filemapEntries } from "./filemap-CsF4oYtT.js";
|
|
3
|
+
import { t as newId } from "./store-DD2L3GDr.js";
|
|
4
|
+
import { l as getTopicSet, m as topicSetIdsOf } from "./clip-kqqR05NC.js";
|
|
5
|
+
import { g as renderRecordLine } from "./model-Z4_-9sAj.js";
|
|
6
|
+
import { a as listCollections } from "./memory-collections-DaSVGbrR.js";
|
|
7
|
+
// src/requirements.ts
|
|
8
|
+
const PATTERNS = [
|
|
9
|
+
/(?:必须|一定要|务必|需要|要求|应该|应当|不能|不可以|禁止|千万别|一律)[::\s]*([^。!?!?\n"'"』」]{4,120})/,
|
|
10
|
+
/(?:待办|TODO|todo)[::\s]+([^。!?!?\n"'"』」]{4,120})/,
|
|
11
|
+
/(?:^|\s)(?:must|should|need to|required to|cannot|can't|do not|don't)\s+([^。!?!?\n"'"』」]{4,120})/i
|
|
12
|
+
];
|
|
13
|
+
/** Extract requirement clauses from one user message. */
|
|
14
|
+
function extractRequirements(text) {
|
|
15
|
+
const out = [];
|
|
16
|
+
const seen = /* @__PURE__ */ new Set();
|
|
17
|
+
const push = (raw) => {
|
|
18
|
+
const clean = raw.trim().replace(/\s+/g, " ").replace(/["'」』]+$/, "").slice(0, 200);
|
|
19
|
+
if (clean.length < 4) return;
|
|
20
|
+
const key = clean.toLowerCase();
|
|
21
|
+
if (seen.has(key)) return;
|
|
22
|
+
seen.add(key);
|
|
23
|
+
out.push(clean);
|
|
24
|
+
};
|
|
25
|
+
for (const pattern of PATTERNS) {
|
|
26
|
+
const flags = pattern.flags.includes("g") ? pattern.flags : `${pattern.flags}g`;
|
|
27
|
+
for (const m of text.matchAll(new RegExp(pattern.source, flags))) {
|
|
28
|
+
const tail = text.slice(m.index + m[0].length);
|
|
29
|
+
const stop = tail.search(/[。!?!?\n]/);
|
|
30
|
+
if (/^[??]/.test((stop < 0 ? "" : tail.slice(stop)).trimStart())) continue;
|
|
31
|
+
if (/^(?:是否|能不能|可不可以|怎么|怎样|如何|为什么|为啥|啥|哪些|哪个|有没有|是不是)/.test(m[1].trim())) continue;
|
|
32
|
+
push(m[1]);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return out;
|
|
36
|
+
}
|
|
37
|
+
/** Persist extracted requirements for one workspace turn (dedup by text). */
|
|
38
|
+
async function rememberRequirements(store, workspaceKey, texts, sourceSessionId, sourceSeq, now) {
|
|
39
|
+
const created = [];
|
|
40
|
+
for (const text of texts) {
|
|
41
|
+
const normalized = text.trim().toLowerCase();
|
|
42
|
+
let duplicate = false;
|
|
43
|
+
for (const [reqId, record] of store.requirements.entries()) if (record.workspaceKey === workspaceKey && record.status === "open" && record.text.trim().toLowerCase() === normalized) {
|
|
44
|
+
duplicate = true;
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
if (duplicate) continue;
|
|
48
|
+
const reqId = newId("req");
|
|
49
|
+
const record = {
|
|
50
|
+
workspaceKey,
|
|
51
|
+
text,
|
|
52
|
+
constraints: [],
|
|
53
|
+
status: "open",
|
|
54
|
+
sourceSessionId,
|
|
55
|
+
sourceSeq,
|
|
56
|
+
createdAt: now
|
|
57
|
+
};
|
|
58
|
+
await store.requirements.put(reqId, record);
|
|
59
|
+
created.push(reqId);
|
|
60
|
+
}
|
|
61
|
+
return created;
|
|
62
|
+
}
|
|
63
|
+
/** Open requirements of one workspace, newest first. */
|
|
64
|
+
function openRequirements(store, workspaceKey) {
|
|
65
|
+
const out = [];
|
|
66
|
+
for (const entry of store.requirements.entries()) if (entry[1].workspaceKey === workspaceKey && entry[1].status === "open") out.push(entry);
|
|
67
|
+
out.sort((a, b) => b[1].createdAt - a[1].createdAt);
|
|
68
|
+
return out;
|
|
69
|
+
}
|
|
70
|
+
// src/export.ts
|
|
71
|
+
var export_exports = /* @__PURE__ */ __exportAll({ buildExport: () => buildExport });
|
|
72
|
+
/**
|
|
73
|
+
* Build the export document for one workspace.
|
|
74
|
+
*
|
|
75
|
+
* @param store - the open domain store
|
|
76
|
+
* @param workspaceKey - workspace isolation key (D4)
|
|
77
|
+
* @param activeTopicSetId - optional topic set rendered as the document head
|
|
78
|
+
*/
|
|
79
|
+
function buildExport(store, workspaceKey, activeTopicSetId) {
|
|
80
|
+
const topicSet = activeTopicSetId ? getTopicSet(store, activeTopicSetId) : void 0;
|
|
81
|
+
const lines = ["# SuperMemory 导出", ""];
|
|
82
|
+
if (topicSet) {
|
|
83
|
+
const tags = topicSet.keywords.length > 0 ? `
|
|
84
|
+
|
|
85
|
+
标签:${topicSet.keywords.join("、")}` : "";
|
|
86
|
+
lines.push(`## 话题集:${topicSet.title}${tags}`, "", topicSet.summary || "(暂无梗概)", "");
|
|
87
|
+
}
|
|
88
|
+
const collections = new Map(listCollections(store, workspaceKey));
|
|
89
|
+
const grouped = /* @__PURE__ */ new Map();
|
|
90
|
+
const loose = [];
|
|
91
|
+
let memoryCount = 0;
|
|
92
|
+
for (const [, record] of store.memories.entries()) {
|
|
93
|
+
if (record.workspaceKey !== workspaceKey || record.status !== "active") continue;
|
|
94
|
+
const line = `- ${renderRecordLine({
|
|
95
|
+
title: record.title,
|
|
96
|
+
text: record.text,
|
|
97
|
+
tags: record.keywords
|
|
98
|
+
})}`;
|
|
99
|
+
const collectionId = record.collectionId && collections.has(record.collectionId) ? record.collectionId : "";
|
|
100
|
+
if (!collectionId) {
|
|
101
|
+
loose.push(line);
|
|
102
|
+
memoryCount += 1;
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
const bucket = grouped.get(collectionId) ?? [];
|
|
106
|
+
bucket.push(line);
|
|
107
|
+
grouped.set(collectionId, bucket);
|
|
108
|
+
memoryCount += 1;
|
|
109
|
+
}
|
|
110
|
+
if (memoryCount > 0) {
|
|
111
|
+
lines.push("## 事实记忆", "");
|
|
112
|
+
for (const [collectionId, rows] of grouped) {
|
|
113
|
+
const collection = collections.get(collectionId);
|
|
114
|
+
const tags = collection && collection.keywords.length > 0 ? `(标签:${collection.keywords.join("、")})` : "";
|
|
115
|
+
lines.push(`### 记忆集合:${collection?.title ?? collectionId}${tags}`, "");
|
|
116
|
+
if (collection?.summary) lines.push(collection.summary, "");
|
|
117
|
+
lines.push(...rows, "");
|
|
118
|
+
}
|
|
119
|
+
if (loose.length > 0) lines.push("### 未归集", "", ...loose, "");
|
|
120
|
+
}
|
|
121
|
+
const reqs = openRequirements(store, workspaceKey);
|
|
122
|
+
if (reqs.length) lines.push("## 未完成需求", "", ...reqs.map(([, r]) => `- ${r.text}`), "");
|
|
123
|
+
const ownTopicSetIds = topicSetIdsOf(store, workspaceKey);
|
|
124
|
+
const eps = [];
|
|
125
|
+
for (const [, episode] of store.episodes.entries()) {
|
|
126
|
+
if (!episode.topicSetId || !ownTopicSetIds.has(episode.topicSetId)) continue;
|
|
127
|
+
if (episode.summary) eps.push(`- ${episode.summary}`);
|
|
128
|
+
}
|
|
129
|
+
if (eps.length) lines.push("## 归档梗概", "", ...eps.slice(-20), "");
|
|
130
|
+
const files = filemapEntries(store, workspaceKey);
|
|
131
|
+
if (files.length) {
|
|
132
|
+
lines.push("## 项目文件地图", "");
|
|
133
|
+
for (const [, entry] of files) lines.push(`- \`${entry.path}\` — ${entry.role}${entry.summary ? ":" + entry.summary : ""}`);
|
|
134
|
+
lines.push("");
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
text: lines.join("\n"),
|
|
138
|
+
memories: memoryCount,
|
|
139
|
+
requirements: reqs.length,
|
|
140
|
+
files: files.length,
|
|
141
|
+
collections: grouped.size
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
export { rememberRequirements as i, export_exports as n, extractRequirements as r, buildExport as t };
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-BJohB4LM.js";
|
|
2
|
+
import { r as workspaceKeyOf } from "./store-DD2L3GDr.js";
|
|
3
|
+
import { readFileSync, readdirSync, statSync } from "node:fs";
|
|
4
|
+
import { join, relative, resolve } from "node:path";
|
|
5
|
+
import { createHash } from "node:crypto";
|
|
6
|
+
// src/filemap.ts
|
|
7
|
+
/**
|
|
8
|
+
* Project file map (P2): `/memory scan` walks the workspace, annotates files
|
|
9
|
+
* with a rule-based role, and invalidates stale entries by hash. The point is
|
|
10
|
+
* the P2 acceptance "新会话能答『这个文件干什么』": filemap entries join the
|
|
11
|
+
* recall ranking alongside memories/episodes/requirements.
|
|
12
|
+
*
|
|
13
|
+
* Annotation is rule-based by design: subagent-parallel LLM annotation only
|
|
14
|
+
* covers the skeleton (entry points, manifests, configs) and stays optional,
|
|
15
|
+
* so a scan never depends on an LLM being available.
|
|
16
|
+
* @module supermemory/filemap
|
|
17
|
+
*/
|
|
18
|
+
var filemap_exports = /* @__PURE__ */ __exportAll({
|
|
19
|
+
filemapEntries: () => filemapEntries,
|
|
20
|
+
scanWorkspace: () => scanWorkspace
|
|
21
|
+
});
|
|
22
|
+
const SKIP_DIRS = /* @__PURE__ */ new Set([
|
|
23
|
+
"node_modules",
|
|
24
|
+
".git",
|
|
25
|
+
".probe",
|
|
26
|
+
"dist",
|
|
27
|
+
"out",
|
|
28
|
+
"build",
|
|
29
|
+
".next",
|
|
30
|
+
".turbo",
|
|
31
|
+
"target",
|
|
32
|
+
"_dsh_src",
|
|
33
|
+
".obsidian",
|
|
34
|
+
"Backup"
|
|
35
|
+
]);
|
|
36
|
+
const MAX_FILES = 600;
|
|
37
|
+
const MAX_BYTES = 524288;
|
|
38
|
+
/** Role inference from path and extension (rule-based skeleton). */
|
|
39
|
+
function roleOf(relPath) {
|
|
40
|
+
const name = relPath.split(/[\\/]/).pop() ?? relPath;
|
|
41
|
+
const ext = name.includes(".") ? name.split(".").pop().toLowerCase() : "";
|
|
42
|
+
if (/^(package\.json|pnpm-lock\.yaml|tsconfig.*\.json|tsdown\.config\.ts|vite\.config\.ts)$/.test(name)) return "构建/依赖清单";
|
|
43
|
+
if (/^README(\.\w+)?\.md$/i.test(name)) return "项目说明";
|
|
44
|
+
if (/^cordis\.(patch\.)?ya?ml$/i.test(name)) return "插件组合层";
|
|
45
|
+
if (name === "DEV-NOTES.md") return "开发运维笔记";
|
|
46
|
+
if (ext === "ts" || ext === "tsx" || ext === "mts" || ext === "cts") return "源码";
|
|
47
|
+
if (ext === "js" || ext === "mjs" || ext === "cjs") return "脚本/产物";
|
|
48
|
+
if (ext === "md" || ext === "markdown") return "文档";
|
|
49
|
+
if (ext === "json" || ext === "jsonc" || ext === "yaml" || ext === "yml" || ext === "toml") return "配置";
|
|
50
|
+
if (ext === "svg" || ext === "png" || ext === "jpg" || ext === "jpeg" || ext === "webp" || ext === "gif") return "图片";
|
|
51
|
+
if (ext === "py") return "Python";
|
|
52
|
+
if (ext === "sh" || ext === "bash" || ext === "ps1" || ext === "cmd" || ext === "bat") return "脚本";
|
|
53
|
+
if (ext === "log" || ext === "jsonl") return "日志/数据";
|
|
54
|
+
return "其他";
|
|
55
|
+
}
|
|
56
|
+
/** D4 key encoding: ws/<workspaceKey hash>/<path hash>-<path-safe>. */
|
|
57
|
+
function filemapKey(workspaceKey, relPath) {
|
|
58
|
+
return `ws/${createHash("sha1").update(workspaceKey).digest("hex").slice(0, 16)}/${createHash("sha1").update(relPath).digest("hex").slice(0, 12)}-${relPath.replace(/[\\/:*?"<>|]+/g, "_")}`;
|
|
59
|
+
}
|
|
60
|
+
/** Walk the workspace and refresh the filemap; returns counts. */
|
|
61
|
+
async function scanWorkspace(store, cwd) {
|
|
62
|
+
const workspaceKey = workspaceKeyOf(cwd);
|
|
63
|
+
const root = resolve(cwd);
|
|
64
|
+
const files = [];
|
|
65
|
+
let truncated = false;
|
|
66
|
+
const walk = (dir, depth) => {
|
|
67
|
+
if (depth > 6) {
|
|
68
|
+
truncated = true;
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if (files.length >= MAX_FILES) {
|
|
72
|
+
truncated = true;
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
let entries;
|
|
76
|
+
try {
|
|
77
|
+
entries = readdirSync(dir);
|
|
78
|
+
} catch {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
for (const name of entries) {
|
|
82
|
+
if (files.length >= MAX_FILES) {
|
|
83
|
+
truncated = true;
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const full = join(dir, name);
|
|
87
|
+
let isDir = false;
|
|
88
|
+
let size = 0;
|
|
89
|
+
try {
|
|
90
|
+
const st = statSync(full);
|
|
91
|
+
isDir = st.isDirectory();
|
|
92
|
+
size = st.size;
|
|
93
|
+
} catch {
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
if (isDir) {
|
|
97
|
+
if (SKIP_DIRS.has(name) || name.startsWith(".")) continue;
|
|
98
|
+
walk(full, depth + 1);
|
|
99
|
+
} else if (size <= MAX_BYTES) files.push(relative(root, full));
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
walk(root, 0);
|
|
103
|
+
const now = Date.now();
|
|
104
|
+
let added = 0;
|
|
105
|
+
let updated = 0;
|
|
106
|
+
let stale = 0;
|
|
107
|
+
const seenKeys = /* @__PURE__ */ new Set();
|
|
108
|
+
for (const rel of files) {
|
|
109
|
+
const posix = rel.replace(/\\/g, "/");
|
|
110
|
+
const key = filemapKey(workspaceKey, posix);
|
|
111
|
+
seenKeys.add(key);
|
|
112
|
+
let hash;
|
|
113
|
+
try {
|
|
114
|
+
hash = createHash("sha1").update(readFileSync(join(root, rel))).digest("hex").slice(0, 16);
|
|
115
|
+
} catch {
|
|
116
|
+
hash = void 0;
|
|
117
|
+
}
|
|
118
|
+
const existing = store.filemap.get(key);
|
|
119
|
+
if (!existing) {
|
|
120
|
+
const entry = {
|
|
121
|
+
workspaceKey,
|
|
122
|
+
path: posix,
|
|
123
|
+
role: roleOf(posix),
|
|
124
|
+
summary: "",
|
|
125
|
+
keywords: keywordsOfPath(posix),
|
|
126
|
+
hash,
|
|
127
|
+
annotatedAt: now
|
|
128
|
+
};
|
|
129
|
+
await store.filemap.put(key, entry);
|
|
130
|
+
added++;
|
|
131
|
+
} else {
|
|
132
|
+
if (existing.hash !== hash) stale++;
|
|
133
|
+
await store.filemap.update(key, (r) => ({
|
|
134
|
+
...r,
|
|
135
|
+
path: posix,
|
|
136
|
+
hash,
|
|
137
|
+
role: roleOf(posix),
|
|
138
|
+
annotatedAt: now
|
|
139
|
+
}));
|
|
140
|
+
if (existing.hash === hash && existing.role !== roleOf(posix)) updated++;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (!truncated) for (const [key, entry] of [...store.filemap.entries()]) {
|
|
144
|
+
if (entry.workspaceKey !== workspaceKey) continue;
|
|
145
|
+
if (seenKeys.has(key)) continue;
|
|
146
|
+
await store.filemap.delete(key);
|
|
147
|
+
stale++;
|
|
148
|
+
}
|
|
149
|
+
return {
|
|
150
|
+
scanned: files.length,
|
|
151
|
+
added,
|
|
152
|
+
updated,
|
|
153
|
+
stale
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
function keywordsOfPath(relPath) {
|
|
157
|
+
const tokens = relPath.toLowerCase().split(/[\\/._\-]+/).filter((t) => t.length >= 2);
|
|
158
|
+
return [...new Set(tokens)].slice(0, 12);
|
|
159
|
+
}
|
|
160
|
+
/** Filemap entries of one workspace, with readable paths. */
|
|
161
|
+
function filemapEntries(store, workspaceKey) {
|
|
162
|
+
const out = [];
|
|
163
|
+
for (const entry of store.filemap.entries()) if (entry[1].workspaceKey === workspaceKey) out.push(entry);
|
|
164
|
+
return out;
|
|
165
|
+
}
|
|
166
|
+
export { filemap_exports as n, scanWorkspace as r, filemapEntries as t };
|