oh-my-fable 0.1.0

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 didrod205
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.
package/README.md ADDED
@@ -0,0 +1,215 @@
1
+ <div align="center">
2
+
3
+ # oh-my-fable
4
+
5
+ ### Fable 5's way of working a long task — plan first, self-correct every step, never lose the thread — as a model-agnostic agent harness.
6
+
7
+ <sub>The <i>fable</i> is <b>Fable 5</b>'s way of thinking; the <code>oh-my-</code> is because, like <code>oh-my-zsh</code>, you just want the good defaults. The mindset is the model's — the engine is any provider.</sub>
8
+
9
+ [![npm version](https://img.shields.io/npm/v/oh-my-fable.svg?color=success)](https://www.npmjs.com/package/oh-my-fable)
10
+ [![CI](https://github.com/didrod205/oh-my-fable/actions/workflows/ci.yml/badge.svg)](https://github.com/didrod205/oh-my-fable/actions/workflows/ci.yml)
11
+ [![types](https://img.shields.io/npm/types/oh-my-fable.svg)](https://www.npmjs.com/package/oh-my-fable)
12
+ [![zero deps](https://img.shields.io/badge/dependencies-0-brightgreen)](https://www.npmjs.com/package/oh-my-fable?activeTab=dependencies)
13
+ [![license](https://img.shields.io/npm/l/oh-my-fable.svg)](./LICENSE)
14
+
15
+ ```bash
16
+ npm i oh-my-fable
17
+ ```
18
+
19
+ </div>
20
+
21
+ The demos are magical. Then you point an agent at a *real* multi-hour task and it
22
+ loops on the same step, loses the plan somewhere in a 40-message chat history, and
23
+ — when your process restarts — forgets everything and starts over.
24
+
25
+ **oh-my-fable** encodes the way a strong reasoning model works a long task — the
26
+ *mindset*, not the model — into a harness: plan first, self-correct every step,
27
+ keep the thread, and finish. It's built around two mechanisms and one rule:
28
+
29
+ > The whole run lives in a single **`RunContext`** — the only source of truth, and
30
+ > always serializable. It's checkpointed after **every** step.
31
+
32
+ From that one rule you get the thing nobody else gives you: **a crash is a pause.**
33
+
34
+ <sub>The name is about the *thinking*, not a model lock-in — the mindset is Fable 5's, the
35
+ engine is whatever `Provider` you hand it (Anthropic, OpenAI-compatible, local, …).</sub>
36
+
37
+ ```
38
+ ── run run_mqf… ──
39
+ 📋 planned 3 steps: outline → draft → edit
40
+ ▶ outline
41
+ → outlined
42
+ 💾 checkpoint saved
43
+ ▶ draft
44
+ 💥 the process just died (power outage, OOM, deploy, whatever)
45
+
46
+ ── resuming from the last checkpoint ──
47
+ ▶ draft ← picks up exactly where it died
48
+ 💾 checkpoint saved
49
+ ▶ edit
50
+ ✅ done
51
+
52
+ steps: outline [done], draft [done], edit [done]
53
+ ```
54
+
55
+ ```ts
56
+ const result = await run(goal, { provider, store }); // crashes at step 2
57
+ // ...process restarts...
58
+ await resume(result.runId, { provider, store }); // finishes from step 2
59
+ ```
60
+
61
+ That's `examples/scripted-run.mjs` — run it with `npm run example`, no API key needed.
62
+
63
+ ## The three things it does that most frameworks don't
64
+
65
+ ### 1. It survives crashes (resumable by construction)
66
+
67
+ State doesn't live in memory or in a chat transcript — it lives in `RunContext`,
68
+ saved to disk after every step. Kill the process at step 47 of 60 and `resume()`
69
+ continues from step 47, plan and progress intact. Swap the `FileStore` for
70
+ SQLite/Redis by implementing one interface.
71
+
72
+ ### 2. It plans first, then self-corrects (plan ≠ history)
73
+
74
+ The **plan** is structured data that lives *outside* the conversation, so the model
75
+ never loses track of "where am I" in a wall of text. After every step a **reflector**
76
+ checks the result against the goal and routes:
77
+
78
+ | verdict | meaning | what happens |
79
+ | --- | --- | --- |
80
+ | `on_track` | normal progress | next step |
81
+ | `needs_replan` | the result changed the plan's assumptions | replan |
82
+ | `blocked` | same obstacle keeps recurring | replan around it / escalate |
83
+ | `goal_met` | success criteria satisfied | stop (even with steps left — no busywork) |
84
+
85
+ And replanning **accumulates**: finished steps are preserved verbatim; only the
86
+ remaining work is regenerated. Long tasks move forward instead of restarting.
87
+
88
+ ### 3. It's deterministically testable (genuinely rare for an agent framework)
89
+
90
+ Because every model call is stateless, you can script the model and assert the
91
+ loop's behavior — no network, no flakiness:
92
+
93
+ ```ts
94
+ import { run, ScriptedProvider, reply, MemoryStore } from "oh-my-fable";
95
+
96
+ const provider = new ScriptedProvider([
97
+ reply.plan([{ id: "s1", intent: "do the thing" }]),
98
+ reply.text("did it"),
99
+ reply.reflection("goal_met"),
100
+ ]);
101
+
102
+ const { status } = await run("do the thing", { provider, store: new MemoryStore() });
103
+ expect(status).toBe("done"); // fully deterministic
104
+ ```
105
+
106
+ The whole harness is tested this way — crash-recovery, replan-accumulation,
107
+ budget halts, the tool loop — all without a single API call.
108
+
109
+ ## Quick start
110
+
111
+ ```ts
112
+ import { run, AnthropicProvider } from "oh-my-fable";
113
+
114
+ const result = await run(
115
+ {
116
+ description: "Research the top 3 Rust web frameworks and write a comparison table",
117
+ successCriteria: ["a markdown table comparing 3 frameworks exists"],
118
+ constraints: ["only use information you can verify"],
119
+ },
120
+ { provider: new AnthropicProvider() }, // reads ANTHROPIC_API_KEY
121
+ );
122
+
123
+ console.log(result.status); // "done" | "halted" | "failed"
124
+ console.log(result.ctx.plan.steps);
125
+ ```
126
+
127
+ ```bash
128
+ npm i oh-my-fable # zero runtime dependencies
129
+ ```
130
+
131
+ Node ≥ 18. The `AnthropicProvider` talks to the API over `fetch` — no SDK. Bring
132
+ any model by implementing the `Provider` interface (three methods).
133
+
134
+ ## Tools
135
+
136
+ ```ts
137
+ import { run, defineTool, AnthropicProvider } from "oh-my-fable";
138
+
139
+ const search = defineTool(
140
+ "web_search",
141
+ "Search the web and return results.",
142
+ { type: "object", properties: { query: { type: "string" } }, required: ["query"] },
143
+ async ({ query }) => ({ ok: true, output: await fetchResults(query) }),
144
+ );
145
+
146
+ await run(goal, { provider: new AnthropicProvider(), tools: [search] });
147
+ ```
148
+
149
+ A tool that throws becomes an `Observation`, not a crash — the reflector decides
150
+ what to do about it.
151
+
152
+ ## Watch it work
153
+
154
+ ```ts
155
+ await run(goal, {
156
+ provider,
157
+ onEvent: (e) => console.log(e.type, e),
158
+ // plan_created · step_start · step_done · reflection · replan · compaction · checkpoint · done · halted
159
+ });
160
+ ```
161
+
162
+ ## It can't run away
163
+
164
+ Three hard ceilings, checked at the top of every loop turn, plus two recovery
165
+ caps — exceed any and it halts cleanly, preserving all work:
166
+
167
+ ```ts
168
+ await run(goal, {
169
+ provider,
170
+ maxSteps: 50, // total step budget
171
+ maxTokens: 2_000_000, // cumulative token budget
172
+ maxWallClockMs: 1_800_000,
173
+ maxStepAttempts: 3, // a single step retried this many times → blocked
174
+ maxReplans: 12, // replan storm → halted
175
+ });
176
+ ```
177
+
178
+ ## How it's built
179
+
180
+ A `planner ↔ executor ↔ reflector` loop over a serializable `RunContext`:
181
+
182
+ ```
183
+ plan → [ budget? → next step → compact? → execute → reflect → checkpoint → route ] → done
184
+ ```
185
+
186
+ - **planner** — goal → ordered steps; `replan` accumulates instead of resetting.
187
+ - **executor** — runs one step, including a provider-agnostic tool mini-loop.
188
+ - **reflector** — heuristics first (cheap, certain), then the model, with JSON
189
+ self-repair and a conservative fallback (a wrong early exit is worse than one
190
+ more loop).
191
+ - **contextManager** — folds old turns into digests so long runs stay inside the
192
+ window; the plan is never compacted.
193
+ - **store / budget** — checkpoint after every step; guard against runaways.
194
+
195
+ Every piece is an interface you can replace without touching the core. The full
196
+ architecture writeup is in [`ARCHITECTURE.md`](./ARCHITECTURE.md).
197
+
198
+ ## Roadmap
199
+
200
+ - A web dashboard that tails a run's events and lets you resume from any checkpoint.
201
+ - More providers in-repo (OpenAI-compatible, local) — though it's a 3-method interface.
202
+ - Parallel step execution for independent branches of the plan DAG.
203
+ - Human-in-the-loop: pause for approval as a first-class step status.
204
+
205
+ ## 💖 Sponsor
206
+
207
+ Free, MIT, zero-dependency, built in spare time. If it saved your agent from
208
+ starting over:
209
+
210
+ - ⭐ **Star the repo** — it's how the next person building an agent finds it.
211
+ - 🍋 **[Sponsor via Lemon Squeezy](https://elab-studio.lemonsqueezy.com/checkout/buy/5d059b89-51d0-456b-b33a-ed56994f7010)** — one-time or recurring.
212
+
213
+ ## License
214
+
215
+ [MIT](./LICENSE) © oh-my-fable contributors