counterfactual-forge
Enables AI agents to fork plans into counterfactual worlds, score them with rubrics and simulations, detect contradictions, measure regret, and merge a winner with a full audit trail.
README
Counterfactual Forge
What-if branching for AI agents. Fork a plan into counterfactual worlds, score them with rubrics + simulated outcomes (confidence intervals), detect contradictions, measure regret, and merge a winner — with a full audit trail.
Expose the whole loop as an MCP server so Cursor / Claude / any MCP client can fork → score → merge from tools.
Packages
| Package | Role |
|---|---|
@counterfactual-forge/core |
Deterministic domain model + fork/score/compare/merge/export |
@counterfactual-forge/mcp-server |
Stdio MCP tools (cf_*) |
@counterfactual-forge/cli |
cff / counterfactual-forge CLI |
@counterfactual-forge/studio |
Vite studio to inspect world trees & scores |
Quick start
git clone https://github.com/SanjoyDat1/counterfactual-forge.git
cd counterfactual-forge
npm install
npm run build
npm test
npm run cff -- demo --out /tmp/cff-report.md
Studio UI:
npm run studio
# → http://localhost:5173
MCP (Cursor)
Add to your MCP config (e.g. Cursor mcp.json):
{
"mcpServers": {
"counterfactual-forge": {
"command": "node",
"args": [
"/ABSOLUTE/PATH/TO/counterfactual-forge/packages/mcp-server/dist/index.js"
]
}
}
}
Or after publishing / linking:
{
"mcpServers": {
"counterfactual-forge": {
"command": "npx",
"args": ["-y", "counterfactual-forge-mcp"]
}
}
}
Tools
| Tool | Description |
|---|---|
cf_create_session |
Create session + baseline world from goal + steps |
cf_fork_worlds |
Fork N strategies (aggressive, conservative, parallel, minimal, custom) |
cf_score_world |
Rubric scores + seeded simulation + confidence interval |
cf_compare |
Ranking, regret, contradiction detection |
cf_merge_winner |
Select winner via merge policy |
cf_get_audit_trail |
Append-only audit events |
cf_export_report |
Export json / markdown / mermaid |
Example agent flow
cf_create_sessionwith goal + plan stepscf_fork_worldswithaggressive+conservative(+ optional others)cf_score_worldfor each forked worldcf_compare→ inspect regret & contradictionscf_merge_winnercf_export_report(markdown) for the decision record
CLI
npx cff demo
npx cff create --goal "Ship X" --steps examples/fixtures/auth-redesign-steps.json
npx cff fork --session <id> --strategies aggressive,conservative,minimal
npx cff score --session <id> --world <id>
npx cff compare --session <id>
npx cff merge --session <id> --mode min_regret
npx cff export --session <id> --format mermaid
Sessions are in-memory per process — export / import to persist.
Creative metrics
- Confidence intervals on overall scores (from outcome simulation percentiles)
- Regret — how many points worse than the best alternative
- Contradiction detection across assumptions / risks / strategy tags
- Mermaid world-tree export embedded in Markdown reports
Architecture
See docs/ARCHITECTURE.md and docs/PLAN.md.
Development
npm run typecheck
npm run test:coverage # core ≥80%
npm run build
Logging uses stderr only (CFF_LOG_LEVEL=debug|info|warn|error|silent) — safe for MCP stdio.
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。