moflo 4.11.6 → 4.11.7
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.
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
## Rule (MUST)
|
|
6
6
|
|
|
7
|
-
When a search hit carries a non-null `navigation` field
|
|
7
|
+
When a search hit carries a non-null `navigation` field and you need adjacent context, prefer `memory_search` with `expand: 'neighbors'` — it inlines each chunk hit's prev/next content in the SAME call (one round-trip, no re-embedding). Otherwise traverse via `mcp__moflo__memory_get_neighbors`. NEVER bulk-retrieve every hit with `memory_retrieve` — the `navigation` crumb is the chunking architecture's contract, and bulk-retrieving defeats it (protocol violation). NEVER `Read` a chunk's `parentPath` for surrounding context when `expand`/neighbors would do — a full-doc Read costs far more tokens. Use `memory_retrieve` only for a single specific key you already hold, or for non-chunk entries where `navigation` is null.
|
|
8
8
|
|
|
9
9
|
---
|
|
10
10
|
|
|
@@ -146,7 +146,8 @@ Once you have a search hit, pick the right follow-up call by what you need next.
|
|
|
146
146
|
| You want | Use | Why |
|
|
147
147
|
|----------|-----|-----|
|
|
148
148
|
| Find an entry-point | `mcp__moflo__memory_search` | Returns chunk hits with `navigation` (parentDoc, prev/next, chunkTitle) |
|
|
149
|
-
| Adjacent context
|
|
149
|
+
| Adjacent context AND you're still searching | `mcp__moflo__memory_search` `{ query, expand: 'neighbors' }` | Cheapest — prev/next content inlined in the search call itself, zero extra round-trips |
|
|
150
|
+
| Adjacent context for a hit you already have | `mcp__moflo__memory_get_neighbors` `{ key, include: ['prev','next'] }` | One round-trip, shaped entries with full nav |
|
|
150
151
|
| Same-section peers (h2/h3 family) | `memory_get_neighbors` `{ include: ['siblings'] }` or `['parent','children']` | Hierarchical traversal — cheaper than re-searching |
|
|
151
152
|
| Full content of one specific chunk | `mcp__moflo__memory_retrieve` `{ key }` | For a key you already hold — never for bulk-retrieving search hits |
|
|
152
153
|
| Whole source doc when truly needed | `Read` `parentPath` from any chunk's nav | Disk read is cheaper than re-indexed `doc-*` |
|
|
@@ -90,6 +90,20 @@ function parseNavigation(metadataJson, mode) {
|
|
|
90
90
|
headerLevel: meta.headerLevel,
|
|
91
91
|
};
|
|
92
92
|
}
|
|
93
|
+
// #1262 lever #1 (dedup-by-source): collapse multiple representations of the
|
|
94
|
+
// SAME underlying source to one result slot. Dogfooding showed a dense query's
|
|
95
|
+
// top-8 is routinely ~40% duplicates — e.g. one file indexed in code-map as
|
|
96
|
+
// `file:<path>` AND in patterns as `pattern:file:<path>`, or a test surfaced as
|
|
97
|
+
// both `file:<path>` and `test-file:<path>`. Path-bearing keys reduce to their
|
|
98
|
+
// path; symbol/chunk/learning keys keep their own identity (a `pattern:class:X`
|
|
99
|
+
// symbol view is NOT the same source as the file, so it survives separately).
|
|
100
|
+
// Operates purely on logical DB keys (always forward-slash), so platform-agnostic.
|
|
101
|
+
function sourceIdOf(key) {
|
|
102
|
+
const pathMatch = key.match(/^(?:pattern:)?(?:file|test-file|dir):(.+)$/);
|
|
103
|
+
if (pathMatch)
|
|
104
|
+
return `src:${pathMatch[1]}`;
|
|
105
|
+
return key.startsWith('pattern:') ? key.slice('pattern:'.length) : key;
|
|
106
|
+
}
|
|
93
107
|
function shapeRetrievedEntry(entry) {
|
|
94
108
|
let value = entry.content;
|
|
95
109
|
try {
|
|
@@ -325,39 +339,53 @@ export const memoryTools = [
|
|
|
325
339
|
},
|
|
326
340
|
{
|
|
327
341
|
name: 'memory_search',
|
|
328
|
-
description: 'Semantic vector search using HNSW index (150x-12,500x faster than keyword search).
|
|
342
|
+
description: 'Semantic vector search using HNSW index (150x-12,500x faster than keyword search). On chunk hits (non-null `navigation`) you MUST get adjacent context via chunk traversal, never a full-doc `Read`: prefer `expand: "neighbors"` in THIS call (cheapest — inlines prev/next), else `memory_get_neighbors`. Bulk `memory_retrieve` per hit is a protocol violation. See `.claude/guidance/moflo-memory-protocol.md`.',
|
|
329
343
|
category: 'memory',
|
|
330
344
|
inputSchema: {
|
|
331
345
|
type: 'object',
|
|
332
346
|
properties: {
|
|
333
347
|
query: { type: 'string', description: 'Search query (semantic similarity)' },
|
|
334
348
|
namespace: { type: 'string', description: 'Namespace to search (default: all namespaces)' },
|
|
335
|
-
limit: { type: 'number', description: 'Maximum results (default: 8)' },
|
|
349
|
+
limit: { type: 'number', description: 'Maximum results (default: 8). Multiple representations of the same source (a file indexed in both code-map and patterns, a test surfaced as both file and test-file) are collapsed to one before this cap, so every slot is a distinct source.' },
|
|
336
350
|
threshold: { type: 'number', description: 'Minimum similarity threshold 0-1 (default: 0.5)' },
|
|
351
|
+
expand: {
|
|
352
|
+
type: 'string',
|
|
353
|
+
enum: ['neighbors'],
|
|
354
|
+
description: "Set to 'neighbors' to inline each chunk hit's adjacent (prev/next) chunk content in this single call. Use instead of a follow-up full-doc `Read` when you need surrounding context. Off by default to keep the envelope lean.",
|
|
355
|
+
},
|
|
337
356
|
},
|
|
338
357
|
required: ['query'],
|
|
339
358
|
},
|
|
340
359
|
handler: async (input) => {
|
|
341
360
|
await ensureInitialized();
|
|
342
|
-
const { searchEntries } = await getMemoryFunctions();
|
|
361
|
+
const { searchEntries, getEntry } = await getMemoryFunctions();
|
|
343
362
|
const query = input.query;
|
|
344
363
|
const namespace = input.namespace || 'all';
|
|
345
|
-
// #1053 S6:
|
|
364
|
+
// #1053 S6: injected-token bar. Each returned hit is injected verbatim,
|
|
365
|
+
// so keep the cap tight — but #1262 dedup (below) makes every one of these
|
|
366
|
+
// slots a DISTINCT source rather than 8 slots holding ~5 uniques + dupes.
|
|
346
367
|
const limit = input.limit || 8;
|
|
347
368
|
// Falsiness check would coerce a caller-supplied 0 to default and silently
|
|
348
369
|
// filter low-similarity matches; use a typeof guard so explicit zero
|
|
349
370
|
// means "no threshold" (#837).
|
|
350
371
|
const threshold = typeof input.threshold === 'number' ? input.threshold : 0.5;
|
|
372
|
+
// #1262 lever #3: opt-in single-call neighbor expansion.
|
|
373
|
+
const wantExpand = input.expand === 'neighbors' || input.expand === true;
|
|
374
|
+
// #1262 lever #1: over-fetch so dedup-by-source can still return a FULL
|
|
375
|
+
// `limit` distinct sources. Local HNSW makes the extra hits free (they're
|
|
376
|
+
// just not injected); 3x headroom clears the ~40% duplication observed in
|
|
377
|
+
// dogfooding. Capped so an explicit large limit can't blow up the fetch.
|
|
378
|
+
const overscan = Math.min(limit * 3, 50);
|
|
351
379
|
validateMemoryInput(undefined, undefined, query);
|
|
352
380
|
try {
|
|
353
381
|
const result = await searchEntries({
|
|
354
382
|
query,
|
|
355
383
|
namespace,
|
|
356
|
-
limit,
|
|
384
|
+
limit: overscan,
|
|
357
385
|
threshold,
|
|
358
386
|
});
|
|
359
387
|
// Parse JSON values in results
|
|
360
|
-
const
|
|
388
|
+
const mapped = result.results.map(r => {
|
|
361
389
|
let value = r.content;
|
|
362
390
|
try {
|
|
363
391
|
value = JSON.parse(r.content);
|
|
@@ -379,13 +407,67 @@ export const memoryTools = [
|
|
|
379
407
|
navigation,
|
|
380
408
|
};
|
|
381
409
|
});
|
|
410
|
+
// #1262 lever #1: collapse duplicate representations of the same source,
|
|
411
|
+
// keeping the highest-scoring one (results arrive score-desc), then trim
|
|
412
|
+
// to `limit`. Net effect vs. the old code: `limit` DISTINCT sources
|
|
413
|
+
// instead of `limit` slots that were often ~40% near-duplicates.
|
|
414
|
+
const seenSources = new Set();
|
|
415
|
+
const results = [];
|
|
416
|
+
for (const hit of mapped) {
|
|
417
|
+
const id = sourceIdOf(hit.key);
|
|
418
|
+
if (seenSources.has(id))
|
|
419
|
+
continue;
|
|
420
|
+
seenSources.add(id);
|
|
421
|
+
results.push(hit);
|
|
422
|
+
if (results.length >= limit)
|
|
423
|
+
break;
|
|
424
|
+
}
|
|
425
|
+
// #1262 lever #3: when asked, fetch each chunk hit's prev/next content
|
|
426
|
+
// inline (one round-trip) so the model doesn't fall back to a full-doc
|
|
427
|
+
// `Read` for surrounding context. Opt-in keeps the default lean.
|
|
428
|
+
if (wantExpand) {
|
|
429
|
+
await Promise.all(results.map(async (hit) => {
|
|
430
|
+
const nav = hit.navigation;
|
|
431
|
+
if (!nav)
|
|
432
|
+
return; // non-chunk hit — nothing adjacent to fetch
|
|
433
|
+
const targets = [
|
|
434
|
+
{ position: 'prev', key: nav.prevChunk },
|
|
435
|
+
{ position: 'next', key: nav.nextChunk },
|
|
436
|
+
].filter((t) => Boolean(t.key));
|
|
437
|
+
if (targets.length === 0)
|
|
438
|
+
return;
|
|
439
|
+
const fetched = await Promise.all(targets.map(async (t) => {
|
|
440
|
+
const res = await getEntry({ key: t.key, namespace: hit.namespace });
|
|
441
|
+
if (!res.found || !res.entry)
|
|
442
|
+
return null;
|
|
443
|
+
const entry = res.entry;
|
|
444
|
+
let value = entry.content;
|
|
445
|
+
try {
|
|
446
|
+
value = JSON.parse(entry.content);
|
|
447
|
+
}
|
|
448
|
+
catch { /* keep string */ }
|
|
449
|
+
return { position: t.position, key: t.key, value };
|
|
450
|
+
}));
|
|
451
|
+
const neighbors = fetched.filter((n) => n !== null);
|
|
452
|
+
if (neighbors.length > 0)
|
|
453
|
+
hit.expanded = neighbors;
|
|
454
|
+
}));
|
|
455
|
+
}
|
|
382
456
|
notifyMemoryGate();
|
|
457
|
+
// #1262 lever #3: steer away from full-doc `Read` toward the cheap
|
|
458
|
+
// adjacent-context path — but only when it's actionable (chunk hits
|
|
459
|
+
// present and the caller didn't already expand), so the hint itself
|
|
460
|
+
// costs no tokens on the common case.
|
|
461
|
+
const nextStep = !wantExpand && results.some(r => r.navigation)
|
|
462
|
+
? "Chunk hits present. For adjacent context, re-call memory_search with expand:'neighbors' (one call) rather than Read-ing parentPath — full-doc Read costs far more tokens."
|
|
463
|
+
: undefined;
|
|
383
464
|
// #1053 S6: searchTime dropped from MCP envelope (CLI keeps it for
|
|
384
465
|
// human reading); `backend` retained — doctor reads it (#1053 epic).
|
|
385
466
|
return {
|
|
386
467
|
query,
|
|
387
468
|
results,
|
|
388
469
|
total: results.length,
|
|
470
|
+
...(nextStep ? { nextStep } : {}),
|
|
389
471
|
backend: BACKEND_LABEL,
|
|
390
472
|
};
|
|
391
473
|
}
|
package/dist/src/cli/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "moflo",
|
|
3
|
-
"version": "4.11.
|
|
3
|
+
"version": "4.11.7",
|
|
4
4
|
"description": "MoFlo — AI agent orchestration for Claude Code. A standalone, opinionated toolkit with semantic memory, learned routing, gates, spells, and the /flo issue-execution skill.",
|
|
5
5
|
"main": "dist/src/cli/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
"@typescript-eslint/eslint-plugin": "^7.18.0",
|
|
95
95
|
"@typescript-eslint/parser": "^7.18.0",
|
|
96
96
|
"eslint": "^8.0.0",
|
|
97
|
-
"moflo": "^4.11.
|
|
97
|
+
"moflo": "^4.11.6",
|
|
98
98
|
"tsx": "^4.21.0",
|
|
99
99
|
"typescript": "^5.9.3",
|
|
100
100
|
"vitest": "^4.0.0"
|