sourcecode 1.24.0__py3-none-any.whl → 1.26.0__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.24.0"
3
+ __version__ = "1.26.0"
sourcecode/cli.py CHANGED
@@ -1773,6 +1773,25 @@ def prepare_context_cmd(
1773
1773
  out["affected_entry_points"] = output.affected_entry_points
1774
1774
  # Delta-specific impact fields
1775
1775
  if task == "delta":
1776
+ if output.error_code:
1777
+ # Hard error — emit structured error JSON and exit, skip normal delta fields
1778
+ _err_out: dict[str, Any] = {
1779
+ "task": output.task,
1780
+ "error": output.error_code,
1781
+ "since": output.since,
1782
+ "message": output.error_message,
1783
+ }
1784
+ if output.error_hints:
1785
+ _err_out["hint"] = output.error_hints
1786
+ _err_json = json.dumps(_err_out, indent=2, ensure_ascii=False)
1787
+ if output_path is not None:
1788
+ output_path.write_text(_err_json, encoding="utf-8")
1789
+ else:
1790
+ import sys as _sys
1791
+ _sys.stdout.buffer.write(_err_json.encode("utf-8"))
1792
+ _sys.stdout.buffer.write(b"\n")
1793
+ _sys.stdout.buffer.flush()
1794
+ raise typer.Exit(code=1)
1776
1795
  if output.since:
1777
1796
  out["since"] = output.since
1778
1797
  if output.impact_summary:
@@ -333,6 +333,10 @@ class TaskOutput:
333
333
  change_type: list[str] = field(default_factory=list)
334
334
  dependency_graph_summary: dict = field(default_factory=dict)
335
335
  impact_score_per_file: dict = field(default_factory=dict)
336
+ # error state (git ref not found, etc.)
337
+ error_code: Optional[str] = None
338
+ error_message: Optional[str] = None
339
+ error_hints: list[str] = field(default_factory=list)
336
340
 
337
341
 
338
342
  # ─────────────────────────────────────────────────────────────────────────────
@@ -618,7 +622,34 @@ class TaskContextBuilder:
618
622
  _delta_files: Optional[set[str]] = None
619
623
  if task_name == "delta":
620
624
  _delta_raw = self._get_git_changed_files(since=since)
621
- if _delta_raw:
625
+ if _delta_raw is None:
626
+ # Explicit --since ref couldn't be resolved — hard error, no fallback
627
+ _avail_branches, _suggested = self._get_available_refs(since or "")
628
+ _hints: list[str] = []
629
+ if _suggested:
630
+ _hints.append(f"Did you mean '{_suggested}'?")
631
+ if _avail_branches:
632
+ _hints.append(f"Available refs: {', '.join(_avail_branches[:8])}")
633
+ return TaskOutput(
634
+ task="delta",
635
+ goal="Produce incremental context for changed files — avoids re-reading the full repo.",
636
+ project_summary=None,
637
+ architecture_summary=None,
638
+ relevant_files=[],
639
+ suspected_areas=[],
640
+ improvement_opportunities=[],
641
+ test_gaps=[],
642
+ key_dependencies=[],
643
+ code_notes_summary=None,
644
+ limitations=[],
645
+ confidence="low",
646
+ since=since,
647
+ error_code="git_ref_not_found",
648
+ error_message=f"Git reference '{since}' does not exist in this repository.",
649
+ error_hints=_hints,
650
+ gaps=[f"Cannot compute delta: git ref '{since}' not found."] + _hints,
651
+ )
652
+ elif _delta_raw:
622
653
  _delta_files = set(_delta_raw)
623
654
 
624
655
  # ── 5c. review-pr suspected_areas (needs git uncommitted_files) ──────
@@ -2087,9 +2118,13 @@ class TaskContextBuilder:
2087
2118
  impact_score_per_file,
2088
2119
  )
2089
2120
 
2090
- def _get_git_changed_files(self, since: Optional[str] = None) -> list[str]:
2121
+ def _get_git_changed_files(self, since: Optional[str] = None) -> Optional[list[str]]:
2091
2122
  """Get files changed since a git ref (default: HEAD~1) relative to self.root.
2092
2123
 
2124
+ Returns None when `since` is explicitly provided but cannot be resolved —
2125
+ this is an error state, not "no changes". Callers must distinguish None
2126
+ (ref invalid) from [] (ref valid, no changes).
2127
+
2093
2128
  Uses --relative so paths are relative to cwd (self.root), not the git repo
2094
2129
  root. This is critical for monorepos where self.root is a subpath of the
2095
2130
  git root and git diff would otherwise return prefixed paths that don't match
@@ -2112,9 +2147,13 @@ class TaskContextBuilder:
2112
2147
  line.strip() for line in (result.stdout or "").splitlines()
2113
2148
  if line.strip()
2114
2149
  ]
2150
+ # Non-zero exit with explicit ref = ref doesn't exist — no silent fallback
2151
+ if since:
2152
+ return None
2115
2153
  except (subprocess.TimeoutExpired, FileNotFoundError):
2116
- pass
2117
- # Fallback: uncommitted changes
2154
+ if since:
2155
+ return None
2156
+ # No explicit since: fall back to uncommitted changes
2118
2157
  try:
2119
2158
  result = subprocess.run(
2120
2159
  ["git", "diff", "--name-only", "--relative"],
@@ -2130,3 +2169,26 @@ class TaskContextBuilder:
2130
2169
  except (subprocess.TimeoutExpired, FileNotFoundError):
2131
2170
  pass
2132
2171
  return []
2172
+
2173
+ def _get_available_refs(self, invalid_ref: str) -> tuple[list[str], Optional[str]]:
2174
+ """Return (available_branch_names, suggested_alternative) for error hints."""
2175
+ import subprocess
2176
+ branches: list[str] = []
2177
+ suggested: Optional[str] = None
2178
+ try:
2179
+ r = subprocess.run(
2180
+ ["git", "branch", "-a", "--format=%(refname:short)"],
2181
+ cwd=str(self.root),
2182
+ capture_output=True, text=True, timeout=5,
2183
+ )
2184
+ if r.returncode == 0:
2185
+ all_refs = [b.strip() for b in r.stdout.splitlines() if b.strip()]
2186
+ branches = [b for b in all_refs if "HEAD" not in b][:10]
2187
+ ref_lower = invalid_ref.lower()
2188
+ if ref_lower == "master" and any(b.rstrip("/").endswith("main") for b in all_refs):
2189
+ suggested = "main"
2190
+ elif ref_lower == "main" and any(b.rstrip("/").endswith("master") for b in all_refs):
2191
+ suggested = "master"
2192
+ except (subprocess.TimeoutExpired, FileNotFoundError):
2193
+ pass
2194
+ return branches, suggested
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sourcecode
3
- Version: 1.24.0
3
+ Version: 1.26.0
4
4
  Summary: Deterministic codebase context for AI coding agents
5
5
  License: Apache License
6
6
  Version 2.0, January 2004
@@ -221,7 +221,7 @@ Description-Content-Type: text/markdown
221
221
 
222
222
  **Compressed AI-ready context for Java/Spring enterprise codebases.**
223
223
 
224
- ![Version](https://img.shields.io/badge/version-1.24.0-blue)
224
+ ![Version](https://img.shields.io/badge/version-1.26.0-blue)
225
225
  ![Python](https://img.shields.io/badge/python-3.10%2B-green)
226
226
 
227
227
  ---
@@ -255,7 +255,7 @@ pipx install sourcecode
255
255
 
256
256
  ```bash
257
257
  sourcecode version
258
- # sourcecode 1.24.0
258
+ # sourcecode 1.26.0
259
259
  ```
260
260
 
261
261
  ---
@@ -263,7 +263,7 @@ sourcecode version
263
263
  ## Quickstart
264
264
 
265
265
  ```bash
266
- # High-signal summary (~600-800 tokens) — recommended starting point
266
+ # High-signal summary (1000–3000 tokens depending on repo size) — recommended starting point
267
267
  sourcecode --compact
268
268
 
269
269
  # Add git hotspots and uncommitted file count
@@ -311,8 +311,9 @@ Example output for a Spring Boot project (`--compact`):
311
311
 
312
312
  | Flag | Alias | Default | Description |
313
313
  |------|-------|---------|-------------|
314
- | `--compact` | | off | **Recommended.** ~600-800 token summary: stack, entry points, dependencies, risk flags, confidence, gaps. Optimized for agent context windows. |
314
+ | `--compact` | | off | High-signal summary (1000–3000 tokens): stacks, entry points, dependencies, risk flags, confidence, gaps. Includes `security_surface`, `mybatis`, and `transactional_boundaries` for Java projects. |
315
315
  | `--agent` | | off | Structured noise-free JSON for AI agents: identity, entry points, dependencies, confidence, gaps. Auto-enables dependency, env-var, and code-notes analysis. |
316
+ | `--full` | | off | Remove truncation limits on `transactional_boundaries`, `mybatis.dto_mappers`, and other capped lists. |
316
317
  | `--git-context` | `-g` | off | Include git activity: recent commits, change hotspots, and uncommitted changes. |
317
318
  | `--changed-only` | | off | Limit output to git-modified files (staged, unstaged, untracked). Forces compact output. |
318
319
  | `--depth` | | `4` | File tree traversal depth (1–20). Java/Maven projects auto-adjust to 12. |
@@ -342,16 +343,18 @@ sourcecode prepare-context TASK [PATH] [OPTIONS]
342
343
  | `refactor` | Structural problems, improvement opportunities, high-annotation files | Code quality review |
343
344
  | `generate-tests` | Source files without test pairs, coverage gap analysis | Writing missing tests |
344
345
  | `review-pr` | Uncommitted/changed files + architectural impact | Pre-merge review |
345
- | `delta` | Only files changed in a git range (`--since`), affected entry points | Incremental CI context |
346
+ | `delta` | Changed files with multi-hop impact analysis, structural import graph, system-level impact summary | Incremental CI/review context |
346
347
 
347
348
  ### Options
348
349
 
349
350
  | Option | Description |
350
351
  |--------|-------------|
351
352
  | `--since REF` | Git ref for `delta` task (e.g. `HEAD~3`, `main`, `v1.2.0`). Required for `delta`; ignored for other tasks. |
353
+ | `--symptom TEXT` | *(fix-bug only)* Keyword hint for the bug — boosts matching files and surfaces related code notes. |
352
354
  | `--llm-prompt` | Append a ready-to-use LLM prompt to the output. |
353
355
  | `--dry-run` | Show what would be analyzed without running it. |
354
356
  | `--copy` / `-c` | Copy output to clipboard after a successful run. |
357
+ | `--output` / `-o` | Write output to a file. |
355
358
  | `--task-help` | List all tasks with descriptions and exit. |
356
359
 
357
360
  ### Examples
@@ -360,11 +363,8 @@ sourcecode prepare-context TASK [PATH] [OPTIONS]
360
363
  # Explain the current repo
361
364
  sourcecode prepare-context explain
362
365
 
363
- # Analyze a specific repo path
364
- sourcecode prepare-context explain /path/to/repo
365
-
366
- # Focus on bug-prone files
367
- sourcecode prepare-context fix-bug
366
+ # Focus on bug-prone files, with a symptom hint
367
+ sourcecode prepare-context fix-bug --symptom "NullPointerException in OrderService"
368
368
 
369
369
  # Incremental context: files changed since branch diverged from main
370
370
  sourcecode prepare-context delta . --since main
@@ -378,6 +378,51 @@ sourcecode prepare-context --task-help
378
378
 
379
379
  ---
380
380
 
381
+ ## `delta` — incremental impact analysis
382
+
383
+ The `delta` task is the recommended mode for CI pipelines and PR reviews. It goes beyond listing changed files: it builds a structural import graph and propagates impact transitively up to 3 hops.
384
+
385
+ ```bash
386
+ sourcecode prepare-context delta [PATH] --since REF
387
+ ```
388
+
389
+ **Output fields:**
390
+
391
+ | Field | Description |
392
+ |-------|-------------|
393
+ | `changed_files` | Files modified in the git range |
394
+ | `relevant_files` | Changed files + files pulled in by the import graph (scored by artifact type and hop distance) |
395
+ | `impact_summary` | Human-readable summary: artifact types changed and active risk areas |
396
+ | `affected_modules` | DDD domain modules touched by the change |
397
+ | `risk_areas` | Per-area severity breakdown (`security`, `api`, `persistence`, etc.) |
398
+ | `change_type` | Closed taxonomy: `behavioral_change`, `structural_change`, `configuration_change`, `dependency_change`, `security_change` |
399
+ | `system_impact` | Subsystems affected, behavioral changes, runtime impact notes |
400
+ | `dependency_graph_summary` | Verified structural import edges (hop 1–3) and `propagation_depth`. **Only real imports — no heuristics, no test files.** |
401
+ | `impact_score_per_file` | Per-file numeric impact score (0–1) |
402
+ | `since` | The git ref used |
403
+ | `gaps` | What the analysis could not determine |
404
+
405
+ **How the import graph works:**
406
+
407
+ 1. Each changed file is classified by artifact type (`controller`, `service`, `repository`, `security`, `spring_config`, etc.).
408
+ 2. A BFS traversal walks the import graph **repo-wide** (not restricted to the same module), up to 3 hops deep.
409
+ 3. `dependency_graph_summary.edges` only contains verified `import` / `@Autowired` / constructor-injection relationships. Test files and heuristic proximity matches are excluded from edges (they appear in `relevant_files` only if they have real imports of changed files).
410
+ 4. Score decays 30% per hop: a directly-changed `SecurityConfig.java` scores 0.90; its direct importer scores 0.63; a transitive importer scores 0.44.
411
+
412
+ ```bash
413
+ # Changed service → controller → facade (3 hops)
414
+ sourcecode prepare-context delta . --since main
415
+
416
+ # Output includes:
417
+ # dependency_graph_summary.edges:
418
+ # hop-1: OrderService.java → OrderRepository.java
419
+ # hop-2: OrderRepository.java → OrderController.java
420
+ # hop-3: OrderController.java → OrderFacade.java
421
+ # propagation_depth: 3
422
+ ```
423
+
424
+ ---
425
+
381
426
  ## Output schema
382
427
 
383
428
  All outputs include a `confidence_summary` block with `overall`, `stack`, and `entry_points` confidence levels (`high` / `medium` / `low`), plus an `analysis_gaps` list describing what could not be analyzed and why.
@@ -1,10 +1,10 @@
1
- sourcecode/__init__.py,sha256=vxwWVqF36gPPYD7_ynbN516dnvoYnfoHZMtsCp4YmrY,103
1
+ sourcecode/__init__.py,sha256=BGzpNPgLZVlNICE4wgxIlHjOfd9TkYGrEflyaIury4c,103
2
2
  sourcecode/adaptive_scanner.py,sha256=RTNExwWPXzjgLaRueT7UuxkPj5ZEToWjGbx1j0LSZ9E,10250
3
3
  sourcecode/architecture_analyzer.py,sha256=MyBa0Hf5HmkudZQDLKrjcWDKETXETXl0mQX1swtTwAA,39091
4
4
  sourcecode/architecture_summary.py,sha256=z34_6v7cSwy98cof2UVciGho7SCrZ93tiqMmq5WNzRQ,20405
5
5
  sourcecode/ast_extractor.py,sha256=XgrZg2DcWcUm9r87cRG3KGO7IK2TIL_N-CvhSbUmmh4,49901
6
6
  sourcecode/classifier.py,sha256=pYve2J1LqtYssU3lYLMDz18PT-CjN5c18QYE7R_IG1Q,7507
7
- sourcecode/cli.py,sha256=d2fAGBqy0xy2ubYe7TQ7oIgsMPPEfJj4W02_Gu_-d4M,76822
7
+ sourcecode/cli.py,sha256=cNEbkJISlXZf6h0-Jw9xlYCi3vyMY3I5NsCfl5emgUo,77707
8
8
  sourcecode/code_notes_analyzer.py,sha256=y1MJBnPZHYp4i6cQCXUb9ATIyifS_qMQWjw_8lPkpsU,9215
9
9
  sourcecode/confidence_analyzer.py,sha256=xw_Jv8pAd0wd8t2vvQlorw8Ih0rSF3YCoFS8K-_4aXg,15762
10
10
  sourcecode/context_scorer.py,sha256=QpChSpsmaAYz91rXA4Ue5xzQmNz_ZboZN09YOHScq1U,14679
@@ -20,7 +20,7 @@ sourcecode/file_classifier.py,sha256=48ly5Z6exkzBy8lNy1AkdP4-oJqIA1zT3LZfffuTyDo
20
20
  sourcecode/git_analyzer.py,sha256=_pCg2V4d2aa17k9hayTzpexAj8syvyk4y9NYNvvgOAI,12802
21
21
  sourcecode/graph_analyzer.py,sha256=iUK-7pSV-cvGqqD2hENdYmhnm0wcXFEyK-xnu5ul8OU,62515
22
22
  sourcecode/metrics_analyzer.py,sha256=m0ENgtqKeBL17kUIK3fmGkgo7UfXBNHxCMj0H_Y5K7c,22750
23
- sourcecode/prepare_context.py,sha256=G3zlB2HEQxje80t1Ds_1QJ_S54R_N-H9Ok84w68FqKM,103213
23
+ sourcecode/prepare_context.py,sha256=UFfEayK_94zl42r9KPU50PG8Z5FtvK48pNK3Fcxltj8,106340
24
24
  sourcecode/progress.py,sha256=qn30sWaHOkjTgXsSBmiPkz7Rsbwc5oSlIe6JNEMYp_k,3149
25
25
  sourcecode/ranking_engine.py,sha256=virVglafZufioHpZpwktjMvUiL0TZELWQCQnQNV8dFo,9360
26
26
  sourcecode/redactor.py,sha256=xuGcadGEHaPw4qZXlMDvzMCsr4VOkdp3oBQptHyJk8c,2884
@@ -61,8 +61,8 @@ sourcecode/telemetry/consent.py,sha256=wLMvGNJeSSyZoNkQXpoUioY6mMv4Qdvuw7S9jAEWn
61
61
  sourcecode/telemetry/events.py,sha256=oEvvulfsv5GIDWG2174gSS6tNB95w38AIYiYeifGKlE,2294
62
62
  sourcecode/telemetry/filters.py,sha256=Asa71oRl7q3Wt_FMwuufIZJFzSYdgRNKS8LHCIyFeYE,4805
63
63
  sourcecode/telemetry/transport.py,sha256=KJeIPCPWMdmbCP3ySGs2iUlia34U6vWne2dZsUezesw,1560
64
- sourcecode-1.24.0.dist-info/METADATA,sha256=qm5HNotxn3mryucu6yiL5YelgzbEyMbv7lqTaI-B4RQ,20626
65
- sourcecode-1.24.0.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
66
- sourcecode-1.24.0.dist-info/entry_points.txt,sha256=ex3F9rmbXeyDIoFQHtkEqTsKSaJow8F0LrVu8XfIktQ,57
67
- sourcecode-1.24.0.dist-info/licenses/LICENSE,sha256=7DdHrU9Z_3e7dSvq4ISijZNjnuHo5NIHNiHDouMQ9JU,10491
68
- sourcecode-1.24.0.dist-info/RECORD,,
64
+ sourcecode-1.26.0.dist-info/METADATA,sha256=asX4Za9LuNeB5rJtVfsqxa3WzlsYjNYrXGEH3-Ty84M,23417
65
+ sourcecode-1.26.0.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
66
+ sourcecode-1.26.0.dist-info/entry_points.txt,sha256=ex3F9rmbXeyDIoFQHtkEqTsKSaJow8F0LrVu8XfIktQ,57
67
+ sourcecode-1.26.0.dist-info/licenses/LICENSE,sha256=7DdHrU9Z_3e7dSvq4ISijZNjnuHo5NIHNiHDouMQ9JU,10491
68
+ sourcecode-1.26.0.dist-info/RECORD,,