reasonix 0.4.15 → 0.4.17

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
@@ -143,11 +143,33 @@ worse than visible rejections.
143
143
  inline clip isn't enough).
144
144
  - `/think` — see the model's full R1 reasoning for the last turn
145
145
  (reasoner preset only).
146
+ - `/memory` — show the project's `REASONIX.md` (see below).
146
147
  - `/undo` — roll back the last applied edit batch.
147
148
  - `/new` — start fresh in the same directory without losing the
148
149
  session file.
149
150
  - Drop `--no-session` for an ephemeral session that doesn't persist.
150
151
 
152
+ ### Project memory — `REASONIX.md`
153
+
154
+ Drop a `REASONIX.md` in the project root and its contents are pinned
155
+ into the immutable-prefix system prompt every time you launch
156
+ `reasonix` in that directory. Good for house conventions, domain
157
+ glossary, or things the model keeps forgetting:
158
+
159
+ ```bash
160
+ cat > REASONIX.md <<'EOF'
161
+ # Notes for Reasonix
162
+ - Use snake_case for new Python modules; legacy camelCase modules keep their style.
163
+ - `cargo check` is in the auto-run allowlist; full `cargo test` needs confirmation.
164
+ - The `api/` dir mirrors `backend/` — keep schemas in sync.
165
+ EOF
166
+ ```
167
+
168
+ Re-launch (or `/new`) to pick it up; the prefix is hashed once per
169
+ session to keep the DeepSeek cache warm. `/memory` prints what's
170
+ currently pinned. `REASONIX_MEMORY=off` disables the lookup for CI /
171
+ offline repro.
172
+
151
173
  ```bash
152
174
  npx reasonix code src/ # narrower sandbox (only src/ is writable)
153
175
  npx reasonix code --no-session # ephemeral — nothing saved to disk
@@ -1,8 +1,53 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/code/prompt.ts
4
+ import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
5
+ import { join as join2 } from "path";
6
+
7
+ // src/project-memory.ts
4
8
  import { existsSync, readFileSync } from "fs";
5
9
  import { join } from "path";
10
+ var PROJECT_MEMORY_FILE = "REASONIX.md";
11
+ var PROJECT_MEMORY_MAX_CHARS = 8e3;
12
+ function readProjectMemory(rootDir) {
13
+ const path = join(rootDir, PROJECT_MEMORY_FILE);
14
+ if (!existsSync(path)) return null;
15
+ let raw;
16
+ try {
17
+ raw = readFileSync(path, "utf8");
18
+ } catch {
19
+ return null;
20
+ }
21
+ const trimmed = raw.trim();
22
+ if (!trimmed) return null;
23
+ const originalChars = trimmed.length;
24
+ const truncated = originalChars > PROJECT_MEMORY_MAX_CHARS;
25
+ const content = truncated ? `${trimmed.slice(0, PROJECT_MEMORY_MAX_CHARS)}
26
+ \u2026 (truncated ${originalChars - PROJECT_MEMORY_MAX_CHARS} chars)` : trimmed;
27
+ return { path, content, originalChars, truncated };
28
+ }
29
+ function memoryEnabled() {
30
+ const env = process.env.REASONIX_MEMORY;
31
+ if (env === "off" || env === "false" || env === "0") return false;
32
+ return true;
33
+ }
34
+ function applyProjectMemory(basePrompt, rootDir) {
35
+ if (!memoryEnabled()) return basePrompt;
36
+ const mem = readProjectMemory(rootDir);
37
+ if (!mem) return basePrompt;
38
+ return `${basePrompt}
39
+
40
+ # Project memory (REASONIX.md)
41
+
42
+ The user pinned these notes about this project \u2014 treat them as authoritative context for every turn:
43
+
44
+ \`\`\`
45
+ ${mem.content}
46
+ \`\`\`
47
+ `;
48
+ }
49
+
50
+ // src/code/prompt.ts
6
51
  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
52
 
8
53
  # When to edit vs. when to explore
@@ -51,18 +96,19 @@ Rules:
51
96
  - 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
97
  `;
53
98
  function codeSystemPrompt(rootDir) {
54
- const gitignorePath = join(rootDir, ".gitignore");
55
- if (!existsSync(gitignorePath)) return CODE_SYSTEM_PROMPT;
99
+ const withMemory = applyProjectMemory(CODE_SYSTEM_PROMPT, rootDir);
100
+ const gitignorePath = join2(rootDir, ".gitignore");
101
+ if (!existsSync2(gitignorePath)) return withMemory;
56
102
  let content;
57
103
  try {
58
- content = readFileSync(gitignorePath, "utf8");
104
+ content = readFileSync2(gitignorePath, "utf8");
59
105
  } catch {
60
- return CODE_SYSTEM_PROMPT;
106
+ return withMemory;
61
107
  }
62
108
  const MAX = 2e3;
63
109
  const truncated = content.length > MAX ? `${content.slice(0, MAX)}
64
110
  \u2026 (truncated ${content.length - MAX} chars)` : content;
65
- return `${CODE_SYSTEM_PROMPT}
111
+ return `${withMemory}
66
112
 
67
113
  # Project .gitignore
68
114
 
@@ -75,7 +121,11 @@ ${truncated}
75
121
  }
76
122
 
77
123
  export {
124
+ PROJECT_MEMORY_FILE,
125
+ readProjectMemory,
126
+ memoryEnabled,
127
+ applyProjectMemory,
78
128
  CODE_SYSTEM_PROMPT,
79
129
  codeSystemPrompt
80
130
  };
81
- //# sourceMappingURL=chunk-2P2MZLCE.js.map
131
+ //# sourceMappingURL=chunk-3YQRWFES.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/code/prompt.ts","../../src/project-memory.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 { applyProjectMemory } from \"../project-memory.js\";\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 * Stacking order (stable for cache prefix):\n * base prompt → project memory (REASONIX.md) → .gitignore block\n */\nexport function codeSystemPrompt(rootDir: string): string {\n const withMemory = applyProjectMemory(CODE_SYSTEM_PROMPT, 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 * 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"],"mappings":";;;AAeA,SAAS,cAAAA,aAAY,gBAAAC,qBAAoB;AACzC,SAAS,QAAAC,aAAY;;;ACKrB,SAAS,YAAY,oBAAoB;AACzC,SAAS,YAAY;AAEd,IAAM,sBAAsB;AAC5B,IAAM,2BAA2B;AAkBjC,SAAS,kBAAkB,SAAuC;AACvE,QAAM,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