devtime-ei 0.5.1__tar.gz → 0.6.0__tar.gz

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.
Files changed (77) hide show
  1. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/PKG-INFO +2 -2
  2. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/pyproject.toml +2 -2
  3. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/__init__.py +1 -1
  4. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/cli.py +31 -0
  5. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/intelligence/verification.py +305 -41
  6. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/mcp/transport.py +14 -1
  7. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/scanner/extractors/tests.py +20 -1
  8. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime_ei.egg-info/PKG-INFO +2 -2
  9. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/LICENSE +0 -0
  10. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/README.md +0 -0
  11. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/setup.cfg +0 -0
  12. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/ai/__init__.py +0 -0
  13. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/ai/local.py +0 -0
  14. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/ai/prompts.py +0 -0
  15. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/ai/providers.py +0 -0
  16. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/assets/devtimeignore.starter +0 -0
  17. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/config.py +0 -0
  18. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/db/__init__.py +0 -0
  19. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/db/connection.py +0 -0
  20. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/db/migrations.py +0 -0
  21. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/db/repository.py +0 -0
  22. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/db/schema.sql +0 -0
  23. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/demo.py +0 -0
  24. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/fixtures/__init__.py +0 -0
  25. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/fixtures/assertions.py +0 -0
  26. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/fixtures/loader.py +0 -0
  27. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/fixtures/runner.py +0 -0
  28. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/intelligence/__init__.py +0 -0
  29. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/intelligence/claims.py +0 -0
  30. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/intelligence/concepts.py +0 -0
  31. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/intelligence/context_pack.py +0 -0
  32. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/intelligence/evidence.py +0 -0
  33. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/intelligence/lineage.py +0 -0
  34. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/intelligence/risk.py +0 -0
  35. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/intelligence/scoring.py +0 -0
  36. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/mcp/__init__.py +0 -0
  37. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/mcp/schemas.py +0 -0
  38. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/mcp/server.py +0 -0
  39. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/mcp/tools.py +0 -0
  40. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/output/__init__.py +0 -0
  41. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/output/json_export.py +0 -0
  42. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/output/markdown.py +0 -0
  43. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/output/terminal.py +0 -0
  44. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/paths.py +0 -0
  45. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/privacy.py +0 -0
  46. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/resources/demo-saas/.devtimeignore +0 -0
  47. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/resources/demo-saas/README.md +0 -0
  48. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/resources/demo-saas/docs/decisions/0001-use-jwt.md +0 -0
  49. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/resources/demo-saas/package.json +0 -0
  50. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/resources/demo-saas/src/admin/permissions.ts +0 -0
  51. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/resources/demo-saas/src/auth/login.ts +0 -0
  52. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/resources/demo-saas/src/auth/middleware.ts +0 -0
  53. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/resources/demo-saas/src/auth/tokens.ts +0 -0
  54. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/resources/demo-saas/src/billing/stripe-webhook.ts +0 -0
  55. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/resources/demo-saas/src/billing/subscription-service.ts +0 -0
  56. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/resources/demo-saas/src/export/export-csv.ts +0 -0
  57. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/resources/demo-saas/src/jobs/email-worker.ts +0 -0
  58. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/resources/demo-saas/src/jobs/queues.ts +0 -0
  59. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/resources/demo-saas/tests/auth-login.test.ts +0 -0
  60. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/resources/demo-saas/tests/stripe-signature.test.ts +0 -0
  61. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/scanner/__init__.py +0 -0
  62. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/scanner/extractors/__init__.py +0 -0
  63. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/scanner/extractors/base.py +0 -0
  64. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/scanner/extractors/config_files.py +0 -0
  65. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/scanner/extractors/docs.py +0 -0
  66. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/scanner/extractors/nextjs.py +0 -0
  67. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/scanner/extractors/python.py +0 -0
  68. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/scanner/extractors/typescript.py +0 -0
  69. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/scanner/file_walker.py +0 -0
  70. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/scanner/ignore.py +0 -0
  71. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/scanner/language.py +0 -0
  72. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime/scanner/signals.py +0 -0
  73. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime_ei.egg-info/SOURCES.txt +0 -0
  74. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime_ei.egg-info/dependency_links.txt +0 -0
  75. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime_ei.egg-info/entry_points.txt +0 -0
  76. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime_ei.egg-info/requires.txt +0 -0
  77. {devtime_ei-0.5.1 → devtime_ei-0.6.0}/src/devtime_ei.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: devtime-ei
3
- Version: 0.5.1
3
+ Version: 0.6.0
4
4
  Summary: Local-first Engineering Intelligence for software repositories
5
5
  Author-email: Aviad Shakargi <aviad94@gmail.com>
6
6
  Maintainer-email: Aviad Shakargi <aviad94@gmail.com>
@@ -8,7 +8,7 @@ License: Apache-2.0
8
8
  Project-URL: Homepage, https://github.com/Shakargy/devtime
9
9
  Project-URL: Repository, https://github.com/Shakargy/devtime
10
10
  Project-URL: Issues, https://github.com/Shakargy/devtime/issues
11
- Project-URL: Release Notes, https://github.com/Shakargy/devtime/releases/tag/v0.5.1
11
+ Project-URL: Release Notes, https://github.com/Shakargy/devtime/releases/tag/v0.6.0
12
12
  Project-URL: Demo, https://youtu.be/1Hiu3Y9J_SI
13
13
  Keywords: devtools,cli,static-analysis,repository-analysis,engineering-intelligence,local-first
14
14
  Classifier: Development Status :: 3 - Alpha
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "devtime-ei"
3
- version = "0.5.1"
3
+ version = "0.6.0"
4
4
  description = "Local-first Engineering Intelligence for software repositories"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.11"
@@ -50,7 +50,7 @@ dev = [
50
50
  Homepage = "https://github.com/Shakargy/devtime"
51
51
  Repository = "https://github.com/Shakargy/devtime"
52
52
  Issues = "https://github.com/Shakargy/devtime/issues"
53
- "Release Notes" = "https://github.com/Shakargy/devtime/releases/tag/v0.5.1"
53
+ "Release Notes" = "https://github.com/Shakargy/devtime/releases/tag/v0.6.0"
54
54
  Demo = "https://youtu.be/1Hiu3Y9J_SI"
55
55
 
56
56
  [project.scripts]
@@ -1,6 +1,6 @@
1
1
  """DevTime - local-first Engineering Intelligence for repository memory."""
2
2
 
3
- __version__ = "0.5.1"
3
+ __version__ = "0.6.0"
4
4
 
5
5
  # Version metadata (Builder Edition, Chapter 20).
6
6
  EVIDENCE_MODEL = "2026.06.1"
@@ -157,23 +157,54 @@ def verify(
157
157
  if result.status in ver.APPLICABLE_STATUSES:
158
158
  ver.save_verification(conn, result)
159
159
 
160
+ state = ver.scan_state(conn)
161
+
160
162
  if as_json:
161
163
  console.print_json(
162
164
  _json.dumps(
163
165
  {
164
166
  "schema_version": "2",
165
167
  "command": "verify",
168
+ "evidence_snapshot": state,
166
169
  "results": [r.to_dict() for r in results],
167
170
  }
168
171
  )
169
172
  )
170
173
  return
171
174
 
175
+ _print_scan_state(state)
172
176
  _print_report(results, single=bool(claim))
173
177
  finally:
174
178
  conn.close()
175
179
 
176
180
 
181
+ def _print_scan_state(state: dict) -> None:
182
+ """Say plainly which snapshot these conclusions came from.
183
+
184
+ Verification reads the last persisted scan, not the working tree. When the
185
+ two disagree, that must be the first thing a reader sees.
186
+ """
187
+ tree = state.get("working_tree")
188
+ if tree == "changed_since_scan":
189
+ changed = state.get("changed_paths") or []
190
+ console.print(
191
+ "[yellow]These results were computed from a scan that no longer "
192
+ "matches your working tree.[/yellow]"
193
+ )
194
+ for p in changed[:5]:
195
+ console.print(f" changed since the scan: {p}", markup=False)
196
+ if len(changed) > 5:
197
+ console.print(f" ... and {len(changed) - 5} more", markup=False)
198
+ console.print("Run [bold]dtc scan[/bold] to verify against current code.")
199
+ console.print("")
200
+ elif tree == "partially_checked":
201
+ console.print(
202
+ "[dim]Working-tree comparison was capped; some files were not "
203
+ "re-checked against the scan.[/dim]"
204
+ )
205
+ console.print("")
206
+
207
+
177
208
  def _print_report(results: list, single: bool) -> None:
178
209
  """Report card: what DevTime can and cannot verify about this repository."""
179
210
  from devtime.intelligence import verification as ver
@@ -31,6 +31,7 @@ Freshness is separate from truth:
31
31
 
32
32
  from __future__ import annotations
33
33
 
34
+ import hashlib
34
35
  import json
35
36
  import re
36
37
  import sqlite3
@@ -123,6 +124,17 @@ class VerificationResult:
123
124
  scan_id: str | None
124
125
  verified_at: str
125
126
  engine_version: str
127
+ # v0.6.0: the complete set of files whose content justified this conclusion.
128
+ # This is NOT the same as `supporting`, which is a bounded selection shown to
129
+ # a human. Displayed evidence may be capped; the dependency set never is,
130
+ # because it is what invalidation is computed from. A WEAK result has
131
+ # dependencies too: the files it examined are exactly what would change the
132
+ # answer.
133
+ dependencies: list[str] = field(default_factory=list)
134
+ # Fingerprint of the surface the claim reasoned about (e.g. the set of
135
+ # application routes). A claim about "all routes" depends on the inventory,
136
+ # so adding a new route must invalidate it even if no existing file changed.
137
+ inventory: str | None = None
126
138
 
127
139
  def to_dict(self) -> dict:
128
140
  # schema_version 2 (v0.5.0): adds the NOT_APPLICABLE status value. All
@@ -142,6 +154,9 @@ class VerificationResult:
142
154
  "scan_id": self.scan_id,
143
155
  "verified_at": self.verified_at,
144
156
  "engine_version": self.engine_version,
157
+ # Bounded on purpose: the full dependency list is stored locally and
158
+ # drives invalidation, but responses stay small.
159
+ "dependency_count": len(self.dependencies),
145
160
  }
146
161
 
147
162
 
@@ -171,7 +186,7 @@ BUILTIN_CLAIMS: dict[str, ClaimDefinition] = {
171
186
  "route-test-coverage": ClaimDefinition(
172
187
  slug="route-test-coverage",
173
188
  name="Route Test Association",
174
- statement="HTTP routes have tests that import their implementation.",
189
+ statement="HTTP routes are referenced by tests that request or import them.",
175
190
  category="testing",
176
191
  ),
177
192
  "admin-authorization": ClaimDefinition(
@@ -219,6 +234,16 @@ def _load_signals(conn: sqlite3.Connection, scan_id: str) -> list[sqlite3.Row]:
219
234
  ).fetchall()
220
235
 
221
236
 
237
+ def _inventory_fingerprint(items: list[str]) -> str:
238
+ """Stable fingerprint of a surface set (routes, handlers).
239
+
240
+ Deterministic and order-independent, so an unchanged repository always
241
+ produces the same value while an added or removed member changes it.
242
+ """
243
+ joined = "\n".join(sorted(items))
244
+ return hashlib.sha256(joined.encode("utf-8")).hexdigest()[:16]
245
+
246
+
222
247
  def _meta(row: sqlite3.Row) -> dict:
223
248
  try:
224
249
  return json.loads(row["metadata_json"] or "{}")
@@ -439,6 +464,14 @@ def _verify_billing_webhook_signature(
439
464
  status = SUPPORTED if n_connected == n_total else WEAK
440
465
  if not signature_tests:
441
466
  missing.append("A test that exercises webhook signature verification.")
467
+ dependencies = sorted(
468
+ {r["path"] for r in webhook_route_rows}
469
+ | verify_files
470
+ | {r["path"] for r in verification_rows}
471
+ )
472
+ inventory = _inventory_fingerprint(
473
+ [_route_label(r) for r in webhook_route_rows]
474
+ )
442
475
  limitations = [
443
476
  "Signature verification is connected to a handler when both appear in "
444
477
  "the same file. Verification reached through an imported helper is not "
@@ -462,6 +495,8 @@ def _verify_billing_webhook_signature(
462
495
  scan_id=scan_id,
463
496
  verified_at=_now(),
464
497
  engine_version=__version__,
498
+ dependencies=dependencies,
499
+ inventory=inventory,
465
500
  )
466
501
 
467
502
  if stub_webhooks and not verifications:
@@ -537,6 +572,9 @@ def _verify_billing_webhook_signature(
537
572
  scan_id=scan_id,
538
573
  verified_at=_now(),
539
574
  engine_version=__version__,
575
+ dependencies=sorted(
576
+ {e.path for e in (supporting + verifications + stub_webhooks)}
577
+ ),
540
578
  )
541
579
 
542
580
 
@@ -660,6 +698,14 @@ def _verify_jwt_authentication(
660
698
  scan_id=scan_id,
661
699
  verified_at=_now(),
662
700
  engine_version=__version__,
701
+ dependencies=sorted(
702
+ {
703
+ e.path
704
+ for e in (
705
+ access_usage + invitation_usage + unclear_usage + jwt_docs + jwt_deps
706
+ )
707
+ }
708
+ ),
663
709
  )
664
710
 
665
711
 
@@ -681,6 +727,17 @@ def _module_token(path: str) -> str:
681
727
  return stem.lower()
682
728
 
683
729
 
730
+ def _is_prefix_relative(route_path: str) -> bool:
731
+ """True when a route path cannot identify a full URL on its own.
732
+
733
+ FastAPI and Express routers are commonly declared relative to a mount
734
+ prefix (`APIRouter()` + `include_router(..., prefix="/api/v1/items")`), so a
735
+ declared path of "/" or "/{id}" says nothing about the served URL.
736
+ """
737
+ p = (route_path or "").strip()
738
+ return p in ("", "/") or p.startswith("/{") or p.startswith("/:")
739
+
740
+
684
741
  def _route_tokens(route_path: str) -> list[str]:
685
742
  """Distinctive, non-generic segments of a route path."""
686
743
  out = []
@@ -717,6 +774,7 @@ def _verify_route_test_coverage(
717
774
  """
718
775
  # Aggregate tests per file: imports + a single blob of test names.
719
776
  test_imports: dict[str, set[str]] = {}
777
+ test_requests: dict[str, set[tuple[str, str]]] = {}
720
778
  test_blobs: dict[str, list[str]] = {}
721
779
  for row in rows:
722
780
  if row["kind"] != "test":
@@ -733,6 +791,14 @@ def _verify_route_test_coverage(
733
791
  imports = test_imports.setdefault(path, set())
734
792
  for imp in meta.get("imports") or []:
735
793
  imports.add(str(imp).lower())
794
+ reqs = test_requests.setdefault(path, set())
795
+ for req in meta.get("requests") or []:
796
+ reqs.add(
797
+ (
798
+ str(req.get("method", "")).upper(),
799
+ str(req.get("path", "")).lower().rstrip("/") or "/",
800
+ )
801
+ )
736
802
  test_blobs.setdefault(path, []).append(str(row["name"] or "").lower())
737
803
 
738
804
  # One joined blob per test file keeps name matching linear in test FILES.
@@ -777,12 +843,22 @@ def _verify_route_test_coverage(
777
843
  associated: list[tuple[str, str, str]] = [] # (impl path, label, reason)
778
844
  suggested: list[tuple[str, str, str]] = [] # name similarity only
779
845
  unassociated: list[tuple[str, str]] = []
846
+ unresolved: list[tuple[str, str]] = [] # full URL cannot be determined
780
847
  for (impl_path, route_path, method), row in sorted(routes.items()):
781
848
  label = f"{method} {route_path}" if route_path else impl_path
782
849
  token = _module_token(impl_path)
783
850
  reason = ""
784
- # Only level that can support the claim: a test importing this module.
785
- if token and len(token) >= 3:
851
+ # Strongest available level: a test that requests this exact endpoint.
852
+ norm_path = route_path.rstrip("/") or "/"
853
+ for test_path, reqs in test_requests.items():
854
+ if (method, norm_path) in reqs or ("ANY", norm_path) in reqs:
855
+ reason = f"{test_path} requests {method} {route_path}"
856
+ break
857
+ if method == "ANY" and any(p == norm_path for _m, p in reqs):
858
+ reason = f"{test_path} requests {route_path}"
859
+ break
860
+ # Next level: a test importing this module.
861
+ if not reason and token and len(token) >= 3:
786
862
  for test_path, stems in test_import_stems.items():
787
863
  if token in stems:
788
864
  reason = f"{test_path} imports {token}"
@@ -799,10 +875,17 @@ def _verify_route_test_coverage(
799
875
  break
800
876
  if hint:
801
877
  suggested.append((impl_path, label, hint))
802
- unassociated.append((impl_path, label))
878
+ # A prefix-relative path ("/" or "/{id}") does not identify a full URL:
879
+ # the router's mount prefix was not resolved, so this is a gap in the
880
+ # analysis, not evidence that the route lacks a test.
881
+ if _is_prefix_relative(route_path):
882
+ unresolved.append((impl_path, label))
883
+ else:
884
+ unassociated.append((impl_path, label))
803
885
 
804
886
  total = len(routes)
805
887
  n_assoc = len(associated)
888
+ n_unresolved = len(unresolved)
806
889
  # Evidence shown to the user is bounded; the dependency set used for
807
890
  # invalidation is tracked separately and is not capped.
808
891
  _EVIDENCE_CAP = 25
@@ -820,36 +903,65 @@ def _verify_route_test_coverage(
820
903
  ]
821
904
 
822
905
  why = [
823
- f"{n_assoc} of {total} routes have a test importing their implementation."
906
+ f"{n_assoc} of {total} routes are referenced by a test that requests or "
907
+ f"imports them."
824
908
  ]
825
909
  missing: list[str] = []
826
910
  if n_assoc == total:
827
911
  status = SUPPORTED
828
912
  why.append(
829
- "Every detected route has a test that imports its implementation. "
830
- "This is a static association, not proof the route was executed."
913
+ "Every detected route is referenced by a test that requests or imports "
914
+ "it. This is a static association, not proof the route was executed "
915
+ "or that its assertions cover the behavior."
831
916
  )
832
917
  else:
833
918
  status = WEAK
834
- why.append(
835
- "Routes without an importing test have no established association."
836
- )
837
- shown = [label for _, label in unassociated[:8]]
838
- missing.append(
839
- f"Tests importing {total - n_assoc} route(s): " + ", ".join(shown)
840
- + (" ..." if len(unassociated) > 8 else "")
841
- )
919
+ if unassociated:
920
+ why.append(
921
+ "Routes with no requesting or importing test have no established "
922
+ "association."
923
+ )
924
+ shown = [label for _, label in unassociated[:8]]
925
+ missing.append(
926
+ f"A test requesting or importing {len(unassociated)} route(s): "
927
+ + ", ".join(shown)
928
+ + (" ..." if len(unassociated) > 8 else "")
929
+ )
930
+ if unresolved:
931
+ why.append(
932
+ f"{n_unresolved} route(s) are declared relative to a router mount "
933
+ "prefix that DevTime did not resolve, so their full URL is unknown. "
934
+ "That is a gap in this analysis, not evidence that they lack tests."
935
+ )
936
+ missing.append(
937
+ "A resolvable full URL for: "
938
+ + ", ".join(label for _, label in unresolved[:6])
939
+ )
842
940
  if suggested:
843
941
  why.append(
844
942
  f"{len(suggested)} route(s) share vocabulary with a test name but no "
845
- "import was found. Name similarity is a suggestion, not evidence: "
943
+ "request or import was found. Name similarity is a suggestion, not "
944
+ "evidence: "
846
945
  + suggested[0][2]
847
946
  )
848
947
 
948
+ # Dependencies: every application route file and every test file that was
949
+ # considered. Editing a test that justified an association must invalidate
950
+ # the result, which v0.5.x did not do because only route files were stored.
951
+ dependencies = sorted(
952
+ {impl for (impl, _p, _m) in routes.keys()}
953
+ | set(test_name_blob.keys())
954
+ | set(test_requests.keys())
955
+ )
956
+ inventory = _inventory_fingerprint(
957
+ [f"{m} {p} {impl}" for (impl, p, m) in routes.keys()]
958
+ )
959
+
849
960
  limitations = [
850
- "Association is established from test imports only. A test that exercises "
851
- "a route indirectly, through a running server, or through a helper that "
852
- "DevTime cannot resolve is reported as unassociated.",
961
+ "Association is established from a test that requests the exact route "
962
+ "path, or from a test that imports the route's implementation module. A "
963
+ "test that reaches a route only through a variable URL, a helper, or a "
964
+ "mounted prefix DevTime cannot resolve is reported as unassociated.",
853
965
  "A static import association is not execution coverage. It does not "
854
966
  "establish that the route ran, that assertions covered its behavior, or "
855
967
  "that the test passes.",
@@ -875,6 +987,8 @@ def _verify_route_test_coverage(
875
987
  scan_id=scan_id,
876
988
  verified_at=_now(),
877
989
  engine_version=__version__,
990
+ dependencies=dependencies,
991
+ inventory=inventory,
878
992
  )
879
993
 
880
994
 
@@ -1011,6 +1125,9 @@ def _verify_admin_authorization(
1011
1125
  + ", ".join(sorted({_route_label(r) for r in unresolved})[:6])
1012
1126
  )
1013
1127
 
1128
+ dependencies = sorted({r["path"] for r in admin_routes})
1129
+ inventory = _inventory_fingerprint([_route_label(r) for r in admin_routes])
1130
+
1014
1131
  limitations = [
1015
1132
  "Authorization is established only from a guard applied at the route's own "
1016
1133
  "call site. Guards applied by a router mount, a server-wide middleware, or "
@@ -1033,6 +1150,8 @@ def _verify_admin_authorization(
1033
1150
  scan_id=scan_id,
1034
1151
  verified_at=_now(),
1035
1152
  engine_version=__version__,
1153
+ dependencies=dependencies,
1154
+ inventory=inventory,
1036
1155
  )
1037
1156
 
1038
1157
 
@@ -1089,6 +1208,7 @@ CREATE TABLE IF NOT EXISTS verifications (
1089
1208
  scan_id TEXT,
1090
1209
  result_json TEXT NOT NULL,
1091
1210
  evidence_fingerprints_json TEXT NOT NULL DEFAULT '[]',
1211
+ inventory_fingerprint TEXT,
1092
1212
  engine_version TEXT NOT NULL,
1093
1213
  created_at TEXT NOT NULL
1094
1214
  );
@@ -1096,32 +1216,54 @@ CREATE TABLE IF NOT EXISTS verifications (
1096
1216
 
1097
1217
 
1098
1218
  def ensure_verifications_table(conn: sqlite3.Connection) -> None:
1099
- """Idempotent: safe for databases initialized before v0.2.0."""
1219
+ """Idempotent: safe for databases initialized before v0.2.0.
1220
+
1221
+ v0.6.0 adds inventory_fingerprint. Existing rows keep NULL, which is read as
1222
+ "inventory was not tracked when this was recorded" and triggers
1223
+ re-verification rather than an unjustified FRESH.
1224
+ """
1100
1225
  conn.execute(_VERIFICATIONS_TABLE)
1226
+ columns = {
1227
+ row["name"] for row in conn.execute("PRAGMA table_info(verifications)")
1228
+ }
1229
+ if "inventory_fingerprint" not in columns:
1230
+ conn.execute("ALTER TABLE verifications ADD COLUMN inventory_fingerprint TEXT")
1231
+ conn.commit()
1101
1232
 
1102
1233
 
1103
1234
  def save_verification(conn: sqlite3.Connection, result: VerificationResult) -> str:
1104
- """Store an immutable verification result with evidence fingerprints."""
1235
+ """Store an immutable verification result with its dependency fingerprints.
1236
+
1237
+ v0.6.0: fingerprints come from the complete dependency set, not from the
1238
+ bounded list of evidence shown to the user. Previously a route/test claim
1239
+ stored only route files, so editing the test that justified the association
1240
+ left the result reported as FRESH.
1241
+ """
1105
1242
  ensure_verifications_table(conn)
1106
1243
  repo = conn.execute("SELECT id FROM repositories LIMIT 1").fetchone()
1107
1244
  repo_id = repo["id"] if repo else "unknown"
1108
- fingerprints = [
1109
- {"path": e.path, "sha256": e.sha256}
1110
- for e in result.supporting
1111
- if e.sha256
1112
- ]
1245
+
1246
+ paths: set[str] = set(result.dependencies)
1247
+ paths |= {e.path for e in result.supporting}
1113
1248
  # Contradiction evidence participates in freshness too: if the stub changes,
1114
1249
  # the contradiction must be re-checked.
1115
1250
  for c in result.contradictions:
1116
- fingerprints += [
1117
- {"path": e.path, "sha256": e.sha256} for e in c.evidence if e.sha256
1118
- ]
1251
+ paths |= {e.path for e in c.evidence}
1252
+
1253
+ sha_by_path = {
1254
+ row["path"]: row["sha256"]
1255
+ for row in conn.execute("SELECT path, sha256 FROM files").fetchall()
1256
+ }
1257
+ fingerprints = [
1258
+ {"path": p, "sha256": sha_by_path.get(p)} for p in sorted(paths)
1259
+ ]
1119
1260
  vid = f"ver-{uuid.uuid4().hex[:10]}"
1120
1261
  conn.execute(
1121
1262
  "INSERT INTO verifications"
1122
1263
  "(id, repository_id, claim_slug, status, scan_id, result_json, "
1123
- " evidence_fingerprints_json, engine_version, created_at) "
1124
- "VALUES (?,?,?,?,?,?,?,?,?)",
1264
+ " evidence_fingerprints_json, inventory_fingerprint, engine_version, "
1265
+ " created_at) "
1266
+ "VALUES (?,?,?,?,?,?,?,?,?,?)",
1125
1267
  (
1126
1268
  vid,
1127
1269
  repo_id,
@@ -1130,6 +1272,7 @@ def save_verification(conn: sqlite3.Connection, result: VerificationResult) -> s
1130
1272
  result.scan_id,
1131
1273
  json.dumps(result.to_dict()),
1132
1274
  json.dumps(fingerprints),
1275
+ result.inventory,
1133
1276
  result.engine_version,
1134
1277
  result.verified_at,
1135
1278
  ),
@@ -1157,6 +1300,82 @@ def load_latest_verification(
1157
1300
  )
1158
1301
 
1159
1302
 
1303
+ def scan_state(conn: sqlite3.Connection, root=None) -> dict:
1304
+ """Describe the evidence snapshot a verification is about to be computed from.
1305
+
1306
+ Verification recomputes conclusions from the last persisted scan. That is
1307
+ not the same as the working tree, and reporting a fresh evaluation timestamp
1308
+ without saying so implies evidence that was never collected. This returns
1309
+ the facts a caller needs to be honest about what was actually examined:
1310
+
1311
+ scan_id / scanned_at which snapshot was used
1312
+ files_scanned its size
1313
+ working_tree "unchecked", "matches_scan", or "changed_since_scan"
1314
+ changed_paths files whose content no longer matches the snapshot
1315
+ """
1316
+ from pathlib import Path
1317
+
1318
+ from devtime import paths as _paths
1319
+
1320
+ row = conn.execute(
1321
+ "SELECT id, started_at, finished_at, file_count, status FROM scans "
1322
+ "WHERE status = 'completed' ORDER BY started_at DESC LIMIT 1"
1323
+ ).fetchone()
1324
+ if row is None:
1325
+ return {
1326
+ "scan_id": None,
1327
+ "scanned_at": None,
1328
+ "files_scanned": 0,
1329
+ "working_tree": "never_scanned",
1330
+ "changed_paths": [],
1331
+ }
1332
+
1333
+ state = {
1334
+ "scan_id": row["id"],
1335
+ "scanned_at": row["finished_at"] or row["started_at"],
1336
+ "files_scanned": row["file_count"],
1337
+ "working_tree": "unchecked",
1338
+ "changed_paths": [],
1339
+ }
1340
+
1341
+ # A bounded, read-only check of the files this scan recorded. Hashing is
1342
+ # capped so a verification never turns into a second full scan.
1343
+ import hashlib as _hashlib
1344
+
1345
+ repo_root = Path(root) if root else _paths.repo_root()
1346
+ rows = conn.execute(
1347
+ "SELECT path, sha256 FROM files WHERE last_seen_scan_id = ? AND sha256 IS NOT NULL",
1348
+ (row["id"],),
1349
+ ).fetchall()
1350
+ if not rows:
1351
+ return state
1352
+
1353
+ _CHECK_CAP = 400
1354
+ changed: list[str] = []
1355
+ checked = 0
1356
+ for f in rows:
1357
+ if checked >= _CHECK_CAP:
1358
+ state["working_tree"] = "partially_checked"
1359
+ break
1360
+ target = repo_root / f["path"]
1361
+ checked += 1
1362
+ try:
1363
+ if not target.exists():
1364
+ changed.append(f["path"])
1365
+ continue
1366
+ digest = _hashlib.sha256(target.read_bytes()).hexdigest()
1367
+ except OSError:
1368
+ continue
1369
+ if digest != f["sha256"]:
1370
+ changed.append(f["path"])
1371
+ if changed:
1372
+ state["working_tree"] = "changed_since_scan"
1373
+ state["changed_paths"] = sorted(changed)[:20]
1374
+ elif state["working_tree"] == "unchecked":
1375
+ state["working_tree"] = "matches_scan"
1376
+ return state
1377
+
1378
+
1160
1379
  def claims_affected_by_paths(
1161
1380
  conn: sqlite3.Connection, changed_paths: list[str]
1162
1381
  ) -> list[dict]:
@@ -1190,23 +1409,68 @@ def claims_affected_by_paths(
1190
1409
 
1191
1410
 
1192
1411
  def freshness_for(conn: sqlite3.Connection, slug: str) -> tuple[str, list[str]]:
1193
- """Compare stored evidence fingerprints against current file hashes.
1194
-
1195
- Returns (freshness, changed_paths). Never flags unrelated file changes:
1196
- only files that were evidence for this claim participate.
1412
+ """Compare stored dependency fingerprints against the latest scan.
1413
+
1414
+ Returns (freshness, changed_paths). Only files this claim actually depended
1415
+ on participate, so unrelated edits never mark a claim stale.
1416
+
1417
+ v0.6.0 fixes three ways a result could look current when it was not:
1418
+ - a dependency file DELETED from the repository (its old row survived in
1419
+ `files`, so the hash still matched and the claim looked FRESH);
1420
+ - a dependency file that was never re-seen by the latest scan (ignored,
1421
+ renamed, or excluded by a policy change);
1422
+ - a change to the claim's INVENTORY, such as a new route appearing, which
1423
+ changes the answer without changing any previously recorded file.
1197
1424
  """
1198
1425
  latest = load_latest_verification(conn, slug)
1199
1426
  if latest is None:
1200
1427
  return NEEDS_VERIFICATION, []
1201
- _, fingerprints, _ = latest
1428
+ result_dict, fingerprints, _ = latest
1429
+
1430
+ if not fingerprints:
1431
+ # Nothing was recorded to justify this result, so "fresh" cannot be
1432
+ # asserted. Re-verify rather than claim currency we cannot support.
1433
+ return NEEDS_VERIFICATION, []
1434
+
1435
+ scan_id = _latest_scan_id(conn)
1436
+ if scan_id is None:
1437
+ return NEEDS_VERIFICATION, []
1438
+
1439
+ current = {
1440
+ row["path"]: row
1441
+ for row in conn.execute(
1442
+ "SELECT path, sha256, last_seen_scan_id FROM files"
1443
+ ).fetchall()
1444
+ }
1445
+
1202
1446
  changed: list[str] = []
1203
1447
  for fp in fingerprints:
1204
- row = conn.execute(
1205
- "SELECT sha256 FROM files WHERE path = ? ORDER BY last_seen_scan_id DESC LIMIT 1",
1206
- (fp["path"],),
1207
- ).fetchone()
1208
- if row is None or row["sha256"] != fp["sha256"]:
1448
+ row = current.get(fp["path"])
1449
+ if row is None:
1450
+ changed.append(fp["path"]) # never seen again
1451
+ continue
1452
+ if row["last_seen_scan_id"] != scan_id:
1453
+ # Present in an older scan only: deleted, renamed, or now ignored.
1454
+ changed.append(fp["path"])
1455
+ continue
1456
+ if row["sha256"] != fp["sha256"]:
1209
1457
  changed.append(fp["path"])
1458
+
1210
1459
  if changed:
1211
1460
  return STALE, sorted(set(changed))
1461
+
1462
+ # The recorded surface set must still match what the repository has now.
1463
+ stored_inventory = conn.execute(
1464
+ "SELECT inventory_fingerprint FROM verifications WHERE claim_slug = ? "
1465
+ "ORDER BY created_at DESC LIMIT 1",
1466
+ (slug,),
1467
+ ).fetchone()
1468
+ stored = stored_inventory["inventory_fingerprint"] if stored_inventory else None
1469
+ if stored is not None:
1470
+ try:
1471
+ current_result = verify_claim(conn, slug)
1472
+ except KeyError:
1473
+ return FRESH, []
1474
+ if current_result.inventory is not None and current_result.inventory != stored:
1475
+ return STALE, ["(the set of routes or handlers this claim covers changed)"]
1212
1476
  return FRESH, []
@@ -152,7 +152,20 @@ def build_server():
152
152
  "error": "unknown_claim",
153
153
  "hint": "Call verify_claim with no claim_id to list built-in claims.",
154
154
  }
155
- return result.to_dict()
155
+ payload = result.to_dict()
156
+ # An agent cannot see the user's working tree, so it must be told
157
+ # which snapshot this conclusion came from and whether that snapshot
158
+ # is still current.
159
+ state = ver.scan_state(conn)
160
+ payload["evidence_snapshot"] = state
161
+ if state.get("working_tree") == "changed_since_scan":
162
+ payload["staleness_warning"] = (
163
+ "This result was computed from a stored scan that no longer "
164
+ "matches the working tree. Files changed since the scan: "
165
+ + ", ".join(state.get("changed_paths", [])[:5])
166
+ + ". Ask the user to run `dtc scan` before relying on it."
167
+ )
168
+ return payload
156
169
  finally:
157
170
  conn.close()
158
171
 
@@ -22,6 +22,24 @@ _IMPORT_RE = re.compile(
22
22
  )
23
23
 
24
24
 
25
+ # HTTP requests made by a test: supertest `request(app).get("/users")`, FastAPI
26
+ # `client.post("/items")`, fetch-style helpers. Only literals that look like a
27
+ # URL path count, so `map.get("key")` is not mistaken for a request (v0.6.0).
28
+ _REQUEST_RE = re.compile(
29
+ r"""\.(get|post|put|patch|delete|head|options)\(\s*['"](/[^'"]*)['"]""",
30
+ re.I,
31
+ )
32
+
33
+
34
+ def _extract_requests(text: str) -> list[dict]:
35
+ seen: list[dict] = []
36
+ for match in _REQUEST_RE.finditer(text):
37
+ entry = {"method": match.group(1).upper(), "path": match.group(2)}
38
+ if entry not in seen:
39
+ seen.append(entry)
40
+ return seen[:50]
41
+
42
+
25
43
  def _extract_imports(text: str) -> list[str]:
26
44
  mods: list[str] = []
27
45
  for m in _IMPORT_RE.finditer(text):
@@ -45,6 +63,7 @@ def extract_test_signals(file: WalkedFile) -> list[Signal]:
45
63
  text = read_text(file)
46
64
  e2e = _is_e2e(file.rel_path)
47
65
  imports = _extract_imports(text)
66
+ requests = _extract_requests(text)
48
67
  signals: list[Signal] = []
49
68
  for match in _TEST_NAME_RE.finditer(text):
50
69
  name = match.group(1) or match.group(2)
@@ -55,7 +74,7 @@ def extract_test_signals(file: WalkedFile) -> list[Signal]:
55
74
  name=name,
56
75
  file=file,
57
76
  confidence=0.4 if e2e else 0.8,
58
- metadata={"e2e": e2e, "imports": imports},
77
+ metadata={"e2e": e2e, "imports": imports, "requests": requests},
59
78
  )
60
79
  )
61
80
  return signals
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: devtime-ei
3
- Version: 0.5.1
3
+ Version: 0.6.0
4
4
  Summary: Local-first Engineering Intelligence for software repositories
5
5
  Author-email: Aviad Shakargi <aviad94@gmail.com>
6
6
  Maintainer-email: Aviad Shakargi <aviad94@gmail.com>
@@ -8,7 +8,7 @@ License: Apache-2.0
8
8
  Project-URL: Homepage, https://github.com/Shakargy/devtime
9
9
  Project-URL: Repository, https://github.com/Shakargy/devtime
10
10
  Project-URL: Issues, https://github.com/Shakargy/devtime/issues
11
- Project-URL: Release Notes, https://github.com/Shakargy/devtime/releases/tag/v0.5.1
11
+ Project-URL: Release Notes, https://github.com/Shakargy/devtime/releases/tag/v0.6.0
12
12
  Project-URL: Demo, https://youtu.be/1Hiu3Y9J_SI
13
13
  Keywords: devtools,cli,static-analysis,repository-analysis,engineering-intelligence,local-first
14
14
  Classifier: Development Status :: 3 - Alpha
File without changes
File without changes
File without changes