cribsheet 0.21.2.dev2__py3-none-any.whl → 0.21.2.dev4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
crib/app.py CHANGED
@@ -3285,10 +3285,16 @@ class Crib:
3285
3285
  new_root = Path(project_path).expanduser().resolve()
3286
3286
  if not new_root.is_dir():
3287
3287
  raise CribUserError(f"no such directory: {new_root}")
3288
- if old in self.code.sweeps or old in self.code_jobs:
3288
+ # a relocate JOB of ours may be mid-flight WITH its own trailing code
3289
+ # sweep (the rehash runs inside the job) — that must JOIN, not fence:
3290
+ # the sweep-conflict refusal exists only when no relocate context exists.
3291
+ if old not in self.relocate_jobs and (
3292
+ old in self.code.sweeps or old in self.code_jobs
3293
+ ):
3289
3294
  raise CribUserError(
3290
- f"a code-index sweep is running for {old!r} — project_cancel "
3291
- "or project_wait it first"
3295
+ f"a code-index sweep is running for {old!r} (not a relocate's "
3296
+ "own) — project_cancel or project_wait it first; a relocate in "
3297
+ "flight would have joined instead"
3292
3298
  )
3293
3299
  if self._reconcile_remaining is not None:
3294
3300
  raise CribUserError(
@@ -3486,8 +3492,9 @@ class Crib:
3486
3492
  "progress": state,
3487
3493
  "resume_hint": (
3488
3494
  "the rekey runs daemon-owned (a client disconnect can't "
3489
- "cancel it) — re-invoke to poll/join, or with "
3490
- "wait_s=<seconds> to block"
3495
+ "cancel it) — POLL it, don't block: project_status "
3496
+ "carries the live progress; re-invoking the verb joins "
3497
+ "or finishes it"
3491
3498
  ),
3492
3499
  }
3493
3500
  started = time.monotonic()
@@ -3500,7 +3507,9 @@ class Crib:
3500
3507
  "relocated": True,
3501
3508
  "running": True,
3502
3509
  "progress": state,
3503
- "resume_hint": "still rekeying — re-invoke to join/poll",
3510
+ "resume_hint": (
3511
+ "still rekeying — poll project_status; re-invoking joins"
3512
+ ),
3504
3513
  }
3505
3514
 
3506
3515
  # 6. The FINISHED path (or nothing to do): the heavy result if a job ran
@@ -3847,11 +3856,92 @@ class Crib:
3847
3856
  """Delegate to Refs (crib/refs.py) — a project's `.crib` refs: targets."""
3848
3857
  return self.refs.project_refs(proj)
3849
3858
 
3859
+ def _job_rows(self, proj: str | None = None) -> list[dict[str, Any]]:
3860
+ """Every long-running project job that a POLL can see — the relocate
3861
+ rekey/citation phase, the code-index sweeps, the background reconcile.
3862
+ Calling this while ANY of them run is the point of it: it never errors,
3863
+ never blocks; it reports running/complete/failed + live counts, and the
3864
+ finished counts a job already banked (citations rewritten, mount named,
3865
+ chunks rekeyed)."""
3866
+ rows: list[dict[str, Any]] = []
3867
+ for p, job in sorted(self.relocate_jobs.items()):
3868
+ if proj is not None and p != proj:
3869
+ continue
3870
+ state = dict(job.get("state") or {})
3871
+ t = job["task"]
3872
+ done, error = t.done(), None
3873
+ if done:
3874
+ try:
3875
+ exc = t.exception() # never re-raised — reported, polled
3876
+ if exc is not None:
3877
+ error = f"{type(exc).__name__}: {exc}"
3878
+ except Exception as e: # noqa: BLE001 — the poll never raises
3879
+ error = f"{type(e).__name__}: {e}"
3880
+ rows.append(
3881
+ {
3882
+ "kind": "relocate",
3883
+ "project": p,
3884
+ "phase": "rekey+rehash",
3885
+ "running": not done,
3886
+ "complete": done and error is None,
3887
+ "error": error,
3888
+ "done": state.get("done", 0),
3889
+ "total": state.get("total", 0),
3890
+ "citations_rewritten": state.get("citations", 0),
3891
+ "mount_renamed": state.get("mount") or [],
3892
+ }
3893
+ )
3894
+ for p, meta in sorted(self.code_jobs.items()):
3895
+ if proj is not None and p != proj:
3896
+ continue
3897
+ sw = self.code.sweeps.get(p) or {}
3898
+ done = meta["task"].done()
3899
+ rows.append(
3900
+ {
3901
+ "kind": "code_index",
3902
+ "project": p,
3903
+ "phase": "extract+describe+embed",
3904
+ "running": not done,
3905
+ "complete": done,
3906
+ "done": sw.get("done"),
3907
+ "total": sw.get("total"),
3908
+ **({"line": sw.get("line")} if sw.get("line") else {}),
3909
+ }
3910
+ )
3911
+ for p in sorted(self.code.sweeps):
3912
+ if p in self.code_jobs or (proj is not None and p != proj):
3913
+ continue
3914
+ sw = self.code.sweeps[p] or {}
3915
+ rows.append(
3916
+ {
3917
+ "kind": "code_index",
3918
+ "project": p,
3919
+ "phase": "sweep (no live call; project_index re-invokes to join)",
3920
+ "running": sw.get("running", True),
3921
+ "complete": False,
3922
+ "done": sw.get("done"),
3923
+ "total": sw.get("total"),
3924
+ }
3925
+ )
3926
+ if self._reconcile_remaining is not None:
3927
+ rows.append(
3928
+ {
3929
+ "kind": "reconcile",
3930
+ "project": "ALL",
3931
+ "phase": "re-embed sweep",
3932
+ "running": True,
3933
+ "complete": False,
3934
+ "remaining": self._reconcile_remaining,
3935
+ }
3936
+ )
3937
+ return rows
3938
+
3850
3939
  def project_status(
3851
3940
  self, project: str | None = None, cwd: Path | None = None
3852
3941
  ) -> dict[str, Any]:
3853
3942
  """Is this project code-indexed? symbol/file counts, kind breakdown, the
3854
- `.crib` source paths — for orienting before setup/index."""
3943
+ `.crib` source paths — for orienting before setup/index. Also the POLL
3944
+ surface for long-running jobs (see `jobs`)."""
3855
3945
  from collections import Counter
3856
3946
 
3857
3947
  from .codeindex import SymbolIndex
@@ -3883,6 +3973,11 @@ class Crib:
3883
3973
  # live reindex progress ({done,total}) while a sweep runs — the poll signal
3884
3974
  # for a budgeted project_index that returned complete=False
3885
3975
  "indexing": self.code.sweeps.get(proj),
3976
+ # the non-blocking poll section: every long-running job for this
3977
+ # project (relocate rekey, code sweep, reconcile) — running/
3978
+ # complete/failed + the counts already banked. NEVER errors, never
3979
+ # blocks; this is what the model polls instead of waiting.
3980
+ "jobs": self._job_rows(proj),
3886
3981
  "doc_sources": srcs,
3887
3982
  "doc_chunks": doc_count,
3888
3983
  "crib": (str(link.root / ".crib") if link and link.root else None),
crib/server.py CHANGED
@@ -853,10 +853,9 @@ def build_server(crib: Crib | None = None):
853
853
  `project_path=<the repo dir>` (a `.crib` is auto-created if missing); a bare
854
854
  `project=<name>` re-indexes an ALREADY-INDEXED project from its recorded root.
855
855
 
856
- Emits PROGRESS markers while the sweep runs (`<proj>: 42/317 files (13%) ·
857
- 2.1/s · eta 2:05`), so a long index streams live progress and doesn't
858
- idle-time-out — and the rate/eta is what a client needs to size its call
859
- timeout instead of guessing. It runs to completion in one call.
856
+ Emits PROGRESS markers while the sweep runs (`<proj>: 42/317 files (13%) ·
857
+ 2.1/s · eta 2:05`) — the call returns when the sweep completes; while it
858
+ runs, `project_status`'s `jobs` section is the non-blocking poll.
860
859
  (`project_status` also carries the live `indexing` counts.) If your client
861
860
  enforces a hard call timeout anyway, two levers:
862
861
  - `wait_s=<seconds>` bounds THIS call: the final result if the sweep
@@ -938,20 +937,19 @@ def build_server(crib: Crib | None = None):
938
937
  keep_prefix: bool = False,
939
938
  ) -> dict[str, Any]:
940
939
  """The move-and-rename verb: a repo project's checkout was moved and/or
941
- renamed on this machine (works after the fact — the old path may be gone).
942
- Re-points everything that recorded the OLD absolute path AND, when the
943
- directory was renamed, re-homes the `sources/<old-name>/` mount prefix to
944
- `sources/<new-name>/…`: the doc chunks rekey (project+relpath hash — the
945
- rare verb's re-embed cost, same class as project_rename) and every
946
- citation in THIS project's notes is rewritten to the new spelling (the
947
- prior note stashed to the ring first). The code index's .source_root and
948
- this repo's own .crib `project:` line (when it names the pre-rename name,
949
- fenced by dead-source evidence) are rewritten; the code + docs rehash at
950
- the new path runs at the end (cheap, content-hash gate). Foreign sites are
951
- REPORTED, not edited (other projects citing this repo). Pass
952
- project=<name> AND project_path=<the repo's new dir>; source=<segment>
953
- disambiguates dead in-situ sources; keep_prefix=true = identity-keeping
954
- only (citations keep spelling the old dir name)."""
940
+ renamed on this machine (works after the fact — the old path may be gone,
941
+ the project renamed, an earlier relocate cut halfway — re-invoke RESUMES).
942
+ The fast half (code-index .source_root, doc-source mounts, the repo's own
943
+ .crib line when it names the pre-rename name, an in-repo store stub) is
944
+ re-pointed at once and idempotent. The HEAVY half — re-homing the
945
+ `sources/<old>/` mount when the DIR was renamed (doc chunks rekey +
946
+ re-embed; every citation in THIS project's notes rewritten to the new
947
+ spelling) — runs as a DAEMON-OWNED job: the call returns a RUNNING HALF
948
+ at once with `progress` + `resume_hint`. DON'T WAIT: poll `project_status`
949
+ (its `jobs` section carries live done/total + the banked counts);
950
+ re-invoking the verb joins when the job is still running. A trailing CODE
951
+ rehash sweep joins too — never an error. keep_prefix=true = identity-
952
+ keeping only. Foreign sites are REPORTED, not edited."""
955
953
  return await crib.project_relocate(project, project_path, source, keep_prefix)
956
954
 
957
955
  @crib_tool("source")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: cribsheet
3
- Version: 0.21.2-dev2
3
+ Version: 0.21.2-dev4
4
4
  Summary: Local MCP server: markdown memory with a Chroma embedding index
5
5
  Requires-Python: >=3.13
6
6
  Requires-Dist: chromadb>=0.5
@@ -1,6 +1,6 @@
1
1
  crib/__init__.py,sha256=zj2qVJwYgLInI0Ie2N4NeJQw1ltiUhCM6_umP4skhcg,1005
2
2
  crib/__main__.py,sha256=umIc03A2oA7s2oiL80Ts_QnS-0zj9fjV3IQ103AmNXg,232
3
- crib/app.py,sha256=plHssTkeyttn3JNYj6hckzNQWgKAhyUU38egWIyR1rE,248675
3
+ crib/app.py,sha256=pi8gEo5p_yhj2mPd-K9cPMtEO8-WPLz_g5Fjgy32vzo,252993
4
4
  crib/chunk.py,sha256=GDGpmVE7JhP7zVy0TzbCBSRO0PnQUIXQISsxkC7SWKA,13653
5
5
  crib/claudemem.py,sha256=Xf4mVgTFbXHdhhqteTIRz2zirc4irf0wim8AeMybudI,4804
6
6
  crib/cli.py,sha256=3CbIsTe605koilnaW-KUwIS61Uc9NT9zC-zGsyRg8gc,139498
@@ -28,7 +28,7 @@ crib/project_services.py,sha256=dOPz7RUdw_QS9AeR18d2gcnk6Z9JzeK9nRiFafF_IuI,2112
28
28
  crib/refs.py,sha256=A42tIAg2vsgjp4r7Gdp1PyfmWm46jcnde9j_DfUpxo8,13106
29
29
  crib/retrieve.py,sha256=eeRiI1oE_02H_i_qDsS6804RvBpvh4BkwD-HYcQo35c,22149
30
30
  crib/section_index.py,sha256=nhFEZQBjlfV9y5fpB39Rp5RPFHLnp2nhZbAG8S7fUNg,8846
31
- crib/server.py,sha256=kt-lwN6MVKo68Tl-fwG-g-QyEYdFQIiQbwUw-9r7l-Y,118555
31
+ crib/server.py,sha256=3ywaAp-q1oZq7isVjkpmShjhkQn_0wnlAcwMbh5lFRM,118399
32
32
  crib/session.py,sha256=HMF_6n6ZIPY3p8mRJfMJ75iByKOoPIUvUJST1r8sSOQ,13631
33
33
  crib/sharedserver.py,sha256=SLGcF3Iax5ThPiFyCJ9ahs3movG-p5nNk0n8dahgWQo,1919
34
34
  crib/sources.py,sha256=gJNhRQeLTKC7v_KSSVGy7kaYgj_9iWJyz_Yd9W8512Q,2918
@@ -39,7 +39,7 @@ crib/tomlrec.py,sha256=ptDbYNhTLmXQeN1BrQGcy2E4wNv0hpKM7aayQ7WvkxE,3796
39
39
  crib/util.py,sha256=pf2iB3cvMC8JG5JJo7vH0t-7qy-d9ABHuSP7AJInauE,3018
40
40
  crib/versions.py,sha256=qFjPG9iFOEyRZ6K5CESM87JvbV1qf4tQoUIvqz-nADk,3621
41
41
  crib/watch.py,sha256=KpH-ipA-wkJVTxeghzM-Y9ljMAyrPxnmMumj3TNchmg,24303
42
- cribsheet-0.21.2.dev2.dist-info/METADATA,sha256=_DWEDLCODXbj5lJvfOfsYS4qvGSG6DYYIeAJHTOZELI,18790
43
- cribsheet-0.21.2.dev2.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
44
- cribsheet-0.21.2.dev2.dist-info/entry_points.txt,sha256=CjLxgcZdPGI6U4VRZmrwQ2kL1gUkNykYNkLzT8EQkfQ,39
45
- cribsheet-0.21.2.dev2.dist-info/RECORD,,
42
+ cribsheet-0.21.2.dev4.dist-info/METADATA,sha256=l3TJdunKdeWALa-OanzZr-3AtWGbbQYADxoCsPDt0YI,18790
43
+ cribsheet-0.21.2.dev4.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
44
+ cribsheet-0.21.2.dev4.dist-info/entry_points.txt,sha256=CjLxgcZdPGI6U4VRZmrwQ2kL1gUkNykYNkLzT8EQkfQ,39
45
+ cribsheet-0.21.2.dev4.dist-info/RECORD,,