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/learning/tap.js
DELETED
|
@@ -1,401 +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.learningObserver = learningObserver;
|
|
7
|
-
const buildIdentity_1 = require("../buildIdentity");
|
|
8
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
-
const agentMemory_1 = require("../mvp/agentMemory");
|
|
10
|
-
const scope_1 = require("../mvp/scope");
|
|
11
|
-
const rankingTrace_1 = require("../retrieval/rankingTrace");
|
|
12
|
-
const schema_1 = require("./schema");
|
|
13
|
-
const store_1 = require("./store");
|
|
14
|
-
const RETRIEVAL_MODES = ['facts', 'hybrid', 'semantic', 'keyword'];
|
|
15
|
-
// A lane string: lane names joined by '+' (semantic+content+recency). Closed vocabulary from the product's own labels.
|
|
16
|
-
const REASON = /^[a-z][a-z0-9+-]{0,127}$/;
|
|
17
|
-
const MODEL = /^[A-Za-z0-9._:/+-]{1,120}$/;
|
|
18
|
-
const COMMIT = /^[0-9a-f]{7,40}$/;
|
|
19
|
-
const MAX_CITES = 20;
|
|
20
|
-
const norm = (value) => value.normalize('NFKC').toLowerCase().replace(/\s+/g, ' ').trim();
|
|
21
|
-
const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
22
|
-
const recordsOf = (value) => (Array.isArray(value) ? value.filter(isRecord) : []);
|
|
23
|
-
let build;
|
|
24
|
-
/** The commit of the running build, read once; null when the build is unstamped. */
|
|
25
|
-
function buildCommit() {
|
|
26
|
-
if (build === undefined) {
|
|
27
|
-
const commit = (0, buildIdentity_1.readBuildIdentity)().commit;
|
|
28
|
-
build = COMMIT.test(commit) ? commit : null;
|
|
29
|
-
}
|
|
30
|
-
return build;
|
|
31
|
-
}
|
|
32
|
-
/** The reply as the tool built it: its JSON body and the text it was sent as (the text is what the token budget counted). */
|
|
33
|
-
function replyOf(result) {
|
|
34
|
-
if (!isRecord(result))
|
|
35
|
-
return null;
|
|
36
|
-
const first = Array.isArray(result.content) ? result.content[0] : undefined;
|
|
37
|
-
const text = isRecord(first) && typeof first.text === 'string' ? first.text : null;
|
|
38
|
-
if (text !== null) {
|
|
39
|
-
try {
|
|
40
|
-
const parsed = JSON.parse(text);
|
|
41
|
-
return isRecord(parsed) ? { body: parsed, text } : null;
|
|
42
|
-
}
|
|
43
|
-
catch {
|
|
44
|
-
return null;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
if (isRecord(result.structuredContent)) {
|
|
48
|
-
return { body: result.structuredContent, text: JSON.stringify(result.structuredContent) };
|
|
49
|
-
}
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
/** The identity of a memory named by its id: `note:<path>`, `entry:<path>#<hash>` (its note) or `fact:<eventId>` (one fact's event). */
|
|
53
|
-
function identityOf(log, id) {
|
|
54
|
-
if (id.startsWith('note:'))
|
|
55
|
-
return { kind: 'note', memoryKey: log.key('note', id.slice(5)) };
|
|
56
|
-
if (id.startsWith('entry:')) {
|
|
57
|
-
const hashAt = id.lastIndexOf('#');
|
|
58
|
-
const notePath = hashAt > 6 ? id.slice(6, hashAt) : id.slice(6);
|
|
59
|
-
return { kind: 'note', memoryKey: log.key('note', notePath) };
|
|
60
|
-
}
|
|
61
|
-
if (id.startsWith('fact:'))
|
|
62
|
-
return { kind: 'event', memoryKey: log.key('event', id.slice(5)) };
|
|
63
|
-
return { kind: 'unkeyed', memoryKey: null };
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* A cite is a memory id (note:, entry: or fact:), a note's path, or a fact's subject: the save tools' own wording, and the same
|
|
67
|
-
* three forms readUsefulness.ts matches. A bare string with a path's shape is a note; any other bare string is a subject, and a
|
|
68
|
-
* subject is keyed within the scope of the save that names it, as a fact's subject is.
|
|
69
|
-
*/
|
|
70
|
-
function citeOf(log, cite, scope) {
|
|
71
|
-
const value = cite.trim();
|
|
72
|
-
if (value === '')
|
|
73
|
-
return { target: 'unkeyed', memoryKey: null, subjectKey: null };
|
|
74
|
-
if (value.startsWith('note:') || value.startsWith('entry:')) {
|
|
75
|
-
return { target: 'note', memoryKey: identityOf(log, value).memoryKey, subjectKey: null };
|
|
76
|
-
}
|
|
77
|
-
if (value.startsWith('fact:'))
|
|
78
|
-
return { target: 'event', memoryKey: identityOf(log, value).memoryKey, subjectKey: null };
|
|
79
|
-
if (/\.md$/i.test(value) || value.includes('/'))
|
|
80
|
-
return { target: 'note', memoryKey: log.key('note', value), subjectKey: null };
|
|
81
|
-
return { target: 'subject', memoryKey: null, subjectKey: log.key('subject', scope, norm(value)) };
|
|
82
|
-
}
|
|
83
|
-
/** A candidate with no ranker trace: the columns the ranker adds are null, and so are its positions and the budget's decision. */
|
|
84
|
-
const UNTRACED = { rank: null, base: null, terms: null, poolRank: null, windowPos: null, budgetKept: null };
|
|
85
|
-
/** A fact as a retrieval served it: the memory is the scope, subject and predicate; the subject alone joins a cite that names it. */
|
|
86
|
-
function factCandidate(log, subject, fact) {
|
|
87
|
-
const predicate = typeof fact.predicate === 'string' ? fact.predicate : null;
|
|
88
|
-
const scope = (0, scope_1.normalizeScope)(typeof fact.scope === 'string' ? fact.scope : 'global');
|
|
89
|
-
const current = typeof fact.current === 'boolean' ? fact.current : null;
|
|
90
|
-
if (typeof subject !== 'string' || predicate === null)
|
|
91
|
-
return unkeyed(null, null, current);
|
|
92
|
-
return {
|
|
93
|
-
...UNTRACED,
|
|
94
|
-
kind: 'fact',
|
|
95
|
-
memoryKey: log.key('fact', scope, norm(subject), norm(predicate)),
|
|
96
|
-
subjectKey: log.key('subject', scope, norm(subject)),
|
|
97
|
-
sectionKey: null,
|
|
98
|
-
score: null,
|
|
99
|
-
reason: 'fact',
|
|
100
|
-
matched: null,
|
|
101
|
-
current,
|
|
102
|
-
text: typeof fact.object === 'string' ? `${subject} ${predicate}: ${fact.object}` : null,
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
/** A note hit: its path is the memory, its heading path (when there is one) the section within it. */
|
|
106
|
-
function noteCandidate(log, hit) {
|
|
107
|
-
const notePath = typeof hit.notePath === 'string' && hit.notePath !== '' ? hit.notePath : null;
|
|
108
|
-
const headingPath = typeof hit.headingPath === 'string' && hit.headingPath !== '' ? hit.headingPath : null;
|
|
109
|
-
const score = typeof hit.score === 'number' && Number.isFinite(hit.score) ? hit.score : null;
|
|
110
|
-
const reason = typeof hit.reason === 'string' && REASON.test(hit.reason) ? hit.reason : null;
|
|
111
|
-
const matched = hit.matched === false ? false : null;
|
|
112
|
-
if (notePath === null)
|
|
113
|
-
return unkeyed(score, reason, null, matched);
|
|
114
|
-
return {
|
|
115
|
-
...UNTRACED,
|
|
116
|
-
kind: 'note',
|
|
117
|
-
memoryKey: log.key('note', notePath),
|
|
118
|
-
subjectKey: null,
|
|
119
|
-
sectionKey: headingPath === null ? null : log.key('section', notePath, headingPath),
|
|
120
|
-
score,
|
|
121
|
-
reason,
|
|
122
|
-
matched,
|
|
123
|
-
current: null,
|
|
124
|
-
text: typeof hit.text === 'string' ? hit.text : null,
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
function unkeyed(score, reason, current, matched = null) {
|
|
128
|
-
return { ...UNTRACED, kind: 'unkeyed', memoryKey: null, subjectKey: null, sectionKey: null, score, reason, matched, current };
|
|
129
|
-
}
|
|
130
|
-
/** The candidates a reply served, in the order it served them. Facts come first, as the reply lists them. */
|
|
131
|
-
function servedOf(log, tool, body) {
|
|
132
|
-
if (tool === 'retrieve_memory') {
|
|
133
|
-
return recordsOf(body.facts).map(fact => ({ record: factCandidate(log, body.subject, fact), traceKey: null, notePath: null, headingPath: null }));
|
|
134
|
-
}
|
|
135
|
-
const notes = (items) => items.map(item => ({
|
|
136
|
-
record: noteCandidate(log, item),
|
|
137
|
-
notePath: typeof item.notePath === 'string' ? item.notePath : null,
|
|
138
|
-
headingPath: typeof item.headingPath === 'string' ? item.headingPath : null,
|
|
139
|
-
traceKey: typeof item.notePath === 'string' && item.notePath !== '' && typeof item.text === 'string'
|
|
140
|
-
? (0, rankingTrace_1.traceKey)(item.notePath, typeof item.headingPath === 'string' ? item.headingPath : undefined, item.text)
|
|
141
|
-
: null,
|
|
142
|
-
}));
|
|
143
|
-
if (tool === 'get_context') {
|
|
144
|
-
return [
|
|
145
|
-
...recordsOf(body.facts).map(fact => ({ record: factCandidate(log, fact.subject, fact), traceKey: null, notePath: null, headingPath: null })),
|
|
146
|
-
...notes(recordsOf(body.memories)),
|
|
147
|
-
];
|
|
148
|
-
}
|
|
149
|
-
return notes(recordsOf(body.hits));
|
|
150
|
-
}
|
|
151
|
-
/** The ranker's record of a candidate, as the candidate row carries it. */
|
|
152
|
-
function tracedFields(entry) {
|
|
153
|
-
return { base: entry.base, terms: entry.terms, poolRank: entry.poolRank, windowPos: entry.windowPos, budgetKept: entry.budgetKept };
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* The rows of one retrieval: each served candidate at its rank, then every candidate the ranker scored or presented that the reply
|
|
157
|
-
* did not serve (rank null). A fact-lane hit (reason `fact`) is left out of the second group: a fact is recorded from its own row.
|
|
158
|
-
*/
|
|
159
|
-
function candidateRows(log, served, trace) {
|
|
160
|
-
const rows = [];
|
|
161
|
-
const servedKeys = new Set();
|
|
162
|
-
let servedNoteIndex = 0;
|
|
163
|
-
served.forEach((item, index) => {
|
|
164
|
-
if (item.traceKey !== null)
|
|
165
|
-
servedKeys.add(item.traceKey);
|
|
166
|
-
let entry = trace && item.traceKey !== null
|
|
167
|
-
? trace.byKey(item.traceKey) ?? (item.notePath === null ? undefined : trace.byLocation(item.notePath, item.headingPath))
|
|
168
|
-
: undefined;
|
|
169
|
-
if (!entry && trace && item.record.memoryKey !== null) {
|
|
170
|
-
const sameNote = trace.all().filter(candidate => candidate.notePath !== ''
|
|
171
|
-
&& log.key('note', candidate.notePath) === item.record.memoryKey);
|
|
172
|
-
if (sameNote.length === 1)
|
|
173
|
-
[entry] = sameNote;
|
|
174
|
-
}
|
|
175
|
-
if (!entry && trace && item.notePath !== null) {
|
|
176
|
-
const shownFile = node_path_1.default.basename(item.notePath);
|
|
177
|
-
const sameFile = trace.all().filter(candidate => node_path_1.default.basename(candidate.notePath) === shownFile);
|
|
178
|
-
if (sameFile.length === 1)
|
|
179
|
-
[entry] = sameFile;
|
|
180
|
-
}
|
|
181
|
-
if (entry?.budgetKept === null && trace?.all().some(candidate => candidate.budgetKept !== null))
|
|
182
|
-
entry = undefined;
|
|
183
|
-
if (!entry && trace && item.notePath !== null) {
|
|
184
|
-
const hasBudget = trace.all().some(candidate => candidate.budgetKept !== null);
|
|
185
|
-
entry = trace.all()
|
|
186
|
-
.filter(candidate => hasBudget ? candidate.budgetKept === true : candidate.windowPos !== null)
|
|
187
|
-
.sort((a, b) => a.windowPos - b.windowPos)[servedNoteIndex];
|
|
188
|
-
}
|
|
189
|
-
if (item.notePath !== null)
|
|
190
|
-
servedNoteIndex++;
|
|
191
|
-
if (entry)
|
|
192
|
-
servedKeys.add(entry.key);
|
|
193
|
-
rows.push({ ...item.record, rank: index + 1, ...(entry ? tracedFields(entry) : {}) });
|
|
194
|
-
});
|
|
195
|
-
if (trace) {
|
|
196
|
-
for (const entry of trace.all()) {
|
|
197
|
-
if (servedKeys.has(entry.key) || entry.reason === 'fact')
|
|
198
|
-
continue;
|
|
199
|
-
const score = entry.base + entry.terms.reduce((sum, term) => sum + term, 0);
|
|
200
|
-
rows.push({
|
|
201
|
-
...tracedFields(entry),
|
|
202
|
-
rank: null,
|
|
203
|
-
kind: entry.notePath === '' ? 'unkeyed' : 'note',
|
|
204
|
-
memoryKey: entry.notePath === '' ? null : log.key('note', entry.notePath),
|
|
205
|
-
subjectKey: null,
|
|
206
|
-
sectionKey: entry.notePath !== '' && entry.headingPath !== null ? log.key('section', entry.notePath, entry.headingPath) : null,
|
|
207
|
-
score,
|
|
208
|
-
reason: REASON.test(entry.reason) ? entry.reason : null,
|
|
209
|
-
matched: null,
|
|
210
|
-
current: null,
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
return rows;
|
|
215
|
-
}
|
|
216
|
-
function recordRetrieval(log, ctx, base, args, reply, ms, trace) {
|
|
217
|
-
const query = typeof args.query === 'string' && args.query.trim() !== '' ? args.query : null;
|
|
218
|
-
const relevance = isRecord(reply.body.relevance) ? reply.body.relevance : null;
|
|
219
|
-
const model = ctx.model();
|
|
220
|
-
const candidates = candidateRows(log, servedOf(log, base.tool, reply.body), trace);
|
|
221
|
-
log.recordRetrieval({
|
|
222
|
-
tool: base.tool,
|
|
223
|
-
actor: base.actor,
|
|
224
|
-
sessionKey: base.sessionKey,
|
|
225
|
-
agentKey: base.agentKey,
|
|
226
|
-
queryKey: query === null ? null : log.key('query', norm(query)),
|
|
227
|
-
// The store keeps this only when the log was opened with rawQueries and the secret scanner passes it (store.ts).
|
|
228
|
-
queryText: query,
|
|
229
|
-
queryRedacted: false,
|
|
230
|
-
scopeKey: log.key('scope', (0, scope_1.normalizeScope)(typeof args.scope === 'string' ? args.scope : undefined)),
|
|
231
|
-
retrieval: typeof reply.body.retrieval === 'string' && RETRIEVAL_MODES.includes(reply.body.retrieval) ? reply.body.retrieval : null,
|
|
232
|
-
ranker: schema_1.RANKER_BASELINE,
|
|
233
|
-
model: model !== null && MODEL.test(model) ? model : null,
|
|
234
|
-
build: buildCommit(),
|
|
235
|
-
candidates,
|
|
236
|
-
ms,
|
|
237
|
-
replyTokens: (0, agentMemory_1.replyTokens)(reply.text),
|
|
238
|
-
relevant: relevance !== null && typeof relevance.relevant === 'boolean' ? relevance.relevant : null,
|
|
239
|
-
truncated: typeof reply.body.truncated === 'boolean' ? reply.body.truncated : null,
|
|
240
|
-
leanItems: (0, agentMemory_1.contextLeanItemsEnabled)(),
|
|
241
|
-
});
|
|
242
|
-
if (ctx.sharing && ctx.sharing.level() === 'data') {
|
|
243
|
-
if (query !== null)
|
|
244
|
-
ctx.sharing.query(log.key('query', norm(query)), query);
|
|
245
|
-
for (const candidate of candidates) {
|
|
246
|
-
if (candidate.memoryKey !== null && candidate.text)
|
|
247
|
-
ctx.sharing.memory(candidate.memoryKey, candidate.text);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
function recordOp(log, base, op, kind, memoryKey, subjectKey, replacedKey = null) {
|
|
252
|
-
log.recordMemoryOp({ actor: base.actor, sessionKey: base.sessionKey, agentKey: base.agentKey, tool: base.tool, ms: base.ms,
|
|
253
|
-
op, kind, memoryKey, subjectKey, replacedKey });
|
|
254
|
-
}
|
|
255
|
-
/**
|
|
256
|
-
* A fact save (save_memory, or remember with subject, predicate and object): the value of one subject, predicate and scope.
|
|
257
|
-
* A supersede is recorded as the operation it is, with the value it replaces. It is not a use of any earlier read: the product's
|
|
258
|
-
* usage signal counts it as one (readUsefulness.ts, `updated`), and this log does not.
|
|
259
|
-
*/
|
|
260
|
-
function factSave(log, ctx, base, action, scope, subject, predicate, object) {
|
|
261
|
-
if (typeof subject !== 'string' || typeof predicate !== 'string')
|
|
262
|
-
return;
|
|
263
|
-
if (action !== 'store' && action !== 'supersede')
|
|
264
|
-
return; // nochange: nothing was written
|
|
265
|
-
const normalized = (0, scope_1.normalizeScope)(typeof scope === 'string' ? scope : undefined);
|
|
266
|
-
const memoryKey = log.key('fact', normalized, norm(subject), norm(predicate));
|
|
267
|
-
const subjectKey = log.key('subject', normalized, norm(subject));
|
|
268
|
-
if (typeof object === 'string' && ctx.sharing && ctx.sharing.level() === 'data')
|
|
269
|
-
ctx.sharing.memory(memoryKey, `${subject} ${predicate}: ${object}`);
|
|
270
|
-
if (action === 'supersede')
|
|
271
|
-
recordOp(log, base, 'supersede', 'fact', memoryKey, subjectKey, memoryKey);
|
|
272
|
-
else
|
|
273
|
-
recordOp(log, base, 'create', 'fact', memoryKey, subjectKey);
|
|
274
|
-
}
|
|
275
|
-
/** A note save (remember or remember_note): the note is created, or it replaces the memory named by `replaces`. */
|
|
276
|
-
function noteSave(log, ctx, base, file, replaces, text) {
|
|
277
|
-
if (typeof file !== 'string' || file === '')
|
|
278
|
-
return;
|
|
279
|
-
const memoryKey = log.key('note', file);
|
|
280
|
-
if (typeof text === 'string' && ctx.sharing && ctx.sharing.level() === 'data')
|
|
281
|
-
ctx.sharing.memory(memoryKey, text);
|
|
282
|
-
const replaced = typeof replaces === 'string' ? identityOf(log, replaces).memoryKey : null;
|
|
283
|
-
if (replaced !== null)
|
|
284
|
-
recordOp(log, base, 'supersede', 'note', memoryKey, null, replaced);
|
|
285
|
-
else
|
|
286
|
-
recordOp(log, base, 'create', 'note', memoryKey, null);
|
|
287
|
-
}
|
|
288
|
-
function recordWrite(log, ctx, base, args, body) {
|
|
289
|
-
if (schema_1.SAVE_TOOLS.includes(base.tool) && Array.isArray(args.cites)) {
|
|
290
|
-
const scope = (0, scope_1.normalizeScope)(typeof args.scope === 'string' ? args.scope : undefined);
|
|
291
|
-
for (const cite of args.cites.filter((value) => typeof value === 'string').slice(0, MAX_CITES)) {
|
|
292
|
-
const named = citeOf(log, cite, scope);
|
|
293
|
-
log.recordFeedback({
|
|
294
|
-
actor: base.actor, sessionKey: base.sessionKey, agentKey: base.agentKey, tool: base.tool,
|
|
295
|
-
target: named.target, memoryKey: named.memoryKey, subjectKey: named.subjectKey,
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
switch (base.tool) {
|
|
300
|
-
case 'save_memory':
|
|
301
|
-
factSave(log, ctx, base, body.action, args.scope, args.subject, args.predicate, args.object);
|
|
302
|
-
return;
|
|
303
|
-
case 'remember':
|
|
304
|
-
if (body.mode === 'fact')
|
|
305
|
-
factSave(log, ctx, base, body.action, args.scope, args.subject, args.predicate, args.object);
|
|
306
|
-
else
|
|
307
|
-
noteSave(log, ctx, base, body.file, args.replaces, args.statement);
|
|
308
|
-
return;
|
|
309
|
-
case 'remember_note':
|
|
310
|
-
noteSave(log, ctx, base, body.file, args.replaces, args.text);
|
|
311
|
-
return;
|
|
312
|
-
case 'retire_memory': {
|
|
313
|
-
if (typeof args.id !== 'string')
|
|
314
|
-
return;
|
|
315
|
-
const named = identityOf(log, args.id);
|
|
316
|
-
if (body.action === 'retired')
|
|
317
|
-
recordOp(log, base, 'delete', named.kind, named.memoryKey, null);
|
|
318
|
-
else if (body.action === 'restored')
|
|
319
|
-
recordOp(log, base, 'restore', named.kind, named.memoryKey, null);
|
|
320
|
-
return;
|
|
321
|
-
}
|
|
322
|
-
case 'restore_memory':
|
|
323
|
-
case 'delete_retired_memory':
|
|
324
|
-
case 'read_memory': {
|
|
325
|
-
if (typeof args.id !== 'string')
|
|
326
|
-
return;
|
|
327
|
-
if (base.tool === 'delete_retired_memory') {
|
|
328
|
-
const erased = Array.isArray(body.ids) ? body.ids.filter((id) => typeof id === 'string') : [args.id];
|
|
329
|
-
for (const id of erased) {
|
|
330
|
-
const named = identityOf(log, id);
|
|
331
|
-
if (named.memoryKey !== null)
|
|
332
|
-
log.eraseMemory(named.memoryKey);
|
|
333
|
-
recordOp(log, base, 'erase', named.kind, null, null);
|
|
334
|
-
}
|
|
335
|
-
return;
|
|
336
|
-
}
|
|
337
|
-
const named = identityOf(log, args.id);
|
|
338
|
-
const op = base.tool === 'restore_memory' ? 'restore' : 'retrieve';
|
|
339
|
-
recordOp(log, base, op, named.kind, named.memoryKey, null);
|
|
340
|
-
return;
|
|
341
|
-
}
|
|
342
|
-
default:
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
/** Records one call. Never throws: a failure to write is dropped, and the call it describes has already happened. */
|
|
346
|
-
function observeTool(log, ctx, tool, rawArgs, result, ok, ms, extra, trace) {
|
|
347
|
-
try {
|
|
348
|
-
if (!ok)
|
|
349
|
-
return;
|
|
350
|
-
const retrieval = schema_1.RETRIEVAL_TOOLS.includes(tool);
|
|
351
|
-
const write = schema_1.WRITE_TOOLS.includes(tool);
|
|
352
|
-
if (!retrieval && !write)
|
|
353
|
-
return;
|
|
354
|
-
const reply = replyOf(result);
|
|
355
|
-
if (reply === null)
|
|
356
|
-
return;
|
|
357
|
-
const args = isRecord(rawArgs) ? rawArgs : {};
|
|
358
|
-
const base = {
|
|
359
|
-
actor: ctx.actor,
|
|
360
|
-
sessionKey: ctx.session === null ? null : log.key('session', ctx.session),
|
|
361
|
-
agentKey: log.key('agent', ctx.agent(extra)),
|
|
362
|
-
tool,
|
|
363
|
-
ms,
|
|
364
|
-
};
|
|
365
|
-
if (retrieval)
|
|
366
|
-
recordRetrieval(log, ctx, base, args, reply, ms, trace);
|
|
367
|
-
else
|
|
368
|
-
recordWrite(log, ctx, base, args, reply.body);
|
|
369
|
-
}
|
|
370
|
-
catch {
|
|
371
|
-
// Recording must never fail the call it describes.
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
/**
|
|
375
|
-
* The observer for one MCP server, or null when the log is off. Off means nothing is opened and no file is made: a server
|
|
376
|
-
* without RENOR_LEARNING_LOG behaves exactly as it did before this module existed. With a sharing hook the observer exists
|
|
377
|
-
* and decides at each call: a user who chose to share turns recording on, with no restart.
|
|
378
|
-
*/
|
|
379
|
-
function learningObserver(settings, ctx) {
|
|
380
|
-
if (settings === undefined)
|
|
381
|
-
return null;
|
|
382
|
-
// Without a sharing choice behind it, the log is on or off for the life of the process, as before.
|
|
383
|
-
if (!settings.enabled && !ctx.sharing)
|
|
384
|
-
return null;
|
|
385
|
-
const sharing = ctx.sharing;
|
|
386
|
-
let held = settings.enabled ? (0, store_1.learningLogAt)(settings) : null;
|
|
387
|
-
return {
|
|
388
|
-
observe: (tool, args, result, ok, ms, extra, trace) => {
|
|
389
|
-
// The sharing choice is read at each call: off records nothing and makes no file, anything above it records.
|
|
390
|
-
if (!settings.enabled && (sharing === undefined || sharing.level() === 'off'))
|
|
391
|
-
return;
|
|
392
|
-
try {
|
|
393
|
-
held ??= (0, store_1.learningLogAt)(settings);
|
|
394
|
-
}
|
|
395
|
-
catch {
|
|
396
|
-
return;
|
|
397
|
-
}
|
|
398
|
-
observeTool(held, ctx, tool, args, result, ok, ms, extra, trace);
|
|
399
|
-
},
|
|
400
|
-
};
|
|
401
|
-
}
|
package/dist/mcp/hive.js
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HIVE_TOOLS = void 0;
|
|
4
|
-
exports.createStdioHiveTools = createStdioHiveTools;
|
|
5
|
-
const zod_1 = require("zod");
|
|
6
|
-
const secretGuard_1 = require("../extraction/secretGuard");
|
|
7
|
-
const agentLease_1 = require("../memory/agentLease");
|
|
8
|
-
const limits_1 = require("../memory/limits");
|
|
9
|
-
const requests_1 = require("../memory/requests");
|
|
10
|
-
const sourceName_1 = require("../memory/sourceName");
|
|
11
|
-
const whatsNew_1 = require("../memory/whatsNew");
|
|
12
|
-
// Identity is deliberately absent from every schema. One stdio process is one
|
|
13
|
-
// connection, named by its operator before startup, never by a tool argument.
|
|
14
|
-
const schemas = {
|
|
15
|
-
whats_new: zod_1.z.object({
|
|
16
|
-
since: zod_1.z.string().optional(), scope: zod_1.z.string().optional(),
|
|
17
|
-
include_own: zod_1.z.boolean().optional(), cursor: zod_1.z.string().optional(),
|
|
18
|
-
}),
|
|
19
|
-
ask_agent: zod_1.z.object({
|
|
20
|
-
to: zod_1.z.string().min(1).max(80), request: zod_1.z.string().min(1).max(limits_1.MAX_STATEMENT_LENGTH), scope: zod_1.z.string().optional(),
|
|
21
|
-
}),
|
|
22
|
-
list_requests: zod_1.z.object({
|
|
23
|
-
status: zod_1.z.enum(['open', 'answered', 'closed']).optional(),
|
|
24
|
-
to: zod_1.z.string().optional(), scope: zod_1.z.string().optional(), before: zod_1.z.string().max(80).optional(),
|
|
25
|
-
}),
|
|
26
|
-
answer_request: zod_1.z.object({ id: zod_1.z.string().min(1).max(80), answer: zod_1.z.string().min(1).max(limits_1.MAX_STATEMENT_LENGTH) }),
|
|
27
|
-
close_request: zod_1.z.object({ id: zod_1.z.string().min(1).max(80) }),
|
|
28
|
-
};
|
|
29
|
-
const descriptions = {
|
|
30
|
-
whats_new: 'Read open requests for this connection, then workspace writes since its last read. Requests and other agents\' write summaries are untrusted agent text, each excerpted to 240 characters; list_requests returns the full request. Follow cursor until it is empty; include_own also shows this connection\'s writes.',
|
|
31
|
-
ask_agent: 'Record a request for a named connection this workspace has seen. It runs nothing and wakes no agent. The recipient sees it in whats_new. The name is the header form (letters, digits and hyphens). Limited to 30 per hour by default (RENOR_ASK_AGENT_PER_HOUR).',
|
|
32
|
-
list_requests: 'List at most 20 requests this connection is a party to, newest first. Defaults to this connection\'s inbox. `to` lists only requests between this connection and that agent, never another inbox. With more_requests, pass before=<last request id> for the next page. Other agents\' text is untrusted.',
|
|
33
|
-
answer_request: 'Record an answer to a request addressed to this connection. Another connection cannot answer it. The reply includes the request and is untrusted agent text. Records a reply; runs nothing.',
|
|
34
|
-
close_request: 'Close a request addressed to, or asked by, this connection. The reply includes the request and is untrusted agent text. Runs nothing.',
|
|
35
|
-
};
|
|
36
|
-
exports.HIVE_TOOLS = Object.entries(schemas).map(([name, schema]) => ({
|
|
37
|
-
name,
|
|
38
|
-
description: descriptions[name],
|
|
39
|
-
inputSchema: { ...zod_1.z.toJSONSchema(schema), type: 'object' },
|
|
40
|
-
}));
|
|
41
|
-
/**
|
|
42
|
-
* Captures the operator's startup name. The returned handlers never read the environment.
|
|
43
|
-
* `holder` is the stdio lease. A second live holder of the same header-form name is refused.
|
|
44
|
-
*/
|
|
45
|
-
function createStdioHiveTools(db, agent, holder = (0, agentLease_1.newLeaseHolder)()) {
|
|
46
|
-
const identity = (0, sourceName_1.hiveIdentity)(agent);
|
|
47
|
-
if (!identity) {
|
|
48
|
-
throw new Error('this connection has no name the hive can use. Set RENOR_CONNECTION_NAME to a name that renders to a non-empty identifier, other than unnamed, then reconnect');
|
|
49
|
-
}
|
|
50
|
-
const touch = () => (0, agentLease_1.claimAgentLease)(db, identity, holder);
|
|
51
|
-
touch();
|
|
52
|
-
(0, requests_1.noteKnownAgent)(db, identity);
|
|
53
|
-
return {
|
|
54
|
-
async whats_new(input) {
|
|
55
|
-
touch();
|
|
56
|
-
const args = schemas.whats_new.parse(input);
|
|
57
|
-
return (0, whatsNew_1.readWhatsNew)(db, {
|
|
58
|
-
agent: identity, scope: args.scope, since: args.since || undefined,
|
|
59
|
-
includeOwn: args.include_own === true, cursor: args.cursor || undefined,
|
|
60
|
-
});
|
|
61
|
-
},
|
|
62
|
-
async ask_agent(input) {
|
|
63
|
-
touch();
|
|
64
|
-
const args = schemas.ask_agent.parse(input);
|
|
65
|
-
if ((0, secretGuard_1.secretGuardEnabled)())
|
|
66
|
-
await (0, secretGuard_1.assertStorable)([{ field: 'to', text: args.to }, { field: 'request', text: args.request }]);
|
|
67
|
-
return (0, requests_1.askAgent)(db, { from: identity, to: args.to, request: args.request, scope: args.scope, knownOnly: true, perHour: (0, requests_1.askAgentPerHour)() });
|
|
68
|
-
},
|
|
69
|
-
async list_requests(input) {
|
|
70
|
-
touch();
|
|
71
|
-
const args = schemas.list_requests.parse(input);
|
|
72
|
-
const page = (0, requests_1.listRequestsPage)(db, { agent: identity, ...args });
|
|
73
|
-
return { ...page, requests: page.requests.map(r => ({ ...r, untrusted: true })) };
|
|
74
|
-
},
|
|
75
|
-
async answer_request(input) {
|
|
76
|
-
touch();
|
|
77
|
-
const args = schemas.answer_request.parse(input);
|
|
78
|
-
if ((0, secretGuard_1.secretGuardEnabled)())
|
|
79
|
-
await (0, secretGuard_1.assertStorable)([{ field: 'answer', text: args.answer }]);
|
|
80
|
-
return { ...(0, requests_1.answerRequest)(db, { agent: identity, ...args }), untrusted: true };
|
|
81
|
-
},
|
|
82
|
-
async close_request(input) {
|
|
83
|
-
touch();
|
|
84
|
-
const args = schemas.close_request.parse(input);
|
|
85
|
-
return { ...(0, requests_1.closeRequest)(db, { agent: identity, ...args }), untrusted: true };
|
|
86
|
-
},
|
|
87
|
-
};
|
|
88
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isZodError = isZodError;
|
|
4
|
-
exports.oneLineInvalidParams = oneLineInvalidParams;
|
|
5
|
-
exports.mapInvalidParams = mapInvalidParams;
|
|
6
|
-
const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
|
|
7
|
-
function isZodError(error) {
|
|
8
|
-
// The SDK's schema parse throws zod v4's `$ZodError`; the transport's parse throws classic `ZodError`.
|
|
9
|
-
return error instanceof Error && /ZodError$/.test(error.name) && Array.isArray(error.issues);
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* A request whose params the SDK's schema refuses is answered with the error its parser threw: a ZodError has
|
|
13
|
-
* no code, so the SDK sends -32603 with the issue list as its message. The client asked wrongly, so the answer is
|
|
14
|
-
* -32602 with one line that names the field. The error carries the code the SDK reads (Protocol sends
|
|
15
|
-
* `error.code` when it is a safe integer).
|
|
16
|
-
*/
|
|
17
|
-
function oneLineInvalidParams(error) {
|
|
18
|
-
if (!isZodError(error))
|
|
19
|
-
return error;
|
|
20
|
-
const detail = error.issues
|
|
21
|
-
.map(issue => `${issue.path.map(String).join('.') || 'params'}: ${issue.message}`)
|
|
22
|
-
.join('; ');
|
|
23
|
-
const message = `Invalid params: ${detail}`;
|
|
24
|
-
return Object.assign(new Error(message.length > 300 ? `${message.slice(0, 297)}...` : message), {
|
|
25
|
-
code: types_js_1.ErrorCode.InvalidParams,
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Wraps every request handler the server has registered, the SDK's own `initialize` included, so a schema refusal
|
|
30
|
-
* reaches the client as -32602. The SDK keeps its handlers in a private map and parses each request inside the
|
|
31
|
-
* handler it stores, so the only place a refusal can be turned into the right code is this wrapper. Call it after
|
|
32
|
-
* every handler is registered and before the transport connects. An SDK that renames the map throws here at startup,
|
|
33
|
-
* and the standing tests catch it before a release.
|
|
34
|
-
*/
|
|
35
|
-
function mapInvalidParams(server) {
|
|
36
|
-
const handlers = server._requestHandlers;
|
|
37
|
-
for (const [method, handler] of handlers) {
|
|
38
|
-
handlers.set(method, async (request, extra) => {
|
|
39
|
-
try {
|
|
40
|
-
return await handler(request, extra);
|
|
41
|
-
}
|
|
42
|
-
catch (error) {
|
|
43
|
-
throw oneLineInvalidParams(error);
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
}
|