@lorekit/cli 1.48.0 → 1.49.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lorekit/cli",
3
- "version": "1.48.0",
3
+ "version": "1.49.0",
4
4
  "description": "Install the LoreKit shared-memory skill and run health checks for the LoreKit MCP server.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -419,7 +419,7 @@ const MEMORY_DISPATCH = {
419
419
  // networkError, unusable }`. A tool that passed either through verbatim would
420
420
  // hand the model two different contracts for one tool name depending on a
421
421
  // config value it cannot see. What is left here is what only the MCP surface
422
- // owns: the ascending sort and the exit-clean degradation below.
422
+ // owns: the count-desc-then-scope-asc sort and the exit-clean degradation below.
423
423
  //
424
424
  // DEGRADATION IS EXIT-CLEAN, mirroring the `scopes` command, which reports an
425
425
  // unreachable remote as a short note at exit 0 rather than failing the run. An
@@ -441,31 +441,31 @@ export async function listScopes(store) {
441
441
  return ok ? { ok: true, scopes: sortScopes(scopes) } : { ok: true, scopes: [], note: reason };
442
442
  }
443
443
 
444
- // Sorted by scope ascending, which is the contract `docs/mcp-tools.md`, the
445
- // tool catalog and `llms.txt` all state for `memory.scopes`. The HOSTED surface
446
- // gets that ordering from `lorekit_memory_scopes` (`order by m.scope asc`,
447
- // migration 00039/00049), but `LocalStore`/`TwoTierStore.listScopes()` both
448
- // return their `Map` insertion order — a walk order, not an ordering — so the
449
- // stdio server owns it here rather than the two surfaces answering differently.
450
- // Sorting BOTH shapes (not just the local one) makes the guarantee a property
451
- // of this function instead of an assumption about the store it was handed.
452
- // Codepoint comparison, deliberately not `localeCompare`: the ordering must not
453
- // depend on the HOST's locale.
444
+ // Sorted by count DESC then scope asc, which is the contract `docs/mcp-tools.md`,
445
+ // the tool catalog and `llms.txt` all state for `memory.scopes`. The HOSTED
446
+ // surface gets that ordering from `lorekit_memory_scopes` (`order by count(*)
447
+ // desc, m.scope asc`, migration 00065), but `LocalStore`/`TwoTierStore.
448
+ // listScopes()` both return their `Map` insertion order — a walk order, not an
449
+ // ordering — so the stdio server owns it here rather than the two surfaces
450
+ // answering differently. Sorting BOTH shapes (not just the local one) makes the
451
+ // guarantee a property of this function instead of an assumption about the store
452
+ // it was handed.
454
453
  //
455
- // That is ascending-by-scope, not byte-identical parity with the hosted path,
456
- // and the difference is worth being precise about. `order by m.scope asc` sorts
457
- // under the DATABASE's collation (`en_US.UTF-8` on a default Supabase project),
458
- // which does not order like codepoint around punctuation and a scope string
459
- // is mostly punctuation (`::`, `/`, `-`), so `repo::a-b` and `repo::ab` can come
460
- // out in the opposite relative order on the two surfaces. Case cannot differ
461
- // (every scope segment is lowercased, see docs/scope-format.md). Closing the
462
- // remaining gap means `collate "C"` on the RPC's `order by`, which changes the
463
- // order `GET /memories/scopes` has always returned a public contract change
464
- // that belongs in its own migration, not here. Until then: both surfaces are
465
- // sorted ascending, neither is unordered, and nothing should depend on the two
466
- // agreeing on the exact position of a punctuated neighbour.
454
+ // The primary key is `count` (a number), which orders identically on both
455
+ // surfaces. Only the scope-asc TIEBREAK between equal-count scopes carries the
456
+ // old caveat: it is a codepoint comparison here (deliberately not
457
+ // `localeCompare`, so the ordering never depends on the HOST's locale), while
458
+ // `order by m.scope asc` sorts under the DATABASE's collation (`en_US.UTF-8` on a
459
+ // default Supabase project), which does not order like codepoint around
460
+ // punctuation — and a scope string is mostly punctuation (`::`, `/`, `-`), so
461
+ // two equal-count scopes like `repo::a-b` and `repo::ab` can come out in the
462
+ // opposite relative order on the two surfaces. Case cannot differ (every scope
463
+ // segment is lowercased, see docs/scope-format.md). Nothing should depend on the
464
+ // two agreeing on the exact position of a punctuated equal-count neighbour.
467
465
  function sortScopes(rows) {
468
- return rows.sort((a, b) => (a.scope < b.scope ? -1 : a.scope > b.scope ? 1 : 0));
466
+ return rows.sort(
467
+ (a, b) => b.count - a.count || (a.scope < b.scope ? -1 : a.scope > b.scope ? 1 : 0),
468
+ );
469
469
  }
470
470
 
471
471
  // Provenance for a tool call: the caller's explicit values win, the working
@@ -257,7 +257,7 @@ class RemoteStore {
257
257
  // The `scopes` array is the SAME `[{ scope, count }]` inventory shape
258
258
  // `LocalStore.listScopes()` returns, so `scopes.mjs` feeds both through the
259
259
  // same pure `filterScopeInventory`/`summarizeScopeInventory` helpers. Ordering
260
- // is not relied upon (the server sorts by scope asc; the view re-sorts by
260
+ // is not relied upon (the server sorts by count desc; the view re-sorts by
261
261
  // scope type). Failures use this store's standard `{ ok:false, error,
262
262
  // networkError }` envelope so the caller can degrade gracefully.
263
263
  //