OXYGENHUB
# 9054759cfbd1 oxygen / format_xenon.py
3.9 KiB · Python · last changed Diffs no longer anchor a block of new lines one line early 1 month ago source blame history raw
1
import re
2
3
with open('/home/andymccall/development/oxygen/docs/xenon_spec.md', 'r') as f:
4
    text = f.read()
5
6
# Fix the preamble
7
text = re.sub(r'Format Version\s*:\s*(\d+)\nDate\s*:\s*(.*?)\nStatus\s*:\s*(.*?)\nTarget VCS\s*:\s*(.*?)\nAudience\s*:\s*(.*?)\n',
8
r'''| | |
9
|---|---|
10
| **Format version** | \1 |
11
| **Date** | \2 |
12
| **Status** | \3 |
13
| **Target VCS** | \4 |
14
| **Audience** | \5 |
15
''', text)
16
17
# Convert ==== headers to ##
18
text = re.sub(r'={10,}\n(.*?)\n={10,}', lambda m: f"## {m.group(1).strip()}", text)
19
20
# Convert 3.1 style headers to ###
21
text = re.sub(r'\n(\d+\.\d+\s+.*?)\n', r'\n### \1\n', text)
22
23
# Code block for KDL
24
text = text.replace('schema-version 1\n\n// Define', '```kdl\nschema-version 1\n\n// Define')
25
text = text.replace('    }\n}\n\n### 3.2', '    }\n}\n```\n\n### 3.2')
26
27
# Code block for Receipt
28
text = text.replace('Receipt {\n', '```cbor\nReceipt {\n')
29
text = text.replace('  duration_ms    [8]: u64\n}\n', '  duration_ms    [8]: u64\n}\n```\n')
30
31
# Code block for Attest
32
text = text.replace('Attest {\n', '```json\nAttest {\n')
33
text = text.replace('    }\n  }\n}\n\n### 7.2', '    }\n  }\n}\n```\n\n### 7.2')
34
35
# Code block for Signature
36
text = text.replace('Signature {\n', '```cbor\nSignature {\n')
37
text = text.replace('  ml  [3]: bytes(3309)                 // Post-quantum signature\n}\n', '  ml  [3]: bytes(3309)                 // Post-quantum signature\n}\n```\n')
38
39
# Code block for PolicyRule
40
text = text.replace('PolicyRule {\n', '```json\nPolicyRule {\n')
41
text = text.replace('      signer_roles: [ "official-worker" ]\n    }\n  ]\n}\n', '      signer_roles: [ "official-worker" ]\n    }\n  ]\n}\n```\n')
42
43
44
# Architectural Fixes:
45
46
# 1. Change change_closure to scope_tree_hash in Receipt
47
text = text.replace('change_closure [3]: [ChangeHash]  // Sorted minimal dependency closure', 'scope_tree_hash [3]: ObjectRef     // BLAKE3 tree hash of the materialized scope')
48
49
text = text.replace('''### 6.2 Cache Re-use Invariant
50
Let Scope(J) be the file paths and tree nodes declared by job J.
51
Let Closure(S) be the dependency closure of State S.
52
The restricted change closure is:
53
  C_J(S) = { c in Closure(S) | TouchedPaths(c) intersects Scope(J) }
54
55
If an existing Receipt R exists such that:
56
  R.job_name == J.name &&
57
  R.pipeline_hash == Hash(J) &&
58
  R.change_closure == C_J(S) &&
59
  R.environment == CurrentEnvironmentHash''', 
60
'''### 6.2 Cache Re-use Invariant
61
Let Scope(J) be the file paths and tree nodes declared by job J.
62
Because changes that do not share scopes commute, we do not need to track lists of ChangeHashes. Instead, we hash the materialized tree of Scope(J).
63
64
If an existing Receipt R exists such that:
65
  R.job_name == J.name &&
66
  R.pipeline_hash == Hash(J) &&
67
  R.scope_tree_hash == TreeHash(Scope(J)) &&
68
  R.environment == CurrentEnvironmentHash''')
69
70
# Fix provenance change_closure
71
text = text.replace('"change_closure": [ChangeHash],  // Transitive changes included', '"scope_tree_hash": ObjectRef,        // Captures exact state without O(N) array bloat')
72
73
# 2. Add Consensus Builds to Policy Integration
74
text = text.replace('''### 8.1 Policy Gate Definition
75
A Policy rule governing a bookmark MAY demand valid Xenon attestations:''',
76
'''### 8.1 Policy Gate Definition
77
A Policy rule governing a bookmark MAY demand valid Xenon attestations. To mitigate a compromised authorized worker, high-security repositories can require **Consensus Builds** by setting the threshold > 1. This requires multiple independent runner identities to arrive at the exact same output hashes and both sign it.''')
78
79
# 3. Add mmap performance note to 5.1
80
text = text.replace('- Missing chunks are fetched lazily using the POST /objects protocol.', '- Missing chunks are fetched lazily using the POST /objects protocol.\n   - To prevent FUSE context-switch bottlenecks on many small reads, xenon-casfs aggressively mmaps chunk data and utilizes host page caching.')
81
82
83
with open('/home/andymccall/development/oxygen/docs/xenon_spec.md', 'w') as f:
84
    f.write(text)