cribsheet 0.24.0.dev2__py3-none-any.whl → 0.24.0.dev3__py3-none-any.whl

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.
crib/app.py CHANGED
@@ -920,16 +920,29 @@ class Crib:
920
920
  spec: facets.FacetSpec,
921
921
  fields: dict[str, Any] | None,
922
922
  where: list[dict[str, Any]] | None,
923
+ tags: list[str] | None = None,
923
924
  ) -> list[dict[str, Any]]:
924
925
  """A facet's items in `proj` whose own fields match the filters (crib.fields),
925
- by relpath: relpath, title, and the declared fields (plus the symbol, for
926
- an anchored facet)."""
926
+ by relpath: relpath, title, tags (its own, plus its `type`), and the
927
+ declared fields (plus the symbol, for an anchored facet). `tags`: only
928
+ items carrying any of them."""
927
929
  conds = conditions(spec, fields, where)
930
+ # tags live on the chunks (`labels`: the note's tags plus its type)
931
+ labels: dict[str, list[str]] = {}
932
+ for m in self.store.get_meta({"project": proj, "kind": spec.noun}).values():
933
+ rel = str(m.get("relpath") or "")
934
+ for t in m.get("labels") or []:
935
+ if t not in labels.setdefault(rel, []):
936
+ labels[rel].append(t)
937
+ want = set(tags or [])
928
938
  out = []
929
939
  for it in self.store.items({"project": proj, "kind": spec.noun}).values():
930
940
  if not matches(conds, it.facet):
931
941
  continue
932
- row: dict[str, Any] = {"relpath": it.relpath, "title": it.title}
942
+ have = labels.get(it.relpath, [])
943
+ if want and not want & set(have):
944
+ continue
945
+ row: dict[str, Any] = {"relpath": it.relpath, "title": it.title, "tags": have}
933
946
  if spec.has("anchored"):
934
947
  row["symbol"] = it.facet.get("symbol_ref")
935
948
  row.update({k: it.facet.get(k) for k in spec.params})
@@ -945,12 +958,14 @@ class Crib:
945
958
  fields: dict[str, Any] | None = None,
946
959
  where: list[dict[str, Any]] | None = None,
947
960
  k: int = 50,
961
+ tags: list[str] | None = None,
948
962
  ) -> dict[str, Any]:
949
963
  """A declared facet's items filtered by its own fields, no query: `fields`
950
- are equality filters, `where` the operator conditions (crib.fields)."""
964
+ are equality filters, `where` the operator conditions (crib.fields),
965
+ `tags` any of the items' tags (a file's `type` counts as one)."""
951
966
  proj = self.resolve_project(project, cwd)
952
967
  self._require_conformed(facet)
953
- rows = self._field_items(proj, facets.by_noun(facet), fields, where)
968
+ rows = self._field_items(proj, facets.by_noun(facet), fields, where, tags)
954
969
  return {"project": proj, "total": len(rows), "items": rows[:k]}
955
970
 
956
971
  def abspath(self, project: str, relpath: str, facet: str = facets.HOME) -> Path:
@@ -1290,7 +1305,8 @@ class Crib:
1290
1305
  facet: str = facets.HOME,
1291
1306
  ) -> str:
1292
1307
  proj = self.resolve_project(project, cwd)
1293
- return str(self.abspath(proj, relpath, facet))
1308
+ store = self._facet_store(facet)
1309
+ return str(store.abspath(proj, store.resolve(proj, relpath)))
1294
1310
 
1295
1311
  async def reindex(
1296
1312
  self,
@@ -2497,6 +2513,7 @@ class Crib:
2497
2513
  "created": new_project,
2498
2514
  "docs_indexed": docs.get("docs", 0),
2499
2515
  **({"facets_mapped": mapped} if mapped else {}),
2516
+ **({"facets": fs} if (fs := self._mapping_summary(proj)) else {}),
2500
2517
  **code,
2501
2518
  }
2502
2519
 
@@ -2639,9 +2656,33 @@ class Crib:
2639
2656
  "crib_created": created,
2640
2657
  "created": new_project,
2641
2658
  "docs_indexed": docs.get("docs", 0),
2659
+ **({"facets": fs} if (fs := self._mapping_summary(proj)) else {}),
2642
2660
  **code,
2643
2661
  }
2644
2662
 
2663
+ def _mapping_summary(self, proj: str) -> dict[str, Any]:
2664
+ """Each facet mapped in `proj` (its `.crib` `facets:`, as recorded):
2665
+ where, how, and how many of its items are indexed (or why none are)."""
2666
+ out: dict[str, Any] = {}
2667
+ for store, loc in self.project_paths(proj).mappings.items():
2668
+ spec = facets.by_store(store)
2669
+ if spec is None or loc.prefix is not None:
2670
+ continue
2671
+ row: dict[str, Any] = {"dir": loc.token, "glob": loc.glob,
2672
+ "read_only": loc.read_only, "ids": loc.ids}
2673
+ pillar = self.pillars.get(store)
2674
+ if spec.noun in self.pending_facets:
2675
+ row["waiting"] = "for `crib facets sync --apply`"
2676
+ elif pillar is not None and (why := pillar.pending_move(proj)):
2677
+ row["waiting"] = why
2678
+ elif not loc.available:
2679
+ row["waiting"] = "its dir isn't on this machine"
2680
+ else:
2681
+ row["items"] = len(self.store.items(
2682
+ {"project": proj, "kind": spec.noun}, vectors=False))
2683
+ out[spec.noun] = row
2684
+ return out
2685
+
2645
2686
  async def project_wait(
2646
2687
  self,
2647
2688
  project: str | None = None,
crib/cli.py CHANGED
@@ -596,6 +596,13 @@ def _emit_project(d: Any, verb: str | None, as_json: bool) -> None:
596
596
  f"{d.get('symbols', 0)} symbols, {d.get('described', 0)} described"
597
597
  f"{fails}{docs}{made}"
598
598
  )
599
+ for noun, f in (d.get("facets") or {}).items():
600
+ how = ", ".join(w for w in ("read-only" if f.get("read_only") else "",
601
+ "ids derived" if f.get("ids") == "derived" else "") if w)
602
+ state = (f"{f['items']} item(s) indexed" if "items" in f
603
+ else f"waiting {f.get('waiting', '')}")
604
+ print(f" facet {noun}: {f.get('dir')} {f.get('glob')}"
605
+ f"{f' ({how})' if how else ''}: {state}")
599
606
  errs = d.get("errors") or []
600
607
  if errs:
601
608
  print(f" {len(errs)} file(s) errored (first: {errs[0].get('file', '')})")
@@ -2302,12 +2309,14 @@ def _b_relpath(a: Any) -> dict[str, Any]:
2302
2309
  def _a_list(s: Any, proj: Any, f: Any) -> None:
2303
2310
  proj(s)
2304
2311
  s.add_argument("-k", type=int, default=50)
2312
+ s.add_argument("--tag", action="append", dest="tags",
2313
+ help="only items with this tag (a file's `type` counts; repeatable: any)")
2305
2314
 
2306
2315
 
2307
2316
  _LIST_CLI = _FacetCli(
2308
2317
  lambda f: f"list {f.plural} by their fields (no search query)",
2309
2318
  _a_list,
2310
- lambda a: {"project": a.project, "k": a.k},
2319
+ lambda a: {"project": a.project, "k": a.k, "tags": a.tags},
2311
2320
  _E, "list_items", False,
2312
2321
  )
2313
2322
 
crib/designs.py CHANGED
@@ -83,6 +83,7 @@ from .items import (
83
83
  prose_hash,
84
84
  )
85
85
  from .notes import Note
86
+ from .util import derived_ulid
86
87
 
87
88
  if TYPE_CHECKING:
88
89
  from .notestore import NoteStore
@@ -632,7 +633,7 @@ class Designs:
632
633
  # and what is already in the mapping (a teammate's committed items)
633
634
  loc = store.location(proj)
634
635
  if loc is not None and loc.available:
635
- nodes += self._nodes_owned(kind, loc)
636
+ nodes += self._nodes_owned(kind, loc, proj)
636
637
  for node in nodes:
637
638
  for src in node.sources:
638
639
  src["current"] = self._section_hash(proj, src, docs)
@@ -713,11 +714,15 @@ class Designs:
713
714
  if not ch:
714
715
  return
715
716
  parsed: list[tuple[str, dict[str, Any], str]] = []
717
+ loc = store.location(proj)
718
+ derived = loc is not None and loc.prefix is None and loc.ids == "derived"
716
719
  for name in sorted(ch.changed):
717
720
  try:
718
721
  fm, body = notes.parse((d / name).read_text(), d / name)
719
722
  except (OSError, UnicodeDecodeError, notes.NoteParseError):
720
723
  continue # one broken note must not blind the graph
724
+ if derived: # the id is the path's, whatever the file says
725
+ fm = {**fm, "id": derived_ulid(proj, name)}
721
726
  parsed.append((name, fm, body))
722
727
  rows = store.index.item_rows(proj, store.spec.name, parsed)
723
728
  files: list[tuple[str, int, int, list[Any]]] = []
@@ -748,9 +753,10 @@ class Designs:
748
753
  return out
749
754
 
750
755
  @staticmethod
751
- def _nodes_owned(kind: str, loc: Any) -> list[Node]:
756
+ def _nodes_owned(kind: str, loc: Any, proj: str = "") -> list[Node]:
752
757
  """`kind`'s nodes parsed from the files a mapped location owns (its
753
- glob), relpaths relative to the mapping."""
758
+ glob), relpaths relative to the mapping (ids derived from the path
759
+ under `ids: derived`)."""
754
760
  out: list[Node] = []
755
761
  for path in sorted(loc.root.rglob("*.md")):
756
762
  rel = str(path.relative_to(loc.root))
@@ -760,6 +766,8 @@ class Designs:
760
766
  fm, body = notes.parse(path.read_text(), path)
761
767
  except (OSError, UnicodeDecodeError, notes.NoteParseError):
762
768
  continue
769
+ if loc.ids == "derived":
770
+ fm = {**fm, "id": derived_ulid(proj, rel)}
763
771
  if fm.get("id"):
764
772
  out.append(_node_from_file(kind, rel, fm, body))
765
773
  return out
crib/doctor.py CHANGED
@@ -10,6 +10,8 @@ Checks:
10
10
  - citations whose source section is gone or has changed since recorded;
11
11
  - learnings whose symbol moved or is gone;
12
12
  - one id in several files;
13
+ - a declared facet's field value that doesn't fit its type (`timeout: 30s`);
14
+ - a declared facet's item with no title (none of its `title_from` sources);
13
15
  - near-duplicate notes / decisions / plans (stored vectors, all pairs);
14
16
  - symbols waiting for a description (outside generation mode "on").
15
17
  """
@@ -137,6 +139,8 @@ def diagnose(crib: Crib, proj: str) -> dict[str, Any]:
137
139
  findings += _duplicate_ids(crib, proj)
138
140
  findings += _near_duplicates(crib, proj)
139
141
  findings += _unstamped(crib, proj)
142
+ findings += _mistyped_fields(crib, proj)
143
+ findings += _untitled(crib, proj)
140
144
 
141
145
  gen = crib._generation_state([{"project": proj, "symbols": 1}])
142
146
  pending = (gen.get("pending_descriptions") or {}).get(proj)
@@ -161,6 +165,87 @@ def diagnose(crib: Crib, proj: str) -> dict[str, Any]:
161
165
  }
162
166
 
163
167
 
168
+ def _mistyped_fields(crib: Crib, proj: str) -> list[dict[str, Any]]:
169
+ """A declared facet's field whose value in a file doesn't fit its type
170
+ (`timeout: 30s` on an int field): the index keeps it as empty, so the item
171
+ quietly drops out of every filter on that field. Read from the files (the
172
+ truth), mapped or not; hand-edited ones are where this happens."""
173
+ from . import notes
174
+ from .errors import CribUserError
175
+ from .filesync import scan
176
+
177
+ out = []
178
+ for spec in facets.FACETS:
179
+ if spec.builtin or not spec.params or spec.noun in crib.pending_facets:
180
+ continue
181
+ store = crib.pillars.get(spec.store)
182
+ if store is None:
183
+ continue
184
+ loc = store.location(proj)
185
+ try:
186
+ root = loc.root if loc is not None else store.root(proj)
187
+ except CribUserError: # pending a move, or not on this machine
188
+ continue
189
+ if not root.is_dir():
190
+ continue
191
+ for rel in sorted(scan(root, ".md", recursive=True)):
192
+ if loc is not None and not loc.owns(rel):
193
+ continue
194
+ try:
195
+ fm, _body = notes.parse((root / rel).read_text())
196
+ except (OSError, UnicodeDecodeError, notes.NoteParseError):
197
+ continue
198
+ out += [{"item": rel, **f} for f in _misfits(spec, fm)]
199
+ return out
200
+
201
+
202
+ def _untitled(crib: Crib, proj: str) -> list[dict[str, Any]]:
203
+ """A declared facet's items that came out with no title: none of its
204
+ `title_from` sources (default: the frontmatter `title`) yielded one. The
205
+ facet insists on titles; name each, and the two ways out."""
206
+ out = []
207
+ for spec in facets.FACETS:
208
+ if spec.builtin or spec.noun in crib.pending_facets:
209
+ continue
210
+ for it in crib.store.items({"project": proj, "kind": spec.noun}, vectors=False).values():
211
+ if not (it.title or "").strip():
212
+ out.append({
213
+ "check": "no title",
214
+ "item": it.relpath,
215
+ "kind": spec.noun,
216
+ "fix": f"give it a `title:` (or a `# heading`), or let the facet "
217
+ f"name its items another way: `title_from = [\"title\", "
218
+ f"\"heading\", \"filename\"]` in its [{spec.noun}] spec",
219
+ })
220
+ return sorted(out, key=lambda f: f["item"])
221
+
222
+
223
+ def _misfits(spec: Any, fm: dict[str, Any]) -> list[dict[str, Any]]:
224
+ """The findings for one file's frontmatter: each field value that doesn't
225
+ fit its declared type (fields.coerce refuses it)."""
226
+ from . import fields as _fields
227
+ from .errors import CribUserError
228
+
229
+ out = []
230
+ for name, kind in spec.params.items():
231
+ value = fm.get(name)
232
+ if value is None:
233
+ continue
234
+ try:
235
+ _fields.coerce(spec, name, value)
236
+ except CribUserError:
237
+ takes = "an ISO date (YYYY-MM-DD)" if kind == "date" else f"an {kind}"
238
+ out.append({
239
+ "check": "field value doesn't fit its type",
240
+ "kind": spec.noun,
241
+ "field": name,
242
+ "value": str(value),
243
+ "fix": f"`{name}` takes {takes}: correct it in the file (until then "
244
+ f"the item has no value for it, so filters on `{name}` miss it)",
245
+ })
246
+ return out
247
+
248
+
164
249
  def _unstamped(crib: Crib, proj: str) -> list[dict[str, Any]]:
165
250
  """A read-only, id-stamped mapped location's files with no id yet: they are
166
251
  not indexed (a temporary id would flip under their links), so say so, and
crib/errors.py CHANGED
@@ -26,3 +26,10 @@ from __future__ import annotations
26
26
 
27
27
  class CribUserError(ValueError):
28
28
  """The caller can fix this by asking differently. The message says how."""
29
+
30
+
31
+ class NoSuchItem(CribUserError, FileNotFoundError):
32
+ """A read of an item that doesn't exist: a user error (a clean message, with
33
+ the nearest names) that is still the FileNotFoundError callers have always
34
+ caught for a missing file."""
35
+
crib/facets.py CHANGED
@@ -249,7 +249,7 @@ HOME = "note"
249
249
  _KEYS = frozenset(
250
250
  {"plural", "store", "aspects", "fields", "legacy_stores", "verbs", "disable",
251
251
  "status", "edges", "label", "requires_body", "extract", "report_taint",
252
- "export_with_deps", "about", "when"}
252
+ "export_with_deps", "about", "when", "title_from"}
253
253
  )
254
254
 
255
255
 
@@ -306,6 +306,10 @@ class FacetSpec:
306
306
  # this family (rather than notes). `when` adds wording to one verb's tool.
307
307
  about: str = ""
308
308
  when: Mapping[str, str] = field(default_factory=lambda: MappingProxyType({}))
309
+ # Where an item's title comes from, tried in order (item_title): its
310
+ # frontmatter `title`, its first `heading`, its `filename`, or a named
311
+ # frontmatter key (toucan's `name`). None found: no title (doctor says so).
312
+ title_from: tuple[str, ...] = ("title",)
309
313
  builtin: bool = False
310
314
 
311
315
  def has(self, aspect: str) -> bool:
@@ -417,6 +421,14 @@ def parse(noun: str, raw: Mapping[str, Any], *, builtin: bool = False) -> FacetS
417
421
  if not set(available) - set(disable):
418
422
  raise FacetSpecError(f"facet {noun!r}: disables every one of its verbs")
419
423
  about, when = _wording(noun, raw, [v for v in available if v not in disable])
424
+ title_from = raw.get("title_from", ["title"])
425
+ if isinstance(title_from, str):
426
+ title_from = [title_from]
427
+ if not isinstance(title_from, list) or not title_from or not all(
428
+ isinstance(t, str) and t.strip() for t in title_from):
429
+ raise FacetSpecError(
430
+ f"facet {noun!r}: title_from is a list of sources: \"title\", \"heading\", "
431
+ "\"filename\" or a frontmatter key")
420
432
  return FacetSpec(
421
433
  noun=noun,
422
434
  plural=plural,
@@ -429,11 +441,32 @@ def parse(noun: str, raw: Mapping[str, Any], *, builtin: bool = False) -> FacetS
429
441
  disabled=frozenset(str(v) for v in disable),
430
442
  about=about,
431
443
  when=MappingProxyType(when),
444
+ title_from=tuple(t.strip() for t in title_from),
432
445
  **graph,
433
446
  builtin=builtin,
434
447
  )
435
448
 
436
449
 
450
+ def item_title(spec: "FacetSpec | None", fm: Mapping[str, Any], body: str,
451
+ relpath: str) -> str:
452
+ """An item's title, by its facet's `title_from` (default: the frontmatter
453
+ `title` alone): the first source that yields one."""
454
+ import re
455
+
456
+ for src in (spec.title_from if spec is not None else ("title",)):
457
+ if src == "heading":
458
+ m = re.search(r"^#{1,6}[ \t]+(.+?)[ \t#]*$", body or "", re.M)
459
+ value: Any = m.group(1) if m else None
460
+ elif src == "filename":
461
+ name = relpath.rsplit("/", 1)[-1]
462
+ value = name[: -len(".md")] if name.endswith(".md") else name
463
+ else: # "title", or any other frontmatter key
464
+ value = fm.get(src)
465
+ if value is not None and str(value).strip():
466
+ return str(value).strip()
467
+ return ""
468
+
469
+
437
470
  def _wording(noun: str, raw: Mapping[str, Any],
438
471
  verbs: list[str]) -> tuple[str, dict[str, str]]:
439
472
  """A spec's `about` (str) and `[<noun>.when]` (verb = wording, one of its
@@ -692,6 +725,8 @@ def to_toml(specs: Iterable[FacetSpec]) -> str:
692
725
  out.append(f"label = {q(s.label)}")
693
726
  if s.about:
694
727
  out.append(f"about = {q(s.about)}")
728
+ if s.title_from != ("title",):
729
+ out.append(f"title_from = {arr(s.title_from)}")
695
730
  if s.requires_body:
696
731
  out.append("requires_body = true")
697
732
  if s.extract:
crib/indexer.py CHANGED
@@ -19,6 +19,7 @@ from collections import defaultdict
19
19
  from dataclasses import dataclass, field, replace
20
20
  from pathlib import Path
21
21
 
22
+ from . import facets as _facets
22
23
  from . import filesync, notes
23
24
  from .chunk import WINDOW_OVERLAP, WINDOW_WORDS, Chunk, chunk_note, kind_of
24
25
  from .embed import Embedder, embed_batch
@@ -280,7 +281,7 @@ class IndexEngine:
280
281
  note_id = str(fm.get("id") or "")
281
282
  if not note_id:
282
283
  continue
283
- title = str(fm.get("title") or "")
284
+ title = _facets.item_title(_facets.by_store(store), fm, body, relpath)
284
285
  want = self._want_item(project, store, relpath, note_id, title, body, fm)
285
286
  item, needs = self._against(want, have.get(note_id))
286
287
  if item is None:
@@ -327,9 +328,12 @@ class IndexEngine:
327
328
  rewrote = notes.heal_file(path) # self-heal merge-duplicated frontmatter (§14)
328
329
  note = notes.load(path)
329
330
  if doc:
330
- note_id = note.id or _derive_id(relpath)
331
+ # a repo's doc: its id is its (keyed) path's, never its own `id:`
332
+ note_id = _derive_id(relpath)
331
333
  elif ids == "derived":
332
- note_id = note.id or _derive_id(project, relpath)
334
+ # the id IS the path's: a file's own `id:` belongs to whatever
335
+ # else reads it (another tool's ids can repeat, or mean otherwise)
336
+ note_id = _derive_id(project, relpath)
333
337
  elif read_only and not note.id:
334
338
  # read-only and id-stamped, but no id yet: wait for a writable
335
339
  # checkout to stamp it, rather than give it an id that would flip
@@ -365,14 +369,17 @@ class IndexEngine:
365
369
  # content gate misses. Refresh metadata cheaply — no re-embed. Compare
366
370
  # ignoring file_mtime, which changes every reindex on its own.
367
371
  meta_updates: dict[str, dict] = {}
372
+ # the title by the facet's title_from (crib's own: the frontmatter's)
373
+ title = _facets.item_title(_facets.by_store(store), note.frontmatter, note.body,
374
+ relpath)
368
375
  for cid, c in new_by_id.items():
369
376
  if existing_hash.get(cid) == c.content_hash: # content unchanged
370
- new_meta = c.metadata(note.title, note.tags, source, mtime, note_type)
377
+ new_meta = c.metadata(title, note.tags, source, mtime, note_type)
371
378
  if _meta_stable(existing.get(cid, {})) != _meta_stable(new_meta):
372
379
  meta_updates[cid] = new_meta
373
380
 
374
381
  item, item_embed = self._item_for(
375
- project, store, relpath, note_id, note.title or "", note.body,
382
+ project, store, relpath, note_id, title, note.body,
376
383
  note.frontmatter)
377
384
  if not to_embed and not stale_ids and not meta_updates:
378
385
  return _Plan(note_id=note_id, item=item, item_embed=item_embed,
@@ -381,7 +388,7 @@ class IndexEngine:
381
388
 
382
389
  return _Plan(
383
390
  note_id=note_id,
384
- to_embed=[(c, c.metadata(note.title, note.tags, source, mtime, note_type))
391
+ to_embed=[(c, c.metadata(title, note.tags, source, mtime, note_type))
385
392
  for c in to_embed],
386
393
  stale_ids=stale_ids, meta_updates=meta_updates,
387
394
  item=item, item_embed=item_embed, wrote=wrote)
crib/notestore.py CHANGED
@@ -296,6 +296,9 @@ class NoteStore:
296
296
  raw = path.read_text()
297
297
  fallback = fallback_id or derived_ulid(project, relpath)
298
298
  ring = self.versions_for(project)
299
+ if self._policy(project).get("ids") == "derived":
300
+ ring.stash(fallback, raw) # the id is the path's (a file's own `id:` isn't crib's)
301
+ return fallback
299
302
  try:
300
303
  fm, body = notes.parse(raw, path)
301
304
  except NoteParseError:
@@ -328,7 +331,46 @@ class NoteStore:
328
331
  store=self.spec.name, **policy)
329
332
 
330
333
  def read(self, project: str, relpath: str) -> str:
331
- return self.abspath(project, relpath).read_text()
334
+ path = self.abspath(project, self.resolve(project, relpath))
335
+ if not path.is_file():
336
+ from .errors import NoSuchItem
337
+
338
+ raise NoSuchItem(self._missing(project, relpath))
339
+ return path.read_text()
340
+
341
+ def resolve(self, project: str, relpath: str) -> str:
342
+ """`relpath`, or, when no such file exists but one does with this
343
+ location's suffix (`morning-briefing` -> `morning-briefing.md`), that
344
+ one: a ref named the way its tool names it still reads."""
345
+ if self.abspath(project, relpath).exists():
346
+ return relpath
347
+ for ext in dict.fromkeys((self.suffix(project), ".md")):
348
+ if not relpath.endswith(ext) and self.abspath(project, relpath + ext).is_file():
349
+ return relpath + ext
350
+ return relpath
351
+
352
+ def _missing(self, project: str, relpath: str) -> str:
353
+ """No such item: say so, with the nearest names this facet has."""
354
+ import difflib
355
+
356
+ from .filesync import scan
357
+
358
+ noun = self.spec.facet or "note"
359
+ loc = self.location(project)
360
+ rels: list[str] = []
361
+ try:
362
+ root = loc.root if loc is not None and loc.prefix is None else self.root(project)
363
+ if root.is_dir():
364
+ rels = [r for r in scan(root, ".md", recursive=True)
365
+ if loc is None or loc.prefix is not None or loc.owns(r)]
366
+ except CribUserError:
367
+ pass
368
+ stem = relpath.rsplit("/", 1)[-1].split(".", 1)[0]
369
+ near = [r for r in rels if r.rsplit("/", 1)[-1].split(".", 1)[0] == stem]
370
+ near += [r for r in difflib.get_close_matches(relpath, rels, n=3, cutoff=0.6)
371
+ if r not in near]
372
+ hint = f" (did you mean {', '.join(near[:3])}?)" if near else ""
373
+ return f"no {noun} {relpath!r} in project {project!r}{hint}"
332
374
 
333
375
  async def delete(self, project: str, relpath: str) -> dict[str, Any]:
334
376
  """Delete a note: stash current content to the version ring (keyed by id, so
@@ -493,6 +535,8 @@ class NoteStore:
493
535
  the still-legible `id:` out of the broken header (the same salvage
494
536
  `_stash_existing` uses on the way in), falling back to the derived id an
495
537
  id-less note's stashes are keyed by."""
538
+ if self._policy(project).get("ids") == "derived":
539
+ return derived_ulid(project, relpath) # the path's, never the file's
496
540
  raw = self.abspath(project, relpath).read_text()
497
541
  try:
498
542
  fm, _body = notes.parse(raw, relpath)
crib/verbs.py CHANGED
@@ -744,12 +744,13 @@ def _m_list(crib: Crib, f: FacetSpec):
744
744
  async def body(
745
745
  project: str | None = None,
746
746
  k: int = 50,
747
+ tags: list[str] | None = None,
747
748
  project_path: str | None = None,
748
749
  **fields: Any,
749
750
  ) -> dict[str, Any]:
750
751
  where = fields.pop("where", None)
751
752
  return crib.list_items(
752
- project, facet=f.noun, fields=fields or None, where=where, k=k
753
+ project, facet=f.noun, fields=fields or None, where=where, k=k, tags=tags
753
754
  )
754
755
 
755
756
  return body
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: cribsheet
3
- Version: 0.24.0-dev2
3
+ Version: 0.24.0-dev3
4
4
  Summary: Local MCP server: markdown memory with a DuckDB embedding index
5
5
  Requires-Python: >=3.14
6
6
  Requires-Dist: duckdb<3,>=2.0
@@ -1,9 +1,9 @@
1
1
  crib/__init__.py,sha256=KzW14Xf3xyTCrmhsSbcFleJVCU6u6-WFidcrLB4YZSw,1001
2
2
  crib/__main__.py,sha256=umIc03A2oA7s2oiL80Ts_QnS-0zj9fjV3IQ103AmNXg,232
3
- crib/app.py,sha256=qY6A7F6KeRyC__trMZLaKSRP4b7IuvtWQcHAbrdAs8k,318150
3
+ crib/app.py,sha256=v6WH79kAizMJNpO1II1_MxAU36uAX06zxkMXbHNlNh4,320318
4
4
  crib/chunk.py,sha256=G5Ftt4zHQ0tx4__ecysFnW64otciPFcqpZ3Y-c_G6JE,15166
5
5
  crib/claudemem.py,sha256=Xf4mVgTFbXHdhhqteTIRz2zirc4irf0wim8AeMybudI,4804
6
- crib/cli.py,sha256=OKqFdnC80gf8FSYTDABeLCEPrtwVxoWhJ5CnsKUFNy0,163109
6
+ crib/cli.py,sha256=nWC-DFW7YX-dm7O3BKUFHyBcKmlDxEH2awDQD3aNruw,163743
7
7
  crib/client.py,sha256=-PRVFFLjbI-D-libZ_wMdDFdcXkyHmc9AYikzxd9PmI,6605
8
8
  crib/codeindex.py,sha256=HYavhLOEieD62iNQasC__kAaMEN6ld1uP2oHmoJjyEI,89916
9
9
  crib/codeindexer.py,sha256=-eocU6ThZdNJar-cGaNJUgB5b6fd21QsjIRx56UFy-I,36737
@@ -11,14 +11,14 @@ crib/codequery.py,sha256=kJe1Mybwixydozjd8XOcxqnxgr9RodUiMFUnVnRsmyk,39191
11
11
  crib/codestore.py,sha256=WgZCt3_ingKHNQgb-SuYNlS3Nkj3Meb6HQpVKkdKT1o,25357
12
12
  crib/config.py,sha256=tVtj7py7ddgIcIWFxejetKOMMSIfGbu5Xpl-byEiNeE,42718
13
13
  crib/describe_queue.py,sha256=orr6BTq9bch5dHTR_cAxEXr8PTqqVy7_a21yc94Amrk,6644
14
- crib/designs.py,sha256=IEEEmeIRVnsXVv_oWQV4u7P0nkJpjbjz79GD_syidkI,160545
14
+ crib/designs.py,sha256=PvOrVy4IEsxyjk3o2EGRIZDsaRUdB4P2YATV60dahuQ,161000
15
15
  crib/diag.py,sha256=0tB2PJ3Vow13FvCIkkTnjKzCbJ8RsgGAV5hEv-Z8i7Y,4805
16
- crib/doctor.py,sha256=EFD2PUBuOw-PwVSZ34x5nNJACIquTZkBaIaHlJtVXzc,9969
16
+ crib/doctor.py,sha256=Oj0glWCGtft9pL6IsQmZ-imoTLFogY481dgbDUxdwCc,13554
17
17
  crib/embed.py,sha256=aCI-3qULlKXx3fu8Q84o8b8IIP0GAtRcwBNSQZy-BOI,11108
18
18
  crib/embedcache.py,sha256=x-4lV90Sw9jzbJWQ6NuxLULixKhFNr34owy9U8jLBXs,4896
19
19
  crib/enrichments.py,sha256=R99rCJxGsiCVx2YgJuzogo80ZgjKTJnyjkO2TBNxq1A,6142
20
- crib/errors.py,sha256=OBCUWM1vH1zbZUPB7DhAkOydBQFYYfSWsCC83XRbDeo,1363
21
- crib/facets.py,sha256=cCcYEJSmItiXt9T6AhF1mEWLHb-k02x0ZTxrE5RNdns,38684
20
+ crib/errors.py,sha256=RZUicsANZz4DxxszDZ-XNGVEtJY606EEfN7CTbUODbo,1612
21
+ crib/facets.py,sha256=hcdMWKxrKNxEWgduNZEnaNc-UdrID7oep_B63BftSTA,40385
22
22
  crib/facets.toml,sha256=et3j0CHGKOWFa-anw3rNJAxDCFdHWYMmX1kaAylCP3Y,2762
23
23
  crib/fields.py,sha256=cFsWKlycprLGX6U97ZMuXmTzisSixLrPWZcr823h_GQ,5297
24
24
  crib/filesync.py,sha256=H8n2gf3HqSBf5ezW7oQWG7RrwchqLmL0kWzomVw91MY,3739
@@ -28,13 +28,13 @@ crib/gensetup.py,sha256=rXOVBMrvr-TlHsjOXRhXKHH0Xd5DaPzAeAQGJT23mbY,17572
28
28
  crib/gitbacking.py,sha256=soVFzumWDQ7QMhn_qBZeP5wtzdofTLrNdmz8Zh4tQMU,25249
29
29
  crib/graph_texts.py,sha256=yvcLJuQPYKVsItgsB4IQHxO4qFUWl1enfhin9IvvCBQ,23244
30
30
  crib/inbound_auth.py,sha256=B2SbiKIMWP5o4pPQribkvtzbDTc_WVYV3MaDoOZ4uTE,4770
31
- crib/indexer.py,sha256=75NTHA7W15tQbliIDN02BgotdKJak_ZeqW43DqCGGJ4,20150
31
+ crib/indexer.py,sha256=_89dahp6ML0wafTLgd6TLHylfgwVrijOBROfyDiB2oc,20618
32
32
  crib/items.py,sha256=a0n2TlOLRYiCZomQ6wn4xvgqSJQLPbTOJiJs6HXeTvQ,14831
33
33
  crib/learnings.py,sha256=1gxKZ6HY7ppVolkepcPTopna6hp276Xc_2Wo-2jXe7w,32185
34
34
  crib/memmirror.py,sha256=DtDxPA9aHuznU5RWsU2Ud2hiz3CRPp9jSCObax1gnSU,5402
35
35
  crib/merge.py,sha256=AE5wQJ7QT_S2hcHBPAGfh9PWVWvcWbP7B2mtyadcuJ8,6285
36
36
  crib/notes.py,sha256=jd-Uf67FzdULtOnCh_bsR9-5Rnxsa6jWnnujNEyyj-k,6938
37
- crib/notestore.py,sha256=9KP_TdLYPpVUQWwN63PoUS2VAbwvnKPv-BSBcq-HVDI,27599
37
+ crib/notestore.py,sha256=hH8Y_LutVSCe4tCTsMzTr38DIGG8cQnys4acarybijc,29716
38
38
  crib/paths.py,sha256=ivosZoXAIYB37JGQOs3XLRFnOI72A7Kn9LnrPsJKaT0,14600
39
39
  crib/proc.py,sha256=7HavbfmtTlA32IUyI-ks3jhOn3tSVlZSYhUFSozcj64,3659
40
40
  crib/project_services.py,sha256=dOPz7RUdw_QS9AeR18d2gcnk6Z9JzeK9nRiFafF_IuI,2112
@@ -53,10 +53,10 @@ crib/symbols.py,sha256=A3sRq1tdPtBhNUGLX9RfQQx2bEnUnC8IBtn4YLIKqzE,27427
53
53
  crib/symconvert.py,sha256=StCH_0SrS9ZaHUZEsSKPq3-lV4-kH5Lk01SzY627VPs,3149
54
54
  crib/tomlrec.py,sha256=ptDbYNhTLmXQeN1BrQGcy2E4wNv0hpKM7aayQ7WvkxE,3796
55
55
  crib/util.py,sha256=EmDszxT0SIjIkgcppD6pDJxbkp3eU-7blYRwri5b_m4,3282
56
- crib/verbs.py,sha256=o8686nxHUnGb6ceWTUbhrKDAUfQps5_6fZIVmbmc28I,53758
56
+ crib/verbs.py,sha256=wl0GruLY9EKnAzAOY_ecHuigkrKwiIvKcVO-tPo6AJc,53808
57
57
  crib/versions.py,sha256=P517DveKCh2jKb3o5IOxkzki8ddwmc-QeuiYMvsBb88,3646
58
58
  crib/watch.py,sha256=Uzy_BgvaTUCMzokTvgmX7vIEdGDh4Rb_M8MReYlAcCw,36361
59
- cribsheet-0.24.0.dev2.dist-info/METADATA,sha256=vwLGkxSaODTHBIUuH7oS8MOF_YajAFpJRqY8Ymbz11Q,21224
60
- cribsheet-0.24.0.dev2.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
61
- cribsheet-0.24.0.dev2.dist-info/entry_points.txt,sha256=CjLxgcZdPGI6U4VRZmrwQ2kL1gUkNykYNkLzT8EQkfQ,39
62
- cribsheet-0.24.0.dev2.dist-info/RECORD,,
59
+ cribsheet-0.24.0.dev3.dist-info/METADATA,sha256=TYLl0S_S2YaEAouIvNpMcujr8x1aAb2emivutgbu-ec,21224
60
+ cribsheet-0.24.0.dev3.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
61
+ cribsheet-0.24.0.dev3.dist-info/entry_points.txt,sha256=CjLxgcZdPGI6U4VRZmrwQ2kL1gUkNykYNkLzT8EQkfQ,39
62
+ cribsheet-0.24.0.dev3.dist-info/RECORD,,