nox-mem 3.8.0 → 3.9.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
@@ -84,6 +84,8 @@ nox-mem stats
84
84
  |---|---|---|
85
85
  | `NOX_DB_PATH` | `~/.nox-mem/nox.db` | SQLite database path. A missing parent directory is created (mode 0700). Its directory is auto-added to the op-audit allowlist. |
86
86
  | `NOX_MEM_DIR` | — | **Not** the notes folder: nothing ingests or watches it. It only sets where pre-op snapshots go (`$NOX_MEM_DIR/.nox-snapshots`) and widens the op-audit allowlist. |
87
+ | `NOX_MEM_SCOPE` | unset | One sentence naming what the memory covers; the MCP server puts it in its `instructions` so the agent knows when a search can help. Without it the server sends no `instructions` (3.9.1+). Recommended, see [Key commands](#key-commands). Collapsed to one line, capped at 800 characters. |
88
+ | `NOX_MEM_INSTRUCTIONS` | unset | `off` sends no `instructions` even with a scope; `unscoped` sends the generic text when `NOX_MEM_SCOPE` is unset (it searches on unrelated changes too). Unset: instructions only when `NOX_MEM_SCOPE` is set. |
87
89
  | `NOX_ALLOW_PROD_INGEST` | — | `1` skips the large-database ingest guard (same as `--allow-prod`). See [Large databases](#large-databases-the-ingest-guard). |
88
90
 
89
91
  ### API server
@@ -257,9 +259,25 @@ nox-mem --help — full command reference
257
259
  Wire the MCP server into Claude Code:
258
260
 
259
261
  ```bash
260
- claude mcp add nox-mem -e NOX_DB_PATH="$HOME/.nox-mem/nox.db" -e GEMINI_API_KEY="$GEMINI_API_KEY" -- nox-mem-mcp
262
+ claude mcp add nox-mem -e NOX_DB_PATH="$HOME/.nox-mem/nox.db" -e GEMINI_API_KEY="$GEMINI_API_KEY" \
263
+ -e NOX_MEM_SCOPE="the billing API and its deploy pipeline, and the data warehouse" -- nox-mem-mcp
261
264
  ```
262
265
 
266
+ **Say what the memory covers (`NOX_MEM_SCOPE`).** An agent that is never told the memory holds
267
+ something relevant does not search it: in our evaluation (Claude Code, Sonnet 5.5) an agent with
268
+ the MCP server connected and no other guidance searched in 5% of tasks that needed the memory and
269
+ answered 7% of them right. The server now sends MCP `instructions` (the one server-side text that
270
+ clients keep in context before the agent picks a tool) saying when to search. With a one-sentence
271
+ scope in `NOX_MEM_SCOPE`, the same tasks were answered right 53% of the time, and the agent
272
+ searched on 2% of control tasks that the memory could not help with. Without a scope the server
273
+ sends no instructions (since 3.9.1): a generic version was about as accurate (56%), but it also
274
+ searched on a third of unrelated configuration changes, so it is only sent if you ask for it with
275
+ `NOX_MEM_INSTRUCTIONS=unscoped`. So set the scope: name the projects or systems your memory holds,
276
+ in one sentence, as you would to a new colleague. `NOX_MEM_INSTRUCTIONS=off` sends no instructions
277
+ even with a scope.
278
+ These numbers are from one model, one client and one corpus; the instructions did not make the
279
+ agent record decisions (`nox_mem_decision_set`) any more often.
280
+
263
281
  HTTP endpoints worth knowing: `GET /api/health`, `GET /api/search?q=`, `GET /api/brief`, `POST /api/answer`, `GET /api/kg`, and `GET /api/reflect?q=…` (synthesis over memory + KG; `q` is required, a request without it is a 400).
264
282
 
265
283
  The temporal filter is also on HTTP (`?as_of=` / `?changed_since=` on `/api/search`, or the same keys in a POST body) and MCP (`as_of` / `changed_since` on `nox_mem_search`). `answer` takes it too: `--as-of` / `--changed-since` on the CLI, and `as_of` / `changed_since` on `POST /api/answer` and on the `nox_mem_answer` MCP tool. A bad or blank date gives exit 2 / HTTP 400 / MCP `isError`. It is a hard SQL pre-filter on `created_at` / `updated_at` (ingestion time), not a ranking boost. `as_of` answers *which chunks existed then*, not *what they said then*: there is no version history, so a chunk edited after the date comes back with its current text. A bare date means the whole day in UTC (`--as-of 2026-05-01` includes 23:59 that day; `--changed-since 2026-05-01` starts at 00:00); a time without an offset is read as UTC. An unparseable date is an error on every surface (exit 2 / HTTP 400 / MCP `isError`), never a silently unfiltered search.
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Text the MCP server sends in the `instructions` field of its `initialize` result.
3
+ *
4
+ * Why it exists: MCP clients such as Claude Code defer tool schemas, so the model sees only tool
5
+ * names until it decides to search. A tool description is read after that decision, never before
6
+ * it. `instructions` is the one server-side channel that is always in context (Claude Code puts it
7
+ * in the system prompt), so it is where "when to search" has to live.
8
+ *
9
+ * Both texts below were measured, word for word, in the skill evaluation (Claude Code, Sonnet 5.5,
10
+ * 36 memory-dependent tasks and 20 control tasks, 3 replicas):
11
+ *
12
+ * - scoped (NOX_MEM_SCOPE set): pass rate 0.07 -> 0.53, +0.46 [0.32, 0.61]; searches on control
13
+ * tasks that do not need the memory +1.7 pp; median token overhead +2.1%.
14
+ * - unscoped (NOX_MEM_SCOPE unset): pass rate 0.07 -> 0.56, +0.49 [0.35, 0.63], but it searched
15
+ * on about one in three unrelated configuration changes (+31.7 pp).
16
+ *
17
+ * Only the scoped text passed the evaluation's decision rule, so it is the only one sent by default:
18
+ * with no NOX_MEM_SCOPE the field is omitted (3.9.1; 3.9.0 sent the unscoped text). The unscoped
19
+ * text stays available on explicit request, NOX_MEM_INSTRUCTIONS=unscoped, with the cost above.
20
+ *
21
+ * Edits to the wording are edits to a measured intervention: the tests pin both texts, and a
22
+ * change should come with a new run.
23
+ */
24
+ const MAX_SCOPE_CHARS = 800;
25
+ const SCOPED_INTRO = (scope) => `nox-mem holds this user's past work on one scope: ${scope}. It holds decisions, incidents, ` +
26
+ `measurements and notes about that scope. You cannot see it unless you search, and the usual ` +
27
+ `failure is not searching at all, because the task never names what the memory holds.`;
28
+ const SCOPED_WHEN = "Search nox-mem before acting when the task touches that scope and: you are about to change, or " +
29
+ "recommend changing, a setting, default, threshold, retention, schedule, schema, model or " +
30
+ "dependency (past decisions often forbid the obvious change); you are explaining why something is " +
31
+ "the way it is or what was decided; you are about to state a number about it; an error looks like " +
32
+ "it may have happened before. Also search when the task names a project or person you do not " +
33
+ "recognize. Do not search for software outside that scope (a setting of some other service, say), " +
34
+ "for general knowledge, or for a fully specified code change.";
35
+ const UNSCOPED_INTRO = "nox-mem holds this user's past work: decisions, incidents, measurements, notes. You cannot see " +
36
+ "it unless you search, and the usual failure is not searching at all, because the task never " +
37
+ "names what the memory holds.";
38
+ const UNSCOPED_WHEN = "Search nox-mem before acting when: you are about to change, or recommend changing, a setting, " +
39
+ "default, threshold, retention, schedule, schema, model or dependency (past decisions often forbid " +
40
+ "the obvious change); you are explaining why something is the way it is or what was decided; the " +
41
+ "task mentions a project, system or person you do not recognize; you are about to state a number " +
42
+ "about this project; an error looks like it may have happened before. Do not search for general " +
43
+ "knowledge or a fully specified code change.";
44
+ const HOW = "How: nox_mem_search with 3 to 8 distinctive nouns; nox_mem_get for the full text of a hit; " +
45
+ "nox_mem_decision_get or nox_mem_decision_list for recorded rules. Stop after three searches and " +
46
+ "say so if nothing relevant comes back. Treat results as dated evidence and name the source you " +
47
+ "relied on.";
48
+ // Measured with no effect on writing (0 of 30 runs wrote when the user stated a decision); kept
49
+ // because it is what was measured with the rest, not because it works.
50
+ const WRITE = "Write when the user states a decision (nox_mem_decision_set, stable slug key, with the reason) or " +
51
+ "a root cause is confirmed. Do not write what git already records.";
52
+ /** Normalise a user-supplied scope: one line, no trailing period, bounded length. */
53
+ export function normaliseScope(raw) {
54
+ if (!raw)
55
+ return "";
56
+ let s = raw.replace(/\s+/g, " ").trim().replace(/\.+$/, "").trim();
57
+ if (s.length > MAX_SCOPE_CHARS)
58
+ s = s.slice(0, MAX_SCOPE_CHARS).replace(/\s+\S*$/, "");
59
+ return s;
60
+ }
61
+ /**
62
+ * Build the `instructions` text, or undefined so the caller omits the field:
63
+ * NOX_MEM_INSTRUCTIONS=off|0|false -> undefined, even with a scope
64
+ * NOX_MEM_SCOPE set -> scoped text (the one that passed)
65
+ * NOX_MEM_INSTRUCTIONS=unscoped -> unscoped text (searched on ~1 in 3 unrelated config changes)
66
+ * otherwise -> undefined
67
+ */
68
+ export function serverInstructions(env = process.env) {
69
+ const mode = (env.NOX_MEM_INSTRUCTIONS || "").trim().toLowerCase();
70
+ if (mode === "off" || mode === "0" || mode === "false")
71
+ return undefined;
72
+ const scope = normaliseScope(env.NOX_MEM_SCOPE);
73
+ if (scope)
74
+ return [SCOPED_INTRO(scope), SCOPED_WHEN, HOW, WRITE].join("\n\n");
75
+ if (mode === "unscoped")
76
+ return [UNSCOPED_INTRO, UNSCOPED_WHEN, HOW, WRITE].join("\n\n");
77
+ return undefined;
78
+ }
@@ -17,14 +17,18 @@ import { createInterface } from "readline";
17
17
  import { VERSION } from "./version.js";
18
18
  import { parseTemporalFilter } from "./lib/dates.js";
19
19
  import { noxMemAnswerTool } from "./mcp/tools/answer.js";
20
+ import { serverInstructions } from "./mcp-instructions.js";
20
21
  const SERVER_INFO = {
21
22
  name: "nox-mem",
22
23
  version: VERSION,
23
24
  };
25
+ // When to search lives here, not in tool descriptions: clients that defer tool schemas show the model
26
+ // only tool names until it has already decided to search. See mcp-instructions.ts.
27
+ const INSTRUCTIONS = serverInstructions();
24
28
  const TOOLS = [
25
29
  {
26
30
  name: "nox_mem_search",
27
- description: "Search nox-mem memory using FTS5 full-text search with BM25 ranking, type boosting, and recency scoring",
31
+ description: "Search this user's project memory (decisions, incidents, measurements, notes) with hybrid full-text and semantic ranking. Use before changing a setting, default, threshold, schedule, schema, model or dependency, or before explaining why something is the way it is: past decisions often forbid the obvious change. Returns each hit's chunk id, source, date and text.",
28
32
  inputSchema: {
29
33
  type: "object",
30
34
  properties: {
@@ -162,7 +166,7 @@ const TOOLS = [
162
166
  },
163
167
  {
164
168
  name: "nox_mem_decision_set",
165
- description: "Set/update a versioned decision. Stores full history — every call creates a new version. Use for technical decisions, policies, or operational rules that may evolve.",
169
+ description: "Record a decision the user states, with its reason, as a versioned entry (every call creates a new version). Use when the user decides something mid-task, or a root cause or operational rule is confirmed.",
166
170
  inputSchema: {
167
171
  type: "object",
168
172
  properties: {
@@ -255,6 +259,7 @@ async function handleRequest(req) {
255
259
  protocolVersion: "2024-11-05",
256
260
  capabilities: { tools: {} },
257
261
  serverInfo: SERVER_INFO,
262
+ ...(INSTRUCTIONS ? { instructions: INSTRUCTIONS } : {}),
258
263
  });
259
264
  break;
260
265
  case "notifications/initialized":
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nox-mem",
3
- "version": "3.8.0",
3
+ "version": "3.9.1",
4
4
  "description": "Pain-weighted hybrid memory engine: FTS5 + semantic search + knowledge graph, self-hosted on any Linux VPS.",
5
5
  "type": "module",
6
6
  "license": "MIT",