renor-engine 1.1.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.
Files changed (193) hide show
  1. package/README.md +27 -2
  2. package/THIRD-PARTY-NOTICES +2661 -0
  3. package/dist/BUILD.json +3 -3
  4. package/dist/cli.js +1656 -490
  5. package/package.json +16 -80
  6. package/dist/.tsbuildinfo +0 -1
  7. package/dist/api/apiAuth.js +0 -43
  8. package/dist/api/server.js +0 -174
  9. package/dist/buildIdentity.js +0 -149
  10. package/dist/callPhases.js +0 -82
  11. package/dist/cli-extractors.js +0 -46
  12. package/dist/config.js +0 -65
  13. package/dist/context/composer.js +0 -320
  14. package/dist/context/readHonesty.js +0 -478
  15. package/dist/context/rowStore.js +0 -238
  16. package/dist/conversation/formatter.js +0 -81
  17. package/dist/conversation/parser.js +0 -193
  18. package/dist/conversation/types.js +0 -2
  19. package/dist/conversation/writer.js +0 -42
  20. package/dist/db/client.js +0 -149
  21. package/dist/db/handoffTable.js +0 -31
  22. package/dist/db/indexSalvage.js +0 -101
  23. package/dist/db/migrations.js +0 -670
  24. package/dist/db/readCache.js +0 -109
  25. package/dist/db/schema.js +0 -5
  26. package/dist/db/sqlite.js +0 -396
  27. package/dist/db/statements.js +0 -89
  28. package/dist/digests/digestCache.js +0 -146
  29. package/dist/digests/digests.js +0 -597
  30. package/dist/digests/worker.js +0 -350
  31. package/dist/embeddings/caching.js +0 -337
  32. package/dist/embeddings/coalescing.js +0 -177
  33. package/dist/embeddings/interactive.js +0 -103
  34. package/dist/embeddings/local.js +0 -70
  35. package/dist/embeddings/openai.js +0 -106
  36. package/dist/embeddings/rebuild.js +0 -166
  37. package/dist/embeddings/simdScan.js +0 -260
  38. package/dist/embeddings/space.js +0 -21
  39. package/dist/embeddings/types.js +0 -14
  40. package/dist/embeddings/vectorIndex.js +0 -674
  41. package/dist/embeddings/vertex.js +0 -334
  42. package/dist/eval/artifacts.js +0 -42
  43. package/dist/eval/cacheReport.js +0 -146
  44. package/dist/eval/comparison.js +0 -182
  45. package/dist/eval/context700-candidate.js +0 -145
  46. package/dist/eval/evalCache.js +0 -568
  47. package/dist/eval/hashEmbedding.js +0 -35
  48. package/dist/eval/indexSnapshots.js +0 -548
  49. package/dist/eval/longmemeval.js +0 -56
  50. package/dist/eval/metrics.js +0 -181
  51. package/dist/eval/pageDump.js +0 -67
  52. package/dist/eval/renorbenchBaseline.js +0 -486
  53. package/dist/eval/renorbenchDocuments.js +0 -134
  54. package/dist/eval/renorbenchProduct.js +0 -182
  55. package/dist/eval/runLedger.js +0 -279
  56. package/dist/eval/runManifest.js +0 -485
  57. package/dist/eval/scoring.js +0 -197
  58. package/dist/eval/textTokens.js +0 -17
  59. package/dist/evidence/attach.js +0 -264
  60. package/dist/evidence/background.js +0 -147
  61. package/dist/evidence/evidenceCache.js +0 -182
  62. package/dist/evidence/gate.js +0 -37
  63. package/dist/evidence/keyPool.js +0 -85
  64. package/dist/evidence/ollamaChat.js +0 -84
  65. package/dist/evidence/optin.js +0 -165
  66. package/dist/evidence/options.js +0 -151
  67. package/dist/evidence/secondPass.js +0 -294
  68. package/dist/extraction/classifyCapture.js +0 -34
  69. package/dist/extraction/decision-model.js +0 -174
  70. package/dist/extraction/eventExtractor.js +0 -113
  71. package/dist/extraction/extractionClient.js +0 -122
  72. package/dist/extraction/factExtractor.js +0 -46
  73. package/dist/extraction/factsWritePath.js +0 -179
  74. package/dist/extraction/preferenceExtractor.js +0 -150
  75. package/dist/extraction/secretGuard.js +0 -176
  76. package/dist/extraction/secretScanner.js +0 -665
  77. package/dist/extraction/typedFacts.js +0 -224
  78. package/dist/extraction/writePathAdjudication.js +0 -110
  79. package/dist/importing/apply.js +0 -672
  80. package/dist/importing/bundle-write.js +0 -80
  81. package/dist/importing/cli.js +0 -408
  82. package/dist/importing/existing.js +0 -51
  83. package/dist/importing/facts.js +0 -121
  84. package/dist/importing/forgetImported.js +0 -79
  85. package/dist/importing/hosted.js +0 -467
  86. package/dist/importing/journalLog.js +0 -96
  87. package/dist/importing/markdown.js +0 -98
  88. package/dist/importing/plan.js +0 -201
  89. package/dist/importing/secretScreen.js +0 -113
  90. package/dist/importing/serialize.js +0 -188
  91. package/dist/importing/source.js +0 -463
  92. package/dist/importing/types.js +0 -6
  93. package/dist/indexer/chunker.js +0 -319
  94. package/dist/indexer/dailyEntries.js +0 -63
  95. package/dist/indexer/hasher.js +0 -10
  96. package/dist/indexer/laneRuns.js +0 -48
  97. package/dist/indexer/o200k.js +0 -481
  98. package/dist/indexer/outsideRoot.js +0 -77
  99. package/dist/indexer/parser.js +0 -170
  100. package/dist/indexer/pipeline.js +0 -988
  101. package/dist/indexer/staleness.js +0 -201
  102. package/dist/indexer/tokenizer.js +0 -77
  103. package/dist/indexer/walker.js +0 -170
  104. package/dist/mcp/hive.js +0 -88
  105. package/dist/mcp/requestErrors.js +0 -47
  106. package/dist/mcp/server.js +0 -426
  107. package/dist/memory/agentLease.js +0 -43
  108. package/dist/memory/confinedWrite.js +0 -315
  109. package/dist/memory/controls.js +0 -73
  110. package/dist/memory/dailyNote.js +0 -265
  111. package/dist/memory/durableAppend.js +0 -57
  112. package/dist/memory/factConflicts.js +0 -203
  113. package/dist/memory/factTerms.js +0 -321
  114. package/dist/memory/handoff.js +0 -363
  115. package/dist/memory/hiveNameHeader.cjs +0 -10
  116. package/dist/memory/inventory.js +0 -55
  117. package/dist/memory/invisibleText.js +0 -20
  118. package/dist/memory/lifecycle.js +0 -1991
  119. package/dist/memory/limits.js +0 -13
  120. package/dist/memory/requests.js +0 -183
  121. package/dist/memory/sourceName.js +0 -276
  122. package/dist/memory/statusFacts.js +0 -61
  123. package/dist/memory/whatsNew.js +0 -158
  124. package/dist/memory/writer.js +0 -175
  125. package/dist/memory/writerConflicts.js +0 -85
  126. package/dist/memorymap/memoryMap.js +0 -1594
  127. package/dist/memorymap/replacedJournal.js +0 -58
  128. package/dist/memorymap/replacements.js +0 -410
  129. package/dist/mvp/activity.js +0 -86
  130. package/dist/mvp/agentMemory.js +0 -1800
  131. package/dist/mvp/answerCheck.js +0 -211
  132. package/dist/mvp/auth.js +0 -531
  133. package/dist/mvp/cli.js +0 -75
  134. package/dist/mvp/client-store.js +0 -462
  135. package/dist/mvp/compileCache.js +0 -242
  136. package/dist/mvp/compileSeed.js +0 -33
  137. package/dist/mvp/config.js +0 -288
  138. package/dist/mvp/connectionStatus.js +0 -80
  139. package/dist/mvp/contextDistinct.js +0 -53
  140. package/dist/mvp/contextProfile.js +0 -87
  141. package/dist/mvp/contextRelevance.js +0 -413
  142. package/dist/mvp/directorySurface.js +0 -68
  143. package/dist/mvp/engine.js +0 -1078
  144. package/dist/mvp/exportAll.js +0 -374
  145. package/dist/mvp/factLanePack.js +0 -77
  146. package/dist/mvp/factMarkers.js +0 -65
  147. package/dist/mvp/factsLane.js +0 -203
  148. package/dist/mvp/hiddenSpans.js +0 -585
  149. package/dist/mvp/history.js +0 -414
  150. package/dist/mvp/hitDates.js +0 -31
  151. package/dist/mvp/hitFloor.js +0 -36
  152. package/dist/mvp/identity.js +0 -18
  153. package/dist/mvp/idle.js +0 -113
  154. package/dist/mvp/log.js +0 -118
  155. package/dist/mvp/memoryDir.js +0 -98
  156. package/dist/mvp/posthogMcp.js +0 -210
  157. package/dist/mvp/readScope.js +0 -104
  158. package/dist/mvp/readUsefulness.js +0 -222
  159. package/dist/mvp/sanitize.js +0 -48
  160. package/dist/mvp/schemaRejections.js +0 -91
  161. package/dist/mvp/scope.js +0 -127
  162. package/dist/mvp/server.js +0 -2604
  163. package/dist/mvp/serverCard.js +0 -38
  164. package/dist/mvp/storedSize.js +0 -139
  165. package/dist/mvp/telemetry.js +0 -474
  166. package/dist/net/poolFetch.js +0 -174
  167. package/dist/recall/actionRecall.js +0 -282
  168. package/dist/recall/autoRecall.js +0 -447
  169. package/dist/recall/searchRecall.js +0 -189
  170. package/dist/retrieval/adviceLines.js +0 -195
  171. package/dist/retrieval/adviceQuestion.js +0 -44
  172. package/dist/retrieval/conversationShape.js +0 -44
  173. package/dist/retrieval/dailyEntryTime.js +0 -55
  174. package/dist/retrieval/entityLookup.js +0 -162
  175. package/dist/retrieval/factsFirst.js +0 -188
  176. package/dist/retrieval/keyword.js +0 -84
  177. package/dist/retrieval/ledgerEventTime.js +0 -51
  178. package/dist/retrieval/ledgerLiveness.js +0 -83
  179. package/dist/retrieval/ledgerPresentation.js +0 -161
  180. package/dist/retrieval/noteIdentity.js +0 -57
  181. package/dist/retrieval/orchestrator.js +0 -1171
  182. package/dist/retrieval/plainWording.js +0 -236
  183. package/dist/retrieval/queryHelpers.js +0 -142
  184. package/dist/retrieval/questionSpan.js +0 -475
  185. package/dist/retrieval/readerEvents.js +0 -690
  186. package/dist/retrieval/readerLayout.js +0 -422
  187. package/dist/retrieval/relativeTimeHints.js +0 -113
  188. package/dist/retrieval/semantic.js +0 -67
  189. package/dist/router/routerCache.js +0 -106
  190. package/dist/router/sessionRouter.js +0 -726
  191. package/dist/toolRefusal.js +0 -120
  192. package/dist/watcher/watcher.js +0 -77
  193. /package/dist/{indexer/o200k.json → o200k.json} +0 -0
@@ -1,363 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HANDOFF_ARG_DESCRIPTIONS = exports.HANDOFF_TOOL_DESCRIPTION = exports.HANDOFF_TOOL_NAME = exports.HANDOFF_MAX_CHARS = exports.HANDOFF_MAX_WORDS = exports.HANDOFF_CLOCK_SKEW_MS = exports.HANDOFF_SWEEP_MS = exports.HANDOFF_TTL_MS = void 0;
4
- exports.handoffNoteEnabled = handoffNoteEnabled;
5
- exports.normaliseRepoKey = normaliseRepoKey;
6
- exports.normaliseBranch = normaliseBranch;
7
- exports.countWords = countWords;
8
- exports.sweepHandoffNotes = sweepHandoffNotes;
9
- exports.startHandoffSweep = startHandoffSweep;
10
- exports.writeHandoffNote = writeHandoffNote;
11
- exports.readHandoffNote = readHandoffNote;
12
- exports.presentHandoffNote = presentHandoffNote;
13
- exports.runHandoffTool = runHandoffTool;
14
- const secretGuard_1 = require("../extraction/secretGuard");
15
- const toolRefusal_1 = require("../toolRefusal");
16
- const controls_1 = require("./controls");
17
- const handoffTable_1 = require("../db/handoffTable");
18
- /**
19
- * The handoff note: the one exception to "save no status".
20
- *
21
- * One note per repository and branch, overwritten (never appended) at the end of a session and shown at the start of the
22
- * next session in that same repository and branch. It is status, and status goes stale: 17 of the 33 wrong reads up to
23
- * 13 Oct 2026 were stale status facts. So the note never enters memory. It lives in its own table (`handoff_notes`,
24
- * db/handoffTable.ts) that no indexer, search, read, map, what's-new or export path reads; only `readHandoffNote` does.
25
- * It is dated, carries the agent that wrote it, and is deleted 7 days after it was written.
26
- *
27
- * Behind RENOR_HANDOFF_NOTE, default OFF: with it off no tool that writes or reads a note is published, no sweep runs,
28
- * and the table is never created, so the database is byte for byte what it is without this code.
29
- *
30
- * What expiry removes: the row, by a sweep that runs when the server starts and every 15 minutes (not only on a handoff
31
- * read or write), with SQLite's secure_delete on for that statement, then a WAL checkpoint, so the note's text is
32
- * overwritten in the database file and gone from its -wal. An overwrite of a note is done the same way. A reader that
33
- * holds the WAL can stop the checkpoint: the row is gone, and every later sweep retries the checkpoint until it succeeds.
34
- * The 7 days are counted on a clock that never goes back (storeNow). Neither reaches copies made outside this database:
35
- * a backup, a filesystem snapshot, or a copy of the file someone took. docs/ENVIRONMENT-VARIABLES.md says the same.
36
- */
37
- /** A note this old is never shown again, and the sweep deletes it. */
38
- exports.HANDOFF_TTL_MS = 7 * 24 * 60 * 60 * 1000;
39
- /** How often the server sweeps expired notes away, besides at start. */
40
- exports.HANDOFF_SWEEP_MS = 15 * 60 * 1000;
41
- /**
42
- * A note dated further ahead than this was written by a clock that has since gone back (or will go forward): it is
43
- * treated as expired, so a clock rollback can never keep a note past its 7 days.
44
- */
45
- exports.HANDOFF_CLOCK_SKEW_MS = 5 * 60 * 1000;
46
- /** The note is short on purpose: what was in progress, the next step, open questions. */
47
- exports.HANDOFF_MAX_WORDS = 200;
48
- exports.HANDOFF_MAX_CHARS = 2000;
49
- const MAX_KEY_CHARS = 600;
50
- /** RENOR_HANDOFF_NOTE: on only for 1, true, yes or on (any case). Unset or any other value keeps the note off. */
51
- function handoffNoteEnabled(env = process.env) {
52
- return ['1', 'true', 'yes', 'on'].includes((env.RENOR_HANDOFF_NOTE ?? '').trim().toLowerCase());
53
- }
54
- /**
55
- * Hosts whose repository paths are case-insensitive and where `x` and `x.git` name the same repository. Only on these
56
- * are case and a `.git` suffix folded; anywhere else two spellings stay two keys.
57
- */
58
- const FOLDING_HOSTS = new Set(['github.com', 'gitlab.com', 'bitbucket.org', 'codeberg.org']);
59
- const DEFAULT_PORTS = { ssh: '22', https: '443', http: '80', git: '9418' };
60
- function refuseUnreadable() {
61
- throw (0, toolRefusal_1.refusal)('invalid_argument', 'handoff_note could not read a repository from repo; pass git remote get-url origin, or the repository\'s absolute path');
62
- }
63
- /**
64
- * The repository's key. Two spellings get the same key only when they name the same repository; anything that can name a
65
- * different one keeps them apart:
66
- *
67
- * - A remote is `remote:` + host + path. Credentials are dropped (never stored). The host is lowercased; a port is kept
68
- * unless it is the scheme's default (22 for ssh and the scp form `git@host:path`, 443 https, 80 http, 9418 git).
69
- * https and http count as one transport and ssh and the scp form as another, and on a host not listed in
70
- * FOLDING_HOSTS the transport is part of the key (`remote:https//host/path`, `remote:ssh//host/path`), since one host
71
- * may serve different repositories over each.
72
- * - On github.com, gitlab.com, bitbucket.org and codeberg.org the transport and the user are dropped, the path is
73
- * lowercased, a leading `/` or `~/`, repeated and trailing slashes and one trailing `.git` are folded:
74
- * `git@github.com:Acme/Fjord.git` and `https://github.com/acme/fjord` are one repository there.
75
- * - Anywhere else the path is kept as git sends it to the server, byte for byte (case, `.git`, repeated and trailing
76
- * slashes). A path relative to the login's home (`git@host:acme/fjord`, `ssh://host/~/acme/fjord`) is keyed with the
77
- * user, `remote:ssh-home//git@host|acme/fjord`, and never meets a root-absolute one (`git@host:/acme/fjord`).
78
- * - A repository with no remote is `path:` + its absolute path, byte for byte except a trailing slash (`/srv/fjord.git`
79
- * and `/srv/fjord` are two folders). A Windows path keeps its spelling with `\` written as `/`.
80
- *
81
- * The key is never cut: one longer than 600 characters is refused. Throws on an empty or unusable value.
82
- */
83
- function normaliseRepoKey(raw) {
84
- const input = (raw ?? '').trim();
85
- if (!input)
86
- throw (0, toolRefusal_1.refusal)('missing_argument', 'handoff_note needs repo: the repository\'s remote URL (git remote get-url origin), or its absolute path when it has none');
87
- let key;
88
- const windows = /^[A-Za-z]:[\\/]/.test(input);
89
- if (input.startsWith('/') || windows || /^file:\/\//i.test(input)) {
90
- let local = input.replace(/^file:\/\//i, '');
91
- if (windows)
92
- local = local.replace(/\\/g, '/');
93
- local = local.replace(/(.)\/+$/, '$1');
94
- if (!local.startsWith('/') && !/^[A-Za-z]:\//.test(local))
95
- refuseUnreadable();
96
- key = `path:${local}`;
97
- }
98
- else {
99
- let transport;
100
- let user = '';
101
- let host;
102
- let port;
103
- // The path as git sends it to the server: `acme/fjord` (home-relative) and `/acme/fjord` (root-absolute) are two
104
- // repositories on an ssh server (`git-upload-pack 'acme/fjord'` against `git-upload-pack '/acme/fjord'`).
105
- let gitPath;
106
- const url = /^([a-z][a-z0-9+.-]*):\/\/(?:([^/@:]*)(?::[^/@]*)?@)?(\[[^\]]+\]|[^/:@]+)(?::(\d*))?(\/.*)?$/i.exec(input);
107
- if (url) {
108
- const scheme = url[1].toLowerCase();
109
- transport = scheme === 'http' || scheme === 'https' ? 'https' : scheme === 'ssh' || scheme === 'git+ssh' || scheme === 'ssh+git' ? 'ssh' : scheme;
110
- user = url[2] ?? '';
111
- host = url[3].toLowerCase();
112
- port = url[4] && url[4] !== DEFAULT_PORTS[scheme] ? url[4] : undefined;
113
- const urlPath = url[5] ?? '';
114
- // git sends ssh://host/~/x and ssh://host/~user/x as `~/x` and `~user/x`, as it does the scp form host:~/x.
115
- gitPath = transport === 'ssh' && urlPath.startsWith('/~') ? urlPath.slice(1) : urlPath;
116
- }
117
- else {
118
- // scp-like: [user@]host:path, which git reads as ssh on port 22, the path sent as written.
119
- const scp = /^(?:([^@/:]+)@)?(\[[^\]]+\]|[^:/@]+):(.+)$/.exec(input);
120
- if (!scp)
121
- refuseUnreadable();
122
- transport = 'ssh';
123
- user = scp[1] ?? '';
124
- host = scp[2].toLowerCase();
125
- gitPath = scp[3];
126
- }
127
- if (!host || !gitPath || gitPath === '/')
128
- refuseUnreadable();
129
- const authority = port ? `${host}:${port}` : host;
130
- if (FOLDING_HOSTS.has(host) && !port) {
131
- // These hosts serve `owner/repo` the same whether it is written relative or absolute, by any user.
132
- key = `remote:${authority}/${gitPath.replace(/^~?\/*/, '').replace(/\/+/g, '/').replace(/\/+$/, '').toLowerCase().replace(/\.git$/, '')}`;
133
- }
134
- else if (gitPath.startsWith('/')) {
135
- // Root-absolute: the path names one place on that host whoever logs in. Kept byte for byte, trailing slash included.
136
- key = `remote:${transport}//${authority}${gitPath}`;
137
- }
138
- else {
139
- // Relative to the login's home (ssh only): the user is part of where it is. `|` cannot appear in a user, host or
140
- // port, so this key never meets an absolute one or another user's.
141
- if (/[|\s]/.test(user))
142
- refuseUnreadable();
143
- key = `remote:${transport}-home//${user}@${authority}|${gitPath}`;
144
- }
145
- }
146
- if (key.length > MAX_KEY_CHARS)
147
- throw (0, toolRefusal_1.refusal)('field_too_long', `handoff_note repo is over ${MAX_KEY_CHARS} characters; it is never cut, so a longer one cannot be keyed`);
148
- (0, controls_1.assertNoUnstorableControls)('handoff_note repo', key);
149
- return key;
150
- }
151
- /** `refs/heads/main` and ` main ` are `main`. A detached HEAD has no branch and is refused. Branch case is kept. */
152
- function normaliseBranch(raw) {
153
- const branch = (raw ?? '').trim().replace(/^refs\/heads\//, '');
154
- if (!branch)
155
- throw (0, toolRefusal_1.refusal)('missing_argument', 'handoff_note needs branch: git rev-parse --abbrev-ref HEAD');
156
- if (branch === 'HEAD')
157
- throw (0, toolRefusal_1.refusal)('invalid_argument', 'handoff_note: a detached HEAD has no branch, so there is no note for it');
158
- if (branch.length > MAX_KEY_CHARS)
159
- throw (0, toolRefusal_1.refusal)('field_too_long', `handoff_note branch is over ${MAX_KEY_CHARS} characters`);
160
- (0, controls_1.assertNoUnstorableControls)('handoff_note branch', branch);
161
- return branch;
162
- }
163
- function countWords(text) {
164
- return text.split(/\s+/).filter(Boolean).length;
165
- }
166
- const SYSTEM_CLOCK = { wall: () => Date.now(), mono: () => performance.now() };
167
- /** A caller's fixed instant: wall time only, so it can move a note's clock forward but never measures elapsed time. */
168
- function clockOf(now, clock) {
169
- if (clock)
170
- return clock;
171
- return now ? { wall: () => now.getTime() } : SYSTEM_CLOCK;
172
- }
173
- /** The last instant this process gave each database, with the monotonic reading it was given at. */
174
- const lastSeen = new WeakMap();
175
- /**
176
- * The time the store goes by, so a wall clock set back cannot keep a note past its 7 days. It never goes back: it is
177
- * the latest of the wall clock, the last instant it gave plus the monotonic time elapsed since (in this process), and
178
- * the high-water mark stored with the notes (across restarts). Limit: time that passes while no process runs, with the
179
- * wall clock set back over it, is not counted, so it can delay an expiry by that long.
180
- */
181
- function storeNow(db, clock) {
182
- const mono = clock.mono?.();
183
- let at = clock.wall();
184
- const seen = lastSeen.get(db);
185
- if (seen && seen.mono !== undefined && mono !== undefined)
186
- at = Math.max(at, seen.at + Math.max(0, mono - seen.mono));
187
- const stored = db.prepare('SELECT high_water FROM handoff_clock WHERE id = 1').get();
188
- if (stored)
189
- at = Math.max(at, stored.high_water);
190
- if (!stored || at > stored.high_water) {
191
- db.prepare('INSERT INTO handoff_clock (id, high_water) VALUES (1, ?) ON CONFLICT(id) DO UPDATE SET high_water = excluded.high_water').run(at);
192
- }
193
- lastSeen.set(db, { at, mono: mono ?? seen?.mono });
194
- return new Date(at);
195
- }
196
- /** Databases whose last erasure's checkpoint did not complete (a reader held the WAL): every sweep retries it. */
197
- const checkpointOwed = new WeakSet();
198
- /**
199
- * Checkpoints the WAL back to empty, so no older copy of an erased page is left in the -wal and the zeroed page is in
200
- * the database file. It does not wait for readers (busy_timeout 0 for the call): when one holds the WAL it reports false,
201
- * the database is marked owed, and the next sweep tries again.
202
- */
203
- function checkpointNow(db) {
204
- const timeout = db.pragma('busy_timeout', { simple: true });
205
- let done = false;
206
- try {
207
- db.pragma('busy_timeout = 0');
208
- const result = db.pragma('wal_checkpoint(TRUNCATE)');
209
- done = result[0]?.busy === 0;
210
- }
211
- catch {
212
- done = false;
213
- }
214
- finally {
215
- db.pragma(`busy_timeout = ${timeout}`);
216
- }
217
- if (done)
218
- checkpointOwed.delete(db);
219
- else
220
- checkpointOwed.add(db);
221
- return done;
222
- }
223
- /**
224
- * Runs `work` with secure_delete on, so the bytes a DELETE or an overwrite frees are zeroed, then checkpoints (see
225
- * checkpointNow). The connection's own secure_delete setting is put back afterwards.
226
- */
227
- function eraseFreed(db, work) {
228
- const before = db.pragma('secure_delete', { simple: true });
229
- db.pragma('secure_delete = ON');
230
- try {
231
- return work();
232
- }
233
- finally {
234
- db.pragma(`secure_delete = ${before ? 'ON' : 'OFF'}`);
235
- checkpointNow(db);
236
- }
237
- }
238
- /** Deletes the expired notes, and any dated ahead of `now` by more than the clock skew. Returns how many it deleted. */
239
- function purgeExpired(db, now) {
240
- const ahead = new Date(now.getTime() + exports.HANDOFF_CLOCK_SKEW_MS).toISOString();
241
- const due = db.prepare('SELECT COUNT(*) AS c FROM handoff_notes WHERE expires_at <= ? OR written_at > ?')
242
- .get(now.toISOString(), ahead);
243
- if (due.c === 0)
244
- return 0;
245
- return eraseFreed(db, () => db.prepare('DELETE FROM handoff_notes WHERE expires_at <= ? OR written_at > ?')
246
- .run(now.toISOString(), ahead).changes);
247
- }
248
- /**
249
- * One expiry pass: deletes every due note, and retries a checkpoint an earlier erasure still owes. `firstPass` also
250
- * checkpoints whatever a process that stopped early left in the WAL.
251
- */
252
- function sweepHandoffNotes(db, clock = SYSTEM_CLOCK, firstPass = false) {
253
- (0, handoffTable_1.ensureHandoffTable)(db);
254
- const deleted = purgeExpired(db, storeNow(db, clock));
255
- if (deleted === 0 && (firstPass || checkpointOwed.has(db)))
256
- checkpointNow(db);
257
- }
258
- /**
259
- * The expiry sweep, independent of reads and writes: one pass now, then one every `everyMs`. Only the servers start it,
260
- * and only with RENOR_HANDOFF_NOTE on. Returns the function that stops it. The timer never keeps a process alive.
261
- */
262
- function startHandoffSweep(db, everyMs = exports.HANDOFF_SWEEP_MS, clock = SYSTEM_CLOCK) {
263
- const sweep = (firstPass) => {
264
- try {
265
- sweepHandoffNotes(db, clock, firstPass);
266
- }
267
- catch { /* a closed or busy database: the next sweep tries again */ }
268
- };
269
- sweep(true);
270
- const timer = setInterval(() => sweep(false), everyMs);
271
- timer.unref?.();
272
- return () => clearInterval(timer);
273
- }
274
- /**
275
- * Writes the note for this repository and branch, replacing any note already there (exactly one row per key; the old
276
- * text is overwritten on disk, see eraseFreed). A note over 200 words or 2,000 characters is refused, never cut; so is
277
- * text the secret guard flags. Returns what was stored.
278
- */
279
- async function writeHandoffNote(db, args) {
280
- const repo = normaliseRepoKey(args.repo);
281
- const branch = normaliseBranch(args.branch);
282
- const note = (args.note ?? '').trim();
283
- if (!note)
284
- throw (0, toolRefusal_1.refusal)('missing_argument', 'handoff_note write needs note: what was in progress, the next step, open questions');
285
- const words = countWords(note);
286
- if (words > exports.HANDOFF_MAX_WORDS)
287
- throw (0, toolRefusal_1.refusal)('field_too_long', `handoff_note is ${words} words; at most ${exports.HANDOFF_MAX_WORDS}. Shorten it to what was in progress, the next step and open questions. Nothing was written.`);
288
- if (note.length > exports.HANDOFF_MAX_CHARS)
289
- throw (0, toolRefusal_1.refusal)('field_too_long', `handoff_note is ${note.length} characters; at most ${exports.HANDOFF_MAX_CHARS}. Nothing was written.`);
290
- (0, controls_1.assertNoUnstorableControls)('handoff_note note', note);
291
- await (0, secretGuard_1.assertStorable)([{ field: 'note', text: note }]);
292
- const writer = args.writer.trim() || 'unnamed';
293
- (0, handoffTable_1.ensureHandoffTable)(db);
294
- const now = storeNow(db, clockOf(args.now, args.clock));
295
- const writtenAt = now.toISOString();
296
- const expiresAt = new Date(now.getTime() + exports.HANDOFF_TTL_MS).toISOString();
297
- purgeExpired(db, now);
298
- const replaced = eraseFreed(db, () => db.transaction(() => {
299
- const had = db.prepare('SELECT 1 FROM handoff_notes WHERE repo = ? AND branch = ?').get(repo, branch) !== undefined;
300
- db.prepare(`INSERT INTO handoff_notes (repo, branch, note, writer, written_at, expires_at) VALUES (?, ?, ?, ?, ?, ?)
301
- ON CONFLICT(repo, branch) DO UPDATE SET note = excluded.note, writer = excluded.writer,
302
- written_at = excluded.written_at, expires_at = excluded.expires_at`)
303
- .run(repo, branch, note, writer, writtenAt, expiresAt);
304
- return had;
305
- })());
306
- return { repo, branch, note, writer, written_at: writtenAt, expires_at: expiresAt, replaced };
307
- }
308
- /**
309
- * The note for exactly this repository and branch, or null: none was written, it is 7 days old, or it is dated ahead of
310
- * the clock. Another branch or another repository never matches. Reading also deletes every due note in the workspace.
311
- */
312
- function readHandoffNote(db, args) {
313
- const repo = normaliseRepoKey(args.repo);
314
- const branch = normaliseBranch(args.branch);
315
- (0, handoffTable_1.ensureHandoffTable)(db);
316
- purgeExpired(db, storeNow(db, clockOf(args.now, args.clock)));
317
- const row = db.prepare('SELECT repo, branch, note, writer, written_at, expires_at FROM handoff_notes WHERE repo = ? AND branch = ?')
318
- .get(repo, branch);
319
- return row ?? null;
320
- }
321
- /**
322
- * The note as an agent shows it at session start: its date, its writer, and its age, then the note. Status, so it is
323
- * labelled as possibly out of date and as agent text.
324
- */
325
- function presentHandoffNote(note, now = new Date()) {
326
- const days = Math.floor((now.getTime() - Date.parse(note.written_at)) / (24 * 60 * 60 * 1000));
327
- const age = days <= 0 ? 'today' : days === 1 ? '1 day ago' : `${days} days ago`;
328
- return `Handoff note for ${note.branch}, written ${note.written_at.slice(0, 16).replace('T', ' ')} UTC (${age}) by ${note.writer}. `
329
- + 'It is the last session\'s status, not memory: check it against the code before relying on it.\n\n'
330
- + note.note;
331
- }
332
- exports.HANDOFF_TOOL_NAME = 'handoff_note';
333
- exports.HANDOFF_TOOL_DESCRIPTION = 'The handoff note for one repository and branch: the only status Renor keeps, and never memory. '
334
- + 'action "write" at the end of a session: what was in progress, the next step, open questions, in at most 200 words. It replaces the note already there; nothing is appended. '
335
- + 'action "read" at the start of a session: the note for exactly this repository and branch, with its date and the agent that wrote it, or found: false. '
336
- + 'repo is `git remote get-url origin` (or the repository\'s absolute path when it has no remote), branch is `git rev-parse --abbrev-ref HEAD`. '
337
- + 'A note is deleted 7 days after it was written. get_context, search_memory, memory_map, whats_new and export_memory never return it. Do not save status anywhere else.';
338
- exports.HANDOFF_ARG_DESCRIPTIONS = {
339
- action: '"write" to replace this repository and branch\'s note, "read" to get it.',
340
- repo: 'The repository: git remote get-url origin, or its absolute path when it has no remote. Credentials in a URL are dropped, never stored.',
341
- branch: 'The branch: git rev-parse --abbrev-ref HEAD.',
342
- note: 'For write: what was in progress, the next step, open questions. At most 200 words.',
343
- };
344
- /**
345
- * The one entry both MCP servers call (the hosted `handoff_note` tool and the stdio one), and the documented function
346
- * a private gate runs: `runHandoffTool(db, { action, repo, branch, note? }, writer, now?)`. `writer` is the connection's
347
- * authenticated name. Returns the reply body; throws a refusal on bad input.
348
- */
349
- async function runHandoffTool(db, args, writer, now) {
350
- if (args.action === 'write') {
351
- const stored = await writeHandoffNote(db, { repo: args.repo, branch: args.branch, note: args.note ?? '', writer, now });
352
- return {
353
- ok: true, action: 'write', replaced: stored.replaced, repo: stored.repo, branch: stored.branch,
354
- writer: stored.writer, written_at: stored.written_at, expires_at: stored.expires_at, words: countWords(stored.note),
355
- };
356
- }
357
- if (args.action !== 'read')
358
- throw (0, toolRefusal_1.refusal)('invalid_argument', 'handoff_note action is "read" or "write"');
359
- const found = readHandoffNote(db, { repo: args.repo, branch: args.branch, now });
360
- if (!found)
361
- return { ok: true, action: 'read', found: false, repo: normaliseRepoKey(args.repo), branch: normaliseBranch(args.branch) };
362
- return { ok: true, action: 'read', found: true, ...found, shown: presentHandoffNote(found, now ?? new Date()) };
363
- }
@@ -1,10 +0,0 @@
1
- const { createHash } = require('node:crypto');
2
-
3
- /** The shared, HTTP-header-safe first stage of every connection's hive name. */
4
- exports.hiveNameHeader = function hiveNameHeader(label) {
5
- const raw = typeof label === 'string' ? label.normalize('NFC').replace(/\s+/g, ' ').trim() : '';
6
- if (raw === '') return 'unnamed';
7
- const text = raw.replace(/[^\t\x20-\x7e\xa0-\xff]/g, '').replace(/\s+/g, ' ').trim();
8
- if (text === '') return `agent-${createHash('sha256').update(raw, 'utf8').digest('hex').slice(0, 8)}`;
9
- return text.slice(0, 80);
10
- };
@@ -1,55 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ledgerNotePath = ledgerNotePath;
4
- exports.countEntities = countEntities;
5
- exports.countInventory = countInventory;
6
- const lifecycle_1 = require("./lifecycle");
7
- const entityLookup_1 = require("../retrieval/entityLookup");
8
- /**
9
- * The ledger file as the index stores its path (the vault walk joins from the same resolved directory), or null when
10
- * the configured path cannot name a file. Null excludes nothing: the SQL below reads it as `IS NOT NULL`.
11
- */
12
- function ledgerNotePath(vault) {
13
- try {
14
- return (0, lifecycle_1.resolveLedgerPath)(vault.memoryDir, vault.ledgerRelPath);
15
- }
16
- catch {
17
- return null;
18
- }
19
- }
20
- function scalar(db, sql, ...params) {
21
- return db.prepare(sql).get(...params).c;
22
- }
23
- /**
24
- * Entities without the one the index registers for the ledger file. The subjects of lifecycle facts (source note
25
- * `_mcp_`), while one of their facts is not retired, and the entity of every other note count. `filter` narrows the count to one scope (entityScopeFilter), so a
26
- * count handed to a caller who may read only that scope is never workspace-wide. lookup_entity reports this same count
27
- * when it finds nothing, so it cannot name a different number of entities than memory_status.
28
- */
29
- function countEntities(db, vault, filter) {
30
- const where = ['source_note IS NOT ?'];
31
- const params = [ledgerNotePath(vault)];
32
- // Without a scope, every scope's (liveEntityFilter): the count lookup_entity reports with no scope.
33
- const narrowed = filter ?? (0, entityLookup_1.liveEntityFilter)();
34
- where.push(narrowed.sql);
35
- params.push(...narrowed.params);
36
- return scalar(db, `SELECT COUNT(*) AS c FROM entities WHERE ${where.join(' AND ')}`, ...params);
37
- }
38
- function countInventory(db, vault) {
39
- // A table that cannot be read counts as empty, as memory_status always has.
40
- const orZero = (count) => {
41
- try {
42
- return count();
43
- }
44
- catch {
45
- return 0;
46
- }
47
- };
48
- return {
49
- notes: orZero(() => scalar(db, 'SELECT COUNT(*) AS c FROM notes WHERE path IS NOT ? AND path IS NOT ?', lifecycle_1.LIFECYCLE_NOTE_PATH, ledgerNotePath(vault))),
50
- chunks: orZero(() => scalar(db, 'SELECT COUNT(*) AS c FROM chunks')),
51
- entities: orZero(() => countEntities(db, vault)),
52
- facts: orZero(() => scalar(db, 'SELECT COUNT(*) AS c FROM facts')),
53
- relations: orZero(() => scalar(db, 'SELECT COUNT(*) AS c FROM relations')),
54
- };
55
- }
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isBlankOrInvisible = isBlankOrInvisible;
4
- /**
5
- * True when `text` holds nothing a reader can see: only whitespace, the Unicode default-ignorable code
6
- * points, the Unicode format controls, and the two blank symbols — U+2800 BRAILLE PATTERN BLANK and
7
- * U+FFFC OBJECT REPLACEMENT CHARACTER — which render as nothing but are neither whitespace nor
8
- * default-ignorable.
9
- *
10
- * A subject, predicate, object, note or statement made only of these is refused on write, so a memory
11
- * that looks empty is never stored and no user has to correct one they cannot see. One rule for every
12
- * write path: the ledger's structured fields (`refuseUnstorableFields`), the daily-note writer
13
- * (`checkedNoteText`) and the import preview all read it here, so a blank a reader cannot see is blank
14
- * everywhere. Whitespace and default-ignorable alone left U+2800, U+FFFC and the interlinear-annotation
15
- * controls U+FFF9..U+FFFB accepted (breaker run 2).
16
- */
17
- const BLANK_OR_INVISIBLE = /^[\s\p{Default_Ignorable_Code_Point}\p{Cf}\u2800\uFFFC]*$/u;
18
- function isBlankOrInvisible(text) {
19
- return BLANK_OR_INVISIBLE.test(text);
20
- }