markstay 0.1.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.
@@ -0,0 +1,7 @@
1
+ __pycache__/
2
+ *.pyc
3
+ *.egg-info/
4
+ .pytest_cache/
5
+ build/
6
+ dist/
7
+ .venv/
markstay-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 markstaymd
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,118 @@
1
+ Metadata-Version: 2.4
2
+ Name: markstay
3
+ Version: 0.1.0
4
+ Summary: Python reference implementation of the markstay spec (v1.1): source-level block identity for Markdown
5
+ Project-URL: Homepage, https://markstay.org
6
+ Project-URL: Repository, https://github.com/markstaymd/markstay-py
7
+ Project-URL: Issues, https://github.com/markstaymd/markstay-py/issues
8
+ Author-email: markstaymd <markstaymd@users.noreply.github.com>
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: block-identity,content-addressed,diff,linter,markdown,markstay,spec
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Topic :: Software Development :: Quality Assurance
17
+ Classifier: Topic :: Text Processing :: Markup :: Markdown
18
+ Requires-Python: >=3.9
19
+ Provides-Extra: commonmark
20
+ Requires-Dist: markdown-it-py>=2; extra == 'commonmark'
21
+ Description-Content-Type: text/markdown
22
+
23
+ # markstay , Python reference implementation (v1 core)
24
+
25
+ The Python reference implementation of the [markstay spec](https://markstay.org)
26
+ (v1.1). markstay is a source-level identity primitive for Markdown blocks: an id
27
+ token that **stays** bound to its block across edits (marker `stay:`), so a
28
+ reference to a block survives the document being rewritten, including by an LLM.
29
+
30
+ This is the **parser-free core**: everything string-level and parser-independent
31
+ (§8 hashing, §3/§4 marker grammar, §5 blank-line segmentation, §7/§11 lint, §9
32
+ quote recovery, §9.1 resolution ladder). It mirrors the JavaScript reference
33
+ ([`markstay` on npm](https://www.npmjs.com/package/markstay)); both are gated by a
34
+ shared language-neutral conformance corpus, which turns "two implementations
35
+ agree" from an assertion into a tested fact.
36
+
37
+ ## Install
38
+
39
+ ```sh
40
+ pip install markstay
41
+ ```
42
+
43
+ Zero runtime dependencies (Python standard library only). CommonMark-tree
44
+ segmentation (§5.2) is an optional extra:
45
+
46
+ ```sh
47
+ pip install "markstay[commonmark]" # pulls in markdown-it-py
48
+ ```
49
+
50
+ Requires Python >= 3.9.
51
+
52
+ ## Library
53
+
54
+ ```python
55
+ import markstay as M
56
+
57
+ md = "The ingest stage retries three times.\n<!-- stay:a1b2 -->\n"
58
+
59
+ # parse into content blocks with attached markers (§5)
60
+ blocks = M.parse_document(md)
61
+
62
+ # well-formedness + intra-doc invariants (§7): duplicate/orphan/malformed/drift
63
+ _, findings = M.lint_document(md)
64
+
65
+ # regeneration diff (§11): what an edit did to the ids (dropped/duplicated/moved)
66
+ findings = M.lint_diff(before_md, after_md)
67
+
68
+ # §8 content hash (ASCII-normalized SHA-256)
69
+ M.body_hash("some block body")
70
+
71
+ # §9.1 resolution ladder: re-attach ids after an edit, or report DETACHED
72
+ anchors = M.build_anchors(before_md)
73
+ resolutions = M.resolve(anchors, after_md) # id -> marker | hash | quote | detached
74
+ ```
75
+
76
+ Public API (mirrors the JS `index.js` surface): `normalize_body`, `body_hash`,
77
+ `Marker`, `find_markers`, `strip_markers`, `segment_blank_line`,
78
+ `segment_commonmark`, `Block`, `parse_document`, `Finding`, `lint_document`,
79
+ `lint_diff`, `sort_findings`, `has_errors`, `Selector`, `normalize`,
80
+ `body_score`, `context_bonus`, `best_match`, `CONTEXT_CHARS`, `Anchor`,
81
+ `Resolution`, `build_anchors`, `resolve`, `DEFAULT_THRESHOLD`, `DEFAULT_MARGIN`.
82
+
83
+ ## CLI
84
+
85
+ ```sh
86
+ markstay FILE [FILE ...] # well-formedness + intra-doc checks
87
+ markstay --before OLD.md NEW.md # regeneration diff (dropped/duplicated/relocated ids)
88
+ markstay --json ... # machine-readable findings
89
+ markstay --commonmark ... # §5.2 CommonMark-tree segmentation (needs the extra)
90
+ ```
91
+
92
+ Exit status is non-zero when any error-level finding is reported, so it can gate
93
+ a commit hook or an agent's post-edit step.
94
+
95
+ ## The conformance corpus (the actual deliverable)
96
+
97
+ The corpus under [`conformance/`](conformance) is shared with the JavaScript
98
+ reference. **276 vectors** across two tiers:
99
+
100
+ - **`spec/`** , hand-authored from the spec prose, asserting what the *words*
101
+ require. These are authority; a `spec/` vector the reference fails is a
102
+ reference bug, not a corpus error.
103
+ - **`gen/`** , emitted from the reference for breadth/regression.
104
+
105
+ The JS reference runs the same JSON, so the two runners are a cross-impl
106
+ regression sentinel: any later change to either implementation that breaks
107
+ agreement fails one of them.
108
+
109
+ ## Running the tests
110
+
111
+ ```sh
112
+ pip install -e ".[commonmark]"
113
+ pytest
114
+ ```
115
+
116
+ ## License
117
+
118
+ MIT
@@ -0,0 +1,96 @@
1
+ # markstay , Python reference implementation (v1 core)
2
+
3
+ The Python reference implementation of the [markstay spec](https://markstay.org)
4
+ (v1.1). markstay is a source-level identity primitive for Markdown blocks: an id
5
+ token that **stays** bound to its block across edits (marker `stay:`), so a
6
+ reference to a block survives the document being rewritten, including by an LLM.
7
+
8
+ This is the **parser-free core**: everything string-level and parser-independent
9
+ (§8 hashing, §3/§4 marker grammar, §5 blank-line segmentation, §7/§11 lint, §9
10
+ quote recovery, §9.1 resolution ladder). It mirrors the JavaScript reference
11
+ ([`markstay` on npm](https://www.npmjs.com/package/markstay)); both are gated by a
12
+ shared language-neutral conformance corpus, which turns "two implementations
13
+ agree" from an assertion into a tested fact.
14
+
15
+ ## Install
16
+
17
+ ```sh
18
+ pip install markstay
19
+ ```
20
+
21
+ Zero runtime dependencies (Python standard library only). CommonMark-tree
22
+ segmentation (§5.2) is an optional extra:
23
+
24
+ ```sh
25
+ pip install "markstay[commonmark]" # pulls in markdown-it-py
26
+ ```
27
+
28
+ Requires Python >= 3.9.
29
+
30
+ ## Library
31
+
32
+ ```python
33
+ import markstay as M
34
+
35
+ md = "The ingest stage retries three times.\n<!-- stay:a1b2 -->\n"
36
+
37
+ # parse into content blocks with attached markers (§5)
38
+ blocks = M.parse_document(md)
39
+
40
+ # well-formedness + intra-doc invariants (§7): duplicate/orphan/malformed/drift
41
+ _, findings = M.lint_document(md)
42
+
43
+ # regeneration diff (§11): what an edit did to the ids (dropped/duplicated/moved)
44
+ findings = M.lint_diff(before_md, after_md)
45
+
46
+ # §8 content hash (ASCII-normalized SHA-256)
47
+ M.body_hash("some block body")
48
+
49
+ # §9.1 resolution ladder: re-attach ids after an edit, or report DETACHED
50
+ anchors = M.build_anchors(before_md)
51
+ resolutions = M.resolve(anchors, after_md) # id -> marker | hash | quote | detached
52
+ ```
53
+
54
+ Public API (mirrors the JS `index.js` surface): `normalize_body`, `body_hash`,
55
+ `Marker`, `find_markers`, `strip_markers`, `segment_blank_line`,
56
+ `segment_commonmark`, `Block`, `parse_document`, `Finding`, `lint_document`,
57
+ `lint_diff`, `sort_findings`, `has_errors`, `Selector`, `normalize`,
58
+ `body_score`, `context_bonus`, `best_match`, `CONTEXT_CHARS`, `Anchor`,
59
+ `Resolution`, `build_anchors`, `resolve`, `DEFAULT_THRESHOLD`, `DEFAULT_MARGIN`.
60
+
61
+ ## CLI
62
+
63
+ ```sh
64
+ markstay FILE [FILE ...] # well-formedness + intra-doc checks
65
+ markstay --before OLD.md NEW.md # regeneration diff (dropped/duplicated/relocated ids)
66
+ markstay --json ... # machine-readable findings
67
+ markstay --commonmark ... # §5.2 CommonMark-tree segmentation (needs the extra)
68
+ ```
69
+
70
+ Exit status is non-zero when any error-level finding is reported, so it can gate
71
+ a commit hook or an agent's post-edit step.
72
+
73
+ ## The conformance corpus (the actual deliverable)
74
+
75
+ The corpus under [`conformance/`](conformance) is shared with the JavaScript
76
+ reference. **276 vectors** across two tiers:
77
+
78
+ - **`spec/`** , hand-authored from the spec prose, asserting what the *words*
79
+ require. These are authority; a `spec/` vector the reference fails is a
80
+ reference bug, not a corpus error.
81
+ - **`gen/`** , emitted from the reference for breadth/regression.
82
+
83
+ The JS reference runs the same JSON, so the two runners are a cross-impl
84
+ regression sentinel: any later change to either implementation that breaks
85
+ agreement fails one of them.
86
+
87
+ ## Running the tests
88
+
89
+ ```sh
90
+ pip install -e ".[commonmark]"
91
+ pytest
92
+ ```
93
+
94
+ ## License
95
+
96
+ MIT
@@ -0,0 +1,77 @@
1
+ {
2
+ "category": "diff",
3
+ "tier": "gen",
4
+ "vectors": [
5
+ {
6
+ "before": "A.\n<!-- stay:a -->\n\nB.\n<!-- stay:b -->\n",
7
+ "after": "A.\n<!-- stay:a -->\n\nB rewritten without its marker.\n",
8
+ "findings": [
9
+ {
10
+ "level": "error",
11
+ "code": "DROPPED_ID",
12
+ "id": "b"
13
+ }
14
+ ],
15
+ "name": "diff-000"
16
+ },
17
+ {
18
+ "before": "A.\n<!-- stay:a -->\n",
19
+ "after": "A.\n<!-- stay:a -->\n\nCopy of A.\n<!-- stay:a -->\n",
20
+ "findings": [
21
+ {
22
+ "level": "error",
23
+ "code": "DUPLICATED_ID",
24
+ "id": "a"
25
+ }
26
+ ],
27
+ "name": "diff-001"
28
+ },
29
+ {
30
+ "before": "A.\n<!-- stay:a -->\n",
31
+ "after": "A.\n<!-- stay:a -->\n\nBrand new block.\n<!-- stay:c -->\n",
32
+ "findings": [
33
+ {
34
+ "level": "info",
35
+ "code": "NEW_ID",
36
+ "id": "c"
37
+ }
38
+ ],
39
+ "name": "diff-002"
40
+ },
41
+ {
42
+ "before": "Alpha content.\n<!-- stay:aaa -->\n\nBeta content.\n<!-- stay:bbb -->\n",
43
+ "after": "Beta content.\n<!-- stay:aaa -->\n\nAlpha content.\n<!-- stay:bbb -->\n",
44
+ "findings": [
45
+ {
46
+ "level": "error",
47
+ "code": "RELOCATED_ID",
48
+ "id": "aaa"
49
+ },
50
+ {
51
+ "level": "error",
52
+ "code": "RELOCATED_ID",
53
+ "id": "bbb"
54
+ }
55
+ ],
56
+ "name": "diff-003"
57
+ },
58
+ {
59
+ "before": "Alpha content.\n<!-- stay:aaa -->\n",
60
+ "after": "Alpha content, now revised.\n<!-- stay:aaa -->\n",
61
+ "findings": [
62
+ {
63
+ "level": "warn",
64
+ "code": "HASH_DRIFT",
65
+ "id": "aaa"
66
+ }
67
+ ],
68
+ "name": "diff-004"
69
+ },
70
+ {
71
+ "before": "Keep me.\n<!-- stay:k -->\n",
72
+ "after": "Keep me.\n<!-- stay:k -->\n",
73
+ "findings": [],
74
+ "name": "diff-005"
75
+ }
76
+ ]
77
+ }
@@ -0,0 +1,174 @@
1
+ {
2
+ "category": "hash",
3
+ "tier": "gen",
4
+ "vectors": [
5
+ {
6
+ "body": "A single normalized paragraph.",
7
+ "normalized": "A single normalized paragraph.",
8
+ "sha256": "23d8cab5b86a660888effcf0c4371a2aadb5a30beb1be8b4e14c8bfc51739154",
9
+ "truncations": {
10
+ "4": "23d8",
11
+ "8": "23d8cab5",
12
+ "12": "23d8cab5b86a",
13
+ "16": "23d8cab5b86a6608"
14
+ },
15
+ "name": "hash-000"
16
+ },
17
+ {
18
+ "body": "trailing spaces here \nand a tab\there\t",
19
+ "normalized": "trailing spaces here\nand a tab\there",
20
+ "sha256": "7b5e1ac324fa21ecc3523b342bb2c4d16a8a54a16d58d904f9dfd12243f6c5d3",
21
+ "truncations": {
22
+ "4": "7b5e",
23
+ "8": "7b5e1ac3",
24
+ "12": "7b5e1ac324fa",
25
+ "16": "7b5e1ac324fa21ec"
26
+ },
27
+ "name": "hash-001"
28
+ },
29
+ {
30
+ "body": "windows\r\nline\r\nendings",
31
+ "normalized": "windows\nline\nendings",
32
+ "sha256": "0ce3289bdb1ff9c4923c4edb0d37e54292ce18e647611419a9117909fb602249",
33
+ "truncations": {
34
+ "4": "0ce3",
35
+ "8": "0ce3289b",
36
+ "12": "0ce3289bdb1f",
37
+ "16": "0ce3289bdb1ff9c4"
38
+ },
39
+ "name": "hash-002"
40
+ },
41
+ {
42
+ "body": "lone\rcarriage\rreturns",
43
+ "normalized": "lone\ncarriage\nreturns",
44
+ "sha256": "33c5d7f8e9e24720f276c251b18d28c80b1bf6c8d60deb39b01167bf5685e7c2",
45
+ "truncations": {
46
+ "4": "33c5",
47
+ "8": "33c5d7f8",
48
+ "12": "33c5d7f8e9e2",
49
+ "16": "33c5d7f8e9e24720"
50
+ },
51
+ "name": "hash-003"
52
+ },
53
+ {
54
+ "body": "\n\n\nleading and trailing blank lines\n\n\n",
55
+ "normalized": "leading and trailing blank lines",
56
+ "sha256": "88354b446814a0b4c0e33cb99cd60418104bc44438f62ff6096000189ce3450f",
57
+ "truncations": {
58
+ "4": "8835",
59
+ "8": "88354b44",
60
+ "12": "88354b446814",
61
+ "16": "88354b446814a0b4"
62
+ },
63
+ "name": "hash-004"
64
+ },
65
+ {
66
+ "body": " \n leading blank-ish lines with whitespace\nbody line\n \n",
67
+ "normalized": " leading blank-ish lines with whitespace\nbody line",
68
+ "sha256": "85c6052d5f101575261ccf0cdeb93436e5929104f3107408261915971d5bb83b",
69
+ "truncations": {
70
+ "4": "85c6",
71
+ "8": "85c6052d",
72
+ "12": "85c6052d5f10",
73
+ "16": "85c6052d5f101575"
74
+ },
75
+ "name": "hash-005"
76
+ },
77
+ {
78
+ "body": "```\ncode with trailing ws \n\tindented\t\n```",
79
+ "normalized": "```\ncode with trailing ws\n\tindented\n```",
80
+ "sha256": "08af614812a08ac12d45b113e923f040667a69bdba12a22ba169b9db69a40072",
81
+ "truncations": {
82
+ "4": "08af",
83
+ "8": "08af6148",
84
+ "12": "08af614812a0",
85
+ "16": "08af614812a08ac1"
86
+ },
87
+ "name": "hash-006"
88
+ },
89
+ {
90
+ "body": "café au lait , non-ASCII UTF-8 body",
91
+ "normalized": "café au lait , non-ASCII UTF-8 body",
92
+ "sha256": "60627234380043936d04070735bd0b17793e13373af36c734a6fae6a5d5fd850",
93
+ "truncations": {
94
+ "4": "6062",
95
+ "8": "60627234",
96
+ "12": "606272343800",
97
+ "16": "6062723438004393"
98
+ },
99
+ "name": "hash-007"
100
+ },
101
+ {
102
+ "body": "emoji body 😀 stays stable",
103
+ "normalized": "emoji body 😀 stays stable",
104
+ "sha256": "11f515982f0d3bde2de3245f973436fdb2f7d051c244857bc567866cbea8ccab",
105
+ "truncations": {
106
+ "4": "11f5",
107
+ "8": "11f51598",
108
+ "12": "11f515982f0d",
109
+ "16": "11f515982f0d3bde"
110
+ },
111
+ "name": "hash-008"
112
+ },
113
+ {
114
+ "body": "line one\nline two\nline three",
115
+ "normalized": "line one\nline two\nline three",
116
+ "sha256": "26a5cd654e540e91433a2f237e2709743fc4753e764deb74ed37299c2f338ece",
117
+ "truncations": {
118
+ "4": "26a5",
119
+ "8": "26a5cd65",
120
+ "12": "26a5cd654e54",
121
+ "16": "26a5cd654e540e91"
122
+ },
123
+ "name": "hash-009"
124
+ },
125
+ {
126
+ "body": "",
127
+ "normalized": "",
128
+ "sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
129
+ "truncations": {
130
+ "4": "e3b0",
131
+ "8": "e3b0c442",
132
+ "12": "e3b0c44298fc",
133
+ "16": "e3b0c44298fc1c14"
134
+ },
135
+ "name": "hash-010"
136
+ },
137
+ {
138
+ "body": " ",
139
+ "normalized": "",
140
+ "sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
141
+ "truncations": {
142
+ "4": "e3b0",
143
+ "8": "e3b0c442",
144
+ "12": "e3b0c44298fc",
145
+ "16": "e3b0c44298fc1c14"
146
+ },
147
+ "name": "hash-011"
148
+ },
149
+ {
150
+ "body": "\n\n",
151
+ "normalized": "",
152
+ "sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
153
+ "truncations": {
154
+ "4": "e3b0",
155
+ "8": "e3b0c442",
156
+ "12": "e3b0c44298fc",
157
+ "16": "e3b0c44298fc1c14"
158
+ },
159
+ "name": "hash-012"
160
+ },
161
+ {
162
+ "body": "one",
163
+ "normalized": "one",
164
+ "sha256": "7692c3ad3540bb803c020b3aee66cd8887123234ea0c6e7143c0add73ff431ed",
165
+ "truncations": {
166
+ "4": "7692",
167
+ "8": "7692c3ad",
168
+ "12": "7692c3ad3540",
169
+ "16": "7692c3ad3540bb80"
170
+ },
171
+ "name": "hash-013"
172
+ }
173
+ ]
174
+ }
@@ -0,0 +1,81 @@
1
+ {
2
+ "category": "lint",
3
+ "tier": "gen",
4
+ "vectors": [
5
+ {
6
+ "doc": "The order pipeline ingests messages and normalizes them.\n<!-- stay:8f24 hash=sha256:9c26 -->\n",
7
+ "findings": [],
8
+ "name": "lint-000"
9
+ },
10
+ {
11
+ "doc": "Users authenticate with an API key.\n<!-- stay:8f24 hash=sha256:9690 -->\n",
12
+ "findings": [],
13
+ "name": "lint-001"
14
+ },
15
+ {
16
+ "doc": "Block one.\n<!-- stay:dup -->\n\nBlock two.\n<!-- stay:dup -->\n",
17
+ "findings": [
18
+ {
19
+ "level": "error",
20
+ "code": "DUPLICATE_ID",
21
+ "id": "dup",
22
+ "line": 5
23
+ }
24
+ ],
25
+ "name": "lint-002"
26
+ },
27
+ {
28
+ "doc": "A paragraph.\n<!-- stay:note=hello -->\n",
29
+ "findings": [
30
+ {
31
+ "level": "error",
32
+ "code": "MALFORMED_MARKER",
33
+ "id": null,
34
+ "line": 2
35
+ }
36
+ ],
37
+ "name": "lint-003"
38
+ },
39
+ {
40
+ "doc": "<!-- stay:loose -->\n\nReal content below.\n",
41
+ "findings": [
42
+ {
43
+ "level": "error",
44
+ "code": "ORPHAN_MARKER",
45
+ "id": "loose",
46
+ "line": 1
47
+ }
48
+ ],
49
+ "name": "lint-004"
50
+ },
51
+ {
52
+ "doc": "Edited content.\n<!-- stay:z9 hash=sha256:dead -->\n",
53
+ "findings": [
54
+ {
55
+ "level": "warn",
56
+ "code": "HASH_DRIFT",
57
+ "id": "z9",
58
+ "line": 2
59
+ }
60
+ ],
61
+ "name": "lint-005"
62
+ },
63
+ {
64
+ "doc": "An MDX block.\n{/* stay:mdx1 hash=sha256:abcd */}\n",
65
+ "findings": [
66
+ {
67
+ "level": "warn",
68
+ "code": "HASH_DRIFT",
69
+ "id": "mdx1",
70
+ "line": 2
71
+ }
72
+ ],
73
+ "name": "lint-006"
74
+ },
75
+ {
76
+ "doc": "clean para.\n<!-- stay:ok -->\n\nanother.\n<!-- stay:ok2 -->\n",
77
+ "findings": [],
78
+ "name": "lint-007"
79
+ }
80
+ ]
81
+ }