reasonix 0.4.17 → 0.4.20

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reasonix",
3
- "version": "0.4.17",
3
+ "version": "0.4.20",
4
4
  "description": "DeepSeek-native agent framework: cache-first loop, R1 thought harvesting, tool-call repair.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,131 +0,0 @@
1
- #!/usr/bin/env node
2
-
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
8
- import { existsSync, readFileSync } from "fs";
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
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.
52
-
53
- # When to edit vs. when to explore
54
-
55
- 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:
56
- - analyze, read, explore, describe, or summarize a project
57
- - explain how something works
58
- - answer a question about the code
59
-
60
- 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.
61
-
62
- 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.
63
-
64
- # Editing files
65
-
66
- When you've been asked to change a file, output one or more SEARCH/REPLACE blocks in this exact format:
67
-
68
- path/to/file.ext
69
- <<<<<<< SEARCH
70
- exact existing lines from the file, including whitespace
71
- =======
72
- the new lines
73
- >>>>>>> REPLACE
74
-
75
- Rules:
76
- - 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.
77
- - One edit per block. Multiple blocks in one response are fine.
78
- - To create a new file, leave SEARCH empty:
79
- path/to/new.ts
80
- <<<<<<< SEARCH
81
- =======
82
- (whole file content here)
83
- >>>>>>> REPLACE
84
- - 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).
85
- - Paths are relative to the working directory. Don't use absolute paths.
86
-
87
- # Exploration
88
-
89
- - 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.
90
- - 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.
91
-
92
- # Style
93
-
94
- - Show edits; don't narrate them in prose. "Here's the fix:" is enough.
95
- - One short paragraph explaining *why*, then the blocks.
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.
97
- `;
98
- function codeSystemPrompt(rootDir) {
99
- const withMemory = applyProjectMemory(CODE_SYSTEM_PROMPT, rootDir);
100
- const gitignorePath = join2(rootDir, ".gitignore");
101
- if (!existsSync2(gitignorePath)) return withMemory;
102
- let content;
103
- try {
104
- content = readFileSync2(gitignorePath, "utf8");
105
- } catch {
106
- return withMemory;
107
- }
108
- const MAX = 2e3;
109
- const truncated = content.length > MAX ? `${content.slice(0, MAX)}
110
- \u2026 (truncated ${content.length - MAX} chars)` : content;
111
- return `${withMemory}
112
-
113
- # Project .gitignore
114
-
115
- The user's repo ships this .gitignore \u2014 treat every pattern as "don't traverse or edit inside these paths unless explicitly asked":
116
-
117
- \`\`\`
118
- ${truncated}
119
- \`\`\`
120
- `;
121
- }
122
-
123
- export {
124
- PROJECT_MEMORY_FILE,
125
- readProjectMemory,
126
- memoryEnabled,
127
- applyProjectMemory,
128
- CODE_SYSTEM_PROMPT,
129
- codeSystemPrompt
130
- };
131
- //# sourceMappingURL=chunk-3YQRWFES.js.map
@@ -1 +0,0 @@
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;AAC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