@orbit-build/cli 1.5.0 → 1.6.4
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/README.md +114 -3
- package/THIRD_PARTY_NOTICES.md +1 -0
- package/commands/cumcm-draft.md +3 -1
- package/dist/index.js +20538 -5446
- package/package.json +5 -3
- package/skills/cumcm-draft/SKILL.md +62 -36
- package/skills/cumcm-draft/agents/openai.yaml +1 -1
- package/skills/cumcm-draft/assets/project-template/.cumcm/profile.json +1 -0
- package/skills/cumcm-draft/references/code-and-output-style.md +13 -2
- package/skills/cumcm-draft/references/latex-figures-tables.md +4 -2
- package/skills/cumcm-draft/references/modeling-quality.md +17 -0
- package/skills/cumcm-draft/references/project-architecture.md +29 -23
- package/skills/cumcm-draft/scripts/audit_paper.py +6 -6
- package/skills/cumcm-draft/scripts/bootstrap_project.py +86 -28
- package/skills/cumcm-draft/scripts/build_paper.py +6 -8
- package/skills/cumcm-draft/scripts/capture_environment.py +31 -21
- package/skills/cumcm-draft/scripts/clean_project.py +91 -2
- package/skills/cumcm-draft/scripts/evidence_freeze.py +2 -2
- package/skills/cumcm-draft/scripts/finalize_project.py +35 -9
- package/skills/cumcm-draft/scripts/inspect_inputs.py +9 -1
- package/skills/cumcm-draft/scripts/package_support.py +50 -9
- package/skills/cumcm-draft/scripts/project_utils.py +9 -2
- package/skills/cumcm-draft/scripts/validate_project.py +67 -68
- package/skills/cumcm-draft/assets/project-template/.cumcm/finalize.py +0 -90
- /package/skills/cumcm-draft/assets/project-template/{paper → happy}/AI/345/267/245/345/205/267/344/275/277/347/224/250/350/257/246/346/203/205.tex" +0 -0
- /package/skills/cumcm-draft/assets/project-template/{paper → happy}/main.tex +0 -0
|
@@ -6,7 +6,12 @@ import re
|
|
|
6
6
|
import shutil
|
|
7
7
|
from pathlib import Path
|
|
8
8
|
|
|
9
|
-
from project_utils import
|
|
9
|
+
from project_utils import (
|
|
10
|
+
control_directory,
|
|
11
|
+
control_path,
|
|
12
|
+
delivery_directory,
|
|
13
|
+
question_numbers,
|
|
14
|
+
)
|
|
10
15
|
|
|
11
16
|
|
|
12
17
|
SKILL_ROOT = Path(__file__).resolve().parents[1]
|
|
@@ -42,7 +47,7 @@ def main() -> None:
|
|
|
42
47
|
for directory in (
|
|
43
48
|
root / "question",
|
|
44
49
|
root / "code",
|
|
45
|
-
root
|
|
50
|
+
delivery_directory(root),
|
|
46
51
|
control_directory(root),
|
|
47
52
|
control_directory(root) / "build",
|
|
48
53
|
control_directory(root) / "generated",
|
|
@@ -64,7 +69,7 @@ def main() -> None:
|
|
|
64
69
|
f"updated {len(updated)}, preserved {len(preserved)} file(s)."
|
|
65
70
|
)
|
|
66
71
|
print(
|
|
67
|
-
"
|
|
72
|
+
" happy/ contains editable TeX, final PDFs, and per-question submission copies; "
|
|
68
73
|
".cumcm/ owns workflow state and build caches."
|
|
69
74
|
)
|
|
70
75
|
if updated:
|
|
@@ -75,7 +80,10 @@ def main() -> None:
|
|
|
75
80
|
|
|
76
81
|
def remove_empty_legacy_layout_directories(root: Path, removed: list[str]) -> None:
|
|
77
82
|
"""Drop empty legacy shells without touching authored files or build output."""
|
|
78
|
-
for directory in (
|
|
83
|
+
for directory in (
|
|
84
|
+
delivery_directory(root) / "sections",
|
|
85
|
+
delivery_directory(root) / "build",
|
|
86
|
+
):
|
|
79
87
|
if not directory.is_dir() or directory.is_symlink():
|
|
80
88
|
continue
|
|
81
89
|
try:
|
|
@@ -104,7 +112,7 @@ def read_declared_count(root: Path) -> int:
|
|
|
104
112
|
path = control_path(
|
|
105
113
|
root,
|
|
106
114
|
"project.json",
|
|
107
|
-
root / "
|
|
115
|
+
delivery_directory(root) / "question-count.json",
|
|
108
116
|
)
|
|
109
117
|
if not path.is_file():
|
|
110
118
|
return 0
|
|
@@ -140,8 +148,9 @@ def create_question_files(
|
|
|
140
148
|
) -> None:
|
|
141
149
|
for number in range(1, count + 1):
|
|
142
150
|
name = f"q{number}"
|
|
151
|
+
question_code = root / "code" / name
|
|
143
152
|
for directory in (
|
|
144
|
-
|
|
153
|
+
question_code,
|
|
145
154
|
root / "results" / name,
|
|
146
155
|
root / "figures" / name,
|
|
147
156
|
):
|
|
@@ -149,12 +158,26 @@ def create_question_files(
|
|
|
149
158
|
write_if_missing(
|
|
150
159
|
root,
|
|
151
160
|
root / "code" / name / "main.py",
|
|
152
|
-
question_main(
|
|
161
|
+
question_main(),
|
|
153
162
|
created,
|
|
154
163
|
preserved,
|
|
155
164
|
)
|
|
156
|
-
|
|
157
|
-
|
|
165
|
+
substantive_modules = [
|
|
166
|
+
path
|
|
167
|
+
for path in question_code.glob("*.py")
|
|
168
|
+
if path.name not in {"__init__.py", "main.py"}
|
|
169
|
+
]
|
|
170
|
+
if not substantive_modules:
|
|
171
|
+
for filename, content in question_modules(name).items():
|
|
172
|
+
write_if_missing(
|
|
173
|
+
root,
|
|
174
|
+
question_code / filename,
|
|
175
|
+
content,
|
|
176
|
+
created,
|
|
177
|
+
preserved,
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
legacy_sections = delivery_directory(root) / "sections"
|
|
158
181
|
if legacy_sections.is_dir():
|
|
159
182
|
create_legacy_question_sections(
|
|
160
183
|
root, count, created, updated, preserved
|
|
@@ -175,12 +198,12 @@ def create_legacy_question_sections(
|
|
|
175
198
|
for number in range(1, count + 1):
|
|
176
199
|
write_if_missing(
|
|
177
200
|
root,
|
|
178
|
-
root / "
|
|
201
|
+
delivery_directory(root) / "sections" / f"q{number}.tex",
|
|
179
202
|
question_tex(number),
|
|
180
203
|
created,
|
|
181
204
|
preserved,
|
|
182
205
|
)
|
|
183
|
-
path = root / "
|
|
206
|
+
path = delivery_directory(root) / "sections" / "questions.tex"
|
|
184
207
|
if not path.exists():
|
|
185
208
|
path.write_text(
|
|
186
209
|
"".join(f"\\input{{sections/q{i}}}\n" for i in range(1, count + 1)),
|
|
@@ -203,13 +226,13 @@ def create_legacy_question_sections(
|
|
|
203
226
|
|
|
204
227
|
|
|
205
228
|
def merge_questions_into_main(root: Path, count: int, updated: list[str]) -> None:
|
|
206
|
-
path = root / "
|
|
229
|
+
path = delivery_directory(root) / "main.tex"
|
|
207
230
|
if not path.is_file():
|
|
208
|
-
raise SystemExit(f"Missing compact
|
|
231
|
+
raise SystemExit(f"Missing compact happy template: {path}")
|
|
209
232
|
content = path.read_text(encoding="utf-8")
|
|
210
233
|
if QUESTION_BEGIN not in content or QUESTION_END not in content:
|
|
211
234
|
print(
|
|
212
|
-
"[WARN] Preserved custom
|
|
235
|
+
"[WARN] Preserved custom happy/main.tex without Orbit question markers; "
|
|
213
236
|
"add missing question sections manually."
|
|
214
237
|
)
|
|
215
238
|
return
|
|
@@ -270,7 +293,7 @@ def write_project_manifest(
|
|
|
270
293
|
existing["schema_version"] = 1
|
|
271
294
|
existing["layout"] = (
|
|
272
295
|
"legacy-v1"
|
|
273
|
-
if (root / "
|
|
296
|
+
if (delivery_directory(root) / "sections").is_dir()
|
|
274
297
|
else "compact-v2"
|
|
275
298
|
)
|
|
276
299
|
existing["questions"] = count
|
|
@@ -293,7 +316,7 @@ def extend_evidence_map(
|
|
|
293
316
|
path = control_path(
|
|
294
317
|
root,
|
|
295
318
|
"evidence-map.yaml",
|
|
296
|
-
root / "
|
|
319
|
+
delivery_directory(root) / "evidence-map.yaml",
|
|
297
320
|
)
|
|
298
321
|
content = (
|
|
299
322
|
path.read_text(encoding="utf-8")
|
|
@@ -310,7 +333,7 @@ def extend_evidence_map(
|
|
|
310
333
|
f" - id: q{i}-main-result",
|
|
311
334
|
f" generated_by: code/q{i}/main.py",
|
|
312
335
|
f" source: results/q{i}/TODO-替换为实际中文结果文件",
|
|
313
|
-
" paper_section:
|
|
336
|
+
" paper_section: happy/main.tex",
|
|
314
337
|
" upstream: TODO",
|
|
315
338
|
" validation: TODO",
|
|
316
339
|
" status: TODO",
|
|
@@ -341,23 +364,29 @@ def write_if_missing(
|
|
|
341
364
|
created.append(relative)
|
|
342
365
|
|
|
343
366
|
|
|
344
|
-
def question_main(
|
|
345
|
-
return
|
|
367
|
+
def question_main() -> str:
|
|
368
|
+
return '''from __future__ import annotations
|
|
346
369
|
|
|
347
|
-
|
|
370
|
+
import os
|
|
371
|
+
import sys
|
|
348
372
|
|
|
373
|
+
os.environ["PYTHONDONTWRITEBYTECODE"] = "1"
|
|
374
|
+
sys.dont_write_bytecode = True
|
|
349
375
|
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
376
|
+
if __package__:
|
|
377
|
+
from .data_preparation import prepare_inputs
|
|
378
|
+
from .evaluation import evaluate_and_report
|
|
379
|
+
from .solver import solve
|
|
380
|
+
else:
|
|
381
|
+
from data_preparation import prepare_inputs
|
|
382
|
+
from evaluation import evaluate_and_report
|
|
383
|
+
from solver import solve
|
|
353
384
|
|
|
354
385
|
|
|
355
386
|
def main() -> None:
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
# 将实际模型拆到按职责命名的同级模块,并使用中文结果/图件文件名。
|
|
360
|
-
raise NotImplementedError("请先实现问题{name}的真实模型与验证流程")
|
|
387
|
+
inputs = prepare_inputs()
|
|
388
|
+
solution = solve(inputs)
|
|
389
|
+
evaluate_and_report(inputs, solution)
|
|
361
390
|
|
|
362
391
|
|
|
363
392
|
if __name__ == "__main__":
|
|
@@ -365,6 +394,33 @@ if __name__ == "__main__":
|
|
|
365
394
|
'''
|
|
366
395
|
|
|
367
396
|
|
|
397
|
+
def question_modules(name: str) -> dict[str, str]:
|
|
398
|
+
"""提供可运行职责骨架;读题后必须改成领域化模块与真实实现。"""
|
|
399
|
+
return {
|
|
400
|
+
"data_preparation.py": f'''from __future__ import annotations
|
|
401
|
+
|
|
402
|
+
|
|
403
|
+
def prepare_inputs():
|
|
404
|
+
# TODO[{name}] 读取题目附件、校验字段、单位和缺失值;完成后删除本标记。
|
|
405
|
+
raise NotImplementedError("请实现问题{name}的数据准备")
|
|
406
|
+
''',
|
|
407
|
+
"solver.py": f'''from __future__ import annotations
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
def solve(inputs):
|
|
411
|
+
# TODO[{name}] 按本题实际方法实现模型、算法和边界条件;完成后删除本标记。
|
|
412
|
+
raise NotImplementedError("请实现问题{name}的求解器")
|
|
413
|
+
''',
|
|
414
|
+
"evaluation.py": f'''from __future__ import annotations
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
def evaluate_and_report(inputs, solution) -> None:
|
|
418
|
+
# TODO[{name}] 完成验证,并输出中文命名的CSV/XLSX及PDF+SVG矢量图。
|
|
419
|
+
raise NotImplementedError("请实现问题{name}的评价与报告")
|
|
420
|
+
''',
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
|
|
368
424
|
def question_tex(number: int) -> str:
|
|
369
425
|
return rf'''\section{{问题{number}:TODO[写明本题目标]}}
|
|
370
426
|
|
|
@@ -393,11 +449,13 @@ def run_all(count: int) -> str:
|
|
|
393
449
|
return f'''from __future__ import annotations
|
|
394
450
|
|
|
395
451
|
import importlib
|
|
452
|
+
import os
|
|
396
453
|
import sys
|
|
397
454
|
from pathlib import Path
|
|
398
455
|
|
|
399
456
|
CODE_ROOT = Path(__file__).resolve().parent
|
|
400
457
|
sys.path.insert(0, str(CODE_ROOT))
|
|
458
|
+
os.environ["PYTHONDONTWRITEBYTECODE"] = "1"
|
|
401
459
|
sys.dont_write_bytecode = True
|
|
402
460
|
|
|
403
461
|
|
|
@@ -11,6 +11,7 @@ from pathlib import Path
|
|
|
11
11
|
from project_utils import (
|
|
12
12
|
build_directory,
|
|
13
13
|
control_path,
|
|
14
|
+
delivery_directory,
|
|
14
15
|
generated_directory,
|
|
15
16
|
iter_regular_files,
|
|
16
17
|
load_profile,
|
|
@@ -27,7 +28,7 @@ EXCLUDED_PARTS = {
|
|
|
27
28
|
"build",
|
|
28
29
|
}
|
|
29
30
|
CODE_SUFFIXES = {".py", ".r", ".jl", ".m", ".cpp", ".c", ".h"}
|
|
30
|
-
SOURCE_APPENDIX_EXCLUDED = {"code/finalize.py"}
|
|
31
|
+
SOURCE_APPENDIX_EXCLUDED = {"code/finalize.py", ".cumcm/finalize.py"}
|
|
31
32
|
LISTING_LANGUAGES = {
|
|
32
33
|
".py": "Python",
|
|
33
34
|
".r": "R",
|
|
@@ -89,18 +90,15 @@ def generate_appendices(root: Path, profile: dict[str, object]) -> None:
|
|
|
89
90
|
support = []
|
|
90
91
|
for directory in ("code", "results", "figures"):
|
|
91
92
|
support.extend(path.relative_to(root).as_posix() for path in iter_regular_files(root, directory, EXCLUDED_PARTS))
|
|
92
|
-
ai_pdf = root / "
|
|
93
|
+
ai_pdf = delivery_directory(root) / "AI工具使用详情.pdf"
|
|
93
94
|
if ai_pdf.is_file():
|
|
94
95
|
support.append("AI工具使用详情.pdf")
|
|
95
96
|
support_profile = profile["support"]
|
|
96
97
|
assert isinstance(support_profile, dict)
|
|
97
|
-
environment = control_path(root, "environment.json")
|
|
98
|
-
if environment.is_file():
|
|
99
|
-
support.append("复现环境.json")
|
|
100
98
|
ai_log = control_path(
|
|
101
99
|
root,
|
|
102
100
|
"ai-use-log.md",
|
|
103
|
-
root / "
|
|
101
|
+
delivery_directory(root) / "ai-use-log.md",
|
|
104
102
|
)
|
|
105
103
|
if bool(support_profile.get("include_ai_log")) and ai_log.is_file():
|
|
106
104
|
support.append("AI工具使用记录.md")
|
|
@@ -281,7 +279,7 @@ def main() -> None:
|
|
|
281
279
|
parser.add_argument("--strict-layout", action="store_true", help="fail on both overfull and underfull boxes")
|
|
282
280
|
args = parser.parse_args()
|
|
283
281
|
root = args.project_root.resolve()
|
|
284
|
-
paper = root
|
|
282
|
+
paper = delivery_directory(root)
|
|
285
283
|
if not (paper / "main.tex").is_file():
|
|
286
284
|
raise SystemExit(f"Missing paper entry point: {paper / 'main.tex'}")
|
|
287
285
|
try:
|
|
@@ -297,7 +295,7 @@ def main() -> None:
|
|
|
297
295
|
if bool(ai_profile.get("used")) and bool(ai_profile.get("details_pdf_required")):
|
|
298
296
|
ai_source = paper / "AI工具使用详情.tex"
|
|
299
297
|
if not ai_source.is_file():
|
|
300
|
-
raise SystemExit("Active profile requires
|
|
298
|
+
raise SystemExit("Active profile requires happy/AI工具使用详情.tex")
|
|
301
299
|
_, ai_pdf = build_tex(paper, ai_source.name, "AI工具使用详情.pdf", args.strict_layout)
|
|
302
300
|
ai_size = check_size(ai_pdf, pdf_limit, "AI disclosure")
|
|
303
301
|
ai_message = f"\n AI disclosure: {ai_pdf} ({ai_size:.2f} MB)"
|
|
@@ -2,7 +2,6 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
import argparse
|
|
4
4
|
import importlib.metadata
|
|
5
|
-
import json
|
|
6
5
|
import platform
|
|
7
6
|
import sys
|
|
8
7
|
from pathlib import Path
|
|
@@ -11,37 +10,48 @@ from project_utils import control_directory
|
|
|
11
10
|
|
|
12
11
|
|
|
13
12
|
def main() -> None:
|
|
14
|
-
parser = argparse.ArgumentParser(
|
|
13
|
+
parser = argparse.ArgumentParser(
|
|
14
|
+
description="Report the selected Python interpreter; optionally keep a private text record."
|
|
15
|
+
)
|
|
15
16
|
parser.add_argument("project_root", type=Path)
|
|
17
|
+
parser.add_argument(
|
|
18
|
+
"--write",
|
|
19
|
+
action="store_true",
|
|
20
|
+
help="write .cumcm/environment.txt; never create results/environment.json",
|
|
21
|
+
)
|
|
16
22
|
args = parser.parse_args()
|
|
17
23
|
root = args.project_root.resolve()
|
|
18
24
|
requirements = root / "code" / "requirements.txt"
|
|
19
|
-
requested
|
|
25
|
+
requested = []
|
|
20
26
|
if requirements.is_file():
|
|
21
|
-
|
|
22
|
-
line
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
27
|
+
requested = [
|
|
28
|
+
line.strip()
|
|
29
|
+
for line in requirements.read_text(encoding="utf-8").splitlines()
|
|
30
|
+
if line.strip() and not line.lstrip().startswith("#")
|
|
31
|
+
]
|
|
32
|
+
rows = [
|
|
33
|
+
f"Python版本: {sys.version.split()[0]}",
|
|
34
|
+
f"解释器路径: {sys.executable}",
|
|
35
|
+
f"操作系统: {platform.platform()}",
|
|
36
|
+
]
|
|
37
|
+
if requested:
|
|
38
|
+
rows.append("依赖版本:")
|
|
26
39
|
for requirement in requested:
|
|
27
40
|
name = requirement.split(";", 1)[0].strip()
|
|
28
41
|
for marker in ("==", ">=", "<=", "~=", "!=", ">", "<", "["):
|
|
29
42
|
name = name.split(marker, 1)[0].strip()
|
|
30
43
|
try:
|
|
31
|
-
|
|
44
|
+
version = importlib.metadata.version(name)
|
|
32
45
|
except importlib.metadata.PackageNotFoundError:
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
output.parent.mkdir(parents=True, exist_ok=True)
|
|
43
|
-
output.write_text(json.dumps(payload, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
|
|
44
|
-
print(f"[OK] Environment captured: {output}")
|
|
46
|
+
version = "未安装"
|
|
47
|
+
rows.append(f"- {name}: {version}")
|
|
48
|
+
content = "\n".join(rows) + "\n"
|
|
49
|
+
print(content, end="")
|
|
50
|
+
if args.write:
|
|
51
|
+
output = control_directory(root) / "environment.txt"
|
|
52
|
+
output.parent.mkdir(parents=True, exist_ok=True)
|
|
53
|
+
output.write_text(content, encoding="utf-8")
|
|
54
|
+
print(f"[OK] Environment note captured privately: {output}")
|
|
45
55
|
|
|
46
56
|
|
|
47
57
|
if __name__ == "__main__":
|
|
@@ -15,34 +15,121 @@ CACHE_DIR_NAMES = {
|
|
|
15
15
|
".ipynb_checkpoints",
|
|
16
16
|
}
|
|
17
17
|
TEX_CACHE_SUFFIXES = {".aux", ".bbl", ".bcf", ".blg", ".fdb_latexmk", ".fls", ".log", ".out", ".run.xml", ".synctex.gz", ".toc", ".xdv"}
|
|
18
|
+
LEGACY_FILES = {
|
|
19
|
+
"happy/ai-use-log.md",
|
|
20
|
+
"happy/contest-profile.json",
|
|
21
|
+
"happy/evidence-freeze.json",
|
|
22
|
+
"happy/evidence-map.yaml",
|
|
23
|
+
"happy/input-inventory.json",
|
|
24
|
+
"happy/question-count.json",
|
|
25
|
+
"happy/question-fingerprint.json",
|
|
26
|
+
"happy/support-materials.zip",
|
|
27
|
+
"results/environment.json",
|
|
28
|
+
}
|
|
29
|
+
LEGACY_RESULT_NAMES = {
|
|
30
|
+
"constraint_checks.json",
|
|
31
|
+
"data_audit.json",
|
|
32
|
+
"metrics.csv",
|
|
33
|
+
"oht_log.csv",
|
|
34
|
+
"summary.json",
|
|
35
|
+
"task_results.csv",
|
|
36
|
+
}
|
|
37
|
+
LEGACY_FIGURE_NAMES = {
|
|
38
|
+
"cross_question_comparison.pdf",
|
|
39
|
+
"cross_question_comparison.png",
|
|
40
|
+
"transfer_time_distribution.pdf",
|
|
41
|
+
"transfer_time_distribution.png",
|
|
42
|
+
}
|
|
43
|
+
REFERENCE_SUFFIXES = {".json", ".md", ".tex", ".yaml", ".yml"}
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def is_referenced_artifact(root: Path, path: Path) -> bool:
|
|
47
|
+
"""保留仍被交付文档、证据或配置引用的历史产物。"""
|
|
48
|
+
relative = path.relative_to(root).as_posix()
|
|
49
|
+
name = path.name
|
|
50
|
+
for base in (root / "happy", root / ".cumcm"):
|
|
51
|
+
if not base.is_dir() or base.is_symlink():
|
|
52
|
+
continue
|
|
53
|
+
for document in base.rglob("*"):
|
|
54
|
+
if (
|
|
55
|
+
not document.is_file()
|
|
56
|
+
or document.is_symlink()
|
|
57
|
+
or document.suffix.lower() not in REFERENCE_SUFFIXES
|
|
58
|
+
):
|
|
59
|
+
continue
|
|
60
|
+
try:
|
|
61
|
+
text = document.read_text(encoding="utf-8", errors="replace")
|
|
62
|
+
except OSError:
|
|
63
|
+
continue
|
|
64
|
+
if relative in text or name in text:
|
|
65
|
+
return True
|
|
66
|
+
return False
|
|
18
67
|
|
|
19
68
|
|
|
20
69
|
def targets(root: Path) -> list[Path]:
|
|
21
70
|
found: set[Path] = set()
|
|
71
|
+
for relative in LEGACY_FILES:
|
|
72
|
+
path = root / relative
|
|
73
|
+
if path.is_file() and not path.is_symlink():
|
|
74
|
+
found.add(path)
|
|
75
|
+
for base, names in (
|
|
76
|
+
(root / "results", LEGACY_RESULT_NAMES),
|
|
77
|
+
(root / "figures", LEGACY_FIGURE_NAMES),
|
|
78
|
+
):
|
|
79
|
+
if base.is_dir() and not base.is_symlink():
|
|
80
|
+
for path in base.rglob("*"):
|
|
81
|
+
if (
|
|
82
|
+
path.is_file()
|
|
83
|
+
and not path.is_symlink()
|
|
84
|
+
and path.name in names
|
|
85
|
+
and not is_referenced_artifact(root, path)
|
|
86
|
+
):
|
|
87
|
+
found.add(path)
|
|
22
88
|
for path in root.rglob("*"):
|
|
23
89
|
if path.is_symlink():
|
|
24
90
|
continue
|
|
25
91
|
if path.is_dir() and path.name in CACHE_DIR_NAMES:
|
|
26
92
|
found.add(path)
|
|
93
|
+
elif path.is_file() and path.suffix.lower() in {".pyc", ".pyo"}:
|
|
94
|
+
found.add(path)
|
|
27
95
|
elif path.is_file() and any(path.name.endswith(suffix) for suffix in TEX_CACHE_SUFFIXES):
|
|
28
96
|
if any(
|
|
29
|
-
part in {"
|
|
97
|
+
part in {"happy", ".cumcm"}
|
|
30
98
|
for part in path.relative_to(root).parts
|
|
31
99
|
):
|
|
32
100
|
found.add(path)
|
|
33
101
|
page_review = build_directory(root) / "page-review"
|
|
34
102
|
if page_review.is_dir() and not page_review.is_symlink():
|
|
35
103
|
found.add(page_review)
|
|
104
|
+
happy_build = root / "happy" / "build"
|
|
105
|
+
if happy_build.is_dir() and not happy_build.is_symlink():
|
|
106
|
+
found.add(happy_build)
|
|
36
107
|
return sorted(found, key=lambda path: (len(path.parts), str(path)), reverse=True)
|
|
37
108
|
|
|
38
109
|
|
|
39
110
|
def main() -> None:
|
|
40
|
-
parser = argparse.ArgumentParser(
|
|
111
|
+
parser = argparse.ArgumentParser(
|
|
112
|
+
description="Remove deterministic caches and unreferenced legacy delivery artifacts."
|
|
113
|
+
)
|
|
41
114
|
parser.add_argument("project_root", type=Path)
|
|
42
115
|
parser.add_argument("--apply", action="store_true", help="perform deletion; default is dry run")
|
|
43
116
|
args = parser.parse_args()
|
|
44
117
|
root = args.project_root.resolve()
|
|
45
118
|
selected = targets(root)
|
|
119
|
+
selected_set = set(selected)
|
|
120
|
+
protected_legacy = [
|
|
121
|
+
path
|
|
122
|
+
for base, names in (
|
|
123
|
+
(root / "results", LEGACY_RESULT_NAMES),
|
|
124
|
+
(root / "figures", LEGACY_FIGURE_NAMES),
|
|
125
|
+
)
|
|
126
|
+
if base.is_dir() and not base.is_symlink()
|
|
127
|
+
for path in base.rglob("*")
|
|
128
|
+
if path.is_file()
|
|
129
|
+
and not path.is_symlink()
|
|
130
|
+
and path.name in names
|
|
131
|
+
and path not in selected_set
|
|
132
|
+
]
|
|
46
133
|
for path in selected:
|
|
47
134
|
print(f"[{'REMOVE' if args.apply else 'DRY-RUN'}] {path.relative_to(root)}")
|
|
48
135
|
if args.apply:
|
|
@@ -50,6 +137,8 @@ def main() -> None:
|
|
|
50
137
|
shutil.rmtree(path)
|
|
51
138
|
elif path.exists():
|
|
52
139
|
path.unlink()
|
|
140
|
+
for path in protected_legacy:
|
|
141
|
+
print(f"[KEEP] referenced legacy artifact: {path.relative_to(root)}")
|
|
53
142
|
print(f"[OK] {'Removed' if args.apply else 'Identified'} {len(selected)} cache/render target(s); final PDFs and source artifacts preserved")
|
|
54
143
|
|
|
55
144
|
|
|
@@ -7,7 +7,7 @@ from datetime import datetime, timezone
|
|
|
7
7
|
from pathlib import Path
|
|
8
8
|
from typing import Any
|
|
9
9
|
|
|
10
|
-
from project_utils import control_path, iter_regular_files
|
|
10
|
+
from project_utils import control_path, delivery_directory, iter_regular_files
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
EXCLUDED_PARTS = {"__pycache__", ".pytest_cache", ".mypy_cache", ".ruff_cache", "build"}
|
|
@@ -40,7 +40,7 @@ def freeze_path(root: Path) -> Path:
|
|
|
40
40
|
return control_path(
|
|
41
41
|
root,
|
|
42
42
|
"evidence-freeze.json",
|
|
43
|
-
root / "
|
|
43
|
+
delivery_directory(root) / "evidence-freeze.json",
|
|
44
44
|
)
|
|
45
45
|
|
|
46
46
|
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
+
# ruff: noqa: E402
|
|
4
|
+
|
|
3
5
|
import argparse
|
|
6
|
+
import os
|
|
4
7
|
import subprocess
|
|
5
8
|
import sys
|
|
6
9
|
from pathlib import Path
|
|
7
10
|
|
|
11
|
+
sys.dont_write_bytecode = True
|
|
12
|
+
|
|
8
13
|
from evidence_freeze import require_refresh_authorization, write_freeze
|
|
9
14
|
from project_utils import question_numbers
|
|
10
15
|
from validate_project import code_architecture_errors
|
|
@@ -14,8 +19,10 @@ SCRIPT_ROOT = Path(__file__).resolve().parent
|
|
|
14
19
|
|
|
15
20
|
|
|
16
21
|
def run(script: str, root: Path, *flags: str) -> None:
|
|
17
|
-
command = [sys.executable, str(SCRIPT_ROOT / script), str(root), *flags]
|
|
18
|
-
|
|
22
|
+
command = [sys.executable, "-B", str(SCRIPT_ROOT / script), str(root), *flags]
|
|
23
|
+
environment = os.environ.copy()
|
|
24
|
+
environment["PYTHONDONTWRITEBYTECODE"] = "1"
|
|
25
|
+
completed = subprocess.run(command, check=False, env=environment)
|
|
19
26
|
if completed.returncode:
|
|
20
27
|
raise SystemExit(f"Finalization stopped because {script} failed with exit code {completed.returncode}.")
|
|
21
28
|
|
|
@@ -27,7 +34,19 @@ def main() -> None:
|
|
|
27
34
|
parser.add_argument("--refresh-evidence", action="store_true", help="explicitly authorize replacing an existing numerical-evidence freeze; requires --run-code")
|
|
28
35
|
parser.add_argument("--strict-layout", action="store_true", help="fail on TeX underfull boxes as well as overfull boxes")
|
|
29
36
|
parser.add_argument("--render-pages", action="store_true", help="render every final PDF page for visual review")
|
|
30
|
-
parser.
|
|
37
|
+
parser.set_defaults(clean=True)
|
|
38
|
+
parser.add_argument(
|
|
39
|
+
"--clean",
|
|
40
|
+
dest="clean",
|
|
41
|
+
action="store_true",
|
|
42
|
+
help="remove deterministic caches before freezing and packaging (default)",
|
|
43
|
+
)
|
|
44
|
+
parser.add_argument(
|
|
45
|
+
"--no-clean",
|
|
46
|
+
dest="clean",
|
|
47
|
+
action="store_false",
|
|
48
|
+
help="keep deterministic caches for local debugging",
|
|
49
|
+
)
|
|
31
50
|
args = parser.parse_args()
|
|
32
51
|
root = args.project_root.resolve()
|
|
33
52
|
if args.refresh_evidence and not args.run_code:
|
|
@@ -37,9 +56,16 @@ def main() -> None:
|
|
|
37
56
|
entry = root / "code" / "run_all.py"
|
|
38
57
|
if not entry.is_file():
|
|
39
58
|
raise SystemExit(f"Missing code entry point: {entry}")
|
|
40
|
-
|
|
59
|
+
environment = os.environ.copy()
|
|
60
|
+
environment["PYTHONDONTWRITEBYTECODE"] = "1"
|
|
61
|
+
completed = subprocess.run(
|
|
62
|
+
[sys.executable, "-B", str(entry)],
|
|
63
|
+
cwd=root / "code",
|
|
64
|
+
check=False,
|
|
65
|
+
env=environment,
|
|
66
|
+
)
|
|
41
67
|
if completed.returncode:
|
|
42
|
-
raise SystemExit("code/run_all.py failed;
|
|
68
|
+
raise SystemExit("code/run_all.py failed; happy output was not rebuilt from stale evidence.")
|
|
43
69
|
discovered_questions = question_numbers(root)
|
|
44
70
|
architecture_errors = code_architecture_errors(
|
|
45
71
|
root, max(discovered_questions, default=0)
|
|
@@ -50,19 +76,19 @@ def main() -> None:
|
|
|
50
76
|
raise SystemExit(
|
|
51
77
|
"Finalization stopped before compilation because modeling code is incomplete."
|
|
52
78
|
)
|
|
53
|
-
run("capture_environment.py", root)
|
|
79
|
+
run("capture_environment.py", root, "--write")
|
|
54
80
|
run("build_paper.py", root, *(["--strict-layout"] if args.strict_layout else []))
|
|
55
81
|
audit_flags = ["--fail-on-errors"]
|
|
56
82
|
if args.render_pages:
|
|
57
83
|
audit_flags.append("--render-pages")
|
|
58
84
|
run("audit_paper.py", root, *audit_flags)
|
|
85
|
+
if args.clean:
|
|
86
|
+
run("clean_project.py", root, "--apply")
|
|
59
87
|
freeze = write_freeze(root)
|
|
60
88
|
print(f"[OK] Numerical evidence phase frozen: {freeze}")
|
|
61
89
|
run("package_support.py", root)
|
|
62
90
|
run("validate_project.py", root, "--strict")
|
|
63
|
-
|
|
64
|
-
run("clean_project.py", root, "--apply")
|
|
65
|
-
print(f"[OK] Complete modeling-paper delivery finalized: {root / 'paper' / 'main.pdf'}")
|
|
91
|
+
print(f"[OK] Complete modeling-paper delivery finalized: {root / 'happy' / 'main.pdf'}")
|
|
66
92
|
print(
|
|
67
93
|
"[ORBIT_TERMINAL_SUCCESS] Final PDF and support archive are current. "
|
|
68
94
|
"Stop tool use and return the final delivery report."
|
|
@@ -30,6 +30,14 @@ def result(status: str, **details: Any) -> dict[str, Any]:
|
|
|
30
30
|
return {"status": status, **details}
|
|
31
31
|
|
|
32
32
|
|
|
33
|
+
def json_default(value: Any) -> str:
|
|
34
|
+
"""把 Excel 日期等预览值稳定转换为可审计文本。"""
|
|
35
|
+
isoformat = getattr(value, "isoformat", None)
|
|
36
|
+
if callable(isoformat):
|
|
37
|
+
return str(isoformat())
|
|
38
|
+
return str(value)
|
|
39
|
+
|
|
40
|
+
|
|
33
41
|
def inspect_delimited(path: Path) -> dict[str, Any]:
|
|
34
42
|
delimiter = "\t" if path.suffix.lower() == ".tsv" else ","
|
|
35
43
|
for encoding in ("utf-8-sig", "gb18030"):
|
|
@@ -222,7 +230,7 @@ def main() -> None:
|
|
|
222
230
|
state = control_directory(root)
|
|
223
231
|
state.mkdir(parents=True, exist_ok=True)
|
|
224
232
|
inventory = state / "input-inventory.json"
|
|
225
|
-
inventory.write_text(json.dumps({"schema_version": 1, "files": entries}, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
|
|
233
|
+
inventory.write_text(json.dumps({"schema_version": 1, "files": entries}, ensure_ascii=False, indent=2, default=json_default) + "\n", encoding="utf-8")
|
|
226
234
|
baseline = state / "question-fingerprint.json"
|
|
227
235
|
baseline_state = "preserved"
|
|
228
236
|
if args.refresh_baseline or not baseline.exists():
|