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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
crib/bundle.py CHANGED
@@ -46,6 +46,11 @@ REGISTRY = "bundles.json"
46
46
  VECTORS_FILE = "embed-cache.parquet" # the bundle's vectors, under DIR/data
47
47
  FORMAT = 1
48
48
  _MANIFEST_MAX = 64 * 1024 # a manifest is a few lines; anything bigger is hostile
49
+ # the cap a registry entry with no `max_expires` (one written by 0.28.0-dev1)
50
+ # gets: `bundle create`'s default --max-retention, counted from its creation
51
+ DEFAULT_RETENTION = datetime.timedelta(days=30)
52
+ # bundles the sweep failed to delete and has said so (once per bundle per process)
53
+ _SWEEP_WARNED: set[str] = set()
49
54
 
50
55
 
51
56
  # ── manifest ─────────────────────────────────────────────────────────────────
@@ -218,6 +223,35 @@ def _copy_project_files(
218
223
  return n
219
224
 
220
225
 
226
+ def _copy_lsp_json(src: Path, dest: Path) -> dict[str, str]:
227
+ """Copy the trusted machine's lsp.json into the bundle with every server
228
+ `command` that is a path reduced to its bare name (`/opt/homebrew/bin/gopls`
229
+ -> `gopls`): the bundle runs on another machine (the review image), where a
230
+ bare name is looked up on PATH (codeindex.resolve_command) and a path from
231
+ here would not exist, silently disabling that server. Returns the rewrites,
232
+ label -> the command it had. A malformed file is not copied (crib would
233
+ ignore it anyway)."""
234
+ if not src.is_file():
235
+ return {}
236
+ try:
237
+ specs = json.loads(src.read_text())
238
+ except (ValueError, OSError) as e:
239
+ print(f"[crib] {src} not copied into the bundle: {e}", file=sys.stderr)
240
+ return {}
241
+ if not isinstance(specs, dict):
242
+ print(f"[crib] {src} not copied into the bundle: not a JSON object",
243
+ file=sys.stderr)
244
+ return {}
245
+ rewritten: dict[str, str] = {}
246
+ for label, spec in specs.items():
247
+ cmd = spec.get("command") if isinstance(spec, dict) else None
248
+ if isinstance(cmd, str) and "/" in cmd:
249
+ spec["command"] = cmd.rstrip("/").rsplit("/", 1)[-1]
250
+ rewritten[str(label)] = cmd
251
+ dest.write_text(json.dumps(specs, indent=2) + "\n")
252
+ return rewritten
253
+
254
+
221
255
  def _trusted_crib(paths: Paths, base: str, overlay: str) -> str | None:
222
256
  """The base repo's `.crib`, renamed to the overlay: code `paths:` and `docs:`
223
257
  only (confined mode ignores residency and mappings anyway)."""
@@ -285,7 +319,8 @@ def create(
285
319
  cap = expiry.parse(max_retention)
286
320
  until = expiry.parse(expires) if expires else cap
287
321
  u_at, cap_at = expiry.when(until), expiry.when(cap)
288
- if u_at is not None and cap_at is not None and u_at > cap_at:
322
+ capped = u_at is not None and cap_at is not None and u_at > cap_at
323
+ if capped:
289
324
  until = cap
290
325
  # Directories this create owns: the bundle (absent, or checked empty above)
291
326
  # and, only when context projects are copied to --context-to, that dir
@@ -296,7 +331,7 @@ def create(
296
331
  owned.append((ctx_dir, not ctx_dir.exists()))
297
332
  try:
298
333
  return _build(paths, cfg, bundle, base, proj, context, ctx_dir, context_to,
299
- context_mount, until, vectors, cap)
334
+ context_mount, until, vectors, cap, capped)
300
335
  except BaseException:
301
336
  # a half-built bundle is unregistered, so nothing would ever clean it up
302
337
  # (and a retry would refuse the non-empty dir): remove what was made
@@ -314,7 +349,7 @@ def create(
314
349
  def _build(paths: Paths, cfg: Any, bundle: Path, base: str, proj: str,
315
350
  context: list[str], ctx_dir: Path, context_to: Path | None,
316
351
  context_mount: str | None, until: str | None, vectors: bool,
317
- cap: str | None = None
352
+ cap: str | None = None, capped: bool = False
318
353
  ) -> dict[str, Any]:
319
354
  """`create`'s body, once the arguments are checked."""
320
355
  from .config import ProjectConfig
@@ -366,7 +401,9 @@ def _build(paths: Paths, cfg: Any, bundle: Path, base: str, proj: str,
366
401
  # the sandbox embeds with the SAME model, or its store refuses the vectors
367
402
  lines += ["", "[embed]", f"model = {json.dumps(cfg.embed.model)}"]
368
403
  (bpaths.config_dir / "config.toml").write_text("\n".join(lines) + "\n")
369
- for extra in ("lsp.json", "grammar.json", "facets.toml"):
404
+ lsp_rewritten = _copy_lsp_json(paths.config_dir / "lsp.json",
405
+ bpaths.config_dir / "lsp.json")
406
+ for extra in ("grammar.json", "facets.toml"):
370
407
  if (src := paths.config_dir / extra).is_file():
371
408
  shutil.copy2(src, bpaths.config_dir / extra)
372
409
 
@@ -397,6 +434,8 @@ def _build(paths: Paths, cfg: Any, bundle: Path, base: str, proj: str,
397
434
  "context": context,
398
435
  "context_dir": str(ctx_dir) if context else None,
399
436
  "expires": until,
437
+ "expires_capped": capped,
438
+ "lsp_rewritten": lsp_rewritten,
400
439
  "files": files,
401
440
  "vectors": vec_rows,
402
441
  }
@@ -536,17 +575,27 @@ def expire(bundle: Path, when: str, paths: Paths | None = None) -> dict[str, Any
536
575
  return {"bundle": str(bundle), "expires": until}
537
576
 
538
577
 
578
+ def _entry_cap(entry: dict[str, Any]) -> datetime.datetime | None:
579
+ """A registry entry's hard cap: its `max_expires`, or for an entry from
580
+ before caps (0.28.0-dev1) its creation plus DEFAULT_RETENTION."""
581
+ from . import expiry
582
+
583
+ if (cap := expiry.when(entry.get("max_expires"))) is not None:
584
+ return cap
585
+ if (made := expiry.when(entry.get("created"))) is not None:
586
+ return made + DEFAULT_RETENTION
587
+ return None
588
+
589
+
539
590
  def listing(paths: Paths, now: datetime.datetime | None = None) -> list[dict[str, Any]]:
540
591
  """Registered bundles with their state (live/due/missing/unreadable) and
541
592
  effective expiry: the manifest's, capped at the registry's `max_expires`."""
542
- from . import expiry
543
-
544
593
  now = now or datetime.datetime.now(datetime.UTC)
545
594
  out = []
546
595
  for path, entry in sorted(registry(paths).items()):
547
596
  row: dict[str, Any] = {"bundle": path, **entry}
548
597
  b = Path(path)
549
- cap = expiry.when(entry.get("max_expires"))
598
+ cap = _entry_cap(entry)
550
599
  if not b.is_dir():
551
600
  row["state"] = "missing"
552
601
  else:
@@ -594,6 +643,8 @@ def sweep(paths: Paths, now: datetime.datetime | None = None) -> list[str]:
594
643
  delete(paths, Path(row["bundle"]))
595
644
  gone.append(row["bundle"])
596
645
  except Exception as e: # noqa: BLE001 — one bundle never blocks the rest
597
- print(f"[crib] expired bundle {row['bundle']} not deleted: {e}",
598
- file=sys.stderr)
646
+ if row["bundle"] not in _SWEEP_WARNED: # once, not every sweep
647
+ _SWEEP_WARNED.add(row["bundle"])
648
+ print(f"[crib] expired bundle {row['bundle']} not deleted: {e}",
649
+ file=sys.stderr)
599
650
  return gone
crib/cli.py CHANGED
@@ -279,10 +279,12 @@ def _code_link(d: dict) -> str | None:
279
279
  if proj not in _SOURCE_ROOTS:
280
280
  try:
281
281
  from .codeindex import SymbolIndex
282
+ from .config import Config
282
283
  from .paths import Paths
283
284
 
284
- _SOURCE_ROOTS[proj] = SymbolIndex(
285
- Paths.resolve().project_dir(proj)).source_root()
285
+ paths = Paths.resolve() # with the context dir: context projects link too
286
+ paths = paths.with_context(Config.load(paths.config_file))
287
+ _SOURCE_ROOTS[proj] = SymbolIndex(paths.project_dir(proj)).source_root()
286
288
  except Exception: # noqa: BLE001 — a link is a nicety, never a failure
287
289
  _SOURCE_ROOTS[proj] = None
288
290
  root = _SOURCE_ROOTS[proj]
@@ -304,8 +306,9 @@ def _item_link(project: Any, relpath: Any, store: str | None) -> str | None:
304
306
 
305
307
  if project not in _ITEM_PATHS:
306
308
  paths = Paths.resolve()
309
+ cfg = Config.load(paths.config_file)
307
310
  _ITEM_PATHS[project] = resolve_project_paths(
308
- paths, Config.load(paths.config_file), str(project))
311
+ paths.with_context(cfg), cfg, str(project))
309
312
  path = _ITEM_PATHS[project].pillar_dir(store) / str(relpath)
310
313
  return _st.file_link(path) if path.is_file() else None
311
314
  except Exception: # noqa: BLE001 — a link is a nicety, never a failure
@@ -4192,8 +4195,12 @@ def _bundle_cmd(args: Any) -> int:
4192
4195
  f"{out['base']})\n context {', '.join(out['context']) or '-'}"
4193
4196
  + (f" at {out['context_dir']}" if out["context_dir"] else "")
4194
4197
  + f"\n files: {files}\n vectors: {out['vectors']}\n"
4195
- f" expires {out['expires']}\n"
4196
- f" open it with: crib --root {out['bundle']} [--store SCRATCH]")
4198
+ f" expires {out['expires']}"
4199
+ + (" (capped by --max-retention)" if out.get("expires_capped") else "")
4200
+ + "\n"
4201
+ + "".join(f" lsp.json {label}: {was} -> bare name (found on PATH)\n"
4202
+ for label, was in (out.get("lsp_rewritten") or {}).items())
4203
+ + f" open it with: crib --root {out['bundle']} [--store SCRATCH]")
4197
4204
  elif cmd == "list":
4198
4205
  out = bundles.listing(paths)
4199
4206
  human = "\n".join(
crib/server.py CHANGED
@@ -325,8 +325,10 @@ def _elicited(crib: Crib, chosen: str) -> ProjectResolution:
325
325
  raise CribUserError(
326
326
  f"no project named {chosen!r} — one of: "
327
327
  + ", ".join(sorted(crib.projects()))
328
- + f" (projects dir: {crib.paths.projects_dir}; CRIB_DATA_DIR: "
329
- f"{os.environ.get('CRIB_DATA_DIR')})"
328
+ + f" (projects dir: {crib.paths.projects_dir}"
329
+ + (f"; context dir: {crib.paths.context_dir}"
330
+ if crib.paths.context_dir is not None else "")
331
+ + f"; CRIB_DATA_DIR: {os.environ.get('CRIB_DATA_DIR')})"
330
332
  )
331
333
  proj = chosen
332
334
  return ProjectResolution(proj, "elicited")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: cribsheet
3
- Version: 0.28.0-dev2
3
+ Version: 0.28.0-dev3
4
4
  Summary: Local MCP server: markdown memory with a DuckDB embedding index
5
5
  Requires-Python: >=3.14
6
6
  Requires-Dist: duckdb<3,>=2.0
@@ -2,10 +2,10 @@ crib/__init__.py,sha256=KzW14Xf3xyTCrmhsSbcFleJVCU6u6-WFidcrLB4YZSw,1001
2
2
  crib/__main__.py,sha256=2kTd4YVxzJpKtMv9nUN9LCJo5qjZmBaPFw_hR1wp_e0,289
3
3
  crib/access.py,sha256=0i9I4MUB0083zdUW4UyQWcXReiFs8G_5Pc0-nu8ISFM,3357
4
4
  crib/app.py,sha256=5bi6WsNUUUMy6H8EEsDIp08fp8iLZ5xJ-9IU450Svbg,333845
5
- crib/bundle.py,sha256=wTB2kt4T3r3uaO1gNXRllUcMRDjsl7zerDuiRS_0Fjc,24600
5
+ crib/bundle.py,sha256=cDV1NS-uIkFVIcOvzcZv7YWc7BJ8L-echwhQC9SxGmo,27036
6
6
  crib/chunk.py,sha256=G5Ftt4zHQ0tx4__ecysFnW64otciPFcqpZ3Y-c_G6JE,15166
7
7
  crib/claudemem.py,sha256=Xf4mVgTFbXHdhhqteTIRz2zirc4irf0wim8AeMybudI,4804
8
- crib/cli.py,sha256=Nb35bffPeqwaKRYxVGqNxHSMh9BgiUqYu1pWpqpjJhQ,181941
8
+ crib/cli.py,sha256=TwugeFIb4D3RhUy-HjG8FGhdTCwyPGwm4ekd8EvUz5E,182438
9
9
  crib/client.py,sha256=-PRVFFLjbI-D-libZ_wMdDFdcXkyHmc9AYikzxd9PmI,6605
10
10
  crib/codeindex.py,sha256=FmrU_YqE4jCZdpV-ExHPZWyF9gNJkC94rCiQDNxNrjs,92214
11
11
  crib/codeindexer.py,sha256=BypXftS8PGvgIAF9wELgLEOTdVvE3LjhMIiTgQUQweA,47382
@@ -46,7 +46,7 @@ crib/refs.py,sha256=Rp-1WSs7tTYY0jvdkIfpZVCN7gJVVOrceyB77vZ46vg,13341
46
46
  crib/related.py,sha256=3DPdxCSdNLFhtGOqB6o1x4DLNUFN3WgPN30nAZCTNvA,3904
47
47
  crib/retrieve.py,sha256=S8b8lEOthfprCRTfSetTZFbDH0B65Iv0nKzcFG-U83c,27140
48
48
  crib/section_index.py,sha256=nhFEZQBjlfV9y5fpB39Rp5RPFHLnp2nhZbAG8S7fUNg,8846
49
- crib/server.py,sha256=B8a-Ku-riGqzgY_9M1Jti1xDiTXZM6X_kYnrpRmOLYU,73496
49
+ crib/server.py,sha256=mKTVoCJ32RxtTkGs63i0A3dGKQyxvDAQmvoxbKy8N3c,73626
50
50
  crib/session.py,sha256=vTu4tbNi42I4ZHjJlPDBDK57z0lUpbSlEfOcXmXdMIE,6780
51
51
  crib/sharedserver.py,sha256=KtCBTQaw_LhaY93ICY5ILI5t3fj5kzXAROb7cI_4-8k,2135
52
52
  crib/sources.py,sha256=ZMCKYixRyV_MSrcFkYq5WUt-haEwWBxCMtDZBgKigBI,2918
@@ -63,7 +63,7 @@ crib/versions.py,sha256=P517DveKCh2jKb3o5IOxkzki8ddwmc-QeuiYMvsBb88,3646
63
63
  crib/watch.py,sha256=Uzy_BgvaTUCMzokTvgmX7vIEdGDh4Rb_M8MReYlAcCw,36361
64
64
  crib/wording.py,sha256=_jNHt5dDCMlEJUgVREpgYAWt-MphX3YctpPnpRfo_M4,1076
65
65
  crib/wording.toml,sha256=wMr-86GIYK06QwgLgQe8-63rgt-SR8yXzPjSw1rtWms,27063
66
- cribsheet-0.28.0.dev2.dist-info/METADATA,sha256=VOeU1RDkHYYSWy1rxTC_QD8NetHgLAfy3vnzU1bxngE,22796
67
- cribsheet-0.28.0.dev2.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
68
- cribsheet-0.28.0.dev2.dist-info/entry_points.txt,sha256=XtJ6pC05pU7frNv_hBoXY6QF3TtFta8wRL6hHtGBfhw,41
69
- cribsheet-0.28.0.dev2.dist-info/RECORD,,
66
+ cribsheet-0.28.0.dev3.dist-info/METADATA,sha256=dBKETrcb2hK3GLhjg1gRw5dQHG3mWqmv0r4xFMZE5q4,22796
67
+ cribsheet-0.28.0.dev3.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
68
+ cribsheet-0.28.0.dev3.dist-info/entry_points.txt,sha256=XtJ6pC05pU7frNv_hBoXY6QF3TtFta8wRL6hHtGBfhw,41
69
+ cribsheet-0.28.0.dev3.dist-info/RECORD,,