renor-engine 1.2.0 → 1.4.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 +34 -2
- package/THIRD-PARTY-NOTICES +2661 -0
- package/bin/renor-engine.cjs +38 -0
- package/dist/BUILD.json +6 -0
- package/dist/cli.js +1674 -516
- package/package.json +17 -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
|
@@ -1,307 +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.JevDecisionModel = exports.JEV_INPUT_USD_PER_MTOK = exports.JEV_COOLDOWN_MS = exports.JEV_TIMEOUT_MS = exports.JEV_STORE_MIN = exports.JEV_MODEL = exports.JEV_BASE_URL = void 0;
|
|
7
|
-
exports.resolveJevOptin = resolveJevOptin;
|
|
8
|
-
exports.readJevKey = readJevKey;
|
|
9
|
-
exports.jevDecisionLogPath = jevDecisionLogPath;
|
|
10
|
-
exports.jevDecisionLog = jevDecisionLog;
|
|
11
|
-
exports.saveDecisionModel = saveDecisionModel;
|
|
12
|
-
/**
|
|
13
|
-
* Jev (TypeSafe System One) behind the DecisionModel seam, for the save path of ONE opted-in workspace.
|
|
14
|
-
*
|
|
15
|
-
* Off unless the workspace's own env file says so (owner decision, 21 Oct 2026: "your own workspace only, now"):
|
|
16
|
-
*
|
|
17
|
-
* RENOR_JEV_OPTIN=<workspace slug> must equal MVP_INSTANCE_ID, so an env file copied to another workspace stays off
|
|
18
|
-
* RENOR_JEV_KEY_FILE=<path> the TypeSafe key, by its path (a file, so the env file never holds the secret)
|
|
19
|
-
*
|
|
20
|
-
* Both are needed, and so is MVP_MEMORY_DIR (every decision is recorded there, so a decision that cannot be recorded is not made).
|
|
21
|
-
* Anything else, or a setting that does not parse, is off with one stderr line naming the setting, never a value.
|
|
22
|
-
*
|
|
23
|
-
* What it does, once per text about to be stored, in one request (the two questions are independent):
|
|
24
|
-
*
|
|
25
|
-
* sensitivity a credential or a personal identifier. The scanner (secretGuard.ts) has already answered and a scanner
|
|
26
|
-
* `sensitive` stays final; this adds a second opinion. `store` is allowed only at P(store) >= 0.7, the rule
|
|
27
|
-
* that caught 243/243 planted items at 2/200 false blocks (LEDGER block F). A block refuses the save, as the
|
|
28
|
-
* scanner does, and nothing is redacted.
|
|
29
|
-
* capture gate whether the text is worth saving. RECORDED ONLY: it never drops a save, because a wrong "not worth it"
|
|
30
|
-
* loses a memory silently and the scout measured 93% recall, not 100%.
|
|
31
|
-
*
|
|
32
|
-
* What it never does: it reads nothing, so no read path reaches it; it sends no text that is already stored; it never owns a
|
|
33
|
-
* dedupe or supersede verdict (dedupe_adjudication is the local rules, byte for byte: Jev made 16/55 wrong supersedes on real
|
|
34
|
-
* pairs); and it never blocks or loses a save for any reason of its own: a timeout, an error, a bad reply or a cool-down all
|
|
35
|
-
* fall back to today's local rules (the scanner has already run). Every call is recorded as numbers and labels, never text.
|
|
36
|
-
*/
|
|
37
|
-
const node_fs_1 = __importDefault(require("node:fs"));
|
|
38
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
39
|
-
const decision_model_1 = require("./decision-model");
|
|
40
|
-
exports.JEV_BASE_URL = 'https://api.typesafe.ai';
|
|
41
|
-
exports.JEV_MODEL = 'jev-latest';
|
|
42
|
-
/** P(store) below this blocks (LEDGER block F: 243/243 planted items caught at 2/200 false blocks). */
|
|
43
|
-
exports.JEV_STORE_MIN = 0.7;
|
|
44
|
-
/** A save never waits longer than this for Jev (the scout measured p95 about 0.3 s). */
|
|
45
|
-
exports.JEV_TIMEOUT_MS = 1500;
|
|
46
|
-
/** After a failed call, saves skip Jev for this long, so an outage costs one timeout, not one per save. */
|
|
47
|
-
exports.JEV_COOLDOWN_MS = 30_000;
|
|
48
|
-
/** $0.042 per million input tokens (COST-MODEL lane-Jev arm; output is free). */
|
|
49
|
-
exports.JEV_INPUT_USD_PER_MTOK = 0.042;
|
|
50
|
-
const SENSITIVITY_QUESTION = {
|
|
51
|
-
type: 'choice',
|
|
52
|
-
instructions: 'Decide how to persist this text. "block" = do not store it at all (it contains a '
|
|
53
|
-
+ 'secret credential: API key, token, password, private key, or live account '
|
|
54
|
-
+ 'identifier). "redact" = the text is useful but contains personal identifiers '
|
|
55
|
-
+ '(phone, email, card, government id) that must be masked before storing. '
|
|
56
|
-
+ '"store" = no secrets or personal identifiers; safe to store verbatim.',
|
|
57
|
-
criteria: {
|
|
58
|
-
store: 'No secrets or personal identifiers; safe to store verbatim.',
|
|
59
|
-
block: 'Contains a secret credential; must not be stored at all.',
|
|
60
|
-
redact: 'Useful text containing personal identifiers that must be masked first.',
|
|
61
|
-
},
|
|
62
|
-
};
|
|
63
|
-
const CAPTURE_QUESTION = {
|
|
64
|
-
type: 'choice',
|
|
65
|
-
instructions: 'What durable information about the user or their world does this user message state?',
|
|
66
|
-
criteria: {
|
|
67
|
-
none: 'Nothing durable: questions, small talk, opinions, transient requests.',
|
|
68
|
-
fact: 'A stable attribute or circumstance.',
|
|
69
|
-
event: 'Something that happened or is scheduled.',
|
|
70
|
-
preference: 'A liking, dislike, habit or standing choice.',
|
|
71
|
-
commitment: 'A plan or promise for future action.',
|
|
72
|
-
sensitive: 'A credential or private identifier.',
|
|
73
|
-
},
|
|
74
|
-
};
|
|
75
|
-
function asChoice(answer) {
|
|
76
|
-
const a = answer;
|
|
77
|
-
return a && a.type === 'choice' && typeof a.choice === 'string' ? a : null;
|
|
78
|
-
}
|
|
79
|
-
function probability(answer, label) {
|
|
80
|
-
const p = answer.probabilities?.[label];
|
|
81
|
-
if (typeof p === 'number' && p >= 0 && p <= 1)
|
|
82
|
-
return p;
|
|
83
|
-
// No distribution in the reply: the chosen label gets its confidence, every other label gets nothing.
|
|
84
|
-
return answer.choice === label ? Math.max(0, Math.min(1, answer.confidence ?? 0)) : 0;
|
|
85
|
-
}
|
|
86
|
-
class JevFallback extends Error {
|
|
87
|
-
reason;
|
|
88
|
-
status;
|
|
89
|
-
constructor(reason, status) {
|
|
90
|
-
super(reason);
|
|
91
|
-
this.reason = reason;
|
|
92
|
-
this.status = status;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
class JevDecisionModel {
|
|
96
|
-
opts;
|
|
97
|
-
local;
|
|
98
|
-
baseUrl;
|
|
99
|
-
timeoutMs;
|
|
100
|
-
cooldownMs;
|
|
101
|
-
now;
|
|
102
|
-
coolUntil = 0;
|
|
103
|
-
constructor(opts) {
|
|
104
|
-
this.opts = opts;
|
|
105
|
-
this.local = opts.local ?? (0, decision_model_1.defaultDecisionModel)();
|
|
106
|
-
this.baseUrl = (opts.baseUrl ?? exports.JEV_BASE_URL).replace(/\/+$/, '');
|
|
107
|
-
this.timeoutMs = opts.timeoutMs ?? exports.JEV_TIMEOUT_MS;
|
|
108
|
-
this.cooldownMs = opts.cooldownMs ?? exports.JEV_COOLDOWN_MS;
|
|
109
|
-
this.now = opts.now ?? Date.now;
|
|
110
|
-
}
|
|
111
|
-
/** Never throws. Dedupe and note classification are the local rules, whatever Jev would say. */
|
|
112
|
-
async decide(request) {
|
|
113
|
-
// Resolve the local decision before branching so every fallback below has the concrete
|
|
114
|
-
// DecisionResult promised by this adapter, rather than its nested asynchronous form.
|
|
115
|
-
const fallback = await this.local.decide(request);
|
|
116
|
-
if (request.task !== 'capture_gate')
|
|
117
|
-
return fallback;
|
|
118
|
-
const text = request.text;
|
|
119
|
-
if (!text.trim())
|
|
120
|
-
return fallback;
|
|
121
|
-
const started = this.now();
|
|
122
|
-
if (started < this.coolUntil) {
|
|
123
|
-
this.record({ outcome: 'fallback', reason: 'cooldown', latencyMs: 0, inputTokens: 0, chars: text.length });
|
|
124
|
-
return fallback;
|
|
125
|
-
}
|
|
126
|
-
// A decision that cannot be recorded is not made: no text leaves the machine without its local record.
|
|
127
|
-
if (!this.canRecord())
|
|
128
|
-
return fallback;
|
|
129
|
-
try {
|
|
130
|
-
const call = await this.call(text);
|
|
131
|
-
const sensitivity = asChoice(call.answers.sensitivity);
|
|
132
|
-
const capture = asChoice(call.answers.capture_gate);
|
|
133
|
-
if (!sensitivity)
|
|
134
|
-
throw new JevFallback('bad_reply');
|
|
135
|
-
const pStore = probability(sensitivity, 'store');
|
|
136
|
-
const blocked = pStore < exports.JEV_STORE_MIN;
|
|
137
|
-
const inputTokens = call.inputTokens;
|
|
138
|
-
const costUSDCents = (inputTokens * exports.JEV_INPUT_USD_PER_MTOK) / 1_000_000 * 100;
|
|
139
|
-
const latencyMs = this.now() - started;
|
|
140
|
-
this.record({
|
|
141
|
-
outcome: 'applied', latencyMs, inputTokens, costUSDCents, chars: text.length,
|
|
142
|
-
sensitivity: { choice: sensitivity.choice, pStore, confidence: sensitivity.confidence ?? 0, blocked },
|
|
143
|
-
...(capture ? { capture: { choice: capture.choice, pDurable: 1 - probability(capture, 'none'), confidence: capture.confidence ?? 0 } } : {}),
|
|
144
|
-
});
|
|
145
|
-
if (!blocked)
|
|
146
|
-
return fallback;
|
|
147
|
-
// Refused like a scanner hit: the guard reads `sensitive` and refuses the save. `redact` is a refusal too (nothing is altered).
|
|
148
|
-
const verdict = { task: 'capture_gate', decision: 'sensitive', confidence: 1 - pStore, latencyMs, costUSDCents };
|
|
149
|
-
return verdict;
|
|
150
|
-
}
|
|
151
|
-
catch (err) {
|
|
152
|
-
this.coolUntil = this.now() + this.cooldownMs;
|
|
153
|
-
const known = err instanceof JevFallback ? err : null;
|
|
154
|
-
this.record({
|
|
155
|
-
outcome: 'fallback', reason: known?.reason ?? 'error', ...(known?.status !== undefined ? { status: known.status } : {}),
|
|
156
|
-
latencyMs: this.now() - started, inputTokens: 0, chars: text.length,
|
|
157
|
-
});
|
|
158
|
-
return fallback;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
async call(text) {
|
|
162
|
-
let res;
|
|
163
|
-
try {
|
|
164
|
-
res = await (this.opts.fetchImpl ?? fetch)(`${this.baseUrl}/v1/systemone`, {
|
|
165
|
-
method: 'POST',
|
|
166
|
-
headers: { 'content-type': 'application/json', authorization: `Bearer ${this.opts.apiKey}` },
|
|
167
|
-
body: JSON.stringify({ model: exports.JEV_MODEL, state: text, questions: { sensitivity: SENSITIVITY_QUESTION, capture_gate: CAPTURE_QUESTION } }),
|
|
168
|
-
signal: AbortSignal.timeout(this.timeoutMs),
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
catch (err) {
|
|
172
|
-
const name = err instanceof Error ? err.name : '';
|
|
173
|
-
throw new JevFallback(name === 'TimeoutError' || name === 'AbortError' ? 'timeout' : 'error');
|
|
174
|
-
}
|
|
175
|
-
if (!res.ok)
|
|
176
|
-
throw new JevFallback('http', res.status);
|
|
177
|
-
let json;
|
|
178
|
-
try {
|
|
179
|
-
json = (await res.json());
|
|
180
|
-
}
|
|
181
|
-
catch (err) {
|
|
182
|
-
const name = err instanceof Error ? err.name : '';
|
|
183
|
-
throw new JevFallback(name === 'TimeoutError' || name === 'AbortError' ? 'timeout' : 'bad_reply');
|
|
184
|
-
}
|
|
185
|
-
if (!json || typeof json.answers !== 'object' || json.answers === null)
|
|
186
|
-
throw new JevFallback('bad_reply');
|
|
187
|
-
return { answers: json.answers, inputTokens: Number.isFinite(json.usage?.input_tokens) ? Number(json.usage?.input_tokens) : 0 };
|
|
188
|
-
}
|
|
189
|
-
canRecord() {
|
|
190
|
-
try {
|
|
191
|
-
return this.opts.canRecord() === true;
|
|
192
|
-
}
|
|
193
|
-
catch {
|
|
194
|
-
return false;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
record(partial) {
|
|
198
|
-
try {
|
|
199
|
-
this.opts.record({
|
|
200
|
-
v: 1, at: new Date(this.now()).toISOString(), workspace: this.opts.workspace, task: 'save_screen', costUSDCents: 0, ...partial,
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
catch { /* a log that cannot be written never costs a save */ }
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
exports.JevDecisionModel = JevDecisionModel;
|
|
207
|
-
const toldOff = new Set();
|
|
208
|
-
/** null when the workspace has not opted in or the setting cannot be honoured; says why on stderr, never a value. */
|
|
209
|
-
function resolveJevOptin(env = process.env) {
|
|
210
|
-
const workspace = (env.RENOR_JEV_OPTIN ?? '').trim().toLowerCase();
|
|
211
|
-
if (workspace === '')
|
|
212
|
-
return null;
|
|
213
|
-
const off = (why) => {
|
|
214
|
-
if (!toldOff.has(why)) {
|
|
215
|
-
toldOff.add(why);
|
|
216
|
-
process.stderr.write(`[jev] RENOR_JEV_OPTIN is set but ${why}: the save screen stays off\n`);
|
|
217
|
-
}
|
|
218
|
-
return null;
|
|
219
|
-
};
|
|
220
|
-
if ((env.MVP_INSTANCE_ID ?? '').trim().toLowerCase() !== workspace)
|
|
221
|
-
return off('it does not name this workspace (MVP_INSTANCE_ID)');
|
|
222
|
-
const keyFile = (env.RENOR_JEV_KEY_FILE ?? '').trim();
|
|
223
|
-
if (!node_path_1.default.isAbsolute(keyFile))
|
|
224
|
-
return off('RENOR_JEV_KEY_FILE is not an absolute path');
|
|
225
|
-
const memoryDir = (env.MVP_MEMORY_DIR ?? '').trim();
|
|
226
|
-
if (!node_path_1.default.isAbsolute(memoryDir))
|
|
227
|
-
return off('MVP_MEMORY_DIR is not an absolute path, so decisions could not be recorded');
|
|
228
|
-
return { workspace, keyFile, memoryDir };
|
|
229
|
-
}
|
|
230
|
-
/** The key in the file: one token. Null (with one stderr line naming the path, never the content) when it cannot be used. */
|
|
231
|
-
function readJevKey(keyFile) {
|
|
232
|
-
try {
|
|
233
|
-
const st = node_fs_1.default.statSync(keyFile);
|
|
234
|
-
if (!st.isFile())
|
|
235
|
-
throw new Error('not a regular file');
|
|
236
|
-
// A service credential readable by anyone but its owner is not used (the contract: mode 0600, the tenant's account only).
|
|
237
|
-
if ((st.mode & 0o077) !== 0)
|
|
238
|
-
throw new Error('readable or writable by group or others; chmod 600 it');
|
|
239
|
-
if (typeof process.getuid === 'function' && st.uid !== process.getuid())
|
|
240
|
-
throw new Error('not owned by this account');
|
|
241
|
-
const key = node_fs_1.default.readFileSync(keyFile, 'utf8').trim();
|
|
242
|
-
if (key === '' || /\s/.test(key))
|
|
243
|
-
throw new Error('empty or not a single token');
|
|
244
|
-
return key;
|
|
245
|
-
}
|
|
246
|
-
catch (err) {
|
|
247
|
-
process.stderr.write(`[jev] the key file ${keyFile} cannot be used (${err instanceof Error ? err.message.replace(keyFile, 'it') : 'unreadable'}): the save screen stays off\n`);
|
|
248
|
-
return null;
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
/** Where a workspace's Jev decisions are kept: beside its index, which the walker, the watcher and release packing already skip. */
|
|
252
|
-
function jevDecisionLogPath(memoryDir) {
|
|
253
|
-
return node_path_1.default.join(node_path_1.default.resolve(memoryDir), '.memory-index', 'jev-decisions.jsonl');
|
|
254
|
-
}
|
|
255
|
-
/**
|
|
256
|
-
* One JSON line per call, owner-only. `ready` opens the log for append before any text is sent, so a log that cannot be
|
|
257
|
-
* written turns the screen off for that save (Jev is not asked; the local rules decide). Told once on stderr; never reaches the save.
|
|
258
|
-
*/
|
|
259
|
-
function jevDecisionLog(memoryDir) {
|
|
260
|
-
const file = jevDecisionLogPath(memoryDir);
|
|
261
|
-
let told = false;
|
|
262
|
-
const tell = (err) => {
|
|
263
|
-
if (told)
|
|
264
|
-
return;
|
|
265
|
-
told = true;
|
|
266
|
-
process.stderr.write(`[jev] a decision could not be recorded (${err instanceof Error ? err.name : 'error'}): Jev is not asked, saves go on\n`);
|
|
267
|
-
};
|
|
268
|
-
return {
|
|
269
|
-
ready: () => {
|
|
270
|
-
try {
|
|
271
|
-
node_fs_1.default.mkdirSync(node_path_1.default.dirname(file), { recursive: true, mode: 0o700 });
|
|
272
|
-
node_fs_1.default.closeSync(node_fs_1.default.openSync(file, 'a', 0o600));
|
|
273
|
-
return true;
|
|
274
|
-
}
|
|
275
|
-
catch (err) {
|
|
276
|
-
tell(err);
|
|
277
|
-
return false;
|
|
278
|
-
}
|
|
279
|
-
},
|
|
280
|
-
write: entry => {
|
|
281
|
-
try {
|
|
282
|
-
node_fs_1.default.appendFileSync(file, `${JSON.stringify(entry)}\n`, { mode: 0o600 });
|
|
283
|
-
}
|
|
284
|
-
catch (err) {
|
|
285
|
-
tell(err);
|
|
286
|
-
}
|
|
287
|
-
},
|
|
288
|
-
};
|
|
289
|
-
}
|
|
290
|
-
let cached;
|
|
291
|
-
/**
|
|
292
|
-
* The model the save path uses, or null (the common case) when this workspace has not opted in. One instance per process, so
|
|
293
|
-
* its cool-down is shared by every save; rebuilt only when the settings change.
|
|
294
|
-
*/
|
|
295
|
-
function saveDecisionModel(env = process.env) {
|
|
296
|
-
const optin = resolveJevOptin(env);
|
|
297
|
-
if (!optin)
|
|
298
|
-
return null;
|
|
299
|
-
const signature = `${optin.workspace}\0${optin.keyFile}\0${optin.memoryDir}`;
|
|
300
|
-
if (cached?.signature === signature)
|
|
301
|
-
return cached.model;
|
|
302
|
-
const key = readJevKey(optin.keyFile);
|
|
303
|
-
const log = jevDecisionLog(optin.memoryDir);
|
|
304
|
-
const model = key ? new JevDecisionModel({ workspace: optin.workspace, apiKey: key, record: log.write, canRecord: log.ready }) : null;
|
|
305
|
-
cached = { signature, model };
|
|
306
|
-
return model;
|
|
307
|
-
}
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PREFS_EXTRACTION_VERSION = exports.PREFS_MODEL = exports.repairMalformedUnicodeEscapes = exports.stripExtractorCodeFence = exports.ExtractorParseError = void 0;
|
|
4
|
-
exports.prefsEnabled = prefsEnabled;
|
|
5
|
-
exports.looksLikeOneOff = looksLikeOneOff;
|
|
6
|
-
exports.extractPreferences = extractPreferences;
|
|
7
|
-
exports.extractPreferencesWithRetry = extractPreferencesWithRetry;
|
|
8
|
-
const typedFacts_1 = require("./typedFacts");
|
|
9
|
-
Object.defineProperty(exports, "ExtractorParseError", { enumerable: true, get: function () { return typedFacts_1.ExtractorParseError; } });
|
|
10
|
-
Object.defineProperty(exports, "stripExtractorCodeFence", { enumerable: true, get: function () { return typedFacts_1.stripExtractorCodeFence; } });
|
|
11
|
-
Object.defineProperty(exports, "repairMalformedUnicodeEscapes", { enumerable: true, get: function () { return typedFacts_1.repairMalformedUnicodeEscapes; } });
|
|
12
|
-
/**
|
|
13
|
-
* C4 standing-preference extraction (HYP-20260921-prefs-extraction, ADR-0003
|
|
14
|
-
* §4 payload schema for the preference lane). v1 schema only — statement,
|
|
15
|
-
* kind — frozen prompt + model. `kind` is an UNVALIDATED RENDER-ONLY enum
|
|
16
|
-
* (N12 KILL: taxonomy reliability is extractor-limited — never gate behavior
|
|
17
|
-
* on it); it is NOT part of the dedupe key (norm(statement) is).
|
|
18
|
-
*
|
|
19
|
-
* Standing-vs-one-off is NOT prompt-only: the extractor prompt instructs the
|
|
20
|
-
* model to reject one-off events, and a code-level structural guard
|
|
21
|
-
* (`looksLikeOneOff`) drops extracted rows whose statement carries past-tense
|
|
22
|
-
* one-off markers ("yesterday", "last <day>", "-ed <unit> ago", …). The
|
|
23
|
-
* synthetic fixture enforces this both ways: "I always run Tuesdays" survives;
|
|
24
|
-
* "I ran 5km yesterday" is rejected even when the model (stub) emits it.
|
|
25
|
-
*
|
|
26
|
-
* Ledger KILLs bound this module: N12/N14/N16b/N20/N25 (no prompt iteration
|
|
27
|
-
* beyond v1), H5 (one-pass multi-head KILL — this extracts preferences only),
|
|
28
|
-
* H6 (yield-prefilter KILL, skip ceiling 43.0% — the hash-keyed skip is the
|
|
29
|
-
* only cost control), N15 (cap-80 KILL — selection is retrieval-scoped in the
|
|
30
|
-
* composer, never a bigger cap). Parse failures are EXPLICIT
|
|
31
|
-
* extractor-parse-errors, retried ≤3 times, never silently `[]`, and never
|
|
32
|
-
* cached (pipeline resets the note hash so the next pass retries).
|
|
33
|
-
*/
|
|
34
|
-
exports.PREFS_MODEL = 'gemma4:31b';
|
|
35
|
-
/** extraction_version = schema:model (ADR §4): hash-keyed cache key component. */
|
|
36
|
-
exports.PREFS_EXTRACTION_VERSION = `prefs-v1:${exports.PREFS_MODEL}`;
|
|
37
|
-
/** RENOR_PREFS (default OFF). Opt in with 1/true/yes/on. No default flip. */
|
|
38
|
-
function prefsEnabled(env = process.env) {
|
|
39
|
-
const raw = (env.RENOR_PREFS ?? '').trim().toLowerCase();
|
|
40
|
-
return raw === '1' || raw === 'true' || raw === 'yes' || raw === 'on';
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Structural guard for the standing-vs-one-off fixture (must not rely on the
|
|
44
|
-
* prompt alone): a statement that describes a completed past-tense one-off
|
|
45
|
-
* action is NOT a standing preference, even if the extractor emitted it.
|
|
46
|
-
* Dataset-free — anchored on explicit temporal one-off markers only, never on
|
|
47
|
-
* topic words (a standing rule about running Tuesdays must survive).
|
|
48
|
-
*/
|
|
49
|
-
function looksLikeOneOff(statement) {
|
|
50
|
-
const s = statement.toLowerCase();
|
|
51
|
-
const markers = [
|
|
52
|
-
/\byesterday\b/,
|
|
53
|
-
/\blast (night|week|month|year|monday|tuesday|wednesday|thursday|friday|saturday|sunday)\b/,
|
|
54
|
-
/\bthis (morning|afternoon|evening)\b/,
|
|
55
|
-
/\b(earlier|ago)\b/,
|
|
56
|
-
/\bjust (ran|did|finished|completed|bought|met|visited|attended|started|watched)\b/,
|
|
57
|
-
/\b(i|we|he|she|they) (ran|walked|went|did|finished|completed|bought|met|visited|attended|watched|ate|drank|had) (yesterday|this morning|last )/,
|
|
58
|
-
/\b(had|have) (just|already) /,
|
|
59
|
-
];
|
|
60
|
-
return markers.some((re) => re.test(s));
|
|
61
|
-
}
|
|
62
|
-
const SYSTEM_PROMPT = `Extract STANDING PREFERENCES, CONSTRAINTS and durable PROFILE FACTS the USER asserts about themselves. Return STRICT JSON only — no YAML, no markdown code fences, no commentary.
|
|
63
|
-
|
|
64
|
-
Shape: {"prefs": [{"statement": "<first-person-compatible standing rule>", "kind": "like" | "dislike" | "policy" | "attribute"}]}
|
|
65
|
-
|
|
66
|
-
Rules:
|
|
67
|
-
- statement: durable rule or attribute as the user would say it (likes/dislikes, aversions, dietary restrictions, allergies, style/communication/tool preferences, standing policies like "I never...", "I always...", "I prefer... over...", durable personal attributes like job, family, pets, home, skills)
|
|
68
|
-
- kind: one of like, dislike, policy, attribute (best guess; never leave empty)
|
|
69
|
-
- STANDING only: what is persistently true or desired — NOT one-off events ("I ran 5km yesterday" is an event, "I always run Tuesdays" is a preference), NOT questions, NOT assistant suggestions, NOT hypotheticals
|
|
70
|
-
- Only preferences the USER asserted — first-person-compatible
|
|
71
|
-
- Each distinct preference ONCE. Extract 0-15 preferences.
|
|
72
|
-
- Do NOT extract from frontmatter metadata.`;
|
|
73
|
-
async function extractPreferences(client, noteTitle, noteBody) {
|
|
74
|
-
// Truncate body to keep the prompt bounded (same budget as the other lanes).
|
|
75
|
-
const body = noteBody.substring(0, 3000);
|
|
76
|
-
const response = await client.chat.completions.create({
|
|
77
|
-
model: exports.PREFS_MODEL,
|
|
78
|
-
temperature: 0,
|
|
79
|
-
response_format: { type: 'json_object' },
|
|
80
|
-
messages: [
|
|
81
|
-
{ role: 'system', content: SYSTEM_PROMPT },
|
|
82
|
-
{ role: 'user', content: `Note: "${noteTitle}"\n\n${body}` },
|
|
83
|
-
],
|
|
84
|
-
});
|
|
85
|
-
const content = response.choices?.[0]?.message?.content;
|
|
86
|
-
if (!content || !content.trim()) {
|
|
87
|
-
throw new typedFacts_1.ExtractorParseError('extractor-parse-error: preference extraction returned empty content');
|
|
88
|
-
}
|
|
89
|
-
// JSON-strict after fence-strip: a fenced or bare response parses; YAML,
|
|
90
|
-
// truncated JSON, or commentary still fails hard as an explicit parse error.
|
|
91
|
-
let parsed;
|
|
92
|
-
try {
|
|
93
|
-
parsed = JSON.parse((0, typedFacts_1.repairMalformedUnicodeEscapes)((0, typedFacts_1.stripExtractorCodeFence)(content)));
|
|
94
|
-
}
|
|
95
|
-
catch {
|
|
96
|
-
throw new typedFacts_1.ExtractorParseError(`extractor-parse-error: preference extraction returned non-JSON response (head: ${content.slice(0, 80)})`);
|
|
97
|
-
}
|
|
98
|
-
if (Array.isArray(parsed)) {
|
|
99
|
-
// Schema-drift tolerance: some gemma4 responses emit the bare prefs array
|
|
100
|
-
// without the {"prefs": ...} wrapper. Valid JSON either way; strict on shape.
|
|
101
|
-
parsed.prefs = parsed;
|
|
102
|
-
}
|
|
103
|
-
else if (parsed && typeof parsed === 'object' && !Array.isArray(parsed.prefs)) {
|
|
104
|
-
// Wrapper-key drift: gemma4 sometimes renames the wrapper key (e.g.
|
|
105
|
-
// "merchants") or emits a single object. Rows without a non-empty
|
|
106
|
-
// `statement` are dropped below, so mis-shaped rows can never become false
|
|
107
|
-
// preferences — empty is the worst case.
|
|
108
|
-
const firstArray = Object.values(parsed).find((v) => Array.isArray(v) && v.length > 0 && typeof v[0] === 'object' && v[0] !== null);
|
|
109
|
-
parsed.prefs = firstArray ?? [parsed];
|
|
110
|
-
}
|
|
111
|
-
if (!parsed || typeof parsed !== 'object' || !Array.isArray(parsed.prefs)) {
|
|
112
|
-
throw new typedFacts_1.ExtractorParseError('extractor-parse-error: preference extraction response is missing a prefs array');
|
|
113
|
-
}
|
|
114
|
-
const prefs = [];
|
|
115
|
-
for (const raw of parsed.prefs) {
|
|
116
|
-
const statement = raw?.statement === undefined || raw?.statement === null ? '' : String(raw.statement).trim();
|
|
117
|
-
if (!statement)
|
|
118
|
-
continue; // malformed rows are dropped, not fatal
|
|
119
|
-
// Structural standing-vs-one-off guard: one-off past-tense events are
|
|
120
|
-
// rejected HERE, not just in the prompt (synthetic-fixture contract).
|
|
121
|
-
if (looksLikeOneOff(statement))
|
|
122
|
-
continue;
|
|
123
|
-
const pref = { statement };
|
|
124
|
-
const kind = raw?.kind;
|
|
125
|
-
if (kind !== undefined && kind !== null && String(kind).trim()) {
|
|
126
|
-
pref.kind = String(kind).trim(); // unvalidated render-only enum (N12)
|
|
127
|
-
}
|
|
128
|
-
prefs.push(pref);
|
|
129
|
-
}
|
|
130
|
-
return prefs;
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Retry wrapper: parse failures are retried up to MAX_EXTRACT_ATTEMPTS total;
|
|
134
|
-
* the final failure is rethrown explicitly (never cached, never silent []).
|
|
135
|
-
* Non-parse errors (network, auth) propagate immediately.
|
|
136
|
-
*/
|
|
137
|
-
async function extractPreferencesWithRetry(extract, noteTitle, noteBody) {
|
|
138
|
-
let lastError;
|
|
139
|
-
for (let attempt = 1; attempt <= typedFacts_1.MAX_EXTRACT_ATTEMPTS; attempt++) {
|
|
140
|
-
try {
|
|
141
|
-
return await extract(noteTitle, noteBody);
|
|
142
|
-
}
|
|
143
|
-
catch (err) {
|
|
144
|
-
if (!(err instanceof typedFacts_1.ExtractorParseError))
|
|
145
|
-
throw err;
|
|
146
|
-
lastError = err;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
throw lastError;
|
|
150
|
-
}
|
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SecretRefusedError = exports.SecretGuardDecisionModel = void 0;
|
|
4
|
-
exports.secretGuardEnabled = secretGuardEnabled;
|
|
5
|
-
exports.refuseUnchecked = refuseUnchecked;
|
|
6
|
-
exports.assertStorable = assertStorable;
|
|
7
|
-
exports.findSensitive = findSensitive;
|
|
8
|
-
exports.logSkip = logSkip;
|
|
9
|
-
/**
|
|
10
|
-
* The write-path secret guard: tier 0 of the sensitivity guardrail
|
|
11
|
-
* (docs/evals/results/SECRET-GUARD-TIER0-20261003.md).
|
|
12
|
-
*
|
|
13
|
-
* Behind RENOR_SECRET_GUARD, default ON (secretGuardEnabled). Every path that writes text into memory screens
|
|
14
|
-
* it with the deterministic scanner first, before anything is written:
|
|
15
|
-
*
|
|
16
|
-
* save `remember` (both modes), `save_memory`, the daily-note writer, the conversation logger:
|
|
17
|
-
* the whole save is refused. Nothing is stored, redacted or altered, so a save that
|
|
18
|
-
* succeeds is still a save that stored every character it was given.
|
|
19
|
-
* import a note or fact in an import plan is left out with its reason, and a plan that still holds
|
|
20
|
-
* one is refused whole (src/importing/secretScreen.ts).
|
|
21
|
-
* retire a memory whose text is flagged is not retired, because retiring copies its text into the
|
|
22
|
-
* retired-memory journal; restore is refused the same way, because it puts the text back
|
|
23
|
-
* into live memory (src/memorymap/memoryMap.ts).
|
|
24
|
-
*
|
|
25
|
-
* With it off (RENOR_SECRET_GUARD=0, false, no or off), nothing here runs on any of those paths.
|
|
26
|
-
*
|
|
27
|
-
* The guard is a DecisionModel, so the write path asks the same `capture_gate` question the indexer
|
|
28
|
-
* asks and refuses on `sensitive`. A model's second opinion, if one is ever approved, composes behind
|
|
29
|
-
* the scanner here, and a scanner `sensitive` stays final.
|
|
30
|
-
*
|
|
31
|
-
* It decides whether text may be STORED. It cannot stop text from reaching the server, and it does not
|
|
32
|
-
* look at what is already stored.
|
|
33
|
-
*/
|
|
34
|
-
const decision_model_1 = require("./decision-model");
|
|
35
|
-
const secretScanner_1 = require("./secretScanner");
|
|
36
|
-
/**
|
|
37
|
-
* RENOR_SECRET_GUARD (default ON, decided 2026-10-12). Off only when set to 0, false, no or off (any case). Unset, empty
|
|
38
|
-
* and any other value keep it on: a value the guard does not recognise must not switch the screen off.
|
|
39
|
-
*/
|
|
40
|
-
function secretGuardEnabled(env = process.env) {
|
|
41
|
-
const raw = (env.RENOR_SECRET_GUARD ?? '').trim().toLowerCase();
|
|
42
|
-
return !(raw === '0' || raw === 'false' || raw === 'no' || raw === 'off');
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Answers the capture gate from the scanner alone: text it flags is `sensitive`, and everything else
|
|
46
|
-
* (all other text, and every dedupe question) is the inner model's, so the guard changes no other decision.
|
|
47
|
-
*/
|
|
48
|
-
class SecretGuardDecisionModel {
|
|
49
|
-
inner;
|
|
50
|
-
constructor(inner = (0, decision_model_1.defaultDecisionModel)()) {
|
|
51
|
-
this.inner = inner;
|
|
52
|
-
}
|
|
53
|
-
async decide(request) {
|
|
54
|
-
if (request.task !== 'capture_gate')
|
|
55
|
-
return this.inner.decide(request);
|
|
56
|
-
const started = Date.now();
|
|
57
|
-
const finding = (0, secretScanner_1.scanSecrets)(request.text);
|
|
58
|
-
if (finding === null)
|
|
59
|
-
return this.inner.decide(request);
|
|
60
|
-
const verdict = {
|
|
61
|
-
task: 'capture_gate',
|
|
62
|
-
decision: 'sensitive',
|
|
63
|
-
confidence: 1,
|
|
64
|
-
latencyMs: Date.now() - started,
|
|
65
|
-
costUSDCents: 0,
|
|
66
|
-
finding,
|
|
67
|
-
};
|
|
68
|
-
return verdict;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
exports.SecretGuardDecisionModel = SecretGuardDecisionModel;
|
|
72
|
-
const APPEARS_TO_CONTAIN = {
|
|
73
|
-
credential: 'a credential (an API key, token, password, PIN or private key)',
|
|
74
|
-
identifier: 'a personal identifier (a payment card, government ID or phone number)',
|
|
75
|
-
sensitive: 'a credential or personal identifier',
|
|
76
|
-
};
|
|
77
|
-
/**
|
|
78
|
-
* What the caller is told. It names the field and the kind of thing found from fixed text, never the
|
|
79
|
-
* text itself, and says what to do next. Kept under the 400 characters the MCP error reply keeps.
|
|
80
|
-
*/
|
|
81
|
-
function refusalMessage(field, reason, action) {
|
|
82
|
-
const lead = action === 'save' ? 'Nothing was saved' : 'Nothing was changed';
|
|
83
|
-
if (reason === 'unavailable') {
|
|
84
|
-
return `${lead}: the secret guard (RENOR_SECRET_GUARD) is on but could not check the ${field}, so it refuses by default. `
|
|
85
|
-
+ 'Try again, and tell the user if it keeps happening.';
|
|
86
|
-
}
|
|
87
|
-
if (action === 'retire') {
|
|
88
|
-
return `${lead}: the ${field} appears to contain ${APPEARS_TO_CONTAIN[reason]}, and the secret guard (RENOR_SECRET_GUARD) is on, `
|
|
89
|
-
+ 'so this memory was not retired: retiring copies its text into the retired-memory journal. It stays as it is. '
|
|
90
|
-
+ 'Remove it with the data-deletion procedure, or ask the owner to switch the guard off first.';
|
|
91
|
-
}
|
|
92
|
-
if (action === 'restore') {
|
|
93
|
-
return `${lead}: the ${field} appears to contain ${APPEARS_TO_CONTAIN[reason]}, and the secret guard (RENOR_SECRET_GUARD) is on, `
|
|
94
|
-
+ 'so this memory was not restored: restoring would put its text back into live memory. It stays retired.';
|
|
95
|
-
}
|
|
96
|
-
return `${lead}: the ${field} appears to contain ${APPEARS_TO_CONTAIN[reason]}, and the secret guard (RENOR_SECRET_GUARD) is on, `
|
|
97
|
-
+ 'so Renor does not store it. Save what it is for instead (for example "the staging API key is in 1Password"), '
|
|
98
|
-
+ 'or reword the text without the value, then save again.';
|
|
99
|
-
}
|
|
100
|
-
/** The operation was refused: nothing was written or moved. `reason` is what was found, or `unavailable` when the guard could not decide. */
|
|
101
|
-
class SecretRefusedError extends Error {
|
|
102
|
-
field;
|
|
103
|
-
reason;
|
|
104
|
-
action;
|
|
105
|
-
constructor(field, reason, action = 'save') {
|
|
106
|
-
super(refusalMessage(field, reason, action));
|
|
107
|
-
this.name = 'SecretRefusedError';
|
|
108
|
-
this.field = field;
|
|
109
|
-
this.reason = reason;
|
|
110
|
-
this.action = action;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
exports.SecretRefusedError = SecretRefusedError;
|
|
114
|
-
/**
|
|
115
|
-
* One line for whoever runs the service, in the same JSON shape as its access log: what was refused and why,
|
|
116
|
-
* never what it said. It is how an operator sees what the guard is refusing.
|
|
117
|
-
*/
|
|
118
|
-
function logRefusal(field, reason, action, cause) {
|
|
119
|
-
console.warn(JSON.stringify({
|
|
120
|
-
ts: new Date().toISOString(), event: 'secret_guard_refusal', action, field, reason,
|
|
121
|
-
...(cause instanceof Error ? { error: cause.name } : {}),
|
|
122
|
-
}));
|
|
123
|
-
}
|
|
124
|
-
function refuse(field, reason, action, cause) {
|
|
125
|
-
logRefusal(field, reason, action, cause);
|
|
126
|
-
throw new SecretRefusedError(field, reason, action);
|
|
127
|
-
}
|
|
128
|
-
/** For a text the guard cannot read in full (too large to hold): refuse, as it does when its own check fails. */
|
|
129
|
-
function refuseUnchecked(field, action) {
|
|
130
|
-
return refuse(field, 'unavailable', action);
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Throws SecretRefusedError when the guard is on and any of `texts` is sensitive; resolves otherwise.
|
|
134
|
-
* It fails closed: if the check itself throws, the save is refused. Call it before the first write.
|
|
135
|
-
* `contentModel`, when a save path passes one, only adds a second opinion on the texts that are not `nameOnly`.
|
|
136
|
-
* With the guard off it returns at once, so callers that must not add a step to the unguarded path
|
|
137
|
-
* check `secretGuardEnabled()` first and skip the call.
|
|
138
|
-
*/
|
|
139
|
-
async function assertStorable(texts, action = 'save', contentModel = null) {
|
|
140
|
-
if (!secretGuardEnabled())
|
|
141
|
-
return;
|
|
142
|
-
const model = new SecretGuardDecisionModel();
|
|
143
|
-
// A second opinion on content only (jevDecisionModel.ts, one opted-in workspace's saves): the scanner still answers first
|
|
144
|
-
// and a scanner `sensitive` is final, because SecretGuardDecisionModel asks the inner model only about text it did not flag.
|
|
145
|
-
const withContentModel = contentModel ? new SecretGuardDecisionModel(contentModel) : model;
|
|
146
|
-
for (const { field, text, nameOnly } of texts) {
|
|
147
|
-
if (text === undefined || text === '')
|
|
148
|
-
continue;
|
|
149
|
-
let verdict;
|
|
150
|
-
try {
|
|
151
|
-
verdict = await (nameOnly ? model : withContentModel).decide({ task: 'capture_gate', text });
|
|
152
|
-
}
|
|
153
|
-
catch (cause) {
|
|
154
|
-
refuse(field, 'unavailable', action, cause);
|
|
155
|
-
}
|
|
156
|
-
if (verdict.decision === 'sensitive') {
|
|
157
|
-
refuse(field, verdict.finding?.class ?? 'sensitive', action);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* The first of `texts` that looks like a secret, or null: the same scanner as `assertStorable`, answered at
|
|
163
|
-
* once and without the DecisionModel, for the bulk paths that screen thousands of texts in synchronous code
|
|
164
|
-
* (an import plan) and decide per item. Independent of the switch: callers check `secretGuardEnabled()`.
|
|
165
|
-
* If the scan throws, the exception propagates, so a plan that cannot be screened is not built or applied.
|
|
166
|
-
*/
|
|
167
|
-
function findSensitive(texts) {
|
|
168
|
-
for (const { field, text } of texts) {
|
|
169
|
-
if (text === undefined || text === '')
|
|
170
|
-
continue;
|
|
171
|
-
const finding = (0, secretScanner_1.scanSecrets)(text);
|
|
172
|
-
if (finding !== null)
|
|
173
|
-
return { field, reason: finding.class };
|
|
174
|
-
}
|
|
175
|
-
return null;
|
|
176
|
-
}
|
|
177
|
-
/** One log line for a text a bulk path left out (same shape as a refusal), so an operator sees what the guard skipped. */
|
|
178
|
-
function logSkip(field, reason) {
|
|
179
|
-
logRefusal(field, reason, 'import');
|
|
180
|
-
}
|