cribsheet 0.22.0.dev2__py3-none-any.whl → 0.23.0.dev1__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 +205 -120
- crib/chunk.py +39 -6
- crib/cli.py +63 -13
- crib/codeindex.py +14 -10
- crib/codeindexer.py +3 -3
- crib/codequery.py +51 -33
- crib/codestore.py +330 -179
- crib/config.py +3 -3
- crib/designs.py +318 -100
- crib/embed.py +13 -1
- crib/embedcache.py +42 -7
- crib/filesync.py +102 -0
- crib/genledger.py +18 -1
- crib/indexer.py +157 -24
- crib/items.py +352 -0
- crib/learnings.py +20 -9
- crib/notestore.py +29 -6
- crib/refs.py +14 -10
- crib/retrieve.py +132 -27
- crib/server.py +24 -7
- crib/store.py +333 -66
- crib/store_duckdb.py +828 -152
- crib/store_quack.py +173 -31
- crib/symbols.py +15 -0
- crib/watch.py +80 -2
- {cribsheet-0.22.0.dev2.dist-info → cribsheet-0.23.0.dev1.dist-info}/METADATA +3 -2
- cribsheet-0.23.0.dev1.dist-info/RECORD +52 -0
- crib/recordcache.py +0 -134
- cribsheet-0.22.0.dev2.dist-info/RECORD +0 -51
- {cribsheet-0.22.0.dev2.dist-info → cribsheet-0.23.0.dev1.dist-info}/WHEEL +0 -0
- {cribsheet-0.22.0.dev2.dist-info → cribsheet-0.23.0.dev1.dist-info}/entry_points.txt +0 -0
crib/app.py
CHANGED
|
@@ -21,15 +21,22 @@ from pathlib import Path
|
|
|
21
21
|
from typing import Any, Callable
|
|
22
22
|
|
|
23
23
|
from . import __version__, claudemem, notes
|
|
24
|
-
from .chunk import
|
|
24
|
+
from .chunk import (
|
|
25
|
+
CHUNK_SCHEMA_VERSION,
|
|
26
|
+
kind_of,
|
|
27
|
+
kinds_in,
|
|
28
|
+
pillar_of,
|
|
29
|
+
section_key,
|
|
30
|
+
section_line_map,
|
|
31
|
+
)
|
|
25
32
|
from .claudemem import MemoryBindings
|
|
26
33
|
from .codeindexer import CodeIndexer
|
|
27
34
|
from .codequery import CodeQuery
|
|
28
|
-
from .codestore import CodeStore,
|
|
35
|
+
from .codestore import CodeStore, StoreCode
|
|
29
36
|
from .codestore import format_sweep
|
|
30
37
|
from .config import Config, CribLink, ProjectConfig, portable_path, resolve_project
|
|
31
38
|
from .designs import Designs
|
|
32
|
-
from .embed import build_embedder,
|
|
39
|
+
from .embed import build_embedder, embed_query_batch
|
|
33
40
|
from .errors import CribUserError
|
|
34
41
|
from .gitbacking import GitBacking
|
|
35
42
|
from .indexer import IndexEngine, IndexResult
|
|
@@ -148,6 +155,15 @@ def _min_max(vals: list[float]) -> list[float]:
|
|
|
148
155
|
return [(v - lo) / rng for v in vals]
|
|
149
156
|
|
|
150
157
|
|
|
158
|
+
|
|
159
|
+
def _kinded(
|
|
160
|
+
follows: list[str] | None, rests_on: list[str] | None, informed_by: list[str] | None
|
|
161
|
+
) -> dict[str, list[str]] | None:
|
|
162
|
+
"""Refs given with an explicit dependency kind, keyed by the kind."""
|
|
163
|
+
out = {k: v for k, v in (("follows", follows), ("rests_on", rests_on),
|
|
164
|
+
("informed_by", informed_by)) if v}
|
|
165
|
+
return out or None
|
|
166
|
+
|
|
151
167
|
class Crib:
|
|
152
168
|
def __init__(self, paths: Paths, config: Config, store: Store) -> None:
|
|
153
169
|
self.paths = paths
|
|
@@ -159,10 +175,12 @@ class Crib:
|
|
|
159
175
|
# any search index is built in memory.
|
|
160
176
|
from . import embedcache
|
|
161
177
|
|
|
178
|
+
# Keyed on what `build_embedder` ACTUALLY returned (its `model_id`), not on
|
|
179
|
+
# `embed_cfg.model`: a missing backend falls back to the hash embedder, and
|
|
180
|
+
# the config key would file those vectors under the real model's name.
|
|
162
181
|
self.embedder = embedcache.wrap(
|
|
163
182
|
build_embedder(embed_cfg, stored_dim=_stored_dim(store)),
|
|
164
183
|
store,
|
|
165
|
-
embed_cfg.model,
|
|
166
184
|
)
|
|
167
185
|
self.index = IndexEngine(
|
|
168
186
|
store,
|
|
@@ -235,12 +253,13 @@ class Crib:
|
|
|
235
253
|
# The code subsystem's shared per-project state (resident cache, freshness
|
|
236
254
|
# epoch, write locks, in-flight/sweep tracking) — owned by CodeStore; the
|
|
237
255
|
# methods below reach through `self.code` (codestore.py).
|
|
238
|
-
self.code = CodeStore(paths, config)
|
|
256
|
+
self.code = CodeStore(paths, config, store, self.embedder)
|
|
239
257
|
# Cross-project refs (.crib refs:) — resolution + edge attribution. Needs two
|
|
240
258
|
# Crib-owned callables it can't own: a ref's resident cache (carries the
|
|
241
259
|
# pipeline revalidate hook) and nested-.crib boundary detection (shared with
|
|
242
260
|
# code enumeration). Crib keeps delegators (below) for its many callers.
|
|
243
|
-
self.refs = Refs(paths, self.
|
|
261
|
+
self.refs = Refs(paths, self._store_code, self._nested_project_roots,
|
|
262
|
+
self.code.view)
|
|
244
263
|
# The project-layer surface the indexing pipeline depends on — narrow deps
|
|
245
264
|
# (refs + code + config for resolution/ref-context, plus two injected callables
|
|
246
265
|
# for enumeration + watcher registration). No back-reference to Crib.
|
|
@@ -262,11 +281,6 @@ class Crib:
|
|
|
262
281
|
|
|
263
282
|
self.ledger = for_store(store)
|
|
264
283
|
self.indexer.set_ledger(self.ledger)
|
|
265
|
-
# Parsed derived-index records (crib.recordcache), backed by the same
|
|
266
|
-
# database, so a fresh daemon doesn't re-parse every TOML.
|
|
267
|
-
from . import recordcache
|
|
268
|
-
|
|
269
|
-
recordcache.attach(store)
|
|
270
284
|
# In-flight project_index JOBS (proj → {task, crib_at}): the join-don't-
|
|
271
285
|
# restart registry. A re-invoke while a sweep runs awaits the existing task
|
|
272
286
|
# instead of racing a second one — the zero-reset counter bug, fixed at the
|
|
@@ -279,7 +293,8 @@ class Crib:
|
|
|
279
293
|
self.relocate_jobs: dict[str, dict[str, Any]] = {}
|
|
280
294
|
# Durable symbol learnings, over refs + their own pillar store.
|
|
281
295
|
# Crib keeps resolve_project + delegate public wrappers (learning_add/…).
|
|
282
|
-
self.learnings = Learnings(paths, self.refs, self.learningstore
|
|
296
|
+
self.learnings = Learnings(paths, self.refs, self.learningstore,
|
|
297
|
+
self.code.records)
|
|
283
298
|
# Design decisions + plan items (notes under design/ and plans/) and the
|
|
284
299
|
# dependency graph over them. Same shape: Crib resolves, Designs executes.
|
|
285
300
|
self.designs = Designs(paths, self.designstore, self.planstore, self.notestore)
|
|
@@ -289,7 +304,7 @@ class Crib:
|
|
|
289
304
|
self.refs,
|
|
290
305
|
self.learnings,
|
|
291
306
|
self.embedder,
|
|
292
|
-
self.
|
|
307
|
+
self._store_code,
|
|
293
308
|
self._require_code_index,
|
|
294
309
|
)
|
|
295
310
|
|
|
@@ -321,6 +336,7 @@ class Crib:
|
|
|
321
336
|
self._on_fs_change,
|
|
322
337
|
loop,
|
|
323
338
|
self._in_repo_store_roots(),
|
|
339
|
+
on_records=self._on_record_change,
|
|
324
340
|
)
|
|
325
341
|
self._watcher.start()
|
|
326
342
|
# Code watcher — reindexes source on edit (notes-watcher reloads notes,
|
|
@@ -352,6 +368,9 @@ class Crib:
|
|
|
352
368
|
# content-hash gate is its durable signal, so the catch-up is a cheap no-op
|
|
353
369
|
# when nothing was lost.
|
|
354
370
|
self._spawn_bg(loop, self._describe_backlog())
|
|
371
|
+
# Records changed while crib was down (a git pull, another machine's sync):
|
|
372
|
+
# the watcher only sees edits from now on, and reads refresh lazily.
|
|
373
|
+
self._spawn_bg(loop, self._refresh_records_at_start())
|
|
355
374
|
self._spawn_bg(loop, self._keyword_backlog())
|
|
356
375
|
|
|
357
376
|
def _in_repo_store_roots(self) -> dict[str, Path]:
|
|
@@ -400,6 +419,38 @@ class Crib:
|
|
|
400
419
|
await self.index.index_file(
|
|
401
420
|
project, pillar.dir(project), relpath, store=pillar.spec.name
|
|
402
421
|
)
|
|
422
|
+
# index_file keeps the chunks (and their stamp); the design/plan graph
|
|
423
|
+
# keeps its own items and stamps, refreshed here rather than at the
|
|
424
|
+
# next graph read
|
|
425
|
+
kind = kind_of(pillar.spec.name)
|
|
426
|
+
if kind in ("design", "plan"):
|
|
427
|
+
await asyncio.to_thread(self.designs.refresh_files, project, kind, [relpath])
|
|
428
|
+
|
|
429
|
+
async def _on_record_change(
|
|
430
|
+
self, project: str, facet: str, names: list[str] | None
|
|
431
|
+
) -> None:
|
|
432
|
+
"""A batch of a facet's record files changed on disk (the watcher; see
|
|
433
|
+
crib.watch.RECORD_TIERS): bring the store in line now, rather than at the
|
|
434
|
+
next read. Reads still refresh, so whichever comes first does the work
|
|
435
|
+
and the stamps make the other a no-op."""
|
|
436
|
+
if facet != "symbol" or project not in self.projects():
|
|
437
|
+
return
|
|
438
|
+
await asyncio.to_thread(self._refresh_symbols, project, names)
|
|
439
|
+
|
|
440
|
+
def _refresh_symbols(self, project: str, names: list[str] | None = None) -> None:
|
|
441
|
+
self.code.refresh(project, names)
|
|
442
|
+
self.code.fill_vectors(project)
|
|
443
|
+
|
|
444
|
+
async def _refresh_records_at_start(self) -> None:
|
|
445
|
+
from .codeindex import SymbolIndex
|
|
446
|
+
|
|
447
|
+
for name in self.projects():
|
|
448
|
+
if not SymbolIndex(self.paths.project_dir(name)).is_populated():
|
|
449
|
+
continue
|
|
450
|
+
try:
|
|
451
|
+
await asyncio.to_thread(self._refresh_symbols, name)
|
|
452
|
+
except Exception as e: # noqa: BLE001 — a read refreshes it later anyway
|
|
453
|
+
print(f"[crib] startup refresh of {name!r} failed: {e}", file=sys.stderr)
|
|
403
454
|
|
|
404
455
|
async def _on_code_change(
|
|
405
456
|
self, project: str, changes: dict[str, tuple[str, bool]]
|
|
@@ -507,13 +558,18 @@ class Crib:
|
|
|
507
558
|
if root is None:
|
|
508
559
|
continue
|
|
509
560
|
hashes: dict[str, str] = {}
|
|
510
|
-
for e in
|
|
561
|
+
for e in self.code.records(name):
|
|
511
562
|
if (
|
|
512
563
|
e.get("content_hash")
|
|
513
564
|
and not e.get("description")
|
|
514
565
|
and e.get("file")
|
|
515
566
|
):
|
|
516
|
-
|
|
567
|
+
# The file's hash is the input; without one, the
|
|
568
|
+
# symbol's own hash, so an edit still counts as new input.
|
|
569
|
+
hashes[f"{name}:{e['file']}"] = str(
|
|
570
|
+
e.get("file_hash") or e.get("content_hash") or ""
|
|
571
|
+
)
|
|
572
|
+
self.ledger.forget_except("describe", f"{name}:", list(hashes))
|
|
517
573
|
if not hashes:
|
|
518
574
|
continue
|
|
519
575
|
pending += len(hashes)
|
|
@@ -889,6 +945,7 @@ class Crib:
|
|
|
889
945
|
relpath: str | None = None,
|
|
890
946
|
project: str | None = None,
|
|
891
947
|
cwd: Path | None = None,
|
|
948
|
+
full: bool = True,
|
|
892
949
|
) -> dict[str, Any]:
|
|
893
950
|
"""Reindex a note, or fully reconcile a project when relpath is None.
|
|
894
951
|
|
|
@@ -909,11 +966,13 @@ class Crib:
|
|
|
909
966
|
# old-layout files a not-yet-upgraded machine pushed into the sync repo.
|
|
910
967
|
mig = self._migrate_legacy_layout(proj)
|
|
911
968
|
recreated = self._maybe_recreate_for_dim()
|
|
912
|
-
|
|
969
|
+
# A wipe just now (recreate) cleared the stamps with the chunks, so a
|
|
970
|
+
# stamp-gated sweep below still re-embeds everything.
|
|
971
|
+
res = await self.notestore.reindex(proj, full=full)
|
|
913
972
|
# Fan out over the sibling pillars — same union sweep, each scoped to its
|
|
914
973
|
# own tree and its own chunks. Empty pillars are cheap no-ops.
|
|
915
974
|
for pillar in (self.designstore, self.planstore, self.learningstore):
|
|
916
|
-
r = await pillar.reindex(proj)
|
|
975
|
+
r = await pillar.reindex(proj, full=full)
|
|
917
976
|
for k in ("files", "changed", "removed"):
|
|
918
977
|
res[k] += r[k]
|
|
919
978
|
res["skipped"] += r["skipped"]
|
|
@@ -935,14 +994,26 @@ class Crib:
|
|
|
935
994
|
doesn't walk) — hoisted out of the per-pillar store so the check runs once
|
|
936
995
|
per full reindex, not once per pillar."""
|
|
937
996
|
cur = self.store.current_dim()
|
|
938
|
-
|
|
997
|
+
model = getattr(self.embedder, "model_id", None)
|
|
998
|
+
stored = self.store.meta_get("embed_model") if model else None
|
|
999
|
+
if cur is None or (cur == self.embedder.dim and stored in (None, model)):
|
|
1000
|
+
# Nothing stored yet, or the same embedder: record who wrote the
|
|
1001
|
+
# vectors, so a later same-dimension model change is caught too.
|
|
1002
|
+
if model and stored != model:
|
|
1003
|
+
self.store.meta_set("embed_model", model)
|
|
939
1004
|
return False
|
|
1005
|
+
change = (
|
|
1006
|
+
f"dim {cur}→{self.embedder.dim}"
|
|
1007
|
+
if cur != self.embedder.dim
|
|
1008
|
+
else f"model {stored}→{model}"
|
|
1009
|
+
)
|
|
940
1010
|
print(
|
|
941
|
-
f"crib: embedder
|
|
942
|
-
f"the vector collection (full re-embed)",
|
|
1011
|
+
f"crib: embedder {change}; recreating the vector store (full re-embed)",
|
|
943
1012
|
file=sys.stderr,
|
|
944
1013
|
)
|
|
945
1014
|
self.store.recreate()
|
|
1015
|
+
if model:
|
|
1016
|
+
self.store.meta_set("embed_model", model)
|
|
946
1017
|
# The derived retrieval caches (BM25 corpus + summary alias vectors) are
|
|
947
1018
|
# built from the store and keyed per project — a wipe invalidates ALL of
|
|
948
1019
|
# them at once, not just one project's. Without this a warm daemon kept
|
|
@@ -1010,6 +1081,7 @@ class Crib:
|
|
|
1010
1081
|
"skipped": [],
|
|
1011
1082
|
}
|
|
1012
1083
|
self._reconcile_remaining = len(projects)
|
|
1084
|
+
rechunk = self.stored_chunk_schema() != CHUNK_SCHEMA_VERSION
|
|
1013
1085
|
try:
|
|
1014
1086
|
for proj in projects:
|
|
1015
1087
|
# A project adopted into a repo that isn't cloned here has no
|
|
@@ -1021,7 +1093,9 @@ class Crib:
|
|
|
1021
1093
|
total.setdefault("unavailable", []).append(proj)
|
|
1022
1094
|
self._reconcile_remaining -= 1
|
|
1023
1095
|
continue
|
|
1024
|
-
|
|
1096
|
+
# Stamp-gated: only notes changed since they were last indexed are
|
|
1097
|
+
# read, unless the chunking scheme changed (then every note is).
|
|
1098
|
+
r = await self.reindex(project=proj, full=rechunk)
|
|
1025
1099
|
total["changed"] += r["changed"]
|
|
1026
1100
|
total["removed"] += r["removed"]
|
|
1027
1101
|
# notes crib couldn't read — carried up so a sweep that skipped
|
|
@@ -1112,6 +1186,14 @@ class Crib:
|
|
|
1112
1186
|
f"[crib] skipped {s['project']}/{s['relpath']}: {s['error']}",
|
|
1113
1187
|
file=sys.stderr,
|
|
1114
1188
|
)
|
|
1189
|
+
checkpoint = getattr(self.store, "checkpoint", None)
|
|
1190
|
+
if callable(checkpoint) and (rec["changed"] or rec["removed"]):
|
|
1191
|
+
# Fold the sweep's writes from the WAL into the file, so a long-lived
|
|
1192
|
+
# daemon's store doesn't sit on an ever-growing log.
|
|
1193
|
+
try:
|
|
1194
|
+
await asyncio.to_thread(checkpoint)
|
|
1195
|
+
except Exception as e: # noqa: BLE001 — housekeeping only
|
|
1196
|
+
print(f"[crib] store checkpoint failed: {e}", file=sys.stderr)
|
|
1115
1197
|
|
|
1116
1198
|
async def _reindex_dirty_code(self) -> dict[str, int]:
|
|
1117
1199
|
"""Rebuild every code file carrying a merge-dirtied symbol (blank
|
|
@@ -1136,7 +1218,7 @@ class Crib:
|
|
|
1136
1218
|
files = sorted(
|
|
1137
1219
|
{
|
|
1138
1220
|
e["file"]
|
|
1139
|
-
for e in
|
|
1221
|
+
for e in self.code.records(proj)
|
|
1140
1222
|
if e.get("file") and not e.get("content_hash")
|
|
1141
1223
|
}
|
|
1142
1224
|
)
|
|
@@ -1158,11 +1240,7 @@ class Crib:
|
|
|
1158
1240
|
return out
|
|
1159
1241
|
|
|
1160
1242
|
def _indexed_projects(self) -> set[str]:
|
|
1161
|
-
|
|
1162
|
-
for m in self.store.get_meta({}).values():
|
|
1163
|
-
if p := m.get("project"):
|
|
1164
|
-
out.add(p)
|
|
1165
|
-
return out
|
|
1243
|
+
return self.store.projects()
|
|
1166
1244
|
|
|
1167
1245
|
@property
|
|
1168
1246
|
def reranker(self) -> Any:
|
|
@@ -1209,6 +1287,7 @@ class Crib:
|
|
|
1209
1287
|
hint_weight: float = 0.15,
|
|
1210
1288
|
*,
|
|
1211
1289
|
store: str = "notes",
|
|
1290
|
+
labels: list[str] | None = None,
|
|
1212
1291
|
) -> list[Hit]:
|
|
1213
1292
|
"""Candidate Hits in DENSE-DOMINANT SCORE order: raw cosine (dense, already
|
|
1214
1293
|
calibrated) + min-max'd keyword_index BM25, over the union candidate pool. Only
|
|
@@ -1226,22 +1305,17 @@ class Crib:
|
|
|
1226
1305
|
|
|
1227
1306
|
kw_blend = 0.5 # fusion weight of the keyword_index term
|
|
1228
1307
|
|
|
1229
|
-
# Retrieval is scoped to ONE pillar store
|
|
1230
|
-
#
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1308
|
+
# Retrieval is scoped to ONE pillar store: every chunk carries the
|
|
1309
|
+
# `kind` of the item it belongs to.
|
|
1310
|
+
where: dict[str, Any] = {"project": proj, "kind": kinds_in(store)}
|
|
1311
|
+
if labels:
|
|
1312
|
+
# A tags= lookup filters IN the query, so the dense top-n is drawn
|
|
1313
|
+
# from matching chunks only, never thinned after the fact.
|
|
1314
|
+
where["labels"] = {"$any": list(labels)}
|
|
1235
1315
|
# `where` is a vector-store filter dict (an exact-match metadata predicate),
|
|
1236
1316
|
# not a SQL string; there is no SQL here.
|
|
1237
1317
|
# pi-lens-ignore: python-sql-injection
|
|
1238
1318
|
dense = self.store.query(vec, k=topn, where=where)
|
|
1239
|
-
if not stamped:
|
|
1240
|
-
dense = [
|
|
1241
|
-
h
|
|
1242
|
-
for h in dense
|
|
1243
|
-
if ((h.metadata or {}).get("store") or "notes") == store
|
|
1244
|
-
]
|
|
1245
1319
|
cos: dict[str, float] = {
|
|
1246
1320
|
h.id: h.score for h in dense
|
|
1247
1321
|
} # raw cosine per candidate
|
|
@@ -1314,19 +1388,24 @@ class Crib:
|
|
|
1314
1388
|
else:
|
|
1315
1389
|
pool = list(dict.fromkeys(list(cos) + list(kw) + list(hint_hits)))
|
|
1316
1390
|
if not docs: # need doc text to back-fill cosines
|
|
1317
|
-
docs =
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1391
|
+
docs = self.store.get_docs(where)
|
|
1392
|
+
if labels:
|
|
1393
|
+
# The lexical index and the alias cache span the whole store, so
|
|
1394
|
+
# their candidates get the same label filter the query applied.
|
|
1395
|
+
wanted = set(labels)
|
|
1396
|
+
|
|
1397
|
+
def _labelled(cid: str) -> bool:
|
|
1398
|
+
h = dense_by.get(cid)
|
|
1399
|
+
meta = h.metadata if h is not None else docs.get(cid, ("", {}))[1]
|
|
1400
|
+
return bool(wanted & set((meta or {}).get("labels") or []))
|
|
1401
|
+
|
|
1402
|
+
pool = [cid for cid in pool if _labelled(cid)]
|
|
1403
|
+
kw = {cid: v for cid, v in kw.items() if cid in pool}
|
|
1323
1404
|
missing = [cid for cid in pool if cid not in cos and cid in docs]
|
|
1324
1405
|
if missing:
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
):
|
|
1329
|
-
cos[cid] = sum(a * b for a, b in zip(vec, dv)) # L2-normalized
|
|
1406
|
+
# Score them on their STORED vectors (breadcrumb + body, what the
|
|
1407
|
+
# dense query ranks), not a re-embedding of the bare body.
|
|
1408
|
+
cos.update(self.store.score_ids(vec, missing))
|
|
1330
1409
|
# drop any we couldn't score, and any alias rep whose chunk vanished
|
|
1331
1410
|
pool = [
|
|
1332
1411
|
cid for cid in pool if cid in cos and (cid in dense_by or cid in docs)
|
|
@@ -1453,6 +1532,7 @@ class Crib:
|
|
|
1453
1532
|
hints=hints,
|
|
1454
1533
|
hint_weight=hint_weight if hint_weight is not None else hw,
|
|
1455
1534
|
store=store,
|
|
1535
|
+
labels=tags,
|
|
1456
1536
|
)
|
|
1457
1537
|
# a store wipe this project hasn't been re-swept after: what comes back is
|
|
1458
1538
|
# incomplete, so every hit says so rather than thin results reading as "all
|
|
@@ -1467,16 +1547,10 @@ class Crib:
|
|
|
1467
1547
|
for h in raw:
|
|
1468
1548
|
if h.score <= min_score: # drop orthogonal / irrelevant matches
|
|
1469
1549
|
continue
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
# those facets are identified by type, not by a hand-added tag, so
|
|
1473
|
-
# `tags=["design"]` is how you scope a lookup to them.
|
|
1474
|
-
have = set(filter(None, (h.metadata.get("tags") or "").split(",")))
|
|
1475
|
-
have |= set(filter(None, [h.metadata.get("type") or ""]))
|
|
1476
|
-
if not (set(tags) & have):
|
|
1477
|
-
continue
|
|
1550
|
+
# tags= was applied in the store query (`labels` = the chunk's tags
|
|
1551
|
+
# plus its frontmatter `type`, so tags=["design"] scopes to that facet).
|
|
1478
1552
|
rp = h.metadata.get("relpath", "")
|
|
1479
|
-
pillar =
|
|
1553
|
+
pillar = pillar_of(h.metadata.get("kind"))
|
|
1480
1554
|
heading = h.metadata.get("heading_path", "")
|
|
1481
1555
|
key = (pillar, rp) if dedupe == "file" else (pillar, rp, heading)
|
|
1482
1556
|
if dedupe != "none" and key in seen:
|
|
@@ -1679,21 +1753,12 @@ class Crib:
|
|
|
1679
1753
|
cw = self._code_watcher
|
|
1680
1754
|
return cw is not None and cw.watches(proj)
|
|
1681
1755
|
|
|
1682
|
-
def
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
def _resident_code(self, proj: str) -> _ResidentCode:
|
|
1689
|
-
return self.code.resident(
|
|
1690
|
-
proj, revalidate=self._revalidate, watched=self._code_watched(proj)
|
|
1691
|
-
)
|
|
1692
|
-
|
|
1693
|
-
def _reload_code(
|
|
1694
|
-
self, proj: str, tok: Any, prev: _ResidentCode | None
|
|
1695
|
-
) -> _ResidentCode:
|
|
1696
|
-
return self.code.reload(proj, tok, prev)
|
|
1756
|
+
def _store_code(self, proj: str) -> StoreCode:
|
|
1757
|
+
"""The project's code index as the code queries read it: from the store,
|
|
1758
|
+
made current first (`CodeStore.ensure`)."""
|
|
1759
|
+
self.code.ensure(proj, revalidate=self._revalidate,
|
|
1760
|
+
watched=self._code_watched(proj))
|
|
1761
|
+
return StoreCode(self.store, proj)
|
|
1697
1762
|
|
|
1698
1763
|
def code_indexed_projects(self) -> list[dict[str, Any]]:
|
|
1699
1764
|
"""Projects that have a symbol_index, with counts — for orienting an agent
|
|
@@ -1704,7 +1769,7 @@ class Crib:
|
|
|
1704
1769
|
for name in self.projects():
|
|
1705
1770
|
si = SymbolIndex(self.paths.project_dir(name))
|
|
1706
1771
|
if si.is_populated():
|
|
1707
|
-
out.append({"project": name, "symbols": len(
|
|
1772
|
+
out.append({"project": name, "symbols": len(self.code.records(name))})
|
|
1708
1773
|
return sorted(out, key=lambda x: -x["symbols"])
|
|
1709
1774
|
|
|
1710
1775
|
def _revalidate(self, proj: str) -> None:
|
|
@@ -2784,8 +2849,9 @@ class Crib:
|
|
|
2784
2849
|
symbol_index is NOT touched here — it travels with the project tree
|
|
2785
2850
|
(delete removes the tree; rename moves it)."""
|
|
2786
2851
|
chunks = list(self.store.get_meta({"project": proj}))
|
|
2787
|
-
|
|
2788
|
-
|
|
2852
|
+
items = list(self.store.items({"project": proj}))
|
|
2853
|
+
if chunks or items:
|
|
2854
|
+
self.store.apply([], chunks, {}, None, items)
|
|
2789
2855
|
self.index.invalidate_caches(proj)
|
|
2790
2856
|
if drop_sources:
|
|
2791
2857
|
reg = self._source_roots(proj)
|
|
@@ -2794,7 +2860,7 @@ class Crib:
|
|
|
2794
2860
|
mirrors_dropped = (
|
|
2795
2861
|
self.memory_bindings.drop_project(proj) if drop_bindings else []
|
|
2796
2862
|
)
|
|
2797
|
-
self.code.
|
|
2863
|
+
self.code.forget(proj)
|
|
2798
2864
|
self._bump_code_epoch(proj)
|
|
2799
2865
|
if self._describe_q is not None:
|
|
2800
2866
|
self._describe_q.drop_project(proj)
|
|
@@ -3563,7 +3629,6 @@ class Crib:
|
|
|
3563
3629
|
old_si_root is None or not old_si_root.exists()
|
|
3564
3630
|
):
|
|
3565
3631
|
symbol_index.set_source_root(new_root)
|
|
3566
|
-
self.code.cache.pop(old, None)
|
|
3567
3632
|
self._bump_code_epoch(old)
|
|
3568
3633
|
if self._code_watcher is not None:
|
|
3569
3634
|
self._code_watcher.watch_root(old, new_root) # re-point
|
|
@@ -4097,14 +4162,10 @@ class Crib:
|
|
|
4097
4162
|
|
|
4098
4163
|
proj = self.resolve_project(project, cwd)
|
|
4099
4164
|
si = SymbolIndex(self.paths.project_dir(proj))
|
|
4100
|
-
entries =
|
|
4165
|
+
entries = self.code.records(proj)
|
|
4101
4166
|
link = CribLink.find(Path(cwd)) if cwd else None
|
|
4102
4167
|
srcs = self._source_roots(proj).all()
|
|
4103
|
-
doc_count =
|
|
4104
|
-
1
|
|
4105
|
-
for m in self.store.get_meta({"project": proj}).values()
|
|
4106
|
-
if m.get("relpath", "").startswith(SRC_PREFIX)
|
|
4107
|
-
)
|
|
4168
|
+
doc_count = self.store.count({"project": proj, "kind": "doc"})
|
|
4108
4169
|
refs = [
|
|
4109
4170
|
{**r, "root": str(r["root"]) if r["root"] else None}
|
|
4110
4171
|
for r in self._project_refs(proj)
|
|
@@ -4147,11 +4208,7 @@ class Crib:
|
|
|
4147
4208
|
nd = pp.notes_dir
|
|
4148
4209
|
ld = pp.pillar_dir("learnings")
|
|
4149
4210
|
sd = pp.project_dir / "symbol_index"
|
|
4150
|
-
doc_chunks =
|
|
4151
|
-
1
|
|
4152
|
-
for m in self.store.get_meta({"project": name}).values()
|
|
4153
|
-
if m.get("relpath", "").startswith(SRC_PREFIX)
|
|
4154
|
-
)
|
|
4211
|
+
doc_chunks = self.store.count({"project": name, "kind": "doc"})
|
|
4155
4212
|
dd = pp.pillar_dir("design")
|
|
4156
4213
|
pd = pp.pillar_dir("plans")
|
|
4157
4214
|
row = {
|
|
@@ -4215,6 +4272,19 @@ class Crib:
|
|
|
4215
4272
|
# projects still un-embedded after a wipe: their lookups are THIN and
|
|
4216
4273
|
# say so per hit (`index_rebuilding`)
|
|
4217
4274
|
out["index_rebuilding"] = sorted(self._resweep_pending)
|
|
4275
|
+
stats = getattr(self.store, "stats", None)
|
|
4276
|
+
if callable(stats):
|
|
4277
|
+
# rows per table, versions, file/WAL size, and (shared) reconnects
|
|
4278
|
+
try:
|
|
4279
|
+
out["store_stats"] = stats()
|
|
4280
|
+
except Exception as e: # noqa: BLE001 — status must still answer
|
|
4281
|
+
out["store_stats"] = {"error": str(e)}
|
|
4282
|
+
hits = getattr(self.embedder, "hits", None)
|
|
4283
|
+
if hits is not None:
|
|
4284
|
+
out["embed_cache"] = {
|
|
4285
|
+
"hits": hits,
|
|
4286
|
+
"misses": getattr(self.embedder, "misses", 0),
|
|
4287
|
+
}
|
|
4218
4288
|
return out
|
|
4219
4289
|
|
|
4220
4290
|
def project_forget(
|
|
@@ -4234,20 +4304,15 @@ class Crib:
|
|
|
4234
4304
|
removed = len(list(si_root.glob("*.toml"))) if si_root.exists() else 0
|
|
4235
4305
|
if si_root.exists():
|
|
4236
4306
|
shutil.rmtree(si_root)
|
|
4237
|
-
self.code.
|
|
4238
|
-
proj, None
|
|
4239
|
-
) # drop resident cache (trust-mode won't see rmtree)
|
|
4307
|
+
self.code.forget(proj) # its items (trust mode won't see the rmtree)
|
|
4240
4308
|
self._bump_code_epoch(proj)
|
|
4241
4309
|
# In-situ docs are index-only (source is master) — drop their chunks + the
|
|
4242
4310
|
# source registry too; re-runnable via `project index`.
|
|
4243
4311
|
reg = self._source_roots(proj)
|
|
4244
|
-
doc_ids =
|
|
4245
|
-
|
|
4246
|
-
|
|
4247
|
-
|
|
4248
|
-
]
|
|
4249
|
-
if doc_ids:
|
|
4250
|
-
self.store.delete(doc_ids)
|
|
4312
|
+
doc_ids = list(self.store.get_meta({"project": proj, "kind": "doc"}))
|
|
4313
|
+
doc_items = list(self.store.items({"project": proj, "kind": "doc"}))
|
|
4314
|
+
if doc_ids or doc_items:
|
|
4315
|
+
self.store.apply([], doc_ids, {}, None, doc_items)
|
|
4251
4316
|
self.index.invalidate_caches(proj)
|
|
4252
4317
|
for prefix in list(reg.all()):
|
|
4253
4318
|
reg.remove(prefix)
|
|
@@ -4430,6 +4495,9 @@ class Crib:
|
|
|
4430
4495
|
sources: list[Any] | None = None,
|
|
4431
4496
|
proposed: bool = False,
|
|
4432
4497
|
cwd: Path | None = None,
|
|
4498
|
+
follows: list[str] | None = None,
|
|
4499
|
+
rests_on: list[str] | None = None,
|
|
4500
|
+
informed_by: list[str] | None = None,
|
|
4433
4501
|
) -> dict[str, Any]:
|
|
4434
4502
|
"""Record a design decision (deps validated + `checked` seeded, `sources`
|
|
4435
4503
|
captured at their current section hashes), with the same near-duplicate
|
|
@@ -4440,7 +4508,8 @@ class Crib:
|
|
|
4440
4508
|
dependents and neither taints the other's."""
|
|
4441
4509
|
proj = self.resolve_project(project, cwd)
|
|
4442
4510
|
out = await self.designs.design_add(
|
|
4443
|
-
proj, title, content, deps, sources, proposed
|
|
4511
|
+
proj, title, content, deps, sources, proposed,
|
|
4512
|
+
_kinded(follows, rests_on, informed_by),
|
|
4444
4513
|
)
|
|
4445
4514
|
similar = await asyncio.to_thread(
|
|
4446
4515
|
self._similar, proj, content, out["relpath"], "design"
|
|
@@ -4552,10 +4621,11 @@ class Crib:
|
|
|
4552
4621
|
dep_ref: str,
|
|
4553
4622
|
project: str | None = None,
|
|
4554
4623
|
cwd: Path | None = None,
|
|
4624
|
+
kind: str | None = None,
|
|
4555
4625
|
) -> dict[str, Any]:
|
|
4556
4626
|
"""Declare that a decision builds on another (cycle-checked)."""
|
|
4557
4627
|
return await self.designs.design_dep_add(
|
|
4558
|
-
self.resolve_project(project, cwd), ref, dep_ref
|
|
4628
|
+
self.resolve_project(project, cwd), ref, dep_ref, kind
|
|
4559
4629
|
)
|
|
4560
4630
|
|
|
4561
4631
|
async def design_dep_remove(
|
|
@@ -4684,6 +4754,9 @@ class Crib:
|
|
|
4684
4754
|
project: str | None = None,
|
|
4685
4755
|
sources: list[Any] | None = None,
|
|
4686
4756
|
cwd: Path | None = None,
|
|
4757
|
+
follows: list[str] | None = None,
|
|
4758
|
+
rests_on: list[str] | None = None,
|
|
4759
|
+
informed_by: list[str] | None = None,
|
|
4687
4760
|
) -> dict[str, Any]:
|
|
4688
4761
|
"""Add one plan item, or a whole batch (`items`), ranked at the end unless
|
|
4689
4762
|
after/before place them."""
|
|
@@ -4696,6 +4769,7 @@ class Crib:
|
|
|
4696
4769
|
before,
|
|
4697
4770
|
items,
|
|
4698
4771
|
sources,
|
|
4772
|
+
_kinded(follows, rests_on, informed_by),
|
|
4699
4773
|
)
|
|
4700
4774
|
|
|
4701
4775
|
async def plan_status(
|
|
@@ -4798,10 +4872,11 @@ class Crib:
|
|
|
4798
4872
|
dep_ref: str,
|
|
4799
4873
|
project: str | None = None,
|
|
4800
4874
|
cwd: Path | None = None,
|
|
4875
|
+
kind: str | None = None,
|
|
4801
4876
|
) -> dict[str, Any]:
|
|
4802
|
-
"""Declare that a plan item
|
|
4877
|
+
"""Declare that a plan item depends on another (cycle-checked)."""
|
|
4803
4878
|
return await self.designs.plan_dep_add(
|
|
4804
|
-
self.resolve_project(project, cwd), ref, dep_ref
|
|
4879
|
+
self.resolve_project(project, cwd), ref, dep_ref, kind
|
|
4805
4880
|
)
|
|
4806
4881
|
|
|
4807
4882
|
async def plan_dep_remove(
|
|
@@ -5718,14 +5793,19 @@ def _build_store(
|
|
|
5718
5793
|
|
|
5719
5794
|
Every store is a rebuildable cache: a fresh or empty one is filled by the
|
|
5720
5795
|
startup reconcile, which re-embeds what is on disk (no LLM)."""
|
|
5721
|
-
from .store import JsonStore
|
|
5722
|
-
|
|
5723
5796
|
backend = config.store.backend
|
|
5724
5797
|
if backend == "json":
|
|
5725
|
-
|
|
5726
|
-
|
|
5798
|
+
# Removed in 0.22: DuckDB ships in the base install, and the JSON file
|
|
5799
|
+
# was rewritten whole on every edit. The store is a cache, so nothing
|
|
5800
|
+
# is lost by switching; the startup reconcile fills the new one.
|
|
5801
|
+
print(
|
|
5802
|
+
'[crib] [store] backend = "json" is no longer supported; using duckdb. '
|
|
5803
|
+
"Remove the setting from config.toml.",
|
|
5804
|
+
file=sys.stderr,
|
|
5805
|
+
)
|
|
5806
|
+
elif backend != "duckdb":
|
|
5727
5807
|
raise CribUserError(
|
|
5728
|
-
f"[store] backend = {backend!r} is not a store crib knows (duckdb
|
|
5808
|
+
f"[store] backend = {backend!r} is not a store crib knows (duckdb)"
|
|
5729
5809
|
)
|
|
5730
5810
|
if config.duckdb.mode == "shared":
|
|
5731
5811
|
return _build_shared_duckdb(paths, config)
|
|
@@ -5772,17 +5852,22 @@ def _build_shared_duckdb(
|
|
|
5772
5852
|
|
|
5773
5853
|
if not c.launch:
|
|
5774
5854
|
# Externally supervised: never start (or restart) it; just attach. A
|
|
5775
|
-
# restart by the supervisor is survived by the client's reconnect
|
|
5776
|
-
|
|
5777
|
-
|
|
5778
|
-
|
|
5779
|
-
|
|
5780
|
-
|
|
5781
|
-
|
|
5782
|
-
|
|
5783
|
-
|
|
5784
|
-
|
|
5785
|
-
|
|
5855
|
+
# restart by the supervisor is survived by the client's reconnect,
|
|
5856
|
+
# which waits for the server like the first attach does.
|
|
5857
|
+
def wait() -> None:
|
|
5858
|
+
try:
|
|
5859
|
+
sharedserver.wait_ready(probe, timeout=c.attach_timeout)
|
|
5860
|
+
except sharedserver.SharedServerError as e:
|
|
5861
|
+
raise CribUserError(
|
|
5862
|
+
f"the crib DuckDB server is not answering at {uri} ({e}). It "
|
|
5863
|
+
"is configured as externally managed ([duckdb] launch = "
|
|
5864
|
+
"false): start it (`python -m crib.store_quack`, e.g. from a "
|
|
5865
|
+
"combiner sharedServers entry), or set launch = true to let "
|
|
5866
|
+
"crib start it"
|
|
5867
|
+
) from e
|
|
5868
|
+
|
|
5869
|
+
wait()
|
|
5870
|
+
store = QuackStore.connect(uri, token, ext, relaunch=wait)
|
|
5786
5871
|
return store, store.close
|
|
5787
5872
|
|
|
5788
5873
|
held = [0] # sharedserver refcounts this crib holds; each one is released at close
|