@bli-cockpit/memory-mcp 0.1.4 → 0.1.5

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
@@ -101,14 +101,21 @@ every machine:
101
101
  `[bli-memory] prompt ok {"hits":0,"elapsed_ms":140,"deadline_ms":3000}`,
102
102
  `[bli-memory] prompt skipped {"reason":"no_prompt"}`, or
103
103
  `[bli-memory] prompt failed {"reason":"dashboard_unreachable","elapsed_ms":2201,"deadline_ms":3000}`.
104
- `reason` on `skipped`/`failed` is always one of a closed set — `timeout`,
105
- `http_<status>`, `unpaired`, `dashboard_unreachable`, `bad_response`,
106
- `no_prompt`, plus three Stop-only local skips (`reentrant`, `no_transcript`,
104
+ `reason` on `skipped`/`failed` is always one of a closed set — the four
105
+ network reasons `timeout`, `http_<status>`, `dashboard_unreachable`,
106
+ `bad_response` (Tower answered with a body that was not readable JSON);
107
+ the six `StdinFailure` reasons `no_stdin`, `stdin_empty`, `stdin_timeout`,
108
+ `stdin_too_large`, `stdin_unreadable`, `stdin_malformed` — each its own
109
+ literal, never folded into `bad_response`, because a malformed payload from
110
+ the host never touched the network (BLI-3700); `unpaired`, `no_prompt`,
111
+ plus three Stop-only local skips (`reentrant`, `no_transcript`,
107
112
  `redaction_failed`) — never a stack trace, never Tower's own error text,
108
- never a prompt, a memory, a path or a token. A `failed` outcome also gets a
109
- one-line `systemMessage` (the same JSON-on-stdout shape the Supermemory
110
- plugin's own banner uses), because Claude Code does not surface a hook's
111
- stderr anywhere a person reads it.
113
+ never a prompt, a memory, a path or a token. A reason `toLogReason` has not
114
+ been taught becomes `unknown_internal:<name>`, never a silent
115
+ `bad_response`. A `failed` outcome also gets a one-line `systemMessage` (the
116
+ same JSON-on-stdout shape the Supermemory plugin's own banner uses),
117
+ because Claude Code does not surface a hook's stderr anywhere a person
118
+ reads it.
112
119
 
113
120
  `hook stop` sends the last user/assistant exchange (at most 12 KB, tail-read so
114
121
  a 40 MB transcript costs nothing) through the collector's own redactor —
@@ -93,6 +93,14 @@ export interface HookOutcome {
93
93
  chars?: number;
94
94
  /** How many secret-like spans were masked before a save. A count, never a value. */
95
95
  masked?: number;
96
+ /**
97
+ * BLI-3718: how many extracted facts collided with another live memory's
98
+ * custom_id rather than being written. Counted SEPARATELY from `saved` so a
99
+ * session where every candidate conflicted reads as `custom_id_conflict`,
100
+ * never as `nothing_worth_keeping` — the two used to be indistinguishable at
101
+ * HTTP 200.
102
+ */
103
+ conflicts?: number;
96
104
  }
97
105
  /** The container this hook's memories live in, and how it was derived. */
98
106
  export interface HookContainer {
@@ -110,11 +118,32 @@ export declare const RECALL_BLOCK: {
110
118
  };
111
119
  /** The vendor plugin's bullet, kept byte for byte so the injection reads the same. */
112
120
  export declare const BULLET = "\u25EA";
113
- /** The per-prompt recall shape the `/v4/profile` shim documents: top 5, ≥ 0.55. */
121
+ /**
122
+ * The vendor's own per-prompt recall floor. Kept only as the FALLBACK for a
123
+ * door old enough not to send its own `semanticFloor` on the search response
124
+ * (BLI-3697 tick 8) — the live floor is read from that response, never
125
+ * hardcoded here, because three tickets already moved the door's real
126
+ * number (0.55 -> 0.30 -> 0.65) while this constant sat still.
127
+ */
114
128
  export declare const RECALL_MIN_SIMILARITY = 0.55;
115
129
  export declare const RECALL_LIMIT = 5;
116
130
  /** One recalled line, capped. The vendor truncated at 300 characters. */
117
131
  export declare const RECALL_LINE_CHARS = 300;
132
+ /**
133
+ * One recalled memory, its text and when it was written (BLI-3697 tick 8).
134
+ * A fact that changes over time — a version number, a decision, a status —
135
+ * read back with no date is a trap: the QA loop found a `min_cli_version`
136
+ * row from 2026-08-18 answering "what is the CLI floor" at rank 1, true in
137
+ * August and wrong by the time it was read. `renderRecall` prefixes every
138
+ * line with its date rather than trying to decide which rows count as
139
+ * "stale" — that judgment belongs to whoever reads the recall, and they
140
+ * cannot make it at all if the date is missing.
141
+ */
142
+ export interface RecalledHit {
143
+ text: string;
144
+ /** ISO timestamp, or `null` when the door did not send one. */
145
+ createdAt: string | null;
146
+ }
118
147
  /** The search door refuses a query over 1000 characters; a long prompt is trimmed, not dropped. */
119
148
  export declare const MAX_QUERY_CHARS = 1000;
120
149
  /** At most the final 12 KB of the last exchange travels to `save`. */
@@ -57,7 +57,13 @@ export const RECALL_BLOCK = {
57
57
  };
58
58
  /** The vendor plugin's bullet, kept byte for byte so the injection reads the same. */
59
59
  export const BULLET = "◪";
60
- /** The per-prompt recall shape the `/v4/profile` shim documents: top 5, ≥ 0.55. */
60
+ /**
61
+ * The vendor's own per-prompt recall floor. Kept only as the FALLBACK for a
62
+ * door old enough not to send its own `semanticFloor` on the search response
63
+ * (BLI-3697 tick 8) — the live floor is read from that response, never
64
+ * hardcoded here, because three tickets already moved the door's real
65
+ * number (0.55 -> 0.30 -> 0.65) while this constant sat still.
66
+ */
61
67
  export const RECALL_MIN_SIMILARITY = 0.55;
62
68
  export const RECALL_LIMIT = 5;
63
69
  /** One recalled line, capped. The vendor truncated at 300 characters. */
@@ -23,28 +23,42 @@
23
23
  * same shape so a real failure — not a quiet turn — is the one case a
24
24
  * person actually sees something.
25
25
  *
26
- * **The reason vocabulary is closed and lives HERE, in one module.** Six
27
- * members answer the ticket's own question (can a timeout, a 5xx, a dead
28
- * dashboard and "nothing to say" be told apart?): `timeout`, `http_<status>`,
29
- * `unpaired`, `dashboard_unreachable`, `bad_response`, `no_prompt`. Three more
30
- * cover skip states that are local to one hook and never touch the network —
31
- * `reentrant` (Stop, re-entrant), `no_transcript` (Stop, nothing to read yet)
32
- * and `redaction_failed` (Stop, the masking pass itself failed) kept as
33
- * their own fixed literals rather than folded into a network bucket, because
34
- * calling a re-entrant Stop hook `bad_response` would tell an operator a
35
- * request failed when nothing was even attempted. Every one of the nine is a
36
- * compile-time literal from OUR OWN code; none of them is `response.body`
37
- * text, an `error.message`, or a stack trace (`door.ts`'s `doorReason` already
38
- * enforces that at the source for the network four). `toLogReason` maps every
39
- * other internal reason string this package can produce onto one of the nine,
40
- * and anything it does not recognise a future reason nobody wired in here —
41
- * falls back to `bad_response` rather than printing unbounded text.
26
+ * **The reason vocabulary is closed and lives HERE, in one module.** Four
27
+ * members answer the network half of the ticket's own question (can a
28
+ * timeout, a 5xx and a dead dashboard be told apart?): `timeout`,
29
+ * `http_<status>`, `dashboard_unreachable`, `bad_response` the last of
30
+ * those meaning specifically "Tower answered with a status but a body that
31
+ * was not readable JSON" (`door.ts`'s `doorReason`). Six more are the
32
+ * **caller's own stdin**, one per `stdin.ts` `StdinFailure` member
33
+ * `no_stdin`, `stdin_empty`, `stdin_timeout`, `stdin_too_large`,
34
+ * `stdin_unreadable`, `stdin_malformed` kept as their OWN literals rather
35
+ * than folded into `bad_response`, because a malformed payload from the host
36
+ * never touched the network at all (BLI-3700, QA tick 6 NEW-9: a plain-text
37
+ * stdin payload printed `bad_response` and read as a Tower outage for four
38
+ * runs that never made a request). `unpaired` and `no_prompt` round those
39
+ * out, and three more cover skip states local to one hook that never touch
40
+ * the network either`reentrant` (Stop, re-entrant), `no_transcript`
41
+ * (Stop, nothing to read yet) and `redaction_failed` (Stop, the masking pass
42
+ * itself failed). Every member is a compile-time literal from OUR OWN code;
43
+ * none of them is `response.body` text, an `error.message`, or a stack trace
44
+ * (`door.ts`'s `doorReason` already enforces that at the source for the
45
+ * network four). `toLogReason` maps every other internal reason string this
46
+ * package can produce onto one of these, and anything it does not recognise —
47
+ * a future reason nobody wired in here — becomes `unknown_internal:<name>`,
48
+ * never a silent `bad_response`: a reason this table has not been taught must
49
+ * say so, not point at the wrong system.
42
50
  */
43
51
  import type { HookEvent, HookOutcome, HookStatus } from "./contract.js";
44
52
  import type { DoorFailureReason } from "../door.js";
53
+ import type { StdinFailure } from "./stdin.js";
45
54
  export declare const HOOK_LOG_TAG = "[bli-memory]";
46
- /** The closed set. Nine literals plus the parameterised `http_<status>` family. */
47
- export type HookLogReason = DoorFailureReason | "unpaired" | "no_prompt" | "reentrant" | "no_transcript" | "redaction_failed";
55
+ /**
56
+ * The closed set: the door's four network members, the six `StdinFailure`
57
+ * members (BLI-3700 — never folded into a door reason), five more fixed
58
+ * local literals, and the `unknown_internal:<name>` escape hatch for a
59
+ * reason `toLogReason` has not been taught.
60
+ */
61
+ export type HookLogReason = DoorFailureReason | StdinFailure | "unpaired" | "no_prompt" | "reentrant" | "no_transcript" | "redaction_failed" | `unknown_internal:${string}`;
48
62
  /** The word printed after the event name. `empty` (ran fine, nothing to say) prints as `ok`. */
49
63
  export type HookLogWord = "ok" | "skipped" | "failed";
50
64
  export declare function logWordFor(status: HookStatus): HookLogWord;
@@ -23,22 +23,30 @@
23
23
  * same shape so a real failure — not a quiet turn — is the one case a
24
24
  * person actually sees something.
25
25
  *
26
- * **The reason vocabulary is closed and lives HERE, in one module.** Six
27
- * members answer the ticket's own question (can a timeout, a 5xx, a dead
28
- * dashboard and "nothing to say" be told apart?): `timeout`, `http_<status>`,
29
- * `unpaired`, `dashboard_unreachable`, `bad_response`, `no_prompt`. Three more
30
- * cover skip states that are local to one hook and never touch the network —
31
- * `reentrant` (Stop, re-entrant), `no_transcript` (Stop, nothing to read yet)
32
- * and `redaction_failed` (Stop, the masking pass itself failed) kept as
33
- * their own fixed literals rather than folded into a network bucket, because
34
- * calling a re-entrant Stop hook `bad_response` would tell an operator a
35
- * request failed when nothing was even attempted. Every one of the nine is a
36
- * compile-time literal from OUR OWN code; none of them is `response.body`
37
- * text, an `error.message`, or a stack trace (`door.ts`'s `doorReason` already
38
- * enforces that at the source for the network four). `toLogReason` maps every
39
- * other internal reason string this package can produce onto one of the nine,
40
- * and anything it does not recognise a future reason nobody wired in here —
41
- * falls back to `bad_response` rather than printing unbounded text.
26
+ * **The reason vocabulary is closed and lives HERE, in one module.** Four
27
+ * members answer the network half of the ticket's own question (can a
28
+ * timeout, a 5xx and a dead dashboard be told apart?): `timeout`,
29
+ * `http_<status>`, `dashboard_unreachable`, `bad_response` the last of
30
+ * those meaning specifically "Tower answered with a status but a body that
31
+ * was not readable JSON" (`door.ts`'s `doorReason`). Six more are the
32
+ * **caller's own stdin**, one per `stdin.ts` `StdinFailure` member
33
+ * `no_stdin`, `stdin_empty`, `stdin_timeout`, `stdin_too_large`,
34
+ * `stdin_unreadable`, `stdin_malformed` kept as their OWN literals rather
35
+ * than folded into `bad_response`, because a malformed payload from the host
36
+ * never touched the network at all (BLI-3700, QA tick 6 NEW-9: a plain-text
37
+ * stdin payload printed `bad_response` and read as a Tower outage for four
38
+ * runs that never made a request). `unpaired` and `no_prompt` round those
39
+ * out, and three more cover skip states local to one hook that never touch
40
+ * the network either`reentrant` (Stop, re-entrant), `no_transcript`
41
+ * (Stop, nothing to read yet) and `redaction_failed` (Stop, the masking pass
42
+ * itself failed). Every member is a compile-time literal from OUR OWN code;
43
+ * none of them is `response.body` text, an `error.message`, or a stack trace
44
+ * (`door.ts`'s `doorReason` already enforces that at the source for the
45
+ * network four). `toLogReason` maps every other internal reason string this
46
+ * package can produce onto one of these, and anything it does not recognise —
47
+ * a future reason nobody wired in here — becomes `unknown_internal:<name>`,
48
+ * never a silent `bad_response`: a reason this table has not been taught must
49
+ * say so, not point at the wrong system.
42
50
  */
43
51
  export const HOOK_LOG_TAG = "[bli-memory]";
44
52
  export function logWordFor(status) {
@@ -68,13 +76,15 @@ export function toLogReason(reason) {
68
76
  case "session_missing_token":
69
77
  return "unpaired";
70
78
  // The host's own payload could not be used (stdin.ts's `StdinFailure`).
79
+ // Each keeps its own literal — never folded into `bad_response`, which
80
+ // names a Tower reply, not a caller-side stdin defect (BLI-3700).
71
81
  case "no_stdin":
72
82
  case "stdin_empty":
73
83
  case "stdin_timeout":
74
84
  case "stdin_too_large":
75
85
  case "stdin_unreadable":
76
86
  case "stdin_malformed":
77
- return "bad_response";
87
+ return reason;
78
88
  // The prompt hook's own empty-prompt skip.
79
89
  case "no_prompt":
80
90
  return "no_prompt";
@@ -91,12 +101,16 @@ export function toLogReason(reason) {
91
101
  case "deadline_exceeded":
92
102
  return "timeout";
93
103
  default:
94
- // A door's `http_<status>` template literal, or an unexpected
95
- // `hook_threw:<Name>` the request happened but produced something
96
- // this hook could not act on. Never the raw string past this point.
104
+ // A door's `http_<status>` template literal passes through as-is; an
105
+ // unexpected reason nobody wired into this table — `hook_threw:<Name>`
106
+ // or a future internal reason becomes `unknown_internal:<name>`
107
+ // rather than a silent `bad_response`, which would misname a caller-side
108
+ // or run-level defect as a Tower reply (BLI-3700). Never the raw
109
+ // string is dropped, and never is it printed unbounded: the name is
110
+ // one of OUR OWN reason literals, never `response.body` text.
97
111
  if (reason.startsWith("http_"))
98
112
  return reason;
99
- return "bad_response";
113
+ return `unknown_internal:${reason}`;
100
114
  }
101
115
  }
102
116
  /**
@@ -120,6 +134,10 @@ export function buildLogLine(event, outcome, elapsedMs, deadlineMs) {
120
134
  ...(outcome.saved === undefined ? {} : { saved: outcome.saved }),
121
135
  ...(outcome.chars === undefined ? {} : { chars: outcome.chars }),
122
136
  ...(outcome.masked === undefined ? {} : { masked: outcome.masked }),
137
+ // BLI-3718: printed whenever set, including 0 — a save that wrote
138
+ // nothing AND conflicted with nothing is a materially different
139
+ // fact from one that conflicted on every candidate.
140
+ ...(outcome.conflicts === undefined ? {} : { conflicts: outcome.conflicts }),
123
141
  elapsed_ms: elapsedMs,
124
142
  deadline_ms: deadlineMs,
125
143
  };
@@ -141,6 +159,11 @@ function failureSentence(reason) {
141
159
  if (reason.startsWith("http_")) {
142
160
  return `Tower refused the request (${reason.slice("http_".length)}).`;
143
161
  }
162
+ if (reason.startsWith("unknown_internal:")) {
163
+ // A reason this table has not been taught. Named, never a crash, and
164
+ // never claims to know which system was at fault (BLI-3700).
165
+ return "something went wrong that this hook does not yet name.";
166
+ }
144
167
  switch (reason) {
145
168
  case "timeout":
146
169
  return "Tower did not answer in time.";
@@ -152,6 +175,24 @@ function failureSentence(reason) {
152
175
  return "this machine is not paired with Tower — run `cockpit login`.";
153
176
  case "redaction_failed":
154
177
  return "the turn could not be safely redacted before saving.";
178
+ // The six `StdinFailure` members (BLI-3700). Skip-only today —
179
+ // `readHookPayload` always returns these as a `skipped` outcome, so
180
+ // `buildSystemMessage` never reaches them in practice — but each still
181
+ // gets its own sentence, named rather than asserted unreachable, so a
182
+ // future change that DID route one through `failed` gets the right
183
+ // words instead of the wrong system's name.
184
+ case "no_stdin":
185
+ return "no payload arrived on stdin (not run from a host that pipes one).";
186
+ case "stdin_empty":
187
+ return "the payload on stdin was empty.";
188
+ case "stdin_timeout":
189
+ return "stdin never closed within this hook's own deadline.";
190
+ case "stdin_too_large":
191
+ return "the payload on stdin exceeded the size ceiling.";
192
+ case "stdin_unreadable":
193
+ return "the payload on stdin could not be read.";
194
+ case "stdin_malformed":
195
+ return "the payload on stdin was not readable JSON.";
155
196
  case "no_transcript":
156
197
  case "reentrant":
157
198
  case "no_prompt":
@@ -161,8 +202,9 @@ function failureSentence(reason) {
161
202
  // `failed` still gets a sentence instead of a crash.
162
203
  return "the recall did not run.";
163
204
  default:
164
- // Unreached: the `http_` family returned above and every other member
165
- // is handled. A safe sentence, never a crash, if that ever changes.
205
+ // Unreached: the `http_`/`unknown_internal:` families returned above
206
+ // and every other member is handled. A safe sentence, never a crash,
207
+ // if that ever changes.
166
208
  return "something went wrong.";
167
209
  }
168
210
  }
@@ -6,8 +6,13 @@
6
6
  * installer's 5 s timeout, one search, print or print nothing.
7
7
  *
8
8
  * The recall shape is the vendor's, kept so the injection reads the same: the
9
- * prompt itself is the query, hits below 0.55 similarity are dropped, at most
10
- * five survive, each capped at 300 characters.
9
+ * prompt itself is the query, hits below the door's OWN floor are dropped
10
+ * (BLI-3697 tick 8: this hook used to keep a hardcoded 0.55 of its own,
11
+ * which drifted out of step when the door's floor moved across three
12
+ * tickets — the door's `semanticFloor` in the response is read instead now,
13
+ * `RECALL_MIN_SIMILARITY` surviving only as the fallback for an older
14
+ * deployment that does not send the field yet), at most five survive, each
15
+ * capped at 300 characters.
11
16
  *
12
17
  * **Zero hits is data.** It prints nothing and exits 0 with `no_hits`. A search
13
18
  * that could NOT run is a different line with a different reason, because an
@@ -6,8 +6,13 @@
6
6
  * installer's 5 s timeout, one search, print or print nothing.
7
7
  *
8
8
  * The recall shape is the vendor's, kept so the injection reads the same: the
9
- * prompt itself is the query, hits below 0.55 similarity are dropped, at most
10
- * five survive, each capped at 300 characters.
9
+ * prompt itself is the query, hits below the door's OWN floor are dropped
10
+ * (BLI-3697 tick 8: this hook used to keep a hardcoded 0.55 of its own,
11
+ * which drifted out of step when the door's floor moved across three
12
+ * tickets — the door's `semanticFloor` in the response is read instead now,
13
+ * `RECALL_MIN_SIMILARITY` surviving only as the fallback for an older
14
+ * deployment that does not send the field yet), at most five survive, each
15
+ * capped at 300 characters.
11
16
  *
12
17
  * **Zero hits is data.** It prints nothing and exits 0 with `no_hits`. A search
13
18
  * that could NOT run is a different line with a different reason, because an
@@ -45,7 +50,8 @@ export async function runPromptHook(context) {
45
50
  if (!response.ok) {
46
51
  return { status: "failed", reason: doorReason(response), stdout: "", hits: 0 };
47
52
  }
48
- const memories = readHits(response.body["results"]);
53
+ const floor = doorFloor(response.body["semanticFloor"]);
54
+ const memories = readHits(response.body["results"], floor);
49
55
  const degraded = typeof response.body["degraded"] === "string" && response.body["degraded"]
50
56
  ? String(response.body["degraded"])
51
57
  : null;
@@ -70,20 +76,35 @@ export async function runPromptHook(context) {
70
76
  };
71
77
  }
72
78
  /**
73
- * The vendor's floor, applied to the vendor's channel only.
79
+ * The door's own floor for THIS search, or the vendor's fallback.
80
+ *
81
+ * BLI-3697 tick 8: this hook used to re-check every row against its own
82
+ * hardcoded `RECALL_MIN_SIMILARITY` (0.55) regardless of what floor the
83
+ * door had actually searched with — three tickets moved that number (0.55 ->
84
+ * 0.30 -> 0.65) and this hook never noticed, silently applying a SECOND,
85
+ * stale threshold on top of the door's real one. `semanticFloor` on the
86
+ * response is the number the search actually ran with; only a door old
87
+ * enough not to send it falls back to the vendor's constant.
88
+ */
89
+ function doorFloor(value) {
90
+ return typeof value === "number" && Number.isFinite(value) ? value : RECALL_MIN_SIMILARITY;
91
+ }
92
+ /**
93
+ * The floor governs the SEMANTIC channel only.
74
94
  *
75
95
  * `similarity` on our door is **cosine similarity, zero when a row came only
76
96
  * from the lexical or recency channel** (`agent-memories/search.ts:74`). The
77
- * vendor filtered at 0.55 against a store where every hit was semantic; doing
78
- * that here would drop every keyword match, and on a deployment with no
79
- * embedding credential it would drop EVERY hit — a recall that silently returns
97
+ * vendor filtered against a store where every hit was semantic; doing that
98
+ * here would drop every keyword match, and on a deployment with no embedding
99
+ * credential it would drop EVERY hit — a recall that silently returns
80
100
  * nothing forever while the door reports `degraded` and nobody reads it.
81
101
  *
82
- * So the floor governs SEMANTIC hits and nothing else: a row the semantic
83
- * channel scored has to clear 0.55, and a row it did not score at all is judged
84
- * by the door's own ranking, which already put it in the top `limit`.
102
+ * So `floor` (the door's own `semanticFloor`, see `doorFloor` above) governs
103
+ * SEMANTIC hits and nothing else: a row the semantic channel scored has to
104
+ * clear it, and a row it did not score at all is judged by the door's own
105
+ * ranking, which already put it in the top `limit`.
85
106
  */
86
- function readHits(value) {
107
+ function readHits(value, floor) {
87
108
  if (!Array.isArray(value))
88
109
  return [];
89
110
  const kept = [];
@@ -101,9 +122,10 @@ function readHits(value) {
101
122
  : // An older door that does not report channels: a non-zero similarity is
102
123
  // the only evidence the semantic channel scored this row.
103
124
  Number.isFinite(similarity) && similarity > 0;
104
- if (scoredSemantically && !(similarity >= RECALL_MIN_SIMILARITY))
125
+ if (scoredSemantically && !(similarity >= floor))
105
126
  continue;
106
- kept.push(memory);
127
+ const createdAt = typeof record["createdAt"] === "string" ? record["createdAt"] : null;
128
+ kept.push({ text: memory, createdAt });
107
129
  if (kept.length >= RECALL_LIMIT)
108
130
  break;
109
131
  }
@@ -14,8 +14,9 @@
14
14
  * A memory is a recalled fact; a fact that arrives phrased as an order and
15
15
  * is obeyed is how a memory store becomes an injection channel.
16
16
  */
17
+ import { type RecalledHit } from "./contract.js";
17
18
  export declare function renderSessionContext(profile: {
18
19
  static: string[];
19
20
  dynamic: string[];
20
21
  }): string;
21
- export declare function renderRecall(memories: string[]): string;
22
+ export declare function renderRecall(hits: readonly RecalledHit[]): string;
@@ -37,8 +37,8 @@ export function renderSessionContext(profile) {
37
37
  lines.push(CONTEXT_BLOCK.close);
38
38
  return lines.join("\n");
39
39
  }
40
- export function renderRecall(memories) {
41
- const items = cleanItems(memories);
40
+ export function renderRecall(hits) {
41
+ const items = cleanRecalledHits(hits);
42
42
  if (items.length === 0)
43
43
  return "";
44
44
  return [
@@ -48,6 +48,38 @@ export function renderRecall(memories) {
48
48
  RECALL_BLOCK.close,
49
49
  ].join("\n");
50
50
  }
51
+ /**
52
+ * One memory, on one line, dated. Folds newlines for the same reason
53
+ * `cleanItems` does; the date prefix is added BEFORE the length cap, so the
54
+ * cap still bounds the whole printed line, never just the text half.
55
+ *
56
+ * Every line gets its date, not only the ones some heuristic calls "stale" —
57
+ * `RecalledHit`'s header in `contract.ts` says why: only the reader can judge
58
+ * staleness, and only if the date is there to judge.
59
+ */
60
+ function cleanRecalledHits(hits) {
61
+ const out = [];
62
+ for (const hit of hits) {
63
+ if (typeof hit.text !== "string")
64
+ continue;
65
+ const folded = hit.text.replace(/\s+/gu, " ").trim();
66
+ if (folded.length === 0)
67
+ continue;
68
+ const prefix = dateLabel(hit.createdAt);
69
+ const line = prefix ? `${prefix} ${folded}` : folded;
70
+ out.push(line.length > RECALL_LINE_CHARS ? `${line.slice(0, RECALL_LINE_CHARS - 1)}…` : line);
71
+ }
72
+ return out;
73
+ }
74
+ /** `[YYYY-MM-DD]`, or `""` when the door sent no date or an unparsable one. */
75
+ function dateLabel(createdAt) {
76
+ if (!createdAt)
77
+ return "";
78
+ const date = new Date(createdAt);
79
+ if (Number.isNaN(date.getTime()))
80
+ return "";
81
+ return `[${date.toISOString().slice(0, 10)}]`;
82
+ }
51
83
  /**
52
84
  * One memory, on one line. Newlines are folded because a multi-line bullet
53
85
  * breaks the list the model is reading, and the cap is the vendor's 300.
@@ -75,19 +75,40 @@ export async function runStopHook(context, options = {}) {
75
75
  if (!response.ok) {
76
76
  return { status: "failed", reason: doorReason(response), stdout: "", saved: 0 };
77
77
  }
78
- const decisions = response.body["decisions"];
79
- const written = Array.isArray(decisions)
80
- ? decisions.filter((decision) => decision &&
81
- typeof decision === "object" &&
82
- decision["verb"] !== "skip").length
78
+ const decisionsRaw = response.body["decisions"];
79
+ const decisions = Array.isArray(decisionsRaw)
80
+ ? decisionsRaw.filter((decision) => Boolean(decision) && typeof decision === "object")
81
+ : null;
82
+ const written = decisions
83
+ ? decisions.filter((decision) => decision["verb"] !== "skip").length
83
84
  : response.body["id"]
84
85
  ? 1
85
86
  : 0;
87
+ // BLI-3718: a candidate that collided with another live memory's custom_id
88
+ // is counted SEPARATELY from `written` — it is neither a save nor "nothing
89
+ // worth keeping", and folding it into the latter is exactly how a session's
90
+ // second-and-later Stop hooks reported `{"skipped":N}` at HTTP 200 while a
91
+ // fact silently never landed.
92
+ const conflicted = decisions
93
+ ? decisions.filter((decision) => decision["reason"] === "custom_id_conflict").length
94
+ : 0;
95
+ if (written > 0) {
96
+ return {
97
+ status: "ok",
98
+ reason: String(response.body["outcome"] ?? "saved"),
99
+ stdout: "",
100
+ saved: written,
101
+ conflicts: conflicted,
102
+ chars: masked.text.length,
103
+ masked: masked.masked,
104
+ };
105
+ }
86
106
  return {
87
- status: written > 0 ? "ok" : "empty",
88
- reason: written > 0 ? String(response.body["outcome"] ?? "saved") : "nothing_worth_keeping",
107
+ status: "empty",
108
+ reason: conflicted > 0 ? "custom_id_conflict" : "nothing_worth_keeping",
89
109
  stdout: "",
90
- saved: written,
110
+ saved: 0,
111
+ conflicts: conflicted,
91
112
  chars: masked.text.length,
92
113
  masked: masked.masked,
93
114
  };
package/dist/server.d.ts CHANGED
@@ -36,7 +36,7 @@ import { z } from "zod";
36
36
  import { type FetchImpl } from "./door.js";
37
37
  import type { MemorySession } from "./session.js";
38
38
  export declare const PACKAGE_NAME = "@bli-cockpit/memory-mcp";
39
- export declare const PACKAGE_VERSION = "0.1.1";
39
+ export declare const PACKAGE_VERSION = "0.1.5";
40
40
  /**
41
41
  * The server id an MCP client registers. Defined in `print-config.ts` and
42
42
  * re-exported here: `index.ts` needs the name on the hook and print-config
package/dist/server.js CHANGED
@@ -37,7 +37,10 @@ import { resolveContainerTag } from "./container-tag.js";
37
37
  import { postMemoryDoor } from "./door.js";
38
38
  import { SERVER_NAME } from "./print-config.js";
39
39
  export const PACKAGE_NAME = "@bli-cockpit/memory-mcp";
40
- export const PACKAGE_VERSION = "0.1.1";
40
+ // BLI-3713: this constant had drifted from package.json's real version
41
+ // (0.1.1 vs 0.1.4) — nobody had bumped it alongside a version bump before.
42
+ // Kept in lockstep with package.json's "version" field going forward.
43
+ export const PACKAGE_VERSION = "0.1.5";
41
44
  /**
42
45
  * The server id an MCP client registers. Defined in `print-config.ts` and
43
46
  * re-exported here: `index.ts` needs the name on the hook and print-config
@@ -241,7 +244,14 @@ export function createServer(deps) {
241
244
  const embedNote = response.body.embedded === false && response.body.embedSkippedReason
242
245
  ? ` It was stored without a search vector (${String(response.body.embedSkippedReason)}), so it is findable by keyword and not yet by meaning.`
243
246
  : "";
244
- return textResult(`Memory ${outcome} in ${landedIn} (id: ${id}).${embedNote}`, response.body);
247
+ // BLI-3713: `mode: "extract"` can fall back to a verbatim save when
248
+ // distillation fails (a bad model answer must never mean the content is
249
+ // dropped) — say so plainly rather than let the caller believe atomic
250
+ // facts were written when the whole note was stored as one row instead.
251
+ const extractNote = response.body.extract === "fell_back_verbatim"
252
+ ? ` Saved as written; extraction failed (${String(response.body.extractFailureReason ?? "unknown")}).`
253
+ : "";
254
+ return textResult(`Memory ${outcome} in ${landedIn} (id: ${id}).${embedNote}${extractNote}`, response.body);
245
255
  });
246
256
  server.registerTool("update_memory", {
247
257
  title: "Correct a memory",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bli-cockpit/memory-mcp",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "private": false,
5
5
  "description": "BLI Memory — an MCP server for the memory layer BLI owns (save, search, update, forget).",
6
6
  "type": "module",