renor-engine 1.2.0 → 1.3.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/README.md +21 -1
- package/THIRD-PARTY-NOTICES +2661 -0
- package/dist/BUILD.json +6 -0
- package/dist/cli.js +1656 -516
- package/package.json +16 -80
- package/dist/.tsbuildinfo +0 -1
- package/dist/api/apiAuth.js +0 -43
- package/dist/api/server.js +0 -174
- package/dist/buildIdentity.js +0 -149
- package/dist/callPhases.js +0 -82
- package/dist/cli-extractors.js +0 -46
- package/dist/config.js +0 -65
- package/dist/context/composer.js +0 -320
- package/dist/context/readHonesty.js +0 -478
- package/dist/context/rowStore.js +0 -238
- package/dist/conversation/formatter.js +0 -81
- package/dist/conversation/parser.js +0 -193
- package/dist/conversation/types.js +0 -2
- package/dist/conversation/writer.js +0 -42
- package/dist/db/client.js +0 -149
- package/dist/db/handoffTable.js +0 -31
- package/dist/db/indexSalvage.js +0 -101
- package/dist/db/migrations.js +0 -670
- package/dist/db/readCache.js +0 -109
- package/dist/db/schema.js +0 -5
- package/dist/db/sqlite.js +0 -396
- package/dist/db/statements.js +0 -89
- package/dist/digests/digestCache.js +0 -146
- package/dist/digests/digests.js +0 -597
- package/dist/digests/worker.js +0 -350
- package/dist/embeddings/caching.js +0 -337
- package/dist/embeddings/coalescing.js +0 -177
- package/dist/embeddings/interactive.js +0 -103
- package/dist/embeddings/local.js +0 -70
- package/dist/embeddings/openai.js +0 -106
- package/dist/embeddings/rebuild.js +0 -166
- package/dist/embeddings/simdScan.js +0 -260
- package/dist/embeddings/space.js +0 -21
- package/dist/embeddings/types.js +0 -14
- package/dist/embeddings/vectorIndex.js +0 -674
- package/dist/embeddings/vertex.js +0 -334
- package/dist/eval/artifacts.js +0 -42
- package/dist/eval/cacheReport.js +0 -146
- package/dist/eval/comparison.js +0 -182
- package/dist/eval/context700-candidate.js +0 -145
- package/dist/eval/evalCache.js +0 -568
- package/dist/eval/hashEmbedding.js +0 -35
- package/dist/eval/indexSnapshots.js +0 -549
- package/dist/eval/longmemeval.js +0 -56
- package/dist/eval/metrics.js +0 -181
- package/dist/eval/pageDump.js +0 -67
- package/dist/eval/renorbenchBaseline.js +0 -486
- package/dist/eval/renorbenchDocuments.js +0 -134
- package/dist/eval/renorbenchProduct.js +0 -182
- package/dist/eval/runLedger.js +0 -279
- package/dist/eval/runManifest.js +0 -485
- package/dist/eval/scoring.js +0 -197
- package/dist/eval/textTokens.js +0 -17
- package/dist/evidence/attach.js +0 -264
- package/dist/evidence/background.js +0 -147
- package/dist/evidence/evidenceCache.js +0 -182
- package/dist/evidence/gate.js +0 -37
- package/dist/evidence/keyPool.js +0 -85
- package/dist/evidence/ollamaChat.js +0 -84
- package/dist/evidence/optin.js +0 -165
- package/dist/evidence/options.js +0 -151
- package/dist/evidence/secondPass.js +0 -294
- package/dist/extraction/classifyCapture.js +0 -34
- package/dist/extraction/decision-model.js +0 -174
- package/dist/extraction/eventExtractor.js +0 -113
- package/dist/extraction/extractionClient.js +0 -122
- package/dist/extraction/factExtractor.js +0 -46
- package/dist/extraction/factsWritePath.js +0 -179
- package/dist/extraction/jevDecisionModel.js +0 -307
- package/dist/extraction/preferenceExtractor.js +0 -150
- package/dist/extraction/secretGuard.js +0 -180
- package/dist/extraction/secretScanner.js +0 -665
- package/dist/extraction/typedFacts.js +0 -224
- package/dist/extraction/writePathAdjudication.js +0 -110
- package/dist/importing/apply.js +0 -672
- package/dist/importing/bundle-write.js +0 -80
- package/dist/importing/cli.js +0 -408
- package/dist/importing/existing.js +0 -51
- package/dist/importing/facts.js +0 -121
- package/dist/importing/forgetImported.js +0 -79
- package/dist/importing/hosted.js +0 -467
- package/dist/importing/journalLog.js +0 -96
- package/dist/importing/markdown.js +0 -98
- package/dist/importing/plan.js +0 -201
- package/dist/importing/secretScreen.js +0 -113
- package/dist/importing/serialize.js +0 -188
- package/dist/importing/source.js +0 -463
- package/dist/importing/types.js +0 -6
- package/dist/indexer/chunker.js +0 -319
- package/dist/indexer/dailyEntries.js +0 -63
- package/dist/indexer/hasher.js +0 -10
- package/dist/indexer/laneRuns.js +0 -48
- package/dist/indexer/o200k.js +0 -481
- package/dist/indexer/outsideRoot.js +0 -77
- package/dist/indexer/parser.js +0 -170
- package/dist/indexer/pipeline.js +0 -988
- package/dist/indexer/staleness.js +0 -201
- package/dist/indexer/tokenizer.js +0 -77
- package/dist/indexer/walker.js +0 -170
- package/dist/learning/cli.js +0 -113
- package/dist/learning/schema.js +0 -144
- package/dist/learning/settings.js +0 -45
- package/dist/learning/store.js +0 -267
- package/dist/learning/tap.js +0 -401
- package/dist/mcp/hive.js +0 -88
- package/dist/mcp/requestErrors.js +0 -47
- package/dist/mcp/server.js +0 -426
- package/dist/memory/agentLease.js +0 -43
- package/dist/memory/confinedWrite.js +0 -315
- package/dist/memory/controls.js +0 -73
- package/dist/memory/dailyNote.js +0 -265
- package/dist/memory/dreamer/adjudicate.js +0 -215
- package/dist/memory/dreamer/apply.js +0 -120
- package/dist/memory/dreamer/budget.js +0 -64
- package/dist/memory/dreamer/candidates.js +0 -149
- package/dist/memory/dreamer/collection.js +0 -104
- package/dist/memory/dreamer/dreamer.js +0 -352
- package/dist/memory/dreamer/review.js +0 -111
- package/dist/memory/durableAppend.js +0 -57
- package/dist/memory/factConflicts.js +0 -205
- package/dist/memory/factTerms.js +0 -321
- package/dist/memory/handoff.js +0 -363
- package/dist/memory/hiveNameHeader.cjs +0 -10
- package/dist/memory/inventory.js +0 -55
- package/dist/memory/invisibleText.js +0 -20
- package/dist/memory/lifecycle.js +0 -2014
- package/dist/memory/limits.js +0 -13
- package/dist/memory/requests.js +0 -183
- package/dist/memory/sourceName.js +0 -276
- package/dist/memory/statusFacts.js +0 -61
- package/dist/memory/whatsNew.js +0 -158
- package/dist/memory/writer.js +0 -176
- package/dist/memory/writerConflicts.js +0 -85
- package/dist/memorymap/memoryMap.js +0 -1594
- package/dist/memorymap/replacedJournal.js +0 -58
- package/dist/memorymap/replacements.js +0 -410
- package/dist/mvp/activity.js +0 -86
- package/dist/mvp/agentMemory.js +0 -1803
- package/dist/mvp/answerCheck.js +0 -211
- package/dist/mvp/auth.js +0 -531
- package/dist/mvp/cli.js +0 -86
- package/dist/mvp/client-store.js +0 -462
- package/dist/mvp/compileCache.js +0 -242
- package/dist/mvp/compileSeed.js +0 -33
- package/dist/mvp/config.js +0 -292
- package/dist/mvp/connectionStatus.js +0 -80
- package/dist/mvp/contextDistinct.js +0 -53
- package/dist/mvp/contextProfile.js +0 -87
- package/dist/mvp/contextRelevance.js +0 -413
- package/dist/mvp/directorySurface.js +0 -68
- package/dist/mvp/engine.js +0 -1078
- package/dist/mvp/exportAll.js +0 -393
- package/dist/mvp/factLanePack.js +0 -77
- package/dist/mvp/factMarkers.js +0 -65
- package/dist/mvp/factsLane.js +0 -203
- package/dist/mvp/hiddenSpans.js +0 -585
- package/dist/mvp/history.js +0 -414
- package/dist/mvp/hitDates.js +0 -31
- package/dist/mvp/hitFloor.js +0 -36
- package/dist/mvp/identity.js +0 -18
- package/dist/mvp/idle.js +0 -113
- package/dist/mvp/log.js +0 -118
- package/dist/mvp/memoryDir.js +0 -98
- package/dist/mvp/posthogMcp.js +0 -210
- package/dist/mvp/readScope.js +0 -104
- package/dist/mvp/readUsefulness.js +0 -222
- package/dist/mvp/sanitize.js +0 -48
- package/dist/mvp/schemaRejections.js +0 -91
- package/dist/mvp/scope.js +0 -127
- package/dist/mvp/server.js +0 -2712
- package/dist/mvp/serverCard.js +0 -38
- package/dist/mvp/storedSize.js +0 -139
- package/dist/mvp/telemetry.js +0 -474
- package/dist/net/poolFetch.js +0 -174
- package/dist/recall/actionRecall.js +0 -282
- package/dist/recall/autoRecall.js +0 -447
- package/dist/recall/searchRecall.js +0 -189
- package/dist/retrieval/adviceLines.js +0 -195
- package/dist/retrieval/adviceQuestion.js +0 -44
- package/dist/retrieval/conversationShape.js +0 -44
- package/dist/retrieval/dailyEntryTime.js +0 -55
- package/dist/retrieval/entityLookup.js +0 -162
- package/dist/retrieval/factsFirst.js +0 -188
- package/dist/retrieval/keyword.js +0 -84
- package/dist/retrieval/ledgerEventTime.js +0 -51
- package/dist/retrieval/ledgerLiveness.js +0 -83
- package/dist/retrieval/ledgerPresentation.js +0 -161
- package/dist/retrieval/noteIdentity.js +0 -57
- package/dist/retrieval/orchestrator.js +0 -1224
- package/dist/retrieval/plainWording.js +0 -236
- package/dist/retrieval/queryHelpers.js +0 -142
- package/dist/retrieval/questionSpan.js +0 -475
- package/dist/retrieval/rankingTrace.js +0 -184
- package/dist/retrieval/readerEvents.js +0 -690
- package/dist/retrieval/readerLayout.js +0 -422
- package/dist/retrieval/relativeTimeHints.js +0 -113
- package/dist/retrieval/semantic.js +0 -67
- package/dist/router/routerCache.js +0 -106
- package/dist/router/sessionRouter.js +0 -726
- package/dist/sharing/cli.js +0 -181
- package/dist/sharing/examples.js +0 -136
- package/dist/sharing/fields.js +0 -225
- package/dist/sharing/loop.js +0 -80
- package/dist/sharing/project.js +0 -327
- package/dist/sharing/send.js +0 -466
- package/dist/sharing/state.js +0 -222
- package/dist/sharing/wording.js +0 -48
- package/dist/toolRefusal.js +0 -120
- package/dist/watcher/watcher.js +0 -77
- /package/dist/{indexer/o200k.json → o200k.json} +0 -0
package/dist/mvp/log.js
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* One operator-log shape for the engine, the gateway and the Edge Functions: a single JSON line
|
|
4
|
-
* `{ ts, level, svc, event, ...fields, err? }`, written with console.log (info), console.warn (warn) or console.error (error).
|
|
5
|
-
*
|
|
6
|
-
* Source of truth: engine/src/mvp/log.ts. Byte-identical copies live at
|
|
7
|
-
* engine/apps/gateway/src/shared/log.ts and supabase/functions/_shared/log.ts, because each runtime
|
|
8
|
-
* deploys alone; engine/tests/mvp/structured-log.test.ts holds them equal. No imports, so it compiles
|
|
9
|
-
* as CommonJS (engine), NodeNext ESM (gateway) and Deno (Edge Functions).
|
|
10
|
-
*
|
|
11
|
-
* What it refuses to write: field values that are not scalars, field names that are not plain identifiers,
|
|
12
|
-
* keys that name a credential or private content (see SENSITIVE_KEY), and, inside every string it writes
|
|
13
|
-
* (fields, the error's name, message, code and each stack frame): control and bidi characters, URL
|
|
14
|
-
* queries and userinfo, bearer tokens, JWTs, known key formats, credential-labelled values, long
|
|
15
|
-
* unlabelled keys, emails and absolute paths (see REDACTIONS). Strings are cut at 300 characters, so a
|
|
16
|
-
* stray memory excerpt cannot leak whole.
|
|
17
|
-
*/
|
|
18
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.serializeError = serializeError;
|
|
20
|
-
exports.formatLogLine = formatLogLine;
|
|
21
|
-
exports.createLogger = createLogger;
|
|
22
|
-
const MAX_STRING = 300;
|
|
23
|
-
const MAX_FRAMES = 5;
|
|
24
|
-
const RESERVED = new Set(['ts', 'level', 'svc', 'event', 'err']);
|
|
25
|
-
const SENSITIVE_KEY = /secret|token|password|passwd|authorization|cookie|api_?key|service_?role|dsn|credential|^body$|^text$|^content$|^query$|^memory$|^email$/i;
|
|
26
|
-
const SAFE_KEY = /^[A-Za-z][A-Za-z0-9_]{0,63}$/;
|
|
27
|
-
// C0/C1 controls, soft hyphen, zero-width and bidi controls, NEL and the Unicode line/paragraph separators: none may
|
|
28
|
-
// reach a log line, where they forge new lines or hide what an operator reads.
|
|
29
|
-
const CONTROL = /[\u0000-\u001f\u007f-\u009f\u00ad\u061c\u180e\u200b-\u200f\u2028-\u202e\u2060-\u206f\ufeff]/g;
|
|
30
|
-
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
31
|
-
/** Applied in order to every string written; each step names what it takes out. */
|
|
32
|
-
const REDACTIONS = [
|
|
33
|
-
[CONTROL, ' '],
|
|
34
|
-
// Credentials in a URL: userinfo (`scheme://user:pass@`) and the whole query string.
|
|
35
|
-
[/\b([a-z][a-z0-9+.-]*:\/\/)[^\s/?#@]+@/gi, '$1[redacted]@'],
|
|
36
|
-
[/\?[^\s#"'<>|]*=[^\s#"'<>|]*/g, '?[redacted]'],
|
|
37
|
-
// Bearer tokens, JWTs and the key formats the services Renor talks to use.
|
|
38
|
-
[/\bBearer\s+[A-Za-z0-9._~+/=-]+/gi, 'Bearer [redacted]'],
|
|
39
|
-
[/\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]+/g, '[redacted]'],
|
|
40
|
-
[/\b(?:sk|pk|rk|whsec|re|phc|phx|sbp|ghp|gho|ghs|xox[abp])[_-][A-Za-z0-9_-]{12,}/g, '[redacted]'],
|
|
41
|
-
// Any value labelled as a credential: `api_key=...`, `password: ...`, `x-api-key: ...`.
|
|
42
|
-
[/\b((?:x-)?(?:api[_-]?key|access[_-]?key|client[_-]?secret|secret|token|password|passwd|pwd|auth|authorization|signature|sig|session|cookie|apikey))(\s*[=:]\s*)("[^"]*"|'[^']*'|[^\s,;&"']+)/gi, '$1$2[redacted]'],
|
|
43
|
-
// An unlabelled long random-looking string (letters and digits, 32+): a key nobody named. UUIDs are ids, and stay.
|
|
44
|
-
[/\b[A-Za-z0-9_-]{32,}\b/g, (m) => (UUID.test(m) || !/[0-9]/.test(m) || !/[A-Za-z]/.test(m) ? m : '[redacted]')],
|
|
45
|
-
[/[A-Za-z0-9._%+-]+@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)+/g, '[email]'],
|
|
46
|
-
// Absolute paths: they name the tenant and the user's own files. A path relative to the memory folder stays.
|
|
47
|
-
[/file:\/\/\/?[^\s()'"`,;]+/g, '[path]'],
|
|
48
|
-
[/(^|[\s(\[='"`,])\/(?:[^\s/()'"`,;]+\/)+[^\s/()'"`,;:]+/g, '$1[path]'],
|
|
49
|
-
[/\b[A-Za-z]:\\[^\s'"`,;]*/g, '[path]'],
|
|
50
|
-
];
|
|
51
|
-
function clean(value) {
|
|
52
|
-
let out = value;
|
|
53
|
-
for (const [pattern, replacement] of REDACTIONS)
|
|
54
|
-
out = out.replace(pattern, replacement);
|
|
55
|
-
return out.length > MAX_STRING ? `${out.slice(0, MAX_STRING)}…` : out;
|
|
56
|
-
}
|
|
57
|
-
/** One stack frame: its function and the code file's name and position, never the directory it runs from. */
|
|
58
|
-
function cleanFrame(frame) {
|
|
59
|
-
return clean(frame.trim().replace(/(?:file:\/\/)?(?:\/|[A-Za-z]:\\)[^\s()]*?([^/\\\s()]+\.[cm]?[jt]sx?):(\d+):(\d+)/g, '$1:$2:$3'));
|
|
60
|
-
}
|
|
61
|
-
/** The error as it is reported everywhere: name, a cut message, an optional code and the top stack frames, each cleaned. */
|
|
62
|
-
function serializeError(err) {
|
|
63
|
-
if (!(err instanceof Error))
|
|
64
|
-
return { name: 'NonError', message: clean(String(err)) };
|
|
65
|
-
const out = { name: clean(String(err.name)), message: clean(String(err.message)) };
|
|
66
|
-
const code = err.code;
|
|
67
|
-
if (typeof code === 'string' || typeof code === 'number')
|
|
68
|
-
out.code = clean(String(code));
|
|
69
|
-
const frames = String(err.stack ?? '').split('\n').filter((line) => /^\s+at /.test(line)).slice(0, MAX_FRAMES);
|
|
70
|
-
if (frames.length > 0)
|
|
71
|
-
out.stack = frames.map(cleanFrame).join(' | ');
|
|
72
|
-
return out;
|
|
73
|
-
}
|
|
74
|
-
/** The JSON line for one event; exported so a test can read exactly what would be written. */
|
|
75
|
-
function formatLogLine(svc, level, event, fields = {}, err) {
|
|
76
|
-
const line = { ts: new Date().toISOString(), level, svc: clean(svc), event: clean(event) };
|
|
77
|
-
for (const [key, value] of Object.entries(fields)) {
|
|
78
|
-
if (value === undefined || RESERVED.has(key) || !SAFE_KEY.test(key))
|
|
79
|
-
continue;
|
|
80
|
-
if (SENSITIVE_KEY.test(key))
|
|
81
|
-
line[key] = '[redacted]';
|
|
82
|
-
else if (typeof value === 'string')
|
|
83
|
-
line[key] = clean(value);
|
|
84
|
-
else if (typeof value === 'number' || typeof value === 'boolean' || value === null)
|
|
85
|
-
line[key] = value;
|
|
86
|
-
}
|
|
87
|
-
if (err !== undefined)
|
|
88
|
-
line.err = serializeError(err);
|
|
89
|
-
return JSON.stringify(line);
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* `stderr: true` writes info lines to stderr too, for code that also runs where stdout is data (the stdio MCP server, a
|
|
93
|
-
* CLI that prints JSON). This module is the only place in the engine, the gateway and the Edge Functions' shared code
|
|
94
|
-
* allowed to call console; engine/tests/mvp/no-raw-console.test.ts holds that.
|
|
95
|
-
*/
|
|
96
|
-
function createLogger(svc, options = {}) {
|
|
97
|
-
const write = (level, event, fields, err) => {
|
|
98
|
-
try {
|
|
99
|
-
const line = formatLogLine(svc, level, event, fields, err);
|
|
100
|
-
if (level === 'info' && !options.stderr)
|
|
101
|
-
console.log(line);
|
|
102
|
-
else if (level === 'info')
|
|
103
|
-
console.error(line);
|
|
104
|
-
else if (level === 'warn')
|
|
105
|
-
console.warn(line);
|
|
106
|
-
else
|
|
107
|
-
console.error(line);
|
|
108
|
-
}
|
|
109
|
-
catch {
|
|
110
|
-
// Logging must never break the product.
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
return {
|
|
114
|
-
info: (event, fields) => write('info', event, fields),
|
|
115
|
-
warn: (event, fields, err) => write('warn', event, fields, err),
|
|
116
|
-
error: (event, fields, err) => write('error', event, fields, err),
|
|
117
|
-
};
|
|
118
|
-
}
|
package/dist/mvp/memoryDir.js
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ensureOwnerOnlyMemoryDir = ensureOwnerOnlyMemoryDir;
|
|
7
|
-
exports.ensureOwnerOnlyFile = ensureOwnerOnlyFile;
|
|
8
|
-
const fs_1 = __importDefault(require("fs"));
|
|
9
|
-
const path_1 = __importDefault(require("path"));
|
|
10
|
-
/**
|
|
11
|
-
* The memory directory holds the user's statements in plain text (daily notes, the ledger) and the index built
|
|
12
|
-
* from them, so it is owner-only, as the OAuth client store already is. A directory the running user owns that
|
|
13
|
-
* group or others can reach is tightened at start (0700 for directories, 0600 for files, one log line); one that
|
|
14
|
-
* cannot be tightened, because someone else owns it or the change is refused, stops the start.
|
|
15
|
-
*/
|
|
16
|
-
function failClosed(dir, reason) {
|
|
17
|
-
throw new Error(`Memory directory is not usable: ${reason}. `
|
|
18
|
-
+ 'Refusing to start with a memory directory other users can read (fail closed). '
|
|
19
|
-
+ `Run: chmod -R go-rwx ${JSON.stringify(dir)} as its owner, then start again.`);
|
|
20
|
-
}
|
|
21
|
-
const accessibleByOthers = (mode) => (mode & 0o077) !== 0;
|
|
22
|
-
/** Tightens what is owned by `uid` under `dir`, without following symlinks; what someone else owns is left alone. */
|
|
23
|
-
function tightenTree(dir, uid) {
|
|
24
|
-
for (const entry of fs_1.default.readdirSync(dir, { withFileTypes: true })) {
|
|
25
|
-
const full = path_1.default.join(dir, entry.name);
|
|
26
|
-
if (entry.isSymbolicLink())
|
|
27
|
-
continue;
|
|
28
|
-
const stat = fs_1.default.lstatSync(full);
|
|
29
|
-
if (stat.uid !== uid)
|
|
30
|
-
continue;
|
|
31
|
-
if (entry.isDirectory()) {
|
|
32
|
-
if (accessibleByOthers(stat.mode))
|
|
33
|
-
fs_1.default.chmodSync(full, 0o700);
|
|
34
|
-
tightenTree(full, uid);
|
|
35
|
-
}
|
|
36
|
-
else if (entry.isFile() && accessibleByOthers(stat.mode)) {
|
|
37
|
-
fs_1.default.chmodSync(full, 0o600);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Creates the directory owner-only (0700) when it does not exist. One that exists must be a directory owned by the
|
|
43
|
-
* running user; if group or others can access it, it is tightened (everything under it that the user owns too) and
|
|
44
|
-
* `log` is told once. Symlinked paths are followed (the directory may live on another disk).
|
|
45
|
-
*/
|
|
46
|
-
function ensureOwnerOnlyMemoryDir(dir, log = console.log) {
|
|
47
|
-
try {
|
|
48
|
-
fs_1.default.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
49
|
-
}
|
|
50
|
-
catch (err) {
|
|
51
|
-
// A file at the path is reported below as what it is.
|
|
52
|
-
if (err.code !== 'EEXIST')
|
|
53
|
-
throw err;
|
|
54
|
-
}
|
|
55
|
-
const uid = process.getuid?.();
|
|
56
|
-
// No POSIX owner to compare on this platform; the client store refuses to run there as well.
|
|
57
|
-
if (uid === undefined)
|
|
58
|
-
return;
|
|
59
|
-
let stat;
|
|
60
|
-
try {
|
|
61
|
-
stat = fs_1.default.statSync(dir);
|
|
62
|
-
}
|
|
63
|
-
catch (err) {
|
|
64
|
-
failClosed(dir, `it is unreadable (${err.code})`);
|
|
65
|
-
}
|
|
66
|
-
if (!stat.isDirectory())
|
|
67
|
-
failClosed(dir, 'the path is not a directory');
|
|
68
|
-
if (stat.uid !== uid)
|
|
69
|
-
failClosed(dir, 'it is not owned by the service user, so it cannot be tightened to owner-only (0700)');
|
|
70
|
-
if (!accessibleByOthers(stat.mode))
|
|
71
|
-
return;
|
|
72
|
-
const was = (stat.mode & 0o777).toString(8);
|
|
73
|
-
try {
|
|
74
|
-
fs_1.default.chmodSync(dir, 0o700);
|
|
75
|
-
tightenTree(dir, uid);
|
|
76
|
-
}
|
|
77
|
-
catch (err) {
|
|
78
|
-
failClosed(dir, `it is accessible by group or others (mode ${was}) and cannot be tightened to owner-only (0700) (${err.code})`);
|
|
79
|
-
}
|
|
80
|
-
log(`[mvp] memory directory ${dir} was accessible by group or others (mode ${was}); tightened to owner-only: directories 0700, files 0600`);
|
|
81
|
-
}
|
|
82
|
-
/** A database file that exists and group or others can reach is tightened to 0600, with its -wal and -shm files. */
|
|
83
|
-
function ensureOwnerOnlyFile(file) {
|
|
84
|
-
const uid = process.getuid?.();
|
|
85
|
-
if (uid === undefined)
|
|
86
|
-
return;
|
|
87
|
-
for (const candidate of [file, `${file}-wal`, `${file}-shm`]) {
|
|
88
|
-
let stat;
|
|
89
|
-
try {
|
|
90
|
-
stat = fs_1.default.lstatSync(candidate);
|
|
91
|
-
}
|
|
92
|
-
catch {
|
|
93
|
-
continue;
|
|
94
|
-
}
|
|
95
|
-
if (stat.isFile() && stat.uid === uid && accessibleByOthers(stat.mode))
|
|
96
|
-
fs_1.default.chmodSync(candidate, 0o600);
|
|
97
|
-
}
|
|
98
|
-
}
|
package/dist/mvp/posthogMcp.js
DELETED
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.redactMcpAnalyticsEvent = redactMcpAnalyticsEvent;
|
|
4
|
-
exports.instrumentMcpServer = instrumentMcpServer;
|
|
5
|
-
exports.shutdownPosthogMcp = shutdownPosthogMcp;
|
|
6
|
-
exports.resetPosthogMcpForTests = resetPosthogMcpForTests;
|
|
7
|
-
const node_crypto_1 = require("node:crypto");
|
|
8
|
-
const telemetry_1 = require("./telemetry");
|
|
9
|
-
/**
|
|
10
|
-
* PostHog MCP Analytics (@posthog/mcp) for the production MVP server.
|
|
11
|
-
*
|
|
12
|
-
* Privacy defaults match Renor's contract: never capture tool args, results,
|
|
13
|
-
* memory content, queries, or model/conversation text. Instrumentation is a
|
|
14
|
-
* no-op when RENOR_POSTHOG_KEY is missing or RENOR_TELEMETRY_DISABLED=true.
|
|
15
|
-
*/
|
|
16
|
-
const DEFAULT_HOST = 'https://us.i.posthog.com';
|
|
17
|
-
// The two packages are ~130 modules and ~110 ms of a cold start (measured with scripts/bench/cold-start.ts), and a
|
|
18
|
-
// workspace without RENOR_POSTHOG_KEY, or with remote telemetry off, never calls into them (instrumentMcpServer returns
|
|
19
|
-
// first). They are loaded here, on the first call that needs them, which is the same moment a configured workspace
|
|
20
|
-
// loaded them before: createMvpApp builds its first server before the service listens.
|
|
21
|
-
const loadPosthogNode = () => require('posthog-node');
|
|
22
|
-
const loadPosthogMcp = () => require('@posthog/mcp');
|
|
23
|
-
/** Property keys that may carry args/results/content — always stripped. */
|
|
24
|
-
const STRIP_EXACT = new Set([
|
|
25
|
-
'$mcp_parameters',
|
|
26
|
-
'$mcp_response',
|
|
27
|
-
'$mcp_intent',
|
|
28
|
-
'$mcp_error_message',
|
|
29
|
-
'$mcp_feedback_details',
|
|
30
|
-
'$mcp_feedback_summary',
|
|
31
|
-
'$mcp_feedback_suggested_improvement',
|
|
32
|
-
'$mcp_feedback_friction_points',
|
|
33
|
-
'$mcp_tool_description',
|
|
34
|
-
'args',
|
|
35
|
-
'arguments',
|
|
36
|
-
'params',
|
|
37
|
-
'parameters',
|
|
38
|
-
'result',
|
|
39
|
-
'response',
|
|
40
|
-
'content',
|
|
41
|
-
'query',
|
|
42
|
-
'statement',
|
|
43
|
-
'text',
|
|
44
|
-
'body',
|
|
45
|
-
'message',
|
|
46
|
-
]);
|
|
47
|
-
const STRIP_SUBSTRING = [
|
|
48
|
-
'parameter',
|
|
49
|
-
'argument',
|
|
50
|
-
'response',
|
|
51
|
-
'content',
|
|
52
|
-
'query',
|
|
53
|
-
'statement',
|
|
54
|
-
'memory',
|
|
55
|
-
'prompt',
|
|
56
|
-
'exception_message',
|
|
57
|
-
'exception_stack',
|
|
58
|
-
];
|
|
59
|
-
let client;
|
|
60
|
-
let shutdownHookInstalled = false;
|
|
61
|
-
function env(name) {
|
|
62
|
-
return (process.env[name] ?? '').trim();
|
|
63
|
-
}
|
|
64
|
-
function remoteDisabled() {
|
|
65
|
-
return env('RENOR_TELEMETRY_DISABLED').toLowerCase() === 'true';
|
|
66
|
-
}
|
|
67
|
-
function pseudonymousDistinctId(instance) {
|
|
68
|
-
const salt = env('RENOR_TELEMETRY_HASH_SALT');
|
|
69
|
-
return (0, node_crypto_1.createHash)('sha256')
|
|
70
|
-
.update(`renor-telemetry:\0${salt}\0${instance}`)
|
|
71
|
-
.digest('hex')
|
|
72
|
-
.slice(0, 24);
|
|
73
|
-
}
|
|
74
|
-
/** Testable privacy filter — strips args/results/content; keeps tool/ok/duration. */
|
|
75
|
-
function redactMcpAnalyticsEvent(event) {
|
|
76
|
-
if (!event || typeof event !== 'object')
|
|
77
|
-
return null;
|
|
78
|
-
// Exception siblings can embed stack/message text — drop entirely.
|
|
79
|
-
if (event.event === '$exception')
|
|
80
|
-
return null;
|
|
81
|
-
const properties = { ...(event.properties ?? {}) };
|
|
82
|
-
for (const key of Object.keys(properties)) {
|
|
83
|
-
const lower = key.toLowerCase();
|
|
84
|
-
if (STRIP_EXACT.has(key) || STRIP_EXACT.has(lower)) {
|
|
85
|
-
delete properties[key];
|
|
86
|
-
continue;
|
|
87
|
-
}
|
|
88
|
-
if (STRIP_SUBSTRING.some((needle) => lower.includes(needle))) {
|
|
89
|
-
// Keep known-safe metadata keys even if they contain a substring match.
|
|
90
|
-
if (key === '$mcp_is_error' ||
|
|
91
|
-
key === '$mcp_duration_ms' ||
|
|
92
|
-
key === '$mcp_tool_name' ||
|
|
93
|
-
key === '$mcp_client_name' ||
|
|
94
|
-
key === '$mcp_client_version' ||
|
|
95
|
-
key === '$mcp_server_name' ||
|
|
96
|
-
key === '$mcp_server_version' ||
|
|
97
|
-
key === '$mcp_protocol_version' ||
|
|
98
|
-
key === '$mcp_listed_tool_names' ||
|
|
99
|
-
key === '$mcp_source' ||
|
|
100
|
-
key === '$groups' ||
|
|
101
|
-
key === '$process_person_profile' ||
|
|
102
|
-
key === 'service') {
|
|
103
|
-
continue;
|
|
104
|
-
}
|
|
105
|
-
delete properties[key];
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
return {
|
|
109
|
-
distinct_id: event.distinct_id,
|
|
110
|
-
event: event.event,
|
|
111
|
-
timestamp: event.timestamp,
|
|
112
|
-
type: 'capture',
|
|
113
|
-
properties,
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
function getOrCreateClient() {
|
|
117
|
-
if (client !== undefined)
|
|
118
|
-
return client;
|
|
119
|
-
if (remoteDisabled()) {
|
|
120
|
-
client = null;
|
|
121
|
-
return null;
|
|
122
|
-
}
|
|
123
|
-
const apiKey = env('RENOR_POSTHOG_KEY');
|
|
124
|
-
if (!apiKey) {
|
|
125
|
-
client = null;
|
|
126
|
-
return null;
|
|
127
|
-
}
|
|
128
|
-
const host = env('RENOR_POSTHOG_HOST') || DEFAULT_HOST;
|
|
129
|
-
try {
|
|
130
|
-
client = new (loadPosthogNode().PostHog)(apiKey, {
|
|
131
|
-
host,
|
|
132
|
-
// Privacy: do not capture IP / personal profiles by default.
|
|
133
|
-
disableGeoip: true,
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
catch {
|
|
137
|
-
client = null;
|
|
138
|
-
}
|
|
139
|
-
return client;
|
|
140
|
-
}
|
|
141
|
-
function installShutdownHook() {
|
|
142
|
-
if (shutdownHookInstalled)
|
|
143
|
-
return;
|
|
144
|
-
shutdownHookInstalled = true;
|
|
145
|
-
// Best-effort: cli.ts also awaits shutdownPosthogMcp on SIGINT/SIGTERM.
|
|
146
|
-
// This covers process paths that skip the CLI handler.
|
|
147
|
-
const onSignal = () => {
|
|
148
|
-
void shutdownPosthogMcp();
|
|
149
|
-
};
|
|
150
|
-
process.once('beforeExit', onSignal);
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* Instrument one McpServer instance (call inside buildMcpServer — SSE builds
|
|
154
|
-
* a fresh server per session). No-ops when PostHog is disabled/unconfigured.
|
|
155
|
-
*/
|
|
156
|
-
function instrumentMcpServer(server) {
|
|
157
|
-
try {
|
|
158
|
-
const posthog = getOrCreateClient();
|
|
159
|
-
if (!posthog)
|
|
160
|
-
return;
|
|
161
|
-
const tenant = (0, telemetry_1.telemetryInstanceId)();
|
|
162
|
-
const distinctId = pseudonymousDistinctId(tenant);
|
|
163
|
-
loadPosthogMcp().instrument(server, posthog, {
|
|
164
|
-
context: false,
|
|
165
|
-
enableConversationId: false,
|
|
166
|
-
captureModel: false,
|
|
167
|
-
enableExceptionAutocapture: false,
|
|
168
|
-
identify: async () => ({
|
|
169
|
-
distinctId,
|
|
170
|
-
// The workspace as PostHog's `tenant` group, filed under the same salted hash as the distinct id and
|
|
171
|
-
// never under the slug: a slug made before opaque workspace names is the owner's email local part.
|
|
172
|
-
groups: tenant && tenant !== 'unknown' ? { tenant: distinctId } : undefined,
|
|
173
|
-
properties: {
|
|
174
|
-
service: 'renor-core',
|
|
175
|
-
$process_person_profile: false,
|
|
176
|
-
},
|
|
177
|
-
}),
|
|
178
|
-
eventProperties: async () => ({
|
|
179
|
-
service: 'renor-core',
|
|
180
|
-
$process_person_profile: false,
|
|
181
|
-
}),
|
|
182
|
-
beforeSend: redactMcpAnalyticsEvent,
|
|
183
|
-
logger: () => {
|
|
184
|
-
// STDIO-safe: discard SDK warnings (HTTP MVP uses stderr only if needed).
|
|
185
|
-
},
|
|
186
|
-
});
|
|
187
|
-
installShutdownHook();
|
|
188
|
-
}
|
|
189
|
-
catch {
|
|
190
|
-
// Observability must never break the product.
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
/** Flush + stop the shared posthog-node client (SIGINT/SIGTERM). */
|
|
194
|
-
async function shutdownPosthogMcp() {
|
|
195
|
-
const current = client;
|
|
196
|
-
client = null;
|
|
197
|
-
if (!current)
|
|
198
|
-
return;
|
|
199
|
-
try {
|
|
200
|
-
await current.shutdown();
|
|
201
|
-
}
|
|
202
|
-
catch {
|
|
203
|
-
// ignore
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
/** Test helper: reset singleton between hermetic tests. */
|
|
207
|
-
function resetPosthogMcpForTests() {
|
|
208
|
-
client = undefined;
|
|
209
|
-
shutdownHookInstalled = false;
|
|
210
|
-
}
|
package/dist/mvp/readScope.js
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createReadScope = createReadScope;
|
|
4
|
-
const readCache_1 = require("../db/readCache");
|
|
5
|
-
const statements_1 = require("../db/statements");
|
|
6
|
-
const lifecycle_1 = require("../memory/lifecycle");
|
|
7
|
-
const ledgerLiveness_1 = require("../retrieval/ledgerLiveness");
|
|
8
|
-
const scope_1 = require("./scope");
|
|
9
|
-
/** How many chunks naming an event make reading every event's scope at once cheaper than asking about each. */
|
|
10
|
-
const PRELOAD_EVENTS_FROM = 64;
|
|
11
|
-
function createReadScope(db, scope) {
|
|
12
|
-
const projected = (0, readCache_1.tableHasColumns)(db, 'facts', ['event_id', 'scope']);
|
|
13
|
-
const eventRow = projected
|
|
14
|
-
? (0, statements_1.prepareOnce)(db, `SELECT COALESCE(scope, 'global') AS scope FROM facts WHERE event_id = ? AND source_path = ?`)
|
|
15
|
-
: null;
|
|
16
|
-
const factRow = projected
|
|
17
|
-
? (0, statements_1.prepareOnce)(db, `SELECT COALESCE(scope, 'global') AS scope FROM facts WHERE id = ? AND source_path = ?`)
|
|
18
|
-
: null;
|
|
19
|
-
const own = (0, scope_1.savedScopeSqlPredicate)(scope, `COALESCE(scope, 'global')`);
|
|
20
|
-
const otherScopeRows = projected
|
|
21
|
-
? (0, statements_1.prepareOnce)(db, `SELECT event_id FROM facts WHERE source_path = ? AND event_id IS NOT NULL AND NOT (${own.sql})`)
|
|
22
|
-
: null;
|
|
23
|
-
// Event ids are stored upper-case, so the unique index on facts(event_id) answers each lookup.
|
|
24
|
-
const events = new Map();
|
|
25
|
-
/** The scope an event was saved in; undefined when the lifecycle layer knows no such event. */
|
|
26
|
-
const eventScope = (id) => {
|
|
27
|
-
const key = id.toUpperCase();
|
|
28
|
-
if (!events.has(key))
|
|
29
|
-
events.set(key, eventRow?.get(key, lifecycle_1.LIFECYCLE_NOTE_PATH)?.scope);
|
|
30
|
-
return events.get(key);
|
|
31
|
-
};
|
|
32
|
-
/**
|
|
33
|
-
* Every event's scope in one read, for the pass over the index (`chunkIds`) that asks about the event of each of its
|
|
34
|
-
* thousands of ledger chunks: one statement each was most of a scoped read's cost, growing with every fact saved. What
|
|
35
|
-
* is kept is what `eventScope` would find: the event of that upper-case id, in the lifecycle layer. An id that is not
|
|
36
|
-
* kept (not upper-case, or not an event) is asked about one by one, as before.
|
|
37
|
-
*/
|
|
38
|
-
const preloadEvents = () => {
|
|
39
|
-
if (!projected)
|
|
40
|
-
return;
|
|
41
|
-
const rows = (0, statements_1.prepareOnce)(db, `SELECT event_id AS id, COALESCE(scope, 'global') AS scope FROM facts WHERE source_path = ? AND event_id IS NOT NULL`).all(lifecycle_1.LIFECYCLE_NOTE_PATH);
|
|
42
|
-
for (const row of rows)
|
|
43
|
-
if (row.id === row.id.toUpperCase() && !events.has(row.id))
|
|
44
|
-
events.set(row.id, row.scope);
|
|
45
|
-
};
|
|
46
|
-
let elsewhere; // ids (lower-case) of the events saved in other scopes, read on first use
|
|
47
|
-
const has = (hit, notePath) => {
|
|
48
|
-
// A fact has no note path to judge it by: the scope on its row decides, and a fact whose row is gone is dropped.
|
|
49
|
-
if (hit.notePath === lifecycle_1.LIFECYCLE_NOTE_PATH && typeof hit.chunkId === 'number' && hit.chunkId < 0) {
|
|
50
|
-
const row = factRow?.get(-hit.chunkId, lifecycle_1.LIFECYCLE_NOTE_PATH);
|
|
51
|
-
return row !== undefined && (0, scope_1.savedScopeMatches)(row.scope, scope);
|
|
52
|
-
}
|
|
53
|
-
// A hit is one chunk, so one event (the chunker splits at every event heading): shown whole, or not at all.
|
|
54
|
-
// Anything that only looks like an event id (an ordinary heading) is no event, and its note path decides.
|
|
55
|
-
const saved = (0, ledgerLiveness_1.ledgerEventIds)(hit).map(eventScope).filter((s) => s !== undefined);
|
|
56
|
-
if (saved.length)
|
|
57
|
-
return saved.every(s => (0, scope_1.savedScopeMatches)(s, scope));
|
|
58
|
-
return (0, scope_1.notePathMatchesScope)(notePath, scope);
|
|
59
|
-
};
|
|
60
|
-
return {
|
|
61
|
-
has,
|
|
62
|
-
hits(hits, notePath) {
|
|
63
|
-
return hits.filter(hit => has(hit, notePath(hit)));
|
|
64
|
-
},
|
|
65
|
-
body(text) {
|
|
66
|
-
// Only the ledger holds events: any other note is returned as it is, without asking the database anything.
|
|
67
|
-
if (!(0, ledgerLiveness_1.ledgerEventIds)({ text }).length)
|
|
68
|
-
return text;
|
|
69
|
-
// A body holds every event, so the ids of other scopes' events are read in one query, once per read, rather than
|
|
70
|
-
// looked up event by event (a 3,000-event ledger: body() 19 ms, now 6 ms).
|
|
71
|
-
elsewhere ??= new Set((otherScopeRows?.all(lifecycle_1.LIFECYCLE_NOTE_PATH, ...own.params) ?? [])
|
|
72
|
-
.map(r => r.event_id.toLowerCase()));
|
|
73
|
-
if (!elsewhere.size)
|
|
74
|
-
return text;
|
|
75
|
-
// The note is cut block by block. Another scope's events go the way closed ones go without history: never
|
|
76
|
-
// shown, and never labelled as history either.
|
|
77
|
-
return (0, ledgerLiveness_1.resolveLedgerHits)([{ text, reason: 'other-scope' }], elsewhere, false)[0]?.text ?? '';
|
|
78
|
-
},
|
|
79
|
-
chunkIds(notePath) {
|
|
80
|
-
// `has` reads a chunk's text only for a line that opens an event (`## MEM_… · `, in any case): every other text is
|
|
81
|
-
// read here as empty, so the pass reads paths and headings, and the text of the few chunks that could hold one. A
|
|
82
|
-
// named scope holds no chunk that names no event outside its own directory (scopeSqlPredicate, the SQL twin of
|
|
83
|
-
// notePathMatchesScope), so only the chunks under it or naming an event are judged; the global scope, every chunk.
|
|
84
|
-
const namesEvent = "text GLOB '*## [Mm][Ee][Mm]_*'";
|
|
85
|
-
const under = scope === 'global' ? null : (0, scope_1.scopeSqlPredicate)(scope, 'note_path');
|
|
86
|
-
const rows = (0, statements_1.prepareOnce)(db, `SELECT id AS chunkId, note_path AS notePath, heading_path AS headingPath,
|
|
87
|
-
CASE WHEN ${namesEvent} THEN text ELSE '' END AS text
|
|
88
|
-
FROM chunks${under ? ` WHERE ${under.sql} OR ${namesEvent} OR heading_path GLOB '*[Mm][Ee][Mm]_*'` : ''}`).all(...(under?.params ?? []));
|
|
89
|
-
// A chunk that names an event is the only one that asks the lifecycle layer anything: a few ask one by one, a
|
|
90
|
-
// ledger's thousands ask all at once.
|
|
91
|
-
const namesOne = (row) => row.text !== '' || (row.headingPath ?? '').toUpperCase().includes('MEM_');
|
|
92
|
-
if (rows.reduce((n, row) => n + (namesOne(row) ? 1 : 0), 0) > PRELOAD_EVENTS_FROM)
|
|
93
|
-
preloadEvents();
|
|
94
|
-
const shown = new Map(); // a note's chunks share its path (the ledger is one note)
|
|
95
|
-
const pathOf = (stored) => {
|
|
96
|
-
let judged = shown.get(stored);
|
|
97
|
-
if (judged === undefined)
|
|
98
|
-
shown.set(stored, (judged = notePath(stored)));
|
|
99
|
-
return judged;
|
|
100
|
-
};
|
|
101
|
-
return rows.filter(row => has(row, pathOf(row.notePath))).map(row => row.chunkId);
|
|
102
|
-
},
|
|
103
|
-
};
|
|
104
|
-
}
|