Skip to content

Scaffold

scaffold

InitScaffoldTool — project scaffolding as an AXMTool.

InitScaffoldTool

Initialize a new Python project with best practices.

Registered as init_scaffold via axm.tools entry point.

Source code in packages/axm-init/src/axm_init/tools/scaffold.py
Python
 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
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
class InitScaffoldTool:
    """Initialize a new Python project with best practices.

    Registered as ``init_scaffold`` via axm.tools entry point.
    """

    @property
    def name(self) -> str:
        """Tool name used for MCP registration."""
        return "init_scaffold"

    @property
    def kinds(self) -> tuple[str, ...]:
        """Scaffold kinds this tool declares, in template order.

        The declared set is the tool's contract: every value is selectable
        through the ``kind`` input (MCP) and ``--kind`` (CLI), and each one
        routes either to a bundled template or the protocol scaffolder.
        """
        return SCAFFOLD_KINDS

    def _validate_inputs(
        self,
        kwargs: dict[str, object],
    ) -> (
        tuple[
            str,
            str | None,
            str,
            str,
            str,
            str,
            str,
            bool,
            bool,
            str | None,
            str | None,
            Framework,
        ]
        | ToolResult
    ):
        """Extract and validate inputs from kwargs.

        Returns a tuple of validated values or a ToolResult on error.
        """

        def _str(key: str, default: str = "") -> str:
            v = kwargs.get(key, default)
            return v if isinstance(v, str) else default

        def _opt_str(key: str) -> str | None:
            v = kwargs.get(key)
            return v if isinstance(v, str) else None

        path: str = _str("path", ".")
        name: str | None = _opt_str("name")
        org: str = _str("org")
        author: str = _str("author")
        email: str = _str("email")
        license_type: str = _str("license", "Apache-2.0")
        license_holder: str | None = _opt_str("license_holder")
        description: str = _str("description")
        private_raw = kwargs.get("private")
        if not isinstance(private_raw, bool):
            return ToolResult(
                success=False,
                error=f"'private' must be a boolean, got {type(private_raw).__name__}",
            )
        private: bool = private_raw
        workspace_raw = kwargs.get("workspace", False)
        if not isinstance(workspace_raw, bool):
            return ToolResult(
                success=False,
                error=(
                    f"'workspace' must be a boolean, got {type(workspace_raw).__name__}"
                ),
            )
        workspace: bool = workspace_raw
        member: str | None = _opt_str("member")

        if not org or not author or not email:
            return ToolResult(
                success=False,
                error="org, author, and email are required",
            )

        try:
            framework = Framework(_str("framework", Framework.PYTHON.value))
        except ValueError:
            valid = ", ".join(f.value for f in Framework)
            return ToolResult(
                success=False,
                error=f"Unknown framework '{_str('framework')}'. Valid: {valid}",
            )

        if workspace and member is not None:
            return ToolResult(
                success=False,
                error="'workspace' and 'member' are mutually exclusive",
            )

        return (
            path,
            name,
            org,
            author,
            email,
            license_type,
            description,
            private,
            workspace,
            member,
            license_holder,
            framework,
        )

    def _build_template_data(
        self,
        *,
        project_name: str,
        workspace: bool,
        description: str,
        meta: _ProjectMeta,
        license_holder: str | None,
        private: bool,
    ) -> dict[str, object]:
        """Build template data dict for workspace or standalone scaffold."""
        name_key = "workspace_name" if workspace else "package_name"
        default_desc = (
            "A modern Python workspace" if workspace else "A modern Python package"
        )
        return {
            name_key: project_name,
            "description": description or default_desc,
            "org": meta.org,
            "license": meta.license_type,
            "license_holder": license_holder or meta.org,
            "author_name": meta.author_name,
            "author_email": meta.author_email,
            "private": private,
            # Jinja has no date filter and copier exposes none, so a template
            # cannot compute this itself: supplied here so a scaffolded
            # wrangler.toml pins the Workers runtime current at creation time
            # rather than a date frozen in the template.
            "compatibility_date": date.today().isoformat(),
        }

    def execute(
        self,
        path: str = ".",
        *,
        name: str | None = None,
        org: str = "",
        author: str = "",
        email: str = "",
        license: str = "Apache-2.0",
        license_holder: str | None = None,
        description: str = "",
        # Safe default: removing one classifier is reversible; a PyPI upload is not.
        private: bool = True,
        workspace: bool = False,
        member: str | None = None,
        framework: str = Framework.PYTHON.value,
        kind: str | None = None,
        check_pypi: bool = False,
        json_output: bool = False,
        profile: str | None = None,
        domain: str | None = None,
        unit: str | None = None,
        protocols: list[dict[str, object]] | str | None = None,
        preview: bool = False,
    ) -> ToolResult:
        """Initialize a new Python project.

        Args:
            path: Path to initialize project.
            name: Project name (defaults to directory name).
            org: GitHub org or username.
            author: Author name.
            email: Author email.
            license: License type.
            license_holder: License holder (defaults to org).
            description: Project description.
            private: If True, prevent publication to PyPI.
            workspace: If True, scaffold a UV workspace.
            member: Member package name to scaffold inside a workspace.
            framework: Target framework (python, node, svelte).
            kind: Explicit scaffold kind — one of ``SCAFFOLD_KINDS``
                (standalone, workspace, member, paper, experiment,
                learning, protocol_unit, protocol).
            check_pypi: If True, check name availability on PyPI.
            json_output: If True, render the structured report.
            profile: Protocol profile to scaffold.
            domain: Protocol domain to scaffold.
            unit: Protocol unit to scaffold.
            protocols: Protocol definitions, as objects or a JSON string.
            preview: If True, report the planned protocol scaffold
                without writing it.

        Returns:
            ToolResult with created files list.
        """
        kwargs: dict[str, object] = {
            "path": path,
            "name": name,
            "org": org,
            "author": author,
            "email": email,
            "license": license,
            "license_holder": license_holder,
            "description": description,
            "private": private,
            "workspace": workspace,
            "member": member,
            "framework": framework,
            "kind": kind,
        }
        prepared = self._prepare_context(
            kwargs,
            protocol_options={
                "profile": profile,
                "domain": domain,
                "unit": unit,
                "protocols": protocols,
                "preview": preview,
            },
            check_pypi=check_pypi,
        )
        if isinstance(prepared, ToolResult):
            return _apply_json_output(prepared, json_output)

        try:
            result = (
                _route_protocol_request(prepared.protocol_request, prepared.target_path)
                or self._dispatch_kind(
                    prepared.kind,
                    target_path=prepared.target_path,
                    name=prepared.name,
                    description=prepared.description,
                    meta=prepared.meta,
                )
                or self._scaffold_from_templates(prepared)
            )
        except Exception as exc:
            result = ToolResult(success=False, error=str(exc))
        return _apply_json_output(result, json_output)

    def _prepare_context(
        self,
        kwargs: dict[str, object],
        *,
        protocol_options: dict[str, object],
        check_pypi: bool,
    ) -> _ScaffoldContext | ToolResult:
        """Validate every precondition, returning a context or the refusal."""
        if kwargs.get("kind") == "paper":
            return ToolResult(
                success=False,
                error="Paper scaffolding is owned by axm-lab; use paper_scaffold.",
            )
        validated = self._validate_inputs(kwargs)
        if isinstance(validated, ToolResult):
            return validated
        (
            path,
            name,
            org,
            author,
            email,
            license_type,
            description,
            private,
            workspace,
            member,
            license_holder,
            framework,
        ) = validated

        kind = _read_kind(kwargs)
        if kind_error := _unknown_kind_error(kind):
            return kind_error
        workspace, member = _apply_kind_flags(
            kind, workspace=workspace, member=member, name=name
        )

        learning_domain = (
            _opt_str_option(protocol_options, "domain") if kind == "learning" else None
        )
        protocol_request = prepare_protocol_request(
            profile=_opt_str_option(protocol_options, "profile"),
            domain=(
                None
                if kind == "learning"
                else _opt_str_option(protocol_options, "domain")
            ),
            unit=_opt_str_option(protocol_options, "unit"),
            protocols=_protocols_option(protocol_options),
            preview=bool(protocol_options.get("preview", False)),
            framework=framework,
        )
        if isinstance(protocol_request, str):
            return ToolResult(success=False, error=protocol_request)

        try:
            target_path = Path(path).resolve()
        except Exception as exc:  # pragma: no cover - defensive path resolution
            return ToolResult(success=False, error=str(exc))
        project_name = name or target_path.name
        if check_pypi:
            taken = _check_pypi_availability(project_name)
            if taken is not None:
                return taken

        return _ScaffoldContext(
            target_path=target_path,
            project_name=project_name,
            name=name,
            description=description,
            license_holder=license_holder,
            private=private,
            framework=framework,
            workspace=workspace,
            member=member,
            kind=kind,
            learning_domain=learning_domain,
            meta=_ProjectMeta(
                org=org,
                license_type=license_type,
                author_name=author,
                author_email=email,
            ),
            protocol_request=protocol_request,
        )

    def _scaffold_from_templates(self, ctx: _ScaffoldContext) -> ToolResult:
        """Route the member / workspace / standalone template cascade."""
        if ctx.member:
            return self._scaffold_member_with_profile(ctx, ctx.member)
        return self._scaffold_root(ctx)

    def _scaffold_member_with_profile(
        self, ctx: _ScaffoldContext, member: str
    ) -> ToolResult:
        """Scaffold a workspace member, registering its protocol profile if asked."""
        meta = ctx.meta
        member_result = self._scaffold_member(
            ctx.target_path,
            member,
            scaffold_data={
                "org": meta.org,
                "author_name": meta.author_name,
                "author_email": meta.author_email,
                "license": meta.license_type,
                "description": ctx.description,
            },
            license_holder=ctx.license_holder,
            private=ctx.private,
            learning=ctx.kind == "learning",
            learning_domain=ctx.learning_domain,
        )
        request = ctx.protocol_request
        if not member_result.success or request is None:
            return member_result
        member_root = ctx.target_path / "packages" / member
        register_protocol_profile(member_root, request.domain)
        member_data = dict(member_result.data or {})
        member_data.update(
            {
                "profile": request.profile,
                "mode": "member",
                "distribution": member,
                "root": str(member_root),
            }
        )
        return ToolResult(success=True, data=member_data, text=member_result.text)

    def _scaffold_root(self, ctx: _ScaffoldContext) -> ToolResult:
        """Render the workspace or standalone template at the target root."""
        from axm_init.adapters.copier import CopierAdapter, CopierConfig
        from axm_init.core.templates import (
            TemplateType,
            get_template_path,
            template_chain,
        )

        template_type = (
            TemplateType.LEARNING
            if ctx.kind == "learning"
            else TemplateType.WORKSPACE
            if ctx.workspace
            else TemplateType.STANDALONE
        )
        module_name = ctx.project_name.replace("-", "_")
        requested_learning_domain = ctx.learning_domain or module_name
        if template_type is TemplateType.LEARNING:
            declared_learning_domain(ctx.target_path, requested_learning_domain)
        template_data = self._build_template_data(
            project_name=ctx.project_name,
            workspace=ctx.workspace,
            description=ctx.description,
            meta=ctx.meta,
            license_holder=ctx.license_holder,
            private=ctx.private,
        )
        if template_type is TemplateType.LEARNING:
            template_data.update(
                {
                    "learning_mode": "standalone",
                    "domain": requested_learning_domain,
                }
            )
        copier = CopierAdapter()
        if template_type is TemplateType.LEARNING:
            layers = template_chain(
                template_type,
                ctx.framework,
                member=False,
                existing=(ctx.target_path / "pyproject.toml").is_file(),
            )
            result = copier.apply_chain(
                list(layers),
                ctx.target_path,
                template_data,
            )
        else:
            result = copier.copy(
                CopierConfig(
                    template_path=get_template_path(template_type, ctx.framework),
                    destination=ctx.target_path,
                    data=template_data,
                    trust_template=True,
                )
            )

        files = [str(f) for f in result.files_created]
        result_data: dict[str, object] = {
            "project_name": ctx.project_name,
            "template": template_type.value,
            "files": files,
        }
        request = ctx.protocol_request
        if result.success and template_type is TemplateType.LEARNING:
            metadata_path = ctx.target_path / "pyproject.toml"
            if metadata_path.is_file():
                register_learning_profile(
                    ctx.target_path,
                    requested_learning_domain,
                    module_name,
                )
            result_data.update(
                {
                    "profile": "learning",
                    "mode": "standalone",
                    "distribution": ctx.project_name,
                    "root": str(ctx.target_path),
                }
            )
        elif result.success and request is not None:
            register_protocol_profile(ctx.target_path, request.domain)
            result_data.update(
                {
                    "profile": request.profile,
                    "mode": "standalone",
                    "distribution": ctx.project_name,
                    "root": str(ctx.target_path),
                }
            )
        return ToolResult(
            success=result.success,
            data=result_data,
            text=(
                _render_scaffold_text(
                    label=ctx.project_name,
                    kind=template_type.value,
                    files=files,
                )
                if result.success
                else None
            ),
            error=None if result.success else result.message,
        )

    def _dispatch_kind(
        self,
        kind: str | None,
        *,
        target_path: Path,
        name: str | None,
        description: str,
        meta: _ProjectMeta,
    ) -> ToolResult | None:
        """Route the paper and experiment kinds.

        Returns ``None`` when *kind* is not one of them, so the caller falls
        through to the member / workspace / standalone cascade.
        """
        label = name or target_path.name
        if kind == "paper":
            return self._scaffold_paper(
                target_path,
                paper_name=label,
                meta=meta,
                description=description,
            )
        if kind == "experiment":
            return self._scaffold_experiment(
                target_path,
                experiment_name=label,
                description=description,
            )
        return None

    def _scaffold_paper(
        self,
        target_path: Path,
        *,
        paper_name: str,
        meta: _ProjectMeta,
        description: str,
    ) -> ToolResult:
        """Direct obsolete paper creation to the edition-aware Lab tool."""
        return ToolResult(
            success=False,
            error=(
                "Paper scaffolding is owned by axm-lab; use paper_scaffold "
                "with workspace, venue, year and slug."
            ),
        )

    def _scaffold_experiment(
        self, target_path: Path, *, experiment_name: str, description: str
    ) -> ToolResult:
        """Refuse retired scaffolding and direct callers to Lab's owned workflow."""
        return ToolResult(
            success=False,
            error=(
                "Experiment scaffolding is owned by axm-lab "
                "investigations/experiments 2.0; install axm-lab and use its "
                "experiment_scaffold tool with an investigation owner."
            ),
        )

    @staticmethod
    def _resolve_workspace_root(target_path: Path) -> Path | None:
        """Resolve workspace root from target path, or None if not in a workspace."""
        return resolve_workspace_root(target_path)

    def _scaffold_member(
        self,
        target_path: Path,
        member_name: str,
        *,
        scaffold_data: dict[str, str],
        license_holder: str | None = None,
        private: bool | None = None,
        learning: bool = False,
        learning_domain: str | None = None,
    ) -> ToolResult:
        """Scaffold a member sub-package inside an existing workspace.

        Args:
            target_path: Current directory (must be inside a workspace).
            member_name: Name of the new member package.
            scaffold_data: Template variables (org, author, email, etc.).
            license_holder: Explicit LICENSE holder; falls back to ``org``.
            private: Publication guard forwarded to Copier when provided.

        Returns:
            ToolResult with member scaffold results.
        """
        from axm_init.adapters.copier import CopierAdapter, CopierConfig
        from axm_init.adapters.workspace_patcher import patch_all
        from axm_init.core.templates import TemplateType, get_template_path
        from axm_init.scaffolding import (
            ScaffoldRequest,
            _finalize_provider,
            _provider_layers,
            load_provider,
        )

        workspace_root = self._resolve_workspace_root(target_path)
        if workspace_root is None:
            return ToolResult(success=False, error="Not inside a UV workspace")

        member_dir = workspace_root / "packages" / member_name
        module_name = member_name.replace("-", "_")
        requested_learning_domain = learning_domain or module_name
        reconcile_learning = False
        if member_dir.exists() and learning:
            existing_domain = declared_learning_domain(
                member_dir, requested_learning_domain
            )
            reconcile_learning = existing_domain == requested_learning_domain or (
                (member_dir / "pyproject.toml").is_file()
            )
        if member_dir.exists() and not reconcile_learning:
            return ToolResult(
                success=False,
                error=f"Member '{member_name}' already exists at {member_dir}",
            )

        recipe_path = member_dir / "src" / module_name / "recipe.py"
        recipe_bytes = (
            recipe_path.read_bytes()
            if reconcile_learning and recipe_path.is_file()
            else None
        )
        data = build_member_data(
            member_name,
            read_workspace_name(workspace_root),
            scaffold_data,
            license_holder=license_holder,
            private=private,
        )
        if learning:
            data.update(
                {
                    "package_name": member_name.replace("_", "-"),
                    "learning_mode": "standalone",
                    "domain": requested_learning_domain,
                }
            )

        copier_adapter = CopierAdapter()

        learning_request = ScaffoldRequest(
            "learning", member=True, existing=reconcile_learning
        )
        layers = _provider_layers(learning_request) if learning else None
        if layers is not None:
            result = copier_adapter.apply_chain(list(layers), member_dir, data)
        else:
            copier_config = CopierConfig(
                template_path=get_template_path(TemplateType.MEMBER),
                destination=member_dir,
                data=data,
                trust_template=True,
                overwrite=reconcile_learning,
            )
            result = copier_adapter.copy(copier_config)
        if recipe_bytes is not None:
            recipe_path.write_bytes(recipe_bytes)

        if not result.success:
            return ToolResult(
                success=False,
                error=result.message or "Member scaffold failed",
            )

        if layers is not None:
            _finalize_provider(
                load_provider("learning"), learning_request, member_dir, data
            )

        report = patch_all(workspace_root, member_name)

        files = [str(f) for f in result.files_created]
        result_data: dict[str, object] = {
            "member": member_name,
            "path": str(member_dir),
            "files": files,
            "patched_root_files": report.patched,
            "skipped_root_files": report.skipped,
            "failed_root_files": report.failed,
        }
        if learning:
            result_data.update(
                {
                    "profile": "learning",
                    "mode": "member",
                    "distribution": member_name,
                    "root": str(member_dir),
                }
            )
        return ToolResult(
            success=True,
            data=result_data,
            text=_render_scaffold_text(
                label=member_name,
                kind="learning" if learning else "member",
                files=files,
                path=str(member_dir),
                report=report,
            ),
        )
kinds property

Scaffold kinds this tool declares, in template order.

The declared set is the tool's contract: every value is selectable through the kind input (MCP) and --kind (CLI), and each one routes either to a bundled template or the protocol scaffolder.

name property

Tool name used for MCP registration.

execute(path='.', *, name=None, org='', author='', email='', license='Apache-2.0', license_holder=None, description='', private=True, workspace=False, member=None, framework=Framework.PYTHON.value, kind=None, check_pypi=False, json_output=False, profile=None, domain=None, unit=None, protocols=None, preview=False)

Initialize a new Python project.

Parameters:

Name Type Description Default
path str

Path to initialize project.

'.'
name str | None

Project name (defaults to directory name).

None
org str

GitHub org or username.

''
author str

Author name.

''
email str

Author email.

''
license str

License type.

'Apache-2.0'
license_holder str | None

License holder (defaults to org).

None
description str

Project description.

''
private bool

If True, prevent publication to PyPI.

True
workspace bool

If True, scaffold a UV workspace.

False
member str | None

Member package name to scaffold inside a workspace.

None
framework str

Target framework (python, node, svelte).

value
kind str | None

Explicit scaffold kind — one of SCAFFOLD_KINDS (standalone, workspace, member, paper, experiment, learning, protocol_unit, protocol).

None
check_pypi bool

If True, check name availability on PyPI.

False
json_output bool

If True, render the structured report.

False
profile str | None

Protocol profile to scaffold.

None
domain str | None

Protocol domain to scaffold.

None
unit str | None

Protocol unit to scaffold.

None
protocols list[dict[str, object]] | str | None

Protocol definitions, as objects or a JSON string.

None
preview bool

If True, report the planned protocol scaffold without writing it.

False

Returns:

Type Description
ToolResult

ToolResult with created files list.

Source code in packages/axm-init/src/axm_init/tools/scaffold.py
Python
def execute(
    self,
    path: str = ".",
    *,
    name: str | None = None,
    org: str = "",
    author: str = "",
    email: str = "",
    license: str = "Apache-2.0",
    license_holder: str | None = None,
    description: str = "",
    # Safe default: removing one classifier is reversible; a PyPI upload is not.
    private: bool = True,
    workspace: bool = False,
    member: str | None = None,
    framework: str = Framework.PYTHON.value,
    kind: str | None = None,
    check_pypi: bool = False,
    json_output: bool = False,
    profile: str | None = None,
    domain: str | None = None,
    unit: str | None = None,
    protocols: list[dict[str, object]] | str | None = None,
    preview: bool = False,
) -> ToolResult:
    """Initialize a new Python project.

    Args:
        path: Path to initialize project.
        name: Project name (defaults to directory name).
        org: GitHub org or username.
        author: Author name.
        email: Author email.
        license: License type.
        license_holder: License holder (defaults to org).
        description: Project description.
        private: If True, prevent publication to PyPI.
        workspace: If True, scaffold a UV workspace.
        member: Member package name to scaffold inside a workspace.
        framework: Target framework (python, node, svelte).
        kind: Explicit scaffold kind — one of ``SCAFFOLD_KINDS``
            (standalone, workspace, member, paper, experiment,
            learning, protocol_unit, protocol).
        check_pypi: If True, check name availability on PyPI.
        json_output: If True, render the structured report.
        profile: Protocol profile to scaffold.
        domain: Protocol domain to scaffold.
        unit: Protocol unit to scaffold.
        protocols: Protocol definitions, as objects or a JSON string.
        preview: If True, report the planned protocol scaffold
            without writing it.

    Returns:
        ToolResult with created files list.
    """
    kwargs: dict[str, object] = {
        "path": path,
        "name": name,
        "org": org,
        "author": author,
        "email": email,
        "license": license,
        "license_holder": license_holder,
        "description": description,
        "private": private,
        "workspace": workspace,
        "member": member,
        "framework": framework,
        "kind": kind,
    }
    prepared = self._prepare_context(
        kwargs,
        protocol_options={
            "profile": profile,
            "domain": domain,
            "unit": unit,
            "protocols": protocols,
            "preview": preview,
        },
        check_pypi=check_pypi,
    )
    if isinstance(prepared, ToolResult):
        return _apply_json_output(prepared, json_output)

    try:
        result = (
            _route_protocol_request(prepared.protocol_request, prepared.target_path)
            or self._dispatch_kind(
                prepared.kind,
                target_path=prepared.target_path,
                name=prepared.name,
                description=prepared.description,
                meta=prepared.meta,
            )
            or self._scaffold_from_templates(prepared)
        )
    except Exception as exc:
        result = ToolResult(success=False, error=str(exc))
    return _apply_json_output(result, json_output)

read_workspace_name(workspace_root)

Read the workspace name from pyproject.toml or fall back to dir name.

Source code in packages/axm-init/src/axm_init/core/scaffolder.py
Python
def read_workspace_name(workspace_root: Path) -> str:
    """Read the workspace name from ``pyproject.toml`` or fall back to dir name."""
    root_pyproject = workspace_root / "pyproject.toml"
    if root_pyproject.is_file():
        with open(root_pyproject, "rb") as f:
            root_data = tomllib.load(f)
        return str(root_data.get("project", {}).get("name", workspace_root.name))
    return workspace_root.name