phronomy 0.25.0 → 0.27.0

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 (323) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +71 -0
  3. data/CONTRIBUTING.md +4 -4
  4. data/README.md +14 -7
  5. data/VERIFY.sh +27 -27
  6. data/benchmark/bench_agent_invoke.rb +26 -22
  7. data/benchmark/bench_context_assembler.rb +4 -5
  8. data/benchmark/bench_regression.rb +1 -1
  9. data/docs/architecture/agent-chat-and-state-ownership.md +147 -0
  10. data/docs/architecture/agent-configuration-and-tool-binding.md +139 -0
  11. data/docs/architecture/agent-context.md +5 -3
  12. data/docs/architecture/agent-transition-ownership.md +89 -0
  13. data/docs/architecture/before-llm-input.md +6 -0
  14. data/docs/architecture/context-management.md +30 -0
  15. data/docs/architecture/context-preparation-steps.md +90 -0
  16. data/docs/architecture/entry-action-and-team-wording.md +72 -0
  17. data/docs/architecture/execution-metadata-and-values.md +80 -0
  18. data/docs/architecture/generator-verifier-ownership.md +111 -0
  19. data/docs/architecture/multi-agent-handoff.md +8 -2
  20. data/docs/architecture/persistence-refactoring-plan.md +50 -0
  21. data/docs/architecture/persistence.md +29 -6
  22. data/docs/architecture/refactoring-closure.md +334 -0
  23. data/docs/architecture/remaining-refactoring-plan.md +374 -0
  24. data/docs/architecture/rubyllm-2-token-ownership.md +82 -0
  25. data/docs/architecture/tool-schema-recording-gap.md +50 -0
  26. data/docs/architecture/tracing.md +4 -4
  27. data/docs/architecture/workflow-terminal-ownership-design.md +104 -0
  28. data/docs/architecture.md +209 -0
  29. data/docs/async-composition.md +205 -0
  30. data/docs/decisions/010-cooperative-first-concurrency.md +23 -23
  31. data/docs/decisions/014-unified-persistence-durable-state.md +11 -0
  32. data/docs/decisions/024-event-loop-single-writer-agent-runtime.md +5 -1
  33. data/docs/decisions/025-process-local-agent-ownership-and-runtime-admission.md +13 -3
  34. data/docs/decisions/026-workflow-runtime-admission-and-durable-terminal-barrier.md +5 -1
  35. data/docs/decisions/030-agent-handoff-domain-and-durable-responsibility.md +5 -0
  36. data/docs/decisions/031-durable-multi-agent-coordination.md +5 -0
  37. data/docs/decisions/032-storage-backend-composition.md +80 -0
  38. data/docs/decisions/033-domain-persistence-ownership.md +79 -0
  39. data/docs/decisions/034-handoff-runner-coordination-ownership.md +76 -0
  40. data/docs/decisions/035-tool-executor-capability-ownership.md +68 -0
  41. data/docs/decisions/036-context-contract-ownership.md +86 -0
  42. data/docs/decisions/037-common-definition-ownership.md +62 -0
  43. data/docs/decisions/038-responsibility-based-source-layout.md +131 -0
  44. data/docs/decisions/039-runtime-configuration-lifecycle-ownership.md +74 -0
  45. data/docs/decisions/040-configuration-default-composition.md +94 -0
  46. data/docs/decisions/041-feature-owned-identity-registries.md +100 -0
  47. data/docs/decisions/042-feature-owned-execution-state.md +106 -0
  48. data/docs/decisions/043-storage-execution-constraint-notifications.md +75 -0
  49. data/docs/decisions/044-agent-default-and-one-shot-composition.md +106 -0
  50. data/docs/decisions/045-worker-input-restriction-ownership.md +100 -0
  51. data/docs/decisions/046-agent-responsibility-layout-and-shared-records.md +110 -0
  52. data/docs/decisions/047-recovered-execution-continuation-contract.md +116 -0
  53. data/docs/decisions/048-dispatch-preparation-worker-ownership.md +120 -0
  54. data/docs/decisions/049-initial-preparation-worker-ownership.md +111 -0
  55. data/docs/decisions/050-approval-resume-snapshot-and-commit-ownership.md +98 -0
  56. data/docs/decisions/051-execution-outcome-worker-ownership.md +151 -0
  57. data/docs/decisions/052-tool-invocation-restoration-ownership.md +92 -0
  58. data/docs/decisions/053-shared-state-coordination-ownership.md +71 -0
  59. data/docs/decisions/054-workflow-terminal-save-single-owner.md +76 -0
  60. data/docs/decisions/055-terminal-observer-failure-settlement.md +60 -0
  61. data/docs/decisions/056-workflow-terminal-policy-ownership.md +87 -0
  62. data/docs/decisions/057-storage-transaction-boundaries.md +73 -0
  63. data/docs/decisions/058-neutral-storage-primitives.md +78 -0
  64. data/docs/decisions/README.md +35 -6
  65. data/docs/design/durable-semantic-coordination/IMPLEMENTATION_DESIGN_V2.md +6 -0
  66. data/docs/design/durable-semantic-coordination/IMPLEMENTATION_REPORT.md +6 -0
  67. data/docs/features.md +21 -12
  68. data/docs/getting-started.md +10 -10
  69. data/docs/migrations/0.15.md +5 -0
  70. data/docs/migrations/durable-semantic-coordination-v2.md +7 -1
  71. data/docs/migrations/handoff-runner-multi-agent.md +35 -0
  72. data/docs/migrations/neutral-storage-spi.md +43 -0
  73. data/docs/migrations/parallel-tool-chat-removal.md +49 -0
  74. data/docs/migrations/shared-state-multi-agent.md +44 -0
  75. data/docs/migrations/storage-backend-composition.md +117 -0
  76. data/docs/migrations/storage-transaction-boundaries.md +74 -0
  77. data/docs/persistence-backends.md +162 -204
  78. data/docs/runtime-and-concurrency.md +205 -60
  79. data/lib/phronomy/agent/api/agent.rb +17 -0
  80. data/lib/phronomy/agent/async_event_api.rb +2 -2
  81. data/lib/phronomy/agent/base.rb +55 -251
  82. data/lib/phronomy/{agent.rb → agent/composition/run_once.rb} +4 -13
  83. data/lib/phronomy/agent/context/capability/base.rb +67 -26
  84. data/lib/phronomy/agent/context/capability/tool_executor.rb +62 -0
  85. data/lib/phronomy/agent/{context_assembler.rb → context_assembly/context_assembler.rb} +143 -88
  86. data/lib/phronomy/agent/{context_importer.rb → context_assembly/context_importer.rb} +2 -2
  87. data/lib/phronomy/agent/{ruby_llm_materializer.rb → context_assembly/ruby_llm_materializer.rb} +4 -7
  88. data/lib/phronomy/agent/context_assembly/runtime_chat_builder.rb +36 -0
  89. data/lib/phronomy/agent/context_assembly/saved_context_reader.rb +53 -0
  90. data/lib/phronomy/agent/context_assembly/state_writer.rb +165 -0
  91. data/lib/phronomy/agent/context_assembly/token_budget_resolver.rb +22 -0
  92. data/lib/phronomy/agent/{context_plan.rb → context_contract/context_plan.rb} +1 -1
  93. data/lib/phronomy/agent/{context_policy_input.rb → context_contract/context_policy_input.rb} +6 -6
  94. data/lib/phronomy/agent/{llm_input_build_context.rb → context_contract/llm_input_build_context.rb} +1 -1
  95. data/lib/phronomy/agent/{llm_input_manifest.rb → context_contract/llm_input_manifest.rb} +20 -20
  96. data/lib/phronomy/agent/{llm_input_patch.rb → context_contract/llm_input_patch.rb} +2 -2
  97. data/lib/phronomy/agent/{agent_execution.rb → execution/agent_execution.rb} +8 -4
  98. data/lib/phronomy/agent/{agent_invocation.rb → execution/agent_invocation.rb} +8 -13
  99. data/lib/phronomy/agent/{agent_invocation_session_builder.rb → execution/agent_invocation_session_builder.rb} +20 -96
  100. data/lib/phronomy/agent/execution/approval_resume_commit.rb +108 -0
  101. data/lib/phronomy/agent/execution/dispatch_preparation.rb +305 -0
  102. data/lib/phronomy/agent/{exact_execution.rb → execution/exact_execution.rb} +12 -13
  103. data/lib/phronomy/agent/{execution_cancellation.rb → execution/execution_cancellation.rb} +2 -3
  104. data/lib/phronomy/agent/execution/execution_coordinator.rb +1925 -0
  105. data/lib/phronomy/agent/execution/execution_failure.rb +30 -0
  106. data/lib/phronomy/agent/execution/execution_metadata.rb +53 -0
  107. data/lib/phronomy/agent/execution/execution_outcome_committer.rb +344 -0
  108. data/lib/phronomy/agent/execution/execution_registry.rb +459 -0
  109. data/lib/phronomy/agent/execution/execution_session_runner.rb +118 -0
  110. data/lib/phronomy/agent/execution/initial_preparation.rb +421 -0
  111. data/lib/phronomy/agent/execution/invocation_transitions.rb +86 -0
  112. data/lib/phronomy/agent/{phase_machine_builder.rb → execution/phase_machine_builder.rb} +22 -73
  113. data/lib/phronomy/agent/{provider_call_outcome.rb → execution/provider_call_outcome.rb} +9 -9
  114. data/lib/phronomy/agent/execution/runtime_record_encoder.rb +210 -0
  115. data/lib/phronomy/agent/{handoff_context.rb → handoff/handoff_context.rb} +2 -2
  116. data/lib/phronomy/agent/handoff/handoff_execution_coordinator.rb +15 -0
  117. data/lib/phronomy/agent/handoff/handoff_outcome_committer.rb +131 -0
  118. data/lib/phronomy/agent/{handoff_state.rb → handoff/handoff_state.rb} +1 -1
  119. data/lib/phronomy/agent/{journal_projection.rb → journal/journal_projection.rb} +4 -0
  120. data/lib/phronomy/agent/{journal_record.rb → journal/journal_record.rb} +3 -3
  121. data/lib/phronomy/agent/{llm_call_record.rb → journal/llm_call_record.rb} +2 -2
  122. data/lib/phronomy/agent/{agent_root.rb → lifecycle/agent_root.rb} +6 -2
  123. data/lib/phronomy/agent/lifecycle/default_persistence.rb +29 -0
  124. data/lib/phronomy/{engine/runtime/agent_ownership_registry.rb → agent/lifecycle/ownership_registry.rb} +24 -10
  125. data/lib/phronomy/{agent_already_exists_error.rb → agent/lifecycle_contract/agent_already_exists_error.rb} +2 -0
  126. data/lib/phronomy/{agent_busy_error.rb → agent/lifecycle_contract/agent_busy_error.rb} +2 -0
  127. data/lib/phronomy/{agent_purged_error.rb → agent/lifecycle_contract/agent_purged_error.rb} +2 -0
  128. data/lib/phronomy/agent/lifecycle_contract/handoff_error.rb +7 -0
  129. data/lib/phronomy/{stream_callback_error.rb → agent/lifecycle_contract/stream_callback_error.rb} +2 -0
  130. data/lib/phronomy/agent/persistence/agent_repository.rb +61 -0
  131. data/lib/phronomy/agent/persistence/codec.rb +358 -0
  132. data/lib/phronomy/agent/persistence/execution_repository.rb +108 -0
  133. data/lib/phronomy/agent/persistence/handoff_state_repository.rb +58 -0
  134. data/lib/phronomy/agent/persistence/journal_repository.rb +54 -0
  135. data/lib/phronomy/agent/persistence/queries.rb +61 -0
  136. data/lib/phronomy/agent/persistence/storage_schema.rb +24 -0
  137. data/lib/phronomy/agent/persistence/watermark.rb +27 -0
  138. data/lib/phronomy/agent/recovery/invocation_restorer.rb +132 -0
  139. data/lib/phronomy/agent/{recovery_coordinator → recovery/recovery_coordinator}/continuation.rb +21 -45
  140. data/lib/phronomy/agent/{recovery_coordinator → recovery/recovery_coordinator}/installation.rb +36 -41
  141. data/lib/phronomy/agent/{recovery_coordinator → recovery/recovery_coordinator}/resolution.rb +37 -40
  142. data/lib/phronomy/agent/{recovery_coordinator.rb → recovery/recovery_coordinator.rb} +9 -13
  143. data/lib/phronomy/agent/recovery/recovery_support.rb +227 -0
  144. data/lib/phronomy/agent/selection/candidate.rb +1 -1
  145. data/lib/phronomy/agent/{approval_evaluation_request.rb → tool_execution/approval_evaluation_request.rb} +1 -12
  146. data/lib/phronomy/agent/{tool_approval_request.rb → tool_execution/tool_approval_request.rb} +1 -10
  147. data/lib/phronomy/agent/tool_execution/tool_binding.rb +90 -0
  148. data/lib/phronomy/agent/{tool_call_intercepted.rb → tool_execution/tool_call_intercepted.rb} +2 -2
  149. data/lib/phronomy/agent/{tool_definition_set.rb → tool_execution/tool_definition_set.rb} +9 -4
  150. data/lib/phronomy/agent/{tool_invocation.rb → tool_execution/tool_invocation.rb} +69 -34
  151. data/lib/phronomy/agent/{tool_invocation_session_builder.rb → tool_execution/tool_invocation_session_builder.rb} +2 -2
  152. data/lib/phronomy/common/configuration_error.rb +7 -0
  153. data/lib/phronomy/common/error.rb +5 -0
  154. data/lib/phronomy/{agent → common/values}/immutable.rb +9 -1
  155. data/lib/phronomy/common/values/serializable.rb +32 -0
  156. data/lib/phronomy/{configuration.rb → configuration/configuration.rb} +14 -5
  157. data/lib/phronomy/configuration/global_configuration.rb +26 -0
  158. data/lib/phronomy/content_store/storage_schema.rb +11 -0
  159. data/lib/phronomy/content_store/stored_contents.rb +43 -0
  160. data/lib/phronomy/engine/backpressure_error.rb +7 -0
  161. data/lib/phronomy/{blocking.rb → engine/blocking.rb} +15 -8
  162. data/lib/phronomy/engine/cancellation_error.rb +7 -0
  163. data/lib/phronomy/engine/concurrency/cancellation_token.rb +4 -0
  164. data/lib/phronomy/engine/concurrency/offload_pool.rb +29 -16
  165. data/lib/phronomy/engine/concurrency/operation_binding.rb +43 -0
  166. data/lib/phronomy/engine/concurrency/physical_completion_task.rb +4 -62
  167. data/lib/phronomy/engine/concurrency/result_collector.rb +99 -0
  168. data/lib/phronomy/engine/concurrency/result_composition.rb +145 -0
  169. data/lib/phronomy/engine/concurrency/subscriptions.rb +68 -0
  170. data/lib/phronomy/engine/concurrency/worker_input_restricted.rb +14 -0
  171. data/lib/phronomy/engine/event_loop.rb +160 -626
  172. data/lib/phronomy/engine/event_loop_reentrancy_error.rb +8 -0
  173. data/lib/phronomy/engine/execution.rb +229 -0
  174. data/lib/phronomy/engine/execution_cancellation_error.rb +14 -0
  175. data/lib/phronomy/engine/execution_receiver.rb +65 -0
  176. data/lib/phronomy/engine/execution_timeout_error.rb +14 -0
  177. data/lib/phronomy/engine/fsm_protocol.rb +14 -0
  178. data/lib/phronomy/engine/fsm_session.rb +38 -31
  179. data/lib/phronomy/{invalid_async_entry_action_error.rb → engine/invalid_async_entry_action_error.rb} +3 -1
  180. data/lib/phronomy/{invalid_async_transition_action_error.rb → engine/invalid_async_transition_action_error.rb} +3 -1
  181. data/lib/phronomy/{invalid_async_workflow_action_error.rb → engine/invalid_async_workflow_action_error.rb} +3 -1
  182. data/lib/phronomy/{invocation_context.rb → engine/invocation_context.rb} +13 -1
  183. data/lib/phronomy/engine/pool_shutdown_error.rb +7 -0
  184. data/lib/phronomy/engine/recursion_limit_error.rb +7 -0
  185. data/lib/phronomy/engine/runtime/timer_queue.rb +11 -0
  186. data/lib/phronomy/engine/runtime.rb +80 -84
  187. data/lib/phronomy/engine/runtime_shutdown_error.rb +7 -0
  188. data/lib/phronomy/engine/runtime_shutdown_reentrancy_error.rb +7 -0
  189. data/lib/phronomy/engine/scheduler_reentrancy_error.rb +9 -0
  190. data/lib/phronomy/engine/{task.rb → task_result.rb} +101 -42
  191. data/lib/phronomy/engine/timeout_error.rb +7 -0
  192. data/lib/phronomy/filter/contract/filter_block_error.rb +14 -0
  193. data/lib/phronomy/generation/generator_verifier/agent_result_receiver.rb +89 -0
  194. data/lib/phronomy/generation/generator_verifier/pipeline_state.rb +57 -0
  195. data/lib/phronomy/generation/generator_verifier/workflow_builder.rb +112 -0
  196. data/lib/phronomy/generation/generator_verifier.rb +118 -0
  197. data/lib/phronomy/generation/low_confidence_error.rb +14 -0
  198. data/lib/phronomy/llm_adapter/base.rb +2 -2
  199. data/lib/phronomy/llm_context_window/token_budget.rb +6 -7
  200. data/lib/phronomy/llm_contract/authentication_error.rb +7 -0
  201. data/lib/phronomy/{context_budget_exceeded_error.rb → llm_contract/context_budget_exceeded_error.rb} +2 -0
  202. data/lib/phronomy/llm_contract/context_length_error.rb +7 -0
  203. data/lib/phronomy/llm_contract/rate_limit_error.rb +7 -0
  204. data/lib/phronomy/{token_usage.rb → llm_contract/token_usage.rb} +2 -2
  205. data/lib/phronomy/llm_contract/transport_error.rb +7 -0
  206. data/lib/phronomy/multi_agent/admission_registry.rb +22 -2
  207. data/lib/phronomy/multi_agent/durable_subagent_coordinator.rb +8 -8
  208. data/lib/phronomy/{agent → multi_agent}/handoff_runner.rb +18 -17
  209. data/lib/phronomy/multi_agent/orchestrator.rb +36 -68
  210. data/lib/phronomy/multi_agent/persistence/codec.rb +55 -0
  211. data/lib/phronomy/multi_agent/persistence/queries.rb +30 -0
  212. data/lib/phronomy/multi_agent/persistence/team_execution_repository.rb +108 -0
  213. data/lib/phronomy/multi_agent/persistence/team_repository.rb +61 -0
  214. data/lib/phronomy/{agent → multi_agent}/shared_state.rb +56 -39
  215. data/lib/phronomy/multi_agent/storage_contract/team_storage_schema.rb +15 -0
  216. data/lib/phronomy/multi_agent/team_coordinator.rb +21 -18
  217. data/lib/phronomy/multi_agent/team_execution.rb +1 -1
  218. data/lib/phronomy/{engine/runtime → multi_agent}/team_ownership_registry.rb +14 -4
  219. data/lib/phronomy/multi_agent/team_root.rb +1 -1
  220. data/lib/phronomy/output_parser/contract/parse_error.rb +7 -0
  221. data/lib/phronomy/persistence/api/persistence.rb +140 -0
  222. data/lib/phronomy/persistence/migration/initial_format_migration.rb +19 -19
  223. data/lib/phronomy/persistence_composition/repositories.rb +77 -0
  224. data/lib/phronomy/persistence_composition/storage_schema.rb +24 -0
  225. data/lib/phronomy/{execution_rehydration_required_error.rb → recovery/execution_rehydration_required_error.rb} +2 -0
  226. data/lib/phronomy/{recovery.rb → recovery/recovery.rb} +1 -1
  227. data/lib/phronomy/runtime_composition/agent_defaults.rb +7 -0
  228. data/lib/phronomy/runtime_composition/configuration_defaults.rb +9 -0
  229. data/lib/phronomy/runtime_composition/global_runtime.rb +19 -0
  230. data/lib/phronomy/storage/backend.rb +101 -0
  231. data/lib/phronomy/storage/backends/in_memory.rb +157 -0
  232. data/lib/phronomy/storage/blob_conflict_error.rb +10 -0
  233. data/lib/phronomy/storage/blobs.rb +31 -0
  234. data/lib/phronomy/storage/condition.rb +25 -0
  235. data/lib/phronomy/storage/condition_failed_error.rb +16 -0
  236. data/lib/phronomy/storage/conflict_error.rb +9 -0
  237. data/lib/phronomy/{persistence → storage}/durable_record.rb +12 -12
  238. data/lib/phronomy/storage/entry.rb +33 -0
  239. data/lib/phronomy/storage/guard_ref.rb +13 -0
  240. data/lib/phronomy/storage/not_found_error.rb +9 -0
  241. data/lib/phronomy/storage/record_codec.rb +177 -0
  242. data/lib/phronomy/storage/records.rb +61 -0
  243. data/lib/phronomy/storage/resource.rb +126 -0
  244. data/lib/phronomy/storage/scope.rb +25 -0
  245. data/lib/phronomy/storage/serialization_error.rb +9 -0
  246. data/lib/phronomy/storage/streams.rb +44 -0
  247. data/lib/phronomy/storage/transaction_error.rb +10 -0
  248. data/lib/phronomy/storage/unique_constraint_error.rb +17 -0
  249. data/lib/phronomy/storage/unsupported_backend_error.rb +9 -0
  250. data/lib/phronomy/storage/validation.rb +53 -0
  251. data/lib/phronomy/storage/view.rb +131 -0
  252. data/lib/phronomy/testing/eval/scorer/llm_judge.rb +5 -3
  253. data/lib/phronomy/testing/fake_clock.rb +13 -9
  254. data/lib/phronomy/testing/persistence_contract/a_content_store.rb +1 -1
  255. data/lib/phronomy/testing/persistence_contract/a_journal_repository.rb +4 -4
  256. data/lib/phronomy/testing/persistence_contract/a_persistence_backend.rb +10 -7
  257. data/lib/phronomy/testing/persistence_contract/a_workflow_state_repository.rb +2 -2
  258. data/lib/phronomy/testing/persistence_contract/an_agent_repository.rb +6 -6
  259. data/lib/phronomy/testing/persistence_contract/an_execution_repository.rb +6 -6
  260. data/lib/phronomy/testing/persistence_contract/coordination_repositories.rb +8 -8
  261. data/lib/phronomy/testing/persistence_contract/neutral_storage_primitives.rb +263 -0
  262. data/lib/phronomy/testing/persistence_contract/storage_transaction_boundaries.rb +123 -0
  263. data/lib/phronomy/testing/persistence_contract.rb +4 -0
  264. data/lib/phronomy/tool/contract/tool_error.rb +7 -0
  265. data/lib/phronomy/tools/agent.rb +6 -6
  266. data/lib/phronomy/vector_store/async_backend.rb +5 -5
  267. data/lib/phronomy/vector_store/embeddings/base.rb +2 -2
  268. data/lib/phronomy/version.rb +1 -1
  269. data/lib/phronomy/{workflow.rb → workflow/execution/workflow.rb} +10 -8
  270. data/lib/phronomy/{workflow_context.rb → workflow/execution/workflow_context.rb} +4 -0
  271. data/lib/phronomy/workflow/execution/workflow_context_ownership_error.rb +7 -0
  272. data/lib/phronomy/workflow/execution/workflow_execution_registry.rb +188 -0
  273. data/lib/phronomy/{workflow_runner.rb → workflow/execution/workflow_runner.rb} +126 -75
  274. data/lib/phronomy/workflow/execution/workflow_terminal_policy.rb +40 -0
  275. data/lib/phronomy/workflow/persistence/codec.rb +153 -0
  276. data/lib/phronomy/workflow/persistence/state_repository.rb +57 -0
  277. data/lib/phronomy/workflow/phase_machine_builder.rb +8 -8
  278. data/lib/phronomy/workflow/storage_contract/workflow_storage_schema.rb +9 -0
  279. data/lib/phronomy.rb +52 -94
  280. data/scripts/api_snapshot.rb +4 -2
  281. data/scripts/storage_spi_snapshot.rb +36 -0
  282. data/sig/phronomy/agent.rbs +4 -5
  283. data/sig/phronomy/execution_receiver.rbs +34 -0
  284. data/sig/phronomy/extensions.rbs +5 -5
  285. data/sig/phronomy/handoff.rbs +4 -2
  286. data/sig/phronomy/multi_agent.rbs +19 -3
  287. data/sig/phronomy/persistence.rbs +7 -91
  288. data/sig/phronomy/runtime.rbs +34 -7
  289. data/sig/phronomy/storage.rbs +174 -0
  290. data/sig/phronomy/tool.rbs +11 -2
  291. data/sig/phronomy/workflow.rbs +1 -1
  292. metadata +236 -99
  293. data/lib/phronomy/agent/execution_coordinator.rb +0 -3138
  294. data/lib/phronomy/agent/handoff_execution_coordinator.rb +0 -143
  295. data/lib/phronomy/agent/recovery_support.rb +0 -504
  296. data/lib/phronomy/agent/token_budget_resolver.rb +0 -70
  297. data/lib/phronomy/agent/tool_executor.rb +0 -55
  298. data/lib/phronomy/generator_verifier.rb +0 -369
  299. data/lib/phronomy/invalid_context_budget_configuration_error.rb +0 -8
  300. data/lib/phronomy/multi_agent/fan_out_invocation.rb +0 -137
  301. data/lib/phronomy/multi_agent/fan_out_session_builder.rb +0 -118
  302. data/lib/phronomy/multi_agent/parallel_tool_chat.rb +0 -116
  303. data/lib/phronomy/persistence/durable_codec.rb +0 -706
  304. data/lib/phronomy/persistence/in_memory.rb +0 -690
  305. data/lib/phronomy/persistence/repository_facades.rb +0 -535
  306. data/lib/phronomy/persistence.rb +0 -276
  307. data/lib/phronomy/ruby_llm_patches.rb +0 -24
  308. data/lib/phronomy/workflow_recovery.rb +0 -123
  309. /data/lib/phronomy/agent/{context_candidate_resolver.rb → context_assembly/context_candidate_resolver.rb} +0 -0
  310. /data/lib/phronomy/agent/{context_policy_input_builder.rb → context_assembly/context_policy_input_builder.rb} +0 -0
  311. /data/lib/phronomy/agent/{context_plan_validator.rb → context_contract/context_plan_validator.rb} +0 -0
  312. /data/lib/phronomy/agent/{context_policy.rb → context_contract/context_policy.rb} +0 -0
  313. /data/lib/phronomy/agent/{llm_operation_result.rb → execution/llm_operation_result.rb} +0 -0
  314. /data/lib/phronomy/agent/{handoff.rb → handoff/handoff.rb} +0 -0
  315. /data/lib/phronomy/agent/{handoff_capability_factory.rb → handoff/handoff_capability_factory.rb} +0 -0
  316. /data/lib/phronomy/agent/{handoff_policy.rb → handoff/handoff_policy.rb} +0 -0
  317. /data/lib/phronomy/agent/{handoff_projection.rb → handoff/handoff_projection.rb} +0 -0
  318. /data/lib/phronomy/agent/{handoff_request.rb → handoff/handoff_request.rb} +0 -0
  319. /data/lib/phronomy/{canonical_json.rb → common/canonical_json.rb} +0 -0
  320. /data/lib/phronomy/{diagnostics.rb → engine/diagnostics.rb} +0 -0
  321. /data/lib/phronomy/{event.rb → engine/event.rb} +0 -0
  322. /data/lib/phronomy/{metrics.rb → engine/metrics.rb} +0 -0
  323. /data/lib/phronomy/{runnable.rb → engine/runnable.rb} +0 -0
@@ -0,0 +1,111 @@
1
+ # GeneratorVerifier ownership and event contract
2
+
3
+ ## Role and problem
4
+
5
+ GeneratorVerifier exposes the draft/review/retry pattern. An application supplies
6
+ two Agent classes, prompt builders, optional result parsers and convergence
7
+ settings. invoke runs the Workflow and returns the existing Result, optionally
8
+ raising LowConfidenceError. Agent completion arrives as Workflow events; Workflow
9
+ entry actions return context immediately rather than awaiting Agent Tasks.
10
+
11
+ R08 and D08 describe the same issue: a 199-line build_workflow mixes the graph
12
+ with Agent startup, response parsing/normalization and failure notification.
13
+ Nested PipelineState also occupies the public facade's source file. Separating
14
+ only the file without removing receiver-to-facade private calls would leave the
15
+ responsibility problem in place.
16
+
17
+ ## Owners and reading order
18
+
19
+ | Owner | Responsibility |
20
+ |---|---|
21
+ | GeneratorVerifier | Public settings and Result; cached Workflow assembly, invocation, default JSON parser fallbacks and final confidence/raise policy. |
22
+ | GeneratorVerifier::WorkflowBuilder | Draft/review/finalize/failed graph, request IDs, prompt creation, Agent startup and convergence guard. |
23
+ | GeneratorVerifier::AgentResultReceiver | Separate draft/review payload conversion, common terminal-event classification and failure notification to the supplied Workflow. |
24
+ | GeneratorVerifier::PipelineState | Existing Workflow fields, request correlation, stale/duplicate rejection and EventLoop-owned state mutation. |
25
+
26
+ The last three constants are private. WorkflowBuilder and AgentResultReceiver
27
+ are new internal classes; PipelineState is the existing class moved with its
28
+ body and canonical name unchanged. The implementation lives in three files under
29
+ generation/generator_verifier. The public facade and Result keep their names and
30
+ locations; no loader changes or compatibility aliases are introduced.
31
+
32
+ The initial D08 sketch suggested multi_agent/generator_verifier_workflow.rb.
33
+ Since the prior layout work established generation as this pattern's owner,
34
+ the internal files now stay there instead of creating a second feature owner.
35
+ The new directory adds a module in directory-based analysis, not a public API.
36
+
37
+ WorkflowBuilder#build reads as a graph: named entries, then ordered transitions.
38
+ start_draft/start_review describe request preparation and dispatch. The receiver's
39
+ draft_payload and review_payload retain different meanings. Their common listener
40
+ has only the two internally selected phases; it is not a public configurable
41
+ pipeline. It shares the same terminal/error rules rather than combining response
42
+ formats into an options-driven generic parser.
43
+
44
+ Default parsers remain explicit callables captured by the facade. Clamp and
45
+ citation normalization move to their receiver owner. The old __send__ calls back
46
+ to facade helpers disappear. The existing private Agent event-sink entry point
47
+ is still called via send; changing that cooperation API is outside this scope.
48
+
49
+ ## Preserved ordering and failure contract
50
+
51
+ - Each Agent is constructed once, lazily during the first successful Workflow
52
+ build. The cached Workflow and Agent instances are reused. Each invoke gets a
53
+ fresh Workflow context. No locking or new concurrency policy is introduced.
54
+ - Each request gets a new UUID and a merged context before prompt construction.
55
+ The listener captures that request ID and the context's stable Workflow ID.
56
+ Workflow closures see the completed Workflow assignment before any entry runs.
57
+ - Entry actions start asynchronous Agent work and return next_state, never a
58
+ TaskResult. Inline completion remains valid because signal queues a Workflow
59
+ event. Unknown/nonterminal Agent events are ignored.
60
+ - done parses output, normalizes the phase-specific payload and signals the
61
+ matching completed event. StandardError from parsing, normalization or success
62
+ notification is signalled as the corresponding failed event with the same
63
+ exception object. Failure-notification exceptions are not retried or wrapped.
64
+ - error/timeout/cancelled use the payload error or the same phase-specific
65
+ fallback message. approval_required remains a pipeline failure. A false return
66
+ from signal is returned without a retry or a new failure event.
67
+ - PipelineState accepts only the current request ID. It clears the accepted ID,
68
+ increments iteration after draft completion, appends feedback after review,
69
+ and consumes old/duplicate results before any transition. The receiver does
70
+ not mutate context or add its own deduplication; stale done payloads can still
71
+ be parsed before the state rejects their correlated event.
72
+ - Review completes when both the lower normalized score meets threshold and
73
+ approval is literal true, or when the iteration limit has been reached.
74
+ Otherwise it returns to draft and passes the last feedback to its prompt.
75
+ - Final Result trust remains confidence >= threshold. At the iteration limit,
76
+ high confidence with approved=false can therefore still produce trusted=true.
77
+ A nonpositive limit still executes one draft/review cycle. These are observed
78
+ existing semantics, not behavior fixes hidden in this extraction.
79
+
80
+ Public initialize/invoke parameters, Result fields/trusted? alias, parser
81
+ fallbacks, score/citation normalization, error messages and PipelineState fields
82
+ remain unchanged. Agent/Workflow/Engine/Storage behavior and SQL are not modified.
83
+ Private clamp/normalize_citations implementations relocate; private overrides are
84
+ not treated as additional supported public APIs.
85
+
86
+ ## Verification and trade-off
87
+
88
+ Thirty-nine behavior examples pass unchanged on Refactor 40 and the candidate.
89
+ They cover inline completion, ignored progress, pending Task returns, both phases'
90
+ error/timeout/cancelled/approval failures, parser and notification failures,
91
+ request correlation, duplicate/old callbacks, clamping, literal approval, final
92
+ trust, iteration limits, caching, fresh state and config forwarding. Existing
93
+ delayed-callback and WebMock integration examples cover the real Workflow path.
94
+
95
+ A separate process comparison preserves public methods, parameters, constants,
96
+ Result shape, the private state name/field schema/defaults and Runtime inactivity.
97
+ Stable/Beta snapshots do not list GeneratorVerifier, so this explicit comparison
98
+ supplements those existing gates. Core/integration/examples/real SQLite, type,
99
+ style, annotations and isolated gem checks are included in distribution evidence.
100
+ Live PostgreSQL, live LLM, candidate CI and performance are not run for this scope.
101
+
102
+ The facade is 369 -> 118 lines. Workflow definition is 199 -> 34 lines, with a
103
+ 12-line facade assembly method. The three internal files are 112/89/57 lines,
104
+ for 376 total, seven more than before. Two new classes and one moved class cost
105
+ additional files; they give graph, receiver and state independent reading units.
106
+ Directory-level dependency counts increase with that physical partition; cycle
107
+ membership is unchanged. This is responsibility separation, not cycle removal.
108
+
109
+ Refactor 41 is applied and independently verified at core e87eb77f, tree
110
+ 14dc8a546a4fd96e19e0713f7480ca2efa3c331a. All nine files and the full tree match.
111
+ R08/D08 is closed. The published diagram is applied41-01. R09 and R10 remain.
@@ -20,7 +20,13 @@ returns control to the caller. Handoff changes the active Agent for the current
20
20
  coordination lifetime.
21
21
 
22
22
  Normative Handoff intent is
23
- [ADR-030](../decisions/030-agent-handoff-domain-and-durable-responsibility.md).
23
+ [ADR-030](../decisions/030-agent-handoff-domain-and-durable-responsibility.md),
24
+ with the Runner ownership amendment in
25
+ [ADR-034](../decisions/034-handoff-runner-coordination-ownership.md).
26
+
27
+ The Runner owns the cross-Agent turn. Handoff edges, Policy, Context and
28
+ Agent terminal/persistence integration remain in Agent during this first
29
+ migration step. See the [Runner migration](../migrations/handoff-runner-multi-agent.md).
24
30
 
25
31
  ## 2. Public API
26
32
 
@@ -32,7 +38,7 @@ handoff = Phronomy::Agent::Handoff.new(
32
38
  policy: policy
33
39
  )
34
40
 
35
- runner = Phronomy::Agent::HandoffRunner.new(
41
+ runner = Phronomy::MultiAgent::HandoffRunner.new(
36
42
  main_agent: triage,
37
43
  handoffs: [handoff]
38
44
  )
@@ -0,0 +1,50 @@
1
+ # Persistence responsibility refactoring plan
2
+
3
+ The Storage staged implementation reaches its bounded S3 cleanup in Refactor 36;
4
+ application verification remains. The broader initial review still has open
5
+ proposals recorded in the remaining responsibility plan.
6
+ [ADR-033](../decisions/033-domain-persistence-ownership.md) established domain
7
+ ownership; [ADR-058](../decisions/058-neutral-storage-primitives.md) now defines
8
+ the neutral Storage SPI. Historical raw contracts are not the current API.
9
+ See the [remaining responsibility plan](remaining-refactoring-plan.md) for the
10
+ applied commit pair and the [closure review](refactoring-closure.md) for the
11
+ final naming, placement and evidence boundary.
12
+
13
+ ## Target and current ownership
14
+
15
+ Domain repositories own record meanings, codecs, revisions and business
16
+ constraints. Storage owns typed neutral resources, Records/Streams/Blobs,
17
+ conditions and transaction scopes. Concrete InMemory and SQL drivers implement
18
+ physical operations. Composition selects implementations and assembles domain
19
+ wrappers; Storage does not import concrete domain implementations.
20
+
21
+ The public `Phronomy::Persistence` facade remains the application entry point.
22
+ It is distinct from `Phronomy::Storage`, the backend extension contract.
23
+ Directories express responsibility; existing public constants need not be
24
+ renamed to match every directory. The dependency graph is not a tree.
25
+
26
+ ## Stages
27
+
28
+ | Stage | Result |
29
+ |---|---|
30
+ | 1. Domain ownership | Refactor 09 moved schemas, repositories and queries to their domains. Later layout work placed record definitions and ownership contracts beside those features. |
31
+ | 2. Neutral contract | Refactors 34 and 35 unified the failure/transaction boundaries and replaced eight raw repository slots with Resources, Records/Streams/Blobs and guarded conditions. Core, InMemory, SQLite and PostgreSQL were migrated together. Applied SPI 2 passed S2c, including real PostgreSQL. |
32
+ | 3. Naming and placement | Refactor 36 retains the facade/SPI names, feature schemas, composition and reference-driver locations. Resource owns schema-reference normalization; generic Validation does not depend on Resource. Documentation records current status and historical boundaries. Distribution application verification remains separate. |
33
+
34
+ ## Invariants and gates
35
+
36
+ All repositories and ContentStore continue to join one backend transaction.
37
+ Splitting classes must not split commits. Codec response validation stays inside
38
+ the atomic boundary. IDs, revisions, journal positions, active constraints,
39
+ record type/version/payload and the F0/F1/F4/X0 limits remain unchanged.
40
+
41
+ Product API and Storage SPI snapshots, RBS, existing domain/backend conformance,
42
+ unit/integration suites, SQL examples and isolated gem loading verify the
43
+ implemented boundary. Record which tests ran against which tree: Refactor 35's
44
+ PostgreSQL CI is evidence for Refactor 35, not a claim that unpublished
45
+ Refactor 36 ran remotely. Refactor 36 does not change SQL or its public protocol.
46
+
47
+ Keep the applied-source diagram until the delivered candidate is applied and
48
+ verified. Remaining directory cycles and runtime collaboration are recorded,
49
+ not described as eliminated by moving files. Future behavior, performance or
50
+ distributed-operation work requires its own scope and evidence.
@@ -9,8 +9,31 @@
9
9
 
10
10
  ## 1. Durable boundary
11
11
 
12
- `Phronomy::Persistence` is the single durable-state backend abstraction for
13
- stateful Agents and durable Workflows.
12
+ `Phronomy::Persistence` is the domain-facing service for the single durable-state
13
+ transaction domain used by Agents, Teams, and Workflows. It composes a
14
+ `Storage::Backend`; storage implementations do not inherit the domain service.
15
+
16
+ The `storage/` directory owns record carriers, portable errors, repository views,
17
+ and the Backend contract. `storage/backends/` owns physical storage implementations.
18
+ The `agent/persistence/`, `multi_agent/persistence/`, and `workflow/persistence/`
19
+ directories own their domain codecs and repositories. Agent and Team result
20
+ queries live with those domains. `storage/record_codec.rb` contains only shared
21
+ record-envelope and scalar validation; it does not select a domain schema.
22
+ `persistence_composition/` assembles the domain repositories over one raw view.
23
+ The public `Phronomy::Persistence` entry point delegates to those components and
24
+ retains its observation-thread guard.
25
+ The root and transaction paths use the same facade construction, with transaction
26
+ facades bound to the raw backend view for that transaction.
27
+ See [ADR-032](../decisions/032-storage-backend-composition.md) and
28
+ [ADR-033](../decisions/033-domain-persistence-ownership.md).
29
+
30
+ Shared value copying belongs to `Values::Immutable` in `values/`. Agent records,
31
+ Team records, Recovery classifications, and Persistence result views use this
32
+ internal helper without borrowing an Agent implementation. It copies and freezes
33
+ Hash, Array, and String trees; other values pass through unchanged. Its separate
34
+ canonical JSON check delegates to `CanonicalJSON`. Each domain codec and repository owns its record schema, key normalization,
35
+ identity, and revision validation. Moving this helper
36
+ does not change record formats, transaction ownership, or recovery guarantees.
14
37
 
15
38
  | Repository | Durable authority |
16
39
  |---|---|
@@ -38,7 +61,7 @@ Durable examples include AgentRoot, Journal records, AgentExecution records,
38
61
  content/Manifest references, and durable Workflow snapshots.
39
62
 
40
63
  Runtime-only examples include FSMSession objects/IDs, AgentInvocation objects,
41
- Task instances/callbacks, EventLoop entries, Runtime admission entries, and
64
+ TaskResult instances/callbacks, EventLoop entries, Runtime admission entries, and
42
65
  in-flight Provider/Tool operation objects.
43
66
 
44
67
  Runtime/process loss removes Runtime-only objects but does not imply confirmed
@@ -70,7 +93,7 @@ Defined semantic durable transitions are atomic according to the Persistence
70
93
  transaction contract and conforming backend.
71
94
 
72
95
  Revision/watermark/CAS checks reject stale durable transitions with
73
- `Persistence::ConflictError` rather than silently merging/reloading competing
96
+ `Storage::ConflictError` rather than silently merging/reloading competing
74
97
  state.
75
98
 
76
99
  Conflict detection is not competing-execution exclusion and cannot undo an
@@ -85,7 +108,7 @@ The canonical logical/durable Workflow identity is `workflow_instance_id`, which
85
108
  is separate from one Runtime `fsm_session_id`.
86
109
 
87
110
  Workflow same-process admission is acquired before durable hydration and retained
88
- through the authoritative terminal/halted save barrier. The caller-facing Task
111
+ through the authoritative terminal/halted save barrier. The caller-facing TaskResult
89
112
  settles after that authoritative durable barrier.
90
113
 
91
114
  See
@@ -107,7 +130,7 @@ Phronomy does not claim arbitrary external exactly-once side effects.
107
130
  ## 7. Durable codec
108
131
 
109
132
  Durable backend exchange uses immutable
110
- `Phronomy::Persistence::DurableRecord` values with:
133
+ `Phronomy::Storage::DurableRecord` values with:
111
134
 
112
135
  ```text
113
136
  record_type
@@ -0,0 +1,334 @@
1
+ # Responsibility refactoring audit (S3)
2
+
3
+ ## Scope and acceptance state
4
+
5
+ The applied baseline is Refactor 43: core
6
+ `5c4c039273eb2324fcc9e9943ccf40bd1ffb3abd` and examples
7
+ `68a0bbd0e354b9e00bbfed728ad2b769b389ed8a` on `refactor/architecture`.
8
+ W1/W2, Storage S1/S2 and Refactor 36's S3 cleanup are applied and verified.
9
+ Refactor 37's D02, Refactor 38's R03/R11, Refactor 39's R06 and Refactor 40's R07
10
+ changes are applied and verified. Refactor 41's R08/D08 is applied and verified. Refactor 42 Tool binding and declaration rules are applied and verified.
11
+ Refactor 43 Chat/state ownership is applied and verified; R09 is closed.
12
+ Refactor 44 implements R10, pending application verification. The separate
13
+ Tool schema recording finding remains open.
14
+
15
+ The S3 audit and its bounded Storage cleanup are verified. The initial review
16
+ still contains open proposals. The previous remaining-work summary omitted still
17
+ unimplemented work. The original R/D proposals must not be marked complete just
18
+ because the later W/S sequence has reached its final step.
19
+
20
+ ## Names and locations retained
21
+
22
+ | Owner | Name and location | Reason |
23
+ |---|---|---|
24
+ | Application facade | `Phronomy::Persistence`, `persistence/api` | Users address domain repositories and queries. This class is not the neutral backend contract. |
25
+ | Domain persistence | Agent, MultiAgent and Workflow `persistence` directories | Codecs, durable meanings, result queries and business constraints belong to the feature. |
26
+ | Resource declarations | Agent persistence, Team/Workflow `storage_contract`, ContentStore | Schemas describe domain metadata; the nested roots keep existing Ruby identities without loading feature runtime just to obtain declarations. |
27
+ | Common storage | `Phronomy::Storage`, `storage` | Resource/Record/Stream/Blob, conditions and transactions describe backend-neutral mechanisms. |
28
+ | InMemory driver | `Storage::Backends::InMemory`, `storage/backends` | Implements physical operations over a supplied resource catalog. It does not choose domain schemas. |
29
+ | Repository assembly | `persistence_composition` | Gathers declarations and constructs the feature wrappers over one View. |
30
+ | SQL reference drivers | examples `shared/storage` and adapter entry points | SQL is a reference integration, not a core ActiveRecord dependency. Physical mapping is separate in `shared/persistence_storage_mapping.rb`. |
31
+ | Configuration and defaults | `configuration` / `runtime_composition` | Scalar settings and default factories do not own concrete Runtime/LLM/Tracing assembly. |
32
+
33
+ No facade rename, new generic dispatcher, compatibility alias or additional
34
+ ExecutionCoordinator split is needed to establish these boundaries.
35
+
36
+ ## Resource-reference ownership
37
+
38
+ GuardRef and the three closed Condition values accept either a Resource object
39
+ or a textual resource ID. Resource owns this type-specific normalization in an
40
+ internal cooperation method. Validation retains scalar and immutable-value
41
+ operations. The dependency is Resource to Validation, with no reverse reference.
42
+
43
+ A Resource object is retained by identity; an ID is validated, copied and frozen.
44
+ There is no duck-typed coercion or conversion of a foreign schema object to an
45
+ ID. View continues to reject an unregistered object even if its ID matches.
46
+ The public constructor signatures, result values, exceptions, scope lifecycle,
47
+ SQL operations and stored formats are unchanged.
48
+
49
+ ## Completed responsibility inventory
50
+
51
+ | Work | Current owner / evidence |
52
+ |---|---|
53
+ | Root layout and shared definitions | Eight direct-root namespace/version files; values and exceptions in common; entry-point loading and public identities guarded by source_layout_spec. |
54
+ | FSM terminal marker and live control | FSMProtocol/FSMSession in Engine; Workflow's result interpretation in WorkflowTerminalPolicy. |
55
+ | Workflow final save | One F1-aware implementation in WorkflowRunner; no WorkflowRecovery prepend override (W1/W2). |
56
+ | ExecutionCoordinator | EventLoop-side sequencing/acceptance; named preparation/persistence workers hold worker-side tasks. ToolInvocation owns its restoration sequence. |
57
+ | Multi-agent coordination | HandoffRunner and SharedState in MultiAgent; durable domain records retain their feature owners. |
58
+ | Public persistence queries | Agent/Team query traversal is separate from the public facade and repository assembly (D07). GeneratorVerifier ownership is applied and verified in Refactor 41 (R08/D08). |
59
+ | Storage | Neutral SPI 2 and all three backends validated; domain conditions and physical operations have distinct owners. |
60
+ | Final naming and documents | Retained names above, Resource/Validation cleanup, current stage status and historical migration guides reconciled in Refactor 36. |
61
+
62
+ The exact implemented names supersede early alternative sketches. For example,
63
+ WorkflowRunner kept its canonical constant in a feature-owned loader root rather
64
+ than being renamed to a nested class. Closing a goal does not require adopting
65
+ every early filename suggestion.
66
+
67
+ ## Initial-proposal reconciliation
68
+
69
+ The original review's R01/R02/R04/R05 and D01/D03-D07/D09 goals have current
70
+ implementations. R12 is the continuing test-review rule used when changing a
71
+ boundary, not a claim that all source-structure guards must disappear. A01's
72
+ shutdown boundary and the revised A02 removal are implemented.
73
+
74
+ The broader A proposals map to those same goals rather than adding another
75
+ independent set of tasks: A03 includes D02 and D08 (both verified);
76
+ A04's record/codec separation and neutral backend contract are implemented,
77
+ while composition review overlaps R09; A05 keeps the same public Tool Class and
78
+ places ToolExecutor beside the capability contract, preserving its documented
79
+ bridge to Engine; A06's execution/context separation is implemented but its
80
+ shared recovery metadata concern is now resolved by Refactor 38 under R03. No claim is made that all
81
+ Agent directory cycles disappeared.
82
+
83
+ The following table tracks the previously omitted initial items, including
84
+ completed follow-ups. The remaining items are not regressions caused by Refactor 35.
85
+
86
+ | Initial item | Current assessment and follow-up |
87
+ |---|---|
88
+ | D02 | Applied and verified in Refactor 37: callers construct OperationBinding directly and retain ordering and cancellation contracts. |
89
+ | R03 | Applied and verified in Refactor 38: ExecutionMetadata owns shared durable keys and snapshots; ToolInvocation owns stable identity. Earlier restoration behavior is preserved. |
90
+ | R06 | Applied and verified in Refactor 39: InvocationTransitions owns Tool events, ordered external transitions and state declarations for both builders and Invocation. |
91
+ | R07 | Applied and verified in Refactor 40: ContextAssembler describes preparation through private instruction, record-candidate, candidate-merge and current-input operations. |
92
+ | R08 / D08 | Applied and verified in Refactor 41, one overlapping item: GeneratorVerifier keeps its facade and Result; private WorkflowBuilder, AgentResultReceiver and the moved PipelineState separate graph construction, reception and state. |
93
+ | R09 | Applied and verified in Refactors 42 and 43: Tool binding, declaration rules, Chat construction and explicit state ownership. Existing DSL behavior is retained. |
94
+ | R10 | Implemented in Refactor 44: private actions describe prepared-input installation and runtime Chat construction; Team-generated text describes business tasks. Application verification is pending. |
95
+ | R11 | Applied and verified in Refactor 38: Values::Serializable owns recursive conversion. Caller-specific diagnostics and distinct immutable/canonical/codec contracts remain. |
96
+
97
+ These entries identify real remaining proposals, not automatic authorization for
98
+ public behavior changes. D02, R03/R11, R06, R07 and R08/D08 are applied and verified.
99
+ Refactor 43 application is verified and R09 is closed. Verify Refactor 44
100
+ application before closing R10. Track the newly found Tool schema gap separately.
101
+ Keep R09's DSL semantics separate.
102
+ A complete initial-review closure requires implementation and verification or an
103
+ explicit decision to defer each item. R10 application is still pending, and the
104
+ new Tool schema finding is not covered by closing the original inventory.
105
+
106
+ ## Evidence and limits
107
+
108
+ Refactor 35 application checks matched both complete repository trees, 85 full
109
+ files and 25 deletions. Local suites: core 2,953 (61 pending), integration 367
110
+ (28 pending), common examples 42, SQLite 116; all failures zero. Do not count
111
+ pending as passed or sum overlapping suites.
112
+
113
+ All 13 examples CI jobs used that exact core/examples pair. PostgreSQL 17.11
114
+ passed 119 examples per Ruby version (3.2/3.3/3.4), plus fresh-pool reload.
115
+ SQLite passed 116 per version. API/RBS, gem loading and old/new SQLite data
116
+ compatibility were also verified. Core remote workflows had no runs.
117
+
118
+ Refactor 36's exact applied tree and all ten files matched its distribution.
119
+ Core/integration/common examples/SQLite, API/RBS and gem checks passed on the
120
+ applied source. The Resource/Validation two-file cycle is removed; the published
121
+ SVG was synchronized to applied36-01 then. Refactor 36 did not rerun live PostgreSQL, and the existing
122
+ examples CI used Refactor 35's core. Do not infer newer-core CI from those runs.
123
+ Refactor 37 was independently verified after application: all seven files and
124
+ the full tree matched, and local core/integration/examples/SQLite, API/RBS and
125
+ gem checks passed. Core CI had no runs. Live PostgreSQL was not rerun.
126
+
127
+ The existing directory cycles (8/6/3/2 members) and the other file cycles remain.
128
+ Static constant/require analysis does not resolve all dynamic collaboration.
129
+ No new promise is made about unknown commit outcomes, distributed Workflow
130
+ admission, exactly-once external effects, performance or live-LLM providers.
131
+ Those are separate design/validation scopes, not unfinished items silently
132
+ added to this refactoring plan.
133
+
134
+
135
+ ## D02 follow-up, applied
136
+
137
+ The direct construction change removes Execution.__operation_binding and its
138
+ three caller detours. OperationBinding keeps validation, linked cancellation,
139
+ deadline handling and subscription cleanup. No new generic factory or public
140
+ entry point is introduced. The three clients retain their admission and cleanup
141
+ ordering, and Orchestrator keeps its actual fan-out/fan-in use of Execution.
142
+ D02 is applied and verified at e7e66184. Seven R groups remained at that point;
143
+ R03/R11 are now applied below.
144
+
145
+
146
+ ## R03/R11: shared execution metadata and conversion (Refactor 38, applied)
147
+
148
+ See [the ownership and compatibility design](execution-metadata-and-values.md).
149
+ ExecutionMetadata owns the shared keys, version, snapshot and merge.
150
+ ToolInvocation.semantic_id owns the stable Tool identity, while
151
+ Values::Serializable owns recursive Ruby-to-JSON-tree conversion.
152
+ RecoverySupport retains recovery interpretation; the existing conversion entry
153
+ points retain their distinct diagnostics. No new restoration, transaction or
154
+ external-operation behavior is introduced.
155
+
156
+ Refactor 38 is applied and independently verified at core 690b2823, tree
157
+ 67ea6df833254341043c3fb1e99729d66f9598f6. All 30 full files and the tree match.
158
+ Core 2,970 (61 pending), integration 367 (28 pending), common examples 42 and
159
+ SQLite 116 passed with zero failures, as did API/RBS, style and gem checks.
160
+ R03/R11 are closed. Five groups remained at that point; R06 is now applied below.
161
+ The diagram was synchronized to applied38-01 then and is now applied42-01.
162
+
163
+
164
+ ## R06: Agent transition ownership (Refactor 39, applied)
165
+
166
+ See [the transition ownership design](agent-transition-ownership.md).
167
+ InvocationTransitions owns the six Tool event names, thirteen external event
168
+ families and their ordered transitions, initial phase and state classifications.
169
+ PhaseMachineBuilder compiles the external transitions into state_machines;
170
+ AgentInvocationSessionBuilder passes the same definition to FSMSession.
171
+ AgentInvocation uses the Tool vocabulary to identify payloads it handles.
172
+
173
+ FSMSession still uses only source-state declarations to decide whether an
174
+ external event is accepted or a phase must wait. The machine evaluates guards
175
+ against the current context, after payload application. Engine does not acquire
176
+ Agent policy, and automatic transitions and entry actions keep their owners.
177
+ No new generic DSL, compatibility alias, public API or persistence format is added.
178
+ R10's entry-action names and R09's DSL inheritance semantics are separate work.
179
+
180
+ The implementation preserves callback-failure, Handoff-failure, Handoff-request,
181
+ Tool-request and output-fallback priority, nil-context fallback, guard exceptions,
182
+ approval suspension and resume. Independent behavioral expectations pass on both
183
+ baseline and candidate; full-suite results are in the distribution evidence.
184
+ Refactor 39 is applied and independently verified at core 4d57614a, tree
185
+ 654241da4b2b7f32d988602d28127bc1fa155641. All 10 full files and the tree match.
186
+ Core 2,993 (61 pending), integration 367 (28 pending), common examples 42 and
187
+ SQLite 116 passed with zero failures, as did API/RBS, style and gem checks.
188
+ R06 is closed. Four groups remained then; R07 is now applied below.
189
+ The diagram was synchronized to applied39-01 then and is now applied42-01.
190
+
191
+
192
+ ## R07: Context preparation steps (Refactor 40, applied)
193
+
194
+ See [the preparation design and compatibility boundaries](context-preparation-steps.md).
195
+ ContextAssembler retains its public preparation/finalization boundary and its
196
+ existing collaborators. Seven private operations separate initial/base/Handoff
197
+ instructions, retained instructions, record candidates, Hook/Handoff merging
198
+ and the current-input item. No production class or file is added.
199
+
200
+ The public prepare methods now describe the preparation steps; item IDs,
201
+ provenance and metadata live in the corresponding item-building operation.
202
+ Initial and follow-up paths share generation filtering and candidate merging,
203
+ while preserving their distinct instruction sources, exclusion rules, call
204
+ sequence and ask/complete delivery. Evaluation and content-store effects retain
205
+ their order. Application Policy remains outside the caller's commit transaction;
206
+ finalize remains validation and persistence, without a Policy call.
207
+
208
+ Ten additional contract examples pass against both Refactor 39 and the candidate.
209
+ Four paired initial/follow-up scenarios compare complete Policy input, Prepared,
210
+ Manifest references/bytes and content operations across separate processes.
211
+ Full core/integration/examples/API/type/package gates are in the distribution.
212
+
213
+ Refactor 40 is applied and independently verified at core b3dfbc5a, tree
214
+ dcd9d1bf8efb1b488f9c2b3b1c4e99bdeda6096c. All six files and the tree match.
215
+ Core 3,003 (61 pending), integration 367 (28 pending), common examples 42 and
216
+ SQLite 116 passed with zero failures, as did API/RBS, style, gem and four paired
217
+ preparation scenarios. R07 is closed. Three groups remained at that point; R08/D08 is now applied below.
218
+ The published diagram is applied42-01; keep it until Refactor 43 application checks.
219
+
220
+
221
+ ## R08/D08: GeneratorVerifier ownership (Refactor 41, applied)
222
+
223
+ See [the ownership and event-contract design](generator-verifier-ownership.md).
224
+ The public facade retains configuration, lazy Workflow caching, default parsers
225
+ and Result construction. Private WorkflowBuilder owns graph assembly, request
226
+ startup and convergence. Private AgentResultReceiver converts Agent terminal
227
+ events into correlated Workflow events. PipelineState moves without changing its
228
+ canonical name, fields, correlation checks or mutation behavior.
229
+
230
+ The three implementation files live below generation/generator_verifier. No
231
+ loader change or alias is needed. This updates the original D08 location sketch:
232
+ the pattern already has generation ownership, so it does not move to MultiAgent.
233
+ Draft/review payload meanings remain separate. Only their identical terminal
234
+ classification, completion-notification rescue and failure notification are shared.
235
+ The receiver holds no request-specific mutable state and never mutates Workflow
236
+ context; PipelineState still applies accepted results on the EventLoop.
237
+
238
+ Thirty-nine additional event-contract examples pass on both baseline and candidate,
239
+ including inline completion, failures, parser/notification exceptions, old and
240
+ duplicate results, normalization, convergence, caching and config forwarding.
241
+ The public signature/Result/state contract also matches. Full gates are recorded
242
+ in the distribution. Existing semantics remain: final trust is score-based, even
243
+ if an unapproved high-score draft is finalized at the iteration limit.
244
+
245
+ Refactor 41 is applied and independently verified at core e87eb77f, tree
246
+ 14dc8a546a4fd96e19e0713f7480ca2efa3c331a. All nine files and the full tree match.
247
+ Core 3,042 (61 pending), integration 367 (28 pending), common examples 42 and
248
+ SQLite 116 passed with zero failures, as did API/RBS, style, gem and explicit
249
+ public/Result/state comparisons. R08/D08 is closed; R09 and R10 remain.
250
+ The diagram is applied41-01.
251
+
252
+
253
+ ## R09: Tool binding and declaration rules (Refactor 42, applied)
254
+
255
+ See [the boundary design and inheritance matrix](agent-configuration-and-tool-binding.md).
256
+ Base retains its preparation hook, non-Class passthrough and setting selection.
257
+ Agent::ToolBinding creates alias/filter decorators and forwards custom async
258
+ logical/physical completion. The default async path stays inherited to avoid
259
+ applying filters twice. ToolInvocation and Orchestrator retain their owners.
260
+ No Agent reference or private callback into Base is passed to ToolBinding.
261
+
262
+ Thirty-five new examples pass on both baseline and candidate. Current DSL rules
263
+ are explicit, including non-inherited model/budgets/filters, live parent lookups,
264
+ shared instructions/policy/Tool-list values and inherited aliases that nil does
265
+ not remove. This package does not unify public configuration behavior.
266
+
267
+ Refactor 42 is applied and verified at core 4a57a3c2, tree
268
+ 1a43ec3fecd5457e4314afa3807eb862bbd16b52. All nine files and the tree match.
269
+ Core 3,077 (61 pending), integration 367 (28 pending), examples 42, SQLite 116
270
+ and the packaged persistence contract 41 pass with zero failures. Public
271
+ contracts, API/SPI, types, style and gem loading also pass. This closes the
272
+ first slice; the original R09 Chat/state scope is addressed below.
273
+
274
+ ## R09: Chat construction and explicit state ownership (Refactor 43, applied)
275
+
276
+ See [the Chat/state ownership design](agent-chat-and-state-ownership.md).
277
+ RuntimeChatBuilder owns provider Chat creation, settings and cached instructions.
278
+ StateWriter owns initial root/context/knowledge writes and explicit idle-Agent
279
+ mutations, using the captured root and one transaction. Both live in the existing
280
+ context_assembly directory. They hold no Agent reference or private callbacks.
281
+
282
+ Base keeps the facade, live-owner checks, root proposals and publication. Its
283
+ projection hook preserves instruction/Tool/message order and existing overrides.
284
+ The writer returns root and records only after the transaction returns; Base
285
+ publishes Journal records before replacing the live root. Initial input order,
286
+ idle checks, CAS, revisions, exception identity and rollback behavior are retained.
287
+ Unknown commits, local publication failure and application-owned outer
288
+ transactions retain their existing limitations; no new reconciliation is added.
289
+
290
+ Thirty-seven new behavioral examples pass against both Refactor 42 and the
291
+ candidate. Full core/integration/examples/SQLite and API/SPI/type/style/package
292
+ gates are recorded in the distribution. Static dependency analysis preserves
293
+ all existing cycle memberships, with one new context_assembly -> lifecycle pair.
294
+ This improves responsibility boundaries; it does not remove existing cycles.
295
+
296
+ Refactor 43 is applied and verified at 5c4c0392, tree
297
+ 841bc7b5b28c2d31380ee4a12ffdc22a85ee3c37. All ten files and the full tree match.
298
+ Core 3,114 (61 pending), integration 367 (28 pending), examples 42, SQLite 116
299
+ and gem contract 41 pass with zero failures. R09 is closed; SVG is applied43-01.
300
+ No live-LLM, live PostgreSQL, remote-CI success or performance claim follows
301
+ from that local validation.
302
+
303
+
304
+ ## R10: Entry actions and Team wording (Refactor 44 candidate)
305
+
306
+ See [the naming and compatibility boundary](entry-action-and-team-wording.md).
307
+ Only two private action names and two generated Team strings change in production.
308
+ State/event vocabulary and action bodies stay unchanged. Legacy saved operation
309
+ results are returned as stored; new operations use business-task wording.
310
+ The original R/D inventory has no other unimplemented item, but R10 remains
311
+ pending application verification.
312
+
313
+ ## New open finding: Tool parameter schema recording
314
+
315
+ The [Tool schema recording gap](tool-schema-recording-gap.md) was reproduced on
316
+ Refactor 43 and Refactor 44 with RubyLLM 1.16.0. The actual schema reader is
317
+ `params_schema`, whereas ToolDefinitionSet records `{}` when its expected
318
+ `parameters_schema` reader is absent. A required/type change can evade the saved
319
+ comparison. This is the next correctness issue to design, with explicit handling
320
+ of historical manifests. It is not fixed by R10 or by passing its recovery tests.
321
+
322
+ ## Refactor 44 applied; Refactor 45 migration candidate
323
+
324
+ R10 was applied at 99ee43cd7b48174d825d20876fc38bbe47e6da11, tree
325
+ 34de332df150ff28ac93b2d04e099197f4a214d1, and verified. The original R/D inventory
326
+ is closed. Earlier candidate wording above is historical.
327
+
328
+ RubyLLM 2.0.0 now supplies the awaited provider-neutral output cap.
329
+ [Refactor 45](rubyllm-2-token-ownership.md) implements the dependency/API migration,
330
+ input-only registry budgeting, output-cap forwarding, schema recording/comparison
331
+ and coordinated examples migration. The schema issue is addressed in this candidate;
332
+ old empty-schema manifests require completion on the original version before upgrade.
333
+ Local verification and the exact package trees are recorded in the distribution.
334
+ User application verification remains outstanding; this is not a published release.