framework-py 0.1.0.dev3__py3-none-any.whl → 0.1.0.dev4__py3-none-any.whl

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.
Files changed (40) hide show
  1. framework/__init__.py +5 -0
  2. framework/__main__.py +64 -5
  3. framework/_agents_md.py +210 -0
  4. framework/_assets/adopt/rules.json +161 -0
  5. framework/_assets/features/jupyter.json +39 -0
  6. framework/_assets/features/quarto.json +18 -0
  7. framework/_assets/features/quarto_manuscript.json +35 -0
  8. framework/_assets/features/quarto_slides.json +29 -0
  9. framework/_assets/features/renv.json +20 -0
  10. framework/_assets/features/targets.json +34 -0
  11. framework/_assets/features/uv.json +17 -0
  12. framework/_assets/schema/layer.v1.json +45 -7
  13. framework/_assets/schema/layers.v1.json +49 -7
  14. framework/_assets/schema/spec.v1.json +38 -7
  15. framework/_assets/sets/packages/tidyverse-analysis.json +42 -0
  16. framework/_assets/sets/skills/framework.json +25 -0
  17. framework/_assets/sets/skills/ggplot2.json +26 -0
  18. framework/_assets/workflows/jupyter.json +14 -0
  19. framework/_assets/workflows/quarto.json +14 -0
  20. framework/_assets/workflows/scripts.json +18 -0
  21. framework/_defaults_cache.py +47 -0
  22. framework/_paths.py +19 -9
  23. framework/adopt.py +365 -0
  24. framework/ai.py +13 -20
  25. framework/cloud.py +128 -13
  26. framework/create.py +395 -18
  27. framework/features.py +195 -0
  28. framework/hooks.py +69 -7
  29. framework/notebooks.py +9 -1
  30. framework/outputs.py +6 -1
  31. framework/quarto.py +77 -25
  32. framework/scaffold.py +50 -3
  33. framework/spec/check.py +31 -7
  34. framework/spec/merge.py +1 -0
  35. framework/spec/resolve.py +80 -6
  36. framework/templates/defaults.yml +0 -1
  37. {framework_py-0.1.0.dev3.dist-info → framework_py-0.1.0.dev4.dist-info}/METADATA +1 -1
  38. {framework_py-0.1.0.dev3.dist-info → framework_py-0.1.0.dev4.dist-info}/RECORD +40 -22
  39. {framework_py-0.1.0.dev3.dist-info → framework_py-0.1.0.dev4.dist-info}/WHEEL +0 -0
  40. {framework_py-0.1.0.dev3.dist-info → framework_py-0.1.0.dev4.dist-info}/licenses/LICENSE +0 -0
framework/create.py CHANGED
@@ -14,7 +14,7 @@ import shutil
14
14
  import subprocess
15
15
  import sys
16
16
  import tempfile
17
- from collections.abc import Mapping, Sequence
17
+ from collections.abc import Callable, Mapping, Sequence
18
18
  from datetime import date
19
19
  from importlib import resources
20
20
  from pathlib import Path
@@ -28,12 +28,23 @@ from framework.errors import FrameworkError
28
28
  from framework.quarto import quarto_generate_all
29
29
  from framework.spec.check import ASSISTANTS, spec_check
30
30
  from framework.spec.merge import SpecError
31
- from framework.spec.resolve import TYPES, author_normalize, spec_resolve
31
+ from framework.spec.resolve import (
32
+ TYPES,
33
+ author_normalize,
34
+ spec_core_files,
35
+ spec_resolve,
36
+ spec_settings_layout,
37
+ spec_tool_on,
38
+ )
32
39
 
33
40
  CHECKOUT_ALLOWLIST = frozenset({".git", ".github", ".framework", "README.md", "LICENSE"})
41
+ # Python's built-in workflow for these structures. Course and presentation
42
+ # are Quarto structures, and bare has no notebooks.
43
+ DEFAULT_JUPYTER = frozenset({"project", "project_sensitive"})
44
+ # "both" is RStudio plus VS Code. Python never writes an .Rproj.
45
+ WORKSPACE_IDES = frozenset({"vscode", "positron", "both"})
34
46
  FILE_LIKE = re.compile(r"\.(qmd|Rmd|R|md|py|ipynb)$")
35
47
  _TEMPLATE_VARS = ("project_name", "author", "author_email", "affiliation", "date")
36
- _SPLIT_TYPES = ("project", "project_sensitive")
37
48
  # Lines that ignore .env (or re-include it with a leading "!"), as in R.
38
49
  _ENV_RULE = re.compile(r"^(!?)/?(\*\*/)?(\.env\*?|\*\.env)$")
39
50
 
@@ -127,7 +138,9 @@ def _sections(spec: Mapping[str, Any]) -> dict[str, Any]:
127
138
  "seed_on_scaffold": scaffold.get("seed_on_scaffold", False),
128
139
  "seed": scaffold.get("seed", ""),
129
140
  "source_all_functions": scaffold.get("source_all_functions", True),
130
- "notebook_format": scaffold.get("notebook_format", "quarto"),
141
+ **({"workflow": scaffold["workflow"]} if scaffold.get("workflow") else {}),
142
+ "notebook_format": scaffold.get("notebook_format")
143
+ or ("quarto" if spec_tool_on(spec, "quarto") else "jupyter"),
131
144
  },
132
145
  "quarto": spec.get("quarto") or {},
133
146
  "connections": spec.get("connections") or {},
@@ -140,8 +153,10 @@ def _write_settings(root: Path, spec: Mapping[str, Any]) -> None:
140
153
  "project_name": spec["name"],
141
154
  "project_type": spec["type"],
142
155
  "language": spec["language"],
143
- "directories": spec.get("directories") or {},
144
156
  }
157
+ if spec.get("tools"):
158
+ main["tools"] = dict(spec["tools"])
159
+ main["directories"] = spec.get("directories") or {}
145
160
  extra = [
146
161
  {"key": key, "label": entry.get("label", key), "path": entry["path"]}
147
162
  for key, entry in (spec.get("extra_directories") or {}).items()
@@ -150,7 +165,7 @@ def _write_settings(root: Path, spec: Mapping[str, Any]) -> None:
150
165
  main["extra_directories"] = extra
151
166
  main["render_dirs"] = spec.get("render_dirs") or {}
152
167
 
153
- if spec["type"] in _SPLIT_TYPES:
168
+ if spec_settings_layout(spec) == "split":
154
169
  for section in ("author", "git", "ai", "scaffold", "quarto"):
155
170
  main[section] = f"settings/{section}.yml"
156
171
  _yaml.write(root / "settings" / f"{section}.yml", {section: sections[section]})
@@ -184,7 +199,7 @@ def _env_rule(line: str) -> bool | None:
184
199
  return None if match is None else not match.group(1)
185
200
 
186
201
 
187
- def ensure_secrets_ignored(root: Path) -> bool:
202
+ def ensure_secrets_ignored(root: Path, message: str = " Added .env to .gitignore") -> bool:
188
203
  """Make sure ``.gitignore`` ignores ``.env``. Returns whether a rule was added.
189
204
 
190
205
  The last rule that mentions ``.env`` decides, as in git, so a layer's
@@ -195,11 +210,54 @@ def ensure_secrets_ignored(root: Path) -> bool:
195
210
  rules = [rule for line in text.splitlines() if (rule := _env_rule(line)) is not None]
196
211
  if rules and rules[-1]:
197
212
  return False
213
+ _add_env_rule(path, text, message)
214
+ return True
215
+
216
+
217
+ def keep_env_out_of_git(root: Path) -> bool:
218
+ """Make sure git ignores ``.env`` before a secret goes in. Returns whether a rule was added.
219
+
220
+ In a git repository, git itself decides (``git check-ignore``), so global
221
+ and nested ignore files count. Without git, or outside a repository,
222
+ ``.gitignore`` is still created or extended, so a later ``git init`` picks
223
+ it up.
224
+
225
+ Raises:
226
+ FrameworkError: When git already tracks ``.env``.
227
+ """
228
+ message = "Added .env to .gitignore so the project token stays out of git"
229
+ if shutil.which("git") is not None:
230
+ tracked = subprocess.run(
231
+ ["git", "-C", str(root), "ls-files", "--error-unmatch", ".env"],
232
+ capture_output=True,
233
+ check=False,
234
+ )
235
+ if tracked.returncode == 0:
236
+ raise FrameworkError(
237
+ "git already tracks .env, so a project token written there would be "
238
+ "committed. Stop tracking it first:\n"
239
+ " git rm --cached .env\n git commit -m 'Stop tracking .env'"
240
+ )
241
+ result = subprocess.run(
242
+ ["git", "-C", str(root), "check-ignore", "-q", ".env"],
243
+ capture_output=True,
244
+ check=False,
245
+ )
246
+ if result.returncode == 0:
247
+ return False
248
+ if result.returncode == 1:
249
+ # A repository that doesn't ignore .env
250
+ path = root / ".gitignore"
251
+ _add_env_rule(path, path.read_text(encoding="utf-8") if path.exists() else "", message)
252
+ return True
253
+ return ensure_secrets_ignored(root, message)
254
+
255
+
256
+ def _add_env_rule(path: Path, text: str, message: str) -> None:
198
257
  if text and not text.endswith("\n"):
199
258
  text += "\n"
200
259
  path.write_text(text + "\n# Secrets (added by Framework)\n.env\n", encoding="utf-8")
201
- inform(" Added .env to .gitignore")
202
- return True
260
+ inform(message)
203
261
 
204
262
 
205
263
  def _scaffold_py(spec: Mapping[str, Any]) -> str:
@@ -351,7 +409,7 @@ def project_create(
351
409
  root.mkdir(parents=True, exist_ok=True)
352
410
  inform(f"Creating project in: {root}")
353
411
 
354
- bare = spec["type"] == "bare"
412
+ bare = not spec_core_files(spec)
355
413
  _create_directories(root, spec)
356
414
  _write_settings(root, spec)
357
415
  if not bare:
@@ -363,8 +421,8 @@ def project_create(
363
421
  if not bare:
364
422
  _write(root, "scaffold.py", _scaffold_py(spec))
365
423
  _write(root, "pyproject.toml", _pyproject(spec))
366
- ide = str((spec.get("scaffold") or {}).get("ide") or "")
367
- if not bare and re.search("vscode|positron", ide, re.IGNORECASE):
424
+ ide = str((spec.get("scaffold") or {}).get("ide") or "").lower()
425
+ if not bare and ide in WORKSPACE_IDES:
368
426
  _write(root, f"{kebab_case(spec['name'])}.code-workspace", _code_workspace())
369
427
  if spec["type"] == "presentation":
370
428
  _write(root, "presentation.qmd", _presentation(spec))
@@ -374,7 +432,7 @@ def project_create(
374
432
  content = entry["content"]
375
433
  _write(root, relative, fill_template(content, spec) if entry.get("template") else content)
376
434
 
377
- if not bare:
435
+ if not bare and spec_tool_on(spec, "quarto"):
378
436
  quarto_generate_all(
379
437
  root,
380
438
  spec["type"],
@@ -382,6 +440,7 @@ def project_create(
382
440
  spec.get("quarto") or {},
383
441
  spec.get("directories") or {},
384
442
  )
443
+ if not bare:
385
444
  db.ensure_db(root)
386
445
  _record(root, spec)
387
446
 
@@ -511,8 +570,19 @@ def new(
511
570
  location: str | Path | None = None,
512
571
  type: str | None = None,
513
572
  *,
573
+ workflow: str | None = None,
574
+ tools: Mapping[str, bool] | Sequence[str] | None = None,
575
+ package_sets: Sequence[str] = (),
576
+ skill_sets: Sequence[str] = (),
577
+ blueprint: str | None = None,
578
+ structure: str | None = None,
579
+ skills: Sequence[str] = (),
580
+ sensitive: bool | None = None,
581
+ ai: bool | Mapping[str, Any] | None = None,
582
+ git: bool | None = None,
514
583
  key: str | None = None,
515
584
  interactive: bool | None = None,
585
+ offline: bool = False,
516
586
  ) -> Path:
517
587
  """Create a new Python project with your defaults.
518
588
 
@@ -520,12 +590,47 @@ def new(
520
590
  name: Project name. Asked for when interactive.
521
591
  location: The project folder to create. Asked for when interactive.
522
592
  type: project, project_sensitive, course, presentation, or bare. When
523
- left out, it is asked for interactively and is ``bare`` otherwise,
524
- as in R's ``new()``.
593
+ you are logged in to Framework Cloud, every choice is resolved there:
594
+ a type is its system blueprint (``framework/<type>``), and with no
595
+ choices at all the project starts from your defaults. When not logged
596
+ in, a missing type is asked for interactively and is ``bare``
597
+ otherwise, as in R's ``new()``.
598
+ workflow: How notebooks are written: ``"jupyter"`` (``.ipynb``, with Quarto kept
599
+ for rendering and publishing), ``"quarto"`` (``.qmd``), or ``"scripts"`` (no
600
+ notebooks). Default: ``"jupyter"`` for project and project_sensitive, and the
601
+ structure's own setup for the others (Quarto for course and presentation).
602
+ tools: Tools to turn on, as a list of ids such as ``["jupyter"]``, or a map of id to
603
+ true or false, which can also turn off a default such as Quarto. A tool another
604
+ one needs is turned on too, with a message. Default: the type's tools (uv, and
605
+ Quarto for every type but bare). See [`tools_available()`](ref:tools_available).
606
+ package_sets: Package sets to add. Offline, a bundled set; with ``blueprint`` or
607
+ ``structure``, any handle on Framework Cloud.
608
+ skill_sets: Skill sets to add, such as ``["framework"]``. They replace the type's
609
+ default skills; a sensitive project keeps framework-sensitive-data.
610
+ blueprint: A Framework Cloud blueprint handle, such as ``"framework/project"`` or
611
+ ``"ada/lab"``. With ``blueprint`` or ``structure``, the choices are resolved by the
612
+ cloud (you must be logged in with [`cloud_login()`](ref:cloud_login)), the project
613
+ is built from the layers it returns, and then it is registered there and gets a
614
+ project token in ``.env``. Cannot be combined with ``type``.
615
+ structure: A Framework Cloud structure handle, such as ``"framework/course"``. It
616
+ replaces the blueprint's structure.
617
+ skills: Skill handles to add on Framework Cloud. Needs ``blueprint`` or
618
+ ``structure``.
619
+ sensitive: Turn the sensitive-data setting on or off. Needs ``blueprint`` or
620
+ ``structure``; offline, use ``type="project_sensitive"``.
621
+ ai: Turn AI assistants on or off, or a map such as
622
+ ``{"enabled": True, "assistants": {"claude": True}}``. Needs ``blueprint`` or
623
+ ``structure``.
624
+ git: Turn git on or off. Needs ``blueprint`` or ``structure``.
525
625
  key: A Framework Cloud project token. The project's definition (its
526
626
  layers) is fetched from the cloud, and the token is saved in the
527
627
  new project's ``.env`` for publishing and the ledger.
528
628
  interactive: Whether to prompt. Default: whether stdin is a terminal.
629
+ offline: Build from Framework's built-in defaults without contacting Framework Cloud.
630
+ When you are logged in and pass no choices, ``new()`` resolves your defaults on
631
+ the cloud and caches them. If the cloud can't be reached, it builds from that
632
+ cache and says so. With no cache it asks first, or, when not interactive, stops
633
+ unless ``offline`` is True. It never falls back silently.
529
634
 
530
635
  Returns:
531
636
  The project folder.
@@ -533,6 +638,25 @@ def new(
533
638
  interactive = sys.stdin.isatty() if interactive is None else interactive
534
639
  if key is not None:
535
640
  return _new_from_cloud(key, location, interactive)
641
+ cloud_choices = blueprint is not None or structure is not None
642
+ if cloud_choices and type is not None:
643
+ raise FrameworkError("Pass type, or blueprint and structure, not both")
644
+ if not cloud_choices:
645
+ needs_cloud = [
646
+ name
647
+ for name, given in (
648
+ ("skills", bool(skills)),
649
+ ("sensitive", sensitive is not None),
650
+ ("ai", ai is not None),
651
+ ("git", git is not None),
652
+ )
653
+ if given
654
+ ]
655
+ if needs_cloud:
656
+ raise FrameworkError(
657
+ f"{', '.join(needs_cloud)} need a Framework Cloud blueprint or structure. "
658
+ "Pass blueprint= or structure=, or use type= for Framework's own structures."
659
+ )
536
660
  if name is None:
537
661
  if not interactive:
538
662
  raise FrameworkError("Project name is required in non-interactive mode")
@@ -544,6 +668,63 @@ def new(
544
668
  raise FrameworkError("Project location is required in non-interactive mode")
545
669
  suggested = Path("~") / "projects" / kebab_case(name)
546
670
  location = input(f"Project location [{suggested}]: ").strip() or suggested
671
+
672
+ def local(register: bool = True) -> Path:
673
+ return _new_local(
674
+ name, location, type, workflow, tools, package_sets, skill_sets, interactive, register
675
+ )
676
+
677
+ if cloud_choices:
678
+ body = _choices_body(
679
+ name,
680
+ blueprint,
681
+ structure,
682
+ workflow,
683
+ tools,
684
+ package_sets,
685
+ skill_sets,
686
+ skills,
687
+ sensitive,
688
+ ai,
689
+ git,
690
+ )
691
+ return _new_from_choices(name, location, body)
692
+ if offline:
693
+ return local(register=False)
694
+ signed_in = _signed_in()
695
+ if signed_in is None:
696
+ return local()
697
+ # Logged in: the cloud resolves every choice. A Framework type is its system blueprint.
698
+ if type is not None and type not in TYPES:
699
+ raise FrameworkError(f"Invalid project type. Must be one of: {', '.join(TYPES)}")
700
+ body = _choices_body(
701
+ name,
702
+ f"framework/{type}" if type else None,
703
+ None,
704
+ workflow,
705
+ tools,
706
+ package_sets,
707
+ skill_sets,
708
+ (),
709
+ None,
710
+ None,
711
+ None,
712
+ )
713
+ return _resolve_and_build(name, location, body, *signed_in, interactive, local)
714
+
715
+
716
+ def _new_local(
717
+ name: str,
718
+ location: str | Path,
719
+ type: str | None,
720
+ workflow: str | None,
721
+ tools: Mapping[str, bool] | Sequence[str] | None,
722
+ package_sets: Sequence[str],
723
+ skill_sets: Sequence[str],
724
+ interactive: bool,
725
+ register: bool = True,
726
+ ) -> Path:
727
+ """Build from Framework's built-in defaults and your local settings."""
547
728
  if type is None:
548
729
  if interactive:
549
730
  choices = ", ".join(TYPES)
@@ -553,22 +734,218 @@ def new(
553
734
  if type not in TYPES:
554
735
  raise FrameworkError(f"Invalid project type. Must be one of: {', '.join(TYPES)}")
555
736
 
737
+ from framework.features import definition_layers, workflow_layers
738
+
739
+ if workflow is None and type in DEFAULT_JUPYTER:
740
+ workflow = "jupyter"
556
741
  layers: Sequence[Any] = [
742
+ # The workflow first, so tools chosen here win
743
+ *(workflow_layers(workflow) if workflow else []),
744
+ *definition_layers(tools or (), package_sets, skill_sets),
557
745
  {"kind": "user", "key": "settings-catalog", "layer": catalog_layer(type)},
558
746
  {"kind": "user", "layer": user_layer(type)},
559
747
  {"kind": "project", "layer": {"type": type, "language": "python"}},
560
748
  ]
561
749
  spec = spec_resolve(layers, name).spec
750
+ if skill_sets:
751
+ _replace_default_skills(spec, type, layers)
562
752
  spec["source"] = {"origin": "python"}
563
753
  inform(f"Creating {type} project: {name}")
564
754
  root = project_create(spec, location)
565
- if type != "bare":
755
+ if register and type != "bare":
566
756
  from framework.cloud import register_project
567
757
 
568
- register_project(root, name, type)
758
+ register_project(root, name, type, spec, package_sets=package_sets, skill_sets=skill_sets)
759
+ return root
760
+
761
+
762
+ def _signed_in() -> tuple[str, str] | None:
763
+ """The cloud server and your token, or None when you are not logged in."""
764
+ from framework.cloud import CloudError, cloud_server, cloud_token
765
+
766
+ try:
767
+ server = cloud_server().url
768
+ except CloudError:
769
+ return None
770
+ token = cloud_token(server)
771
+ return None if token is None else (server, token)
772
+
773
+
774
+ def _resolve_and_build(
775
+ name: str,
776
+ location: str | Path,
777
+ body: dict[str, Any],
778
+ server: str,
779
+ token: str,
780
+ interactive: bool,
781
+ local: Callable[[], Path],
782
+ ) -> Path:
783
+ """Resolve the choices on the cloud and build the project.
784
+
785
+ With no choices, the result is your defaults, which are cached for offline
786
+ use. Offline, the cache is used for those. Anything else asks, or stops
787
+ when not interactive, before building from the built-ins.
788
+ """
789
+ from framework._defaults_cache import read_cached_defaults, write_cached_defaults
790
+ from framework.cloud import CloudOfflineError, _MissingEndpointError, host, resolve_choices
791
+
792
+ if Path(location).expanduser().exists():
793
+ raise FrameworkError(f"Project directory already exists: {Path(location).expanduser()}")
794
+ defaults_only = set(body) <= {"name", "language"}
795
+ try:
796
+ envelope, revision = resolve_choices(body, token, server)
797
+ except _MissingEndpointError:
798
+ problem = (
799
+ f"{host(server)} doesn't resolve projects yet, so this project would use "
800
+ "Framework's built-in defaults."
801
+ )
802
+ _confirm_built_ins(problem, interactive)
803
+ return local()
804
+ except CloudOfflineError as error:
805
+ cached = read_cached_defaults(server, "python") if defaults_only else None
806
+ if cached is None:
807
+ what = (
808
+ "your Framework Cloud defaults aren't cached yet"
809
+ if defaults_only
810
+ else "these choices need Framework Cloud to resolve them"
811
+ )
812
+ _confirm_built_ins(f"Can't reach {host(server)}, and {what}.\n{error}", interactive)
813
+ return local()
814
+ inform(f"Using your Framework Cloud defaults from {str(cached['fetched_at'])[:10]}")
815
+ envelope = cached["envelope"]
816
+ else:
817
+ if defaults_only:
818
+ inform(f"Starting from your defaults on {host(server)}")
819
+ write_cached_defaults(server, "python", envelope, revision)
820
+ return _build_and_register(name, location, envelope, body, server, token)
821
+
822
+
823
+ def _confirm_built_ins(problem: str, interactive: bool) -> None:
824
+ """Ask before building from the built-ins instead of what the cloud would resolve.
825
+
826
+ Raises:
827
+ FrameworkError: When the answer is no, or when not interactive.
828
+ """
829
+ if not interactive:
830
+ raise FrameworkError(
831
+ f"{problem}\nPass offline=True to build from Framework's built-in defaults instead."
832
+ )
833
+ print(problem, file=sys.stderr)
834
+ answer = input("Build from Framework's built-in defaults instead? [y/N] ").strip().lower()
835
+ if answer not in ("y", "yes"):
836
+ raise FrameworkError("Cancelled. Nothing was created.")
837
+ inform("Building from Framework's built-in defaults")
838
+
839
+
840
+ def _choices_body(
841
+ name: str,
842
+ blueprint: str | None,
843
+ structure: str | None,
844
+ workflow: str | None,
845
+ tools: Mapping[str, bool] | Sequence[str] | None,
846
+ package_sets: Sequence[str],
847
+ skill_sets: Sequence[str],
848
+ skills: Sequence[str],
849
+ sensitive: bool | None,
850
+ ai: bool | Mapping[str, Any] | None,
851
+ git: bool | None,
852
+ ) -> dict[str, Any]:
853
+ """The body for the cloud's resolve and create endpoints.
854
+
855
+ Framework's tools get what they require added here, with a message, so
856
+ the cloud's strict check never rejects the request.
857
+ """
858
+ from framework.features import _tools, resolve_tools
859
+
860
+ choices = dict(tools) if isinstance(tools, Mapping) else dict.fromkeys(tools or (), True)
861
+ off = [t for t, on in choices.items() if on is False]
862
+ known = [t for t, on in choices.items() if on and t in _tools()]
863
+ for tool in resolve_tools(known, off):
864
+ choices.setdefault(tool, True)
865
+ body: dict[str, Any] = {"name": name, "language": "python"}
866
+ if blueprint is not None:
867
+ body["blueprint"] = blueprint
868
+ if structure is not None:
869
+ body["structure"] = structure
870
+ if workflow is not None:
871
+ body["workflow"] = workflow
872
+ if choices:
873
+ body["tools"] = choices
874
+ for field, values in (
875
+ ("package_sets", package_sets),
876
+ ("skill_sets", skill_sets),
877
+ ("skills", skills),
878
+ ):
879
+ if values:
880
+ # A bare id names one of Framework's own, as offline
881
+ body[field] = [v if "/" in v or field == "skills" else f"framework/{v}" for v in values]
882
+ settings = {
883
+ k: v for k, v in (("sensitive", sensitive), ("git", git), ("ai", ai)) if v is not None
884
+ }
885
+ if settings:
886
+ body["settings"] = settings
887
+ return body
888
+
889
+
890
+ def _new_from_choices(name: str, location: str | Path, body: dict[str, Any]) -> Path:
891
+ """Resolve choices on the cloud, build the project, then register it there."""
892
+ from framework.cloud import _require_token, cloud_server, host, resolve_choices
893
+
894
+ server = cloud_server().url
895
+ token = _require_token(server)
896
+ if Path(location).expanduser().exists():
897
+ raise FrameworkError(f"Project directory already exists: {Path(location).expanduser()}")
898
+ inform(f"Resolving the project's pieces on {host(server)}")
899
+ envelope, _ = resolve_choices(body, token, server)
900
+ return _build_and_register(name, location, envelope, body, server, token)
901
+
902
+
903
+ def _build_and_register(
904
+ name: str,
905
+ location: str | Path,
906
+ envelope: Mapping[str, Any],
907
+ body: Mapping[str, Any],
908
+ server: str,
909
+ token: str,
910
+ ) -> Path:
911
+ """Build from a resolved envelope, then register the project on the cloud."""
912
+ from framework.cloud import CloudError, api, host, write_project_token
913
+
914
+ spec = spec_resolve(envelope.get("layers") or [], name, envelope.get("author")).spec
915
+ spec["source"] = envelope.get("source") or {"origin": "cloud"}
916
+ root = project_create(spec, location)
917
+ try:
918
+ created = api("/api/v2/projects", token, server, method="POST", body=body)
919
+ except CloudError as error:
920
+ inform(f"Cloud project registration skipped: {error}")
921
+ return root
922
+ inform(f"[ok] Registered on {host(server)}: {created.get('slug')}")
923
+ if spec_core_files(spec) and created.get("token"):
924
+ write_project_token(root, str(created["token"]), server)
569
925
  return root
570
926
 
571
927
 
928
+ def _replace_default_skills(spec: dict[str, Any], type: str, layers: Sequence[Any]) -> None:
929
+ """Chosen skill sets replace the type's default skills, as in R.
930
+
931
+ A sensitive project keeps framework-sensitive-data.
932
+ """
933
+ from framework.spec.resolve import package_defaults
934
+
935
+ chosen = {
936
+ name
937
+ for entry in layers
938
+ if str(entry.get("key", "")).startswith("framework/skills-")
939
+ for name in (entry["layer"].get("skills") or {})
940
+ }
941
+ defaults = set(package_defaults(type)["skills"]) - {"framework-sensitive-data"}
942
+ spec["skills"] = {
943
+ name: value
944
+ for name, value in spec["skills"].items()
945
+ if name not in defaults or name in chosen
946
+ }
947
+
948
+
572
949
  def _new_from_cloud(key: str, location: str | Path | None, interactive: bool) -> Path:
573
950
  from framework.cloud import fetch_layers, write_project_token
574
951
 
@@ -584,7 +961,7 @@ def _new_from_cloud(key: str, location: str | Path | None, interactive: bool) ->
584
961
  spec = resolved.spec
585
962
  spec["source"] = envelope.get("source") or {"origin": "cloud"}
586
963
  root = project_create(spec, location)
587
- if spec["type"] != "bare":
964
+ if spec_core_files(spec):
588
965
  write_project_token(root, key, server)
589
966
  inform(f"Project ready at {root}")
590
967
  return root