@elvis1513/auto-coding-skill 4.1.6 → 4.1.9

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.
@@ -25,7 +25,8 @@ from pathlib import Path
25
25
  from typing import Iterator, Optional, List
26
26
 
27
27
  from core import APError, ensure_git_repo, copy_tree, run, load_yaml, find_config, run_shell, http_get_status, require_yaml
28
- from scaffold_templates import scaffold_groups, templates_for
28
+ from install_integrity import verify_managed_install
29
+ from scaffold_templates import MANAGED_FRAMEWORK_DOCS, scaffold_groups, templates_for
29
30
 
30
31
 
31
32
  _JENKINS_CRUMB_CACHE: dict[str, dict[str, str]] = {}
@@ -46,7 +47,7 @@ _RECOMMENDED_FINAL_TOTAL_SECONDS = 180.0
46
47
  _WORKFLOW_MIGRATION_POLICY = Path("data/policies/workflow-migrations-v1.json")
47
48
  _FALLBACK_WORKFLOW_MIGRATION_POLICY = {
48
49
  "schema_version": 1,
49
- "managed_versions": {"agents": "4.1.6", "engineering": "4.1.6"},
50
+ "managed_versions": {"agents": "4.1.9", "engineering": "4.1.9"},
50
51
  "known_official_engineering_body_sha256": [
51
52
  "d1306cc626e8baf8c83c953b760fd771066de2bf125168eca3a7b7d6ff2b87a2",
52
53
  "305931c6edef770033a4f1970b00e5fb1c1728351856a173dbfa497daf563021",
@@ -620,6 +621,332 @@ def _initialize_engineering_defaults(path: Path, repo: Path) -> None:
620
621
  path.write_text(updated, encoding="utf-8")
621
622
 
622
623
 
624
+ def _mapping(value: object) -> dict:
625
+ return value if isinstance(value, dict) else {}
626
+
627
+
628
+ def _string_list(value: object) -> list[str]:
629
+ if not isinstance(value, list):
630
+ return []
631
+ return [item.strip() for item in value if isinstance(item, str) and item.strip()]
632
+
633
+
634
+ def _copy_scalar_path(source: dict, target: dict, path: tuple[str, ...]) -> None:
635
+ current: object = source
636
+ for key in path:
637
+ if not isinstance(current, dict) or key not in current:
638
+ return
639
+ current = current[key]
640
+ destination = target
641
+ for key in path[:-1]:
642
+ destination = destination[key]
643
+ expected = destination[path[-1]]
644
+ compatible = (
645
+ (isinstance(expected, bool) and isinstance(current, bool))
646
+ or (isinstance(expected, str) and isinstance(current, str))
647
+ or (
648
+ isinstance(expected, (int, float))
649
+ and not isinstance(expected, bool)
650
+ and isinstance(current, (int, float))
651
+ and not isinstance(current, bool)
652
+ )
653
+ )
654
+ if compatible:
655
+ destination[path[-1]] = current
656
+
657
+
658
+ def _normalize_validation_routes(value: object) -> list[dict]:
659
+ routes: list[dict] = []
660
+ if not isinstance(value, list):
661
+ return routes
662
+ for raw in value:
663
+ if not isinstance(raw, dict):
664
+ continue
665
+ route: dict = {}
666
+ name = _text(raw.get("name"))
667
+ paths = _string_list(raw.get("paths"))
668
+ commands = [_command_name(item) for item in _string_list(raw.get("commands"))]
669
+ commands = [item for item in commands if item]
670
+ if name:
671
+ route["name"] = name
672
+ if paths:
673
+ route["paths"] = paths
674
+ exclude = _string_list(raw.get("exclude"))
675
+ if exclude:
676
+ route["exclude"] = exclude
677
+ if commands:
678
+ route["commands"] = commands
679
+ timeout = raw.get("timeout_seconds")
680
+ if isinstance(timeout, (int, float)) and not isinstance(timeout, bool) and timeout > 0:
681
+ route["timeout_seconds"] = timeout
682
+ if paths and commands:
683
+ routes.append(route)
684
+ return routes
685
+
686
+
687
+ def _normalize_risk_rules(value: object) -> list[dict]:
688
+ rules: list[dict] = []
689
+ if not isinstance(value, list):
690
+ return rules
691
+ for raw in value:
692
+ if not isinstance(raw, dict):
693
+ continue
694
+ rule: dict = {}
695
+ name = _text(raw.get("name"))
696
+ paths = _string_list(raw.get("paths"))
697
+ if name:
698
+ rule["name"] = name
699
+ if paths:
700
+ rule["paths"] = paths
701
+ profile = _text(raw.get("profile")).lower()
702
+ if profile in _WORKFLOW_PROFILES - {"auto"}:
703
+ rule["profile"] = profile
704
+ for key in ["review", "design"]:
705
+ value_text = _text(raw.get(key)).lower()
706
+ if value_text in {"required", "true", "yes", "false", "no"}:
707
+ rule[key] = value_text
708
+ if paths:
709
+ rules.append(rule)
710
+ return rules
711
+
712
+
713
+ def _normalize_layer_rules(value: object) -> list[dict]:
714
+ rules: list[dict] = []
715
+ if not isinstance(value, list):
716
+ return rules
717
+ for raw in value:
718
+ if not isinstance(raw, dict):
719
+ continue
720
+ paths = _string_list(raw.get("paths"))
721
+ forbidden = _string_list(raw.get("forbidden_imports"))
722
+ if not paths or not forbidden:
723
+ continue
724
+ rule = {"paths": paths, "forbidden_imports": forbidden}
725
+ name = _text(raw.get("name"))
726
+ if name:
727
+ rule = {"name": name, **rule}
728
+ rules.append(rule)
729
+ return rules
730
+
731
+
732
+ def _converged_engineering_document(repo: Path, template_path: Path) -> str:
733
+ template_cfg, template_body = _read_frontmatter_markdown(template_path)
734
+ engineering = repo / "docs" / "ENGINEERING.md"
735
+ current_cfg: dict = {}
736
+ if engineering.exists():
737
+ try:
738
+ current_cfg, _ = _read_frontmatter_markdown(engineering)
739
+ except Exception:
740
+ # Initialization is an authoritative reset. Malformed legacy policy
741
+ # must not prevent the current schema from taking effect.
742
+ current_cfg = {}
743
+
744
+ converged = json.loads(json.dumps(template_cfg))
745
+ preserve_scalar_paths = [
746
+ ("project", "name"),
747
+ ("project", "repo_root"),
748
+ ("project", "stack"),
749
+ ("access", "project", "frontend", "url"),
750
+ ("access", "project", "frontend", "username"),
751
+ ("access", "project", "frontend", "password"),
752
+ ("access", "project", "backend", "url"),
753
+ ("access", "project", "backend", "username"),
754
+ ("access", "project", "backend", "password"),
755
+ ("access", "jenkins", "frontend", "url"),
756
+ ("access", "jenkins", "frontend", "username"),
757
+ ("access", "jenkins", "frontend", "password"),
758
+ ("access", "jenkins", "backend", "url"),
759
+ ("access", "jenkins", "backend", "username"),
760
+ ("access", "jenkins", "backend", "password"),
761
+ ("access", "gitlab", "url"),
762
+ ("access", "gitlab", "username"),
763
+ ("access", "gitlab", "password"),
764
+ ("access", "nexus", "frontend", "url"),
765
+ ("access", "nexus", "frontend", "username"),
766
+ ("access", "nexus", "frontend", "password"),
767
+ ("concurrency", "base_ref"),
768
+ ("concurrency", "target_branch"),
769
+ ("concurrency", "branch_prefix"),
770
+ ("concurrency", "worktree_root"),
771
+ ("concurrency", "cleanup_merged"),
772
+ ("concurrency", "delete_remote_branch"),
773
+ ("validation", "max_command_seconds"),
774
+ ("validation", "max_total_seconds"),
775
+ ("structure", "architecture_standard"),
776
+ ("docs", "api_docs_required"),
777
+ ]
778
+ for field_path in preserve_scalar_paths:
779
+ _copy_scalar_path(current_cfg, converged, field_path)
780
+
781
+ current_concurrency = _mapping(current_cfg.get("concurrency"))
782
+ isolation = _text(current_concurrency.get("isolation")).lower()
783
+ if isolation in {"adaptive", "worktree"}:
784
+ converged["concurrency"]["isolation"] = isolation
785
+ converged["concurrency"]["disposable_ignored"] = _string_list(
786
+ current_concurrency.get("disposable_ignored")
787
+ )
788
+
789
+ current_commands = _mapping(current_cfg.get("commands"))
790
+ current_validation = _mapping(current_cfg.get("validation"))
791
+ routes = _normalize_validation_routes(current_validation.get("routes"))
792
+ referenced_commands = {
793
+ command
794
+ for route in routes
795
+ for command in _string_list(route.get("commands"))
796
+ }
797
+ referenced_commands.add("project_fast")
798
+ commands = {
799
+ str(name): value.strip()
800
+ for name, value in current_commands.items()
801
+ if name in referenced_commands and isinstance(name, str) and isinstance(value, str) and value.strip()
802
+ }
803
+ inferred = _inferred_gate_commands(repo)
804
+ if not commands.get("project_fast") and inferred.get("project_fast"):
805
+ commands["project_fast"] = inferred["project_fast"]
806
+ converged["commands"].update(commands)
807
+
808
+ converged["validation"]["routes"] = routes
809
+ converged["risk"]["rules"] = _normalize_risk_rules(
810
+ _mapping(current_cfg.get("risk")).get("rules")
811
+ )
812
+ current_structure = _mapping(current_cfg.get("structure"))
813
+ converged["structure"]["accepted_debt_paths"] = _string_list(
814
+ current_structure.get("accepted_debt_paths")
815
+ )
816
+ current_layers = _mapping(current_structure.get("layer_rules"))
817
+ converged["structure"]["layer_rules"]["rules"] = _normalize_layer_rules(
818
+ current_layers.get("rules")
819
+ )
820
+
821
+ if not _text(_mapping(converged.get("project")).get("name")):
822
+ converged["project"]["name"] = repo.name
823
+ dumped = require_yaml().safe_dump(converged, allow_unicode=True, sort_keys=False).strip()
824
+ return f"---\n{dumped}\n---\n{template_body.lstrip()}"
825
+
826
+
827
+ _PROJECT_ARTIFACT_PATTERNS = (
828
+ "docs/architecture/*.md",
829
+ "docs/architecture/adr/*.md",
830
+ "docs/deployment/deploy-records/*.md",
831
+ "docs/design/*.md",
832
+ "docs/interfaces/*.md",
833
+ "docs/reviews/*.md",
834
+ )
835
+
836
+
837
+ def _is_allowed_project_doc(rel: Path) -> bool:
838
+ return any(rel.match(pattern) for pattern in _PROJECT_ARTIFACT_PATTERNS)
839
+
840
+
841
+ def cmd_project_converge(args: argparse.Namespace) -> None:
842
+ repo = Path(args.repo).resolve()
843
+ template = _skill_root() / "data" / "templates" / "ENGINEERING.md"
844
+ engineering = repo / "docs" / "ENGINEERING.md"
845
+ output = _converged_engineering_document(repo, template)
846
+ current = engineering.read_text(encoding="utf-8") if engineering.exists() else ""
847
+ changed = not bool(current)
848
+ if current:
849
+ try:
850
+ current_cfg, current_body = _parse_frontmatter_markdown_text(current, engineering)
851
+ output_cfg, output_body = _parse_frontmatter_markdown_text(output, engineering)
852
+ changed = current_cfg != output_cfg or current_body != output_body
853
+ except Exception:
854
+ changed = True
855
+ actions: list[dict] = []
856
+ version = _text(_mapping(_read_frontmatter_markdown(template)[0].get("workflow")).get("skill_version")) or "current"
857
+
858
+ def archive_previous(source_path: Path, content: str, label: str) -> None:
859
+ archive_root = repo / ".agents" / "archive" / "auto-coding-skill" / version
860
+ archive = archive_root / source_path.relative_to(repo)
861
+ if archive.exists() and archive.read_text(encoding="utf-8") != content:
862
+ digest = hashlib.sha256(content.encode("utf-8")).hexdigest()[:12]
863
+ archive = archive.with_name(f"{archive.stem}-{digest}{archive.suffix}")
864
+ if archive.exists():
865
+ return
866
+ actions.append({"action": "archive", "path": _repo_rel(repo, archive), "detail": label})
867
+ if args.write:
868
+ archive.parent.mkdir(parents=True, exist_ok=True)
869
+ archive.write_text(content, encoding="utf-8")
870
+
871
+ def archive_extra(source_path: Path, label: str) -> None:
872
+ content = source_path.read_bytes()
873
+ archive_root = repo / ".agents" / "archive" / "auto-coding-skill" / version
874
+ archive = archive_root / source_path.relative_to(repo)
875
+ if archive.exists() and archive.read_bytes() != content:
876
+ digest = hashlib.sha256(content).hexdigest()[:12]
877
+ archive = archive.with_name(f"{archive.stem}-{digest}{archive.suffix}")
878
+ if not archive.exists():
879
+ actions.append({"action": "archive", "path": _repo_rel(repo, archive), "detail": label})
880
+ if args.write:
881
+ archive.parent.mkdir(parents=True, exist_ok=True)
882
+ archive.write_bytes(content)
883
+
884
+ if changed and current:
885
+ archive_header = (
886
+ f"# Archived ENGINEERING.md before auto-coding-skill {version}\n\n"
887
+ "Historical and non-authoritative. Do not use this file as workflow policy.\n\n---\n\n"
888
+ )
889
+ archive_previous(engineering, archive_header + current, "previous project configuration")
890
+ if changed:
891
+ actions.append({
892
+ "action": "create" if not current else "replace",
893
+ "path": "docs/ENGINEERING.md",
894
+ })
895
+ if args.write:
896
+ engineering.parent.mkdir(parents=True, exist_ok=True)
897
+ engineering.write_text(output, encoding="utf-8")
898
+
899
+ for rel, canonical in sorted(templates_for("all").items()):
900
+ target = repo / rel
901
+ existing = target.read_text(encoding="utf-8") if target.exists() else ""
902
+ managed = rel in MANAGED_FRAMEWORK_DOCS
903
+ if existing and (not managed or existing == canonical):
904
+ continue
905
+ if existing:
906
+ archive_previous(target, existing, "previous managed documentation template")
907
+ actions.append({"action": "create" if not existing else "replace", "path": rel})
908
+ if args.write:
909
+ target.parent.mkdir(parents=True, exist_ok=True)
910
+ target.write_text(canonical, encoding="utf-8")
911
+
912
+ allowed_docs = {
913
+ Path("docs/ENGINEERING.md"),
914
+ Path("docs/tools/autopipeline/ap.py"),
915
+ *(Path(rel) for rel in templates_for("all")),
916
+ }
917
+ docs_root = repo / "docs"
918
+ if docs_root.exists():
919
+ for candidate in sorted(docs_root.rglob("*")):
920
+ if not candidate.is_file() and not candidate.is_symlink():
921
+ continue
922
+ rel = candidate.relative_to(repo)
923
+ if rel in allowed_docs or _is_allowed_project_doc(rel):
924
+ continue
925
+ archive_extra(candidate, "removed from the exact docs framework")
926
+ actions.append({"action": "delete", "path": rel.as_posix()})
927
+ if args.write:
928
+ candidate.unlink()
929
+ if args.write:
930
+ for directory in sorted(
931
+ (item for item in docs_root.rglob("*") if item.is_dir()),
932
+ key=lambda item: len(item.parts),
933
+ reverse=True,
934
+ ):
935
+ try:
936
+ directory.rmdir()
937
+ except OSError:
938
+ pass
939
+
940
+ result = {"changed": bool(actions), "mode": "write" if args.write else "plan", "actions": actions}
941
+ if args.json:
942
+ print(json.dumps(result, ensure_ascii=False, indent=2))
943
+ return
944
+ for action in actions:
945
+ print(f"[project-converge] {action['action']}: {action['path']}")
946
+ if not actions:
947
+ print("[project-converge] OK: already current")
948
+
949
+
623
950
  def _migrate_fast_development_defaults(cfg: dict, repo: Path) -> list[str]:
624
951
  changed: list[str] = []
625
952
 
@@ -633,8 +960,8 @@ def _migrate_fast_development_defaults(cfg: dict, repo: Path) -> list[str]:
633
960
  if _text(workflow_cfg.get("completion")).lower() != "push":
634
961
  workflow_cfg["completion"] = "push"
635
962
  changed.append("workflow.completion")
636
- if _text(workflow_cfg.get("skill_version")) != "4.1.6":
637
- workflow_cfg["skill_version"] = "4.1.6"
963
+ if _text(workflow_cfg.get("skill_version")) != "4.1.9":
964
+ workflow_cfg["skill_version"] = "4.1.9"
638
965
  changed.append("workflow.skill_version")
639
966
 
640
967
  commands_cfg = cfg.setdefault("commands", {})
@@ -947,16 +1274,16 @@ def cmd_upgrade(args: argparse.Namespace) -> None:
947
1274
  if current_agents:
948
1275
  archive_dir = repo / "docs" / "archive" / "workflow"
949
1276
  archive_header = (
950
- "# Archived AGENTS.md before auto-coding-skill 4.1.6\n\n"
1277
+ "# Archived AGENTS.md before auto-coding-skill 4.1.9\n\n"
951
1278
  "This file is historical and non-authoritative. The root AGENTS.md is fully managed.\n"
952
1279
  "Move any still-current project facts into docs/ENGINEERING.md or docs/project/,\n"
953
1280
  "without copying workflow rules back into the root AGENTS.md.\n\n---\n\n"
954
1281
  )
955
1282
  archive_content = archive_header + current_agents
956
- archive = archive_dir / "AGENTS.pre-4.1.6.md"
1283
+ archive = archive_dir / "AGENTS.pre-4.1.9.md"
957
1284
  if archive.exists() and archive.read_text(encoding="utf-8") != archive_content:
958
1285
  digest = hashlib.sha256(current_agents.encode("utf-8")).hexdigest()[:12]
959
- archive = archive_dir / f"AGENTS.pre-4.1.6-{digest}.md"
1286
+ archive = archive_dir / f"AGENTS.pre-4.1.9-{digest}.md"
960
1287
  if not archive.exists():
961
1288
  add_action("policy", archive, "archive", "historical and non-authoritative")
962
1289
  if write:
@@ -5983,6 +6310,22 @@ def cmd_doctor(args: argparse.Namespace) -> None:
5983
6310
  if runtime_enabled and not str(runtime_cfg.get("docker_compose_file") or "").strip():
5984
6311
  validation_errors.append("runtime config is partially enabled but runtime.docker_compose_file is missing")
5985
6312
 
6313
+ version_match = re.fullmatch(r"([0-9]+)\.([0-9]+)\.([0-9]+)", skill_version)
6314
+ integrity_required = bool(
6315
+ version_match
6316
+ and tuple(int(part) for part in version_match.groups()) >= (4, 1, 9)
6317
+ )
6318
+ manifest_exists = (repo / ".agents" / "managed-install.json").is_file()
6319
+ if integrity_required or manifest_exists:
6320
+ integrity = verify_managed_install(
6321
+ repo,
6322
+ mode="project",
6323
+ expected_version=skill_version or None,
6324
+ )
6325
+ validation_errors.extend(
6326
+ f"install integrity: {issue}" for issue in integrity["errors"]
6327
+ )
6328
+
5986
6329
  missing.extend(validation_errors)
5987
6330
 
5988
6331
  if missing:
@@ -8552,6 +8895,11 @@ def main(argv: Optional[List[str]] = None) -> int:
8552
8895
  s.add_argument("--json", action="store_true")
8553
8896
  s.set_defaults(func=cmd_upgrade)
8554
8897
 
8898
+ s = sp.add_parser("project-converge", help=argparse.SUPPRESS)
8899
+ s.add_argument("--write", action="store_true")
8900
+ s.add_argument("--json", action="store_true")
8901
+ s.set_defaults(func=cmd_project_converge)
8902
+
8555
8903
  s = sp.add_parser("baseline")
8556
8904
  baseline_sp = s.add_subparsers(dest="baseline_cmd", required=True)
8557
8905
  b = baseline_sp.add_parser("init")