cribsheet 0.23.1.dev2__py3-none-any.whl → 0.24.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 +815 -231
- crib/chunk.py +3 -2
- crib/cli.py +1254 -1294
- crib/codequery.py +4 -3
- crib/config.py +198 -7
- crib/designs.py +416 -246
- crib/doctor.py +54 -2
- crib/facets.py +867 -0
- crib/facets.toml +84 -0
- crib/fields.py +151 -0
- crib/graph_texts.py +47 -0
- crib/indexer.py +36 -10
- crib/items.py +33 -31
- crib/learnings.py +59 -17
- crib/notestore.py +145 -19
- crib/paths.py +94 -6
- crib/related.py +2 -1
- crib/server.py +21 -1101
- crib/store.py +32 -0
- crib/store_duckdb.py +188 -18
- crib/store_quack.py +6 -2
- crib/verbs.py +1466 -0
- crib/watch.py +54 -2
- {cribsheet-0.23.1.dev2.dist-info → cribsheet-0.24.0.dev2.dist-info}/METADATA +13 -3
- {cribsheet-0.23.1.dev2.dist-info → cribsheet-0.24.0.dev2.dist-info}/RECORD +27 -22
- {cribsheet-0.23.1.dev2.dist-info → cribsheet-0.24.0.dev2.dist-info}/WHEEL +0 -0
- {cribsheet-0.23.1.dev2.dist-info → cribsheet-0.24.0.dev2.dist-info}/entry_points.txt +0 -0
crib/app.py
CHANGED
|
@@ -21,7 +21,7 @@ from dataclasses import dataclass, replace
|
|
|
21
21
|
from pathlib import Path
|
|
22
22
|
from typing import Any, Callable
|
|
23
23
|
|
|
24
|
-
from . import __version__, claudemem, notes
|
|
24
|
+
from . import __version__, claudemem, facets, notes
|
|
25
25
|
from .chunk import (
|
|
26
26
|
CHUNK_SCHEMA_VERSION,
|
|
27
27
|
kind_of,
|
|
@@ -41,10 +41,25 @@ 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 .
|
|
44
|
+
from .fields import conditions, matches, setting
|
|
45
|
+
from .learnings import AnchoredSet, Learnings
|
|
45
46
|
from .notes import Note, NoteParseError
|
|
46
|
-
from .notestore import
|
|
47
|
-
|
|
47
|
+
from .notestore import (
|
|
48
|
+
DESIGN_SPEC,
|
|
49
|
+
LEARNINGS_SPEC,
|
|
50
|
+
NOTES_SPEC,
|
|
51
|
+
PLANS_SPEC,
|
|
52
|
+
STORE_SPECS,
|
|
53
|
+
NoteStore,
|
|
54
|
+
)
|
|
55
|
+
from .paths import (
|
|
56
|
+
FacetLocation,
|
|
57
|
+
Paths,
|
|
58
|
+
ProjectPathResolver,
|
|
59
|
+
ProjectPaths,
|
|
60
|
+
check_project_name,
|
|
61
|
+
confine,
|
|
62
|
+
)
|
|
48
63
|
from .project_services import ProjectServices
|
|
49
64
|
from .refs import Refs
|
|
50
65
|
from .sources import SRC_PREFIX, SourceRoots, src_relpath
|
|
@@ -213,25 +228,23 @@ class Crib:
|
|
|
213
228
|
# over the SAME shared backends (vector store / IndexEngine / ring /
|
|
214
229
|
# resolver) — the pillars differ only by their StoreSpec. Crib keeps
|
|
215
230
|
# delegators for the notes pillar (below); the facet layers own theirs.
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
)
|
|
222
|
-
self.planstore = NoteStore(
|
|
223
|
-
paths, store, self.index, self.versions, self.project_paths, PLANS_SPEC
|
|
224
|
-
)
|
|
225
|
-
self.learningstore = NoteStore(
|
|
226
|
-
paths, store, self.index, self.versions, self.project_paths, LEARNINGS_SPEC
|
|
227
|
-
)
|
|
228
|
-
# Routing table for relpath-first entry points (the watcher, migration).
|
|
231
|
+
# One per facet in the registry (crib.facets), by store name: the
|
|
232
|
+
# routing table for relpath-first entry points (the watcher, migration).
|
|
233
|
+
# A declared facet whose definition this store hasn't been conformed to
|
|
234
|
+
# (`crib facets sync`) is PENDING: no store, not indexed or watched; its
|
|
235
|
+
# verbs refuse with the reason.
|
|
236
|
+
self.pending_facets: dict[str, str] = store.facet_pending()
|
|
229
237
|
self.pillars: dict[str, NoteStore] = {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
238
|
+
spec.name: NoteStore(
|
|
239
|
+
paths, store, self.index, self.versions, self.project_paths, spec
|
|
240
|
+
)
|
|
241
|
+
for noun, spec in STORE_SPECS.items()
|
|
242
|
+
if noun not in self.pending_facets
|
|
234
243
|
}
|
|
244
|
+
self.notestore = self.pillars[NOTES_SPEC.name]
|
|
245
|
+
self.designstore = self.pillars[DESIGN_SPEC.name]
|
|
246
|
+
self.planstore = self.pillars[PLANS_SPEC.name]
|
|
247
|
+
self.learningstore = self.pillars[LEARNINGS_SPEC.name]
|
|
235
248
|
self.memory_bindings = MemoryBindings(paths.data_dir / "memory-bindings.json")
|
|
236
249
|
self._reranker: Any = None # lazy cross-encoder, warm for the daemon
|
|
237
250
|
self._watcher: Watcher | None = None
|
|
@@ -301,16 +314,28 @@ class Crib:
|
|
|
301
314
|
self.relocate_jobs: dict[str, dict[str, Any]] = {}
|
|
302
315
|
# Durable symbol learnings, over refs + their own pillar store.
|
|
303
316
|
# Crib keeps resolve_project + delegate public wrappers (learning_add/…).
|
|
304
|
-
|
|
305
|
-
|
|
317
|
+
# One per anchored facet in the registry (crib.facets): learnings, and any
|
|
318
|
+
# declared facet whose items are about a code symbol.
|
|
319
|
+
self.anchored: dict[str, Learnings] = {
|
|
320
|
+
spec.noun: Learnings(paths, self.refs, self._facet_store(spec.noun),
|
|
321
|
+
self.code.records, noun=spec.noun)
|
|
322
|
+
for spec in facets.FACETS
|
|
323
|
+
if spec.has("anchored") and spec.noun not in self.pending_facets
|
|
324
|
+
}
|
|
325
|
+
self.learnings = self.anchored["learning"]
|
|
306
326
|
# Design decisions + plan items (notes under design/ and plans/) and the
|
|
307
327
|
# dependency graph over them. Same shape: Crib resolves, Designs executes.
|
|
308
|
-
|
|
328
|
+
# Every graph facet's store (links + status), pending ones aside.
|
|
329
|
+
self.designs = Designs(paths, {
|
|
330
|
+
spec.noun: self.pillars[spec.store]
|
|
331
|
+
for spec in facets.FACETS
|
|
332
|
+
if spec.has("links") and spec.has("status") and spec.store in self.pillars
|
|
333
|
+
}, self.notestore)
|
|
309
334
|
# Code-index queries (lookup/xref/dossier/graph) over refs + learnings + the
|
|
310
335
|
# resident cache. Crib keeps resolve_project + delegate public wrappers.
|
|
311
336
|
self.query = CodeQuery(
|
|
312
337
|
self.refs,
|
|
313
|
-
self.
|
|
338
|
+
AnchoredSet(tuple(self.anchored.values())),
|
|
314
339
|
self.embedder,
|
|
315
340
|
self._store_code,
|
|
316
341
|
self._require_code_index,
|
|
@@ -345,6 +370,7 @@ class Crib:
|
|
|
345
370
|
loop,
|
|
346
371
|
self._in_repo_store_roots(),
|
|
347
372
|
on_records=self._on_record_change,
|
|
373
|
+
mapped=self._mapped_facet_roots(),
|
|
348
374
|
)
|
|
349
375
|
self._watcher.start()
|
|
350
376
|
# Code watcher — reindexes source on edit (notes-watcher reloads notes,
|
|
@@ -386,6 +412,139 @@ class Crib:
|
|
|
386
412
|
self._watcher.start_probe(d.watch_probe_s, d.watch_catchup_s,
|
|
387
413
|
self._catch_up_while_degraded)
|
|
388
414
|
|
|
415
|
+
async def _sync_mappings(self, proj: str, link: CribLink) -> dict[str, Any]:
|
|
416
|
+
"""Record the repo's `.crib` `facets:` mappings in the project's stub (the
|
|
417
|
+
daemon, watcher and reconcile find them with no cwd), and reindex every
|
|
418
|
+
facet whose mapping changed. Nothing changed: nothing written."""
|
|
419
|
+
want: dict[str, dict[str, Any]] = {}
|
|
420
|
+
for noun, m in link.facets.items():
|
|
421
|
+
root = link.facet_dir(noun)
|
|
422
|
+
if root is None or m.prefix is not None:
|
|
423
|
+
continue # a prefixed mapping (docs) is registered by its sweep
|
|
424
|
+
want[noun] = {"root": portable_path(root, self.config.locations),
|
|
425
|
+
"glob": m.glob, "read_only": m.read_only, "ids": m.ids}
|
|
426
|
+
pp = self.project_paths(proj)
|
|
427
|
+
pcfg = ProjectConfig.load(pp.config_file, proj)
|
|
428
|
+
had = pcfg.mappings or {}
|
|
429
|
+
for noun in self._stranded_by(proj, link, had, want):
|
|
430
|
+
want[noun] = had[noun] # keep it recorded: release / a move can use it
|
|
431
|
+
if had == want:
|
|
432
|
+
return {}
|
|
433
|
+
pcfg.mappings = want or None
|
|
434
|
+
pcfg.save(pp.config_file)
|
|
435
|
+
self.project_paths.invalidate(proj)
|
|
436
|
+
self._rewatch(proj)
|
|
437
|
+
out: dict[str, Any] = {}
|
|
438
|
+
for noun in sorted(set(had) | set(want)):
|
|
439
|
+
if had.get(noun) == want.get(noun) or noun in self.pending_facets:
|
|
440
|
+
continue
|
|
441
|
+
spec = facets.get(noun)
|
|
442
|
+
if spec is None or spec.store not in self.pillars:
|
|
443
|
+
continue
|
|
444
|
+
# moved, added or dropped: the sweep re-reads the new home and drops
|
|
445
|
+
# what was indexed from the old one
|
|
446
|
+
res = await self.pillars[spec.store].reindex(proj)
|
|
447
|
+
out[noun] = {"root": (want.get(noun) or {}).get("root"),
|
|
448
|
+
"files": res["files"], **({"unstamped": res["unstamped"]}
|
|
449
|
+
if res.get("unstamped") else {})}
|
|
450
|
+
return out
|
|
451
|
+
|
|
452
|
+
def _stranded_by(self, proj: str, link: CribLink, had: dict[str, Any],
|
|
453
|
+
want: dict[str, Any]) -> list[str]:
|
|
454
|
+
"""The crib-owned mappings (writable, stamped) that `.crib` dropped or
|
|
455
|
+
moved while their items still sit at the recorded dir and the new home
|
|
456
|
+
holds none: following the change would re-point the facet at an empty
|
|
457
|
+
place and drop every indexed item, stranding the files. Each is warned
|
|
458
|
+
about, naming the fix; the caller keeps it recorded."""
|
|
459
|
+
from .filesync import scan
|
|
460
|
+
|
|
461
|
+
out = []
|
|
462
|
+
pp = self.project_paths(proj)
|
|
463
|
+
for noun, old in had.items():
|
|
464
|
+
new = want.get(noun)
|
|
465
|
+
if new == old or old.get("read_only") or old.get("ids", "stamp") != "stamp":
|
|
466
|
+
continue
|
|
467
|
+
spec = facets.get(noun)
|
|
468
|
+
if spec is None:
|
|
469
|
+
continue
|
|
470
|
+
loc = pp.mappings.get(spec.store)
|
|
471
|
+
if loc is None or not loc.available:
|
|
472
|
+
continue
|
|
473
|
+
# the items, by the ids stamped in them: the new home "holds them"
|
|
474
|
+
# only if files there carry those ids (what moving them looks like;
|
|
475
|
+
# an unrelated README there doesn't count)
|
|
476
|
+
ids = self._stamped_ids(loc.root, [r for r in scan(loc.root, ".md", recursive=True)
|
|
477
|
+
if loc.owns(r)])
|
|
478
|
+
n = len(ids)
|
|
479
|
+
if not n:
|
|
480
|
+
continue
|
|
481
|
+
if new is None:
|
|
482
|
+
home = pp.home_dir(spec.store)
|
|
483
|
+
found = self._stamped_ids(home, [str(f.relative_to(home))
|
|
484
|
+
for f in home.rglob("*.md")]) if home.is_dir() else set()
|
|
485
|
+
else:
|
|
486
|
+
root = link.facet_dir(noun)
|
|
487
|
+
m = link.facets[noun]
|
|
488
|
+
nloc = FacetLocation(root, "", m.glob) if root is not None else None
|
|
489
|
+
found = self._stamped_ids(root, [r for r in scan(root, ".md", recursive=True)
|
|
490
|
+
if nloc.owns(r)]) \
|
|
491
|
+
if root is not None and nloc is not None and root.is_dir() else set()
|
|
492
|
+
if ids <= found:
|
|
493
|
+
continue # every item is at the new home
|
|
494
|
+
what = "removed" if new is None else "moved"
|
|
495
|
+
where = link.root / ".crib" if link.root is not None else ".crib"
|
|
496
|
+
missing = len(ids - found)
|
|
497
|
+
state = ("the new home is empty" if not found else
|
|
498
|
+
f"the new home holds {len(found)} of the facet's items")
|
|
499
|
+
print(f"[crib] {where}: facets.{noun} was {what}, but {missing} of its "
|
|
500
|
+
f"item(s) are still in {loc.root} and {state} — "
|
|
501
|
+
f"keeping the mapping until they move: `crib project release` "
|
|
502
|
+
f"(back to crib's data dir), move the files"
|
|
503
|
+
f"{'' if new is None else ' to the new dir'}, or remove them if the "
|
|
504
|
+
f"facet is meant to start afresh, then re-run",
|
|
505
|
+
file=sys.stderr)
|
|
506
|
+
out.append(noun)
|
|
507
|
+
return out
|
|
508
|
+
|
|
509
|
+
@staticmethod
|
|
510
|
+
def _stamped_ids(root: Path, rels: list[str]) -> set[str]:
|
|
511
|
+
"""The ids stamped in these files under `root` (unreadable ones skipped)."""
|
|
512
|
+
out: set[str] = set()
|
|
513
|
+
for r in rels:
|
|
514
|
+
with contextlib.suppress(OSError, UnicodeDecodeError):
|
|
515
|
+
if nid := notes.scan_id((root / r).read_text()):
|
|
516
|
+
out.add(nid)
|
|
517
|
+
return out
|
|
518
|
+
|
|
519
|
+
def _rewatch(self, proj: str) -> None:
|
|
520
|
+
"""Bring the running watcher in line with `proj`'s storage after it
|
|
521
|
+
changed (mappings recorded or dropped, adopt, release): its mapped
|
|
522
|
+
facets' dirs and its in-repo store. No watcher (CLI, tests): nothing."""
|
|
523
|
+
w = self._watcher
|
|
524
|
+
if w is None:
|
|
525
|
+
return
|
|
526
|
+
self.project_paths.invalidate(proj)
|
|
527
|
+
w.set_mapped(proj, {store: root for (name, store), root
|
|
528
|
+
in self._mapped_facet_roots(only=proj).items()})
|
|
529
|
+
pp = self.project_paths(proj)
|
|
530
|
+
if pp.in_repo and pp.available and pp.store_root is not None:
|
|
531
|
+
w.add_store(proj, pp.data_root)
|
|
532
|
+
elif proj in w.stores:
|
|
533
|
+
w.forget_store(w.stores[proj])
|
|
534
|
+
|
|
535
|
+
def _mapped_facet_roots(self, only: str | None = None) -> dict[tuple[str, str], Path]:
|
|
536
|
+
"""`{(project, store): root}` for every mapped facet (`.crib` `facets:`)
|
|
537
|
+
whose directory is on this machine — the watcher's mapped roots. A
|
|
538
|
+
pending facet (`crib facets sync`) isn't watched."""
|
|
539
|
+
roots: dict[tuple[str, str], Path] = {}
|
|
540
|
+
for name in ([only] if only is not None else self.projects()):
|
|
541
|
+
for store, loc in self.project_paths(name).mappings.items():
|
|
542
|
+
spec = facets.by_store(store)
|
|
543
|
+
if spec is None or spec.noun in self.pending_facets or not loc.available:
|
|
544
|
+
continue
|
|
545
|
+
roots[(name, store)] = loc.root
|
|
546
|
+
return roots
|
|
547
|
+
|
|
389
548
|
def _in_repo_store_roots(self) -> dict[str, Path]:
|
|
390
549
|
"""`{project: data root}` for every project adopted into a repo whose
|
|
391
550
|
store is actually here — the extra watcher roots. The DATA ROOT, not the
|
|
@@ -435,15 +594,23 @@ class Crib:
|
|
|
435
594
|
t.add_done_callback(lambda _t: DIAG.done(token))
|
|
436
595
|
|
|
437
596
|
async def _on_fs_change(self, project: str, store: str, relpath: str) -> None:
|
|
597
|
+
if (spec := facets.by_store(store)) is not None and spec.noun in self.pending_facets:
|
|
598
|
+
return # not conformed yet (`crib facets sync`): nothing to index into
|
|
438
599
|
pillar = self.pillars.get(store, self.notestore)
|
|
600
|
+
if pillar.pending_move(project) is not None:
|
|
601
|
+
return # its items wait for `crib project adopt`: not served yet
|
|
602
|
+
loc = pillar.location(project)
|
|
603
|
+
if loc is not None and not loc.owns(relpath):
|
|
604
|
+
return # under the mapped dir, but not one of the facet's files
|
|
439
605
|
await self.index.index_file(
|
|
440
|
-
project, pillar.dir(project), relpath, store=pillar.spec.name
|
|
606
|
+
project, pillar.dir(project), relpath, store=pillar.spec.name,
|
|
607
|
+
**pillar._policy(project),
|
|
441
608
|
)
|
|
442
609
|
# index_file keeps the chunks (and their stamp); the design/plan graph
|
|
443
610
|
# keeps its own items and stamps, refreshed here rather than at the
|
|
444
611
|
# next graph read
|
|
445
612
|
kind = kind_of(pillar.spec.name)
|
|
446
|
-
if kind in
|
|
613
|
+
if kind in self.designs._stores: # a graph facet keeps its own items
|
|
447
614
|
await asyncio.to_thread(self.designs.refresh_files, project, kind, [relpath])
|
|
448
615
|
|
|
449
616
|
async def _on_record_change(
|
|
@@ -728,17 +895,82 @@ class Crib:
|
|
|
728
895
|
"""Per-project registry of docs indexed in-situ (prefix -> repo root)."""
|
|
729
896
|
return self.notestore.source_roots(project)
|
|
730
897
|
|
|
731
|
-
def
|
|
732
|
-
|
|
898
|
+
def _facet_store(self, facet: str) -> NoteStore:
|
|
899
|
+
"""The note store of a facet in the registry (crib.facets), by noun."""
|
|
900
|
+
self._require_conformed(facet)
|
|
901
|
+
return self.pillars[facets.by_noun(facet).store]
|
|
733
902
|
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
903
|
+
def _require_conformed(self, facet: str) -> None:
|
|
904
|
+
"""Refuse a facet the store hasn't been conformed to, saying what changed
|
|
905
|
+
and what to run."""
|
|
906
|
+
if (why := self.pending_facets.get(facet)) is not None:
|
|
907
|
+
raise CribUserError(
|
|
908
|
+
f"facet {facet!r} isn't ready in this store ({why}). Run "
|
|
909
|
+
"`crib facets sync` to see the plan, `crib facets sync --apply` to "
|
|
910
|
+
"carry it out, then restart the daemon."
|
|
911
|
+
)
|
|
912
|
+
|
|
913
|
+
def _anchored_facet(self, facet: str) -> Learnings:
|
|
914
|
+
self._require_conformed(facet)
|
|
915
|
+
return self.anchored[facet]
|
|
916
|
+
|
|
917
|
+
def _field_items(
|
|
918
|
+
self,
|
|
919
|
+
proj: str,
|
|
920
|
+
spec: facets.FacetSpec,
|
|
921
|
+
fields: dict[str, Any] | None,
|
|
922
|
+
where: list[dict[str, Any]] | None,
|
|
923
|
+
) -> list[dict[str, Any]]:
|
|
924
|
+
"""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)."""
|
|
927
|
+
conds = conditions(spec, fields, where)
|
|
928
|
+
out = []
|
|
929
|
+
for it in self.store.items({"project": proj, "kind": spec.noun}).values():
|
|
930
|
+
if not matches(conds, it.facet):
|
|
931
|
+
continue
|
|
932
|
+
row: dict[str, Any] = {"relpath": it.relpath, "title": it.title}
|
|
933
|
+
if spec.has("anchored"):
|
|
934
|
+
row["symbol"] = it.facet.get("symbol_ref")
|
|
935
|
+
row.update({k: it.facet.get(k) for k in spec.params})
|
|
936
|
+
out.append(row)
|
|
937
|
+
return sorted(out, key=lambda r: r["relpath"])
|
|
938
|
+
|
|
939
|
+
def list_items(
|
|
940
|
+
self,
|
|
941
|
+
project: str | None = None,
|
|
942
|
+
cwd: Path | None = None,
|
|
943
|
+
*,
|
|
944
|
+
facet: str,
|
|
945
|
+
fields: dict[str, Any] | None = None,
|
|
946
|
+
where: list[dict[str, Any]] | None = None,
|
|
947
|
+
k: int = 50,
|
|
948
|
+
) -> dict[str, Any]:
|
|
949
|
+
"""A declared facet's items filtered by its own fields, no query: `fields`
|
|
950
|
+
are equality filters, `where` the operator conditions (crib.fields)."""
|
|
951
|
+
proj = self.resolve_project(project, cwd)
|
|
952
|
+
self._require_conformed(facet)
|
|
953
|
+
rows = self._field_items(proj, facets.by_noun(facet), fields, where)
|
|
954
|
+
return {"project": proj, "total": len(rows), "items": rows[:k]}
|
|
955
|
+
|
|
956
|
+
def abspath(self, project: str, relpath: str, facet: str = facets.HOME) -> Path:
|
|
957
|
+
return self._facet_store(facet).abspath(project, relpath)
|
|
958
|
+
|
|
959
|
+
async def _write_note(
|
|
960
|
+
self, project: str, relpath: str, note: Note, facet: str = facets.HOME
|
|
961
|
+
) -> IndexResult:
|
|
962
|
+
res = await self._facet_store(facet).write(project, relpath, note)
|
|
963
|
+
if facet == facets.HOME:
|
|
964
|
+
self._schedule_keyword_refresh(project, relpath) # keep the sparse facet fresh
|
|
965
|
+
elif facets.by_noun(facet).has("enriched"):
|
|
966
|
+
self._schedule_keyword_refresh(project, relpath, kind=facet)
|
|
737
967
|
return res
|
|
738
968
|
|
|
739
969
|
_KW_SETTLE_S = 1.0 # per-note debounce before the refresh fires
|
|
740
970
|
|
|
741
|
-
def _schedule_keyword_refresh(
|
|
971
|
+
def _schedule_keyword_refresh(
|
|
972
|
+
self, project: str, relpath: str, kind: str | None = None
|
|
973
|
+
) -> None:
|
|
742
974
|
"""AUTO enrichment: after a note write, (re)generate the terms for the active
|
|
743
975
|
`keyword_labels` (BM25 facet) AND `summary_labels` (dense alias facet) — OFF
|
|
744
976
|
the save path, content-hash-gated so unchanged sections skip. Without this the
|
|
@@ -770,11 +1002,11 @@ class Crib:
|
|
|
770
1002
|
# labels) in one generation per section. `_generate_enrichment`
|
|
771
1003
|
# already drops the lexical/summary caches iff it generated anything,
|
|
772
1004
|
# so the next query rebuilds — no extra invalidation needed here.
|
|
773
|
-
await self.enrich(relpath=relpath, project=project)
|
|
1005
|
+
await self.enrich(relpath=relpath, project=project, kind=kind)
|
|
774
1006
|
except Exception as e: # noqa: BLE001 — best-effort background refresh
|
|
775
1007
|
print(f"[crib] auto enrichment refresh failed: {e}", file=sys.stderr)
|
|
776
1008
|
|
|
777
|
-
key = (project, relpath)
|
|
1009
|
+
key = (project, relpath) if kind is None else (project, f"{kind}:{relpath}")
|
|
778
1010
|
|
|
779
1011
|
def _fire() -> None:
|
|
780
1012
|
self._kw_timers.pop(key, None)
|
|
@@ -793,16 +1025,30 @@ class Crib:
|
|
|
793
1025
|
"""True if `proj` has no notes dir yet (a write would create it)."""
|
|
794
1026
|
return not self.project_paths(proj).notes_dir.exists()
|
|
795
1027
|
|
|
796
|
-
def
|
|
1028
|
+
def _import_relpath(self, proj: str, facet: str, src: Path) -> str:
|
|
1029
|
+
"""Where an imported doc lands: `imported/<name>`, or under a mapped
|
|
1030
|
+
location, a name its glob takes (the glob's suffix; no `imported/` dir
|
|
1031
|
+
when the glob doesn't reach into subdirectories)."""
|
|
1032
|
+
store = self._facet_store(facet)
|
|
1033
|
+
loc = store.location(proj)
|
|
1034
|
+
rel = f"imported/{src.name}"
|
|
1035
|
+
if loc is None or loc.prefix is not None or loc.owns(rel):
|
|
1036
|
+
return rel
|
|
1037
|
+
stem = src.name[: -len(".md")] if src.name.endswith(".md") else src.stem
|
|
1038
|
+
nested = f"imported/{stem}{loc.suffix}"
|
|
1039
|
+
return nested if loc.owns(nested) else f"imported-{stem}{loc.suffix}"
|
|
1040
|
+
|
|
1041
|
+
def _unique_relpath(self, proj: str, slug: str, facet: str = facets.HOME) -> str:
|
|
797
1042
|
"""`<slug>.md`, with a numeric suffix only on collision — predictable and
|
|
798
1043
|
hand-referenceable. Stable identity is the frontmatter `id`, not the path."""
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
1044
|
+
store = self._facet_store(facet)
|
|
1045
|
+
base, ext = store.dir(proj), store.suffix(proj)
|
|
1046
|
+
if not (base / f"{slug}{ext}").exists():
|
|
1047
|
+
return f"{slug}{ext}"
|
|
802
1048
|
i = 2
|
|
803
|
-
while (base / f"{slug}-{i}
|
|
1049
|
+
while (base / f"{slug}-{i}{ext}").exists():
|
|
804
1050
|
i += 1
|
|
805
|
-
return f"{slug}-{i}
|
|
1051
|
+
return f"{slug}-{i}{ext}"
|
|
806
1052
|
|
|
807
1053
|
# Write-time warnings (`similar`, Stage E4), measured on the live corpus
|
|
808
1054
|
# (1,141 items, 2026-11-13): an item's nearest same-project neighbour sits at
|
|
@@ -853,7 +1099,7 @@ class Crib:
|
|
|
853
1099
|
# doesn't depend on probably builds on it
|
|
854
1100
|
my_deps = {e.dst for e in me.edges
|
|
855
1101
|
if e.kind == "dep" or e.kind in ("follows", "rests_on", "informed_by")}
|
|
856
|
-
noun =
|
|
1102
|
+
noun = kind if kind in self.designs._stores else None
|
|
857
1103
|
rows: list[dict[str, Any]] = []
|
|
858
1104
|
for k in self._SIMILAR_KINDS:
|
|
859
1105
|
for it in self.store.items({"project": proj, "kind": k}).values():
|
|
@@ -912,6 +1158,9 @@ class Crib:
|
|
|
912
1158
|
project: str | None = None,
|
|
913
1159
|
tags: list[str] | None = None,
|
|
914
1160
|
cwd: Path | None = None,
|
|
1161
|
+
*,
|
|
1162
|
+
facet: str = facets.HOME,
|
|
1163
|
+
fields: dict[str, Any] | None = None,
|
|
915
1164
|
) -> dict[str, Any]:
|
|
916
1165
|
proj = self.resolve_project(project, cwd)
|
|
917
1166
|
created = self.project_is_new(proj)
|
|
@@ -921,13 +1170,16 @@ class Crib:
|
|
|
921
1170
|
title = title or (
|
|
922
1171
|
content.strip().splitlines()[0][:60] if content.strip() else "note"
|
|
923
1172
|
)
|
|
924
|
-
relpath = self._unique_relpath(proj, _slug(title))
|
|
1173
|
+
relpath = self._unique_relpath(proj, _slug(title), facet)
|
|
925
1174
|
fm: dict[str, Any] = {"title": title, "source": "manual"}
|
|
926
1175
|
if tags:
|
|
927
1176
|
fm["tags"] = tags
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
1177
|
+
fm.update(setting(facets.by_noun(facet), fields)) # a declared facet's own
|
|
1178
|
+
note = Note(path=self.abspath(proj, relpath, facet), frontmatter=fm, body=content)
|
|
1179
|
+
res = await self._write_note(proj, relpath, note, facet)
|
|
1180
|
+
similar = await asyncio.to_thread(
|
|
1181
|
+
self._similar, proj, relpath, facets.by_noun(facet).store
|
|
1182
|
+
)
|
|
931
1183
|
return {
|
|
932
1184
|
"project": proj,
|
|
933
1185
|
"relpath": relpath,
|
|
@@ -943,11 +1195,13 @@ class Crib:
|
|
|
943
1195
|
to_relpath: str | None = None,
|
|
944
1196
|
project: str | None = None,
|
|
945
1197
|
cwd: Path | None = None,
|
|
1198
|
+
*,
|
|
1199
|
+
facet: str = facets.HOME,
|
|
946
1200
|
) -> dict[str, Any]:
|
|
947
1201
|
"""Relocate a note across projects and/or rename it, preserving its `id`
|
|
948
1202
|
(and thus version-ring history). One-way: write destination, drop source."""
|
|
949
1203
|
src_proj = self.resolve_project(project, cwd)
|
|
950
|
-
return await self.
|
|
1204
|
+
return await self._facet_store(facet).move(
|
|
951
1205
|
src_proj, relpath, to_project or src_proj, to_relpath or relpath
|
|
952
1206
|
)
|
|
953
1207
|
|
|
@@ -958,9 +1212,11 @@ class Crib:
|
|
|
958
1212
|
heading: str | None = None,
|
|
959
1213
|
project: str | None = None,
|
|
960
1214
|
cwd: Path | None = None,
|
|
1215
|
+
*,
|
|
1216
|
+
facet: str = facets.HOME,
|
|
961
1217
|
) -> dict[str, Any]:
|
|
962
1218
|
proj = self.resolve_project(project, cwd)
|
|
963
|
-
path = self.abspath(proj, relpath)
|
|
1219
|
+
path = self.abspath(proj, relpath, facet)
|
|
964
1220
|
note = (
|
|
965
1221
|
notes.load(path)
|
|
966
1222
|
if path.exists()
|
|
@@ -968,7 +1224,7 @@ class Crib:
|
|
|
968
1224
|
)
|
|
969
1225
|
block = f"\n\n## {heading}\n{content}" if heading else f"\n\n{content}"
|
|
970
1226
|
note.body = note.body.rstrip() + block
|
|
971
|
-
res = await self._write_note(proj, relpath, note)
|
|
1227
|
+
res = await self._write_note(proj, relpath, note, facet)
|
|
972
1228
|
return {"project": proj, "relpath": relpath, "indexed": res.upserted}
|
|
973
1229
|
|
|
974
1230
|
async def edit_note(
|
|
@@ -977,23 +1233,33 @@ class Crib:
|
|
|
977
1233
|
new_content: str,
|
|
978
1234
|
project: str | None = None,
|
|
979
1235
|
cwd: Path | None = None,
|
|
1236
|
+
*,
|
|
1237
|
+
facet: str = facets.HOME,
|
|
1238
|
+
fields: dict[str, Any] | None = None,
|
|
980
1239
|
) -> dict[str, Any]:
|
|
981
|
-
"""Replace raw file content (frontmatter preserved if present in input).
|
|
1240
|
+
"""Replace raw file content (frontmatter preserved if present in input).
|
|
1241
|
+
`fields` sets a declared facet's own fields (only the ones given)."""
|
|
982
1242
|
proj = self.resolve_project(project, cwd)
|
|
983
1243
|
fm, body = notes.parse(new_content)
|
|
984
|
-
path = self.abspath(proj, relpath)
|
|
1244
|
+
path = self.abspath(proj, relpath, facet)
|
|
985
1245
|
if not fm and path.exists():
|
|
986
1246
|
try:
|
|
987
1247
|
fm = notes.load(path).frontmatter # keep existing frontmatter
|
|
988
1248
|
except NoteParseError:
|
|
989
1249
|
fm = {} # unparseable header: this edit REPAIRS it (the old
|
|
990
1250
|
# bytes go to the version ring on the way through)
|
|
1251
|
+
fm.update(setting(facets.by_noun(facet), fields))
|
|
991
1252
|
note = Note(path=path, frontmatter=fm, body=body)
|
|
992
|
-
res = await self._write_note(proj, relpath, note)
|
|
1253
|
+
res = await self._write_note(proj, relpath, note, facet)
|
|
993
1254
|
return {"project": proj, "relpath": relpath, "indexed": res.upserted}
|
|
994
1255
|
|
|
995
1256
|
async def forget(
|
|
996
|
-
self,
|
|
1257
|
+
self,
|
|
1258
|
+
relpath: str,
|
|
1259
|
+
project: str | None = None,
|
|
1260
|
+
cwd: Path | None = None,
|
|
1261
|
+
*,
|
|
1262
|
+
facet: str = facets.HOME,
|
|
997
1263
|
) -> dict[str, Any]:
|
|
998
1264
|
"""Delete a note: remove it from disk and drop its chunks from the index.
|
|
999
1265
|
|
|
@@ -1002,19 +1268,29 @@ class Crib:
|
|
|
1002
1268
|
of the index entry happens through the same `index_file` — once the file
|
|
1003
1269
|
is gone, it sees a missing path and drops all chunks for that relpath."""
|
|
1004
1270
|
proj = self.resolve_project(project, cwd)
|
|
1005
|
-
return await self.
|
|
1271
|
+
return await self._facet_store(facet).delete(proj, relpath)
|
|
1006
1272
|
|
|
1007
1273
|
def read_note(
|
|
1008
|
-
self,
|
|
1274
|
+
self,
|
|
1275
|
+
relpath: str,
|
|
1276
|
+
project: str | None = None,
|
|
1277
|
+
cwd: Path | None = None,
|
|
1278
|
+
*,
|
|
1279
|
+
facet: str = facets.HOME,
|
|
1009
1280
|
) -> str:
|
|
1010
1281
|
proj = self.resolve_project(project, cwd)
|
|
1011
|
-
return self.
|
|
1282
|
+
return self._facet_store(facet).read(proj, relpath)
|
|
1012
1283
|
|
|
1013
1284
|
def locate(
|
|
1014
|
-
self,
|
|
1285
|
+
self,
|
|
1286
|
+
relpath: str,
|
|
1287
|
+
project: str | None = None,
|
|
1288
|
+
cwd: Path | None = None,
|
|
1289
|
+
*,
|
|
1290
|
+
facet: str = facets.HOME,
|
|
1015
1291
|
) -> str:
|
|
1016
1292
|
proj = self.resolve_project(project, cwd)
|
|
1017
|
-
return str(self.abspath(proj, relpath))
|
|
1293
|
+
return str(self.abspath(proj, relpath, facet))
|
|
1018
1294
|
|
|
1019
1295
|
async def reindex(
|
|
1020
1296
|
self,
|
|
@@ -1022,9 +1298,15 @@ class Crib:
|
|
|
1022
1298
|
project: str | None = None,
|
|
1023
1299
|
cwd: Path | None = None,
|
|
1024
1300
|
full: bool = True,
|
|
1301
|
+
*,
|
|
1302
|
+
facet: str = facets.HOME,
|
|
1025
1303
|
) -> dict[str, Any]:
|
|
1026
1304
|
"""Reindex a note, or fully reconcile a project when relpath is None.
|
|
1027
1305
|
|
|
1306
|
+
For a facet other than notes, the reconcile covers that facet's store
|
|
1307
|
+
only; the notes reconcile is the whole project's (every pillar, plus the
|
|
1308
|
+
legacy-layout migration and the embedder check).
|
|
1309
|
+
|
|
1028
1310
|
Full reconcile walks the UNION of on-disk notes and indexed paths, so it
|
|
1029
1311
|
catches files added/edited while crib was down AND drops orphaned chunks
|
|
1030
1312
|
for notes deleted off disk. All idempotent via the hash gate (§4).
|
|
@@ -1036,7 +1318,9 @@ class Crib:
|
|
|
1036
1318
|
returning nothing."""
|
|
1037
1319
|
proj = self.resolve_project(project, cwd)
|
|
1038
1320
|
if relpath:
|
|
1039
|
-
return await self.
|
|
1321
|
+
return await self._facet_store(facet).reindex(proj, relpath)
|
|
1322
|
+
if facet != facets.HOME:
|
|
1323
|
+
return await self._facet_store(facet).reindex(proj, full=full)
|
|
1040
1324
|
# Self-heal the legacy facet layout FIRST, so this very sweep drops the
|
|
1041
1325
|
# old-path chunks and embeds the moved files — also what absorbs
|
|
1042
1326
|
# old-layout files a not-yet-upgraded machine pushed into the sync repo.
|
|
@@ -1047,7 +1331,7 @@ class Crib:
|
|
|
1047
1331
|
res = await self.notestore.reindex(proj, full=full)
|
|
1048
1332
|
# Fan out over the sibling pillars — same union sweep, each scoped to its
|
|
1049
1333
|
# own tree and its own chunks. Empty pillars are cheap no-ops.
|
|
1050
|
-
for pillar in (
|
|
1334
|
+
for pillar in (s for s in self.pillars.values() if s is not self.notestore):
|
|
1051
1335
|
r = await pillar.reindex(proj, full=full)
|
|
1052
1336
|
for k in ("files", "changed", "removed"):
|
|
1053
1337
|
res[k] += r[k]
|
|
@@ -1371,6 +1655,7 @@ class Crib:
|
|
|
1371
1655
|
*,
|
|
1372
1656
|
store: str = "notes",
|
|
1373
1657
|
labels: list[str] | None = None,
|
|
1658
|
+
relpaths: frozenset[str] | None = None,
|
|
1374
1659
|
) -> list[Hit]:
|
|
1375
1660
|
"""Candidate Hits in DENSE-DOMINANT SCORE order: raw cosine (dense, already
|
|
1376
1661
|
calibrated) + min-max'd keyword_index BM25, over the union candidate pool. Only
|
|
@@ -1395,6 +1680,8 @@ class Crib:
|
|
|
1395
1680
|
# A tags= lookup filters IN the query, so the dense top-n is drawn
|
|
1396
1681
|
# from matching chunks only, never thinned after the fact.
|
|
1397
1682
|
where["labels"] = {"$any": list(labels)}
|
|
1683
|
+
if relpaths is not None: # a declared facet's field filters, likewise
|
|
1684
|
+
where["relpath"] = {"$in": sorted(relpaths)}
|
|
1398
1685
|
# `where` is a vector-store filter dict (an exact-match metadata predicate),
|
|
1399
1686
|
# not a SQL string; there is no SQL here.
|
|
1400
1687
|
# pi-lens-ignore: python-sql-injection
|
|
@@ -1472,15 +1759,19 @@ class Crib:
|
|
|
1472
1759
|
pool = list(dict.fromkeys(list(cos) + list(kw) + list(hint_hits)))
|
|
1473
1760
|
if not docs: # need doc text to back-fill cosines
|
|
1474
1761
|
docs = self.store.get_docs(where)
|
|
1475
|
-
if labels:
|
|
1762
|
+
if labels or relpaths is not None:
|
|
1476
1763
|
# The lexical index and the alias cache span the whole store, so
|
|
1477
|
-
# their candidates get the same label filter the query
|
|
1478
|
-
|
|
1764
|
+
# their candidates get the same label / relpath filter the query
|
|
1765
|
+
# applied.
|
|
1766
|
+
wanted = set(labels or ())
|
|
1479
1767
|
|
|
1480
1768
|
def _labelled(cid: str) -> bool:
|
|
1481
1769
|
h = dense_by.get(cid)
|
|
1482
1770
|
meta = h.metadata if h is not None else docs.get(cid, ("", {}))[1]
|
|
1483
|
-
|
|
1771
|
+
meta = meta or {}
|
|
1772
|
+
if wanted and not wanted & set(meta.get("labels") or []):
|
|
1773
|
+
return False
|
|
1774
|
+
return relpaths is None or meta.get("relpath") in relpaths
|
|
1484
1775
|
|
|
1485
1776
|
pool = [cid for cid in pool if _labelled(cid)]
|
|
1486
1777
|
kw = {cid: v for cid, v in kw.items() if cid in pool}
|
|
@@ -1552,6 +1843,8 @@ class Crib:
|
|
|
1552
1843
|
hint_weight: float | None = None,
|
|
1553
1844
|
*,
|
|
1554
1845
|
store: str = "notes",
|
|
1846
|
+
fields: dict[str, Any] | None = None,
|
|
1847
|
+
where: list[dict[str, Any]] | None = None,
|
|
1555
1848
|
) -> list[LookupHit]:
|
|
1556
1849
|
"""Ranked sections matching `query`.
|
|
1557
1850
|
|
|
@@ -1601,6 +1894,18 @@ class Crib:
|
|
|
1601
1894
|
hw = self.config.retrieve.hint_weight if hint_weight is None else hint_weight
|
|
1602
1895
|
# Hybrid pulls a wider candidate pool so BM25 can promote terms dense ranked low.
|
|
1603
1896
|
topn = max(k * 3, 30) if use_hybrid else (k if dedupe == "none" else k * 3)
|
|
1897
|
+
# A declared facet's field filters: the search runs over the matching
|
|
1898
|
+
# items only (none match: nothing to search).
|
|
1899
|
+
relpaths: frozenset[str] | None = None
|
|
1900
|
+
spec = facets.by_store(store)
|
|
1901
|
+
if spec is not None:
|
|
1902
|
+
self._require_conformed(spec.noun)
|
|
1903
|
+
if spec is not None and (fields or where):
|
|
1904
|
+
relpaths = frozenset(
|
|
1905
|
+
it["relpath"] for it in self._field_items(proj, spec, fields, where)
|
|
1906
|
+
)
|
|
1907
|
+
if not relpaths:
|
|
1908
|
+
return []
|
|
1604
1909
|
raw = self._retrieve(
|
|
1605
1910
|
proj,
|
|
1606
1911
|
query,
|
|
@@ -1616,6 +1921,7 @@ class Crib:
|
|
|
1616
1921
|
hint_weight=hint_weight if hint_weight is not None else hw,
|
|
1617
1922
|
store=store,
|
|
1618
1923
|
labels=tags,
|
|
1924
|
+
relpaths=relpaths,
|
|
1619
1925
|
)
|
|
1620
1926
|
return self._hits_from(proj, raw, k, dedupe, min_score)
|
|
1621
1927
|
|
|
@@ -1692,6 +1998,10 @@ class Crib:
|
|
|
1692
1998
|
tags: list[str] | None = None,
|
|
1693
1999
|
cwd: Path | None = None,
|
|
1694
2000
|
hints: list[str] | None = None,
|
|
2001
|
+
*,
|
|
2002
|
+
facet: str = facets.HOME,
|
|
2003
|
+
fields: dict[str, Any] | None = None,
|
|
2004
|
+
where: list[dict[str, Any]] | None = None,
|
|
1695
2005
|
) -> list[dict[str, Any]]:
|
|
1696
2006
|
"""`lookup` (same section-level dedupe) but each hit carries the FULL
|
|
1697
2007
|
matching section markdown — sliced from the file by its line span — rather
|
|
@@ -1699,7 +2009,8 @@ class Crib:
|
|
|
1699
2009
|
proj = self.resolve_project(project, cwd)
|
|
1700
2010
|
out: list[dict[str, Any]] = []
|
|
1701
2011
|
for h in self.lookup(
|
|
1702
|
-
query, project, k, tags, dedupe="section", cwd=cwd, hints=hints
|
|
2012
|
+
query, project, k, tags, dedupe="section", cwd=cwd, hints=hints,
|
|
2013
|
+
store=facets.by_noun(facet).store, fields=fields, where=where,
|
|
1703
2014
|
):
|
|
1704
2015
|
section = h.snippet
|
|
1705
2016
|
if h.line_start and h.line_end:
|
|
@@ -1715,7 +2026,12 @@ class Crib:
|
|
|
1715
2026
|
|
|
1716
2027
|
# --- generation: distill + elaborate (knowledge-capture §2/§4, §3.1) ---
|
|
1717
2028
|
async def distill(
|
|
1718
|
-
self,
|
|
2029
|
+
self,
|
|
2030
|
+
relpath: str,
|
|
2031
|
+
project: str | None = None,
|
|
2032
|
+
cwd: Path | None = None,
|
|
2033
|
+
*,
|
|
2034
|
+
facet: str = facets.HOME,
|
|
1719
2035
|
) -> dict[str, Any]:
|
|
1720
2036
|
"""Revise a note in place via the LLM: compress, dedupe, normalize; keep
|
|
1721
2037
|
facts/decisions, drop deliberation, preserve code verbatim. Thrash-guarded
|
|
@@ -1723,7 +2039,7 @@ class Crib:
|
|
|
1723
2039
|
through the version ring so a bad revision is a cheap rollback."""
|
|
1724
2040
|
self._require_generation("distill")
|
|
1725
2041
|
proj = self.resolve_project(project, cwd)
|
|
1726
|
-
path = self.abspath(proj, relpath)
|
|
2042
|
+
path = self.abspath(proj, relpath, facet)
|
|
1727
2043
|
if not path.exists():
|
|
1728
2044
|
raise CribUserError(f"no such note: {relpath} in project {proj!r}")
|
|
1729
2045
|
note = notes.load(path)
|
|
@@ -1743,7 +2059,7 @@ class Crib:
|
|
|
1743
2059
|
return {"project": proj, "relpath": relpath, "changed": False}
|
|
1744
2060
|
note.frontmatter["source"] = "distilled"
|
|
1745
2061
|
note.body = new_body
|
|
1746
|
-
res = await self._write_note(proj, relpath, note)
|
|
2062
|
+
res = await self._write_note(proj, relpath, note, facet)
|
|
1747
2063
|
return {
|
|
1748
2064
|
"project": proj,
|
|
1749
2065
|
"relpath": relpath,
|
|
@@ -1758,6 +2074,8 @@ class Crib:
|
|
|
1758
2074
|
project: str | None = None,
|
|
1759
2075
|
cwd: Path | None = None,
|
|
1760
2076
|
overwrite: bool = False,
|
|
2077
|
+
*,
|
|
2078
|
+
facet: str = facets.HOME,
|
|
1761
2079
|
) -> dict[str, Any]:
|
|
1762
2080
|
"""keyword_index: generate search terms per section for BM25 (§3.1).
|
|
1763
2081
|
`crib elaborate <label>`; activate via `[retrieve].keyword_labels`."""
|
|
@@ -1773,6 +2091,7 @@ class Crib:
|
|
|
1773
2091
|
project,
|
|
1774
2092
|
cwd,
|
|
1775
2093
|
overwrite,
|
|
2094
|
+
kind=None if facet == facets.HOME else facet,
|
|
1776
2095
|
)
|
|
1777
2096
|
|
|
1778
2097
|
async def summarize(
|
|
@@ -1782,6 +2101,8 @@ class Crib:
|
|
|
1782
2101
|
project: str | None = None,
|
|
1783
2102
|
cwd: Path | None = None,
|
|
1784
2103
|
overwrite: bool = False,
|
|
2104
|
+
*,
|
|
2105
|
+
facet: str = facets.HOME,
|
|
1785
2106
|
) -> dict[str, Any]:
|
|
1786
2107
|
"""summary_index: generate LLM rephrasings per section, embedded as dense
|
|
1787
2108
|
alias vectors (§3). `crib summarize <label>`; activate via
|
|
@@ -1798,6 +2119,7 @@ class Crib:
|
|
|
1798
2119
|
project,
|
|
1799
2120
|
cwd,
|
|
1800
2121
|
overwrite,
|
|
2122
|
+
kind=None if facet == facets.HOME else facet,
|
|
1801
2123
|
)
|
|
1802
2124
|
|
|
1803
2125
|
# --- code symbol index (docs/code-symbol-index.md) --------------------
|
|
@@ -2162,6 +2484,7 @@ class Crib:
|
|
|
2162
2484
|
link, created = self._ensure_crib(cwd, project, want_code=True, want_docs=True)
|
|
2163
2485
|
proj = project or link.project
|
|
2164
2486
|
new_project = proj not in self.projects() # before indexing creates its dirs
|
|
2487
|
+
mapped = await self._sync_mappings(proj, link)
|
|
2165
2488
|
docs = (
|
|
2166
2489
|
await self.index_docs_insitu(proj, link.root) if link.doc_patterns else {}
|
|
2167
2490
|
)
|
|
@@ -2173,6 +2496,7 @@ class Crib:
|
|
|
2173
2496
|
"crib_created": created,
|
|
2174
2497
|
"created": new_project,
|
|
2175
2498
|
"docs_indexed": docs.get("docs", 0),
|
|
2499
|
+
**({"facets_mapped": mapped} if mapped else {}),
|
|
2176
2500
|
**code,
|
|
2177
2501
|
}
|
|
2178
2502
|
|
|
@@ -2204,6 +2528,7 @@ class Crib:
|
|
|
2204
2528
|
re-skip via the content-hash gate)."""
|
|
2205
2529
|
link, created = self._ensure_crib(cwd, project, want_code=True, want_docs=False)
|
|
2206
2530
|
proj = project or link.project
|
|
2531
|
+
await self._sync_mappings(proj, link)
|
|
2207
2532
|
crib_file = link.root / ".crib"
|
|
2208
2533
|
crib_at = crib_file.stat().st_mtime if crib_file.exists() else None
|
|
2209
2534
|
running = self.code_jobs.get(proj)
|
|
@@ -2433,28 +2758,93 @@ class Crib:
|
|
|
2433
2758
|
ids.append(note_id)
|
|
2434
2759
|
return ids
|
|
2435
2760
|
|
|
2761
|
+
@staticmethod
|
|
2762
|
+
def _tree_pairs(src: Path, dst: Path) -> list[tuple[Path, Path]]:
|
|
2763
|
+
"""`(file, its place under dst)` for every file under `src`."""
|
|
2764
|
+
if not src.is_dir():
|
|
2765
|
+
return []
|
|
2766
|
+
return [(p, dst / p.relative_to(src)) for p in sorted(src.rglob("*")) if p.is_file()]
|
|
2767
|
+
|
|
2436
2768
|
@staticmethod
|
|
2437
2769
|
def _move_tree(src: Path, dst: Path) -> int:
|
|
2438
2770
|
"""Move every file under `src` to the same relpath under `dst`, returning
|
|
2439
|
-
the count
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
file moves."""
|
|
2771
|
+
the count: a version-ring entry's stashes (_move_ring). Per-file, and a
|
|
2772
|
+
stash already at the destination is kept, never overwritten (items move
|
|
2773
|
+
through `_move_files`, all or nothing)."""
|
|
2443
2774
|
|
|
2444
2775
|
import shutil
|
|
2445
2776
|
|
|
2446
2777
|
moved = 0
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2778
|
+
kept = 0
|
|
2779
|
+
for p, target in Crib._tree_pairs(src, dst):
|
|
2780
|
+
if target.exists():
|
|
2781
|
+
kept += 1 # never overwritten; the source keeps it
|
|
2451
2782
|
continue
|
|
2452
|
-
target = dst / p.relative_to(src)
|
|
2453
2783
|
target.parent.mkdir(parents=True, exist_ok=True)
|
|
2454
2784
|
shutil.move(str(p), str(target))
|
|
2455
2785
|
moved += 1
|
|
2786
|
+
if kept:
|
|
2787
|
+
print(f"[crib] {kept} version stash(es) already in {dst} were kept; "
|
|
2788
|
+
f"the copies in {src} stay where they are", file=sys.stderr)
|
|
2456
2789
|
return moved
|
|
2457
2790
|
|
|
2791
|
+
@staticmethod
|
|
2792
|
+
def _merge_clashes(a_rels: list[str], b_rels: list[str]) -> list[str]:
|
|
2793
|
+
"""What stops merging one tree's items into another's: the same relpath
|
|
2794
|
+
on both sides (the move would overwrite a file). Disjoint trees merge:
|
|
2795
|
+
that is what makes an interrupted adopt resumable, and a teammate's
|
|
2796
|
+
committed items joinable by yours. Two files sharing one ID (a copy of
|
|
2797
|
+
the same item on both sides) is what the reindex after the move reports
|
|
2798
|
+
(`duplicate_ids`, and `crib project doctor`): a human picks the survivor,
|
|
2799
|
+
as for an interrupted note move."""
|
|
2800
|
+
return sorted(set(a_rels) & set(b_rels))
|
|
2801
|
+
|
|
2802
|
+
@staticmethod
|
|
2803
|
+
def _move_files(pairs: list[tuple[Path, Path]], what: str) -> int:
|
|
2804
|
+
"""Move each `(src, dst)` file, all or nothing: an OSError part-way (a
|
|
2805
|
+
read-only checkout, a full disk) moves back what already moved and
|
|
2806
|
+
refuses with the reason, so a facet's items are never split between
|
|
2807
|
+
two homes."""
|
|
2808
|
+
import shutil
|
|
2809
|
+
|
|
2810
|
+
if taken := [str(d) for _, d in pairs if d.exists()]:
|
|
2811
|
+
raise CribUserError(
|
|
2812
|
+
f"moving {what} would overwrite {len(taken)} existing file(s) "
|
|
2813
|
+
f"({', '.join(taken[:3])}{', ...' if len(taken) > 3 else ''}): "
|
|
2814
|
+
"nothing was moved. Move those aside and re-run")
|
|
2815
|
+
done: list[tuple[Path, Path]] = []
|
|
2816
|
+
current: tuple[Path, Path] | None = None
|
|
2817
|
+
try:
|
|
2818
|
+
for src, dst in pairs:
|
|
2819
|
+
current = (src, dst)
|
|
2820
|
+
dst.parent.mkdir(parents=True, exist_ok=True)
|
|
2821
|
+
shutil.move(str(src), str(dst))
|
|
2822
|
+
done.append((src, dst))
|
|
2823
|
+
current = None
|
|
2824
|
+
except OSError as e:
|
|
2825
|
+
# across filesystems a move is copy + unlink: a copy that failed
|
|
2826
|
+
# part-way leaves a partial file at the destination; the source is
|
|
2827
|
+
# still whole, so the partial copy goes
|
|
2828
|
+
if current is not None and current[0].exists() and current[1].exists():
|
|
2829
|
+
with contextlib.suppress(OSError):
|
|
2830
|
+
current[1].unlink()
|
|
2831
|
+
stuck: list[str] = []
|
|
2832
|
+
for src, dst in reversed(done):
|
|
2833
|
+
try:
|
|
2834
|
+
shutil.move(str(dst), str(src))
|
|
2835
|
+
except OSError:
|
|
2836
|
+
stuck.append(str(dst))
|
|
2837
|
+
if stuck:
|
|
2838
|
+
raise CribUserError(
|
|
2839
|
+
f"moving {what} failed at {e.filename or '?'} ({e.strerror or e}), "
|
|
2840
|
+
f"and {len(stuck)} file(s) that had moved could not be put back: "
|
|
2841
|
+
f"{', '.join(stuck[:5])}{', ...' if len(stuck) > 5 else ''} "
|
|
2842
|
+
"(they are whole, at the destination)") from e
|
|
2843
|
+
raise CribUserError(
|
|
2844
|
+
f"moving {what} failed at {e.filename or '?'} ({e.strerror or e}); "
|
|
2845
|
+
f"nothing was moved") from e
|
|
2846
|
+
return len(done)
|
|
2847
|
+
|
|
2458
2848
|
def _move_ring(self, ids: list[str], src: Path, dst: Path) -> int:
|
|
2459
2849
|
"""Move the named notes' ring dirs between rings, returning the count."""
|
|
2460
2850
|
moved = 0
|
|
@@ -2471,6 +2861,126 @@ class Crib:
|
|
|
2471
2861
|
s.rmdir()
|
|
2472
2862
|
return moved
|
|
2473
2863
|
|
|
2864
|
+
async def _adopt_mapped(self, proj: str, repo: Path | None = None) -> dict[str, Any]:
|
|
2865
|
+
"""Move each mapped facet's items still waiting under the data root into
|
|
2866
|
+
its mapping (the explicit move a pending facet asks for), with their
|
|
2867
|
+
version-ring entries. Refuses to merge into a mapping that already
|
|
2868
|
+
holds that facet's items."""
|
|
2869
|
+
pp = self.project_paths(proj)
|
|
2870
|
+
moved: dict[str, Any] = {}
|
|
2871
|
+
# Every refusal before any file moves: one facet's problem must not
|
|
2872
|
+
# leave another half-moved.
|
|
2873
|
+
plan: list[tuple[str, str, FacetLocation, Path]] = []
|
|
2874
|
+
for seg, loc in pp.mappings.items():
|
|
2875
|
+
store = self.pillars.get(seg)
|
|
2876
|
+
if loc.prefix is not None or store is None or store.pending_move(proj) is None:
|
|
2877
|
+
continue
|
|
2878
|
+
noun = store.spec.facet or "note"
|
|
2879
|
+
if loc.read_only:
|
|
2880
|
+
raise CribUserError(
|
|
2881
|
+
f"{proj}'s {noun} mapping {loc.token} is read-only, so the "
|
|
2882
|
+
f"{noun} items under crib's data dir ({pp.home_dir(seg)}) can't "
|
|
2883
|
+
"move there: move them into that repo yourself, or forget them "
|
|
2884
|
+
f"(`crib {noun} forget`) before mapping the facet")
|
|
2885
|
+
makeable = (not loc.available and repo is not None and repo.is_dir()
|
|
2886
|
+
and loc.root.resolve().is_relative_to(repo.resolve()))
|
|
2887
|
+
if not loc.available and not makeable:
|
|
2888
|
+
raise CribUserError(
|
|
2889
|
+
f"{proj}'s {noun} mapping {loc.token} isn't on this machine")
|
|
2890
|
+
src = pp.home_dir(seg)
|
|
2891
|
+
there = [str(f.relative_to(loc.root)) for f in loc.root.rglob("*") if f.is_file()]
|
|
2892
|
+
here = [str(f.relative_to(src)) for f in sorted(src.rglob("*.md"))]
|
|
2893
|
+
if stray := [r for r in here if not loc.owns(r)]:
|
|
2894
|
+
raise CribUserError(
|
|
2895
|
+
f"{len(stray)} of {proj}'s {noun} items under crib's data dir "
|
|
2896
|
+
f"don't match the mapping's glob `{loc.glob}` "
|
|
2897
|
+
f"({', '.join(stray[:5])}{', ...' if len(stray) > 5 else ''}): "
|
|
2898
|
+
"moved there, the facet couldn't see them. Rename them to match, "
|
|
2899
|
+
"or widen the glob, then re-run")
|
|
2900
|
+
if clash := self._merge_clashes(here, there):
|
|
2901
|
+
raise CribUserError(
|
|
2902
|
+
f"{loc.root} already holds {noun} items that clash with the ones "
|
|
2903
|
+
f"under crib's data dir ({', '.join(clash[:5])}"
|
|
2904
|
+
f"{', ...' if len(clash) > 5 else ''}): refusing to merge them. "
|
|
2905
|
+
"Rename or remove one side's, then re-run")
|
|
2906
|
+
plan.append((seg, noun, loc, src))
|
|
2907
|
+
for _seg, noun, loc, src in plan:
|
|
2908
|
+
loc.root.mkdir(parents=True, exist_ok=True) # a first adopt makes it
|
|
2909
|
+
ring_ids = self._note_ring_ids(proj, src)
|
|
2910
|
+
n = self._move_files(
|
|
2911
|
+
[(f, loc.root / f.relative_to(src)) for f in sorted(src.rglob("*.md"))],
|
|
2912
|
+
f"{proj}'s {noun} items into {loc.token}")
|
|
2913
|
+
v = self._move_ring(ring_ids, pp.versions_dir, loc.versions_dir)
|
|
2914
|
+
left = sorted(str(f.relative_to(src)) for f in src.rglob("*")
|
|
2915
|
+
if f.is_file() and f.suffix != ".md")
|
|
2916
|
+
if not (gi := loc.versions_dir / ".gitignore").exists():
|
|
2917
|
+
loc.versions_dir.mkdir(parents=True, exist_ok=True)
|
|
2918
|
+
gi.write_text("*\n") # the repo owns the files, crib their history
|
|
2919
|
+
with contextlib.suppress(OSError):
|
|
2920
|
+
src.rmdir()
|
|
2921
|
+
moved[noun] = {"to": loc.token, "notes_moved": n, "versions_moved": v,
|
|
2922
|
+
**({"left_behind": left} if left else {})}
|
|
2923
|
+
if left:
|
|
2924
|
+
print(f"[crib] adopt: {len(left)} non-markdown file(s) left in {src} "
|
|
2925
|
+
f"(not {noun} items): {', '.join(left[:5])}", file=sys.stderr)
|
|
2926
|
+
if moved:
|
|
2927
|
+
self._rewatch(proj) # a first adopt may have made the mapping's dir
|
|
2928
|
+
for noun in moved:
|
|
2929
|
+
res = await self.pillars[facets.by_noun(noun).store].reindex(proj)
|
|
2930
|
+
if res.get("duplicate_ids"): # one item on both sides of a merge
|
|
2931
|
+
moved[noun]["duplicate_ids"] = res["duplicate_ids"]
|
|
2932
|
+
return moved
|
|
2933
|
+
|
|
2934
|
+
def _release_mapped(self, proj: str) -> tuple[dict[str, Any], dict[str, Any]]:
|
|
2935
|
+
"""The inverse: move each mapped facet's own files (the ones its glob
|
|
2936
|
+
picks, nothing else in that dir) back under the data root, with their
|
|
2937
|
+
ring entries, and forget the mapping in the stub. Only what adopt moves
|
|
2938
|
+
in moves out: a READ-ONLY or `ids: derived` mapping's files are the
|
|
2939
|
+
repo's, crib just indexes them, so they stay where they are and the
|
|
2940
|
+
mapping stays recorded (returned as `kept`). Returns `(moved, kept)`."""
|
|
2941
|
+
from .filesync import scan
|
|
2942
|
+
|
|
2943
|
+
pp = self.project_paths(proj)
|
|
2944
|
+
moved: dict[str, Any] = {}
|
|
2945
|
+
kept: dict[str, Any] = {}
|
|
2946
|
+
plan: list[tuple[str, FacetLocation, Path, list[str]]] = []
|
|
2947
|
+
for seg, loc in pp.mappings.items():
|
|
2948
|
+
store = self.pillars.get(seg)
|
|
2949
|
+
if loc.prefix is not None or store is None:
|
|
2950
|
+
continue
|
|
2951
|
+
noun = store.spec.facet or "note"
|
|
2952
|
+
if loc.read_only or loc.ids != "stamp":
|
|
2953
|
+
kept[noun] = {"at": loc.token, "why": (
|
|
2954
|
+
"read-only" if loc.read_only else "ids derived from the repo's paths")
|
|
2955
|
+
+ ": its files are the repo's, crib only indexes them"}
|
|
2956
|
+
continue
|
|
2957
|
+
if not loc.available:
|
|
2958
|
+
continue
|
|
2959
|
+
home = pp.home_dir(seg)
|
|
2960
|
+
owned = [r for r in scan(loc.root, ".md", recursive=True) if loc.owns(r)]
|
|
2961
|
+
at_home = ([str(f.relative_to(home)) for f in sorted(home.rglob("*.md"))]
|
|
2962
|
+
if home.is_dir() else [])
|
|
2963
|
+
if clash := self._merge_clashes(owned, at_home):
|
|
2964
|
+
raise CribUserError(
|
|
2965
|
+
f"{home} already holds {noun} items that clash with the mapping's "
|
|
2966
|
+
f"({', '.join(clash[:5])}): refusing to merge them. Rename or "
|
|
2967
|
+
"remove one side's, then re-run")
|
|
2968
|
+
plan.append((noun, loc, home, owned))
|
|
2969
|
+
for noun, loc, home, owned in plan:
|
|
2970
|
+
ring_ids = self._note_ring_ids(proj, loc.root) if owned else []
|
|
2971
|
+
n = self._move_files([(loc.root / r, home / r) for r in owned],
|
|
2972
|
+
f"{proj}'s {noun} items out of {loc.token}")
|
|
2973
|
+
v = self._move_ring(ring_ids, loc.versions_dir, pp.versions_dir)
|
|
2974
|
+
moved[noun] = {"from": loc.token, "notes_moved": n, "versions_moved": v}
|
|
2975
|
+
if moved:
|
|
2976
|
+
pcfg = ProjectConfig.load(pp.config_file, proj)
|
|
2977
|
+
pcfg.mappings = {k: v for k, v in (pcfg.mappings or {}).items()
|
|
2978
|
+
if k not in moved} or None
|
|
2979
|
+
pcfg.save(pp.config_file)
|
|
2980
|
+
self.project_paths.invalidate(proj)
|
|
2981
|
+
self._rewatch(proj)
|
|
2982
|
+
return moved, kept
|
|
2983
|
+
|
|
2474
2984
|
_STORE_GITIGNORE = (
|
|
2475
2985
|
"# crib in-repo store — the notes ARE the repo's, the "
|
|
2476
2986
|
"version ring is not\n.versions/\n"
|
|
@@ -2502,6 +3012,38 @@ class Crib:
|
|
|
2502
3012
|
)
|
|
2503
3013
|
return hits
|
|
2504
3014
|
|
|
3015
|
+
def _check_store_target(self, proj: str, link: CribLink, store: Path) -> None:
|
|
3016
|
+
"""Refuse (before anything moves) a `store:` adopt can't carry out:
|
|
3017
|
+
already adopted elsewhere, a store path that is a file, or a pillar dir
|
|
3018
|
+
there that already holds notes."""
|
|
3019
|
+
from .watch import PILLAR_SEGMENTS
|
|
3020
|
+
|
|
3021
|
+
pp = self.project_paths(proj)
|
|
3022
|
+
if pp.in_repo:
|
|
3023
|
+
if pp.store_root == store:
|
|
3024
|
+
return # idempotent: already here
|
|
3025
|
+
raise CribUserError(
|
|
3026
|
+
f"{proj} is already adopted into {pp.store_root} — `crib project "
|
|
3027
|
+
f"release {proj}` first, then adopt here (a project's notes live "
|
|
3028
|
+
"in exactly one place)"
|
|
3029
|
+
)
|
|
3030
|
+
if store.exists() and not store.is_dir():
|
|
3031
|
+
# `.crib` is itself a FILE at the repo root, so `store: .crib/store`
|
|
3032
|
+
# (an inviting-looking spelling) can never be created — say that here
|
|
3033
|
+
# rather than surfacing a bare NotADirectoryError from mkdir.
|
|
3034
|
+
raise CribUserError(
|
|
3035
|
+
f"`store: {link.store}` is not a directory ({store} exists as a "
|
|
3036
|
+
"file) — point it at a directory path, e.g. `store: .crib-store`"
|
|
3037
|
+
)
|
|
3038
|
+
for seg in (s for s in PILLAR_SEGMENTS if s not in pp.mappings):
|
|
3039
|
+
dest = store / seg
|
|
3040
|
+
if any(dest.rglob("*.md")) if dest.is_dir() else False:
|
|
3041
|
+
raise CribUserError(
|
|
3042
|
+
f"{dest} already holds notes — refusing to merge two note "
|
|
3043
|
+
"trees. Move them aside (or pick a different `store:`) and "
|
|
3044
|
+
"re-run"
|
|
3045
|
+
)
|
|
3046
|
+
|
|
2505
3047
|
async def project_adopt(
|
|
2506
3048
|
self, project: str | None = None, cwd: Path | None = None
|
|
2507
3049
|
) -> dict[str, Any]:
|
|
@@ -2528,7 +3070,17 @@ class Crib:
|
|
|
2528
3070
|
f"the `.crib` at {link.root} names project {link.project!r}, not "
|
|
2529
3071
|
f"{proj!r} — adopt is about THIS repo's project"
|
|
2530
3072
|
)
|
|
3073
|
+
# The repo's facet mappings first (recorded in the stub), and every
|
|
3074
|
+
# mapped pillar's waiting items moved into its mapping.
|
|
3075
|
+
await self._sync_mappings(proj, link)
|
|
3076
|
+
# every refusal the store move can make, BEFORE a mapped facet moves:
|
|
3077
|
+
# a refused adopt changes nothing
|
|
3078
|
+
if (store := link.store_dir) is not None:
|
|
3079
|
+
self._check_store_target(proj, link, store)
|
|
3080
|
+
mapped = await self._adopt_mapped(proj, link.root)
|
|
2531
3081
|
store = link.store_dir
|
|
3082
|
+
if store is None and (mapped or self.project_paths(proj).mappings):
|
|
3083
|
+
return {"project": proj, "changed": bool(mapped), "mapped": mapped}
|
|
2532
3084
|
if store is None:
|
|
2533
3085
|
raise CribUserError(
|
|
2534
3086
|
f"{link.root / '.crib'} declares no `store:` — add e.g. "
|
|
@@ -2546,6 +3098,7 @@ class Crib:
|
|
|
2546
3098
|
"versions_moved": 0,
|
|
2547
3099
|
"store_root": pp.store_token,
|
|
2548
3100
|
"message": f"{proj} already lives in {store}",
|
|
3101
|
+
**({"mapped": mapped} if mapped else {}),
|
|
2549
3102
|
}
|
|
2550
3103
|
raise CribUserError(
|
|
2551
3104
|
f"{proj} is already adopted into {pp.store_root} — `crib project "
|
|
@@ -2562,7 +3115,9 @@ class Crib:
|
|
|
2562
3115
|
)
|
|
2563
3116
|
from .watch import PILLAR_SEGMENTS
|
|
2564
3117
|
|
|
2565
|
-
|
|
3118
|
+
# a mapped facet lives at its mapping: the store move leaves it alone
|
|
3119
|
+
segments = [s for s in PILLAR_SEGMENTS if s not in pp.mappings]
|
|
3120
|
+
for seg in segments:
|
|
2566
3121
|
dest = store / seg
|
|
2567
3122
|
if any(dest.rglob("*.md")) if dest.is_dir() else False:
|
|
2568
3123
|
raise CribUserError(
|
|
@@ -2572,17 +3127,19 @@ class Crib:
|
|
|
2572
3127
|
)
|
|
2573
3128
|
ring_ids = [
|
|
2574
3129
|
nid
|
|
2575
|
-
for seg in
|
|
2576
|
-
if (src := pp.
|
|
3130
|
+
for seg in segments
|
|
3131
|
+
if (src := pp.home_dir(seg)).is_dir()
|
|
2577
3132
|
for nid in self._note_ring_ids(proj, src)
|
|
2578
3133
|
]
|
|
2579
3134
|
store.mkdir(parents=True, exist_ok=True)
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
3135
|
+
# every unmapped pillar sibling travels together, all or nothing
|
|
3136
|
+
notes_moved = self._move_files(
|
|
3137
|
+
[pair for seg in segments
|
|
3138
|
+
for pair in self._tree_pairs(pp.home_dir(seg), store / seg)],
|
|
3139
|
+
f"{proj}'s items into {store}")
|
|
3140
|
+
for seg in segments:
|
|
2584
3141
|
with contextlib.suppress(OSError):
|
|
2585
|
-
|
|
3142
|
+
pp.home_dir(seg).rmdir() # only if the move emptied it
|
|
2586
3143
|
versions_moved = self._move_ring(
|
|
2587
3144
|
ring_ids, self.paths.versions_dir, store / ".versions"
|
|
2588
3145
|
)
|
|
@@ -2597,6 +3154,7 @@ class Crib:
|
|
|
2597
3154
|
pcfg.store_root = portable_path(store, self.config.locations)
|
|
2598
3155
|
pcfg.save(pp.config_file)
|
|
2599
3156
|
self.project_paths.invalidate(proj)
|
|
3157
|
+
self._rewatch(proj) # live now, not at the next daemon start
|
|
2600
3158
|
rec = await self.reindex(project=proj)
|
|
2601
3159
|
return {
|
|
2602
3160
|
"project": proj,
|
|
@@ -2606,6 +3164,7 @@ class Crib:
|
|
|
2606
3164
|
"notes_moved": notes_moved,
|
|
2607
3165
|
"versions_moved": versions_moved,
|
|
2608
3166
|
"reconciled": rec,
|
|
3167
|
+
**({"mapped": mapped} if mapped else {}),
|
|
2609
3168
|
}
|
|
2610
3169
|
|
|
2611
3170
|
async def project_release(
|
|
@@ -2616,13 +3175,22 @@ class Crib:
|
|
|
2616
3175
|
when the repo is going away, or when the notes should stop travelling with
|
|
2617
3176
|
it. Idempotent: releasing an already-global project is a no-op."""
|
|
2618
3177
|
proj = self.resolve_project(project, cwd)
|
|
3178
|
+
mapped, kept = self._release_mapped(proj)
|
|
3179
|
+
extra = {**({"mapped": mapped} if mapped else {}),
|
|
3180
|
+
**({"kept": kept} if kept else {})}
|
|
2619
3181
|
pp = self.project_paths(proj)
|
|
3182
|
+
if not pp.in_repo and mapped:
|
|
3183
|
+
await self.reindex(project=proj)
|
|
3184
|
+
return {"project": proj, "changed": True, **extra,
|
|
3185
|
+
"message": "mapped facets moved back; remove their `facets:` "
|
|
3186
|
+
"entries from the repo's .crib, or the next index maps them again"}
|
|
2620
3187
|
if not pp.in_repo:
|
|
2621
3188
|
return {
|
|
2622
3189
|
"project": proj,
|
|
2623
3190
|
"changed": False,
|
|
2624
3191
|
"notes_moved": 0,
|
|
2625
3192
|
"versions_moved": 0,
|
|
3193
|
+
**extra,
|
|
2626
3194
|
"message": f"{proj} already lives in the global store",
|
|
2627
3195
|
}
|
|
2628
3196
|
pp.require() # can't move notes that aren't on this machine
|
|
@@ -2641,12 +3209,13 @@ class Crib:
|
|
|
2641
3209
|
ring_ids = [
|
|
2642
3210
|
nid
|
|
2643
3211
|
for seg in PILLAR_SEGMENTS
|
|
2644
|
-
if (src := pp.
|
|
3212
|
+
if (src := pp.home_dir(seg)).is_dir()
|
|
2645
3213
|
for nid in self._note_ring_ids(proj, src)
|
|
2646
3214
|
]
|
|
2647
|
-
notes_moved =
|
|
2648
|
-
|
|
2649
|
-
|
|
3215
|
+
notes_moved = self._move_files(
|
|
3216
|
+
[pair for seg in PILLAR_SEGMENTS
|
|
3217
|
+
for pair in self._tree_pairs(pp.home_dir(seg), gdir / seg)],
|
|
3218
|
+
f"{proj}'s items back to {gdir}")
|
|
2650
3219
|
versions_moved = self._move_ring(
|
|
2651
3220
|
ring_ids, pp.versions_dir, self.paths.versions_dir
|
|
2652
3221
|
)
|
|
@@ -2654,7 +3223,7 @@ class Crib:
|
|
|
2654
3223
|
if gi.is_file() and gi.read_text() == self._STORE_GITIGNORE:
|
|
2655
3224
|
gi.unlink() # ours, and now describing nothing
|
|
2656
3225
|
for d in (
|
|
2657
|
-
*(pp.
|
|
3226
|
+
*(pp.home_dir(seg) for seg in PILLAR_SEGMENTS),
|
|
2658
3227
|
pp.versions_dir,
|
|
2659
3228
|
store,
|
|
2660
3229
|
):
|
|
@@ -2664,6 +3233,7 @@ class Crib:
|
|
|
2664
3233
|
pcfg.store_root = None
|
|
2665
3234
|
pcfg.save(pp.config_file)
|
|
2666
3235
|
self.project_paths.invalidate(proj)
|
|
3236
|
+
self._rewatch(proj)
|
|
2667
3237
|
rec = await self.reindex(project=proj)
|
|
2668
3238
|
return {
|
|
2669
3239
|
"project": proj,
|
|
@@ -2672,6 +3242,7 @@ class Crib:
|
|
|
2672
3242
|
"notes_moved": notes_moved,
|
|
2673
3243
|
"versions_moved": versions_moved,
|
|
2674
3244
|
"reconciled": rec,
|
|
3245
|
+
**extra,
|
|
2675
3246
|
}
|
|
2676
3247
|
|
|
2677
3248
|
# ── project lifecycle: create / delete / rename (docs/surface.md) ─────────
|
|
@@ -4032,7 +4603,9 @@ class Crib:
|
|
|
4032
4603
|
}
|
|
4033
4604
|
|
|
4034
4605
|
async def learning_migrate(
|
|
4035
|
-
self, project: str | None = None, cwd: Path | None = None, apply: bool = False
|
|
4606
|
+
self, project: str | None = None, cwd: Path | None = None, apply: bool = False,
|
|
4607
|
+
*,
|
|
4608
|
+
facet: str = "learning",
|
|
4036
4609
|
) -> dict[str, Any]:
|
|
4037
4610
|
"""Rebind a project's learning notes to the current symbol identity.
|
|
4038
4611
|
|
|
@@ -4044,7 +4617,7 @@ class Crib:
|
|
|
4044
4617
|
Per record, no ordering constraint against the entry conversion, re-running
|
|
4045
4618
|
is the resume. DRY RUN unless `apply`."""
|
|
4046
4619
|
proj = self.resolve_project(project, cwd)
|
|
4047
|
-
return await self.
|
|
4620
|
+
return await self._anchored_facet(facet).convert_notes(proj, apply=apply)
|
|
4048
4621
|
|
|
4049
4622
|
async def code_convert(
|
|
4050
4623
|
self, project: str | None = None, cwd: Path | None = None, apply: bool = False
|
|
@@ -4547,15 +5120,19 @@ class Crib:
|
|
|
4547
5120
|
lang: str = "",
|
|
4548
5121
|
project: str | None = None,
|
|
4549
5122
|
cwd: Path | None = None,
|
|
5123
|
+
*,
|
|
5124
|
+
facet: str = "learning",
|
|
5125
|
+
fields: dict[str, Any] | None = None,
|
|
4550
5126
|
) -> dict[str, Any]:
|
|
4551
5127
|
"""Attach a durable learning to a code symbol (append a dated entry)."""
|
|
4552
|
-
return await self.
|
|
5128
|
+
return await self._anchored_facet(facet).append(
|
|
4553
5129
|
self.resolve_project(project, cwd),
|
|
4554
5130
|
symbol,
|
|
4555
5131
|
text,
|
|
4556
5132
|
path=path,
|
|
4557
5133
|
scope=scope,
|
|
4558
5134
|
lang=lang,
|
|
5135
|
+
fields=setting(facets.by_noun(facet), fields),
|
|
4559
5136
|
)
|
|
4560
5137
|
|
|
4561
5138
|
async def learning_edit(
|
|
@@ -4567,15 +5144,19 @@ class Crib:
|
|
|
4567
5144
|
lang: str = "",
|
|
4568
5145
|
project: str | None = None,
|
|
4569
5146
|
cwd: Path | None = None,
|
|
5147
|
+
*,
|
|
5148
|
+
facet: str = "learning",
|
|
5149
|
+
fields: dict[str, Any] | None = None,
|
|
4570
5150
|
) -> dict[str, Any]:
|
|
4571
5151
|
"""Rewrite a symbol's learning body wholesale."""
|
|
4572
|
-
return await self.
|
|
5152
|
+
return await self._anchored_facet(facet).edit(
|
|
4573
5153
|
self.resolve_project(project, cwd),
|
|
4574
5154
|
symbol,
|
|
4575
5155
|
new_content,
|
|
4576
5156
|
path=path,
|
|
4577
5157
|
scope=scope,
|
|
4578
5158
|
lang=lang,
|
|
5159
|
+
fields=setting(facets.by_noun(facet), fields),
|
|
4579
5160
|
)
|
|
4580
5161
|
|
|
4581
5162
|
async def learning_forget(
|
|
@@ -4586,9 +5167,11 @@ class Crib:
|
|
|
4586
5167
|
lang: str = "",
|
|
4587
5168
|
project: str | None = None,
|
|
4588
5169
|
cwd: Path | None = None,
|
|
5170
|
+
*,
|
|
5171
|
+
facet: str = "learning",
|
|
4589
5172
|
) -> dict[str, Any]:
|
|
4590
5173
|
"""Remove a symbol's learning (recoverable; works on orphans)."""
|
|
4591
|
-
return await self.
|
|
5174
|
+
return await self._anchored_facet(facet).forget(
|
|
4592
5175
|
self.resolve_project(project, cwd),
|
|
4593
5176
|
symbol,
|
|
4594
5177
|
path=path,
|
|
@@ -4604,9 +5187,11 @@ class Crib:
|
|
|
4604
5187
|
lang: str = "",
|
|
4605
5188
|
project: str | None = None,
|
|
4606
5189
|
cwd: Path | None = None,
|
|
5190
|
+
*,
|
|
5191
|
+
facet: str = "learning",
|
|
4607
5192
|
) -> dict[str, Any]:
|
|
4608
5193
|
"""Clear a learning's stale flag without rewriting it."""
|
|
4609
|
-
return await self.
|
|
5194
|
+
return await self._anchored_facet(facet).reaffirm(
|
|
4610
5195
|
self.resolve_project(project, cwd),
|
|
4611
5196
|
symbol,
|
|
4612
5197
|
path=path,
|
|
@@ -4624,8 +5209,7 @@ class Crib:
|
|
|
4624
5209
|
return diagnose(self, self.resolve_project(project, cwd))
|
|
4625
5210
|
|
|
4626
5211
|
# The pillars one cross-kind lookup searches, as (kind, store) pairs.
|
|
4627
|
-
_LOOKUP_PILLARS = ((
|
|
4628
|
-
("learning", "learnings"))
|
|
5212
|
+
_LOOKUP_PILLARS = tuple((s.noun, s.store) for s in facets.FACETS)
|
|
4629
5213
|
|
|
4630
5214
|
def lookup_all(
|
|
4631
5215
|
self,
|
|
@@ -4671,7 +5255,7 @@ class Crib:
|
|
|
4671
5255
|
out: list[dict[str, Any]] = []
|
|
4672
5256
|
for h in self._hits_from(proj, pool, len(pool), "section", 0.0):
|
|
4673
5257
|
row = {"kind": kind_of_store.get(h.store, h.store), **dataclasses.asdict(h)}
|
|
4674
|
-
if row["kind"] in
|
|
5258
|
+
if row["kind"] in self.designs._stores:
|
|
4675
5259
|
graph = graph or self.designs._load_graph(proj)
|
|
4676
5260
|
node = next((n for n in graph.of_kind(row["kind"])
|
|
4677
5261
|
if n.relpath == h.relpath), None)
|
|
@@ -4697,9 +5281,11 @@ class Crib:
|
|
|
4697
5281
|
project: str | None = None,
|
|
4698
5282
|
cwd: Path | None = None,
|
|
4699
5283
|
orphans_only: bool = False,
|
|
5284
|
+
*,
|
|
5285
|
+
facet: str = "learning",
|
|
4700
5286
|
) -> list[dict[str, Any]]:
|
|
4701
5287
|
"""Health report for attached learnings (ok/moved/orphan)."""
|
|
4702
|
-
return self.
|
|
5288
|
+
return self._anchored_facet(facet).report(self.resolve_project(project, cwd), orphans_only)
|
|
4703
5289
|
|
|
4704
5290
|
async def learning_rehome(
|
|
4705
5291
|
self,
|
|
@@ -4707,9 +5293,11 @@ class Crib:
|
|
|
4707
5293
|
new_fqn: str | None = None,
|
|
4708
5294
|
project: str | None = None,
|
|
4709
5295
|
cwd: Path | None = None,
|
|
5296
|
+
*,
|
|
5297
|
+
facet: str = "learning",
|
|
4710
5298
|
) -> dict[str, Any]:
|
|
4711
5299
|
"""Re-point an orphaned learning (no target = ranked suggestions)."""
|
|
4712
|
-
return await self.
|
|
5300
|
+
return await self._anchored_facet(facet).rehome(
|
|
4713
5301
|
self.resolve_project(project, cwd), old_fqn, new_fqn
|
|
4714
5302
|
)
|
|
4715
5303
|
|
|
@@ -4721,9 +5309,11 @@ class Crib:
|
|
|
4721
5309
|
lang: str = "",
|
|
4722
5310
|
project: str | None = None,
|
|
4723
5311
|
cwd: Path | None = None,
|
|
5312
|
+
*,
|
|
5313
|
+
facet: str = "learning",
|
|
4724
5314
|
) -> dict[str, Any]:
|
|
4725
5315
|
"""Read a symbol's learning note (frontmatter + body)."""
|
|
4726
|
-
return self.
|
|
5316
|
+
return self._anchored_facet(facet).read(
|
|
4727
5317
|
self.resolve_project(project, cwd),
|
|
4728
5318
|
symbol,
|
|
4729
5319
|
path=path,
|
|
@@ -4747,8 +5337,7 @@ class Crib:
|
|
|
4747
5337
|
cwd: Path | None = None,
|
|
4748
5338
|
follows: list[str] | None = None,
|
|
4749
5339
|
rests_on: list[str] | None = None,
|
|
4750
|
-
informed_by: list[str] | None = None,
|
|
4751
|
-
) -> dict[str, Any]:
|
|
5340
|
+
informed_by: list[str] | None = None, *, facet: str = "design") -> dict[str, Any]:
|
|
4752
5341
|
"""Record a design decision (deps validated + `checked` seeded, `sources`
|
|
4753
5342
|
captured at their current section hashes), with the same near-duplicate
|
|
4754
5343
|
probe `note_store` runs.
|
|
@@ -4760,19 +5349,19 @@ class Crib:
|
|
|
4760
5349
|
out = await self.designs.design_add(
|
|
4761
5350
|
proj, title, content, deps, sources, proposed,
|
|
4762
5351
|
_kinded(follows, rests_on, informed_by),
|
|
5352
|
+
facet=facet,
|
|
4763
5353
|
)
|
|
4764
|
-
similar = await asyncio.to_thread(self._similar, proj, out["relpath"],
|
|
5354
|
+
similar = await asyncio.to_thread(self._similar, proj, out["relpath"], facets.by_noun(facet).store)
|
|
4765
5355
|
return {**out, "similar": similar}
|
|
4766
5356
|
|
|
4767
5357
|
def design_read(
|
|
4768
|
-
self, ref: str, project: str | None = None, cwd: Path | None = None
|
|
4769
|
-
) -> dict[str, Any]:
|
|
5358
|
+
self, ref: str, project: str | None = None, cwd: Path | None = None, *, facet: str = "design") -> dict[str, Any]:
|
|
4770
5359
|
"""A decision's dossier: body, status, annotated edges, taint + chains,
|
|
4771
5360
|
and `suggested_deps`: live decisions it is close to but doesn't depend
|
|
4772
5361
|
on (see `_similar`)."""
|
|
4773
5362
|
proj = self.resolve_project(project, cwd)
|
|
4774
|
-
out = self.designs.design_read(proj, ref)
|
|
4775
|
-
return {**out, "suggested_deps": self._suggested_deps(proj, out,
|
|
5363
|
+
out = self.designs.design_read(proj, ref, facet=facet)
|
|
5364
|
+
return {**out, "suggested_deps": self._suggested_deps(proj, out, facets.by_noun(facet).store)}
|
|
4776
5365
|
|
|
4777
5366
|
async def design_edit(
|
|
4778
5367
|
self,
|
|
@@ -4780,12 +5369,11 @@ class Crib:
|
|
|
4780
5369
|
new_content: str,
|
|
4781
5370
|
project: str | None = None,
|
|
4782
5371
|
sources: list[Any] | None = None,
|
|
4783
|
-
cwd: Path | None = None,
|
|
4784
|
-
) -> dict[str, Any]:
|
|
5372
|
+
cwd: Path | None = None, *, facet: str = "design") -> dict[str, Any]:
|
|
4785
5373
|
"""Rewrite a decision through the facet; result names what it tainted.
|
|
4786
5374
|
`sources`, when given, replaces its citations."""
|
|
4787
5375
|
return await self.designs.design_edit(
|
|
4788
|
-
self.resolve_project(project, cwd), ref, new_content, sources
|
|
5376
|
+
self.resolve_project(project, cwd), ref, new_content, sources, facet=facet
|
|
4789
5377
|
)
|
|
4790
5378
|
|
|
4791
5379
|
async def design_append(
|
|
@@ -4794,33 +5382,29 @@ class Crib:
|
|
|
4794
5382
|
content: str,
|
|
4795
5383
|
project: str | None = None,
|
|
4796
5384
|
cwd: Path | None = None,
|
|
4797
|
-
sources: list[Any] | None = None,
|
|
4798
|
-
) -> dict[str, Any]:
|
|
5385
|
+
sources: list[Any] | None = None, *, facet: str = "design") -> dict[str, Any]:
|
|
4799
5386
|
"""Extend a decision through the facet; result names what it tainted.
|
|
4800
5387
|
`sources` ADDS citations (post-hoc doc wiring), never replaces."""
|
|
4801
5388
|
return await self.designs.design_append(
|
|
4802
|
-
self.resolve_project(project, cwd), ref, content, sources
|
|
5389
|
+
self.resolve_project(project, cwd), ref, content, sources, facet=facet
|
|
4803
5390
|
)
|
|
4804
5391
|
|
|
4805
5392
|
def design_list(
|
|
4806
|
-
self, tainted: bool = False, project: str | None = None, cwd: Path | None = None
|
|
4807
|
-
) -> dict[str, Any]:
|
|
5393
|
+
self, tainted: bool = False, project: str | None = None, cwd: Path | None = None, *, facet: str = "design") -> dict[str, Any]:
|
|
4808
5394
|
"""Every decision as a flat table (`tainted` filters to the stale ones)."""
|
|
4809
|
-
return self.designs.design_list(self.resolve_project(project, cwd), tainted)
|
|
5395
|
+
return self.designs.design_list(self.resolve_project(project, cwd), tainted, facet=facet)
|
|
4810
5396
|
|
|
4811
5397
|
def design_export(
|
|
4812
|
-
self, project: str | None = None, cwd: Path | None = None
|
|
4813
|
-
) -> dict[str, Any]:
|
|
5398
|
+
self, project: str | None = None, cwd: Path | None = None, *, facet: str = "design") -> dict[str, Any]:
|
|
4814
5399
|
"""The whole decision graph as ONE consolidated markdown doc
|
|
4815
5400
|
(dep-topological, ties by rank/title/id — deterministic across runs)."""
|
|
4816
|
-
return self.designs.export_facet(self.resolve_project(project, cwd),
|
|
5401
|
+
return self.designs.export_facet(self.resolve_project(project, cwd), facet)
|
|
4817
5402
|
|
|
4818
5403
|
def plan_export(
|
|
4819
|
-
self, project: str | None = None, cwd: Path | None = None
|
|
4820
|
-
) -> dict[str, Any]:
|
|
5404
|
+
self, project: str | None = None, cwd: Path | None = None, *, facet: str = "plan") -> dict[str, Any]:
|
|
4821
5405
|
"""The whole plan as ONE consolidated markdown doc (same ordering
|
|
4822
5406
|
contract as the design export)."""
|
|
4823
|
-
return self.designs.export_facet(self.resolve_project(project, cwd),
|
|
5407
|
+
return self.designs.export_facet(self.resolve_project(project, cwd), facet)
|
|
4824
5408
|
|
|
4825
5409
|
def design_lookup(
|
|
4826
5410
|
self,
|
|
@@ -4828,8 +5412,7 @@ class Crib:
|
|
|
4828
5412
|
project: str | None = None,
|
|
4829
5413
|
k: int = 8,
|
|
4830
5414
|
cwd: Path | None = None,
|
|
4831
|
-
hints: list[str] | None = None,
|
|
4832
|
-
) -> list[dict[str, Any]]:
|
|
5415
|
+
hints: list[str] | None = None, *, facet: str = "design") -> list[dict[str, Any]]:
|
|
4833
5416
|
"""Retrieval scoped to the DESIGN facet, each hit annotated with the facet
|
|
4834
5417
|
state that decides whether to trust it (`status`, `tainted`, edge counts).
|
|
4835
5418
|
|
|
@@ -4840,10 +5423,10 @@ class Crib:
|
|
|
4840
5423
|
[
|
|
4841
5424
|
vars(h)
|
|
4842
5425
|
for h in self.lookup(
|
|
4843
|
-
query, project, k, cwd=cwd, store=
|
|
5426
|
+
query, project, k, cwd=cwd, store=facets.by_noun(facet).store, hints=hints
|
|
4844
5427
|
)
|
|
4845
5428
|
],
|
|
4846
|
-
kind=
|
|
5429
|
+
kind=facet,
|
|
4847
5430
|
)
|
|
4848
5431
|
|
|
4849
5432
|
def plan_lookup(
|
|
@@ -4852,8 +5435,7 @@ class Crib:
|
|
|
4852
5435
|
project: str | None = None,
|
|
4853
5436
|
k: int = 8,
|
|
4854
5437
|
cwd: Path | None = None,
|
|
4855
|
-
hints: list[str] | None = None,
|
|
4856
|
-
) -> list[dict[str, Any]]:
|
|
5438
|
+
hints: list[str] | None = None, *, facet: str = "plan") -> list[dict[str, Any]]:
|
|
4857
5439
|
"""Retrieval scoped to the PLAN facet, hits annotated as `design_lookup`
|
|
4858
5440
|
annotates its own."""
|
|
4859
5441
|
return self.designs.annotate_hits(
|
|
@@ -4861,10 +5443,10 @@ class Crib:
|
|
|
4861
5443
|
[
|
|
4862
5444
|
vars(h)
|
|
4863
5445
|
for h in self.lookup(
|
|
4864
|
-
query, project, k, cwd=cwd, store=
|
|
5446
|
+
query, project, k, cwd=cwd, store=facets.by_noun(facet).store, hints=hints
|
|
4865
5447
|
)
|
|
4866
5448
|
],
|
|
4867
|
-
kind=
|
|
5449
|
+
kind=facet,
|
|
4868
5450
|
)
|
|
4869
5451
|
|
|
4870
5452
|
async def design_dep_add(
|
|
@@ -4873,11 +5455,10 @@ class Crib:
|
|
|
4873
5455
|
dep_ref: str,
|
|
4874
5456
|
project: str | None = None,
|
|
4875
5457
|
cwd: Path | None = None,
|
|
4876
|
-
kind: str | None = None,
|
|
4877
|
-
) -> dict[str, Any]:
|
|
5458
|
+
kind: str | None = None, *, facet: str = "design") -> dict[str, Any]:
|
|
4878
5459
|
"""Declare that a decision builds on another (cycle-checked)."""
|
|
4879
5460
|
return await self.designs.design_dep_add(
|
|
4880
|
-
self.resolve_project(project, cwd), ref, dep_ref, kind
|
|
5461
|
+
self.resolve_project(project, cwd), ref, dep_ref, kind, facet=facet
|
|
4881
5462
|
)
|
|
4882
5463
|
|
|
4883
5464
|
async def design_dep_remove(
|
|
@@ -4885,11 +5466,10 @@ class Crib:
|
|
|
4885
5466
|
ref: str,
|
|
4886
5467
|
dep_ref: str,
|
|
4887
5468
|
project: str | None = None,
|
|
4888
|
-
cwd: Path | None = None,
|
|
4889
|
-
) -> dict[str, Any]:
|
|
5469
|
+
cwd: Path | None = None, *, facet: str = "design") -> dict[str, Any]:
|
|
4890
5470
|
"""Drop a dependency edge between two decisions."""
|
|
4891
5471
|
return await self.designs.design_dep_remove(
|
|
4892
|
-
self.resolve_project(project, cwd), ref, dep_ref
|
|
5472
|
+
self.resolve_project(project, cwd), ref, dep_ref, facet=facet
|
|
4893
5473
|
)
|
|
4894
5474
|
|
|
4895
5475
|
async def design_forget(
|
|
@@ -4897,64 +5477,64 @@ class Crib:
|
|
|
4897
5477
|
ref: str,
|
|
4898
5478
|
force: bool = False,
|
|
4899
5479
|
project: str | None = None,
|
|
4900
|
-
cwd: Path | None = None,
|
|
4901
|
-
) -> dict[str, Any]:
|
|
5480
|
+
cwd: Path | None = None, *, facet: str = "design") -> dict[str, Any]:
|
|
4902
5481
|
"""Delete a decision; blocks on dependents unless forced."""
|
|
4903
5482
|
return await self.designs.design_forget(
|
|
4904
|
-
self.resolve_project(project, cwd), ref, force
|
|
5483
|
+
self.resolve_project(project, cwd), ref, force, facet=facet
|
|
4905
5484
|
)
|
|
4906
5485
|
|
|
4907
5486
|
def design_check(
|
|
4908
5487
|
self,
|
|
4909
5488
|
ref: str | None = None,
|
|
4910
5489
|
project: str | None = None,
|
|
4911
|
-
cwd: Path | None = None,
|
|
4912
|
-
) -> dict[str, Any]:
|
|
5490
|
+
cwd: Path | None = None, *, facet: str = "design") -> dict[str, Any]:
|
|
4913
5491
|
"""Which decisions are stale with respect to what they build on."""
|
|
4914
|
-
return self.designs.design_check(self.resolve_project(project, cwd), ref)
|
|
5492
|
+
return self.designs.design_check(self.resolve_project(project, cwd), ref, facet=facet)
|
|
4915
5493
|
|
|
4916
5494
|
async def design_reaffirm(
|
|
4917
|
-
self, ref: str, project: str | None = None, cwd: Path | None = None
|
|
4918
|
-
) -> dict[str, Any]:
|
|
5495
|
+
self, ref: str, project: str | None = None, cwd: Path | None = None, *, facet: str = "design") -> dict[str, Any]:
|
|
4919
5496
|
"""Re-record a decision's dep hashes after re-reading it (the cheap,
|
|
4920
5497
|
normal outcome of a taint — not error recovery)."""
|
|
4921
5498
|
return await self.designs.design_reaffirm(
|
|
4922
|
-
self.resolve_project(project, cwd), ref
|
|
5499
|
+
self.resolve_project(project, cwd), ref, facet=facet
|
|
4923
5500
|
)
|
|
4924
5501
|
|
|
4925
5502
|
async def plan_reaffirm(
|
|
4926
|
-
self, ref: str, project: str | None = None, cwd: Path | None = None
|
|
4927
|
-
) -> dict[str, Any]:
|
|
5503
|
+
self, ref: str, project: str | None = None, cwd: Path | None = None, *, facet: str = "plan") -> dict[str, Any]:
|
|
4928
5504
|
"""Re-record a plan item's dep hashes after re-reading what moved — the
|
|
4929
5505
|
plan-side twin of design_reaffirm (clears a benign taint without the
|
|
4930
5506
|
dep_remove/dep_add dance, and without pretending the work moved)."""
|
|
4931
|
-
return await self.designs.plan_reaffirm(self.resolve_project(project, cwd), ref)
|
|
5507
|
+
return await self.designs.plan_reaffirm(self.resolve_project(project, cwd), ref, facet=facet)
|
|
5508
|
+
|
|
5509
|
+
async def graph_transition(
|
|
5510
|
+
self, ref: str, verb: str, project: str | None = None, cwd: Path | None = None,
|
|
5511
|
+
*, facet: str) -> dict[str, Any]:
|
|
5512
|
+
"""A declared graph facet's named transition (Designs.graph_transition)."""
|
|
5513
|
+
return await self.designs.graph_transition(
|
|
5514
|
+
self.resolve_project(project, cwd), ref, verb, facet=facet)
|
|
4932
5515
|
|
|
4933
5516
|
async def design_promote(
|
|
4934
|
-
self, ref: str, project: str | None = None, cwd: Path | None = None
|
|
4935
|
-
) -> dict[str, Any]:
|
|
5517
|
+
self, ref: str, project: str | None = None, cwd: Path | None = None, *, facet: str = "design", to: str | None = None) -> dict[str, Any]:
|
|
4936
5518
|
"""Promote an extracted decision: proposed → active, hashes seeded fresh."""
|
|
4937
5519
|
return await self.designs.design_promote(
|
|
4938
|
-
self.resolve_project(project, cwd), ref
|
|
5520
|
+
self.resolve_project(project, cwd), ref, facet=facet, to=to
|
|
4939
5521
|
)
|
|
4940
5522
|
|
|
4941
5523
|
def design_import(
|
|
4942
|
-
self, relpath: str, project: str | None = None, cwd: Path | None = None
|
|
4943
|
-
) -> dict[str, Any]:
|
|
5524
|
+
self, relpath: str, project: str | None = None, cwd: Path | None = None, *, facet: str = "design") -> dict[str, Any]:
|
|
4944
5525
|
"""A doc's sections + hashes + existing citations + the extraction
|
|
4945
5526
|
procedure — the read that precedes an LLM-driven design import. Each
|
|
4946
5527
|
section names the existing decisions `closest` to it (Stage E7)."""
|
|
4947
5528
|
proj = self.resolve_project(project, cwd)
|
|
4948
|
-
return self._import_matches(proj, self.designs.design_import(proj, relpath),
|
|
4949
|
-
|
|
5529
|
+
return self._import_matches(proj, self.designs.design_import(proj, relpath, facet=facet),
|
|
5530
|
+
facet)
|
|
4950
5531
|
|
|
4951
5532
|
def plan_import(
|
|
4952
|
-
self, relpath: str, project: str | None = None, cwd: Path | None = None
|
|
4953
|
-
) -> dict[str, Any]:
|
|
5533
|
+
self, relpath: str, project: str | None = None, cwd: Path | None = None, *, facet: str = "plan") -> dict[str, Any]:
|
|
4954
5534
|
"""The same for the plan facet (actionable work rather than decisions)."""
|
|
4955
5535
|
proj = self.resolve_project(project, cwd)
|
|
4956
|
-
return self._import_matches(proj, self.designs.plan_import(proj, relpath),
|
|
4957
|
-
|
|
5536
|
+
return self._import_matches(proj, self.designs.plan_import(proj, relpath, facet=facet),
|
|
5537
|
+
facet)
|
|
4958
5538
|
|
|
4959
5539
|
def _import_matches(self, proj: str, out: dict[str, Any],
|
|
4960
5540
|
kind: str) -> dict[str, Any]:
|
|
@@ -4990,7 +5570,7 @@ class Crib:
|
|
|
4990
5570
|
[text_by_source[s["source"]] for s in rows]),
|
|
4991
5571
|
dtype=np.float32)
|
|
4992
5572
|
S = Q @ M.T
|
|
4993
|
-
noun =
|
|
5573
|
+
noun = kind
|
|
4994
5574
|
for row, sims in zip(rows, S):
|
|
4995
5575
|
best = [j for j in np.argsort(-sims)[:3] if sims[j] >= self.SIMILAR_RELATED]
|
|
4996
5576
|
row["closest"] = [{
|
|
@@ -5010,30 +5590,27 @@ class Crib:
|
|
|
5010
5590
|
direction: str = "deps",
|
|
5011
5591
|
depth: int = 6,
|
|
5012
5592
|
project: str | None = None,
|
|
5013
|
-
cwd: Path | None = None,
|
|
5014
|
-
) -> dict[str, Any]:
|
|
5593
|
+
cwd: Path | None = None, *, facet: str = "design") -> dict[str, Any]:
|
|
5015
5594
|
"""The dependency tree around a decision, taint-flagged."""
|
|
5016
5595
|
return self.designs.design_tree(
|
|
5017
|
-
self.resolve_project(project, cwd), ref, direction, depth
|
|
5596
|
+
self.resolve_project(project, cwd), ref, direction, depth, facet=facet
|
|
5018
5597
|
)
|
|
5019
5598
|
|
|
5020
5599
|
def design_graph(
|
|
5021
|
-
self, project: str | None = None, cwd: Path | None = None, sources: bool = False
|
|
5022
|
-
) -> dict[str, Any]:
|
|
5600
|
+
self, project: str | None = None, cwd: Path | None = None, sources: bool = False, *, facet: str = "design") -> dict[str, Any]:
|
|
5023
5601
|
"""The decision map as {nodes, edges} — the symbol graph's consumer
|
|
5024
5602
|
contract, for decisions. `tainted` is this graph's ※."""
|
|
5025
5603
|
return self.designs.facet_graph(
|
|
5026
|
-
self.resolve_project(project, cwd),
|
|
5604
|
+
self.resolve_project(project, cwd), facet, sources
|
|
5027
5605
|
)
|
|
5028
5606
|
|
|
5029
5607
|
def plan_graph(
|
|
5030
|
-
self, project: str | None = None, cwd: Path | None = None, sources: bool = False
|
|
5031
|
-
) -> dict[str, Any]:
|
|
5608
|
+
self, project: str | None = None, cwd: Path | None = None, sources: bool = False, *, facet: str = "plan") -> dict[str, Any]:
|
|
5032
5609
|
"""The plan as {nodes, edges}, INCLUDING the design nodes items rest on —
|
|
5033
5610
|
those edges gate, so a plan graph without them would misdraw the plan as
|
|
5034
5611
|
self-contained."""
|
|
5035
5612
|
return self.designs.facet_graph(
|
|
5036
|
-
self.resolve_project(project, cwd),
|
|
5613
|
+
self.resolve_project(project, cwd), facet, sources
|
|
5037
5614
|
)
|
|
5038
5615
|
|
|
5039
5616
|
async def design_supersede(
|
|
@@ -5041,11 +5618,10 @@ class Crib:
|
|
|
5041
5618
|
ref: str,
|
|
5042
5619
|
by_ref: str | None = None,
|
|
5043
5620
|
project: str | None = None,
|
|
5044
|
-
cwd: Path | None = None,
|
|
5045
|
-
) -> dict[str, Any]:
|
|
5621
|
+
cwd: Path | None = None, *, facet: str = "design") -> dict[str, Any]:
|
|
5046
5622
|
"""Soft-delete a decision and taint its dependents."""
|
|
5047
5623
|
return await self.designs.design_supersede(
|
|
5048
|
-
self.resolve_project(project, cwd), ref, by_ref
|
|
5624
|
+
self.resolve_project(project, cwd), ref, by_ref, facet=facet
|
|
5049
5625
|
)
|
|
5050
5626
|
|
|
5051
5627
|
async def plan_add(
|
|
@@ -5061,8 +5637,7 @@ class Crib:
|
|
|
5061
5637
|
cwd: Path | None = None,
|
|
5062
5638
|
follows: list[str] | None = None,
|
|
5063
5639
|
rests_on: list[str] | None = None,
|
|
5064
|
-
informed_by: list[str] | None = None,
|
|
5065
|
-
) -> dict[str, Any]:
|
|
5640
|
+
informed_by: list[str] | None = None, *, facet: str = "plan") -> dict[str, Any]:
|
|
5066
5641
|
"""Add one plan item, or a whole batch (`items`), ranked at the end unless
|
|
5067
5642
|
after/before place them. A single item answers with `similar` (what it
|
|
5068
5643
|
is close to, with a verdict: see `_similar`)."""
|
|
@@ -5077,18 +5652,18 @@ class Crib:
|
|
|
5077
5652
|
items,
|
|
5078
5653
|
sources,
|
|
5079
5654
|
_kinded(follows, rests_on, informed_by),
|
|
5655
|
+
facet=facet,
|
|
5080
5656
|
)
|
|
5081
5657
|
if not items and out.get("relpath"):
|
|
5082
5658
|
out["similar"] = await asyncio.to_thread(
|
|
5083
|
-
self._similar, proj, out["relpath"],
|
|
5659
|
+
self._similar, proj, out["relpath"], facets.by_noun(facet).store)
|
|
5084
5660
|
return out
|
|
5085
5661
|
|
|
5086
5662
|
async def plan_status(
|
|
5087
|
-
self, ref: str, status: str, project: str | None = None, cwd: Path | None = None
|
|
5088
|
-
) -> dict[str, Any]:
|
|
5663
|
+
self, ref: str, status: str, project: str | None = None, cwd: Path | None = None, *, facet: str = "plan") -> dict[str, Any]:
|
|
5089
5664
|
"""Set a plan item's status (todo/in-progress/parked/done/verified)."""
|
|
5090
5665
|
return await self.designs.plan_status(
|
|
5091
|
-
self.resolve_project(project, cwd), ref, status
|
|
5666
|
+
self.resolve_project(project, cwd), ref, status, facet=facet
|
|
5092
5667
|
)
|
|
5093
5668
|
|
|
5094
5669
|
async def plan_park(
|
|
@@ -5097,12 +5672,11 @@ class Crib:
|
|
|
5097
5672
|
project: str | None = None,
|
|
5098
5673
|
triggers: list[str] | None = None,
|
|
5099
5674
|
why: str | None = None,
|
|
5100
|
-
cwd: Path | None = None,
|
|
5101
|
-
) -> dict[str, Any]:
|
|
5675
|
+
cwd: Path | None = None, *, facet: str = "plan", to: str | None = None) -> dict[str, Any]:
|
|
5102
5676
|
"""Park an item — not now, with a stated reason; optionally watching refs
|
|
5103
5677
|
whose change SURFACES it (never auto-wakes it)."""
|
|
5104
5678
|
return await self.designs.plan_park(
|
|
5105
|
-
self.resolve_project(project, cwd), ref, triggers, why
|
|
5679
|
+
self.resolve_project(project, cwd), ref, triggers, why, facet=facet, to=to
|
|
5106
5680
|
)
|
|
5107
5681
|
|
|
5108
5682
|
async def plan_decline(
|
|
@@ -5111,46 +5685,43 @@ class Crib:
|
|
|
5111
5685
|
why: str | None = None,
|
|
5112
5686
|
project: str | None = None,
|
|
5113
5687
|
triggers: list[str] | None = None,
|
|
5114
|
-
cwd: Path | None = None,
|
|
5115
|
-
) -> dict[str, Any]:
|
|
5688
|
+
cwd: Path | None = None, *, facet: str = "plan", to: str | None = None) -> dict[str, Any]:
|
|
5116
5689
|
"""Decline an item — never scheduled, remembered with the why-not (a
|
|
5117
5690
|
decline without the why-not is refused: the rationale IS the payload)."""
|
|
5118
5691
|
return await self.designs.plan_decline(
|
|
5119
|
-
self.resolve_project(project, cwd), ref, why, triggers
|
|
5692
|
+
self.resolve_project(project, cwd), ref, why, triggers, facet=facet, to=to
|
|
5120
5693
|
)
|
|
5121
5694
|
|
|
5122
5695
|
async def plan_review(
|
|
5123
|
-
self, project: str | None = None, cwd: Path | None = None
|
|
5124
|
-
) -> dict[str, Any]:
|
|
5696
|
+
self, project: str | None = None, cwd: Path | None = None, *, facet: str = "plan") -> dict[str, Any]:
|
|
5125
5697
|
"""The review EVIDENCE PACK: the consolidated export + per-item evidence
|
|
5126
5698
|
(age, deps, overlap probes vs open AND done/declined items) + the review
|
|
5127
5699
|
contract. Runs no model, writes nothing — the session LLM judges, then
|
|
5128
5700
|
`plan_review_apply` applies the batch."""
|
|
5129
5701
|
return await self.designs.plan_review(
|
|
5130
5702
|
self.resolve_project(project, cwd),
|
|
5131
|
-
probe=lambda p, text, exclude: self._similar(p, exclude,
|
|
5703
|
+
probe=lambda p, text, exclude: self._similar(p, exclude, facets.by_noun(facet).store),
|
|
5704
|
+
facet=facet,
|
|
5132
5705
|
)
|
|
5133
5706
|
|
|
5134
5707
|
async def plan_review_apply(
|
|
5135
5708
|
self,
|
|
5136
5709
|
project: str | None = None,
|
|
5137
5710
|
batch: list[dict] | None = None,
|
|
5138
|
-
cwd: Path | None = None,
|
|
5139
|
-
) -> dict[str, Any]:
|
|
5711
|
+
cwd: Path | None = None, *, facet: str = "plan") -> dict[str, Any]:
|
|
5140
5712
|
"""Apply a judged review batch, edge-aware, stamped `reviewed`."""
|
|
5141
5713
|
return await self.designs.plan_review_apply(
|
|
5142
|
-
self.resolve_project(project, cwd), batch or []
|
|
5714
|
+
self.resolve_project(project, cwd), batch or [], facet=facet
|
|
5143
5715
|
)
|
|
5144
5716
|
|
|
5145
5717
|
def plan_read(
|
|
5146
|
-
self, ref: str, project: str | None = None, cwd: Path | None = None
|
|
5147
|
-
) -> dict[str, Any]:
|
|
5718
|
+
self, ref: str, project: str | None = None, cwd: Path | None = None, *, facet: str = "plan") -> dict[str, Any]:
|
|
5148
5719
|
"""A plan item's dossier: body, status, annotated edges, derived blocking
|
|
5149
5720
|
+ taint — the plan-side design_read — and `suggested_deps` (see
|
|
5150
5721
|
`design_read`)."""
|
|
5151
5722
|
proj = self.resolve_project(project, cwd)
|
|
5152
|
-
out = self.designs.plan_read(proj, ref)
|
|
5153
|
-
return {**out, "suggested_deps": self._suggested_deps(proj, out,
|
|
5723
|
+
out = self.designs.plan_read(proj, ref, facet=facet)
|
|
5724
|
+
return {**out, "suggested_deps": self._suggested_deps(proj, out, facets.by_noun(facet).store)}
|
|
5154
5725
|
|
|
5155
5726
|
def _suggested_deps(self, proj: str, read: dict[str, Any],
|
|
5156
5727
|
store: str) -> list[dict[str, Any]]:
|
|
@@ -5168,12 +5739,11 @@ class Crib:
|
|
|
5168
5739
|
new_content: str,
|
|
5169
5740
|
project: str | None = None,
|
|
5170
5741
|
sources: list[Any] | None = None,
|
|
5171
|
-
cwd: Path | None = None,
|
|
5172
|
-
) -> dict[str, Any]:
|
|
5742
|
+
cwd: Path | None = None, *, facet: str = "plan") -> dict[str, Any]:
|
|
5173
5743
|
"""Rewrite a plan item's body through the facet; result names what it
|
|
5174
5744
|
tainted. `sources`, when given, replaces its citations."""
|
|
5175
5745
|
return await self.designs.plan_edit(
|
|
5176
|
-
self.resolve_project(project, cwd), ref, new_content, sources
|
|
5746
|
+
self.resolve_project(project, cwd), ref, new_content, sources, facet=facet
|
|
5177
5747
|
)
|
|
5178
5748
|
|
|
5179
5749
|
async def plan_append(
|
|
@@ -5182,12 +5752,11 @@ class Crib:
|
|
|
5182
5752
|
content: str,
|
|
5183
5753
|
project: str | None = None,
|
|
5184
5754
|
cwd: Path | None = None,
|
|
5185
|
-
sources: list[Any] | None = None,
|
|
5186
|
-
) -> dict[str, Any]:
|
|
5755
|
+
sources: list[Any] | None = None, *, facet: str = "plan") -> dict[str, Any]:
|
|
5187
5756
|
"""Extend a plan item's body through the facet; result names what it
|
|
5188
5757
|
tainted. `sources` ADDS citations, never replaces."""
|
|
5189
5758
|
return await self.designs.plan_append(
|
|
5190
|
-
self.resolve_project(project, cwd), ref, content, sources
|
|
5759
|
+
self.resolve_project(project, cwd), ref, content, sources, facet=facet
|
|
5191
5760
|
)
|
|
5192
5761
|
|
|
5193
5762
|
async def plan_dep_add(
|
|
@@ -5196,11 +5765,10 @@ class Crib:
|
|
|
5196
5765
|
dep_ref: str,
|
|
5197
5766
|
project: str | None = None,
|
|
5198
5767
|
cwd: Path | None = None,
|
|
5199
|
-
kind: str | None = None,
|
|
5200
|
-
) -> dict[str, Any]:
|
|
5768
|
+
kind: str | None = None, *, facet: str = "plan") -> dict[str, Any]:
|
|
5201
5769
|
"""Declare that a plan item depends on another (cycle-checked)."""
|
|
5202
5770
|
return await self.designs.plan_dep_add(
|
|
5203
|
-
self.resolve_project(project, cwd), ref, dep_ref, kind
|
|
5771
|
+
self.resolve_project(project, cwd), ref, dep_ref, kind, facet=facet
|
|
5204
5772
|
)
|
|
5205
5773
|
|
|
5206
5774
|
async def plan_dep_remove(
|
|
@@ -5208,11 +5776,10 @@ class Crib:
|
|
|
5208
5776
|
ref: str,
|
|
5209
5777
|
dep_ref: str,
|
|
5210
5778
|
project: str | None = None,
|
|
5211
|
-
cwd: Path | None = None,
|
|
5212
|
-
) -> dict[str, Any]:
|
|
5779
|
+
cwd: Path | None = None, *, facet: str = "plan") -> dict[str, Any]:
|
|
5213
5780
|
"""Drop a must-precede edge between plan items."""
|
|
5214
5781
|
return await self.designs.plan_dep_remove(
|
|
5215
|
-
self.resolve_project(project, cwd), ref, dep_ref
|
|
5782
|
+
self.resolve_project(project, cwd), ref, dep_ref, facet=facet
|
|
5216
5783
|
)
|
|
5217
5784
|
|
|
5218
5785
|
async def plan_forget(
|
|
@@ -5220,11 +5787,10 @@ class Crib:
|
|
|
5220
5787
|
ref: str,
|
|
5221
5788
|
force: bool = False,
|
|
5222
5789
|
project: str | None = None,
|
|
5223
|
-
cwd: Path | None = None,
|
|
5224
|
-
) -> dict[str, Any]:
|
|
5790
|
+
cwd: Path | None = None, *, facet: str = "plan") -> dict[str, Any]:
|
|
5225
5791
|
"""Delete a plan item; blocks on dependents unless forced."""
|
|
5226
5792
|
return await self.designs.plan_forget(
|
|
5227
|
-
self.resolve_project(project, cwd), ref, force
|
|
5793
|
+
self.resolve_project(project, cwd), ref, force, facet=facet
|
|
5228
5794
|
)
|
|
5229
5795
|
|
|
5230
5796
|
async def plan_move(
|
|
@@ -5233,24 +5799,21 @@ class Crib:
|
|
|
5233
5799
|
after: str | None = None,
|
|
5234
5800
|
before: str | None = None,
|
|
5235
5801
|
project: str | None = None,
|
|
5236
|
-
cwd: Path | None = None,
|
|
5237
|
-
) -> dict[str, Any]:
|
|
5802
|
+
cwd: Path | None = None, *, facet: str = "plan") -> dict[str, Any]:
|
|
5238
5803
|
"""Re-rank a plan item (deps untouched)."""
|
|
5239
5804
|
return await self.designs.plan_move(
|
|
5240
|
-
self.resolve_project(project, cwd), ref, after, before
|
|
5805
|
+
self.resolve_project(project, cwd), ref, after, before, facet=facet
|
|
5241
5806
|
)
|
|
5242
5807
|
|
|
5243
5808
|
def plan_list(
|
|
5244
|
-
self, all: bool = False, project: str | None = None, cwd: Path | None = None
|
|
5245
|
-
) -> dict[str, Any]:
|
|
5809
|
+
self, all: bool = False, project: str | None = None, cwd: Path | None = None, *, facet: str = "plan") -> dict[str, Any]:
|
|
5246
5810
|
"""The plan in topological, rank-tie-broken order."""
|
|
5247
|
-
return self.designs.plan_list(self.resolve_project(project, cwd), all)
|
|
5811
|
+
return self.designs.plan_list(self.resolve_project(project, cwd), all, facet=facet)
|
|
5248
5812
|
|
|
5249
5813
|
def plan_next(
|
|
5250
|
-
self, k: int = 5, project: str | None = None, cwd: Path | None = None
|
|
5251
|
-
) -> dict[str, Any]:
|
|
5814
|
+
self, k: int = 5, project: str | None = None, cwd: Path | None = None, *, facet: str = "plan") -> dict[str, Any]:
|
|
5252
5815
|
"""The actionable plan items right now (todo, deps satisfied)."""
|
|
5253
|
-
return self.designs.plan_next(self.resolve_project(project, cwd), k)
|
|
5816
|
+
return self.designs.plan_next(self.resolve_project(project, cwd), k, facet=facet)
|
|
5254
5817
|
|
|
5255
5818
|
def code_lookup(
|
|
5256
5819
|
self,
|
|
@@ -5343,6 +5906,7 @@ class Crib:
|
|
|
5343
5906
|
cwd: Path | None = None,
|
|
5344
5907
|
overwrite: bool = False,
|
|
5345
5908
|
background: bool = False,
|
|
5909
|
+
kind: str | None = None,
|
|
5346
5910
|
) -> dict[str, Any]:
|
|
5347
5911
|
"""ONE enrichment pass over every configured facet — the keyword labels (BM25
|
|
5348
5912
|
side) AND the summary labels (dense alias side) together, one bulk generation
|
|
@@ -5388,7 +5952,8 @@ class Crib:
|
|
|
5388
5952
|
if not facets:
|
|
5389
5953
|
return {"project": proj, "labels": [], "written": {}, "total": 0}
|
|
5390
5954
|
return await self._generate_enrichment(
|
|
5391
|
-
proj, "elaborate", facets, relpath, overwrite, background=background
|
|
5955
|
+
proj, "elaborate", facets, relpath, overwrite, background=background,
|
|
5956
|
+
kind=kind,
|
|
5392
5957
|
)
|
|
5393
5958
|
|
|
5394
5959
|
async def _generate_index(
|
|
@@ -5401,6 +5966,7 @@ class Crib:
|
|
|
5401
5966
|
project: str | None,
|
|
5402
5967
|
cwd: Path | None,
|
|
5403
5968
|
overwrite: bool,
|
|
5969
|
+
kind: str | None = None,
|
|
5404
5970
|
) -> dict[str, Any]:
|
|
5405
5971
|
"""Single-facet shim over `_generate_enrichment` (the `elaborate`/`summarize`
|
|
5406
5972
|
verbs) — legacy flat result shape preserved."""
|
|
@@ -5419,7 +5985,7 @@ class Crib:
|
|
|
5419
5985
|
"store": SectionIndex(self.paths.project_dir(proj), root_name),
|
|
5420
5986
|
}
|
|
5421
5987
|
out = await self._generate_enrichment(
|
|
5422
|
-
proj, purpose, [facet], relpath, overwrite
|
|
5988
|
+
proj, purpose, [facet], relpath, overwrite, kind=kind
|
|
5423
5989
|
)
|
|
5424
5990
|
return {
|
|
5425
5991
|
"project": proj,
|
|
@@ -5440,6 +6006,7 @@ class Crib:
|
|
|
5440
6006
|
relpath: str | None,
|
|
5441
6007
|
overwrite: bool,
|
|
5442
6008
|
background: bool = False,
|
|
6009
|
+
kind: str | None = None,
|
|
5443
6010
|
) -> dict[str, Any]:
|
|
5444
6011
|
"""Shared MULTI-FACET section-level generation: one bulk call per note batch
|
|
5445
6012
|
emits terms for EVERY facet (a facet = one label of keyword_index or
|
|
@@ -5501,7 +6068,12 @@ class Crib:
|
|
|
5501
6068
|
# (section_hash, relpath, heading, body, missing-facets)
|
|
5502
6069
|
targets: list[tuple[str, str, str, str, list[dict]]] = []
|
|
5503
6070
|
skipped = 0
|
|
5504
|
-
|
|
6071
|
+
# `kind` scopes the pass to one facet's items (a declared facet's verbs);
|
|
6072
|
+
# unscoped, it covers the whole project, every pillar.
|
|
6073
|
+
where: dict[str, Any] = {"project": proj}
|
|
6074
|
+
if kind is not None:
|
|
6075
|
+
where["kind"] = kind
|
|
6076
|
+
for _cid, (doc, meta) in self.store.get_docs(where).items():
|
|
5505
6077
|
if relpath and meta.get("relpath") != relpath:
|
|
5506
6078
|
continue
|
|
5507
6079
|
sh = meta.get("section_hash") or meta.get("content_hash")
|
|
@@ -5857,7 +6429,12 @@ class Crib:
|
|
|
5857
6429
|
|
|
5858
6430
|
# --- import ------------------------------------------------------------
|
|
5859
6431
|
async def import_files(
|
|
5860
|
-
self,
|
|
6432
|
+
self,
|
|
6433
|
+
paths: list[str],
|
|
6434
|
+
project: str | None = None,
|
|
6435
|
+
cwd: Path | None = None,
|
|
6436
|
+
*,
|
|
6437
|
+
facet: str = facets.HOME,
|
|
5861
6438
|
) -> dict[str, Any]:
|
|
5862
6439
|
"""Copy explicit files INTO memory as crib-owned notes — manual only.
|
|
5863
6440
|
|
|
@@ -5888,9 +6465,9 @@ class Crib:
|
|
|
5888
6465
|
src = src.resolve()
|
|
5889
6466
|
if not src.is_file():
|
|
5890
6467
|
raise CribUserError(f"not a file: {p}")
|
|
5891
|
-
relpath =
|
|
6468
|
+
relpath = self._import_relpath(proj, facet, src)
|
|
5892
6469
|
sfm, sbody = notes.parse(src.read_text())
|
|
5893
|
-
tgt = self.abspath(proj, relpath)
|
|
6470
|
+
tgt = self.abspath(proj, relpath, facet)
|
|
5894
6471
|
prev = notes.load(tgt) if tgt.exists() else None
|
|
5895
6472
|
fm = dict(sfm)
|
|
5896
6473
|
fm.update(
|
|
@@ -5904,7 +6481,7 @@ class Crib:
|
|
|
5904
6481
|
note_id = (prev.id if prev and prev.id else None) or derived_ulid(relpath)
|
|
5905
6482
|
fm = {"id": note_id, **fm}
|
|
5906
6483
|
note = Note(path=tgt, frontmatter=fm, body=sbody)
|
|
5907
|
-
await self._write_note(proj, relpath, note)
|
|
6484
|
+
await self._write_note(proj, relpath, note, facet)
|
|
5908
6485
|
imported.append(relpath)
|
|
5909
6486
|
return {
|
|
5910
6487
|
"project": proj,
|
|
@@ -6021,10 +6598,15 @@ class Crib:
|
|
|
6021
6598
|
|
|
6022
6599
|
# --- versioning / git --------------------------------------------------
|
|
6023
6600
|
def list_versions(
|
|
6024
|
-
self,
|
|
6601
|
+
self,
|
|
6602
|
+
relpath: str,
|
|
6603
|
+
project: str | None = None,
|
|
6604
|
+
cwd: Path | None = None,
|
|
6605
|
+
*,
|
|
6606
|
+
facet: str = facets.HOME,
|
|
6025
6607
|
) -> list[dict[str, Any]]:
|
|
6026
6608
|
proj = self.resolve_project(project, cwd)
|
|
6027
|
-
return self.
|
|
6609
|
+
return self._facet_store(facet).list_versions(proj, relpath)
|
|
6028
6610
|
|
|
6029
6611
|
async def restore(
|
|
6030
6612
|
self,
|
|
@@ -6032,10 +6614,12 @@ class Crib:
|
|
|
6032
6614
|
version: str,
|
|
6033
6615
|
project: str | None = None,
|
|
6034
6616
|
cwd: Path | None = None,
|
|
6617
|
+
*,
|
|
6618
|
+
facet: str = facets.HOME,
|
|
6035
6619
|
) -> dict[str, Any]:
|
|
6036
6620
|
proj = self.resolve_project(project, cwd)
|
|
6037
|
-
content = self.
|
|
6038
|
-
return await self.edit_note(relpath, content, project=proj)
|
|
6621
|
+
content = self._facet_store(facet).version_content(proj, relpath, version)
|
|
6622
|
+
return await self.edit_note(relpath, content, project=proj, facet=facet)
|
|
6039
6623
|
|
|
6040
6624
|
def snapshot(self, message: str | None = None) -> str:
|
|
6041
6625
|
return self.git.snapshot(message)
|