@orbit-build/cli 0.4.4 → 0.4.5
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.
- package/commands/math-draft.md +11 -0
- package/dist/index.js +103 -10
- package/package.json +4 -2
- package/skills/math-model-draft/SKILL.md +216 -0
- package/skills/math-model-draft/agents/openai.yaml +6 -0
- package/skills/math-model-draft/assets/project-template/code/always/__init__.py +1 -0
- package/skills/math-model-draft/assets/project-template/code/always/config.py +17 -0
- package/skills/math-model-draft/assets/project-template/code/always/data.py +23 -0
- package/skills/math-model-draft/assets/project-template/code/always/plotting.py +24 -0
- package/skills/math-model-draft/assets/project-template/code/always/validation.py +20 -0
- package/skills/math-model-draft/assets/project-template/code/finalize.py +55 -0
- package/skills/math-model-draft/assets/project-template/code/requirements.txt +11 -0
- package/skills/math-model-draft/assets/project-template/paper/AI/345/267/245/345/205/267/344/275/277/347/224/250/350/257/246/346/203/205.tex +34 -0
- package/skills/math-model-draft/assets/project-template/paper/ai-use-log.md +7 -0
- package/skills/math-model-draft/assets/project-template/paper/contest-profile.json +25 -0
- package/skills/math-model-draft/assets/project-template/paper/main.tex +53 -0
- package/skills/math-model-draft/assets/project-template/paper/sections/abstract.tex +6 -0
- package/skills/math-model-draft/assets/project-template/paper/sections/ai-disclosure.tex +3 -0
- package/skills/math-model-draft/assets/project-template/paper/sections/appendix.tex +9 -0
- package/skills/math-model-draft/assets/project-template/paper/sections/assumptions.tex +5 -0
- package/skills/math-model-draft/assets/project-template/paper/sections/data.tex +19 -0
- package/skills/math-model-draft/assets/project-template/paper/sections/evaluation.tex +9 -0
- package/skills/math-model-draft/assets/project-template/paper/sections/problem-analysis.tex +3 -0
- package/skills/math-model-draft/assets/project-template/paper/sections/problem-restatement.tex +3 -0
- package/skills/math-model-draft/assets/project-template/paper/sections/references.tex +6 -0
- package/skills/math-model-draft/assets/project-template/paper/sections/source-code.tex +1 -0
- package/skills/math-model-draft/assets/project-template/paper/sections/support-files.tex +3 -0
- package/skills/math-model-draft/references/code-and-output-style.md +91 -0
- package/skills/math-model-draft/references/cumcm-compliance.md +56 -0
- package/skills/math-model-draft/references/latex-figures-tables.md +60 -0
- package/skills/math-model-draft/references/modeling-quality.md +91 -0
- package/skills/math-model-draft/references/paper-architecture.md +125 -0
- package/skills/math-model-draft/references/paper-revision.md +76 -0
- package/skills/math-model-draft/references/project-architecture.md +65 -0
- package/skills/math-model-draft/scripts/audit_paper.py +185 -0
- package/skills/math-model-draft/scripts/bootstrap_project.py +275 -0
- package/skills/math-model-draft/scripts/build_paper.py +226 -0
- package/skills/math-model-draft/scripts/capture_environment.py +46 -0
- package/skills/math-model-draft/scripts/clean_project.py +46 -0
- package/skills/math-model-draft/scripts/finalize_project.py +49 -0
- package/skills/math-model-draft/scripts/inspect_inputs.py +193 -0
- package/skills/math-model-draft/scripts/package_support.py +52 -0
- package/skills/math-model-draft/scripts/project_utils.py +106 -0
- package/skills/math-model-draft/scripts/validate_project.py +313 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import re
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import Any, Iterable
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
DEFAULT_PROFILE: dict[str, Any] = {
|
|
10
|
+
"schema_version": 1,
|
|
11
|
+
"profile": "generic",
|
|
12
|
+
"paper": {
|
|
13
|
+
"max_pdf_mb": None,
|
|
14
|
+
"max_body_pages": None,
|
|
15
|
+
"include_support_file_list": False,
|
|
16
|
+
"include_source_appendix": False,
|
|
17
|
+
},
|
|
18
|
+
"support": {"max_archive_mb": None, "include_ai_log": False},
|
|
19
|
+
"ai": {
|
|
20
|
+
"policy": "supplied-rules",
|
|
21
|
+
"used": True,
|
|
22
|
+
"declaration_before_references": True,
|
|
23
|
+
"details_pdf_required": False,
|
|
24
|
+
},
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def load_profile(root: Path) -> dict[str, Any]:
|
|
29
|
+
path = root / "paper" / "contest-profile.json"
|
|
30
|
+
if not path.is_file():
|
|
31
|
+
return json.loads(json.dumps(DEFAULT_PROFILE))
|
|
32
|
+
try:
|
|
33
|
+
payload = json.loads(path.read_text(encoding="utf-8"))
|
|
34
|
+
except (OSError, json.JSONDecodeError) as error:
|
|
35
|
+
raise ValueError(f"invalid contest profile {path}: {error}") from error
|
|
36
|
+
if not isinstance(payload, dict) or payload.get("schema_version") != 1:
|
|
37
|
+
raise ValueError("contest-profile.json requires schema_version 1")
|
|
38
|
+
merged = json.loads(json.dumps(DEFAULT_PROFILE))
|
|
39
|
+
for key, value in payload.items():
|
|
40
|
+
if isinstance(value, dict) and isinstance(merged.get(key), dict):
|
|
41
|
+
merged[key].update(value)
|
|
42
|
+
else:
|
|
43
|
+
merged[key] = value
|
|
44
|
+
return merged
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def numeric_limit(section: dict[str, Any], name: str) -> float | None:
|
|
48
|
+
value = section.get(name)
|
|
49
|
+
if value is None:
|
|
50
|
+
return None
|
|
51
|
+
if isinstance(value, bool) or not isinstance(value, (int, float)) or value <= 0:
|
|
52
|
+
raise ValueError(f"profile field {name} must be null or a positive number")
|
|
53
|
+
return float(value)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def ensure_safe_file(root: Path, path: Path, prefixes: Iterable[str]) -> Path:
|
|
57
|
+
resolved_root = root.resolve()
|
|
58
|
+
if path.is_symlink():
|
|
59
|
+
raise ValueError(f"symbolic links are not allowed: {path}")
|
|
60
|
+
resolved = path.resolve()
|
|
61
|
+
try:
|
|
62
|
+
relative = resolved.relative_to(resolved_root)
|
|
63
|
+
except ValueError as error:
|
|
64
|
+
raise ValueError(f"path escapes project root: {path}") from error
|
|
65
|
+
allowed = set(prefixes)
|
|
66
|
+
if not relative.parts or relative.parts[0] not in allowed:
|
|
67
|
+
raise ValueError(f"path is outside allowed directories {sorted(allowed)}: {relative}")
|
|
68
|
+
return resolved
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def iter_regular_files(root: Path, directory: str, excluded: set[str]) -> list[Path]:
|
|
72
|
+
base = root / directory
|
|
73
|
+
if not base.exists():
|
|
74
|
+
return []
|
|
75
|
+
if base.is_symlink():
|
|
76
|
+
raise ValueError(f"symbolic directory is not allowed: {base}")
|
|
77
|
+
files: list[Path] = []
|
|
78
|
+
for path in base.rglob("*"):
|
|
79
|
+
if any(part in excluded for part in path.relative_to(root).parts):
|
|
80
|
+
continue
|
|
81
|
+
if path.is_symlink():
|
|
82
|
+
raise ValueError(f"symbolic links are not allowed: {path}")
|
|
83
|
+
if path.is_file():
|
|
84
|
+
ensure_safe_file(root, path, {directory})
|
|
85
|
+
files.append(path)
|
|
86
|
+
return sorted(files)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def question_numbers(root: Path) -> set[int]:
|
|
90
|
+
numbers: set[int] = set()
|
|
91
|
+
pattern = re.compile(r"q([1-9]\d*)$")
|
|
92
|
+
for base_name in ("code", "results", "figures"):
|
|
93
|
+
base = root / base_name
|
|
94
|
+
if not base.is_dir():
|
|
95
|
+
continue
|
|
96
|
+
for path in base.iterdir():
|
|
97
|
+
match = pattern.fullmatch(path.name)
|
|
98
|
+
if path.is_dir() and match:
|
|
99
|
+
numbers.add(int(match.group(1)))
|
|
100
|
+
sections = root / "paper" / "sections"
|
|
101
|
+
if sections.is_dir():
|
|
102
|
+
for path in sections.glob("q*.tex"):
|
|
103
|
+
match = re.fullmatch(r"q([1-9]\d*)\.tex", path.name)
|
|
104
|
+
if match:
|
|
105
|
+
numbers.add(int(match.group(1)))
|
|
106
|
+
return numbers
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import hashlib
|
|
5
|
+
import json
|
|
6
|
+
import re
|
|
7
|
+
import subprocess
|
|
8
|
+
import sys
|
|
9
|
+
import zipfile
|
|
10
|
+
from pathlib import Path, PurePosixPath
|
|
11
|
+
from typing import Any
|
|
12
|
+
|
|
13
|
+
from project_utils import ensure_safe_file, load_profile, numeric_limit, question_numbers
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def sha256(path: Path) -> str:
|
|
17
|
+
digest = hashlib.sha256()
|
|
18
|
+
with path.open("rb") as stream:
|
|
19
|
+
for chunk in iter(lambda: stream.read(1024 * 1024), b""):
|
|
20
|
+
digest.update(chunk)
|
|
21
|
+
return digest.hexdigest()
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def read_json(path: Path) -> dict[str, Any]:
|
|
25
|
+
payload = json.loads(path.read_text(encoding="utf-8"))
|
|
26
|
+
if not isinstance(payload, dict):
|
|
27
|
+
raise ValueError("root must be an object")
|
|
28
|
+
return payload
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def load_evidence_yaml(path: Path) -> dict[str, Any]:
|
|
32
|
+
try:
|
|
33
|
+
import yaml
|
|
34
|
+
except ImportError:
|
|
35
|
+
return load_simple_evidence_yaml(path)
|
|
36
|
+
try:
|
|
37
|
+
payload = yaml.safe_load(path.read_text(encoding="utf-8"))
|
|
38
|
+
except Exception as error: # PyYAML exposes parser-specific subclasses.
|
|
39
|
+
raise ValueError(str(error)) from error
|
|
40
|
+
if not isinstance(payload, dict):
|
|
41
|
+
raise ValueError("root must be a mapping")
|
|
42
|
+
return payload
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def load_simple_evidence_yaml(path: Path) -> dict[str, Any]:
|
|
46
|
+
"""Parse the bundled flat qN/claims schema when PyYAML is unavailable."""
|
|
47
|
+
payload: dict[str, Any] = {}
|
|
48
|
+
current_question: dict[str, Any] | None = None
|
|
49
|
+
current_claim: dict[str, str] | None = None
|
|
50
|
+
for number, raw in enumerate(path.read_text(encoding="utf-8").splitlines(), start=1):
|
|
51
|
+
line = raw.split("#", 1)[0].rstrip()
|
|
52
|
+
if not line.strip():
|
|
53
|
+
continue
|
|
54
|
+
question_match = re.fullmatch(r"(q[1-9]\d*):", line)
|
|
55
|
+
if question_match:
|
|
56
|
+
current_question = {"claims": []}
|
|
57
|
+
payload[question_match.group(1)] = current_question
|
|
58
|
+
current_claim = None
|
|
59
|
+
continue
|
|
60
|
+
stripped = line.strip()
|
|
61
|
+
if stripped == "claims:" and current_question is not None:
|
|
62
|
+
continue
|
|
63
|
+
field_match = re.fullmatch(
|
|
64
|
+
r"(?:-\s*)?([A-Za-z_][A-Za-z0-9_]*):\s*(.*?)\s*",
|
|
65
|
+
stripped,
|
|
66
|
+
)
|
|
67
|
+
if not field_match or current_question is None:
|
|
68
|
+
raise ValueError(
|
|
69
|
+
f"unsupported evidence YAML syntax at line {number}: {raw}"
|
|
70
|
+
)
|
|
71
|
+
field, value = field_match.groups()
|
|
72
|
+
if stripped.startswith("-"):
|
|
73
|
+
current_claim = {}
|
|
74
|
+
current_question["claims"].append(current_claim)
|
|
75
|
+
if current_claim is None:
|
|
76
|
+
raise ValueError(f"claim field outside a list item at line {number}")
|
|
77
|
+
current_claim[field] = value.strip("\"'")
|
|
78
|
+
return payload
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def validate_evidence(root: Path, count: int, errors: list[str], warnings: list[str]) -> None:
|
|
82
|
+
path = root / "paper" / "evidence-map.yaml"
|
|
83
|
+
if not path.is_file():
|
|
84
|
+
errors.append("missing paper/evidence-map.yaml")
|
|
85
|
+
return
|
|
86
|
+
try:
|
|
87
|
+
payload = load_evidence_yaml(path)
|
|
88
|
+
except (OSError, ValueError) as error:
|
|
89
|
+
errors.append(f"invalid evidence-map.yaml: {error}")
|
|
90
|
+
return
|
|
91
|
+
valid_status = {"TODO", "verified"}
|
|
92
|
+
seen_ids: set[str] = set()
|
|
93
|
+
for number in range(1, count + 1):
|
|
94
|
+
key = f"q{number}"
|
|
95
|
+
block = payload.get(key)
|
|
96
|
+
if not isinstance(block, dict) or not isinstance(block.get("claims"), list):
|
|
97
|
+
errors.append(f"evidence map requires {key}.claims list")
|
|
98
|
+
continue
|
|
99
|
+
for index, claim in enumerate(block["claims"], start=1):
|
|
100
|
+
location = f"{key}.claims[{index}]"
|
|
101
|
+
if not isinstance(claim, dict):
|
|
102
|
+
errors.append(f"{location} must be a mapping")
|
|
103
|
+
continue
|
|
104
|
+
claim_id = claim.get("id")
|
|
105
|
+
if not isinstance(claim_id, str) or not claim_id.strip():
|
|
106
|
+
errors.append(f"{location}.id is required")
|
|
107
|
+
elif claim_id in seen_ids:
|
|
108
|
+
errors.append(f"duplicate evidence id: {claim_id}")
|
|
109
|
+
else:
|
|
110
|
+
seen_ids.add(claim_id)
|
|
111
|
+
for field, prefix in (("source", "results"), ("paper_section", "paper")):
|
|
112
|
+
value = claim.get(field)
|
|
113
|
+
if not isinstance(value, str) or not value:
|
|
114
|
+
errors.append(f"{location}.{field} is required")
|
|
115
|
+
continue
|
|
116
|
+
candidate = root / value
|
|
117
|
+
try:
|
|
118
|
+
resolved = ensure_safe_file(root, candidate, {prefix})
|
|
119
|
+
except ValueError as error:
|
|
120
|
+
errors.append(f"unsafe {location}.{field}: {error}")
|
|
121
|
+
continue
|
|
122
|
+
relative = resolved.relative_to(root).as_posix()
|
|
123
|
+
if field == "paper_section" and not relative.startswith("paper/sections/"):
|
|
124
|
+
errors.append(f"{location}.paper_section must be under paper/sections/")
|
|
125
|
+
if not resolved.is_file():
|
|
126
|
+
errors.append(f"evidence path does not exist: {value}")
|
|
127
|
+
status = claim.get("status")
|
|
128
|
+
if status not in valid_status:
|
|
129
|
+
errors.append(f"{location}.status must be TODO or verified")
|
|
130
|
+
elif status == "TODO":
|
|
131
|
+
warnings.append(f"unresolved evidence claim: {claim_id or location}")
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def main() -> None:
|
|
135
|
+
parser = argparse.ArgumentParser(description="Audit a modeling project and active contest profile.")
|
|
136
|
+
parser.add_argument("project_root", type=Path)
|
|
137
|
+
parser.add_argument("--strict", action="store_true")
|
|
138
|
+
parser.add_argument("--run-code", action="store_true")
|
|
139
|
+
args = parser.parse_args()
|
|
140
|
+
root = args.project_root.resolve()
|
|
141
|
+
errors: list[str] = []
|
|
142
|
+
warnings: list[str] = []
|
|
143
|
+
try:
|
|
144
|
+
profile = load_profile(root)
|
|
145
|
+
paper_profile = profile["paper"]
|
|
146
|
+
support_profile = profile["support"]
|
|
147
|
+
ai_profile = profile["ai"]
|
|
148
|
+
assert isinstance(paper_profile, dict) and isinstance(support_profile, dict) and isinstance(ai_profile, dict)
|
|
149
|
+
pdf_limit = numeric_limit(paper_profile, "max_pdf_mb")
|
|
150
|
+
page_limit = numeric_limit(paper_profile, "max_body_pages")
|
|
151
|
+
archive_limit = numeric_limit(support_profile, "max_archive_mb")
|
|
152
|
+
except (ValueError, TypeError, AssertionError) as error:
|
|
153
|
+
errors.append(str(error))
|
|
154
|
+
profile = {}
|
|
155
|
+
paper_profile = support_profile = ai_profile = {}
|
|
156
|
+
pdf_limit = page_limit = archive_limit = None
|
|
157
|
+
|
|
158
|
+
for name in ("question", "code", "results", "figures", "paper"):
|
|
159
|
+
path = root / name
|
|
160
|
+
if not path.is_dir():
|
|
161
|
+
errors.append(f"missing top-level directory: {name}/")
|
|
162
|
+
elif path.is_symlink():
|
|
163
|
+
errors.append(f"symbolic top-level directory is unsafe: {name}/")
|
|
164
|
+
|
|
165
|
+
count_path = root / "paper" / "question-count.json"
|
|
166
|
+
count = 0
|
|
167
|
+
if not count_path.is_file():
|
|
168
|
+
errors.append("missing paper/question-count.json")
|
|
169
|
+
else:
|
|
170
|
+
try:
|
|
171
|
+
count = int(read_json(count_path).get("questions", 0))
|
|
172
|
+
except (OSError, ValueError, json.JSONDecodeError) as error:
|
|
173
|
+
errors.append(f"invalid paper/question-count.json: {error}")
|
|
174
|
+
if not 1 <= count <= 20:
|
|
175
|
+
errors.append("paper/question-count.json must declare 1 to 20 questions")
|
|
176
|
+
discovered = question_numbers(root)
|
|
177
|
+
if discovered and max(discovered) > count:
|
|
178
|
+
errors.append(f"question-count.json omits discovered subproblem q{max(discovered)}")
|
|
179
|
+
|
|
180
|
+
if args.run_code:
|
|
181
|
+
entry = root / "code" / "run_all.py"
|
|
182
|
+
if not entry.is_file():
|
|
183
|
+
errors.append("missing code/run_all.py")
|
|
184
|
+
else:
|
|
185
|
+
completed = subprocess.run([sys.executable, str(entry)], cwd=root / "code", stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, encoding="utf-8", errors="replace", check=False)
|
|
186
|
+
if completed.returncode:
|
|
187
|
+
errors.append("code/run_all.py failed:\n" + "\n".join(completed.stdout.splitlines()[-25:]))
|
|
188
|
+
else:
|
|
189
|
+
print("[OK] code/run_all.py completed")
|
|
190
|
+
|
|
191
|
+
for number in range(1, count + 1):
|
|
192
|
+
name = f"q{number}"
|
|
193
|
+
required = (f"code/{name}", f"results/{name}", f"figures/{name}", f"paper/sections/{name}.tex")
|
|
194
|
+
for relative in required:
|
|
195
|
+
if not (root / relative).exists():
|
|
196
|
+
errors.append(f"missing subproblem artifact: {relative}")
|
|
197
|
+
summary = root / "results" / name / "summary.json"
|
|
198
|
+
if not summary.is_file():
|
|
199
|
+
errors.append(f"missing result evidence: results/{name}/summary.json")
|
|
200
|
+
else:
|
|
201
|
+
try:
|
|
202
|
+
if read_json(summary).get("status") == "TODO":
|
|
203
|
+
warnings.append(f"{name} still emits placeholder results")
|
|
204
|
+
except (OSError, ValueError, json.JSONDecodeError) as error:
|
|
205
|
+
errors.append(f"invalid {summary.relative_to(root)}: {error}")
|
|
206
|
+
|
|
207
|
+
inventory_path = root / "paper" / "input-inventory.json"
|
|
208
|
+
if not inventory_path.is_file():
|
|
209
|
+
warnings.append("input inventory is missing; run inspect_inputs.py")
|
|
210
|
+
else:
|
|
211
|
+
try:
|
|
212
|
+
inventory = read_json(inventory_path)
|
|
213
|
+
unresolved = [item.get("path", "unknown") for item in inventory.get("files", []) if isinstance(item, dict) and item.get("status") != "ok" and not item.get("details", {}).get("blank")]
|
|
214
|
+
if unresolved:
|
|
215
|
+
warnings.append("unresolved input inspection: " + ", ".join(map(str, unresolved)))
|
|
216
|
+
except (OSError, ValueError, json.JSONDecodeError) as error:
|
|
217
|
+
errors.append(f"invalid input inventory: {error}")
|
|
218
|
+
|
|
219
|
+
baseline = root / "paper" / "question-fingerprint.json"
|
|
220
|
+
if not baseline.is_file():
|
|
221
|
+
warnings.append("question fingerprint baseline is missing; run inspect_inputs.py")
|
|
222
|
+
elif (root / "question").is_dir():
|
|
223
|
+
try:
|
|
224
|
+
expected = {str(item["path"]): str(item["sha256"]) for item in read_json(baseline).get("files", [])}
|
|
225
|
+
actual = {path.relative_to(root).as_posix(): sha256(path) for path in sorted((root / "question").rglob("*")) if path.is_file() and not path.is_symlink()}
|
|
226
|
+
if actual != expected:
|
|
227
|
+
errors.append("question/ changed after its fingerprint baseline was recorded")
|
|
228
|
+
except (KeyError, OSError, ValueError, json.JSONDecodeError) as error:
|
|
229
|
+
errors.append(f"invalid question fingerprint: {error}")
|
|
230
|
+
|
|
231
|
+
compile_result = subprocess.run([sys.executable, "-m", "compileall", "-q", str(root / "code")], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, check=False)
|
|
232
|
+
if compile_result.returncode:
|
|
233
|
+
errors.append("Python compile failed: " + compile_result.stdout.strip())
|
|
234
|
+
validate_evidence(root, count, errors, warnings)
|
|
235
|
+
|
|
236
|
+
tex_files = [path for path in (root / "paper").rglob("*.tex") if path.is_file() and not path.is_symlink()]
|
|
237
|
+
tex = "\n".join(path.read_text(encoding="utf-8", errors="replace") for path in tex_files)
|
|
238
|
+
todo_count = tex.count(r"\TODO{") + len(re.findall(r"TODO\[", tex))
|
|
239
|
+
if todo_count:
|
|
240
|
+
warnings.append(f"paper contains {todo_count} visible TODO marker(s)")
|
|
241
|
+
if re.search(r"[A-Za-z]:[\\/]", tex):
|
|
242
|
+
errors.append("paper contains an absolute Windows path")
|
|
243
|
+
if re.search(r"(姓名|学号|学校|指导教师)\s*[::]\s*\S+", tex):
|
|
244
|
+
warnings.append("paper may contain identifying information")
|
|
245
|
+
main_tex = root / "paper" / "main.tex"
|
|
246
|
+
if bool(ai_profile.get("used")) and bool(ai_profile.get("declaration_before_references")) and main_tex.is_file():
|
|
247
|
+
content = main_tex.read_text(encoding="utf-8", errors="replace")
|
|
248
|
+
declaration = content.find("sections/ai-disclosure")
|
|
249
|
+
references = content.find("sections/references")
|
|
250
|
+
if declaration < 0 or references < 0 or declaration > references:
|
|
251
|
+
errors.append("AI use declaration must be included immediately before references")
|
|
252
|
+
|
|
253
|
+
pdf = root / "paper" / "main.pdf"
|
|
254
|
+
if not pdf.is_file():
|
|
255
|
+
errors.append("paper/main.pdf is missing; run build_paper.py")
|
|
256
|
+
else:
|
|
257
|
+
if pdf_limit is not None and pdf.stat().st_size > pdf_limit * 1024 * 1024:
|
|
258
|
+
errors.append(f"paper/main.pdf exceeds active {pdf_limit:g} MB limit")
|
|
259
|
+
if any(path.stat().st_mtime > pdf.stat().st_mtime for path in tex_files):
|
|
260
|
+
warnings.append("paper/main.pdf is older than at least one TeX source")
|
|
261
|
+
|
|
262
|
+
archive = root / "paper" / "support-materials.zip"
|
|
263
|
+
if not archive.is_file():
|
|
264
|
+
warnings.append("support-materials.zip is missing; run package_support.py")
|
|
265
|
+
else:
|
|
266
|
+
if archive_limit is not None and archive.stat().st_size > archive_limit * 1024 * 1024:
|
|
267
|
+
errors.append(f"support-materials.zip exceeds active {archive_limit:g} MB limit")
|
|
268
|
+
try:
|
|
269
|
+
with zipfile.ZipFile(archive) as bundle:
|
|
270
|
+
names = bundle.namelist()
|
|
271
|
+
unsafe = [name for name in names if PurePosixPath(name.replace("\\", "/")).is_absolute() or ".." in PurePosixPath(name.replace("\\", "/")).parts or re.match(r"^[A-Za-z]:", name)]
|
|
272
|
+
if unsafe:
|
|
273
|
+
errors.append("support archive contains unsafe absolute/traversal paths")
|
|
274
|
+
if any(name.replace("\\", "/").lower().startswith("question/") for name in names):
|
|
275
|
+
errors.append("support archive contains immutable question input files")
|
|
276
|
+
if "paper/ai-use-log.md" in names and not bool(support_profile.get("include_ai_log")):
|
|
277
|
+
errors.append("support archive leaks internal ai-use-log.md contrary to profile")
|
|
278
|
+
if bool(ai_profile.get("used")) and bool(ai_profile.get("details_pdf_required")) and "paper/AI工具使用详情.pdf" not in names:
|
|
279
|
+
errors.append("support archive is missing required AI工具使用详情.pdf")
|
|
280
|
+
except zipfile.BadZipFile:
|
|
281
|
+
errors.append("paper/support-materials.zip is not a valid ZIP archive")
|
|
282
|
+
|
|
283
|
+
aux = root / "paper" / "build" / "main.aux"
|
|
284
|
+
if page_limit is not None and aux.is_file():
|
|
285
|
+
match = re.search(r"\\newlabel\{body-end\}\{\{.*?\}\{(\d+)\}", aux.read_text(encoding="utf-8", errors="replace"))
|
|
286
|
+
if match:
|
|
287
|
+
body_pages = max(int(match.group(1)) - 1, 0)
|
|
288
|
+
if body_pages > page_limit:
|
|
289
|
+
errors.append(f"paper body has {body_pages} pages; active limit is {page_limit:g}")
|
|
290
|
+
else:
|
|
291
|
+
print(f" Body page audit: {body_pages}/{page_limit:g}")
|
|
292
|
+
else:
|
|
293
|
+
warnings.append("could not resolve body-end page label")
|
|
294
|
+
|
|
295
|
+
if bool(ai_profile.get("used")):
|
|
296
|
+
disclosure = root / "paper" / "ai-use-log.md"
|
|
297
|
+
if not disclosure.is_file():
|
|
298
|
+
warnings.append("internal AI use log is missing")
|
|
299
|
+
if bool(ai_profile.get("details_pdf_required")) and not (root / "paper" / "AI工具使用详情.pdf").is_file():
|
|
300
|
+
errors.append("AI tool disclosure PDF is required but missing")
|
|
301
|
+
|
|
302
|
+
print(f"[RUN] Validation summary: {len(errors)} error(s), {len(warnings)} warning(s)")
|
|
303
|
+
for message in errors:
|
|
304
|
+
print(f"[ERROR] {message}")
|
|
305
|
+
for message in warnings:
|
|
306
|
+
print(f"[WARN] {message}")
|
|
307
|
+
if errors or (args.strict and warnings):
|
|
308
|
+
raise SystemExit(1)
|
|
309
|
+
print("[OK] Structure, provenance, evidence, syntax, profile, and delivery checks passed")
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
if __name__ == "__main__":
|
|
313
|
+
main()
|