reasonix 0.3.2 → 0.4.1

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 CHANGED
@@ -173,6 +173,38 @@ every message appended atomically, so killing the CLI never loses
173
173
  context. Oversized tool results auto-heal on load, so poisoning a
174
174
  session with one giant `read_file` doesn't brick your history.
175
175
 
176
+ ### Code mode — `npx reasonix code`
177
+
178
+ A thin opinionated layer on top of chat: filesystem MCP bridged at
179
+ `cwd`, coding system prompt, reasoner preset, per-directory session.
180
+ The model proposes edits as **SEARCH/REPLACE blocks**:
181
+
182
+ ```
183
+ src/foo.ts
184
+ <<<<<<< SEARCH
185
+ const x = 1;
186
+ =======
187
+ const x = 2;
188
+ >>>>>>> REPLACE
189
+ ```
190
+
191
+ Reasonix parses them out of each turn, applies them to disk, reports
192
+ `✓ applied src/foo.ts` in the TUI. SEARCH must match byte-for-byte;
193
+ we never fuzzy-match (silent wrong edits are worse than loud
194
+ rejections). Run `git diff` to review, `git checkout .` to undo.
195
+
196
+ ```bash
197
+ cd my-project
198
+ npx reasonix code # default: cwd, reasoner, per-dir session
199
+ npx reasonix code src/ # scope the filesystem sandbox tighter
200
+ npx reasonix code --no-session # ephemeral
201
+ ```
202
+
203
+ First-run sandbox: because code mode uses the filesystem MCP from
204
+ `@modelcontextprotocol/server-filesystem`, the model can only read
205
+ and write inside the directory you pointed at. It literally can't
206
+ touch files above that root.
207
+
176
208
  ### Advanced — CLI subcommands and flags
177
209
 
178
210
  ```bash
@@ -0,0 +1,81 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/code/prompt.ts
4
+ import { existsSync, readFileSync } from "fs";
5
+ import { join } from "path";
6
+ var CODE_SYSTEM_PROMPT = `You are Reasonix Code, a coding assistant. You have filesystem tools (read_file, write_file, list_directory, search_files, etc.) rooted at the user's working directory.
7
+
8
+ # When to edit vs. when to explore
9
+
10
+ Only 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:
11
+ - analyze, read, explore, describe, or summarize a project
12
+ - explain how something works
13
+ - answer a question about the code
14
+
15
+ In 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.
16
+
17
+ When you do propose edits, the user will review them and decide whether to \`/apply\` or \`/discard\`. Don't assume they'll accept \u2014 write as if each edit will be audited, because it will.
18
+
19
+ # Editing files
20
+
21
+ When you've been asked to change a file, output one or more SEARCH/REPLACE blocks in this exact format:
22
+
23
+ path/to/file.ext
24
+ <<<<<<< SEARCH
25
+ exact existing lines from the file, including whitespace
26
+ =======
27
+ the new lines
28
+ >>>>>>> REPLACE
29
+
30
+ Rules:
31
+ - 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.
32
+ - One edit per block. Multiple blocks in one response are fine.
33
+ - To create a new file, leave SEARCH empty:
34
+ path/to/new.ts
35
+ <<<<<<< SEARCH
36
+ =======
37
+ (whole file content here)
38
+ >>>>>>> REPLACE
39
+ - Do NOT use write_file to change existing files \u2014 the user reviews your edits as SEARCH/REPLACE. write_file is only for files you explicitly want to overwrite wholesale (rare).
40
+ - Paths are relative to the working directory. Don't use absolute paths.
41
+
42
+ # Exploration
43
+
44
+ - Avoid listing or reading inside these common dependency / build directories unless the user explicitly asks about them: node_modules, dist, build, out, .next, .nuxt, .svelte-kit, .git, .venv, venv, __pycache__, target, coverage, .turbo, .cache. They're expensive and usually irrelevant.
45
+ - Prefer search_files / grep over list_directory when you know roughly what you're looking for \u2014 it saves context and avoids enumerating huge trees.
46
+
47
+ # Style
48
+
49
+ - Show edits; don't narrate them in prose. "Here's the fix:" is enough.
50
+ - One short paragraph explaining *why*, then the blocks.
51
+ - If you need to explore first (list / grep / read), do it with tool calls before writing any prose \u2014 silence while exploring is fine.
52
+ `;
53
+ function codeSystemPrompt(rootDir) {
54
+ const gitignorePath = join(rootDir, ".gitignore");
55
+ if (!existsSync(gitignorePath)) return CODE_SYSTEM_PROMPT;
56
+ let content;
57
+ try {
58
+ content = readFileSync(gitignorePath, "utf8");
59
+ } catch {
60
+ return CODE_SYSTEM_PROMPT;
61
+ }
62
+ const MAX = 2e3;
63
+ const truncated = content.length > MAX ? `${content.slice(0, MAX)}
64
+ \u2026 (truncated ${content.length - MAX} chars)` : content;
65
+ return `${CODE_SYSTEM_PROMPT}
66
+
67
+ # Project .gitignore
68
+
69
+ The user's repo ships this .gitignore \u2014 treat every pattern as "don't traverse or edit inside these paths unless explicitly asked":
70
+
71
+ \`\`\`
72
+ ${truncated}
73
+ \`\`\`
74
+ `;
75
+ }
76
+
77
+ export {
78
+ CODE_SYSTEM_PROMPT,
79
+ codeSystemPrompt
80
+ };
81
+ //# sourceMappingURL=chunk-2P2MZLCE.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/code/prompt.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\";\n\nexport const CODE_SYSTEM_PROMPT = `You are Reasonix Code, a coding assistant. You have filesystem tools (read_file, write_file, list_directory, search_files, etc.) rooted at the user's working directory.\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\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# Exploration\n\n- Avoid listing or reading inside these common dependency / build directories unless the user explicitly asks about them: node_modules, dist, build, out, .next, .nuxt, .svelte-kit, .git, .venv, venv, __pycache__, target, coverage, .turbo, .cache. They're expensive and usually irrelevant.\n- Prefer search_files / grep over list_directory when you know roughly what you're looking for — it saves context and avoids enumerating huge trees.\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 / grep / read), do it with tool calls before writing any prose — silence while exploring is fine.\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 * Missing or unreadable .gitignore → returns the base prompt unchanged.\n */\nexport function codeSystemPrompt(rootDir: string): string {\n const gitignorePath = join(rootDir, \".gitignore\");\n if (!existsSync(gitignorePath)) return CODE_SYSTEM_PROMPT;\n let content: string;\n try {\n content = readFileSync(gitignorePath, \"utf8\");\n } catch {\n return CODE_SYSTEM_PROMPT;\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 `${CODE_SYSTEM_PROMPT}\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"],"mappings":";;;AAeA,SAAS,YAAY,oBAAoB;AACzC,SAAS,YAAY;AAEd,IAAM,qBAAqB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAwD3B,SAAS,iBAAiB,SAAyB;AACxD,QAAM,gBAAgB,KAAK,SAAS,YAAY;AAChD,MAAI,CAAC,WAAW,aAAa,EAAG,QAAO;AACvC,MAAI;AACJ,MAAI;AACF,cAAU,aAAa,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,kBAAkB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAO5B,SAAS;AAAA;AAAA;AAGX;","names":[]}