@orbit-build/cli 0.8.3 → 0.8.6
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 +4 -1
- package/commands/cumcm-draft.md +3 -1
- package/dist/index.js +1158 -310
- package/package.json +1 -1
- package/skills/cumcm-draft/SKILL.md +102 -48
- package/skills/cumcm-draft/agents/openai.yaml +1 -1
- package/skills/cumcm-draft/assets/project-template/{code → .cumcm}/finalize.py +33 -4
- package/skills/cumcm-draft/assets/project-template/{paper/contest-profile.json → .cumcm/profile.json} +9 -6
- package/skills/cumcm-draft/assets/project-template/code/requirements.txt +1 -11
- package/skills/cumcm-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 +1 -11
- package/skills/cumcm-draft/assets/project-template/paper/main.tex +70 -11
- package/skills/cumcm-draft/references/code-and-output-style.md +9 -14
- package/skills/cumcm-draft/references/cumcm-compliance.md +28 -25
- package/skills/cumcm-draft/references/latex-figures-tables.md +1 -1
- package/skills/cumcm-draft/references/modeling-quality.md +1 -1
- package/skills/cumcm-draft/references/paper-architecture.md +3 -3
- package/skills/cumcm-draft/references/project-architecture.md +70 -89
- package/skills/cumcm-draft/scripts/audit_paper.py +37 -9
- package/skills/cumcm-draft/scripts/bootstrap_project.py +198 -56
- package/skills/cumcm-draft/scripts/build_paper.py +38 -23
- package/skills/cumcm-draft/scripts/capture_environment.py +3 -1
- package/skills/cumcm-draft/scripts/clean_project.py +7 -2
- package/skills/cumcm-draft/scripts/evidence_freeze.py +8 -4
- package/skills/cumcm-draft/scripts/finalize_project.py +16 -0
- package/skills/cumcm-draft/scripts/inspect_inputs.py +6 -4
- package/skills/cumcm-draft/scripts/package_support.py +41 -15
- package/skills/cumcm-draft/scripts/project_utils.py +40 -8
- package/skills/cumcm-draft/scripts/validate_project.py +394 -57
- package/skills/cumcm-draft/assets/project-template/code/always/__init__.py +0 -1
- package/skills/cumcm-draft/assets/project-template/code/always/config.py +0 -18
- package/skills/cumcm-draft/assets/project-template/code/always/data.py +0 -24
- package/skills/cumcm-draft/assets/project-template/code/always/plotting.py +0 -25
- package/skills/cumcm-draft/assets/project-template/code/always/validation.py +0 -21
- package/skills/cumcm-draft/assets/project-template/paper/sections/abstract.tex +0 -6
- package/skills/cumcm-draft/assets/project-template/paper/sections/ai-disclosure.tex +0 -3
- package/skills/cumcm-draft/assets/project-template/paper/sections/appendix.tex +0 -3
- package/skills/cumcm-draft/assets/project-template/paper/sections/assumptions.tex +0 -5
- package/skills/cumcm-draft/assets/project-template/paper/sections/data.tex +0 -19
- package/skills/cumcm-draft/assets/project-template/paper/sections/evaluation.tex +0 -9
- package/skills/cumcm-draft/assets/project-template/paper/sections/problem-analysis.tex +0 -3
- package/skills/cumcm-draft/assets/project-template/paper/sections/problem-restatement.tex +0 -3
- package/skills/cumcm-draft/assets/project-template/paper/sections/references.tex +0 -12
- package/skills/cumcm-draft/assets/project-template/paper/sections/source-code.tex +0 -1
- package/skills/cumcm-draft/assets/project-template/paper/sections/support-files.tex +0 -3
- /package/skills/cumcm-draft/assets/project-template/{paper → .cumcm}/ai-use-log.md +0 -0
|
@@ -6,16 +6,27 @@ import re
|
|
|
6
6
|
import shutil
|
|
7
7
|
from pathlib import Path
|
|
8
8
|
|
|
9
|
-
from project_utils import question_numbers
|
|
9
|
+
from project_utils import control_directory, control_path, question_numbers
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
SKILL_ROOT = Path(__file__).resolve().parents[1]
|
|
13
13
|
TEMPLATE_ROOT = SKILL_ROOT / "assets" / "project-template"
|
|
14
|
+
QUESTION_BEGIN = "% ORBIT:QUESTIONS:BEGIN"
|
|
15
|
+
QUESTION_END = "% ORBIT:QUESTIONS:END"
|
|
16
|
+
LEGACY_CONTROL_FILES = {
|
|
17
|
+
"contest-profile.json": "profile.json",
|
|
18
|
+
"question-count.json": "project.json",
|
|
19
|
+
"evidence-map.yaml": "evidence-map.yaml",
|
|
20
|
+
"input-inventory.json": "input-inventory.json",
|
|
21
|
+
"question-fingerprint.json": "question-fingerprint.json",
|
|
22
|
+
"ai-use-log.md": "ai-use-log.md",
|
|
23
|
+
"evidence-freeze.json": "evidence-freeze.json",
|
|
24
|
+
}
|
|
14
25
|
|
|
15
26
|
|
|
16
27
|
def main() -> None:
|
|
17
28
|
parser = argparse.ArgumentParser(
|
|
18
|
-
description="Create or extend a non-destructive modeling project
|
|
29
|
+
description="Create or extend a compact, non-destructive modeling project."
|
|
19
30
|
)
|
|
20
31
|
parser.add_argument("project_root", type=Path)
|
|
21
32
|
parser.add_argument("--questions", type=int, required=True)
|
|
@@ -27,32 +38,74 @@ def main() -> None:
|
|
|
27
38
|
created: list[str] = []
|
|
28
39
|
updated: list[str] = []
|
|
29
40
|
preserved: list[str] = []
|
|
41
|
+
removed: list[str] = []
|
|
30
42
|
for directory in (
|
|
31
43
|
root / "question",
|
|
32
|
-
root / "code"
|
|
33
|
-
root / "paper"
|
|
34
|
-
root
|
|
44
|
+
root / "code",
|
|
45
|
+
root / "paper",
|
|
46
|
+
control_directory(root),
|
|
47
|
+
control_directory(root) / "build",
|
|
48
|
+
control_directory(root) / "generated",
|
|
35
49
|
):
|
|
36
50
|
directory.mkdir(parents=True, exist_ok=True)
|
|
37
51
|
|
|
52
|
+
migrate_legacy_control_files(root, created, preserved)
|
|
53
|
+
copy_template_tree(root, created, preserved)
|
|
54
|
+
remove_empty_legacy_layout_directories(root, removed)
|
|
38
55
|
declared = read_declared_count(root)
|
|
39
56
|
discovered = max(question_numbers(root), default=0)
|
|
40
57
|
question_count = max(args.questions, declared, discovered)
|
|
41
|
-
copy_template_tree(root, created, preserved)
|
|
42
58
|
create_question_files(root, question_count, created, updated, preserved)
|
|
43
59
|
extend_evidence_map(root, question_count, created, updated)
|
|
44
60
|
|
|
45
|
-
print(f"[OK]
|
|
61
|
+
print(f"[OK] Compact project skeleton ready: {root}")
|
|
46
62
|
print(
|
|
47
63
|
f" Questions: {question_count}; created {len(created)}, "
|
|
48
64
|
f"updated {len(updated)}, preserved {len(preserved)} file(s)."
|
|
49
65
|
)
|
|
66
|
+
print(
|
|
67
|
+
" paper/ contains only editable paper sources and final deliverables; "
|
|
68
|
+
".cumcm/ owns workflow state and build caches."
|
|
69
|
+
)
|
|
50
70
|
if updated:
|
|
51
71
|
print(" Updated orchestrators: " + ", ".join(updated))
|
|
72
|
+
if removed:
|
|
73
|
+
print(" Removed empty legacy layout shells: " + ", ".join(removed))
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def remove_empty_legacy_layout_directories(root: Path, removed: list[str]) -> None:
|
|
77
|
+
"""Drop empty legacy shells without touching authored files or build output."""
|
|
78
|
+
for directory in (root / "paper" / "sections", root / "paper" / "build"):
|
|
79
|
+
if not directory.is_dir() or directory.is_symlink():
|
|
80
|
+
continue
|
|
81
|
+
try:
|
|
82
|
+
next(directory.iterdir())
|
|
83
|
+
except StopIteration:
|
|
84
|
+
directory.rmdir()
|
|
85
|
+
removed.append(directory.relative_to(root).as_posix() + "/")
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def migrate_legacy_control_files(
|
|
89
|
+
root: Path, created: list[str], preserved: list[str]
|
|
90
|
+
) -> None:
|
|
91
|
+
"""Copy legacy 0.8.3 state into .cumcm without deleting user files."""
|
|
92
|
+
destination_root = control_directory(root)
|
|
93
|
+
for legacy_name, current_name in LEGACY_CONTROL_FILES.items():
|
|
94
|
+
source = root / "paper" / legacy_name
|
|
95
|
+
target = destination_root / current_name
|
|
96
|
+
if target.exists():
|
|
97
|
+
preserved.append(target.relative_to(root).as_posix())
|
|
98
|
+
elif source.is_file() and not source.is_symlink():
|
|
99
|
+
shutil.copy2(source, target)
|
|
100
|
+
created.append(target.relative_to(root).as_posix())
|
|
52
101
|
|
|
53
102
|
|
|
54
103
|
def read_declared_count(root: Path) -> int:
|
|
55
|
-
path =
|
|
104
|
+
path = control_path(
|
|
105
|
+
root,
|
|
106
|
+
"project.json",
|
|
107
|
+
root / "paper" / "question-count.json",
|
|
108
|
+
)
|
|
56
109
|
if not path.is_file():
|
|
57
110
|
return 0
|
|
58
111
|
try:
|
|
@@ -62,7 +115,9 @@ def read_declared_count(root: Path) -> int:
|
|
|
62
115
|
return count if 1 <= count <= 20 else 0
|
|
63
116
|
|
|
64
117
|
|
|
65
|
-
def copy_template_tree(
|
|
118
|
+
def copy_template_tree(
|
|
119
|
+
root: Path, created: list[str], preserved: list[str]
|
|
120
|
+
) -> None:
|
|
66
121
|
for source in TEMPLATE_ROOT.rglob("*"):
|
|
67
122
|
if not source.is_file():
|
|
68
123
|
continue
|
|
@@ -85,47 +140,113 @@ def create_question_files(
|
|
|
85
140
|
) -> None:
|
|
86
141
|
for number in range(1, count + 1):
|
|
87
142
|
name = f"q{number}"
|
|
88
|
-
for directory in (
|
|
143
|
+
for directory in (
|
|
144
|
+
root / "code" / name,
|
|
145
|
+
root / "results" / name,
|
|
146
|
+
root / "figures" / name,
|
|
147
|
+
):
|
|
89
148
|
directory.mkdir(parents=True, exist_ok=True)
|
|
90
|
-
|
|
91
|
-
root
|
|
92
|
-
root / "code" / name / "main.py"
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
149
|
+
write_if_missing(
|
|
150
|
+
root,
|
|
151
|
+
root / "code" / name / "main.py",
|
|
152
|
+
question_main(name),
|
|
153
|
+
created,
|
|
154
|
+
preserved,
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
legacy_sections = root / "paper" / "sections"
|
|
158
|
+
if legacy_sections.is_dir():
|
|
159
|
+
create_legacy_question_sections(
|
|
160
|
+
root, count, created, updated, preserved
|
|
161
|
+
)
|
|
162
|
+
else:
|
|
163
|
+
merge_questions_into_main(root, count, updated)
|
|
99
164
|
merge_run_all(root, count, created, updated)
|
|
100
|
-
|
|
165
|
+
write_project_manifest(root, count, created, updated)
|
|
101
166
|
|
|
102
167
|
|
|
103
|
-
def
|
|
168
|
+
def create_legacy_question_sections(
|
|
169
|
+
root: Path,
|
|
170
|
+
count: int,
|
|
171
|
+
created: list[str],
|
|
172
|
+
updated: list[str],
|
|
173
|
+
preserved: list[str],
|
|
174
|
+
) -> None:
|
|
175
|
+
for number in range(1, count + 1):
|
|
176
|
+
write_if_missing(
|
|
177
|
+
root,
|
|
178
|
+
root / "paper" / "sections" / f"q{number}.tex",
|
|
179
|
+
question_tex(number),
|
|
180
|
+
created,
|
|
181
|
+
preserved,
|
|
182
|
+
)
|
|
104
183
|
path = root / "paper" / "sections" / "questions.tex"
|
|
105
184
|
if not path.exists():
|
|
106
|
-
path.write_text(
|
|
185
|
+
path.write_text(
|
|
186
|
+
"".join(f"\\input{{sections/q{i}}}\n" for i in range(1, count + 1)),
|
|
187
|
+
encoding="utf-8",
|
|
188
|
+
)
|
|
107
189
|
created.append(path.relative_to(root).as_posix())
|
|
108
190
|
return
|
|
109
191
|
content = path.read_text(encoding="utf-8")
|
|
110
|
-
additions = [
|
|
192
|
+
additions = [
|
|
193
|
+
f"\\input{{sections/q{i}}}"
|
|
194
|
+
for i in range(1, count + 1)
|
|
195
|
+
if not re.search(rf"\\input\{{sections/q{i}\}}", content)
|
|
196
|
+
]
|
|
111
197
|
if additions:
|
|
112
|
-
path.write_text(
|
|
198
|
+
path.write_text(
|
|
199
|
+
content.rstrip() + "\n" + "\n".join(additions) + "\n",
|
|
200
|
+
encoding="utf-8",
|
|
201
|
+
)
|
|
113
202
|
updated.append(path.relative_to(root).as_posix())
|
|
114
203
|
|
|
115
204
|
|
|
116
|
-
def
|
|
205
|
+
def merge_questions_into_main(root: Path, count: int, updated: list[str]) -> None:
|
|
206
|
+
path = root / "paper" / "main.tex"
|
|
207
|
+
if not path.is_file():
|
|
208
|
+
raise SystemExit(f"Missing compact paper template: {path}")
|
|
209
|
+
content = path.read_text(encoding="utf-8")
|
|
210
|
+
if QUESTION_BEGIN not in content or QUESTION_END not in content:
|
|
211
|
+
print(
|
|
212
|
+
"[WARN] Preserved custom paper/main.tex without Orbit question markers; "
|
|
213
|
+
"add missing question sections manually."
|
|
214
|
+
)
|
|
215
|
+
return
|
|
216
|
+
additions = [
|
|
217
|
+
question_tex(number).rstrip()
|
|
218
|
+
for number in range(1, count + 1)
|
|
219
|
+
if not re.search(rf"\\section\{{问题{number}(?:[::]|\}})", content)
|
|
220
|
+
]
|
|
221
|
+
if not additions:
|
|
222
|
+
return
|
|
223
|
+
insertion = "\n\n".join(additions) + "\n"
|
|
224
|
+
content = content.replace(QUESTION_END, insertion + QUESTION_END, 1)
|
|
225
|
+
path.write_text(content, encoding="utf-8")
|
|
226
|
+
updated.append(path.relative_to(root).as_posix())
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
def merge_run_all(
|
|
230
|
+
root: Path, count: int, created: list[str], updated: list[str]
|
|
231
|
+
) -> None:
|
|
117
232
|
path = root / "code" / "run_all.py"
|
|
118
233
|
if not path.exists():
|
|
119
234
|
path.write_text(run_all(count), encoding="utf-8")
|
|
120
235
|
created.append(path.relative_to(root).as_posix())
|
|
121
236
|
return
|
|
122
237
|
content = path.read_text(encoding="utf-8")
|
|
123
|
-
missing = [
|
|
238
|
+
missing = [
|
|
239
|
+
f"q{i}.main"
|
|
240
|
+
for i in range(1, count + 1)
|
|
241
|
+
if f'"q{i}.main"' not in content and f"'q{i}.main'" not in content
|
|
242
|
+
]
|
|
124
243
|
if not missing:
|
|
125
244
|
return
|
|
126
245
|
match = re.search(r"(?ms)(^\s*modules\s*=\s*\[.*?)(^\s*\])", content)
|
|
127
246
|
if not match:
|
|
128
|
-
print(
|
|
247
|
+
print(
|
|
248
|
+
f"[WARN] Preserved custom run_all.py; add manually: {', '.join(missing)}"
|
|
249
|
+
)
|
|
129
250
|
return
|
|
130
251
|
indent = re.match(r"\s*", match.group(2)).group(0)
|
|
131
252
|
rows = "".join(f'{indent} "{module}",\n' for module in missing)
|
|
@@ -134,8 +255,10 @@ def merge_run_all(root: Path, count: int, created: list[str], updated: list[str]
|
|
|
134
255
|
updated.append(path.relative_to(root).as_posix())
|
|
135
256
|
|
|
136
257
|
|
|
137
|
-
def
|
|
138
|
-
|
|
258
|
+
def write_project_manifest(
|
|
259
|
+
root: Path, count: int, created: list[str], updated: list[str]
|
|
260
|
+
) -> None:
|
|
261
|
+
path = control_directory(root) / "project.json"
|
|
139
262
|
existing: dict[str, object] = {}
|
|
140
263
|
if path.is_file():
|
|
141
264
|
try:
|
|
@@ -144,8 +267,18 @@ def write_count(root: Path, count: int, created: list[str], updated: list[str])
|
|
|
144
267
|
existing = payload
|
|
145
268
|
except (OSError, json.JSONDecodeError):
|
|
146
269
|
pass
|
|
270
|
+
existing["schema_version"] = 1
|
|
271
|
+
existing["layout"] = (
|
|
272
|
+
"legacy-v1"
|
|
273
|
+
if (root / "paper" / "sections").is_dir()
|
|
274
|
+
else "compact-v2"
|
|
275
|
+
)
|
|
147
276
|
existing["questions"] = count
|
|
148
|
-
existing["support_paths"] = [
|
|
277
|
+
existing["support_paths"] = [
|
|
278
|
+
item
|
|
279
|
+
for i in range(1, count + 1)
|
|
280
|
+
for item in (f"code/q{i}", f"results/q{i}", f"figures/q{i}")
|
|
281
|
+
]
|
|
149
282
|
rendered = json.dumps(existing, ensure_ascii=False, indent=2) + "\n"
|
|
150
283
|
if path.exists() and path.read_text(encoding="utf-8") == rendered:
|
|
151
284
|
return
|
|
@@ -154,9 +287,19 @@ def write_count(root: Path, count: int, created: list[str], updated: list[str])
|
|
|
154
287
|
(updated if was_present else created).append(path.relative_to(root).as_posix())
|
|
155
288
|
|
|
156
289
|
|
|
157
|
-
def extend_evidence_map(
|
|
158
|
-
|
|
159
|
-
|
|
290
|
+
def extend_evidence_map(
|
|
291
|
+
root: Path, count: int, created: list[str], updated: list[str]
|
|
292
|
+
) -> None:
|
|
293
|
+
path = control_path(
|
|
294
|
+
root,
|
|
295
|
+
"evidence-map.yaml",
|
|
296
|
+
root / "paper" / "evidence-map.yaml",
|
|
297
|
+
)
|
|
298
|
+
content = (
|
|
299
|
+
path.read_text(encoding="utf-8")
|
|
300
|
+
if path.exists()
|
|
301
|
+
else "# Claims must resolve to program-generated evidence.\n"
|
|
302
|
+
)
|
|
160
303
|
additions: list[str] = []
|
|
161
304
|
for i in range(1, count + 1):
|
|
162
305
|
if not re.search(rf"(?m)^q{i}:\s*$", content):
|
|
@@ -166,8 +309,8 @@ def extend_evidence_map(root: Path, count: int, created: list[str], updated: lis
|
|
|
166
309
|
" claims:",
|
|
167
310
|
f" - id: q{i}-main-result",
|
|
168
311
|
f" generated_by: code/q{i}/main.py",
|
|
169
|
-
f" source: results/q{i}/
|
|
170
|
-
|
|
312
|
+
f" source: results/q{i}/TODO-替换为实际中文结果文件",
|
|
313
|
+
" paper_section: paper/main.tex",
|
|
171
314
|
" upstream: TODO",
|
|
172
315
|
" validation: TODO",
|
|
173
316
|
" status: TODO",
|
|
@@ -177,11 +320,18 @@ def extend_evidence_map(root: Path, count: int, created: list[str], updated: lis
|
|
|
177
320
|
return
|
|
178
321
|
rendered = content.rstrip() + "\n" + "\n".join(additions) + "\n"
|
|
179
322
|
existed = path.exists()
|
|
323
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
180
324
|
path.write_text(rendered, encoding="utf-8")
|
|
181
325
|
(updated if existed else created).append(path.relative_to(root).as_posix())
|
|
182
326
|
|
|
183
327
|
|
|
184
|
-
def write_if_missing(
|
|
328
|
+
def write_if_missing(
|
|
329
|
+
root: Path,
|
|
330
|
+
path: Path,
|
|
331
|
+
content: str,
|
|
332
|
+
created: list[str],
|
|
333
|
+
preserved: list[str],
|
|
334
|
+
) -> None:
|
|
185
335
|
relative = path.relative_to(root).as_posix()
|
|
186
336
|
if path.exists():
|
|
187
337
|
preserved.append(relative)
|
|
@@ -194,28 +344,20 @@ def write_if_missing(root: Path, path: Path, content: str, created: list[str], p
|
|
|
194
344
|
def question_main(name: str) -> str:
|
|
195
345
|
return f'''from __future__ import annotations
|
|
196
346
|
|
|
197
|
-
import
|
|
347
|
+
from pathlib import Path
|
|
198
348
|
|
|
199
|
-
|
|
349
|
+
|
|
350
|
+
PROJECT_ROOT = Path(__file__).resolve().parents[2]
|
|
351
|
+
RESULTS_DIR = PROJECT_ROOT / "results" / "{name}"
|
|
352
|
+
FIGURES_DIR = PROJECT_ROOT / "figures" / "{name}"
|
|
200
353
|
|
|
201
354
|
|
|
202
355
|
def main() -> None:
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
summary = {{
|
|
209
|
-
"question": "{name}",
|
|
210
|
-
"status": "TODO",
|
|
211
|
-
"validation": {{"selection_data": "TODO", "test_data": "TODO", "checks": []}},
|
|
212
|
-
"claims": [],
|
|
213
|
-
}}
|
|
214
|
-
(results_dir / "summary.json").write_text(
|
|
215
|
-
json.dumps(summary, ensure_ascii=False, indent=2) + "\\n",
|
|
216
|
-
encoding="utf-8",
|
|
217
|
-
)
|
|
218
|
-
print("[OK] {name} scaffold completed")
|
|
356
|
+
RESULTS_DIR.mkdir(parents=True, exist_ok=True)
|
|
357
|
+
FIGURES_DIR.mkdir(parents=True, exist_ok=True)
|
|
358
|
+
# 读题后:让 main.py 只编排输入、领域计算、检验和落盘。
|
|
359
|
+
# 将实际模型拆到按职责命名的同级模块,并使用中文结果/图件文件名。
|
|
360
|
+
raise NotImplementedError("请先实现问题{name}的真实模型与验证流程")
|
|
219
361
|
|
|
220
362
|
|
|
221
363
|
if __name__ == "__main__":
|
|
@@ -230,7 +372,7 @@ def question_tex(number: int) -> str:
|
|
|
230
372
|
\TODO{{明确本题交付、输入、单位及其与前后小题的数据关系;成稿时把本标题改成领域化标题。}}
|
|
231
373
|
|
|
232
374
|
\subsection{{方法比较与选择依据}}
|
|
233
|
-
\TODO{{比较候选方法,说明所选方法为何匹配数据、约束和决策目标。}}
|
|
375
|
+
\TODO{{比较候选方法,说明所选方法为何匹配数据、约束和决策目标。}}
|
|
234
376
|
|
|
235
377
|
\subsection{{模型构建与参数来源}}
|
|
236
378
|
\TODO{{定义变量、目标函数、约束和参数来源,保持符号、单位与代码一致。}}
|
|
@@ -239,7 +381,7 @@ def question_tex(number: int) -> str:
|
|
|
239
381
|
\TODO{{说明算法步骤、数据切分、边界处理及结果文件的生成路径。}}
|
|
240
382
|
|
|
241
383
|
\subsection{{结果解释与有效性检验}}
|
|
242
|
-
\TODO{{从 results/q{number}/
|
|
384
|
+
\TODO{{从 results/q{number}/ 引用实际中文结果文件和 figures/q{number}/ 的描述性中文图件,解释结果并报告误差、敏感性、稳健性或基线比较。}}
|
|
243
385
|
|
|
244
386
|
\subsection{{本问结论与后续接口}}
|
|
245
387
|
\TODO{{用两三句话直接回答本题,并说明输出如何进入下一问;成稿时按实际内容改名。}}
|
|
@@ -8,7 +8,14 @@ import subprocess
|
|
|
8
8
|
from collections import defaultdict
|
|
9
9
|
from pathlib import Path
|
|
10
10
|
|
|
11
|
-
from project_utils import
|
|
11
|
+
from project_utils import (
|
|
12
|
+
build_directory,
|
|
13
|
+
control_path,
|
|
14
|
+
generated_directory,
|
|
15
|
+
iter_regular_files,
|
|
16
|
+
load_profile,
|
|
17
|
+
numeric_limit,
|
|
18
|
+
)
|
|
12
19
|
|
|
13
20
|
|
|
14
21
|
EXCLUDED_PARTS = {
|
|
@@ -72,25 +79,31 @@ def tex_file_name(value: str) -> str:
|
|
|
72
79
|
|
|
73
80
|
|
|
74
81
|
def generate_appendices(root: Path, profile: dict[str, object]) -> None:
|
|
75
|
-
|
|
76
|
-
|
|
82
|
+
generated = generated_directory(root)
|
|
83
|
+
generated.mkdir(parents=True, exist_ok=True)
|
|
77
84
|
paper_profile = profile["paper"]
|
|
78
85
|
assert isinstance(paper_profile, dict)
|
|
79
86
|
|
|
80
|
-
support_path =
|
|
87
|
+
support_path = generated / "support-files.tex"
|
|
81
88
|
if bool(paper_profile.get("include_support_file_list")):
|
|
82
89
|
support = []
|
|
83
90
|
for directory in ("code", "results", "figures"):
|
|
84
91
|
support.extend(path.relative_to(root).as_posix() for path in iter_regular_files(root, directory, EXCLUDED_PARTS))
|
|
85
92
|
ai_pdf = root / "paper" / "AI工具使用详情.pdf"
|
|
86
93
|
if ai_pdf.is_file():
|
|
87
|
-
support.append("
|
|
88
|
-
support.append("paper/evidence-freeze.json")
|
|
94
|
+
support.append("AI工具使用详情.pdf")
|
|
89
95
|
support_profile = profile["support"]
|
|
90
96
|
assert isinstance(support_profile, dict)
|
|
91
|
-
|
|
97
|
+
environment = control_path(root, "environment.json")
|
|
98
|
+
if environment.is_file():
|
|
99
|
+
support.append("复现环境.json")
|
|
100
|
+
ai_log = control_path(
|
|
101
|
+
root,
|
|
102
|
+
"ai-use-log.md",
|
|
103
|
+
root / "paper" / "ai-use-log.md",
|
|
104
|
+
)
|
|
92
105
|
if bool(support_profile.get("include_ai_log")) and ai_log.is_file():
|
|
93
|
-
support.append("
|
|
106
|
+
support.append("AI工具使用记录.md")
|
|
94
107
|
grouped: dict[str, list[str]] = defaultdict(list)
|
|
95
108
|
for path in sorted(set(support)):
|
|
96
109
|
item = Path(path)
|
|
@@ -117,9 +130,9 @@ def generate_appendices(root: Path, profile: dict[str, object]) -> None:
|
|
|
117
130
|
rows.extend([" \\bottomrule", "\\end{longtable}", "\\normalsize"])
|
|
118
131
|
support_path.write_text("\n".join(rows) + "\n", encoding="utf-8")
|
|
119
132
|
else:
|
|
120
|
-
support_path.write_text("% Disabled by
|
|
133
|
+
support_path.write_text("% Disabled by .cumcm/profile.json.\n", encoding="utf-8")
|
|
121
134
|
|
|
122
|
-
source_path =
|
|
135
|
+
source_path = generated / "source-code.tex"
|
|
123
136
|
if bool(paper_profile.get("include_source_appendix")):
|
|
124
137
|
listings = [
|
|
125
138
|
"\\section{完整可运行程序代码}",
|
|
@@ -148,18 +161,19 @@ def generate_appendices(root: Path, profile: dict[str, object]) -> None:
|
|
|
148
161
|
)
|
|
149
162
|
source_path.write_text("\n\n".join(listings) + "\n", encoding="utf-8")
|
|
150
163
|
else:
|
|
151
|
-
source_path.write_text("% Disabled by
|
|
164
|
+
source_path.write_text("% Disabled by .cumcm/profile.json.\n", encoding="utf-8")
|
|
152
165
|
|
|
153
166
|
|
|
154
|
-
def find_engine() -> tuple[list[str], str]:
|
|
167
|
+
def find_engine(output_directory: Path) -> tuple[list[str], str]:
|
|
168
|
+
output = str(output_directory)
|
|
155
169
|
xelatex = shutil.which("xelatex")
|
|
156
170
|
if os.name == "nt" and xelatex:
|
|
157
|
-
return [xelatex, "-interaction=nonstopmode", "-halt-on-error", "-file-line-error", "-output-directory=
|
|
171
|
+
return [xelatex, "-interaction=nonstopmode", "-halt-on-error", "-file-line-error", f"-output-directory={output}", "main.tex"], "xelatex"
|
|
158
172
|
latexmk = shutil.which("latexmk")
|
|
159
173
|
if latexmk:
|
|
160
|
-
return [latexmk, "-xelatex", "-interaction=nonstopmode", "-halt-on-error", "-file-line-error", "-outdir=
|
|
174
|
+
return [latexmk, "-xelatex", "-interaction=nonstopmode", "-halt-on-error", "-file-line-error", f"-outdir={output}", "main.tex"], "latexmk"
|
|
161
175
|
if xelatex:
|
|
162
|
-
return [xelatex, "-interaction=nonstopmode", "-halt-on-error", "-file-line-error", "-output-directory=
|
|
176
|
+
return [xelatex, "-interaction=nonstopmode", "-halt-on-error", "-file-line-error", f"-output-directory={output}", "main.tex"], "xelatex"
|
|
163
177
|
raise SystemExit("Neither latexmk nor xelatex is available on PATH (TeX Live required).")
|
|
164
178
|
|
|
165
179
|
|
|
@@ -189,9 +203,8 @@ def audit_log(log_path: Path, strict_layout: bool) -> None:
|
|
|
189
203
|
raise SystemExit("TeX quality audit failed: " + ", ".join(failures) + f". Inspect {log_path}\n{diagnostics}")
|
|
190
204
|
|
|
191
205
|
|
|
192
|
-
def clear_entry_build_artifacts(
|
|
206
|
+
def clear_entry_build_artifacts(build: Path, source_name: str) -> None:
|
|
193
207
|
"""Remove only deterministic outputs for one TeX entry point."""
|
|
194
|
-
build = paper / "build"
|
|
195
208
|
stem = Path(source_name).stem
|
|
196
209
|
for suffix in BUILD_ARTIFACT_SUFFIXES:
|
|
197
210
|
target = build / f"{stem}{suffix}"
|
|
@@ -229,23 +242,25 @@ def build_tex(paper: Path, source_name: str, output_name: str, strict_layout: bo
|
|
|
229
242
|
source = paper / source_name
|
|
230
243
|
if source.is_symlink():
|
|
231
244
|
raise SystemExit(f"Symbolic TeX entry points are not allowed: {source}")
|
|
232
|
-
|
|
233
|
-
|
|
245
|
+
build = build_directory(paper.parent)
|
|
246
|
+
build.mkdir(parents=True, exist_ok=True)
|
|
247
|
+
clear_entry_build_artifacts(build, source_name)
|
|
248
|
+
command, engine = find_engine(build)
|
|
234
249
|
command[-1] = source_name
|
|
235
250
|
completed = run(command, paper)
|
|
236
251
|
if completed.returncode == 0 and engine == "xelatex":
|
|
237
252
|
completed = run(command, paper)
|
|
238
253
|
if completed.returncode != 0:
|
|
239
254
|
stem = Path(source_name).stem
|
|
240
|
-
log_path =
|
|
255
|
+
log_path = build / f"{stem}.log"
|
|
241
256
|
diagnostics = tex_failure_diagnostics(log_path, completed.stdout)
|
|
242
257
|
raise SystemExit(
|
|
243
258
|
f"TeX build failed ({engine}, {source_name}). "
|
|
244
259
|
f"Repair the first reported source error and rerun the finalizer.\n{diagnostics}"
|
|
245
260
|
)
|
|
246
261
|
stem = Path(source_name).stem
|
|
247
|
-
built =
|
|
248
|
-
audit_log(
|
|
262
|
+
built = build / f"{stem}.pdf"
|
|
263
|
+
audit_log(build / f"{stem}.log", strict_layout)
|
|
249
264
|
if not built.is_file():
|
|
250
265
|
raise SystemExit(f"TeX reported success but did not create {built}")
|
|
251
266
|
final = paper / output_name
|
|
@@ -274,7 +289,7 @@ def main() -> None:
|
|
|
274
289
|
pdf_limit = numeric_limit(profile["paper"], "max_pdf_mb")
|
|
275
290
|
except (ValueError, TypeError) as error:
|
|
276
291
|
raise SystemExit(str(error)) from error
|
|
277
|
-
(
|
|
292
|
+
build_directory(root).mkdir(parents=True, exist_ok=True)
|
|
278
293
|
|
|
279
294
|
ai_profile = profile["ai"]
|
|
280
295
|
assert isinstance(ai_profile, dict)
|
|
@@ -7,6 +7,8 @@ import platform
|
|
|
7
7
|
import sys
|
|
8
8
|
from pathlib import Path
|
|
9
9
|
|
|
10
|
+
from project_utils import control_directory
|
|
11
|
+
|
|
10
12
|
|
|
11
13
|
def main() -> None:
|
|
12
14
|
parser = argparse.ArgumentParser(description="Capture the reproducibility environment.")
|
|
@@ -36,7 +38,7 @@ def main() -> None:
|
|
|
36
38
|
"platform": platform.platform(),
|
|
37
39
|
"packages": packages,
|
|
38
40
|
}
|
|
39
|
-
output = root / "
|
|
41
|
+
output = control_directory(root) / "environment.json"
|
|
40
42
|
output.parent.mkdir(parents=True, exist_ok=True)
|
|
41
43
|
output.write_text(json.dumps(payload, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
|
|
42
44
|
print(f"[OK] Environment captured: {output}")
|
|
@@ -4,6 +4,8 @@ import argparse
|
|
|
4
4
|
import shutil
|
|
5
5
|
from pathlib import Path
|
|
6
6
|
|
|
7
|
+
from project_utils import build_directory
|
|
8
|
+
|
|
7
9
|
|
|
8
10
|
CACHE_DIR_NAMES = {
|
|
9
11
|
"__pycache__",
|
|
@@ -23,9 +25,12 @@ def targets(root: Path) -> list[Path]:
|
|
|
23
25
|
if path.is_dir() and path.name in CACHE_DIR_NAMES:
|
|
24
26
|
found.add(path)
|
|
25
27
|
elif path.is_file() and any(path.name.endswith(suffix) for suffix in TEX_CACHE_SUFFIXES):
|
|
26
|
-
if
|
|
28
|
+
if any(
|
|
29
|
+
part in {"paper", ".cumcm"}
|
|
30
|
+
for part in path.relative_to(root).parts
|
|
31
|
+
):
|
|
27
32
|
found.add(path)
|
|
28
|
-
page_review = root / "
|
|
33
|
+
page_review = build_directory(root) / "page-review"
|
|
29
34
|
if page_review.is_dir() and not page_review.is_symlink():
|
|
30
35
|
found.add(page_review)
|
|
31
36
|
return sorted(found, key=lambda path: (len(path.parts), str(path)), reverse=True)
|
|
@@ -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 iter_regular_files
|
|
10
|
+
from project_utils import control_path, iter_regular_files
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
EXCLUDED_PARTS = {"__pycache__", ".pytest_cache", ".mypy_cache", ".ruff_cache", "build"}
|
|
@@ -37,7 +37,11 @@ def snapshot_evidence(root: Path) -> list[dict[str, Any]]:
|
|
|
37
37
|
|
|
38
38
|
|
|
39
39
|
def freeze_path(root: Path) -> Path:
|
|
40
|
-
return
|
|
40
|
+
return control_path(
|
|
41
|
+
root,
|
|
42
|
+
"evidence-freeze.json",
|
|
43
|
+
root / "paper" / "evidence-freeze.json",
|
|
44
|
+
)
|
|
41
45
|
|
|
42
46
|
|
|
43
47
|
def load_freeze(root: Path) -> dict[str, Any] | None:
|
|
@@ -53,7 +57,7 @@ def load_freeze(root: Path) -> dict[str, Any] | None:
|
|
|
53
57
|
def evidence_differences(root: Path) -> list[str]:
|
|
54
58
|
payload = load_freeze(root)
|
|
55
59
|
if payload is None:
|
|
56
|
-
return ["
|
|
60
|
+
return [".cumcm/evidence-freeze.json is missing"]
|
|
57
61
|
expected = {str(item["path"]): (int(item["size_bytes"]), str(item["sha256"])) for item in payload["files"] if isinstance(item, dict)}
|
|
58
62
|
actual = {str(item["path"]): (int(item["size_bytes"]), str(item["sha256"])) for item in snapshot_evidence(root)}
|
|
59
63
|
differences = [f"added evidence: {path}" for path in sorted(actual.keys() - expected.keys())]
|
|
@@ -65,7 +69,7 @@ def evidence_differences(root: Path) -> list[str]:
|
|
|
65
69
|
def require_refresh_authorization(root: Path, refresh: bool) -> None:
|
|
66
70
|
if freeze_path(root).is_file() and not refresh:
|
|
67
71
|
raise SystemExit(
|
|
68
|
-
"Evidence is frozen by
|
|
72
|
+
"Evidence is frozen by .cumcm/evidence-freeze.json. Refusing to rerun code. "
|
|
69
73
|
"Use --refresh-evidence together with --run-code only after an explicit request to recompute results."
|
|
70
74
|
)
|
|
71
75
|
|
|
@@ -6,6 +6,8 @@ import sys
|
|
|
6
6
|
from pathlib import Path
|
|
7
7
|
|
|
8
8
|
from evidence_freeze import require_refresh_authorization, write_freeze
|
|
9
|
+
from project_utils import question_numbers
|
|
10
|
+
from validate_project import code_architecture_errors
|
|
9
11
|
|
|
10
12
|
|
|
11
13
|
SCRIPT_ROOT = Path(__file__).resolve().parent
|
|
@@ -38,6 +40,16 @@ def main() -> None:
|
|
|
38
40
|
completed = subprocess.run([sys.executable, str(entry)], cwd=root / "code", check=False)
|
|
39
41
|
if completed.returncode:
|
|
40
42
|
raise SystemExit("code/run_all.py failed; paper was not rebuilt from stale evidence.")
|
|
43
|
+
discovered_questions = question_numbers(root)
|
|
44
|
+
architecture_errors = code_architecture_errors(
|
|
45
|
+
root, max(discovered_questions, default=0)
|
|
46
|
+
)
|
|
47
|
+
if architecture_errors:
|
|
48
|
+
for error in architecture_errors:
|
|
49
|
+
print(f"[ERROR] {error}")
|
|
50
|
+
raise SystemExit(
|
|
51
|
+
"Finalization stopped before compilation because modeling code is incomplete."
|
|
52
|
+
)
|
|
41
53
|
run("capture_environment.py", root)
|
|
42
54
|
run("build_paper.py", root, *(["--strict-layout"] if args.strict_layout else []))
|
|
43
55
|
audit_flags = ["--fail-on-errors"]
|
|
@@ -51,6 +63,10 @@ def main() -> None:
|
|
|
51
63
|
if args.clean:
|
|
52
64
|
run("clean_project.py", root, "--apply")
|
|
53
65
|
print(f"[OK] Complete modeling-paper delivery finalized: {root / 'paper' / 'main.pdf'}")
|
|
66
|
+
print(
|
|
67
|
+
"[ORBIT_TERMINAL_SUCCESS] Final PDF and support archive are current. "
|
|
68
|
+
"Stop tool use and return the final delivery report."
|
|
69
|
+
)
|
|
54
70
|
|
|
55
71
|
|
|
56
72
|
if __name__ == "__main__":
|