@yasaswy.nagavolu/agents 0.26.13 → 0.26.14

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.
@@ -66,8 +66,28 @@ def record(slug: str, mdx_path: Path, notes: str = "") -> None:
66
66
  })
67
67
 
68
68
 
69
+ def _legacy_hashes(mdx_path: Path) -> set[str]:
70
+ """The pre-v2 hash was sha256 of the raw file bytes. Accept the same text with either
71
+ line ending, since a checkout may convert them."""
72
+ raw = mdx_path.read_bytes()
73
+ lf = raw.replace(b"\r\n", b"\n")
74
+ return {hashlib.sha256(b).hexdigest()[:16] for b in (raw, lf, lf.replace(b"\n", b"\r\n"))}
75
+
76
+
77
+ def _upgrade_legacy(slug: str, payload: dict, mdx_path: Path) -> dict:
78
+ """A v1 record whose raw-bytes hash equals the current file proves the same content was
79
+ reviewed: rewrite it as v2. Any other v1 record is left alone (stale)."""
80
+ if payload.get("hash_version") is not None or payload.get("content_hash") not in _legacy_hashes(mdx_path):
81
+ return payload
82
+ upgraded = {**payload, "content_hash": content_hash(mdx_path), "hash_version": HASH_VERSION, "upgraded_from_hash_version": 1}
83
+ review_store.write(KIND, slug, upgraded)
84
+ return upgraded
85
+
86
+
69
87
  def check(slug: str, mdx_path: Path) -> tuple[bool, str]:
70
88
  payload = review_store.read(KIND, slug)
89
+ if payload is not None:
90
+ payload = _upgrade_legacy(slug, payload, mdx_path)
71
91
  if payload is None:
72
92
  return False, (
73
93
  f"no html-mocker review recorded for '{slug}' — run "
@@ -115,6 +115,45 @@ def test_record_with_old_hash_scheme_is_stale(isolated_reviews, tmp_path):
115
115
  mdx = _write_mdx(tmp_path)
116
116
  isolated_reviews.mkdir(parents=True)
117
117
  (isolated_reviews / "some-slug.json").write_text(
118
- json.dumps({"slug": "some-slug", "content_hash": html_mock_review.content_hash(mdx)}), encoding="utf-8")
118
+ json.dumps({"slug": "some-slug", "content_hash": "0123456789abcdef"}), encoding="utf-8")
119
119
  ok, msg = html_mock_review.check("some-slug", mdx)
120
120
  assert ok is False and "stale" in msg
121
+
122
+
123
+ def _legacy_record(isolated_reviews, slug, raw_bytes):
124
+ import hashlib
125
+ import json
126
+
127
+ isolated_reviews.mkdir(parents=True, exist_ok=True)
128
+ (isolated_reviews / f"{slug}.json").write_text(
129
+ json.dumps({"slug": slug, "content_hash": hashlib.sha256(raw_bytes).hexdigest()[:16], "notes": "n"}), encoding="utf-8")
130
+
131
+
132
+ def test_old_record_for_identical_content_is_upgraded_not_stale(isolated_reviews, tmp_path):
133
+ raw = b'---\r\ntitle: "T"\r\ndraft: false\r\n---\r\nbody\r\n'
134
+ mdx = tmp_path / "a.mdx"
135
+ mdx.write_bytes(raw)
136
+ _legacy_record(isolated_reviews, "s", raw)
137
+ ok, msg = html_mock_review.check("s", mdx)
138
+ assert ok is True, msg
139
+ import json
140
+
141
+ saved = json.loads((isolated_reviews / "s.json").read_text(encoding="utf-8"))
142
+ assert saved["hash_version"] == html_mock_review.HASH_VERSION and saved["upgraded_from_hash_version"] == 1
143
+ assert saved["notes"] == "n"
144
+
145
+
146
+ def test_old_record_survives_a_line_ending_conversion(isolated_reviews, tmp_path):
147
+ crlf = b'---\r\ntitle: "T"\r\n---\r\nbody\r\n'
148
+ mdx = tmp_path / "a.mdx"
149
+ mdx.write_bytes(crlf.replace(b"\r\n", b"\n"))
150
+ _legacy_record(isolated_reviews, "s", crlf)
151
+ assert html_mock_review.check("s", mdx)[0] is True
152
+
153
+
154
+ def test_old_record_for_different_content_stays_stale(isolated_reviews, tmp_path):
155
+ mdx = tmp_path / "a.mdx"
156
+ mdx.write_bytes(b"new content")
157
+ _legacy_record(isolated_reviews, "s", b"old content")
158
+ ok, msg = html_mock_review.check("s", mdx)
159
+ assert ok is False and "stale" in msg
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yasaswy.nagavolu/agents",
3
- "version": "0.26.13",
3
+ "version": "0.26.14",
4
4
  "description": "CLI for installing the yasaswy.nagavolu agent/skill/hook bundle. `install` opens an interactive bundle menu in a TTY (or `--bundle <key> --yes` for non-interactive installs), with hash-tracked idempotent deploys, automatic hook wiring into settings.json, and masked secret prompting. `update` reconciles installed bundles against the current source (hash-tracked: silent overwrite, conflict diff+prompt, or --theirs/--keep-mine). `uninstall` removes a bundle's files and wiring. `secrets` re-runs secret prompting for already-installed bundles.",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",