reasonix 0.11.0 → 0.11.2
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/README.md +136 -4
- package/README.zh-CN.md +118 -3
- package/dist/cli/{chunk-GXABXQMU.js → chunk-JDVY4JDU.js} +11 -1
- package/dist/cli/chunk-JDVY4JDU.js.map +1 -0
- package/dist/cli/index.js +617 -201
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/{prompt-FMYQ7IDW.js → prompt-YRY4HPMZ.js} +2 -2
- package/dist/index.d.ts +7 -3
- package/dist/index.js +45 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/cli/chunk-GXABXQMU.js.map +0 -1
- /package/dist/cli/{prompt-FMYQ7IDW.js.map → prompt-YRY4HPMZ.js.map} +0 -0
package/README.md
CHANGED
|
@@ -18,9 +18,10 @@
|
|
|
18
18
|
[](https://www.npmjs.com/package/reasonix)
|
|
19
19
|
[](./package.json)
|
|
20
20
|
|
|
21
|
-
**A DeepSeek-native AI coding agent in your terminal.**
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
**A DeepSeek-native AI coding agent in your terminal.** ~30× cheaper
|
|
22
|
+
per task than Claude Code, with a cache-first loop engineered for
|
|
23
|
+
DeepSeek's pricing model. Edits as reviewable SEARCH/REPLACE blocks.
|
|
24
|
+
MIT-licensed. No IDE lock-in. MCP first-class.
|
|
24
25
|
|
|
25
26
|
---
|
|
26
27
|
|
|
@@ -71,6 +72,137 @@ command list.
|
|
|
71
72
|
|
|
72
73
|
---
|
|
73
74
|
|
|
75
|
+
## Why Reasonix? (vs Cursor / Claude Code / Cline / Aider)
|
|
76
|
+
|
|
77
|
+
Three things you'd come to Reasonix for, that nothing else combines:
|
|
78
|
+
|
|
79
|
+
- **The cost economics actually land in your bill.** DeepSeek V4 is
|
|
80
|
+
~30× cheaper than Claude Sonnet per token. Cheaper tokens alone
|
|
81
|
+
isn't the win — *cheap tokens with a 90%+ prefix-cache hit* is.
|
|
82
|
+
Reasonix's loop is engineered around append-only prompt growth so
|
|
83
|
+
the cache-stable prefix survives every tool call, which the
|
|
84
|
+
benchmarks section below verifies end-to-end (94.4% live, vs 46.6%
|
|
85
|
+
for a generic harness against the same workload). The `/stats`
|
|
86
|
+
panel tracks "vs Claude Sonnet 4.6" savings every turn so you can
|
|
87
|
+
watch your bill not happen.
|
|
88
|
+
|
|
89
|
+
- **It lives in your terminal.** Pure CLI — no Electron, no VS Code
|
|
90
|
+
extension, no IDE plugin to wedge into your editor. Sits next to
|
|
91
|
+
git, tmux, and your shell history. macOS / Linux / Windows
|
|
92
|
+
(PowerShell, Git Bash, Windows Terminal all tested). The only
|
|
93
|
+
network call is to the DeepSeek API itself; no vendor server in
|
|
94
|
+
the middle.
|
|
95
|
+
|
|
96
|
+
- **Open source and hackable, end to end.** MIT-licensed TypeScript.
|
|
97
|
+
The entire loop, tool registry, cache-stable prefix, TUI, MCP
|
|
98
|
+
bridge — all in `src/` under 30k lines. Fork it, ship a private
|
|
99
|
+
build, drop it into CI. No SaaS layer, no enterprise tier, no
|
|
100
|
+
feature gates.
|
|
101
|
+
|
|
102
|
+
| | Reasonix | Claude Code | Cursor | Cline | Aider |
|
|
103
|
+
|---|---|---|---|---|---|
|
|
104
|
+
| Backend | DeepSeek V4 only | Anthropic only | OpenAI / Anthropic | any (OpenRouter) | any (OpenRouter) |
|
|
105
|
+
| Cost / typical task | **~$0.001–$0.005** | ~$0.05–$0.50 | $20/mo + usage | varies | varies |
|
|
106
|
+
| Where it runs | terminal | terminal + IDE | IDE (Electron) | VS Code only | terminal |
|
|
107
|
+
| License | **MIT** | closed | closed | Apache 2 | Apache 2 |
|
|
108
|
+
| Cache-first prefix loop | **engineered (94% hit)** | basic | n/a | n/a | basic |
|
|
109
|
+
| MCP servers | **first-class** | first-class | — | beta | — |
|
|
110
|
+
| Plan mode (read-only audit gate) | **yes** | yes | — | yes | — |
|
|
111
|
+
| User-authored skills | **yes** | yes | — | — | — |
|
|
112
|
+
| Edit review (no auto-write) | **yes** (`/apply`) | yes | partial | yes | yes |
|
|
113
|
+
| Workspace switch (`/cwd`, `change_workspace`) | **yes** | — | n/a (per-window) | — | — |
|
|
114
|
+
| Cross-session cost dashboard | **yes** (`/stats`) | — | — | — | — |
|
|
115
|
+
| Sandbox boundary enforcement | **strict** (refuses `..` escape) | yes | partial | yes | partial |
|
|
116
|
+
|
|
117
|
+
### Pick something else when
|
|
118
|
+
|
|
119
|
+
- **You want multi-provider flexibility** (mix Claude / GPT / Gemini /
|
|
120
|
+
local Llama in one tool). Try [Aider](https://aider.chat) or
|
|
121
|
+
[Cline](https://cline.bot). Reasonix is DeepSeek-only on purpose —
|
|
122
|
+
every layer (cache-first loop, R1 harvesting, JSON-mode tool repair,
|
|
123
|
+
reasoning-effort cap) is tuned against DeepSeek-specific behavior
|
|
124
|
+
and economics. Coupling to one backend is the feature, not a
|
|
125
|
+
limitation we'll grow out of.
|
|
126
|
+
- **You want IDE integration** (inline diff in your gutter,
|
|
127
|
+
multi-cursor, ghost text, refactor previews). Try
|
|
128
|
+
[Cursor](https://cursor.com) or Claude Code's IDE mode. Reasonix
|
|
129
|
+
is terminal-first; the diff lives in `git diff`, the file tree
|
|
130
|
+
lives in `ls`, the chat lives in your shell.
|
|
131
|
+
- **You're chasing the hardest reasoning benchmarks.** Claude Opus
|
|
132
|
+
4.6 still wins some leaderboards. DeepSeek V4-pro is competitive
|
|
133
|
+
on most coding tasks but doesn't lead every benchmark. If your
|
|
134
|
+
task is "solve this PhD-level proof" rather than "fix this auth
|
|
135
|
+
bug," start with Claude.
|
|
136
|
+
- **You need fully-local / fully-free**. DeepSeek's API has free
|
|
137
|
+
credit on signup, but isn't free forever. For air-gapped or
|
|
138
|
+
always-free, look at Aider + Ollama or [Continue](https://continue.dev).
|
|
139
|
+
|
|
140
|
+
### "But DeepSeek now has an Anthropic-compatible API — can't I just point Claude Code at it?"
|
|
141
|
+
|
|
142
|
+
You can. DeepSeek ships an official Anthropic-compatible endpoint at
|
|
143
|
+
`https://api.deepseek.com/anthropic`, and Claude Code (or any Anthropic
|
|
144
|
+
SDK client) talks to it without modification. The protocol works. The
|
|
145
|
+
**caching economics** don't transfer, and that's the whole point.
|
|
146
|
+
|
|
147
|
+
Look at DeepSeek's [own compatibility table](https://api-docs.deepseek.com/guides/anthropic_api):
|
|
148
|
+
|
|
149
|
+
| Field | Status on DeepSeek's compat endpoint |
|
|
150
|
+
|---|---|
|
|
151
|
+
| `cache_control` markers | **Ignored** |
|
|
152
|
+
| `mcp_servers` (API-level) | Ignored |
|
|
153
|
+
| `thinking.budget_tokens` | Ignored |
|
|
154
|
+
| Images / documents / citations | Not supported |
|
|
155
|
+
|
|
156
|
+
`cache_control: Ignored` is the load-bearing line. Two completely
|
|
157
|
+
different cache mechanics are colliding here:
|
|
158
|
+
|
|
159
|
+
| | Anthropic native | DeepSeek auto-cache |
|
|
160
|
+
|---|---|---|
|
|
161
|
+
| Model | **Marker-based.** You put `cache_control` on a message; Anthropic caches "everything up to this marker" as a content-addressed unit. Multiple markers = multiple independent breakpoints. | **Byte-stable prefix.** The cache fingerprints the literal byte stream from byte 0. |
|
|
162
|
+
| Claude Code's design | Built around this. Markers on system prompt + tool defs let the loop reorder, compact, or insert metadata after the markers without losing the cache. | n/a — Claude Code wasn't designed for byte-stable prefixes. |
|
|
163
|
+
| What happens when Claude Code → DeepSeek compat | Markers stripped (ignored). Claude Code's main caching strategy disappears. | Falls back to auto-cache. But Claude Code's prefix isn't byte-stable (markers were the *substitute* for byte-stability), so auto-cache misses too. |
|
|
164
|
+
|
|
165
|
+
Net effect: **Claude Code's loop, redirected at DeepSeek, gets the
|
|
166
|
+
cheap tokens and loses the cache hit it depended on.** A loop running
|
|
167
|
+
at 80%+ cache hit on Anthropic's marker cache lands somewhere in the
|
|
168
|
+
40-60% range on DeepSeek's auto-cache (matches the generic-harness
|
|
169
|
+
baseline in our benchmarks). Same model, same API, same workload —
|
|
170
|
+
the loop's invariants don't fit the cache mechanic it's now talking
|
|
171
|
+
to.
|
|
172
|
+
|
|
173
|
+
Reasonix's loop was designed around byte-stable prefix from line one.
|
|
174
|
+
No markers, no breakpoints — append-only is the invariant. That's why
|
|
175
|
+
the same τ-bench workload lands at **94.4% cache hit** on Reasonix
|
|
176
|
+
and **46.6%** on a cache-hostile baseline (committed transcripts;
|
|
177
|
+
benchmarks section below). At DeepSeek's pricing — $0.07/Mtok
|
|
178
|
+
uncached, ~$0.014/Mtok cached — the difference between 50% and 94%
|
|
179
|
+
hit is **roughly 2.5× on input cost alone**.
|
|
180
|
+
|
|
181
|
+
### "What about Aider / Cline / Continue?"
|
|
182
|
+
|
|
183
|
+
They support DeepSeek natively (no compat layer needed) and you do
|
|
184
|
+
get the cheap token price. What you don't get is the DeepSeek-
|
|
185
|
+
specific loop work — those tools' loops support every backend
|
|
186
|
+
generically (OpenAI / Anthropic / local Llama / ...) and use
|
|
187
|
+
compaction + summarization patterns that destroy byte-stability. They
|
|
188
|
+
land in the same 40-60% cache-hit range as the baseline. Plus a
|
|
189
|
+
handful of DeepSeek-specific quirks generic loops don't handle:
|
|
190
|
+
|
|
191
|
+
| Generic loops assume | DeepSeek actually does | Reasonix's fix |
|
|
192
|
+
|---|---|---|
|
|
193
|
+
| Reasoning emitted as a structured `thinking` block | R1 sometimes leaks tool-call JSON inside `<think>` tags | a `scavenge` pass that pulls escaped tool calls back out, otherwise the model thinks it called and waits for output that never comes |
|
|
194
|
+
| Tool schemas validated strictly | DeepSeek silently drops deeply-nested object/array params | auto-flatten — nested params get rewritten to single-level prefixed names so the model sees them at all |
|
|
195
|
+
| Tool-call args are well-formed JSON | DeepSeek occasionally produces `string="false"` and other malformed fragments | dedicated `ToolCallRepair` heals the common shapes before they hit dispatch |
|
|
196
|
+
| Reasoning depth tuned via system-level switches | V4 exposes a `reasoning_effort` knob (`max` / `high`) | `/effort` slash + `--effort` flag, so users can step down for cheap turns |
|
|
197
|
+
| Old tool results kept in full forever | 1M context — don't compact pre-emptively, but most agents do | call-storm breaker + result token cap, but the prefix is *never* rewritten; compaction lands as new turns at the tail |
|
|
198
|
+
|
|
199
|
+
> Cache-stability isn't a feature you turn on; it's an invariant
|
|
200
|
+
> the loop is designed around. Reasonix isn't yet-another agent
|
|
201
|
+
> CLI — it's an agent CLI built around DeepSeek's specific cache
|
|
202
|
+
> mechanic and pricing model.
|
|
203
|
+
|
|
204
|
+
---
|
|
205
|
+
|
|
74
206
|
## `reasonix code` — pair programmer in your terminal
|
|
75
207
|
|
|
76
208
|
Scoped to the directory you launch from. The model has native
|
|
@@ -771,7 +903,7 @@ cd reasonix
|
|
|
771
903
|
npm install
|
|
772
904
|
npm run dev code # run CLI from source via tsx
|
|
773
905
|
npm run build # tsup to dist/
|
|
774
|
-
npm test # vitest (
|
|
906
|
+
npm test # vitest (1482 tests)
|
|
775
907
|
npm run lint # biome
|
|
776
908
|
npm run typecheck # tsc --noEmit
|
|
777
909
|
```
|
package/README.zh-CN.md
CHANGED
|
@@ -18,8 +18,9 @@
|
|
|
18
18
|
[](https://www.npmjs.com/package/reasonix)
|
|
19
19
|
[](./package.json)
|
|
20
20
|
|
|
21
|
-
**DeepSeek 原生的终端 AI 编程代理。**
|
|
22
|
-
|
|
21
|
+
**DeepSeek 原生的终端 AI 编程代理。** 单次任务成本约为 Claude Code 的
|
|
22
|
+
1/30,缓存优先的循环是为 DeepSeek 的定价模型量身打造的。编辑以可审查的
|
|
23
|
+
SEARCH/REPLACE 块呈现,落盘前必须确认。MIT 许可、不绑 IDE、原生 MCP。
|
|
23
24
|
|
|
24
25
|
---
|
|
25
26
|
|
|
@@ -68,6 +69,120 @@ Windows Terminal)。任何时候按 `Esc` 中断;`/help` 查看完整命令
|
|
|
68
69
|
|
|
69
70
|
---
|
|
70
71
|
|
|
72
|
+
## 为什么选 Reasonix?(vs Cursor / Claude Code / Cline / Aider)
|
|
73
|
+
|
|
74
|
+
三件事,别家不会同时都给你:
|
|
75
|
+
|
|
76
|
+
- **成本节省落到账单上。** DeepSeek V4 的 token 单价大约是 Claude Sonnet
|
|
77
|
+
的 1/30。光便宜还不够 —— *便宜的 token 配上 90%+ 的前缀缓存命中*才是关键。
|
|
78
|
+
Reasonix 的循环按 append-only 增长设计,缓存稳定的前缀在每次工具调用之间
|
|
79
|
+
都活着,下面的 benchmark 章节端到端验证过:实测 94.4% 缓存命中,对照组通用
|
|
80
|
+
框架只有 46.6%。`/stats` 面板每轮都跟踪 "vs Claude Sonnet 4.6" 的节省额,
|
|
81
|
+
你可以亲眼看着账单不涨。
|
|
82
|
+
|
|
83
|
+
- **它住在终端里。** 纯 CLI —— 没有 Electron,没有 VS Code 插件,没有要
|
|
84
|
+
塞进编辑器的 IDE 插件。和 git、tmux、shell 历史并排。macOS / Linux /
|
|
85
|
+
Windows(PowerShell、Git Bash、Windows Terminal 都测过)。唯一的网络
|
|
86
|
+
请求就是 DeepSeek API 本身,中间没有厂商服务器。
|
|
87
|
+
|
|
88
|
+
- **开源且彻底可改。** MIT 许可的 TypeScript。整个循环、工具注册表、
|
|
89
|
+
缓存稳定前缀、TUI、MCP 桥接 —— 全部在 `src/` 下,不到 3 万行。Fork
|
|
90
|
+
它、做私有构建、塞进 CI 都可以。没有 SaaS 层,没有企业版,没有功能闸门。
|
|
91
|
+
|
|
92
|
+
| | Reasonix | Claude Code | Cursor | Cline | Aider |
|
|
93
|
+
|---|---|---|---|---|---|
|
|
94
|
+
| 后端 | 仅 DeepSeek V4 | 仅 Anthropic | OpenAI / Anthropic | 任意(OpenRouter)| 任意(OpenRouter)|
|
|
95
|
+
| 单次任务成本 | **~$0.001–$0.005** | ~$0.05–$0.50 | $20/月 + 用量 | 视情况 | 视情况 |
|
|
96
|
+
| 运行环境 | 终端 | 终端 + IDE | IDE(Electron)| 仅 VS Code | 终端 |
|
|
97
|
+
| 开源协议 | **MIT** | 闭源 | 闭源 | Apache 2 | Apache 2 |
|
|
98
|
+
| 缓存优先前缀循环 | **工程化(94% 命中)** | 基础 | n/a | n/a | 基础 |
|
|
99
|
+
| MCP 服务器 | **原生支持** | 原生支持 | — | 测试中 | — |
|
|
100
|
+
| 计划模式(只读审计闸门)| **支持** | 支持 | — | 支持 | — |
|
|
101
|
+
| 用户编写的 skills | **支持** | 支持 | — | — | — |
|
|
102
|
+
| 编辑审阅(不自动落盘)| **支持**(`/apply`)| 支持 | 部分 | 支持 | 支持 |
|
|
103
|
+
| 工作区切换(`/cwd`、`change_workspace`)| **支持** | — | n/a(每窗一项目)| — | — |
|
|
104
|
+
| 跨会话成本面板 | **支持**(`/stats`)| — | — | — | — |
|
|
105
|
+
| 沙箱边界强制 | **严格**(拒绝 `..` 逃逸)| 支持 | 部分 | 支持 | 部分 |
|
|
106
|
+
|
|
107
|
+
### 这些情况下应该选别的
|
|
108
|
+
|
|
109
|
+
- **你想要多模型混用**(在一个工具里同时切 Claude / GPT / Gemini / 本地 Llama)。
|
|
110
|
+
试试 [Aider](https://aider.chat) 或 [Cline](https://cline.bot)。Reasonix
|
|
111
|
+
故意只绑 DeepSeek —— 每一层(缓存优先循环、R1 harvest、JSON 模式的工具
|
|
112
|
+
调用修复、reasoning_effort 上限)都是为 DeepSeek 的具体行为和经济模型
|
|
113
|
+
调出来的。绑死后端是设计选择,不是早晚要解决的限制。
|
|
114
|
+
- **你想要 IDE 集成**(编辑器侧边栏 inline diff、多光标、ghost text、重构
|
|
115
|
+
预览)。试试 [Cursor](https://cursor.com) 或 Claude Code 的 IDE 模式。
|
|
116
|
+
Reasonix 是终端优先的:diff 在 `git diff` 里、文件树在 `ls` 里、对话
|
|
117
|
+
在 shell 里。
|
|
118
|
+
- **你在追最难的推理 benchmark**。Claude Opus 4.6 还是赢一些榜单的。
|
|
119
|
+
DeepSeek V4-pro 在大多数编程任务上都很有竞争力,但不是每个 benchmark
|
|
120
|
+
都领先。如果你的任务是"证明这个 PhD 级别的数学命题"而不是"修这个
|
|
121
|
+
auth bug",从 Claude 起步更合适。
|
|
122
|
+
- **你需要完全本地 / 永远免费**。DeepSeek API 注册送额度,但不是永久
|
|
123
|
+
免费。要真正离线/永久免费,看看 Aider + Ollama 或者
|
|
124
|
+
[Continue](https://continue.dev)。
|
|
125
|
+
|
|
126
|
+
### "DeepSeek 现在有 Anthropic 兼容 API 了,我直接拿 Claude Code 接上不就行?"
|
|
127
|
+
|
|
128
|
+
可以接。DeepSeek 官方提供了 Anthropic 兼容端点
|
|
129
|
+
`https://api.deepseek.com/anthropic`,Claude Code(或任何 Anthropic SDK
|
|
130
|
+
客户端)不改一行代码就能连上去。**协议跑得通,缓存经济学跑不通** ——
|
|
131
|
+
而后者才是关键。
|
|
132
|
+
|
|
133
|
+
看 [DeepSeek 自己的兼容性表](https://api-docs.deepseek.com/guides/anthropic_api):
|
|
134
|
+
|
|
135
|
+
| 字段 | 在 DeepSeek 兼容端点上的状态 |
|
|
136
|
+
|---|---|
|
|
137
|
+
| `cache_control` 标记 | **Ignored(被忽略)** |
|
|
138
|
+
| `mcp_servers`(API 层)| Ignored |
|
|
139
|
+
| `thinking.budget_tokens` | Ignored |
|
|
140
|
+
| 图像 / 文档 / 引用 | 不支持 |
|
|
141
|
+
|
|
142
|
+
`cache_control: Ignored` 就是杀手级的那一行。这里有**两套完全不同的缓存
|
|
143
|
+
机制在打架**:
|
|
144
|
+
|
|
145
|
+
| | Anthropic 原生 | DeepSeek 自动缓存 |
|
|
146
|
+
|---|---|---|
|
|
147
|
+
| 模型 | **Marker 驱动。** 你在某条消息上打 `cache_control`,Anthropic 把"到此 marker 为止"的内容做内容寻址缓存。多个 marker = 多个独立断点。 | **Byte-stable prefix。** 缓存对字面字节流从第 0 字节起做指纹。 |
|
|
148
|
+
| Claude Code 的设计 | 围绕这个设计的。在 system prompt + tool 定义上插 marker,让 loop 在 marker 之后做重排、压缩、插元数据都不丢缓存。 | n/a —— Claude Code 不是为 byte-stable prefix 设计的。 |
|
|
149
|
+
| Claude Code 接 DeepSeek 兼容端点之后 | Marker 被 strip(忽略)。Claude Code 的主缓存策略消失。 | Fallback 到 auto-cache。但 Claude Code 的 prefix 不是 byte-stable 的(marker 本来就是 byte-stability 的*替代*),auto-cache 也命中不了。 |
|
|
150
|
+
|
|
151
|
+
净效果:**Claude Code 的 loop 重定向到 DeepSeek 之后,便宜 token 拿到了,
|
|
152
|
+
原本依赖的缓存命中没了**。一个在 Anthropic marker cache 上 80%+ 命中的
|
|
153
|
+
loop,到 DeepSeek 的 auto-cache 上大概率掉到 40-60%(跟我们 benchmark 里
|
|
154
|
+
通用 harness 的 baseline 同区间)。同一个模型、同一个 API、同一个负载 ——
|
|
155
|
+
loop 的 invariant 跟它现在对话的缓存机制不匹配。
|
|
156
|
+
|
|
157
|
+
Reasonix 的 loop 从第一行起就是按 byte-stable prefix 的不变量设计的。没有
|
|
158
|
+
marker、没有断点 —— append-only 就是 invariant。这就是为什么同一份 τ-bench
|
|
159
|
+
负载在 Reasonix 上是 **94.4% 缓存命中**、在 cache-hostile baseline 上是
|
|
160
|
+
**46.6%**(已 commit 的 transcript,见下面 benchmark 段)。按 DeepSeek 的
|
|
161
|
+
单价 —— $0.07/Mtok 非缓存、约 $0.014/Mtok 缓存命中 —— 50% 和 94% 命中之间
|
|
162
|
+
**仅 input 这一侧就大约是 2.5× 的差距**。
|
|
163
|
+
|
|
164
|
+
### "那 Aider / Cline / Continue 呢?"
|
|
165
|
+
|
|
166
|
+
它们原生支持 DeepSeek(不需要兼容层),便宜 token 单价你确实拿到了。
|
|
167
|
+
但你拿不到 DeepSeek-specific 的循环工程 —— 这些工具的 loop 是为**通用支持**
|
|
168
|
+
所有后端(OpenAI / Anthropic / 本地 Llama / ...)设计的,用的是那种会破坏
|
|
169
|
+
byte-stability 的通用压缩 / 摘要模式。命中率落在和 baseline 同样的 40-60%
|
|
170
|
+
区间。再加上一堆 DeepSeek 怪癖通用 loop 不处理:
|
|
171
|
+
|
|
172
|
+
| 通用 loop 假定 | DeepSeek 实际行为 | Reasonix 怎么处理 |
|
|
173
|
+
|---|---|---|
|
|
174
|
+
| 推理通过结构化 `thinking` 块产出 | R1 偶尔把 tool-call JSON 漏到 `<think>` 标签里 | `scavenge` 扫描把漏出的 tool call 拣回,否则模型以为自己已经调用,等不到结果 |
|
|
175
|
+
| tool schema 严格校验 | DeepSeek 静默丢弃深嵌套 object/array 参数 | auto-flatten:嵌套参数被重写成单层 prefixed name,模型才看得见 |
|
|
176
|
+
| tool-call args 是良构 JSON | DeepSeek 偶发 `string="false"` 之类的破碎片段 | 专用 `ToolCallRepair` 在 dispatch 之前修好常见形状 |
|
|
177
|
+
| 推理深度靠系统级开关 | V4 直接暴露 `reasoning_effort` 旋钮(`max` / `high`) | `/effort` slash + `--effort` flag,简单任务可以降到 high 省钱 |
|
|
178
|
+
| 老 tool result 永久保留 | 1M context 不需要主动 compact,但通用工具都会做 | call-storm breaker + 结果 token cap,但前缀**永不重写** —— 压缩作为新 turn 追加在尾部 |
|
|
179
|
+
|
|
180
|
+
> 缓存稳定性不是一个开关,是 loop 设计之初就要建立的不变量。Reasonix
|
|
181
|
+
> 不是"又一个 agent CLI",是**围绕 DeepSeek 具体的缓存机制和定价模型
|
|
182
|
+
> 设计的 agent CLI**。
|
|
183
|
+
|
|
184
|
+
---
|
|
185
|
+
|
|
71
186
|
## `reasonix code` — 终端里的结对编程
|
|
72
187
|
|
|
73
188
|
作用域为启动目录。模型自带 `read_file` / `write_file` / `edit_file` /
|
|
@@ -709,7 +824,7 @@ cd reasonix
|
|
|
709
824
|
npm install
|
|
710
825
|
npm run dev code # 用 tsx 直接从源码跑 CLI
|
|
711
826
|
npm run build # tsup 打包到 dist/
|
|
712
|
-
npm test # vitest(
|
|
827
|
+
npm test # vitest(1482 个测试)
|
|
713
828
|
npm run lint # biome
|
|
714
829
|
npm run typecheck # tsc --noEmit
|
|
715
830
|
```
|
|
@@ -891,6 +891,16 @@ Two different rules depending on which tool:
|
|
|
891
891
|
- **Filesystem tools** (\`read_file\`, \`list_directory\`, \`search_files\`, \`edit_file\`, etc.): paths are sandbox-relative. \`/\` means the project root, \`/src/foo.ts\` means \`<project>/src/foo.ts\`. Both relative (\`src/foo.ts\`) and POSIX-absolute (\`/src/foo.ts\`) forms work.
|
|
892
892
|
- **\`run_command\`**: the command runs in a real OS shell with cwd pinned to the project root. Paths inside the shell command are interpreted by THAT shell, not by us. **Never use leading \`/\` in run_command arguments** \u2014 Windows treats \`/tests\` as drive-root \`F:\\tests\` (non-existent), POSIX shells treat it as filesystem root. Use plain relative paths (\`tests\`, \`./tests\`, \`src/loop.ts\`) instead.
|
|
893
893
|
|
|
894
|
+
# When the user wants to switch project / working directory
|
|
895
|
+
|
|
896
|
+
If the user asks to switch / change / open a different directory or project ("\u5207\u6362\u5230...", "switch to ...", "let's work in ...", "open the X project"), call **\`change_workspace\`** with the absolute target path. The tool always requires the user's explicit approval via a TUI modal \u2014 your call surfaces a "switch / deny" prompt, and STOPS your turn until they pick. After approval the filesystem / shell / memory tools re-register against the new root and your subsequent calls land there.
|
|
897
|
+
|
|
898
|
+
Hard rules:
|
|
899
|
+
- Do NOT try to switch via \`run_command\` (\`cd\`, \`pushd\`, etc.) \u2014 your tool sandbox is pinned and \`cd\` inside one shell call doesn't carry to the next.
|
|
900
|
+
- Do NOT chain other tool calls in the same turn as \`change_workspace\` \u2014 wait for the user's confirmation. Their next message will tell you whether the switch happened.
|
|
901
|
+
- Do NOT call \`change_workspace\` to "preview" a sibling directory; only when the user explicitly asked to change projects.
|
|
902
|
+
- The user can also type \`/cwd <path>\` themselves \u2014 fine, you'll see the new root take effect on the next turn either way.
|
|
903
|
+
|
|
894
904
|
# Foreground vs. background commands
|
|
895
905
|
|
|
896
906
|
You have TWO tools for running shell commands, and picking the right one is non-negotiable:
|
|
@@ -985,4 +995,4 @@ export {
|
|
|
985
995
|
CODE_SYSTEM_PROMPT,
|
|
986
996
|
codeSystemPrompt
|
|
987
997
|
};
|
|
988
|
-
//# sourceMappingURL=chunk-
|
|
998
|
+
//# sourceMappingURL=chunk-JDVY4JDU.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/code/prompt.ts","../../src/prompt-fragments.ts","../../src/user-memory.ts","../../src/project-memory.ts","../../src/skills.ts"],"sourcesContent":["/**\n * System prompt used by `reasonix code`. Teaches the model:\n *\n * 1. It has a filesystem MCP bridge rooted at the user's CWD.\n * 2. To modify files it emits SEARCH/REPLACE blocks (not\n * `write_file` — that would whole-file rewrite and kill diff\n * reviewability).\n * 3. Read first, edit second — SEARCH must match byte-for-byte.\n * 4. Be concise. The user can read a diff faster than prose.\n *\n * Kept short on purpose. Long system prompts eat context budget that\n * the Cache-First Loop is trying to conserve. The SEARCH/REPLACE spec\n * is the one unavoidable bloat; we trim everything else.\n */\n\nimport { existsSync, readFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { ESCALATION_CONTRACT, TUI_FORMATTING_RULES } from \"../prompt-fragments.js\";\nimport { applyMemoryStack } from \"../user-memory.js\";\n\nexport const CODE_SYSTEM_PROMPT = `You are Reasonix Code, a coding assistant. You have filesystem tools (read_file, write_file, edit_file, list_directory, directory_tree, search_files, search_content, get_file_info) rooted at the user's working directory, plus run_command / run_background for shell.\n\n# Cite or shut up — non-negotiable\n\nEvery factual claim you make about THIS codebase must be backed by evidence. Reasonix VALIDATES the citations you write — broken paths or out-of-range lines render in **red strikethrough with ❌** in front of the user.\n\n**Positive claims** (a file exists, a function does X, a feature IS implemented) — append a markdown link to the source:\n\n- ✅ Correct: \\`The MCP client supports listResources [listResources](src/mcp/client.ts:142).\\`\n- ❌ Wrong: \\`The MCP client supports listResources.\\` ← no citation, looks authoritative but unverifiable.\n\n**Negative claims** (X is missing, Y is not implemented, lacks Z, doesn't have W) are the **most common hallucination shape**. They feel safe to write because no citation seems possible — but that's exactly why you must NOT write them on instinct.\n\nIf you are about to write \"X is missing\" or \"Y is not implemented\" — **STOP**. Call \\`search_content\\` for the relevant symbol or term FIRST. Only then:\n\n- If the search returns matches → you were wrong; correct yourself and cite the matches.\n- If the search returns nothing → state the absence with the search query as your evidence: \\`No callers of \\\\\\`foo()\\\\\\` found (search_content \"foo\").\\`\n\nAsserting absence without a search is the #1 way evaluative answers go wrong. Treat the urge to write \"missing\" as a red flag in your own reasoning.\n\n# When to propose a plan (submit_plan)\n\nYou have a \\`submit_plan\\` tool that shows the user a markdown plan and lets them Approve / Refine / Cancel before you execute. Use it proactively when the task is large enough to deserve a review gate:\n\n- Multi-file refactors or renames.\n- Architecture changes (moving modules, splitting / merging files, new abstractions).\n- Anything where \"undo\" after the fact would be expensive — migrations, destructive cleanups, API shape changes.\n- When the user's request is ambiguous and multiple reasonable interpretations exist — propose your reading as a plan and let them confirm.\n\nSkip submit_plan for small, obvious changes: one-line typo, clear bug with a clear fix, adding a missing import, renaming a local variable. Just do those.\n\nPlan body: one-sentence summary, then a file-by-file breakdown of what you'll change and why, and any risks or open questions. If some decisions are genuinely up to the user (naming, tradeoffs, out-of-scope possibilities), list them in an \"Open questions\" section — the user sees the plan in a picker and has a text input to answer your questions before approving. Don't pretend certainty you don't have; flagged questions are how the user tells you what they care about. After calling submit_plan, STOP — don't call any more tools, wait for the user's verdict.\n\n**Do NOT use submit_plan to present A/B/C route menus.** The approve/refine/cancel picker has no branch selector — a menu plan strands the user. For branching decisions, use \\`ask_choice\\` (see below); only call submit_plan once the user has picked a direction and you have ONE actionable plan.\n\n# When to ask the user to pick (ask_choice)\n\nYou have an \\`ask_choice\\` tool. **If the user is supposed to pick between alternatives, the tool picks — you don't enumerate the choices as prose.** Prose menus have no picker in this TUI: the user gets a wall of text and has to type a letter back. The tool fires an arrow-key picker that's strictly better.\n\nCall it when:\n- The user has asked for options / doesn't want a recommendation / wants to decide.\n- You've analyzed multiple approaches and the final call is theirs.\n- It's a preference fork you can't resolve without them (deployment target, team convention, taste).\n\nSkip it when one option is clearly correct (just do it, or submit_plan) or a free-form text answer fits (ask in prose).\n\nEach option: short stable id (A/B/C), one-line title, optional summary. \\`allowCustom: true\\` when their real answer might not fit. Max 6. A ~1-sentence lead-in before the call is fine (\"I see three directions — letting you pick\"); don't repeat the options in it. After the call, STOP.\n\n# Plan mode (/plan)\n\nThe user can ALSO enter \"plan mode\" via /plan, which is a stronger, explicit constraint:\n- Write tools (edit_file, write_file, create_directory, move_file) and non-allowlisted run_command calls are BOUNCED at dispatch — you'll get a tool result like \"unavailable in plan mode\". Don't retry them.\n- Read tools (read_file, list_directory, search_files, directory_tree, get_file_info) and allowlisted read-only / test shell commands still work — use them to investigate.\n- You MUST call submit_plan before anything will execute. Approve exits plan mode; Refine stays in; Cancel exits without implementing.\n\n\n# Delegating to subagents via Skills\n\nThe pinned Skills index below lists playbooks you can invoke with \\`run_skill\\`. Entries tagged \\`[🧬 subagent]\\` spawn an **isolated subagent** — a fresh child loop that runs the playbook in its own context and returns only the final answer. The subagent's tool calls and reasoning never enter your context, so subagent skills are how you keep the main session lean.\n\n**When you call \\`run_skill\\`, the \\`name\\` is ONLY the identifier before the tag** — e.g. \\`run_skill({ name: \"explore\", arguments: \"...\" })\\`, NOT \\`\"[🧬 subagent] explore\"\\` and NOT \\`\"explore [🧬 subagent]\"\\`. The tag is display sugar; the name argument is just the bare identifier.\n\nTwo built-ins ship by default:\n- **explore** \\`[🧬 subagent]\\` — read-only investigation across the codebase. Use when the user says things like \"find all places that...\", \"how does X work across the project\", \"survey the code for Y\". Pass \\`arguments\\` describing the concrete question.\n- **research** \\`[🧬 subagent]\\` — combines web search + code reading. Use for \"is X supported by lib Y\", \"what's the canonical way to Z\", \"compare our impl to the spec\".\n\nWhen to delegate (call \\`run_skill\\` with a subagent skill):\n- The task would otherwise need >5 file reads or searches.\n- You only need the conclusion, not the exploration trail.\n- The work is self-contained (you can describe it in one paragraph).\n\nWhen NOT to delegate:\n- Direct, narrow questions answerable in 1-2 tool calls — just do them.\n- Anything where you need to track intermediate results yourself (planning, multi-step edits).\n- Anything that requires user interaction (subagents can't submit plans or ask you for clarification).\n\nAlways pass a clear, self-contained \\`arguments\\` — that text is the **only** context the subagent gets.\n\n# When to edit vs. when to explore\n\nOnly propose edits when the user explicitly asks you to change, fix, add, remove, refactor, or write something. Do NOT propose edits when the user asks you to:\n- analyze, read, explore, describe, or summarize a project\n- explain how something works\n- answer a question about the code\n\nIn those cases, use tools to gather what you need, then reply in prose. No SEARCH/REPLACE blocks, no file changes. If you're unsure what the user wants, ask.\n\nWhen you do propose edits, the user will review them and decide whether to \\`/apply\\` or \\`/discard\\`. Don't assume they'll accept — write as if each edit will be audited, because it will.\n\nReasonix runs an **edit gate**. The user's current mode (\\`review\\` or \\`auto\\`) decides what happens to your writes; you DO NOT see which mode is active, and you SHOULD NOT ask. Write the same way in both cases.\n\n- In \\`auto\\` mode \\`edit_file\\` / \\`write_file\\` calls land on disk immediately with an undo window — you'll get the normal \"edit blocks: 1/1 applied\" style response.\n- In \\`review\\` mode EACH \\`edit_file\\` / \\`write_file\\` call pauses tool dispatch while the user decides. You'll get one of these responses:\n - \\`\"edit blocks: 1/1 applied\"\\` — user approved it. Continue as normal.\n - \\`\"User rejected this edit to <path>. Don't retry the same SEARCH/REPLACE…\"\\` — user said no to THIS specific edit. Do NOT re-emit the same block, do NOT switch tools to sneak it past the gate (write_file → edit_file, or text-form SEARCH/REPLACE). Either take a clearly different approach or stop and ask the user what they want instead.\n - Text-form SEARCH/REPLACE blocks in your assistant reply queue for end-of-turn /apply — same \"don't retry on rejection\" rule.\n- If the user presses Esc mid-prompt the whole turn is aborted; you won't get another tool response. Don't keep spamming tool calls after an abort.\n\n# Editing files\n\nWhen you've been asked to change a file, output one or more SEARCH/REPLACE blocks in this exact format:\n\npath/to/file.ext\n<<<<<<< SEARCH\nexact existing lines from the file, including whitespace\n=======\nthe new lines\n>>>>>>> REPLACE\n\nRules:\n- Always read_file first so your SEARCH matches byte-for-byte. If it doesn't match, the edit is rejected and you'll have to retry with the exact current content.\n- One edit per block. Multiple blocks in one response are fine.\n- To create a new file, leave SEARCH empty:\n path/to/new.ts\n <<<<<<< SEARCH\n =======\n (whole file content here)\n >>>>>>> REPLACE\n- Do NOT use write_file to change existing files — the user reviews your edits as SEARCH/REPLACE. write_file is only for files you explicitly want to overwrite wholesale (rare).\n- Paths are relative to the working directory. Don't use absolute paths.\n\n# Trust what you already know\n\nBefore exploring the filesystem to answer a factual question, check whether the answer is already in context: the user's current message, earlier turns in this conversation (including prior tool results from \\`remember\\`), and the pinned memory blocks at the top of this prompt. When the user has stated a fact or you have remembered one, it outranks what the files say — don't re-derive from code what the user already told you. Explore when you genuinely don't know.\n\n# Exploration\n\n- Skip dependency, build, and VCS directories unless the user explicitly asks. The pinned .gitignore block (if any, below) is your authoritative denylist.\n- Prefer \\`search_files\\` over \\`list_directory\\` when you know roughly what you're looking for — it saves context and avoids enumerating huge trees. Note: \\`search_files\\` matches file NAMES; for searching file CONTENTS use \\`search_content\\`.\n- Available exploration tools: \\`read_file\\`, \\`list_directory\\`, \\`directory_tree\\`, \\`search_files\\` (filename match), \\`search_content\\` (content grep — use for \"where is X called\", \"find all references to Y\"), \\`get_file_info\\`. Don't call \\`grep\\` or other tools that aren't in this list — they don't exist as functions.\n\n# Path conventions\n\nTwo different rules depending on which tool:\n\n- **Filesystem tools** (\\`read_file\\`, \\`list_directory\\`, \\`search_files\\`, \\`edit_file\\`, etc.): paths are sandbox-relative. \\`/\\` means the project root, \\`/src/foo.ts\\` means \\`<project>/src/foo.ts\\`. Both relative (\\`src/foo.ts\\`) and POSIX-absolute (\\`/src/foo.ts\\`) forms work.\n- **\\`run_command\\`**: the command runs in a real OS shell with cwd pinned to the project root. Paths inside the shell command are interpreted by THAT shell, not by us. **Never use leading \\`/\\` in run_command arguments** — Windows treats \\`/tests\\` as drive-root \\`F:\\\\tests\\` (non-existent), POSIX shells treat it as filesystem root. Use plain relative paths (\\`tests\\`, \\`./tests\\`, \\`src/loop.ts\\`) instead.\n\n# When the user wants to switch project / working directory\n\nIf the user asks to switch / change / open a different directory or project (\"切换到...\", \"switch to ...\", \"let's work in ...\", \"open the X project\"), call **\\`change_workspace\\`** with the absolute target path. The tool always requires the user's explicit approval via a TUI modal — your call surfaces a \"switch / deny\" prompt, and STOPS your turn until they pick. After approval the filesystem / shell / memory tools re-register against the new root and your subsequent calls land there.\n\nHard rules:\n- Do NOT try to switch via \\`run_command\\` (\\`cd\\`, \\`pushd\\`, etc.) — your tool sandbox is pinned and \\`cd\\` inside one shell call doesn't carry to the next.\n- Do NOT chain other tool calls in the same turn as \\`change_workspace\\` — wait for the user's confirmation. Their next message will tell you whether the switch happened.\n- Do NOT call \\`change_workspace\\` to \"preview\" a sibling directory; only when the user explicitly asked to change projects.\n- The user can also type \\`/cwd <path>\\` themselves — fine, you'll see the new root take effect on the next turn either way.\n\n# Foreground vs. background commands\n\nYou have TWO tools for running shell commands, and picking the right one is non-negotiable:\n\n- \\`run_command\\` — blocks until the process exits. Use for: **tests, builds, lints, typechecks, git operations, one-shot scripts**. Anything that naturally returns in under a minute.\n- \\`run_background\\` — spawns and detaches after a brief startup window. Use for: **dev servers, watchers, any command with \"dev\" / \"serve\" / \"watch\" / \"start\" in the name**. Examples: \\`npm run dev\\`, \\`pnpm dev\\`, \\`yarn start\\`, \\`vite\\`, \\`next dev\\`, \\`uvicorn app:app --reload\\`, \\`flask run\\`, \\`python -m http.server\\`, \\`cargo watch\\`, \\`tsc --watch\\`, \\`webpack serve\\`.\n\n**Never use run_command for a dev server.** It will block for 60s, time out, and the user will see a frozen tool call while the server was actually running fine. Always \\`run_background\\`, then \\`job_output\\` to peek at the logs when you need to verify something.\n\nAfter \\`run_background\\`, tools available to you:\n- \\`job_output(jobId, tailLines?)\\` — read recent logs to verify startup / debug errors.\n- \\`list_jobs\\` — see every job this session (running + exited).\n- \\`stop_job(jobId)\\` — SIGTERM → SIGKILL after grace. Stop before switching port / config.\n\nDon't re-start an already-running dev server — call \\`list_jobs\\` first when in doubt.\n\n# Scope discipline on \"run it\" / \"start it\" requests\n\nWhen the user's request is to **run / start / launch / serve / boot up** something, your job is ONLY:\n\n1. Start it (\\`run_background\\` for dev servers, \\`run_command\\` for one-shots).\n2. Verify it came up (read a ready signal via \\`job_output\\`, or fetch the URL with \\`web_fetch\\` if they want you to confirm).\n3. Report what's running, where (URL / port / pid), and STOP.\n\nDo NOT, in the same turn:\n- Run \\`tsc\\` / type-checkers / linters unless the user asked for it.\n- Scan for bugs to \"proactively\" fix. The page rendering is success.\n- Clean up unused imports, dead code, or refactor \"while you're here.\"\n- Edit files to improve anything the user didn't mention.\n\nIf you notice an obvious issue, MENTION it in one sentence and wait for the user to say \"fix it.\" The cost of over-eagerness is real: you burn tokens, make surprise edits the user didn't want, and chain into cascading \"fix the new error I just introduced\" loops. The storm-breaker will cut you off, but the user still sees the mess.\n\n\"It works\" is the end state. Resist the urge to polish.\n\n# Style\n\n- Show edits; don't narrate them in prose. \"Here's the fix:\" is enough.\n- One short paragraph explaining *why*, then the blocks.\n- If you need to explore first (list / read / search), do it with tool calls before writing any prose — silence while exploring is fine.\n\n${ESCALATION_CONTRACT}\n\n${TUI_FORMATTING_RULES}\n`;\n\n/**\n * Inject the project's `.gitignore` content into the system prompt as a\n * \"respect this on top of the built-in denylist\" hint. We don't parse\n * the file — we hand it to the model as-is. Truncate long ones so we\n * don't eat context budget on huge generated ignore lists.\n *\n * Stacking order (stable for cache prefix):\n * base prompt → REASONIX.md → global MEMORY.md → project MEMORY.md → .gitignore\n */\n/**\n * Routing fragment appended to the code-mode system prompt when the\n * project has a semantic index built. Without this nudge the model\n * defaults to grep (`search_content`) for every query — semantic\n * search loses the \"first attempt\" battle on token-rich phrasings\n * even when the question is descriptive.\n *\n * Kept short and explicit: rules over rationale. The model that needs\n * this hint isn't reading three paragraphs of \"why semantic search\n * is good\"; it needs a clear if/else.\n */\nconst SEMANTIC_SEARCH_ROUTING = `\n\n# Search routing\n\nYou have BOTH \\`semantic_search\\` (vector index) and \\`search_content\\` (literal grep).\n\n- **Descriptive queries** (\"where do we handle X\", \"which file owns Y\", \"how does Z work\", \"find the logic that does …\", \"the code responsible for …\") → call \\`semantic_search\\` FIRST. It indexes the project by meaning, so it finds the right file even when your phrasing shares no tokens with the code.\n- **Exact-token queries** (a specific identifier, regex, or \"find every call to foo\") → call \\`search_content\\`.\n\nIf \\`semantic_search\\` returns nothing useful (low scores, off-topic), THEN fall back to \\`search_content\\`. Don't go the other way — grepping a paraphrased question wastes turns.`;\n\nexport interface CodeSystemPromptOptions {\n /** True when semantic_search is registered for this run. Adds an\n * explicit routing fragment so the model picks it for intent-style\n * queries instead of defaulting to grep. */\n hasSemanticSearch?: boolean;\n}\n\nexport function codeSystemPrompt(rootDir: string, opts: CodeSystemPromptOptions = {}): string {\n const base = opts.hasSemanticSearch\n ? `${CODE_SYSTEM_PROMPT}${SEMANTIC_SEARCH_ROUTING}`\n : CODE_SYSTEM_PROMPT;\n const withMemory = applyMemoryStack(base, rootDir);\n const gitignorePath = join(rootDir, \".gitignore\");\n if (!existsSync(gitignorePath)) return withMemory;\n let content: string;\n try {\n content = readFileSync(gitignorePath, \"utf8\");\n } catch {\n return withMemory;\n }\n const MAX = 2000;\n const truncated =\n content.length > MAX\n ? `${content.slice(0, MAX)}\\n… (truncated ${content.length - MAX} chars)`\n : content;\n return `${withMemory}\n\n# Project .gitignore\n\nThe user's repo ships this .gitignore — treat every pattern as \"don't traverse or edit inside these paths unless explicitly asked\":\n\n\\`\\`\\`\n${truncated}\n\\`\\`\\`\n`;\n}\n","/**\n * Reusable prompt fragments. Every rule that applies across multiple\n * prompt surfaces (main agent + subagents + built-in skills) lives\n * here so one edit covers every place the model learns the house\n * style. The 4-copy formatting-rule drift that motivated this was a\n * real bug: Unicode box-drawing warnings diverged between subagent\n * prompts, and the main code prompt lacked them entirely even though\n * its reply goes through the same markdown renderer.\n */\n\n/**\n * How replies get rendered. Matches behaviors the TUI's markdown\n * pipeline (src/cli/ui/markdown.tsx) actually handles best.\n * Embedded literally into prompts — no string interpolation, so it\n * survives Reasonix's prefix-cache hashing unchanged across sessions.\n */\nexport const TUI_FORMATTING_RULES = `Formatting (rendered in a TUI with a real markdown renderer):\n- Tabular data → GitHub-Flavored Markdown tables with ASCII pipes (\\`| col | col |\\` header + \\`| --- | --- |\\` separator). Never use Unicode box-drawing characters (│ ─ ┼ ┌ ┐ └ ┘ ├ ┤) — they look intentional but break terminal word-wrap and render as garbled columns at narrow widths.\n- Keep table cells short (one phrase each). If a cell needs a paragraph, use bullets below the table instead.\n- Code, file paths with line ranges, and shell commands → fenced code blocks (\\`\\`\\`).\n- Do NOT draw decorative frames around content with \\`┌──┐ │ └──┘\\` characters. The renderer adds its own borders; extra ASCII art adds noise and shatters at narrow widths.\n- For flow charts and diagrams: a plain bullet list with \\`→\\` or \\`↓\\` between steps. Don't try to draw boxes-and-arrows in ASCII; it never survives word-wrap.`;\n\n/**\n * Self-report escalation contract — teaches the model (running on\n * flash by default) how to ask for a retry on v4-pro. When Reasonix\n * sees \"<<<NEEDS_PRO>>>\" as the first line of assistant output on\n * flash, it aborts the call, upgrades this turn to pro, and re-issues\n * the same messages. One retry per turn; pro never re-escalates.\n *\n * Why this exists: non-expert users can't reliably predict which\n * tasks need the frontier tier, and reactive-only escalation (wait\n * for flash to fail N times) wastes tokens + time. Letting the model\n * self-assess catches hard tasks upfront when flash recognizes the\n * difficulty — without silently auto-upgrading every prompt (which\n * would destroy cost savings).\n *\n * Use sparingly: most coding tasks stay on flash. The escape hatch\n * is for tasks where flash would otherwise emit a mediocre / guessed\n * answer.\n */\nexport const ESCALATION_CONTRACT = `Cost-aware escalation (when you're running on deepseek-v4-flash):\n\nIf a task CLEARLY exceeds what flash can do well — complex cross-file architecture refactors, subtle concurrency / security / correctness invariants you can't resolve with confidence, or a design trade-off you'd be guessing at — output the marker as the FIRST line of your response (nothing before it, not even whitespace on a separate line). This aborts the current call and retries this turn on deepseek-v4-pro, one shot.\n\nTwo accepted forms:\n- \\`<<<NEEDS_PRO>>>\\` — bare marker, no rationale.\n- \\`<<<NEEDS_PRO: <one-sentence reason>>>>\\` — preferred. The reason text appears in the user-visible warning (\"⇧ flash requested escalation — <your reason>\"), so they understand WHY a more expensive call is happening. Keep it under ~150 chars, no newlines, no nested \\`>\\` characters. Examples: \\`<<<NEEDS_PRO: cross-file refactor across 6 modules with circular imports>>>\\` or \\`<<<NEEDS_PRO: subtle session-token race; flash would likely miss the locking invariant>>>\\`.\n\nDo NOT emit any other content in the same response when you request escalation. Use this sparingly: normal tasks — reading files, small edits, clear bug fixes, straightforward feature additions — stay on flash. Request escalation ONLY when you would otherwise produce a guess or a visibly-mediocre answer. If in doubt, attempt the task on flash first; the system also escalates automatically if you hit 3+ repair / SEARCH-mismatch errors in a single turn (the user sees a typed breakdown).`;\n\n/**\n * \"Don't assert absence without checking.\" Subagents that run without\n * this rule will confidently report \"X is missing\" based on their\n * partial exploration, and the parent agent swallows it as fact. The\n * main code prompt has its own, longer version of this — kept separate\n * because the code agent is in a richer conversational frame.\n */\nexport const NEGATIVE_CLAIM_RULE = `Negative claims (\"X is missing\", \"Y isn't implemented\", \"there's no Z\") are the #1 hallucination shape. They feel safe to write because no citation seems possible — but that's exactly why you must NOT write them on instinct.\n\nIf you have a search tool (\\`search_content\\`, \\`grep\\`, web search), call it FIRST before asserting absence:\n- Returns matches → you were wrong; correct yourself and cite the matches.\n- Returns nothing → state the absence WITH the search query as evidence: \\`No callers of \\\\\\`foo()\\\\\\` found (search_content \"foo\").\\`\n\nIf you have no search tool, qualify hard: \"I haven't verified — this is a guess.\" Never assert absence with fake authority.`;\n","/**\n * User memory — `~/.reasonix/memory/` markdown notes pinned into the\n * immutable-prefix system prompt across sessions.\n *\n * Two scopes:\n * - `global` → `~/.reasonix/memory/global/` (cross-project)\n * - `project` → `~/.reasonix/memory/<hash>/` (per sandbox root)\n *\n * Each scope has an always-loaded `MEMORY.md` index plus zero-or-more\n * `<name>.md` detail files loaded on demand via `recall_memory`.\n *\n * Distinct from `src/project-memory.ts` (REASONIX.md) in purpose:\n * REASONIX.md is committable, team-shared project memory.\n * ~/.reasonix/memory is user-private memory, never committed.\n */\n\nimport { createHash } from \"node:crypto\";\nimport {\n existsSync,\n mkdirSync,\n readFileSync,\n readdirSync,\n unlinkSync,\n writeFileSync,\n} from \"node:fs\";\nimport { homedir } from \"node:os\";\nimport { join, resolve } from \"node:path\";\nimport { applyProjectMemory, memoryEnabled } from \"./project-memory.js\";\nimport { applySkillsIndex } from \"./skills.js\";\n\nexport const USER_MEMORY_DIR = \"memory\";\nexport const MEMORY_INDEX_FILE = \"MEMORY.md\";\n/** Cap on the index file content loaded into the prefix, per scope. */\nexport const MEMORY_INDEX_MAX_CHARS = 4000;\n\nexport type MemoryType = \"user\" | \"feedback\" | \"project\" | \"reference\";\nexport type MemoryScope = \"global\" | \"project\";\n\nexport interface MemoryEntry {\n name: string;\n type: MemoryType;\n scope: MemoryScope;\n description: string;\n body: string;\n /** ISO date string (YYYY-MM-DD). */\n createdAt: string;\n}\n\nexport interface MemoryStoreOptions {\n /** Override `~/.reasonix` — tests set this to a tmpdir. */\n homeDir?: string;\n /** Absolute sandbox root. Required to use `scope: \"project\"`. */\n projectRoot?: string;\n}\n\nexport interface WriteInput {\n name: string;\n type: MemoryType;\n scope: MemoryScope;\n description: string;\n body: string;\n}\n\nconst VALID_NAME = /^[a-zA-Z0-9_-][a-zA-Z0-9_.-]{1,38}[a-zA-Z0-9]$/;\n\n/**\n * Throws on filename injection attempts (`../foo`, `foo/bar`, leading\n * dots, etc.). Allowed: 3-40 chars, alnum + `_` + `-` + interior `.`.\n */\nexport function sanitizeMemoryName(raw: string): string {\n const trimmed = String(raw ?? \"\").trim();\n if (!VALID_NAME.test(trimmed)) {\n throw new Error(\n `invalid memory name: ${JSON.stringify(raw)} — must be 3-40 chars, alnum/_/-, no path separators`,\n );\n }\n return trimmed;\n}\n\n/** Stable 16-hex-char hash of an absolute sandbox root path. */\nexport function projectHash(rootDir: string): string {\n const abs = resolve(rootDir);\n return createHash(\"sha1\").update(abs).digest(\"hex\").slice(0, 16);\n}\n\nfunction scopeDir(opts: { homeDir: string; scope: MemoryScope; projectRoot?: string }): string {\n if (opts.scope === \"global\") {\n return join(opts.homeDir, USER_MEMORY_DIR, \"global\");\n }\n if (!opts.projectRoot) {\n throw new Error(\"scope=project requires a projectRoot on MemoryStore\");\n }\n return join(opts.homeDir, USER_MEMORY_DIR, projectHash(opts.projectRoot));\n}\n\nfunction ensureDir(p: string): void {\n if (!existsSync(p)) mkdirSync(p, { recursive: true });\n}\n\n/**\n * Parse a `---` frontmatter block off the top of a markdown string.\n * Tolerates missing frontmatter, returning `{}` for data and the full\n * string as body. Only recognizes the simple `key: value` shape — no\n * quoting, no multi-line, no YAML features. Matches what we emit.\n */\nfunction parseFrontmatter(raw: string): { data: Record<string, string>; body: string } {\n const lines = raw.split(/\\r?\\n/);\n if (lines[0] !== \"---\") return { data: {}, body: raw };\n const end = lines.indexOf(\"---\", 1);\n if (end < 0) return { data: {}, body: raw };\n const data: Record<string, string> = {};\n for (let i = 1; i < end; i++) {\n const line = lines[i];\n if (!line) continue;\n const m = line.match(/^([a-zA-Z_][a-zA-Z0-9_-]*):\\s*(.*)$/);\n if (m?.[1]) data[m[1]] = (m[2] ?? \"\").trim();\n }\n return {\n data,\n body: lines\n .slice(end + 1)\n .join(\"\\n\")\n .replace(/^\\n+/, \"\"),\n };\n}\n\nfunction formatFrontmatter(e: WriteInput & { createdAt: string }): string {\n return [\n \"---\",\n `name: ${e.name}`,\n `description: ${e.description.replace(/\\n/g, \" \")}`,\n `type: ${e.type}`,\n `scope: ${e.scope}`,\n `created: ${e.createdAt}`,\n \"---\",\n \"\",\n ].join(\"\\n\");\n}\n\nfunction todayIso(): string {\n const d = new Date();\n return d.toISOString().slice(0, 10);\n}\n\n/**\n * A `MEMORY.md` index line for one entry. One-liner, under ~150 chars.\n * `description` is truncated if it would push past the soft limit.\n */\nfunction indexLine(e: Pick<MemoryEntry, \"name\" | \"description\">): string {\n const safeDesc = e.description.replace(/\\n/g, \" \").trim();\n const max = 130 - e.name.length;\n const clipped = safeDesc.length > max ? `${safeDesc.slice(0, Math.max(1, max - 1))}…` : safeDesc;\n return `- [${e.name}](${e.name}.md) — ${clipped}`;\n}\n\nexport class MemoryStore {\n private readonly homeDir: string;\n private readonly projectRoot: string | undefined;\n\n constructor(opts: MemoryStoreOptions = {}) {\n this.homeDir = opts.homeDir ?? join(homedir(), \".reasonix\");\n this.projectRoot = opts.projectRoot ? resolve(opts.projectRoot) : undefined;\n }\n\n /** Directory this store writes `scope` files into, creating it if needed. */\n dir(scope: MemoryScope): string {\n const d = scopeDir({ homeDir: this.homeDir, scope, projectRoot: this.projectRoot });\n ensureDir(d);\n return d;\n }\n\n /** Absolute path to a memory file (no existence check). */\n pathFor(scope: MemoryScope, name: string): string {\n return join(this.dir(scope), `${sanitizeMemoryName(name)}.md`);\n }\n\n /** True iff this store is configured with a project scope available. */\n hasProjectScope(): boolean {\n return this.projectRoot !== undefined;\n }\n\n /**\n * Read the `MEMORY.md` index for a scope. Returns post-cap content\n * (with a truncation marker if clipped), or `null` when absent / empty.\n */\n loadIndex(\n scope: MemoryScope,\n ): { content: string; originalChars: number; truncated: boolean } | null {\n if (scope === \"project\" && !this.projectRoot) return null;\n const file = join(\n scopeDir({ homeDir: this.homeDir, scope, projectRoot: this.projectRoot }),\n MEMORY_INDEX_FILE,\n );\n if (!existsSync(file)) return null;\n let raw: string;\n try {\n raw = readFileSync(file, \"utf8\");\n } catch {\n return null;\n }\n const trimmed = raw.trim();\n if (!trimmed) return null;\n const originalChars = trimmed.length;\n const truncated = originalChars > MEMORY_INDEX_MAX_CHARS;\n const content = truncated\n ? `${trimmed.slice(0, MEMORY_INDEX_MAX_CHARS)}\\n… (truncated ${originalChars - MEMORY_INDEX_MAX_CHARS} chars)`\n : trimmed;\n return { content, originalChars, truncated };\n }\n\n /** Read one memory file's body (frontmatter stripped). Throws if missing. */\n read(scope: MemoryScope, name: string): MemoryEntry {\n const file = this.pathFor(scope, name);\n if (!existsSync(file)) {\n throw new Error(`memory not found: scope=${scope} name=${name}`);\n }\n const raw = readFileSync(file, \"utf8\");\n const { data, body } = parseFrontmatter(raw);\n return {\n name: data.name ?? name,\n type: (data.type as MemoryType) ?? \"project\",\n scope: (data.scope as MemoryScope) ?? scope,\n description: data.description ?? \"\",\n body: body.trim(),\n createdAt: data.created ?? \"\",\n };\n }\n\n /**\n * List every memory in this store. Scans both scopes (skips project\n * scope if unconfigured). Silently skips malformed files; the index\n * must stay queryable even if one file is hand-edited into nonsense.\n */\n list(): MemoryEntry[] {\n const out: MemoryEntry[] = [];\n const scopes: MemoryScope[] = this.projectRoot ? [\"global\", \"project\"] : [\"global\"];\n for (const scope of scopes) {\n const dir = scopeDir({ homeDir: this.homeDir, scope, projectRoot: this.projectRoot });\n if (!existsSync(dir)) continue;\n let entries: string[];\n try {\n entries = readdirSync(dir);\n } catch {\n continue;\n }\n for (const entry of entries) {\n if (entry === MEMORY_INDEX_FILE) continue;\n if (!entry.endsWith(\".md\")) continue;\n const name = entry.slice(0, -3);\n try {\n out.push(this.read(scope, name));\n } catch {\n // malformed file — skip rather than fail the whole list\n }\n }\n }\n return out;\n }\n\n /**\n * Write a new memory (or overwrite existing). Creates the scope dir,\n * writes the `.md` file, and regenerates `MEMORY.md`. Returns the\n * absolute path written to.\n */\n write(input: WriteInput): string {\n if (input.scope === \"project\" && !this.projectRoot) {\n throw new Error(\"cannot write project-scoped memory: no projectRoot configured\");\n }\n const name = sanitizeMemoryName(input.name);\n const desc = String(input.description ?? \"\").trim();\n if (!desc) throw new Error(\"memory description cannot be empty\");\n const body = String(input.body ?? \"\").trim();\n if (!body) throw new Error(\"memory body cannot be empty\");\n const entry: WriteInput & { createdAt: string } = {\n ...input,\n name,\n description: desc,\n body,\n createdAt: todayIso(),\n };\n const dir = this.dir(input.scope);\n const file = join(dir, `${name}.md`);\n const content = `${formatFrontmatter(entry)}${body}\\n`;\n writeFileSync(file, content, \"utf8\");\n this.regenerateIndex(input.scope);\n return file;\n }\n\n /** Delete one memory + its index line. No-op if the file is already gone. */\n delete(scope: MemoryScope, rawName: string): boolean {\n if (scope === \"project\" && !this.projectRoot) {\n throw new Error(\"cannot delete project-scoped memory: no projectRoot configured\");\n }\n const file = this.pathFor(scope, rawName);\n if (!existsSync(file)) return false;\n unlinkSync(file);\n this.regenerateIndex(scope);\n return true;\n }\n\n /**\n * Rebuild `MEMORY.md` from the `.md` files currently in the scope dir.\n * Called after every write/delete. Sorted by name for stable prefix\n * hashing — two stores with the same set of files produce byte-identical\n * MEMORY.md content, keeping the cache prefix reproducible.\n */\n private regenerateIndex(scope: MemoryScope): void {\n const dir = scopeDir({ homeDir: this.homeDir, scope, projectRoot: this.projectRoot });\n if (!existsSync(dir)) return;\n let files: string[];\n try {\n files = readdirSync(dir);\n } catch {\n return;\n }\n const mdFiles = files\n .filter((f) => f !== MEMORY_INDEX_FILE && f.endsWith(\".md\"))\n .sort((a, b) => a.localeCompare(b));\n const indexPath = join(dir, MEMORY_INDEX_FILE);\n if (mdFiles.length === 0) {\n if (existsSync(indexPath)) unlinkSync(indexPath);\n return;\n }\n const lines: string[] = [];\n for (const f of mdFiles) {\n const name = f.slice(0, -3);\n try {\n const entry = this.read(scope, name);\n lines.push(indexLine({ name: entry.name || name, description: entry.description }));\n } catch {\n // Malformed: still surface it in the index so the user notices.\n lines.push(`- [${name}](${name}.md) — (malformed, check frontmatter)`);\n }\n }\n writeFileSync(indexPath, `${lines.join(\"\\n\")}\\n`, \"utf8\");\n }\n}\n\n/**\n * Read the freeform global REASONIX.md (~/.reasonix/REASONIX.md). This\n * is the destination for the `#g <note>` quick-write prefix — symmetric\n * to project REASONIX.md but pinned across every session regardless of\n * working directory. Returns post-cap content or `null` when the file\n * is absent / empty / unreadable.\n *\n * Distinct from MEMORY.md (the curated index of named .md files) — this\n * is one freeform bullet list the user appends to with `#g`.\n */\nexport function readGlobalReasonixMemory(\n homeDir: string = join(homedir(), \".reasonix\"),\n): { path: string; content: string; originalChars: number; truncated: boolean } | null {\n const path = join(homeDir, \"REASONIX.md\");\n if (!existsSync(path)) return null;\n let raw: string;\n try {\n raw = readFileSync(path, \"utf8\");\n } catch {\n return null;\n }\n const trimmed = raw.trim();\n if (!trimmed) return null;\n const originalChars = trimmed.length;\n // Reuse the project-memory cap so both freeform files have the same\n // headroom (8000 chars ≈ 2k tokens). They serve the same purpose at\n // different scopes.\n const truncated = originalChars > 8000;\n const content = truncated\n ? `${trimmed.slice(0, 8000)}\\n… (truncated ${originalChars - 8000} chars)`\n : trimmed;\n return { path, content, originalChars, truncated };\n}\n\n/**\n * Append the global freeform REASONIX.md to `basePrompt` as its own\n * pinned section. No-op when the file is absent / empty / disabled.\n * Stable byte output for stable prefix hashing — same file content\n * always produces the same prompt suffix.\n */\nexport function applyGlobalReasonixMemory(basePrompt: string, homeDir?: string): string {\n if (!memoryEnabled()) return basePrompt;\n const dir = homeDir ?? join(homedir(), \".reasonix\");\n const mem = readGlobalReasonixMemory(dir);\n if (!mem) return basePrompt;\n return [\n basePrompt,\n \"\",\n \"# Global memory (~/.reasonix/REASONIX.md)\",\n \"\",\n \"Cross-project notes the user pinned via the `#g` prompt prefix. Treat as authoritative — same level of trust as project memory.\",\n \"\",\n \"```\",\n mem.content,\n \"```\",\n ].join(\"\\n\");\n}\n\n/**\n * Append `MEMORY_GLOBAL` and (optionally) `MEMORY_PROJECT` blocks to\n * `basePrompt`. Omits a block entirely when its index is absent — an\n * empty tag would add bytes to the prefix hash without content.\n * Respects `REASONIX_MEMORY=off` via `memoryEnabled()` from\n * `project-memory.ts`.\n */\nexport function applyUserMemory(\n basePrompt: string,\n opts: { homeDir?: string; projectRoot?: string } = {},\n): string {\n if (!memoryEnabled()) return basePrompt;\n const store = new MemoryStore(opts);\n const global = store.loadIndex(\"global\");\n const project = store.hasProjectScope() ? store.loadIndex(\"project\") : null;\n if (!global && !project) return basePrompt;\n const parts: string[] = [basePrompt];\n if (global) {\n parts.push(\n \"\",\n \"# User memory — global (~/.reasonix/memory/global/MEMORY.md)\",\n \"\",\n \"Cross-project facts and preferences the user has told you in prior sessions. TREAT AS AUTHORITATIVE — don't re-verify via filesystem or web. One-liners index detail files; call `recall_memory` for full bodies only when the one-liner isn't enough.\",\n \"\",\n \"```\",\n global.content,\n \"```\",\n );\n }\n if (project) {\n parts.push(\n \"\",\n \"# User memory — this project\",\n \"\",\n \"Per-project facts the user established in prior sessions (not committed to the repo). TREAT AS AUTHORITATIVE. Same recall pattern as global memory.\",\n \"\",\n \"```\",\n project.content,\n \"```\",\n );\n }\n return parts.join(\"\\n\");\n}\n\n/**\n * Compose every lazy-loaded prefix block in one call: project REASONIX.md,\n * global REASONIX.md (`#g` destination), user memory indexes (global +\n * per-project), and the skills index. Drop-in replacement for\n * `applyProjectMemory` at CLI entry points. Stacking order is stable —\n * the prefix hash only changes when block *content* changes, not when\n * this helper is called a second time with the same filesystem state.\n */\nexport function applyMemoryStack(basePrompt: string, rootDir: string): string {\n const withProject = applyProjectMemory(basePrompt, rootDir);\n const withGlobal = applyGlobalReasonixMemory(withProject);\n const withMemory = applyUserMemory(withGlobal, { projectRoot: rootDir });\n return applySkillsIndex(withMemory, { projectRoot: rootDir });\n}\n","/**\n * Project memory — a user-authored `REASONIX.md` in the project root\n * that gets pinned into the immutable-prefix system prompt.\n *\n * Design notes:\n *\n * - The file lands in `ImmutablePrefix.system`, so the whole memory\n * block is hashed into the cache prefix fingerprint. Editing the\n * file invalidates the prefix; unchanged memory across sessions\n * keeps the DeepSeek prefix cache warm. That matches Pillar 1 —\n * memory is a deliberate, stable prefix, not per-turn drift.\n * - Only one source: the working-root `REASONIX.md`. No parent walk,\n * no `~/.reasonix/REASONIX.md`, no CLAUDE.md fallback. User-global\n * memory can come later; for v1 one file == one mental model.\n * - Truncated at 8 000 chars (≈ 2k tokens). `.gitignore` gets 2 000\n * because it's a constraint dump; memory gets more headroom because\n * it's deliberate instructions.\n * - Opt-out via `REASONIX_MEMORY=off|false|0`. No CLI flag — memory\n * is a file, `rm REASONIX.md` is the other opt-out.\n */\n\nimport { existsSync, readFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\n\nexport const PROJECT_MEMORY_FILE = \"REASONIX.md\";\nexport const PROJECT_MEMORY_MAX_CHARS = 8000;\n\nexport interface ProjectMemory {\n /** Absolute path the memory was read from. */\n path: string;\n /** Post-truncation content (may include a \"… (truncated N chars)\" marker). */\n content: string;\n /** Original byte length before truncation. */\n originalChars: number;\n /** True iff `originalChars > PROJECT_MEMORY_MAX_CHARS`. */\n truncated: boolean;\n}\n\n/**\n * Read `REASONIX.md` from `rootDir`. Returns `null` when the file is\n * missing, unreadable, or empty (whitespace-only counts as empty — an\n * empty memory file shouldn't perturb the cache prefix).\n */\nexport function readProjectMemory(rootDir: string): ProjectMemory | null {\n const path = join(rootDir, PROJECT_MEMORY_FILE);\n if (!existsSync(path)) return null;\n let raw: string;\n try {\n raw = readFileSync(path, \"utf8\");\n } catch {\n return null;\n }\n const trimmed = raw.trim();\n if (!trimmed) return null;\n const originalChars = trimmed.length;\n const truncated = originalChars > PROJECT_MEMORY_MAX_CHARS;\n const content = truncated\n ? `${trimmed.slice(0, PROJECT_MEMORY_MAX_CHARS)}\\n… (truncated ${\n originalChars - PROJECT_MEMORY_MAX_CHARS\n } chars)`\n : trimmed;\n return { path, content, originalChars, truncated };\n}\n\n/**\n * Resolve whether project memory should be read. Default: on.\n * `REASONIX_MEMORY=off|false|0` turns it off (CI, reproducing issues,\n * intentional offline runs).\n */\nexport function memoryEnabled(): boolean {\n const env = process.env.REASONIX_MEMORY;\n if (env === \"off\" || env === \"false\" || env === \"0\") return false;\n return true;\n}\n\n/**\n * Return `basePrompt` with the project's `REASONIX.md` appended as a\n * \"Project memory\" section. No-op when the file is absent, empty, or\n * memory is disabled via env.\n *\n * The appended block is deterministic — identical input ⇒ identical\n * output — so every session that opens against the same memory file\n * gets the same prefix hash.\n */\nexport function applyProjectMemory(basePrompt: string, rootDir: string): string {\n if (!memoryEnabled()) return basePrompt;\n const mem = readProjectMemory(rootDir);\n if (!mem) return basePrompt;\n return `${basePrompt}\n\n# Project memory (REASONIX.md)\n\nThe user pinned these notes about this project — treat them as authoritative context for every turn:\n\n\\`\\`\\`\n${mem.content}\n\\`\\`\\`\n`;\n}\n","/**\n * Skills — user-defined prompt packs pinned (by name) into the\n * immutable prefix and loaded (by body) on demand.\n *\n * Two scopes mirror the user-memory layout:\n * - `project` → `<projectRoot>/.reasonix/skills/` (this repo only)\n * - `global` → `~/.reasonix/skills/` (every session)\n *\n * Project scope wins on a name collision. Deliberately NOT tied to\n * any specific client's directory convention (`.claude/`, `.glm/`,\n * etc.) — Reasonix is model-agnostic at the conversation layer, so\n * coupling the skill filesystem to one vendor would break any user\n * running a different backend.\n *\n * Accepted file layouts (both emit the same `Skill`):\n * - `{dir}/<name>/SKILL.md` (preferred — lets a skill bundle\n * additional assets alongside)\n * - `{dir}/<name>.md` (flat, one-file shorthand)\n *\n * Frontmatter keys we read:\n * - `name` — optional, defaults to the file / dir name\n * - `description` — one-line index description (REQUIRED for listing)\n * - `allowed-tools` — parsed but UNUSED in v1 (see tools/skills.ts)\n *\n * Cache-First contract (Pillar 1):\n * - The PREFIX sees only names + descriptions (one line each).\n * - Bodies enter the APPEND-ONLY LOG lazily, via `run_skill` or\n * `/skill <name>` — never the prefix. That keeps the prefix hash\n * stable across skill additions to the body store.\n */\n\nimport { existsSync, readFileSync, readdirSync, statSync } from \"node:fs\";\nimport { homedir } from \"node:os\";\nimport { join, resolve } from \"node:path\";\nimport { NEGATIVE_CLAIM_RULE, TUI_FORMATTING_RULES } from \"./prompt-fragments.js\";\n\nexport const SKILLS_DIRNAME = \"skills\";\nexport const SKILL_FILE = \"SKILL.md\";\n/** Cap on the pinned skills-index block, mirrors memory-index cap. */\nexport const SKILLS_INDEX_MAX_CHARS = 4000;\n/** Skill identifier shape — alnum + `_` + `-` + interior `.`, 1-64 chars. */\nconst VALID_SKILL_NAME = /^[a-zA-Z0-9][a-zA-Z0-9._-]{0,63}$/;\n\nexport type SkillScope = \"project\" | \"global\" | \"builtin\";\n\n/**\n * Execution mode for a skill. `inline` (default) returns the body as a\n * tool result so the body enters the parent's append-only log — the\n * model continues the loop using the loaded instructions. `subagent`\n * spawns an isolated child loop with the body as the system prompt and\n * the user-supplied `arguments` as the task; only the child's final\n * answer comes back. Use `subagent` for big-context exploration / research\n * playbooks where the parent doesn't need to see the trail.\n */\nexport type SkillRunAs = \"inline\" | \"subagent\";\n\nexport interface Skill {\n /** Canonical name — sanitized, matches the directory / filename stem. */\n name: string;\n /** One-line description shown in the pinned index. */\n description: string;\n /** Full markdown body (post-frontmatter). Loaded on demand. */\n body: string;\n /** Which scope this skill was loaded from. */\n scope: SkillScope;\n /** Absolute path to the SKILL.md (or {name}.md) file, or \"(builtin)\" for shipped defaults. */\n path: string;\n /** Raw `allowed-tools` field from frontmatter, if any. Unused in v1. */\n allowedTools?: string;\n /**\n * Execution mode (frontmatter `runAs`). Defaults to `inline` for\n * backwards compatibility with skills written before this field\n * existed.\n */\n runAs: SkillRunAs;\n /**\n * Frontmatter `model` — when set, overrides the default model the\n * subagent runs on. Only meaningful when `runAs === \"subagent\"`.\n * Accept any DeepSeek model id; the subagent layer falls back to its\n * own default if this is missing or invalid.\n */\n model?: string;\n}\n\nexport interface SkillStoreOptions {\n /** Override `$HOME` — tests point this at a tmpdir. */\n homeDir?: string;\n /**\n * Absolute project root. Required to surface project-scope skills;\n * omit (e.g. in `reasonix chat` without `code`) and the store only\n * reads the global scope.\n */\n projectRoot?: string;\n /**\n * Suppress the bundled built-in skills (`explore`, `research`).\n * Used by unit tests that want to assert exact list contents\n * without the +2 builtins distorting counts. Production callers\n * leave this off so users always get the bundled defaults.\n */\n disableBuiltins?: boolean;\n}\n\n/**\n * Parse a `---` frontmatter block. Same minimal shape as user-memory:\n * `key: value` lines, no quoting, no nesting. Returns `{}` data and the\n * full input as body when no frontmatter fence is present — so hand-\n * written files without frontmatter still surface (with empty desc).\n */\nfunction parseFrontmatter(raw: string): { data: Record<string, string>; body: string } {\n const lines = raw.split(/\\r?\\n/);\n if (lines[0] !== \"---\") return { data: {}, body: raw };\n const end = lines.indexOf(\"---\", 1);\n if (end < 0) return { data: {}, body: raw };\n const data: Record<string, string> = {};\n for (let i = 1; i < end; i++) {\n const line = lines[i];\n if (!line) continue;\n const m = line.match(/^([a-zA-Z_][a-zA-Z0-9_-]*):\\s*(.*)$/);\n if (m?.[1]) data[m[1]] = (m[2] ?? \"\").trim();\n }\n return {\n data,\n body: lines\n .slice(end + 1)\n .join(\"\\n\")\n .replace(/^\\n+/, \"\"),\n };\n}\n\nfunction isValidSkillName(name: string): boolean {\n return VALID_SKILL_NAME.test(name);\n}\n\nexport class SkillStore {\n private readonly homeDir: string;\n private readonly projectRoot: string | undefined;\n private readonly disableBuiltins: boolean;\n\n constructor(opts: SkillStoreOptions = {}) {\n this.homeDir = opts.homeDir ?? homedir();\n this.projectRoot = opts.projectRoot ? resolve(opts.projectRoot) : undefined;\n this.disableBuiltins = opts.disableBuiltins === true;\n }\n\n /** True iff this store was configured with a project root. */\n hasProjectScope(): boolean {\n return this.projectRoot !== undefined;\n }\n\n /**\n * Root directories scanned, in priority order. Project scope first\n * so a per-repo skill overrides a global one with the same name —\n * users expect the local copy to win when both exist.\n */\n roots(): Array<{ dir: string; scope: SkillScope }> {\n const out: Array<{ dir: string; scope: SkillScope }> = [];\n if (this.projectRoot) {\n out.push({\n dir: join(this.projectRoot, \".reasonix\", SKILLS_DIRNAME),\n scope: \"project\",\n });\n }\n out.push({ dir: join(this.homeDir, \".reasonix\", SKILLS_DIRNAME), scope: \"global\" });\n return out;\n }\n\n /**\n * List every skill visible to this store. On name collisions the\n * higher-priority root (project over global over builtin) wins.\n * Sorted by name for stable prefix hashing.\n */\n list(): Skill[] {\n const byName = new Map<string, Skill>();\n for (const { dir, scope } of this.roots()) {\n if (!existsSync(dir)) continue;\n let entries: import(\"node:fs\").Dirent[];\n try {\n entries = readdirSync(dir, { withFileTypes: true });\n } catch {\n continue;\n }\n for (const entry of entries) {\n const skill = this.readEntry(dir, scope, entry);\n if (!skill) continue;\n if (!byName.has(skill.name)) byName.set(skill.name, skill);\n }\n }\n // Builtins are appended last so user/project files take precedence\n // when names collide. The same priority you'd expect: my-project's\n // \"explore\" overrides the shipped one without forcing a different\n // name.\n if (!this.disableBuiltins) {\n for (const skill of BUILTIN_SKILLS) {\n if (!byName.has(skill.name)) byName.set(skill.name, skill);\n }\n }\n return [...byName.values()].sort((a, b) => a.name.localeCompare(b.name));\n }\n\n /** Resolve one skill by name. Returns `null` if not found or malformed. */\n read(name: string): Skill | null {\n if (!isValidSkillName(name)) return null;\n for (const { dir, scope } of this.roots()) {\n if (!existsSync(dir)) continue;\n const dirCandidate = join(dir, name, SKILL_FILE);\n if (existsSync(dirCandidate) && statSync(dirCandidate).isFile()) {\n return this.parse(dirCandidate, name, scope);\n }\n const flatCandidate = join(dir, `${name}.md`);\n if (existsSync(flatCandidate) && statSync(flatCandidate).isFile()) {\n return this.parse(flatCandidate, name, scope);\n }\n }\n // Fall back to builtins. Same precedence as `list()` — user-authored\n // wins, builtins are the floor.\n if (!this.disableBuiltins) {\n for (const skill of BUILTIN_SKILLS) {\n if (skill.name === name) return skill;\n }\n }\n return null;\n }\n\n private readEntry(dir: string, scope: SkillScope, entry: import(\"node:fs\").Dirent): Skill | null {\n if (entry.isDirectory()) {\n if (!isValidSkillName(entry.name)) return null;\n const file = join(dir, entry.name, SKILL_FILE);\n if (!existsSync(file)) return null;\n return this.parse(file, entry.name, scope);\n }\n if (entry.isFile() && entry.name.endsWith(\".md\")) {\n const stem = entry.name.slice(0, -3);\n if (!isValidSkillName(stem)) return null;\n return this.parse(join(dir, entry.name), stem, scope);\n }\n return null;\n }\n\n private parse(path: string, stem: string, scope: SkillScope): Skill | null {\n let raw: string;\n try {\n raw = readFileSync(path, \"utf8\");\n } catch {\n return null;\n }\n const { data, body } = parseFrontmatter(raw);\n const name = data.name && isValidSkillName(data.name) ? data.name : stem;\n return {\n name,\n description: (data.description ?? \"\").trim(),\n body: body.trim(),\n scope,\n path,\n allowedTools: data[\"allowed-tools\"],\n runAs: parseRunAs(data.runAs),\n model: data.model?.startsWith(\"deepseek-\") ? data.model : undefined,\n };\n }\n}\n\n/**\n * Coerce a frontmatter `runAs` string to the discriminated union. Any\n * value other than the literal \"subagent\" is treated as inline — typos\n * and unknown values default to the safe (non-spawning) mode rather\n * than failing the load.\n */\nfunction parseRunAs(raw: string | undefined): SkillRunAs {\n return raw?.trim() === \"subagent\" ? \"subagent\" : \"inline\";\n}\n\n/**\n * Build a single index line for one skill. Shape mirrors memory's\n * `indexLine` — a bullet suitable for a markdown fenced block in the\n * system prompt. Description is truncated to keep the full line under\n * ~150 chars.\n *\n * Subagent-runAs skills carry a `[🧬 subagent]` tag AFTER the name\n * so the model can't confuse the marker for part of the skill name.\n * (Historical bug: when the marker led the name — `- 🧬 explore` —\n * models would call `run_skill({ name: \"🧬 explore\" })` verbatim\n * and fail lookup. Wrapping the marker in brackets AFTER the name\n * eliminates that confusion; `run_skill`'s name arg also strips any\n * leading non-word chars as a belt-and-suspenders measure.)\n */\nfunction skillIndexLine(s: Pick<Skill, \"name\" | \"description\" | \"runAs\">): string {\n const safeDesc = s.description.replace(/\\n/g, \" \").trim();\n const tag = s.runAs === \"subagent\" ? \" [🧬 subagent]\" : \"\";\n const max = 130 - s.name.length - tag.length;\n const clipped = safeDesc.length > max ? `${safeDesc.slice(0, Math.max(1, max - 1))}…` : safeDesc;\n return clipped ? `- ${s.name}${tag} — ${clipped}` : `- ${s.name}${tag}`;\n}\n\n/**\n * Append a `# Skills` block to `basePrompt` listing every discovered\n * skill (name + description only). Bodies are NOT inlined — that's the\n * whole point: the prefix stays short and cacheable; full content loads\n * on demand via `run_skill` or `/skill <name>`.\n *\n * Emits nothing when no skills are discovered — keeps the prefix hash\n * stable for users who don't use skills at all.\n */\nexport function applySkillsIndex(basePrompt: string, opts: SkillStoreOptions = {}): string {\n const store = new SkillStore(opts);\n const skills = store.list().filter((s) => s.description);\n if (skills.length === 0) return basePrompt;\n const lines = skills.map(skillIndexLine);\n const joined = lines.join(\"\\n\");\n const truncated =\n joined.length > SKILLS_INDEX_MAX_CHARS\n ? `${joined.slice(0, SKILLS_INDEX_MAX_CHARS)}\\n… (truncated ${\n joined.length - SKILLS_INDEX_MAX_CHARS\n } chars)`\n : joined;\n return [\n basePrompt,\n \"\",\n \"# Skills — playbooks you can invoke\",\n \"\",\n 'One-liner index. Each entry is either a built-in or a user-authored playbook. Call `run_skill({ name: \"<skill-name>\", arguments: \"<task>\" })` — the `name` is JUST the skill identifier (e.g. `\"explore\"`), NOT the `[🧬 subagent]` tag that appears after it. Entries tagged `[🧬 subagent]` spawn an **isolated subagent** — its tool calls and reasoning never enter your context, only its final answer does. Use subagent skills for tasks that would otherwise flood your context (deep exploration, multi-step research, anything where you only need the conclusion). Plain skills are inlined: their body becomes a tool result you read and act on directly. The user can also invoke a skill via `/skill <name>`.',\n \"\",\n \"```\",\n truncated,\n \"```\",\n ].join(\"\\n\");\n}\n\n/**\n * Built-in skills shipped with Reasonix. These are always available\n * (no install step) and live as constants rather than files because:\n * - Zero filesystem coupling — no copy-on-first-run dance, nothing\n * to migrate when we update them.\n * - They participate in the same `byName` priority as user/project\n * skills: write `~/.reasonix/skills/explore.md` to override.\n *\n * Keep this list small and high-leverage. The bar for adding one: it\n * demonstrates a pattern users would otherwise have to invent\n * themselves, and the body fits in a screen.\n */\nconst BUILTIN_EXPLORE_BODY = `You are running as an exploration subagent. Your job is to investigate the codebase the parent agent pointed you at, then return one focused, distilled answer.\n\nHow to operate:\n- Use read_file, search_files, search_content, directory_tree, list_directory, get_file_info as your primary tools. Stay read-only.\n- For \"find all places that call / reference / use X\" questions, use \\`search_content\\` (content grep) — NOT \\`search_files\\` (which only matches file names). This is the most common subagent mistake; using the wrong tool gives empty results and you waste your iter budget chasing a phantom.\n- Cast a wide net first (search_content for symbol references, directory_tree for structure) to map the territory; then read the 3-10 most relevant files in full.\n- Don't read every file — be selective. Aim for breadth on the first pass, depth only where the question demands it.\n- Stop exploring as soon as you can answer the question. The parent doesn't see your tool calls, so over-exploration is pure waste.\n\nYour final answer:\n- One paragraph (or a few short bullets). Lead with the conclusion.\n- Cite specific file paths + line ranges when they support the answer.\n- If the question can't be answered from what you found, say so plainly and suggest where to look next.\n- No follow-up offers, no \"let me know if you need more.\" The parent will ask again if they need more.\n\n${NEGATIVE_CLAIM_RULE}\n\n${TUI_FORMATTING_RULES}\n\nThe 'task' the parent gave you is the question you must answer. Treat any other reading of it as scope creep.`;\n\nconst BUILTIN_RESEARCH_BODY = `You are running as a research subagent. Your job is to gather information from code AND the web, synthesize it, and return one focused conclusion.\n\nHow to operate:\n- Combine code reading (read_file, search_files) with web tools (web_search, web_fetch) as appropriate to the question.\n- For \"how does X work\" / \"is Y supported\" questions: web first to find the canonical reference, then verify against the local code.\n- For \"what's our policy on Z\" / \"where do we use Q\": local code first, web only if you need to compare against external standards.\n- Cap yourself at ~10 tool calls. If you can't converge in 10, return what you have plus a note about what's missing.\n\nYour final answer:\n- One paragraph (or short bullets). Lead with the conclusion.\n- Cite both code (file:line) AND web sources (URL) when they back the answer.\n- Distinguish \"I verified this in code\" from \"I read this on a docs page\" — the parent will trust the former more.\n- If the answer is uncertain, say so. Don't invent confidence.\n\n${NEGATIVE_CLAIM_RULE}\n\n${TUI_FORMATTING_RULES}\n\nThe 'task' the parent gave you is the research question. Stay on it.`;\n\nconst BUILTIN_REVIEW_BODY = `You are running as a code-review subagent. Your job is to inspect the changes the user is about to ship — usually the current git branch vs its upstream — and produce a focused review the parent can hand back to the user.\n\nHow to operate:\n- Default scope: the current branch's diff vs the default branch. If the user's task names a specific commit range or files, honor that instead.\n- Discover scope first: \\`run_command git status\\`, \\`git diff --stat\\`, \\`git log --oneline\\` to see what changed. Then \\`git diff\\` (or \\`git diff <base>...HEAD\\`) for the actual hunks.\n- Read the touched files (\\`read_file\\`) when the diff alone doesn't carry enough context — function signatures, surrounding invariants, callers.\n- For \"any callers depending on this?\" questions: \\`search_content\\` against the symbol BEFORE asserting impact.\n- Stay read-only. Never \\`run_command git commit\\`, never write files, never propose SEARCH/REPLACE blocks. The parent decides whether to act on your findings.\n- Cap yourself at ~12 tool calls. If the diff is too big to review in one pass, pick the riskiest 2-3 files and say so explicitly.\n\nWhat to look for, in priority order:\n1. **Correctness bugs** — off-by-one, null/undefined handling, race conditions, wrong sign / wrong operator, edge cases the code doesn't handle.\n2. **Security** — injection (SQL, shell, path traversal), secrets in code, missing authz checks, unsafe deserialization.\n3. **Behavior changes the diff hides** — renames that miss callers, removed branches that were load-bearing, error-handling that now swallows what used to surface.\n4. **Tests** — does the change have tests for the new behavior? Are existing tests still meaningful, or did the change make them tautological?\n5. **Style + consistency** — only flag deviations that matter (unsafe \\`any\\`, missing types in TypeScript, inconsistent error shape). Don't pile on cosmetic nits if the substance is clean.\n\nYour final answer:\n- Lead with a one-sentence verdict: \"ship as-is\" / \"minor nits, OK to ship after\" / \"blocking issues, do not ship\".\n- Then a short bulleted list of issues, each with: file:line citation + the problem in one sentence + what to change.\n- Group by severity if you have more than 4 items: **Blocking**, **Should-fix**, **Nits**.\n- If everything looks clean, say so plainly. Don't manufacture concerns.\n\n${NEGATIVE_CLAIM_RULE}\n\n${TUI_FORMATTING_RULES}\n\nThe 'task' the parent gave you describes WHAT to review (a branch, a file set, or \"the pending changes\"). Stay on it; don't redesign the feature.`;\n\nconst BUILTIN_SECURITY_REVIEW_BODY = `You are running as a security-review subagent. Your job is to inspect the changes the user is about to ship — usually the current git branch vs its upstream — through a security lens specifically, and report exploitable issues.\n\nHow to operate:\n- Default scope: the current branch's diff vs the default branch. If the user names a different range or a directory, honor that.\n- Discover scope first: \\`git status\\`, \\`git diff --stat\\`, \\`git diff <base>...HEAD\\`. Read touched files (\\`read_file\\`) when the diff alone doesn't carry security context — auth checks, input validation, the actual handler that calls into the changed function.\n- Use \\`search_content\\` to verify \"is this user-controlled input ever sanitized later?\" / \"are there other call sites that depend on this validation?\" before asserting impact.\n- Stay read-only. Never write, never run destructive commands, never propose SEARCH/REPLACE blocks. The parent decides what to act on.\n- Cap yourself at ~12 tool calls. If the diff is too big, focus on the riskiest 2-3 files and say so explicitly.\n\nThreat model — flag with severity:\n\n**CRITICAL** (do-not-ship):\n- SQL / NoSQL / shell / template injection — user input concatenated into a query, command, or template without parameterization.\n- Path traversal — user-controlled filenames touching the filesystem without canonicalization + sandbox check.\n- Authentication / authorization missing — endpoints / actions that should require a session check but don't.\n- Hardcoded secrets — API keys, passwords, signing tokens visible in the diff.\n- Deserialization of untrusted input — \\`pickle.loads\\`, \\`yaml.load\\` (non-safe), \\`eval\\`, \\`Function()\\`, \\`unserialize()\\`.\n- Cryptographic mistakes — homemade crypto, weak hashes (MD5/SHA-1) for passwords, missing IVs, ECB mode, predictable nonces.\n\n**HIGH**:\n- XSS — user input rendered into HTML without escaping (or wrong escaping context).\n- SSRF — fetching URLs from user input without an allowlist.\n- Race conditions in security-relevant code — TOCTOU on auth/file checks.\n- Open redirects — user-controlled URL passed to a redirect helper.\n- Insufficient logging on security events (login failure, permission denial) — only flag if the codebase clearly DOES log elsewhere.\n\n**MEDIUM**:\n- Verbose error messages leaking internal paths / stack traces / SQL.\n- Missing rate limiting on a credential / token endpoint.\n- Cross-origin / cookie-flag issues (missing \\`Secure\\` / \\`HttpOnly\\` / \\`SameSite\\`).\n\nThings to NOT pile on (out of scope here — the regular /review covers them):\n- Style, formatting, naming.\n- Performance, refactor opportunities, test coverage gaps that aren't security-relevant.\n- \"Should be a constant\" / \"extract this helper\" — irrelevant to ship-blocking.\n\nYour final answer:\n- Lead with a one-sentence verdict: \"no security issues found\", \"minor concerns\", or \"blocking issues\".\n- Then a list grouped by severity. Each item: file:line + 1-sentence threat + 1-sentence fix direction (no full SEARCH/REPLACE — the user / parent agent will write that).\n- If clean, say so plainly. Don't manufacture findings.\n\n${NEGATIVE_CLAIM_RULE}\n\n${TUI_FORMATTING_RULES}\n\nThe 'task' the parent gave you names what to review. Stay on it; don't redesign the feature.`;\n\nconst BUILTIN_TEST_BODY = `You are running as the parent agent — this skill is INLINED, not a subagent. The user invoked /test (or asked you to \"run the tests and fix failures\"). Your job: run the project's test suite, diagnose any failure, propose fixes as SEARCH/REPLACE edit blocks, then re-run. Repeat until green or you hit a wall you should escalate.\n\nHow to operate:\n\n1. **Detect the test command**.\n - Look for \\`package.json\\` → \\`scripts.test\\` first (most common: \\`npm test\\`, \\`pnpm test\\`, \\`yarn test\\`).\n - If no package.json or no test script: try \\`pytest\\`, \\`go test ./...\\`, \\`cargo test\\` based on what files exist (pyproject.toml/requirements.txt → pytest; go.mod → go test; Cargo.toml → cargo test).\n - If you can't tell, ASK the user for the command — don't guess. One question, one tool call to confirm.\n\n2. **Run it via run_command** (typical timeout 120s, bigger if the suite is large). Capture stdout + stderr.\n\n3. **Read the failures**. Pull out: which test names failed, the actual error/traceback, the file + line that threw. Don't just paraphrase — locate the exact assertion or stack frame.\n\n4. **Propose fixes**. For each distinct failure:\n - If the failure is in PRODUCTION code (test catches a real bug) → propose a SEARCH/REPLACE that fixes the production code.\n - If the failure is in TEST code (test is wrong, codebase is right) → propose a SEARCH/REPLACE that updates the test, AND say so explicitly: \"This is a test bug, not a production bug — updating the assertion.\"\n - If the failure is environmental (missing dep, wrong node version, missing fixture file) → say so and stop. Don't try to install packages or change config without checking with the user.\n\n5. **Apply + re-run**. After the user accepts the edit blocks, run the test command again. Iterate.\n\n6. **Stop conditions**:\n - All tests pass → report green, summarize what changed.\n - Same test still failing after 2 fix attempts on the same line → STOP. Tell the user \"I've tried twice, it's still failing — here's what I think is happening, want me to try a different angle?\". Don't loop indefinitely.\n - 3+ unrelated failures → fix one at a time, smallest first, so each pass narrows the surface.\n\nDon't:\n- Run \\`npm install\\` / \\`pip install\\` / \\`cargo update\\` without asking — those mutate lockfiles and have global effects.\n- Disable, skip, or delete failing tests to \"make it green\". If a test seems wrong, update its assertion with a one-sentence explanation, but never add \\`.skip\\` / \\`it.skip\\` / \\`@pytest.mark.skip\\`.\n- Modify the test runner config (vitest.config, jest.config, etc.) to silence failures.\n\nLead each turn with a one-line status: \"▸ running \\`npm test\\` ...\" → \"▸ 2 failures in tests/foo.test.ts — first is …\" → so the user always knows where you are without scrolling tool output.`;\n\nconst BUILTIN_SKILLS: readonly Skill[] = Object.freeze([\n Object.freeze<Skill>({\n name: \"explore\",\n description:\n \"Explore the codebase in an isolated subagent — wide-net read-only investigation that returns one distilled answer. Best for: 'find all places that...', 'how does X work across the project', 'survey the code for Y'.\",\n body: BUILTIN_EXPLORE_BODY,\n scope: \"builtin\",\n path: \"(builtin)\",\n runAs: \"subagent\",\n }),\n Object.freeze<Skill>({\n name: \"research\",\n description:\n \"Research a question by combining web search + code reading in an isolated subagent. Best for: 'is X feature supported by lib Y', 'what's the canonical way to do Z', 'compare our impl against the spec'.\",\n body: BUILTIN_RESEARCH_BODY,\n scope: \"builtin\",\n path: \"(builtin)\",\n runAs: \"subagent\",\n }),\n Object.freeze<Skill>({\n name: \"review\",\n description:\n \"Review the pending changes (current branch diff by default) in an isolated subagent — flags correctness, security, missing tests, hidden behavior changes; reports verdict + per-issue file:line. Read-only; the parent decides what to act on.\",\n body: BUILTIN_REVIEW_BODY,\n scope: \"builtin\",\n path: \"(builtin)\",\n runAs: \"subagent\",\n }),\n Object.freeze<Skill>({\n name: \"security-review\",\n description:\n \"Security-focused review of the current branch diff in an isolated subagent — flags injection/authz/secrets/deserialization/path-traversal/crypto issues, severity-tagged. Read-only. Use when shipping changes that touch auth, input parsing, file IO, or external requests.\",\n body: BUILTIN_SECURITY_REVIEW_BODY,\n scope: \"builtin\",\n path: \"(builtin)\",\n runAs: \"subagent\",\n }),\n Object.freeze<Skill>({\n name: \"test\",\n description:\n \"Run the project's test suite, diagnose failures, propose SEARCH/REPLACE fixes, re-run until green (or stop after 2 fix attempts on the same failure). Inlined — runs in the parent loop so you see the edit blocks and can /apply them. Detects npm/pnpm/yarn/pytest/go/cargo.\",\n body: BUILTIN_TEST_BODY,\n scope: \"builtin\",\n path: \"(builtin)\",\n runAs: \"inline\",\n }),\n]);\n"],"mappings":";;;AAeA,SAAS,cAAA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AAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA4LhC,mBAAmB;AAAA;AAAA,EAEnB,oBAAoB;AAAA;AAuBtB,IAAM,0BAA0B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBzB,SAAS,iBAAiB,SAAiB,OAAgC,CAAC,GAAW;AAC5F,QAAM,OAAO,KAAK,oBACd,GAAG,kBAAkB,GAAG,uBAAuB,KAC/C;AACJ,QAAM,aAAa,iBAAiB,MAAM,OAAO;AACjD,QAAM,gBAAgBG,MAAK,SAAS,YAAY;AAChD,MAAI,CAACC,YAAW,aAAa,EAAG,QAAO;AACvC,MAAI;AACJ,MAAI;AACF,cAAUC,cAAa,eAAe,MAAM;AAAA,EAC9C,QAAQ;AACN,WAAO;AAAA,EACT;AACA,QAAM,MAAM;AACZ,QAAM,YACJ,QAAQ,SAAS,MACb,GAAG,QAAQ,MAAM,GAAG,GAAG,CAAC;AAAA,oBAAkB,QAAQ,SAAS,GAAG,YAC9D;AACN,SAAO,GAAG,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOpB,SAAS;AAAA;AAAA;AAGX;","names":["existsSync","readFileSync","join","existsSync","readFileSync","readdirSync","homedir","join","resolve","existsSync","readFileSync","join","join","existsSync","readFileSync","resolve","join","existsSync","parseFrontmatter","homedir","readFileSync","readdirSync","join","existsSync","readFileSync"]}
|