File size: 25,535 Bytes
a291258
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7bca22f
 
 
 
6ed86db
2735488
 
6ed86db
 
120333b
 
 
 
 
919ab88
 
 
 
 
 
 
 
 
 
21651a6
7d6704b
21651a6
7d6704b
21651a6
 
0854282
21651a6
 
d286817
 
66d036a
45deef7
 
40a0560
 
 
7d6704b
6cd6d32
 
 
 
 
 
 
 
 
 
 
 
 
93c739c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cb3cf77
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b4daf16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a291258
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7bca22f
 
6ed86db
 
 
 
 
 
 
7bca22f
 
 
 
 
 
 
 
 
 
919ab88
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7d6704b
 
 
 
 
 
 
0854282
 
 
 
d286817
 
 
 
 
66d036a
 
45deef7
 
40a0560
 
66d036a
 
 
 
 
 
 
 
45deef7
 
 
 
 
 
 
 
 
 
 
d286817
40a0560
 
 
 
 
 
 
 
 
 
7d6704b
0854282
 
7d6704b
 
 
 
 
 
 
 
 
 
 
 
6cd6d32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93c739c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cb3cf77
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7d6704b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
708f6fb
 
 
 
 
 
 
 
b4daf16
 
 
708f6fb
b4daf16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
708f6fb
 
 
 
 
 
 
 
b4daf16
 
 
 
 
 
 
 
a291258
 
 
 
 
7bca22f
a291258
 
 
 
 
 
 
b0ae303
120333b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b0ae303
120333b
a291258
120333b
 
a291258
 
 
 
 
 
 
 
 
 
 
b0ae303
a291258
 
 
b0ae303
a291258
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b4daf16
a291258
2d92d10
b4daf16
a291258
 
 
 
7d6704b
 
 
 
2be5985
e3007c4
93c739c
e6fa5d0
3c55827
c4cc86f
1b2531c
 
5618ed1
7d6704b
a291258
 
 
 
 
 
 
 
 
 
 
989ac73
680841f
 
 
989ac73
 
1b2531c
 
5618ed1
989ac73
 
2735488
 
 
 
 
 
 
 
 
a291258
 
 
 
 
 
 
 
 
 
 
 
7d6704b
cb3cf77
6cd6d32
93c739c
7d6704b
 
b4daf16
a291258
 
 
 
7bca22f
 
919ab88
a291258
 
 
 
 
7bca22f
 
 
 
a291258
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
#!/usr/bin/env python3
"""Sync repo publication files into the prepared Hugging Face bundles.

The upload step publishes ../hf_publish/{space,artifacts,model}; this helper
keeps those staging folders aligned with the same file groups checked by
validate_mirror_parity.py.
"""

from __future__ import annotations

import argparse
import importlib.util
import json
import shutil
from pathlib import Path


ROOT = Path(__file__).resolve().parents[1]
DEFAULT_HF_ROOT = ROOT.parent / "hf_publish"
PARITY_SCRIPT = ROOT / "scripts/validate_mirror_parity.py"
STALE_MIRROR_FILES = [
    "artifacts/scripts/omni/collect_qwen3_v4_publication_artifacts.py",
    "model/scripts/omni/collect_qwen3_v4_publication_artifacts.py",
]
STALE_MIRROR_DIRS = [
    # Large result bundles belong in the artifact dataset and model mirror.
    # A compact allowlist is copied back into the Space below for source links.
    "space/results",
]
GENERATED_REPORT_DATA_FILES = [
    # The parity validator rewrites this report, so it is synced after checks
    # rather than included in the self-referential hash parity file set.
    "mirror_parity.json",
]
ENHANCEMENT_MARKER = "docs/data/task_suite_enhancement_128.json"
ENHANCEMENT_CARD_BLOCK = """
## 128-Episode Enhancement Pack

The no-new-episode suite push is recorded in `TASK_SUITE_ENHANCEMENT_128.md`
and `docs/data/task_suite_enhancement_128.json`. It recommends
`multiscale_20s10_40s20_80s40`, hierarchical action/subtask targets,
label-normalized scoring, and compact raw-feature shards before adding more
episodes.
"""
TIER2_MARKER = "docs/data/task_suite_20.json"
TIER2_CARD_BLOCK = """
## Unified 20-Task Suite

The public-sample task surface is now one unified 20-task suite in
`TASK_SUITE_20.md` and `docs/data/task_suite_20.json`. Tasks 1-12 are the
original sample tasks; Tasks 13-20 reuse the same 20-frame windows, 5-frame
stride, feature manifest, chronological split, and minimal/neural head pattern.
The historical `tier2_task_suite` path is retained only for stable artifact
links to tasks 13-20. The unified radar chart is published as
`docs/assets/charts/unified_task_model_radar.svg` with values in
`docs/data/unified_task_model_radar.json`; the 9-method by 20-task completion
matrix is in `docs/data/task_method_20_result_matrix.json`, with the explicit
gap audit in `docs/data/task_method_20_gap_audit.json`. Split radars for
the one-episode baselines and selected 128-episode methods are published as
`docs/assets/charts/single_episode_task_model_radar.svg` and
`docs/assets/charts/episode128_task_model_radar.svg`.
"""
READER_MAP_MARKER = "docs/data/public_reader_map.json"
READER_MAP_ARTIFACT_ROW = (
    "| Choose the right public surface | `PUBLIC_READER_MAP.md`, "
    "`docs/data/public_reader_map.json` |"
)
READER_MAP_CARD_BLOCK = """
## Public Surface Map

Use `PUBLIC_READER_MAP.md` and `docs/data/public_reader_map.json` to choose
between the GitHub repo, GitHub Pages dashboard, HF Space, artifact dataset,
baseline model repo, Qwen3/Cosmos model repos, and release-health checks without
losing the full evidence trail.
"""
XPERIENCE128_MARKER = "docs/data/xperience10m_128_episode_feature_index.json"
XPERIENCE128_ARTIFACT_ROW = (
    "| Trace the 128-episode source and feature map | "
    "`XPERIENCE10M_128_EPISODE_FEATURE_INDEX.md`, "
    "`docs/data/xperience10m_128_episode_feature_index.json` |"
)
XPERIENCE128_CARD_BLOCK = """
## 128-Episode Source and Feature Index

The selected 128-episode split is linked back to the official gated
`ropedia-ai/xperience-10m` episode tree in
`XPERIENCE10M_128_EPISODE_FEATURE_INDEX.md` and
`docs/data/xperience10m_128_episode_feature_index.json`. The public mirrors
carry only public-safe processed artifacts: selection files, inspected
manifests, dense multiscale window rows, metadata feature matrices, and result
summaries.
"""
LANGUAGE_VERSIONS_MARKER = "docs/data/language_versions.json"
LANGUAGE_VERSIONS_ROW = (
    "| Read the project in 8 languages | `README.md`, `README.zh.md`, "
    "`README.es.md`, `README.fr.md`, `README.de.md`, `README.ja.md`, "
    "`README.ko.md`, `README.pt.md`, `docs/data/language_versions.json` |"
)
LANGUAGE_VERSIONS_CARD_BLOCK = """
## Multilingual Entry Points

The canonical repo README now has eight public reader entry points: English,
Chinese, Spanish, French, German, Japanese, Korean, and Portuguese. The
machine-readable language map is in `docs/data/language_versions.json`; each
Hugging Face mirror carries the same translated README files so readers can
move between GitHub, the dashboard, the Space, the artifact dataset, and model
cards without losing the evidence trail.
"""
QWEN_COMPARISON_MARKER = "docs/data/qwen3_v5_v6_comparison.json"
QWEN_COMPARISON_ROW = (
    "| Compare Qwen3 v5/v6 diagnostic branches | "
    "`docs/data/qwen3_v5_v6_comparison.json` |"
)
QWEN_ARTIFACT_OLD_BULLET = """- A current verified Qwen3-Omni strict-label v3 held-out package for the
  selected 96/16/16 episode split, with 100.00% JSON validity and weak
  action/subtask quality documented as the next error-analysis target."""
QWEN_ARTIFACT_CURRENT_BULLET = """- The latest verified Qwen3-Omni LoRA v6 diagnostic package for the selected
  96/16/16 episode split includes 34,269 exported windows, 4,032 held-out test
  predictions, 99.90% JSON validity, and public-safe metrics/predictions."""
README_QWEN_OLD_PARAGRAPH = """The current verified diagnostic package uses the same selected split and 8-GPU
training path, records validation loss over 512 validation windows, and keeps
the held-out test split sealed for final evaluation. The next pass should keep
this package contract while tightening JSON decoding, target formatting, and
action/subtask error analysis."""
README_QWEN_CURRENT_PARAGRAPH = """The latest verified diagnostic package uses the same selected split and 8-GPU
training path, includes the full held-out evaluation with 4,032 predictions and
99.90% JSON validity, and keeps raw data plus full Qwen weights out of the
public repos. The next pass should keep this package contract while improving
action/subtask target quality and error analysis."""


def load_parity_module():
    spec = importlib.util.spec_from_file_location("validate_mirror_parity", PARITY_SCRIPT)
    if spec is None or spec.loader is None:
        raise SystemExit(f"Could not load {PARITY_SCRIPT}")
    module = importlib.util.module_from_spec(spec)
    spec.loader.exec_module(module)
    return module


def copy_file(src: Path, destinations: list[Path], *, dry_run: bool) -> list[dict]:
    records = []
    if not src.is_file():
        raise SystemExit(f"Missing source file: {src}")
    for dst in destinations:
        records.append({"source": src.relative_to(ROOT).as_posix(), "dest": dst.as_posix()})
        if dry_run:
            continue
        dst.parent.mkdir(parents=True, exist_ok=True)
        shutil.copy2(src, dst)
    return records


def parse_args() -> argparse.Namespace:
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("--hf-root", type=Path, default=DEFAULT_HF_ROOT)
    parser.add_argument("--dry-run", action="store_true")
    parser.add_argument("--json", action="store_true", help="print machine-readable copy records")
    return parser.parse_args()


def prune_stale_files(hf_root: Path, *, dry_run: bool) -> list[str]:
    removed = []
    for relative_path in STALE_MIRROR_DIRS:
        path = hf_root / relative_path
        if not path.exists():
            continue
        removed.append(path.as_posix())
        if not dry_run:
            shutil.rmtree(path)
    for relative_path in STALE_MIRROR_FILES:
        path = hf_root / relative_path
        if not path.exists():
            continue
        removed.append(path.as_posix())
        if not dry_run:
            path.unlink()
    return removed


def ensure_enhancement_card_links(hf_root: Path, *, dry_run: bool) -> list[str]:
    updated = []
    for relative_path in ("artifacts/README.md", "model/README.md"):
        path = hf_root / relative_path
        if not path.exists():
            continue
        text = path.read_text(encoding="utf-8")
        if ENHANCEMENT_MARKER in text:
            continue
        insert_before = "\n## Dataset Boundary" if relative_path.startswith("artifacts/") else "\n## Start Here"
        if insert_before in text:
            text = text.replace(insert_before, ENHANCEMENT_CARD_BLOCK + insert_before, 1)
        else:
            text = text.rstrip() + "\n" + ENHANCEMENT_CARD_BLOCK
        updated.append(relative_path)
        if not dry_run:
            path.write_text(text, encoding="utf-8")
    return updated


def ensure_tier2_card_links(hf_root: Path, *, dry_run: bool) -> list[str]:
    updated = []
    for relative_path in ("space/README.md", "artifacts/README.md", "model/README.md"):
        path = hf_root / relative_path
        if not path.exists():
            continue
        text = path.read_text(encoding="utf-8")
        text = text.replace(
            "original sample tasks; tasks 13-20 reuse",
            "original sample tasks; Tasks 13-20 reuse",
        )
        if "docs/data/unified_task_model_radar.json" not in text:
            text = text.replace(
                "links to tasks 13-20.\n",
                "links to tasks 13-20. The unified radar chart is published as\n"
                "`docs/assets/charts/unified_task_model_radar.svg` with values in\n"
                "`docs/data/unified_task_model_radar.json`; the 9-method by\n"
                "20-task completion matrix is in\n"
                "`docs/data/task_method_20_result_matrix.json`, with the explicit\n"
                "gap audit in `docs/data/task_method_20_gap_audit.json`. Split radars are in\n"
                "`docs/assets/charts/single_episode_task_model_radar.svg` and\n"
                "`docs/assets/charts/episode128_task_model_radar.svg`.\n",
            )
        if (
            "docs/data/unified_task_model_radar.json" in text
            and "docs/data/task_method_20_result_matrix.json" not in text
        ):
            text = text.replace(
                "`docs/data/unified_task_model_radar.json`.",
                "`docs/data/unified_task_model_radar.json`; the 9-method by 20-task\n"
                "completion matrix is in `docs/data/task_method_20_result_matrix.json`,\n"
                "with the explicit gap audit in `docs/data/task_method_20_gap_audit.json`.",
            )
        if (
            "docs/data/task_method_20_result_matrix.json" in text
            and "docs/data/task_method_20_gap_audit.json" not in text
        ):
            text = text.replace(
                "`docs/data/task_method_20_result_matrix.json`.",
                "`docs/data/task_method_20_result_matrix.json`, with the explicit\n"
                "gap audit in `docs/data/task_method_20_gap_audit.json`.",
            )
        if (
            "docs/data/task_method_20_result_matrix.json" in text
            and "docs/assets/charts/single_episode_task_model_radar.svg" not in text
        ):
            text = text.replace(
                "`docs/data/task_method_20_result_matrix.json`.",
                "`docs/data/task_method_20_result_matrix.json`. Split radars are in\n"
                "`docs/assets/charts/single_episode_task_model_radar.svg` and\n"
                "`docs/assets/charts/episode128_task_model_radar.svg`.",
            )
        if TIER2_MARKER in text:
            if not dry_run:
                path.write_text(text, encoding="utf-8")
            continue
        insert_before = "\n## Dataset Boundary" if relative_path.startswith("artifacts/") else "\n## Start Here"
        if insert_before in text:
            text = text.replace(insert_before, TIER2_CARD_BLOCK + insert_before, 1)
        else:
            text = text.rstrip() + "\n" + TIER2_CARD_BLOCK
        updated.append(relative_path)
        if not dry_run:
            path.write_text(text, encoding="utf-8")
    return updated


def ensure_reader_map_card_links(hf_root: Path, *, dry_run: bool) -> list[str]:
    updated = []
    artifacts_readme = hf_root / "artifacts/README.md"
    if not artifacts_readme.exists():
        return updated
    text = artifacts_readme.read_text(encoding="utf-8")
    original = text
    if READER_MAP_ARTIFACT_ROW not in text:
        table_anchor = "| Reader goal | Artifact |\n| --- | --- |\n"
        if table_anchor in text:
            text = text.replace(table_anchor, table_anchor + READER_MAP_ARTIFACT_ROW + "\n", 1)
        else:
            text = text.rstrip() + "\n\n" + READER_MAP_ARTIFACT_ROW + "\n"
    if "## Public Surface Map" not in text:
        insert_before = "\n## Dataset Boundary"
        if insert_before in text:
            text = text.replace(insert_before, READER_MAP_CARD_BLOCK + insert_before, 1)
        else:
            text = text.rstrip() + "\n" + READER_MAP_CARD_BLOCK
    if text != original:
        updated.append("artifacts/README.md")
        if not dry_run:
            artifacts_readme.write_text(text, encoding="utf-8")
    return updated


def ensure_xperience128_card_links(hf_root: Path, *, dry_run: bool) -> list[str]:
    updated = []
    artifacts_readme = hf_root / "artifacts/README.md"
    if not artifacts_readme.exists():
        return updated
    text = artifacts_readme.read_text(encoding="utf-8")
    original = text
    if XPERIENCE128_ARTIFACT_ROW not in text:
        table_anchor = "| Reader goal | Artifact |\n| --- | --- |\n"
        if table_anchor in text:
            text = text.replace(table_anchor, table_anchor + XPERIENCE128_ARTIFACT_ROW + "\n", 1)
        else:
            text = text.rstrip() + "\n\n" + XPERIENCE128_ARTIFACT_ROW + "\n"
    if XPERIENCE128_MARKER not in text:
        insert_before = "\n## Dataset Boundary"
        if insert_before in text:
            text = text.replace(insert_before, XPERIENCE128_CARD_BLOCK + insert_before, 1)
        else:
            text = text.rstrip() + "\n" + XPERIENCE128_CARD_BLOCK
    if text != original:
        updated.append("artifacts/README.md")
        if not dry_run:
            artifacts_readme.write_text(text, encoding="utf-8")
    return updated


def ensure_language_card_links(hf_root: Path, *, dry_run: bool) -> list[str]:
    updated = []
    artifacts_readme = hf_root / "artifacts/README.md"
    if not artifacts_readme.exists():
        return updated
    text = artifacts_readme.read_text(encoding="utf-8")
    original = text
    if LANGUAGE_VERSIONS_ROW not in text:
        table_anchor = "| Reader goal | Artifact |\n| --- | --- |\n"
        if table_anchor in text:
            text = text.replace(table_anchor, table_anchor + LANGUAGE_VERSIONS_ROW + "\n", 1)
        else:
            text = text.rstrip() + "\n\n" + LANGUAGE_VERSIONS_ROW + "\n"
    if "## Multilingual Entry Points" not in text:
        insert_before = "\n## Dataset Boundary"
        if insert_before in text:
            text = text.replace(insert_before, LANGUAGE_VERSIONS_CARD_BLOCK + insert_before, 1)
        else:
            text = text.rstrip() + "\n" + LANGUAGE_VERSIONS_CARD_BLOCK
    if text != original:
        updated.append("artifacts/README.md")
        if not dry_run:
            artifacts_readme.write_text(text, encoding="utf-8")
    return updated


def split_hf_frontmatter(text: str) -> tuple[str, str]:
    lines = text.splitlines()
    if not lines or lines[0].strip() != "---":
        return "", text
    for idx in range(1, len(lines)):
        if lines[idx].strip() == "---":
            frontmatter = "\n".join(lines[: idx + 1]).rstrip() + "\n\n"
            body = "\n".join(lines[idx + 1 :]).lstrip()
            return frontmatter, body
    return "", text


def refresh_project_readme_cards(hf_root: Path, *, dry_run: bool) -> list[str]:
    """Keep HF project cards aligned with the current repo README body."""

    project_readme = (ROOT / "README.md").read_text(encoding="utf-8").rstrip() + "\n"
    updated = []
    for relative_path in ("space/PROJECT_README.md", "artifacts/PROJECT_README.md", "model/PROJECT_README.md"):
        path = hf_root / relative_path
        if not path.exists():
            continue
        original = path.read_text(encoding="utf-8")
        if original == project_readme:
            continue
        updated.append(relative_path)
        if not dry_run:
            path.write_text(project_readme, encoding="utf-8")

    for relative_path in ("space/README.md", "model/README.md"):
        path = hf_root / relative_path
        if not path.exists():
            continue
        original = path.read_text(encoding="utf-8")
        frontmatter, _body = split_hf_frontmatter(original)
        refreshed = frontmatter + project_readme
        if original == refreshed:
            continue
        updated.append(relative_path)
        if not dry_run:
            path.write_text(refreshed, encoding="utf-8")
    return updated


def read_current_scaleup_line() -> str | None:
    """Return the legacy Markdown scale-up row when the README still has one.

    The current public README uses an HTML table for the research overview, so
    mirrored full project cards no longer need a standalone Markdown row. Keep
    this compatibility hook for older compact cards only.
    """

    for line in (ROOT / "README.md").read_text(encoding="utf-8").splitlines():
        if line.startswith("| Scale-up |"):
            return line
    return None


def ensure_current_qwen_card_links(hf_root: Path, *, dry_run: bool) -> list[str]:
    updated = []

    artifacts_readme = hf_root / "artifacts/README.md"
    if artifacts_readme.exists():
        text = artifacts_readme.read_text(encoding="utf-8")
        original = text
        if QWEN_COMPARISON_ROW not in text:
            anchor = "| Compare current versions and model groups | `docs/data/omni_model_comparison.json` |"
            text = text.replace(anchor, anchor + "\n" + QWEN_COMPARISON_ROW, 1)
        if QWEN_ARTIFACT_OLD_BULLET in text:
            text = text.replace(QWEN_ARTIFACT_OLD_BULLET, QWEN_ARTIFACT_CURRENT_BULLET, 1)
        if "99.90% JSON validity" not in text:
            text = text.rstrip() + "\n\n" + QWEN_ARTIFACT_CURRENT_BULLET + "\n"
        if QWEN_COMPARISON_MARKER not in text:
            text = text.rstrip() + f"\n\nQwen v5/v6 comparison: `{QWEN_COMPARISON_MARKER}`.\n"
        if text != original:
            updated.append("artifacts/README.md")
            if not dry_run:
                artifacts_readme.write_text(text, encoding="utf-8")

    scaleup_line = read_current_scaleup_line()
    for relative_path in ("model/README.md", "model/PROJECT_README.md"):
        path = hf_root / relative_path
        if not path.exists():
            continue
        original = path.read_text(encoding="utf-8")
        text = original
        if README_QWEN_OLD_PARAGRAPH in text:
            text = text.replace(README_QWEN_OLD_PARAGRAPH, README_QWEN_CURRENT_PARAGRAPH, 1)
        changed = text != original
        lines = text.splitlines()
        if scaleup_line:
            for idx, line in enumerate(lines):
                if line.startswith("| Scale-up |"):
                    if line != scaleup_line:
                        lines[idx] = scaleup_line
                        changed = True
                    break
        if changed:
            updated.append(relative_path)
            if not dry_run:
                path.write_text("\n".join(lines) + "\n", encoding="utf-8")

    return updated


def main() -> int:
    args = parse_args()
    hf_root = args.hf_root.expanduser().resolve()
    parity = load_parity_module()

    removed = prune_stale_files(hf_root, dry_run=args.dry_run)
    copied: list[dict] = []
    for filename in parity.DATA_FILES:
        src = ROOT / "docs/data" / filename
        copied += copy_file(
            src,
            [
                hf_root / "space/data" / filename,
                hf_root / "space/docs/data" / filename,
                hf_root / "artifacts/data" / filename,
                hf_root / "artifacts/docs/data" / filename,
                hf_root / "model/data" / filename,
                hf_root / "model/docs/data" / filename,
                hf_root / "model/metrics" / filename,
            ],
            dry_run=args.dry_run,
        )

    for filename in GENERATED_REPORT_DATA_FILES:
        src = ROOT / "docs/data" / filename
        copied += copy_file(
            src,
            [
                hf_root / "space/data" / filename,
                hf_root / "space/docs/data" / filename,
                hf_root / "artifacts/data" / filename,
                hf_root / "artifacts/docs/data" / filename,
                hf_root / "model/data" / filename,
                hf_root / "model/docs/data" / filename,
                hf_root / "model/metrics" / filename,
            ],
            dry_run=args.dry_run,
        )

    for filename in parity.ASSET_FILES:
        src = ROOT / "docs/assets" / filename
        copied += copy_file(
            src,
            [
                hf_root / "space/assets" / filename,
                hf_root / "space/docs/assets" / filename,
                hf_root / "artifacts/docs/assets" / filename,
                hf_root / "artifacts/assets" / filename,
                hf_root / "model/assets" / filename,
                hf_root / "model/docs/assets" / filename,
            ],
            dry_run=args.dry_run,
        )

    for filename in parity.SCRIPT_FILES:
        src = ROOT / "scripts" / filename
        copied += copy_file(
            src,
            [
                hf_root / "artifacts/scripts" / filename,
                hf_root / "model/scripts" / filename,
            ],
            dry_run=args.dry_run,
        )

    for filename in parity.WEBSITE_FILES:
        src = ROOT / "docs" / filename
        copied += copy_file(
            src,
            [
                hf_root / "space" / filename,
                hf_root / "artifacts" / filename,
                hf_root / "artifacts/docs" / filename,
                hf_root / "model" / filename,
                hf_root / "model/docs" / filename,
            ],
            dry_run=args.dry_run,
        )

    result_files = sorted(
        set(parity.RESULT_FILES)
        | set(parity.verified_public_result_files())
        | set(parity.tier2_result_files())
        | set(parity.a100_128_metadata_result_files())
        | set(parity.a100_128_raw20_result_files())
        | set(parity.xperience10m_128_data_feature_files())
        | set(parity.model_output_task_probe_result_files())
        | set(parity.qwen3_future_task_probe_result_files())
        | set(parity.qwen3_retrieval_task_probe_result_files())
        | set(parity.cosmos3_super_retrieval_task_probe_result_files())
        | set(parity.cosmos3_super_future_task_probe_result_files())
        | set(parity.cosmos3_super_interaction_text_task_probe_result_files())
    )
    for filename in result_files:
        src = ROOT / "results" / filename
        copied += copy_file(
            src,
            [
                hf_root / "artifacts/results" / filename,
                hf_root / "model/results" / filename,
            ],
            dry_run=args.dry_run,
        )

    space_result_files = sorted(
        set(parity.RESULT_FILES)
        | set(parity.tier2_result_files())
        | set(parity.model_output_task_probe_result_files())
        | set(parity.qwen3_future_task_probe_result_files())
        | set(parity.qwen3_retrieval_task_probe_result_files())
        | set(parity.cosmos3_super_retrieval_task_probe_result_files())
        | set(parity.cosmos3_super_future_task_probe_result_files())
        | set(parity.cosmos3_super_interaction_text_task_probe_result_files())
    )
    for filename in space_result_files:
        src = ROOT / "results" / filename
        copied += copy_file(
            src,
            [
                hf_root / "space/results" / filename,
            ],
            dry_run=args.dry_run,
        )

    for filename in parity.DOC_FILES:
        src = ROOT / filename
        copied += copy_file(
            src,
            [
                hf_root / "space" / filename,
                hf_root / "artifacts" / filename,
                hf_root / "model" / filename,
            ],
            dry_run=args.dry_run,
        )

    card_updates = refresh_project_readme_cards(hf_root, dry_run=args.dry_run)
    card_updates += ensure_language_card_links(hf_root, dry_run=args.dry_run)
    card_updates += ensure_reader_map_card_links(hf_root, dry_run=args.dry_run)
    card_updates += ensure_xperience128_card_links(hf_root, dry_run=args.dry_run)
    card_updates += ensure_enhancement_card_links(hf_root, dry_run=args.dry_run)
    card_updates += ensure_tier2_card_links(hf_root, dry_run=args.dry_run)
    card_updates += ensure_current_qwen_card_links(hf_root, dry_run=args.dry_run)
    summary = {
        "status": "dry_run" if args.dry_run else "synced",
        "hf_root": hf_root.as_posix(),
        "copy_count": len(copied),
        "removed_stale_count": len(removed),
        "removed_stale": removed,
        "card_updates": card_updates,
        "records": copied,
    }
    if args.json:
        print(json.dumps(summary, indent=2))
    else:
        print(
            f"{summary['status'].upper()}: copied {summary['copy_count']} files into {hf_root}; "
            f"removed {summary['removed_stale_count']} stale files"
        )
    return 0


if __name__ == "__main__":
    raise SystemExit(main())