prior-sdk 0.1.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 (170) hide show
  1. prior_sdk-0.1.0/LICENSE +21 -0
  2. prior_sdk-0.1.0/MANIFEST.in +12 -0
  3. prior_sdk-0.1.0/PKG-INFO +523 -0
  4. prior_sdk-0.1.0/README.md +491 -0
  5. prior_sdk-0.1.0/RELEASING.md +54 -0
  6. prior_sdk-0.1.0/console/__init__.py +5 -0
  7. prior_sdk-0.1.0/console/client.py +81 -0
  8. prior_sdk-0.1.0/examples/agent_call.py +31 -0
  9. prior_sdk-0.1.0/examples/fixture_skill.md +15 -0
  10. prior_sdk-0.1.0/examples/memecoin_agent.py +669 -0
  11. prior_sdk-0.1.0/examples/prior_local.py +87 -0
  12. prior_sdk-0.1.0/prior/__init__.py +287 -0
  13. prior_sdk-0.1.0/prior/__main__.py +8 -0
  14. prior_sdk-0.1.0/prior/adapters/__init__.py +1 -0
  15. prior_sdk-0.1.0/prior/adapters/custom.py +566 -0
  16. prior_sdk-0.1.0/prior/adapters/horizons.py +114 -0
  17. prior_sdk-0.1.0/prior/adapters/jupiter.py +266 -0
  18. prior_sdk-0.1.0/prior/adapters/jupiter_predict.py +914 -0
  19. prior_sdk-0.1.0/prior/adapters/prices/__init__.py +5 -0
  20. prior_sdk-0.1.0/prior/adapters/prices/coingecko.py +203 -0
  21. prior_sdk-0.1.0/prior/adapters/tests/__init__.py +0 -0
  22. prior_sdk-0.1.0/prior/adapters/tests/test_jupiter_predict.py +839 -0
  23. prior_sdk-0.1.0/prior/api/__init__.py +5 -0
  24. prior_sdk-0.1.0/prior/api/__main__.py +24 -0
  25. prior_sdk-0.1.0/prior/api/app.py +66 -0
  26. prior_sdk-0.1.0/prior/api/routes/__init__.py +1 -0
  27. prior_sdk-0.1.0/prior/api/routes/adapters.py +55 -0
  28. prior_sdk-0.1.0/prior/api/routes/cases.py +192 -0
  29. prior_sdk-0.1.0/prior/api/routes/checkbacks.py +25 -0
  30. prior_sdk-0.1.0/prior/api/routes/common.py +331 -0
  31. prior_sdk-0.1.0/prior/api/routes/evals.py +21 -0
  32. prior_sdk-0.1.0/prior/api/routes/health.py +90 -0
  33. prior_sdk-0.1.0/prior/api/routes/keys.py +54 -0
  34. prior_sdk-0.1.0/prior/api/routes/memory.py +111 -0
  35. prior_sdk-0.1.0/prior/api/routes/overview.py +219 -0
  36. prior_sdk-0.1.0/prior/api/routes/recall.py +103 -0
  37. prior_sdk-0.1.0/prior/api/routes/rules.py +309 -0
  38. prior_sdk-0.1.0/prior/api/routes/subjects.py +89 -0
  39. prior_sdk-0.1.0/prior/api/routes/usage.py +43 -0
  40. prior_sdk-0.1.0/prior/checklist/__init__.py +58 -0
  41. prior_sdk-0.1.0/prior/checklist/__main__.py +133 -0
  42. prior_sdk-0.1.0/prior/checklist/decision.py +230 -0
  43. prior_sdk-0.1.0/prior/checklist/filter.py +65 -0
  44. prior_sdk-0.1.0/prior/checklist/label.py +43 -0
  45. prior_sdk-0.1.0/prior/checklist/models.py +179 -0
  46. prior_sdk-0.1.0/prior/checklist/retrieve.py +59 -0
  47. prior_sdk-0.1.0/prior/checklist/skills.py +54 -0
  48. prior_sdk-0.1.0/prior/checklist/store.py +231 -0
  49. prior_sdk-0.1.0/prior/checklist/time.py +23 -0
  50. prior_sdk-0.1.0/prior/cli/__init__.py +1 -0
  51. prior_sdk-0.1.0/prior/cli/__main__.py +3 -0
  52. prior_sdk-0.1.0/prior/cli/main.py +591 -0
  53. prior_sdk-0.1.0/prior/cli/tests/__init__.py +0 -0
  54. prior_sdk-0.1.0/prior/cli/tests/test_cli.py +176 -0
  55. prior_sdk-0.1.0/prior/core/__init__.py +34 -0
  56. prior_sdk-0.1.0/prior/core/conditions.py +91 -0
  57. prior_sdk-0.1.0/prior/core/errors.py +10 -0
  58. prior_sdk-0.1.0/prior/core/models.py +394 -0
  59. prior_sdk-0.1.0/prior/core/time.py +109 -0
  60. prior_sdk-0.1.0/prior/mcp/__init__.py +27 -0
  61. prior_sdk-0.1.0/prior/mcp/__main__.py +28 -0
  62. prior_sdk-0.1.0/prior/mcp/http.py +185 -0
  63. prior_sdk-0.1.0/prior/mcp/quota.py +37 -0
  64. prior_sdk-0.1.0/prior/mcp/server.py +201 -0
  65. prior_sdk-0.1.0/prior/mcp/tests/__init__.py +0 -0
  66. prior_sdk-0.1.0/prior/mcp/tests/test_api_parity.py +155 -0
  67. prior_sdk-0.1.0/prior/mcp/tests/test_http.py +352 -0
  68. prior_sdk-0.1.0/prior/mcp/tests/test_tools.py +632 -0
  69. prior_sdk-0.1.0/prior/mcp/tools.py +888 -0
  70. prior_sdk-0.1.0/prior/recall.py +137 -0
  71. prior_sdk-0.1.0/prior/replay.py +117 -0
  72. prior_sdk-0.1.0/prior/sdk/__init__.py +39 -0
  73. prior_sdk-0.1.0/prior/sdk/client.py +572 -0
  74. prior_sdk-0.1.0/prior/sdk/errors.py +66 -0
  75. prior_sdk-0.1.0/prior/sdk/facts.py +48 -0
  76. prior_sdk-0.1.0/prior/sdk/http.py +140 -0
  77. prior_sdk-0.1.0/prior/sdk/models.py +163 -0
  78. prior_sdk-0.1.0/prior/sdk/ports.py +43 -0
  79. prior_sdk-0.1.0/prior/sdk/queue.py +173 -0
  80. prior_sdk-0.1.0/prior/sdk/spine.py +339 -0
  81. prior_sdk-0.1.0/prior/sdk/tests/__init__.py +0 -0
  82. prior_sdk-0.1.0/prior/sdk/tests/test_http.py +80 -0
  83. prior_sdk-0.1.0/prior/sdk/tests/test_local.py +115 -0
  84. prior_sdk-0.1.0/prior/sdk/tests/test_recall.py +93 -0
  85. prior_sdk-0.1.0/prior/sdk/tests/test_record.py +138 -0
  86. prior_sdk-0.1.0/prior/sdk/time.py +79 -0
  87. prior_sdk-0.1.0/prior/services/__init__.py +21 -0
  88. prior_sdk-0.1.0/prior/services/benchmark.py +177 -0
  89. prior_sdk-0.1.0/prior/services/bootstrap.py +61 -0
  90. prior_sdk-0.1.0/prior/services/checkback.py +287 -0
  91. prior_sdk-0.1.0/prior/services/consolidate.py +493 -0
  92. prior_sdk-0.1.0/prior/services/evals.py +295 -0
  93. prior_sdk-0.1.0/prior/services/gate_stats.py +717 -0
  94. prior_sdk-0.1.0/prior/services/killswitch.py +81 -0
  95. prior_sdk-0.1.0/prior/services/policy.py +79 -0
  96. prior_sdk-0.1.0/prior/services/runner.py +319 -0
  97. prior_sdk-0.1.0/prior/services/settle.py +178 -0
  98. prior_sdk-0.1.0/prior/services/similar.py +97 -0
  99. prior_sdk-0.1.0/prior/services/worker.py +248 -0
  100. prior_sdk-0.1.0/prior/store/__init__.py +6 -0
  101. prior_sdk-0.1.0/prior/store/ports.py +78 -0
  102. prior_sdk-0.1.0/prior/store/sqlite.py +943 -0
  103. prior_sdk-0.1.0/prior_sdk.egg-info/PKG-INFO +523 -0
  104. prior_sdk-0.1.0/prior_sdk.egg-info/SOURCES.txt +168 -0
  105. prior_sdk-0.1.0/prior_sdk.egg-info/dependency_links.txt +1 -0
  106. prior_sdk-0.1.0/prior_sdk.egg-info/entry_points.txt +4 -0
  107. prior_sdk-0.1.0/prior_sdk.egg-info/requires.txt +7 -0
  108. prior_sdk-0.1.0/prior_sdk.egg-info/top_level.txt +2 -0
  109. prior_sdk-0.1.0/pyproject.toml +65 -0
  110. prior_sdk-0.1.0/setup.cfg +4 -0
  111. prior_sdk-0.1.0/tests/fixtures/contexts/fixture-episode-1.json +27 -0
  112. prior_sdk-0.1.0/tests/fixtures/contexts/fixture-skill-context.json +32 -0
  113. prior_sdk-0.1.0/tests/fixtures/episodes/fixture-episode-1.json +16 -0
  114. prior_sdk-0.1.0/tests/fixtures/memory-empty.json +1 -0
  115. prior_sdk-0.1.0/tests/fixtures/memory-items.json +37 -0
  116. prior_sdk-0.1.0/tests/fixtures/memory-missing.json +10 -0
  117. prior_sdk-0.1.0/tests/fixtures/skills/fixture_skill.md +15 -0
  118. prior_sdk-0.1.0/tests/fixtures/skills/missing_selector.md +8 -0
  119. prior_sdk-0.1.0/tests/fixtures/skills/prose_only.md +3 -0
  120. prior_sdk-0.1.0/tests/fixtures/skills/prose_selector.md +9 -0
  121. prior_sdk-0.1.0/tests/prior_factory.py +104 -0
  122. prior_sdk-0.1.0/tests/test_adapter_custom.py +406 -0
  123. prior_sdk-0.1.0/tests/test_adapter_horizons.py +70 -0
  124. prior_sdk-0.1.0/tests/test_adapter_jupiter.py +393 -0
  125. prior_sdk-0.1.0/tests/test_arms.py +110 -0
  126. prior_sdk-0.1.0/tests/test_benchmark.py +194 -0
  127. prior_sdk-0.1.0/tests/test_checkback_blame.py +299 -0
  128. prior_sdk-0.1.0/tests/test_checkbacks.py +555 -0
  129. prior_sdk-0.1.0/tests/test_cli.py +87 -0
  130. prior_sdk-0.1.0/tests/test_coin_gecko_tier.py +98 -0
  131. prior_sdk-0.1.0/tests/test_coingecko_price.py +126 -0
  132. prior_sdk-0.1.0/tests/test_conditions.py +425 -0
  133. prior_sdk-0.1.0/tests/test_console_api.py +704 -0
  134. prior_sdk-0.1.0/tests/test_consolidate.py +715 -0
  135. prior_sdk-0.1.0/tests/test_cors_origins.py +74 -0
  136. prior_sdk-0.1.0/tests/test_decision.py +230 -0
  137. prior_sdk-0.1.0/tests/test_demo_audit.py +244 -0
  138. prior_sdk-0.1.0/tests/test_demo_distill.py +369 -0
  139. prior_sdk-0.1.0/tests/test_demo_find_moments.py +293 -0
  140. prior_sdk-0.1.0/tests/test_demo_loop.py +501 -0
  141. prior_sdk-0.1.0/tests/test_demo_loosening.py +509 -0
  142. prior_sdk-0.1.0/tests/test_demo_mcp.py +386 -0
  143. prior_sdk-0.1.0/tests/test_demo_rebuild.py +163 -0
  144. prior_sdk-0.1.0/tests/test_demo_recorded.py +189 -0
  145. prior_sdk-0.1.0/tests/test_demo_report.py +151 -0
  146. prior_sdk-0.1.0/tests/test_eval.py +598 -0
  147. prior_sdk-0.1.0/tests/test_exports.py +108 -0
  148. prior_sdk-0.1.0/tests/test_filter.py +44 -0
  149. prior_sdk-0.1.0/tests/test_gate_stats.py +718 -0
  150. prior_sdk-0.1.0/tests/test_holes.py +383 -0
  151. prior_sdk-0.1.0/tests/test_idempotency.py +111 -0
  152. prior_sdk-0.1.0/tests/test_keys_cli.py +135 -0
  153. prior_sdk-0.1.0/tests/test_killswitch.py +123 -0
  154. prior_sdk-0.1.0/tests/test_label.py +52 -0
  155. prior_sdk-0.1.0/tests/test_one_package.py +300 -0
  156. prior_sdk-0.1.0/tests/test_policy.py +82 -0
  157. prior_sdk-0.1.0/tests/test_prediction_set.py +154 -0
  158. prior_sdk-0.1.0/tests/test_prior_leak.py +78 -0
  159. prior_sdk-0.1.0/tests/test_prior_leak_path.py +140 -0
  160. prior_sdk-0.1.0/tests/test_prior_recall.py +181 -0
  161. prior_sdk-0.1.0/tests/test_prior_replay.py +121 -0
  162. prior_sdk-0.1.0/tests/test_prior_store.py +112 -0
  163. prior_sdk-0.1.0/tests/test_replay_report.py +105 -0
  164. prior_sdk-0.1.0/tests/test_replay_set.py +96 -0
  165. prior_sdk-0.1.0/tests/test_retrieve.py +80 -0
  166. prior_sdk-0.1.0/tests/test_skills.py +36 -0
  167. prior_sdk-0.1.0/tests/test_store.py +390 -0
  168. prior_sdk-0.1.0/tests/test_subject_scope.py +121 -0
  169. prior_sdk-0.1.0/tests/test_warnings.py +197 -0
  170. prior_sdk-0.1.0/tests/test_worker.py +234 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Tobi Omotade
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,12 @@
1
+ include LICENSE
2
+ include README.md
3
+ include RELEASING.md
4
+
5
+ graft tests
6
+ graft examples
7
+ graft prior/adapters/tests
8
+ graft prior/cli/tests
9
+ graft prior/mcp/tests
10
+ graft prior/sdk/tests
11
+
12
+ global-exclude *.py[cod]
@@ -0,0 +1,523 @@
1
+ Metadata-Version: 2.4
2
+ Name: prior-sdk
3
+ Version: 0.1.0
4
+ Summary: Time-honest memory for trading agents. The frozen tracemind checklist still ships in this distribution.
5
+ Author: Tobi Omotade
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/tobi-techy/prior#readme
8
+ Project-URL: Repository, https://github.com/tobi-techy/prior
9
+ Project-URL: Issues, https://github.com/tobi-techy/prior/issues
10
+ Project-URL: Documentation, https://github.com/tobi-techy/prior/tree/main/docs
11
+ Keywords: trading agents,agent memory,memory store,point-in-time,evals,replay,solana,llm
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Framework :: FastAPI
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3 :: Only
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Topic :: Office/Business :: Financial :: Investment
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Requires-Python: >=3.11
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ Requires-Dist: pydantic==2.14.4
26
+ Requires-Dist: fastapi==0.165.0
27
+ Requires-Dist: opentelemetry-api==1.45.3
28
+ Requires-Dist: uvicorn==0.55.0
29
+ Provides-Extra: dev
30
+ Requires-Dist: httpx2==2.17.2; extra == "dev"
31
+ Dynamic: license-file
32
+
33
+ <p align="center">
34
+ <img alt="Prior. Memory for trading agents." src="docs/assets/prior-banner.png" width="100%">
35
+ </p>
36
+
37
+ <h3 align="center">Your trading agent remembers every call, finds out how it went, and learns before the next one.</h3>
38
+
39
+ <p align="center">
40
+ Time-honest by design. Prior can never hand your agent something it couldn't have known at the moment it decided.
41
+ </p>
42
+
43
+ <p align="center">
44
+ <a href="#quickstart">Quickstart</a> ยท
45
+ <a href="#how-it-works">How it works</a> ยท
46
+ <a href="#core-ideas">Core ideas</a> ยท
47
+ <a href="#a-case-from-start-to-finish">Example</a> ยท
48
+ <a href="#status">Status</a> ยท
49
+ <a href="#faq">FAQ</a> ยท
50
+ <a href="docs/PRIOR-TECHNICAL-SPEC.md">Spec</a>
51
+ </p>
52
+
53
+ ---
54
+
55
+ ## Contents
56
+
57
+ - [Why Prior](#why-prior)
58
+ - [How it works](#how-it-works)
59
+ - [Core ideas](#core-ideas)
60
+ - [Two clocks, no lookahead](#two-clocks-no-lookahead)
61
+ - [A Case from start to finish](#a-case-from-start-to-finish)
62
+ - [Quickstart](#quickstart)
63
+ - [SDK reference](#sdk-reference)
64
+ - [CLI reference](#cli-reference)
65
+ - [Check-backs and outcomes](#check-backs-and-outcomes)
66
+ - [How Prior learns](#how-prior-learns)
67
+ - [Evals](#evals)
68
+ - [Venues and adapters](#venues-and-adapters)
69
+ - [Safety](#safety)
70
+ - [Status](#status)
71
+ - [Repo layout](#repo-layout)
72
+ - [Tests](#tests)
73
+ - [FAQ](#faq)
74
+
75
+ ---
76
+
77
+ ## Why Prior
78
+
79
+ Trading agents make the same mistake twice.
80
+
81
+ - **They forget.** Last week's rug looks brand new this week.
82
+ - **They never learn from what they skipped.** If the agent passed on a token that went 5x, nobody tells it.
83
+ - **Their "lessons" can't be trusted.** When an agent says it learned something, there's usually no way to prove the lesson didn't peek at the future. A backtest that sees tomorrow's price looks brilliant and means nothing.
84
+
85
+ Prior is a memory layer your agent calls **before** and **after** every decision. It records what happened, goes back later to see how it turned out, turns repeated mistakes into rules, and hands those rules back at the next decision. It does all of that only with what was actually known at the time.
86
+
87
+ > Prior advises. It never signs a transaction, holds a key or places a trade. Your agent stays in control.
88
+
89
+ ---
90
+
91
+ ## How it works
92
+
93
+ Four steps, on a loop.
94
+
95
+ | | Step | What happens |
96
+ |---|---|---|
97
+ | 1 | **Record** | Every bet, trade **or skip** becomes a **Case**: what the agent saw, what it decided, why, and what actually filled. |
98
+ | 2 | **Check back** | Later (1h, 6h, 24h, 7d, or when a market resolves) Prior looks again and settles the Case: win, loss, dump avoided, runner missed and so on. |
99
+ | 3 | **Learn** | Patterns across settled Cases become proposed **Rules** (from losses) and **Playbooks** (from wins). Each cites the Cases it came from. You promote it before it goes live. |
100
+ | 4 | **Recall** | Before the next decision, the agent asks "what do I know, as of now?" and gets the matching rules, similar past Cases and a hint: `skip` or `proceed`. |
101
+
102
+ ```
103
+ your agent
104
+ โ”‚
105
+ โ”œโ”€โ”€ 1. recall(facts, as_of=now) โ”€โ”€โ”€โ”€โ”€โ”€โ–บ rules + similar cases + hint
106
+ โ”‚
107
+ โ”œโ”€โ”€ decide and trade (your code, your keys)
108
+ โ”‚
109
+ โ””โ”€โ”€ 2. record(case) โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บ Case
110
+ โ”‚
111
+ 3. check back 1h ยท 6h ยท 24h ยท 7d ยท resolution
112
+ โ”‚
113
+ Outcome (scored vs a benchmark)
114
+ โ”‚
115
+ 4. consolidate โ”€โ”€โ–บ proposed Rule / Playbook
116
+ โ”‚
117
+ you promote โ”€โ”€โ–บ live ยท versioned ยท revocable
118
+ ```
119
+
120
+ ---
121
+
122
+ ## Core ideas
123
+
124
+ | Term | Plain meaning |
125
+ |---|---|
126
+ | **Agent** | One trading bot. It has its own memory and its own API keys, like a workspace. |
127
+ | **Subject** | Who or what a decision was for, such as one user's wallet. Rules can apply to one subject or the whole agent. |
128
+ | **Case** | One decision: the snapshot of facts the agent saw, the action (`buy`, `skip`, `bet_yes` โ€ฆ), the reasoning, what it recalled and the execution. |
129
+ | **Check-back** | A scheduled look at the market after the decision. |
130
+ | **Outcome** | What a check-back found, as a label plus numbers. A Case can get several outcome versions as more check-backs land. |
131
+ | **Rule** | A learned "don't" or "be careful", e.g. *skip when top-10 holders own over 30%*. It has a condition, an effect and evidence. |
132
+ | **Playbook** | A learned "this works", e.g. *size up when the pool is over 6h old and volume is rising*. |
133
+ | **Version** | Rules never change in place. Every edit, promotion, pause or revoke is a new version with its own dates. |
134
+ | **As of** | The moment you're asking from. Every read in Prior takes one. |
135
+
136
+ ---
137
+
138
+ ## Two clocks, no lookahead
139
+
140
+ This is the part that makes Prior different, so here it is slowly.
141
+
142
+ Every object carries **two kinds of time**:
143
+
144
+ | Field | Question it answers |
145
+ |---|---|
146
+ | `seen_at`, `decided_at` | When did the agent see the data, and when did it act? |
147
+ | `known_at` | When did *this fact, outcome or rule version* become knowable? |
148
+ | `valid_from`, `valid_to` | When was this rule version in force? |
149
+
150
+ Every read goes through **one gate**, `visible_at(T)`. It only returns things with `known_at <= T`, and for rules also `valid_from <= T` and no `valid_to` yet. An outcome that wasn't settled at `T` comes back as `pending`, with no label.
151
+
152
+ **Why it matters.** Say the agent bought $WIF at 14:00 and it dumped at 18:00. A rule learned from that dump has `known_at = 18:00` or later. If you replay a 15:00 decision, that rule simply isn't there, because it couldn't have been.
153
+
154
+ That gives you **deterministic replay**:
155
+
156
+ ```bash
157
+ prior replay case_8f2c --audit
158
+ ```
159
+
160
+ It rebuilds the decision with exactly the memory it had and checks every rule and outcome it touched. If anything has `known_at` after the decision, the audit fails and names it.
161
+
162
+ ```json
163
+ {
164
+ "case_id": "case_8f2c",
165
+ "cutoff": "2026-11-12T15:00:00Z",
166
+ "replay_match": true,
167
+ "objects_touched": 4,
168
+ "max_known_at": "2026-11-12T14:58:10Z",
169
+ "violations": [],
170
+ "passed": true
171
+ }
172
+ ```
173
+
174
+ ---
175
+
176
+ ## A Case from start to finish
177
+
178
+ A memecoin spot agent looking at a new token on Jupiter.
179
+
180
+ **1. Recall, before deciding.** The agent sends what it sees:
181
+
182
+ ```python
183
+ mem = prior.recall(
184
+ instrument={"mint": "<mint>", "symbol": "MOODENG", "venue": "jupiter"},
185
+ facts={"top10_holders_pct": 41.2, "liquidity_usd": 412_000, "pool_age_min": 38},
186
+ )
187
+ ```
188
+
189
+ Prior answers with what was knowable right now (example values):
190
+
191
+ ```json
192
+ {
193
+ "decision_hint": "skip",
194
+ "rules": [
195
+ {
196
+ "id": "R-14", "version": 3,
197
+ "text": "Skip when top-10 holders own more than 30%.",
198
+ "condition": {"all": [{"fact": "top10_holders_pct", "op": ">", "value": 30}]},
199
+ "effect": {"type": "skip"},
200
+ "evidence": ["case_41a0", "case_5b77", "case_7c19"]
201
+ }
202
+ ],
203
+ "similar_cases": [],
204
+ "max_known_at": "2026-11-29T09:12:00Z"
205
+ }
206
+ ```
207
+
208
+ **2. Record the decision, even a skip.**
209
+
210
+ ```python
211
+ prior.record("skip", instrument=token, facts=facts, recall=mem,
212
+ kind="spot", reasoning="R-14 fired: 41% in top 10")
213
+ ```
214
+
215
+ **3. Check back.** Prior looks at the price at 1h, 6h, 24h and 7d. At 24h the token is down 63%, so the outcome is `dump_avoided`. If it had gone up 3x instead, it would be `runner_missed`, and that evidence would count *against* R-14.
216
+
217
+ **4. Learn.** If R-14 starts missing more runners than dumps it avoids, consolidation proposes a looser version (say, over 45% instead of over 30%) with the Cases that justify it. You review it and promote it or not.
218
+
219
+ ---
220
+
221
+ ## Quickstart
222
+
223
+ Needs Python 3.11 or newer. `pip install prior-sdk` installs pydantic 2.14.4, fastapi 0.165.0, and uvicorn 0.55.0, pinned from PyPI on 3 Dec 2026.
224
+
225
+ ```bash
226
+ python -m venv .venv && source .venv/bin/activate
227
+ pip install prior-sdk
228
+ ```
229
+
230
+ To work on Prior itself, clone this repository and run `pip install -e .` instead.
231
+
232
+ ### Record and recall (local mode)
233
+
234
+ Local mode keeps everything in one SQLite file, so there's no server to run.
235
+
236
+ ```python
237
+ from prior.sdk import Prior
238
+
239
+ prior = Prior.local("./prior.db", agent_id="ag_demo")
240
+
241
+ token = {"mint": "<mint>", "symbol": "MOODENG", "venue": "jupiter"}
242
+ facts = {"top10_holders_pct": 41.2, "liquidity_usd": 412_000, "pool_age_min": 38}
243
+
244
+ # 1. Ask what you know, as of now
245
+ mem = prior.recall(instrument=token, facts=facts)
246
+
247
+ # 2. Decide with your own logic, then record it. Skips are recorded too.
248
+ action = "skip" if mem.decision_hint == "skip" else "buy"
249
+ prior.record(action, instrument=token, facts=facts, recall=mem,
250
+ size_usd=50, kind="spot", reasoning="why the agent did this",
251
+ synthetic=True)
252
+
253
+ prior.close()
254
+ ```
255
+
256
+ ### See the audit catch a leak
257
+
258
+ ```bash
259
+ python examples/prior_local.py
260
+ ```
261
+
262
+ It records a Case, recalls it, then sneaks in a rule from the future. The replay audit catches it and names the rule.
263
+
264
+ ---
265
+
266
+ ## SDK reference
267
+
268
+ | Call | What it does | Guarantee |
269
+ |---|---|---|
270
+ | `Prior.local(path, agent_id=...)` | Open a local SQLite memory | One file, no server |
271
+ | `prior.recall(instrument, facts, as_of=None, subject=None, k=5)` | Rules, playbooks, similar Cases and a hint, as of `as_of` (default now) | Times out at **300 ms** and returns an empty `degraded` result instead of raising |
272
+ | `prior.record(action, instrument, facts, recall, reasoning, size_usd, kind, subject)` | Save a decision as a Case | Returns in under **50 ms**. If the store is down the Case is spilled to disk and retried. Never raises into your loop unless `strict=True` |
273
+ | `prior.flush()` | Retry anything spilled | |
274
+ | `prior.replay(case_id)` | Deterministic replay and lookahead audit | Same inputs, same answer, every time |
275
+ | `prior.cases.list(...)`, `prior.cases.get(id)` | Read Cases as of a time | Goes through `visible_at` |
276
+
277
+ `kind` is `spot`, `prediction` or `perp`. `action` is one of `buy`, `sell`, `skip`, `bet_yes`, `bet_no`, `open_long`, `open_short` or `close`.
278
+
279
+ A hosted client (`Prior(api_key=...)`) is in the SDK and will point at the `/v1` API once that lands. The TypeScript client is `prior-sdk` on npm (`npm install prior-sdk`), sourced in `sdk/`. It wraps this API and does not open a second store.
280
+
281
+ ---
282
+
283
+ ## CLI reference
284
+
285
+ ```bash
286
+ export PRIOR_DB=./prior.db
287
+ export PRIOR_AGENT_ID=ag_demo
288
+
289
+ python -m prior.cli cases list --since 7d
290
+ python -m prior.cli cases list --outcome loss --as-of 2026-11-30
291
+ python -m prior.cli cases show <case_id>
292
+ python -m prior.cli recall --facts facts.json --as-of 2026-11-30
293
+ python -m prior.cli replay <case_id> --audit
294
+ python -m prior.cli leak-test
295
+ ```
296
+
297
+ - After `pip install prior-sdk`, replay also works as `prior replay <case_id> --audit --db ./prior.db`.
298
+ - `prior checkbacks run --db ./prior.db` reads due check-backs and appends outcome versions. It needs `COINGECKO_API_KEY`, and a **Pro** key needs `COINGECKO_TIER=pro`: the default tier is `demo`, so a Pro key on the demo base returns a 400 (`error_code 10010`) and the read reports no price. CoinGecko onchain price is a live pool price, not a historical candle, and the command does not invent one. `known_at` is the time the read returns.
299
+ - `python -m prior.api --db ./prior.db` serves the same SQLite file. Reads take `as_of` and go through `visible_at`. Lists return `{items, next_cursor}`. Keys use `pr_live_` and `pr_test_`. Only the hash is stored. Postgres waits. There is no second database.
300
+ - Add `--json` to any command for scripts.
301
+ - `leak-test` runs the time-honesty checks against the Cases in your database and exits non-zero on failure. An empty database doesn't count as a pass.
302
+
303
+ ---
304
+
305
+ ## Check-backs and outcomes
306
+
307
+ Check-backs are created the moment a Case is recorded, **including skips**.
308
+
309
+ | Market | Check-backs | The one that settles it |
310
+ |---|---|---|
311
+ | Spot | 1h ยท 6h ยท 24h ยท 7d | 24h |
312
+ | Perp | 1h ยท 6h ยท 24h ยท close | close (or liquidation) |
313
+ | Prediction | resolution, polled hourly for up to 30 days | resolution |
314
+
315
+ A failed read retries three times (60s, 5m, 15m), then stays `failed` until retried by hand. Every check-back writes a new outcome version. Old ones are never changed.
316
+
317
+ | Label | Meaning |
318
+ |---|---|
319
+ | `win` / `loss` / `flat` | A trade that made, lost or roughly broke even |
320
+ | `dump_avoided` | A skip, and the price fell more than 50% within 24h |
321
+ | `runner_missed` | A skip, and the price more than doubled within 24h |
322
+ | `rug` | Liquidity pulled or price went to zero |
323
+ | `resolved_yes` / `resolved_no` | A prediction market settled |
324
+
325
+ **Scored fairly.** Each outcome is compared with a benchmark over the same window (SOL for spot, the market's own price for prediction), giving `excess_return_pct`. A trade that lost 10% while the market lost 20% did *better* than the market, and Prior won't learn a "don't" from it. Prediction bets also get a **Brier score**, so you can see whether the agent's probabilities are honest.
326
+
327
+ ---
328
+
329
+ ## How Prior learns
330
+
331
+ Consolidation reads settled Cases (only those whose outcome was known by the time it runs) and **proposes** new rule and playbook versions. It never promotes on its own.
332
+
333
+ - **Evidence or nothing.** A proposal lists the Cases behind it, and its condition must actually match them. A draft whose text doesn't match its own condition is rejected.
334
+ - **No noise rules.** Candidate rules go through a Benjamini-Hochberg false-discovery check, so random streaks don't become rules.
335
+ - **Not too cautious.** If a skip rule has missed more runners than dumps it avoided over the last 30 days, Prior proposes a looser version.
336
+ - **Excess return, not raw PnL.** Rules are learned from how a decision did *against the benchmark*.
337
+ - **Kill switch.** Every rule carries `pause_if: rolling_30d_edge < 0 or ci95.high < 0`, so a rule that stops paying for itself gets paused. (The automatic pause is being wired in now.)
338
+ - **Missing facts never match.** If the agent didn't have a fact, no rule that needs it can fire.
339
+
340
+ ---
341
+
342
+ ## Evals
343
+
344
+ Does memory actually help? Prior answers that with a **walk-forward eval** over a frozen list of Cases. It uses one decision function, and the arms differ only in what memory they're allowed to see.
345
+
346
+ | Arm | Sees |
347
+ |---|---|
348
+ | `no_memory` | Nothing. A fixed checklist only (mint and freeze authority, thin liquidity, token age) |
349
+ | `prior` | Rule versions and settled outcomes with `known_at <= decided_at` |
350
+ | `shuffled` | The same amount of memory, scrambled. A control: if this does as well as `prior`, the memory isn't the reason |
351
+
352
+ The report lists every decision where the arms disagree, with the real outcome beside it. It doesn't name a winner for you.
353
+
354
+ <!-- replay-set:start -->
355
+ Prior replay set, 542 cases, Sep to Nov 2026. 542 of them settled, read as of 2026-12-04T13:11:21.346415Z.
356
+
357
+ | Agent | Arm | Cases | Skips | Mean excess when proceed (%) |
358
+ |---|---|---|---|---|
359
+ | `ag_replay_prediction` | `no_memory` | 36 | 0 | 33.2021 |
360
+ | `ag_replay_prediction` | `raw_notes` | 36 | 0 | 33.2021 |
361
+ | `ag_replay_prediction` | `rules_no_checkback` | 36 | 0 | 33.2021 |
362
+ | `ag_replay_prediction` | `prior` | 36 | 0 | 33.2021 |
363
+ | `ag_replay_prediction` | `shuffled` | 36 | 0 | 33.2021 |
364
+ | `ag_replay_spot` | `no_memory` | 506 | 0 | 0.0788971 |
365
+ | `ag_replay_spot` | `raw_notes` | 506 | 0 | 0.0788971 |
366
+ | `ag_replay_spot` | `rules_no_checkback` | 506 | 0 | 0.0788971 |
367
+ | `ag_replay_spot` | `prior` | 506 | 393 | -0.325771 |
368
+ | `ag_replay_spot` | `shuffled` | 506 | 0 | 0.0788971 |
369
+
370
+ | Agent | Metric | `prior - no_memory` | Dropped pairs | 95% CI |
371
+ |---|---|---|---|---|
372
+ | `ag_replay_prediction` | paired mean weighted excess, % per case both arms took, pairs either arm could not price dropped | 0 | 0 | [0, 0] |
373
+ | `ag_replay_spot` | paired mean weighted excess, % per case both arms took, pairs either arm could not price dropped | -0.151648 | 0 | [-0.820938, 0.529609] |
374
+
375
+ Replay audit over the full set: 542 cases, 0 lookahead violations, passed true. Leak sweep: 544 cutoffs, 0 violations, passed true.
376
+
377
+ The arms disagree on 393 decisions; `evals/report.json` lists each case id with its real outcome and excess beside it.
378
+
379
+ Every case names 1048 decision-time sources and 542 outcome sources by public url and timestamp in `evals/dataset.json`. Data by Coingecko API.
380
+
381
+ `ag_replay_prediction`: the five arms take the same decision on all 36 cases, so there is nothing to separate here.
382
+ `ag_replay_spot`: `prior` is -0.151648 points per case against `no_memory`, interval [-0.820938, 0.529609], so the interval spans zero and this set does not separate the two arms. The arms disagree on 393 of 506 decisions.
383
+ <!-- replay-set:end -->
384
+
385
+ ---
386
+
387
+ ## Venues and adapters
388
+
389
+ Adapters wrap **your** function. They read quotes and results and attach the execution to the Case. They never sign.
390
+
391
+ | Venue | Market | Status | How outcomes are checked |
392
+ |---|---|---|---|
393
+ | **Jupiter** | Spot swaps, Solana memecoins | Built | CoinGecko on-chain token price by mint |
394
+ | **Jupiter Predict** | Prediction markets, YES / NO | In progress | Market resolution |
395
+ | **Phoenix** | Perps | Stretch goal | Phoenix market data and funding |
396
+ | **Custom** | Any function you wrap | Built | A price function you supply |
397
+
398
+ ```python
399
+ from prior.adapters import jupiter
400
+
401
+ swap = jupiter.wrap(my_swap_fn) # your function, your signer
402
+ ```
403
+
404
+ The wrapper records quote, fill, slippage, fees and the transaction signature. A failed swap is stored as `failed` and the original error is re-raised.
405
+
406
+ A spot arm prices its token through CoinGecko onchain by mint, which needs `COINGECKO_API_KEY`, and a Pro key needs `COINGECKO_TIER=pro` because the default tier is `demo`. Without both, the arm records no spot case and says `no_price_source` instead of a price; it never fills the gap with a number it did not read.
407
+
408
+ Spot prices: Data by CoinGecko API.
409
+
410
+ ---
411
+
412
+ ## Safety
413
+
414
+ - **No keys, ever.** Adapters refuse to store anything that looks like a private key or keypair (`KeypairRefusal`).
415
+ - **Append-only.** The database blocks `UPDATE` and `DELETE` on Cases, outcomes and rule versions.
416
+ - **Human in the loop.** Rules are proposed, not promoted, until you say so.
417
+ - **Never in your way.** A slow or broken Prior can't stall or crash your trading loop.
418
+
419
+ ---
420
+
421
+ ## Status
422
+
423
+ Prior is being built in the open for the Solana **Perps and Prediction** hackathon. Submissions close Tue 8 Dec 2026, 22:00 WAT.
424
+
425
+ | Piece | What it does | State |
426
+ |---|---|---|
427
+ | Store and replay audit | Append-only SQLite, `visible_at(T)`, lookahead audit, leak sweep | โœ… Merged ยท #6 |
428
+ | SDK and CLI | Non-blocking record, safe recall, replay, leak-test | โœ… Merged ยท #11 |
429
+ | Adapters | Jupiter and custom swap wrap, never signs | ๐ŸŸก In review ยท #8 |
430
+ | Check-back and settle | Check-backs for every Case, outcome versions, CoinGecko price | ๐ŸŸก In review ยท #9 |
431
+ | Consolidation | Proposes rules and playbooks, too-cautious loop, FDR | ๐ŸŸก In review ยท #12 |
432
+ | Walk-forward eval | `no_memory` vs `prior` vs `shuffled` | ๐ŸŸก In review ยท #10 |
433
+ | Console client | Typed reads for the dashboard | ๐ŸŸก In review ยท #7 |
434
+ | One shared model package | Every service on `prior.core` | ๐Ÿ”œ Next |
435
+ | REST API and keys | `/v1` server, scoped `pr_live_` / `pr_test_` keys | ๐Ÿ”œ Next |
436
+ | Check-back runner | Settles due Cases on a schedule | ๐Ÿ”œ Next |
437
+ | Jupiter Predict adapter | Markets, bets, resolution | ๐Ÿ”œ Next |
438
+ | Console | Cases, Memory, Replay, Evals, Keys | ๐ŸŽจ Designed, wiring next |
439
+ | MCP server | `/mcp` for Claude, Cursor and Codex, ten tools incl. `prior_check` | ๐ŸŸก In review ยท #31 |
440
+
441
+ The older checklist now imports as `prior.checklist`. It is frozen. New work goes in the rest of `prior/`.
442
+
443
+ ---
444
+
445
+ ## Repo layout
446
+
447
+ ```
448
+ prior/
449
+ core/ models, the visible_at time gate, condition logic
450
+ store/ SQLite store with append-only triggers
451
+ services/ checkback, settle, consolidate, evals
452
+ adapters/ jupiter, custom, prices/coingecko
453
+ sdk/ Prior client: local and hosted, queue, disk spill
454
+ cli/ python -m prior.cli
455
+ recall.py recall as of a cutoff
456
+ replay.py deterministic replay and lookahead audit
457
+ console/ typed client for the dashboard
458
+ examples/ prior_local.py: record, recall, then fail an audit on purpose
459
+ docs/ technical spec and brand assets
460
+ tests/ leak, append-only, replay, check-back, consolidation, eval
461
+ prior/checklist/ frozen checklist, formerly tracemind
462
+ ```
463
+
464
+ ---
465
+
466
+
467
+ ## Tests
468
+
469
+ ```bash
470
+ pip install -e ".[dev]"
471
+ python -m unittest discover -s tests -q
472
+ python -m unittest discover -s prior -q
473
+ ```
474
+
475
+ The `dev` extra carries `httpx2`, which `fastapi.testclient` needs at import time: `prior.mcp.tests.test_api_parity` fails at import on a clean `pip install -e .` without it.
476
+
477
+ What the important ones prove:
478
+
479
+ | Test | Proves |
480
+ |---|---|
481
+ | Leak sweep | Across 50 random cutoffs, no read returns anything from after the cutoff |
482
+ | Replay | 100 replays match their stored recall exactly, and a seeded future rule fails the audit |
483
+ | Append-only | `UPDATE` and `DELETE` are refused, including replace |
484
+ | Skip check-back | A skip gets check-backs and can settle as `dump_avoided` or `runner_missed` |
485
+ | Too-cautious | A skip rule that misses runners gets a looser proposal |
486
+ | Missing facts | A rule needing a fact the agent didn't have doesn't match, and nothing crashes |
487
+ | Non-blocking SDK | With the store down, `record` returns in under 50 ms and the Case lands later |
488
+
489
+ ---
490
+
491
+ ## FAQ
492
+
493
+ **Is this a trading bot?**
494
+ No. Prior is memory for a trading bot. Your agent makes the calls. Prior remembers them, checks how they went and tells the agent what it has learned.
495
+
496
+ **Does it predict prices?**
497
+ No. It learns from your agent's own track record, not from forecasting.
498
+
499
+ **Why record skips?**
500
+ Because most lessons hide there. A rule that skips everything looks safe until you count the runners it missed.
501
+
502
+ **Why not just use raw PnL?**
503
+ Raw PnL punishes the agent for market-wide moves it couldn't control. Prior scores against a benchmark so it learns from the agent's choices, not the market's mood.
504
+
505
+ **What does "time-honest" really mean?**
506
+ For any past decision you can prove which memory it used, and that all of it existed before the decision. Run `prior replay <case> --audit` and check.
507
+
508
+ **Can a rule go live by itself?**
509
+ No. Consolidation only proposes. A person promotes, and any rule can be paused or revoked at any time.
510
+
511
+ **What happens if Prior is down?**
512
+ Your agent keeps trading. `record` spills to disk and retries, and `recall` returns an empty `degraded` result.
513
+
514
+ ---
515
+
516
+ <p align="center">
517
+ <a href="docs/PRIOR-TECHNICAL-SPEC.md">Read the full technical spec</a>
518
+ </p>
519
+
520
+ <p align="center"><sub>prior ยท the past is known, the future is open</sub></p>
521
+
522
+
523
+