@orbit-build/cli 0.5.8 → 0.6.1
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 +2 -1
- package/dist/index.js +15 -17
- package/package.json +1 -1
- package/skills/cumcm-draft/SKILL.md +17 -0
- package/skills/cumcm-draft/assets/project-template/paper/contest-profile.json +9 -2
- package/skills/cumcm-draft/references/code-and-output-style.md +32 -2
- package/skills/cumcm-draft/references/cumcm-compliance.md +9 -3
- package/skills/cumcm-draft/references/project-architecture.md +8 -1
- package/skills/cumcm-draft/scripts/project_utils.py +13 -1
- package/skills/cumcm-draft/scripts/validate_project.py +384 -1
package/README.md
CHANGED
|
@@ -102,7 +102,8 @@ context.
|
|
|
102
102
|
The official DeepSeek profile refreshes its live catalog after login and keeps
|
|
103
103
|
the selector stable as `Auto`, `deepseek-v4-flash`, and `deepseek-v4-pro`;
|
|
104
104
|
dated backend build names are
|
|
105
|
-
shown only in diagnostics.
|
|
105
|
+
shown only in diagnostics. Both official lanes use the native Responses API in
|
|
106
|
+
automatic mode; compatible gateways retain their explicitly configured transport.
|
|
106
107
|
|
|
107
108
|
Credentials use native OS protection when available and are redacted from
|
|
108
109
|
configuration, diagnostics, events, sessions, and exported traces.
|
package/dist/index.js
CHANGED
|
@@ -242122,11 +242122,11 @@ import { z as z33 } from "zod";
|
|
|
242122
242122
|
var DEEPSEEK_V4_FLASH = "deepseek-v4-flash";
|
|
242123
242123
|
var DEEPSEEK_V4_PRO = "deepseek-v4-pro";
|
|
242124
242124
|
var DEEPSEEK_V4_FLASH_VERSION = "DeepSeek-V4-Flash-0731";
|
|
242125
|
-
var DEEPSEEK_V4_PRO_VERSION = "DeepSeek-V4-Pro";
|
|
242125
|
+
var DEEPSEEK_V4_PRO_VERSION = "DeepSeek-V4-Pro-0813";
|
|
242126
242126
|
var DEEPSEEK_V4_CONTEXT_TOKENS = 1048576;
|
|
242127
242127
|
var DEEPSEEK_V4_MAX_OUTPUT_TOKENS = 384e3;
|
|
242128
242128
|
var DEEPSEEK_V4_EFFECTIVE_CONTEXT_PERCENT = 0.95;
|
|
242129
|
-
var DEEPSEEK_REASONING_EFFORTS = ["high", "max"];
|
|
242129
|
+
var DEEPSEEK_REASONING_EFFORTS = ["low", "high", "max"];
|
|
242130
242130
|
function isOfficialDeepSeekApi(baseUrl) {
|
|
242131
242131
|
try {
|
|
242132
242132
|
const url = new URL(baseUrl);
|
|
@@ -242147,24 +242147,22 @@ function getDeepSeekV4ModelProfile(model) {
|
|
|
242147
242147
|
canonicalModel: DEEPSEEK_V4_FLASH,
|
|
242148
242148
|
modelVersion: DEEPSEEK_V4_FLASH_VERSION,
|
|
242149
242149
|
supportsResponses: true,
|
|
242150
|
-
defaultReasoningEffort: "high",
|
|
242151
242150
|
reasoningEfforts: DEEPSEEK_REASONING_EFFORTS,
|
|
242152
242151
|
parallelToolCalls: true,
|
|
242153
242152
|
officialRequestModel: officialRequestModel && leaf === DEEPSEEK_V4_FLASH
|
|
242154
242153
|
};
|
|
242155
242154
|
}
|
|
242156
|
-
if (leaf === DEEPSEEK_V4_PRO) {
|
|
242155
|
+
if (leaf === DEEPSEEK_V4_PRO || leaf === `${DEEPSEEK_V4_PRO}-0813`) {
|
|
242157
242156
|
return {
|
|
242158
242157
|
lane: "pro",
|
|
242159
242158
|
legacyAlias: false,
|
|
242160
242159
|
optimizedThinkingDefault: true,
|
|
242161
242160
|
canonicalModel: DEEPSEEK_V4_PRO,
|
|
242162
242161
|
modelVersion: DEEPSEEK_V4_PRO_VERSION,
|
|
242163
|
-
supportsResponses:
|
|
242164
|
-
defaultReasoningEffort: "high",
|
|
242162
|
+
supportsResponses: true,
|
|
242165
242163
|
reasoningEfforts: DEEPSEEK_REASONING_EFFORTS,
|
|
242166
242164
|
parallelToolCalls: true,
|
|
242167
|
-
officialRequestModel
|
|
242165
|
+
officialRequestModel: officialRequestModel && leaf === DEEPSEEK_V4_PRO
|
|
242168
242166
|
};
|
|
242169
242167
|
}
|
|
242170
242168
|
if (leaf === "deepseek-chat") {
|
|
@@ -242175,7 +242173,6 @@ function getDeepSeekV4ModelProfile(model) {
|
|
|
242175
242173
|
canonicalModel: DEEPSEEK_V4_FLASH,
|
|
242176
242174
|
modelVersion: DEEPSEEK_V4_FLASH_VERSION,
|
|
242177
242175
|
supportsResponses: true,
|
|
242178
|
-
defaultReasoningEffort: "high",
|
|
242179
242176
|
reasoningEfforts: DEEPSEEK_REASONING_EFFORTS,
|
|
242180
242177
|
parallelToolCalls: true,
|
|
242181
242178
|
officialRequestModel
|
|
@@ -242189,7 +242186,6 @@ function getDeepSeekV4ModelProfile(model) {
|
|
|
242189
242186
|
canonicalModel: DEEPSEEK_V4_FLASH,
|
|
242190
242187
|
modelVersion: DEEPSEEK_V4_FLASH_VERSION,
|
|
242191
242188
|
supportsResponses: true,
|
|
242192
|
-
defaultReasoningEffort: "high",
|
|
242193
242189
|
reasoningEfforts: DEEPSEEK_REASONING_EFFORTS,
|
|
242194
242190
|
parallelToolCalls: true,
|
|
242195
242191
|
officialRequestModel
|
|
@@ -242198,8 +242194,7 @@ function getDeepSeekV4ModelProfile(model) {
|
|
|
242198
242194
|
return void 0;
|
|
242199
242195
|
}
|
|
242200
242196
|
function getDeepSeekReasoningEffort(budgetTokens = 4096, explicitEffort) {
|
|
242201
|
-
if (explicitEffort
|
|
242202
|
-
if (explicitEffort) return "high";
|
|
242197
|
+
if (explicitEffort) return explicitEffort;
|
|
242203
242198
|
if (budgetTokens >= 8192) return "max";
|
|
242204
242199
|
return "high";
|
|
242205
242200
|
}
|
|
@@ -242215,8 +242210,8 @@ function getDeepSeekThinkingPolicy(profile, input) {
|
|
|
242215
242210
|
}
|
|
242216
242211
|
return {
|
|
242217
242212
|
enabled: true,
|
|
242218
|
-
effort:
|
|
242219
|
-
budgetTokens:
|
|
242213
|
+
effort: "low",
|
|
242214
|
+
budgetTokens: 2048
|
|
242220
242215
|
};
|
|
242221
242216
|
}
|
|
242222
242217
|
function resolveModelAdaptation(model) {
|
|
@@ -244858,7 +244853,10 @@ var DeepSeekOpenAIProvider = class {
|
|
|
244858
244853
|
bodyData.prompt = prompt;
|
|
244859
244854
|
bodyData.suffix = options.suffix;
|
|
244860
244855
|
}
|
|
244861
|
-
|
|
244856
|
+
const requestedAdaptation = resolveModelAdaptation(
|
|
244857
|
+
options?.model ?? DEEPSEEK_V4_FLASH
|
|
244858
|
+
);
|
|
244859
|
+
bodyData.model = requestedAdaptation.family === "deepseek-v4" && !requestedAdaptation.deepSeekV4.legacyAlias ? requestedAdaptation.deepSeekV4.canonicalModel : DEEPSEEK_V4_FLASH;
|
|
244862
244860
|
}
|
|
244863
244861
|
const response = await fetchWithRetry(
|
|
244864
244862
|
url,
|
|
@@ -267501,17 +267499,17 @@ function buildDeepSeekDoctorSection(cwd, config) {
|
|
|
267501
267499
|
);
|
|
267502
267500
|
lines.push(
|
|
267503
267501
|
picocolors6.gray(
|
|
267504
|
-
`\u25CF Model
|
|
267502
|
+
`\u25CF Model profiles: Flash=${DEEPSEEK_V4_FLASH_VERSION}; Pro=${DEEPSEEK_V4_PRO_VERSION}; ${DEEPSEEK_V4_CONTEXT_TOKENS.toLocaleString("en-US")} context tokens and ${DEEPSEEK_V4_MAX_OUTPUT_TOKENS.toLocaleString("en-US")} maximum output tokens.`
|
|
267505
267503
|
)
|
|
267506
267504
|
);
|
|
267507
267505
|
lines.push(
|
|
267508
267506
|
picocolors6.gray(
|
|
267509
|
-
`\u25CF Orbit
|
|
267507
|
+
`\u25CF Orbit V4 policy: Flash=${config.agent?.fastMaxOutputTokens ?? 32768} output tokens with low/high/max task-adaptive thinking; Pro=${config.agent?.maxOutputTokens ?? 16384} with high/max thinking.`
|
|
267510
267508
|
)
|
|
267511
267509
|
);
|
|
267512
267510
|
lines.push(
|
|
267513
267511
|
picocolors6.gray(
|
|
267514
|
-
`\u25CF DeepSeek API format: ${provider?.deepSeekApiFormat ?? "chat-completions"}. Official Flash
|
|
267512
|
+
`\u25CF DeepSeek API format: ${provider?.deepSeekApiFormat ?? "chat-completions"}. Official Flash and Pro use Responses in auto mode; compatible gateways use their configured DeepSeek transport.`
|
|
267515
267513
|
)
|
|
267516
267514
|
);
|
|
267517
267515
|
lines.push(
|
package/package.json
CHANGED
|
@@ -191,6 +191,23 @@ the outcome. Record explicit upstream artifact contracts between subproblems.
|
|
|
191
191
|
- Run from a clean entry point and repair failures before asserting results.
|
|
192
192
|
- Save factual outputs in `results/qN`, paper-ready visuals in `figures/qN`,
|
|
193
193
|
and completed workbook deliverables in `results/qN`.
|
|
194
|
+
- Treat leaf tabular deliverables under `results/qN` as Chinese-facing evidence:
|
|
195
|
+
give CSV/TSV/XLS/XLSX files descriptive Chinese filenames; write CSV/TSV
|
|
196
|
+
column headers, Excel worksheet names, and Excel table headers in Chinese;
|
|
197
|
+
include units in the header when applicable; and retain standard symbols or
|
|
198
|
+
abbreviations only after the Chinese meaning, such as `均方根误差(RMSE)`.
|
|
199
|
+
Encode CSV/TSV with UTF-8-SIG for reliable Excel display. Stable machine
|
|
200
|
+
control files such as `summary.json` and `environment.json` may keep their
|
|
201
|
+
documented ASCII names.
|
|
202
|
+
- Preserve a non-Chinese filename, header, or worksheet name only when the
|
|
203
|
+
problem statement or supplied fill-in template fixes it. Do not translate or
|
|
204
|
+
silently reshape that prescribed schema. Register the exact output path,
|
|
205
|
+
immutable `question/` source (or root-level problem input), reason, and only
|
|
206
|
+
the necessary allowances in
|
|
207
|
+
`paper/contest-profile.json.result_artifacts.fixed_schema_exceptions` so the
|
|
208
|
+
finalizer can distinguish a contest requirement from an accidental English
|
|
209
|
+
artifact. Internal convenience and cross-question code contracts are not
|
|
210
|
+
exceptions; use a Chinese persisted schema and validate it explicitly.
|
|
194
211
|
- In a compact handoff, place only explicitly required submission artifacts
|
|
195
212
|
(final PDFs and required filled Excel/Word files) at project root. Keep
|
|
196
213
|
internal CSV/JSON evidence under `results/qN`. Package code, necessary
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schema_version": 1,
|
|
3
3
|
"profile": "cumcm-2026",
|
|
4
|
-
"rules_checked_at": "2026-08-
|
|
4
|
+
"rules_checked_at": "2026-08-12",
|
|
5
5
|
"paper": {
|
|
6
6
|
"max_pdf_mb": 20,
|
|
7
7
|
"max_body_pages": 30,
|
|
@@ -12,6 +12,13 @@
|
|
|
12
12
|
"max_archive_mb": 20,
|
|
13
13
|
"include_ai_log": false
|
|
14
14
|
},
|
|
15
|
+
"result_artifacts": {
|
|
16
|
+
"require_chinese_filenames": true,
|
|
17
|
+
"require_chinese_headers": true,
|
|
18
|
+
"require_chinese_sheet_names": true,
|
|
19
|
+
"require_utf8_sig_csv": true,
|
|
20
|
+
"fixed_schema_exceptions": []
|
|
21
|
+
},
|
|
15
22
|
"ai": {
|
|
16
23
|
"policy": "cumcm-2025-trial",
|
|
17
24
|
"used": true,
|
|
@@ -23,6 +30,6 @@
|
|
|
23
30
|
"sources": [
|
|
24
31
|
"https://www.mcm.edu.cn/html_cn/node/4cd596519c9eb9fbd866398f6df0caa3.html",
|
|
25
32
|
"https://www.mcm.edu.cn/html_cn/node/9d8e511fe7a1447b35f53a82c908e2e0.html",
|
|
26
|
-
"https://
|
|
33
|
+
"https://en.mcm.edu.cn/html_en/node/b87f1a9b1dbbd987f56513609f416722.html"
|
|
27
34
|
]
|
|
28
35
|
}
|
|
@@ -80,8 +80,38 @@ For each `results/qN` prefer:
|
|
|
80
80
|
- serialized model only when later questions need it;
|
|
81
81
|
- completed `.xlsx` only when the problem requests a filled workbook.
|
|
82
82
|
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
All leaf tabular evidence is Chinese-facing by default:
|
|
84
|
+
|
|
85
|
+
- use a descriptive Chinese filename for every generated CSV, TSV, XLS, or
|
|
86
|
+
XLSX file, such as `逐日需求预测.csv` rather than `forecast.csv` or
|
|
87
|
+
`result.csv`;
|
|
88
|
+
- use Chinese column headers and include units where applicable, such as
|
|
89
|
+
`日期`, `预测需求量(件)`, and `均方根误差(RMSE)`;
|
|
90
|
+
- use Chinese Excel worksheet names and Chinese table headers for generated
|
|
91
|
+
workbooks;
|
|
92
|
+
- write CSV and TSV with UTF-8-SIG so Chinese text opens correctly in Excel;
|
|
93
|
+
- keep fixed machine-control artifacts such as `summary.json` and
|
|
94
|
+
`environment.json` at their documented stable paths.
|
|
95
|
+
|
|
96
|
+
Do not translate a filename, field, column order, or worksheet name that the
|
|
97
|
+
problem or a supplied fill-in template explicitly fixes. Record that exact
|
|
98
|
+
exception in
|
|
99
|
+
`paper/contest-profile.json.result_artifacts.fixed_schema_exceptions`:
|
|
100
|
+
|
|
101
|
+
```json
|
|
102
|
+
{
|
|
103
|
+
"path": "results/q2/submit.csv",
|
|
104
|
+
"source": "question/附件3-提交模板.csv",
|
|
105
|
+
"reason": "题目要求按原文件名和原字段上传",
|
|
106
|
+
"allow": ["filename", "headers"]
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Allowed exception scopes are `filename`, `headers`, `sheet_names`, and
|
|
111
|
+
`encoding`. Grant only what the official requirement fixes. A code-facing
|
|
112
|
+
English schema, a library default, or personal convenience is not an exception;
|
|
113
|
+
persist a Chinese schema and adapt internal variables at the read/write
|
|
114
|
+
boundary. Never write outputs into `question/`.
|
|
85
115
|
|
|
86
116
|
## Figures
|
|
87
117
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# CUMCM compliance profile
|
|
2
2
|
|
|
3
|
-
Checked against the official CUMCM site on 2026-08-
|
|
3
|
+
Checked against the official CUMCM site on 2026-08-12. Recheck the official
|
|
4
4
|
site at the start of every contest cycle; newer organizer material and supplied
|
|
5
5
|
regional requirements outrank this reference.
|
|
6
6
|
|
|
@@ -46,8 +46,14 @@ format and participation rules. Until a newer primary rule replaces it:
|
|
|
46
46
|
6. If no AI was used, place `本参赛队未使用任何 AI 工具` after the references.
|
|
47
47
|
Never claim this when an AI Skill or agent contributed.
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
The Chinese rules index still lists the 2025 trial AI rule, and the 2026
|
|
50
|
+
participation rule continues to require it. The Chinese detail URL returned 404
|
|
51
|
+
when rechecked on 2026-08-12, so use the accessible official English mirror for
|
|
52
|
+
the full text until the organizer restores or replaces the Chinese page:
|
|
53
|
+
<https://en.mcm.edu.cn/html_en/node/b87f1a9b1dbbd987f56513609f416722.html>
|
|
54
|
+
|
|
55
|
+
Official Chinese rules index:
|
|
56
|
+
<https://www.mcm.edu.cn/html_cn/block/44e92058f537729c6b6a62a3662ee417.html>
|
|
51
57
|
|
|
52
58
|
The 2026 participation rule explicitly allows AI only as an auxiliary tool and
|
|
53
59
|
requires compliance with the AI-use rule:
|
|
@@ -66,7 +66,14 @@ project-root/
|
|
|
66
66
|
|
|
67
67
|
- Use `q1`, `q2`, ... exactly; do not mix `Q1`, `question1`, or Chinese folder
|
|
68
68
|
names.
|
|
69
|
-
-
|
|
69
|
+
- Use descriptive Chinese filenames for generated tabular artifacts under
|
|
70
|
+
`results/qN`; use Chinese CSV/TSV headers and Chinese Excel worksheet/table
|
|
71
|
+
headers, with units where applicable. Fixed control files such as
|
|
72
|
+
`summary.json` retain their documented ASCII names.
|
|
73
|
+
- Preserve non-Chinese output names or headers only for a problem-prescribed
|
|
74
|
+
fill-in/upload schema, and declare the narrow exception with its immutable
|
|
75
|
+
source and reason under
|
|
76
|
+
`contest-profile.json.result_artifacts.fixed_schema_exceptions`.
|
|
70
77
|
- Use stable ASCII Python module names.
|
|
71
78
|
- Use UTF-8 for text and UTF-8 with BOM for CSV intended for Excel.
|
|
72
79
|
- Include units in column labels or metadata.
|
|
@@ -9,7 +9,7 @@ from typing import Any, Iterable
|
|
|
9
9
|
DEFAULT_PROFILE: dict[str, Any] = {
|
|
10
10
|
"schema_version": 1,
|
|
11
11
|
"profile": "cumcm-2026",
|
|
12
|
-
"rules_checked_at": "2026-08-
|
|
12
|
+
"rules_checked_at": "2026-08-12",
|
|
13
13
|
"paper": {
|
|
14
14
|
"max_pdf_mb": 20,
|
|
15
15
|
"max_body_pages": 30,
|
|
@@ -17,6 +17,13 @@ DEFAULT_PROFILE: dict[str, Any] = {
|
|
|
17
17
|
"include_source_appendix": True,
|
|
18
18
|
},
|
|
19
19
|
"support": {"max_archive_mb": 20, "include_ai_log": False},
|
|
20
|
+
"result_artifacts": {
|
|
21
|
+
"require_chinese_filenames": True,
|
|
22
|
+
"require_chinese_headers": True,
|
|
23
|
+
"require_chinese_sheet_names": True,
|
|
24
|
+
"require_utf8_sig_csv": True,
|
|
25
|
+
"fixed_schema_exceptions": [],
|
|
26
|
+
},
|
|
20
27
|
"ai": {
|
|
21
28
|
"policy": "cumcm-2025-trial",
|
|
22
29
|
"used": True,
|
|
@@ -25,6 +32,11 @@ DEFAULT_PROFILE: dict[str, Any] = {
|
|
|
25
32
|
"reference_key": "ai-tool",
|
|
26
33
|
"details_pdf_required": True,
|
|
27
34
|
},
|
|
35
|
+
"sources": [
|
|
36
|
+
"https://www.mcm.edu.cn/html_cn/node/4cd596519c9eb9fbd866398f6df0caa3.html",
|
|
37
|
+
"https://www.mcm.edu.cn/html_cn/node/9d8e511fe7a1447b35f53a82c908e2e0.html",
|
|
38
|
+
"https://en.mcm.edu.cn/html_en/node/b87f1a9b1dbbd987f56513609f416722.html",
|
|
39
|
+
],
|
|
28
40
|
}
|
|
29
41
|
|
|
30
42
|
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
import argparse
|
|
4
|
+
import csv
|
|
4
5
|
import hashlib
|
|
6
|
+
import io
|
|
5
7
|
import json
|
|
8
|
+
import posixpath
|
|
6
9
|
import re
|
|
7
10
|
import subprocess
|
|
8
11
|
import sys
|
|
9
12
|
import zipfile
|
|
10
13
|
from pathlib import Path, PurePosixPath
|
|
11
14
|
from typing import Any
|
|
15
|
+
from xml.etree import ElementTree
|
|
12
16
|
|
|
13
17
|
from project_utils import ensure_safe_file, load_profile, numeric_limit, question_numbers
|
|
14
18
|
from evidence_freeze import evidence_differences
|
|
@@ -24,6 +28,14 @@ SUPPORT_EXCLUDED_PARTS = {
|
|
|
24
28
|
"build",
|
|
25
29
|
}
|
|
26
30
|
NESTED_ARCHIVE_SUFFIXES = {".zip", ".rar", ".7z"}
|
|
31
|
+
TABULAR_RESULT_SUFFIXES = {".csv", ".tsv", ".xls", ".xlsx"}
|
|
32
|
+
RESULT_EXCEPTION_SCOPES = {"filename", "headers", "sheet_names", "encoding"}
|
|
33
|
+
HAN_RE = re.compile(r"[\u3400-\u4dbf\u4e00-\u9fff\uf900-\ufaff]")
|
|
34
|
+
SPREADSHEET_NS = "{http://schemas.openxmlformats.org/spreadsheetml/2006/main}"
|
|
35
|
+
OFFICE_REL_NS = (
|
|
36
|
+
"{http://schemas.openxmlformats.org/officeDocument/2006/relationships}"
|
|
37
|
+
)
|
|
38
|
+
PACKAGE_REL_NS = "{http://schemas.openxmlformats.org/package/2006/relationships}"
|
|
27
39
|
SCRATCH_DELIVERY_NAMES = {
|
|
28
40
|
"audit_results.py",
|
|
29
41
|
"build_support_zip.ps1",
|
|
@@ -77,6 +89,368 @@ def cumcm_margin_error(main_tex: str) -> str | None:
|
|
|
77
89
|
return None
|
|
78
90
|
|
|
79
91
|
|
|
92
|
+
def has_chinese(value: str) -> bool:
|
|
93
|
+
return HAN_RE.search(value) is not None
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def normalized_relative_path(value: str) -> PurePosixPath:
|
|
97
|
+
normalized = PurePosixPath(value.replace("\\", "/"))
|
|
98
|
+
if normalized.is_absolute() or not normalized.parts or ".." in normalized.parts:
|
|
99
|
+
raise ValueError(f"path must be project-relative without traversal: {value}")
|
|
100
|
+
return normalized
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def first_symlink_component(root: Path, path: Path) -> Path | None:
|
|
104
|
+
try:
|
|
105
|
+
relative = path.relative_to(root)
|
|
106
|
+
except ValueError:
|
|
107
|
+
return path
|
|
108
|
+
current = root
|
|
109
|
+
for part in relative.parts:
|
|
110
|
+
current /= part
|
|
111
|
+
if current.is_symlink():
|
|
112
|
+
return current
|
|
113
|
+
return None
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def fixed_schema_source_error(root: Path, value: str) -> str | None:
|
|
117
|
+
try:
|
|
118
|
+
relative = normalized_relative_path(value)
|
|
119
|
+
except ValueError as error:
|
|
120
|
+
return str(error)
|
|
121
|
+
source = root.joinpath(*relative.parts)
|
|
122
|
+
symlink = first_symlink_component(root, source)
|
|
123
|
+
if symlink is not None:
|
|
124
|
+
return f"fixed-schema source must not traverse a symbolic link: {value}"
|
|
125
|
+
try:
|
|
126
|
+
source.resolve().relative_to(root.resolve())
|
|
127
|
+
except ValueError:
|
|
128
|
+
return f"fixed-schema source escapes the project root: {value}"
|
|
129
|
+
is_question_file = relative.parts[0] == "question"
|
|
130
|
+
is_root_problem_file = (
|
|
131
|
+
len(relative.parts) == 1 and source.suffix.lower() in INPUT_SUFFIXES
|
|
132
|
+
)
|
|
133
|
+
if not is_question_file and not is_root_problem_file:
|
|
134
|
+
return (
|
|
135
|
+
"fixed-schema source must be under question/ or be a supported "
|
|
136
|
+
f"root-level problem input: {value}"
|
|
137
|
+
)
|
|
138
|
+
if not source.is_file():
|
|
139
|
+
return f"fixed-schema source does not exist: {value}"
|
|
140
|
+
return None
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def delimited_header(
|
|
144
|
+
path: Path, delimiter: str, allow_prescribed_encoding: bool = False
|
|
145
|
+
) -> tuple[bool, list[str]]:
|
|
146
|
+
raw = path.read_bytes()
|
|
147
|
+
has_utf8_bom = raw.startswith(b"\xef\xbb\xbf")
|
|
148
|
+
encodings = (
|
|
149
|
+
("utf-8-sig", "gb18030", "utf-16")
|
|
150
|
+
if allow_prescribed_encoding
|
|
151
|
+
else ("utf-8-sig",)
|
|
152
|
+
)
|
|
153
|
+
decode_error: UnicodeDecodeError | None = None
|
|
154
|
+
for encoding in encodings:
|
|
155
|
+
try:
|
|
156
|
+
text = raw.decode(encoding)
|
|
157
|
+
break
|
|
158
|
+
except UnicodeDecodeError as error:
|
|
159
|
+
decode_error = error
|
|
160
|
+
else:
|
|
161
|
+
assert decode_error is not None
|
|
162
|
+
raise decode_error
|
|
163
|
+
for row in csv.reader(io.StringIO(text), delimiter=delimiter):
|
|
164
|
+
headers = [cell.strip() for cell in row]
|
|
165
|
+
if any(headers):
|
|
166
|
+
return has_utf8_bom, headers
|
|
167
|
+
return has_utf8_bom, []
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def xlsx_sheet_headers(path: Path) -> list[tuple[str, list[str]]]:
|
|
171
|
+
"""Read worksheet names and first non-empty rows without optional packages."""
|
|
172
|
+
with zipfile.ZipFile(path) as workbook:
|
|
173
|
+
shared_strings: list[str] = []
|
|
174
|
+
if "xl/sharedStrings.xml" in workbook.namelist():
|
|
175
|
+
shared_root = ElementTree.fromstring(workbook.read("xl/sharedStrings.xml"))
|
|
176
|
+
for item in shared_root.iter(f"{SPREADSHEET_NS}si"):
|
|
177
|
+
shared_strings.append(
|
|
178
|
+
"".join(node.text or "" for node in item.iter(f"{SPREADSHEET_NS}t"))
|
|
179
|
+
)
|
|
180
|
+
|
|
181
|
+
workbook_root = ElementTree.fromstring(workbook.read("xl/workbook.xml"))
|
|
182
|
+
relationships_root = ElementTree.fromstring(
|
|
183
|
+
workbook.read("xl/_rels/workbook.xml.rels")
|
|
184
|
+
)
|
|
185
|
+
targets = {
|
|
186
|
+
relationship.attrib["Id"]: relationship.attrib["Target"]
|
|
187
|
+
for relationship in relationships_root.iter(f"{PACKAGE_REL_NS}Relationship")
|
|
188
|
+
if "Id" in relationship.attrib and "Target" in relationship.attrib
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
sheets: list[tuple[str, list[str]]] = []
|
|
192
|
+
for sheet in workbook_root.iter(f"{SPREADSHEET_NS}sheet"):
|
|
193
|
+
name = sheet.attrib.get("name", "").strip()
|
|
194
|
+
relationship_id = sheet.attrib.get(f"{OFFICE_REL_NS}id")
|
|
195
|
+
if not relationship_id or relationship_id not in targets:
|
|
196
|
+
raise ValueError(f"worksheet relationship is missing for {name or 'unnamed sheet'}")
|
|
197
|
+
target = targets[relationship_id].replace("\\", "/")
|
|
198
|
+
member = target.lstrip("/")
|
|
199
|
+
if not member.startswith("xl/"):
|
|
200
|
+
member = posixpath.normpath(f"xl/{member}")
|
|
201
|
+
if member.startswith("../") or not member.startswith("xl/"):
|
|
202
|
+
raise ValueError(f"unsafe worksheet path in workbook: {target}")
|
|
203
|
+
sheet_root = ElementTree.fromstring(workbook.read(member))
|
|
204
|
+
headers: list[str] = []
|
|
205
|
+
for row in sheet_root.iter(f"{SPREADSHEET_NS}row"):
|
|
206
|
+
values: list[str] = []
|
|
207
|
+
for cell in row.findall(f"{SPREADSHEET_NS}c"):
|
|
208
|
+
cell_type = cell.attrib.get("t")
|
|
209
|
+
if cell_type == "inlineStr":
|
|
210
|
+
value = "".join(
|
|
211
|
+
node.text or ""
|
|
212
|
+
for node in cell.iter(f"{SPREADSHEET_NS}t")
|
|
213
|
+
)
|
|
214
|
+
else:
|
|
215
|
+
raw_value = cell.findtext(f"{SPREADSHEET_NS}v") or ""
|
|
216
|
+
if cell_type == "s" and raw_value:
|
|
217
|
+
try:
|
|
218
|
+
value = shared_strings[int(raw_value)]
|
|
219
|
+
except (IndexError, ValueError) as error:
|
|
220
|
+
raise ValueError(
|
|
221
|
+
f"invalid shared-string index in worksheet {name}"
|
|
222
|
+
) from error
|
|
223
|
+
else:
|
|
224
|
+
value = raw_value
|
|
225
|
+
values.append(value.strip())
|
|
226
|
+
if any(values):
|
|
227
|
+
headers = values
|
|
228
|
+
break
|
|
229
|
+
sheets.append((name, headers))
|
|
230
|
+
return sheets
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
def result_artifact_contract_errors(
|
|
234
|
+
root: Path, profile: dict[str, object]
|
|
235
|
+
) -> list[str]:
|
|
236
|
+
"""Validate Chinese-facing result tables and narrow fixed-schema exceptions."""
|
|
237
|
+
errors: list[str] = []
|
|
238
|
+
flag_names = (
|
|
239
|
+
"require_chinese_filenames",
|
|
240
|
+
"require_chinese_headers",
|
|
241
|
+
"require_chinese_sheet_names",
|
|
242
|
+
"require_utf8_sig_csv",
|
|
243
|
+
)
|
|
244
|
+
flags: dict[str, bool] = {}
|
|
245
|
+
for name in flag_names:
|
|
246
|
+
value = profile.get(name, True)
|
|
247
|
+
if value is not True:
|
|
248
|
+
errors.append(
|
|
249
|
+
f"result_artifacts.{name} must be true; use a provenance-backed "
|
|
250
|
+
"fixed_schema_exceptions entry for a problem-prescribed schema"
|
|
251
|
+
)
|
|
252
|
+
value = True
|
|
253
|
+
flags[name] = value
|
|
254
|
+
|
|
255
|
+
raw_exceptions = profile.get("fixed_schema_exceptions", [])
|
|
256
|
+
if not isinstance(raw_exceptions, list):
|
|
257
|
+
errors.append("result_artifacts.fixed_schema_exceptions must be a list")
|
|
258
|
+
raw_exceptions = []
|
|
259
|
+
exceptions: dict[str, set[str]] = {}
|
|
260
|
+
for index, item in enumerate(raw_exceptions, start=1):
|
|
261
|
+
location = f"result_artifacts.fixed_schema_exceptions[{index}]"
|
|
262
|
+
if not isinstance(item, dict):
|
|
263
|
+
errors.append(f"{location} must be an object")
|
|
264
|
+
continue
|
|
265
|
+
valid = True
|
|
266
|
+
unknown = sorted(set(item) - {"path", "source", "reason", "allow"})
|
|
267
|
+
if unknown:
|
|
268
|
+
errors.append(f"{location} has unsupported fields: {', '.join(unknown)}")
|
|
269
|
+
valid = False
|
|
270
|
+
path_value = item.get("path")
|
|
271
|
+
source_value = item.get("source")
|
|
272
|
+
reason = item.get("reason")
|
|
273
|
+
allow = item.get("allow")
|
|
274
|
+
if not isinstance(path_value, str) or not path_value.strip():
|
|
275
|
+
errors.append(f"{location}.path is required")
|
|
276
|
+
valid = False
|
|
277
|
+
else:
|
|
278
|
+
try:
|
|
279
|
+
relative = normalized_relative_path(path_value)
|
|
280
|
+
except ValueError as error:
|
|
281
|
+
errors.append(f"invalid {location}.path: {error}")
|
|
282
|
+
valid = False
|
|
283
|
+
else:
|
|
284
|
+
in_results = relative.parts[0] == "results"
|
|
285
|
+
in_compact_results = (
|
|
286
|
+
len(relative.parts) >= 2
|
|
287
|
+
and relative.parts[0] == "produce"
|
|
288
|
+
and relative.parts[1] == "results"
|
|
289
|
+
)
|
|
290
|
+
if not in_results and not in_compact_results:
|
|
291
|
+
errors.append(f"{location}.path must be under results/ or produce/results/")
|
|
292
|
+
valid = False
|
|
293
|
+
if relative.suffix.lower() not in TABULAR_RESULT_SUFFIXES:
|
|
294
|
+
errors.append(f"{location}.path must identify a CSV/TSV/XLS/XLSX file")
|
|
295
|
+
valid = False
|
|
296
|
+
target = root.joinpath(*relative.parts)
|
|
297
|
+
if first_symlink_component(root, target) is not None or not target.is_file():
|
|
298
|
+
errors.append(f"{location}.path does not identify a regular file: {path_value}")
|
|
299
|
+
valid = False
|
|
300
|
+
if not isinstance(source_value, str) or not source_value.strip():
|
|
301
|
+
errors.append(f"{location}.source is required")
|
|
302
|
+
valid = False
|
|
303
|
+
else:
|
|
304
|
+
source_error = fixed_schema_source_error(root, source_value)
|
|
305
|
+
if source_error:
|
|
306
|
+
errors.append(f"invalid {location}.source: {source_error}")
|
|
307
|
+
valid = False
|
|
308
|
+
if not isinstance(reason, str) or not reason.strip():
|
|
309
|
+
errors.append(f"{location}.reason is required")
|
|
310
|
+
valid = False
|
|
311
|
+
if (
|
|
312
|
+
not isinstance(allow, list)
|
|
313
|
+
or not allow
|
|
314
|
+
or any(not isinstance(scope, str) for scope in allow)
|
|
315
|
+
):
|
|
316
|
+
errors.append(f"{location}.allow must be a non-empty string list")
|
|
317
|
+
valid = False
|
|
318
|
+
allowed_scopes: set[str] = set()
|
|
319
|
+
else:
|
|
320
|
+
allowed_scopes = set(allow)
|
|
321
|
+
if len(allowed_scopes) != len(allow):
|
|
322
|
+
errors.append(f"{location}.allow must not contain duplicates")
|
|
323
|
+
valid = False
|
|
324
|
+
invalid_scopes = sorted(allowed_scopes - RESULT_EXCEPTION_SCOPES)
|
|
325
|
+
if invalid_scopes:
|
|
326
|
+
errors.append(
|
|
327
|
+
f"{location}.allow has unsupported scopes: {', '.join(invalid_scopes)}"
|
|
328
|
+
)
|
|
329
|
+
valid = False
|
|
330
|
+
if valid and isinstance(path_value, str):
|
|
331
|
+
key = normalized_relative_path(path_value).as_posix().casefold()
|
|
332
|
+
if key in exceptions:
|
|
333
|
+
errors.append(f"duplicate fixed-schema exception path: {path_value}")
|
|
334
|
+
else:
|
|
335
|
+
exceptions[key] = allowed_scopes
|
|
336
|
+
|
|
337
|
+
roots = (root / "results", root / "produce" / "results")
|
|
338
|
+
for base in roots:
|
|
339
|
+
if not base.exists():
|
|
340
|
+
continue
|
|
341
|
+
if first_symlink_component(root, base) is not None:
|
|
342
|
+
errors.append(f"symbolic result directory is unsafe: {base.relative_to(root)}")
|
|
343
|
+
continue
|
|
344
|
+
for path in sorted(base.rglob("*")):
|
|
345
|
+
relative = path.relative_to(root).as_posix()
|
|
346
|
+
if path.is_symlink():
|
|
347
|
+
errors.append(f"symbolic path under result artifacts is unsafe: {relative}")
|
|
348
|
+
continue
|
|
349
|
+
if path.suffix.lower() not in TABULAR_RESULT_SUFFIXES:
|
|
350
|
+
continue
|
|
351
|
+
if not path.is_file():
|
|
352
|
+
errors.append(f"tabular result must be a regular file: {relative}")
|
|
353
|
+
continue
|
|
354
|
+
allowances = exceptions.get(relative.casefold(), set())
|
|
355
|
+
suffix = path.suffix.lower()
|
|
356
|
+
if flags["require_chinese_filenames"] and "filename" not in allowances:
|
|
357
|
+
if not has_chinese(path.stem):
|
|
358
|
+
errors.append(
|
|
359
|
+
f"tabular result filename must contain a descriptive Chinese name: {relative}"
|
|
360
|
+
)
|
|
361
|
+
|
|
362
|
+
if suffix in {".csv", ".tsv"}:
|
|
363
|
+
irrelevant = allowances & {"sheet_names"}
|
|
364
|
+
if irrelevant:
|
|
365
|
+
errors.append(
|
|
366
|
+
f"fixed-schema exception uses Excel-only scope for {relative}: sheet_names"
|
|
367
|
+
)
|
|
368
|
+
try:
|
|
369
|
+
has_bom, headers = delimited_header(
|
|
370
|
+
path,
|
|
371
|
+
"\t" if suffix == ".tsv" else ",",
|
|
372
|
+
allow_prescribed_encoding="encoding" in allowances,
|
|
373
|
+
)
|
|
374
|
+
except (OSError, UnicodeDecodeError, csv.Error) as error:
|
|
375
|
+
errors.append(f"could not read UTF-8 tabular result {relative}: {error}")
|
|
376
|
+
continue
|
|
377
|
+
if (
|
|
378
|
+
flags["require_utf8_sig_csv"]
|
|
379
|
+
and "encoding" not in allowances
|
|
380
|
+
and not has_bom
|
|
381
|
+
):
|
|
382
|
+
errors.append(f"CSV/TSV result must use UTF-8-SIG: {relative}")
|
|
383
|
+
if not headers:
|
|
384
|
+
errors.append(f"tabular result is missing a header row: {relative}")
|
|
385
|
+
elif "headers" not in allowances:
|
|
386
|
+
if any(not header for header in headers):
|
|
387
|
+
errors.append(f"tabular result contains an empty header: {relative}")
|
|
388
|
+
duplicate_headers = sorted(
|
|
389
|
+
{header for header in headers if header and headers.count(header) > 1}
|
|
390
|
+
)
|
|
391
|
+
if duplicate_headers:
|
|
392
|
+
errors.append(
|
|
393
|
+
f"tabular result contains duplicate headers in {relative}: "
|
|
394
|
+
+ ", ".join(duplicate_headers)
|
|
395
|
+
)
|
|
396
|
+
if flags["require_chinese_headers"]:
|
|
397
|
+
non_chinese = [header for header in headers if not has_chinese(header)]
|
|
398
|
+
if non_chinese:
|
|
399
|
+
errors.append(
|
|
400
|
+
f"tabular result headers must state their Chinese meaning in {relative}: "
|
|
401
|
+
+ ", ".join(non_chinese)
|
|
402
|
+
)
|
|
403
|
+
elif suffix == ".xlsx":
|
|
404
|
+
if "encoding" in allowances:
|
|
405
|
+
errors.append(
|
|
406
|
+
f"fixed-schema exception uses CSV-only scope for {relative}: encoding"
|
|
407
|
+
)
|
|
408
|
+
try:
|
|
409
|
+
sheets = xlsx_sheet_headers(path)
|
|
410
|
+
except (KeyError, OSError, ValueError, zipfile.BadZipFile, ElementTree.ParseError) as error:
|
|
411
|
+
errors.append(f"could not inspect XLSX result {relative}: {error}")
|
|
412
|
+
continue
|
|
413
|
+
if not sheets:
|
|
414
|
+
errors.append(f"XLSX result contains no worksheets: {relative}")
|
|
415
|
+
for sheet_name, headers in sheets:
|
|
416
|
+
if (
|
|
417
|
+
flags["require_chinese_sheet_names"]
|
|
418
|
+
and "sheet_names" not in allowances
|
|
419
|
+
and not has_chinese(sheet_name)
|
|
420
|
+
):
|
|
421
|
+
errors.append(
|
|
422
|
+
f"XLSX worksheet name must state its Chinese meaning in {relative}: {sheet_name or '<empty>'}"
|
|
423
|
+
)
|
|
424
|
+
if not headers:
|
|
425
|
+
errors.append(
|
|
426
|
+
f"XLSX worksheet is missing a header row in {relative}: {sheet_name or '<empty>'}"
|
|
427
|
+
)
|
|
428
|
+
elif flags["require_chinese_headers"] and "headers" not in allowances:
|
|
429
|
+
non_chinese = [header for header in headers if not has_chinese(header)]
|
|
430
|
+
if non_chinese:
|
|
431
|
+
errors.append(
|
|
432
|
+
f"XLSX headers must state their Chinese meaning in {relative}/{sheet_name}: "
|
|
433
|
+
+ ", ".join(non_chinese)
|
|
434
|
+
)
|
|
435
|
+
else:
|
|
436
|
+
if "encoding" in allowances:
|
|
437
|
+
errors.append(
|
|
438
|
+
f"fixed-schema exception uses CSV-only scope for {relative}: encoding"
|
|
439
|
+
)
|
|
440
|
+
required_scopes = set()
|
|
441
|
+
if flags["require_chinese_headers"]:
|
|
442
|
+
required_scopes.add("headers")
|
|
443
|
+
if flags["require_chinese_sheet_names"]:
|
|
444
|
+
required_scopes.add("sheet_names")
|
|
445
|
+
missing_scopes = sorted(required_scopes - allowances)
|
|
446
|
+
if missing_scopes:
|
|
447
|
+
errors.append(
|
|
448
|
+
f"legacy XLS result cannot be inspected safely; generate XLSX or register the prescribed schema scopes for {relative}: "
|
|
449
|
+
+ ", ".join(missing_scopes)
|
|
450
|
+
)
|
|
451
|
+
return errors
|
|
452
|
+
|
|
453
|
+
|
|
80
454
|
def expected_support_names(root: Path, ai_profile: dict[str, object], support_profile: dict[str, object]) -> set[str]:
|
|
81
455
|
names: set[str] = set()
|
|
82
456
|
for directory in ("code", "results", "figures"):
|
|
@@ -283,8 +657,14 @@ def main() -> None:
|
|
|
283
657
|
profile = load_profile(root)
|
|
284
658
|
paper_profile = profile["paper"]
|
|
285
659
|
support_profile = profile["support"]
|
|
660
|
+
result_artifact_profile = profile["result_artifacts"]
|
|
286
661
|
ai_profile = profile["ai"]
|
|
287
|
-
assert
|
|
662
|
+
assert (
|
|
663
|
+
isinstance(paper_profile, dict)
|
|
664
|
+
and isinstance(support_profile, dict)
|
|
665
|
+
and isinstance(result_artifact_profile, dict)
|
|
666
|
+
and isinstance(ai_profile, dict)
|
|
667
|
+
)
|
|
288
668
|
pdf_limit = numeric_limit(paper_profile, "max_pdf_mb")
|
|
289
669
|
page_limit = numeric_limit(paper_profile, "max_body_pages")
|
|
290
670
|
archive_limit = numeric_limit(support_profile, "max_archive_mb")
|
|
@@ -292,6 +672,7 @@ def main() -> None:
|
|
|
292
672
|
errors.append(str(error))
|
|
293
673
|
profile = {}
|
|
294
674
|
paper_profile = support_profile = ai_profile = {}
|
|
675
|
+
result_artifact_profile = None
|
|
295
676
|
pdf_limit = page_limit = archive_limit = None
|
|
296
677
|
|
|
297
678
|
for name in ("question", "code", "results", "figures", "paper"):
|
|
@@ -379,6 +760,8 @@ def main() -> None:
|
|
|
379
760
|
errors.append("Python compile failed: " + compile_result.stdout.strip())
|
|
380
761
|
warnings.extend(code_architecture_warnings(root, count))
|
|
381
762
|
warnings.extend(delivery_hygiene_warnings(root))
|
|
763
|
+
if result_artifact_profile is not None:
|
|
764
|
+
errors.extend(result_artifact_contract_errors(root, result_artifact_profile))
|
|
382
765
|
validate_evidence(root, count, errors, warnings)
|
|
383
766
|
try:
|
|
384
767
|
frozen_differences = evidence_differences(root)
|