codeplain 0.3.10.dev3__py3-none-any.whl → 0.3.10.dev5__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: codeplain
3
- Version: 0.3.10.dev3
3
+ Version: 0.3.10.dev5
4
4
  Summary: Transform plain language specifications into working code
5
5
  License-File: LICENSE
6
6
  Classifier: Environment :: Console
@@ -1,16 +1,17 @@
1
1
  change_detection.py,sha256=CazORZrezeZSw2I6VBvieN-c2SEjieZPo6pNrKwmMVA,6915
2
- codeplain_REST_api.py,sha256=x-sCbbBSswID4eKXDMvv84nzWynNSbBPoyAtq__6tas,21644
2
+ codeplain_REST_api.py,sha256=Iu3htCE05k-8BOA6I2acz4Ezr74cHQIXmhBIsgnX4Ng,21232
3
3
  concept_utils.py,sha256=TpyiQ4DfMtO231j-lPj65i0suRTPr8t9j3QNf9KiM4A,8080
4
+ conformance_fix_journal.py,sha256=7wL3UOc3BWaUo5MCmiFbb3kIwOQ6iEpdQSyEmedo8Vk,9488
4
5
  diff_utils.py,sha256=AjiQlqo5pRos_8hVXZo5yBurl5BzSrTMGrQv4dCtRCg,1198
5
6
  event_bus.py,sha256=g5XLwRfjrvTIcB6urjREuCJzZj5TA93hy8lKXLGXuCE,650
6
7
  file_utils.py,sha256=MNZ5li1ofIMOYB6FCrMa_UkX6nkGCgSZuaqzhqVc1Ok,11682
7
8
  git_utils.py,sha256=gCUA6_9zg19f6k_0aVcRnIVlAJSBD0Vt6takx-0pKME,16547
8
- memory_management.py,sha256=SPoK0BXB9_yDyrrOKjFtOOlKkJIq0I5EXV7dE0OsE8g,5972
9
+ memory_management.py,sha256=CwIOQqF7Xo1sNfvP69zQRK_CpjinQD9dbolhRPl6lTk,2446
9
10
  metadata_utils.py,sha256=YO17o7IAma5TT1ZN0pTwrLVr_KxFQ8APv02KqKPpI5k,1641
10
11
  module_renderer.py,sha256=IJBle8mbBARn_xrekjSpsVID7719yy2rNPkM15-ONoI,6982
11
12
  partial_rendering.py,sha256=uzZc2j4d3pAXzfiHw_y1TK4yLRsLOb1Mm21570AGxJ8,13837
12
13
  path_resolution.py,sha256=0tMqU0a1g4DYhTOp7QjLVSEkv_cgasb4NI1mK809dUM,2233
13
- plain2code.py,sha256=NsZf7JS2bGmOQ6HsbiTqNA3EMXXY5YQW6nBBXCG7m-U,17392
14
+ plain2code.py,sha256=v8xBTv3mQjntpBTBJUvl5naGnSPFAzhEQTqpeRr40ow,18072
14
15
  plain2code_arguments.py,sha256=xMK-R13Vu005bHz3MUDY8F0Cf3ED9hCPqNsC6jGZmkk,17620
15
16
  plain2code_console.py,sha256=5N4_GIV8qE-2zvFh6qoOHhhsuwCF_3r7jG19S-YWtfk,5906
16
17
  plain2code_events.py,sha256=rgDF5PDtNr_lEPvJmd1tIQXZrzwgzZW5b-_pykugqe4,1587
@@ -39,26 +40,27 @@ render_machine/code_renderer.py,sha256=-vp_ltU7e3ssX9hbS8IY4ETSp-39JAuoJ3ZltKpdt
39
40
  render_machine/conformance_tests.py,sha256=PNTCnJNd_xNIhpTPPS8vlx8qws3cTgQSTLdADRab2YM,9617
40
41
  render_machine/implementation_code_helpers.py,sha256=Fxm-IInoZjAIZn41_-WXWj7VIYczpW4yH44Gt8CYMAQ,2378
41
42
  render_machine/render_context.py,sha256=iaJWI_EMSn51LNF_b7KRvlir46ZgUkjbaEiVgSvMTCI,26314
42
- render_machine/render_types.py,sha256=cT3D0lmxQ3enIo0jGp3LEGCY2t3X1Q1_tqwcadzSAv0,8761
43
+ render_machine/render_types.py,sha256=IY16mGnt5uoZlLKy16Wmpq0_M5PAitVDvt2khnDhKU0,8479
43
44
  render_machine/render_utils.py,sha256=yA3X15E_Lebk_-MxkSz9rM_qy-Pes8EQ9Ye-smkHCDw,9320
44
- render_machine/state_machine_config.py,sha256=NnX5sBGkc6cNG8OOQ4PrJeJBCADRGZKJYQXV7ndR4bs,26789
45
- render_machine/states.py,sha256=niFXqayyA_rezCrlzo0hYeHAruErcPzQVF-BeIBGnL8,1968
45
+ render_machine/state_machine_config.py,sha256=0pL4PyrZ5F2UumvHLMRfhyh64M4pDvf-9zEs-5OAEU8,27866
46
+ render_machine/states.py,sha256=Lu-7upbs9_bjJsy0P738qx5IiN0DzVcFdhF2-m6YjnQ,2067
46
47
  render_machine/triggers.py,sha256=VekNhHGR-u5JXIboqc_Eyqf73LNH7wezLK7r3WWtodk,1269
47
48
  render_machine/actions/analyze_specification_ambiguity.py,sha256=SykZAozGvr1jySxbpKCgt11nMpZhOK0sN-J66M42T5Y,2847
48
49
  render_machine/actions/base_action.py,sha256=vVzMp-LanrZyq-jamHyWaQxpRl-pLqtTdtiEzUBhfyE,534
49
50
  render_machine/actions/commit_conformance_tests_changes.py,sha256=08yxCPCpf5TlrzLPsEh5SJXVVvnLfwdNKSr7BlzlYxo,2589
50
51
  render_machine/actions/commit_implementation_code_changes.py,sha256=yi51oAArLCgWcmFbynes-BK2IGnZwA7wygrTJGoL8dY,826
51
52
  render_machine/actions/create_dist.py,sha256=ykER7i2OvWAXjrlAZnkQHpiNl00vSMF8WDxNhlWKfsA,1088
53
+ render_machine/actions/distill_conformance_test_memory.py,sha256=ENjfhTWqRLePHeRF4t8zNRhWKDV2rU4pLYuU_CZhhmo,2639
52
54
  render_machine/actions/exit_with_error.py,sha256=W6TMULHJcHEaXE4WUnlELEu0_l7IZy9HWaPkXyqg7ck,1279
53
55
  render_machine/actions/finish_functional_requirement.py,sha256=usQgPSg6PHpBOR1RhK7lPz9zjY-2VJJDqi3T0nlqdLw,841
54
- render_machine/actions/fix_conformance_test.py,sha256=EZLVjF4A8zSTmyqdgcLoz-2pLpeieq4M_Rb71pY3IKA,10095
56
+ render_machine/actions/fix_conformance_test.py,sha256=mHk-UJNEZ7Y65YLLUBljJ3Z5zBVA4jIYRSJ0VCd_LOw,11012
55
57
  render_machine/actions/fix_unit_tests.py,sha256=hvwvCJDk_-8fHMpkNFyeBSG1IshIcufDpymF00ulPXY,2301
56
- render_machine/actions/prepare_repositories.py,sha256=8poItxPrUZWKCFReqdAKL__bxjM71Ig2zLkg1TDGmpY,3439
58
+ render_machine/actions/prepare_repositories.py,sha256=HyZ1R6E3H5V-G4WDSGfhxl_arskmW9FcaxNdQr6JjVs,3867
57
59
  render_machine/actions/prepare_testing_environment.py,sha256=kIsXgV6-jOlqp-04cimPgTQoHPrVIu0zW-H_Jj-jowE,2106
58
60
  render_machine/actions/refactor_code.py,sha256=gyPsnqgHseL2bkENu4WeGCRyV0R18_GH3JOrPdoxKvg,2609
59
61
  render_machine/actions/render_conformance_tests.py,sha256=5gOQn-G1T9UWEI8sDfALcVdArk0ln9DgUprOPjccS-U,9268
60
62
  render_machine/actions/render_functional_requirement.py,sha256=53KzMVlcefoag1x73roCEQvQ7FbmH8FzhXMQau-s8tg,4655
61
- render_machine/actions/run_conformance_tests.py,sha256=4sJTORl6YLFXQIdLMBQHDeJd2hztGyt3tsVvrCviBko,4008
63
+ render_machine/actions/run_conformance_tests.py,sha256=yUG6buqp75EOmJYxdM6MmCNF5_G4TUxA-QSTKx7EzxA,3760
62
64
  render_machine/actions/run_unit_tests.py,sha256=A4WXtSzpCLDHYR8fQAbfxUf_E19GYflZSHZaSreoFPk,2101
63
65
  render_machine/actions/summarize_conformance_tests.py,sha256=Vy1kRK8vyazK_BbsKuz1MLDN_TQWVxxzkwEEm-50byc,1639
64
66
  standard_template_library/golang-console-app-template.plain,sha256=JOusEjCj7jagnXUzaI-SdIr3hj1wTo2uShK017aNtVM,949
@@ -70,7 +72,10 @@ tests/conftest.py,sha256=QZcp08htUlJGgmHDlRWFgsWXZ8o8IBWTD5QqJaUMlU8,790
70
72
  tests/test_arg_provenance.py,sha256=d_J7aCeHMXBpctBWTt60WU-I8pEKN7XRXRTJZZGCdo0,3441
71
73
  tests/test_change_detection.py,sha256=jH8SEhndX400DNqIKmcYLzxHqq9WFdgmuvY3XPq-ZFc,13534
72
74
  tests/test_cli_output.py,sha256=ZV2F1NNW4EiZvMNkhF9XUZH6bFJbddfkZof5qAFxe3Y,18885
75
+ tests/test_conformance_fix_journal.py,sha256=olTeAuxXgFwQ8LSQyt0FqtBy9_XY_gK-Ei_pUuJ0C3M,10389
73
76
  tests/test_console_log_styles.py,sha256=63DQWiwWNhe_rMP70bW9DAB6-EPaqU3Wpwyh8eR09pc,4080
77
+ tests/test_distill_conformance_test_memory.py,sha256=Tftw9l-gLVwIU6QttY03h2VedvuFxpIsCmZIzvWfxMA,5481
78
+ tests/test_dry_run_link_validation.py,sha256=ivvYXQPqUkQ8glbFyUrdCninCxF2mg-rAsDcfjcB7MM,2140
74
79
  tests/test_file_utils.py,sha256=R_ZIhrTtwlhHxgmbBtA8PFEU5-QB4Fi5skJ7PS2KzdU,3614
75
80
  tests/test_folder_path_resolution.py,sha256=K9v684xkPE0HOAsovg8uDixpZmaIk7ho-Wd3rTjKLF0,6560
76
81
  tests/test_git_utils.py,sha256=h3rWhhs4XVRYqzVzdmj51siF_AYD-GkbZiefK2iGfWo,15614
@@ -87,7 +92,7 @@ tests/test_plain_modules.py,sha256=Fn3FeH-M4exnyFJDZzc9YWaLEfBmiqPH5TpiBT9jgAs,3
87
92
  tests/test_plainfile.py,sha256=wZ_PN4GULPWIpl_AK_r_6jkgtX0Ch8EHmN5IhX7huOE,11027
88
93
  tests/test_plainfileparser.py,sha256=l8GfXkVaSzgH74fX45Wp5jX0q3QlO6t_TgDG72dc28o,23867
89
94
  tests/test_plainspec.py,sha256=ng55E8ajrH2-gPC1p_QDIe_zXplPvoqHJ-d57UWKFTw,3577
90
- tests/test_prepare_repositories_layout.py,sha256=iHDfZi2OFLDp4SyjR9o11imKKiTGzycb_1nWBkW7QFE,12515
95
+ tests/test_prepare_repositories_layout.py,sha256=PhJQLnHfjfjo6CTWoicyEKgL0_GtjwB2OKYAWSBVHtk,14638
91
96
  tests/test_requires.py,sha256=6tnHYaKudxN-RiQjSFoi9nHe_x0ze3QF-f-j67zAE74,1250
92
97
  tests/test_resolve_config_file.py,sha256=b87tDOvyzbsnE-QRWbZ97ou7NuyaAgskv-dbYBum31c,2830
93
98
  tests/test_script_path_resolution.py,sha256=tiEqMevQRXr9YpfHN0xldOOQpLAUgnSqTzeZWkKHaUY,4156
@@ -104,11 +109,11 @@ tui/models.py,sha256=KMjlWubmPD41GA-BjgiqkaV9v7tLJ0fuWKBDPmZj4JA,1493
104
109
  tui/plain2code_tui.py,sha256=8F7ZYRpmTiWRdTeQ63LPf2LGrreYjIYXvf_9XNSPyHs,17104
105
110
  tui/plain_module_render_choice_tui.py,sha256=XwBMMzyDat9FYqMkKdIV7kmIevddfwGA5Qk9kgy5sYY,12112
106
111
  tui/spinner.py,sha256=Ro6Gd9Przf-whuHqPRY6HwI0T57yJjyNPbhDbigZKZE,2471
107
- tui/state_handlers.py,sha256=4r_6m5YMcprQtgiTP0De3XFfGAF8VzgaWXHxPweYPbQ,16325
112
+ tui/state_handlers.py,sha256=zbUS_D9eU8qIwVpaxPEp9zL9bpg8gXsWNoUaqg9TLrQ,16664
108
113
  tui/styles.css,sha256=kiC7Og_2G1E7owoiZgV95-3_dSeQnsNj3qzaY04xkDg,6727
109
114
  tui/widget_helpers.py,sha256=ToO9MV2bF2Rp-XMNcjIYclnB_qmgO5sLw4UtQ2CyTMg,6652
110
- codeplain-0.3.10.dev3.dist-info/METADATA,sha256=BQ2CP4ur9t4LBdTGsYW7aJncruH-tL-sPRpHX_vpMAA,7256
111
- codeplain-0.3.10.dev3.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
112
- codeplain-0.3.10.dev3.dist-info/entry_points.txt,sha256=oDZkBqu9WhtZApb_K6ia8-fn9aojwmAsgnKELceX5T4,46
113
- codeplain-0.3.10.dev3.dist-info/licenses/LICENSE,sha256=pCeKgQ1mXE5OmNUuKOfOZh1T1vqkeCUxghE7N8qgnzc,11345
114
- codeplain-0.3.10.dev3.dist-info/RECORD,,
115
+ codeplain-0.3.10.dev5.dist-info/METADATA,sha256=nG1mz4SKQy9tZ2ybsG-Va9_plwrluGfGVc9AxONWh2s,7256
116
+ codeplain-0.3.10.dev5.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
117
+ codeplain-0.3.10.dev5.dist-info/entry_points.txt,sha256=oDZkBqu9WhtZApb_K6ia8-fn9aojwmAsgnKELceX5T4,46
118
+ codeplain-0.3.10.dev5.dist-info/licenses/LICENSE,sha256=pCeKgQ1mXE5OmNUuKOfOZh1T1vqkeCUxghE7N8qgnzc,11345
119
+ codeplain-0.3.10.dev5.dist-info/RECORD,,
codeplain_REST_api.py CHANGED
@@ -254,7 +254,7 @@ class CodeplainAPI:
254
254
 
255
255
  return self.post_request(endpoint_url, headers, payload, run_state)
256
256
 
257
- def create_conformance_test_memory(
257
+ def distill_conformance_test_memory(
258
258
  self,
259
259
  frid,
260
260
  plain_source_tree,
@@ -263,15 +263,10 @@ class CodeplainAPI:
263
263
  memory_files_content,
264
264
  module_name,
265
265
  required_modules,
266
- code_diff,
267
- conformance_tests_files,
268
- acceptance_tests,
269
- conformance_tests_issue,
270
- conformance_tests_folder_name,
271
- previous_conformance_tests_issue_old,
266
+ fix_journals,
272
267
  run_state: RunState,
273
268
  ):
274
- endpoint_url = f"{self.api_url}/create_conformance_test_memory"
269
+ endpoint_url = f"{self.api_url}/distill_conformance_test_memory"
275
270
  headers = {"X-API-Key": self.api_key, "Content-Type": "application/json"}
276
271
 
277
272
  payload = {
@@ -282,12 +277,7 @@ class CodeplainAPI:
282
277
  "memory_files_content": memory_files_content,
283
278
  "module_name": module_name,
284
279
  "required_modules": required_modules,
285
- "code_diff": code_diff,
286
- "conformance_tests_files": conformance_tests_files,
287
- "acceptance_tests": acceptance_tests,
288
- "conformance_tests_issue": conformance_tests_issue,
289
- "conformance_tests_folder_name": conformance_tests_folder_name,
290
- "previous_conformance_tests_issue": previous_conformance_tests_issue_old,
280
+ "fix_journals": fix_journals,
291
281
  }
292
282
 
293
283
  return self.post_request(endpoint_url, headers, payload, run_state)
@@ -381,6 +371,7 @@ class CodeplainAPI:
381
371
  conformance_tests_folder_name,
382
372
  current_testing_frid_high_level_implementation_plan: Optional[str],
383
373
  conflicting_requirements_count: int,
374
+ fix_attempts_journal: list,
384
375
  run_state: RunState,
385
376
  ):
386
377
  endpoint_url = f"{self.api_url}/fix_conformance_tests_issue"
@@ -403,6 +394,7 @@ class CodeplainAPI:
403
394
  "conformance_tests_folder_name": conformance_tests_folder_name,
404
395
  "current_testing_frid_high_level_implementation_plan": current_testing_frid_high_level_implementation_plan,
405
396
  "conflicting_requirements_count": conflicting_requirements_count,
397
+ "fix_attempts_journal": fix_attempts_journal,
406
398
  }
407
399
 
408
400
  if acceptance_tests is not None:
@@ -0,0 +1,207 @@
1
+ """Deterministic journal of conformance tests fix attempts.
2
+
3
+ While a functionality's conformance tests are failing, every fix attempt is recorded here: the
4
+ issue that triggered it, what the fixer said it tried, which files it changed and whether the tests
5
+ passed afterwards. A digest of the journal is sent back with every fix request so the fixer does
6
+ not repeat attempts that already failed, and once the functionality's conformance tests all pass
7
+ the journal is distilled into durable memories and deleted.
8
+
9
+ Each entry carries the issue in two forms: the raw script output (kept untruncated, on disk only)
10
+ and the prepared form the server built for the fix prompt (trimmed, and summarized or truncated
11
+ when oversized) - the issue exactly the way the fixer saw it. The prepared form is what travels in
12
+ the fix digest and the distillation payload; the raw form exists for humans debugging a render.
13
+ An attempt's outcome text is not stored twice: the output produced after an attempt is the raw
14
+ issue of the next attempt.
15
+
16
+ Journals are keyed by the (module, frid) whose tests are being fixed - during the regression sweep
17
+ that can be a previously implemented functionality, possibly from a required module.
18
+ """
19
+
20
+ import hashlib
21
+ import json
22
+ import os
23
+ import shutil
24
+
25
+ from plain2code_console import console
26
+
27
+ CONFORMANCE_TEST_JOURNAL_SUBFOLDER = "conformance_test_journal"
28
+
29
+ # Cap for the issue excerpts included in payloads (the per-attempt issue in the fix digest, and the
30
+ # initial issue in the distillation payload). The server-prepared issue is already bounded (LLM
31
+ # summary or ~10k-char truncation), so this only trims the rare oversized case - it must not
32
+ # routinely cut into summaries the server already sized for a prompt.
33
+ MAX_ISSUE_EXCERPT_CHARS = 8000
34
+
35
+ # The keys of a journal entry that make up the digest sent to the fixer and the distiller.
36
+ DIGEST_KEYS = ["attempt", "hypothesis", "approach", "target", "files_changed", "duplicate_of", "result"]
37
+
38
+
39
+ def _trim_issue(issue: str | None, max_chars: int) -> str | None:
40
+ if issue is None or len(issue) <= max_chars:
41
+ return issue
42
+ return f"(TRUNCATED - showing the last {max_chars} characters)\n" + issue[-max_chars:]
43
+
44
+
45
+ def normalized_diff_hash(diff_files: dict[str, str] | None) -> str | None:
46
+ """Hashes a fix's diff so that essentially identical retries can be detected.
47
+
48
+ Whitespace-only differences are ignored - a fix that reproduces an earlier failed change with
49
+ different formatting is still the same attempt.
50
+ """
51
+ if not diff_files:
52
+ return None
53
+
54
+ normalized_parts = []
55
+ for file_name in sorted(diff_files):
56
+ content_lines = [line.strip() for line in (diff_files[file_name] or "").splitlines() if line.strip()]
57
+ normalized_parts.append(file_name + "\n" + "\n".join(content_lines))
58
+
59
+ return hashlib.sha256("\n".join(normalized_parts).encode("utf-8")).hexdigest()
60
+
61
+
62
+ class FixAttemptJournal:
63
+ """File-backed journal, one JSONL file per (module, frid) whose conformance tests are fixed."""
64
+
65
+ def __init__(self, memory_folder: str):
66
+ self.journal_folder = os.path.join(memory_folder, CONFORMANCE_TEST_JOURNAL_SUBFOLDER)
67
+
68
+ def _journal_path(self, module_name: str, frid: str) -> str:
69
+ return os.path.join(self.journal_folder, f"{module_name}__{frid}.jsonl")
70
+
71
+ def _read_entries(self, module_name: str, frid: str) -> list[dict]:
72
+ journal_path = self._journal_path(module_name, frid)
73
+ if not os.path.exists(journal_path):
74
+ return []
75
+
76
+ entries = []
77
+ with open(journal_path, "r", encoding="utf-8") as journal_file:
78
+ for line in journal_file:
79
+ line = line.strip()
80
+ if not line:
81
+ continue
82
+ try:
83
+ entries.append(json.loads(line))
84
+ except json.JSONDecodeError:
85
+ console.error(f"Skipping malformed journal entry in {journal_path}.")
86
+
87
+ return entries
88
+
89
+ def _write_entries(self, module_name: str, frid: str, entries: list[dict]):
90
+ os.makedirs(self.journal_folder, exist_ok=True)
91
+ with open(self._journal_path(module_name, frid), "w", encoding="utf-8") as journal_file:
92
+ for entry in entries:
93
+ journal_file.write(json.dumps(entry) + "\n")
94
+
95
+ def open_attempt(self, module_name: str, frid: str, attempt_no: int, issue_before: str):
96
+ """Starts a new journal entry for a fix attempt that is about to be made.
97
+
98
+ The raw issue is stored untruncated - it never travels in a payload, only its prepared form
99
+ (recorded later by record_fix) does.
100
+ """
101
+ entries = self._read_entries(module_name, frid)
102
+ entries.append({"attempt": attempt_no, "issue_before_raw": issue_before})
103
+ self._write_entries(module_name, frid, entries)
104
+
105
+ def record_fix(
106
+ self,
107
+ module_name: str,
108
+ frid: str,
109
+ fix_attempt_summary: dict | None,
110
+ files_changed: list[str],
111
+ target: str,
112
+ diff_files: dict[str, str] | None,
113
+ prepared_issue: str | None,
114
+ ):
115
+ """Completes the open attempt with what the fix actually did.
116
+
117
+ The prepared issue is the form the server built for the fix prompt - the issue exactly the
118
+ way the fixer saw it. The diff hash marks the attempt as a duplicate when an earlier attempt
119
+ in the same journal produced essentially the same change - the strongest signal that the
120
+ fixer is going in circles.
121
+ """
122
+ entries = self._read_entries(module_name, frid)
123
+ if not entries:
124
+ console.error("Cannot record a fix - no journal entry is open.")
125
+ return
126
+
127
+ entry = entries[-1]
128
+ if isinstance(fix_attempt_summary, dict):
129
+ entry["hypothesis"] = fix_attempt_summary.get("hypothesis")
130
+ entry["approach"] = fix_attempt_summary.get("approach")
131
+ if prepared_issue:
132
+ entry["issue_before"] = prepared_issue
133
+ entry["files_changed"] = sorted(files_changed)
134
+ entry["target"] = target
135
+
136
+ diff_hash = normalized_diff_hash(diff_files)
137
+ entry["diff_hash"] = diff_hash
138
+ if diff_hash is not None:
139
+ for earlier_entry in entries[:-1]:
140
+ if earlier_entry.get("diff_hash") == diff_hash:
141
+ entry["duplicate_of"] = earlier_entry["attempt"]
142
+ break
143
+
144
+ self._write_entries(module_name, frid, entries)
145
+
146
+ def record_result(self, module_name: str, frid: str, passed: bool):
147
+ """Records whether the conformance tests passed after the last fix attempt was applied.
148
+
149
+ A failed run's output is not stored here - it becomes the raw issue of the next attempt.
150
+ Does nothing when no attempt is pending: the first test run of a functionality has no fix
151
+ attempt behind it.
152
+ """
153
+ entries = self._read_entries(module_name, frid)
154
+ if not entries or "result" in entries[-1]:
155
+ return
156
+
157
+ entries[-1]["result"] = "conformance tests passed" if passed else "conformance tests still failed"
158
+ self._write_entries(module_name, frid, entries)
159
+
160
+ def build_digest(self, module_name: str, frid: str) -> list[dict]:
161
+ """Builds the compact attempt history sent with a fix request.
162
+
163
+ Only attempts whose fix has been recorded are included - the entry just opened for the
164
+ attempt being made (and any dangling entry an interrupted render left behind) carries no
165
+ information for the fixer. Each included attempt carries the prepared issue it addressed,
166
+ so the fixer can see how the issue evolved across attempts. Raw outputs never travel - the
167
+ current issue is sent with the request separately.
168
+ """
169
+ return [self._digest_entry(entry) for entry in self._read_entries(module_name, frid) if "target" in entry]
170
+
171
+ @staticmethod
172
+ def _digest_entry(entry: dict) -> dict:
173
+ digest_entry = {key: entry[key] for key in DIGEST_KEYS if key in entry}
174
+ if entry.get("issue_before"):
175
+ digest_entry["issue"] = _trim_issue(entry["issue_before"], MAX_ISSUE_EXCERPT_CHARS)
176
+ return digest_entry
177
+
178
+ def collect_all(self) -> list[dict]:
179
+ """Collects the digests of every journal, keyed by the tested module and frid, for distillation."""
180
+ if not os.path.exists(self.journal_folder):
181
+ return []
182
+
183
+ journals = []
184
+ for file_name in sorted(os.listdir(self.journal_folder)):
185
+ if not file_name.endswith(".jsonl") or "__" not in file_name:
186
+ continue
187
+ module_name, _, frid = file_name[: -len(".jsonl")].rpartition("__")
188
+ entries = [entry for entry in self._read_entries(module_name, frid) if "target" in entry]
189
+ if not entries:
190
+ continue
191
+ initial_issue = entries[0].get("issue_before") or _trim_issue(
192
+ entries[0].get("issue_before_raw"), MAX_ISSUE_EXCERPT_CHARS
193
+ )
194
+ journal = {
195
+ "module": module_name,
196
+ "frid": frid,
197
+ "initial_issue": initial_issue,
198
+ "attempts": [self._digest_entry(entry) for entry in entries],
199
+ }
200
+ journals.append(journal)
201
+
202
+ return journals
203
+
204
+ def clear_all(self):
205
+ """Deletes every journal. Called after the journals have been distilled into memories."""
206
+ if os.path.exists(self.journal_folder):
207
+ shutil.rmtree(self.journal_folder)
memory_management.py CHANGED
@@ -1,16 +1,18 @@
1
- import json
2
1
  import os
3
2
 
4
3
  import file_utils
4
+ from conformance_fix_journal import FixAttemptJournal
5
5
  from plain2code_console import console
6
- from render_machine.implementation_code_helpers import ImplementationCodeHelpers
7
- from render_machine.render_context import RenderContext
8
6
 
9
- CONFORMANCE_TESTS_SUCCESS_EXIT_CODE = 0
10
7
  CONFORMANCE_TEST_MEMORY_SUBFOLDER = "conformance_test_memory"
11
8
 
12
9
 
13
10
  class MemoryManager:
11
+ """Manages a module's memory store at <build>/<module>/.memory.
12
+
13
+ The distilled memories are inherited by the next module in the chain (copied over when its
14
+ render starts, like the code repo), so learnings travel across modules.
15
+ """
14
16
 
15
17
  @staticmethod
16
18
  def fetch_memory_files(memory_folder: str) -> tuple[list[str], dict[str, str]]:
@@ -26,107 +28,25 @@ class MemoryManager:
26
28
  def __init__(self, codeplain_api, memory_folder: str):
27
29
  self.codeplain_api = codeplain_api
28
30
  self.memory_folder = memory_folder
31
+ self.journal = FixAttemptJournal(memory_folder)
29
32
 
30
- def create_conformance_tests_memory(
31
- self, render_context: RenderContext, exit_code: int, conformance_tests_issue: str
32
- ):
33
-
34
- current_conformance_tests_issue_frid = render_context.conformance_tests_running_context.current_testing_frid
35
- current_conformance_tests_issue_module = (
36
- render_context.conformance_tests_running_context.current_testing_module_name
37
- )
38
- old_conformance_tests_issue_frid = (
39
- render_context.conformance_tests_running_context.previous_conformance_tests_issue_frid
40
- )
41
- old_conformance_tests_issue_module = (
42
- render_context.conformance_tests_running_context.previous_conformance_tests_issue_module
43
- )
44
-
45
- old_conformance_tests_issue = (
46
- render_context.conformance_tests_running_context.previous_conformance_tests_issue_old
47
- )
48
-
49
- is_first_time_running_conformance_tests = (
50
- old_conformance_tests_issue_frid is None
51
- or old_conformance_tests_issue_frid == ""
52
- or old_conformance_tests_issue_module != current_conformance_tests_issue_module
53
- )
54
- is_same_frid_as_previous_failing_test = (
55
- current_conformance_tests_issue_frid == old_conformance_tests_issue_frid
56
- and current_conformance_tests_issue_module == old_conformance_tests_issue_module
57
- )
58
- is_conformance_test_failed = exit_code != CONFORMANCE_TESTS_SUCCESS_EXIT_CODE
59
-
60
- should_create_memory = not is_first_time_running_conformance_tests and (
61
- is_same_frid_as_previous_failing_test or is_conformance_test_failed
62
- )
63
- code_diff_files = render_context.conformance_tests_running_context.code_diff_files
33
+ def store_memory_files(self, response_files: dict[str, str]):
34
+ """Stores distilled memory files, applying deletions (None content) to existing memories."""
35
+ memory_path = os.path.join(self.memory_folder, CONFORMANCE_TEST_MEMORY_SUBFOLDER)
36
+ memory_files, _ = MemoryManager.fetch_memory_files(self.memory_folder)
37
+ file_utils.store_response_files(memory_path, response_files, memory_files)
64
38
 
65
- if not should_create_memory or code_diff_files is None:
66
- console.debug(
67
- "Skipping creation of conformance test memory because the conditions for creating memories are not met."
68
- )
39
+ @staticmethod
40
+ def inherit_memories(source_memory_folder: str, destination_memory_folder: str):
41
+ """Copies the distilled memories of a previously rendered module into this module's store.
42
+
43
+ Only the distilled memories travel - fix attempt journals are transient state of one
44
+ module's render. A previous module without memories (e.g. shipped as an archive that
45
+ carries only code) is a no-op.
46
+ """
47
+ source_path = os.path.join(source_memory_folder, CONFORMANCE_TEST_MEMORY_SUBFOLDER)
48
+ if not os.path.isdir(source_path):
69
49
  return
70
-
71
- existing_files, existing_files_content = ImplementationCodeHelpers.fetch_existing_files(
72
- render_context.build_folder
73
- )
74
- memory_files, memory_files_content = MemoryManager.fetch_memory_files(self.memory_folder)
75
-
76
- conformance_tests_folder_name = (
77
- render_context.conformance_tests_running_context.get_current_conformance_test_folder_name()
78
- )
79
-
80
- (
81
- _,
82
- existing_conformance_test_files_content,
83
- ) = render_context.conformance_tests.fetch_existing_conformance_test_files(
84
- render_context.module_name,
85
- render_context.required_modules,
86
- render_context.conformance_tests_running_context.current_testing_module_name,
87
- conformance_tests_folder_name,
88
- )
89
- acceptance_tests = render_context.conformance_tests_running_context.get_current_acceptance_tests()
90
-
91
- response_files = render_context.codeplain_api.create_conformance_test_memory(
92
- render_context.frid_context.frid,
93
- render_context.plain_source_tree,
94
- render_context.frid_context.linked_resources,
95
- existing_files_content,
96
- memory_files_content,
97
- render_context.module_name,
98
- render_context.get_required_modules_functionalities(),
99
- code_diff_files,
100
- existing_conformance_test_files_content,
101
- acceptance_tests,
102
- conformance_tests_issue,
103
- conformance_tests_folder_name,
104
- old_conformance_tests_issue,
105
- run_state=render_context.run_state,
50
+ file_utils.copy_folder_content(
51
+ source_path, os.path.join(destination_memory_folder, CONFORMANCE_TEST_MEMORY_SUBFOLDER)
106
52
  )
107
- if len(response_files) > 0:
108
- memory_folder_path = os.path.join(self.memory_folder, CONFORMANCE_TEST_MEMORY_SUBFOLDER)
109
- file_utils.store_response_files(memory_folder_path, response_files, memory_files)
110
-
111
- def delete_unresolved_memory_files(self):
112
- """Delete memory files whose resolution_status is not 'RESOLVED'."""
113
- memory_path = os.path.join(self.memory_folder, CONFORMANCE_TEST_MEMORY_SUBFOLDER)
114
- if not os.path.exists(memory_path):
115
- return
116
-
117
- memory_files = file_utils.list_all_text_files(memory_path)
118
- for file_name in memory_files:
119
- file_path = os.path.join(memory_path, file_name)
120
- try:
121
- with open(file_path, "r") as f:
122
- content = json.load(f)
123
- if content.get("resolution_status") == "RESOLVED":
124
- continue
125
- else:
126
- os.remove(file_path)
127
- except (json.JSONDecodeError, OSError):
128
- # Not a valid JSON file, unlikely to be a valid memory file, delete it
129
- console.error(f"Memory file is not a valid JSON file: {file_name}. Deleting it.")
130
- os.remove(file_path)
131
-
132
- console.debug(f"Deleted temporary memory file: {file_name}")
plain2code.py CHANGED
@@ -203,6 +203,15 @@ def warn_if_acceptance_tests_without_conformance_script(plain_module, args) -> N
203
203
  )
204
204
 
205
205
 
206
+ def validate_linked_resources(plain_module) -> None:
207
+ """Load every linked resource exactly the way rendering does, so dry-run
208
+ surfaces the same errors (binary file, missing file, oversized base64 blob)."""
209
+ for module in plain_module.all_required_modules + [plain_module]:
210
+ resources_list: list[dict] = []
211
+ plain_spec.collect_linked_resources(module.plain_source, resources_list, None, True)
212
+ file_utils.load_linked_resources(module.template_dirs, resources_list, module.module_name)
213
+
214
+
206
215
  def render( # noqa: C901
207
216
  plain_module: plain_modules.PlainModule,
208
217
  args,
@@ -393,6 +402,12 @@ def main(): # noqa: C901
393
402
  return
394
403
 
395
404
  if args.dry_run:
405
+ try:
406
+ validate_linked_resources(plain_module)
407
+ except Exception as e:
408
+ console.error(f"Error: {str(e)}")
409
+ return
410
+
396
411
  console.info("Printing dry run output...\n")
397
412
  render_range = plain_spec.compute_render_range(args, plain_module.plain_source)
398
413
  print_dry_run_output(plain_module.plain_source, render_range)
@@ -0,0 +1,56 @@
1
+ from typing import Any
2
+
3
+ from plain2code_console import console
4
+ from render_machine.actions.base_action import BaseAction
5
+ from render_machine.implementation_code_helpers import ImplementationCodeHelpers
6
+ from render_machine.render_context import RenderContext
7
+
8
+
9
+ class DistillConformanceTestMemory(BaseAction):
10
+ """Distills the conformance tests fix journals into durable memories once all tests pass.
11
+
12
+ Runs exactly once per functional requirement, as the first postprocessing step. When no fix
13
+ attempts were needed there is nothing to distill and no API call is made. Distillation is best
14
+ effort - a failure must never fail the render, so the journals are kept for the next
15
+ distillation instead.
16
+
17
+ The memories land in the module's own memory store and are inherited by the next module in the
18
+ chain when its render starts.
19
+ """
20
+
21
+ SUCCESSFUL_OUTCOME = "conformance_test_memory_distilled"
22
+
23
+ def execute(self, render_context: RenderContext, _previous_action_payload: Any | None):
24
+ journal = render_context.memory_manager.journal
25
+ fix_journals = journal.collect_all()
26
+ if not fix_journals:
27
+ return self.SUCCESSFUL_OUTCOME, None
28
+
29
+ console.info(f"Distilling conformance test fix learnings for functionality {render_context.frid_context.frid}.")
30
+
31
+ try:
32
+ _, existing_files_content = ImplementationCodeHelpers.fetch_existing_files(render_context.build_folder)
33
+ _, memory_files_content = render_context.memory_manager.fetch_memory_files(
34
+ render_context.memory_manager.memory_folder
35
+ )
36
+
37
+ response_files = render_context.codeplain_api.distill_conformance_test_memory(
38
+ frid=render_context.frid_context.frid,
39
+ plain_source_tree=render_context.plain_source_tree,
40
+ linked_resources=render_context.frid_context.linked_resources,
41
+ existing_files_content=existing_files_content,
42
+ memory_files_content=memory_files_content,
43
+ module_name=render_context.module_name,
44
+ required_modules=render_context.get_required_modules_functionalities(),
45
+ fix_journals=fix_journals,
46
+ run_state=render_context.run_state,
47
+ )
48
+
49
+ if response_files:
50
+ render_context.memory_manager.store_memory_files(response_files)
51
+ except Exception as e:
52
+ console.error(f"Failed to distill conformance test memory (keeping the journals): {e}")
53
+ return self.SUCCESSFUL_OUTCOME, None
54
+
55
+ journal.clear_all()
56
+ return self.SUCCESSFUL_OUTCOME, None