leapflow 0.0.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 (204) hide show
  1. leapflow-0.0.0/LICENSE +201 -0
  2. leapflow-0.0.0/PKG-INFO +35 -0
  3. leapflow-0.0.0/README.md +3 -0
  4. leapflow-0.0.0/leapflow/__init__.py +6 -0
  5. leapflow-0.0.0/leapflow/__main__.py +13 -0
  6. leapflow-0.0.0/leapflow/analysis/__init__.py +17 -0
  7. leapflow-0.0.0/leapflow/analysis/abstractor.py +304 -0
  8. leapflow-0.0.0/leapflow/analysis/causal.py +91 -0
  9. leapflow-0.0.0/leapflow/analysis/consensus.py +111 -0
  10. leapflow-0.0.0/leapflow/analysis/denoise.py +248 -0
  11. leapflow-0.0.0/leapflow/analysis/episode_dedup.py +50 -0
  12. leapflow-0.0.0/leapflow/analysis/intent_inferrer.py +367 -0
  13. leapflow-0.0.0/leapflow/analysis/patterns.py +260 -0
  14. leapflow-0.0.0/leapflow/analysis/pipeline.py +764 -0
  15. leapflow-0.0.0/leapflow/analysis/segmenter.py +331 -0
  16. leapflow-0.0.0/leapflow/analysis/synthesis.py +1348 -0
  17. leapflow-0.0.0/leapflow/causal/__init__.py +35 -0
  18. leapflow-0.0.0/leapflow/causal/adapter.py +202 -0
  19. leapflow-0.0.0/leapflow/causal/channel.py +310 -0
  20. leapflow-0.0.0/leapflow/causal/components.py +557 -0
  21. leapflow-0.0.0/leapflow/causal/inference.py +627 -0
  22. leapflow-0.0.0/leapflow/causal/pipeline.py +522 -0
  23. leapflow-0.0.0/leapflow/causal/types.py +327 -0
  24. leapflow-0.0.0/leapflow/cli/__init__.py +5 -0
  25. leapflow-0.0.0/leapflow/cli/banner.py +229 -0
  26. leapflow-0.0.0/leapflow/cli/cli.py +216 -0
  27. leapflow-0.0.0/leapflow/cli/commands/__init__.py +1 -0
  28. leapflow-0.0.0/leapflow/cli/commands/chat.py +18 -0
  29. leapflow-0.0.0/leapflow/cli/commands/host.py +393 -0
  30. leapflow-0.0.0/leapflow/cli/commands/interactive.py +375 -0
  31. leapflow-0.0.0/leapflow/cli/commands/learn.py +551 -0
  32. leapflow-0.0.0/leapflow/cli/commands/relearn.py +63 -0
  33. leapflow-0.0.0/leapflow/cli/commands/run.py +262 -0
  34. leapflow-0.0.0/leapflow/cli/commands/skills.py +290 -0
  35. leapflow-0.0.0/leapflow/cli/context.py +924 -0
  36. leapflow-0.0.0/leapflow/cli/helpers.py +76 -0
  37. leapflow-0.0.0/leapflow/cli/tui.py +101 -0
  38. leapflow-0.0.0/leapflow/config.py +608 -0
  39. leapflow-0.0.0/leapflow/domain/__init__.py +48 -0
  40. leapflow-0.0.0/leapflow/domain/events.py +87 -0
  41. leapflow-0.0.0/leapflow/domain/perception.py +75 -0
  42. leapflow-0.0.0/leapflow/domain/platform.py +98 -0
  43. leapflow-0.0.0/leapflow/domain/skill_types.py +114 -0
  44. leapflow-0.0.0/leapflow/domain/trajectory.py +234 -0
  45. leapflow-0.0.0/leapflow/domain/ui_vocabulary.py +81 -0
  46. leapflow-0.0.0/leapflow/engine/__init__.py +36 -0
  47. leapflow-0.0.0/leapflow/engine/audit.py +73 -0
  48. leapflow-0.0.0/leapflow/engine/confirmation.py +220 -0
  49. leapflow-0.0.0/leapflow/engine/engine.py +953 -0
  50. leapflow-0.0.0/leapflow/engine/graph_planner.py +363 -0
  51. leapflow-0.0.0/leapflow/engine/intent_classifier.py +152 -0
  52. leapflow-0.0.0/leapflow/engine/planner.py +80 -0
  53. leapflow-0.0.0/leapflow/engine/resilience.py +5 -0
  54. leapflow-0.0.0/leapflow/engine/scheduler.py +389 -0
  55. leapflow-0.0.0/leapflow/engine/session.py +802 -0
  56. leapflow-0.0.0/leapflow/engine/shortcuts.py +120 -0
  57. leapflow-0.0.0/leapflow/engine/situational_assessor.py +189 -0
  58. leapflow-0.0.0/leapflow/engine/task_graph.py +608 -0
  59. leapflow-0.0.0/leapflow/engine/terminal_io.py +5 -0
  60. leapflow-0.0.0/leapflow/host/__init__.py +39 -0
  61. leapflow-0.0.0/leapflow/host/dev.py +340 -0
  62. leapflow-0.0.0/leapflow/host/launchd.py +197 -0
  63. leapflow-0.0.0/leapflow/host/manager.py +547 -0
  64. leapflow-0.0.0/leapflow/host/permissions.py +160 -0
  65. leapflow-0.0.0/leapflow/learning/__init__.py +17 -0
  66. leapflow-0.0.0/leapflow/learning/active_learning.py +1244 -0
  67. leapflow-0.0.0/leapflow/learning/codegen.py +773 -0
  68. leapflow-0.0.0/leapflow/learning/distiller.py +463 -0
  69. leapflow-0.0.0/leapflow/learning/doc_generator.py +657 -0
  70. leapflow-0.0.0/leapflow/learning/document.py +443 -0
  71. leapflow-0.0.0/leapflow/learning/feedback.py +339 -0
  72. leapflow-0.0.0/leapflow/learning/similarity.py +303 -0
  73. leapflow-0.0.0/leapflow/learning/stream_progress.py +5 -0
  74. leapflow-0.0.0/leapflow/llm/__init__.py +21 -0
  75. leapflow-0.0.0/leapflow/llm/base.py +52 -0
  76. leapflow-0.0.0/leapflow/llm/message_builder.py +53 -0
  77. leapflow-0.0.0/leapflow/llm/openai_provider.py +449 -0
  78. leapflow-0.0.0/leapflow/memory/__init__.py +8 -0
  79. leapflow-0.0.0/leapflow/memory/decay.py +33 -0
  80. leapflow-0.0.0/leapflow/memory/immediate.py +175 -0
  81. leapflow-0.0.0/leapflow/memory/long_term.py +316 -0
  82. leapflow-0.0.0/leapflow/memory/working_memory.py +94 -0
  83. leapflow-0.0.0/leapflow/perception/__init__.py +37 -0
  84. leapflow-0.0.0/leapflow/perception/config.py +112 -0
  85. leapflow-0.0.0/leapflow/perception/cv/__init__.py +1 -0
  86. leapflow-0.0.0/leapflow/perception/cv/optical_flow.py +173 -0
  87. leapflow-0.0.0/leapflow/perception/cv/phash.py +183 -0
  88. leapflow-0.0.0/leapflow/perception/cv/scene_cut.py +102 -0
  89. leapflow-0.0.0/leapflow/perception/cv/text_diff.py +156 -0
  90. leapflow-0.0.0/leapflow/perception/cv/ui_detect.py +81 -0
  91. leapflow-0.0.0/leapflow/perception/encoding/__init__.py +1 -0
  92. leapflow-0.0.0/leapflow/perception/encoding/delta.py +303 -0
  93. leapflow-0.0.0/leapflow/perception/encoding/encoder.py +118 -0
  94. leapflow-0.0.0/leapflow/perception/encoding/tiler.py +184 -0
  95. leapflow-0.0.0/leapflow/perception/extraction/__init__.py +1 -0
  96. leapflow-0.0.0/leapflow/perception/extraction/extractor.py +394 -0
  97. leapflow-0.0.0/leapflow/perception/extraction/feature_extractor.py +117 -0
  98. leapflow-0.0.0/leapflow/perception/extraction/pipeline.py +369 -0
  99. leapflow-0.0.0/leapflow/perception/extraction/preprocessor.py +123 -0
  100. leapflow-0.0.0/leapflow/perception/extraction/refiner.py +152 -0
  101. leapflow-0.0.0/leapflow/perception/extraction/router.py +80 -0
  102. leapflow-0.0.0/leapflow/perception/sampling/__init__.py +1 -0
  103. leapflow-0.0.0/leapflow/perception/session.py +464 -0
  104. leapflow-0.0.0/leapflow/perception/signals.py +53 -0
  105. leapflow-0.0.0/leapflow/perception/state_snapshot.py +241 -0
  106. leapflow-0.0.0/leapflow/perception/storage/__init__.py +1 -0
  107. leapflow-0.0.0/leapflow/perception/storage/deduplicator.py +121 -0
  108. leapflow-0.0.0/leapflow/perception/storage/frame_store.py +145 -0
  109. leapflow-0.0.0/leapflow/perception/storage/semantic_cache.py +129 -0
  110. leapflow-0.0.0/leapflow/perception/types.py +350 -0
  111. leapflow-0.0.0/leapflow/perception/video/__init__.py +25 -0
  112. leapflow-0.0.0/leapflow/perception/video/analyzer.py +413 -0
  113. leapflow-0.0.0/leapflow/perception/video/prompts.py +243 -0
  114. leapflow-0.0.0/leapflow/perception/video/recorder.py +118 -0
  115. leapflow-0.0.0/leapflow/perception/video/segmenter.py +143 -0
  116. leapflow-0.0.0/leapflow/perception/video/timeline.py +250 -0
  117. leapflow-0.0.0/leapflow/platform/__init__.py +37 -0
  118. leapflow-0.0.0/leapflow/platform/adapters/__init__.py +1 -0
  119. leapflow-0.0.0/leapflow/platform/adapters/darwin.py +259 -0
  120. leapflow-0.0.0/leapflow/platform/adapters/mock.py +189 -0
  121. leapflow-0.0.0/leapflow/platform/capabilities.py +128 -0
  122. leapflow-0.0.0/leapflow/platform/client.py +366 -0
  123. leapflow-0.0.0/leapflow/platform/event_bus.py +194 -0
  124. leapflow-0.0.0/leapflow/platform/facade.py +100 -0
  125. leapflow-0.0.0/leapflow/platform/mock.py +156 -0
  126. leapflow-0.0.0/leapflow/platform/normalizer.py +434 -0
  127. leapflow-0.0.0/leapflow/platform/protocol.py +145 -0
  128. leapflow-0.0.0/leapflow/platform/relevance.py +74 -0
  129. leapflow-0.0.0/leapflow/platform/reorder_buffer.py +76 -0
  130. leapflow-0.0.0/leapflow/prompts/__init__.py +5 -0
  131. leapflow-0.0.0/leapflow/prompts/templates.py +63 -0
  132. leapflow-0.0.0/leapflow/recording/__init__.py +27 -0
  133. leapflow-0.0.0/leapflow/recording/attention.py +937 -0
  134. leapflow-0.0.0/leapflow/recording/attention_tuner.py +148 -0
  135. leapflow-0.0.0/leapflow/recording/field_policy_loader.py +426 -0
  136. leapflow-0.0.0/leapflow/recording/health.py +146 -0
  137. leapflow-0.0.0/leapflow/recording/perceptual_field.py +463 -0
  138. leapflow-0.0.0/leapflow/recording/recorder.py +789 -0
  139. leapflow-0.0.0/leapflow/signal_fusion/__init__.py +51 -0
  140. leapflow-0.0.0/leapflow/signal_fusion/action_agent.py +135 -0
  141. leapflow-0.0.0/leapflow/signal_fusion/cross_app.py +172 -0
  142. leapflow-0.0.0/leapflow/signal_fusion/episode_agent.py +313 -0
  143. leapflow-0.0.0/leapflow/signal_fusion/integrator.py +250 -0
  144. leapflow-0.0.0/leapflow/signal_fusion/pipeline.py +230 -0
  145. leapflow-0.0.0/leapflow/signal_fusion/protocol.py +63 -0
  146. leapflow-0.0.0/leapflow/signal_fusion/quality.py +89 -0
  147. leapflow-0.0.0/leapflow/signal_fusion/segment_agent.py +258 -0
  148. leapflow-0.0.0/leapflow/signal_fusion/types.py +305 -0
  149. leapflow-0.0.0/leapflow/signal_fusion/wait_classifier.py +103 -0
  150. leapflow-0.0.0/leapflow/skills/__init__.py +17 -0
  151. leapflow-0.0.0/leapflow/skills/action_policy.py +218 -0
  152. leapflow-0.0.0/leapflow/skills/activator.py +273 -0
  153. leapflow-0.0.0/leapflow/skills/bridge_factory.py +200 -0
  154. leapflow-0.0.0/leapflow/skills/builtin/__init__.py +5 -0
  155. leapflow-0.0.0/leapflow/skills/builtin/app_launcher.py +41 -0
  156. leapflow-0.0.0/leapflow/skills/builtin/clipboard_manager.py +41 -0
  157. leapflow-0.0.0/leapflow/skills/builtin/file_organizer.py +124 -0
  158. leapflow-0.0.0/leapflow/skills/conditions.py +219 -0
  159. leapflow-0.0.0/leapflow/skills/registry.py +388 -0
  160. leapflow-0.0.0/leapflow/skills/sandbox.py +221 -0
  161. leapflow-0.0.0/leapflow/skills/semantic_adapter.py +501 -0
  162. leapflow-0.0.0/leapflow/skills/tool_executor.py +910 -0
  163. leapflow-0.0.0/leapflow/skills/ui_selector.py +201 -0
  164. leapflow-0.0.0/leapflow/skills/ui_summarizer.py +159 -0
  165. leapflow-0.0.0/leapflow/storage/__init__.py +13 -0
  166. leapflow-0.0.0/leapflow/storage/bundle_writer.py +142 -0
  167. leapflow-0.0.0/leapflow/storage/session_store.py +162 -0
  168. leapflow-0.0.0/leapflow/storage/skill_docs.py +247 -0
  169. leapflow-0.0.0/leapflow/storage/skill_library.py +729 -0
  170. leapflow-0.0.0/leapflow/storage/trajectory_store.py +474 -0
  171. leapflow-0.0.0/leapflow/utils/__init__.py +27 -0
  172. leapflow-0.0.0/leapflow/utils/diagnostics.py +156 -0
  173. leapflow-0.0.0/leapflow/utils/progress.py +167 -0
  174. leapflow-0.0.0/leapflow/utils/resilience.py +71 -0
  175. leapflow-0.0.0/leapflow/utils/stream_progress.py +73 -0
  176. leapflow-0.0.0/leapflow/utils/terminal_io.py +24 -0
  177. leapflow-0.0.0/leapflow/version.py +3 -0
  178. leapflow-0.0.0/leapflow/world_model/__init__.py +29 -0
  179. leapflow-0.0.0/leapflow/world_model/_json_utils.py +18 -0
  180. leapflow-0.0.0/leapflow/world_model/budget.py +165 -0
  181. leapflow-0.0.0/leapflow/world_model/curiosity.py +267 -0
  182. leapflow-0.0.0/leapflow/world_model/embedding.py +117 -0
  183. leapflow-0.0.0/leapflow/world_model/experience_store.py +348 -0
  184. leapflow-0.0.0/leapflow/world_model/prediction.py +417 -0
  185. leapflow-0.0.0/leapflow/world_model/replay.py +377 -0
  186. leapflow-0.0.0/leapflow/world_model/trajectory_grader.py +213 -0
  187. leapflow-0.0.0/leapflow.egg-info/PKG-INFO +35 -0
  188. leapflow-0.0.0/leapflow.egg-info/SOURCES.txt +202 -0
  189. leapflow-0.0.0/leapflow.egg-info/dependency_links.txt +1 -0
  190. leapflow-0.0.0/leapflow.egg-info/entry_points.txt +2 -0
  191. leapflow-0.0.0/leapflow.egg-info/requires.txt +14 -0
  192. leapflow-0.0.0/leapflow.egg-info/top_level.txt +1 -0
  193. leapflow-0.0.0/pyproject.toml +58 -0
  194. leapflow-0.0.0/setup.cfg +4 -0
  195. leapflow-0.0.0/tests/test_agent_execution.py +360 -0
  196. leapflow-0.0.0/tests/test_memory_and_storage.py +316 -0
  197. leapflow-0.0.0/tests/test_perception_pipeline.py +255 -0
  198. leapflow-0.0.0/tests/test_platform_synthesis.py +278 -0
  199. leapflow-0.0.0/tests/test_pure_algorithms.py +148 -0
  200. leapflow-0.0.0/tests/test_safety_and_policy.py +139 -0
  201. leapflow-0.0.0/tests/test_skill_lifecycle.py +288 -0
  202. leapflow-0.0.0/tests/test_teach_learn_lifecycle.py +454 -0
  203. leapflow-0.0.0/tests/test_visual_pipeline.py +830 -0
  204. leapflow-0.0.0/tests/test_world_model.py +609 -0
leapflow-0.0.0/LICENSE ADDED
@@ -0,0 +1,201 @@
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
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,35 @@
1
+ Metadata-Version: 2.4
2
+ Name: leapflow
3
+ Version: 0.0.0
4
+ Summary: LEAP Agent — Learning and Evolving from Actual Practice
5
+ Author: LEAP Agent Team
6
+ License: Apache-2.0
7
+ Keywords: agent,ai,macos,automation,imitation-learning
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
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Classifier: Programming Language :: Python :: 3.14
16
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
17
+ Requires-Python: >=3.11
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ Requires-Dist: openai>=1.40
21
+ Requires-Dist: python-dotenv>=1.0.1
22
+ Requires-Dist: msgpack>=1.0.8
23
+ Requires-Dist: duckdb>=1.0.0
24
+ Requires-Dist: pyyaml>=6.0
25
+ Requires-Dist: Pillow>=10.0
26
+ Requires-Dist: gnureadline>=8.0; sys_platform == "darwin"
27
+ Provides-Extra: dev
28
+ Requires-Dist: pytest>=8.0.0; extra == "dev"
29
+ Requires-Dist: pytest-asyncio>=0.23.0; extra == "dev"
30
+ Requires-Dist: ruff>=0.4.0; extra == "dev"
31
+ Dynamic: license-file
32
+
33
+ # LeapFlow
34
+
35
+ **Learning and Evolving from Actual Practice**
@@ -0,0 +1,3 @@
1
+ # LeapFlow
2
+
3
+ **Learning and Evolving from Actual Practice**
@@ -0,0 +1,6 @@
1
+ """LEAP Agent — Learning and Evolving from Actual Practice."""
2
+
3
+ from leapflow.config import load_config
4
+ from leapflow.version import __version__
5
+
6
+ __all__ = ["__version__", "load_config"]
@@ -0,0 +1,13 @@
1
+ """CLI entrypoint for LEAP Agent.
2
+
3
+ Subcommands:
4
+ leap learn — Interactive learning mode (record → distill)
5
+ leap run — Execute a skill by trigger match or explicit name
6
+ leap skills — List / inspect learned skills
7
+ leap chat — Conversational mode (original single-turn or interactive)
8
+ """
9
+
10
+ from leapflow.cli import main
11
+
12
+ if __name__ == "__main__":
13
+ raise SystemExit(main())
@@ -0,0 +1,17 @@
1
+ """Offline analysis layer — synthesis, abstraction, segmentation, and distillation pipeline."""
2
+
3
+ from leapflow.analysis.abstractor import ActionAbstractor
4
+ from leapflow.analysis.synthesis import PlatformSynthesisPass
5
+
6
+ __all__ = [
7
+ "ActionAbstractor",
8
+ "ImitationPipeline",
9
+ "PlatformSynthesisPass",
10
+ ]
11
+
12
+
13
+ def __getattr__(name: str):
14
+ if name == "ImitationPipeline":
15
+ from leapflow.analysis.pipeline import ImitationPipeline
16
+ return ImitationPipeline
17
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
@@ -0,0 +1,304 @@
1
+ """Multi-level action abstraction for trajectory analysis.
2
+
3
+ Abstraction levels:
4
+ L0 (Raw) → individual events from EventBus
5
+ L1 (Grouped) → consecutive same-type actions merged (e.g. keystrokes → type_text)
6
+ L2 (Pattern) → recognized action patterns (e.g. copy + switch + paste → transfer_data)
7
+ L3 (Intent) → LLM-inferred user intent (optional, requires LLMProvider)
8
+
9
+ Each level is a composable AbstractionPass (Pipeline pattern).
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ import logging
15
+ from abc import ABC, abstractmethod
16
+ from typing import Any, Dict, List, Optional, Sequence
17
+
18
+ from leapflow.analysis.patterns import PatternLibrary
19
+ from leapflow.domain.trajectory import (
20
+ ActionType,
21
+ RawAction,
22
+ SemanticAction,
23
+ TrajectoryStep,
24
+ )
25
+
26
+ logger = logging.getLogger(__name__)
27
+
28
+
29
+ # ── Abstraction pass protocol ──
30
+
31
+
32
+ class AbstractionPass(ABC):
33
+ """A single transformation in the abstraction pipeline."""
34
+
35
+ @abstractmethod
36
+ def apply(
37
+ self,
38
+ actions: List[SemanticAction],
39
+ steps: Optional[List[TrajectoryStep]] = None,
40
+ ) -> List[SemanticAction]:
41
+ """Transform a list of semantic actions into a (usually shorter) list.
42
+
43
+ Args:
44
+ actions: Current semantic actions to transform.
45
+ steps: Optional raw trajectory steps for passes that need
46
+ access to state context (e.g., visual frames).
47
+ """
48
+
49
+
50
+ # ── L0→L1: Rule-based grouping ──
51
+
52
+
53
+ class GroupingPass(AbstractionPass):
54
+ """Merge consecutive low-level actions of the same type.
55
+
56
+ - Sequential type events → single "type_text" with merged text_content
57
+ - Sequential file modifications on the same target → single "batch_modify"
58
+ - Sequential clipboard changes → keep only the last one
59
+ """
60
+
61
+ def apply(
62
+ self,
63
+ actions: List[SemanticAction],
64
+ steps: Optional[List[TrajectoryStep]] = None,
65
+ ) -> List[SemanticAction]:
66
+ if len(actions) <= 1:
67
+ return actions
68
+
69
+ result: List[SemanticAction] = []
70
+ i = 0
71
+ while i < len(actions):
72
+ # Special case: merge consecutive type events with char data
73
+ if actions[i].action_name == "ui.type":
74
+ type_end = self._find_type_group_end(actions, i)
75
+ if type_end > i + 1:
76
+ result.append(self._merge_type_group(actions[i:type_end]))
77
+ i = type_end
78
+ continue
79
+
80
+ group_end = self._find_group_end(actions, i)
81
+ if group_end > i + 1:
82
+ result.append(self._merge_group(actions[i:group_end]))
83
+ i = group_end
84
+ else:
85
+ result.append(actions[i])
86
+ i += 1
87
+ return result
88
+
89
+ def _find_type_group_end(self, actions: List[SemanticAction], start: int) -> int:
90
+ """Find end of a consecutive ui.type run within the same app."""
91
+ app = actions[start].parameters.get("app_bundle_id", "")
92
+ end = start + 1
93
+ while end < len(actions) and actions[end].action_name == "ui.type":
94
+ if actions[end].parameters.get("app_bundle_id", "") != app:
95
+ break
96
+ end += 1
97
+ return end
98
+
99
+ @staticmethod
100
+ def _merge_type_group(group: List[SemanticAction]) -> SemanticAction:
101
+ """Merge consecutive type actions, concatenating char fields into text_content."""
102
+ first, last = group[0], group[-1]
103
+ chars = [a.parameters.get("char", "") for a in group]
104
+ text_content = "".join(chars)
105
+ params: Dict[str, Any] = {
106
+ "app_bundle_id": first.parameters.get("app_bundle_id", ""),
107
+ "keystroke_count": len(group),
108
+ }
109
+ if text_content:
110
+ params["text_content"] = text_content
111
+ return SemanticAction(
112
+ action_name="type_text",
113
+ description=f"Type '{text_content[:50]}'" if text_content else f"Type {len(group)} keys",
114
+ parameters=params,
115
+ raw_action_range=(first.raw_action_range[0], last.raw_action_range[1]),
116
+ confidence=1.0,
117
+ )
118
+
119
+ def _find_group_end(self, actions: List[SemanticAction], start: int) -> int:
120
+ """Find the end index of a mergeable group starting at `start`."""
121
+ base = actions[start]
122
+ end = start + 1
123
+ while end < len(actions):
124
+ curr = actions[end]
125
+ if not self._can_merge(base, curr):
126
+ break
127
+ end += 1
128
+ return end
129
+
130
+ @staticmethod
131
+ def _can_merge(a: SemanticAction, b: SemanticAction) -> bool:
132
+ if a.action_name != b.action_name:
133
+ return False
134
+ mergeable = {"file.modify", "file.create", "file.rename", "file.move", "clipboard.copy"}
135
+ return a.action_name in mergeable
136
+
137
+ @staticmethod
138
+ def _merge_group(group: List[SemanticAction]) -> SemanticAction:
139
+ first, last = group[0], group[-1]
140
+ count = len(group)
141
+ merged_params = dict(first.parameters)
142
+ merged_params["count"] = count
143
+ return SemanticAction(
144
+ action_name=f"batch_{first.action_name.split('.')[-1]}",
145
+ description=f"{first.action_name} x{count}",
146
+ parameters=merged_params,
147
+ raw_action_range=(first.raw_action_range[0], last.raw_action_range[1]),
148
+ confidence=min(a.confidence for a in group),
149
+ )
150
+
151
+
152
+ # ── L1→L2: Pattern matching ──
153
+
154
+
155
+ class PatternPass(AbstractionPass):
156
+ """Pattern-based action abstraction using an extensible PatternLibrary.
157
+
158
+ Replaces hardcoded patterns with a YAML-driven, wildcard-capable
159
+ pattern matching engine that supports runtime addition of new patterns.
160
+ """
161
+
162
+ def __init__(self, library: Optional[PatternLibrary] = None) -> None:
163
+ self._library = library or PatternLibrary.default()
164
+
165
+ def apply(
166
+ self,
167
+ actions: List[SemanticAction],
168
+ steps: Optional[List[TrajectoryStep]] = None,
169
+ ) -> List[SemanticAction]:
170
+ if len(actions) < 2:
171
+ return actions
172
+
173
+ matches = self._library.match(actions)
174
+ if not matches:
175
+ return list(actions)
176
+
177
+ # Build result: replace matched spans with semantic actions, keep rest
178
+ result: List[SemanticAction] = []
179
+ consumed = 0
180
+
181
+ for m in matches:
182
+ # Append unmatched actions before this match
183
+ result.extend(actions[consumed : m.start_idx])
184
+ # Create the abstracted semantic action
185
+ first = actions[m.start_idx]
186
+ last = actions[m.end_idx - 1]
187
+ params: Dict[str, Any] = {}
188
+ # Merge original params from matched window
189
+ for a in actions[m.start_idx : m.end_idx]:
190
+ params.update(a.parameters)
191
+ # Overlay extracted params from pattern rules
192
+ params.update(m.extracted_params)
193
+
194
+ result.append(
195
+ SemanticAction(
196
+ action_name=m.pattern.semantic_name,
197
+ description=m.pattern.description or m.pattern.semantic_name,
198
+ parameters=params,
199
+ raw_action_range=(
200
+ first.raw_action_range[0],
201
+ last.raw_action_range[1],
202
+ ),
203
+ confidence=m.match_confidence,
204
+ )
205
+ )
206
+ consumed = m.end_idx
207
+
208
+ # Append remaining unmatched actions
209
+ result.extend(actions[consumed:])
210
+ return result
211
+
212
+
213
+ # ── Orchestrator ──
214
+
215
+
216
+ class ActionAbstractor:
217
+ """Multi-level action abstraction pipeline.
218
+
219
+ By default runs L0→L1→L2 (rule-based only, no LLM cost).
220
+ """
221
+
222
+ def __init__(
223
+ self,
224
+ passes: Sequence[AbstractionPass] | None = None,
225
+ *,
226
+ platform_hint: str = "darwin",
227
+ ) -> None:
228
+ if passes is not None:
229
+ self._passes = list(passes)
230
+ else:
231
+ from leapflow.analysis.denoise import DenoisePass
232
+ from leapflow.analysis.synthesis import PlatformSynthesisPass
233
+ self._passes = [
234
+ DenoisePass(),
235
+ PlatformSynthesisPass.for_platform(platform_hint),
236
+ GroupingPass(),
237
+ PatternPass(),
238
+ ]
239
+
240
+ def abstract(self, steps: List[TrajectoryStep]) -> List[SemanticAction]:
241
+ """Run the abstraction pipeline on raw trajectory steps."""
242
+ actions = [self._step_to_semantic(i, step) for i, step in enumerate(steps)]
243
+ for p in self._passes:
244
+ actions = p.apply(actions, steps=steps)
245
+ return actions
246
+
247
+ @staticmethod
248
+ def _step_to_semantic(idx: int, step: TrajectoryStep) -> SemanticAction:
249
+ """Convert a single TrajectoryStep to an initial SemanticAction (L0)."""
250
+ a = step.action
251
+ params: Dict[str, Any] = {}
252
+
253
+ if a.target:
254
+ params["target"] = a.target
255
+ if a.target_label:
256
+ params["target_label"] = a.target_label
257
+ if a.app_bundle_id:
258
+ params["app_bundle_id"] = a.app_bundle_id
259
+ if a.action_type in (ActionType.FILE_CREATE, ActionType.FILE_MODIFY,
260
+ ActionType.FILE_DELETE, ActionType.FILE_RENAME):
261
+ params["path"] = a.target
262
+ if a.action_type == ActionType.CLIPBOARD_COPY:
263
+ params["text"] = a.params.get("text", "")
264
+ if a.action_type == ActionType.UI_TYPE:
265
+ char = a.params.get("char")
266
+ if char:
267
+ params["char"] = char
268
+ if a.action_type == ActionType.UI_DRAG:
269
+ for k in ("start_x", "start_y", "end_x", "end_y",
270
+ "end_role", "end_label", "cross_app", "start_app", "end_app"):
271
+ if k in a.params:
272
+ params[k] = a.params[k]
273
+
274
+ return SemanticAction(
275
+ action_name=a.action_type.value,
276
+ description=_describe_action(a),
277
+ parameters=params,
278
+ raw_action_range=(idx, idx + 1),
279
+ confidence=1.0,
280
+ )
281
+
282
+
283
+ def _describe_action(a: RawAction) -> str:
284
+ """Generate a human-readable description of a raw action."""
285
+ at = a.action_type
286
+ if at == ActionType.APP_SWITCH:
287
+ return f"Switch to {a.app_name or a.app_bundle_id}"
288
+ if at in (ActionType.FILE_CREATE, ActionType.FILE_MODIFY,
289
+ ActionType.FILE_DELETE, ActionType.FILE_RENAME):
290
+ verb = at.value.split(".")[-1].capitalize()
291
+ return f"{verb} {a.target}"
292
+ if at == ActionType.CLIPBOARD_COPY:
293
+ length = a.params.get("text_length", 0)
294
+ return f"Copy to clipboard ({length} chars)"
295
+ if at == ActionType.UI_CLICK:
296
+ return f"Click {a.target_label or a.target or 'element'}"
297
+ if at == ActionType.UI_TYPE:
298
+ char = a.params.get("char", "")
299
+ return f"Type '{char}'" if char else "Type key"
300
+ if at == ActionType.UI_DRAG:
301
+ label = a.target_label or "element"
302
+ end_label = a.params.get("end_label", "") or "target"
303
+ return f"Drag {label} to {end_label}"
304
+ return f"{at.value} {a.target or ''}"
@@ -0,0 +1,91 @@
1
+ """Causal chain extraction from semantic action sequences.
2
+
3
+ Identifies only the actions that contribute to the final observable state,
4
+ filtering out detours, distractions, and non-contributing operations.
5
+ Used by the distillation layer to produce minimal, goal-directed skill steps.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import logging
11
+ from typing import FrozenSet, List, Set
12
+
13
+ from leapflow.domain.trajectory import SemanticAction
14
+
15
+ logger = logging.getLogger(__name__)
16
+
17
+ _EFFECT_ACTIONS: FrozenSet[str] = frozenset({
18
+ "file.create", "file.modify", "file.delete", "file.rename", "file.move",
19
+ "clipboard.copy", "batch_modify", "batch_rename", "batch_delete",
20
+ "batch_move", "batch_move_to_folder", "move_to_new_folder",
21
+ })
22
+
23
+ _SUPPORT_ACTIONS: FrozenSet[str] = frozenset({
24
+ "app.switch", "open_file_dialog", "transfer_data",
25
+ "create_and_edit", "download_organize",
26
+ })
27
+
28
+
29
+ class CausalChainAnalyzer:
30
+ """Extract causally-necessary steps from a semantic action sequence.
31
+
32
+ Algorithm:
33
+ 1. Forward scan: identify effect actions (file ops, clipboard writes)
34
+ 2. For each effect action, back-trace to the nearest un-claimed
35
+ support action (app.switch, open_file_dialog, etc.)
36
+ 3. Return only the causal subset, preserving original order.
37
+ """
38
+
39
+ def __init__(
40
+ self,
41
+ *,
42
+ effect_actions: FrozenSet[str] = _EFFECT_ACTIONS,
43
+ support_actions: FrozenSet[str] = _SUPPORT_ACTIONS,
44
+ ) -> None:
45
+ self._effects = effect_actions
46
+ self._supports = support_actions
47
+
48
+ def extract_causal_chain(
49
+ self, actions: List[SemanticAction]
50
+ ) -> List[SemanticAction]:
51
+ if len(actions) <= 2:
52
+ return list(actions)
53
+
54
+ causal_indices = self._find_causal_indices(actions)
55
+ if not causal_indices:
56
+ return list(actions)
57
+
58
+ result = [a for i, a in enumerate(actions) if i in causal_indices]
59
+ if len(result) < len(actions):
60
+ logger.debug(
61
+ "causal_chain: %d → %d actions (removed %d non-causal)",
62
+ len(actions), len(result), len(actions) - len(result),
63
+ )
64
+ return result
65
+
66
+ def _find_causal_indices(self, actions: List[SemanticAction]) -> Set[int]:
67
+ causal: List[int] = []
68
+ claimed: Set[int] = set()
69
+
70
+ for i, action in enumerate(actions):
71
+ if action.action_name in self._effects:
72
+ causal.append(i)
73
+ claimed.add(i)
74
+ self._backtrace_support(actions, i, causal, claimed)
75
+
76
+ return set(causal)
77
+
78
+ def _backtrace_support(
79
+ self,
80
+ actions: List[SemanticAction],
81
+ effect_idx: int,
82
+ causal: List[int],
83
+ claimed: Set[int],
84
+ ) -> None:
85
+ for j in range(effect_idx - 1, -1, -1):
86
+ if j in claimed:
87
+ break
88
+ if actions[j].action_name in self._supports:
89
+ causal.append(j)
90
+ claimed.add(j)
91
+ break