cribsheet 0.24.0.dev4__py3-none-any.whl → 0.25.0.dev2__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
@@ -41,7 +41,7 @@ from .embed import build_embedder, embed_query_batch
41
41
  from .errors import CribUserError
42
42
  from .gitbacking import GitBacking
43
43
  from .indexer import IndexEngine, IndexResult
44
- from .fields import conditions, matches, setting
44
+ from .fields import conditions, matches, require, setting
45
45
  from .learnings import AnchoredSet, Learnings
46
46
  from .notes import Note, NoteParseError
47
47
  from .notestore import (
@@ -1189,6 +1189,7 @@ class Crib:
1189
1189
  fm: dict[str, Any] = {"title": title, "source": "manual"}
1190
1190
  if tags:
1191
1191
  fm["tags"] = tags
1192
+ require(facets.by_noun(facet), fields) # a new item: its required fields
1192
1193
  fm.update(setting(facets.by_noun(facet), fields)) # a declared facet's own
1193
1194
  note = Note(path=self.abspath(proj, relpath, facet), frontmatter=fm, body=content)
1194
1195
  res = await self._write_note(proj, relpath, note, facet)
crib/cli.py CHANGED
@@ -469,6 +469,14 @@ def _emit_projects(rows: Any, as_json: bool) -> None:
469
469
  print(line)
470
470
 
471
471
 
472
+ def _sweep_progress(d: Any) -> str:
473
+ """`done/total files`, or "starting" before the sweep has counted its files
474
+ (right after it began, both are still None)."""
475
+ if d.get("total") is None:
476
+ return "starting (counting files)"
477
+ return f"{d.get('done') or 0}/{d['total']} files"
478
+
479
+
472
480
  def _emit_facet_summary(d: Any) -> None:
473
481
  """One line per facet mapping a setup/index answer reports (`facets`)."""
474
482
  for noun, f in (d.get("facets") or {}).items():
@@ -579,7 +587,7 @@ def _emit_project(d: Any, verb: str | None, as_json: bool) -> None:
579
587
  if verb == "wait":
580
588
  if d.get("running"):
581
589
  print(
582
- f"{proj}: still running — {d.get('done')}/{d.get('total')} files; "
590
+ f"{proj}: still running — {_sweep_progress(d)}; "
583
591
  f"call `crib project wait` again to keep waiting"
584
592
  )
585
593
  else:
@@ -598,7 +606,7 @@ def _emit_project(d: Any, verb: str | None, as_json: bool) -> None:
598
606
  return
599
607
  # setup / index
600
608
  if d.get("running"): # a daemon-side sweep still going (joined or started)
601
- print(f"{proj}: indexing in progress — {d.get('done')}/{d.get('total')} files "
609
+ print(f"{proj}: indexing in progress — {_sweep_progress(d)} "
602
610
  f"(`crib project wait` to follow it, `crib project status` to look)")
603
611
  _emit_facet_summary(d)
604
612
  return
crib/doctor.py CHANGED
@@ -230,6 +230,14 @@ def _misfits(spec: Any, fm: dict[str, Any]) -> list[dict[str, Any]]:
230
230
  for name, kind in spec.params.items():
231
231
  value = fm.get(name)
232
232
  if value is None:
233
+ if name in spec.required:
234
+ out.append({
235
+ "check": "required field missing",
236
+ "kind": spec.noun,
237
+ "field": name,
238
+ "fix": f"give it `{name}:`, or mark the field optional in the "
239
+ f"[{spec.noun}] spec (`optional = [\"{name}\"]`)",
240
+ })
233
241
  continue
234
242
  try:
235
243
  _fields.coerce(spec, name, value)
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", "title_from"}
252
+ "export_with_deps", "about", "when", "title_from", "optional"}
253
253
  )
254
254
 
255
255
 
@@ -310,8 +310,16 @@ class FacetSpec:
310
310
  # frontmatter `title`, its first `heading`, its `filename`, or a named
311
311
  # frontmatter key (toucan's `name`). None found: no title (doctor says so).
312
312
  title_from: tuple[str, ...] = ("title",)
313
+ # A declared field is REQUIRED unless named here: `add` refuses an item
314
+ # without it, `crib project doctor` names files missing it.
315
+ optional: frozenset[str] = frozenset()
313
316
  builtin: bool = False
314
317
 
318
+ @property
319
+ def required(self) -> tuple[str, ...]:
320
+ """Its declared fields an item must carry (all but the optional ones)."""
321
+ return tuple(n for n in self.params if n not in self.optional)
322
+
315
323
  def has(self, aspect: str) -> bool:
316
324
  return aspect in self.aspects
317
325
 
@@ -429,6 +437,13 @@ def parse(noun: str, raw: Mapping[str, Any], *, builtin: bool = False) -> FacetS
429
437
  raise FacetSpecError(
430
438
  f"facet {noun!r}: title_from is a list of sources: \"title\", \"heading\", "
431
439
  "\"filename\" or a frontmatter key")
440
+ optional = raw.get("optional", [])
441
+ if not isinstance(optional, list) or not all(isinstance(o, str) for o in optional):
442
+ raise FacetSpecError(f"facet {noun!r}: optional must be a list of field names")
443
+ if stray := sorted(set(optional) - set(params)):
444
+ raise FacetSpecError(
445
+ f"facet {noun!r}: optional names {stray}, not among its fields "
446
+ f"{sorted(params)}")
432
447
  return FacetSpec(
433
448
  noun=noun,
434
449
  plural=plural,
@@ -442,6 +457,7 @@ def parse(noun: str, raw: Mapping[str, Any], *, builtin: bool = False) -> FacetS
442
457
  about=about,
443
458
  when=MappingProxyType(when),
444
459
  title_from=tuple(t.strip() for t in title_from),
460
+ optional=frozenset(optional),
445
461
  **graph,
446
462
  builtin=builtin,
447
463
  )
@@ -725,6 +741,8 @@ def to_toml(specs: Iterable[FacetSpec]) -> str:
725
741
  out.append(f"label = {q(s.label)}")
726
742
  if s.about:
727
743
  out.append(f"about = {q(s.about)}")
744
+ if s.optional:
745
+ out.append(f"optional = {arr([n for n in s.params if n in s.optional])}")
728
746
  if s.title_from != ("title",):
729
747
  out.append(f"title_from = {arr(s.title_from)}")
730
748
  if s.requires_body:
crib/fields.py CHANGED
@@ -63,6 +63,19 @@ def coerce(spec: FacetSpec, name: str, value: Any) -> int | str:
63
63
  ) from None
64
64
 
65
65
 
66
+ def require(spec: FacetSpec, values: Mapping[str, Any] | None,
67
+ have: Mapping[str, Any] | None = None) -> None:
68
+ """Refuse a new item missing a required field (a declared field the spec
69
+ doesn't mark optional): not given now, and not already on the item."""
70
+ given = {k for k, v in (values or {}).items() if v is not None}
71
+ there = {k for k, v in (have or {}).items() if v is not None}
72
+ if missing := [n for n in spec.required if n not in given | there]:
73
+ names = ", ".join(f"`{n}`" for n in missing)
74
+ raise CribUserError(
75
+ f"a {spec.noun} needs {names} (required fields; the facet's spec can "
76
+ f"mark a field optional with `optional = [...]`)")
77
+
78
+
66
79
  def setting(spec: FacetSpec, values: Mapping[str, Any] | None) -> dict[str, Any]:
67
80
  """The fields a write sets: the given ones (None = leave alone), coerced."""
68
81
  return {k: coerce(spec, k, v) for k, v in (values or {}).items() if v is not None}
crib/learnings.py CHANGED
@@ -249,6 +249,12 @@ class Learnings:
249
249
  "source": "code-note",
250
250
  },
251
251
  )
252
+ if not existed: # a new item carries its facet's required fields
253
+ from . import facets as _facets
254
+ from .fields import require
255
+
256
+ if (spec := _facets.get(self.noun)) is not None:
257
+ require(spec, fields)
252
258
  note.frontmatter.update(fields or {}) # a declared facet's own, coerced
253
259
  today = datetime.date.today().isoformat()
254
260
  note.body = note.body.rstrip() + f"\n\n### {today}\n{text.strip()}\n"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: cribsheet
3
- Version: 0.24.0-dev4
3
+ Version: 0.25.0-dev2
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=zFgt1LxkqwaVMBUHP77dXgfeDEFzBvEF4jcfEjjlELk,321012
3
+ crib/app.py,sha256=egeaBtiXNuF2YJagEPF_L1TkxgT5dz4JuNWfbnqvcc0,321103
4
4
  crib/chunk.py,sha256=G5Ftt4zHQ0tx4__ecysFnW64otciPFcqpZ3Y-c_G6JE,15166
5
5
  crib/claudemem.py,sha256=Xf4mVgTFbXHdhhqteTIRz2zirc4irf0wim8AeMybudI,4804
6
- crib/cli.py,sha256=iIp5S4cN9AFcsYH63NhnDRx6Ivdw6RQjwsexo90-VRM,164191
6
+ crib/cli.py,sha256=08CAcNJlFdVGzZ8O6usFM60EGPL6M-yTpB8SbhYsZPw,164453
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
@@ -13,14 +13,14 @@ crib/config.py,sha256=tVtj7py7ddgIcIWFxejetKOMMSIfGbu5Xpl-byEiNeE,42718
13
13
  crib/describe_queue.py,sha256=orr6BTq9bch5dHTR_cAxEXr8PTqqVy7_a21yc94Amrk,6644
14
14
  crib/designs.py,sha256=PvOrVy4IEsxyjk3o2EGRIZDsaRUdB4P2YATV60dahuQ,161000
15
15
  crib/diag.py,sha256=0tB2PJ3Vow13FvCIkkTnjKzCbJ8RsgGAV5hEv-Z8i7Y,4805
16
- crib/doctor.py,sha256=Oj0glWCGtft9pL6IsQmZ-imoTLFogY481dgbDUxdwCc,13554
16
+ crib/doctor.py,sha256=p1TI19KZ11lvhF1BzniSdunICCwWw8i2HevebuVkm7Q,13924
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
20
  crib/errors.py,sha256=RZUicsANZz4DxxszDZ-XNGVEtJY606EEfN7CTbUODbo,1612
21
- crib/facets.py,sha256=hcdMWKxrKNxEWgduNZEnaNc-UdrID7oep_B63BftSTA,40385
21
+ crib/facets.py,sha256=W9KRMOBjSXAuoxzxix4vpcGg8w6TLoJTBHyCmyW4DFk,41346
22
22
  crib/facets.toml,sha256=et3j0CHGKOWFa-anw3rNJAxDCFdHWYMmX1kaAylCP3Y,2762
23
- crib/fields.py,sha256=cFsWKlycprLGX6U97ZMuXmTzisSixLrPWZcr823h_GQ,5297
23
+ crib/fields.py,sha256=iSRQOS9DrVelv1pthVRePY8Acvl-Q9FoKx8fpb4fg6I,6008
24
24
  crib/filesync.py,sha256=H8n2gf3HqSBf5ezW7oQWG7RrwchqLmL0kWzomVw91MY,3739
25
25
  crib/generate.py,sha256=lDvqbUOkEoPm2nAR5UxDqq38hLG9FNZGvqbM5GgOiZ0,15448
26
26
  crib/genledger.py,sha256=cgHo3ucf1gFU8b42PApfEI2Rhh5oo-66AciTr0zuI6U,7450
@@ -30,7 +30,7 @@ crib/graph_texts.py,sha256=yvcLJuQPYKVsItgsB4IQHxO4qFUWl1enfhin9IvvCBQ,23244
30
30
  crib/inbound_auth.py,sha256=B2SbiKIMWP5o4pPQribkvtzbDTc_WVYV3MaDoOZ4uTE,4770
31
31
  crib/indexer.py,sha256=_89dahp6ML0wafTLgd6TLHylfgwVrijOBROfyDiB2oc,20618
32
32
  crib/items.py,sha256=a0n2TlOLRYiCZomQ6wn4xvgqSJQLPbTOJiJs6HXeTvQ,14831
33
- crib/learnings.py,sha256=1gxKZ6HY7ppVolkepcPTopna6hp276Xc_2Wo-2jXe7w,32185
33
+ crib/learnings.py,sha256=_1hB1PqaQRL7abdZYpVZhFFaMKVWIlPovpxzyE9Kdz0,32443
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
@@ -56,7 +56,7 @@ crib/util.py,sha256=EmDszxT0SIjIkgcppD6pDJxbkp3eU-7blYRwri5b_m4,3282
56
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.dev4.dist-info/METADATA,sha256=jNLI1P3PsgslZ4oxQNdzzPods-THgl_a7Ux95ycN9Qk,21224
60
- cribsheet-0.24.0.dev4.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
61
- cribsheet-0.24.0.dev4.dist-info/entry_points.txt,sha256=CjLxgcZdPGI6U4VRZmrwQ2kL1gUkNykYNkLzT8EQkfQ,39
62
- cribsheet-0.24.0.dev4.dist-info/RECORD,,
59
+ cribsheet-0.25.0.dev2.dist-info/METADATA,sha256=CSOV21pmZgYvObiquRenVQCch-Z03uWTYKqJ_qu7-fM,21224
60
+ cribsheet-0.25.0.dev2.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
61
+ cribsheet-0.25.0.dev2.dist-info/entry_points.txt,sha256=CjLxgcZdPGI6U4VRZmrwQ2kL1gUkNykYNkLzT8EQkfQ,39
62
+ cribsheet-0.25.0.dev2.dist-info/RECORD,,