renor-engine 1.0.0 → 1.1.0
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/LICENSE +202 -661
- package/NOTICE +8 -6
- package/README.md +6 -6
- package/dist/.tsbuildinfo +1 -0
- package/dist/BUILD.json +2 -2
- package/dist/api/server.js +10 -8
- package/dist/buildIdentity.js +18 -1
- package/dist/callPhases.js +82 -0
- package/dist/cli.js +10 -1
- package/dist/context/rowStore.js +1 -1
- package/dist/conversation/parser.js +40 -36
- package/dist/db/client.js +6 -4
- package/dist/db/handoffTable.js +31 -0
- package/dist/db/indexSalvage.js +24 -4
- package/dist/db/migrations.js +30 -2
- package/dist/db/sqlite.js +396 -0
- package/dist/digests/digestCache.js +6 -2
- package/dist/digests/digests.js +3 -3
- package/dist/digests/worker.js +3 -1
- package/dist/embeddings/caching.js +5 -5
- package/dist/embeddings/local.js +5 -3
- package/dist/embeddings/openai.js +4 -3
- package/dist/embeddings/simdScan.js +3 -1
- package/dist/embeddings/vectorIndex.js +0 -1
- package/dist/embeddings/vertex.js +123 -13
- package/dist/eval/cacheReport.js +7 -0
- package/dist/eval/context700-candidate.js +5 -5
- package/dist/eval/evalCache.js +46 -3
- package/dist/eval/indexSnapshots.js +548 -0
- package/dist/eval/pageDump.js +67 -0
- package/dist/eval/runManifest.js +6 -0
- package/dist/eval/textTokens.js +17 -0
- package/dist/evidence/attach.js +0 -3
- package/dist/evidence/evidenceCache.js +3 -3
- package/dist/evidence/options.js +46 -25
- package/dist/evidence/secondPass.js +8 -170
- package/dist/extraction/factExtractor.js +1 -1
- package/dist/extraction/preferenceExtractor.js +1 -4
- package/dist/extraction/typedFacts.js +1 -1
- package/dist/importing/apply.js +42 -14
- package/dist/importing/cli.js +9 -8
- package/dist/importing/existing.js +2 -0
- package/dist/importing/facts.js +0 -2
- package/dist/importing/plan.js +0 -5
- package/dist/importing/source.js +1 -1
- package/dist/indexer/parser.js +4 -1
- package/dist/indexer/pipeline.js +99 -279
- package/dist/indexer/walker.js +11 -25
- package/dist/mcp/server.js +36 -6
- package/dist/memory/handoff.js +363 -0
- package/dist/memory/lifecycle.js +310 -75
- package/dist/memory/sourceName.js +77 -1
- package/dist/memory/statusFacts.js +61 -0
- package/dist/memorymap/memoryMap.js +39 -13
- package/dist/memorymap/replacements.js +8 -3
- package/dist/mvp/agentMemory.js +106 -50
- package/dist/mvp/answerCheck.js +211 -0
- package/dist/mvp/cli.js +3 -1
- package/dist/mvp/compileCache.js +3 -10
- package/dist/mvp/compileSeed.js +9 -3
- package/dist/mvp/contextDistinct.js +53 -0
- package/dist/mvp/contextProfile.js +87 -0
- package/dist/mvp/directorySurface.js +68 -0
- package/dist/mvp/engine.js +39 -26
- package/dist/mvp/exportAll.js +17 -2
- package/dist/mvp/factMarkers.js +18 -2
- package/dist/mvp/history.js +5 -4
- package/dist/mvp/log.js +118 -0
- package/dist/mvp/server.js +642 -127
- package/dist/mvp/serverCard.js +12 -3
- package/dist/mvp/telemetry.js +35 -2
- package/dist/net/poolFetch.js +174 -0
- package/dist/recall/actionRecall.js +282 -0
- package/dist/recall/autoRecall.js +447 -0
- package/dist/recall/searchRecall.js +189 -0
- package/dist/retrieval/entityLookup.js +53 -4
- package/dist/retrieval/orchestrator.js +93 -8
- package/dist/retrieval/plainWording.js +236 -0
- package/dist/retrieval/readerLayout.js +143 -224
- package/dist/router/routerCache.js +2 -2
- package/dist/watcher/watcher.js +5 -3
- package/package.json +5 -7
- package/dist/importing/index.js +0 -29
package/dist/mvp/server.js
CHANGED
|
@@ -3,7 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.MVP_VERSION_PATH = exports.MVP_MCP_PATH = exports.SEARCH_REFUSAL_REASONS = exports.sanitizeErrorMessage = exports.DIRECTORY_HEADER = exports.DASHBOARD_HEADER = void 0;
|
|
6
|
+
exports.MVP_VERSION_PATH = exports.MVP_MCP_PATH = exports.SEARCH_REFUSAL_REASONS = exports.sanitizeErrorMessage = exports.DIRECTORY_HEADER = exports.DASHBOARD_HEADER = exports.OUTPUT_SCHEMA_BOUND_NOTE = void 0;
|
|
7
|
+
exports.toolOutputSchemasEnabled = toolOutputSchemasEnabled;
|
|
7
8
|
exports.createMvpApp = createMvpApp;
|
|
8
9
|
exports.toolError = toolError;
|
|
9
10
|
exports.startMvpService = startMvpService;
|
|
@@ -27,8 +28,10 @@ const limits_1 = require("../memory/limits");
|
|
|
27
28
|
const sourceName_1 = require("../memory/sourceName");
|
|
28
29
|
const secretGuard_1 = require("../extraction/secretGuard");
|
|
29
30
|
const whatsNew_1 = require("../memory/whatsNew");
|
|
31
|
+
const handoff_1 = require("../memory/handoff");
|
|
30
32
|
const requests_1 = require("../memory/requests");
|
|
31
33
|
const history_1 = require("./history");
|
|
34
|
+
const directorySurface_1 = require("./directorySurface");
|
|
32
35
|
const identity_1 = require("./identity");
|
|
33
36
|
const serverCard_1 = require("./serverCard");
|
|
34
37
|
const requestErrors_1 = require("../mcp/requestErrors");
|
|
@@ -48,6 +51,7 @@ const hitDates_1 = require("./hitDates");
|
|
|
48
51
|
const replacements_1 = require("../memorymap/replacements");
|
|
49
52
|
const contextRelevance_1 = require("./contextRelevance");
|
|
50
53
|
const hitFloor_1 = require("./hitFloor");
|
|
54
|
+
const answerCheck_1 = require("./answerCheck");
|
|
51
55
|
const readerLayout_1 = require("../retrieval/readerLayout");
|
|
52
56
|
const questionSpan_1 = require("../retrieval/questionSpan");
|
|
53
57
|
const readerEvents_1 = require("../retrieval/readerEvents");
|
|
@@ -62,13 +66,16 @@ const memoryMap_1 = require("../memorymap/memoryMap");
|
|
|
62
66
|
const idle_1 = require("./idle");
|
|
63
67
|
const activity_1 = require("./activity");
|
|
64
68
|
const storedSize_1 = require("./storedSize");
|
|
65
|
-
const storedSize_2 = require("./storedSize");
|
|
66
69
|
const sanitize_1 = require("./sanitize");
|
|
67
70
|
Object.defineProperty(exports, "sanitizeErrorMessage", { enumerable: true, get: function () { return sanitize_1.sanitizeErrorMessage; } });
|
|
68
71
|
const controls_1 = require("../memory/controls");
|
|
69
72
|
const hiddenSpans_1 = require("./hiddenSpans");
|
|
70
73
|
const connectionStatus_1 = require("./connectionStatus");
|
|
71
74
|
const toolRefusal_1 = require("../toolRefusal");
|
|
75
|
+
const callPhases_1 = require("../callPhases");
|
|
76
|
+
const log_1 = require("./log");
|
|
77
|
+
const contextProfile_1 = require("./contextProfile");
|
|
78
|
+
const log = (0, log_1.createLogger)('engine');
|
|
72
79
|
/**
|
|
73
80
|
* Single-user ChatGPT MVP remote MCP service.
|
|
74
81
|
*
|
|
@@ -86,10 +93,6 @@ const toolRefusal_1 = require("../toolRefusal");
|
|
|
86
93
|
* serialized, validated, honest receipts, restart replay), so persistence,
|
|
87
94
|
* correction and restart recovery inherit the Gate1A guarantees.
|
|
88
95
|
*/
|
|
89
|
-
/**
|
|
90
|
-
* What search_memory says of the digest table, only where write-time digests are switched on (RENOR_DIGESTS), so a
|
|
91
|
-
* workspace without them has the description it always had.
|
|
92
|
-
*/
|
|
93
96
|
/**
|
|
94
97
|
* What search_memory says of the event lines, only where RENOR_READER_EVENTS is set to an on value (`1`, `true`, `yes`, `on`).
|
|
95
98
|
* With it unset the lines still lead the page (the default) and say what they are in their own first words, but the tool list is
|
|
@@ -97,6 +100,10 @@ const toolRefusal_1 = require("../toolRefusal");
|
|
|
97
100
|
* gateway's server card.
|
|
98
101
|
*/
|
|
99
102
|
const EVENTS_HITS = ' When the question asks for the order or the date of something the user did, the first hit is a list of the user\'s own statements that match it, each under the day it is about, oldest first, and the excerpts stay in full below it (reason "events"). A question about a duration has no such list.';
|
|
103
|
+
/**
|
|
104
|
+
* What search_memory says of the digest table, only where write-time digests are switched on (RENOR_DIGESTS), so a
|
|
105
|
+
* workspace without them has the description it always had.
|
|
106
|
+
*/
|
|
100
107
|
const DIGEST_HITS = ' This workspace writes a dated digest of each saved note in the background: when the notes matched have digests, one table of dated items drawn from them leads the hits (after any evidence table), outside the rankedBy order and top_k, with reason "digest". It is read from stored digests, no model is called to make it, and a note saved a moment ago may not have its digest yet. Use the table when it holds the value needed, and the excerpts when it does not.';
|
|
101
108
|
/**
|
|
102
109
|
* What search_memory says of the duration line, only where RENOR_READER_DURATION is set to an on value (`1`, `true`, `yes`, `on`)
|
|
@@ -110,7 +117,6 @@ const SPAN_HITS = ' When the question asks how many days, weeks or months lie be
|
|
|
110
117
|
*/
|
|
111
118
|
const TIMELINE_HITS = ' When the question asks what a value is now, the first hit is a timeline of the user\'s own statements of that value, oldest first, the last line marked latest, and the excerpts stay in full below it (reason "timeline"). A question about a duration or an order has no timeline.';
|
|
112
119
|
const MCP_PATH = '/mcp';
|
|
113
|
-
/** True when any message is a tools/call that omitted `id`. An explicit `id: null` still has the key. */
|
|
114
120
|
/**
|
|
115
121
|
* A request body must be UTF-8. Node decodes an invalid byte as U+FFFD, and the tool would store that, so the
|
|
116
122
|
* body is refused before it is parsed. The error carries a 400 status, which body-parser keeps.
|
|
@@ -123,6 +129,7 @@ function requireUtf8Body(_req, _res, body) {
|
|
|
123
129
|
throw Object.assign(new Error('request body is not valid UTF-8; nothing was run'), { status: 400, expose: true });
|
|
124
130
|
}
|
|
125
131
|
}
|
|
132
|
+
/** True when any message is a tools/call that omitted `id`. An explicit `id: null` still has the key. */
|
|
126
133
|
function bodyHasToolsCallNotification(body) {
|
|
127
134
|
const messages = Array.isArray(body) ? body : [body];
|
|
128
135
|
return messages.some((message) => {
|
|
@@ -199,12 +206,53 @@ function isLocalDirectCall(req) {
|
|
|
199
206
|
*/
|
|
200
207
|
const EVIDENCE_WAIT_STATES = ' This deployment waits for the evidence model only a bounded time, so two more states mean that this response alone has no table: "pending" (the extraction did not finish in time; it continues, and once its table is cached the same request over the same notes returns it) and "busy" (as many extractions were already waiting as the deployment allows, so none was started).';
|
|
201
208
|
const EVIDENCE_DAILY_CAP_STATE = ' This workspace has a daily allowance of evidence-model calls, so one more state means that this response alone has no table: "capped" (the allowance is used up until 00:00 UTC; retrieval is unaffected and the hits are the whole result).';
|
|
209
|
+
/**
|
|
210
|
+
* RENOR_TOOL_OUTPUT_SCHEMAS (default off; `1` / `true` / `yes` / `on` turns it on): every tool lists its `outputSchema` and
|
|
211
|
+
* every answer also carries `structuredContent`. Off, the tools listing and every reply are what they were before the
|
|
212
|
+
* schemas existed. It is off by default because the structured form doubles the wire: each answer then carries its JSON
|
|
213
|
+
* twice (the text block and `structuredContent`), get_context's `max_tokens` bounds the text block alone, and the tools
|
|
214
|
+
* listing grows by the schemas (about +47%). Read once per server, so the listing and the replies always agree.
|
|
215
|
+
*/
|
|
216
|
+
function toolOutputSchemasEnabled(env = process.env) {
|
|
217
|
+
const v = (env.RENOR_TOOL_OUTPUT_SCHEMAS ?? '').trim().toLowerCase();
|
|
218
|
+
return v === '1' || v === 'true' || v === 'yes' || v === 'on';
|
|
219
|
+
}
|
|
220
|
+
/** A tool's registration with its outputSchema only when output schemas are on: off, the tool lists none, as before. */
|
|
221
|
+
function withOutputSchemaIf(on, config) {
|
|
222
|
+
if (on || config.outputSchema === undefined)
|
|
223
|
+
return config;
|
|
224
|
+
const { outputSchema: _dropped, ...rest } = config;
|
|
225
|
+
return rest;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* With output schemas on, get_context's bound covers its text block, and structuredContent repeats the same JSON: a client
|
|
229
|
+
* that passes both to a model pays about twice the bound (measured on #680: 703 tokens of text, 1,446 on the wire).
|
|
230
|
+
*/
|
|
231
|
+
exports.OUTPUT_SCHEMA_BOUND_NOTE = ' With output schemas on, max_tokens bounds the text block; structuredContent carries the same JSON again.';
|
|
202
232
|
/**
|
|
203
233
|
* Every tool answers in the same shape: its JSON on one line. Indentation is whitespace an agent pays for in tokens on
|
|
204
234
|
* every call and reads nothing from; indented, a get_context answer was about a fifth larger.
|
|
235
|
+
*
|
|
236
|
+
* The text block is the JSON with its hidden characters written as \uXXXX escapes (escapeInvisibleControls), so no
|
|
237
|
+
* client is handed one raw in text. With output schemas on (RENOR_TOOL_OUTPUT_SCHEMAS), `structuredContent` is exactly
|
|
238
|
+
* JSON.parse of that text block: the decoded value, as any client that parses the text block reads it. Escaping is a
|
|
239
|
+
* property of JSON text and is never applied to a decoded value, which would turn every newline, tab and emoji joiner
|
|
240
|
+
* of a note into the literal text "\u000a" (review of #680, HIGH 1).
|
|
205
241
|
*/
|
|
206
|
-
function
|
|
207
|
-
|
|
242
|
+
function jsonResultOf(body, structured) {
|
|
243
|
+
const text = (0, sanitize_1.escapeInvisibleControls)(JSON.stringify(body));
|
|
244
|
+
return {
|
|
245
|
+
content: [{ type: 'text', text }],
|
|
246
|
+
...(structured ? { structuredContent: JSON.parse(text) } : {}),
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* A refusal: the same JSON text a client already reads, as a plain isError result. A refusal carries no
|
|
251
|
+
* structuredContent, since the output schema describes a tool's answer and a refusal is not one (the SDK does not
|
|
252
|
+
* check an isError result against it either).
|
|
253
|
+
*/
|
|
254
|
+
function refusalResult(body) {
|
|
255
|
+
return { content: [{ type: 'text', text: (0, sanitize_1.escapeInvisibleControls)(JSON.stringify(body)) }], isError: true };
|
|
208
256
|
}
|
|
209
257
|
/**
|
|
210
258
|
* An optional argument that a client may send as JSON null, which is how some clients spell an argument they leave out:
|
|
@@ -238,33 +286,31 @@ const REPLACES_ARG = omittedWhenBlank(zod_1.z.string().max(1024).optional()).des
|
|
|
238
286
|
const SCOPE_ARG = omittedWhenBlank(zod_1.z.string().optional()).describe('"global" (default) or project:<slug>, e.g. project:atlas.');
|
|
239
287
|
/** What a client is told a `source` is: the name of the app or agent saving, never a path (memory/sourceName.ts). */
|
|
240
288
|
const SOURCE_ARG_DESCRIPTION = 'Name of the app or agent saving this, for example claude-code. Leave it out to use the connecting client. Never a file path or document name.';
|
|
241
|
-
|
|
289
|
+
/**
|
|
290
|
+
* Shared pieces of the tools' declared output schemas (MCP `outputSchema`). Every hosted tool declares the object it
|
|
291
|
+
* already returns: the SDK validates the result's `structuredContent` against it, and clients read that as the
|
|
292
|
+
* structured result. A field a reply does not always carry is optional here, so a declared schema never refuses a
|
|
293
|
+
* reply the tool already produced. Each top level is a loose object (additional properties allowed): a client that
|
|
294
|
+
* validates against the schema it listed keeps accepting replies after a later release adds a field.
|
|
295
|
+
*/
|
|
296
|
+
/** An index pass a save or index run reports: rows walked, indexed, failed. */
|
|
297
|
+
const OUT_INDEX_PASS = zod_1.z.object({ total: zod_1.z.number(), indexed: zod_1.z.number(), errors: zod_1.z.number(), failure: zod_1.z.string().optional() }).optional();
|
|
298
|
+
/** The fact a save created: its id (null when it was already stored), its value and when it became valid. */
|
|
299
|
+
const OUT_CREATED_FACT = zod_1.z.object({ factId: zod_1.z.number().nullable(), object: zod_1.z.string(), validFrom: zod_1.z.string() }).nullable().optional();
|
|
300
|
+
/** The fact a superseding save closed. */
|
|
301
|
+
const OUT_CLOSED_FACT = zod_1.z.object({ factId: zod_1.z.number(), object: zod_1.z.string(), validTo: zod_1.z.string() }).nullable().optional();
|
|
302
|
+
/** A current value that may be the same fact under another name or scope (advisory, never merged). */
|
|
303
|
+
const OUT_DUPLICATES = zod_1.z.array(zod_1.z.object({
|
|
304
|
+
subject: zod_1.z.string(), object: zod_1.z.string(), scope: zod_1.z.string(), validFrom: zod_1.z.string(),
|
|
305
|
+
source: zod_1.z.string().optional(), untrusted: zod_1.z.literal(true).optional(),
|
|
306
|
+
})).optional();
|
|
307
|
+
/** What a `replaces` link did: the correction recorded, or why none was made. */
|
|
308
|
+
const OUT_REPLACEMENT = zod_1.z.object({ id: zod_1.z.string(), by: zod_1.z.string() }).optional();
|
|
309
|
+
/** One hit/excerpt a search or read returns; its own keys vary by reason, so only its object shape is fixed. */
|
|
310
|
+
const OUT_HIT = zod_1.z.record(zod_1.z.string(), zod_1.z.unknown());
|
|
242
311
|
const CALLER_SOURCE_ASCII = /^[A-Za-z0-9 _.:/@-]+$/;
|
|
243
312
|
/** A User-Agent product keeps its punctuation (cleanSource folds it) but may hold no character outside printable ASCII. */
|
|
244
313
|
const USER_AGENT_PRODUCT_ASCII = /^[\x20-\x7e]+$/;
|
|
245
|
-
const SOURCE_IDENTITY_SEPARATORS = /[ ._-]/g;
|
|
246
|
-
/** Return the reserved identity a writer spelling claims, including the import-style prefix form. */
|
|
247
|
-
function reservedSourceIdentity(source) {
|
|
248
|
-
const lower = source.toLowerCase();
|
|
249
|
-
const identity = lower.replace(SOURCE_IDENTITY_SEPARATORS, '');
|
|
250
|
-
const colon = lower.indexOf(':');
|
|
251
|
-
const authorityPrefix = colon < 0 ? null : lower.slice(0, colon).replace(SOURCE_IDENTITY_SEPARATORS, '');
|
|
252
|
-
return RESERVED_SOURCE_IDENTITIES.has(identity)
|
|
253
|
-
? identity
|
|
254
|
-
: authorityPrefix !== null && RESERVED_SOURCE_IDENTITIES.has(authorityPrefix) ? authorityPrefix : null;
|
|
255
|
-
}
|
|
256
|
-
/**
|
|
257
|
-
* The reserved identity a writer name would store as, under any spelling a write persists: the typed one, the fact's
|
|
258
|
-
* cleanSource and the note's headerSource. Paths, URLs, truncation and punctuation folding cannot manufacture one past this.
|
|
259
|
-
*/
|
|
260
|
-
function reservedSourceIn(source) {
|
|
261
|
-
for (const form of [source, (0, sourceName_1.cleanSource)(source), (0, sourceName_1.headerSource)(source)]) {
|
|
262
|
-
const reserved = reservedSourceIdentity(form);
|
|
263
|
-
if (reserved)
|
|
264
|
-
return reserved;
|
|
265
|
-
}
|
|
266
|
-
return null;
|
|
267
|
-
}
|
|
268
314
|
/** Validate an untrusted writer name and every spelling either writer can persist. */
|
|
269
315
|
function callerSource(source) {
|
|
270
316
|
// Check what the caller actually supplied. Normalizing first would let fullwidth and other compatibility characters
|
|
@@ -272,7 +318,7 @@ function callerSource(source) {
|
|
|
272
318
|
if (!CALLER_SOURCE_ASCII.test(source)) {
|
|
273
319
|
throw (0, toolRefusal_1.refusal)('invalid_argument', 'writer names must be plain ASCII (letters, digits, spaces, and - _ . : / @ only)');
|
|
274
320
|
}
|
|
275
|
-
const reserved =
|
|
321
|
+
const reserved = (0, sourceName_1.reservedCallerSource)(source);
|
|
276
322
|
if (reserved)
|
|
277
323
|
throw (0, toolRefusal_1.refusal)('invalid_argument', `source names a reserved identity (${reserved}); use an ordinary app or agent name, or leave source out`);
|
|
278
324
|
return source;
|
|
@@ -281,14 +327,26 @@ function markImportedOrigin(item, pathKey) {
|
|
|
281
327
|
return String(item[pathKey] ?? '').startsWith('Imported/') ? { ...item, origin: 'import' } : item;
|
|
282
328
|
}
|
|
283
329
|
/**
|
|
284
|
-
*
|
|
285
|
-
*
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
330
|
+
* A memory_map or read_memory memory as a read shows it: imported (origin), and a stored source that is a reserved identity
|
|
331
|
+
* (an entry saved before the rule, or written into a file by hand) marked `untrusted`, a claim and not who saved it.
|
|
332
|
+
*/
|
|
333
|
+
function markStoredMemory(item) {
|
|
334
|
+
const marked = markImportedOrigin(item, 'path');
|
|
335
|
+
return (0, sourceName_1.isReservedSource)(marked.source) && marked.untrusted !== true ? { ...marked, untrusted: true } : marked;
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* A search_memory or search_text hit as a read shows it: imported (origin), and `untrusted` when it is a daily-log chunk an
|
|
339
|
+
* entry of which claims a reserved source (factMarkers.ts claimsReservedEntrySource), as get_context marks the same chunk.
|
|
291
340
|
*/
|
|
341
|
+
function markStoredHit(hit) {
|
|
342
|
+
const marked = markImportedOrigin(hit, 'notePath');
|
|
343
|
+
return marked.untrusted !== true && (0, factMarkers_1.claimsReservedEntrySource)(marked.notePath, marked.text) ? { ...marked, untrusted: true } : marked;
|
|
344
|
+
}
|
|
345
|
+
/** A hit's score as an agent is shown it: six decimals. The 17 digits of a double cost about 4 tokens a hit and say nothing the order does not. */
|
|
346
|
+
function shortScore(hit) {
|
|
347
|
+
return typeof hit.score === 'number' ? { ...hit, score: (0, agentMemory_1.scoreForReply)(hit.score) } : hit;
|
|
348
|
+
}
|
|
349
|
+
/** A request header's first value, when it is a string. */
|
|
292
350
|
function headerText(headers, name) {
|
|
293
351
|
const raw = headers?.[name];
|
|
294
352
|
const value = Array.isArray(raw) ? raw[0] : raw;
|
|
@@ -302,21 +360,34 @@ function trustedAgentRaw(extra, config) {
|
|
|
302
360
|
return typeof agent === 'string' ? agent : undefined;
|
|
303
361
|
}
|
|
304
362
|
/**
|
|
305
|
-
* The hive identity of a trusted connection name, or "unnamed". A name that is a reserved identity is no name
|
|
306
|
-
*
|
|
307
|
-
*
|
|
363
|
+
* The hive identity of a trusted connection name, or "unnamed". A name that is a reserved identity is no name, so its saves
|
|
364
|
+
* cannot read as `owner` or `system`, as a typed source or a User-Agent cannot. `clientChosen` is a self-hosted OAuth
|
|
365
|
+
* client_name, which the client registers itself: it is held to the caller rule (a reserved first word, digit look-alikes).
|
|
366
|
+
* A gateway key's name is the owner's, chosen in the dashboard: only an exact reserved identity is refused, so `Developer
|
|
367
|
+
* Laptop` or `Renor CLI` keeps its name. A hosted OAuth sign-in is `OAuth-<client>`, which never is one.
|
|
308
368
|
*/
|
|
309
|
-
function trustedIdentity(raw) {
|
|
369
|
+
function trustedIdentity(raw, clientChosen) {
|
|
310
370
|
const identity = (0, sourceName_1.hiveIdentity)(raw);
|
|
311
|
-
|
|
371
|
+
if (identity === null)
|
|
372
|
+
return 'unnamed';
|
|
373
|
+
return (clientChosen ? (0, sourceName_1.reservedCallerSource)(identity) : (0, sourceName_1.reservedSourceIn)(identity)) !== null ? 'unnamed' : identity;
|
|
312
374
|
}
|
|
375
|
+
/**
|
|
376
|
+
* The source a hosted write stores. The connection's name (`x-renor-agent` behind the gateway, the
|
|
377
|
+
* verified OAuth client's name on self-hosted) as its hive identity, or "unnamed" when that connection
|
|
378
|
+
* has no name a header can render — an unnamed connection never takes a name the client typed;
|
|
379
|
+
* otherwise the one the client sent when it names someone; otherwise the product in the User-Agent
|
|
380
|
+
* (`claude-code/2.1.289` is `claude-code`), so an agent never has to pass one;
|
|
381
|
+
* otherwise undefined, which leaves the tool's own default. A source with no letter or digit in it (blank, a bare path,
|
|
382
|
+
* punctuation) names no one (memory/sourceName.ts).
|
|
383
|
+
*/
|
|
313
384
|
function sourceOf(sent, extra, config) {
|
|
314
385
|
// The gateway sets this from the connection key's name and overwrites a client-sent copy, so on a named
|
|
315
386
|
// connection it is the author: a `source` the client types cannot write as another agent.
|
|
316
387
|
// A present name that canonicalizes to no identity (punctuation-only, or `unnamed`) cannot take a typed source.
|
|
317
388
|
const raw = trustedAgentRaw(extra, config);
|
|
318
389
|
if (typeof raw === 'string' && raw.trim() !== '')
|
|
319
|
-
return trustedIdentity(raw);
|
|
390
|
+
return trustedIdentity(raw, !config.gatewaySecret);
|
|
320
391
|
// Self-hosted always resolves a name for the verified client (the sign-in middleware sets the key, even
|
|
321
392
|
// when the stored name renders empty). That connection is unnamed, and an unnamed connection cannot
|
|
322
393
|
// choose an author, exactly as an unnamed stdio connection cannot.
|
|
@@ -331,7 +402,7 @@ function sourceOf(sent, extra, config) {
|
|
|
331
402
|
// A reserved product (`system/1.0`, `owner/2 (x)`, `https:system`) or a non-ASCII one (a lookalike such as `SYSTEΜ/1.0`) falls back
|
|
332
403
|
// to the tool's default instead of storing it.
|
|
333
404
|
const product = (0, sourceName_1.productFromUserAgent)(extra?.requestInfo?.headers?.['user-agent']);
|
|
334
|
-
return product !== undefined && USER_AGENT_PRODUCT_ASCII.test(product) &&
|
|
405
|
+
return product !== undefined && USER_AGENT_PRODUCT_ASCII.test(product) && (0, sourceName_1.reservedCallerSource)(product) === null ? product : undefined;
|
|
335
406
|
}
|
|
336
407
|
/**
|
|
337
408
|
* Hosted names come only from the trusted gateway. Self-hosted names come only from
|
|
@@ -342,7 +413,7 @@ function agentOf(extra, config) {
|
|
|
342
413
|
const raw = trustedAgentRaw(extra, config);
|
|
343
414
|
if (typeof raw !== 'string' || raw.trim() === '')
|
|
344
415
|
return 'unnamed';
|
|
345
|
-
return trustedIdentity(raw);
|
|
416
|
+
return trustedIdentity(raw, !config.gatewaySecret);
|
|
346
417
|
}
|
|
347
418
|
/** Nameless connections must not share a feed, mark or inbox. */
|
|
348
419
|
function hiveAgentOf(extra, tool, config) {
|
|
@@ -377,7 +448,13 @@ function isDirectoryCall(headers, config) {
|
|
|
377
448
|
* What a directory client is told about the memory. It says nothing about call order or behaviour: the directory rules forbid
|
|
378
449
|
* that for other tools. Named agent keys keep the instructions built below.
|
|
379
450
|
*/
|
|
380
|
-
const DIRECTORY_INSTRUCTIONS = 'Renor single-owner memory: the owner\'s own saved memory, kept in their private workspace. get_context returns the current facts and the saved memories that match a request. remember saves one statement,
|
|
451
|
+
const DIRECTORY_INSTRUCTIONS = 'Renor single-owner memory: the owner\'s own saved memory, kept in their private workspace. get_context returns the current facts and the saved memories that match a request. remember saves one statement, or a value with its subject, predicate and object.';
|
|
452
|
+
/** A tool's config with its title copied into annotations.title, where the Claude directory reads a display name from. */
|
|
453
|
+
function withAnnotationTitle(config) {
|
|
454
|
+
if (typeof config?.title !== 'string' || config.annotations?.title !== undefined)
|
|
455
|
+
return config;
|
|
456
|
+
return { ...config, annotations: { ...config.annotations, title: config.title } };
|
|
457
|
+
}
|
|
381
458
|
/**
|
|
382
459
|
* The one tool only the dashboard may list or run: it erases retired memories for good. Its registerTool call below spells the name
|
|
383
460
|
* as a literal, because the docs binding and the hosted-tool tests read the registry off the literal call sites; if the two ever
|
|
@@ -402,23 +479,33 @@ function registeredToolEntry(server, name) {
|
|
|
402
479
|
* their own server (bounded, in-process); JSON mode shares one.
|
|
403
480
|
*/
|
|
404
481
|
function buildMcpServer(db, config, engine, idle, digests, usefulness, connection, announceFirst, telemetrySession = null, dashboard = false, directory = false) {
|
|
482
|
+
// RENOR_TOOL_OUTPUT_SCHEMAS, read once for this server: its tools list an outputSchema exactly when its answers carry
|
|
483
|
+
// structuredContent.
|
|
484
|
+
const withSchemas = toolOutputSchemasEnabled();
|
|
485
|
+
const jsonResult = (body) => jsonResultOf(body, withSchemas);
|
|
405
486
|
// Which Renor this is, on the first reply of a session and on every error (connectionStatus.ts); nothing in a workspace
|
|
406
487
|
// that is not hosted. A server that serves no session of its own (the stateless one, or one built for a session this
|
|
407
488
|
// process forgot) has no first reply to announce on.
|
|
408
489
|
const announcer = new connectionStatus_1.ConnectionAnnouncer(connection, announceFirst);
|
|
409
490
|
const evidence = (0, engine_1.resolveEngineEvidence)(config, process.env, idle);
|
|
491
|
+
// RENOR_ANSWER_CHECK (default off): null unless armed and the evidence pass has a key; then a relevant verdict a model
|
|
492
|
+
// reads as unanswered turns false. One per app, so every session shares its answers.
|
|
493
|
+
const answerChecker = (0, answerCheck_1.answerCheckerFor)(config, process.env);
|
|
410
494
|
// The reading agent's name as a save records it (remember's cleanSource and default), so its own facts carry no source.
|
|
411
495
|
const readerOf = (extra) => (0, sourceName_1.cleanSource)(sourceOf(undefined, extra, config) ?? '') || 'agent';
|
|
412
496
|
// Only told to agents while get_context can actually return the signal.
|
|
413
497
|
const relevanceGuidance = (0, contextRelevance_1.contextRelevanceArmed)(engine) ? contextRelevance_1.CONTEXT_RELEVANCE_GUIDANCE : '';
|
|
414
498
|
const relevanceKeepsMatch = relevanceGuidance ? contextRelevance_1.CONTEXT_RELEVANCE_KEEPS_MATCH : '';
|
|
415
499
|
const budgetKeepsNewest = relevanceGuidance ? contextRelevance_1.CONTEXT_BUDGET_KEEPS_NEWEST : ''; // where there is a bar, the budget reads it
|
|
416
|
-
|
|
500
|
+
// RENOR_MCP_* (contextProfile.ts, every lever off by default): a benchmark arm's tool subset, descriptions, instructions and
|
|
501
|
+
// reply shape. A directory client keeps the surface the directory rules fix.
|
|
502
|
+
const profile = directory ? {} : (0, contextProfile_1.contextProfileFromEnv)();
|
|
503
|
+
const server = new mcp_js_1.McpServer({ name: serverCard_1.SERVER_NAME, version: serverCard_1.SERVER_VERSION, icons: serverCard_1.SERVER_ICONS }, { instructions: directory ? DIRECTORY_INSTRUCTIONS : profile.instructions ?? ('Renor single-owner memory. At the start of every task, call whats_new before anything else. Open requests addressed to you are first in that reply; answering or closing one records the reply and never runs anything by itself. For substantive user requests, call get_context with the current request before answering so relevant prior context can follow the user across agents. '
|
|
417
504
|
+ 'Call it again before you decide something an earlier session may have settled and before you review another agent\'s work, with that choice or topic as the query: reading once at the start is not enough. '
|
|
418
505
|
+ 'To save anything, call remember with one argument, statement: the thing to remember, in plain words. When the user says to remember or save something, they mean this tool, not your own memory. '
|
|
419
506
|
+ 'Renor is the place for the why, next to your board or tracker, not a copy of it: when you save on your own, save decisions with their reason, root causes and corrections, not status, progress or event logs. '
|
|
420
507
|
+ 'Cite an earlier entry by its subject or task instead of restating it, and save nothing that only repeats one. '
|
|
421
|
-
+ 'Only for a value that stays current until it changes (a city, a database, a deadline, a preference), also pass subject, predicate and object together, never guessed: saving the same subject, predicate and scope again replaces the value and keeps the old one in history. save_memory is that structured form alone; remember_note appends a line to a day\'s log.' + relevanceGuidance });
|
|
508
|
+
+ 'Only for a value that stays current until it changes (a city, a database, a deadline, a preference), also pass subject, predicate and object together, never guessed: saving the same subject, predicate and scope again replaces the value and keeps the old one in history. save_memory is that structured form alone; remember_note appends a line to a day\'s log.' + relevanceGuidance) });
|
|
422
509
|
// PostHog MCP Analytics: per-server (SSE builds a fresh McpServer per session).
|
|
423
510
|
(0, posthogMcp_1.instrumentMcpServer)(server);
|
|
424
511
|
// Only the server of one SSE session is handed a telemetrySession: the JSON-mode server is shared by every client, so
|
|
@@ -448,13 +535,19 @@ function buildMcpServer(db, config, engine, idle, digests, usefulness, connectio
|
|
|
448
535
|
function tracedTool(tool, handler) {
|
|
449
536
|
// On-demand: a running tool call (a write, an index job) holds the engine awake
|
|
450
537
|
// even after its client disconnects.
|
|
451
|
-
const run = idle ? (...args) => idle.track(() => handler(...args)) : handler;
|
|
452
|
-
|
|
538
|
+
const run = idle ? (...args) => idle.track(async () => handler(...args)) : handler;
|
|
539
|
+
const traced = async (...args) => {
|
|
453
540
|
const started = Date.now();
|
|
454
541
|
const first = announcer.takeFirst();
|
|
455
542
|
noteFirstCall(tool);
|
|
543
|
+
// The two reads also say where their time went (callPhases.ts), on this same line; every other tool is as it was.
|
|
544
|
+
const phases = (0, callPhases_1.isPhasedTool)(tool) ? new callPhases_1.CallPhases() : undefined;
|
|
545
|
+
const phasesOf = () => {
|
|
546
|
+
const report = phases?.report();
|
|
547
|
+
return report && Object.keys(report).length > 0 ? { phases: report } : {};
|
|
548
|
+
};
|
|
456
549
|
try {
|
|
457
|
-
const result = await run(...args);
|
|
550
|
+
const result = await (phases ? phases.run(() => run(...args)) : run(...args));
|
|
458
551
|
const ok = toolResultOk(result);
|
|
459
552
|
(0, telemetry_1.emitTelemetry)({
|
|
460
553
|
event: 'tool_use',
|
|
@@ -464,6 +557,7 @@ function buildMcpServer(db, config, engine, idle, digests, usefulness, connectio
|
|
|
464
557
|
// error_kind is unchanged (dashboards read it); error_reason is what the refusal was: the code the
|
|
465
558
|
// refusal site named, or the generic `refused` for one that has no better code in the closed set.
|
|
466
559
|
...(ok ? {} : { error_kind: 'other', error_reason: (0, toolRefusal_1.toolRefusalOf)(result) ?? 'refused' }),
|
|
560
|
+
...phasesOf(),
|
|
467
561
|
});
|
|
468
562
|
return announcer.decorate(result, first);
|
|
469
563
|
}
|
|
@@ -475,20 +569,42 @@ function buildMcpServer(db, config, engine, idle, digests, usefulness, connectio
|
|
|
475
569
|
ms: Date.now() - started,
|
|
476
570
|
error_kind: 'internal',
|
|
477
571
|
error_reason: 'internal',
|
|
572
|
+
...phasesOf(),
|
|
478
573
|
});
|
|
479
574
|
throw err;
|
|
480
575
|
}
|
|
481
576
|
};
|
|
577
|
+
// Same arguments and the same result, awaited: the SDK awaits a tool's result whether or not the handler is async.
|
|
578
|
+
return traced;
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* A note save's row in write_events, which whats_new and memory_map's events read (delete_retired_memory takes it out
|
|
582
|
+
* again by path and this excerpt). Both note saves write it: remember with only a statement, and remember_note. The
|
|
583
|
+
* line keeps the engine's own default source; only the feed's author falls back to unnamed. Best effort: the note is
|
|
584
|
+
* already on disk, so a failure here must not answer an error the agent would retry into a duplicate line.
|
|
585
|
+
*/
|
|
586
|
+
function recordNoteSave(file, text, source, scope) {
|
|
587
|
+
try {
|
|
588
|
+
db.prepare('INSERT INTO write_events (note_path, action, summary, created_at, author, scope) VALUES (?, ?, ?, ?, ?, ?)')
|
|
589
|
+
.run(file, 'note', text.slice(0, 240), new Date().toISOString(), source ?? 'unnamed', scope);
|
|
590
|
+
}
|
|
591
|
+
catch (err) {
|
|
592
|
+
log.error('whats_new_row_failed', { detail: 'the note save was written' }, err);
|
|
593
|
+
}
|
|
482
594
|
}
|
|
483
595
|
const registerTool = server.registerTool.bind(server);
|
|
484
|
-
|
|
596
|
+
// The title also goes into annotations.title: the Claude directory reads a tool's display name from there and flags every tool
|
|
597
|
+
// without one.
|
|
598
|
+
const tracedRegisterTool = (name, config, cb) => registerTool(name, withAnnotationTitle(withOutputSchemaIf(withSchemas, config)), tracedTool(name, cb));
|
|
599
|
+
server.registerTool = tracedRegisterTool;
|
|
485
600
|
server.registerTool('remember', {
|
|
486
601
|
title: 'Remember something naturally',
|
|
487
602
|
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: false },
|
|
488
603
|
description: 'Save something to memory: pass `statement`, in plain words, and nothing else. Do not save passwords, API keys or tokens. Example: remember({"statement": "We moved the Fjord database to SQLite because it needs no server."}). It is stored whole and indexed at once, so get_context finds it right away; the receipt\'s id is what read_memory and retire_memory take. `scope` ("project:<slug>") keeps it with one project. '
|
|
489
604
|
+ 'Only for a value that stays current until it changes (a city, a project\'s database, a deadline, a preference), also pass subject, predicate and object together: "subject": "Fjord", "predicate": "database", "object": "SQLite". Saving the same subject, predicate and scope again replaces the value: the old one leaves current reads and stays in history. A save by a different agent than the one that saved the current value is shown in reads as a CONFLICT line until that agent saves it again (see save_memory). Spell them the same every time. Decisions, events and notes need none of the three: leave them out, never guess them. '
|
|
490
605
|
+ `The same statement for the same fact again changes nothing. A statement over ${limits_1.MAX_STATEMENT_LENGTH} characters is refused, never cut, in either form. Saved on its own as a note, one that is not valid Unicode or holds a control character (U+0000 to U+001F except tab, newline and carriage return, or U+007F) is refused and nothing is written; with subject, predicate and object it is saved as a fact with its control characters escaped in the ledger, and only those three fields refuse them. A fact receipt may list possibleDuplicates (the same predicate under a name one word longer or shorter, or in another scope): nothing is merged; to correct one, save again with its subject and scope. A save is compared within the scope it names.`
|
|
491
|
-
+ ' To correct one specific earlier note or log entry (not a fact), also pass `replaces`, its id (from memory_map with a query, or an earlier save\'s receipt): that memory is then marked replaced, with a pointer to this save, in every recall, and this save is listed before it. Nothing is deleted; retire_memory on this save undoes it, and the receipt says `replaced` (or `replacesIgnored` when linking would make a loop, as when the save is the same line as the memory it replaces).'
|
|
606
|
+
+ ' To correct one specific earlier note or log entry (not a fact), also pass `replaces`, its id (from memory_map with a query, or an earlier save\'s receipt): that memory is then marked replaced, with a pointer to this save, in every recall, and this save is listed before it. Nothing is deleted; retire_memory on this save undoes it, and the receipt says `replaced` (or `replacesIgnored` when linking would make a loop, as when the save is the same line as the memory it replaces). '
|
|
607
|
+
+ 'Sent with subject, predicate and object as well, replaces naming a note or entry makes the save that plain-words correction (`factFieldsIgnored`), and replaces naming a fact is dropped while the fact is saved (`replacesIgnored`).',
|
|
492
608
|
inputSchema: {
|
|
493
609
|
statement: zod_1.z.string().min(1).max(limits_1.MAX_STATEMENT_LENGTH).describe('The thing to remember, in plain words.'),
|
|
494
610
|
subject: omittedWhenBlank(zod_1.z.string().optional()).describe('With predicate and object: who or what the value is about, e.g. "Fjord".'),
|
|
@@ -500,6 +616,29 @@ function buildMcpServer(db, config, engine, idle, digests, usefulness, connectio
|
|
|
500
616
|
cites: CITES_ARG,
|
|
501
617
|
replaces: REPLACES_ARG,
|
|
502
618
|
},
|
|
619
|
+
outputSchema: zod_1.z.looseObject({
|
|
620
|
+
ok: zod_1.z.boolean(),
|
|
621
|
+
mode: zod_1.z.enum(['fact', 'note']),
|
|
622
|
+
statement: zod_1.z.string(),
|
|
623
|
+
action: zod_1.z.enum(['store', 'supersede', 'nochange']).optional(),
|
|
624
|
+
eventId: zod_1.z.string().optional(),
|
|
625
|
+
subject: zod_1.z.string().optional(),
|
|
626
|
+
predicate: zod_1.z.string().optional(),
|
|
627
|
+
closed: OUT_CLOSED_FACT,
|
|
628
|
+
alsoClosed: OUT_CLOSED_FACT,
|
|
629
|
+
created: OUT_CREATED_FACT,
|
|
630
|
+
scope: zod_1.z.string().optional(),
|
|
631
|
+
possibleDuplicates: OUT_DUPLICATES,
|
|
632
|
+
possibleDuplicatesTotal: zod_1.z.number().optional(),
|
|
633
|
+
file: zod_1.z.string().optional(),
|
|
634
|
+
id: zod_1.z.string().optional(),
|
|
635
|
+
replaced: OUT_REPLACEMENT,
|
|
636
|
+
replacesIgnored: zod_1.z.string().optional(),
|
|
637
|
+
indexed: zod_1.z.boolean().optional(),
|
|
638
|
+
index: OUT_INDEX_PASS,
|
|
639
|
+
warning: zod_1.z.string().optional(),
|
|
640
|
+
detail: zod_1.z.string().optional(),
|
|
641
|
+
}),
|
|
503
642
|
}, async (args, extra) => {
|
|
504
643
|
try {
|
|
505
644
|
const structured = [args.subject, args.predicate, args.object];
|
|
@@ -507,13 +646,26 @@ function buildMcpServer(db, config, engine, idle, digests, usefulness, connectio
|
|
|
507
646
|
if (present !== 0 && present !== 3) {
|
|
508
647
|
throw (0, toolRefusal_1.refusal)('invalid_argument', 'remember requires subject, predicate, and object together, or none of them: to save plain words pass only statement');
|
|
509
648
|
}
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
649
|
+
// A client may send a value's subject, predicate and object together with replaces. One of the two is kept rather than the
|
|
650
|
+
// call refused, so the save lands on the first try: replaces naming a fact is dropped (a fact is corrected by saving it
|
|
651
|
+
// again, which this save does), and replaces naming a note or log entry wins (the save becomes a plain-words correction
|
|
652
|
+
// of it, which is the only way that note is marked replaced). The receipt says which.
|
|
653
|
+
let replaces = args.replaces;
|
|
654
|
+
let asFact = present === 3;
|
|
655
|
+
let adjusted = {};
|
|
656
|
+
if (replaces !== undefined && asFact) {
|
|
657
|
+
if (replaces.startsWith('fact:')) {
|
|
658
|
+
replaces = undefined;
|
|
659
|
+
adjusted = { replacesIgnored: 'replaces named a fact: a fact is corrected by saving it again with the same subject, predicate and scope, which this save did' };
|
|
660
|
+
}
|
|
661
|
+
else {
|
|
662
|
+
asFact = false;
|
|
663
|
+
adjusted = { factFieldsIgnored: 'replaces named a note or log entry, so this save is a plain-words correction of it; subject, predicate and object were not saved as a fact' };
|
|
513
664
|
}
|
|
514
|
-
await (0, replacements_1.assertReplaceable)(mapContext(), args.replaces, (0, scope_1.normalizeScope)(args.scope));
|
|
515
665
|
}
|
|
516
|
-
if (
|
|
666
|
+
if (replaces !== undefined)
|
|
667
|
+
await (0, replacements_1.assertReplaceable)(mapContext(), replaces, (0, scope_1.normalizeScope)(args.scope));
|
|
668
|
+
if (asFact) {
|
|
517
669
|
const receipt = await (0, lifecycle_1.remember)(db, config.memoryDir, config.ledgerRelPath, {
|
|
518
670
|
subject: args.subject,
|
|
519
671
|
predicate: args.predicate,
|
|
@@ -568,14 +720,17 @@ function buildMcpServer(db, config, engine, idle, digests, usefulness, connectio
|
|
|
568
720
|
scope: (0, scope_1.normalizeScope)(args.scope),
|
|
569
721
|
...(duplicates.values.length > 0 ? { possibleDuplicates: duplicates.values } : {}),
|
|
570
722
|
...(duplicates.total > duplicates.values.length ? { possibleDuplicatesTotal: duplicates.total } : {}),
|
|
723
|
+
...adjusted,
|
|
571
724
|
...refresh,
|
|
572
725
|
});
|
|
573
726
|
}
|
|
574
|
-
const
|
|
727
|
+
const source = sourceOf(args.source, extra, config);
|
|
728
|
+
const note = await (0, engine_1.engineRememberNote)(config, args.statement, undefined, source ?? 'mcp:remember', args.scope, args.timezone);
|
|
729
|
+
recordNoteSave(note.file, args.statement, source, note.scope);
|
|
575
730
|
usefulness.cited(args.cites);
|
|
576
|
-
const replaced =
|
|
731
|
+
const replaced = replaces !== undefined && note.id
|
|
577
732
|
// The source the entry was written with (the default of this write, when none), so the link names the same one.
|
|
578
|
-
? await replacementReceipt(
|
|
733
|
+
? await replacementReceipt(replaces, note.id, source ?? 'mcp:remember')
|
|
579
734
|
: {};
|
|
580
735
|
return jsonResult({
|
|
581
736
|
ok: true,
|
|
@@ -584,6 +739,7 @@ function buildMcpServer(db, config, engine, idle, digests, usefulness, connectio
|
|
|
584
739
|
file: note.file,
|
|
585
740
|
scope: note.scope,
|
|
586
741
|
...(note.id ? { id: note.id } : {}),
|
|
742
|
+
...adjusted,
|
|
587
743
|
...replaced,
|
|
588
744
|
...(await indexSavedNote(db, config, engine, digests, note.file)),
|
|
589
745
|
});
|
|
@@ -595,14 +751,34 @@ function buildMcpServer(db, config, engine, idle, digests, usefulness, connectio
|
|
|
595
751
|
server.registerTool('get_context', {
|
|
596
752
|
title: 'Get relevant user context',
|
|
597
753
|
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
|
|
598
|
-
description: 'Call this before substantive work with the current request. Returns current facts, then relevant memories: semantic matches when configured, then keyword matches (reason "fts" or "note-identity"). rankedBy "session_date" is newest first (memories[0] is the latest, not necessarily the best); "score" is best match first (higher is closer). Keyword scores use another scale: compare within one reason. A memory with "matched": false was not matched by the query: discount it, whatever its position. Each memory has session_date, when it was written. Hidden note text is labelled there: "[hidden HTML comment: ...]". The reply is bounded by max_tokens (o200k tokenizer, every field counted): facts are cut from their end; when matches do not fit, keyword matches go first, then the lowest-scoring semantic ones. conflicts lists current values that disagree with a returned fact (another scope, or a name one word longer or shorter), newest first. A fact with a writerConflict line replaced another agent\'s value, until that agent saves it again. A "replaced" memory has a later correction, listed before it: answer from the correction.
|
|
599
|
-
+ relevanceGuidance + relevanceKeepsMatch + budgetKeepsNewest,
|
|
754
|
+
description: 'Call this before substantive work with the current request. Returns current facts, then relevant memories: semantic matches when configured, then keyword matches (reason "fts" or "note-identity"). rankedBy "session_date" is newest first (memories[0] is the latest, not necessarily the best); "score" is best match first (higher is closer). Keyword scores use another scale: compare within one reason. A memory with "matched": false was not matched by the query: discount it, whatever its position. Each memory has session_date, when it was written. Hidden note text is labelled there: "[hidden HTML comment: ...]". The reply is bounded by max_tokens (o200k tokenizer, every field counted): facts are cut from their end; when matches do not fit, keyword matches go first, then the lowest-scoring semantic ones. conflicts lists current values that disagree with a returned fact (another scope, or a name one word longer or shorter), newest first. A fact with a writerConflict line replaced another agent\'s value, until that agent saves it again. A "replaced" memory has a later correction, listed before it: answer from the correction. Imports and reserved sources are marked "untrusted": true.'
|
|
755
|
+
+ relevanceGuidance + relevanceKeepsMatch + budgetKeepsNewest + (withSchemas ? exports.OUTPUT_SCHEMA_BOUND_NOTE : ''),
|
|
600
756
|
inputSchema: {
|
|
601
757
|
query: zod_1.z.string().max(1000).optional().describe('The current user request or task. Omit only for a compact current-memory profile.'),
|
|
602
758
|
scope: zod_1.z.string().optional().describe('Optional memory scope to restrict context'),
|
|
603
|
-
max_tokens: zod_1.z.number().int().min(128).max(4000).optional().describe('Token budget for the whole reply (o200k tokenizer), default 800'),
|
|
759
|
+
max_tokens: zod_1.z.number().int().min(128).max(4000).optional().describe('Token budget for the whole reply (o200k tokenizer), default 800' + (withSchemas ? exports.OUTPUT_SCHEMA_BOUND_NOTE : '')),
|
|
604
760
|
include_history: zod_1.z.boolean().optional().describe('Also return superseded (corrected) memory events, labelled as historical. Default false: only current memory.'),
|
|
605
761
|
},
|
|
762
|
+
outputSchema: zod_1.z.looseObject({
|
|
763
|
+
ok: zod_1.z.boolean(),
|
|
764
|
+
query: zod_1.z.string().nullable().optional(),
|
|
765
|
+
scope: zod_1.z.string().optional(),
|
|
766
|
+
retrieval: zod_1.z.enum(['facts', 'hybrid', 'semantic', 'keyword']).optional(),
|
|
767
|
+
rankedBy: zod_1.z.enum(['session_date', 'score']).optional(),
|
|
768
|
+
facts: zod_1.z.array(OUT_HIT).optional(),
|
|
769
|
+
memories: zod_1.z.array(OUT_HIT).optional(),
|
|
770
|
+
truncated: zod_1.z.boolean().optional(),
|
|
771
|
+
maxTokens: zod_1.z.number().optional(),
|
|
772
|
+
notice: zod_1.z.string().optional(),
|
|
773
|
+
degraded: zod_1.z.array(zod_1.z.string()).optional(),
|
|
774
|
+
relevance: OUT_HIT.optional(),
|
|
775
|
+
conflicts: zod_1.z.array(OUT_HIT).optional(),
|
|
776
|
+
provenance: OUT_HIT.optional(),
|
|
777
|
+
abstention: zod_1.z.unknown().optional(),
|
|
778
|
+
evidence: OUT_HIT.optional(),
|
|
779
|
+
index: OUT_HIT.optional(),
|
|
780
|
+
renor: zod_1.z.string().optional(),
|
|
781
|
+
}),
|
|
606
782
|
}, async (args, extra) => {
|
|
607
783
|
try {
|
|
608
784
|
const semantic = engine.provider !== null && Boolean(args.query?.trim());
|
|
@@ -618,8 +794,9 @@ function buildMcpServer(db, config, engine, idle, digests, usefulness, connectio
|
|
|
618
794
|
// Which Renor answered: inside max_tokens with the rest of the trailer.
|
|
619
795
|
trailer: () => ({ ...(0, factsLane_1.indexNotice)(db, semantic, config, args.scope), renor: (0, identity_1.identityLine)(extra?.requestInfo?.headers) }),
|
|
620
796
|
});
|
|
621
|
-
|
|
622
|
-
|
|
797
|
+
const checked = await (0, answerCheck_1.applyAnswerCheck)(body, args.query, answerChecker, body.maxTokens);
|
|
798
|
+
usefulness.measure('get_context', () => (0, readUsefulness_1.contextItems)(checked));
|
|
799
|
+
return jsonResult(checked);
|
|
623
800
|
}
|
|
624
801
|
catch (err) {
|
|
625
802
|
return toolError(err);
|
|
@@ -639,6 +816,19 @@ function buildMcpServer(db, config, engine, idle, digests, usefulness, connectio
|
|
|
639
816
|
scope: SCOPE_ARG,
|
|
640
817
|
cites: CITES_ARG,
|
|
641
818
|
},
|
|
819
|
+
outputSchema: zod_1.z.looseObject({
|
|
820
|
+
ok: zod_1.z.boolean(),
|
|
821
|
+
action: zod_1.z.enum(['store', 'supersede', 'nochange']),
|
|
822
|
+
eventId: zod_1.z.string(),
|
|
823
|
+
subject: zod_1.z.string(),
|
|
824
|
+
predicate: zod_1.z.string(),
|
|
825
|
+
closed: OUT_CLOSED_FACT,
|
|
826
|
+
alsoClosed: OUT_CLOSED_FACT,
|
|
827
|
+
created: OUT_CREATED_FACT,
|
|
828
|
+
possibleDuplicates: OUT_DUPLICATES,
|
|
829
|
+
possibleDuplicatesTotal: zod_1.z.number().optional(),
|
|
830
|
+
ledger: zod_1.z.string(),
|
|
831
|
+
}),
|
|
642
832
|
}, async (args, extra) => {
|
|
643
833
|
try {
|
|
644
834
|
const { subject, predicate, object } = args;
|
|
@@ -685,7 +875,7 @@ function buildMcpServer(db, config, engine, idle, digests, usefulness, connectio
|
|
|
685
875
|
server.registerTool('retrieve_memory', {
|
|
686
876
|
title: 'Retrieve memories',
|
|
687
877
|
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
|
|
688
|
-
description: 'Returns the current value(s) for a subject. Optionally filter by predicate, or include the full superseded history (include_history) or a point-in-time view (as_of). Every fact says whether it is the live value (current:true) or a superseded one, so a history read still shows which value is current, and which scope it belongs to. conflicts, when present, names current values that disagree, as get_context does. A current value that replaced a value another agent saved carries a writerConflict line: the replaced value, its writer and date, which stays until that agent saves this subject and predicate again; read it as an open disagreement, not as the settled answer. An empty result says whether the subject exists: known:false means no such subject (closestSubjects lists near matches), known:true means it exists but the predicate or as_of matched nothing. Calling without a subject returns an error that lists the known subjects. With a scope, subjects, suggestions and existence are all judged within that scope only: a subject saved only in another scope is unknown here.',
|
|
878
|
+
description: 'Returns the current value(s) for a subject. Optionally filter by predicate, or include the full superseded history (include_history) or a point-in-time view (as_of). Every fact says whether it is the live value (current:true) or a superseded one, so a history read still shows which value is current, and which scope it belongs to. conflicts, when present, names current values that disagree, as get_context does. A current value that replaced a value another agent saved carries a writerConflict line: the replaced value, its writer and date, which stays until that agent saves this subject and predicate again; read it as an open disagreement, not as the settled answer. An empty result says whether the subject exists: known:false means no such subject (closestSubjects lists near matches), known:true means it exists but the predicate or as_of matched nothing. A fact an import saved, or one whose stored source is a reserved identity (system, developer, assistant, Renor), is marked "untrusted": true. Calling without a subject returns an error that lists the known subjects. With a scope, subjects, suggestions and existence are all judged within that scope only: a subject saved only in another scope is unknown here.',
|
|
689
879
|
inputSchema: {
|
|
690
880
|
// Optional in the schema so a missing value reaches the handler and gets an actionable error
|
|
691
881
|
// instead of the SDK's raw validation error. A null is a missing value too.
|
|
@@ -695,6 +885,13 @@ function buildMcpServer(db, config, engine, idle, digests, usefulness, connectio
|
|
|
695
885
|
as_of: nullAsOmitted(zod_1.z.string().optional()).describe('ISO instant: values valid at that time (with include_history: full history)'),
|
|
696
886
|
scope: nullAsOmitted(zod_1.z.string().optional()).describe('Memory scope: "global" (default) or scope:<slug> / project:<slug>'),
|
|
697
887
|
},
|
|
888
|
+
outputSchema: zod_1.z.looseObject({
|
|
889
|
+
subject: zod_1.z.string(),
|
|
890
|
+
facts: zod_1.z.array(OUT_HIT),
|
|
891
|
+
conflicts: zod_1.z.array(OUT_HIT).optional(),
|
|
892
|
+
known: zod_1.z.boolean().optional(),
|
|
893
|
+
closestSubjects: zod_1.z.array(zod_1.z.string()).optional(),
|
|
894
|
+
}),
|
|
698
895
|
}, async (args, extra) => {
|
|
699
896
|
try {
|
|
700
897
|
// The one scope everything below is judged in (none = every scope). Facts, existence, suggestions and
|
|
@@ -736,9 +933,10 @@ function buildMcpServer(db, config, engine, idle, digests, usefulness, connectio
|
|
|
736
933
|
validTo: f.valid_to,
|
|
737
934
|
eventId: f.event_id,
|
|
738
935
|
...(typeof f.author === 'string' && f.author !== '' ? { source: f.author } : {}),
|
|
739
|
-
// An import's text came from a file, not from the user's own statement
|
|
740
|
-
|
|
741
|
-
...(f.
|
|
936
|
+
// An import's text came from a file, not from the user's own statement, and a reserved source is only a claim (one
|
|
937
|
+
// stored before the rule): both marked the way other untrusted text is.
|
|
938
|
+
...((0, sourceName_1.isImportSource)(f.author) || (0, sourceName_1.isReservedSource)(f.author) ? { untrusted: true } : {}),
|
|
939
|
+
...(f.valid_to == null && f.event_id !== null && displaced.has(f.event_id) ? { writerConflict: displaced.get(f.event_id) } : {}),
|
|
742
940
|
}));
|
|
743
941
|
const body = { subject, facts: rows };
|
|
744
942
|
// Current values that disagree with another current value of the same predicate under this subject in another
|
|
@@ -775,6 +973,22 @@ function buildMcpServer(db, config, engine, idle, digests, usefulness, connectio
|
|
|
775
973
|
section: nullAsOmitted(zod_1.z.enum(exportAll_1.EXPORT_SECTIONS).optional()).describe('Continue with this section only (from the manifest\'s nextSection)'),
|
|
776
974
|
offset: nullAsOmitted(zod_1.z.number().int().min(0).optional()).describe('The item of that section to continue from (from the manifest\'s nextItem); default 0'),
|
|
777
975
|
},
|
|
976
|
+
outputSchema: zod_1.z.looseObject({
|
|
977
|
+
file: zod_1.z.string(),
|
|
978
|
+
format: zod_1.z.string(),
|
|
979
|
+
formatVersion: zod_1.z.string(),
|
|
980
|
+
bytes: zod_1.z.number().nullable(),
|
|
981
|
+
counts: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()),
|
|
982
|
+
sections: zod_1.z.array(zod_1.z.object({ name: zod_1.z.string(), items: zod_1.z.number().nullable(), events: zod_1.z.number().nullable().optional() })),
|
|
983
|
+
notExported: zod_1.z.array(zod_1.z.object({ kind: zod_1.z.string(), what: zod_1.z.string(), reason: zod_1.z.string() })),
|
|
984
|
+
included: zod_1.z.array(zod_1.z.string()),
|
|
985
|
+
truncated: zod_1.z.boolean(),
|
|
986
|
+
nextSection: zod_1.z.string().nullable(),
|
|
987
|
+
nextItem: zod_1.z.number().optional(),
|
|
988
|
+
documentChars: zod_1.z.number(),
|
|
989
|
+
section: zod_1.z.string().optional(),
|
|
990
|
+
offset: zod_1.z.number().optional(),
|
|
991
|
+
}),
|
|
778
992
|
}, async (args) => {
|
|
779
993
|
try {
|
|
780
994
|
const { manifest, document } = await (0, exportAll_1.exportEverything)(mapContext(), { section: args.section, offset: args.offset });
|
|
@@ -785,6 +999,9 @@ function buildMcpServer(db, config, engine, idle, digests, usefulness, connectio
|
|
|
785
999
|
{ type: 'text', text: (0, sanitize_1.escapeInvisibleControls)(JSON.stringify(manifest)) },
|
|
786
1000
|
{ type: 'text', text: document },
|
|
787
1001
|
],
|
|
1002
|
+
// The structured result (output schemas on) is the manifest: JSON.parse of the first block, the value a client parses
|
|
1003
|
+
// from it. The second block (the portable document) is not structured data.
|
|
1004
|
+
...(withSchemas ? { structuredContent: JSON.parse((0, sanitize_1.escapeInvisibleControls)(JSON.stringify(manifest))) } : {}),
|
|
788
1005
|
};
|
|
789
1006
|
}
|
|
790
1007
|
catch (err) {
|
|
@@ -799,6 +1016,21 @@ function buildMcpServer(db, config, engine, idle, digests, usefulness, connectio
|
|
|
799
1016
|
query: zod_1.z.string().min(1).max(200).describe('Lexical search terms, 1..200 characters'),
|
|
800
1017
|
limit: zod_1.z.number().int().min(1).max(20).optional().describe('Max results (default 5, max 20)'),
|
|
801
1018
|
},
|
|
1019
|
+
outputSchema: zod_1.z.looseObject({
|
|
1020
|
+
ok: zod_1.z.boolean(),
|
|
1021
|
+
configured: zod_1.z.boolean(),
|
|
1022
|
+
results: zod_1.z.array(OUT_HIT),
|
|
1023
|
+
query: zod_1.z.string().optional(),
|
|
1024
|
+
total_matches: zod_1.z.number().optional(),
|
|
1025
|
+
returned: zod_1.z.number().optional(),
|
|
1026
|
+
skipped_ineligible: zod_1.z.number().optional(),
|
|
1027
|
+
skipped_too_large: zod_1.z.number().optional(),
|
|
1028
|
+
skipped_over_limit: zod_1.z.number().optional(),
|
|
1029
|
+
note: zod_1.z.string().optional(),
|
|
1030
|
+
error: zod_1.z.string().optional(),
|
|
1031
|
+
detail: zod_1.z.string().optional(),
|
|
1032
|
+
disclaimer: zod_1.z.string(),
|
|
1033
|
+
}),
|
|
802
1034
|
}, async (args) => {
|
|
803
1035
|
try {
|
|
804
1036
|
const response = (0, history_1.searchHistory)(config.historyDir, args.query, args.limit);
|
|
@@ -808,17 +1040,14 @@ function buildMcpServer(db, config, engine, idle, digests, usefulness, connectio
|
|
|
808
1040
|
if (err instanceof history_1.HistoryUnavailableError) {
|
|
809
1041
|
// Bounded, explicit, fail-closed: the configured history is unusable,
|
|
810
1042
|
// but fact memory is untouched and the service stays up.
|
|
811
|
-
return (0, toolRefusal_1.markToolRefusal)({
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
}),
|
|
820
|
-
isError: true,
|
|
821
|
-
}, 'capability_unavailable');
|
|
1043
|
+
return (0, toolRefusal_1.markToolRefusal)(refusalResult({
|
|
1044
|
+
ok: false,
|
|
1045
|
+
configured: true,
|
|
1046
|
+
error: 'history-not-available',
|
|
1047
|
+
detail: err.message.slice(0, 300),
|
|
1048
|
+
results: [],
|
|
1049
|
+
disclaimer: history_1.HISTORY_DISCLAIMER,
|
|
1050
|
+
}), 'capability_unavailable');
|
|
822
1051
|
}
|
|
823
1052
|
return toolError(err);
|
|
824
1053
|
}
|
|
@@ -826,13 +1055,26 @@ function buildMcpServer(db, config, engine, idle, digests, usefulness, connectio
|
|
|
826
1055
|
server.registerTool('search_memory', {
|
|
827
1056
|
title: 'Search memory by meaning (where enabled)',
|
|
828
1057
|
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
|
|
829
|
-
description: 'Searches notes by meaning when memory_status reports semantic: true;
|
|
1058
|
+
description: 'Searches notes by meaning when memory_status reports semantic: true; else it returns no hits and says why (semantic-unavailable or semantic-rebuilding), so use search_text or get_context. rankedBy "session_date" (the default) is newest first, so hits[0] is the latest, not necessarily the best; "score" is best match first. Judge hits by score (higher is closer), not position. A conversation\'s hits on one date are one hit, opening with its date (its header alone is no hit); a time phrase in it is resolved below, counted from that session. A hit without session_date comes last; a fact\'s hit has no notePath. There is no `evidence` object when this deployment has no evidence model configured and the pass is not switched off: no second pass runs, and the hits are the whole result. When there is one, its items come first, outside rankedBy, with reason "evidence", and its state is "ok", "off", "not-applied" or "failed". Facts saved with remember are added outside rankedBy, within top_k; a writerConflict line on one means it replaced another agent\'s value. index.stale: the semantic index lags saved facts. A "replaced" hit\'s correction is listed before it (by: its id, source: who saved it).' + (evidence?.options.background ? EVIDENCE_WAIT_STATES : '') + (evidence?.options.dailyCap !== undefined ? EVIDENCE_DAILY_CAP_STATE : '') + (digests ? DIGEST_HITS : '') + ((0, readerLayout_1.readerLayoutEnabled)() && (0, questionSpan_1.readerDurationNamed)() ? SPAN_HITS : '') + ((0, readerEvents_1.readerEventsNamed)() ? EVENTS_HITS : '') + ((0, readerLayout_1.readerTimelineEnabled)() ? TIMELINE_HITS : '') + (relevanceGuidance ? contextRelevance_1.SEARCH_RELEVANCE_GUIDANCE : ''),
|
|
830
1059
|
inputSchema: {
|
|
831
1060
|
query: zod_1.z.string().min(1).max(500).describe('Natural language query'),
|
|
832
1061
|
top_k: zod_1.z.number().int().min(1).max(50).optional().describe('Max matches (default 20), not counting the short statements the session expansion adds to them'),
|
|
833
1062
|
scope: zod_1.z.string().optional().describe('Memory scope: "global" (default) or scope:<slug> / project:<slug>'),
|
|
834
1063
|
include_history: zod_1.z.boolean().optional().describe('Also return superseded (corrected) memory events, labelled as historical. Default false: only current memory.'),
|
|
835
1064
|
},
|
|
1065
|
+
outputSchema: zod_1.z.looseObject({
|
|
1066
|
+
ok: zod_1.z.boolean(),
|
|
1067
|
+
hits: zod_1.z.array(OUT_HIT),
|
|
1068
|
+
error: zod_1.z.string().optional(),
|
|
1069
|
+
notice: zod_1.z.string().optional(),
|
|
1070
|
+
note: zod_1.z.string().optional(),
|
|
1071
|
+
rankedBy: zod_1.z.enum(['session_date', 'score']).optional(),
|
|
1072
|
+
scope: zod_1.z.string().optional(),
|
|
1073
|
+
evidence: OUT_HIT.optional(),
|
|
1074
|
+
index: OUT_HIT.optional(),
|
|
1075
|
+
relevance: OUT_HIT.optional(),
|
|
1076
|
+
floor: zod_1.z.object({ similarity: zod_1.z.number(), withheld: zod_1.z.number() }).optional(),
|
|
1077
|
+
}),
|
|
836
1078
|
}, async (args, extra) => {
|
|
837
1079
|
try {
|
|
838
1080
|
const topK = args.top_k ?? 20;
|
|
@@ -851,6 +1093,7 @@ function buildMcpServer(db, config, engine, idle, digests, usefulness, connectio
|
|
|
851
1093
|
query: args.query, scope: args.scope, includeHistory: args.include_history === true, ledgerRelPath: config.ledgerRelPath,
|
|
852
1094
|
}, probe, body.hits, topK);
|
|
853
1095
|
const hits = (0, factsLane_1.withFactHits)(db, config, body.hits, { query: args.query, scope: args.scope, match: 'any', limit: topK, dated: true, reader: readerOf(extra) }, verdict.listFact ? [verdict.listFact] : []);
|
|
1096
|
+
(0, callPhases_1.markRetrieved)(); // the matches and the facts are in hand: what follows builds the reply
|
|
854
1097
|
// Filter the completed page without backfilling. If the operator raises the floor above the relevance
|
|
855
1098
|
// bar and removes the closest chunk, withhold its verdict: the unchanged tool guidance promises the match.
|
|
856
1099
|
const floored = floor === 0 ? null : (0, hitFloor_1.applyHitFloor)(hits, floor);
|
|
@@ -868,22 +1111,26 @@ function buildMcpServer(db, config, engine, idle, digests, usefulness, connectio
|
|
|
868
1111
|
if (!filteredVerdict.relevance)
|
|
869
1112
|
shownVerdict = {};
|
|
870
1113
|
}
|
|
871
|
-
// What the read served is the page the caller is shown, floor included: a hit the floor left out was not served, and
|
|
872
|
-
// a page it left empty served nothing, whatever the verdict judged over every hit.
|
|
873
|
-
usefulness.measure('search_memory', () => {
|
|
874
|
-
const served = (0, readUsefulness_1.searchItems)(db, (0, ledgerPresentation_1.ledgerNoteMatcher)(config), page, shownVerdict.relevance);
|
|
875
|
-
return floored && served.items.length === 0 ? { ...served, relevant: false } : served;
|
|
876
|
-
});
|
|
877
1114
|
// The event of a fact is read from the ledger's heading, which is taken off below.
|
|
1115
|
+
const layout = (0, readerLayout_1.readerLayoutPage)(body.rankedBy, (await (0, replacements_1.withReplacements)(mapContext(), (0, ledgerPresentation_1.withoutLedgerMetadata)(page, (0, ledgerPresentation_1.ledgerNoteMatcher)(config)), { limit: Math.max(page.length, topK) })).map(hiddenSpans_1.labelMemoryText), (0, ledgerPresentation_1.ledgerNoteMatcher)(config), { query: args.query, turnsOf: (0, readerEvents_1.readerEventsEnabled)() ? (0, readerEvents_1.noteTurnsLoader)(db) : undefined, scoreTurns: (0, readerEvents_1.readerEventsEnabled)() && (0, readerEvents_1.vectorsMeanSomething)(engine.provider?.identity?.kind) && probe.queryVector && engine.vectorIndex ? (0, readerEvents_1.turnScorer)(engine.vectorIndex, probe.queryVector) : undefined }, laidOut);
|
|
878
1116
|
result = {
|
|
879
1117
|
...body,
|
|
880
|
-
|
|
1118
|
+
// With RENOR_READER_ORDER=relevance a page of conversations comes best match first (readerLayout.ts), and says so.
|
|
1119
|
+
rankedBy: layout.rankedBy,
|
|
1120
|
+
hits: layout.hits.map(markStoredHit).map(shortScore).map(agentMemory_1.headingForReply),
|
|
881
1121
|
...(0, factsLane_1.indexNotice)(db, true, config, args.scope),
|
|
882
1122
|
...(shownVerdict.relevance ? { relevance: shownVerdict.relevance } : {}),
|
|
883
1123
|
...(floored ? { floor: { similarity: floor, withheld: floored.withheld } } : {}),
|
|
884
1124
|
};
|
|
1125
|
+
result = await (0, answerCheck_1.applyAnswerCheck)(result, args.query, answerChecker);
|
|
1126
|
+
// What the read served is the page the caller is shown, floor included: a hit the floor left out was not served, and
|
|
1127
|
+
// a page it left empty served nothing, whatever the verdict judged over every hit.
|
|
1128
|
+
usefulness.measure('search_memory', () => {
|
|
1129
|
+
const served = (0, readUsefulness_1.searchItems)(db, (0, ledgerPresentation_1.ledgerNoteMatcher)(config), page, result.relevance);
|
|
1130
|
+
return floored && served.items.length === 0 ? { ...served, relevant: false } : served;
|
|
1131
|
+
});
|
|
885
1132
|
}
|
|
886
|
-
return searchResult(body, result);
|
|
1133
|
+
return searchResult(body, result, withSchemas);
|
|
887
1134
|
}
|
|
888
1135
|
catch (err) {
|
|
889
1136
|
return toolError(err);
|
|
@@ -892,7 +1139,7 @@ function buildMcpServer(db, config, engine, idle, digests, usefulness, connectio
|
|
|
892
1139
|
server.registerTool('search_text', {
|
|
893
1140
|
title: 'Search memory by keywords',
|
|
894
1141
|
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
|
|
895
|
-
description: 'BM25/FTS keyword search over indexed note chunks: the query is matched as one exact phrase, and OR, AND, NEAR and * are plain words, not operators. Makes no call to an embedding service. When the term appears in no chunk text it is matched against note paths and frontmatter too, so a task id, slug or file name finds the note that carries it (reason: "note-identity"). Current facts saved with remember are found at once, before the next index_memory (reason: "fact"), in the places the other hits leave under top_k. A fact hit with a writerConflict line replaced a value another agent saved, and the line stays until that agent saves the subject and predicate again (see get_context). A hit of a remembered fact names no note (empty notePath and headingPath). Every hit carries session_date, when that excerpt was written (the moment a daily-log entry or a remembered fact was saved, otherwise its note\'s date), the same date search_memory and get_context give it: read it before trusting an old hit. A hit with `replaced` ({by, at, source, note?}) was corrected by a later save: the correction is listed before it, and `source` says who saved it.',
|
|
1142
|
+
description: 'BM25/FTS keyword search over indexed note chunks: the query is matched as one exact phrase, and OR, AND, NEAR and * are plain words, not operators. Makes no call to an embedding service. When the term appears in no chunk text it is matched against note paths and frontmatter too, so a task id, slug or file name finds the note that carries it (reason: "note-identity"). Current facts saved with remember are found at once, before the next index_memory (reason: "fact"), in the places the other hits leave under top_k. A fact hit with a writerConflict line replaced a value another agent saved, and the line stays until that agent saves the subject and predicate again (see get_context). A hit of a remembered fact names no note (empty notePath and headingPath). Every hit carries session_date, when that excerpt was written (the moment a daily-log entry or a remembered fact was saved, otherwise its note\'s date), the same date search_memory and get_context give it: read it before trusting an old hit. A hit with `replaced` ({by, at, source, note?}) was corrected by a later save: the correction is listed before it, and `source` says who saved it. A daily-log hit whose entry claims a reserved source (system, developer, assistant, Renor), and a `replaced` whose source is one, is marked "untrusted": true.',
|
|
896
1143
|
inputSchema: {
|
|
897
1144
|
// A control character (NUL above all) has no place in words to search for: SQLite answers it with its own error text.
|
|
898
1145
|
query: zod_1.z.string().min(1).max(200).superRefine((query, ctx) => {
|
|
@@ -903,20 +1150,35 @@ function buildMcpServer(db, config, engine, idle, digests, usefulness, connectio
|
|
|
903
1150
|
top_k: zod_1.z.number().int().min(1).max(50).optional().describe('Max hits (default 20)'),
|
|
904
1151
|
scope: zod_1.z.string().optional().describe('Memory scope: "global" (default) or scope:<slug> / project:<slug>'),
|
|
905
1152
|
},
|
|
1153
|
+
outputSchema: zod_1.z.looseObject({
|
|
1154
|
+
ok: zod_1.z.boolean(),
|
|
1155
|
+
results: zod_1.z.array(OUT_HIT),
|
|
1156
|
+
error: zod_1.z.string().optional(),
|
|
1157
|
+
detail: zod_1.z.string().optional(),
|
|
1158
|
+
scope: zod_1.z.string().optional(),
|
|
1159
|
+
}),
|
|
906
1160
|
}, async (args, extra) => {
|
|
907
1161
|
try {
|
|
908
1162
|
const topK = args.top_k ?? 20;
|
|
909
|
-
const
|
|
1163
|
+
const exact = (0, engine_1.engineSearchText)(db, config.memoryDir, args.query, topK, args.scope, false, config.ledgerRelPath);
|
|
1164
|
+
// H12 (RENOR_SEARCH_TEXT_FALLBACK=1, default off): when the exact phrase finds nothing, the words are searched with OR and
|
|
1165
|
+
// the reply says so (`fallback`). A reply that has hits is never changed. Pre-registered: data/renor-goal-better-temporal-2/prereg/H11b-H18-H12.md.
|
|
1166
|
+
const body = (0, agentMemory_1.searchTextFallbackEnabled)() && exact.ok && exact.results.length === 0
|
|
1167
|
+
? (() => {
|
|
1168
|
+
const any = (0, engine_1.engineSearchText)(db, config.memoryDir, args.query, topK, args.scope, false, config.ledgerRelPath, undefined, (0, agentMemory_1.keywordOrMatch)(args.query));
|
|
1169
|
+
return any.ok && any.results.length > 0 ? { ...any, fallback: 'any-word' } : exact;
|
|
1170
|
+
})()
|
|
1171
|
+
: exact;
|
|
910
1172
|
if (body.ok)
|
|
911
1173
|
(0, factMarkers_1.markFactHits)(db, body.results, readerOf(extra), (0, ledgerPresentation_1.ledgerNoteMatcher)(config));
|
|
912
1174
|
const result = body.ok
|
|
913
1175
|
? {
|
|
914
1176
|
...body,
|
|
915
1177
|
// An added correction takes the place of a hit, so the page is no longer than top_k (or than it was, if it was longer).
|
|
916
|
-
results: (await (async (dated) => (0, replacements_1.withReplacements)(mapContext(), dated, { limit: Math.max(dated.length, topK) }))(await (0, hitDates_1.withHitDates)(db, config.memoryDir, (0, ledgerPresentation_1.withoutLedgerMetadata)((0, factsLane_1.withFactHits)(db, config, body.results, { query: args.query, scope: args.scope, match: 'all', limit: topK, dated: true, reader: readerOf(extra) }), (0, ledgerPresentation_1.ledgerNoteMatcher)(config))))).map(
|
|
1178
|
+
results: (await (async (dated) => (0, replacements_1.withReplacements)(mapContext(), dated, { limit: Math.max(dated.length, topK) }))(await (0, hitDates_1.withHitDates)(db, config.memoryDir, (0, ledgerPresentation_1.withoutLedgerMetadata)((0, factsLane_1.withFactHits)(db, config, body.results, { query: args.query, scope: args.scope, match: 'all', limit: topK, dated: true, reader: readerOf(extra) }), (0, ledgerPresentation_1.ledgerNoteMatcher)(config))))).map(markStoredHit),
|
|
917
1179
|
}
|
|
918
1180
|
: body;
|
|
919
|
-
return searchResult(body, result);
|
|
1181
|
+
return searchResult(body, result, withSchemas);
|
|
920
1182
|
}
|
|
921
1183
|
catch (err) {
|
|
922
1184
|
return toolError(err);
|
|
@@ -925,15 +1187,25 @@ function buildMcpServer(db, config, engine, idle, digests, usefulness, connectio
|
|
|
925
1187
|
server.registerTool('lookup_entity', {
|
|
926
1188
|
title: 'Look up an entity',
|
|
927
1189
|
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
|
|
928
|
-
description: 'Find a person/project/concept by name or alias. Does not call embeddings. Matches in order: exact canonical name, frontmatter alias, substring of a canonical name, substring of a source note path — never words inside note text, so a word that appears only inside a saved note is not an entity. A miss returns reason "no-entity-match" plus the entity count and the tool that would find the word. With scope set, the search and that count are restricted to the scope, so "no such entity" and "exists in another scope" return the same answer.',
|
|
1190
|
+
description: 'Find a person/project/concept by name or alias. Does not call embeddings. Matches in order: exact canonical name, frontmatter alias, substring of a canonical name, substring of a source note path — never words inside note text, so a word that appears only inside a saved note is not an entity. A miss returns reason "no-entity-match" plus the entity count and the tool that would find the word. With scope set, the search and that count are restricted to the scope, so "no such entity" and "exists in another scope" return the same answer. The entity of an imported note carries origin: "import".',
|
|
929
1191
|
inputSchema: {
|
|
930
1192
|
name: zod_1.z.string().min(1).max(200).describe('Entity name or alias'),
|
|
931
1193
|
scope: zod_1.z.string().optional().describe('Memory scope: "global" (default) or scope:<slug> / project:<slug>; restricts to entities whose source note belongs to the scope'),
|
|
932
1194
|
},
|
|
1195
|
+
outputSchema: zod_1.z.looseObject({
|
|
1196
|
+
ok: zod_1.z.boolean(),
|
|
1197
|
+
entity: zod_1.z.union([OUT_HIT, zod_1.z.null()]).optional(),
|
|
1198
|
+
reason: zod_1.z.string().optional(),
|
|
1199
|
+
searched: zod_1.z.string().optional(),
|
|
1200
|
+
entitiesIndexed: zod_1.z.number().optional(),
|
|
1201
|
+
note: zod_1.z.string().optional(),
|
|
1202
|
+
scope: zod_1.z.string().optional(),
|
|
1203
|
+
}),
|
|
933
1204
|
}, async (args) => {
|
|
934
1205
|
try {
|
|
935
1206
|
const body = (0, engine_1.engineLookupEntity)(db, config, args.name, args.scope);
|
|
936
|
-
|
|
1207
|
+
// The entity of an imported note says so, as every read of that note does.
|
|
1208
|
+
return jsonResult(body.entity ? { ...body, entity: markImportedOrigin(body.entity, 'sourceNote') } : body);
|
|
937
1209
|
}
|
|
938
1210
|
catch (err) {
|
|
939
1211
|
return toolError(err);
|
|
@@ -953,15 +1225,25 @@ function buildMcpServer(db, config, engine, idle, digests, usefulness, connectio
|
|
|
953
1225
|
cites: CITES_ARG,
|
|
954
1226
|
replaces: REPLACES_ARG,
|
|
955
1227
|
},
|
|
1228
|
+
outputSchema: zod_1.z.looseObject({
|
|
1229
|
+
ok: zod_1.z.boolean(),
|
|
1230
|
+
file: zod_1.z.string(),
|
|
1231
|
+
scope: zod_1.z.string(),
|
|
1232
|
+
id: zod_1.z.string().optional(),
|
|
1233
|
+
replaced: OUT_REPLACEMENT,
|
|
1234
|
+
replacesIgnored: zod_1.z.string().optional(),
|
|
1235
|
+
indexed: zod_1.z.boolean().optional(),
|
|
1236
|
+
index: OUT_INDEX_PASS,
|
|
1237
|
+
warning: zod_1.z.string().optional(),
|
|
1238
|
+
detail: zod_1.z.string().optional(),
|
|
1239
|
+
}),
|
|
956
1240
|
}, async (args, extra) => {
|
|
957
1241
|
try {
|
|
958
1242
|
const source = sourceOf(args.source, extra, config);
|
|
959
1243
|
if (args.replaces !== undefined)
|
|
960
1244
|
await (0, replacements_1.assertReplaceable)(mapContext(), args.replaces, (0, scope_1.normalizeScope)(args.scope));
|
|
961
1245
|
const body = await (0, engine_1.engineRememberNote)(config, args.text, args.date, source, args.scope, args.timezone);
|
|
962
|
-
|
|
963
|
-
db.prepare('INSERT INTO write_events (note_path, action, summary, created_at, author, scope) VALUES (?, ?, ?, ?, ?, ?)')
|
|
964
|
-
.run(body.file, 'note', args.text.slice(0, 240), new Date().toISOString(), source ?? 'unnamed', body.scope);
|
|
1246
|
+
recordNoteSave(body.file, args.text, source, body.scope);
|
|
965
1247
|
usefulness.cited(args.cites);
|
|
966
1248
|
const replaced = args.replaces !== undefined && body.id
|
|
967
1249
|
// The source the entry was written with (engineRememberNote's default when none), so the link names the same one.
|
|
@@ -978,6 +1260,17 @@ function buildMcpServer(db, config, engine, idle, digests, usefulness, connectio
|
|
|
978
1260
|
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false },
|
|
979
1261
|
description: 'Walks the workspace\'s Markdown notes into the search index (chunks, keyword index, entities). If an embedding provider is configured, stamps new and changed notes with it; the provider must match the existing index dimensions. Run it when search_memory or get_context report index.stale; saved facts are keyword-searchable without it. It does not wait for a slow or refusing embedding service: such files are reported (warning "index-unfinished") and finished in the background.',
|
|
980
1262
|
inputSchema: {},
|
|
1263
|
+
outputSchema: zod_1.z.looseObject({
|
|
1264
|
+
ok: zod_1.z.boolean(),
|
|
1265
|
+
total: zod_1.z.number(),
|
|
1266
|
+
indexed: zod_1.z.number(),
|
|
1267
|
+
errors: zod_1.z.number(),
|
|
1268
|
+
skippedNonUtf8Names: zod_1.z.array(zod_1.z.string()).optional(),
|
|
1269
|
+
skippedTooLarge: zod_1.z.array(zod_1.z.string()).optional(),
|
|
1270
|
+
failure: zod_1.z.string().optional(),
|
|
1271
|
+
warning: zod_1.z.string().optional(),
|
|
1272
|
+
detail: zod_1.z.string().optional(),
|
|
1273
|
+
}),
|
|
981
1274
|
}, async () => {
|
|
982
1275
|
try {
|
|
983
1276
|
const stats = await (0, engine_1.engineIndex)(db, config, engine, { interactive: true });
|
|
@@ -1022,6 +1315,21 @@ function buildMcpServer(db, config, engine, idle, digests, usefulness, connectio
|
|
|
1022
1315
|
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false },
|
|
1023
1316
|
description: 'Dry run for an agent-led import of notes into Imported/<label>/. The server cannot read your disk: read each file yourself and send its text as files: [{ relativePath, markdown }], relativePath being the path inside the folder you import (notes/idea.md: / separators, no leading / or ./ or ..). Only .md files: save a ChatGPT or Claude memory list, JSON or other text as Markdown first and leave attachments out. Names starting with "." are skipped. Returns counts, conflicts (a different file already at the destination is kept, not overwritten; use a new label to import a changed copy), skipped files with reasons, and an expiring batchId; writes no memory. Max 100 files, 64 KiB/file and 128 KiB per call including paths; for more, call again per group. Up to 8 previews can wait at once: apply one, or wait 15 minutes. Refuses unsafe or oversize inputs. Selection: include/exclude path prefixes. stage: false only checks (no batchId, nothing held). Show preview before apply_import.',
|
|
1024
1317
|
inputSchema: hosted_1.importPreviewSchema,
|
|
1318
|
+
outputSchema: zod_1.z.looseObject({
|
|
1319
|
+
ok: zod_1.z.boolean(),
|
|
1320
|
+
namespace: zod_1.z.string(),
|
|
1321
|
+
counts: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()),
|
|
1322
|
+
conflicts: zod_1.z.array(zod_1.z.string()),
|
|
1323
|
+
unchanged: zod_1.z.number(),
|
|
1324
|
+
toWrite: zod_1.z.number(),
|
|
1325
|
+
skipped: zod_1.z.array(OUT_HIT),
|
|
1326
|
+
limits: OUT_HIT,
|
|
1327
|
+
staged: zod_1.z.boolean().optional(),
|
|
1328
|
+
batchId: zod_1.z.string().optional(),
|
|
1329
|
+
expiresAt: zod_1.z.string().optional(),
|
|
1330
|
+
secretGuard: OUT_HIT.optional(),
|
|
1331
|
+
unchangedPaths: zod_1.z.array(zod_1.z.string()).optional(),
|
|
1332
|
+
}),
|
|
1025
1333
|
}, async (args) => {
|
|
1026
1334
|
try {
|
|
1027
1335
|
return jsonResult(await (0, hosted_1.previewImport)(mapContext(), args));
|
|
@@ -1043,6 +1351,21 @@ function buildMcpServer(db, config, engine, idle, digests, usefulness, connectio
|
|
|
1043
1351
|
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false },
|
|
1044
1352
|
description: 'Apply preview_import batchId within 15 minutes (same tenant process). Additive: preserves existing different files and reports conflicts. Immediately keyword searchable; on a workspace with semantic search the new notes are then embedded in the background (memory_status says semantic: false until they are). No fact extraction. Returns batchId for undo_import; retries are idempotent.',
|
|
1045
1353
|
inputSchema: hosted_1.importBatchSchema,
|
|
1354
|
+
outputSchema: zod_1.z.looseObject({
|
|
1355
|
+
ok: zod_1.z.boolean(),
|
|
1356
|
+
batchId: zod_1.z.string(),
|
|
1357
|
+
namespace: zod_1.z.string().optional(),
|
|
1358
|
+
notesWritten: zod_1.z.number().optional(),
|
|
1359
|
+
notesUnchanged: zod_1.z.number().optional(),
|
|
1360
|
+
notesConflicting: zod_1.z.number().optional(),
|
|
1361
|
+
conflicts: zod_1.z.array(zod_1.z.string()).optional(),
|
|
1362
|
+
eventsAppended: zod_1.z.number().optional(),
|
|
1363
|
+
eventsAlreadyPresent: zod_1.z.number().optional(),
|
|
1364
|
+
ledgerReplayed: zod_1.z.number().optional(),
|
|
1365
|
+
indexRows: OUT_HIT.optional(),
|
|
1366
|
+
destination: zod_1.z.union([OUT_HIT, zod_1.z.null()]).optional(),
|
|
1367
|
+
recall: zod_1.z.string().optional(),
|
|
1368
|
+
}),
|
|
1046
1369
|
}, async ({ batchId }, extra) => {
|
|
1047
1370
|
try {
|
|
1048
1371
|
return jsonResult(await (0, hosted_1.applyHostedImport)(mapContext(), batchId, storageLimitOf(extra?.requestInfo?.headers)));
|
|
@@ -1064,6 +1387,14 @@ function buildMcpServer(db, config, engine, idle, digests, usefulness, connectio
|
|
|
1064
1387
|
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: false },
|
|
1065
1388
|
description: 'Undo this batch\'s claim on imported notes. A created note stays live while a later batch still asserts the same bytes; undoing the last such batch retires it. Preserves pre-existing files, conflicts and later edits; reports preserved paths and the re-assertion reason. Uses existing retirement journal and trash. Batch receipts persist across restarts and are tenant-local.',
|
|
1066
1389
|
inputSchema: hosted_1.importBatchSchema,
|
|
1390
|
+
outputSchema: zod_1.z.looseObject({
|
|
1391
|
+
ok: zod_1.z.boolean(),
|
|
1392
|
+
batchId: zod_1.z.string(),
|
|
1393
|
+
retired: zod_1.z.number().optional(),
|
|
1394
|
+
preserved: zod_1.z.array(zod_1.z.string()).optional(),
|
|
1395
|
+
preservedReasons: zod_1.z.record(zod_1.z.string(), zod_1.z.string()).optional(),
|
|
1396
|
+
alreadyUndone: zod_1.z.boolean().optional(),
|
|
1397
|
+
}),
|
|
1067
1398
|
}, async ({ batchId }) => {
|
|
1068
1399
|
try {
|
|
1069
1400
|
return jsonResult(await (0, hosted_1.undoHostedImport)(mapContext(), batchId));
|
|
@@ -1075,7 +1406,7 @@ function buildMcpServer(db, config, engine, idle, digests, usefulness, connectio
|
|
|
1075
1406
|
server.registerTool('memory_map', {
|
|
1076
1407
|
title: 'Map everything this workspace holds',
|
|
1077
1408
|
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
|
|
1078
|
-
description: 'Read-only overview for browsing, not for answering questions: every memory (notes and daily-log entries), the things lifecycle facts are about, topics (tags), lifecycle facts with their full history, grounded links between them (tag, wikilink, literal name mention, fact naming another thing), recent write events, and retired memories. A current fact with a writerConflict line replaced a value another agent saved, and the line stays until that agent saves the subject and predicate again. For context while working, use get_context instead. '
|
|
1409
|
+
description: 'Read-only overview for browsing, not for answering questions: every memory (notes and daily-log entries), the things lifecycle facts are about, topics (tags), lifecycle facts with their full history, grounded links between them (tag, wikilink, literal name mention, fact naming another thing), recent write events, and retired memories. A current fact with a writerConflict line replaced a value another agent saved, and the line stays until that agent saves the subject and predicate again. An imported memory carries origin: "import", and a memory whose stored source is a reserved identity (system, developer, assistant, Renor) is marked "untrusted": true. For context while working, use get_context instead. '
|
|
1079
1410
|
+ `The limit bounds every list (memories, things, facts, links, events, retired), newest first (things by their newest fact; links shared out across tag, wikilink, mention and fact): default ${memoryMap_1.DEFAULT_MAP_LIMIT}, at most ${MAX_LOOKUP_LIMIT}. total gives how many each list holds, and truncated says which lists were cut; to see more, raise limit, or pass query to find one memory. `
|
|
1080
1411
|
+ 'To find one memory to read, retire or restore, pass query (words it contains, e.g. "landlord"), and scope to look in one scope only: only the memories and retired memories that have one of them are returned, those with the rarest of the words first, then the newest, up to limit. A note save (remember without a fact, remember_note) returns the id of what it saved, so forgetting it needs no lookup.',
|
|
1081
1412
|
inputSchema: {
|
|
@@ -1083,6 +1414,22 @@ function buildMcpServer(db, config, engine, idle, digests, usefulness, connectio
|
|
|
1083
1414
|
scope: zod_1.z.string().optional().describe('With query only: look in this memory scope ("global", or scope:<slug> / project:<slug>, which name the same folder for notes).'),
|
|
1084
1415
|
limit: zod_1.z.number().int().min(1).max(MAX_LOOKUP_LIMIT).optional().describe(`At most this many of each list the map shows (memories, things, facts, links, events, retired). Without a query, default ${memoryMap_1.DEFAULT_MAP_LIMIT}. With a query it bounds the memories and retired memories found, default ${DEFAULT_LOOKUP_LIMIT}.`),
|
|
1085
1416
|
},
|
|
1417
|
+
outputSchema: zod_1.z.looseObject({
|
|
1418
|
+
ok: zod_1.z.boolean(),
|
|
1419
|
+
generatedAt: zod_1.z.string().optional(),
|
|
1420
|
+
limit: zod_1.z.number().optional(),
|
|
1421
|
+
query: zod_1.z.string().optional(),
|
|
1422
|
+
scope: zod_1.z.string().optional(),
|
|
1423
|
+
memories: zod_1.z.array(OUT_HIT).optional(),
|
|
1424
|
+
things: zod_1.z.array(OUT_HIT).optional(),
|
|
1425
|
+
topics: zod_1.z.array(OUT_HIT).optional(),
|
|
1426
|
+
facts: zod_1.z.array(OUT_HIT).optional(),
|
|
1427
|
+
links: zod_1.z.array(OUT_HIT).optional(),
|
|
1428
|
+
events: zod_1.z.array(OUT_HIT).optional(),
|
|
1429
|
+
retired: zod_1.z.array(OUT_HIT).optional(),
|
|
1430
|
+
total: zod_1.z.record(zod_1.z.string(), zod_1.z.number()).optional(),
|
|
1431
|
+
truncated: zod_1.z.record(zod_1.z.string(), zod_1.z.boolean()).optional(),
|
|
1432
|
+
}),
|
|
1086
1433
|
}, async (args) => {
|
|
1087
1434
|
try {
|
|
1088
1435
|
if (args.query === undefined) {
|
|
@@ -1091,7 +1438,7 @@ function buildMcpServer(db, config, engine, idle, digests, usefulness, connectio
|
|
|
1091
1438
|
if (args.scope !== undefined)
|
|
1092
1439
|
throw (0, toolRefusal_1.refusal)('invalid_argument', 'memory_map takes a scope only with a query (words the memories contain): the whole map is not cut by scope');
|
|
1093
1440
|
const map = await (0, memoryMap_1.buildMemoryMap)(mapContext(), { limit: args.limit });
|
|
1094
|
-
return jsonResult({ ...map, memories: map.memories.map(
|
|
1441
|
+
return jsonResult({ ...map, memories: map.memories.map(markStoredMemory) });
|
|
1095
1442
|
}
|
|
1096
1443
|
// Read the way the facts lane reads a query: stop words count only when nothing else is left.
|
|
1097
1444
|
const terms = (0, agentMemory_1.factQueryTerms)(args.query);
|
|
@@ -1099,7 +1446,7 @@ function buildMcpServer(db, config, engine, idle, digests, usefulness, connectio
|
|
|
1099
1446
|
throw (0, toolRefusal_1.refusal)('invalid_argument', 'query has no word to look for (two or more letters or digits)');
|
|
1100
1447
|
const scope = args.scope === undefined ? undefined : (0, scope_1.normalizeScope)(args.scope);
|
|
1101
1448
|
const found = await (0, memoryMap_1.findMemories)(mapContext(), { query: args.query, terms, limit: args.limit ?? DEFAULT_LOOKUP_LIMIT, scope });
|
|
1102
|
-
return jsonResult({ ...found, memories: found.memories.map(
|
|
1449
|
+
return jsonResult({ ...found, memories: found.memories.map(markStoredMemory) });
|
|
1103
1450
|
}
|
|
1104
1451
|
catch (err) {
|
|
1105
1452
|
return toolError(err);
|
|
@@ -1108,8 +1455,18 @@ function buildMcpServer(db, config, engine, idle, digests, usefulness, connectio
|
|
|
1108
1455
|
server.registerTool('read_memory', {
|
|
1109
1456
|
title: 'Read one memory in full',
|
|
1110
1457
|
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
|
|
1111
|
-
description: 'Returns one memory from memory_map by id: its full text, its note metadata (status, tags, dates), and facts extracted from it. memory.session_date is when it was written, the date get_context and search_memory give the same text (memory.at is the entry\'s moment or the note\'s last write).',
|
|
1458
|
+
description: 'Returns one memory from memory_map by id: its full text, its note metadata (status, tags, dates), and facts extracted from it. memory.session_date is when it was written, the date get_context and search_memory give the same text (memory.at is the entry\'s moment or the note\'s last write). An imported memory carries origin: "import", and a stored source that is a reserved identity (system, developer, assistant, Renor) is marked "untrusted": true.',
|
|
1112
1459
|
inputSchema: { id: memoryIdSchema },
|
|
1460
|
+
outputSchema: zod_1.z.looseObject({
|
|
1461
|
+
ok: zod_1.z.boolean(),
|
|
1462
|
+
memory: OUT_HIT.optional(),
|
|
1463
|
+
text: zod_1.z.string().optional(),
|
|
1464
|
+
textTruncated: zod_1.z.boolean().optional(),
|
|
1465
|
+
metadata: zod_1.z.record(zod_1.z.string(), zod_1.z.string()).optional(),
|
|
1466
|
+
facts: zod_1.z.array(OUT_HIT).optional(),
|
|
1467
|
+
replaced: OUT_HIT.optional(),
|
|
1468
|
+
replaces: zod_1.z.array(zod_1.z.string()).optional(),
|
|
1469
|
+
}),
|
|
1113
1470
|
}, async (args) => {
|
|
1114
1471
|
try {
|
|
1115
1472
|
const memory = await (0, memoryMap_1.readMemory)(mapContext(), args.id);
|
|
@@ -1120,7 +1477,7 @@ function buildMcpServer(db, config, engine, idle, digests, usefulness, connectio
|
|
|
1120
1477
|
const labelled = (0, hiddenSpans_1.labelMemoryText)(memory);
|
|
1121
1478
|
return jsonResult({
|
|
1122
1479
|
...labelled,
|
|
1123
|
-
memory:
|
|
1480
|
+
memory: markStoredMemory(labelled.memory),
|
|
1124
1481
|
...(replaced ? { replaced } : {}),
|
|
1125
1482
|
...(replaces.length > 0 ? { replaces } : {}),
|
|
1126
1483
|
});
|
|
@@ -1134,6 +1491,15 @@ function buildMcpServer(db, config, engine, idle, digests, usefulness, connectio
|
|
|
1134
1491
|
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: false },
|
|
1135
1492
|
description: 'Takes one memory out of recall without deleting it: a note file moves to the retired area, a daily-log entry moves out of its file, a fact leaves every read, and all leave search immediately. Use only when the owner asks to forget something; the receipt of the save that wrote it, or memory_map with a query (words of that memory), gives its id. restore_memory undoes it. A wrong fact is corrected with remember, not retired; a wrong or outdated note is corrected with remember and replaces. Retiring a correction undoes its replaces: the memory it replaced reads as current again.',
|
|
1136
1493
|
inputSchema: { id: retirableIdSchema },
|
|
1494
|
+
outputSchema: zod_1.z.looseObject({
|
|
1495
|
+
ok: zod_1.z.boolean(),
|
|
1496
|
+
id: zod_1.z.string(),
|
|
1497
|
+
action: zod_1.z.enum(['retired', 'restored']),
|
|
1498
|
+
title: zod_1.z.string(),
|
|
1499
|
+
at: zod_1.z.string(),
|
|
1500
|
+
eventId: zod_1.z.string().optional(),
|
|
1501
|
+
current: zod_1.z.boolean().optional(),
|
|
1502
|
+
}),
|
|
1137
1503
|
}, async (args, extra) => {
|
|
1138
1504
|
try {
|
|
1139
1505
|
return jsonResult(await (0, memoryMap_1.retireMemory)({ ...mapContext(), source: sourceOf(undefined, extra, config) }, args.id));
|
|
@@ -1147,11 +1513,20 @@ function buildMcpServer(db, config, engine, idle, digests, usefulness, connectio
|
|
|
1147
1513
|
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false },
|
|
1148
1514
|
description: 'Puts a retired memory back exactly as it was and re-indexes it. Refuses to overwrite a file that now occupies the same path.',
|
|
1149
1515
|
inputSchema: { id: retirableIdSchema },
|
|
1516
|
+
outputSchema: zod_1.z.looseObject({
|
|
1517
|
+
ok: zod_1.z.boolean(),
|
|
1518
|
+
id: zod_1.z.string(),
|
|
1519
|
+
action: zod_1.z.enum(['retired', 'restored']),
|
|
1520
|
+
title: zod_1.z.string(),
|
|
1521
|
+
at: zod_1.z.string(),
|
|
1522
|
+
eventId: zod_1.z.string().optional(),
|
|
1523
|
+
current: zod_1.z.boolean().optional(),
|
|
1524
|
+
}),
|
|
1150
1525
|
}, async (args, extra) => {
|
|
1151
1526
|
try {
|
|
1152
1527
|
const storageLimit = storageLimitOf(extra?.requestInfo?.headers);
|
|
1153
1528
|
return jsonResult(await (0, memoryMap_1.restoreMemory)({ ...mapContext(), source: sourceOf(undefined, extra, config) }, args.id, storageLimit === undefined ? {} : { validateAfterWrite: async () => {
|
|
1154
|
-
const bytes = await (0,
|
|
1529
|
+
const bytes = await (0, storedSize_1.measureMarkdownBytes)(config.memoryDir);
|
|
1155
1530
|
if (bytes > storageLimit) {
|
|
1156
1531
|
throw (0, toolRefusal_1.refusal)('storage_limit', `Renor: this write would need ${bytes.toLocaleString('en-US')} bytes of Markdown storage and would not fit; the storage limit is ${storageLimit.toLocaleString('en-US')} bytes. This memory write was not run.`);
|
|
1157
1532
|
}
|
|
@@ -1174,11 +1549,18 @@ function buildMcpServer(db, config, engine, idle, digests, usefulness, connectio
|
|
|
1174
1549
|
server.registerTool('delete_retired_memory', {
|
|
1175
1550
|
title: 'Permanently delete retired memories (owner only)',
|
|
1176
1551
|
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: false },
|
|
1177
|
-
description: 'Permanently deletes a retired
|
|
1552
|
+
description: 'Permanently deletes a retired memory (id from memory_map.retired), or every listed retired memory (id: "all"; with ids, only those ids). Cannot be undone. A live memory is retired first.',
|
|
1178
1553
|
inputSchema: {
|
|
1179
|
-
id: zod_1.z.string().min(1).max(64).describe('retired
|
|
1180
|
-
ids: zod_1.z.array(zod_1.z.string().min(1).max(64)).min(1).max(MAX_LOOKUP_LIMIT).optional().describe('With id "all": only these retired
|
|
1554
|
+
id: zod_1.z.string().min(1).max(64).describe('A retired memory id from memory_map.retired, or "all"'),
|
|
1555
|
+
ids: zod_1.z.array(zod_1.z.string().min(1).max(64)).min(1).max(MAX_LOOKUP_LIMIT).optional().describe('With id "all": only these retired memory ids (what the owner saw listed)'),
|
|
1181
1556
|
},
|
|
1557
|
+
outputSchema: zod_1.z.looseObject({
|
|
1558
|
+
ok: zod_1.z.boolean(),
|
|
1559
|
+
action: zod_1.z.enum(['deleted']),
|
|
1560
|
+
ids: zod_1.z.array(zod_1.z.string()),
|
|
1561
|
+
freedBytes: zod_1.z.number(),
|
|
1562
|
+
at: zod_1.z.string(),
|
|
1563
|
+
}),
|
|
1182
1564
|
}, async (args, extra) => {
|
|
1183
1565
|
try {
|
|
1184
1566
|
if (!isDashboardCall(extra?.requestInfo?.headers, config)) {
|
|
@@ -1203,6 +1585,14 @@ function buildMcpServer(db, config, engine, idle, digests, usefulness, connectio
|
|
|
1203
1585
|
include_own: zod_1.z.boolean().optional().describe('Also return what this connection wrote. Default false.'),
|
|
1204
1586
|
cursor: omittedWhenBlank(zod_1.z.string().optional()).describe('The cursor from the previous reply, when that reply was full.'),
|
|
1205
1587
|
},
|
|
1588
|
+
outputSchema: zod_1.z.looseObject({
|
|
1589
|
+
items: zod_1.z.array(OUT_HIT),
|
|
1590
|
+
as_of: zod_1.z.string(),
|
|
1591
|
+
next_since: zod_1.z.string().nullable(),
|
|
1592
|
+
cursor: zod_1.z.string().nullable(),
|
|
1593
|
+
more_requests: zod_1.z.number().optional(),
|
|
1594
|
+
more_requests_hint: zod_1.z.string().optional(),
|
|
1595
|
+
}),
|
|
1206
1596
|
}, async (args, extra) => {
|
|
1207
1597
|
try {
|
|
1208
1598
|
const agent = hiveAgentOf(extra, 'whats_new', config);
|
|
@@ -1218,6 +1608,27 @@ function buildMcpServer(db, config, engine, idle, digests, usefulness, connectio
|
|
|
1218
1608
|
return toolError(err);
|
|
1219
1609
|
}
|
|
1220
1610
|
});
|
|
1611
|
+
// The handoff note (memory/handoff.ts): published only with RENOR_HANDOFF_NOTE on, so the default tool list is unchanged.
|
|
1612
|
+
if ((0, handoff_1.handoffNoteEnabled)())
|
|
1613
|
+
server.registerTool(handoff_1.HANDOFF_TOOL_NAME, {
|
|
1614
|
+
title: 'Handoff note for this branch',
|
|
1615
|
+
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: false },
|
|
1616
|
+
description: handoff_1.HANDOFF_TOOL_DESCRIPTION,
|
|
1617
|
+
inputSchema: {
|
|
1618
|
+
action: zod_1.z.enum(['read', 'write']).describe(handoff_1.HANDOFF_ARG_DESCRIPTIONS.action),
|
|
1619
|
+
repo: zod_1.z.string().min(1).max(1000).describe(handoff_1.HANDOFF_ARG_DESCRIPTIONS.repo),
|
|
1620
|
+
branch: zod_1.z.string().min(1).max(1000).describe(handoff_1.HANDOFF_ARG_DESCRIPTIONS.branch),
|
|
1621
|
+
note: omittedWhenBlank(zod_1.z.string().max(handoff_1.HANDOFF_MAX_CHARS * 2).optional()).describe(handoff_1.HANDOFF_ARG_DESCRIPTIONS.note),
|
|
1622
|
+
},
|
|
1623
|
+
outputSchema: zod_1.z.looseObject({ ok: zod_1.z.boolean(), action: zod_1.z.enum(['read', 'write']) }),
|
|
1624
|
+
}, async (args, extra) => {
|
|
1625
|
+
try {
|
|
1626
|
+
return jsonResult(await (0, handoff_1.runHandoffTool)(db, args, agentOf(extra, config)));
|
|
1627
|
+
}
|
|
1628
|
+
catch (err) {
|
|
1629
|
+
return toolError(err);
|
|
1630
|
+
}
|
|
1631
|
+
});
|
|
1221
1632
|
server.registerTool('ask_agent', {
|
|
1222
1633
|
title: 'Ask another agent',
|
|
1223
1634
|
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false },
|
|
@@ -1227,6 +1638,13 @@ function buildMcpServer(db, config, engine, idle, digests, usefulness, connectio
|
|
|
1227
1638
|
request: zod_1.z.string().min(1).max(limits_1.MAX_STATEMENT_LENGTH).describe('What you are asking, in plain words.'),
|
|
1228
1639
|
scope: SCOPE_ARG,
|
|
1229
1640
|
},
|
|
1641
|
+
outputSchema: zod_1.z.looseObject({
|
|
1642
|
+
id: zod_1.z.string(),
|
|
1643
|
+
status: zod_1.z.enum(['open', 'answered', 'closed']),
|
|
1644
|
+
from_agent: zod_1.z.string(),
|
|
1645
|
+
to_agent: zod_1.z.string(),
|
|
1646
|
+
created_at: zod_1.z.string(),
|
|
1647
|
+
}),
|
|
1230
1648
|
}, async (args, extra) => {
|
|
1231
1649
|
try {
|
|
1232
1650
|
const from = hiveAgentOf(extra, 'ask_agent', config);
|
|
@@ -1249,6 +1667,11 @@ function buildMcpServer(db, config, engine, idle, digests, usefulness, connectio
|
|
|
1249
1667
|
scope: SCOPE_ARG,
|
|
1250
1668
|
before: omittedWhenBlank(zod_1.z.string().max(80).optional()).describe('Only requests older than this one: the id of the last request a previous list_requests or whats_new showed.'),
|
|
1251
1669
|
},
|
|
1670
|
+
outputSchema: zod_1.z.looseObject({
|
|
1671
|
+
requests: zod_1.z.array(OUT_HIT),
|
|
1672
|
+
more_requests: zod_1.z.number().optional(),
|
|
1673
|
+
more_requests_hint: zod_1.z.string().optional(),
|
|
1674
|
+
}),
|
|
1252
1675
|
}, async (args, extra) => {
|
|
1253
1676
|
try {
|
|
1254
1677
|
const agent = hiveAgentOf(extra, 'list_requests', config);
|
|
@@ -1271,6 +1694,19 @@ function buildMcpServer(db, config, engine, idle, digests, usefulness, connectio
|
|
|
1271
1694
|
id: zod_1.z.string().min(1).max(80).describe('The request id from whats_new or list_requests.'),
|
|
1272
1695
|
answer: zod_1.z.string().min(1).max(limits_1.MAX_STATEMENT_LENGTH).describe('The answer, in plain words.'),
|
|
1273
1696
|
},
|
|
1697
|
+
outputSchema: zod_1.z.looseObject({
|
|
1698
|
+
id: zod_1.z.string(),
|
|
1699
|
+
scope: zod_1.z.string().nullable(),
|
|
1700
|
+
from_agent: zod_1.z.string(),
|
|
1701
|
+
to_agent: zod_1.z.string(),
|
|
1702
|
+
question: zod_1.z.string(),
|
|
1703
|
+
answer: zod_1.z.string().nullable(),
|
|
1704
|
+
status: zod_1.z.enum(['open', 'answered', 'closed']),
|
|
1705
|
+
created_at: zod_1.z.string(),
|
|
1706
|
+
answered_at: zod_1.z.string().nullable(),
|
|
1707
|
+
closed_at: zod_1.z.string().nullable(),
|
|
1708
|
+
untrusted: zod_1.z.literal(true),
|
|
1709
|
+
}),
|
|
1274
1710
|
}, async (args, extra) => {
|
|
1275
1711
|
try {
|
|
1276
1712
|
const agent = hiveAgentOf(extra, 'answer_request', config);
|
|
@@ -1289,6 +1725,19 @@ function buildMcpServer(db, config, engine, idle, digests, usefulness, connectio
|
|
|
1289
1725
|
inputSchema: {
|
|
1290
1726
|
id: zod_1.z.string().min(1).max(80).describe('The request id.'),
|
|
1291
1727
|
},
|
|
1728
|
+
outputSchema: zod_1.z.looseObject({
|
|
1729
|
+
id: zod_1.z.string(),
|
|
1730
|
+
scope: zod_1.z.string().nullable(),
|
|
1731
|
+
from_agent: zod_1.z.string(),
|
|
1732
|
+
to_agent: zod_1.z.string(),
|
|
1733
|
+
question: zod_1.z.string(),
|
|
1734
|
+
answer: zod_1.z.string().nullable(),
|
|
1735
|
+
status: zod_1.z.enum(['open', 'answered', 'closed']),
|
|
1736
|
+
created_at: zod_1.z.string(),
|
|
1737
|
+
answered_at: zod_1.z.string().nullable(),
|
|
1738
|
+
closed_at: zod_1.z.string().nullable(),
|
|
1739
|
+
untrusted: zod_1.z.literal(true),
|
|
1740
|
+
}),
|
|
1292
1741
|
}, async (args, extra) => {
|
|
1293
1742
|
try {
|
|
1294
1743
|
const agent = hiveAgentOf(extra, 'close_request', config);
|
|
@@ -1309,6 +1758,20 @@ function buildMcpServer(db, config, engine, idle, digests, usefulness, connectio
|
|
|
1309
1758
|
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
|
|
1310
1759
|
description: 'Counts of what this workspace holds: notes (files; a daily log is one note per day), chunks (index size), entities, facts (superseded values included), and whether semantic search can answer now (semantic): while the embeddings are being built (after a provider is configured or changed, or notes are imported) semantic is false and embeddingRebuild counts the chunks left, and keyword search works meanwhile. The engine\'s own ledger is not counted as a note, entity or fact. With semantic search configured, chunksWithoutVectors counts the chunks search by meaning cannot find yet because they have no vector (a save whose embedding failed: the next save or search embeds them; imported notes not embedded yet). No embeddings API call.',
|
|
1311
1760
|
inputSchema: {},
|
|
1761
|
+
outputSchema: zod_1.z.looseObject({
|
|
1762
|
+
notes: zod_1.z.number(),
|
|
1763
|
+
chunks: zod_1.z.number(),
|
|
1764
|
+
entities: zod_1.z.number(),
|
|
1765
|
+
facts: zod_1.z.number(),
|
|
1766
|
+
relations: zod_1.z.number(),
|
|
1767
|
+
embeddingDims: zod_1.z.number().nullable(),
|
|
1768
|
+
semantic: zod_1.z.boolean(),
|
|
1769
|
+
embeddingRebuild: zod_1.z.object({ chunksLeft: zod_1.z.number(), chunks: zod_1.z.number() }).optional(),
|
|
1770
|
+
chunksWithoutVectors: zod_1.z.number().optional(),
|
|
1771
|
+
degraded: zod_1.z.object({ keyword: zod_1.z.string().optional(), semantic: zod_1.z.string().optional() }).optional(),
|
|
1772
|
+
renor: zod_1.z.string(),
|
|
1773
|
+
digests: OUT_HIT.optional(),
|
|
1774
|
+
}),
|
|
1312
1775
|
}, async (_args, extra) => {
|
|
1313
1776
|
try {
|
|
1314
1777
|
const body = { ...(0, engine_1.engineStatus)(db, engine, config), renor: (0, identity_1.identityLine)(extra?.requestInfo?.headers) };
|
|
@@ -1319,6 +1782,19 @@ function buildMcpServer(db, config, engine, idle, digests, usefulness, connectio
|
|
|
1319
1782
|
return toolError(err);
|
|
1320
1783
|
}
|
|
1321
1784
|
});
|
|
1785
|
+
// Nor the tools directorySurface.ts keeps from a directory client: disabled the same way, once every one of them is registered.
|
|
1786
|
+
if (directory)
|
|
1787
|
+
for (const name of directorySurface_1.DIRECTORY_HIDDEN_TOOLS)
|
|
1788
|
+
registeredToolEntry(server, name).enabled = false;
|
|
1789
|
+
// The profile's tool subset: the others are disabled in the SDK's registry, so neither listed nor run.
|
|
1790
|
+
if (profile.tools || profile.descriptions) {
|
|
1791
|
+
const registered = Object.keys(server._registeredTools ?? {});
|
|
1792
|
+
(0, contextProfile_1.checkProfileTools)(profile, registered);
|
|
1793
|
+
if (profile.tools)
|
|
1794
|
+
for (const name of registered)
|
|
1795
|
+
if (!profile.tools.has(name))
|
|
1796
|
+
registeredToolEntry(server, name).enabled = false;
|
|
1797
|
+
}
|
|
1322
1798
|
// Every tool is registered above; the SDK's own handlers (initialize included) are mapped in the same pass.
|
|
1323
1799
|
(0, requestErrors_1.mapInvalidParams)(server.server);
|
|
1324
1800
|
// Layer 1 above: the owner-only tool is in the answer only when this request carries the mark. It is decided on the answer, after the
|
|
@@ -1331,19 +1807,49 @@ function buildMcpServer(db, config, engine, idle, digests, usefulness, connectio
|
|
|
1331
1807
|
listHandlers.set('tools/list', async (request, extra) => {
|
|
1332
1808
|
const answer = await listTools(request, extra);
|
|
1333
1809
|
const headers = extra?.requestInfo?.headers;
|
|
1810
|
+
const forDirectory = directory || isDirectoryCall(headers, config);
|
|
1334
1811
|
const hidden = new Set();
|
|
1335
1812
|
if (!isDashboardCall(headers, config))
|
|
1336
1813
|
hidden.add(OWNER_ONLY_TOOL);
|
|
1337
|
-
if (
|
|
1338
|
-
for (const name of HIVE_TOOLS)
|
|
1814
|
+
if (forDirectory)
|
|
1815
|
+
for (const name of [...HIVE_TOOLS, ...directorySurface_1.DIRECTORY_HIDDEN_TOOLS])
|
|
1339
1816
|
hidden.add(name);
|
|
1340
|
-
if (hidden.size === 0)
|
|
1817
|
+
if (hidden.size === 0 && !forDirectory && !profile.descriptions)
|
|
1341
1818
|
return answer;
|
|
1342
1819
|
// An answer this cannot read is not passed on unfiltered.
|
|
1343
1820
|
if (!Array.isArray(answer?.tools))
|
|
1344
1821
|
throw new Error('tools/list answered without a tools array');
|
|
1345
|
-
|
|
1822
|
+
const tools = answer.tools.filter((tool) => !hidden.has(tool.name));
|
|
1823
|
+
// A directory client reads descriptions that say what a tool does, with no instruction to the model (directorySurface.ts).
|
|
1824
|
+
return {
|
|
1825
|
+
...answer,
|
|
1826
|
+
tools: forDirectory
|
|
1827
|
+
? tools.map((tool) => {
|
|
1828
|
+
const own = typeof tool.name === 'string' ? directorySurface_1.DIRECTORY_DESCRIPTIONS[tool.name] : undefined;
|
|
1829
|
+
const description = own && withSchemas && tool.name === 'get_context' ? own + exports.OUTPUT_SCHEMA_BOUND_NOTE : own;
|
|
1830
|
+
return description ? { ...tool, description } : tool;
|
|
1831
|
+
})
|
|
1832
|
+
: profile.descriptions
|
|
1833
|
+
? tools.map((tool) => {
|
|
1834
|
+
const own = typeof tool.name === 'string' ? profile.descriptions[tool.name] : undefined;
|
|
1835
|
+
return own ? { ...tool, description: own } : tool;
|
|
1836
|
+
})
|
|
1837
|
+
: tools,
|
|
1838
|
+
};
|
|
1346
1839
|
});
|
|
1840
|
+
// The profile's reply shape: a read's text block as lines (renderLines); structuredContent, where there is one, is unchanged.
|
|
1841
|
+
if (profile.response === 'lines') {
|
|
1842
|
+
const callTool = listHandlers.get('tools/call');
|
|
1843
|
+
if (!callTool)
|
|
1844
|
+
throw new Error('tools/call handler missing');
|
|
1845
|
+
listHandlers.set('tools/call', async (request, extra) => {
|
|
1846
|
+
const result = await callTool(request, extra);
|
|
1847
|
+
const name = request.params?.name;
|
|
1848
|
+
if (typeof name !== 'string' || !contextProfile_1.LINE_TOOLS.has(name) || result?.isError || !Array.isArray(result?.content))
|
|
1849
|
+
return result;
|
|
1850
|
+
return { ...result, content: result.content.map((c, i) => (i === 0 && c.type === 'text' ? { ...c, text: (0, contextProfile_1.renderLines)(c.text) } : c)) };
|
|
1851
|
+
});
|
|
1852
|
+
}
|
|
1347
1853
|
return server;
|
|
1348
1854
|
}
|
|
1349
1855
|
function createMvpApp(config, engineOverride) {
|
|
@@ -1353,6 +1859,8 @@ function createMvpApp(config, engineOverride) {
|
|
|
1353
1859
|
(0, memoryDir_1.ensureOwnerOnlyMemoryDir)(config.memoryDir);
|
|
1354
1860
|
(0, memoryDir_1.ensureOwnerOnlyFile)(config.dbPath);
|
|
1355
1861
|
const db = (0, client_1.openIndexDb)(config.dbPath, (0, lifecycle_1.resolveLedgerPath)(config.memoryDir, config.ledgerRelPath));
|
|
1862
|
+
// Expired handoff notes are deleted on a timer, not only when one is read (memory/handoff.ts). Off: nothing runs.
|
|
1863
|
+
const stopHandoffSweep = (0, handoff_1.handoffNoteEnabled)() ? (0, handoff_1.startHandoffSweep)(db) : null;
|
|
1356
1864
|
(0, schema_1.runMigrations)(db);
|
|
1357
1865
|
// Facts saved before the term index existed, or by a release without it, are indexed before the first search.
|
|
1358
1866
|
(0, factTerms_1.ensureFactTerms)(db);
|
|
@@ -1360,7 +1868,7 @@ function createMvpApp(config, engineOverride) {
|
|
|
1360
1868
|
// go before anything reads the index, so no note is served from a place it no longer is. Fails the start if it cannot.
|
|
1361
1869
|
const rowsOutsideRoot = (0, outsideRoot_1.removeRowsOutsideRoot)(db, config.memoryDir).total;
|
|
1362
1870
|
if (rowsOutsideRoot > 0)
|
|
1363
|
-
|
|
1871
|
+
log.info('startup_rows_outside_root_removed', { rows: rowsOutsideRoot, detail: 'index rows for files outside the memory folder; the folder is indexed again before serving' });
|
|
1364
1872
|
const pendingPass = (0, outsideRoot_1.reindexPending)(db);
|
|
1365
1873
|
const engine = (0, engine_1.attachEngine)(db, config, engineOverride);
|
|
1366
1874
|
// An index whose vectors are in another model's space, or in none anyone can vouch for, is cleared and embedded
|
|
@@ -1393,10 +1901,10 @@ function createMvpApp(config, engineOverride) {
|
|
|
1393
1901
|
try {
|
|
1394
1902
|
const removed = (0, pipeline_1.removeDailyHeaderFacts)(db);
|
|
1395
1903
|
if (removed > 0)
|
|
1396
|
-
|
|
1904
|
+
log.info('startup_header_facts_removed', { facts: removed, detail: 'daily-note header facts an earlier build indexed' });
|
|
1397
1905
|
}
|
|
1398
1906
|
catch (err) {
|
|
1399
|
-
|
|
1907
|
+
log.error('startup_header_cleanup_failed', {}, err);
|
|
1400
1908
|
}
|
|
1401
1909
|
const app = (0, express_1.default)();
|
|
1402
1910
|
// Express's default error page prints the stack, with absolute paths, unless the app is in production mode.
|
|
@@ -1404,6 +1912,10 @@ function createMvpApp(config, engineOverride) {
|
|
|
1404
1912
|
// No `X-Powered-By: Express`: it names the stack to a scanner and serves no client, and the gateway
|
|
1405
1913
|
// passes this engine's answers through to mcp.renor.cloud as they are (live-security F5).
|
|
1406
1914
|
app.disable('x-powered-by');
|
|
1915
|
+
app.use((_req, res, next) => {
|
|
1916
|
+
res.setHeader('X-Content-Type-Options', 'nosniff');
|
|
1917
|
+
next();
|
|
1918
|
+
});
|
|
1407
1919
|
// ACCESS LOG (diagnostics only): one metadata-only line per HTTP outcome
|
|
1408
1920
|
// covering every status class, so server-side connector calls (ChatGPT)
|
|
1409
1921
|
// become visible without any sensitive material. Fields: method, path
|
|
@@ -1451,7 +1963,7 @@ function createMvpApp(config, engineOverride) {
|
|
|
1451
1963
|
fields.client_prefix = clientPrefix;
|
|
1452
1964
|
if (closedWithoutFinish)
|
|
1453
1965
|
fields.outcome = 'closed'; // client abort / mid-stream disconnect
|
|
1454
|
-
|
|
1966
|
+
log.info('http_access', fields);
|
|
1455
1967
|
};
|
|
1456
1968
|
res.on('finish', () => emit(false));
|
|
1457
1969
|
res.on('close', () => emit(true)); // aborted or disconnected responses
|
|
@@ -1576,7 +2088,8 @@ function createMvpApp(config, engineOverride) {
|
|
|
1576
2088
|
const namesSeen = new Set();
|
|
1577
2089
|
const noteConnectionName = (raw) => {
|
|
1578
2090
|
const name = Array.isArray(raw) ? raw[0] : raw;
|
|
1579
|
-
|
|
2091
|
+
// Already agentOf's answer, which applied the rule its connection's kind needs: only the exact rule is left to apply.
|
|
2092
|
+
const identity = typeof name === 'string' ? trustedIdentity(name, false) : 'unnamed';
|
|
1580
2093
|
if (identity === 'unnamed' || namesSeen.has(identity))
|
|
1581
2094
|
return;
|
|
1582
2095
|
try {
|
|
@@ -1865,13 +2378,13 @@ function createMvpApp(config, engineOverride) {
|
|
|
1865
2378
|
app.use((err, req, res, next) => {
|
|
1866
2379
|
if (res.headersSent)
|
|
1867
2380
|
return next(err);
|
|
1868
|
-
const status = Number.isInteger(err
|
|
2381
|
+
const status = typeof err?.status === 'number' && Number.isInteger(err.status) && err.status >= 400 && err.status < 600 ? err.status : 500;
|
|
1869
2382
|
const message = status === 400 ? 'Parse error'
|
|
1870
2383
|
: status === 413 ? 'Request body too large'
|
|
1871
2384
|
: status === 415 ? 'Unsupported media type'
|
|
1872
2385
|
: status >= 500 ? 'Internal error' : 'Invalid Request';
|
|
1873
2386
|
if (status >= 500)
|
|
1874
|
-
|
|
2387
|
+
log.error('http_unhandled', { status }, err);
|
|
1875
2388
|
if (req.path === MCP_PATH) {
|
|
1876
2389
|
const code = status === 400 ? -32700 : status >= 500 ? -32603 : -32600;
|
|
1877
2390
|
res.status(status).json({ jsonrpc: '2.0', error: { code, message }, id: null });
|
|
@@ -1912,6 +2425,7 @@ function createMvpApp(config, engineOverride) {
|
|
|
1912
2425
|
running.abort();
|
|
1913
2426
|
await running.done;
|
|
1914
2427
|
}
|
|
2428
|
+
stopHandoffSweep?.();
|
|
1915
2429
|
db.close();
|
|
1916
2430
|
// The query cache this process opened (an injected provider is its owner's to close).
|
|
1917
2431
|
if (engineOverride === undefined)
|
|
@@ -2024,9 +2538,10 @@ exports.SEARCH_REFUSAL_REASONS = {
|
|
|
2024
2538
|
'fts-query': 'invalid_query',
|
|
2025
2539
|
};
|
|
2026
2540
|
/** A search reply: ok as the search answered it, and its refusal code beside it when it did not search. */
|
|
2027
|
-
function searchResult(body, result) {
|
|
2028
|
-
|
|
2029
|
-
|
|
2541
|
+
function searchResult(body, result, structured) {
|
|
2542
|
+
if (body.ok)
|
|
2543
|
+
return { ...jsonResultOf(result, structured), isError: false };
|
|
2544
|
+
return (0, toolRefusal_1.markToolRefusal)(refusalResult(result), exports.SEARCH_REFUSAL_REASONS[String(body.error)] ?? 'refused');
|
|
2030
2545
|
}
|
|
2031
2546
|
/**
|
|
2032
2547
|
* Startup for the MVP service: open the derived index, AWAIT the ledger replay
|
|
@@ -2051,7 +2566,7 @@ async function startMvpService(config, engineOverride) {
|
|
|
2051
2566
|
if (pass.errors === 0)
|
|
2052
2567
|
(0, outsideRoot_1.clearReindexPending)(mvp.db);
|
|
2053
2568
|
else
|
|
2054
|
-
|
|
2569
|
+
log.error('startup_index_incomplete', { failedFiles: pass.errors, detail: 'the next start runs the pass again' });
|
|
2055
2570
|
}
|
|
2056
2571
|
// Bind by listening, not by the callback Express gives: `app.listen` routes a bind failure to
|
|
2057
2572
|
// that same callback as a success, so a promise waiting on it resolves with a server that never
|