synalog 2.7.0__tar.gz → 2.9.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (197) hide show
  1. {synalog-2.7.0 → synalog-2.9.0}/Cargo.lock +2 -2
  2. {synalog-2.7.0 → synalog-2.9.0}/Cargo.toml +1 -1
  3. {synalog-2.7.0 → synalog-2.9.0}/PKG-INFO +9 -6
  4. {synalog-2.7.0 → synalog-2.9.0}/README.md +8 -5
  5. {synalog-2.7.0 → synalog-2.9.0}/docs/assertions.md +1 -0
  6. {synalog-2.7.0 → synalog-2.9.0}/docs/cli.md +31 -4
  7. {synalog-2.7.0 → synalog-2.9.0}/docs/development.md +1 -1
  8. {synalog-2.7.0 → synalog-2.9.0}/docs/examples/run.py +3 -2
  9. {synalog-2.7.0 → synalog-2.9.0}/docs/examples/shop/rules/customer_revenue.l +1 -1
  10. {synalog-2.7.0 → synalog-2.9.0}/docs/examples/shop/rules/orders_by_status.l +1 -1
  11. {synalog-2.7.0 → synalog-2.9.0}/docs/examples/shop.log +2 -2
  12. {synalog-2.7.0 → synalog-2.9.0}/docs/examples/smoke/rules/failures_by_device.l +1 -1
  13. {synalog-2.7.0 → synalog-2.9.0}/docs/examples/smoke.log +2 -2
  14. {synalog-2.7.0 → synalog-2.9.0}/docs/getting-started.md +6 -6
  15. {synalog-2.7.0 → synalog-2.9.0}/docs/language/index.md +17 -15
  16. {synalog-2.7.0 → synalog-2.9.0}/docs/python-api.md +1 -1
  17. {synalog-2.7.0 → synalog-2.9.0}/pyproject.toml +1 -1
  18. {synalog-2.7.0 → synalog-2.9.0}/python/synalog/cli.py +133 -4
  19. {synalog-2.7.0 → synalog-2.9.0}/python/synalog/introspect.py +1 -1
  20. {synalog-2.7.0 → synalog-2.9.0}/python/synalog/project.py +153 -8
  21. {synalog-2.7.0 → synalog-2.9.0}/python/synalog/runners.py +178 -98
  22. {synalog-2.7.0 → synalog-2.9.0}/skills/synalog/SKILL.md +14 -13
  23. {synalog-2.7.0/skills/synalog/examples/company/concepts → synalog-2.9.0/skills/synalog/examples/company/relationships}/works_in.l +2 -2
  24. {synalog-2.7.0 → synalog-2.9.0}/skills/synalog/examples/company/rules/team_mate.l +3 -3
  25. {synalog-2.7.0 → synalog-2.9.0}/skills/synalog/examples/sales/rules/total_by_region.l +1 -1
  26. {synalog-2.7.0 → synalog-2.9.0}/src/assertion/translate.rs +60 -5
  27. {synalog-2.7.0 → synalog-2.9.0}/src/compiler/type_inference/builder.rs +26 -1
  28. {synalog-2.7.0 → synalog-2.9.0}/src/verifier/assertions.rs +132 -4
  29. {synalog-2.7.0 → synalog-2.9.0}/uv.lock +1 -1
  30. {synalog-2.7.0 → synalog-2.9.0}/verified/Cargo.toml +1 -1
  31. {synalog-2.7.0 → synalog-2.9.0}/.gitignore +0 -0
  32. {synalog-2.7.0 → synalog-2.9.0}/LICENSE +0 -0
  33. {synalog-2.7.0 → synalog-2.9.0}/NOTICE +0 -0
  34. {synalog-2.7.0 → synalog-2.9.0}/docs/assets/synalog-dark.svg +0 -0
  35. {synalog-2.7.0 → synalog-2.9.0}/docs/assets/synalog-light.svg +0 -0
  36. {synalog-2.7.0 → synalog-2.9.0}/docs/assets/synalog_favicon.png +0 -0
  37. {synalog-2.7.0 → synalog-2.9.0}/docs/benchmark/results.json +0 -0
  38. {synalog-2.7.0 → synalog-2.9.0}/docs/benchmark/speedup_by_engine.png +0 -0
  39. {synalog-2.7.0 → synalog-2.9.0}/docs/benchmark/speedup_distribution.png +0 -0
  40. {synalog-2.7.0 → synalog-2.9.0}/docs/benchmark/summary.md +0 -0
  41. {synalog-2.7.0 → synalog-2.9.0}/docs/benchmark/summary.png +0 -0
  42. {synalog-2.7.0 → synalog-2.9.0}/docs/benchmark/time_comparison.png +0 -0
  43. {synalog-2.7.0 → synalog-2.9.0}/docs/benchmark/verify_by_engine.png +0 -0
  44. {synalog-2.7.0 → synalog-2.9.0}/docs/benchmark.md +0 -0
  45. {synalog-2.7.0 → synalog-2.9.0}/docs/differences-datalog.md +0 -0
  46. {synalog-2.7.0 → synalog-2.9.0}/docs/differences.md +0 -0
  47. {synalog-2.7.0 → synalog-2.9.0}/docs/engines.md +0 -0
  48. {synalog-2.7.0 → synalog-2.9.0}/docs/examples/aggregation.l +0 -0
  49. {synalog-2.7.0 → synalog-2.9.0}/docs/examples/aggregation.log +0 -0
  50. {synalog-2.7.0 → synalog-2.9.0}/docs/examples/directives.l +0 -0
  51. {synalog-2.7.0 → synalog-2.9.0}/docs/examples/directives.log +0 -0
  52. {synalog-2.7.0 → synalog-2.9.0}/docs/examples/functions.l +0 -0
  53. {synalog-2.7.0 → synalog-2.9.0}/docs/examples/functions.log +0 -0
  54. {synalog-2.7.0 → synalog-2.9.0}/docs/examples/functors.l +0 -0
  55. {synalog-2.7.0 → synalog-2.9.0}/docs/examples/functors.log +0 -0
  56. {synalog-2.7.0 → synalog-2.9.0}/docs/examples/getting_started.l +0 -0
  57. {synalog-2.7.0 → synalog-2.9.0}/docs/examples/getting_started.log +0 -0
  58. {synalog-2.7.0 → synalog-2.9.0}/docs/examples/knowledge_graphs.l +0 -0
  59. {synalog-2.7.0 → synalog-2.9.0}/docs/examples/knowledge_graphs.log +0 -0
  60. {synalog-2.7.0 → synalog-2.9.0}/docs/examples/recursion.l +0 -0
  61. {synalog-2.7.0 → synalog-2.9.0}/docs/examples/recursion.log +0 -0
  62. {synalog-2.7.0 → synalog-2.9.0}/docs/examples/shop/data/orders.csv +0 -0
  63. {synalog-2.7.0/docs/examples/shop/concepts → synalog-2.9.0/docs/examples/shop/entities}/customer.l +0 -0
  64. {synalog-2.7.0/docs/examples/shop/concepts → synalog-2.9.0/docs/examples/shop/entities}/order_status.l +0 -0
  65. {synalog-2.7.0 → synalog-2.9.0}/docs/examples/shop/layer.toml +0 -0
  66. {synalog-2.7.0 → synalog-2.9.0}/docs/examples/shop/rules/top_customers.l +0 -0
  67. {synalog-2.7.0 → synalog-2.9.0}/docs/examples/shop/tables/orders.l +0 -0
  68. {synalog-2.7.0 → synalog-2.9.0}/docs/examples/smoke/data/smoke_tests.csv +0 -0
  69. {synalog-2.7.0/docs/examples/smoke/concepts → synalog-2.9.0/docs/examples/smoke/entities}/device.l +0 -0
  70. {synalog-2.7.0/docs/examples/smoke/concepts → synalog-2.9.0/docs/examples/smoke/entities}/test_status.l +0 -0
  71. {synalog-2.7.0 → synalog-2.9.0}/docs/examples/smoke/layer.toml +0 -0
  72. {synalog-2.7.0 → synalog-2.9.0}/docs/examples/smoke/rules/runs_per_day.l +0 -0
  73. {synalog-2.7.0 → synalog-2.9.0}/docs/examples/smoke/tables/smoke_tests.l +0 -0
  74. {synalog-2.7.0 → synalog-2.9.0}/docs/examples/syntax.l +0 -0
  75. {synalog-2.7.0 → synalog-2.9.0}/docs/examples/syntax.log +0 -0
  76. {synalog-2.7.0 → synalog-2.9.0}/docs/examples/temporal.l +0 -0
  77. {synalog-2.7.0 → synalog-2.9.0}/docs/examples/temporal.log +0 -0
  78. {synalog-2.7.0 → synalog-2.9.0}/docs/examples/temporal_graph.l +0 -0
  79. {synalog-2.7.0 → synalog-2.9.0}/docs/examples/temporal_graph.log +0 -0
  80. {synalog-2.7.0 → synalog-2.9.0}/docs/examples/verification.l +0 -0
  81. {synalog-2.7.0 → synalog-2.9.0}/docs/examples/verification.log +0 -0
  82. {synalog-2.7.0 → synalog-2.9.0}/docs/index.md +0 -0
  83. {synalog-2.7.0 → synalog-2.9.0}/docs/javascripts/playground.js +0 -0
  84. {synalog-2.7.0 → synalog-2.9.0}/docs/javascripts/summarize.js +0 -0
  85. {synalog-2.7.0 → synalog-2.9.0}/docs/javascripts/synalog-highlight.js +0 -0
  86. {synalog-2.7.0 → synalog-2.9.0}/docs/knowledge-graphs.md +0 -0
  87. {synalog-2.7.0 → synalog-2.9.0}/docs/language/aggregation.md +0 -0
  88. {synalog-2.7.0 → synalog-2.9.0}/docs/language/directives.md +0 -0
  89. {synalog-2.7.0 → synalog-2.9.0}/docs/language/functions.md +0 -0
  90. {synalog-2.7.0 → synalog-2.9.0}/docs/language/functors.md +0 -0
  91. {synalog-2.7.0 → synalog-2.9.0}/docs/language/recursion.md +0 -0
  92. {synalog-2.7.0 → synalog-2.9.0}/docs/language/syntax.md +0 -0
  93. {synalog-2.7.0 → synalog-2.9.0}/docs/language/temporal.md +0 -0
  94. {synalog-2.7.0 → synalog-2.9.0}/docs/playground/vendor/codemirror.js +0 -0
  95. {synalog-2.7.0 → synalog-2.9.0}/docs/playground.md +0 -0
  96. {synalog-2.7.0 → synalog-2.9.0}/docs/stylesheets/extra.css +0 -0
  97. {synalog-2.7.0 → synalog-2.9.0}/docs/verification.md +0 -0
  98. {synalog-2.7.0 → synalog-2.9.0}/docs/why.md +0 -0
  99. {synalog-2.7.0 → synalog-2.9.0}/img/synalog-dark.svg +0 -0
  100. {synalog-2.7.0 → synalog-2.9.0}/img/synalog-light.svg +0 -0
  101. {synalog-2.7.0 → synalog-2.9.0}/python/synalog/__init__.py +0 -0
  102. {synalog-2.7.0 → synalog-2.9.0}/python/synalog/__main__.py +0 -0
  103. {synalog-2.7.0 → synalog-2.9.0}/python/synalog/checking.py +0 -0
  104. {synalog-2.7.0 → synalog-2.9.0}/python/synalog/config.py +0 -0
  105. {synalog-2.7.0 → synalog-2.9.0}/python/synalog/execution.py +0 -0
  106. {synalog-2.7.0 → synalog-2.9.0}/python/synalog/writes.py +0 -0
  107. {synalog-2.7.0 → synalog-2.9.0}/skills/synalog/examples/company/data/departments.csv +0 -0
  108. {synalog-2.7.0 → synalog-2.9.0}/skills/synalog/examples/company/data/employees.csv +0 -0
  109. {synalog-2.7.0/skills/synalog/examples/company/concepts → synalog-2.9.0/skills/synalog/examples/company/entities}/department.l +0 -0
  110. {synalog-2.7.0/skills/synalog/examples/company/concepts → synalog-2.9.0/skills/synalog/examples/company/entities}/person.l +0 -0
  111. {synalog-2.7.0 → synalog-2.9.0}/skills/synalog/examples/company/layer.toml +0 -0
  112. {synalog-2.7.0 → synalog-2.9.0}/skills/synalog/examples/company/tables/departments.l +0 -0
  113. {synalog-2.7.0 → synalog-2.9.0}/skills/synalog/examples/company/tables/employees.l +0 -0
  114. {synalog-2.7.0 → synalog-2.9.0}/skills/synalog/examples/org/data/employees.csv +0 -0
  115. {synalog-2.7.0/skills/synalog/examples/org/concepts → synalog-2.9.0/skills/synalog/examples/org/entities}/all_managers.l +0 -0
  116. {synalog-2.7.0 → synalog-2.9.0}/skills/synalog/examples/org/layer.toml +0 -0
  117. {synalog-2.7.0 → synalog-2.9.0}/skills/synalog/examples/org/tables/employees.l +0 -0
  118. {synalog-2.7.0 → synalog-2.9.0}/skills/synalog/examples/sales/data/sales.csv +0 -0
  119. {synalog-2.7.0/skills/synalog/examples/sales/concepts → synalog-2.9.0/skills/synalog/examples/sales/entities}/region.l +0 -0
  120. {synalog-2.7.0 → synalog-2.9.0}/skills/synalog/examples/sales/layer.toml +0 -0
  121. {synalog-2.7.0 → synalog-2.9.0}/skills/synalog/examples/sales/rules/monthly_sales.l +0 -0
  122. {synalog-2.7.0 → synalog-2.9.0}/skills/synalog/examples/sales/rules/top_region.l +0 -0
  123. {synalog-2.7.0 → synalog-2.9.0}/skills/synalog/examples/sales/tables/sales.l +0 -0
  124. {synalog-2.7.0 → synalog-2.9.0}/src/assertion/mod.rs +0 -0
  125. {synalog-2.7.0 → synalog-2.9.0}/src/assertion/parse.rs +0 -0
  126. {synalog-2.7.0 → synalog-2.9.0}/src/assertion/report.rs +0 -0
  127. {synalog-2.7.0 → synalog-2.9.0}/src/compiler/annotations.rs +0 -0
  128. {synalog-2.7.0 → synalog-2.9.0}/src/compiler/annotations_test.rs +0 -0
  129. {synalog-2.7.0 → synalog-2.9.0}/src/compiler/dialects.rs +0 -0
  130. {synalog-2.7.0 → synalog-2.9.0}/src/compiler/dialects_test.rs +0 -0
  131. {synalog-2.7.0 → synalog-2.9.0}/src/compiler/expr_translate.rs +0 -0
  132. {synalog-2.7.0 → synalog-2.9.0}/src/compiler/expr_translate_test.rs +0 -0
  133. {synalog-2.7.0 → synalog-2.9.0}/src/compiler/functors.rs +0 -0
  134. {synalog-2.7.0 → synalog-2.9.0}/src/compiler/functors_test.rs +0 -0
  135. {synalog-2.7.0 → synalog-2.9.0}/src/compiler/home_guard.rs +0 -0
  136. {synalog-2.7.0 → synalog-2.9.0}/src/compiler/home_guard_test.rs +0 -0
  137. {synalog-2.7.0 → synalog-2.9.0}/src/compiler/mod.rs +0 -0
  138. {synalog-2.7.0 → synalog-2.9.0}/src/compiler/rule_translate.rs +0 -0
  139. {synalog-2.7.0 → synalog-2.9.0}/src/compiler/rule_translate_test.rs +0 -0
  140. {synalog-2.7.0 → synalog-2.9.0}/src/compiler/type_inference/built_in.rs +0 -0
  141. {synalog-2.7.0 → synalog-2.9.0}/src/compiler/type_inference/edge.rs +0 -0
  142. {synalog-2.7.0 → synalog-2.9.0}/src/compiler/type_inference/expression.rs +0 -0
  143. {synalog-2.7.0 → synalog-2.9.0}/src/compiler/type_inference/graph.rs +0 -0
  144. {synalog-2.7.0 → synalog-2.9.0}/src/compiler/type_inference/inference.rs +0 -0
  145. {synalog-2.7.0 → synalog-2.9.0}/src/compiler/type_inference/intersection.rs +0 -0
  146. {synalog-2.7.0 → synalog-2.9.0}/src/compiler/type_inference/mod.rs +0 -0
  147. {synalog-2.7.0 → synalog-2.9.0}/src/compiler/type_inference/types.rs +0 -0
  148. {synalog-2.7.0 → synalog-2.9.0}/src/compiler/universe.rs +0 -0
  149. {synalog-2.7.0 → synalog-2.9.0}/src/compiler/universe_test.rs +0 -0
  150. {synalog-2.7.0 → synalog-2.9.0}/src/errors.rs +0 -0
  151. {synalog-2.7.0 → synalog-2.9.0}/src/lib.rs +0 -0
  152. {synalog-2.7.0 → synalog-2.9.0}/src/parser/json.rs +0 -0
  153. {synalog-2.7.0 → synalog-2.9.0}/src/parser/json_test.rs +0 -0
  154. {synalog-2.7.0 → synalog-2.9.0}/src/parser/mod.rs +0 -0
  155. {synalog-2.7.0 → synalog-2.9.0}/src/parser/names.rs +0 -0
  156. {synalog-2.7.0 → synalog-2.9.0}/src/parser/parse.rs +0 -0
  157. {synalog-2.7.0 → synalog-2.9.0}/src/parser/parse_test.rs +0 -0
  158. {synalog-2.7.0 → synalog-2.9.0}/src/parser/rewrite.rs +0 -0
  159. {synalog-2.7.0 → synalog-2.9.0}/src/parser/rewrite_test.rs +0 -0
  160. {synalog-2.7.0 → synalog-2.9.0}/src/parser/span.rs +0 -0
  161. {synalog-2.7.0 → synalog-2.9.0}/src/parser/span_test.rs +0 -0
  162. {synalog-2.7.0 → synalog-2.9.0}/src/parser/traverse.rs +0 -0
  163. {synalog-2.7.0 → synalog-2.9.0}/src/parser/traverse_test.rs +0 -0
  164. {synalog-2.7.0 → synalog-2.9.0}/src/python.rs +0 -0
  165. {synalog-2.7.0 → synalog-2.9.0}/src/verifier/arity.rs +0 -0
  166. {synalog-2.7.0 → synalog-2.9.0}/src/verifier/cast.rs +0 -0
  167. {synalog-2.7.0 → synalog-2.9.0}/src/verifier/contradiction.rs +0 -0
  168. {synalog-2.7.0 → synalog-2.9.0}/src/verifier/dependencies.rs +0 -0
  169. {synalog-2.7.0 → synalog-2.9.0}/src/verifier/directives.rs +0 -0
  170. {synalog-2.7.0 → synalog-2.9.0}/src/verifier/front_matter.rs +0 -0
  171. {synalog-2.7.0 → synalog-2.9.0}/src/verifier/functors.rs +0 -0
  172. {synalog-2.7.0 → synalog-2.9.0}/src/verifier/mod.rs +0 -0
  173. {synalog-2.7.0 → synalog-2.9.0}/src/verifier/orderby.rs +0 -0
  174. {synalog-2.7.0 → synalog-2.9.0}/src/verifier/positional.rs +0 -0
  175. {synalog-2.7.0 → synalog-2.9.0}/src/verifier/recursion.rs +0 -0
  176. {synalog-2.7.0 → synalog-2.9.0}/src/verifier/reserved.rs +0 -0
  177. {synalog-2.7.0 → synalog-2.9.0}/src/verifier/safety.rs +0 -0
  178. {synalog-2.7.0 → synalog-2.9.0}/src/verifier/sqlexpr.rs +0 -0
  179. {synalog-2.7.0 → synalog-2.9.0}/src/verifier/stratification.rs +0 -0
  180. {synalog-2.7.0 → synalog-2.9.0}/src/verifier/undefined.rs +0 -0
  181. {synalog-2.7.0 → synalog-2.9.0}/src/verifier/vars.rs +0 -0
  182. {synalog-2.7.0 → synalog-2.9.0}/src/wasm.rs +0 -0
  183. {synalog-2.7.0 → synalog-2.9.0}/verified/src/arity.rs +0 -0
  184. {synalog-2.7.0 → synalog-2.9.0}/verified/src/cast.rs +0 -0
  185. {synalog-2.7.0 → synalog-2.9.0}/verified/src/contradiction.rs +0 -0
  186. {synalog-2.7.0 → synalog-2.9.0}/verified/src/convergence.rs +0 -0
  187. {synalog-2.7.0 → synalog-2.9.0}/verified/src/home.rs +0 -0
  188. {synalog-2.7.0 → synalog-2.9.0}/verified/src/lib.rs +0 -0
  189. {synalog-2.7.0 → synalog-2.9.0}/verified/src/membership.rs +0 -0
  190. {synalog-2.7.0 → synalog-2.9.0}/verified/src/page.rs +0 -0
  191. {synalog-2.7.0 → synalog-2.9.0}/verified/src/plan.rs +0 -0
  192. {synalog-2.7.0 → synalog-2.9.0}/verified/src/quote.rs +0 -0
  193. {synalog-2.7.0 → synalog-2.9.0}/verified/src/recursion.rs +0 -0
  194. {synalog-2.7.0 → synalog-2.9.0}/verified/src/safety.rs +0 -0
  195. {synalog-2.7.0 → synalog-2.9.0}/verified/src/strata.rs +0 -0
  196. {synalog-2.7.0 → synalog-2.9.0}/verified/src/types.rs +0 -0
  197. {synalog-2.7.0 → synalog-2.9.0}/zensical.toml +0 -0
@@ -300,7 +300,7 @@ dependencies = [
300
300
 
301
301
  [[package]]
302
302
  name = "synalog"
303
- version = "2.7.0"
303
+ version = "2.9.0"
304
304
  dependencies = [
305
305
  "anyhow",
306
306
  "indexmap",
@@ -316,7 +316,7 @@ dependencies = [
316
316
 
317
317
  [[package]]
318
318
  name = "synalog-verified"
319
- version = "2.7.0"
319
+ version = "2.9.0"
320
320
  dependencies = [
321
321
  "vstd",
322
322
  ]
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "synalog"
3
- version = "2.7.0"
3
+ version = "2.9.0"
4
4
  edition = "2024"
5
5
  description = "Logic programming for AI agents: Datalog-family language compiling to optimized SQL"
6
6
  license = "Apache-2.0"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: synalog
3
- Version: 2.7.0
3
+ Version: 2.9.0
4
4
  Classifier: Programming Language :: Rust
5
5
  Classifier: Programming Language :: Python :: Implementation :: CPython
6
6
  Classifier: Programming Language :: Python :: 3
@@ -311,13 +311,16 @@ All of these functions accept an optional `engine` keyword that overrides the pr
311
311
 
312
312
  ## Language overview
313
313
 
314
- A Synalog program is a **project**: a folder with a `layer.toml`, holding one predicate per file in three folders, the layout of [semantic layers](https://github.com/SynaLinks/semantic-layers):
314
+ A Synalog program is a **project**: a folder with a `layer.toml`, holding one predicate per file in `tables/`, `entities/`, `relationships/` and `rules/`, the layout of [semantic layers](https://github.com/SynaLinks/semantic-layers):
315
315
 
316
316
  ```
317
317
  shop/
318
+ ├── data/orders.csv # local data files, loaded with --load
318
319
  ├── tables/orders.l # the data: one file per database table
319
- ├── concepts/customer.l # entities and relationships extracted from tables
320
- ├── rules/customer_revenue.l # insights derived from concepts
320
+ ├── entities/customer.l # entities extracted from tables
321
+ ├── entities/order_status.l
322
+ ├── relationships/ # relationships join entities
323
+ ├── rules/customer_revenue.l # insights derived from entities and relationships
321
324
  ├── rules/top_customers.l
322
325
  └── layer.toml # the project's name, description and database
323
326
  ```
@@ -336,7 +339,7 @@ Orders(order_id:, customer_id:, amount:, status:) :-
336
339
  orders(order_id:, customer_id:, amount:, status:);
337
340
  ```
338
341
 
339
- `concepts/customer.l`
342
+ `entities/customer.l`
340
343
 
341
344
  ```synalog
342
345
  ---
@@ -356,7 +359,7 @@ Customer(customer_id:) distinct :- Orders(customer_id:);
356
359
  name: CustomerRevenue
357
360
  description: Total amount ordered by each customer, all statuses included.
358
361
  ---
359
- import concepts.customer.Customer;
362
+ import entities.customer.Customer;
360
363
  import tables.orders.Orders;
361
364
 
362
365
  @OrderBy(CustomerRevenue, "customer_id");
@@ -263,13 +263,16 @@ All of these functions accept an optional `engine` keyword that overrides the pr
263
263
 
264
264
  ## Language overview
265
265
 
266
- A Synalog program is a **project**: a folder with a `layer.toml`, holding one predicate per file in three folders, the layout of [semantic layers](https://github.com/SynaLinks/semantic-layers):
266
+ A Synalog program is a **project**: a folder with a `layer.toml`, holding one predicate per file in `tables/`, `entities/`, `relationships/` and `rules/`, the layout of [semantic layers](https://github.com/SynaLinks/semantic-layers):
267
267
 
268
268
  ```
269
269
  shop/
270
+ ├── data/orders.csv # local data files, loaded with --load
270
271
  ├── tables/orders.l # the data: one file per database table
271
- ├── concepts/customer.l # entities and relationships extracted from tables
272
- ├── rules/customer_revenue.l # insights derived from concepts
272
+ ├── entities/customer.l # entities extracted from tables
273
+ ├── entities/order_status.l
274
+ ├── relationships/ # relationships join entities
275
+ ├── rules/customer_revenue.l # insights derived from entities and relationships
273
276
  ├── rules/top_customers.l
274
277
  └── layer.toml # the project's name, description and database
275
278
  ```
@@ -288,7 +291,7 @@ Orders(order_id:, customer_id:, amount:, status:) :-
288
291
  orders(order_id:, customer_id:, amount:, status:);
289
292
  ```
290
293
 
291
- `concepts/customer.l`
294
+ `entities/customer.l`
292
295
 
293
296
  ```synalog
294
297
  ---
@@ -308,7 +311,7 @@ Customer(customer_id:) distinct :- Orders(customer_id:);
308
311
  name: CustomerRevenue
309
312
  description: Total amount ordered by each customer, all statuses included.
310
313
  ---
311
- import concepts.customer.Customer;
314
+ import entities.customer.Customer;
312
315
  import tables.orders.Orders;
313
316
 
314
317
  @OrderBy(CustomerRevenue, "customer_id");
@@ -194,6 +194,7 @@ Each assertion has a status, which `assertions()` reports:
194
194
  |-------|-------|-----|
195
195
  | `Invalid assertion 'P.name': …` | The statement does not parse, or applies a predicate to the wrong number of arguments | Fix the statement; count the predicate's columns |
196
196
  | `Invalid assertion 'P.name': variable 'v' is quantified by '∀' but never used …` | A `∀`, `∃` or `∑` names a variable its formula never uses | Remove the variable, or use it where it was meant to appear |
197
+ | `Invalid assertion 'P.name': 'v' appears only after '→' …` | A variable meant for every value (after `∀`, or undeclared) is named only in the conclusion, so nothing gives it values | Say "some value" with `∃ v,` right after `→`, or name it in a premise |
197
198
  | `Duplicate assertion 'P.name': …` | The same name is stated twice for a predicate | Give each property its own name |
198
199
  | `Malformed @Assert: …` | The annotation is not `@Assert(Predicate, name: "statement", ...)` | One named argument per property |
199
200
  | `Assertion 'P.name' is violated: …` | The data holds a counterexample | Fix the rule, or the assertion if it was wrong |
@@ -156,7 +156,7 @@ A failing program never produces partial output: `run` either prints the table o
156
156
 
157
157
  ## Projects: `layer.toml`
158
158
 
159
- A Synalog program is a [project](language/index.md): a folder with a `layer.toml`, its predicates in `tables/`, `concepts/` and `rules/`, one per file. The file names and describes the project, and its `[connection]` says which database it runs on, as plain fields — commit it:
159
+ A Synalog program is a [project](language/index.md): a folder with a `layer.toml`, its predicates in `tables/`, `entities/`, `relationships/` and `rules/`, one per file. The file names and describes the project, and its `[connection]` says which database it runs on, as plain fields — commit it:
160
160
 
161
161
  ```toml
162
162
  [project]
@@ -174,20 +174,47 @@ schema = "public"
174
174
 
175
175
  Secrets never go in the file (synalog refuses it): each comes from the environment as `SYNALOG_<ENGINE>_<FIELD>` — `SYNALOG_PSQL_PASSWORD`, `SYNALOG_DATABRICKS_ACCESS_TOKEN`, or `GOOGLE_APPLICATION_CREDENTIALS` for BigQuery — usually from the project's `.env`, kept out of git. Anywhere in the project, `run`, `print`, `verify` and `introspect` use that engine and connection, and [imports](#imports) resolve from the project's folder. The project's file is the only place a connection comes from: `--engine` and an `@Engine` annotation choose the dialect, and a remote engine runs only through the project's connection to it. The fields of every engine are in `synalog.project.ENGINES`.
176
176
 
177
+ ### Init
178
+
179
+ ```console
180
+ $ synalog init
181
+ Initialized /path/to/sales (data, tables, entities, relationships, rules + layer.toml, .env.template, .gitignore, AGENTS.md, CLAUDE.md)
182
+ ```
183
+
184
+ `synalog init [PATH]` scaffolds a layer project — here, or at the given path:
185
+
186
+ ```
187
+ sales/
188
+ ├── data/
189
+ ├── tables/
190
+ ├── entities/
191
+ ├── relationships/
192
+ ├── rules/
193
+ ├── layer.toml
194
+ ├── .env.template
195
+ ├── .gitignore
196
+ ├── AGENTS.md
197
+ └── CLAUDE.md -> AGENTS.md
198
+ ```
199
+
200
+ Each folder gets a `.gitkeep`; `layer.toml` names the project after its folder and documents every engine's connection, commented out (without one the project runs in memory on DuckDB, the default); `.env.template` lists the engines' secrets, to copy to `.env` and fill in; `.gitignore` keeps `.env` out of git. `AGENTS.md` explains the layer — layout, conventions, commands — to any coding agent; `CLAUDE.md` links to it. An existing `layer.toml` is kept and refuses the command: nothing is overwritten.
201
+
177
202
  ### Connect
178
203
 
179
204
  ```console
180
205
  $ synalog connect psql host=db.example.com database=sales user=analyst password=...
181
- Connected /path/to/sales/layer.toml to psql (secrets in .env)
206
+ Connected /path/to/sales/layer.toml to psql (secrets in .env, connection tested)
182
207
  $ synalog connect
183
208
  /path/to/sales/layer.toml
184
209
  engine = psql
185
210
  host = db.example.com
186
211
  ...
187
212
  password: SYNALOG_PSQL_PASSWORD set
213
+ $ synalog connect test
214
+ Connection to psql (db.example.com) works
188
215
  ```
189
216
 
190
- `synalog connect <engine> key=value ...` writes it — the non-secret fields to `layer.toml`, the secret ones to `.env` — `synalog connect` shows it (secrets hidden), `synalog connect clear` removes it. It runs in the project's folder — the nearest `layer.toml`'s, else the current directory — keeps the file's other tables, adds `.env` to `.gitignore`, and writes nothing when a required field is missing.
217
+ `synalog connect <engine> key=value ...` writes it — the non-secret fields to `layer.toml`, the secret ones to `.env` — `synalog connect` shows it (secrets hidden), `synalog connect clear` removes it. It runs in the project's folder — the nearest `layer.toml`'s, else the current directory — keeps the file's other tables, adds `.env` to `.gitignore`, and writes nothing when a required field is missing. The connection is tested before it is written (a database that does not answer writes nothing), and `synalog connect test` re-tests it any time.
191
218
 
192
219
  ### Introspect
193
220
 
@@ -207,7 +234,7 @@ description: Orders.
207
234
  PublicOrders(order_id:, customer_id:, amount:, status:) :- public.orders(order_id:, customer_id:, amount:, status:);
208
235
  ```
209
236
 
210
- Run it again when the schema changes: the declarations are regenerated, and a file's front matter (its description, keywords, ...) is kept as written. A table the database no longer has keeps its file, since concepts may import it, and is listed. It needs a project connected to its database. PostgreSQL, Trino, Presto, Databricks and BigQuery can be introspected.
237
+ Run it again when the schema changes: the declarations are regenerated, and a file's front matter (its description, keywords, ...) is kept as written. A table the database no longer has keeps its file, since entities and relationships may import it, and is listed. It needs a project connected to its database. PostgreSQL, Trino, Presto, Databricks and BigQuery can be introspected.
211
238
 
212
239
  ## Add the skill to your coding agent
213
240
 
@@ -153,7 +153,7 @@ It deploys to GitHub Pages automatically on push via `.github/workflows/docs.yml
153
153
 
154
154
  ### Documentation examples
155
155
 
156
- The example projects (`docs/examples/shop/`, `docs/examples/smoke/`) are laid out as every Synalog project is: `tables/`, `concepts/`, `rules/`, a `layer.toml`, and their data in `data/<table>.csv`. `run.py` loads the data into an in-memory DuckDB, checks every file, runs the predicate its front matter names, and writes the results to `<project>.log`.
156
+ The example projects (`docs/examples/shop/`, `docs/examples/smoke/`) are laid out as every Synalog project is: `tables/`, `entities/`, `relationships/`, `rules/`, a `layer.toml`, and their data in `data/<table>.csv`. `run.py` loads the data into an in-memory DuckDB, checks every file, runs the predicate its front matter names, and writes the results to `<project>.log`.
157
157
 
158
158
  The feature examples (aggregation, functors, recursion, ...) are single `.l` programs with their data as inline facts. For those, the `run.py` harness validates each program with `synalog.check()`, compiles every predicate listed in its `# run:` header, executes the SQL on an in-memory DuckDB, and writes the combined output to the matching `.log` file. A `# load: <file>.csv as <table>` header loads a CSV from `docs/examples/` into a DuckDB table before the predicates run. The `Today`/`Now` built-in concepts need no special handling, since the compiler inlines them per dialect:
159
159
 
@@ -2,7 +2,8 @@
2
2
  """Run every documentation example and capture its output.
3
3
 
4
4
  Each folder holding a ``layer.toml`` is a project, laid out as every
5
- Synalog project is: ``tables/``, ``concepts/`` and ``rules/``, one predicate per
5
+ Synalog project is: ``tables/``, ``entities/``, ``relationships/`` and
6
+ ``rules/``, one predicate per
6
7
  file named in its front matter, and its data in ``data/<table>.csv``. Every file
7
8
  is checked, then its predicate runs on an in-memory DuckDB holding the data;
8
9
  the results go to ``<project>.log``.
@@ -109,7 +110,7 @@ def run_example(path: Path) -> None:
109
110
  path.with_suffix(".log").write_text("\n".join(out) + "\n")
110
111
 
111
112
 
112
- FOLDERS = ("tables", "concepts", "rules")
113
+ FOLDERS = ("tables", "entities", "relationships", "rules")
113
114
 
114
115
 
115
116
  def run_project(folder: Path) -> None:
@@ -3,7 +3,7 @@ name: CustomerRevenue
3
3
  description: Total amount ordered by each customer, all statuses included.
4
4
  keywords: [revenue, spend, sales]
5
5
  ---
6
- import concepts.customer.Customer;
6
+ import entities.customer.Customer;
7
7
  import tables.orders.Orders;
8
8
 
9
9
  @OrderBy(CustomerRevenue, "customer_id");
@@ -2,7 +2,7 @@
2
2
  name: OrdersByStatus
3
3
  description: Number of orders per status.
4
4
  ---
5
- import concepts.order_status.OrderStatus;
5
+ import entities.order_status.OrderStatus;
6
6
  import tables.orders.Orders;
7
7
 
8
8
  @OrderBy(OrdersByStatus, "status");
@@ -10,7 +10,7 @@ $ synalog tables/orders.l run Orders
10
10
  | 5 | 200 | 95 | shipped |
11
11
  (5 rows)
12
12
 
13
- $ synalog concepts/customer.l run Customer
13
+ $ synalog entities/customer.l run Customer
14
14
  | customer_id |
15
15
  |-------------|
16
16
  | 100 |
@@ -18,7 +18,7 @@ $ synalog concepts/customer.l run Customer
18
18
  | 300 |
19
19
  (3 rows)
20
20
 
21
- $ synalog concepts/order_status.l run OrderStatus
21
+ $ synalog entities/order_status.l run OrderStatus
22
22
  | status |
23
23
  |-----------|
24
24
  | cancelled |
@@ -3,7 +3,7 @@ name: FailuresByDevice
3
3
  description: Number of failed smoke tests per device, most failures first.
4
4
  keywords: [failures, errors, broken devices]
5
5
  ---
6
- import concepts.device.Device;
6
+ import entities.device.Device;
7
7
  import tables.smoke_tests.SmokeTests;
8
8
 
9
9
  @OrderBy(FailuresByDevice, "failures DESC");
@@ -17,7 +17,7 @@ $ synalog tables/smoke_tests.l run SmokeTests
17
17
  | 12 | gateway | passed | 1822 | 2026-06-11 20:00:22 |
18
18
  (12 rows)
19
19
 
20
- $ synalog concepts/device.l run Device
20
+ $ synalog entities/device.l run Device
21
21
  | device |
22
22
  |----------|
23
23
  | gateway |
@@ -25,7 +25,7 @@ $ synalog concepts/device.l run Device
25
25
  | sensor-b |
26
26
  (3 rows)
27
27
 
28
- $ synalog concepts/test_status.l run TestStatus
28
+ $ synalog entities/test_status.l run TestStatus
29
29
  | status |
30
30
  |--------|
31
31
  | failed |
@@ -19,7 +19,7 @@ duckdb (the default engine), sqlite and PostgreSQL work out of the box: synalog
19
19
 
20
20
  ## Your first program
21
21
 
22
- A Synalog project maps **tables** (the data), defines **concepts** (entities and relationships extracted from tables) and writes **rules** (what you want to know), one predicate per file (see [Program structure](language/index.md)). You compile a predicate to SQL and run it with any database driver. To start, a single program can hold its own data as facts:
22
+ A Synalog project maps **tables** (the data), defines **entities** and **relationships** (extracted from tables) and writes **rules** (what you want to know), one predicate per file (see [Program structure](language/index.md)). You compile a predicate to SQL and run it with any database driver. To start, a single program can hold its own data as facts:
23
23
 
24
24
  ```python
25
25
  import synalog
@@ -105,7 +105,7 @@ $ npx skills add SynaLinks/synalog # this project
105
105
  $ npx skills add SynaLinks/synalog -g # user-wide, across all projects
106
106
  ```
107
107
 
108
- Then lay out the project as [tables, concepts and rules](language/index.md), one predicate per file. See [Add the skill to your coding agent](cli.md#add-the-skill-to-your-coding-agent) for the per-agent options.
108
+ Then lay out the project as [tables, entities, relationships and rules](language/index.md), one predicate per file. See [Add the skill to your coding agent](cli.md#add-the-skill-to-your-coding-agent) for the per-agent options.
109
109
 
110
110
  ## Querying a CSV file
111
111
 
@@ -119,8 +119,8 @@ Real data lives in files or database tables, not inline facts. Here it is a smal
119
119
  smoke/
120
120
  ├── data/smoke_tests.csv
121
121
  ├── tables/smoke_tests.l
122
- ├── concepts/device.l
123
- ├── concepts/test_status.l
122
+ ├── entities/device.l
123
+ ├── entities/test_status.l
124
124
  ├── rules/failures_by_device.l
125
125
  ├── rules/runs_per_day.l
126
126
  └── layer.toml
@@ -132,10 +132,10 @@ The table file maps the database table `smoke_tests`, referenced by its lowercas
132
132
  --8<-- "docs/examples/smoke/tables/smoke_tests.l"
133
133
  ```
134
134
 
135
- A concept extracts the devices, and a rule counts the failures of each, importing both:
135
+ An entity extracts the devices, and a rule counts the failures of each, importing both:
136
136
 
137
137
  ```synalog
138
- --8<-- "docs/examples/smoke/concepts/device.l"
138
+ --8<-- "docs/examples/smoke/entities/device.l"
139
139
  ```
140
140
 
141
141
  ```synalog
@@ -1,14 +1,15 @@
1
1
  # Program structure
2
2
 
3
- A Synalog program is a **project**: a folder with a `layer.toml`, holding one predicate per file in three folders. This is the layout of [semantic layers](https://github.com/SynaLinks/semantic-layers), and the one this documentation follows.
3
+ A Synalog program is a **project**: a folder with a `layer.toml`, holding one predicate per file in four folders. This is the layout of [semantic layers](https://github.com/SynaLinks/semantic-layers), and the one this documentation follows.
4
4
 
5
5
  ```
6
6
  shop/
7
7
  ├── tables/ # the data: one file per database table
8
8
  │ └── orders.l
9
- ├── concepts/ # what the data is about: entities, relationships, clean views
9
+ ├── entities/ # what the data is about: one kind of thing per file
10
10
  │ ├── customer.l
11
11
  │ └── order_status.l
12
+ ├── relationships/ # what joins entities: one edge per file
12
13
  ├── rules/ # what you want to know: counts, rates, rankings
13
14
  │ ├── customer_revenue.l
14
15
  │ ├── orders_by_status.l
@@ -21,8 +22,9 @@ A predicate's kind is the folder it is in:
21
22
  | Folder | Holds |
22
23
  |---|---|
23
24
  | `tables/` | the data: each file maps one database table to a predicate |
24
- | `concepts/` | entities and relationships extracted from tables (`Customer`, `Purchased`), and views that filter tables or rename messy columns |
25
- | `rules/` | insights derived from concepts and other rules: counts, rates, rankings, trends |
25
+ | `entities/` | entities extracted from tables (`Customer`, `OrderStatus`), and views that filter tables or rename messy columns |
26
+ | `relationships/` | relationships joining entities (`Purchased`, `WorksIn`) |
27
+ | `rules/` | insights derived from entities, relationships and other rules: counts, rates, rankings, trends |
26
28
 
27
29
  ## A file, a predicate
28
30
 
@@ -32,7 +34,7 @@ Each file is named after the predicate it defines, in snake_case: `<folder>/<nam
32
34
  2. one `import` per predicate it builds on, by folder, file and predicate: `import tables.orders.Orders;`;
33
35
  3. the predicate's rules, after its directives. Every predicate is ordered with [`@OrderBy`](directives.md#orderby): results are paginated, and without a stable order a page differs between calls.
34
36
 
35
- `rules/top_customers.l` builds on `rules/customer_revenue.l`, which builds on a concept and a table:
37
+ `rules/top_customers.l` builds on `rules/customer_revenue.l`, which builds on an entity and a table:
36
38
 
37
39
  ```synalog
38
40
  --8<-- "docs/examples/shop/rules/customer_revenue.l"
@@ -54,22 +56,22 @@ A table file maps one database table, referenced by its database name (lowercase
54
56
 
55
57
  Table files are generated from the database's schema: [`synalog introspect`](../cli.md#introspect) writes one per table, ordered by its first column, with a description made from its name until someone writes a better one, and keeps the front matter written by hand when it runs again.
56
58
 
57
- ### Concepts
59
+ ### Entities and relationships
58
60
 
59
- Concepts extract the entities and relationships hidden in tables:
61
+ Entities and relationships extract what the data is about from tables, each kind in its folder:
60
62
 
61
- - Entity concepts are named after the entity: `Customer`, `Product`.
62
- - Relationship concepts are named after the relationship: `Purchased`, `WorksIn`.
63
+ - Entities are named after the entity: `Customer`, `Product`.
64
+ - Relationships are named after the relationship: `Purchased`, `WorksIn`.
63
65
 
64
66
  ```synalog
65
- --8<-- "docs/examples/shop/concepts/customer.l"
67
+ --8<-- "docs/examples/shop/entities/customer.l"
66
68
  ```
67
69
 
68
70
  See [Knowledge graphs](../knowledge-graphs.md) for the full modeling conventions.
69
71
 
70
72
  ### Rules
71
73
 
72
- Rules derive what you want to know from concepts and other rules. They carry no suffix: `CustomerRevenue`, `TopCustomers`.
74
+ Rules derive what you want to know from entities, relationships and other rules. They carry no suffix: `CustomerRevenue`, `TopCustomers`.
73
75
 
74
76
  ## Running a project
75
77
 
@@ -112,7 +114,7 @@ Orders(order_id: 2, customer_id: 100, amount: 1200, status: "pending");
112
114
  Every file opens with YAML front matter, as in Markdown: a first line `---`, the YAML, and a closing `---` line. It says what the file is, and carries metadata for the tools around your project (keywords, ownership, ...). Synalog checks that it is well-formed YAML — a syntax error is reported on its line — and reads two keys, both required: `name` is the predicate the file is about — it must be one the file defines and orders with `@OrderBy` — and `description` says what its rows are, in the words someone would search for (see [verification](../verification.md#front-matter)). Other keys are left to the host (`keywords`, `locked`, ...), and the file parses as if the block were not there, so error line numbers stay those of the file. It must be the very first thing in the file; an opening `---` that is never closed is an error.
113
115
 
114
116
  ```synalog
115
- --8<-- "docs/examples/shop/concepts/customer.l"
117
+ --8<-- "docs/examples/shop/entities/customer.l"
116
118
  ```
117
119
 
118
120
  To read it from Python, use [`front_matter`](../python-api.md#front_matter).
@@ -126,7 +128,7 @@ The power of logic programming is composition: define a predicate once, in its o
126
128
  `import` brings one predicate of another file into scope: `import <folder>.<name>.<Name>;` reads the project's `<folder>/<name>.l` and names its predicate `<Name>`. One import statement names exactly one predicate; every import must be used.
127
129
 
128
130
  ```synalog
129
- import concepts.customer.Customer;
131
+ import entities.customer.Customer;
130
132
  import tables.orders.Orders;
131
133
  ```
132
134
 
@@ -138,10 +140,10 @@ Imports resolve from the project's folder (the one holding `layer.toml`) in the
138
140
 
139
141
  ## Extract categorical values first
140
142
 
141
- For columns like `status`, `type`, `tier`, `category` or `country`, extract the distinct values as a concept *before* writing rules over them. This gives consistency, reuse and discoverability:
143
+ For columns like `status`, `type`, `tier`, `category` or `country`, extract the distinct values as an entity *before* writing rules over them. This gives consistency, reuse and discoverability:
142
144
 
143
145
  ```synalog
144
- --8<-- "docs/examples/shop/concepts/order_status.l"
146
+ --8<-- "docs/examples/shop/entities/order_status.l"
145
147
  ```
146
148
 
147
149
  ```synalog
@@ -222,7 +222,7 @@ The YAML [front matter](language/index.md#front-matter) opening a program file,
222
222
  ```python
223
223
  import yaml, synalog
224
224
 
225
- source = open("concepts/active_customer.l").read()
225
+ source = open("entities/active_customer.l").read()
226
226
  meta = yaml.safe_load(synalog.front_matter(source) or "") or {}
227
227
  meta.get("description") # "Customers with at least one delivered order."
228
228
  ```
@@ -4,7 +4,7 @@ build-backend = "maturin"
4
4
 
5
5
  [project]
6
6
  name = "synalog"
7
- version = "2.7.0"
7
+ version = "2.9.0"
8
8
  description = "Logic programming for AI agents: Datalog-family language compiling to optimized SQL"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -25,6 +25,7 @@ options above also apply to the session.
25
25
 
26
26
  from __future__ import annotations
27
27
 
28
+ import contextlib
28
29
  import csv
29
30
  import os
30
31
  import re
@@ -38,7 +39,7 @@ from rich.syntax import Syntax
38
39
  from rich.table import Table
39
40
  from rich.text import Text
40
41
 
41
- from . import __version__, project
42
+ from . import __version__, project, runners
42
43
  from ._synalog import (
43
44
  SUPPORTED_ENGINES,
44
45
  check,
@@ -163,6 +164,64 @@ def _load_callback(ctx, param, value):
163
164
  return loads
164
165
 
165
166
 
167
+ # ---------------------------------------------------------------------------
168
+ # Project scaffolding (init)
169
+ # ---------------------------------------------------------------------------
170
+
171
+
172
+ def cmd_init(args: tuple[str, ...], project_file: Path | None) -> int:
173
+ """Scaffold a layer project: its folders, layer.toml and .env.template.
174
+
175
+ \b
176
+ synalog init [PATH] create a layer project here (or at PATH)
177
+
178
+ The project is five folders — data/, tables/, entities/, relationships/,
179
+ rules/ — a layer.toml naming it after its folder, a .env.template
180
+ listing every engine's secrets to copy to .env, a .gitignore keeping
181
+ .env out of git, and an AGENTS.md explaining the layer to coding agents
182
+ (CLAUDE.md links to it). The layer.toml documents every engine's
183
+ connection, commented out — without one the project runs in memory on
184
+ DuckDB, the default. An existing layer.toml is kept and refuses the
185
+ command: nothing is overwritten.
186
+ """
187
+ if len(args) > 1:
188
+ raise click.UsageError("usage: synalog init [PATH]")
189
+ target = Path(args[0]) if args else Path.cwd()
190
+ target.mkdir(parents=True, exist_ok=True)
191
+ if (target / "layer.toml").exists():
192
+ fail(f"{target / 'layer.toml'} already exists")
193
+ for folder in ("data", "tables", "entities", "relationships", "rules"):
194
+ (target / folder).mkdir(parents=True, exist_ok=True)
195
+ gitkeep = target / folder / ".gitkeep"
196
+ if not gitkeep.exists():
197
+ gitkeep.touch()
198
+ (target / "layer.toml").write_text(project.template(target.name), encoding="utf-8")
199
+ env_template = target / ".env.template"
200
+ if not env_template.exists():
201
+ env_template.write_text(project.env_template(), encoding="utf-8")
202
+ gitignore = target / ".gitignore"
203
+ if not gitignore.exists():
204
+ gitignore.write_text(
205
+ "# Secrets — copy .env.template to .env and fill it in;"
206
+ " never commit .env.\n.env\n",
207
+ encoding="utf-8",
208
+ )
209
+ agents_md = target / "AGENTS.md"
210
+ if not agents_md.exists():
211
+ agents_md.write_text(project.agents_md(target.name), encoding="utf-8")
212
+ claude_md = target / "CLAUDE.md"
213
+ if not claude_md.exists():
214
+ try:
215
+ os.symlink("AGENTS.md", claude_md)
216
+ except (OSError, NotImplementedError): # no symlink privilege
217
+ claude_md.write_text("@AGENTS.md\n", encoding="utf-8")
218
+ click.echo(
219
+ f"Initialized {target} (data, tables, entities, relationships, rules"
220
+ " + layer.toml, .env.template, .gitignore, AGENTS.md, CLAUDE.md)"
221
+ )
222
+ return 0
223
+
224
+
166
225
  # ---------------------------------------------------------------------------
167
226
  # The project's connection (connect)
168
227
  # ---------------------------------------------------------------------------
@@ -193,17 +252,49 @@ def _engine_fields() -> str:
193
252
  return "\n".join(lines)
194
253
 
195
254
 
255
+ def _candidate(engine: str, fields: dict) -> tuple[dict, dict[str, str]]:
256
+ """The connection the given fields describe, resolved as it would be once
257
+ written — defaults filled, secrets taken from the fields first, then the
258
+ environment — and the fields' secrets named by variable: some drivers
259
+ (BigQuery's client) read only the environment."""
260
+ overlay = {
261
+ project.secret_env(engine, f.key): str(fields[f.key])
262
+ for f in project.ENGINES[engine].fields
263
+ if f.secret and fields.get(f.key) not in (None, "")
264
+ }
265
+ resolved = project.details({"engine": engine, **fields}, env={**os.environ, **overlay})
266
+ return {"engine": engine, **resolved}, overlay
267
+
268
+
269
+ @contextlib.contextmanager
270
+ def _env_overlaid(values: dict[str, str]):
271
+ """``values`` set in the process environment for the block, then restored."""
272
+ saved = {key: os.environ.get(key) for key in values}
273
+ os.environ.update(values)
274
+ try:
275
+ yield
276
+ finally:
277
+ for key, value in saved.items():
278
+ if value is None:
279
+ os.environ.pop(key, None)
280
+ else:
281
+ os.environ[key] = value
282
+
283
+
196
284
  def cmd_connect(args: tuple[str, ...], project_file: Path | None) -> int:
197
285
  """Give the project its database, in its layer.toml.
198
286
 
199
287
  \b
200
288
  synalog connect show the project's connection (secrets hidden)
201
289
  synalog connect <engine> key=value ... connect the project: layer.toml, secrets in .env
290
+ synalog connect test test the project's connection
202
291
  synalog connect clear remove the connection (back to in-memory engines)
203
292
 
204
293
  The project is the folder of the nearest layer.toml, else the current
205
294
  directory. Secret fields (a password, a token) go to its .env, kept out
206
- of git; the others to layer.toml, meant to be committed.
295
+ of git; the others to layer.toml, meant to be committed. The connection
296
+ is tested before it is written: a database that does not answer writes
297
+ nothing.
207
298
  """
208
299
  folder = project_file.parent if project_file is not None else Path.cwd()
209
300
  if not args:
@@ -225,14 +316,49 @@ def cmd_connect(args: tuple[str, ...], project_file: Path | None) -> int:
225
316
  project.clear(folder)
226
317
  click.echo(f"Removed the connection of {folder / project.PROJECT_FILE}")
227
318
  return 0
319
+ if args[0] == "test":
320
+ if len(args) != 1:
321
+ raise click.UsageError("usage: synalog connect test")
322
+ return _connect_test(project_file)
228
323
  engine, fields = args[0], _connection_fields(args[1:])
229
324
  if engine not in project.ENGINES:
230
325
  fail(f"'{engine}' takes no connection; engines that do: {', '.join(project.ENGINES)}\n" + _engine_fields())
231
326
  try:
232
- path = project.write(folder, engine, fields)
327
+ fields = project.check(engine, fields)
328
+ candidate, overlay = _candidate(engine, fields)
233
329
  except project.ProjectError as e:
234
330
  fail(f"{e}\n" + _engine_fields())
235
- click.echo(f"Connected {path} to {engine}" + (" (secrets in .env)" if project.secrets(engine, fields) else ""))
331
+ try:
332
+ with _env_overlaid(overlay): # BigQuery's client reads the environment
333
+ runners.probe(engine, candidate)
334
+ except RunnerUnavailable as e:
335
+ fail(e)
336
+ except Exception as e: # noqa: BLE001 - a driver or server error: report it, no traceback
337
+ fail(f"{type(e).__name__}: {e}")
338
+ # Checked and tested: the write cannot fail.
339
+ path = project.write(folder, engine, fields)
340
+ notes = ["secrets in .env"] if project.secrets(engine, fields) else []
341
+ click.echo(f"Connected {path} to {engine} ({', '.join([*notes, 'connection tested'])})")
342
+ return 0
343
+
344
+
345
+ def _connect_test(project_file: Path | None) -> int:
346
+ """`synalog connect test`: probe the project's connection as written."""
347
+ try:
348
+ conn = project.resolve(project_file.parent) if project_file is not None else None
349
+ except project.ProjectError as e:
350
+ fail(e)
351
+ if conn is None:
352
+ click.echo("No connection: synalog runs in memory (duckdb). " + _CONNECT_USAGE)
353
+ return 0
354
+ try:
355
+ runners.probe(conn["engine"], conn)
356
+ except RunnerUnavailable as e:
357
+ fail(e)
358
+ except Exception as e: # noqa: BLE001 - a driver or server error: report it, no traceback
359
+ fail(f"{type(e).__name__}: {e}")
360
+ where = conn.get("host") or conn.get("server_hostname") or conn.get("project")
361
+ click.echo(f"Connection to {conn['engine']} ({where}) works")
236
362
  return 0
237
363
 
238
364
 
@@ -351,6 +477,7 @@ def main(args, inline, engine, limit, offset, as_csv, search_pattern,
351
477
  synalog program.l run Predicate ... execute and print a table
352
478
  synalog program.l run Predicate --csv execute and print CSV
353
479
  synalog program.l verify [Predicate ...] check the @Assert statements
480
+ synalog init [PATH] scaffold a layer project
354
481
  synalog connect ENGINE KEY=VALUE ... connect the project to its database
355
482
  synalog introspect [ENGINE] write a project's tables/ from its database
356
483
 
@@ -384,6 +511,8 @@ def main(args, inline, engine, limit, offset, as_csv, search_pattern,
384
511
  if project_file is not None:
385
512
  dirs.insert(1 if len(dirs) > 1 else 0, str(project_file.parent))
386
513
  config.load_dotenv(*dirs)
514
+ if args and args[0] == "init" and inline is None:
515
+ sys.exit(cmd_init(args[1:], project_file))
387
516
  if args and args[0] == "connect" and inline is None:
388
517
  sys.exit(cmd_connect(args[1:], project_file))
389
518
  if args and args[0] == "introspect" and inline is None: