phronomy 0.26.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 (304) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +40 -0
  3. data/README.md +4 -0
  4. data/VERIFY.sh +27 -27
  5. data/benchmark/bench_agent_invoke.rb +26 -22
  6. data/benchmark/bench_context_assembler.rb +4 -5
  7. data/docs/architecture/agent-chat-and-state-ownership.md +147 -0
  8. data/docs/architecture/agent-configuration-and-tool-binding.md +139 -0
  9. data/docs/architecture/agent-context.md +4 -2
  10. data/docs/architecture/agent-transition-ownership.md +89 -0
  11. data/docs/architecture/before-llm-input.md +6 -0
  12. data/docs/architecture/context-management.md +30 -0
  13. data/docs/architecture/context-preparation-steps.md +90 -0
  14. data/docs/architecture/entry-action-and-team-wording.md +72 -0
  15. data/docs/architecture/execution-metadata-and-values.md +80 -0
  16. data/docs/architecture/generator-verifier-ownership.md +111 -0
  17. data/docs/architecture/multi-agent-handoff.md +8 -2
  18. data/docs/architecture/persistence-refactoring-plan.md +50 -0
  19. data/docs/architecture/persistence.md +27 -4
  20. data/docs/architecture/refactoring-closure.md +334 -0
  21. data/docs/architecture/remaining-refactoring-plan.md +374 -0
  22. data/docs/architecture/rubyllm-2-token-ownership.md +82 -0
  23. data/docs/architecture/tool-schema-recording-gap.md +50 -0
  24. data/docs/architecture/tracing.md +1 -1
  25. data/docs/architecture/workflow-terminal-ownership-design.md +104 -0
  26. data/docs/architecture.md +209 -0
  27. data/docs/decisions/014-unified-persistence-durable-state.md +11 -0
  28. data/docs/decisions/024-event-loop-single-writer-agent-runtime.md +5 -1
  29. data/docs/decisions/025-process-local-agent-ownership-and-runtime-admission.md +13 -3
  30. data/docs/decisions/026-workflow-runtime-admission-and-durable-terminal-barrier.md +5 -1
  31. data/docs/decisions/030-agent-handoff-domain-and-durable-responsibility.md +5 -0
  32. data/docs/decisions/031-durable-multi-agent-coordination.md +5 -0
  33. data/docs/decisions/032-storage-backend-composition.md +80 -0
  34. data/docs/decisions/033-domain-persistence-ownership.md +79 -0
  35. data/docs/decisions/034-handoff-runner-coordination-ownership.md +76 -0
  36. data/docs/decisions/035-tool-executor-capability-ownership.md +68 -0
  37. data/docs/decisions/036-context-contract-ownership.md +86 -0
  38. data/docs/decisions/037-common-definition-ownership.md +62 -0
  39. data/docs/decisions/038-responsibility-based-source-layout.md +131 -0
  40. data/docs/decisions/039-runtime-configuration-lifecycle-ownership.md +74 -0
  41. data/docs/decisions/040-configuration-default-composition.md +94 -0
  42. data/docs/decisions/041-feature-owned-identity-registries.md +100 -0
  43. data/docs/decisions/042-feature-owned-execution-state.md +106 -0
  44. data/docs/decisions/043-storage-execution-constraint-notifications.md +75 -0
  45. data/docs/decisions/044-agent-default-and-one-shot-composition.md +106 -0
  46. data/docs/decisions/045-worker-input-restriction-ownership.md +100 -0
  47. data/docs/decisions/046-agent-responsibility-layout-and-shared-records.md +110 -0
  48. data/docs/decisions/047-recovered-execution-continuation-contract.md +116 -0
  49. data/docs/decisions/048-dispatch-preparation-worker-ownership.md +120 -0
  50. data/docs/decisions/049-initial-preparation-worker-ownership.md +111 -0
  51. data/docs/decisions/050-approval-resume-snapshot-and-commit-ownership.md +98 -0
  52. data/docs/decisions/051-execution-outcome-worker-ownership.md +151 -0
  53. data/docs/decisions/052-tool-invocation-restoration-ownership.md +92 -0
  54. data/docs/decisions/053-shared-state-coordination-ownership.md +71 -0
  55. data/docs/decisions/054-workflow-terminal-save-single-owner.md +76 -0
  56. data/docs/decisions/055-terminal-observer-failure-settlement.md +60 -0
  57. data/docs/decisions/056-workflow-terminal-policy-ownership.md +87 -0
  58. data/docs/decisions/057-storage-transaction-boundaries.md +73 -0
  59. data/docs/decisions/058-neutral-storage-primitives.md +78 -0
  60. data/docs/decisions/README.md +35 -6
  61. data/docs/design/durable-semantic-coordination/IMPLEMENTATION_DESIGN_V2.md +6 -0
  62. data/docs/design/durable-semantic-coordination/IMPLEMENTATION_REPORT.md +6 -0
  63. data/docs/features.md +9 -3
  64. data/docs/getting-started.md +4 -4
  65. data/docs/migrations/0.15.md +5 -0
  66. data/docs/migrations/durable-semantic-coordination-v2.md +6 -0
  67. data/docs/migrations/handoff-runner-multi-agent.md +35 -0
  68. data/docs/migrations/neutral-storage-spi.md +43 -0
  69. data/docs/migrations/parallel-tool-chat-removal.md +49 -0
  70. data/docs/migrations/shared-state-multi-agent.md +44 -0
  71. data/docs/migrations/storage-backend-composition.md +117 -0
  72. data/docs/migrations/storage-transaction-boundaries.md +74 -0
  73. data/docs/persistence-backends.md +162 -204
  74. data/docs/runtime-and-concurrency.md +117 -32
  75. data/lib/phronomy/agent/api/agent.rb +17 -0
  76. data/lib/phronomy/agent/async_event_api.rb +2 -2
  77. data/lib/phronomy/agent/base.rb +51 -241
  78. data/lib/phronomy/{agent.rb → agent/composition/run_once.rb} +4 -13
  79. data/lib/phronomy/agent/context/capability/base.rb +67 -26
  80. data/lib/phronomy/agent/context/capability/tool_executor.rb +62 -0
  81. data/lib/phronomy/agent/{context_assembler.rb → context_assembly/context_assembler.rb} +143 -88
  82. data/lib/phronomy/agent/{context_importer.rb → context_assembly/context_importer.rb} +2 -2
  83. data/lib/phronomy/agent/{ruby_llm_materializer.rb → context_assembly/ruby_llm_materializer.rb} +4 -7
  84. data/lib/phronomy/agent/context_assembly/runtime_chat_builder.rb +36 -0
  85. data/lib/phronomy/agent/context_assembly/saved_context_reader.rb +53 -0
  86. data/lib/phronomy/agent/context_assembly/state_writer.rb +165 -0
  87. data/lib/phronomy/agent/context_assembly/token_budget_resolver.rb +22 -0
  88. data/lib/phronomy/agent/{context_plan.rb → context_contract/context_plan.rb} +1 -1
  89. data/lib/phronomy/agent/{context_policy_input.rb → context_contract/context_policy_input.rb} +6 -6
  90. data/lib/phronomy/agent/{llm_input_build_context.rb → context_contract/llm_input_build_context.rb} +1 -1
  91. data/lib/phronomy/agent/{llm_input_manifest.rb → context_contract/llm_input_manifest.rb} +20 -20
  92. data/lib/phronomy/agent/{llm_input_patch.rb → context_contract/llm_input_patch.rb} +2 -2
  93. data/lib/phronomy/agent/{agent_execution.rb → execution/agent_execution.rb} +8 -4
  94. data/lib/phronomy/agent/{agent_invocation.rb → execution/agent_invocation.rb} +8 -13
  95. data/lib/phronomy/agent/{agent_invocation_session_builder.rb → execution/agent_invocation_session_builder.rb} +19 -95
  96. data/lib/phronomy/agent/execution/approval_resume_commit.rb +108 -0
  97. data/lib/phronomy/agent/execution/dispatch_preparation.rb +305 -0
  98. data/lib/phronomy/agent/{exact_execution.rb → execution/exact_execution.rb} +9 -10
  99. data/lib/phronomy/agent/{execution_cancellation.rb → execution/execution_cancellation.rb} +2 -3
  100. data/lib/phronomy/agent/execution/execution_coordinator.rb +1925 -0
  101. data/lib/phronomy/agent/execution/execution_failure.rb +30 -0
  102. data/lib/phronomy/agent/execution/execution_metadata.rb +53 -0
  103. data/lib/phronomy/agent/execution/execution_outcome_committer.rb +344 -0
  104. data/lib/phronomy/agent/execution/execution_registry.rb +459 -0
  105. data/lib/phronomy/agent/execution/execution_session_runner.rb +118 -0
  106. data/lib/phronomy/agent/execution/initial_preparation.rb +421 -0
  107. data/lib/phronomy/agent/execution/invocation_transitions.rb +86 -0
  108. data/lib/phronomy/agent/{phase_machine_builder.rb → execution/phase_machine_builder.rb} +20 -71
  109. data/lib/phronomy/agent/{provider_call_outcome.rb → execution/provider_call_outcome.rb} +9 -9
  110. data/lib/phronomy/agent/execution/runtime_record_encoder.rb +210 -0
  111. data/lib/phronomy/agent/{handoff_context.rb → handoff/handoff_context.rb} +2 -2
  112. data/lib/phronomy/agent/handoff/handoff_execution_coordinator.rb +15 -0
  113. data/lib/phronomy/agent/handoff/handoff_outcome_committer.rb +131 -0
  114. data/lib/phronomy/agent/{handoff_state.rb → handoff/handoff_state.rb} +1 -1
  115. data/lib/phronomy/agent/{journal_projection.rb → journal/journal_projection.rb} +4 -0
  116. data/lib/phronomy/agent/{journal_record.rb → journal/journal_record.rb} +3 -3
  117. data/lib/phronomy/agent/{llm_call_record.rb → journal/llm_call_record.rb} +2 -2
  118. data/lib/phronomy/agent/{agent_root.rb → lifecycle/agent_root.rb} +6 -2
  119. data/lib/phronomy/agent/lifecycle/default_persistence.rb +29 -0
  120. data/lib/phronomy/{engine/runtime/agent_ownership_registry.rb → agent/lifecycle/ownership_registry.rb} +24 -10
  121. data/lib/phronomy/{agent_already_exists_error.rb → agent/lifecycle_contract/agent_already_exists_error.rb} +2 -0
  122. data/lib/phronomy/{agent_busy_error.rb → agent/lifecycle_contract/agent_busy_error.rb} +2 -0
  123. data/lib/phronomy/{agent_purged_error.rb → agent/lifecycle_contract/agent_purged_error.rb} +2 -0
  124. data/lib/phronomy/agent/lifecycle_contract/handoff_error.rb +7 -0
  125. data/lib/phronomy/{stream_callback_error.rb → agent/lifecycle_contract/stream_callback_error.rb} +2 -0
  126. data/lib/phronomy/agent/persistence/agent_repository.rb +61 -0
  127. data/lib/phronomy/agent/persistence/codec.rb +358 -0
  128. data/lib/phronomy/agent/persistence/execution_repository.rb +108 -0
  129. data/lib/phronomy/agent/persistence/handoff_state_repository.rb +58 -0
  130. data/lib/phronomy/agent/persistence/journal_repository.rb +54 -0
  131. data/lib/phronomy/agent/persistence/queries.rb +61 -0
  132. data/lib/phronomy/agent/persistence/storage_schema.rb +24 -0
  133. data/lib/phronomy/agent/persistence/watermark.rb +27 -0
  134. data/lib/phronomy/agent/recovery/invocation_restorer.rb +132 -0
  135. data/lib/phronomy/agent/{recovery_coordinator → recovery/recovery_coordinator}/continuation.rb +21 -45
  136. data/lib/phronomy/agent/{recovery_coordinator → recovery/recovery_coordinator}/installation.rb +32 -37
  137. data/lib/phronomy/agent/{recovery_coordinator → recovery/recovery_coordinator}/resolution.rb +37 -40
  138. data/lib/phronomy/agent/{recovery_coordinator.rb → recovery/recovery_coordinator.rb} +6 -10
  139. data/lib/phronomy/agent/recovery/recovery_support.rb +227 -0
  140. data/lib/phronomy/agent/selection/candidate.rb +1 -1
  141. data/lib/phronomy/agent/{approval_evaluation_request.rb → tool_execution/approval_evaluation_request.rb} +1 -12
  142. data/lib/phronomy/agent/{tool_approval_request.rb → tool_execution/tool_approval_request.rb} +1 -10
  143. data/lib/phronomy/agent/tool_execution/tool_binding.rb +90 -0
  144. data/lib/phronomy/agent/{tool_call_intercepted.rb → tool_execution/tool_call_intercepted.rb} +2 -2
  145. data/lib/phronomy/agent/{tool_definition_set.rb → tool_execution/tool_definition_set.rb} +9 -4
  146. data/lib/phronomy/agent/{tool_invocation.rb → tool_execution/tool_invocation.rb} +69 -34
  147. data/lib/phronomy/common/configuration_error.rb +7 -0
  148. data/lib/phronomy/common/error.rb +5 -0
  149. data/lib/phronomy/{agent → common/values}/immutable.rb +9 -1
  150. data/lib/phronomy/common/values/serializable.rb +32 -0
  151. data/lib/phronomy/{configuration.rb → configuration/configuration.rb} +14 -5
  152. data/lib/phronomy/configuration/global_configuration.rb +26 -0
  153. data/lib/phronomy/content_store/storage_schema.rb +11 -0
  154. data/lib/phronomy/content_store/stored_contents.rb +43 -0
  155. data/lib/phronomy/engine/backpressure_error.rb +7 -0
  156. data/lib/phronomy/{blocking.rb → engine/blocking.rb} +1 -1
  157. data/lib/phronomy/engine/cancellation_error.rb +7 -0
  158. data/lib/phronomy/engine/concurrency/cancellation_token.rb +4 -0
  159. data/lib/phronomy/engine/concurrency/offload_pool.rb +4 -0
  160. data/lib/phronomy/engine/concurrency/operation_binding.rb +1 -1
  161. data/lib/phronomy/engine/concurrency/worker_input_restricted.rb +14 -0
  162. data/lib/phronomy/engine/event_loop.rb +158 -624
  163. data/lib/phronomy/engine/event_loop_reentrancy_error.rb +8 -0
  164. data/lib/phronomy/{execution.rb → engine/execution.rb} +0 -7
  165. data/lib/phronomy/{execution_cancellation_error.rb → engine/execution_cancellation_error.rb} +2 -0
  166. data/lib/phronomy/engine/execution_receiver.rb +65 -0
  167. data/lib/phronomy/{execution_timeout_error.rb → engine/execution_timeout_error.rb} +2 -0
  168. data/lib/phronomy/engine/fsm_protocol.rb +14 -0
  169. data/lib/phronomy/engine/fsm_session.rb +35 -28
  170. data/lib/phronomy/{invalid_async_entry_action_error.rb → engine/invalid_async_entry_action_error.rb} +2 -0
  171. data/lib/phronomy/{invalid_async_transition_action_error.rb → engine/invalid_async_transition_action_error.rb} +2 -0
  172. data/lib/phronomy/{invalid_async_workflow_action_error.rb → engine/invalid_async_workflow_action_error.rb} +2 -0
  173. data/lib/phronomy/engine/pool_shutdown_error.rb +7 -0
  174. data/lib/phronomy/engine/recursion_limit_error.rb +7 -0
  175. data/lib/phronomy/engine/runtime.rb +80 -84
  176. data/lib/phronomy/engine/runtime_shutdown_error.rb +7 -0
  177. data/lib/phronomy/engine/runtime_shutdown_reentrancy_error.rb +7 -0
  178. data/lib/phronomy/engine/scheduler_reentrancy_error.rb +9 -0
  179. data/lib/phronomy/engine/task_result.rb +4 -0
  180. data/lib/phronomy/engine/timeout_error.rb +7 -0
  181. data/lib/phronomy/filter/contract/filter_block_error.rb +14 -0
  182. data/lib/phronomy/generation/generator_verifier/agent_result_receiver.rb +89 -0
  183. data/lib/phronomy/generation/generator_verifier/pipeline_state.rb +57 -0
  184. data/lib/phronomy/generation/generator_verifier/workflow_builder.rb +112 -0
  185. data/lib/phronomy/generation/generator_verifier.rb +118 -0
  186. data/lib/phronomy/generation/low_confidence_error.rb +14 -0
  187. data/lib/phronomy/llm_context_window/token_budget.rb +6 -7
  188. data/lib/phronomy/llm_contract/authentication_error.rb +7 -0
  189. data/lib/phronomy/{context_budget_exceeded_error.rb → llm_contract/context_budget_exceeded_error.rb} +2 -0
  190. data/lib/phronomy/llm_contract/context_length_error.rb +7 -0
  191. data/lib/phronomy/llm_contract/rate_limit_error.rb +7 -0
  192. data/lib/phronomy/{token_usage.rb → llm_contract/token_usage.rb} +2 -2
  193. data/lib/phronomy/llm_contract/transport_error.rb +7 -0
  194. data/lib/phronomy/multi_agent/admission_registry.rb +22 -2
  195. data/lib/phronomy/multi_agent/durable_subagent_coordinator.rb +5 -5
  196. data/lib/phronomy/{agent → multi_agent}/handoff_runner.rb +18 -17
  197. data/lib/phronomy/multi_agent/orchestrator.rb +2 -2
  198. data/lib/phronomy/multi_agent/persistence/codec.rb +55 -0
  199. data/lib/phronomy/multi_agent/persistence/queries.rb +30 -0
  200. data/lib/phronomy/multi_agent/persistence/team_execution_repository.rb +108 -0
  201. data/lib/phronomy/multi_agent/persistence/team_repository.rb +61 -0
  202. data/lib/phronomy/{agent → multi_agent}/shared_state.rb +56 -39
  203. data/lib/phronomy/multi_agent/storage_contract/team_storage_schema.rb +15 -0
  204. data/lib/phronomy/multi_agent/team_coordinator.rb +21 -18
  205. data/lib/phronomy/multi_agent/team_execution.rb +1 -1
  206. data/lib/phronomy/{engine/runtime → multi_agent}/team_ownership_registry.rb +14 -4
  207. data/lib/phronomy/multi_agent/team_root.rb +1 -1
  208. data/lib/phronomy/output_parser/contract/parse_error.rb +7 -0
  209. data/lib/phronomy/persistence/api/persistence.rb +140 -0
  210. data/lib/phronomy/persistence/migration/initial_format_migration.rb +19 -19
  211. data/lib/phronomy/persistence_composition/repositories.rb +77 -0
  212. data/lib/phronomy/persistence_composition/storage_schema.rb +24 -0
  213. data/lib/phronomy/{execution_rehydration_required_error.rb → recovery/execution_rehydration_required_error.rb} +2 -0
  214. data/lib/phronomy/{recovery.rb → recovery/recovery.rb} +1 -1
  215. data/lib/phronomy/runtime_composition/agent_defaults.rb +7 -0
  216. data/lib/phronomy/runtime_composition/configuration_defaults.rb +9 -0
  217. data/lib/phronomy/runtime_composition/global_runtime.rb +19 -0
  218. data/lib/phronomy/storage/backend.rb +101 -0
  219. data/lib/phronomy/storage/backends/in_memory.rb +157 -0
  220. data/lib/phronomy/storage/blob_conflict_error.rb +10 -0
  221. data/lib/phronomy/storage/blobs.rb +31 -0
  222. data/lib/phronomy/storage/condition.rb +25 -0
  223. data/lib/phronomy/storage/condition_failed_error.rb +16 -0
  224. data/lib/phronomy/storage/conflict_error.rb +9 -0
  225. data/lib/phronomy/{persistence → storage}/durable_record.rb +12 -12
  226. data/lib/phronomy/storage/entry.rb +33 -0
  227. data/lib/phronomy/storage/guard_ref.rb +13 -0
  228. data/lib/phronomy/storage/not_found_error.rb +9 -0
  229. data/lib/phronomy/storage/record_codec.rb +177 -0
  230. data/lib/phronomy/storage/records.rb +61 -0
  231. data/lib/phronomy/storage/resource.rb +126 -0
  232. data/lib/phronomy/storage/scope.rb +25 -0
  233. data/lib/phronomy/storage/serialization_error.rb +9 -0
  234. data/lib/phronomy/storage/streams.rb +44 -0
  235. data/lib/phronomy/storage/transaction_error.rb +10 -0
  236. data/lib/phronomy/storage/unique_constraint_error.rb +17 -0
  237. data/lib/phronomy/storage/unsupported_backend_error.rb +9 -0
  238. data/lib/phronomy/storage/validation.rb +53 -0
  239. data/lib/phronomy/storage/view.rb +131 -0
  240. data/lib/phronomy/testing/persistence_contract/a_content_store.rb +1 -1
  241. data/lib/phronomy/testing/persistence_contract/a_journal_repository.rb +4 -4
  242. data/lib/phronomy/testing/persistence_contract/a_persistence_backend.rb +10 -7
  243. data/lib/phronomy/testing/persistence_contract/a_workflow_state_repository.rb +2 -2
  244. data/lib/phronomy/testing/persistence_contract/an_agent_repository.rb +6 -6
  245. data/lib/phronomy/testing/persistence_contract/an_execution_repository.rb +6 -6
  246. data/lib/phronomy/testing/persistence_contract/coordination_repositories.rb +8 -8
  247. data/lib/phronomy/testing/persistence_contract/neutral_storage_primitives.rb +263 -0
  248. data/lib/phronomy/testing/persistence_contract/storage_transaction_boundaries.rb +123 -0
  249. data/lib/phronomy/testing/persistence_contract.rb +4 -0
  250. data/lib/phronomy/tool/contract/tool_error.rb +7 -0
  251. data/lib/phronomy/tools/agent.rb +1 -1
  252. data/lib/phronomy/version.rb +1 -1
  253. data/lib/phronomy/{workflow.rb → workflow/execution/workflow.rb} +8 -6
  254. data/lib/phronomy/{workflow_context.rb → workflow/execution/workflow_context.rb} +4 -0
  255. data/lib/phronomy/workflow/execution/workflow_context_ownership_error.rb +7 -0
  256. data/lib/phronomy/workflow/execution/workflow_execution_registry.rb +188 -0
  257. data/lib/phronomy/{workflow_runner.rb → workflow/execution/workflow_runner.rb} +122 -71
  258. data/lib/phronomy/workflow/execution/workflow_terminal_policy.rb +40 -0
  259. data/lib/phronomy/workflow/persistence/codec.rb +153 -0
  260. data/lib/phronomy/workflow/persistence/state_repository.rb +57 -0
  261. data/lib/phronomy/workflow/phase_machine_builder.rb +2 -2
  262. data/lib/phronomy/workflow/storage_contract/workflow_storage_schema.rb +9 -0
  263. data/lib/phronomy.rb +52 -94
  264. data/scripts/api_snapshot.rb +1 -1
  265. data/scripts/storage_spi_snapshot.rb +36 -0
  266. data/sig/phronomy/agent.rbs +0 -1
  267. data/sig/phronomy/execution_receiver.rbs +34 -0
  268. data/sig/phronomy/handoff.rbs +4 -2
  269. data/sig/phronomy/multi_agent.rbs +18 -0
  270. data/sig/phronomy/persistence.rbs +7 -91
  271. data/sig/phronomy/storage.rbs +174 -0
  272. data/sig/phronomy/tool.rbs +10 -1
  273. metadata +230 -99
  274. data/lib/phronomy/agent/execution_coordinator.rb +0 -3151
  275. data/lib/phronomy/agent/handoff_execution_coordinator.rb +0 -143
  276. data/lib/phronomy/agent/recovery_support.rb +0 -504
  277. data/lib/phronomy/agent/token_budget_resolver.rb +0 -70
  278. data/lib/phronomy/agent/tool_executor.rb +0 -55
  279. data/lib/phronomy/generator_verifier.rb +0 -369
  280. data/lib/phronomy/invalid_context_budget_configuration_error.rb +0 -8
  281. data/lib/phronomy/multi_agent/parallel_tool_chat.rb +0 -116
  282. data/lib/phronomy/persistence/durable_codec.rb +0 -706
  283. data/lib/phronomy/persistence/in_memory.rb +0 -690
  284. data/lib/phronomy/persistence/repository_facades.rb +0 -535
  285. data/lib/phronomy/persistence.rb +0 -276
  286. data/lib/phronomy/ruby_llm_patches.rb +0 -24
  287. data/lib/phronomy/workflow_recovery.rb +0 -123
  288. /data/lib/phronomy/agent/{context_candidate_resolver.rb → context_assembly/context_candidate_resolver.rb} +0 -0
  289. /data/lib/phronomy/agent/{context_policy_input_builder.rb → context_assembly/context_policy_input_builder.rb} +0 -0
  290. /data/lib/phronomy/agent/{context_plan_validator.rb → context_contract/context_plan_validator.rb} +0 -0
  291. /data/lib/phronomy/agent/{context_policy.rb → context_contract/context_policy.rb} +0 -0
  292. /data/lib/phronomy/agent/{llm_operation_result.rb → execution/llm_operation_result.rb} +0 -0
  293. /data/lib/phronomy/agent/{handoff.rb → handoff/handoff.rb} +0 -0
  294. /data/lib/phronomy/agent/{handoff_capability_factory.rb → handoff/handoff_capability_factory.rb} +0 -0
  295. /data/lib/phronomy/agent/{handoff_policy.rb → handoff/handoff_policy.rb} +0 -0
  296. /data/lib/phronomy/agent/{handoff_projection.rb → handoff/handoff_projection.rb} +0 -0
  297. /data/lib/phronomy/agent/{handoff_request.rb → handoff/handoff_request.rb} +0 -0
  298. /data/lib/phronomy/agent/{tool_invocation_session_builder.rb → tool_execution/tool_invocation_session_builder.rb} +0 -0
  299. /data/lib/phronomy/{canonical_json.rb → common/canonical_json.rb} +0 -0
  300. /data/lib/phronomy/{diagnostics.rb → engine/diagnostics.rb} +0 -0
  301. /data/lib/phronomy/{event.rb → engine/event.rb} +0 -0
  302. /data/lib/phronomy/{invocation_context.rb → engine/invocation_context.rb} +0 -0
  303. /data/lib/phronomy/{metrics.rb → engine/metrics.rb} +0 -0
  304. /data/lib/phronomy/{runnable.rb → engine/runnable.rb} +0 -0
@@ -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.