workpeg 0.154.0__tar.gz → 0.155.0__tar.gz

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 (137) hide show
  1. {workpeg-0.154.0/src/workpeg.egg-info → workpeg-0.155.0}/PKG-INFO +1 -1
  2. {workpeg-0.154.0 → workpeg-0.155.0}/pyproject.toml +1 -1
  3. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/cli.py +35 -10
  4. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/project.py +26 -25
  5. workpeg-0.155.0/src/workpeg/starter.py +116 -0
  6. workpeg-0.155.0/src/workpeg/templates/agents/AGENTS.md +1042 -0
  7. workpeg-0.155.0/src/workpeg/templates/agents/CLAUDE.md +1 -0
  8. workpeg-0.155.0/src/workpeg/templates/project/README.md +27 -0
  9. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/templates/project/function/app/main.py +1 -1
  10. workpeg-0.155.0/src/workpeg/templates/starter/app_shell.py +23 -0
  11. workpeg-0.155.0/src/workpeg/templates/starter/components.py +108 -0
  12. workpeg-0.155.0/src/workpeg/templates/starter/main.py +78 -0
  13. workpeg-0.155.0/src/workpeg/templates/starter/pages/__init__.py +0 -0
  14. workpeg-0.155.0/src/workpeg/templates/starter/pages/customer.py +199 -0
  15. workpeg-0.155.0/src/workpeg/templates/starter/pages/customers.py +262 -0
  16. workpeg-0.155.0/src/workpeg/templates/starter/pages/home.py +45 -0
  17. workpeg-0.155.0/src/workpeg/templates/starter/pages/not_found.py +15 -0
  18. workpeg-0.155.0/src/workpeg/ui/create.py +93 -0
  19. {workpeg-0.154.0 → workpeg-0.155.0/src/workpeg.egg-info}/PKG-INFO +1 -1
  20. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg.egg-info/SOURCES.txt +12 -1
  21. workpeg-0.155.0/tests/test_agents_guide.py +267 -0
  22. {workpeg-0.154.0 → workpeg-0.155.0}/tests/test_project_create.py +64 -4
  23. workpeg-0.154.0/src/workpeg/templates/project/README.md +0 -20
  24. workpeg-0.154.0/src/workpeg/templates/project/ui/main.py +0 -15
  25. workpeg-0.154.0/src/workpeg/ui/create.py +0 -276
  26. {workpeg-0.154.0 → workpeg-0.155.0}/LICENSE +0 -0
  27. {workpeg-0.154.0 → workpeg-0.155.0}/MANIFEST.in +0 -0
  28. {workpeg-0.154.0 → workpeg-0.155.0}/README.md +0 -0
  29. {workpeg-0.154.0 → workpeg-0.155.0}/setup.cfg +0 -0
  30. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/__init__.py +0 -0
  31. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/auth.py +0 -0
  32. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/build.py +0 -0
  33. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/cdn.py +0 -0
  34. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/config.py +0 -0
  35. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/context.py +0 -0
  36. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/create_new.py +0 -0
  37. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/doctor.py +0 -0
  38. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/run.py +0 -0
  39. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/runtime.py +0 -0
  40. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/sandbox/__init__.py +0 -0
  41. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/sandbox/docker_driver.py +0 -0
  42. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/sandbox/driver.py +0 -0
  43. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/submit.py +0 -0
  44. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/templates/__init__.py +0 -0
  45. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/templates/functions/Dockerfile +0 -0
  46. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/templates/functions/LICENSE +0 -0
  47. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/templates/functions/README.md +0 -0
  48. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/templates/functions/app/__init__.py +0 -0
  49. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/templates/functions/app/main.py +0 -0
  50. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/templates/functions/requirements.txt +0 -0
  51. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/templates/project/function/Dockerfile +0 -0
  52. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/templates/project/function/app/__init__.py +0 -0
  53. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/templates/project/function/requirements.txt +0 -0
  54. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/templates/project/workpeg.json +0 -0
  55. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/terminal.py +0 -0
  56. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/__init__.py +0 -0
  57. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/actions.py +0 -0
  58. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/actions_manifest.py +0 -0
  59. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/app.py +0 -0
  60. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/build.py +0 -0
  61. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/calendar.py +0 -0
  62. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/compiler/__init__.py +0 -0
  63. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/compiler/ast_parser.py +0 -0
  64. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/compiler/ir.py +0 -0
  65. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/compiler/js_generator.py +0 -0
  66. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/dates.py +0 -0
  67. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/dev_refused_names.json +0 -0
  68. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/devmode.py +0 -0
  69. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/devserve.py +0 -0
  70. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/devsite.py +0 -0
  71. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/fake_cloud.py +0 -0
  72. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/minify.py +0 -0
  73. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/render_nodes.py +0 -0
  74. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/renderers_manifest.py +0 -0
  75. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/runtime/ai-concurrent-replies.md +0 -0
  76. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/runtime/ai-prompt-queue.md +0 -0
  77. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/runtime/ai-question-frame.md +0 -0
  78. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/runtime/ai-subagent-frame.md +0 -0
  79. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/runtime/ai.js +0 -0
  80. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/runtime/editor.js +0 -0
  81. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/runtime/fonts/OFL.txt +0 -0
  82. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/runtime/fonts/geist-italic-cyrillic-ext.af944491.woff2 +0 -0
  83. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/runtime/fonts/geist-italic-cyrillic.88be6946.woff2 +0 -0
  84. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/runtime/fonts/geist-italic-latin-ext.370a8962.woff2 +0 -0
  85. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/runtime/fonts/geist-italic-latin.7611b95c.woff2 +0 -0
  86. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/runtime/fonts/geist-italic-vietnamese.8dfcf303.woff2 +0 -0
  87. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/runtime/fonts/geist-normal-cyrillic-ext.b7a545bb.woff2 +0 -0
  88. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/runtime/fonts/geist-normal-cyrillic.6129fc85.woff2 +0 -0
  89. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/runtime/fonts/geist-normal-latin-ext.58a6b173.woff2 +0 -0
  90. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/runtime/fonts/geist-normal-latin.9b6f5ff4.woff2 +0 -0
  91. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/runtime/fonts/geist-normal-vietnamese.f689f638.woff2 +0 -0
  92. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/runtime/icons.css.gz +0 -0
  93. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/runtime/overlay.js +0 -0
  94. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/runtime/pegment.css +0 -0
  95. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/runtime/scaffold.js +0 -0
  96. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/runtime/workpeg-runtime.js +0 -0
  97. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/scaffold.py +0 -0
  98. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/search_manifest.py +0 -0
  99. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/serve.py +0 -0
  100. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/skills_manifest.py +0 -0
  101. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/state.py +0 -0
  102. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/validators.py +0 -0
  103. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/watcher.py +0 -0
  104. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/widgets/__init__.py +0 -0
  105. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/widgets/base.py +0 -0
  106. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/widgets/canvas.py +0 -0
  107. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/widgets/display.py +0 -0
  108. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/widgets/fields.py +0 -0
  109. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/widgets/forms.py +0 -0
  110. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/widgets/futures.py +0 -0
  111. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/widgets/gestures.py +0 -0
  112. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/widgets/interactive.py +0 -0
  113. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/widgets/layout.py +0 -0
  114. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/ui/widgets/pickers.py +0 -0
  115. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg/utils.py +0 -0
  116. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg.egg-info/dependency_links.txt +0 -0
  117. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg.egg-info/entry_points.txt +0 -0
  118. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg.egg-info/requires.txt +0 -0
  119. {workpeg-0.154.0 → workpeg-0.155.0}/src/workpeg.egg-info/top_level.txt +0 -0
  120. {workpeg-0.154.0 → workpeg-0.155.0}/tests/test_auth.py +0 -0
  121. {workpeg-0.154.0 → workpeg-0.155.0}/tests/test_build.py +0 -0
  122. {workpeg-0.154.0 → workpeg-0.155.0}/tests/test_cdn.py +0 -0
  123. {workpeg-0.154.0 → workpeg-0.155.0}/tests/test_cdn_publish.py +0 -0
  124. {workpeg-0.154.0 → workpeg-0.155.0}/tests/test_changelog.py +0 -0
  125. {workpeg-0.154.0 → workpeg-0.155.0}/tests/test_changelog_guard.py +0 -0
  126. {workpeg-0.154.0 → workpeg-0.155.0}/tests/test_cli.py +0 -0
  127. {workpeg-0.154.0 → workpeg-0.155.0}/tests/test_config.py +0 -0
  128. {workpeg-0.154.0 → workpeg-0.155.0}/tests/test_context.py +0 -0
  129. {workpeg-0.154.0 → workpeg-0.155.0}/tests/test_create_new.py +0 -0
  130. {workpeg-0.154.0 → workpeg-0.155.0}/tests/test_doctor.py +0 -0
  131. {workpeg-0.154.0 → workpeg-0.155.0}/tests/test_release_script.py +0 -0
  132. {workpeg-0.154.0 → workpeg-0.155.0}/tests/test_run.py +0 -0
  133. {workpeg-0.154.0 → workpeg-0.155.0}/tests/test_runtime.py +0 -0
  134. {workpeg-0.154.0 → workpeg-0.155.0}/tests/test_submit.py +0 -0
  135. {workpeg-0.154.0 → workpeg-0.155.0}/tests/test_utils.py +0 -0
  136. {workpeg-0.154.0 → workpeg-0.155.0}/tests/test_version.py +0 -0
  137. {workpeg-0.154.0 → workpeg-0.155.0}/tests/test_watch_pipeline.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: workpeg
3
- Version: 0.154.0
3
+ Version: 0.155.0
4
4
  Summary: Workpeg function runtime and SDK
5
5
  Author-email: Workpeg <support@workpeg.com>
6
6
  License: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "workpeg"
7
- version = "0.154.0"
7
+ version = "0.155.0"
8
8
  description = "Workpeg function runtime and SDK"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -209,8 +209,8 @@ def build_parser() -> argparse.ArgumentParser:
209
209
  "\n"
210
210
  "Examples:\n"
211
211
  " workpeg project create my-peg\n"
212
- " workpeg ui serve my-peg/ui/\n"
213
- " workpeg run my-peg/function/\n"
212
+ " workpeg ui serve my-peg/ui/ --fake-cloud\n"
213
+ " workpeg function run --path my-peg/function/\n"
214
214
  ),
215
215
  )
216
216
  project_p.set_defaults(_namespace_parser=project_p)
@@ -227,6 +227,8 @@ def build_parser() -> argparse.ArgumentParser:
227
227
  epilog=(
228
228
  "Creates:\n"
229
229
  " my-peg/workpeg.json the manifest\n"
230
+ " my-peg/AGENTS.md the guide for coding agents\n"
231
+ " my-peg/CLAUDE.md imports AGENTS.md\n"
230
232
  " my-peg/ui/ the interface\n"
231
233
  " my-peg/function/ the backend\n"
232
234
  "\n"
@@ -830,14 +832,22 @@ def main(argv=None) -> None:
830
832
  #
831
833
 
832
834
  if args._handler == "ui.new":
835
+ import pathlib
836
+
833
837
  from workpeg.ui.build import PublicAssetError
834
838
  from workpeg.ui.create import ProjectExistsError, create_ui_project
835
839
  from workpeg.ui.compiler.ast_parser import UnsupportedSyntaxError
836
840
 
841
+ from workpeg.starter import GUIDE_FILES, starter_files
842
+
837
843
  name = args.name
838
844
 
839
845
  print(f"Creating {name}...")
840
846
 
847
+ # Asked before writing: an AGENTS.md or CLAUDE.md already here is
848
+ # kept even under --force, and the person is told so.
849
+ kept = [g for g in GUIDE_FILES if (pathlib.Path(name) / g).exists()]
850
+
841
851
  try:
842
852
  project_dir, source_file = create_ui_project(
843
853
  name, force=args.force
@@ -850,12 +860,16 @@ def main(argv=None) -> None:
850
860
  raise SystemExit(2)
851
861
 
852
862
  rel = project_dir.name
853
- print(f"\n {rel}/main.py")
854
- print(f" {rel}/app_shell.py")
855
- print(f" {rel}/pages/home.py")
856
- print(f" {rel}/pages/counter.py")
857
- print(f" {rel}/pages/not_found.py")
863
+ print()
864
+ for guide in GUIDE_FILES:
865
+ note = " (kept yours)" if guide in kept else ""
866
+ print(f" {rel}/{guide}{note}")
867
+ for path in starter_files():
868
+ if not path.endswith("__init__.py"):
869
+ print(f" {rel}/{path}")
858
870
  print(f" {rel}/dist/\n")
871
+ if "AGENTS.md" not in kept:
872
+ print("AGENTS.md tells a coding agent how to build this peg.\n")
859
873
 
860
874
  if args.no_serve:
861
875
  print(f"Done. Open {project_dir / 'dist' / 'index.html'} in a browser.")
@@ -998,7 +1012,11 @@ def main(argv=None) -> None:
998
1012
 
999
1013
  from workpeg.project import ProjectError, create_project
1000
1014
 
1015
+ from workpeg.starter import GUIDE_FILES
1016
+
1001
1017
  target = pathlib.Path(args.path or args.name)
1018
+ # Asked before writing: an existing guide is kept even with --force.
1019
+ kept = [g for g in GUIDE_FILES if (target / g).exists()]
1002
1020
  try:
1003
1021
  created = create_project(target, args.name, force=args.force)
1004
1022
  except ProjectError as exc:
@@ -1008,11 +1026,18 @@ def main(argv=None) -> None:
1008
1026
  rel = os.path.relpath(created, pathlib.Path.cwd())
1009
1027
  print(f"Created {rel}/")
1010
1028
  print(f" workpeg.json namespace: {args.name}")
1011
- print(" ui/ the interface")
1029
+ for guide in GUIDE_FILES:
1030
+ if guide in kept:
1031
+ print(f" {guide:<14} kept yours")
1032
+ elif guide == "AGENTS.md":
1033
+ print(f" {guide:<14} how a coding agent should build it")
1034
+ else:
1035
+ print(f" {guide:<14} imports AGENTS.md")
1036
+ print(" ui/ the interface, a Scaffold app")
1012
1037
  print(" function/ the backend")
1013
1038
  print("\nNext:")
1014
- print(f" workpeg ui serve {rel}/ui/")
1015
- print(f" workpeg run {rel}/function/")
1039
+ print(f" workpeg ui serve {rel}/ui/ --fake-cloud")
1040
+ print(f" workpeg function run --path {rel}/function/")
1016
1041
  return
1017
1042
 
1018
1043
  if args._handler == "ui.build":
@@ -10,8 +10,10 @@ WHY ONE FOLDER WITH TWO SUBDIRECTORIES
10
10
 
11
11
  my-peg/
12
12
  workpeg.json the manifest: namespace, function entrypoint, runtime
13
+ AGENTS.md the guide a coding agent reads first (CLAUDE.md
14
+ CLAUDE.md imports it)
13
15
  ui/ workpeg ui serve|build point here
14
- function/ workpeg run|build|submit point here
16
+ function/ workpeg function run|build point here
15
17
 
16
18
  The halves sit in subdirectories rather than merged at the root because each
17
19
  existing command already expects to own its directory: ``workpeg ui build``
@@ -26,14 +28,16 @@ and because ``workpeg project submit`` will read it to release both together.
26
28
  from __future__ import annotations
27
29
 
28
30
  import re
29
- import shutil
30
31
  from importlib import resources
31
32
  from pathlib import Path
32
33
 
33
- #: Substituted through every template file. A single token rather than a
34
- #: templating language: the whole scaffold is seven small files, and a
35
- #: dependency for that would cost more than it saves.
36
- PLACEHOLDER = "REPLACE_NAMESPACE"
34
+ from workpeg.starter import (
35
+ PLACEHOLDER, TemplateExists, copy_template, write_agent_guide,
36
+ write_starter,
37
+ )
38
+
39
+ __all__ = ["PLACEHOLDER", "ProjectError", "create_project",
40
+ "validate_namespace"]
37
41
 
38
42
  #: What a namespace may be. It becomes the first label of
39
43
  #: <namespace>.workpeg.com, so it is bounded by DNS, not by taste — and by the
@@ -79,7 +83,13 @@ def validate_namespace(name: str) -> str:
79
83
 
80
84
 
81
85
  def create_project(target: Path, namespace: str, *, force: bool = False):
82
- """Write the scaffold into *target*. Returns the created path."""
86
+ """Write the scaffold into *target*. Returns the created path.
87
+
88
+ The manifest and the function come from ``templates/project/``; ``ui/``
89
+ is the same Scaffold starter ``workpeg ui new`` writes; ``AGENTS.md`` and
90
+ ``CLAUDE.md`` go at the root, where an agent working in either half finds
91
+ them, and an existing one is kept even under *force*.
92
+ """
83
93
  namespace = validate_namespace(namespace)
84
94
  target = Path(target).expanduser().resolve()
85
95
 
@@ -91,25 +101,16 @@ def create_project(target: Path, namespace: str, *, force: bool = False):
91
101
  source = resources.files("workpeg") / "templates" / "project"
92
102
  with resources.as_file(source) as root:
93
103
  _copy(Path(root), target, namespace, force=force)
104
+ try:
105
+ write_starter(target / "ui", namespace, force=force)
106
+ except TemplateExists as exc:
107
+ raise ProjectError(str(exc)) from None
108
+ write_agent_guide(target, namespace)
94
109
  return target
95
110
 
96
111
 
97
112
  def _copy(source: Path, target: Path, namespace: str, *, force: bool):
98
- for item in sorted(source.rglob("*")):
99
- rel = item.relative_to(source)
100
- dest = target / rel
101
- if item.is_dir():
102
- dest.mkdir(parents=True, exist_ok=True)
103
- continue
104
- dest.parent.mkdir(parents=True, exist_ok=True)
105
- if dest.exists() and not force:
106
- raise ProjectError(f"{dest} already exists.")
107
- # Text files carry the placeholder; anything binary is copied as-is.
108
- # Decided by trying to read it rather than by extension, so a template
109
- # gaining a .png does not need this function to be told about it.
110
- try:
111
- body = item.read_text(encoding="utf-8")
112
- except UnicodeDecodeError:
113
- shutil.copy2(item, dest)
114
- continue
115
- dest.write_text(body.replace(PLACEHOLDER, namespace), encoding="utf-8")
113
+ try:
114
+ copy_template(source, target, namespace, force=force)
115
+ except TemplateExists as exc:
116
+ raise ProjectError(str(exc)) from None
@@ -0,0 +1,116 @@
1
+ """The code every new peg starts from, and the guide that comes with it.
2
+
3
+ Two commands create a peg's interface, ``workpeg project create`` and
4
+ ``workpeg ui new``, and until now each wrote its own: one a single page that
5
+ subclassed ``Scaffold``, the other a counter and a page of ASCII art laid out
6
+ with a hand-written style dict. A coding agent opening either project copied
7
+ what it found, so the first thing it learned was the opposite of how a peg is
8
+ meant to look.
9
+
10
+ Both now write the same starter from ``templates/starter/``: a ``Router``
11
+ whose pages sit under the ``/b/[business_id]`` shell, an ``AppShell`` that
12
+ returns the SDK ``Scaffold``, shared state Components, and a list page and a
13
+ detail page that draw every state a data view has. Beside it they write
14
+ ``AGENTS.md``, the guide an agent reads before it changes anything, and a
15
+ one-line ``CLAUDE.md`` that imports it.
16
+
17
+ The guide is never overwritten. A repository often has its own ``AGENTS.md``
18
+ or ``CLAUDE.md`` already, and ``--force`` is how a person writes a starter
19
+ into a folder that has files in it; replacing their guide with ours would be
20
+ silent data loss. So an existing file is kept, always, and the caller is told
21
+ which ones were.
22
+ """
23
+ from __future__ import annotations
24
+
25
+ import shutil
26
+ from importlib import resources
27
+ from pathlib import Path
28
+
29
+ #: Substituted through every template file. A single token rather than a
30
+ #: templating language: the scaffold is a handful of small files, and a
31
+ #: dependency for that would cost more than it saves.
32
+ PLACEHOLDER = "REPLACE_NAMESPACE"
33
+
34
+ #: The guide's files, in the order a person is told about them.
35
+ GUIDE_FILES = ("AGENTS.md", "CLAUDE.md")
36
+
37
+
38
+ class TemplateExists(Exception):
39
+ """A template file would overwrite one that is already there."""
40
+
41
+
42
+ def _template(name: str):
43
+ return resources.files("workpeg") / "templates" / name
44
+
45
+
46
+ def copy_template(source: Path, target: Path, namespace: str, *,
47
+ force: bool) -> list[Path]:
48
+ """Copy *source* into *target*, replacing the placeholder in text files.
49
+
50
+ Returns the files written, relative to *target*. Without *force*, a file
51
+ that already exists stops the copy before it is touched.
52
+ """
53
+ written = []
54
+ for item in sorted(source.rglob("*")):
55
+ if "__pycache__" in item.parts or item.suffix == ".pyc":
56
+ continue
57
+ rel = item.relative_to(source)
58
+ dest = target / rel
59
+ if item.is_dir():
60
+ dest.mkdir(parents=True, exist_ok=True)
61
+ continue
62
+ dest.parent.mkdir(parents=True, exist_ok=True)
63
+ if dest.exists() and not force:
64
+ raise TemplateExists(f"{dest} already exists.")
65
+ # Text files carry the placeholder; anything binary is copied as-is.
66
+ # Decided by trying to read it rather than by extension, so a template
67
+ # gaining a .png does not need this function to be told about it.
68
+ try:
69
+ body = item.read_text(encoding="utf-8")
70
+ except UnicodeDecodeError:
71
+ shutil.copy2(item, dest)
72
+ else:
73
+ dest.write_text(body.replace(PLACEHOLDER, namespace),
74
+ encoding="utf-8")
75
+ written.append(rel)
76
+ return written
77
+
78
+
79
+ def starter_files() -> list[str]:
80
+ """The starter's files, relative and in POSIX form, sorted."""
81
+ with resources.as_file(_template("starter")) as root:
82
+ root = Path(root)
83
+ return sorted(
84
+ p.relative_to(root).as_posix() for p in root.rglob("*")
85
+ if p.is_file() and "__pycache__" not in p.parts
86
+ and p.suffix != ".pyc")
87
+
88
+
89
+ def write_starter(target: Path, namespace: str, *, force: bool) -> list[Path]:
90
+ """Write the Scaffold starter into *target*, the folder for ``main.py``."""
91
+ with resources.as_file(_template("starter")) as root:
92
+ return copy_template(Path(root), Path(target), namespace, force=force)
93
+
94
+
95
+ def write_agent_guide(target: Path,
96
+ namespace: str) -> tuple[list[str], list[str]]:
97
+ """Write ``AGENTS.md`` and ``CLAUDE.md`` into *target*.
98
+
99
+ Returns ``(written, kept)``: the names written, and the names left alone
100
+ because a file of that name was already there. Never overwrites, whatever
101
+ the caller's ``--force`` said.
102
+ """
103
+ target = Path(target)
104
+ target.mkdir(parents=True, exist_ok=True)
105
+ written, kept = [], []
106
+ with resources.as_file(_template("agents")) as root:
107
+ for name in GUIDE_FILES:
108
+ dest = target / name
109
+ if dest.exists():
110
+ kept.append(name)
111
+ continue
112
+ body = (Path(root) / name).read_text(encoding="utf-8")
113
+ dest.write_text(body.replace(PLACEHOLDER, namespace),
114
+ encoding="utf-8")
115
+ written.append(name)
116
+ return written, kept