Skip to content

Commit 9fd7ef9

Browse files
committed
First commit
1 parent 8e4f838 commit 9fd7ef9

File tree

373 files changed

+5413
-3947
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

373 files changed

+5413
-3947
lines changed

fix_blank_lines.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env python3
2+
import os
3+
4+
5+
def fix_blank_lines(file_path):
6+
with open(file_path, 'r') as f:
7+
lines = f.readlines()
8+
9+
new_lines = []
10+
blank_count = 0
11+
for line in lines:
12+
if line.strip() == '':
13+
blank_count += 1
14+
if blank_count <= 2:
15+
new_lines.append(line)
16+
else:
17+
blank_count = 0
18+
new_lines.append(line)
19+
20+
with open(file_path, 'w') as f:
21+
f.writelines(new_lines)
22+
23+
24+
def main():
25+
for root, dirs, files in os.walk('src'):
26+
for file in files:
27+
if file.endswith('.py'):
28+
fix_blank_lines(os.path.join(root, file))
29+
30+
31+
if __name__ == '__main__':
32+
main()

scripts/attach_test_refs.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
registry = []
1515
hex_id_re = re.compile(r"[0-9a-f]{10,}")
1616

17+
1718
def extract_tests_from_file(p: Path):
1819
txt = p.read_text()
1920
functions = re.findall(r"def\s+(test_[A-Za-z0-9_]+)", txt)
@@ -28,6 +29,7 @@ def extract_tests_from_file(p: Path):
2829
'content': txt,
2930
}
3031

32+
3133
for f in sorted(TEST_ROOT.rglob('test_*.py')):
3234
registry.append(extract_tests_from_file(f))
3335

scripts/audit_docs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@
3232
report = {'categories': categories, 'total_files': sum(len(v) for v in categories.values())}
3333
report_path = OUT / 'doc_classification_report.json'
3434
report_path.write_text(json.dumps(report, indent=2))
35-
print(json.dumps(report, indent=2))
35+
print(json.dumps(report, indent=2))

scripts/canonical_full_run.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ def run_once(tag: str):
2828

2929
# Clear persona/exec state
3030
exec_dir = Path("artifacts")
31-
for fname in ["execution_state_v1.json", "persona_annotations_v1.json", "persona_events_v1.json", "persona_events_v1.hash"]:
31+
for fname in [
32+
"execution_state_v1.json",
33+
"persona_annotations_v1.json",
34+
"persona_events_v1.json",
35+
"persona_events_v1.hash"]:
3236
p = exec_dir / fname
3337
if p.exists():
3438
p.unlink()
@@ -83,6 +87,8 @@ def run_once(tag: str):
8387
return run_dir, produced
8488

8589
# Run twice
90+
91+
8692
def main():
8793
run1_dir, run1_files = run_once("run1")
8894
run2_dir, run2_files = run_once("run2")

scripts/canonicalize_spec.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import os
1+
import yaml
22
import json
33
import hashlib
44
from pathlib import Path
@@ -10,7 +10,6 @@
1010
OUT_DIR.mkdir(parents=True, exist_ok=True)
1111

1212
# Load source YAML via safe loader
13-
import yaml
1413
src = yaml.safe_load(open(SRC))
1514

1615
# Helper
@@ -122,8 +121,27 @@
122121
out_spec.write_text(json.dumps(canonical, indent=2, sort_keys=True))
123122

124123
# Step 3: produce gap report
125-
missing_required_fields = [k for k, v in canonical.items() if v == UNKNOWN or (isinstance(v, dict) and any(vv == UNKNOWN or (isinstance(vv, list) and UNKNOWN in vv) for vv in v.values()))]
126-
ambiguous_sections = ["build_contract", "error_contract", "evidence_bundle", "state_machine", "schema_contract", "artifact_contract", "ci_contract", "generation_mappings", "observability", "security"]
124+
missing_required_fields = [
125+
k for k,
126+
v in canonical.items() if v == UNKNOWN or (
127+
isinstance(
128+
v,
129+
dict) and any(
130+
vv == UNKNOWN or (
131+
isinstance(
132+
vv,
133+
list) and UNKNOWN in vv) for vv in v.values()))]
134+
ambiguous_sections = [
135+
"build_contract",
136+
"error_contract",
137+
"evidence_bundle",
138+
"state_machine",
139+
"schema_contract",
140+
"artifact_contract",
141+
"ci_contract",
142+
"generation_mappings",
143+
"observability",
144+
"security"]
127145
blocked_generation_reasons = []
128146
if metadata["product_id"] == UNKNOWN:
129147
blocked_generation_reasons.append("missing_product_id")

scripts/ci/clean_pycache.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/usr/bin/env python3
22
"""Utility: remove stale __pycache__ and .pyc files in the repository (for CI hygiene)."""
3-
import os
43
import pathlib
54

65
root = pathlib.Path(__file__).resolve().parents[2]

scripts/deep_dsl_field_trace.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
import ast, json, os
1+
import ast
2+
import json
3+
import os
24

35
TARGET = "artifacts/dsl_field_usage.json"
46

57
# Keys accessed via obj["key"] or dict.get("key")
8+
9+
610
class FieldAccessVisitor(ast.NodeVisitor):
711
def __init__(self):
812
self.keys = set()
@@ -27,6 +31,8 @@ def visit_Call(self, node):
2731
self.generic_visit(node)
2832

2933
# JSON pointer fragments inside string literals
34+
35+
3036
class PointerVisitor(ast.NodeVisitor):
3137
def __init__(self):
3238
self.fragments = set()
@@ -77,5 +83,6 @@ def main():
7783
with open(TARGET, "w", encoding="utf-8") as f:
7884
json.dump(out, f, indent=2)
7985

86+
8087
if __name__ == "__main__":
8188
main()

scripts/dsl_runtime_reflector.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import json, os, importlib
1+
import json
2+
import importlib
23
from inspect import getmembers, isclass, isfunction
34

45
SCHEMA_PATH = 'spec/schemas/se_dsl_v1.schema.json'
@@ -10,6 +11,7 @@
1011

1112
schema_fields = set()
1213

14+
1315
def walk_schema(node, prefix=''):
1416
if isinstance(node, dict):
1517
for k, v in node.items():
@@ -22,6 +24,7 @@ def walk_schema(node, prefix=''):
2224
for item in node:
2325
walk_schema(item, prefix)
2426

27+
2528
walk_schema(schema)
2629

2730
# Runtime structural extraction
@@ -35,6 +38,7 @@ def walk_schema(node, prefix=''):
3538
'shieldcraft',
3639
]
3740

41+
3842
def collect_from_object(obj):
3943
# Look for attribute access patterns
4044
for name in dir(obj):
@@ -61,6 +65,7 @@ def load_and_reflect():
6165
except Exception:
6266
pass
6367

68+
6469
load_and_reflect()
6570

6671
# Compare schema fields and runtime fields

scripts/emit_manifest_dryrun.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,38 @@
22
"""
33
Emit manifest in dry-run mode for CI validation.
44
"""
5+
from shieldcraft.services.spec.schema_validator import validate_spec_against_schema
6+
from shieldcraft.dsl.loader import load_spec
57
import json
68
import sys
79
from pathlib import Path
810

911
# Add src to path
1012
sys.path.insert(0, str(Path(__file__).parent.parent / "src"))
1113

12-
from shieldcraft.dsl.loader import load_spec
13-
from shieldcraft.services.spec.schema_validator import validate_spec_against_schema
14-
from shieldcraft.services.io.manifest_writer import write_manifest_v2
15-
1614

1715
def main():
1816
spec_path = "spec/se_dsl_v1.spec.json"
1917
schema_path = "spec/schemas/se_dsl_v1.schema.json"
20-
18+
2119
# Load spec using canonical DSL
2220
spec = load_spec(spec_path)
23-
21+
2422
# Extract raw dict from SpecModel if needed
2523
if hasattr(spec, 'raw'):
2624
spec_raw = spec.raw
2725
else:
2826
spec_raw = spec
29-
27+
3028
# Validate
3129
valid, errors = validate_spec_against_schema(spec_raw, schema_path)
32-
30+
3331
if not valid:
3432
print("ERROR: Schema validation failed")
3533
for error in errors:
3634
print(f" - {error}")
3735
sys.exit(1)
38-
36+
3937
# Create dry-run manifest preview
4038
manifest_data = {
4139
"spec_path": spec_path,
@@ -44,12 +42,12 @@ def main():
4442
"validation": "passed",
4543
"dry_run": True
4644
}
47-
45+
4846
# Write preview
4947
Path("artifacts").mkdir(exist_ok=True)
5048
with open("artifacts/manifest_preview.json", "w") as f:
5149
json.dump(manifest_data, f, indent=2)
52-
50+
5351
print("Manifest preview written to artifacts/manifest_preview.json")
5452
return 0
5553

scripts/extract_dsl_field_usage.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
import os, json, ast
1+
import os
2+
import json
3+
import ast
24

35
TARGET_FILE = "artifacts/dsl_field_usage.json"
46

7+
58
def extract_keys_from_dict_nodes(node):
69
keys = []
710
if isinstance(node, ast.Dict):
@@ -10,6 +13,7 @@ def extract_keys_from_dict_nodes(node):
1013
keys.append(k.value)
1114
return keys
1215

16+
1317
def walk_file(path):
1418
keys = []
1519
try:
@@ -21,6 +25,7 @@ def walk_file(path):
2125
pass
2226
return keys
2327

28+
2429
def list_python_files():
2530
result = []
2631
for root, dirs, files in os.walk("src/shieldcraft"):
@@ -29,6 +34,7 @@ def list_python_files():
2934
result.append(os.path.join(root, f))
3035
return result
3136

37+
3238
def main():
3339
files = list_python_files()
3440
ast_fields = set()
@@ -64,5 +70,6 @@ def main():
6470
with open(TARGET_FILE, "w", encoding="utf-8") as f:
6571
json.dump(final, f, indent=2)
6672

73+
6774
if __name__ == "__main__":
6875
main()

0 commit comments

Comments
 (0)