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,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MAX_STATEMENT_LENGTH = void 0;
4
- /**
5
- * The longest statement `remember` admits, in UTF-16 code units (what `String.length` counts, and what
6
- * a zod `.max()` on a string counts).
7
- *
8
- * One number for every place that stores the user's words: the MCP schema, the ledger's `statement`
9
- * field and the daily-note writer all read it from here, so a statement that is admitted is a statement
10
- * that is kept. They used to disagree (4000 admitted, 2000 written) and the writer cut the difference
11
- * without a word.
12
- */
13
- exports.MAX_STATEMENT_LENGTH = 4000;
@@ -1,183 +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.REQUEST_PAGE_LIMIT = exports.DEFAULT_ASK_AGENT_PER_HOUR = void 0;
7
- exports.askAgentPerHour = askAgentPerHour;
8
- exports.noteKnownAgent = noteKnownAgent;
9
- exports.askAgent = askAgent;
10
- exports.listRequests = listRequests;
11
- exports.listRequestsPage = listRequestsPage;
12
- exports.answerRequest = answerRequest;
13
- exports.closeRequest = closeRequest;
14
- const crypto_1 = __importDefault(require("crypto"));
15
- const scope_1 = require("../mvp/scope");
16
- const controls_1 = require("./controls");
17
- const sourceName_1 = require("./sourceName");
18
- const STATUSES = new Set(['open', 'answered', 'closed']);
19
- /** How many requests one sending connection may record per rolling hour, unless RENOR_ASK_AGENT_PER_HOUR says otherwise. */
20
- exports.DEFAULT_ASK_AGENT_PER_HOUR = 30;
21
- const HOUR_MS = 60 * 60 * 1000;
22
- /** The hourly limit for ask_agent: RENOR_ASK_AGENT_PER_HOUR when it is a positive integer, otherwise the default. */
23
- function askAgentPerHour() {
24
- const raw = Number(process.env.RENOR_ASK_AGENT_PER_HOUR);
25
- return Number.isInteger(raw) && raw > 0 ? raw : exports.DEFAULT_ASK_AGENT_PER_HOUR;
26
- }
27
- /** Records a connection name the gateway set (x-renor-agent), so ask_agent can address it. "unnamed" is never recorded. */
28
- function noteKnownAgent(db, agent, now = new Date()) {
29
- if (agent === 'unnamed')
30
- return;
31
- db.prepare('INSERT OR IGNORE INTO known_agents (agent, first_seen) VALUES (?, ?)').run(agent, now.toISOString());
32
- }
33
- function isKnownAgent(db, agent) {
34
- return db.prepare('SELECT 1 FROM known_agents WHERE agent = ?').get(agent) !== undefined;
35
- }
36
- function row(db, id) {
37
- const found = db.prepare('SELECT * FROM agent_requests WHERE id = ?').get(id);
38
- if (!found)
39
- throw new Error('no request with that id');
40
- return found;
41
- }
42
- function askAgent(db, args) {
43
- const rawTo = args.to.trim();
44
- const question = args.request.trim();
45
- if (!rawTo)
46
- throw new Error('ask_agent needs who it is for');
47
- if (!question)
48
- throw new Error('ask_agent needs a request');
49
- // Store the header form, the same name stdio and hosted publish. A spelling a header cannot render is unnamed.
50
- const to = (0, sourceName_1.hiveIdentity)(rawTo);
51
- const from = (0, sourceName_1.hiveIdentity)(args.from);
52
- if (!from)
53
- throw new Error('ask_agent needs a connection name');
54
- if (!to)
55
- throw new Error('ask_agent cannot address unnamed: that is every connection whose key has no name. Name the key, then ask it by that name');
56
- // A request is text another agent reads, so it is held to the same rule as a memory: no control
57
- // character a reader cannot see (memory/controls.ts). Checked before anything is stored.
58
- (0, controls_1.assertNoUnstorableControls)('ask_agent to', to);
59
- (0, controls_1.assertNoUnstorableControls)('ask_agent request', question);
60
- const now = args.now ?? new Date();
61
- if (args.knownOnly) {
62
- if (!isKnownAgent(db, to))
63
- throw new Error(`no connection named ${JSON.stringify(to)} has connected to this workspace; ask_agent addresses an agent by the name on its connection key`);
64
- }
65
- if (args.perHour !== undefined) {
66
- const since = new Date(now.getTime() - HOUR_MS).toISOString();
67
- const recent = db.prepare('SELECT COUNT(*) AS n, MIN(created_at) AS oldest FROM agent_requests WHERE from_agent = ? AND created_at > ?').get(from, since);
68
- if (recent.n >= args.perHour) {
69
- const retry = new Date(Date.parse(recent.oldest) + HOUR_MS).toISOString();
70
- throw new Error(`ask_agent is limited to ${args.perHour} requests per hour per connection; this one can ask again after ${retry}`);
71
- }
72
- }
73
- const id = `req_${crypto_1.default.randomBytes(8).toString('hex')}`;
74
- const created = now.toISOString();
75
- db.prepare(`INSERT INTO agent_requests (id, scope, from_agent, to_agent, question, answer, status, created_at, answered_at, closed_at)
76
- VALUES (?, ?, ?, ?, ?, NULL, 'open', ?, NULL, NULL)`).run(id, args.scope !== undefined && args.scope.trim() !== '' ? (0, scope_1.normalizeScope)(args.scope) : null, from, to, question, created);
77
- return { id, status: 'open', from_agent: from, to_agent: to, created_at: created };
78
- }
79
- /** At most this many requests one list returns, the newest; the rest are counted. whats_new leads with the same number. */
80
- exports.REQUEST_PAGE_LIMIT = 20;
81
- function listWhere(args) {
82
- const status = args.status ?? 'open';
83
- if (!STATUSES.has(status))
84
- throw new Error('list_requests status must be open, answered or closed');
85
- const caller = (0, sourceName_1.hiveIdentity)(args.agent) ?? args.agent.trim();
86
- let sql;
87
- const params = [];
88
- if (args.to !== undefined && args.to.trim() !== '') {
89
- // `to` names the other party of a thread, not an inbox to read. Both directions count: the request
90
- // this connection asked of that agent, and the request that agent asked of this one. A connection
91
- // that is neither party to a thread cannot list it, and cannot page through it.
92
- const other = (0, sourceName_1.hiveIdentity)(args.to);
93
- if (!other)
94
- throw new Error('list_requests cannot address unnamed: that is every connection whose key has no name. Name the key, then ask it by that name');
95
- sql = 'status = ? AND ((from_agent = ? AND to_agent = ?) OR (from_agent = ? AND to_agent = ?))';
96
- params.push(status, caller, other, other, caller);
97
- }
98
- else {
99
- // With no `to` this is the caller's own inbox, exactly as it has always been.
100
- sql = 'status = ? AND to_agent = ?';
101
- params.push(status, caller);
102
- }
103
- let scopeSql = '';
104
- if (args.scope !== undefined && args.scope.trim() !== '') {
105
- // Every spelling of the scope (atlas, scope:atlas, project:atlas); a request asked with no scope is global.
106
- const saved = (0, scope_1.savedScopeSqlPredicate)((0, scope_1.normalizeScope)(args.scope), "COALESCE(scope, 'global')");
107
- scopeSql = ` AND ${saved.sql}`;
108
- params.push(...saved.params);
109
- }
110
- return { sql: `${sql}${scopeSql}`, params, caller };
111
- }
112
- /** An answer is for the agent who asked and the one who answered; anyone else sees that it was answered, not what. */
113
- function visibleTo(agent, r) {
114
- return r.from_agent === agent || r.to_agent === agent ? r : { ...r, answer: null };
115
- }
116
- /** Every request matching `args`, newest first. Unbounded: the tools read `listRequestsPage`. */
117
- function listRequests(db, args) {
118
- const where = listWhere(args);
119
- const rows = db.prepare(`SELECT * FROM agent_requests WHERE ${where.sql} ORDER BY created_at DESC, rowid DESC`).all(...where.params);
120
- return rows.map((r) => visibleTo(args.agent, r));
121
- }
122
- /**
123
- * The newest REQUEST_PAGE_LIMIT requests matching `args` (older than `args.before` when given), and how many more there
124
- * are (`more_requests`, absent when none) with the call that lists them (`more_requests_hint`). What list_requests and
125
- * whats_new return: a flood of requests costs a reader one bounded page, never all of it.
126
- */
127
- function listRequestsPage(db, args) {
128
- const where = listWhere(args);
129
- let sql = where.sql;
130
- const params = [...where.params];
131
- if (args.before !== undefined && args.before.trim() !== '') {
132
- // Same order as the list (created_at, then insertion): strictly after the given request in it.
133
- // The anchor has to be a request this caller is a party to. Another pair's id is not a page cursor.
134
- const anchor = db.prepare('SELECT created_at, rowid AS rid FROM agent_requests WHERE id = ? AND (from_agent = ? OR to_agent = ?)').get(args.before.trim(), where.caller, where.caller);
135
- if (!anchor)
136
- throw new Error('list_requests before must be the id of a request from whats_new or list_requests');
137
- sql += ' AND (created_at < ? OR (created_at = ? AND rowid < ?))';
138
- params.push(anchor.created_at, anchor.created_at, anchor.rid);
139
- }
140
- const rows = db.prepare(`SELECT * FROM agent_requests WHERE ${sql} ORDER BY created_at DESC, rowid DESC LIMIT ?`).all(...params, exports.REQUEST_PAGE_LIMIT);
141
- const requests = rows.map((r) => visibleTo(args.agent, r));
142
- if (requests.length < exports.REQUEST_PAGE_LIMIT)
143
- return { requests };
144
- const total = db.prepare(`SELECT COUNT(*) AS n FROM agent_requests WHERE ${sql}`).get(...params).n;
145
- if (total <= requests.length)
146
- return { requests };
147
- const more = total - requests.length;
148
- const last = requests[requests.length - 1].id;
149
- return {
150
- requests,
151
- more_requests: more,
152
- more_requests_hint: `${more} older request${more === 1 ? '' : 's'} not shown; use list_requests with before=${last}`,
153
- };
154
- }
155
- function answerRequest(db, args) {
156
- const found = row(db, args.id);
157
- if (found.to_agent !== args.agent)
158
- throw new Error('only the agent this request is for can answer it');
159
- if (found.status === 'closed')
160
- throw new Error('a closed request cannot be answered');
161
- const answer = args.answer.trim();
162
- if (!answer)
163
- throw new Error('answer_request needs an answer');
164
- // The same rule ask_agent holds to: an answer is text another agent reads back (memory/controls.ts).
165
- (0, controls_1.assertNoUnstorableControls)('answer_request answer', answer);
166
- const at = (args.now ?? new Date()).toISOString();
167
- // The guard is in the statement too: a close on another handle between the read above and this write must win.
168
- const changed = db.prepare(`UPDATE agent_requests SET status = 'answered', answer = ?, answered_at = ? WHERE id = ? AND status != 'closed'`).run(answer, at, args.id).changes;
169
- if (changed === 0)
170
- throw new Error('a closed request cannot be answered');
171
- return row(db, args.id);
172
- }
173
- function closeRequest(db, args) {
174
- const found = row(db, args.id);
175
- if (found.to_agent !== args.agent && found.from_agent !== args.agent) {
176
- throw new Error('only the agent this request is for, or the one who asked, can close it');
177
- }
178
- if (found.status === 'closed')
179
- return found;
180
- const at = (args.now ?? new Date()).toISOString();
181
- db.prepare(`UPDATE agent_requests SET status = 'closed', closed_at = ? WHERE id = ?`).run(at, args.id);
182
- return row(db, args.id);
183
- }
@@ -1,276 +0,0 @@
1
- "use strict";
2
- /**
3
- * The source of a memory: a short name for who or what saved it (`claude-code`, `cursor`, `executor-3`). It is stored with
4
- * the entry, in the daily-note header (`- [08:30:00] (cursor) ...`) and in the ledger event (`- source: cursor`), and shown
5
- * beside it ("by cursor").
6
- *
7
- * A client may send more than a name. An agent that builds its call by hand sometimes sends where the words came from
8
- * instead: a file path (`/home/ana/project/BOARD.md`), a Windows path, a URL. That is a location, not a name, and the two
9
- * stores each did the wrong thing with it. The daily-note header deletes every character that is not a letter, a digit or a
10
- * hyphen, so the whole path ran together into one word (`homeanaprojectBOARDmd`), with no limit on its length; the ledger
11
- * kept the path as sent, the directories of the sender's machine in it, and refused the whole save past 256 characters.
12
- *
13
- * Three rules, shared by both writers and by the hosted tools:
14
- * - `cleanSource`: a location is reduced to the name it ends in and the name is cut at MAX_SOURCE_LENGTH characters. A path
15
- * becomes its last component; a URL becomes its host, or with no host the last component of its path, and its userinfo
16
- * (`user:password@`) is never part of what it becomes, whatever else the URL lacks or spells oddly. A `/` or `\` is what
17
- * makes a source a location, whatever else it is: `crew/executor-7` is stored as `executor-7`. The ledger stores this.
18
- * A control character is dropped first, as a URL parser drops a tab or a newline, so a stray one never loses the save and
19
- * never hides the URL a browser would read (`ht<newline>tps://user:pw@host` is `host`).
20
- * It is not a secret scanner: a URL inside a longer text is a name like any other (RENOR_SECRET_GUARD judges the rest).
21
- * - `headerSource`: what a note header stores, which keeps letters, digits and hyphens only. It is `cleanSource` with every
22
- * run of other characters written as one hyphen instead of deleted, so the words stay apart (`Claude Code` is
23
- * `Claude-Code`, `board.md` is `board-md`).
24
- * - `productFromUserAgent`: when a client names no one, the name it gives itself, the product in its User-Agent.
25
- * They decide what a NEW write stores and nothing more: an entry or event written earlier is read back exactly as it was
26
- * stored, and is never rewritten.
27
- */
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.IMPORT_SOURCE_PREFIX = exports.MAX_SOURCE_LENGTH = void 0;
30
- exports.cleanSource = cleanSource;
31
- exports.headerSource = headerSource;
32
- exports.hiveIdentity = hiveIdentity;
33
- exports.productFromUserAgent = productFromUserAgent;
34
- exports.isImportSource = isImportSource;
35
- exports.savedSource = savedSource;
36
- exports.reservedCallerSource = reservedCallerSource;
37
- exports.reservedSourceIn = reservedSourceIn;
38
- exports.isReservedSource = isReservedSource;
39
- exports.authorMarker = authorMarker;
40
- const hiveNameHeader_cjs_1 = require("./hiveNameHeader.cjs");
41
- /** The longest source a write stores, in characters (code points). */
42
- exports.MAX_SOURCE_LENGTH = 40;
43
- /** `scheme:` at the start. Group 1 is the scheme. It has two letters or more: `C:\\Users` and `C://Users` are a Windows drive, not a URL. */
44
- const SCHEME = /^([A-Za-z][A-Za-z0-9+.-]+):/;
45
- /**
46
- * The schemes a browser reads an authority after, whatever follows the colon: any run of `/` and `\`, none included, so
47
- * `https://h`, `https:/h`, `https:\h`, `https:h` and `https:///h` are one URL. Any other scheme has an authority only after two
48
- * separators (`ssh://h`), and a path after fewer: a browser reads `ssh:/user:pw@h` and `ssh:user:pw@h` as paths, and
49
- * `file:/home/ana/BOARD.md` as a path (`file` is not one of these).
50
- */
51
- const WEB_SCHEME = /^(?:https?|wss?|ftp)$/i;
52
- /** Where a URL's authority ends: its path, query or fragment starts. */
53
- const AUTHORITY_END = /[\\/?#]/;
54
- const SEPARATOR = /[\\/]/;
55
- const COMPONENT_SEPARATORS = /[\\/]+/;
56
- /** Every control character (C0, DEL and C1): the ledger refuses the first two in a field, and a URL parser drops a tab or a newline wherever it is. */
57
- const CONTROL_CHARACTERS = /\p{Cc}+/gu;
58
- /** The last component of a path that names something: `.` and `..` do not, and a trailing separator leaves an empty one. */
59
- function lastComponent(location) {
60
- const components = location.split(COMPONENT_SEPARATORS);
61
- for (let i = components.length - 1; i >= 0; i--) {
62
- const component = components[i].trim();
63
- if (component !== '' && component !== '.' && component !== '..')
64
- return component;
65
- }
66
- return '';
67
- }
68
- /** At most MAX_SOURCE_LENGTH characters, counted as the code points they are, so a letter outside the BMP is never split. */
69
- function cut(name) {
70
- // Code units are never fewer than code points, so a short string needs no walk.
71
- if (name.length <= exports.MAX_SOURCE_LENGTH)
72
- return name.trim();
73
- let end = 0;
74
- let count = 0;
75
- for (const point of name) {
76
- if (count === exports.MAX_SOURCE_LENGTH)
77
- break;
78
- end += point.length;
79
- count++;
80
- }
81
- return name.slice(0, end).trim();
82
- }
83
- /**
84
- * `rest` without the userinfo of an authority that only a `/`, `?` or `#` ends. A browser ends the authority of a scheme that is
85
- * neither a web scheme nor `file` there and nowhere else, so its userinfo may hold a `\` (`custom://\user:pw@host`), which
86
- * urlName otherwise reads as the end of a host (`smb://server\share`). Everything up to the last `@` of that authority goes first.
87
- */
88
- function afterUserinfo(rest) {
89
- const end = rest.search(/[/?#]/);
90
- const authority = end === -1 ? rest : rest.slice(0, end);
91
- return rest.slice(authority.lastIndexOf('@') + 1);
92
- }
93
- /**
94
- * What a URL names, or null when `given` is not one (no scheme, or a scheme with no authority): its host, or when it has none
95
- * (`file:///home/ana/BOARD.md`, `https://user:pass@`) the last component of its path, its query and fragment left out.
96
- *
97
- * The userinfo (`user:password@`) is never part of the answer, because the authority is parsed rather than matched: it is
98
- * what follows the scheme's separators up to the first `/`, `\`, `?` or `#`, and its userinfo is everything up to the LAST `@`
99
- * in it, so a password with an unescaped `@`, an empty host, a port with no host and every spelling of the same URL a browser
100
- * reads (`https:\\`, `https:///`, `https:/`, `https:`) leave the credentials in neither the host nor the path. (A scheme that is
101
- * neither a web scheme nor `file` ends it at a `/`, `?` or `#` only, so a `\` can be part of its userinfo: afterUserinfo.) A
102
- * path is still a path: an `@` in `file:///home/ana/notes@2024.md` is part of a file name. A URL inside a longer text is not
103
- * recognised here; that is a name like any other, and so is a one-letter scheme (a Windows drive) and
104
- * `jdbc:postgresql://user:pw@host`, which a browser reads as a path.
105
- */
106
- function urlName(given) {
107
- const scheme = SCHEME.exec(given);
108
- if (!scheme)
109
- return null;
110
- let rest = given.slice(scheme[0].length);
111
- if (WEB_SCHEME.test(scheme[1]))
112
- rest = rest.replace(/^[\\/]+/, '');
113
- else if (/^[\\/]{2}/.test(rest))
114
- rest = /^file$/i.test(scheme[1]) ? rest.slice(2) : afterUserinfo(rest.slice(2));
115
- else
116
- return null;
117
- const end = rest.search(AUTHORITY_END);
118
- const authority = end === -1 ? rest : rest.slice(0, end);
119
- const hostAndPort = authority.slice(authority.lastIndexOf('@') + 1);
120
- // A bracketed IPv6 host keeps its colons; otherwise the host stops at the port's colon. Always matches (possibly empty).
121
- const host = /^\[[^\]]*\]|^[^:]*/.exec(hostAndPort)[0];
122
- if (host.trim() !== '')
123
- return host;
124
- return lastComponent(end === -1 ? '' : rest.slice(end).split(/[?#]/, 1)[0]);
125
- }
126
- /**
127
- * The name a write stores for the `source` a client sent: a path or a URL reduced to the name it ends in, at most
128
- * MAX_SOURCE_LENGTH characters, with no control character in it. It may be empty (a source that was only blanks, controls or
129
- * separators, or a URL that names nothing), which names no one. Never throws on a string.
130
- */
131
- function cleanSource(source) {
132
- // Dropped, not turned into a blank: a URL parser drops a tab or a newline too, so a control character inside the scheme or
133
- // between its separators (`https:/<tab>/user:pw@host`) must not hide the URL it is in.
134
- const given = source.replace(CONTROL_CHARACTERS, '').trim();
135
- const url = urlName(given);
136
- if (url !== null)
137
- return cut(url);
138
- return cut(SEPARATOR.test(given) ? lastComponent(given) : given);
139
- }
140
- /**
141
- * The name a daily-note header stores: letters, digits and hyphens, and nothing else, because the header's marks (`+esc`,
142
- * `, UTC-03:00`) are told apart from a source name by what a name cannot hold (dailyNote.ts). Every run of other characters
143
- * is written as one hyphen instead of being deleted, none at either end; accents are composed first (a macOS file name is
144
- * decomposed) and a combining mark that cannot be composed is dropped. It may be empty.
145
- */
146
- function headerSource(source) {
147
- return cleanSource(source)
148
- .normalize('NFC')
149
- .replace(/\p{M}+/gu, '')
150
- .replace(/[^\p{L}\p{N}]+/gu, '-')
151
- .replace(/^-|-$/g, '');
152
- }
153
- /**
154
- * The hive name of a connection, on stdio and on hosted HTTP. It is the daily-note header form, so two
155
- * spellings a header cannot tell apart are one agent. All transports first use the gateway's shared
156
- * header-safe reduction, including its stable hash for names with no HTTP-renderable characters.
157
- * An empty final header form, or the reserved word `unnamed`, is no name.
158
- */
159
- function hiveIdentity(raw) {
160
- if (typeof raw !== 'string')
161
- return null;
162
- const rendered = headerSource((0, hiveNameHeader_cjs_1.hiveNameHeader)(raw));
163
- if (rendered === '' || rendered === 'unnamed')
164
- return null;
165
- return rendered;
166
- }
167
- /**
168
- * The product a client names in its User-Agent: `claude-code/2.1.289 (external, cli)` is `claude-code`. It is the name to
169
- * give a memory the client saved without saying who it is. Undefined when there is no product with a letter or a digit in it.
170
- */
171
- function productFromUserAgent(userAgent) {
172
- const header = Array.isArray(userAgent) ? userAgent[0] : userAgent;
173
- if (typeof header !== 'string')
174
- return undefined;
175
- const product = /^\s*([^\s/()]+)/.exec(header)?.[1];
176
- return product !== undefined && headerSource(product) !== '' ? product : undefined;
177
- }
178
- /**
179
- * The prefix every imported fact's ledger source carries (importing/plan.ts), and only an import's: it is how a read tells
180
- * an imported fact from an agent's save. A named connection's author is a header name, which has no colon, so a named agent
181
- * cannot write it; a source a caller chose (typed, or the product in its User-Agent) is kept off it by savedSource.
182
- */
183
- exports.IMPORT_SOURCE_PREFIX = 'import:';
184
- /** Whether a stored source names an import (`import:markdown`, `import:renor-index`). */
185
- function isImportSource(source) {
186
- return typeof source === 'string' && source.startsWith(exports.IMPORT_SOURCE_PREFIX);
187
- }
188
- /**
189
- * The ledger source of a save a caller made (remember, save_memory, retire, restore): `cleanSource`, with the import prefix
190
- * written as a hyphen (`import:markdown` is `import-markdown`, as a note header writes it), so no caller records a save
191
- * the way an import is recorded. The import path writes its events itself and never comes through here.
192
- */
193
- function savedSource(source) {
194
- const name = cleanSource(source);
195
- return isImportSource(name) ? `import-${name.slice(exports.IMPORT_SOURCE_PREFIX.length)}` : name;
196
- }
197
- /**
198
- * The identities no caller may write as: the roles a model reads as authority (system, developer, assistant), Renor itself,
199
- * and the workspace's admin, owner and tools. A typed source or a User-Agent product that names one is refused or dropped
200
- * (mvp/server.ts callerSource and sourceOf), and a trusted connection name that names one is unnamed.
201
- */
202
- const RESERVED_SOURCE_IDENTITIES = new Set(['system', 'developer', 'assistant', 'renor', 'admin', 'owner', 'tool']);
203
- /**
204
- * The reserved identities a name a CLIENT chooses may not even start with: `System Message`, `system-prompt`,
205
- * `developer note`, `renor-engine` and `Renor Support` read as the role or as Renor. Only a whole first word counts
206
- * (`system2`, `ecosystem` and `my-system` are ordinary names), and admin, owner and tool are reserved as whole names only
207
- * (`Admin Bot`, `toolbox`). A name the OWNER chose (a gateway key's, from the dashboard) is held to the exact rule only, so a
208
- * key called `Developer Laptop` or `Renor CLI` keeps its name, and so does what a read shows of a stored source.
209
- */
210
- const RESERVED_LEADING_WORDS = new Set(['system', 'developer', 'assistant', 'renor']);
211
- const SOURCE_IDENTITY_SEPARATORS = /[ ._-]/g;
212
- /** The digits and signs a typed name can stand in for a letter with (`SYST3M`, `0wner`). `1` is tried as both i and l. */
213
- const DIGIT_LOOKALIKES = { '0': 'o', '3': 'e', '4': 'a', '5': 's', '7': 't', '@': 'a', '$': 's' };
214
- const EXACT_RULE = { leadingWords: false, digits: false };
215
- const CLIENT_RULE = { leadingWords: true, digits: true };
216
- /** The lower-case forms a name is judged in: NFKC, accents dropped, and (with `digits`) its digit look-alikes read as letters. */
217
- function judgedForms(source, digits) {
218
- const base = source.normalize('NFKC').normalize('NFD').replace(/\p{M}+/gu, '').toLowerCase();
219
- if (!digits)
220
- return [base];
221
- const letters = base.replace(/[03457@$]/g, ch => DIGIT_LOOKALIKES[ch]);
222
- return [...new Set([letters.replace(/1/g, 'i'), letters.replace(/1/g, 'l')])];
223
- }
224
- /** The reserved identity a writer spelling claims under `rule`: the whole name, its `role:` prefix, or its first word. */
225
- function reservedSourceIdentity(source, rule) {
226
- for (const lower of judgedForms(source, rule.digits)) {
227
- const identity = lower.replace(SOURCE_IDENTITY_SEPARATORS, '');
228
- if (RESERVED_SOURCE_IDENTITIES.has(identity))
229
- return identity;
230
- const colon = lower.indexOf(':');
231
- const authorityPrefix = colon < 0 ? null : lower.slice(0, colon).replace(SOURCE_IDENTITY_SEPARATORS, '');
232
- if (authorityPrefix !== null && RESERVED_SOURCE_IDENTITIES.has(authorityPrefix))
233
- return authorityPrefix;
234
- if (!rule.leadingWords)
235
- continue;
236
- const firstWord = lower.split(/[^\p{L}\p{N}]+/u).find(word => word !== '');
237
- if (firstWord !== undefined && RESERVED_LEADING_WORDS.has(firstWord))
238
- return firstWord;
239
- }
240
- return null;
241
- }
242
- /** The reserved identity under any spelling a write persists: the name as given, the fact's cleanSource and the note's headerSource. */
243
- function reservedUnder(source, rule) {
244
- for (const form of [source, cleanSource(source), headerSource(source)]) {
245
- const reserved = reservedSourceIdentity(form, rule);
246
- if (reserved)
247
- return reserved;
248
- }
249
- return null;
250
- }
251
- /**
252
- * The reserved identity a name a client chose would claim: a typed `source`, a User-Agent product, or a self-hosted OAuth
253
- * client_name (the client registers it). The exact rule, plus a reserved first word and digit look-alikes.
254
- */
255
- function reservedCallerSource(source) {
256
- return reservedUnder(source, CLIENT_RULE);
257
- }
258
- /**
259
- * The reserved identity a name claims exactly (whole name or `role:` prefix, fullwidth and accents folded): the rule for a
260
- * gateway key's name, which the owner chose, and for what a read shows of a stored source. Paths, URLs, truncation and
261
- * punctuation folding cannot manufacture one past this.
262
- */
263
- function reservedSourceIn(source) {
264
- return reservedUnder(source, EXACT_RULE);
265
- }
266
- /** Whether a stored source names a reserved identity: one saved before the rule, or written into a file by hand. */
267
- function isReservedSource(source) {
268
- return typeof source === 'string' && source !== '' && reservedSourceIn(source) !== null;
269
- }
270
- function authorMarker(author, reader) {
271
- const fromOther = typeof author === 'string' && author !== '' && author !== reader;
272
- return {
273
- ...(fromOther ? { source: author } : {}),
274
- ...(isImportSource(author) || isReservedSource(author) ? { untrusted: true } : {}),
275
- };
276
- }
@@ -1,61 +0,0 @@
1
- "use strict";
2
- /**
3
- * Short-lived status kept from misleading later readers (RENOR_STATUS_FRESHNESS, default OFF).
4
- *
5
- * Agents save status as facts ("PR 648 is not merged", "main is at 3f9a1c2", "12 tests failing") that are wrong within
6
- * hours. A fact is status-like when its subject/predicate/object names the state of a PR, commit, branch, build or
7
- * count. Such a fact has a freshness window counted from its `validFrom`; once past it, a read labels it `stale`
8
- * (`label`) or leaves it out (`hide`). Decisions, preferences and standing rules never match, so they are unaffected.
9
- * Nothing is stored or rewritten: the window is derived from the saved text, so turning the switch on or off changes
10
- * only what a read shows.
11
- */
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.STATUS_FRESHNESS_FLAG = void 0;
14
- exports.statusFreshnessMode = statusFreshnessMode;
15
- exports.statusWindowHours = statusWindowHours;
16
- exports.staleStatusOf = staleStatusOf;
17
- exports.STATUS_FRESHNESS_FLAG = 'RENOR_STATUS_FRESHNESS';
18
- function statusFreshnessMode(env = process.env) {
19
- const raw = (env[exports.STATUS_FRESHNESS_FLAG] ?? '').trim().toLowerCase();
20
- if (raw === 'hide')
21
- return 'hide';
22
- return raw === '1' || raw === 'true' || raw === 'yes' || raw === 'on' || raw === 'label' ? 'label' : 'off';
23
- }
24
- const HOUR = 3_600_000;
25
- /** Standing wording wins over status wording: "always check whether the PR is merged" is a rule, not a status. */
26
- const DURABLE = /\b(always|never|must|should|prefers?|policy|rule|convention|decid(?:ed|es|ion)|we (?:use|chose)|going forward|by default)\b/i;
27
- const PATTERNS = [
28
- // PR / issue / CI state
29
- { re: /\b(?:pr|pull request|issue)\s*#?\d+\b.*\b(?:open|closed|merged|not merged|unmerged|draft|approved|blocked|failing|passing|green|red|in review|waiting)\b/i, hours: 12 },
30
- { re: /\b(?:ci|build|checks?|pipeline|tests?)\b.*\b(?:failing|passing|green|red|broken|failed|flaky)\b/i, hours: 12 },
31
- { re: /\bnot (?:yet )?(?:merged|deployed|released|reviewed|pushed|shipped)\b/i, hours: 12 },
32
- // commit / branch heads
33
- { re: /\b(?:main|master|develop|head|branch\s+\S+|origin\/\S+)\b.*\b(?:is at|points? to|at commit|head is|is on)\b.*\b[0-9a-f]{7,40}\b/i, hours: 6 },
34
- { re: /\b(?:latest|current|last) (?:commit|release|deploy(?:ment)?|version|build)\b/i, hours: 24 },
35
- // counts that change
36
- { re: /\b\d+\s+(?:open\s+)?(?:prs?|pull requests|issues|tests?|failures|errors|todos?|tasks?)\s+(?:open|failing|passing|remaining|left|pending)\b/i, hours: 24 },
37
- ];
38
- /** Hours the fact stays fresh, or null when it is not status-like. */
39
- function statusWindowHours(fact) {
40
- const text = `${fact.subject} ${fact.predicate.replace(/_/g, ' ')} ${fact.object}`;
41
- if (DURABLE.test(text))
42
- return null;
43
- for (const { re, hours } of PATTERNS)
44
- if (re.test(text))
45
- return hours;
46
- return null;
47
- }
48
- /** Set when a status-like fact is past its window at `now`. */
49
- function staleStatusOf(fact, now = Date.now()) {
50
- const hours = statusWindowHours(fact);
51
- if (hours === null)
52
- return null;
53
- const saved = Date.parse(fact.validFrom);
54
- if (Number.isNaN(saved))
55
- return null;
56
- const age = now - saved;
57
- if (age <= hours * HOUR)
58
- return null;
59
- const ago = age >= 48 * HOUR ? `${Math.floor(age / (24 * HOUR))} days` : `${Math.floor(age / HOUR)} hours`;
60
- return `status saved ${ago} ago; likely out of date, verify before relying on it`;
61
- }