bunnyquery 1.17.0 → 1.18.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/bunnyquery.js +13 -8
- package/dist/engine.cjs +13 -7
- package/dist/engine.cjs.map +1 -1
- package/dist/engine.d.mts +14 -1
- package/dist/engine.d.ts +14 -1
- package/dist/engine.mjs +13 -8
- package/dist/engine.mjs.map +1 -1
- package/package.json +1 -1
- package/src/engine/links.ts +28 -8
- package/src/engine/prompts/chat_system_prompt.ts +6 -1
- package/src/engine/retrieval_memory.ts +16 -8
package/package.json
CHANGED
package/src/engine/links.ts
CHANGED
|
@@ -206,6 +206,24 @@ export function encodePathSegments(path: string): string {
|
|
|
206
206
|
return path.split('/').filter(Boolean).map(function (s) { return encodeURIComponent(s); }).join('/');
|
|
207
207
|
}
|
|
208
208
|
|
|
209
|
+
/**
|
|
210
|
+
* A stored-file path the MODEL wrote (a `db:` link target or a `src::` token).
|
|
211
|
+
*
|
|
212
|
+
* The prompt says the path is written exactly as stored, NOT url-encoded, and
|
|
213
|
+
* models do not always obey: a GPT answer linked `db:testing/2023-09%20(1).xlsx`
|
|
214
|
+
* for the stored file `testing/2023-09 (1).xlsx`, and the chip minted a url for a
|
|
215
|
+
* key that does not exist. A stored name CAN contain a literal "%20" too, which
|
|
216
|
+
* is why this does not decode unconditionally. The two are told apart by the one
|
|
217
|
+
* thing an encoder never leaves behind: raw whitespace. A path with a real space
|
|
218
|
+
* in it was not encoded and is kept as written; a path with no whitespace and a
|
|
219
|
+
* valid %XX escape was, and is decoded.
|
|
220
|
+
*/
|
|
221
|
+
export function normalizeStoredPathTarget(value: string): string {
|
|
222
|
+
var p = String(value || '').trim().replace(/\\/g, '/').replace(/^\/+/, '').replace(/\/+/g, '/');
|
|
223
|
+
if (!/\s/.test(p) && /%[0-9A-Fa-f]{2}/.test(p)) p = safeDecodeURIComponent(p);
|
|
224
|
+
return p;
|
|
225
|
+
}
|
|
226
|
+
|
|
209
227
|
export function normalizeAttachmentPathCandidate(value: string): string {
|
|
210
228
|
return safeDecodeURIComponent((value || '').trim()).replace(/\\/g, '/').replace(/^\/+/, '').replace(/\/+/g, '/');
|
|
211
229
|
}
|
|
@@ -529,9 +547,9 @@ export function classifyInlineLink(
|
|
|
529
547
|
var srcPath = readExpiredAttachmentHref(rawPath)
|
|
530
548
|
|| (srcIsUrl
|
|
531
549
|
? (extractRemotePathFromAttachmentHref(rawPath, ctx.projectId) || normalizeAttachmentPathCandidate(rawPath))
|
|
532
|
-
// bare stored path: same
|
|
533
|
-
//
|
|
534
|
-
: rawPath
|
|
550
|
+
// bare stored path: same normalize as the db: branch (decoded only when
|
|
551
|
+
// the model visibly url-encoded it, see normalizeStoredPathTarget).
|
|
552
|
+
: normalizeStoredPathTarget(rawPath));
|
|
535
553
|
var srcBuilt = asStoredFile(srcPath, srcPath);
|
|
536
554
|
return srcBuilt ? { part: srcBuilt.part, tail: tail } : null;
|
|
537
555
|
}
|
|
@@ -546,11 +564,13 @@ export function classifyInlineLink(
|
|
|
546
564
|
// EMITTING it; until then this branch simply never fires.
|
|
547
565
|
var dbTarget = /^db:(.+)$/i.exec(g5.trim());
|
|
548
566
|
if (dbTarget) {
|
|
549
|
-
//
|
|
550
|
-
//
|
|
551
|
-
//
|
|
552
|
-
//
|
|
553
|
-
|
|
567
|
+
// The prompt asks for the path exactly as stored, NOT url-encoded, and the
|
|
568
|
+
// MCP's own key builder never decodes a bare path. Decoding every target
|
|
569
|
+
// turned a stored name containing a literal "%20" into the wrong key, and
|
|
570
|
+
// decoding none sent a model's encoded `2023-09%20(1).xlsx` to a key that
|
|
571
|
+
// does not exist. normalizeStoredPathTarget decodes only the visibly encoded.
|
|
572
|
+
// A markdown title, `[a](db:x.pdf "title")`, is not part of the path.
|
|
573
|
+
var rawDbPath = normalizeStoredPathTarget(dbTarget[1].replace(/\s+"[^"\n]*"\s*$/, ''));
|
|
554
574
|
var declared = asStoredFile(rawDbPath, g4);
|
|
555
575
|
if (!declared) return null;
|
|
556
576
|
declared.part.label = truncateLabelForDisplay(g4);
|
|
@@ -112,8 +112,13 @@ These three rules govern every claim about the project's data. They do not limit
|
|
|
112
112
|
// readFileContent; nothing found is said as such. The last sentence follows
|
|
113
113
|
// the web switch: with the web off the chat has no such tool, with it on a web
|
|
114
114
|
// fact must be marked as one. Additive: the rules around it are unchanged.
|
|
115
|
+
// Quick search first (2026-11-15): a file the user names is found by getUniqueId gte / lte and
|
|
116
|
+
// searched by path. "Find a file that contains X" is searchText WITHOUT path, which narrows by
|
|
117
|
+
// itself (the MCP reads every file named like the query first, across calls): quick results are
|
|
118
|
+
// given and the full search is offered once (cursor = full_scan_cursor, which leaves the quick
|
|
119
|
+
// files out); with no quick match the full search runs unasked.
|
|
115
120
|
const documentRules =
|
|
116
|
-
`DOCUMENTS (a contract, a report, a manual, a letter, any uploaded file the user asks about the content of): FIRST FIND THE FILE, with getFileOutline when you know its storage path, otherwise with getUniqueId using unique_id "src::" and condition "gte" (narrow it by the name the user used). THEN FIND THE PAGE: call searchText with the file's path and the words the user asked about; it returns the file, the page and the matching excerpt. QUOTE THE EXACT TEXT it returned and CITE THE FILE AND THE PAGE ("report.pdf, page 7"); never present a paraphrase as a quote. If searchText answers no_page_text, the file was indexed before page text existed: read it with readFileContent instead, paging with the cursor until END OF FILE, and cite the file. When searchText and the file's records come back empty over files that HAVE page text, say that the data does not have it and name the files and the terms you searched. Never fill the gap from your general knowledge, and never from the web${webAccess
|
|
121
|
+
`DOCUMENTS (a contract, a report, a manual, a letter, any uploaded file the user asks about the content of): FIRST FIND THE FILE, with getFileOutline when you know its storage path, otherwise with getUniqueId using unique_id "src::" and condition "gte" (narrow it by the name the user used; condition "lte" with the file name alone finds it in any folder). THEN FIND THE PAGE: call searchText with the file's path and the words the user asked about; it returns the file, the page and the matching excerpt. When the user did not name a file ("find a file that contains X"), call searchText WITHOUT path: it narrows by itself. It first searches every file whose name matches: while quick_complete is false, keep its hits and call again with next_cursor without answering yet. When quick_complete is true, give the quick results, then ALWAYS ask the user once whether they want all files searched too, since they may be looking for something else, and only if they say yes call searchText again with cursor = full_scan_cursor (it leaves out the files already searched). With no quick match it searches every other file itself: follow next_cursor until search_complete is true, and once its hits answer the question, answer and ask the user before reading the rest. QUOTE THE EXACT TEXT it returned and CITE THE FILE AND THE PAGE ("report.pdf, page 7"); never present a paraphrase as a quote. If searchText answers no_page_text, the file was indexed before page text existed: read it with readFileContent instead, paging with the cursor until END OF FILE, and cite the file. When searchText and the file's records come back empty over files that HAVE page text, say that the data does not have it and name the files and the terms you searched. Never fill the gap from your general knowledge, and never from the web${webAccess
|
|
117
122
|
? ` without saying so. WEB ACCESS IS ON for this project: when the user asks for something that is not in the project's data, you may search the web for it, but every such fact must be marked as coming from the web (name the site), kept apart from what the project's data says, and never used to fill in or complete a document's content. This is the one exception to the four sources named above.`
|
|
118
123
|
: `: this chat has no web tool.`}`;
|
|
119
124
|
|
|
@@ -37,6 +37,8 @@
|
|
|
37
37
|
* requests to today.
|
|
38
38
|
*/
|
|
39
39
|
|
|
40
|
+
import { normalizeStoredPathTarget, normalizeTrailingInlineToken } from './links';
|
|
41
|
+
|
|
40
42
|
export type RetrievalHit = { path: string; page: number };
|
|
41
43
|
|
|
42
44
|
export type RetrievalNote = {
|
|
@@ -259,16 +261,22 @@ function noteFromToolBlocks(body: any): RetrievalNote | null {
|
|
|
259
261
|
export function retrievalNoteFromText(text: string | null | undefined): RetrievalNote | null {
|
|
260
262
|
if (typeof text !== 'string' || !text) return null;
|
|
261
263
|
var note = emptyNote('answer');
|
|
262
|
-
// [label](db:path) and [label](db:path "title")
|
|
263
|
-
//
|
|
264
|
-
//
|
|
265
|
-
|
|
264
|
+
// [label](db:path) and [label](db:path "title"). The path is read with the SAME
|
|
265
|
+
// grammar the chip renderer uses (createInlineLinkRegex's path branch): spaces
|
|
266
|
+
// allowed, one level of balanced parens. The old `[^)\s"]+` stopped at the
|
|
267
|
+
// first space or ")", so `db:testing/2023-09 (1).xlsx` was remembered as
|
|
268
|
+
// `testing/2023-09` and the encoded form as `testing/2023-09%20(1`, and the
|
|
269
|
+
// citation chip drawn from this note linked to a file that does not exist.
|
|
270
|
+
// One character per step and disjoint alternatives, so it stays linear.
|
|
271
|
+
var link = /\]\(db:((?:[^()\n"]|\([^()\n"]*\))+)(?:"[^"\n]*")?\)/g;
|
|
266
272
|
var m: RegExpExecArray | null;
|
|
267
|
-
while ((m = link.exec(text)) !== null) pushUnique(note.files, m[1]);
|
|
268
|
-
|
|
273
|
+
while ((m = link.exec(text)) !== null) pushUnique(note.files, normalizeStoredPathTarget(m[1]));
|
|
274
|
+
// src::<token>, read exactly as classifyInlineLink reads it: the token runs to
|
|
275
|
+
// whitespace and normalizeTrailingInlineToken drops sentence punctuation and
|
|
276
|
+
// unmatched wrappers while keeping a balanced `(1)` inside the name.
|
|
277
|
+
var src = /src::(\S+)/g;
|
|
269
278
|
while ((m = src.exec(text)) !== null) {
|
|
270
|
-
|
|
271
|
-
pushUnique(note.files, m[1].replace(/[.,;:!?]+$/, ''));
|
|
279
|
+
pushUnique(note.files, normalizeStoredPathTarget(normalizeTrailingInlineToken(m[1])));
|
|
272
280
|
}
|
|
273
281
|
return noteHasContent(note) ? note : null;
|
|
274
282
|
}
|