trace-agent-lang 0.1.0a2__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 (48) hide show
  1. trace_agent_lang-0.1.0a2/LICENSE +175 -0
  2. trace_agent_lang-0.1.0a2/PKG-INFO +258 -0
  3. trace_agent_lang-0.1.0a2/README.md +240 -0
  4. trace_agent_lang-0.1.0a2/pyproject.toml +29 -0
  5. trace_agent_lang-0.1.0a2/setup.cfg +4 -0
  6. trace_agent_lang-0.1.0a2/tests/test_agent_tools.py +122 -0
  7. trace_agent_lang-0.1.0a2/tests/test_agent_workflow.py +183 -0
  8. trace_agent_lang-0.1.0a2/tests/test_api.py +64 -0
  9. trace_agent_lang-0.1.0a2/tests/test_context.py +84 -0
  10. trace_agent_lang-0.1.0a2/tests/test_counterexamples.py +352 -0
  11. trace_agent_lang-0.1.0a2/tests/test_edge_cases.py +41 -0
  12. trace_agent_lang-0.1.0a2/tests/test_engine.py +181 -0
  13. trace_agent_lang-0.1.0a2/tests/test_field_names.py +36 -0
  14. trace_agent_lang-0.1.0a2/tests/test_formal_gate.py +38 -0
  15. trace_agent_lang-0.1.0a2/tests/test_foundation_adversarial.py +206 -0
  16. trace_agent_lang-0.1.0a2/tests/test_identity.py +252 -0
  17. trace_agent_lang-0.1.0a2/tests/test_identity_cli.py +58 -0
  18. trace_agent_lang-0.1.0a2/tests/test_identity_concurrency.py +260 -0
  19. trace_agent_lang-0.1.0a2/tests/test_lens.py +143 -0
  20. trace_agent_lang-0.1.0a2/tests/test_local_patches.py +82 -0
  21. trace_agent_lang-0.1.0a2/tests/test_saga.py +497 -0
  22. trace_agent_lang-0.1.0a2/tests/test_saga_adversarial.py +192 -0
  23. trace_agent_lang-0.1.0a2/tests/test_saga_chaos.py +361 -0
  24. trace_agent_lang-0.1.0a2/tests/test_saga_faults.py +185 -0
  25. trace_agent_lang-0.1.0a2/tests/test_saga_model.py +53 -0
  26. trace_agent_lang-0.1.0a2/tests/test_schema.py +89 -0
  27. trace_agent_lang-0.1.0a2/tests/test_sdk.py +149 -0
  28. trace_agent_lang-0.1.0a2/tests/test_syntax.py +410 -0
  29. trace_agent_lang-0.1.0a2/trace_agent_lang.egg-info/PKG-INFO +258 -0
  30. trace_agent_lang-0.1.0a2/trace_agent_lang.egg-info/SOURCES.txt +46 -0
  31. trace_agent_lang-0.1.0a2/trace_agent_lang.egg-info/dependency_links.txt +1 -0
  32. trace_agent_lang-0.1.0a2/trace_agent_lang.egg-info/entry_points.txt +3 -0
  33. trace_agent_lang-0.1.0a2/trace_agent_lang.egg-info/top_level.txt +1 -0
  34. trace_agent_lang-0.1.0a2/trace_lang/__init__.py +20 -0
  35. trace_agent_lang-0.1.0a2/trace_lang/__main__.py +186 -0
  36. trace_agent_lang-0.1.0a2/trace_lang/agent_tools.py +241 -0
  37. trace_agent_lang-0.1.0a2/trace_lang/api.py +186 -0
  38. trace_agent_lang-0.1.0a2/trace_lang/context.py +112 -0
  39. trace_agent_lang-0.1.0a2/trace_lang/counterexamples.py +676 -0
  40. trace_agent_lang-0.1.0a2/trace_lang/engine.py +398 -0
  41. trace_agent_lang-0.1.0a2/trace_lang/errors.py +9 -0
  42. trace_agent_lang-0.1.0a2/trace_lang/identity.py +344 -0
  43. trace_agent_lang-0.1.0a2/trace_lang/lens.py +738 -0
  44. trace_agent_lang-0.1.0a2/trace_lang/patches.py +112 -0
  45. trace_agent_lang-0.1.0a2/trace_lang/saga.py +869 -0
  46. trace_agent_lang-0.1.0a2/trace_lang/schema.py +288 -0
  47. trace_agent_lang-0.1.0a2/trace_lang/sdk.py +226 -0
  48. trace_agent_lang-0.1.0a2/trace_lang/syntax.py +774 -0
@@ -0,0 +1,175 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work.
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object
40
+ form, that is based on (or derived from) the Work and for which the
41
+ editorial revisions, annotations, elaborations, or other modifications
42
+ represent, as a whole, an original work of authorship. For the purposes
43
+ of this License, Derivative Works shall not include works that remain
44
+ separable from, or merely link (or bind by name) to the interfaces of,
45
+ the Work and Derivative Works thereof.
46
+
47
+ "Contribution" shall mean any work of authorship, including
48
+ the original version of the Work and any modifications or additions
49
+ to that Work or Derivative Works thereof, that is intentionally
50
+ submitted to Licensor for inclusion in the Work by the copyright owner
51
+ or by an individual or Legal Entity authorized to submit on behalf of
52
+ the copyright owner. For the purposes of this definition, "submitted"
53
+ means any form of electronic, verbal, or written communication sent
54
+ to the Licensor or its representatives, including but not limited to
55
+ communication on electronic mailing lists, source code control systems,
56
+ and issue tracking systems that are managed by, or on behalf of, the
57
+ Licensor for the purpose of discussing and improving the Work, but
58
+ excluding communication that is conspicuously marked or otherwise
59
+ designated in writing by the copyright owner as "Not a Contribution."
60
+
61
+ "Contributor" shall mean Licensor and any individual or Legal Entity
62
+ on behalf of whom a Contribution has been received by Licensor and
63
+ subsequently incorporated within the Work.
64
+
65
+ 2. Grant of Copyright License. Subject to the terms and conditions of
66
+ this License, each Contributor hereby grants to You a perpetual,
67
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
68
+ copyright license to reproduce, prepare Derivative Works of,
69
+ publicly display, publicly perform, sublicense, and distribute the
70
+ Work and such Derivative Works in Source or Object form.
71
+
72
+ 3. Grant of Patent License. Subject to the terms and conditions of
73
+ this License, each Contributor hereby grants to You a perpetual,
74
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
75
+ (except as stated in this section) patent license to make, have made,
76
+ use, offer to sell, sell, import, and otherwise transfer the Work,
77
+ where such license applies only to those patent claims licensable
78
+ by such Contributor that are necessarily infringed by their
79
+ Contribution(s) alone or by combination of their Contribution(s)
80
+ with the Work to which such Contribution(s) was submitted. If You
81
+ institute patent litigation against any entity (including a
82
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
83
+ or a Contribution incorporated within the Work constitutes direct
84
+ or contributory patent infringement, then any patent licenses
85
+ granted to You under this License for that Work shall terminate
86
+ as of the date such litigation is filed.
87
+
88
+ 4. Redistribution. You may reproduce and distribute copies of the
89
+ Work or Derivative Works thereof in any medium, with or without
90
+ modifications, and in Source or Object form, provided that You
91
+ meet the following conditions:
92
+
93
+ (a) You must give any other recipients of the Work or
94
+ Derivative Works a copy of this License; and
95
+
96
+ (b) You must cause any modified files to carry prominent notices
97
+ stating that You changed the files; and
98
+
99
+ (c) You must retain, in the Source form of any Derivative Works
100
+ that You distribute, all copyright, patent, trademark, and
101
+ attribution notices from the Source form of the Work,
102
+ excluding those notices that do not pertain to any part of
103
+ the Derivative Works; and
104
+
105
+ (d) If the Work includes a "NOTICE" text file as part of its
106
+ distribution, then any Derivative Works that You distribute must
107
+ include a readable copy of the attribution notices contained
108
+ within such NOTICE file, excluding those notices that do not
109
+ pertain to any part of the Derivative Works, in at least one
110
+ of the following places: within a NOTICE text file distributed
111
+ as part of the Derivative Works; within the Source form or
112
+ documentation, if provided along with the Derivative Works; or,
113
+ within a display generated by the Derivative Works, if and
114
+ wherever such third-party notices normally appear. The contents
115
+ of the NOTICE file are for informational purposes only and
116
+ do not modify the License. You may add Your own attribution
117
+ notices within Derivative Works that You distribute, alongside
118
+ or as an addendum to the NOTICE text from the Work, provided
119
+ that such additional attribution notices cannot be construed
120
+ as modifying the License.
121
+
122
+ You may add Your own copyright statement to Your modifications and
123
+ may provide additional or different license terms and conditions
124
+ for use, reproduction, or distribution of Your modifications, or
125
+ for any such Derivative Works as a whole, provided Your use,
126
+ reproduction, and distribution of the Work otherwise complies with
127
+ the conditions stated in this License.
128
+
129
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
130
+ any Contribution intentionally submitted for inclusion in the Work
131
+ by You to the Licensor shall be under the terms and conditions of
132
+ this License, without any additional terms or conditions.
133
+ Notwithstanding the above, nothing herein shall supersede or modify
134
+ the terms of any separate license agreement you may have executed
135
+ with Licensor regarding such Contributions.
136
+
137
+ 6. Trademarks. This License does not grant permission to use the trade
138
+ names, trademarks, service marks, or product names of the Licensor,
139
+ except as required for reasonable and customary use in describing the
140
+ origin of the Work and reproducing the content of the NOTICE file.
141
+
142
+ 7. Disclaimer of Warranty. Unless required by applicable law or
143
+ agreed to in writing, Licensor provides the Work (and each
144
+ Contributor provides its Contributions) on an "AS IS" BASIS,
145
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
146
+ implied, including, without limitation, any warranties or conditions
147
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
148
+ PARTICULAR PURPOSE. You are solely responsible for determining the
149
+ appropriateness of using or redistributing the Work and assume any
150
+ risks associated with Your exercise of permissions under this License.
151
+
152
+ 8. Limitation of Liability. In no event and under no legal theory,
153
+ whether in tort (including negligence), contract, or otherwise,
154
+ unless required by applicable law (such as deliberate and grossly
155
+ negligent acts) or agreed to in writing, shall any Contributor be
156
+ liable to You for damages, including any direct, indirect, special,
157
+ incidental, or exemplary damages of any character arising as a
158
+ result of this License or out of the use or inability to use the
159
+ Work (including but not limited to damages for loss of goodwill,
160
+ work stoppage, computer failure or malfunction, or any and all
161
+ other commercial damages or losses), even if such Contributor
162
+ has been advised of the possibility of such damages.
163
+
164
+ 9. Accepting Warranty or Additional Liability. While redistributing
165
+ the Work or Derivative Works thereof, You may choose to offer,
166
+ and charge a fee for, acceptance of support, warranty, indemnity,
167
+ or other liability obligations and/or rights consistent with this
168
+ License. However, in accepting such obligations, You may act only
169
+ on Your own behalf and on Your sole responsibility, not on behalf
170
+ of any other Contributor, and only if You agree to indemnify,
171
+ defend, and hold each Contributor harmless for any liability
172
+ incurred by, or claims asserted against, such Contributor by reason
173
+ of your accepting any such warranty or additional liability.
174
+
175
+ END OF TERMS AND CONDITIONS
@@ -0,0 +1,258 @@
1
+ Metadata-Version: 2.4
2
+ Name: trace-agent-lang
3
+ Version: 0.1.0a2
4
+ Summary: Agent-native computation language & durable transaction runtime with Lean 4 verified invariants
5
+ Author: Trace Contributors
6
+ License: Apache-2.0
7
+ Keywords: agent,saga,transactions,formal-verification,ast,lean4,devtools
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: License :: OSI Approved :: Apache Software License
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: Topic :: Software Development :: Compilers
14
+ Requires-Python: >=3.11
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Dynamic: license-file
18
+
19
+ <div align="center">
20
+
21
+ # ⚡ TRACE / 迹
22
+
23
+ ### The Agent-Native Computation Language & Durable Transaction Runtime
24
+ **Backed by Lean 4.35.0 Machine-Checked Mathematical Invariants**
25
+
26
+ [![Lean 4 Verified](https://img.shields.io/badge/Lean_4.35.0-Verified_(27_Theorems)-blue?logo=lean)](formal/)
27
+ [![Tests](https://img.shields.io/badge/Tests-188%20Passed-success)](tests/)
28
+ [![Admissions](https://img.shields.io/badge/Lean_Admissions-0_Sorry_/_Admit-brightgreen)](formal/)
29
+ [![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](LICENSE)
30
+ [![Python](https://img.shields.io/badge/Python-3.11+-informational)](pyproject.toml)
31
+
32
+ [为什么需要 Trace](#-why-trace) • [使用场景与边界](#-现实中怎么用开发所有项目都要用它吗) • [5分钟快速上手](#-quickstart-in-5-minutes) • [Trace Lens 可视化](#-trace-lens-visual-devtools) • [商业化蓝图](docs/OPEN_CORE_STRATEGY.md)
33
+
34
+ </div>
35
+
36
+ ---
37
+
38
+ ## 💡 Why Trace?
39
+
40
+ When Autonomous AI Agents write and execute software today, they suffer from three fundamental limitations:
41
+
42
+ 1. **Context Window Token Bloat**: LLMs waste 50% to 80% of tokens reading entire files and massive 50-line traceback dumps just to fix a single bug.
43
+ 2. **Crash Inconsistency & Duplicate Side Effects**: When an agent's multi-step execution crashes mid-way (e.g., API timeout or server restart), external effects are leaked, payments double-charged, or compensation order broken.
44
+ 3. **Multi-Agent Collision (Lost Updates)**: Text-based Git diffs fail when multiple agents collaborate on the same file, resulting in torn ASTs and merge conflicts.
45
+
46
+ **Trace solves this at the language and runtime foundation:**
47
+ - 🛡️ **Durable Sagas**: Mathematically proven reverse compensation order, process crash recovery (`os._exit` resilient), and failure blockades.
48
+ - 🌳 **Persistent AST Identity & CAS**: Every syntax node has a stable cryptographic UUID and content hash. Updates apply via Compare-And-Swap (0% lost updates).
49
+ - 🎯 **Sub-Millisecond Counterexample Shrinking**: Automatically isolates minimal failing inputs in 0.3ms, cutting diagnostic tokens by 77% and achieving single-turn Pass@1 bug repairs.
50
+ - 📐 **Mechanically Verified in Lean 4**: 27 core theorems proved with zero unreviewed axioms and zero `sorry`.
51
+
52
+ ---
53
+
54
+ ## 🎯 现实中怎么用?开发所有项目都要用它吗?
55
+ ### When Should I Use Trace? (And When Shouldn't I?)
56
+
57
+ > **tl;dr 核心结论**:**绝对不要所有项目都用它,你完全不需要推翻重写现有的项目!**
58
+ > 90% 的普通业务逻辑(写网页界面、查数据库列表、做数据分析)继续用你熟悉的 Python/Go/JS/Vue;只有那 **10% 最核心的“AI Agent 调度、多步外部 API 扣费/发货、容灾防重复”** 的高危链路,交给 Trace 守护。
59
+
60
+ ```
61
+ ┌────────────────────────────────────────────────────────────────────────┐
62
+ │ 你的现有项目 (FastAPI / Django / Go) │
63
+ │ │
64
+ │ 常规业务接口 (90%) 高危交易 / AI Agent 任务 (10%) │
65
+ │ ┌───────────────────────────┐ ┌──────────────────────────┐ │
66
+ │ │ 查列表、展示数据、写网页 │ │ 多步扣费、调度外部 API │ │
67
+ │ │ 普通 Python / Vue 代码 │ │ 用 Trace @flow 守护 │ │
68
+ │ └───────────────────────────┘ └────────────┬─────────────┘ │
69
+ └────────────────────────────────────────────────────────┼───────────────┘
70
+ │
71
+ ┌─────────────▼───────────────┐
72
+ │ Trace Lens 本地可视化控制台 │
73
+ │ (http://127.0.0.1:8080) │
74
+ └─────────────────────────────┘
75
+ ```
76
+
77
+ #### 🌟 适用场景:它在什么时候是“救命稻草”?
78
+
79
+ 1. **场景 1:AI Agent 复杂多步外部调用(核心痛点:崩溃防重与自动回滚)**
80
+ - **典型业务**:Agent 执行 `“抓取数据 ➔ 扣除用户 50 积分 ➔ 调用外部模型 ➔ 发送短信通知”`。
81
+ - **痛点**:普通 Python 代码一旦在第 4 步发短信时网络超时,由于已经扣了 50 积分,重试就会导致**“重复扣费 100 积分”**;不重试就会导致**“扣了费没发短信”**。
82
+ - **Trace 怎么解决**:用 `@flow` 包装。Trace 自动落盘事务日志,断电重启自动断点续跑;若短信彻底失败,**严格按数学反向顺序自动触发退款回滚,0 重复扣费,0 坏账**。
83
+
84
+ 2. **场景 2:让 AI 程序员(Cursor / Devin / 自动化 Agent)修代码**
85
+ - **典型业务**:让 AI 自动给已有系统找 bug 并打补丁。
86
+ - **痛点**:传统 Python 报错会丢出 50 行堆栈,消耗巨量 Token 且 Agent 容易改错;如果有 2 个 Agent 同时改代码,还会把彼此的代码直接覆盖(Lost Update)。
87
+ - **Trace 怎么解决**:用 `trace agent-ce` 在 **0.3毫秒内**把报错精准收缩成最小输入(例如:`输入为 0 时越界`),Token 消耗降低 **77%**;提交补丁使用 **AST 密码学 CAS**,冲突直接拦截,绝不会互相覆盖。
88
+
89
+ 3. **场景 3:金融/电商/审批等高敏感交易链条**
90
+ - **典型业务**:跨系统的订单支付、库存锁定、优惠券核销。
91
+ - **痛点**:手写 try-catch、防重表和分布式回滚极容易出 bug。
92
+ - **Trace 怎么解决**:底层经过 **Lean 4.35.0 形式化机械证明(27项定理)**,从数学公理上保证“只要补偿失败就强制封锁告警,绝不假装成功”。
93
+
94
+ #### 🚫 哪些场景绝对不要用它?
95
+ - ❌ **不要用来写网页前端(UI)**:做页面请继续用 Vue/React。
96
+ - ❌ **不要用来做大模型矩阵计算或极低延迟网关**:做张量计算用 PyTorch/CUDA,做微秒级通信用 C++/Rust。
97
+ - ❌ **不要用来写简单的一次性脚本**:如果只是写一个爬虫、或者转个 Excel 文件,普通的几行 Python 脚本是最快的,引入形式化事务属于过度设计。
98
+
99
+ ---
100
+
101
+ ## 📊 Feature Comparison
102
+
103
+ | Capability | Raw Python / JS | Temporal / Cadence | LangGraph / CrewAI | **Trace** |
104
+ | :--- | :---: | :---: | :---: | :---: |
105
+ | **Crash-Safe Multi-Step Saga** | ❌ Manual | ✅ Yes (Heavy Server) | ❌ Memory-only | **✅ Built-in & Lean 4 Proven** |
106
+ | **Zero Side-Effect Leaks on Crash**| ❌ No | ✅ Yes | ❌ No | **✅ 100% Guaranteed** |
107
+ | **AST-Level Compare-And-Swap (CAS)**| ❌ Text Diffs | ❌ N/A | ❌ N/A | **✅ Cryptographic AST Identity** |
108
+ | **Sub-Millisecond Counterexample Shrinking**| ❌ Raw Tracebacks | ❌ N/A | ❌ No | **✅ 0.3ms Minimal Inputs** |
109
+ | **Context Window Token Savings** | 0% | 0% | 0% | **✅ 53.3% - 80%+ Reduction** |
110
+ | **Runtime Overhead & Dependencies** | Low | Heavy Cluster | Medium | **Zero External Dependencies** |
111
+
112
+ ---
113
+
114
+ ## 🚀 Quickstart in 5 Minutes
115
+
116
+ Trace adopts a **Progressive Adoption Ladder**: start directly in your existing Python codebase with zero rewrite, or use the dedicated `.trace` DSL.
117
+
118
+ ### Level 0: Python Decorator SDK (`@flow` & `@contract`)
119
+
120
+ No new syntax required! Import Trace directly into your Python service:
121
+
122
+ ```python
123
+ from trace_lang import flow, contract
124
+
125
+ # 1. Add contracts with automatic property fuzzing
126
+ @contract(
127
+ requires=lambda price: price >= 0,
128
+ ensures=lambda result, price: result >= 0
129
+ )
130
+ def calculate_discount(price: int) -> int:
131
+ return price - 50 if price > 100 else price
132
+
133
+ # 2. Define durable, crash-resilient multi-step Sagas
134
+ @flow(db_path="ecommerce.db")
135
+ def checkout_pipeline(ctx, order_id: str, amount: int):
136
+ # If payment succeeds but license fails, payment is automatically refunded in reverse order!
137
+ ctx.step("charge_card", forward=stripe_charge, undo=stripe_refund, payload=amount)
138
+ ctx.step("provision_key", forward=generate_license, undo=revoke_license, payload=1)
139
+
140
+ # Execute or resume after crash
141
+ order = checkout_pipeline(run_id="order_9901", order_id="ord_9901", amount=150)
142
+ result = order.run()
143
+ print(f"Status: {result['status']}") # 'succeeded' or 'compensated'
144
+ ```
145
+
146
+ ### Level 1: Launch Trace Lens Visual DevTools
147
+
148
+ Trace includes an embedded local web console for real-time transaction debugging and AST inspection:
149
+
150
+ ```bash
151
+ # Launch interactive developer UI on http://127.0.0.1:8080
152
+ python -m trace_lang lens
153
+ ```
154
+
155
+ ![Trace Lens Preview](docs/images/trace_lens_preview.png)
156
+ *(Interactive visual DAG of Sagas, compensation flows, AST lineage, and 0.3ms property fuzzing sandbox)*
157
+
158
+ ### Level 2: Agent Tooling CLI (For Autonomous Coding Agents)
159
+
160
+ When an AI agent needs to inspect or patch code, use Trace's specialized CLI:
161
+
162
+ ```bash
163
+ # 1. Get minimal dependency slice & hole info (saves >50% context tokens)
164
+ python -m trace_lang agent-context examples/orders.trace --target "fn.quote"
165
+
166
+ # 2. Find and shrink minimal counterexample
167
+ python -m trace_lang agent-ce examples/discount.trace --fn discount
168
+ # Output: {"status": "counterexample_found", "minimal_args": [0], "diagnostic": "E_CONTRACT"}
169
+
170
+ # 3. Apply atomic AST patch with revision check
171
+ python -m trace_lang patch examples/orders.trace patch.json --output patched.trace
172
+ ```
173
+
174
+ ### Level 3: Pure `.trace` DSL & Formal Machine Checking
175
+
176
+ Trace programs express pure computation, typed contracts, and persistent UUIDs:
177
+
178
+ ```trace
179
+ @revision(1)
180
+ @id("type.Cart")
181
+ type Cart = { items_count: Int, subtotal: Int }
182
+
183
+ @id("fn.apply_coupon")
184
+ fn apply_coupon(cart: Cart, discount: Int) -> Int
185
+ require cart.subtotal >= 0 && discount >= 0
186
+ ensure result >= 0
187
+ {
188
+ if discount >= cart.subtotal then 0 else cart.subtotal - discount
189
+ }
190
+ ```
191
+
192
+ Verify formal proofs with Lean 4:
193
+ ```bash
194
+ python tools/check_formal.py --lean <path-to-lean-4.35.0>
195
+ # Output: {"status": "checked", "lean_theorems": 27, "admissions": 0}
196
+ ```
197
+
198
+ ---
199
+
200
+ ## 📈 Benchmarks
201
+
202
+ Empirical performance evaluation from [`benchmarks/agent_efficiency/`](benchmarks/agent_efficiency/):
203
+
204
+ | Metric | Baseline (Python/Git) | Trace Agent Engine | Gain |
205
+ | :--- | :--- | :--- | :--- |
206
+ | **Context Window Consumption** | 2,840 bytes (full file) | **1,326 bytes** (dependency slice) | **53.3% - 80%+ Saved** |
207
+ | **Diagnostic Traceback Size** | 822 bytes (stack trace) | **188 bytes** (shrunk counterexample)| **77.1% Saved** |
208
+ | **Agent Repair Convergence** | 3 - 5 turns (trial & error) | **1 turn (Pass@1)** | **3x Faster Convergence** |
209
+ | **Crash Side-Effect Leakage** | Frequent duplicate API calls | **0 leaked side effects** | **100% Mathematical Safety** |
210
+ | **Multi-Agent CAS Collision** | Silent overwrite / torn AST | **1 winner + E_ID_CONFLICT abort**| **100% Atomic Serialization** |
211
+
212
+ ---
213
+
214
+ ## 🏗️ Repository Architecture
215
+
216
+ ```text
217
+ ├── trace_lang/ # Core Python implementation (Zero external dependencies)
218
+ │ ├── sdk.py # Progressive Adoption SDK (@flow, @step, @contract)
219
+ │ ├── lens.py # Trace Lens embedded local Web DevTools & API
220
+ │ ├── saga.py # Crash-safe Saga coordinator & SQLite journal
221
+ │ ├── identity.py # Persistent AST Identity CAS engine & lineage index
222
+ │ ├── agent_tools.py # Context slicing, counterexample shrinking, atomic patches
223
+ │ ├── syntax.py # Trace parser, lexer, and AST formatter
224
+ │ └── engine.py # Runtime interpreter & contract evaluator
225
+ ├── formal/ # Lean 4.35.0 Formal Verification Proofs (27 Theorems)
226
+ │ ├── CoreTyping.lean # Type uniqueness & preservation semantics
227
+ │ ├── Identity.lean # Monotonic retirement & CAS safety theorems
228
+ │ └── Saga.lean # Reverse compensation ordering & failure blockade
229
+ ├── tests/ # 188 Unit & Industrial Chaos Tests
230
+ │ ├── test_sdk.py # Level 0 Python SDK tests
231
+ │ ├── test_lens.py # Trace Lens devtools HTTP server tests
232
+ │ ├── test_saga_chaos.py # os._exit crash, reverse replay, blockade & lock tests
233
+ │ └── test_identity_concurrency.py # Multi-process CAS stress tests
234
+ ├── benchmarks/ # Agent efficiency & token savings benchmark suite
235
+ └── docs/ # Architecture, SAGA model, and Open-Core strategy
236
+ ```
237
+
238
+ ---
239
+
240
+ ## 📜 Open-Core & Commercial Strategy
241
+
242
+ Trace follows an **Open-Core** model:
243
+ - **Community Core (Open Source, Apache 2.0)**: Single-node Saga coordinator, AST Identity, Python SDK, Agent CLI, and Trace Lens Community.
244
+ - **Enterprise & Cloud (Commercial / BSL)**: Multi-node distributed Raft Saga cluster, tamper-evident cryptographic compliance gateway, enterprise RBAC/SSO, and Trace Lens Pro.
245
+
246
+ For full architectural breakdown and commercialization details, read [docs/OPEN_CORE_STRATEGY.md](docs/OPEN_CORE_STRATEGY.md).
247
+
248
+ ---
249
+
250
+ ## 🤝 Contributing
251
+
252
+ Contributions are welcome! Please read [CONTRIBUTING.md](CONTRIBUTING.md) and [SECURITY.md](SECURITY.md) before opening pull requests. All PRs touching core semantics must pass the Lean 4 formal gate.
253
+
254
+ ---
255
+
256
+ ## 📄 License
257
+
258
+ Trace is open-source software licensed under the [Apache 2.0 License](LICENSE).