open-memex 0.10.0 → 0.11.0-alpha.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/AGENTS.md +3 -3
- package/CHANGELOG.md +4 -0
- package/README.md +41 -20
- package/README.zh-CN.md +19 -7
- package/dist/.build-stamp +1 -1
- package/dist/cli.js +95 -21
- package/dist/curate.js +374 -16
- package/dist/init.js +4 -0
- package/dist/mcp.js +8 -3
- package/dist/store/curate.js +418 -102
- package/dist/store/curation-feedback.js +51 -0
- package/dist/submit.js +124 -6
- package/dist/tools/ops.js +40 -6
- package/docs/V2-DESIGN.md +2 -2
- package/docs/design/decisions.md +4 -1
- package/package.json +66 -66
- package/scripts/curate-eval.ts +345 -19
- package/scripts/smoke-pure.ts +116 -1
- package/src/cli.ts +95 -20
- package/src/curate.ts +460 -17
- package/src/init.ts +4 -0
- package/src/mcp.ts +8 -3
- package/src/store/curate.ts +675 -270
- package/src/store/curation-feedback.ts +81 -0
- package/src/submit.ts +135 -4
- package/src/tools/ops.ts +38 -6
package/dist/curate.js
CHANGED
|
@@ -1,19 +1,51 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* D78: deterministic curation for the submit path.
|
|
2
|
+
* D78/D95: deterministic curation for the submit path.
|
|
3
3
|
*
|
|
4
|
-
* This module is PURE: it decides what can be auto-applied and
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* This module is PURE: it decides what can be auto-applied and what needs the
|
|
5
|
+
* one-shot batch decision, and renders the receipts/summary. File writes live
|
|
6
|
+
* in src/store/curate.ts; `submit` owns the ordering (validate ->
|
|
7
|
+
* branch/conflict preflight -> plan -> apply -> copy -> commit).
|
|
7
8
|
*
|
|
8
|
-
*
|
|
9
|
+
* Confidence tiers (D78):
|
|
10
|
+
*
|
|
11
|
+
* auto-apply (deterministic, never guesses about content the human wrote):
|
|
9
12
|
* - exact duplicates (contentHash: whitespace-normalized body identical)
|
|
10
13
|
* - empty / whitespace-only bodies
|
|
11
14
|
* - title normalization (the first non-empty body line is the de-facto title)
|
|
15
|
+
* - type/tag inference from a keyword capture with a HIGH-confidence signal
|
|
16
|
+
* (the hook never chose a type/tag, so there is nothing explicit to
|
|
17
|
+
* overwrite)
|
|
18
|
+
*
|
|
19
|
+
* batch-confirm (one summary screen, accept all or decline all):
|
|
20
|
+
* - semantic merges: near-duplicates whose token sets are the same but whose
|
|
21
|
+
* bytes differ (case/punctuation/order). 0.8-0.9 stays report-only: one
|
|
22
|
+
* flipped word (thursday/friday) lands there and merging it would drop a
|
|
23
|
+
* real difference.
|
|
24
|
+
* - splits: an overlong body with two unrelated paragraphs. The accept path
|
|
25
|
+
* keeps BOTH halves - the original keeps the first, a derived memory gets
|
|
26
|
+
* the second.
|
|
27
|
+
* - uncertain type/tag inference (tool/CLI saves may have chosen the current
|
|
28
|
+
* type explicitly, so they are never changed silently).
|
|
12
29
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
30
|
+
* Nothing in the batch tier is ever auto-applied. A declined batch leaves
|
|
31
|
+
* every memory untouched; an accepted batch is undone as a unit with
|
|
32
|
+
* `open-memex curate undo --batch <id>`.
|
|
15
33
|
*/
|
|
34
|
+
import { createHash } from "node:crypto";
|
|
16
35
|
import { contentHash, similarity, NEAR_DUP_THRESHOLD, } from "./store/lifecycle.js";
|
|
36
|
+
/** D95: near-dup is the "worth a look" signal; a merge proposal needs the
|
|
37
|
+
* same token content, not a one-word difference. */
|
|
38
|
+
export const SEMANTIC_MERGE_THRESHOLD = 0.9;
|
|
39
|
+
/** Both sides of a merge proposal must be roughly the same size. */
|
|
40
|
+
export const SEMANTIC_MERGE_MIN_LENGTH_RATIO = 0.6;
|
|
41
|
+
/** A split needs an overlong body ... */
|
|
42
|
+
export const MIN_SPLIT_BODY_CHARS = 320;
|
|
43
|
+
/** ... with two substantial halves ... */
|
|
44
|
+
export const MIN_SPLIT_PART_CHARS = 100;
|
|
45
|
+
/** ... that talk about different things. */
|
|
46
|
+
export const MAX_SPLIT_OVERLAP = 0.25;
|
|
47
|
+
/** Never add more than this many inferred tags to one memory. */
|
|
48
|
+
export const MAX_INFERRED_TAGS = 3;
|
|
17
49
|
/** Trim + collapse internal whitespace. Never strips Markdown markers. */
|
|
18
50
|
export function normalizeTitleLine(line) {
|
|
19
51
|
return line.trim().replace(/\s+/g, " ");
|
|
@@ -46,21 +78,149 @@ export function normalizeTitle(body) {
|
|
|
46
78
|
lines[i] = after;
|
|
47
79
|
return { body: lines.join("\n"), before, after };
|
|
48
80
|
}
|
|
81
|
+
const TYPE_RULES = [
|
|
82
|
+
// Explicit markers.
|
|
83
|
+
{ re: /(^|\n)[ \t]*(todo|TODO)[ \t]*[::]/, type: "todo", confidence: "high" },
|
|
84
|
+
{ re: /(^|\n)[ \t]*(待办|TODO)[ \t]*[::]/, type: "todo", confidence: "high" },
|
|
85
|
+
{ re: /(^|\n)[ \t]*(gotcha|beware|warning)[ \t]*[::]/i, type: "gotcha", confidence: "high" },
|
|
86
|
+
{ re: /(^|\n)[ \t]*(坑|注意)[ \t]*[::]/, type: "gotcha", confidence: "high" },
|
|
87
|
+
{ re: /(^|\n)[ \t]*#{0,6}[ \t]*how[ \t]+to\b/i, type: "howto", confidence: "high" },
|
|
88
|
+
{ re: /(^|\n)[ \t]*decision[ \t]*[::]/i, type: "decision", confidence: "high" },
|
|
89
|
+
{ re: /(^|\n)[ \t]*preference[ \t]*[::]/i, type: "preference", confidence: "high" },
|
|
90
|
+
// Explicit prose.
|
|
91
|
+
{ re: /\bwe[ \t]+(?:have[ \t]+)?decided\b/i, type: "decision", confidence: "high" },
|
|
92
|
+
{ re: /我们(?:已经)?决定/, type: "decision", confidence: "high" },
|
|
93
|
+
{ re: /\bi[ \t]+prefer\b/i, type: "preference", confidence: "high" },
|
|
94
|
+
{ re: /我(?:更)?喜欢/, type: "preference", confidence: "high" },
|
|
95
|
+
// Weaker signals: always batch-confirm.
|
|
96
|
+
{ re: /\b(remember[ \t]+to|follow[ -]?up)\b/i, type: "todo", confidence: "medium" },
|
|
97
|
+
{ re: /\b(must|required|never|only[ \t]+if|constraint)\b/i, type: "constraint", confidence: "medium" },
|
|
98
|
+
{ re: /\b(learned|lesson|postmortem|retrospective)\b/i, type: "lesson", confidence: "medium" },
|
|
99
|
+
{ re: /https?:\/\//, type: "reference", confidence: "medium" },
|
|
100
|
+
{ re: /\b(install|setup|set[ \t]+up|run[ \t]+the[ \t]+following|steps?)\b/i, type: "howto", confidence: "medium" },
|
|
101
|
+
{ re: /\b(pitfall|watch[ \t]+out|breaks?)\b/i, type: "gotcha", confidence: "medium" },
|
|
102
|
+
];
|
|
103
|
+
export function inferType(body) {
|
|
104
|
+
for (const rule of TYPE_RULES) {
|
|
105
|
+
if (rule.re.test(body)) {
|
|
106
|
+
return { type: rule.type, confidence: rule.confidence, signal: `type:${rule.type}` };
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
function escapeRegExp(s) {
|
|
112
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* D95: tag inference. Two deterministic sources, both additive only:
|
|
116
|
+
* - explicit hashtags in the body (`#release`);
|
|
117
|
+
* - a tag from the scope's existing vocabulary (used by >=2 memories) that
|
|
118
|
+
* appears as a whole word in the body.
|
|
119
|
+
* Existing tags are never removed or renamed.
|
|
120
|
+
*/
|
|
121
|
+
export function inferTags(body, existing, knownTags = []) {
|
|
122
|
+
const have = new Set(existing.map((t) => t.toLowerCase()));
|
|
123
|
+
const out = [];
|
|
124
|
+
const add = (tag) => {
|
|
125
|
+
const t = tag.trim();
|
|
126
|
+
if (!t)
|
|
127
|
+
return;
|
|
128
|
+
const k = t.toLowerCase();
|
|
129
|
+
if (have.has(k) || out.includes(k))
|
|
130
|
+
return;
|
|
131
|
+
if (out.length >= MAX_INFERRED_TAGS)
|
|
132
|
+
return;
|
|
133
|
+
out.push(k);
|
|
134
|
+
};
|
|
135
|
+
const hashtag = /(^|\s)#([a-z0-9][a-z0-9_-]{1,23})\b/gi;
|
|
136
|
+
let m;
|
|
137
|
+
while ((m = hashtag.exec(body)) !== null)
|
|
138
|
+
add(m[2]);
|
|
139
|
+
for (const tag of knownTags) {
|
|
140
|
+
if (tag.length < 3)
|
|
141
|
+
continue;
|
|
142
|
+
if (new RegExp(`(^|[^\\p{L}\\p{N}_])${escapeRegExp(tag)}([^\\p{L}\\p{N}_]|$)`, "iu").test(body)) {
|
|
143
|
+
add(tag);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (out.length === 0)
|
|
147
|
+
return null;
|
|
148
|
+
return { tags: out, signal: out[0] ? `tag:${out[0]}` : "tag" };
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* D95: split detection for overloaded memories. Two or more substantial
|
|
152
|
+
* paragraphs with unrelated vocabulary (Jaccard < 0.25) are the signal. Code
|
|
153
|
+
* fences are left alone - splitting a code sample is a human's call.
|
|
154
|
+
*/
|
|
155
|
+
export function splitCandidate(body) {
|
|
156
|
+
const text = body.replace(/\r\n/g, "\n").trim();
|
|
157
|
+
if (text.length < MIN_SPLIT_BODY_CHARS)
|
|
158
|
+
return null;
|
|
159
|
+
if (text.includes("```"))
|
|
160
|
+
return null;
|
|
161
|
+
const parts = text
|
|
162
|
+
.split(/\n\s*\n/)
|
|
163
|
+
.map((p) => p.trim())
|
|
164
|
+
.filter(Boolean);
|
|
165
|
+
if (parts.length < 2)
|
|
166
|
+
return null;
|
|
167
|
+
let best = null;
|
|
168
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
169
|
+
const first = parts.slice(0, i + 1).join("\n\n");
|
|
170
|
+
const second = parts.slice(i + 1).join("\n\n");
|
|
171
|
+
if (first.length < MIN_SPLIT_PART_CHARS || second.length < MIN_SPLIT_PART_CHARS)
|
|
172
|
+
continue;
|
|
173
|
+
const score = similarity(first, second);
|
|
174
|
+
if (score > MAX_SPLIT_OVERLAP)
|
|
175
|
+
continue;
|
|
176
|
+
if (!best || score < best.score)
|
|
177
|
+
best = { i, score, first, second };
|
|
178
|
+
}
|
|
179
|
+
if (!best)
|
|
180
|
+
return null;
|
|
181
|
+
return { firstPart: best.first, secondPart: best.second, overlap: best.score };
|
|
182
|
+
}
|
|
49
183
|
function undoLine(kind, id) {
|
|
50
184
|
if (kind === "archive-empty")
|
|
51
185
|
return `open-memex status ${id} active`;
|
|
52
186
|
return `open-memex curate undo ${id}`;
|
|
53
187
|
}
|
|
188
|
+
export function batchIdFor(proposals) {
|
|
189
|
+
const keys = proposals
|
|
190
|
+
.map((p) => `${p.kind}:${p.id}:${p.canonicalId ?? ""}:${p.toType ?? ""}:${(p.addedTags ?? []).join(",")}`)
|
|
191
|
+
.sort();
|
|
192
|
+
return `b${createHash("sha1").update(keys.join("|"), "utf8").digest("hex").slice(0, 10)}`;
|
|
193
|
+
}
|
|
194
|
+
/** A record whose type/tags were chosen by a human or an agent (anything but
|
|
195
|
+
* a bare keyword capture) is never changed silently. */
|
|
196
|
+
function inferenceIsAuto(source, confidence) {
|
|
197
|
+
return confidence === "high" && source === "keyword";
|
|
198
|
+
}
|
|
199
|
+
function knownTagVocabulary(records) {
|
|
200
|
+
const counts = new Map();
|
|
201
|
+
for (const r of records) {
|
|
202
|
+
for (const t of r.tags ?? []) {
|
|
203
|
+
const k = t.trim().toLowerCase();
|
|
204
|
+
if (!k)
|
|
205
|
+
continue;
|
|
206
|
+
counts.set(k, (counts.get(k) ?? 0) + 1);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return [...counts.entries()].filter(([, n]) => n >= 2).map(([t]) => t);
|
|
210
|
+
}
|
|
54
211
|
/**
|
|
55
|
-
* Build the
|
|
56
|
-
* archive-empty
|
|
57
|
-
* each group, so two runs over the
|
|
212
|
+
* Build the plan. Input order is irrelevant: output order is
|
|
213
|
+
* archive-empty -> merge-duplicate -> infer-type -> infer-tags ->
|
|
214
|
+
* normalize-title, then id ascending inside each group, so two runs over the
|
|
215
|
+
* same store render the same summary. Proposals follow the same kind order.
|
|
58
216
|
*/
|
|
59
|
-
export function planCuration(records) {
|
|
217
|
+
export function planCuration(records, opts = {}) {
|
|
60
218
|
const actions = [];
|
|
219
|
+
const proposals = [];
|
|
61
220
|
const skipped = [];
|
|
62
221
|
const active = records.filter((r) => r.status === "active");
|
|
63
222
|
const nonEmpty = active.filter((r) => r.body.trim().length > 0);
|
|
223
|
+
const knownTags = opts.knownTags ?? knownTagVocabulary(records);
|
|
64
224
|
// 1. Empty fragments are archived, never deleted: the file is the source of
|
|
65
225
|
// truth and `status ... active` is the undo path.
|
|
66
226
|
for (const r of active) {
|
|
@@ -69,6 +229,7 @@ export function planCuration(records) {
|
|
|
69
229
|
kind: "archive-empty",
|
|
70
230
|
id: r.id,
|
|
71
231
|
undo: undoLine("archive-empty", r.id),
|
|
232
|
+
signal: "archive:empty",
|
|
72
233
|
reason: "empty body - archived, not deleted (status is reversible)",
|
|
73
234
|
});
|
|
74
235
|
}
|
|
@@ -114,16 +275,160 @@ export function planCuration(records) {
|
|
|
114
275
|
kind: "merge-duplicate",
|
|
115
276
|
id: dup.id,
|
|
116
277
|
canonicalId: canonical.id,
|
|
278
|
+
signal: "merge:exact",
|
|
117
279
|
undo: undoLine("merge-duplicate", dup.id),
|
|
118
280
|
reason: "normalized body is identical to " + canonical.id + "; supersede chain preserves the duplicate file",
|
|
119
281
|
});
|
|
120
282
|
merged.add(dup.id);
|
|
121
283
|
}
|
|
122
284
|
}
|
|
123
|
-
|
|
285
|
+
const candidates = nonEmpty.filter((r) => !merged.has(r.id));
|
|
286
|
+
// 3. Semantic merge proposals. Near-duplicates whose token content is the
|
|
287
|
+
// same (case/punctuation/order differences only) are genuinely one memory.
|
|
288
|
+
// 0.8-0.9 pairs stay in the report: a single flipped word (thursday/friday)
|
|
289
|
+
// sits there, and a bulk-accepted merge must not drop it.
|
|
290
|
+
const proposalTouched = new Set();
|
|
291
|
+
const mergeTarget = new Set();
|
|
292
|
+
const nearCandidates = [];
|
|
293
|
+
for (let i = 0; i < candidates.length; i++) {
|
|
294
|
+
for (let j = i + 1; j < candidates.length; j++) {
|
|
295
|
+
const a = candidates[i];
|
|
296
|
+
const b = candidates[j];
|
|
297
|
+
if (contentHash(a.body) === contentHash(b.body))
|
|
298
|
+
continue;
|
|
299
|
+
const ratio = Math.min(a.body.length, b.body.length) / Math.max(a.body.length, b.body.length);
|
|
300
|
+
if (ratio < SEMANTIC_MERGE_MIN_LENGTH_RATIO)
|
|
301
|
+
continue;
|
|
302
|
+
const score = similarity(a.body, b.body);
|
|
303
|
+
if (score < NEAR_DUP_THRESHOLD)
|
|
304
|
+
continue;
|
|
305
|
+
if (score < SEMANTIC_MERGE_THRESHOLD)
|
|
306
|
+
continue;
|
|
307
|
+
nearCandidates.push({ a, b, score });
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
nearCandidates.sort((x, y) => y.score - x.score ||
|
|
311
|
+
x.a.createdAt.localeCompare(y.a.createdAt) ||
|
|
312
|
+
x.a.id.localeCompare(y.a.id));
|
|
313
|
+
for (const { a, b, score } of nearCandidates) {
|
|
314
|
+
if (proposalTouched.has(a.id) || proposalTouched.has(b.id) || mergeTarget.has(a.id) || mergeTarget.has(b.id)) {
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
// A chain-managed record is never a canonical or a target: its history is
|
|
318
|
+
// already a human decision.
|
|
319
|
+
const free = [a, b].filter((r) => !r.supersedes && !r.supersededBy);
|
|
320
|
+
if (free.length < 2) {
|
|
321
|
+
skipped.push({
|
|
322
|
+
id: a.id,
|
|
323
|
+
reason: "near-duplicate is already in a supersede chain - a human must decide which version is canonical",
|
|
324
|
+
});
|
|
325
|
+
continue;
|
|
326
|
+
}
|
|
327
|
+
free.sort((x, y) => x.createdAt.localeCompare(y.createdAt) || x.id.localeCompare(y.id));
|
|
328
|
+
const canonical = free[0];
|
|
329
|
+
const target = free[1];
|
|
330
|
+
proposals.push({
|
|
331
|
+
kind: "semantic-merge",
|
|
332
|
+
id: target.id,
|
|
333
|
+
canonicalId: canonical.id,
|
|
334
|
+
score,
|
|
335
|
+
signal: "merge:semantic",
|
|
336
|
+
reason: `similarity ${score.toFixed(2)} with ${canonical.id} (same token content, different bytes); supersede chain keeps both files`,
|
|
337
|
+
});
|
|
338
|
+
proposalTouched.add(canonical.id);
|
|
339
|
+
proposalTouched.add(target.id);
|
|
340
|
+
mergeTarget.add(target.id);
|
|
341
|
+
}
|
|
342
|
+
// 4. Split proposals: overloaded memories with two unrelated paragraphs.
|
|
343
|
+
for (const r of candidates) {
|
|
344
|
+
if (proposalTouched.has(r.id))
|
|
345
|
+
continue;
|
|
346
|
+
const split = splitCandidate(r.body);
|
|
347
|
+
if (!split)
|
|
348
|
+
continue;
|
|
349
|
+
proposals.push({
|
|
350
|
+
kind: "split",
|
|
351
|
+
id: r.id,
|
|
352
|
+
firstPart: split.firstPart,
|
|
353
|
+
secondPart: split.secondPart,
|
|
354
|
+
signal: "split:paragraph",
|
|
355
|
+
reason: `two unrelated paragraphs (overlap ${split.overlap.toFixed(2)}); accepting keeps both halves - the original and a derived memory`,
|
|
356
|
+
});
|
|
357
|
+
proposalTouched.add(r.id);
|
|
358
|
+
}
|
|
359
|
+
// 5. Type/tag inference. High confidence + a keyword capture is the only
|
|
360
|
+
// automatic path: the hook never chose a type or tag. Everything else is a
|
|
361
|
+
// batch proposal, because a tool/CLI save may have set the value on purpose.
|
|
362
|
+
for (const r of candidates) {
|
|
363
|
+
if (proposalTouched.has(r.id))
|
|
364
|
+
continue;
|
|
365
|
+
const currentType = r.type ?? "fact";
|
|
366
|
+
if (currentType === "fact") {
|
|
367
|
+
const inferred = inferType(r.body);
|
|
368
|
+
if (inferred && inferred.type !== currentType) {
|
|
369
|
+
const auto = inferenceIsAuto(r.source, inferred.confidence);
|
|
370
|
+
const reason = auto
|
|
371
|
+
? `keyword capture, no type was chosen; ${inferred.confidence}-confidence signal for "${inferred.type}"`
|
|
372
|
+
: `type is the default "fact" but the save may have chosen it; ${inferred.confidence}-confidence signal for "${inferred.type}"`;
|
|
373
|
+
if (auto) {
|
|
374
|
+
actions.push({
|
|
375
|
+
kind: "infer-type",
|
|
376
|
+
id: r.id,
|
|
377
|
+
fromType: currentType,
|
|
378
|
+
toType: inferred.type,
|
|
379
|
+
signal: inferred.signal,
|
|
380
|
+
undo: undoLine("infer-type", r.id),
|
|
381
|
+
reason,
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
else {
|
|
385
|
+
proposals.push({
|
|
386
|
+
kind: "infer-type",
|
|
387
|
+
id: r.id,
|
|
388
|
+
fromType: currentType,
|
|
389
|
+
toType: inferred.type,
|
|
390
|
+
signal: inferred.signal,
|
|
391
|
+
reason,
|
|
392
|
+
});
|
|
393
|
+
proposalTouched.add(r.id);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
const inferredTags = inferTags(r.body, r.tags ?? [], knownTags);
|
|
398
|
+
if (inferredTags) {
|
|
399
|
+
const auto = inferenceIsAuto(r.source, "high");
|
|
400
|
+
const reason = auto
|
|
401
|
+
? `keyword capture; ${inferredTags.tags.length} explicit/vocabulary tag(s) added, none removed`
|
|
402
|
+
: `tags are additive but the save may have chosen them; add ${inferredTags.tags.join(", ")} (nothing removed)`;
|
|
403
|
+
if (auto) {
|
|
404
|
+
actions.push({
|
|
405
|
+
kind: "infer-tags",
|
|
406
|
+
id: r.id,
|
|
407
|
+
addedTags: inferredTags.tags,
|
|
408
|
+
signal: inferredTags.signal,
|
|
409
|
+
undo: undoLine("infer-tags", r.id),
|
|
410
|
+
reason,
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
else {
|
|
414
|
+
proposals.push({
|
|
415
|
+
kind: "infer-tags",
|
|
416
|
+
id: r.id,
|
|
417
|
+
addedTags: inferredTags.tags,
|
|
418
|
+
signal: inferredTags.signal,
|
|
419
|
+
reason,
|
|
420
|
+
});
|
|
421
|
+
proposalTouched.add(r.id);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
// 6. Title normalization. A duplicate being merged is history now, so don't
|
|
124
426
|
// report a title action for it; the canonical survives and can be fixed.
|
|
427
|
+
// A record carrying a batch proposal is under one human decision, and its
|
|
428
|
+
// body is the exact text that proposal was validated against - the auto tier
|
|
429
|
+
// must not rewrite the first line out from under it.
|
|
125
430
|
for (const r of nonEmpty) {
|
|
126
|
-
if (merged.has(r.id))
|
|
431
|
+
if (merged.has(r.id) || proposalTouched.has(r.id))
|
|
127
432
|
continue;
|
|
128
433
|
const n = normalizeTitle(r.body);
|
|
129
434
|
if (!n)
|
|
@@ -133,11 +438,13 @@ export function planCuration(records) {
|
|
|
133
438
|
id: r.id,
|
|
134
439
|
before: n.before,
|
|
135
440
|
after: n.after,
|
|
441
|
+
signal: "title:normalize",
|
|
136
442
|
undo: undoLine("normalize-title", r.id),
|
|
137
443
|
reason: "first line is the de-facto title; whitespace normalized, no content changed",
|
|
138
444
|
});
|
|
139
445
|
}
|
|
140
|
-
// Near-duplicates are a report
|
|
446
|
+
// Near-duplicates are a report (the batch tier promotes only the 0.9+ ones
|
|
447
|
+
// above). Keep the full 0.8 list so a human can see the ambiguous pairs.
|
|
141
448
|
const nearDuplicates = [];
|
|
142
449
|
for (let i = 0; i < nonEmpty.length; i++) {
|
|
143
450
|
for (let j = i + 1; j < nonEmpty.length; j++) {
|
|
@@ -159,11 +466,26 @@ export function planCuration(records) {
|
|
|
159
466
|
const order = {
|
|
160
467
|
"archive-empty": 0,
|
|
161
468
|
"merge-duplicate": 1,
|
|
162
|
-
"
|
|
469
|
+
"infer-type": 2,
|
|
470
|
+
"infer-tags": 3,
|
|
471
|
+
"normalize-title": 4,
|
|
163
472
|
};
|
|
164
473
|
actions.sort((a, b) => order[a.kind] - order[b.kind] || a.id.localeCompare(b.id));
|
|
474
|
+
const batchOrder = {
|
|
475
|
+
"semantic-merge": 0,
|
|
476
|
+
split: 1,
|
|
477
|
+
"infer-type": 2,
|
|
478
|
+
"infer-tags": 3,
|
|
479
|
+
};
|
|
480
|
+
proposals.sort((a, b) => batchOrder[a.kind] - batchOrder[b.kind] || a.id.localeCompare(b.id));
|
|
165
481
|
skipped.sort((a, b) => a.id.localeCompare(b.id));
|
|
166
|
-
return {
|
|
482
|
+
return {
|
|
483
|
+
actions,
|
|
484
|
+
proposals,
|
|
485
|
+
nearDuplicates,
|
|
486
|
+
skipped,
|
|
487
|
+
batchId: proposals.length > 0 ? batchIdFor(proposals) : null,
|
|
488
|
+
};
|
|
167
489
|
}
|
|
168
490
|
/** One human-readable receipt line for an action that was applied. */
|
|
169
491
|
export function formatCurationAction(a) {
|
|
@@ -173,5 +495,41 @@ export function formatCurationAction(a) {
|
|
|
173
495
|
if (a.kind === "archive-empty") {
|
|
174
496
|
return `archived ${a.id} (empty body; undo: ${a.undo})`;
|
|
175
497
|
}
|
|
498
|
+
if (a.kind === "infer-type") {
|
|
499
|
+
return `inferred type ${a.id}: ${a.fromType} -> ${a.toType} (undo: ${a.undo})`;
|
|
500
|
+
}
|
|
501
|
+
if (a.kind === "infer-tags") {
|
|
502
|
+
return `inferred tags ${a.id}: +${(a.addedTags ?? []).join(", +")} (undo: ${a.undo})`;
|
|
503
|
+
}
|
|
176
504
|
return `normalized ${a.id} title ${JSON.stringify(a.before)} -> ${JSON.stringify(a.after)} (undo: ${a.undo})`;
|
|
177
505
|
}
|
|
506
|
+
/** One line for the batch-confirm screen. */
|
|
507
|
+
export function formatBatchProposal(p) {
|
|
508
|
+
if (p.kind === "semantic-merge") {
|
|
509
|
+
return `[merge] ${p.id} -> ${p.canonicalId} (similarity ${(p.score ?? 0).toFixed(2)}): ${p.reason}`;
|
|
510
|
+
}
|
|
511
|
+
if (p.kind === "split") {
|
|
512
|
+
return `[split] ${p.id}: ${p.reason}`;
|
|
513
|
+
}
|
|
514
|
+
if (p.kind === "infer-type") {
|
|
515
|
+
return `[type] ${p.id}: ${p.fromType} -> ${p.toType} (${p.reason})`;
|
|
516
|
+
}
|
|
517
|
+
return `[tag] ${p.id}: +${(p.addedTags ?? []).join(", +")} (${p.reason})`;
|
|
518
|
+
}
|
|
519
|
+
/**
|
|
520
|
+
* The one summary screen for the batch tier. Nothing here is applied; the
|
|
521
|
+
* caller either passes an accept/decline decision or shows this verbatim.
|
|
522
|
+
*/
|
|
523
|
+
export function formatBatchSummary(plan, opts) {
|
|
524
|
+
if (!plan.batchId || plan.proposals.length === 0)
|
|
525
|
+
return "";
|
|
526
|
+
const lines = [];
|
|
527
|
+
lines.push(`batch-confirm ${plan.batchId}: ${plan.proposals.length} proposal(s) — one decision, never per-item approval:`);
|
|
528
|
+
for (const p of plan.proposals)
|
|
529
|
+
lines.push(` ${formatBatchProposal(p)}`);
|
|
530
|
+
const idList = opts.ids.join(" ");
|
|
531
|
+
lines.push(` accept all: open-memex submit ${idList} --accept-batch`);
|
|
532
|
+
lines.push(` decline all: open-memex submit ${idList} --decline-batch (the batch stays unchanged; the deterministic tier still runs on the re-run)`);
|
|
533
|
+
lines.push(` after accepting, undo the whole batch: open-memex curate undo --batch ${plan.batchId}`);
|
|
534
|
+
return lines.join("\n");
|
|
535
|
+
}
|
package/dist/init.js
CHANGED
|
@@ -114,6 +114,10 @@ yet. Syncing them into the repo for review is an explicit, user-approved step:
|
|
|
114
114
|
copies the drafts into the current project's \`.ai/open-memex/\` directory as
|
|
115
115
|
\`proposed\` and commits locally on the CURRENT branch. It NEVER creates a
|
|
116
116
|
branch on its own.
|
|
117
|
+
- If the result says a BATCH DECISION is required, show that one summary and ask
|
|
118
|
+
the user once for the whole batch. Call again with \`curateBatch="accept"\` or
|
|
119
|
+
\`"decline"\` — never per-item confirmations, and never accept on your own
|
|
120
|
+
judgement.
|
|
117
121
|
- After the submit, ask ONE follow-up: "want me to create a branch + push +
|
|
118
122
|
open the PR, or will you handle it yourself?" A "yes, you do it" answer
|
|
119
123
|
covers the whole chain — branch creation, push, PR creation — do NOT re-ask
|
package/dist/mcp.js
CHANGED
|
@@ -81,9 +81,14 @@ them by these full names.
|
|
|
81
81
|
open the PR, or will you handle it yourself?" NEVER create branches, push, or
|
|
82
82
|
open PRs without the user's explicit approval. A "yes, you do it" covers the
|
|
83
83
|
whole chain — do NOT re-ask at each step.
|
|
84
|
-
- memory_submit prints its
|
|
85
|
-
|
|
86
|
-
not hide an automatic change to the user's memories.
|
|
84
|
+
- memory_submit prints its curation receipts (duplicate merges, empty-body
|
|
85
|
+
archives, title normalization, inferred type/tags) with undo commands. Relay
|
|
86
|
+
them; do not hide an automatic change to the user's memories.
|
|
87
|
+
- If memory_submit reports that a BATCH DECISION is required, show that single
|
|
88
|
+
summary and ask the user ONCE for the whole batch, then call again with
|
|
89
|
+
curateBatch="accept" or "decline". Semantic merges, splits and uncertain
|
|
90
|
+
type/tag inferences are never applied without that one decision, and never
|
|
91
|
+
per item.
|
|
87
92
|
- BE PROACTIVE about facts the user states directly: when the user shares a
|
|
88
93
|
decision, preference, project convention, or fix-and-cause worth remembering
|
|
89
94
|
across sessions, call memory_add without being asked. Keep each memory to one
|