agentengine-sdk-python 0.8.6__py3-none-any.whl → 0.8.8__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (764) hide show
  1. {agentengine_sdk_python-0.8.6.dist-info → agentengine_sdk_python-0.8.8.dist-info}/METADATA +41 -18
  2. {agentengine_sdk_python-0.8.6.dist-info → agentengine_sdk_python-0.8.8.dist-info}/RECORD +710 -526
  3. {agentengine_sdk_python-0.8.6.dist-info → agentengine_sdk_python-0.8.8.dist-info}/WHEEL +1 -1
  4. ksadk/__init__.py +2 -1
  5. ksadk/_build_provenance.json +1 -1
  6. ksadk/_mcp_compat.py +305 -0
  7. ksadk/a2a/_invocation_state.py +1 -1
  8. ksadk/a2a/adk_invocation_context.py +2 -1
  9. ksadk/a2a/adk_tools.py +19 -9
  10. ksadk/a2a/bootstrap.py +7 -6
  11. ksadk/a2a/codex.py +2 -1
  12. ksadk/a2a/control_plane.py +119 -2
  13. ksadk/a2a/executor.py +24 -7
  14. ksadk/a2a/invocation_service.py +198 -7
  15. ksadk/a2a/kernel_task_adapter.py +60 -9
  16. ksadk/a2a/langgraph_invocation_context.py +3 -2
  17. ksadk/a2a/langgraph_managed.py +17 -1
  18. ksadk/a2a/langgraph_recovery.py +43 -5
  19. ksadk/a2a/langgraph_tool_runtime.py +8 -6
  20. ksadk/a2a/langgraph_tools.py +13 -1
  21. ksadk/a2a/platform.py +8 -2
  22. ksadk/a2a/runtime_approval.py +6 -21
  23. ksadk/a2a/runtime_input.py +3 -2
  24. ksadk/a2a/timeouts.py +37 -0
  25. ksadk/a2a/tool_outcomes.py +73 -0
  26. ksadk/a2a/workload_tokens.py +21 -134
  27. ksadk/a2ui/__init__.py +4 -0
  28. ksadk/a2ui/assets/basic-v0_9_1.json +1383 -0
  29. ksadk/a2ui/assets/common-types-v0_9.json +305 -0
  30. ksadk/a2ui/assets/legacy-seven-components.json +230 -0
  31. ksadk/a2ui/assets/manifest.json +86 -0
  32. ksadk/a2ui/budget.py +54 -0
  33. ksadk/a2ui/catalog.py +64 -0
  34. ksadk/a2ui/generation.py +71 -0
  35. ksadk/a2ui/legacy.py +88 -0
  36. ksadk/a2ui/linking.py +115 -0
  37. ksadk/a2ui/payload.py +46 -0
  38. ksadk/a2ui/presentation.py +79 -0
  39. ksadk/a2ui/registry.py +166 -0
  40. ksadk/a2ui/wire.py +110 -0
  41. ksadk/agent.py +29 -0
  42. ksadk/agui/_agent_helpers.py +16 -1
  43. ksadk/agui/_agent_kernel.py +515 -0
  44. ksadk/agui/_agent_projection.py +379 -0
  45. ksadk/agui/_agent_resume.py +279 -0
  46. ksadk/agui/_agent_types.py +67 -0
  47. ksadk/agui/a2ui_projection.py +3 -1
  48. ksadk/agui/agent.py +184 -571
  49. ksadk/agui/config.py +19 -5
  50. ksadk/agui/hosted.py +343 -0
  51. ksadk/agui/request_identity.py +11 -0
  52. ksadk/agui/routes.py +79 -2
  53. ksadk/api/client.py +158 -7
  54. ksadk/builders/code_builder.py +174 -52
  55. ksadk/builders/container_builder.py +28 -7
  56. ksadk/builders/framework_requirements.py +5 -4
  57. ksadk/builders/mcp_builder.py +145 -1
  58. ksadk/builders/project_imports.py +66 -0
  59. ksadk/cli/cmd_deploy.py +5 -0
  60. ksadk/cli/cmd_invoke.py +57 -2
  61. ksadk/cli/cmd_mcp.py +1 -1
  62. ksadk/cli/cmd_run.py +2 -4
  63. ksadk/cli/cmd_studio.py +19 -3
  64. ksadk/cli/cmd_web.py +28 -56
  65. ksadk/cli/hosted_command_events.py +148 -0
  66. ksadk/cli/hosted_invoke.py +66 -14
  67. ksadk/cli/runtime_bootstrap.py +5 -1
  68. ksadk/codex/async_client.py +354 -12
  69. ksadk/codex/runtime.py +17 -2
  70. ksadk/common/cloud_headers.py +33 -6
  71. ksadk/common/diagnostics.py +15 -0
  72. ksadk/compat/adk_compat.py +2 -0
  73. ksadk/compat/adk_stream.py +35 -0
  74. ksadk/compat/copilotkit_a2ui.py +85 -21
  75. ksadk/configs/env_registry.py +102 -19
  76. ksadk/configs/env_registry_a2a.py +42 -0
  77. ksadk/conversations/a2ui_projection.py +50 -0
  78. ksadk/conversations/context.py +12 -0
  79. ksadk/conversations/message_projection.py +106 -60
  80. ksadk/conversations/message_projection_blocks.py +75 -3
  81. ksadk/conversations/message_projection_outcomes.py +81 -0
  82. ksadk/conversations/projector.py +35 -0
  83. ksadk/conversations/runtime_invocation.py +3 -0
  84. ksadk/conversations/runtime_observability.py +1 -0
  85. ksadk/conversations/runtime_projection.py +23 -1
  86. ksadk/conversations/runtime_stream_events.py +11 -7
  87. ksadk/conversations/runtime_streaming.py +21 -17
  88. ksadk/deployment/mcp.py +93 -0
  89. ksadk/deployment/providers/serverless.py +130 -4
  90. ksadk/detection/mcp_detector.py +80 -22
  91. ksadk/events/_v1_compat/projection.py +2 -0
  92. ksadk/events/adapters/_langgraph_custom.py +195 -0
  93. ksadk/events/adapters/_langgraph_model_tasks.py +59 -0
  94. ksadk/events/adapters/_langgraph_support.py +80 -29
  95. ksadk/events/adapters/_langgraph_tool_outcomes.py +71 -0
  96. ksadk/events/adapters/_langgraph_usage_origin.py +86 -0
  97. ksadk/events/adapters/adk.py +11 -0
  98. ksadk/events/adapters/langgraph.py +188 -20
  99. ksadk/events/canonical.py +23 -1
  100. ksadk/events/canonical_store.py +133 -4
  101. ksadk/events/cold_recovery.py +2 -1
  102. ksadk/events/native_checkpoint.py +10 -0
  103. ksadk/events/reducer.py +9 -9
  104. ksadk/events/run_authority.py +15 -0
  105. ksadk/events/session_event.py +61 -0
  106. ksadk/events/sse_heartbeat.py +50 -0
  107. ksadk/events/usage.py +50 -0
  108. ksadk/harness/__init__.py +3 -0
  109. ksadk/harness/app.py +1 -1
  110. ksadk/harness/artifact_adapters/native_catalog.py +92 -0
  111. ksadk/harness/artifact_adapters/native_tool.py +16 -0
  112. ksadk/harness/browser_adapters/native_playwright.py +3 -1
  113. ksadk/harness/browser_adapters/native_vision.py +2 -1
  114. ksadk/harness/engine/postgres_checkpointer.py +170 -29
  115. ksadk/harness/model_adapters/native_openai.py +3 -1
  116. ksadk/harness/native/artifact_catalog_contract.py +26 -0
  117. ksadk/harness/native/artifact_partial_read_capacity.py +6 -3
  118. ksadk/harness/native/artifact_read_capacity.py +15 -87
  119. ksadk/harness/native/artifact_runtime.py +44 -1
  120. ksadk/harness/native/artifact_search_capacity.py +20 -119
  121. ksadk/harness/native/artifact_single_read_capacity.py +7 -6
  122. ksadk/harness/native/background_command_contract.py +40 -0
  123. ksadk/harness/native/background_commands.py +101 -0
  124. ksadk/harness/native/call_budget.py +24 -0
  125. ksadk/harness/native/child_budget.py +6 -6
  126. ksadk/harness/native/child_interruption.py +3 -2
  127. ksadk/harness/native/child_media.py +105 -0
  128. ksadk/harness/native/context.py +44 -0
  129. ksadk/harness/native/context_compaction_projection.py +38 -2
  130. ksadk/harness/native/context_continuation.py +54 -0
  131. ksadk/harness/native/context_contributions.py +2 -1
  132. ksadk/harness/native/context_directory_progress.py +117 -0
  133. ksadk/harness/native/context_driver.py +136 -11
  134. ksadk/harness/native/context_partial_summary.py +2 -0
  135. ksadk/harness/native/context_partition.py +37 -1
  136. ksadk/harness/native/context_replay.py +2 -1
  137. ksadk/harness/native/context_request_projection.py +59 -6
  138. ksadk/harness/native/context_runtime.py +211 -16
  139. ksadk/harness/native/context_runtime_contracts.py +123 -1
  140. ksadk/harness/native/context_session_history.py +96 -0
  141. ksadk/harness/native/context_source_progress.py +164 -5
  142. ksadk/harness/native/context_summary_planning.py +63 -15
  143. ksadk/harness/native/context_summary_prompt.py +72 -0
  144. ksadk/harness/native/context_summary_recovery.py +3 -1
  145. ksadk/harness/native/delivery_artifacts.py +58 -0
  146. ksadk/harness/native/delivery_context.py +64 -0
  147. ksadk/harness/native/delivery_feedback.py +95 -0
  148. ksadk/harness/native/delivery_review.py +10 -10
  149. ksadk/harness/native/effect_control.py +45 -1
  150. ksadk/harness/native/effect_receipts.py +50 -3
  151. ksadk/harness/native/effect_runtime.py +10 -1
  152. ksadk/harness/native/engine.py +601 -16
  153. ksadk/harness/native/execution_budget.py +88 -0
  154. ksadk/harness/native/history.py +1 -0
  155. ksadk/harness/native/machine.py +44 -7
  156. ksadk/harness/native/model.py +17 -3
  157. ksadk/harness/native/model_runtime.py +192 -12
  158. ksadk/harness/native/model_takeover.py +4 -2
  159. ksadk/harness/native/notification_admission.py +183 -0
  160. ksadk/harness/native/ports.py +54 -6
  161. ksadk/harness/native/run_clock.py +13 -6
  162. ksadk/harness/native/state.py +100 -1
  163. ksadk/harness/native/stream_display_buffer.py +198 -0
  164. ksadk/harness/native/subagents.py +21 -0
  165. ksadk/harness/native/task_policy.py +8 -3
  166. ksadk/harness/native/tool_batch_capacity.py +152 -0
  167. ksadk/harness/native/tool_budget.py +38 -9
  168. ksadk/harness/native/tool_error_recovery.py +241 -0
  169. ksadk/harness/native/tool_error_streak.py +10 -1
  170. ksadk/harness/native/tool_progress.py +1 -0
  171. ksadk/harness/native/tool_scheduling.py +9 -10
  172. ksadk/harness/native/turn_control.py +21 -2
  173. ksadk/harness/native/verification_runtime.py +2 -1
  174. ksadk/harness/native_facade.py +180 -9
  175. ksadk/harness/native_projection.py +18 -8
  176. ksadk/harness/native_runtime.py +208 -3
  177. ksadk/harness/provider_thinking.py +63 -0
  178. ksadk/harness/public_activity.py +3 -0
  179. ksadk/harness/service_presentation.py +44 -0
  180. ksadk/harness/service_runtime.py +1038 -0
  181. ksadk/harness/skill_adapters/native_disclosure.py +13 -1
  182. ksadk/harness/skill_adapters/native_metadata.py +40 -0
  183. ksadk/harness/spec.py +6 -0
  184. ksadk/harness/stores/native_commit_history.py +373 -0
  185. ksadk/harness/stores/native_contract.py +205 -1
  186. ksadk/harness/stores/native_memory.py +363 -1
  187. ksadk/harness/stores/native_sqlite.py +572 -14
  188. ksadk/harness/stores/native_sqlite_migration.py +34 -7
  189. ksadk/harness/subagent.py +6 -1
  190. ksadk/harness/subagent_adapters/native_background_child.py +8 -7
  191. ksadk/harness/subagent_adapters/native_child.py +87 -8
  192. ksadk/harness/tool_display.py +113 -2
  193. ksadk/harness/tool_display_contract.py +34 -1
  194. ksadk/interaction/contracts.py +19 -4
  195. ksadk/interaction/display_values.py +140 -0
  196. ksadk/interaction/form_values.py +130 -0
  197. ksadk/interaction/langgraph.py +53 -0
  198. ksadk/interaction/langgraph_approval.py +59 -0
  199. ksadk/interaction/langgraph_interrupt.py +129 -0
  200. ksadk/interaction/langgraph_observer.py +125 -0
  201. ksadk/interaction/ledger.py +32 -5
  202. ksadk/interaction/native_events.py +29 -0
  203. ksadk/interaction/providers/harness.py +9 -4
  204. ksadk/interaction/providers/langgraph.py +19 -8
  205. ksadk/interaction/resolution.py +43 -0
  206. ksadk/interaction/schema.py +168 -0
  207. ksadk/interaction/submission.py +184 -0
  208. ksadk/kernel/admission_cursor.py +19 -0
  209. ksadk/kernel/bootstrap.py +344 -228
  210. ksadk/kernel/contract_fingerprints.py +5 -0
  211. ksadk/kernel/contracts.py +1 -0
  212. ksadk/kernel/control.py +67 -0
  213. ksadk/kernel/conversation_input.py +39 -0
  214. ksadk/kernel/execution_host_ingress.py +6 -3
  215. ksadk/kernel/history_projection.py +85 -4
  216. ksadk/kernel/ingress.py +89 -27
  217. ksadk/kernel/interactions_memory.py +447 -0
  218. ksadk/kernel/interactions_postgres.py +500 -0
  219. ksadk/kernel/interactions_sqlite.py +684 -0
  220. ksadk/kernel/legacy_postgres_repair.py +113 -0
  221. ksadk/kernel/local_interactions.py +172 -0
  222. ksadk/kernel/memory_store.py +137 -366
  223. ksadk/kernel/native_confirmation.py +109 -0
  224. ksadk/kernel/postgres_locks.py +23 -0
  225. ksadk/kernel/postgres_store.py +573 -511
  226. ksadk/kernel/postgres_time.py +12 -0
  227. ksadk/kernel/recovery.py +26 -1
  228. ksadk/kernel/runtime_config.py +72 -0
  229. ksadk/kernel/runtime_environment.py +301 -0
  230. ksadk/kernel/session_storage.py +144 -0
  231. ksadk/kernel/sql/002_session_retirement.sql +86 -0
  232. ksadk/kernel/sql/003_legacy_repair_queue.sql +49 -0
  233. ksadk/kernel/sql/backfill_session_namespaces.sql +59 -0
  234. ksadk/kernel/sqlite_session_cleanup.py +84 -0
  235. ksadk/kernel/sqlite_store.py +232 -622
  236. ksadk/kernel/store.py +6 -0
  237. ksadk/kernel/submission_postgres.py +99 -0
  238. ksadk/kernel/submission_sqlite.py +107 -0
  239. ksadk/kernel/teams_effects.py +3 -4
  240. ksadk/kernel/teams_execution_context.py +3 -4
  241. ksadk/kernel/worker.py +91 -202
  242. ksadk/kernel/worker_controls.py +112 -27
  243. ksadk/kernel/worker_identity.py +15 -8
  244. ksadk/kernel/worker_interactions.py +343 -47
  245. ksadk/knowledge_base/__init__.py +1 -1
  246. ksadk/knowledge_base/client.py +138 -17
  247. ksadk/knowledge_base/openclaw_bridge.py +58 -0
  248. ksadk/knowledge_base/service.py +2 -0
  249. ksadk/mcp_runtime/__init__.py +34 -15
  250. ksadk/mcp_runtime/_adk.py +14 -0
  251. ksadk/mcp_runtime/oauth/__init__.py +6 -0
  252. ksadk/mcp_runtime/oauth/_agent.py +215 -0
  253. ksadk/mcp_runtime/oauth/_durable_tools.py +208 -0
  254. ksadk/mcp_runtime/oauth/bootstrap.py +69 -0
  255. ksadk/mcp_runtime/oauth/client.py +200 -0
  256. ksadk/mcp_runtime/oauth/code_config.py +90 -0
  257. ksadk/mcp_runtime/oauth/contract.json +32 -0
  258. ksadk/mcp_runtime/oauth/contract.py +6 -0
  259. ksadk/mcp_runtime/oauth/declarations.py +106 -0
  260. ksadk/mcp_runtime/oauth/http.py +63 -0
  261. ksadk/mcp_runtime/oauth/kernel.py +717 -0
  262. ksadk/mcp_runtime/oauth/langgraph.py +434 -0
  263. ksadk/mcp_runtime/oauth/local/__init__.py +1 -0
  264. ksadk/mcp_runtime/oauth/local/broker.py +491 -0
  265. ksadk/mcp_runtime/oauth/local/checkpoint.py +17 -0
  266. ksadk/mcp_runtime/oauth/local/persistence.py +227 -0
  267. ksadk/mcp_runtime/oauth/local/protocol.py +390 -0
  268. ksadk/mcp_runtime/oauth/local/runtime.py +413 -0
  269. ksadk/mcp_runtime/oauth/local/transport.py +79 -0
  270. ksadk/mcp_runtime/oauth/runtime_io.py +43 -0
  271. ksadk/mcp_runtime/oauth/security.py +73 -0
  272. ksadk/mcp_runtime/oauth/tools.py +434 -0
  273. ksadk/mcp_runtime/oauth/transport.py +109 -0
  274. ksadk/memory/adk/backends/sdk_ltm_backend.py +21 -12
  275. ksadk/memory/adk/long_term_memory.py +1 -2
  276. ksadk/memory/openclaw_bridge.py +115 -0
  277. ksadk/memory/providers/local_postgres.py +247 -55
  278. ksadk/memory/scope_ids.py +49 -0
  279. ksadk/memory/service.py +29 -3
  280. ksadk/model_gateway/client.py +1 -1
  281. ksadk/model_proxy/compat.py +22 -0
  282. ksadk/model_proxy/transform.py +3 -4
  283. ksadk/plugins/providers/codex.py +37 -2
  284. ksadk/plugins/providers/harness.py +65 -28
  285. ksadk/plugins/providers/harness_service.py +198 -0
  286. ksadk/plugins/providers/harness_service_context.py +175 -0
  287. ksadk/plugins/providers/harness_service_hooks.py +168 -0
  288. ksadk/plugins/providers/harness_service_memory.py +479 -0
  289. ksadk/plugins/providers/harness_tools.py +39 -2
  290. ksadk/plugins/providers/platform_resources.py +2 -2
  291. ksadk/resource_runtime/contracts.py +8 -3
  292. ksadk/resource_runtime/knowledge.py +1 -1
  293. ksadk/resource_runtime/langgraph.py +7 -3
  294. ksadk/resource_runtime/managed_projection.py +24 -9
  295. ksadk/resource_runtime/mcp_server.py +3 -3
  296. ksadk/resource_runtime/worker.py +24 -5
  297. ksadk/runners/_adk_a2a_stream.py +10 -0
  298. ksadk/runners/_adk_canonical_stream.py +38 -10
  299. ksadk/runners/_adk_tunnel_history.py +96 -0
  300. ksadk/runners/_langgraph_answer_contract.py +47 -0
  301. ksadk/runners/_langgraph_canonical_stream.py +657 -0
  302. ksadk/runners/_langgraph_checkpoint_binding.py +89 -0
  303. ksadk/runners/_langgraph_factory.py +79 -0
  304. ksadk/runners/_langgraph_final_answer.py +91 -0
  305. ksadk/runners/_langgraph_fresh_turn.py +67 -0
  306. ksadk/runners/_langgraph_interactions.py +199 -0
  307. ksadk/runners/_langgraph_output.py +69 -0
  308. ksadk/runners/_langgraph_runner_streams.py +38 -75
  309. ksadk/runners/_langgraph_state_reader.py +5 -0
  310. ksadk/runners/_langgraph_wait_cancellation.py +49 -0
  311. ksadk/runners/_session_identity.py +30 -4
  312. ksadk/runners/adk_runner.py +108 -22
  313. ksadk/runners/base_runner.py +21 -0
  314. ksadk/runners/langgraph_runner.py +122 -108
  315. ksadk/runners/patch_langchain.py +4 -2
  316. ksadk/runtime/_langgraph_interaction_adapter.py +333 -0
  317. ksadk/runtime/_runner_adapter/a2ui_surface.py +194 -22
  318. ksadk/runtime/_runner_adapter/chunk_mapping.py +688 -0
  319. ksadk/runtime/_runner_adapter/resume_context.py +64 -0
  320. ksadk/runtime/_runner_adapter/stream_mapping.py +29 -597
  321. ksadk/runtime/conversation_execution.py +61 -32
  322. ksadk/runtime/executor.py +34 -1
  323. ksadk/runtime/factory.py +17 -5
  324. ksadk/runtime/framework_adapters.py +37 -2
  325. ksadk/runtime/langgraph_checkpoint_view.py +168 -0
  326. ksadk/runtime/launch.py +2 -0
  327. ksadk/runtime/preprocessing.py +9 -1
  328. ksadk/runtime/runner_adapter.py +77 -37
  329. ksadk/runtime/session_storage.py +71 -0
  330. ksadk/sandbox/backends/e2b.py +95 -13
  331. ksadk/sandbox/backends/local_process.py +68 -4
  332. ksadk/sandbox/base.py +1 -1
  333. ksadk/sandbox/diagnostics.py +31 -0
  334. ksadk/sandbox/e2b_background.py +1768 -0
  335. ksadk/sandbox/e2b_errors.py +26 -0
  336. ksadk/sandbox/local_background.py +406 -0
  337. ksadk/sandbox/local_controls.py +8 -1
  338. ksadk/server/database_access.py +369 -0
  339. ksadk/server/database_access_contract.py +222 -0
  340. ksadk/server/factory.py +180 -3
  341. ksadk/server/history_deadline.py +20 -4
  342. ksadk/server/history_page_cache.py +8 -2
  343. ksadk/server/routes/common.py +13 -1
  344. ksadk/server/routes/control.py +2 -1
  345. ksadk/server/routes/database_access.py +17 -0
  346. ksadk/server/routes/dependencies.py +28 -0
  347. ksadk/server/routes/harness_service_view.py +38 -0
  348. ksadk/server/routes/interactions.py +106 -0
  349. ksadk/server/routes/kernel_ingress.py +19 -1
  350. ksadk/server/routes/local_kernel_control.py +80 -0
  351. ksadk/server/routes/openai_compat.py +6 -0
  352. ksadk/server/routes/projection.py +159 -2
  353. ksadk/server/routes/routers.py +6 -0
  354. ksadk/server/routes/run.py +30 -1
  355. ksadk/server/routes/session_identity.py +130 -0
  356. ksadk/server/routes/sessions.py +326 -312
  357. ksadk/server/routes/streaming.py +3 -2
  358. ksadk/server/routes/ui_bootstrap.py +265 -0
  359. ksadk/server/routes/workspace.py +7 -0
  360. ksadk/server/static/a2ui/basic-v0_9_1.json +1383 -0
  361. ksadk/server/static/a2ui/common-types-v0_9.json +305 -0
  362. ksadk/server/static/a2ui/legacy-seven-components.json +230 -0
  363. ksadk/server/static/a2ui/manifest.json +86 -0
  364. ksadk/server/static/a2ui/material-icons-OFL-1.1.txt +93 -0
  365. ksadk/server/static/assets/{ArtifactsPanel-CILaW-fC.js → ArtifactsPanel-Cdr5C_vM.js} +1 -1
  366. ksadk/server/static/assets/{CodeBlock-BVrNVtJC.js → CodeBlock-BWRafud9.js} +6 -6
  367. ksadk/server/static/assets/{MathMessageMarkdown-Dp7c4wWD.js → MathMessageMarkdown-CFKeJIvy.js} +7 -7
  368. ksadk/server/static/assets/{MermaidBlock-Dxop8Rd7.js → MermaidBlock-BneAGUOd.js} +9 -9
  369. ksadk/server/static/assets/NativeTerminalPanel-BHI85zDO.js +1 -0
  370. ksadk/server/static/assets/OfficialA2uiRenderer-BOmT36lJ.js +16 -0
  371. ksadk/server/static/assets/{abnfDiagram-VCTEODGH-ckWDmOzw.js → abnfDiagram-VCTEODGH-DQvlOsBI.js} +1 -1
  372. ksadk/server/static/assets/{arc-DqxJede-.js → arc-CGx0e4pN.js} +1 -1
  373. ksadk/server/static/assets/architecture-7GRP2DOG-CFWjFkDL.js +1 -0
  374. ksadk/server/static/assets/{architectureDiagram-5GKGNRK7-SEQA4bVi.js → architectureDiagram-5GKGNRK7-WyybcNKX.js} +1 -1
  375. ksadk/server/static/assets/{blockDiagram-NRAW4CY4-pM0B-6NJ.js → blockDiagram-NRAW4CY4-C9Cx_GVs.js} +1 -1
  376. ksadk/server/static/assets/{c4Diagram-UCG6FXSJ-m2tuCNVq.js → c4Diagram-UCG6FXSJ-Bh7X3bGr.js} +1 -1
  377. ksadk/server/static/assets/channel-D6Dp_l74.js +1 -0
  378. ksadk/server/static/assets/chunk-2Q5K7J3B-CwmjhFYK.js +1 -0
  379. ksadk/server/static/assets/{chunk-5VM5RSS4-GJHDr9Ww.js → chunk-5VM5RSS4-cP9XupZj.js} +1 -1
  380. ksadk/server/static/assets/{chunk-F27PBJKO-CbAN45AV.js → chunk-F27PBJKO-Bm77fvR9.js} +1 -1
  381. ksadk/server/static/assets/{chunk-G27WJ6UU-D5ngbbzF.js → chunk-G27WJ6UU-DDKNPesQ.js} +1 -1
  382. ksadk/server/static/assets/{chunk-JWPE2WC7-Cc5IwuYC.js → chunk-JWPE2WC7-BqiUDB7s.js} +1 -1
  383. ksadk/server/static/assets/{chunk-LCL6LL3I-CprgDDdJ.js → chunk-LCL6LL3I-C528mMZy.js} +1 -1
  384. ksadk/server/static/assets/{chunk-POPQ4Y6H-CDZhSy82.js → chunk-POPQ4Y6H-CzZ9g_Uf.js} +1 -1
  385. ksadk/server/static/assets/{chunk-RHFEMEQ7-CZchUNro.js → chunk-RHFEMEQ7-CXj4tUZ-.js} +1 -1
  386. ksadk/server/static/assets/{chunk-SVP7TREG-BVruqk6T.js → chunk-SVP7TREG-BHyd85pS.js} +1 -1
  387. ksadk/server/static/assets/{chunk-XXDRQBXY-4ld9SxPN.js → chunk-XXDRQBXY-Qe29PHGe.js} +1 -1
  388. ksadk/server/static/assets/classDiagram-DTDB5LWJ-DsbvkCAV.js +1 -0
  389. ksadk/server/static/assets/classDiagram-v2-JRS7N3AN-DsbvkCAV.js +1 -0
  390. ksadk/server/static/assets/{cose-bilkent-JH36ORCC-Dmyyk_Vp.js → cose-bilkent-JH36ORCC-maRKgeec.js} +1 -1
  391. ksadk/server/static/assets/cynefin-OW5HDTMX-CBZRVuc4.js +1 -0
  392. ksadk/server/static/assets/{cynefinDiagram-5FMLGOSQ-BIyq3EJb.js → cynefinDiagram-5FMLGOSQ-CoD0bEvn.js} +1 -1
  393. ksadk/server/static/assets/{dagre-3AP2YEHR-eBw08Qdk.js → dagre-3AP2YEHR-BkpgQqyW.js} +1 -1
  394. ksadk/server/static/assets/{dagre-DfvnEf45.js → dagre-BUaTFrYa.js} +1 -1
  395. ksadk/server/static/assets/{diagram-S7CK7UJ4-CUSrE3Mg.js → diagram-S7CK7UJ4-25HdTbjE.js} +1 -1
  396. ksadk/server/static/assets/{diagram-UQ7AKVKN-Dq5Zw2gy.js → diagram-UQ7AKVKN-KO-WqOIg.js} +1 -1
  397. ksadk/server/static/assets/{diagram-VSXAHHWV-DyUHfNwT.js → diagram-VSXAHHWV-B360BkDQ.js} +1 -1
  398. ksadk/server/static/assets/{diagram-VX7I27RA-CREmM89O.js → diagram-VX7I27RA-COr1Oqsg.js} +1 -1
  399. ksadk/server/static/assets/{diagram-Z3DM3KII-Dw9zhHUK.js → diagram-Z3DM3KII-CgaKrIwB.js} +1 -1
  400. ksadk/server/static/assets/{dist-AEv-vXf-.js → dist--HftQyp9.js} +1 -1
  401. ksadk/server/static/assets/{dist-pq-nD33R.js → dist-B3Jp5r1e.js} +1 -1
  402. ksadk/server/static/assets/{dist-cxTGfdqx.js → dist-BEbS8Bag.js} +1 -1
  403. ksadk/server/static/assets/{dist-BX_-FENW.js → dist-BQ116UdZ.js} +1 -1
  404. ksadk/server/static/assets/{dist-DDSyLEOX.js → dist-BoRn8a_t.js} +1 -1
  405. ksadk/server/static/assets/{dist-BBsYarrI.js → dist-Brbrdmff.js} +1 -1
  406. ksadk/server/static/assets/{dist-B8Myiet9.js → dist-Bsuusoi0.js} +1 -1
  407. ksadk/server/static/assets/{dist-DUxO0R99.js → dist-Bxcu8Ca0.js} +1 -1
  408. ksadk/server/static/assets/{dist-CVPau3tn.js → dist-By-MVndb.js} +1 -1
  409. ksadk/server/static/assets/{dist-lOy23y43.js → dist-C9BTMVwS.js} +1 -1
  410. ksadk/server/static/assets/{dist-C_qdxcSH.js → dist-CBo9AHUv.js} +1 -1
  411. ksadk/server/static/assets/{dist-bupkyEBZ.js → dist-CR61WJFC.js} +1 -1
  412. ksadk/server/static/assets/{dist-CHpW1BHj.js → dist-CwnkOyDn.js} +1 -1
  413. ksadk/server/static/assets/{dist-0uJ4tdx6.js → dist-CxIl4t92.js} +1 -1
  414. ksadk/server/static/assets/{dist-Cp2PaOMY.js → dist-DKG0OYnk.js} +1 -1
  415. ksadk/server/static/assets/{dist-BQMrUwdI.js → dist-DSw5Ju6-.js} +1 -1
  416. ksadk/server/static/assets/{dist-hL5p1til.js → dist-DXOlCAay.js} +1 -1
  417. ksadk/server/static/assets/{dist-CD4L6ymH.js → dist-DgJ57sRe.js} +1 -1
  418. ksadk/server/static/assets/{dist-CuR5Bgme.js → dist-DmWw0IXB.js} +1 -1
  419. ksadk/server/static/assets/{dist-Co68Apq4.js → dist-DzdXSBJb.js} +1 -1
  420. ksadk/server/static/assets/{dist-B49GzZDb.js → dist-HHvdjADB.js} +1 -1
  421. ksadk/server/static/assets/{dist-QzbGrED_.js → dist-_0Xgu_07.js} +1 -1
  422. ksadk/server/static/assets/{ebnfDiagram-PWID7BFC-BS5LdNoR.js → ebnfDiagram-PWID7BFC-DogDP2db.js} +1 -1
  423. ksadk/server/static/assets/{erDiagram-SSCWMZ5O-Bv1QtiY-.js → erDiagram-SSCWMZ5O-CeBDnUjR.js} +1 -1
  424. ksadk/server/static/assets/eventmodeling-NTZA5JFV-vXZWMkpn.js +1 -0
  425. ksadk/server/static/assets/flowDiagram-A5DVABFB-5LRgzKLv.js +1 -0
  426. ksadk/server/static/assets/{ganttDiagram-EL5Y4UJY-musi-e0G.js → ganttDiagram-EL5Y4UJY-oIQL3MCp.js} +1 -1
  427. ksadk/server/static/assets/gitGraph-4MIJSDKK-BUWSkncI.js +1 -0
  428. ksadk/server/static/assets/{gitGraphDiagram-WWUBYQGX-DH37EGkG.js → gitGraphDiagram-WWUBYQGX-B7qz0cmZ.js} +1 -1
  429. ksadk/server/static/assets/index-4g1ndaxW.js +1132 -0
  430. ksadk/server/static/assets/index-DEVfafsU.css +2 -0
  431. ksadk/server/static/assets/info-A6RAGUB7-CzJ_YrOs.js +1 -0
  432. ksadk/server/static/assets/{infoDiagram-RXCK75RN-C1kEtv2y.js → infoDiagram-RXCK75RN-yQRC41Ya.js} +1 -1
  433. ksadk/server/static/assets/{ishikawaDiagram-5VMMS53U-BCNPyMka.js → ishikawaDiagram-5VMMS53U-BCu4HiwL.js} +1 -1
  434. ksadk/server/static/assets/{journeyDiagram-EYS64GPL--cDbKnjP.js → journeyDiagram-EYS64GPL-JaqmO73K.js} +1 -1
  435. ksadk/server/static/assets/{kanban-definition-3QL26DDD-R1rAVw2f.js → kanban-definition-3QL26DDD-DQo4X8NO.js} +1 -1
  436. ksadk/server/static/assets/{katex-BT-X-V7U.js → katex-t_DWylQw.js} +1 -1
  437. ksadk/server/static/assets/{linear-DTR631iG.js → linear-DWdnI35B.js} +1 -1
  438. ksadk/server/static/assets/material-icons-latin-400-normal-kAwBdRge.woff2 +0 -0
  439. ksadk/server/static/assets/{mermaid-parser.core-DfFzJhX8.js → mermaid-parser.core-BHrT2Pfe.js} +2 -2
  440. ksadk/server/static/assets/{mindmap-definition-FBJOCRG2-D4by_rmk.js → mindmap-definition-FBJOCRG2-PBVAhZYV.js} +1 -1
  441. ksadk/server/static/assets/packet-AYTQ26CC-CXoos6fx.js +1 -0
  442. ksadk/server/static/assets/{pegDiagram-XKGWAZYB-xWXPEh0c.js → pegDiagram-XKGWAZYB-CU_cLfow.js} +1 -1
  443. ksadk/server/static/assets/pie-WAS4IAKB-CjF9NoIt.js +1 -0
  444. ksadk/server/static/assets/{pieDiagram-E7YTZNPT-BudBDlCI.js → pieDiagram-E7YTZNPT-B1h0-_pW.js} +1 -1
  445. ksadk/server/static/assets/{quadrantDiagram-AXDQQJYC-DXZ0PCJF.js → quadrantDiagram-AXDQQJYC-DEMoGo5a.js} +1 -1
  446. ksadk/server/static/assets/radar-RG4KPBEZ-BQGWs9nw.js +1 -0
  447. ksadk/server/static/assets/railroad-74A4TZTK-B6znvLUK.js +1 -0
  448. ksadk/server/static/assets/railroad-abnf-HS5TGJTU-Bzquz0As.js +1 -0
  449. ksadk/server/static/assets/railroad-ebnf-LZEXJU2U-1IikGkb5.js +1 -0
  450. ksadk/server/static/assets/railroad-peg-WCYAUIDC-BKKgHzdc.js +1 -0
  451. ksadk/server/static/assets/{railroadDiagram-O6MQD6OU-BdAYRYB8.js → railroadDiagram-O6MQD6OU-BTAob2wg.js} +1 -1
  452. ksadk/server/static/assets/{requirementDiagram-EFPCY7ZU-CBBmaL70.js → requirementDiagram-EFPCY7ZU-Dl0Q2SuO.js} +1 -1
  453. ksadk/server/static/assets/{sankeyDiagram-P5KCCOFB-Doc3rdwp.js → sankeyDiagram-P5KCCOFB-DeaTWkur.js} +1 -1
  454. ksadk/server/static/assets/{sequenceDiagram-WJ2MYXX4-0J8R8hWW.js → sequenceDiagram-WJ2MYXX4-gFQYrsOd.js} +1 -1
  455. ksadk/server/static/assets/{sizeCapture-X5ZJPWSS-CfFLlWsK.js → sizeCapture-X5ZJPWSS-pGQzddMB.js} +1 -1
  456. ksadk/server/static/assets/{stateDiagram-HBIQ2CUA-jBwkjtTy.js → stateDiagram-HBIQ2CUA-DmpYOZt1.js} +1 -1
  457. ksadk/server/static/assets/stateDiagram-v2-4QOOHH4V-Dolxgkw3.js +1 -0
  458. ksadk/server/static/assets/{swimlanes-XN3QIQJK-B0WxTQf8.js → swimlanes-XN3QIQJK-BfuSAsrr.js} +1 -1
  459. ksadk/server/static/assets/swimlanesDiagram-VK2B7HYN-BuI1erYj.js +8 -0
  460. ksadk/server/static/assets/{timeline-definition-24CTP7MA-BfCT_75A.js → timeline-definition-24CTP7MA-CgJwrrxf.js} +1 -1
  461. ksadk/server/static/assets/treeView-Q6P3EWNA-DtMdDH8N.js +1 -0
  462. ksadk/server/static/assets/treemap-WGGIJYW6-VoU8QtLZ.js +1 -0
  463. ksadk/server/static/assets/{vennDiagram-4TSXK5OY-9gX1VMDC.js → vennDiagram-4TSXK5OY-CBSAgXDd.js} +1 -1
  464. ksadk/server/static/assets/wardley-WFR3VGLG-YWSRB0Zm.js +1 -0
  465. ksadk/server/static/assets/{wardleyDiagram-VM6X3IG4-sEs_BP6O.js → wardleyDiagram-VM6X3IG4-013TZ2JZ.js} +1 -1
  466. ksadk/server/static/assets/{xychartDiagram-S5SC5T6Z-Ll4jvUN9.js → xychartDiagram-S5SC5T6Z-u6Frp8xp.js} +1 -1
  467. ksadk/server/static/index.html +2 -2
  468. ksadk/server/static/ui-source.json +11 -0
  469. ksadk/sessions/_local_service_sync.py +146 -5
  470. ksadk/sessions/_postgres_schema.py +17 -0
  471. ksadk/sessions/base.py +3 -0
  472. ksadk/sessions/continuity.py +7 -1
  473. ksadk/sessions/db_budget.py +14 -12
  474. ksadk/sessions/history_budget.py +7 -0
  475. ksadk/sessions/in_memory.py +113 -4
  476. ksadk/sessions/persistence.py +73 -7
  477. ksadk/sessions/postgres_service.py +948 -8
  478. ksadk/sessions/resilience.py +16 -0
  479. ksadk/sessions/resilient.py +601 -5
  480. ksadk/sessions/topology.py +9 -2
  481. ksadk/skills/mcp_server/register.py +471 -415
  482. ksadk/skills/mcp_server/server.py +239 -217
  483. ksadk/skills/request_connection.py +188 -0
  484. ksadk/skills/runtime/backends/e2b.py +52 -12
  485. ksadk/skills/service_client.py +104 -45
  486. ksadk/studio/api.py +413 -11
  487. ksadk/studio/api_contracts.py +7 -3
  488. ksadk/studio/api_plugin_routes.py +13 -6
  489. ksadk/studio/authoring_coordinator.py +6 -1
  490. ksadk/studio/background_output.py +72 -0
  491. ksadk/studio/build_resolution.py +28 -4
  492. ksadk/studio/cloud.py +516 -7
  493. ksadk/studio/cloud_history.py +149 -0
  494. ksadk/studio/cloud_shared_web.py +32 -3
  495. ksadk/studio/compiler.py +93 -4
  496. ksadk/studio/contracts.py +376 -9
  497. ksadk/studio/dsh_application.py +17 -4
  498. ksadk/studio/execution_host.py +10 -5
  499. ksadk/studio/interaction_submission.py +7 -2
  500. ksadk/studio/mcp_runtime.py +23 -8
  501. ksadk/studio/model_chat_tools.py +22 -10
  502. ksadk/studio/model_client.py +41 -11
  503. ksadk/studio/model_wire_identity.py +24 -0
  504. ksadk/studio/native_background_command_port.py +97 -0
  505. ksadk/studio/native_background_connection.py +230 -0
  506. ksadk/studio/native_background_locator.py +272 -0
  507. ksadk/studio/native_background_ownership.py +255 -0
  508. ksadk/studio/native_background_wakeup.py +686 -0
  509. ksadk/studio/native_browser_port.py +9 -3
  510. ksadk/studio/native_child_skills.py +4 -0
  511. ksadk/studio/native_coding_template.py +287 -0
  512. ksadk/studio/native_command_policy.py +23 -0
  513. ksadk/studio/native_context_evidence.py +81 -0
  514. ksadk/studio/native_context_port.py +13 -2
  515. ksadk/studio/native_directory_observation.py +177 -0
  516. ksadk/studio/native_final_shape.py +148 -19
  517. ksadk/studio/native_mcp_disclosure.py +8 -6
  518. ksadk/studio/native_mcp_tool_port.py +3 -1
  519. ksadk/studio/native_memory_context.py +10 -8
  520. ksadk/studio/native_model_port.py +201 -43
  521. ksadk/studio/native_planning.py +43 -2
  522. ksadk/studio/native_product.py +237 -12
  523. ksadk/studio/native_project_instructions.py +267 -0
  524. ksadk/studio/native_read_budget.py +21 -3
  525. ksadk/studio/native_subagent_port.py +125 -2
  526. ksadk/studio/native_tool_port.py +255 -14
  527. ksadk/studio/native_verification_presentation.py +13 -3
  528. ksadk/studio/plugin_composition.py +8 -1
  529. ksadk/studio/plugin_kernel_adapter.py +13 -0
  530. ksadk/studio/plugin_native_activation.py +6 -4
  531. ksadk/studio/plugin_runtime.py +9 -0
  532. ksadk/studio/presentation.py +12 -0
  533. ksadk/studio/project_instruction_trust.py +54 -0
  534. ksadk/studio/repository.py +1 -1
  535. ksadk/studio/resource_catalog.py +4 -1
  536. ksadk/studio/run_activity.py +8 -0
  537. ksadk/studio/run_service.py +496 -40
  538. ksadk/studio/scheduler_assistant.py +3 -1
  539. ksadk/studio/service.py +101 -2
  540. ksadk/studio/shared_web.py +38 -12
  541. ksadk/studio/shared_web_response_events.py +32 -5
  542. ksadk/studio/static/assets/ChannelsPage-Do_mRmVu.js +8 -0
  543. ksadk/studio/static/assets/{CodeBlock-DMIf4h33-CkufcPYo.js → CodeBlock-DMIf4h33-CsO7rJKv.js} +3 -3
  544. ksadk/studio/static/assets/{ExecutionTree-v3HexvPo-Bk8wzGSy.js → ExecutionTree-v3HexvPo-BeWoMqA-.js} +1 -1
  545. ksadk/studio/static/assets/{MathMessageMarkdown-BesSeCYl-DYG1Wzbx.js → MathMessageMarkdown-BesSeCYl-CiB60plG.js} +1 -1
  546. ksadk/studio/static/assets/{MermaidBlock-H_0qzQDf-BdXtxug_.js → MermaidBlock-H_0qzQDf-oRTZUNRr.js} +3 -3
  547. ksadk/studio/static/assets/{MessageMarkdown-CwMTvgFj-BeyLyQHu.js → MessageMarkdown-CwMTvgFj-BzEmQkHH.js} +5 -5
  548. ksadk/studio/static/assets/OfficialA2uiRenderer-DI49Kpxu-BBxfdj3P.js +16 -0
  549. ksadk/studio/static/assets/{PrismRenderer-5pK6tUdb.js → PrismRenderer-CcrOV6Lf.js} +1 -1
  550. ksadk/studio/static/assets/TeamsPage-qNVYpcox.js +4 -0
  551. ksadk/studio/static/assets/{abnfDiagram-VCTEODGH-Bnb1O3tA.js → abnfDiagram-VCTEODGH-BdEjkX5G.js} +1 -1
  552. ksadk/studio/static/assets/{arc-Pry-7G1_.js → arc-4LNeT6Qr.js} +1 -1
  553. ksadk/studio/static/assets/architecture-7GRP2DOG-C6BmiLXs.js +1 -0
  554. ksadk/studio/static/assets/{architectureDiagram-5GKGNRK7-5Zn1gqJv.js → architectureDiagram-5GKGNRK7-nKXkceF2.js} +3 -3
  555. ksadk/studio/static/assets/{blockDiagram-I7D4REHJ-CLB4L11u.js → blockDiagram-I7D4REHJ-pSawBX0F.js} +1 -1
  556. ksadk/studio/static/assets/{c4Diagram-7LVT6UL2-BOma_Z_F.js → c4Diagram-7LVT6UL2-D3DGtCIa.js} +1 -1
  557. ksadk/studio/static/assets/channel-CwBcaXYb.js +1 -0
  558. ksadk/studio/static/assets/{chunk-2E4U76K2-BFf_huql.js → chunk-2E4U76K2-CfUBZPB8.js} +2 -2
  559. ksadk/studio/static/assets/chunk-2Q5K7J3B-B9fZb2AW.js +1 -0
  560. ksadk/studio/static/assets/{chunk-2ZTRR5NV-C2qZJila.js → chunk-2ZTRR5NV-63jTqPgP.js} +1 -1
  561. ksadk/studio/static/assets/{chunk-3Z5EZCMW-DMniOlPd.js → chunk-3Z5EZCMW-CLzTC-ds.js} +1 -1
  562. ksadk/studio/static/assets/{chunk-4HAMMTFA-DVtDP4rm.js → chunk-4HAMMTFA--k1euiK8.js} +3 -3
  563. ksadk/studio/static/assets/{chunk-5V3GS4D5-i-ZDOEnP.js → chunk-5V3GS4D5--NT8dMSC.js} +1 -1
  564. ksadk/studio/static/assets/{chunk-5VM5RSS4-ZNzvKenW.js → chunk-5VM5RSS4-B4EX-xPG.js} +2 -2
  565. ksadk/studio/static/assets/{chunk-6AZGARVD-BB6FqMl-.js → chunk-6AZGARVD-BxyCuIKr.js} +1 -1
  566. ksadk/studio/static/assets/{chunk-6EIED4P4-DdUJkP0f.js → chunk-6EIED4P4-BqAnqs6L.js} +1 -1
  567. ksadk/studio/static/assets/{chunk-6K3QC6MW-CqVsVn-y.js → chunk-6K3QC6MW-DqKCc1_c.js} +1 -1
  568. ksadk/studio/static/assets/{chunk-6TQVIW2G-DKlLbNIP.js → chunk-6TQVIW2G-NQp6TssR.js} +1 -1
  569. ksadk/studio/static/assets/{chunk-747NJXEK-BFkZPlab.js → chunk-747NJXEK-CFf3ol0D.js} +1 -1
  570. ksadk/studio/static/assets/{chunk-75Z2AOVW-BZNhM4vB.js → chunk-75Z2AOVW-DpzsVI3p.js} +1 -1
  571. ksadk/studio/static/assets/chunk-CLGD4ZFX-BiEFihjn.js +1 -0
  572. ksadk/studio/static/assets/{chunk-DU6HZSFF-CpEZCUgg.js → chunk-DU6HZSFF-HbWKkMwX.js} +3 -3
  573. ksadk/studio/static/assets/{chunk-F27PBJKO-D7pvKf0C.js → chunk-F27PBJKO-BY9pwz0W.js} +1 -1
  574. ksadk/studio/static/assets/{chunk-FOHPRMQF-DHwB1DNv.js → chunk-FOHPRMQF-BAABtQ6R.js} +5 -5
  575. ksadk/studio/static/assets/{chunk-GMAD6QVW-DE_8H717.js → chunk-GMAD6QVW-C-Lw1ag9.js} +1 -1
  576. ksadk/studio/static/assets/{chunk-GVQU2GXP-BfEB0lNv.js → chunk-GVQU2GXP-CCUMaVF8.js} +1 -1
  577. ksadk/studio/static/assets/{chunk-I5DQTOEV-Hm2LfiYI.js → chunk-I5DQTOEV-DpUJ7zEH.js} +1 -1
  578. ksadk/studio/static/assets/{chunk-ICYGCRZG-749o-pGJ.js → chunk-ICYGCRZG-CknVx2uG.js} +1 -1
  579. ksadk/studio/static/assets/{chunk-IH6LHLGP-CC6I9F3i.js → chunk-IH6LHLGP-BJ6nT6RF.js} +1 -1
  580. ksadk/studio/static/assets/{chunk-IMKFNOWR-D38axYOR.js → chunk-IMKFNOWR-CTelL5KO.js} +1 -1
  581. ksadk/studio/static/assets/{chunk-JWPE2WC7-DVXcaiue.js → chunk-JWPE2WC7-CMg2kMrr.js} +1 -1
  582. ksadk/studio/static/assets/{chunk-KI3K4JFJ-Rma-0k_M.js → chunk-KI3K4JFJ-B1SKa0PC.js} +1 -1
  583. ksadk/studio/static/assets/{chunk-L3NEJ4N5-Dq5xn7aL.js → chunk-L3NEJ4N5-C8A22muD.js} +1 -1
  584. ksadk/studio/static/assets/{chunk-LNGE3PJU-DWpGwHrW.js → chunk-LNGE3PJU-D_NJe87O.js} +1 -1
  585. ksadk/studio/static/assets/{chunk-OSK3NFVY-DiCQjx9b.js → chunk-OSK3NFVY-DFHvKoNt.js} +1 -1
  586. ksadk/studio/static/assets/{chunk-OUJLGHUK-D0j2JRSg.js → chunk-OUJLGHUK-DkHSrVKj.js} +1 -1
  587. ksadk/studio/static/assets/{chunk-P2QGCYS3-VdhKmfYq.js → chunk-P2QGCYS3-C3nH7MEr.js} +1 -1
  588. ksadk/studio/static/assets/{chunk-POPQ4Y6H-C1_rzO5M.js → chunk-POPQ4Y6H-CLm6A2JW.js} +1 -1
  589. ksadk/studio/static/assets/{chunk-PWAF6VOD-B45HvflI.js → chunk-PWAF6VOD-BmVQq92D.js} +1 -1
  590. ksadk/studio/static/assets/{chunk-SHT3W25Y-DsCFnRVE.js → chunk-SHT3W25Y-cETj_Yg7.js} +1 -1
  591. ksadk/studio/static/assets/{chunk-SVP7TREG-DljApgRX.js → chunk-SVP7TREG-hm4Ur8KN.js} +1 -1
  592. ksadk/studio/static/assets/{chunk-TICWLB2K-DWqRtyqa.js → chunk-TICWLB2K-BuVjFGjc.js} +1 -1
  593. ksadk/studio/static/assets/{chunk-TLUHSLCS-DUeGgnD5.js → chunk-TLUHSLCS-7mZ4xr0q.js} +2 -2
  594. ksadk/studio/static/assets/{chunk-UY3FDG6J-CnmaAkG5.js → chunk-UY3FDG6J-2nV2i5mW.js} +1 -1
  595. ksadk/studio/static/assets/{chunk-XHIXRSVI-BFQ6B8BE.js → chunk-XHIXRSVI-BIR36bKX.js} +1 -1
  596. ksadk/studio/static/assets/chunk-XXDRQBXY-rafYnJzG.js +1 -0
  597. ksadk/studio/static/assets/classDiagram-ZZMXUADV-DdyoXyMk.js +1 -0
  598. ksadk/studio/static/assets/classDiagram-v2-VYDZK3BY-DdyoXyMk.js +1 -0
  599. ksadk/studio/static/assets/{cose-bilkent-JH36ORCC-om8AY0Mc.js → cose-bilkent-JH36ORCC-B9Ubz7rk.js} +1 -1
  600. ksadk/studio/static/assets/{createLucideIcon-DR0LGTP5.js → createLucideIcon-CTD6_IjT.js} +1 -1
  601. ksadk/studio/static/assets/cynefin-OW5HDTMX-BVS4hy6V.js +1 -0
  602. ksadk/studio/static/assets/{cynefinDiagram-5FMLGOSQ-6BrmK52S.js → cynefinDiagram-5FMLGOSQ-CKrgw1wI.js} +1 -1
  603. ksadk/studio/static/assets/{cytoscape.esm-CGd-uY3x.js → cytoscape.esm-Jip0ihto.js} +16 -16
  604. ksadk/studio/static/assets/{dagre-GXQ25YYZ-buZBRlwz.js → dagre-GXQ25YYZ-NjDjs3Kl.js} +1 -1
  605. ksadk/studio/static/assets/{dagre-PrKaheQc.js → dagre-YnTFOVV4.js} +1 -1
  606. ksadk/studio/static/assets/{diagram-S7CK7UJ4-C6aH78c4.js → diagram-S7CK7UJ4-C6X87QRZ.js} +1 -1
  607. ksadk/studio/static/assets/{diagram-UQ7AKVKN-DY_tQ6C_.js → diagram-UQ7AKVKN-Xf2JVuyK.js} +1 -1
  608. ksadk/studio/static/assets/{diagram-VSXAHHWV-DX9p5cQT.js → diagram-VSXAHHWV-CUZlU7Dr.js} +1 -1
  609. ksadk/studio/static/assets/{diagram-VX7I27RA-DB2WSH8X.js → diagram-VX7I27RA-BOcfFxfe.js} +1 -1
  610. ksadk/studio/static/assets/{diagram-Z3DM3KII-Ce1BJwHE.js → diagram-Z3DM3KII-1zrr7ezR.js} +1 -1
  611. ksadk/studio/static/assets/{dist-v5Q1xZ2K.js → dist-Brlz61T5.js} +1 -1
  612. ksadk/studio/static/assets/{ebnfDiagram-PWID7BFC-Daukxwqf.js → ebnfDiagram-PWID7BFC-C1LymnKg.js} +1 -1
  613. ksadk/studio/static/assets/{erDiagram-RLTQ6QDP-CGthTMmJ.js → erDiagram-RLTQ6QDP-Dm0YWPea.js} +1 -1
  614. ksadk/studio/static/assets/eventmodeling-NTZA5JFV-D9gMNzTL.js +1 -0
  615. ksadk/studio/static/assets/flowDiagram-HODETNUW-NYJgBJQu.js +1 -0
  616. ksadk/studio/static/assets/{ganttDiagram-EL5Y4UJY-BfoAZW9X.js → ganttDiagram-EL5Y4UJY-uJ27IKEw.js} +1 -1
  617. ksadk/studio/static/assets/gitGraph-4MIJSDKK-DQVCMicu.js +1 -0
  618. ksadk/studio/static/assets/{gitGraphDiagram-WWUBYQGX-S985OIJF.js → gitGraphDiagram-WWUBYQGX-mtpvi7ne.js} +3 -3
  619. ksadk/studio/static/assets/index-Cp9Unfkn.css +2 -0
  620. ksadk/studio/static/assets/index-HepnaEeR.js +1152 -0
  621. ksadk/studio/static/assets/{index.dom-BQenBtFm.js → index.dom-DSf_jcX2.js} +1 -1
  622. ksadk/studio/static/assets/info-A6RAGUB7-CMrsF9SP.js +1 -0
  623. ksadk/studio/static/assets/{infoDiagram-27XIBGKW-CO3W8tFn.js → infoDiagram-27XIBGKW-Hqrd2vbU.js} +1 -1
  624. ksadk/studio/static/assets/{ishikawaDiagram-5VMMS53U-BUGEl8cO.js → ishikawaDiagram-5VMMS53U-BB7nm3Dk.js} +1 -1
  625. ksadk/studio/static/assets/{journeyDiagram-3NMN7TZE-Ch2ZYxvr.js → journeyDiagram-3NMN7TZE-BXbRt7Ps.js} +1 -1
  626. ksadk/studio/static/assets/{kanban-definition-UXKFOSKX-Da-Fp4vC.js → kanban-definition-UXKFOSKX-2EtAxRbw.js} +1 -1
  627. ksadk/studio/static/assets/{katex-DhON-x74.js → katex-K_8DQ5UN.js} +1 -1
  628. ksadk/studio/static/assets/{line-BDaeq300.js → line-C4h80pWP.js} +1 -1
  629. ksadk/studio/static/assets/{linear-DmucvK78.js → linear-DCteYK3U.js} +1 -1
  630. ksadk/studio/static/assets/{mermaid-parser.core-Cj5mYdBi.js → mermaid-parser.core-TWhr-wg2.js} +2 -2
  631. ksadk/studio/static/assets/{mindmap-definition-YA3MSWOX-CvlsVQ38.js → mindmap-definition-YA3MSWOX-BC7jpEOt.js} +1 -1
  632. ksadk/studio/static/assets/{ordinal-BDEzSJ7C.js → ordinal-BXUrfsNY.js} +1 -1
  633. ksadk/studio/static/assets/packet-AYTQ26CC-BdMfjW7Z.js +1 -0
  634. ksadk/studio/static/assets/{pegDiagram-XKGWAZYB-BuHuNgT5.js → pegDiagram-XKGWAZYB-C-ZzWopk.js} +1 -1
  635. ksadk/studio/static/assets/pie-WAS4IAKB-B06bKgAM.js +1 -0
  636. ksadk/studio/static/assets/{pieDiagram-E7YTZNPT-DlrWiSOv.js → pieDiagram-E7YTZNPT-DGDL1XJp.js} +1 -1
  637. ksadk/studio/static/assets/{quadrantDiagram-AXDQQJYC-BA3hpUZM.js → quadrantDiagram-AXDQQJYC-DAPa64vy.js} +1 -1
  638. ksadk/studio/static/assets/radar-RG4KPBEZ-4lhecdYg.js +1 -0
  639. ksadk/studio/static/assets/railroad-74A4TZTK-CBTdV2Xq.js +1 -0
  640. ksadk/studio/static/assets/railroad-abnf-HS5TGJTU-D4HzgxJY.js +1 -0
  641. ksadk/studio/static/assets/railroad-ebnf-LZEXJU2U-D-qRzoh8.js +1 -0
  642. ksadk/studio/static/assets/railroad-peg-WCYAUIDC-DYA99dLv.js +1 -0
  643. ksadk/studio/static/assets/{railroadDiagram-O6MQD6OU-BxpAazym.js → railroadDiagram-O6MQD6OU-CkH0b7UT.js} +1 -1
  644. ksadk/studio/static/assets/{react-vendor-BNmTiJ-I.js → react-vendor-CTyAWUMQ.js} +1 -1
  645. ksadk/studio/static/assets/{requirementDiagram-BXWQKSXE-E-Ge0FcV.js → requirementDiagram-BXWQKSXE-BgZ0H8ni.js} +2 -2
  646. ksadk/studio/static/assets/rolldown-runtime-cO0ylGnt.js +1 -0
  647. ksadk/studio/static/assets/{sankeyDiagram-P5KCCOFB-CA6YKhQ3.js → sankeyDiagram-P5KCCOFB-BgqqGK6v.js} +1 -1
  648. ksadk/studio/static/assets/{sequenceDiagram-WJ2MYXX4-CcElXGg4.js → sequenceDiagram-WJ2MYXX4-CbQE1ava.js} +1 -1
  649. ksadk/studio/static/assets/{sizeCapture-INFHLROL-B0uUizjq.js → sizeCapture-INFHLROL-BtEJ4_JN.js} +1 -1
  650. ksadk/studio/static/assets/{src-B6xuSHsQ.js → src-DSHesKRm.js} +1 -1
  651. ksadk/studio/static/assets/{stateDiagram-D77RDMKH-DdXZOFqY.js → stateDiagram-D77RDMKH-D9uG2y8U.js} +1 -1
  652. ksadk/studio/static/assets/stateDiagram-v2-MP3YSRHH-2pITMnQn.js +1 -0
  653. ksadk/studio/static/assets/{swimlanes-42K2YHIH-NtgEEHLY.js → swimlanes-42K2YHIH-B0QgwqLd.js} +1 -1
  654. ksadk/studio/static/assets/swimlanesDiagram-VR7AAH4N-TXD08-JZ.js +8 -0
  655. ksadk/studio/static/assets/{timeline-definition-24CTP7MA-CIuYhNy3.js → timeline-definition-24CTP7MA-tbRyDWb4.js} +1 -1
  656. ksadk/studio/static/assets/treeView-Q6P3EWNA-NawrivXx.js +1 -0
  657. ksadk/studio/static/assets/treemap-WGGIJYW6-DabVcIU4.js +1 -0
  658. ksadk/studio/static/assets/{vennDiagram-4TSXK5OY-7HbApbrv.js → vennDiagram-4TSXK5OY-Xjhys4e4.js} +1 -1
  659. ksadk/studio/static/assets/wardley-WFR3VGLG-BrU5uhdd.js +1 -0
  660. ksadk/studio/static/assets/{wardleyDiagram-VM6X3IG4-CMJiaedy.js → wardleyDiagram-VM6X3IG4--sd605zd.js} +1 -1
  661. ksadk/studio/static/assets/{xychartDiagram-S5SC5T6Z-BdgtMvW2.js → xychartDiagram-S5SC5T6Z-B3XzcsnZ.js} +1 -1
  662. ksadk/studio/static/index.html +9 -9
  663. ksadk/studio/static/ui-source.json +11 -0
  664. ksadk/studio/teams_installation.py +1 -1
  665. ksadk/studio/templates.py +33 -3
  666. ksadk/toolsets/__init__.py +14 -1
  667. ksadk/toolsets/sandbox.py +303 -7
  668. ksadk/toolsets/workspace.py +17 -10
  669. ksadk/toolsets/workspace_editing.py +40 -0
  670. ksadk/toolsets/workspace_model_observation.py +6 -1
  671. ksadk/tracing/__init__.py +10 -1
  672. ksadk/tracing/routed.py +416 -0
  673. ksadk/tracing/setup.py +111 -6
  674. ksadk/tunnel/__init__.py +37 -0
  675. ksadk/tunnel/connector.py +384 -0
  676. ksadk/tunnel/discovery.py +107 -0
  677. ksadk/tunnel/failure.py +168 -0
  678. ksadk/tunnel/http_tools.py +100 -0
  679. ksadk/tunnel/langgraph.py +125 -0
  680. ksadk/tunnel/middleware.py +28 -0
  681. ksadk/tunnel/peers.py +872 -0
  682. ksadk/tunnel/protocol.py +97 -0
  683. ksadk/tunnel/registry.py +306 -0
  684. ksadk/tunnel/runtime.py +147 -0
  685. ksadk/tunnel/server.py +201 -0
  686. ksadk/tunnel/services.py +366 -0
  687. ksadk/tunnel/toolset.py +78 -0
  688. ksadk/version.py +1 -1
  689. ksadk_runtime_common/memory_backend/manifest.py +1 -1
  690. ksadk_runtime_common/memory_backend/providers/ksmem.py +60 -0
  691. ksadk_runtime_common/memory_backend/providers/lancedb.py +1 -2
  692. ksadk_runtime_common/memory_backend/providers/mem0.py +21 -0
  693. ksadk_runtime_common/memory_backend/registry.py +2 -0
  694. ksadk_runtime_common/memory_backend/render.py +1 -1
  695. ksadk_runtime_common/schemas/memory_backend_manifest.schema.json +37 -12
  696. ksadk_runtime_common/schemas/runtime_event_v2.json +2 -1
  697. ksadk/server/static/assets/NativeTerminalPanel-Cjjz8B30.js +0 -1
  698. ksadk/server/static/assets/architecture-7GRP2DOG-pn_DuLy6.js +0 -1
  699. ksadk/server/static/assets/channel-fySsnkft.js +0 -1
  700. ksadk/server/static/assets/chunk-2Q5K7J3B-BheGxKRQ.js +0 -1
  701. ksadk/server/static/assets/classDiagram-DTDB5LWJ-DSfLtNYm.js +0 -1
  702. ksadk/server/static/assets/classDiagram-v2-JRS7N3AN-DSfLtNYm.js +0 -1
  703. ksadk/server/static/assets/cynefin-OW5HDTMX-PFWIGtvA.js +0 -1
  704. ksadk/server/static/assets/eventmodeling-NTZA5JFV-DsM4upQX.js +0 -1
  705. ksadk/server/static/assets/flowDiagram-A5DVABFB-D5NA16k9.js +0 -1
  706. ksadk/server/static/assets/gitGraph-4MIJSDKK-DUCVz-ih.js +0 -1
  707. ksadk/server/static/assets/index-CZdkAvsv.js +0 -244
  708. ksadk/server/static/assets/index-CvXdHgF3.css +0 -2
  709. ksadk/server/static/assets/info-A6RAGUB7-rw0ZNHZp.js +0 -1
  710. ksadk/server/static/assets/packet-AYTQ26CC-Ca4Hvki9.js +0 -1
  711. ksadk/server/static/assets/pie-WAS4IAKB-hwiz6fbw.js +0 -1
  712. ksadk/server/static/assets/radar-RG4KPBEZ-BR1oZXLM.js +0 -1
  713. ksadk/server/static/assets/railroad-74A4TZTK-DfgEISfX.js +0 -1
  714. ksadk/server/static/assets/railroad-abnf-HS5TGJTU-CWOC3rdk.js +0 -1
  715. ksadk/server/static/assets/railroad-ebnf-LZEXJU2U-CiRvHCLY.js +0 -1
  716. ksadk/server/static/assets/railroad-peg-WCYAUIDC-DSDDyJ2f.js +0 -1
  717. ksadk/server/static/assets/stateDiagram-v2-4QOOHH4V-Cw1fPb5w.js +0 -1
  718. ksadk/server/static/assets/swimlanesDiagram-VK2B7HYN-Cc3JMBAF.js +0 -8
  719. ksadk/server/static/assets/treeView-Q6P3EWNA-C05SJHxo.js +0 -1
  720. ksadk/server/static/assets/treemap-WGGIJYW6-BqNLAhc3.js +0 -1
  721. ksadk/server/static/assets/wardley-WFR3VGLG-DokNktqB.js +0 -1
  722. ksadk/studio/static/assets/ChannelsPage-xX5HlMId.js +0 -8
  723. ksadk/studio/static/assets/TeamsPage-CCaaGaVp.js +0 -3
  724. ksadk/studio/static/assets/architecture-7GRP2DOG-BMOPAkUC.js +0 -1
  725. ksadk/studio/static/assets/channel-r8itPEik.js +0 -1
  726. ksadk/studio/static/assets/chunk-2Q5K7J3B-C1jixKkw.js +0 -1
  727. ksadk/studio/static/assets/chunk-CLGD4ZFX-D-GTtyKs.js +0 -1
  728. ksadk/studio/static/assets/chunk-XXDRQBXY-DqAYeljN.js +0 -1
  729. ksadk/studio/static/assets/classDiagram-ZZMXUADV-DjeMNJmu.js +0 -1
  730. ksadk/studio/static/assets/classDiagram-v2-VYDZK3BY-DjeMNJmu.js +0 -1
  731. ksadk/studio/static/assets/cynefin-OW5HDTMX-7tP7QfM3.js +0 -1
  732. ksadk/studio/static/assets/eventmodeling-NTZA5JFV-BR2FzK4R.js +0 -1
  733. ksadk/studio/static/assets/flowDiagram-HODETNUW-CZ1tEenp.js +0 -1
  734. ksadk/studio/static/assets/gitGraph-4MIJSDKK-DYlXv_yJ.js +0 -1
  735. ksadk/studio/static/assets/index-C7DNDik2.css +0 -2
  736. ksadk/studio/static/assets/index-Cy68gTlH.js +0 -265
  737. ksadk/studio/static/assets/info-A6RAGUB7-BlU-8_xu.js +0 -1
  738. ksadk/studio/static/assets/packet-AYTQ26CC-BSJEH9Lb.js +0 -1
  739. ksadk/studio/static/assets/pie-WAS4IAKB-qxv01Y8W.js +0 -1
  740. ksadk/studio/static/assets/radar-RG4KPBEZ-B6h6pWOs.js +0 -1
  741. ksadk/studio/static/assets/railroad-74A4TZTK-CGtTWdGc.js +0 -1
  742. ksadk/studio/static/assets/railroad-abnf-HS5TGJTU-Cq7y22IA.js +0 -1
  743. ksadk/studio/static/assets/railroad-ebnf-LZEXJU2U-V0aQVv9m.js +0 -1
  744. ksadk/studio/static/assets/railroad-peg-WCYAUIDC-BQiIsX_p.js +0 -1
  745. ksadk/studio/static/assets/rolldown-runtime-hePW80VL.js +0 -1
  746. ksadk/studio/static/assets/stateDiagram-v2-MP3YSRHH-CJbOM-QK.js +0 -1
  747. ksadk/studio/static/assets/swimlanesDiagram-VR7AAH4N-D-AVlW8B.js +0 -8
  748. ksadk/studio/static/assets/treeView-Q6P3EWNA-BTTYcvrF.js +0 -1
  749. ksadk/studio/static/assets/treemap-WGGIJYW6-Cg7tyfH8.js +0 -1
  750. ksadk/studio/static/assets/wardley-WFR3VGLG-C6N1rULY.js +0 -1
  751. {agentengine_sdk_python-0.8.6.dist-info → agentengine_sdk_python-0.8.8.dist-info}/entry_points.txt +0 -0
  752. {agentengine_sdk_python-0.8.6.dist-info → agentengine_sdk_python-0.8.8.dist-info}/licenses/LICENSE +0 -0
  753. {agentengine_sdk_python-0.8.6.dist-info → agentengine_sdk_python-0.8.8.dist-info}/top_level.txt +0 -0
  754. /ksadk/studio/static/assets/{array-BifhSqXX.js → array-mTkv7xdZ.js} +0 -0
  755. /ksadk/studio/static/assets/{chunk-Y2CYZVJY-DsF7k-Jl.js → chunk-Y2CYZVJY-C72YQVBQ.js} +0 -0
  756. /ksadk/studio/static/assets/{clsx-DB0hHKMi.js → clsx-BE-4uLAX.js} +0 -0
  757. /ksadk/studio/static/assets/{defaultLocale-BFoDCU3G.js → defaultLocale-YBltSZ3l.js} +0 -0
  758. /ksadk/studio/static/assets/{graphlib-DS17s2tU.js → graphlib-CYZB3_li.js} +0 -0
  759. /ksadk/studio/static/assets/{init-C-OQMol4.js → init-Ccnd9r3c.js} +0 -0
  760. /ksadk/studio/static/assets/{path-fybaL0A-.js → path-BfzAkHoX.js} +0 -0
  761. /ksadk/studio/static/assets/{preload-helper-CO68xz6u.js → preload-helper-2TpOpXko.js} +0 -0
  762. /ksadk/studio/static/assets/{presentation-yYw7xK60-BmcZriri.js → presentation-yYw7xK60-B7PYgYAE.js} +0 -0
  763. /ksadk/studio/static/assets/{rolldown-runtime-Dy4uBu1J-DK3Fl9T5.js → rolldown-runtime-Dy4uBu1J-CmRlGT1x.js} +0 -0
  764. /ksadk/studio/static/assets/{rough.esm-Dy-Kn_BL.js → rough.esm-BF6Sy8cM.js} +0 -0
@@ -28,22 +28,41 @@ from ksadk.harness.native.state import (
28
28
  )
29
29
 
30
30
  from .native_command_settlement import settle_terminal_commands
31
+ from .native_commit_history import (
32
+ CHAIN_USAGE_MIGRATION_ID,
33
+ CHAIN_USAGE_SCHEMA,
34
+ HISTORY_MIGRATION_ID,
35
+ HISTORY_SCHEMA,
36
+ SCHEMA_VERSION,
37
+ decode_snapshot,
38
+ encode_snapshot,
39
+ matches_payload,
40
+ payload_digest,
41
+ schema_digest,
42
+ validate_chain_usage_schema,
43
+ validate_history_schema,
44
+ )
31
45
  from .native_contract import (
32
46
  EffectAlreadyClaimed,
33
47
  LeaseBusy,
48
+ NotificationTurnCreation,
34
49
  PendingCommandConflict,
35
50
  ScopeMismatch,
36
51
  StoreConflict,
52
+ TaskChainUsage,
53
+ check_chain_turn,
37
54
  check_commit,
38
55
  check_fence,
39
56
  check_fork,
40
57
  check_initial,
41
58
  check_intent,
59
+ check_notification_turn,
42
60
  check_receipt,
43
61
  check_scope,
44
62
  check_turn,
45
63
  detached,
46
64
  duplicate_fork,
65
+ duplicate_notification_turn,
47
66
  encode,
48
67
  )
49
68
  from .native_sqlite_audit import (
@@ -127,17 +146,16 @@ class SQLiteRunStore:
127
146
  # process's completed upgrade must not be recorded as our work.
128
147
  self._connection.execute("BEGIN IMMEDIATE")
129
148
  version = self._connection.execute("PRAGMA user_version").fetchone()[0]
130
- if version not in {0, 1, 2}:
149
+ if version not in {0, 1, 2, SCHEMA_VERSION}:
131
150
  raise StoreConflict("unsupported native SQLite schema version")
151
+ prior_runs = (
152
+ self._connection.execute(
153
+ "SELECT 1 FROM sqlite_master WHERE type='table' AND name='native_runs'"
154
+ ).fetchone() is not None
155
+ )
132
156
  if version < 2:
133
157
  # Version 0 is the original unmarked schema. DDL and the
134
158
  # marker commit together; an interrupted upgrade rolls back.
135
- prior_runs = (
136
- self._connection.execute(
137
- "SELECT 1 FROM sqlite_master WHERE type='table' AND name='native_runs'"
138
- ).fetchone()
139
- is not None
140
- )
141
159
  source_digest = _fingerprint(self._connection) if prior_runs else None
142
160
  # This is our fixed DDL, with no literal semicolons. Unlike
143
161
  # executescript, execute does not commit the inspection lock.
@@ -153,8 +171,68 @@ class SQLiteRunStore:
153
171
  (CONSERVATIVE_MIGRATION_ID, SNAPSHOT_READER_VERSION, source_digest, "[]"),
154
172
  )
155
173
  self._executed_migration_ids = (CONSERVATIVE_MIGRATION_ID,)
156
- else:
157
- initialize_audit_tables(self._connection)
174
+ initialize_audit_tables(self._connection)
175
+ if version < SCHEMA_VERSION:
176
+ source_schema = schema_digest(self._connection)
177
+ for statement in HISTORY_SCHEMA.split(";"):
178
+ if statement.strip():
179
+ self._connection.execute(statement)
180
+ validate_history_schema(self._connection)
181
+ self._connection.execute(f"PRAGMA user_version = {SCHEMA_VERSION}")
182
+ if prior_runs:
183
+ # This upgrade only adds the codec/head table. Its source
184
+ # fingerprint describes DDL; old execution rows are untouched.
185
+ self._connection.execute(
186
+ "INSERT OR IGNORE INTO native_store_migrations VALUES (?,?,?,?)",
187
+ (HISTORY_MIGRATION_ID, SNAPSHOT_READER_VERSION, source_schema, "[]"),
188
+ )
189
+ self._executed_migration_ids += (HISTORY_MIGRATION_ID,)
190
+ validate_history_schema(self._connection)
191
+ # Task-chain usage ledger: additive migration with strict schema
192
+ # validation. A pre-existing table with wrong columns is rejected
193
+ # (fail-closed), not silently accepted. The migration is recorded
194
+ # in native_store_migrations for audit; an interrupted upgrade rolls
195
+ # back the entire BEGIN IMMEDIATE transaction.
196
+ chain_already_migrated = (
197
+ self._connection.execute(
198
+ "SELECT 1 FROM native_store_migrations WHERE migration_id=?",
199
+ (CHAIN_USAGE_MIGRATION_ID,),
200
+ ).fetchone() is not None
201
+ )
202
+ # Capture the source schema digest BEFORE any chain-usage DDL, so the
203
+ # audit record describes the pre-migration image — same contract as
204
+ # the history migration (source_schema captured before HISTORY_SCHEMA
205
+ # DDL at line 176 above).
206
+ if not chain_already_migrated:
207
+ chain_source_schema = schema_digest(self._connection)
208
+ # Check if the registration table already existed BEFORE our DDL.
209
+ # This must happen before CREATE TABLE IF NOT EXISTS below.
210
+ registrations_existed_before = (
211
+ self._connection.execute(
212
+ "SELECT 1 FROM sqlite_master WHERE type='table' "
213
+ "AND name='native_task_chain_registrations'"
214
+ ).fetchone() is not None
215
+ )
216
+ # Always run the DDL (IF NOT EXISTS is safe for both fresh and
217
+ # already-migrated DBs). A B12 DB that has native_task_chain_usage
218
+ # but not native_task_chain_registrations will get the new table
219
+ # created here; a table with wrong columns is rejected by validation.
220
+ for statement in CHAIN_USAGE_SCHEMA.split(";"):
221
+ if statement.strip():
222
+ self._connection.execute(statement)
223
+ # Always validate structure — even if already migrated, a corrupt
224
+ # or manually-altered table must be rejected.
225
+ validate_chain_usage_schema(self._connection)
226
+ # Record the migration only if this open actually created the
227
+ # registration table (it didn't exist before our DDL). If it already
228
+ # existed (from a prior open or export), do NOT claim we executed it.
229
+ if not chain_already_migrated and not registrations_existed_before and prior_runs:
230
+ self._connection.execute(
231
+ "INSERT OR IGNORE INTO native_store_migrations VALUES (?,?,?,?)",
232
+ (CHAIN_USAGE_MIGRATION_ID, SNAPSHOT_READER_VERSION,
233
+ chain_source_schema, "[]"),
234
+ )
235
+ self._executed_migration_ids += (CHAIN_USAGE_MIGRATION_ID,)
158
236
  self._connection.commit()
159
237
  except BaseException:
160
238
  self._connection.rollback()
@@ -168,13 +246,23 @@ class SQLiteRunStore:
168
246
  if self._closed:
169
247
  raise StoreConflict("store is closed")
170
248
  connection = self._connection
171
- connection.execute("BEGIN IMMEDIATE" if write else "BEGIN")
249
+ try:
250
+ connection.execute("BEGIN IMMEDIATE" if write else "BEGIN")
251
+ except sqlite3.OperationalError as exc:
252
+ if "locked" in str(exc).lower() or "busy" in str(exc).lower():
253
+ raise StoreConflict("persistent store is busy; retry the operation") from exc
254
+ raise
172
255
  try:
173
256
  yield connection
174
257
  connection.commit()
175
258
  except sqlite3.IntegrityError as exc:
176
259
  connection.rollback()
177
260
  raise StoreConflict("persistent uniqueness or integrity conflict") from exc
261
+ except sqlite3.OperationalError as exc:
262
+ connection.rollback()
263
+ if "locked" in str(exc).lower() or "busy" in str(exc).lower():
264
+ raise StoreConflict("persistent store is busy; retry the operation") from exc
265
+ raise
178
266
  except BaseException:
179
267
  connection.rollback()
180
268
  raise
@@ -274,6 +362,13 @@ class SQLiteRunStore:
274
362
  with self._transaction(write=True) as connection:
275
363
  head = self._session_head(connection, key, snapshot.session_id)
276
364
  check_turn(snapshot, head, expected_parent_run_id)
365
+ members = connection.execute(
366
+ "SELECT r.snapshot FROM native_task_chain_registrations AS c "
367
+ "JOIN native_runs AS r ON r.scope=c.scope AND r.run_id=c.run_id "
368
+ "WHERE c.scope=? AND c.task_chain_id=?",
369
+ (key, snapshot.task_chain_id),
370
+ ).fetchall()
371
+ check_chain_turn(snapshot, (RunSnapshot.model_validate_json(row[0]) for row in members))
277
372
  connection.execute(
278
373
  "INSERT INTO native_runs(scope, run_id, snapshot) VALUES (?, ?, ?)",
279
374
  (key, snapshot.run_id, encode(snapshot)),
@@ -283,6 +378,98 @@ class SQLiteRunStore:
283
378
  "ON CONFLICT(scope, session_id) DO UPDATE SET run_id = excluded.run_id",
284
379
  (key, snapshot.session_id, snapshot.run_id),
285
380
  )
381
+ # Atomically register the task-chain ledger at zero usage in the same
382
+ # transaction. If the chain already has an entry (continuation), skip.
383
+ if snapshot.task_chain_id:
384
+ self._register_chain_in_txn(
385
+ connection, key, snapshot.task_chain_id, snapshot.run_id,
386
+ )
387
+
388
+ def _register_chain_in_txn(
389
+ self, connection: sqlite3.Connection, scope_key: str,
390
+ task_chain_id: str, run_id: str,
391
+ ) -> None:
392
+ """Register chain membership + zero-usage entry if new; verify if existing."""
393
+ # Check if chain is already registered.
394
+ reg_existing = connection.execute(
395
+ "SELECT 1 FROM native_task_chain_registrations "
396
+ "WHERE scope=? AND task_chain_id=? AND run_id=?",
397
+ (scope_key, task_chain_id, run_id),
398
+ ).fetchone()
399
+ if reg_existing is not None:
400
+ return # already registered this run for this chain
401
+ # Check if chain exists at all (any registration).
402
+ chain_exists = connection.execute(
403
+ "SELECT 1 FROM native_task_chain_registrations "
404
+ "WHERE scope=? AND task_chain_id=?",
405
+ (scope_key, task_chain_id),
406
+ ).fetchone()
407
+ if chain_exists is not None:
408
+ # Existing chain: must have a usage entry. If missing → corruption.
409
+ usage_exists = connection.execute(
410
+ "SELECT 1 FROM native_task_chain_usage "
411
+ "WHERE scope=? AND task_chain_id=?",
412
+ (scope_key, task_chain_id),
413
+ ).fetchone()
414
+ if usage_exists is None:
415
+ raise StoreConflict(
416
+ "task-chain registered but usage entry missing; fail-closed"
417
+ )
418
+ # Add this run as a member.
419
+ connection.execute(
420
+ "INSERT INTO native_task_chain_registrations"
421
+ "(scope, task_chain_id, run_id, registered_at) VALUES (?, ?, ?, ?)",
422
+ (scope_key, task_chain_id, run_id, time()),
423
+ )
424
+ else:
425
+ # No registration row for this (chain, run). Check if the chain has
426
+ # a usage entry from a prior migration (legacy DB without registrations
427
+ # table). If so, this is an existing chain that needs backfill, not
428
+ # a brand-new chain.
429
+ usage_exists = connection.execute(
430
+ "SELECT 1 FROM native_task_chain_usage "
431
+ "WHERE scope=? AND task_chain_id=?",
432
+ (scope_key, task_chain_id),
433
+ ).fetchone()
434
+ if usage_exists is not None:
435
+ # Legacy chain with usage but no registration: backfill membership.
436
+ connection.execute(
437
+ "INSERT INTO native_task_chain_registrations"
438
+ "(scope, task_chain_id, run_id, registered_at) VALUES (?, ?, ?, ?)",
439
+ (scope_key, task_chain_id, run_id, time()),
440
+ )
441
+ else:
442
+ # Truly new chain: create registration + zero usage.
443
+ connection.execute(
444
+ "INSERT INTO native_task_chain_registrations"
445
+ "(scope, task_chain_id, run_id, registered_at) VALUES (?, ?, ?, ?)",
446
+ (scope_key, task_chain_id, run_id, time()),
447
+ )
448
+ connection.execute(
449
+ "INSERT INTO native_task_chain_usage(scope, task_chain_id, "
450
+ "model_calls, tool_calls, execution_elapsed_seconds, "
451
+ "compaction_count, descendant_model_calls, "
452
+ "descendant_tool_calls, notification_turns) "
453
+ "VALUES (?, ?, 0, 0, 0.0, 0, 0, 0, 0)",
454
+ (scope_key, task_chain_id),
455
+ )
456
+
457
+ def register_task_chain(
458
+ self, scope: RunScope, task_chain_id: str, run_id: str,
459
+ ) -> None:
460
+ key = encode(scope)
461
+ with self._transaction(write=True) as connection:
462
+ self._register_chain_in_txn(connection, key, task_chain_id, run_id)
463
+
464
+ def chain_is_registered(self, scope: RunScope, task_chain_id: str) -> bool:
465
+ key = encode(scope)
466
+ with self._transaction() as connection:
467
+ row = connection.execute(
468
+ "SELECT 1 FROM native_task_chain_registrations "
469
+ "WHERE scope=? AND task_chain_id=? LIMIT 1",
470
+ (key, task_chain_id),
471
+ ).fetchone()
472
+ return row is not None
286
473
 
287
474
  def create_fork(self, snapshot: RunSnapshot) -> ForkCreation:
288
475
  snapshot = detached(snapshot)
@@ -314,6 +501,277 @@ class SQLiteRunStore:
314
501
  )
315
502
  return ForkCreation(snapshot=snapshot, created=True)
316
503
 
504
+ def create_notification_turn(
505
+ self, snapshot: RunSnapshot, *, expected_parent_run_id: str | None
506
+ ) -> NotificationTurnCreation:
507
+ snapshot = detached(snapshot)
508
+ key = encode(snapshot.scope)
509
+ with self._transaction(write=True) as connection:
510
+ head = self._session_head(connection, key, snapshot.session_id)
511
+ prior = connection.execute(
512
+ "SELECT snapshot FROM native_runs WHERE scope=? AND run_id=?",
513
+ (key, snapshot.run_id),
514
+ ).fetchone()
515
+ if prior is not None:
516
+ # Idempotent repeat: a retry/crash-recovery admission returns the
517
+ # already-created notification turn, never a second run.
518
+ return duplicate_notification_turn(
519
+ snapshot, RunSnapshot.model_validate_json(prior[0])
520
+ )
521
+ # Load the ORIGINAL source run (from the notification_command's
522
+ # source_run_id, or the snapshot's parent_run_id) for task/config/chain
523
+ # binding. The expected_parent_run_id is the current session head (which
524
+ # may be a prior notification turn, not the original source) and is used
525
+ # only for the CAS check inside check_notification_turn.
526
+ original_source_id = (
527
+ snapshot.notification_command.source_run_id
528
+ if snapshot.notification_command is not None
529
+ else snapshot.parent_run_id or ""
530
+ )
531
+ try:
532
+ source = RunSnapshot.model_validate_json(
533
+ self._row(connection, key, original_source_id)[0]
534
+ )
535
+ except KeyError as exc:
536
+ raise StoreConflict("notification source run not found") from exc
537
+ check_notification_turn(snapshot, source, head, expected_parent_run_id)
538
+ members = connection.execute(
539
+ "SELECT r.snapshot FROM native_task_chain_registrations AS c "
540
+ "JOIN native_runs AS r ON r.scope=c.scope AND r.run_id=c.run_id "
541
+ "WHERE c.scope=? AND c.task_chain_id=?",
542
+ (key, snapshot.task_chain_id),
543
+ ).fetchall()
544
+ check_chain_turn(snapshot, (RunSnapshot.model_validate_json(row[0]) for row in members))
545
+ connection.execute(
546
+ "INSERT INTO native_runs(scope, run_id, snapshot) VALUES (?, ?, ?)",
547
+ (key, snapshot.run_id, encode(snapshot)),
548
+ )
549
+ connection.execute(
550
+ "INSERT INTO native_session_heads(scope, session_id, run_id) VALUES (?, ?, ?) "
551
+ "ON CONFLICT(scope, session_id) DO UPDATE SET run_id = excluded.run_id",
552
+ (key, snapshot.session_id, snapshot.run_id),
553
+ )
554
+ # Register the chain (inherits source's chain, so already has an entry).
555
+ if snapshot.task_chain_id:
556
+ self._register_chain_in_txn(
557
+ connection, key, snapshot.task_chain_id, snapshot.run_id,
558
+ )
559
+ return NotificationTurnCreation(snapshot=snapshot, created=True)
560
+
561
+ def task_chain_usage(self, scope: RunScope, task_chain_id: str) -> TaskChainUsage:
562
+ key = encode(scope)
563
+ with self._transaction() as connection:
564
+ row = connection.execute(
565
+ "SELECT model_calls, tool_calls, execution_elapsed_seconds, "
566
+ "compaction_count, descendant_model_calls, descendant_tool_calls, "
567
+ "notification_turns "
568
+ "FROM native_task_chain_usage WHERE scope=? AND task_chain_id=?",
569
+ (key, task_chain_id),
570
+ ).fetchone()
571
+ if row is None:
572
+ # Check if chain is registered but usage missing → corruption.
573
+ reg = connection.execute(
574
+ "SELECT 1 FROM native_task_chain_registrations "
575
+ "WHERE scope=? AND task_chain_id=? LIMIT 1",
576
+ (key, task_chain_id),
577
+ ).fetchone()
578
+ if reg is not None:
579
+ raise StoreConflict(
580
+ "task-chain registered but usage entry missing; fail-closed"
581
+ )
582
+ raise StoreConflict(
583
+ "task-chain ledger entry missing for chain; fail-closed"
584
+ )
585
+ return TaskChainUsage(
586
+ task_chain_id=task_chain_id, model_calls=int(row[0]),
587
+ tool_calls=int(row[1]), execution_elapsed_seconds=float(row[2]),
588
+ compaction_count=int(row[3]), descendant_model_calls=int(row[4]),
589
+ descendant_tool_calls=int(row[5]), notification_turns=int(row[6]),
590
+ )
591
+
592
+ def chain_settled_run_ids(self, scope: RunScope, task_chain_id: str) -> tuple[str, ...]:
593
+ key = encode(scope)
594
+ with self._transaction() as connection:
595
+ rows = connection.execute(
596
+ "SELECT run_id FROM native_task_chain_settled_runs "
597
+ "WHERE scope=? AND task_chain_id=?",
598
+ (key, task_chain_id),
599
+ ).fetchall()
600
+ return tuple(row[0] for row in rows)
601
+
602
+ def chain_has_committed_runs(self, scope: RunScope, task_chain_id: str) -> bool:
603
+ key = encode(scope)
604
+ with self._transaction() as connection:
605
+ # Any committed member pins the ledger, including a later member
606
+ # when the first member was created but never committed.
607
+ row = connection.execute(
608
+ "SELECT 1 FROM native_runs AS r "
609
+ "JOIN native_commits AS c ON c.scope=r.scope AND c.run_id=r.run_id "
610
+ "WHERE r.scope=? AND json_extract(r.snapshot, '$.task_chain_id')=? LIMIT 1",
611
+ (key, task_chain_id),
612
+ ).fetchone()
613
+ return row is not None
614
+
615
+ def settle_task_chain_usage(
616
+ self, scope: RunScope, task_chain_id: str, *,
617
+ commit_id: str, snapshot: RunSnapshot, notification_turn: bool = False,
618
+ compaction_count: int = 0,
619
+ ) -> TaskChainUsage:
620
+ """External settlement entry point — restricted. The snapshot must belong
621
+ to this scope and the run must exist in the store. The atomic in-commit
622
+ path (_settle_chain_in_transaction) is the primary entry; this method is
623
+ for host-initiated reconciliation only and enforces the same scope/run
624
+ checks as the RunStore contract.
625
+ """
626
+ if not isinstance(commit_id, str) or not commit_id:
627
+ raise StoreConflict("settle requires a non-empty commit_id")
628
+ check_scope(scope, snapshot)
629
+ if snapshot.task_chain_id != task_chain_id:
630
+ raise StoreConflict("settle task_chain_id does not match snapshot")
631
+ # Reject non-terminal snapshots: only terminal runs can be settled.
632
+ if not snapshot.phase.terminal:
633
+ raise StoreConflict("settle requires a terminal snapshot")
634
+ key = encode(scope)
635
+ with self._transaction(write=True) as connection:
636
+ # Verify the run exists in this store (not a foreign run).
637
+ self._row(connection, key, snapshot.run_id)
638
+ # Verify the commit_id was actually committed AND the snapshot matches
639
+ # the canonical committed snapshot — not a fabricated commit or a
640
+ # tampered snapshot with inflated model_calls.
641
+ committed_snapshot = decode_snapshot(
642
+ connection, key, snapshot.run_id, commit_id
643
+ )
644
+ # The CANONICAL committed snapshot must be terminal — a caller can
645
+ # forge the passed snapshot's phase to "completed" while the actual
646
+ # committed snapshot at that commit_id is non-terminal (e.g. an
647
+ # early PREPARING_CONTEXT commit). Settling a non-terminal canonical
648
+ # commit would let a reconciler refund the chain ledger (the
649
+ # non-terminal commit carries lower usage). Reject: only a canonical
650
+ # terminal commit may be settled. (Runs are immutable once terminal;
651
+ # do not invent multiple mutable terminal commits.)
652
+ if not committed_snapshot.phase.terminal:
653
+ raise StoreConflict(
654
+ "settle commit is not a canonical terminal snapshot"
655
+ )
656
+ # The usage counters are taken from the CANONICAL committed snapshot,
657
+ # not the caller's (possibly-forged) copy. The caller's budget
658
+ # fields were already checked to match the canonical snapshot above;
659
+ # use the canonical values so a stale/forged caller snapshot cannot
660
+ # refund or inflate the ledger.
661
+ settle_model_calls = committed_snapshot.model_calls
662
+ settle_tool_calls = committed_snapshot.tool_calls
663
+ settle_elapsed = committed_snapshot.execution_elapsed_seconds
664
+ settle_desc_model = committed_snapshot.descendant_model_calls
665
+ settle_desc_tool = committed_snapshot.descendant_tool_calls
666
+ if (settle_model_calls != snapshot.model_calls
667
+ or settle_tool_calls != snapshot.tool_calls
668
+ or settle_elapsed != snapshot.execution_elapsed_seconds
669
+ or settle_desc_model != snapshot.descendant_model_calls
670
+ or settle_desc_tool != snapshot.descendant_tool_calls
671
+ or committed_snapshot.task_chain_id != snapshot.task_chain_id):
672
+ raise StoreConflict("settle snapshot does not match committed snapshot")
673
+ # Derive compaction_count and is_notification from the CANONICAL
674
+ # committed snapshot (history/origin), not the caller's parameters.
675
+ # The caller's compaction_count/notification_turn are reconciler hints;
676
+ # if they disagree with the canonical facts, reject (fail-closed) —
677
+ # never silently trust a caller-supplied counter that could reset or
678
+ # inflate the chain ledger (e.g. compaction_count=999 on a run with
679
+ # no compaction history, or notification_turn=False on a notification
680
+ # run). This matches the in-commit settlement derivation.
681
+ canonical_compaction = 0
682
+ ch = committed_snapshot.compaction_history
683
+ if isinstance(ch, dict):
684
+ canonical_compaction = int(ch.get("prior_compactions", 0)) + int(ch.get("count", 0))
685
+ canonical_notification = bool(
686
+ isinstance(committed_snapshot.origin, dict)
687
+ and committed_snapshot.origin.get("notification")
688
+ )
689
+ if compaction_count != canonical_compaction:
690
+ raise StoreConflict(
691
+ "settle compaction_count disagrees with canonical compaction history"
692
+ )
693
+ if notification_turn != canonical_notification:
694
+ raise StoreConflict(
695
+ "settle notification_turn disagrees with canonical run origin"
696
+ )
697
+ existing = connection.execute(
698
+ "SELECT model_calls, tool_calls, execution_elapsed_seconds, "
699
+ "compaction_count, descendant_model_calls, descendant_tool_calls, "
700
+ "is_notification FROM native_task_chain_settled_runs "
701
+ "WHERE scope=? AND task_chain_id=? AND run_id=?",
702
+ (key, task_chain_id, snapshot.run_id),
703
+ ).fetchone()
704
+ if existing is not None:
705
+ # Already settled — update commit_id AND usage. The usage is
706
+ # MONOTONIC (high-water): each settled-run counter is the MAX of
707
+ # the existing value and the canonical committed value, so a
708
+ # re-settle with an earlier/lower commit (or a forged stale
709
+ # snapshot) can never refund the chain ledger. is_notification is
710
+ # latched (once a notification turn, always one).
711
+ connection.execute(
712
+ "UPDATE native_task_chain_settled_runs SET commit_id=?, "
713
+ "model_calls=?, tool_calls=?, execution_elapsed_seconds=?, "
714
+ "compaction_count=?, descendant_model_calls=?, "
715
+ "descendant_tool_calls=?, is_notification=? "
716
+ "WHERE scope=? AND task_chain_id=? AND run_id=?",
717
+ (commit_id,
718
+ max(existing[0], settle_model_calls),
719
+ max(existing[1], settle_tool_calls),
720
+ max(existing[2], settle_elapsed),
721
+ max(existing[3], canonical_compaction),
722
+ max(existing[4], settle_desc_model),
723
+ max(existing[5], settle_desc_tool),
724
+ existing[6] or (1 if canonical_notification else 0),
725
+ key, task_chain_id, snapshot.run_id),
726
+ )
727
+ else:
728
+ connection.execute(
729
+ "INSERT INTO native_task_chain_settled_runs "
730
+ "(scope, task_chain_id, run_id, commit_id, model_calls, "
731
+ "tool_calls, execution_elapsed_seconds, compaction_count, "
732
+ "descendant_model_calls, descendant_tool_calls, "
733
+ "is_notification, settled_at) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)",
734
+ (key, task_chain_id, snapshot.run_id, commit_id,
735
+ settle_model_calls, settle_tool_calls,
736
+ settle_elapsed, canonical_compaction,
737
+ settle_desc_model, settle_desc_tool,
738
+ 1 if canonical_notification else 0, time()),
739
+ )
740
+ # Recompute totals from settled-runs.
741
+ totals = connection.execute(
742
+ "SELECT COALESCE(SUM(model_calls),0), COALESCE(SUM(tool_calls),0), "
743
+ "COALESCE(SUM(execution_elapsed_seconds),0.0), "
744
+ "COALESCE(SUM(compaction_count),0), "
745
+ "COALESCE(SUM(descendant_model_calls),0), "
746
+ "COALESCE(SUM(descendant_tool_calls),0), "
747
+ "COALESCE(SUM(is_notification),0) "
748
+ "FROM native_task_chain_settled_runs "
749
+ "WHERE scope=? AND task_chain_id=?",
750
+ (key, task_chain_id),
751
+ ).fetchone()
752
+ connection.execute(
753
+ "INSERT INTO native_task_chain_usage(scope, task_chain_id, "
754
+ "model_calls, tool_calls, execution_elapsed_seconds, "
755
+ "compaction_count, descendant_model_calls, descendant_tool_calls, "
756
+ "notification_turns) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) "
757
+ "ON CONFLICT(scope, task_chain_id) DO UPDATE SET "
758
+ "model_calls=excluded.model_calls, tool_calls=excluded.tool_calls, "
759
+ "execution_elapsed_seconds=excluded.execution_elapsed_seconds, "
760
+ "compaction_count=excluded.compaction_count, "
761
+ "descendant_model_calls=excluded.descendant_model_calls, "
762
+ "descendant_tool_calls=excluded.descendant_tool_calls, "
763
+ "notification_turns=excluded.notification_turns",
764
+ (key, task_chain_id, int(totals[0]), int(totals[1]),
765
+ float(totals[2]), int(totals[3]), int(totals[4]),
766
+ int(totals[5]), int(totals[6])),
767
+ )
768
+ return TaskChainUsage(
769
+ task_chain_id=task_chain_id, model_calls=int(totals[0]),
770
+ tool_calls=int(totals[1]), execution_elapsed_seconds=float(totals[2]),
771
+ compaction_count=int(totals[3]), descendant_model_calls=int(totals[4]),
772
+ descendant_tool_calls=int(totals[5]), notification_turns=int(totals[6]),
773
+ )
774
+
317
775
  def acquire(self, scope: RunScope, run_id: str) -> int:
318
776
  key = encode(scope)
319
777
  with self._transaction(write=True) as connection:
@@ -489,9 +947,9 @@ class SQLiteRunStore:
489
947
  (key, run_id, batch.commit_id),
490
948
  ).fetchone()
491
949
  if prior is not None:
492
- if prior[0] != raw:
950
+ if not matches_payload(prior[0], raw):
493
951
  raise StoreConflict("commit ID payload mismatch")
494
- return RunSnapshot.model_validate_json(prior[1])
952
+ return decode_snapshot(connection, key, run_id, batch.commit_id)
495
953
  current = RunSnapshot.model_validate_json(current_raw)
496
954
  check_commit(current, batch, expected_revision)
497
955
  if delivery is not None:
@@ -624,6 +1082,9 @@ class SQLiteRunStore:
624
1082
  (key, run_id, command_id),
625
1083
  )
626
1084
  saved = encode(batch.snapshot)
1085
+ history, digest, depth, delta_bytes = encode_snapshot(
1086
+ connection, key, run_id, current_raw, saved,
1087
+ )
627
1088
  connection.execute(
628
1089
  "UPDATE native_runs SET snapshot = ? WHERE scope = ? AND run_id = ?",
629
1090
  (saved, key, run_id),
@@ -631,9 +1092,106 @@ class SQLiteRunStore:
631
1092
  connection.execute(
632
1093
  "INSERT INTO native_commits(scope, run_id, commit_id, payload, snapshot) "
633
1094
  "VALUES (?, ?, ?, ?, ?)",
634
- (key, run_id, batch.commit_id, raw, saved),
1095
+ (key, run_id, batch.commit_id, payload_digest(raw, digest), history),
635
1096
  )
636
- return RunSnapshot.model_validate_json(saved)
1097
+ connection.execute(
1098
+ "INSERT INTO native_commit_heads "
1099
+ "(scope, run_id, commit_id, snapshot_digest, delta_depth, delta_bytes) "
1100
+ "VALUES (?,?,?,?,?,?) ON CONFLICT(scope,run_id) DO UPDATE SET "
1101
+ "commit_id=excluded.commit_id, snapshot_digest=excluded.snapshot_digest, "
1102
+ "delta_depth=excluded.delta_depth, delta_bytes=excluded.delta_bytes",
1103
+ (key, run_id, batch.commit_id, digest, depth, delta_bytes),
1104
+ )
1105
+ committed = RunSnapshot.model_validate_json(saved)
1106
+ # Atomically settle task-chain usage in the same transaction as the
1107
+ # commit. If this run just reached a terminal state with a task_chain_id,
1108
+ # charge its usage to the chain ledger — idempotent per commit_id so a
1109
+ # retry/crash-recovery neither double-charges nor drops. A settlement
1110
+ # failure rolls back the entire commit, never a silent gap.
1111
+ if committed.phase.terminal and committed.task_chain_id:
1112
+ self._settle_chain_in_transaction(
1113
+ connection, key, committed, batch.commit_id,
1114
+ )
1115
+ return committed
1116
+
1117
+ def _settle_chain_in_transaction(
1118
+ self, connection: sqlite3.Connection, scope_key: str,
1119
+ committed: RunSnapshot, commit_id: str,
1120
+ ) -> None:
1121
+ """Settle task-chain usage within the caller's commit transaction.
1122
+
1123
+ Per-run high-water mark: a run is charged exactly once regardless of how
1124
+ many terminal commits it has (retry/crash-recovery). The settled-runs
1125
+ subtable keys on (scope, chain, run_id) — if this run already settled,
1126
+ skip. Chain totals are recomputed from the settled-runs subtable, so a
1127
+ re-settlement with a different commit_id for the same run updates the row
1128
+ (not duplicates it). A failure here rolls back the entire commit.
1129
+ """
1130
+ chain_id = committed.task_chain_id
1131
+ if not chain_id:
1132
+ return
1133
+ run_id = committed.run_id
1134
+ # Check if this run already settled for this chain.
1135
+ # Compaction count: total_compactions = prior_compactions + count.
1136
+ compaction_count = 0
1137
+ ch = committed.compaction_history
1138
+ if isinstance(ch, dict):
1139
+ compaction_count = int(ch.get("prior_compactions", 0)) + int(ch.get("count", 0))
1140
+ is_notification = bool(
1141
+ isinstance(committed.origin, dict) and committed.origin.get("notification")
1142
+ )
1143
+ # A later terminal commit can increase the contribution. Upsert a
1144
+ # high-water mark, then recompute totals, matching MemoryRunStore.
1145
+ connection.execute(
1146
+ "INSERT INTO native_task_chain_settled_runs "
1147
+ "(scope, task_chain_id, run_id, commit_id, model_calls, tool_calls, "
1148
+ "execution_elapsed_seconds, compaction_count, descendant_model_calls, "
1149
+ "descendant_tool_calls, is_notification, settled_at) "
1150
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) "
1151
+ "ON CONFLICT(scope, task_chain_id, run_id) DO UPDATE SET "
1152
+ "commit_id=excluded.commit_id, "
1153
+ "model_calls=MAX(model_calls, excluded.model_calls), "
1154
+ "tool_calls=MAX(tool_calls, excluded.tool_calls), "
1155
+ "execution_elapsed_seconds=MAX(execution_elapsed_seconds, "
1156
+ "excluded.execution_elapsed_seconds), "
1157
+ "compaction_count=MAX(compaction_count, excluded.compaction_count), "
1158
+ "descendant_model_calls=MAX(descendant_model_calls, excluded.descendant_model_calls), "
1159
+ "descendant_tool_calls=MAX(descendant_tool_calls, excluded.descendant_tool_calls), "
1160
+ "is_notification=MAX(is_notification, excluded.is_notification)",
1161
+ (scope_key, chain_id, run_id, commit_id,
1162
+ committed.model_calls, committed.tool_calls,
1163
+ committed.execution_elapsed_seconds, compaction_count,
1164
+ committed.descendant_model_calls, committed.descendant_tool_calls,
1165
+ 1 if is_notification else 0, time()),
1166
+ )
1167
+ # Recompute chain totals from the settled-runs subtable (sum, not append).
1168
+ totals = connection.execute(
1169
+ "SELECT "
1170
+ "COALESCE(SUM(model_calls), 0), COALESCE(SUM(tool_calls), 0), "
1171
+ "COALESCE(SUM(execution_elapsed_seconds), 0.0), "
1172
+ "COALESCE(SUM(compaction_count), 0), "
1173
+ "COALESCE(SUM(descendant_model_calls), 0), "
1174
+ "COALESCE(SUM(descendant_tool_calls), 0), "
1175
+ "COALESCE(SUM(is_notification), 0) "
1176
+ "FROM native_task_chain_settled_runs "
1177
+ "WHERE scope=? AND task_chain_id=?",
1178
+ (scope_key, chain_id),
1179
+ ).fetchone()
1180
+ connection.execute(
1181
+ "INSERT INTO native_task_chain_usage(scope, task_chain_id, model_calls, "
1182
+ "tool_calls, execution_elapsed_seconds, compaction_count, "
1183
+ "descendant_model_calls, descendant_tool_calls, notification_turns) "
1184
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) "
1185
+ "ON CONFLICT(scope, task_chain_id) DO UPDATE SET "
1186
+ "model_calls=excluded.model_calls, tool_calls=excluded.tool_calls, "
1187
+ "execution_elapsed_seconds=excluded.execution_elapsed_seconds, "
1188
+ "compaction_count=excluded.compaction_count, "
1189
+ "descendant_model_calls=excluded.descendant_model_calls, "
1190
+ "descendant_tool_calls=excluded.descendant_tool_calls, "
1191
+ "notification_turns=excluded.notification_turns",
1192
+ (scope_key, chain_id, int(totals[0]), int(totals[1]), float(totals[2]),
1193
+ int(totals[3]), int(totals[4]), int(totals[5]), int(totals[6])),
1194
+ )
637
1195
 
638
1196
  def events(self, scope: RunScope, run_id: str, after_seq: int = 0) -> tuple[NativeEvent, ...]:
639
1197
  key = encode(scope)