sourcecode 1.33.1__py3-none-any.whl → 1.33.2__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.
sourcecode/__init__.py CHANGED
@@ -1,3 +1,3 @@
1
1
  """sourcecode — Deterministic codebase context maps for AI coding agents."""
2
2
 
3
- __version__ = "1.33.1"
3
+ __version__ = "1.33.2"
sourcecode/cache.py CHANGED
@@ -57,6 +57,7 @@ import hashlib
57
57
  import json
58
58
  import os
59
59
  import re
60
+ import subprocess
60
61
  from datetime import datetime, timezone
61
62
  from pathlib import Path
62
63
  from typing import Any, Optional
@@ -110,6 +111,24 @@ _CORE_RE = re.compile(r"^core-([0-9a-f]+)-[0-9a-f]+\.json\.gz$")
110
111
  _VIEW_RE = re.compile(r"^view-([0-9a-f]{16})-[0-9a-f]+\.json\.gz$")
111
112
 
112
113
 
114
+ # ---------------------------------------------------------------------------
115
+ # Internal helpers
116
+ # ---------------------------------------------------------------------------
117
+
118
+ def _get_git_head(repo_root: Path) -> str:
119
+ """Return short git HEAD SHA, or '' on any error."""
120
+ try:
121
+ r = subprocess.run(
122
+ ["git", "-C", str(repo_root), "rev-parse", "--short", "HEAD"],
123
+ capture_output=True, text=True, timeout=2,
124
+ )
125
+ if r.returncode == 0:
126
+ return r.stdout.strip()
127
+ except Exception:
128
+ pass
129
+ return ""
130
+
131
+
113
132
  # ---------------------------------------------------------------------------
114
133
  # Public API — location helpers
115
134
  # ---------------------------------------------------------------------------
@@ -138,15 +157,51 @@ def cache_dir(repo_root: Path) -> Path:
138
157
  def status(repo_root: Path) -> dict[str, Any]:
139
158
  """Return a stats dict describing the current cache state for *repo_root*.
140
159
 
141
- Keys: ``cache_dir``, ``cores``, ``snapshots``, ``views``, ``cas_blobs``,
142
- ``total_size_bytes``, ``total_size_mb``.
160
+ Keys: ``cache_dir``, ``cores``, ``views``, ``cas_blobs``,
161
+ ``total_size_bytes``, ``total_size_mb``, ``ris_exists``, ``ris_git_head``,
162
+ ``ris_last_updated_at``, ``ris_is_stale``, ``current_git_head``.
163
+
164
+ Note: ``snapshots`` is a legacy v1 field — always 0 in v2 (kept for
165
+ backward compatibility; v2 writes ``core-*`` and ``view-*`` files only).
143
166
  """
144
167
  cache_d = cache_dir(repo_root)
168
+ current_head = _get_git_head(repo_root)
169
+
170
+ # RIS metadata (lazy import to avoid circular dependency)
171
+ ris_fields: dict[str, Any]
172
+ try:
173
+ from sourcecode.ris import load_ris as _load_ris # noqa: PLC0415
174
+ _ris = _load_ris(repo_root)
175
+ if _ris is not None:
176
+ _ris_stale = bool(current_head and _ris.git_head and current_head != _ris.git_head)
177
+ ris_fields = {
178
+ "ris_exists": True,
179
+ "ris_git_head": _ris.git_head,
180
+ "ris_last_updated_at": _ris.last_updated_at,
181
+ "ris_is_stale": _ris_stale,
182
+ }
183
+ else:
184
+ ris_fields = {
185
+ "ris_exists": False,
186
+ "ris_git_head": None,
187
+ "ris_last_updated_at": None,
188
+ "ris_is_stale": False,
189
+ }
190
+ except Exception:
191
+ ris_fields = {
192
+ "ris_exists": False,
193
+ "ris_git_head": None,
194
+ "ris_last_updated_at": None,
195
+ "ris_is_stale": False,
196
+ }
197
+
145
198
  if not cache_d.exists():
146
199
  return {
147
200
  "cache_dir": str(cache_d),
148
201
  "cores": 0, "snapshots": 0, "views": 0, "cas_blobs": 0,
149
202
  "total_size_bytes": 0, "total_size_mb": 0.0,
203
+ "current_git_head": current_head,
204
+ **ris_fields,
150
205
  }
151
206
  cores = list(cache_d.glob("core-*.json.gz"))
152
207
  snapshots = list(cache_d.glob("snapshot-*.json.gz"))
@@ -162,11 +217,18 @@ def status(repo_root: Path) -> dict[str, Any]:
162
217
  "cas_blobs": len(cas_blobs),
163
218
  "total_size_bytes": total_bytes,
164
219
  "total_size_mb": round(total_bytes / (1024 * 1024), 2),
220
+ "current_git_head": current_head,
221
+ **ris_fields,
165
222
  }
166
223
 
167
224
 
168
- def clear(repo_root: Path) -> int:
169
- """Delete all cache files for *repo_root*. Returns the number of files removed."""
225
+ def clear(repo_root: Path, *, clear_ris: bool = False) -> int:
226
+ """Delete cache files for *repo_root*. Returns the number of files removed.
227
+
228
+ By default, RIS (``ris.json.gz``) is preserved across clears — it is the
229
+ persistent structural index used by cold-start bootstrapping. Pass
230
+ ``clear_ris=True`` (CLI: ``--include-ris``) to also delete the RIS.
231
+ """
170
232
  cache_d = cache_dir(repo_root)
171
233
  if not cache_d.exists():
172
234
  return 0
@@ -180,6 +242,11 @@ def clear(repo_root: Path) -> int:
180
242
  for f in cas_d.glob("*.gz"):
181
243
  _safe_unlink(f)
182
244
  removed += 1
245
+ if clear_ris:
246
+ ris_file = cache_d / "ris.json.gz"
247
+ if ris_file.exists():
248
+ _safe_unlink(ris_file)
249
+ removed += 1
183
250
  return removed
184
251
 
185
252
 
sourcecode/cli.py CHANGED
@@ -1058,6 +1058,22 @@ def main(
1058
1058
  code_notes = True
1059
1059
  architecture = True
1060
1060
 
1061
+ def _inject_cache_meta(raw: str, meta: dict) -> str:
1062
+ """Inject ``_cache`` provenance block into a JSON dict string.
1063
+
1064
+ Parses *raw* as JSON, adds ``_cache`` key, re-serialises. Returns *raw*
1065
+ unchanged on any parse failure or non-dict JSON (YAML pass-through, etc.).
1066
+ """
1067
+ try:
1068
+ import json as _jm
1069
+ obj = _jm.loads(raw)
1070
+ if isinstance(obj, dict):
1071
+ obj["_cache"] = meta
1072
+ return _jm.dumps(obj, indent=2, ensure_ascii=False)
1073
+ except Exception:
1074
+ pass
1075
+ return raw
1076
+
1061
1077
  # ── Two-layer cache ────────────────────────────────────────────────────────
1062
1078
  # L1 (core): (repo, commit, analysis_flags) → pre-computed view data dict
1063
1079
  # key = core-<git_sha>-<analysis_hash>.json.gz
@@ -1202,6 +1218,23 @@ def main(
1202
1218
 
1203
1219
  if _cache_hit_content is not None:
1204
1220
  from sourcecode.serializer import write_output
1221
+ if format == "json":
1222
+ try:
1223
+ from sourcecode.ris import _has_uncommitted_changes as _huc
1224
+ _uncommitted = _huc(target)
1225
+ except Exception:
1226
+ _uncommitted = False
1227
+ _hit_source = "L2_view" if (_view_key and _core_hash) else "L1_core"
1228
+ _data_scope = "COMPACT" if compact else ("AGENT" if agent else "FULL")
1229
+ _cache_hit_content = _inject_cache_meta(_cache_hit_content, {
1230
+ "cache_source": _hit_source,
1231
+ "git_head_at_generation": _git_sha,
1232
+ "current_git_head": _git_sha,
1233
+ "is_stale": False,
1234
+ "has_uncommitted_changes": _uncommitted,
1235
+ "generated_at": None,
1236
+ "data_scope": _data_scope,
1237
+ })
1205
1238
  write_output(_cache_hit_content, output=output)
1206
1239
  if copy and not output:
1207
1240
  _copy_to_clipboard(_cache_hit_content)
@@ -2082,6 +2115,23 @@ def main(
2082
2115
 
2083
2116
  # 6. Write output (CLI-04)
2084
2117
  _progress.finish()
2118
+ if format == "json":
2119
+ try:
2120
+ from sourcecode.ris import _has_uncommitted_changes as _huc_fresh
2121
+ _uncommitted_fresh = _huc_fresh(target)
2122
+ except Exception:
2123
+ _uncommitted_fresh = False
2124
+ import datetime as _dt
2125
+ _data_scope_fresh = "COMPACT" if compact else ("AGENT" if agent else "FULL")
2126
+ content = _inject_cache_meta(content, {
2127
+ "cache_source": "fresh",
2128
+ "git_head_at_generation": _git_sha,
2129
+ "current_git_head": _git_sha,
2130
+ "is_stale": False,
2131
+ "has_uncommitted_changes": _uncommitted_fresh,
2132
+ "generated_at": _dt.datetime.now(_dt.timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"),
2133
+ "data_scope": _data_scope_fresh,
2134
+ })
2085
2135
  write_output(content, output=output)
2086
2136
 
2087
2137
  # Persist to two-layer cache (git SHA unchanged → re-use on next run).
@@ -4231,23 +4281,36 @@ def cache_status_cmd(
4231
4281
  else:
4232
4282
  typer.echo(f"Cache dir: {stats['cache_dir']}")
4233
4283
  typer.echo(f"Cores: {stats['cores']}")
4234
- typer.echo(f"Snapshots: {stats['snapshots']}")
4235
4284
  typer.echo(f"Views: {stats['views']}")
4236
4285
  typer.echo(f"CAS blobs: {stats['cas_blobs']}")
4237
4286
  typer.echo(f"Total size: {stats['total_size_mb']} MB")
4287
+ # RIS section
4288
+ if stats.get("ris_exists"):
4289
+ _stale_tag = " [STALE]" if stats.get("ris_is_stale") else ""
4290
+ typer.echo(f"RIS: exists HEAD={stats.get('ris_git_head', '?')}{_stale_tag} updated={stats.get('ris_last_updated_at', '?')}")
4291
+ else:
4292
+ typer.echo("RIS: none (run analysis to build)")
4293
+ if stats.get("current_git_head"):
4294
+ typer.echo(f"Current HEAD:{stats['current_git_head']}")
4238
4295
 
4239
4296
 
4240
4297
  @cache_app.command("clear")
4241
4298
  def cache_clear_cmd(
4242
4299
  path: Path = typer.Argument(Path("."), help="Repository path (default: current directory)"),
4243
4300
  yes: bool = typer.Option(False, "--yes", "-y", help="Skip confirmation prompt."),
4301
+ include_ris: bool = typer.Option(False, "--include-ris", help="Also delete the RIS snapshot (ris.json.gz). By default, RIS is preserved across clears."),
4244
4302
  ) -> None:
4245
- """Delete all cached snapshots for a repository."""
4303
+ """Delete cached snapshots for a repository.
4304
+
4305
+ By default, RIS (ris.json.gz) is preserved — it is the persistent structural
4306
+ index used for cold-start bootstrapping. Use --include-ris to also clear it.
4307
+ """
4246
4308
  from sourcecode import cache as _cm
4247
4309
  target = Path(path).resolve()
4248
4310
  if not yes:
4249
- typer.confirm(f"Delete all cache files for {target}?", abort=True)
4250
- removed = _cm.clear(target)
4311
+ _ris_note = " (including RIS)" if include_ris else " (RIS preserved — use --include-ris to also clear it)"
4312
+ typer.confirm(f"Delete all cache files for {target}{_ris_note}?", abort=True)
4313
+ removed = _cm.clear(target, clear_ris=include_ris)
4251
4314
  typer.echo(f"Removed {removed} file(s).")
4252
4315
 
4253
4316
 
sourcecode/ris.py CHANGED
@@ -349,6 +349,26 @@ def _current_git_head(repo_root: Path) -> str:
349
349
  return ""
350
350
 
351
351
 
352
+ def _has_uncommitted_changes(repo_root: Path) -> bool:
353
+ """Return True if working tree has staged or unstaged changes.
354
+
355
+ Uses ``git status --porcelain`` — any non-empty output means the working
356
+ tree diverges from HEAD. Returns False on any error (non-git dirs, etc.).
357
+ """
358
+ try:
359
+ result = subprocess.run(
360
+ ["git", "-C", str(repo_root), "status", "--porcelain"],
361
+ capture_output=True,
362
+ text=True,
363
+ timeout=2,
364
+ )
365
+ if result.returncode == 0:
366
+ return bool(result.stdout.strip())
367
+ except Exception:
368
+ pass
369
+ return False
370
+
371
+
352
372
  def get_cold_start_context(repo_root: Path) -> dict:
353
373
  """Return a lightweight bootstrap object from the persisted RIS.
354
374
 
@@ -361,14 +381,19 @@ def get_cold_start_context(repo_root: Path) -> dict:
361
381
 
362
382
  current_head = _current_git_head(repo_root)
363
383
  stale = bool(current_head and ris.git_head and current_head != ris.git_head)
384
+ uncommitted = _has_uncommitted_changes(repo_root)
364
385
 
365
386
  endpoints = ris.api_surface.get("endpoints", [])
366
387
  result: dict = {
367
388
  "status": "cold_start_stale" if stale else "cold_start_ready",
368
389
  "repo_id": ris.repo_id,
369
390
  "git_head": ris.git_head,
391
+ "current_git_head": current_head,
370
392
  "stale": stale,
393
+ "has_uncommitted_changes": uncommitted,
371
394
  "last_updated_at": ris.last_updated_at,
395
+ "cache_source": "RIS",
396
+ "data_scope": "RIS_BOOTSTRAP",
372
397
  "summary": ris.compact_summary,
373
398
  "entrypoints": ris.structural_map.get("entrypoints", []),
374
399
  "endpoints": endpoints,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sourcecode
3
- Version: 1.33.1
3
+ Version: 1.33.2
4
4
  Summary: Persistent structural context and ultra-fast repeated analysis for AI coding agents
5
5
  License-File: LICENSE
6
6
  Keywords: agents,ai,codebase,context,developer-tools,llm
@@ -39,7 +39,7 @@ Description-Content-Type: text/markdown
39
39
 
40
40
  **Persistent structural context and ultra-fast repeated analysis for AI coding agents.**
41
41
 
42
- ![Version](https://img.shields.io/badge/version-1.33.1-blue)
42
+ ![Version](https://img.shields.io/badge/version-1.33.2-blue)
43
43
  ![Python](https://img.shields.io/badge/python-3.10%2B-green)
44
44
 
45
45
  ---
@@ -113,7 +113,7 @@ pipx install sourcecode
113
113
 
114
114
  ```bash
115
115
  sourcecode version
116
- # sourcecode 1.33.1
116
+ # sourcecode 1.33.2
117
117
  ```
118
118
 
119
119
  ---
@@ -1,13 +1,13 @@
1
- sourcecode/__init__.py,sha256=etbaHEAFq4Y5ytZacDtpQYJt_hteBOpOxKlJl-EIGJY,103
1
+ sourcecode/__init__.py,sha256=tN8Xe7UyyVpCOi0lC9IYgThLHlUY6kso5Yf2r_0OwA0,103
2
2
  sourcecode/adaptive_scanner.py,sha256=XffluXKzJUXrMtjEiAOnSNPZnztdIcts17T9ouHeID0,10521
3
3
  sourcecode/architecture_analyzer.py,sha256=qh749a7ykPtGmQI1MR9y6j8TtL_jBdVYFx9YRsLqOMw,44121
4
4
  sourcecode/architecture_summary.py,sha256=z34_6v7cSwy98cof2UVciGho7SCrZ93tiqMmq5WNzRQ,20405
5
5
  sourcecode/ast_extractor.py,sha256=_btmeOJIe3t-NicF94D5ZAesa2YIJ0_QNExGnbHxGFE,50578
6
- sourcecode/cache.py,sha256=h1BT-9PG_7HK---ZzH0j5u3PN0dz2s6IRAUOjQIPYH4,28055
6
+ sourcecode/cache.py,sha256=wAyPrXN5DqiGivnMpeEuun2xHDKfBer2_oBsh6kj_vc,30447
7
7
  sourcecode/cache.tmp_new,sha256=-IvV7CojiZjqeKMln1m-lqI0QVA2uFGWmYir4XRFOUk,27970
8
8
  sourcecode/canonical_ir.py,sha256=_HM3AUmKSdna9u4dCoU6rpgSA6HdF8gzOKZykIUCNGY,23277
9
9
  sourcecode/classifier.py,sha256=2lYoSH3vOTkXZYPU7Go2WIet1-IuNzTWVhc-ULnXtgw,8024
10
- sourcecode/cli.py,sha256=aoy3H0QhffBj6CLMGHDMlhtW2TQOwrJfK8LFEsajJFM,173536
10
+ sourcecode/cli.py,sha256=rtQ4Bx4L82G0vuSPz1Iabu1azPwF3vuNiAZVxQSvXrQ,176581
11
11
  sourcecode/code_notes_analyzer.py,sha256=EJemNCNc9Dn-1RZYu-aNbK0ELzmsyC4s6FdHi3XyNEI,9392
12
12
  sourcecode/confidence_analyzer.py,sha256=_jckZSxksV-OU38vbkxfVNBnWCtlCq8Vwfg23x1uspA,19054
13
13
  sourcecode/context_scorer.py,sha256=QpChSpsmaAYz91rXA4Ue5xzQmNz_ZboZN09YOHScq1U,14679
@@ -36,7 +36,7 @@ sourcecode/redactor.py,sha256=SB4hwIvg8h-hvcqKcDWaZvA-aSyn-at-BIRwa0tUv5E,3227
36
36
  sourcecode/relevance_scorer.py,sha256=MYF4FFkveAQps9SmTeTlh6ODiBz2F--_hWNeHMLtUHQ,8405
37
37
  sourcecode/repo_classifier.py,sha256=FG1vaWKdWXsWdl-S8hjVMiTqcwgaRXkDyvK4rPcOGtQ,22681
38
38
  sourcecode/repository_ir.py,sha256=-NjBQUT7zyya4ng8Hq0-ChoiHZkUif9lr-Q878gmj8M,153163
39
- sourcecode/ris.py,sha256=2pQcNN-5akweoBjjWAk_x3QpJ06wukQInmMlMj7WxwI,14737
39
+ sourcecode/ris.py,sha256=dAzD8suyQyq_gixQbgzFiIzeFBfONJ6A54qd44vOwMc,15595
40
40
  sourcecode/runtime_classifier.py,sha256=uTAD6BDCiBLUZEDRfqk718kM4RTT_vAbfkcOI2_Xx58,18432
41
41
  sourcecode/scanner.py,sha256=WdOQ78mMzjR1NjmKTlbxdgwinnCTfAhxCVLBEFQiFHU,8899
42
42
  sourcecode/schema.py,sha256=aHNXDf8LGyUC8ZDE_VS9kiskC2-Oswhi_WnpdGy6HDw,24897
@@ -80,8 +80,8 @@ sourcecode/telemetry/consent.py,sha256=wLMvGNJeSSyZoNkQXpoUioY6mMv4Qdvuw7S9jAEWn
80
80
  sourcecode/telemetry/events.py,sha256=oEvvulfsv5GIDWG2174gSS6tNB95w38AIYiYeifGKlE,2294
81
81
  sourcecode/telemetry/filters.py,sha256=Asa71oRl7q3Wt_FMwuufIZJFzSYdgRNKS8LHCIyFeYE,4805
82
82
  sourcecode/telemetry/transport.py,sha256=KJeIPCPWMdmbCP3ySGs2iUlia34U6vWne2dZsUezesw,1560
83
- sourcecode-1.33.1.dist-info/METADATA,sha256=NqcQIRQo2sldQvv32_3mF9QUqPAxJR5LO4kgdBaojY0,16440
84
- sourcecode-1.33.1.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
85
- sourcecode-1.33.1.dist-info/entry_points.txt,sha256=ex3F9rmbXeyDIoFQHtkEqTsKSaJow8F0LrVu8XfIktQ,57
86
- sourcecode-1.33.1.dist-info/licenses/LICENSE,sha256=7DdHrU9Z_3e7dSvq4ISijZNjnuHo5NIHNiHDouMQ9JU,10491
87
- sourcecode-1.33.1.dist-info/RECORD,,
83
+ sourcecode-1.33.2.dist-info/METADATA,sha256=5ow3o68xzE1c77dH1MfolgnmPKRepCxBGOtZco3luV8,16440
84
+ sourcecode-1.33.2.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
85
+ sourcecode-1.33.2.dist-info/entry_points.txt,sha256=ex3F9rmbXeyDIoFQHtkEqTsKSaJow8F0LrVu8XfIktQ,57
86
+ sourcecode-1.33.2.dist-info/licenses/LICENSE,sha256=7DdHrU9Z_3e7dSvq4ISijZNjnuHo5NIHNiHDouMQ9JU,10491
87
+ sourcecode-1.33.2.dist-info/RECORD,,