@ngockhoale/ukit 3.5.4 → 3.5.5
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/CHANGELOG.md +15 -0
- package/package.json +3 -2
- package/src/cli/commands/memory.js +11 -0
- package/src/core/memory/memoryCheckRun.js +13 -1
- package/src/core/memory/memoryHit.js +31 -15
- package/src/core/memory/recallEngine.js +39 -3
- package/src/core/memory/recallLanes.js +182 -0
- package/src/core/memory/retrieval.js +13 -1
- package/src/core/memory/topicCommand.js +75 -0
- package/src/core/memory/topicPages.js +545 -0
- package/src/core/runtimeConfig.js +45 -0
- package/src/decision/registry.js +17 -0
- package/src/index/buildIndex.js +287 -6
- package/src/index/languageTools.js +100 -0
- package/src/index/paths.js +2 -1
- package/src/index/queryIndex.js +134 -7
- package/template_project/.claude/ukit/index/lib/index-core.mjs +519 -11
- package/template_project/.claude/ukit/index/refresh-index.mjs +11 -0
- package/template_project/.claude/ukit/runtime/memory-lanes.mjs +9 -2
- package/template_project/.claude/ukit/runtime/memory-recall.mjs +39 -3
- package/template_project/.claude/ukit/runtime/memory-topics.mjs +545 -0
- package/template_project/ukit/storage/config.json +19 -2
- package/manifests/instructionRules.yaml +0 -442
package/src/index/buildIndex.js
CHANGED
|
@@ -150,11 +150,11 @@ const EXCLUDED_DIR_NAMES = new Set([
|
|
|
150
150
|
'.venv',
|
|
151
151
|
'venv',
|
|
152
152
|
]);
|
|
153
|
-
const CODE_EXTENSIONS = new Set(['.js', '.mjs', '.cjs', '.ts', '.tsx', '.jsx', '.vue', '.sql']);
|
|
153
|
+
const CODE_EXTENSIONS = new Set(['.js', '.mjs', '.cjs', '.ts', '.tsx', '.jsx', '.vue', '.svelte', '.py', '.go', '.java', '.cs', '.php', '.rb', '.rs', '.sql']);
|
|
154
154
|
const STYLE_EXTENSIONS = new Set(['.css', '.scss', '.sass', '.less']);
|
|
155
155
|
// `.sh` is tracked but never parsed, like `.md`/`.json`/`.yaml` — it is matched
|
|
156
156
|
// by path only. Without it every shipped hook script was invisible to the index.
|
|
157
|
-
const TRACKED_EXTENSIONS = new Set(['.js', '.mjs', '.cjs', '.ts', '.tsx', '.jsx', '.vue', '.sql', '.json', '.yaml', '.yml', '.md', '.sh']);
|
|
157
|
+
const TRACKED_EXTENSIONS = new Set(['.js', '.mjs', '.cjs', '.ts', '.tsx', '.jsx', '.vue', '.svelte', '.py', '.go', '.java', '.cs', '.php', '.rb', '.rs', '.sql', '.json', '.yaml', '.yml', '.md', '.sh']);
|
|
158
158
|
const DISCOVERED_EXTENSIONS = new Set([...TRACKED_EXTENSIONS, ...STYLE_EXTENSIONS]);
|
|
159
159
|
export const DEFAULT_INDEX_CACHE_MAX_AGE_MS = 24 * 60 * 60 * 1000;
|
|
160
160
|
// Bumped only when the snapshot shape itself changes; consumers must reject
|
|
@@ -1586,7 +1586,7 @@ function findScriptClose(content, startIndex) {
|
|
|
1586
1586
|
}
|
|
1587
1587
|
|
|
1588
1588
|
export function extractScriptContent(filePath, content) {
|
|
1589
|
-
if (
|
|
1589
|
+
if (!/\.(?:vue|svelte)$/.test(filePath)) {
|
|
1590
1590
|
return content;
|
|
1591
1591
|
}
|
|
1592
1592
|
|
|
@@ -1682,6 +1682,278 @@ function computeSignature(content, lineStartIndex) {
|
|
|
1682
1682
|
return `${collapsed.slice(0, 199)}…`;
|
|
1683
1683
|
}
|
|
1684
1684
|
|
|
1685
|
+
// ── Non-JS languages (3.5.5): line/indent/brace based, no parser. Rows are { name, type, index, parent? }.
|
|
1686
|
+
// Kinds follow the JS lane: exported/public top-level -> function|class, private -> local-*, members -> method,
|
|
1687
|
+
// interface/enum/struct/trait/type aliases -> type.
|
|
1688
|
+
const POLYGLOT_EXT = /\.(?:py|go|java|cs|php|rb|rs)$/i;
|
|
1689
|
+
const POLY_MEMBER_SKIP = new Set(['if', 'for', 'while', 'switch', 'catch', 'return', 'new', 'else', 'throw', 'using', 'lock', 'foreach', 'fixed', 'match', 'await', 'yield', 'do', 'try', 'sizeof', 'typeof', 'nameof', 'default', 'when', 'base', 'this']);
|
|
1690
|
+
const POLY_MODS = '(?:(?:public|protected|private|internal|static|final|abstract|sealed|partial|readonly|virtual|override|async|extern|unsafe|new|synchronized|native|strictfp|default|open)\\s+)*';
|
|
1691
|
+
const POLY_JAVA_TYPE_RE = new RegExp(`^[ \\t]*(?:@\\w+(?:\\([^)]*\\))?\\s+)*${POLY_MODS}(class|interface|enum|struct|record(?:\\s+(?:class|struct))?)\\s+([A-Za-z_]\\w*)`);
|
|
1692
|
+
const POLY_JAVA_METHOD_RE = new RegExp(`^[ \\t]*(?:@\\w+(?:\\([^)]*\\))?\\s+)*(?:<[^>]+>\\s+)?(?:[\\w.<>\\[\\],?]+\\s+)*?([A-Za-z_]\\w*)[ \\t]*(?:<[^>()]*>[ \\t]*)?\\(`);
|
|
1693
|
+
const POLY_PHP_TYPE_RE = /^[ \t]*(?:(?:abstract|final|readonly)\s+)*(class|interface|trait|enum)\s+([A-Za-z_]\w*)/;
|
|
1694
|
+
const POLY_PHP_FUNC_RE = /^[ \t]*(?:(?:public|protected|private|static|abstract|final)\s+)*function[ \t]+(?:&[ \t]*)?([A-Za-z_]\w*)/;
|
|
1695
|
+
const POLY_RS_PUB = '(?:pub(?:\\([^)]*\\))?\\s+)?';
|
|
1696
|
+
const POLY_RS_FN_RE = new RegExp(`^[ \\t]*(${POLY_RS_PUB})(?:(?:default|const|async|unsafe)\\s+)*(?:extern\\s+(?:"[^"]*"\\s+)?)?fn\\s+([A-Za-z_]\\w*)`);
|
|
1697
|
+
const POLY_RS_TYPE_RE = new RegExp(`^[ \\t]*${POLY_RS_PUB}(struct|enum|union|type)\\s+([A-Za-z_]\\w*)`);
|
|
1698
|
+
const POLY_RS_TRAIT_RE = new RegExp(`^[ \\t]*${POLY_RS_PUB}(?:unsafe\\s+)?trait\\s+([A-Za-z_]\\w*)`);
|
|
1699
|
+
// Bounds against pathological input (regex stalls): files above 512 KB (the content-lane per-file cap) are not
|
|
1700
|
+
// extracted, and any line over 2000 chars is blanked in place (offsets preserved) before the per-line patterns run.
|
|
1701
|
+
const POLY_MAX_FILE_CHARS = 512 * 1024;
|
|
1702
|
+
const POLY_MAX_LINE_CHARS = 2000;
|
|
1703
|
+
// impl header -> implemented type name, without a backtracking pattern: skip a balanced <generics>, then the
|
|
1704
|
+
// type after the first `for` (trait impl) or the first identifier (inherent impl).
|
|
1705
|
+
function polyRsImplName(line) {
|
|
1706
|
+
const head = /^[ \t]*(?:unsafe[ \t]+)?impl\b/.exec(line);
|
|
1707
|
+
if (!head) return null;
|
|
1708
|
+
let rest = line.slice(head[0].length).replace(/^[ \t]+/, '');
|
|
1709
|
+
if (rest[0] === '<') {
|
|
1710
|
+
let depth = 0;
|
|
1711
|
+
let k = 0;
|
|
1712
|
+
for (; k < rest.length; k += 1) {
|
|
1713
|
+
if (rest[k] === '<') depth += 1;
|
|
1714
|
+
else if (rest[k] === '>' && (depth -= 1) === 0) break;
|
|
1715
|
+
}
|
|
1716
|
+
rest = rest.slice(k + 1);
|
|
1717
|
+
}
|
|
1718
|
+
const cut = rest.search(/[{]|[ \t]where\b/);
|
|
1719
|
+
const header = cut < 0 ? rest : rest.slice(0, cut);
|
|
1720
|
+
const forAt = header.search(/(?:^|[ \t])for[ \t]/);
|
|
1721
|
+
const target = forAt < 0 ? header : header.slice(forAt).replace(/^[ \t]*for[ \t]+/, '');
|
|
1722
|
+
return /^[ \t]*([A-Za-z_]\w*)/.exec(target)?.[1] ?? null;
|
|
1723
|
+
}
|
|
1724
|
+
const POLY_RS_MOD_RE = new RegExp(`^[ \\t]*${POLY_RS_PUB}mod\\s+([A-Za-z_]\\w*)`);
|
|
1725
|
+
|
|
1726
|
+
// Same-length copy with comments (and, per mode, string bodies) blanked, so offsets/lines stay valid.
|
|
1727
|
+
// mode 0 = comments only, 1 = + "strings", 2 = + "strings" and 'chars'.
|
|
1728
|
+
function maskCLike(content, mode) {
|
|
1729
|
+
const out = content.split('');
|
|
1730
|
+
const n = content.length;
|
|
1731
|
+
const blank = (from, to) => {
|
|
1732
|
+
for (let k = from; k < to; k += 1) {
|
|
1733
|
+
if (out[k] !== '\n') out[k] = ' ';
|
|
1734
|
+
}
|
|
1735
|
+
};
|
|
1736
|
+
let i = 0;
|
|
1737
|
+
while (i < n) {
|
|
1738
|
+
const c = content[i];
|
|
1739
|
+
const d = content[i + 1];
|
|
1740
|
+
if (c === '/' && d === '/') {
|
|
1741
|
+
let end = content.indexOf('\n', i);
|
|
1742
|
+
if (end < 0) end = n;
|
|
1743
|
+
blank(i, end);
|
|
1744
|
+
i = end;
|
|
1745
|
+
} else if (c === '/' && d === '*') {
|
|
1746
|
+
let end = content.indexOf('*/', i + 2);
|
|
1747
|
+
end = end < 0 ? n : end + 2;
|
|
1748
|
+
blank(i, end);
|
|
1749
|
+
i = end;
|
|
1750
|
+
} else if ((mode >= 1 && c === '"') || (mode >= 2 && c === "'")) {
|
|
1751
|
+
let k = i + 1;
|
|
1752
|
+
while (k < n && content[k] !== c && content[k] !== '\n') {
|
|
1753
|
+
if (content[k] === '\\') k += 1;
|
|
1754
|
+
k += 1;
|
|
1755
|
+
}
|
|
1756
|
+
blank(i + 1, Math.min(k, n));
|
|
1757
|
+
i = k + 1;
|
|
1758
|
+
} else {
|
|
1759
|
+
i += 1;
|
|
1760
|
+
}
|
|
1761
|
+
}
|
|
1762
|
+
return out.join('');
|
|
1763
|
+
}
|
|
1764
|
+
|
|
1765
|
+
function extractIndentLanguageSymbols(filePath, content) {
|
|
1766
|
+
const isPy = /\.py$/i.test(filePath);
|
|
1767
|
+
const scopeRe = isPy ? /^([ \t]*)class[ \t]+([A-Za-z_]\w*)/ : /^([ \t]*)(?:module|class)[ \t]+([A-Z][\w:]*)/;
|
|
1768
|
+
const defRe = isPy ? /^([ \t]*)(?:async[ \t]+)?def[ \t]+([A-Za-z_]\w*)/ : /^([ \t]*)def[ \t]+(?:[A-Za-z_]\w*\.)?([A-Za-z_]\w*[?!=]?)/;
|
|
1769
|
+
const rows = [];
|
|
1770
|
+
const stack = [];
|
|
1771
|
+
let docQuote = null;
|
|
1772
|
+
let offset = 0;
|
|
1773
|
+
for (const line of content.split('\n')) {
|
|
1774
|
+
const lineStart = offset;
|
|
1775
|
+
offset += line.length + 1;
|
|
1776
|
+
const startedInDoc = docQuote !== null;
|
|
1777
|
+
if (isPy) {
|
|
1778
|
+
for (const quote of ['"""', "'''"]) {
|
|
1779
|
+
const count = line.split(quote).length - 1;
|
|
1780
|
+
if (count % 2 === 1) docQuote = docQuote === quote ? null : (docQuote ?? quote);
|
|
1781
|
+
}
|
|
1782
|
+
if (startedInDoc) continue;
|
|
1783
|
+
}
|
|
1784
|
+
const scope = scopeRe.exec(line);
|
|
1785
|
+
const def = scope ? null : defRe.exec(line);
|
|
1786
|
+
const m = scope ?? def;
|
|
1787
|
+
if (!m) continue;
|
|
1788
|
+
const indent = m[1].length;
|
|
1789
|
+
while (stack.length > 0 && stack[stack.length - 1].indent >= indent) stack.pop();
|
|
1790
|
+
const top = stack[stack.length - 1];
|
|
1791
|
+
const name = m[2];
|
|
1792
|
+
const index = lineStart + indent;
|
|
1793
|
+
if (scope) {
|
|
1794
|
+
if (!top || top.kind === 'scope') {
|
|
1795
|
+
rows.push({ name, type: isPy && name.startsWith('_') ? 'local-class' : 'class', index, parent: top?.name });
|
|
1796
|
+
}
|
|
1797
|
+
stack.push({ indent, kind: 'scope', name });
|
|
1798
|
+
} else {
|
|
1799
|
+
if (!top) {
|
|
1800
|
+
rows.push({ name, type: isPy && name.startsWith('_') ? 'local-function' : 'function', index });
|
|
1801
|
+
} else if (top.kind === 'scope') {
|
|
1802
|
+
rows.push({ name, type: 'method', index, parent: top.name });
|
|
1803
|
+
}
|
|
1804
|
+
stack.push({ indent, kind: 'def', name });
|
|
1805
|
+
}
|
|
1806
|
+
}
|
|
1807
|
+
return rows;
|
|
1808
|
+
}
|
|
1809
|
+
|
|
1810
|
+
function extractGoSymbols(content) {
|
|
1811
|
+
const text = maskCLike(content, 0);
|
|
1812
|
+
const rows = [];
|
|
1813
|
+
for (const m of text.matchAll(/^type[ \t]+([A-Za-z_]\w*)/gm)) {
|
|
1814
|
+
rows.push({ name: m[1], type: 'type', index: m.index });
|
|
1815
|
+
}
|
|
1816
|
+
for (const m of text.matchAll(/^func[ \t]+([A-Za-z_]\w*)[ \t]*[[(]/gm)) {
|
|
1817
|
+
rows.push({ name: m[1], type: /^[A-Z]/.test(m[1]) ? 'function' : 'local-function', index: m.index });
|
|
1818
|
+
}
|
|
1819
|
+
for (const m of text.matchAll(/^func[ \t]*\([ \t]*(?:[A-Za-z_]\w*[ \t]+)?(?:\*[ \t]*)?([A-Za-z_]\w*)(?:\[[^\]\n]*\])?[ \t]*\)[ \t]*([A-Za-z_]\w*)/gm)) {
|
|
1820
|
+
rows.push({ name: m[2], type: 'method', index: m.index, parent: m[1] });
|
|
1821
|
+
}
|
|
1822
|
+
return rows;
|
|
1823
|
+
}
|
|
1824
|
+
|
|
1825
|
+
// Java, C#, PHP and Rust: depth-tracked on a comment/string-masked copy. A container
|
|
1826
|
+
// (class, trait, impl, mod ...) owns the lines exactly one brace level below its declaration.
|
|
1827
|
+
function extractBraceLanguageSymbols(filePath, content) {
|
|
1828
|
+
const ext = filePath.slice(filePath.lastIndexOf('.') + 1).toLowerCase();
|
|
1829
|
+
const text = maskCLike(content, ext === 'rs' ? 1 : 2);
|
|
1830
|
+
const rows = [];
|
|
1831
|
+
const stack = [];
|
|
1832
|
+
let depth = 0;
|
|
1833
|
+
let offset = 0;
|
|
1834
|
+
for (const line of text.split('\n')) {
|
|
1835
|
+
const lineStart = offset;
|
|
1836
|
+
offset += line.length + 1;
|
|
1837
|
+
while (stack.length > 0 && stack[stack.length - 1].opened && depth <= stack[stack.length - 1].depth) stack.pop();
|
|
1838
|
+
const top = stack[stack.length - 1];
|
|
1839
|
+
const atMember = top ? depth === top.depth + 1 : false;
|
|
1840
|
+
const index = lineStart + Math.max(0, line.search(/\S/));
|
|
1841
|
+
const pushContainer = (kind, name) => {
|
|
1842
|
+
if (line.includes(';') && !line.includes('{')) return;
|
|
1843
|
+
stack.push({ kind, name, depth, opened: false });
|
|
1844
|
+
};
|
|
1845
|
+
|
|
1846
|
+
if (ext === 'java' || ext === 'cs') {
|
|
1847
|
+
const typeMatch = POLY_JAVA_TYPE_RE.exec(line);
|
|
1848
|
+
if (typeMatch) {
|
|
1849
|
+
const kind = typeMatch[1].split(/\s/)[0];
|
|
1850
|
+
rows.push({ name: typeMatch[2], type: kind === 'class' ? 'class' : 'type', index, parent: top?.name });
|
|
1851
|
+
pushContainer(kind, typeMatch[2]);
|
|
1852
|
+
} else if (atMember) {
|
|
1853
|
+
const m = POLY_JAVA_METHOD_RE.exec(line);
|
|
1854
|
+
if (m && !POLY_MEMBER_SKIP.has(m[1]) && !(top.kind === 'enum' && /^[A-Z0-9_]+$/.test(m[1]))) {
|
|
1855
|
+
rows.push({ name: m[1], type: 'method', index, parent: top.name });
|
|
1856
|
+
}
|
|
1857
|
+
}
|
|
1858
|
+
} else if (ext === 'php') {
|
|
1859
|
+
const typeMatch = POLY_PHP_TYPE_RE.exec(line);
|
|
1860
|
+
const fn = typeMatch ? null : POLY_PHP_FUNC_RE.exec(line);
|
|
1861
|
+
if (typeMatch) {
|
|
1862
|
+
rows.push({ name: typeMatch[2], type: typeMatch[1] === 'class' ? 'class' : 'type', index, parent: top?.name });
|
|
1863
|
+
pushContainer(typeMatch[1], typeMatch[2]);
|
|
1864
|
+
} else if (fn && !top) {
|
|
1865
|
+
rows.push({ name: fn[1], type: 'function', index });
|
|
1866
|
+
} else if (fn && atMember) {
|
|
1867
|
+
rows.push({ name: fn[1], type: 'method', index, parent: top.name });
|
|
1868
|
+
}
|
|
1869
|
+
} else {
|
|
1870
|
+
const fn = POLY_RS_FN_RE.exec(line);
|
|
1871
|
+
const trait = fn ? null : POLY_RS_TRAIT_RE.exec(line);
|
|
1872
|
+
const impl = fn || trait ? null : polyRsImplName(line);
|
|
1873
|
+
const mod = fn || trait || impl ? null : POLY_RS_MOD_RE.exec(line);
|
|
1874
|
+
const typeMatch = fn || trait || impl || mod ? null : POLY_RS_TYPE_RE.exec(line);
|
|
1875
|
+
const atModuleLevel = top ? top.kind === 'mod' && atMember : depth === 0;
|
|
1876
|
+
if (fn) {
|
|
1877
|
+
const container = top && (top.kind === 'impl' || top.kind === 'trait');
|
|
1878
|
+
if (container && atMember) {
|
|
1879
|
+
rows.push({ name: fn[2], type: 'method', index, parent: top.name });
|
|
1880
|
+
} else if (atModuleLevel) {
|
|
1881
|
+
rows.push({ name: fn[2], type: fn[1].trim() ? 'function' : 'local-function', index });
|
|
1882
|
+
}
|
|
1883
|
+
} else if (trait) {
|
|
1884
|
+
if (atModuleLevel) rows.push({ name: trait[1], type: 'type', index });
|
|
1885
|
+
pushContainer('trait', trait[1]);
|
|
1886
|
+
} else if (impl) {
|
|
1887
|
+
pushContainer('impl', impl);
|
|
1888
|
+
} else if (mod) {
|
|
1889
|
+
pushContainer('mod', mod[1]);
|
|
1890
|
+
} else if (typeMatch && atModuleLevel) {
|
|
1891
|
+
rows.push({ name: typeMatch[2], type: 'type', index });
|
|
1892
|
+
}
|
|
1893
|
+
}
|
|
1894
|
+
|
|
1895
|
+
let maxDepth = depth;
|
|
1896
|
+
for (let k = 0; k < line.length; k += 1) {
|
|
1897
|
+
if (line[k] === '{') {
|
|
1898
|
+
depth += 1;
|
|
1899
|
+
if (depth > maxDepth) maxDepth = depth;
|
|
1900
|
+
} else if (line[k] === '}' && depth > 0) {
|
|
1901
|
+
depth -= 1;
|
|
1902
|
+
}
|
|
1903
|
+
}
|
|
1904
|
+
for (const entry of stack) {
|
|
1905
|
+
if (!entry.opened && maxDepth > entry.depth) entry.opened = true;
|
|
1906
|
+
}
|
|
1907
|
+
}
|
|
1908
|
+
return rows;
|
|
1909
|
+
}
|
|
1910
|
+
|
|
1911
|
+
function extractPolyglotSymbols(filePath, rawContent) {
|
|
1912
|
+
if (rawContent.length > POLY_MAX_FILE_CHARS) return [];
|
|
1913
|
+
const parts = rawContent.split('\n');
|
|
1914
|
+
const content = parts.some((l) => l.length > POLY_MAX_LINE_CHARS)
|
|
1915
|
+
? parts.map((l) => (l.length > POLY_MAX_LINE_CHARS ? ' '.repeat(l.length) : l)).join('\n')
|
|
1916
|
+
: rawContent;
|
|
1917
|
+
const ext = filePath.slice(filePath.lastIndexOf('.') + 1).toLowerCase();
|
|
1918
|
+
let rows;
|
|
1919
|
+
if (ext === 'py' || ext === 'rb') rows = extractIndentLanguageSymbols(filePath, content);
|
|
1920
|
+
else if (ext === 'go') rows = extractGoSymbols(content);
|
|
1921
|
+
else rows = extractBraceLanguageSymbols(filePath, content);
|
|
1922
|
+
const seen = new Set();
|
|
1923
|
+
return rows.filter((row) => {
|
|
1924
|
+
const key = `${row.type}:${row.name}:${row.parent ?? ''}`;
|
|
1925
|
+
if (seen.has(key)) return false;
|
|
1926
|
+
seen.add(key);
|
|
1927
|
+
return true;
|
|
1928
|
+
});
|
|
1929
|
+
}
|
|
1930
|
+
|
|
1931
|
+
// `const x = (` also opens plain parenthesised expressions (`const n = (a ?? 0)`), so only a
|
|
1932
|
+
// parameter list whose closing paren is followed by `=>` (optionally after a return type) is a function.
|
|
1933
|
+
function findParenArrowDeclarations(content) {
|
|
1934
|
+
const found = [];
|
|
1935
|
+
for (const match of content.matchAll(/(?:const|let|var)\s+([A-Za-z_$][A-Za-z0-9_$]*)\s*=\s*(?:async\s*)?\(/g)) {
|
|
1936
|
+
const open = match.index + match[0].length - 1;
|
|
1937
|
+
const limit = Math.min(content.length, open + 2000);
|
|
1938
|
+
let depth = 0;
|
|
1939
|
+
let close = -1;
|
|
1940
|
+
for (let i = open; i < limit; i += 1) {
|
|
1941
|
+
if (content[i] === '(') depth += 1;
|
|
1942
|
+
else if (content[i] === ')') {
|
|
1943
|
+
depth -= 1;
|
|
1944
|
+
if (depth === 0) {
|
|
1945
|
+
close = i;
|
|
1946
|
+
break;
|
|
1947
|
+
}
|
|
1948
|
+
}
|
|
1949
|
+
}
|
|
1950
|
+
if (close >= 0 && /^\s*(?::\s*[^;\n{}=]*?(?:=>\s*[^;\n{}=]*?)?)?=>/.test(content.slice(close + 1, close + 201))) {
|
|
1951
|
+
found.push({ name: match[1], index: match.index });
|
|
1952
|
+
}
|
|
1953
|
+
}
|
|
1954
|
+
return found;
|
|
1955
|
+
}
|
|
1956
|
+
|
|
1685
1957
|
const CLASS_METHOD_SKIP = new Set(['if', 'for', 'while', 'switch', 'catch', 'function', 'return', 'with', 'constructor', 'super']);
|
|
1686
1958
|
|
|
1687
1959
|
export function extractSymbols(filePath, content) {
|
|
@@ -1709,6 +1981,13 @@ export function extractSymbols(filePath, content) {
|
|
|
1709
1981
|
}
|
|
1710
1982
|
};
|
|
1711
1983
|
|
|
1984
|
+
if (POLYGLOT_EXT.test(filePath)) {
|
|
1985
|
+
for (const row of extractPolyglotSymbols(filePath, content)) {
|
|
1986
|
+
addSymbol(row.name, row.type, row.index, row.parent ? { parent: row.parent } : null);
|
|
1987
|
+
}
|
|
1988
|
+
return symbols;
|
|
1989
|
+
}
|
|
1990
|
+
|
|
1712
1991
|
if (filePath.endsWith('.sql')) {
|
|
1713
1992
|
// Capture the object name, skipping an optional schema qualifier (qas.fn_rpt_billing → fn_rpt_billing).
|
|
1714
1993
|
const sqlIdent = '(?:(?:["`]?[A-Za-z_][A-Za-z0-9_$]*["`]?)\\s*\\.\\s*)?["`]?([A-Za-z_][A-Za-z0-9_$]*)["`]?';
|
|
@@ -1743,8 +2022,10 @@ export function extractSymbols(filePath, content) {
|
|
|
1743
2022
|
|
|
1744
2023
|
addMatches(/export\s+(?:async\s+)?function\s+([A-Za-z_$][A-Za-z0-9_$]*)/g, 'function');
|
|
1745
2024
|
addMatches(/export\s+class\s+([A-Za-z_$][A-Za-z0-9_$]*)/g, 'class');
|
|
1746
|
-
|
|
1747
|
-
|
|
2025
|
+
for (const decl of findParenArrowDeclarations(content)) {
|
|
2026
|
+
addSymbol(decl.name, 'callable', decl.index);
|
|
2027
|
+
}
|
|
2028
|
+
addMatches(/(?:const|let|var)\s+([A-Za-z_$][A-Za-z0-9_$]*)\s*=\s*(?:async\s+)?[A-Za-z_$][A-Za-z0-9_$]*\s*=>/g, 'callable');
|
|
1748
2029
|
addMatches(/export\s+default\s+(?:async\s+)?function\s+([A-Za-z_$][A-Za-z0-9_$]*)/g, 'default-function');
|
|
1749
2030
|
addMatches(/export\s+default\s+class\s+([A-Za-z_$][A-Za-z0-9_$]*)/g, 'default-class');
|
|
1750
2031
|
addMatches(/export\s+default\s+([A-Za-z_$][A-Za-z0-9_$]*)\s*(?:;|\n|$)/g, 'default-reference');
|
|
@@ -1757,7 +2038,7 @@ export function extractSymbols(filePath, content) {
|
|
|
1757
2038
|
addMatches(/^[ \t]*(?:async\s+)?function\s*\*?\s*([A-Za-z_$][A-Za-z0-9_$]*)\s*[(<]/gm, 'local-function');
|
|
1758
2039
|
addMatches(/^[ \t]*(?:const|let|var)\s+([A-Za-z_$][A-Za-z0-9_$]*)\s*=\s*(?:async\s+)?function\b/gm, 'callable');
|
|
1759
2040
|
addMatches(/^[ \t]*(?:abstract\s+)?class\s+([A-Za-z_$][A-Za-z0-9_$]*)/gm, 'local-class');
|
|
1760
|
-
if (/\.(?:ts|tsx|mts|cts|vue)$/.test(filePath)) {
|
|
2041
|
+
if (/\.(?:ts|tsx|mts|cts|vue|svelte)$/.test(filePath)) {
|
|
1761
2042
|
addMatches(/^[ \t]*(?:export\s+)?(?:declare\s+)?(?:const\s+)?(?:interface|enum)\s+([A-Za-z_$][A-Za-z0-9_$]*)/gm, 'type');
|
|
1762
2043
|
addMatches(/^[ \t]*(?:export\s+)?(?:declare\s+)?type\s+([A-Za-z_$][A-Za-z0-9_$]*)\s*(?:<[^=\n]*>)?\s*=/gm, 'type');
|
|
1763
2044
|
}
|
|
@@ -19,6 +19,46 @@ const VIETNAMESE_PHRASE_ALIASES = [
|
|
|
19
19
|
{ regex: /\bthanh phan\b/gu, expansions: ['component'] },
|
|
20
20
|
{ regex: /\bkiem thu\b/gu, expansions: ['test', 'testing'] },
|
|
21
21
|
{ regex: /\bbo cuc\b/gu, expansions: ['layout'] },
|
|
22
|
+
// General programming vocabulary (diacritics folded; matches with or without accents).
|
|
23
|
+
{ regex: /\bnhay cam\b/gu, expansions: ['sensitive'] },
|
|
24
|
+
{ regex: /\bbi mat\b/gu, expansions: ['secret'] },
|
|
25
|
+
{ regex: /\bgia tri\b/gu, expansions: ['value'] },
|
|
26
|
+
{ regex: /\bvan ban\b/gu, expansions: ['text'] },
|
|
27
|
+
{ regex: /\bsao luu\b/gu, expansions: ['backup'] },
|
|
28
|
+
{ regex: /\bkhoi phuc\b/gu, expansions: ['restore', 'recover'] },
|
|
29
|
+
{ regex: /\bdinh danh\b/gu, expansions: ['identity', 'id'] },
|
|
30
|
+
{ regex: /\bdu an\b/gu, expansions: ['project'] },
|
|
31
|
+
{ regex: /\bthu muc\b/gu, expansions: ['directory', 'dir', 'folder'] },
|
|
32
|
+
{ regex: /\bphan loai\b/gu, expansions: ['classify', 'category'] },
|
|
33
|
+
{ regex: /\buoc tinh\b/gu, expansions: ['estimate'] },
|
|
34
|
+
{ regex: /\bcong chan\b/gu, expansions: ['gate', 'guard'] },
|
|
35
|
+
{ regex: /\bcap nhat\b/gu, expansions: ['update'] },
|
|
36
|
+
{ regex: /\bgo cai dat\b/gu, expansions: ['uninstall'] },
|
|
37
|
+
{ regex: /\bcai dat\b/gu, expansions: ['install', 'setup'] },
|
|
38
|
+
{ regex: /\bcau hinh\b/gu, expansions: ['config', 'configuration'] },
|
|
39
|
+
{ regex: /\bbao cao\b/gu, expansions: ['report'] },
|
|
40
|
+
{ regex: /\blich su\b/gu, expansions: ['history'] },
|
|
41
|
+
{ regex: /\bnhat ky\b/gu, expansions: ['log'] },
|
|
42
|
+
{ regex: /\bchi muc\b/gu, expansions: ['index'] },
|
|
43
|
+
{ regex: /\bxu ly\b/gu, expansions: ['handle', 'process'] },
|
|
44
|
+
{ regex: /\bphan tich\b/gu, expansions: ['parse', 'analyze'] },
|
|
45
|
+
{ regex: /\bhet han\b/gu, expansions: ['expire', 'expiry'] },
|
|
46
|
+
{ regex: /\bchup anh\b/gu, expansions: ['snapshot'] },
|
|
47
|
+
{ regex: /\bhoan tac\b/gu, expansions: ['rollback', 'revert'] },
|
|
48
|
+
{ regex: /\bnguoi dung\b/gu, expansions: ['user'] },
|
|
49
|
+
{ regex: /\bthong bao\b/gu, expansions: ['notify', 'message'] },
|
|
50
|
+
{ regex: /\bsap xep\b/gu, expansions: ['sort'] },
|
|
51
|
+
{ regex: /\bdang ky\b/gu, expansions: ['register'] },
|
|
52
|
+
{ regex: /\btham so\b/gu, expansions: ['argument', 'param', 'option'] },
|
|
53
|
+
{ regex: /\bket qua\b/gu, expansions: ['result'] },
|
|
54
|
+
{ regex: /\bmac dinh\b/gu, expansions: ['default'] },
|
|
55
|
+
{ regex: /\bdau vao\b/gu, expansions: ['input'] },
|
|
56
|
+
{ regex: /\bdau ra\b/gu, expansions: ['output'] },
|
|
57
|
+
{ regex: /\bhang doi\b/gu, expansions: ['queue'] },
|
|
58
|
+
{ regex: /\bma hoa\b/gu, expansions: ['encode', 'encrypt'] },
|
|
59
|
+
{ regex: /\bgiai ma\b/gu, expansions: ['decode', 'decrypt'] },
|
|
60
|
+
{ regex: /\bbo nho\b/gu, expansions: ['memory'] },
|
|
61
|
+
{ regex: /\bcanh bao\b/gu, expansions: ['warning', 'warn'] },
|
|
22
62
|
];
|
|
23
63
|
|
|
24
64
|
const VIETNAMESE_TOKEN_ALIASES = new Map([
|
|
@@ -40,8 +80,58 @@ const VIETNAMESE_TOKEN_ALIASES = new Map([
|
|
|
40
80
|
['soat', ['review', 'audit']],
|
|
41
81
|
['trien', ['implement', 'build', 'ship']],
|
|
42
82
|
['khai', ['implement', 'build', 'ship']],
|
|
83
|
+
['kho', ['store', 'storage']],
|
|
84
|
+
['ghi', ['write', 'record']],
|
|
85
|
+
['doc', ['read']],
|
|
86
|
+
['luu', ['save', 'store', 'persist']],
|
|
87
|
+
['tim', ['find', 'search', 'resolve']],
|
|
88
|
+
['hong', ['broken', 'repair']],
|
|
89
|
+
['phut', ['minute', 'minutes']],
|
|
90
|
+
['ham', ['function']],
|
|
91
|
+
['bien', ['variable']],
|
|
92
|
+
['lop', ['class']],
|
|
93
|
+
['lenh', ['command']],
|
|
94
|
+
['chay', ['run', 'execute']],
|
|
95
|
+
['phien', ['session']],
|
|
96
|
+
['loc', ['filter']],
|
|
97
|
+
['gui', ['send', 'dispatch']],
|
|
98
|
+
['khoa', ['lock']],
|
|
99
|
+
['huy', ['cancel', 'abort']],
|
|
100
|
+
['quyet', ['decision']],
|
|
43
101
|
]);
|
|
44
102
|
|
|
103
|
+
// Query-time light stemming: adds the singular/base form of an English query word so
|
|
104
|
+
// 'files' reaches `file`, 'checks' reaches `check`, 'written' reaches `write`. Added next
|
|
105
|
+
// to the original token, never in place of it, and never applied to indexed text.
|
|
106
|
+
const IRREGULAR_STEMS = new Map([
|
|
107
|
+
['written', 'write'], ['wrote', 'write'], ['built', 'build'], ['ran', 'run'], ['saved', 'save'],
|
|
108
|
+
['found', 'find'], ['sent', 'send'], ['made', 'make'], ['read', 'read'], ['began', 'begin'],
|
|
109
|
+
]);
|
|
110
|
+
|
|
111
|
+
const STEM_MIN_QUERY_TOKENS = 5;
|
|
112
|
+
|
|
113
|
+
function stemToken(token) {
|
|
114
|
+
if (!/^[a-z]+$/.test(token) || token.length < 4) {
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
if (IRREGULAR_STEMS.has(token)) {
|
|
118
|
+
return IRREGULAR_STEMS.get(token);
|
|
119
|
+
}
|
|
120
|
+
let stem = null;
|
|
121
|
+
if (token.endsWith('ies') && token.length > 4) {
|
|
122
|
+
stem = `${token.slice(0, -3)}y`;
|
|
123
|
+
} else if (/(?:ches|shes|xes|sses)$/.test(token)) {
|
|
124
|
+
stem = token.slice(0, -2);
|
|
125
|
+
} else if (token.endsWith('s') && !/(?:ss|us|is|as|os)$/.test(token)) {
|
|
126
|
+
stem = token.slice(0, -1);
|
|
127
|
+
} else if (token.endsWith('ing') && token.length > 5) {
|
|
128
|
+
stem = token.slice(0, -3);
|
|
129
|
+
} else if (token.endsWith('ed') && token.length > 4) {
|
|
130
|
+
stem = token.endsWith('ied') ? `${token.slice(0, -3)}y` : token.slice(0, -2);
|
|
131
|
+
}
|
|
132
|
+
return stem && stem.length >= 3 && stem !== token ? stem : null;
|
|
133
|
+
}
|
|
134
|
+
|
|
45
135
|
export function buildRouteSignalText(...values) {
|
|
46
136
|
const baseText = values
|
|
47
137
|
.map((value) => String(value || '').trim())
|
|
@@ -73,6 +163,16 @@ export function buildSearchDescriptor(value, { expandVietnameseAliases = false }
|
|
|
73
163
|
for (const token of collectVietnameseAliasTokens(foldedLower, tokens)) {
|
|
74
164
|
tokens.add(token);
|
|
75
165
|
}
|
|
166
|
+
// Stems only for question-like queries: identifier-style queries (findRelatedItemIds,
|
|
167
|
+
// collectVietnameseAliasTokens) must keep matching exact tokens.
|
|
168
|
+
if (tokens.size >= STEM_MIN_QUERY_TOKENS) {
|
|
169
|
+
for (const token of [...tokens]) {
|
|
170
|
+
const stem = stemToken(token);
|
|
171
|
+
if (stem && !GENERIC_STOPWORDS.has(stem)) {
|
|
172
|
+
tokens.add(stem);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
76
176
|
}
|
|
77
177
|
|
|
78
178
|
return {
|
package/src/index/paths.js
CHANGED
|
@@ -21,7 +21,7 @@ export const INDEX_ARTIFACTS = {
|
|
|
21
21
|
// files or the new extractions silently vanish.
|
|
22
22
|
// v10: symbols.json gains unexported function/class ('local-function', 'local-class'),
|
|
23
23
|
// function-expression consts, class 'method' rows and TS interface/enum/type ('type') rows.
|
|
24
|
-
export const INDEX_SCHEMA_VERSION =
|
|
24
|
+
export const INDEX_SCHEMA_VERSION = 11;
|
|
25
25
|
|
|
26
26
|
export function getIndexDir(rootDir) {
|
|
27
27
|
return path.join(rootDir, '.cache', 'index');
|
|
@@ -62,5 +62,6 @@ export function isLikelyTestFilePath(filePath) {
|
|
|
62
62
|
|| lower.endsWith('.spec.jsx')
|
|
63
63
|
|| lower.endsWith('.spec.mjs')
|
|
64
64
|
|| lower.endsWith('.spec.cjs')
|
|
65
|
+
|| /(?:_test\.(?:go|py|rb|rs)|_spec\.rb|(?:^|\/)test_[^/]+\.py|[a-z0-9]Tests?\.(?:java|cs))$/.test(filePath)
|
|
65
66
|
);
|
|
66
67
|
}
|
package/src/index/queryIndex.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { execFile } from 'node:child_process';
|
|
4
|
+
import { createHash } from 'node:crypto';
|
|
5
|
+
|
|
6
|
+
import { withFileLock } from '../core/fileOps.js';
|
|
4
7
|
|
|
5
8
|
import { getArtifactPath, getIndexDir, INDEX_ARTIFACTS, INDEX_SCHEMA_VERSION, isLikelyTestFilePath } from './paths.js';
|
|
6
9
|
import { importsNeedAliasContext, loadImportAliasContext, resolveImportSpecifier } from './importResolution.js';
|
|
@@ -196,12 +199,13 @@ export async function queryCodeIndex({ rootDir = process.cwd(), query, limit = 5
|
|
|
196
199
|
}),
|
|
197
200
|
});
|
|
198
201
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
202
|
+
const ranked = [...finalScores.values()]
|
|
203
|
+
.map((entry) => ({ ...entry, score: finalizeScore(entry) }))
|
|
204
|
+
.sort((a, b) => b.score - a.score || a.filePath.localeCompare(b.filePath));
|
|
205
|
+
const fused = contentLane && ranked.length > 0 && ranked[0].score < FUSION_WEAK_SCORE && queryDescriptor.tokens.size >= FUSION_MIN_TOKENS
|
|
206
|
+
? await fuseWeakQuery({ absoluteRoot, query: normalizedQuery, ranked, searchDescriptorsByFile, includeLikelyTestFiles })
|
|
207
|
+
: null;
|
|
208
|
+
return withContentLaneStatus(freezeQueryResults((fused ?? ranked).slice(0, limit)), contentLaneRan, contentCutShort);
|
|
205
209
|
})().catch((error) => {
|
|
206
210
|
QUERY_RESULT_CACHE.delete(queryCacheKey);
|
|
207
211
|
throw error;
|
|
@@ -211,6 +215,129 @@ export async function queryCodeIndex({ rootDir = process.cwd(), query, limit = 5
|
|
|
211
215
|
return queryPromise;
|
|
212
216
|
}
|
|
213
217
|
|
|
218
|
+
// Opt-in lane fusion (default OFF): a weak natural-language query (best score below
|
|
219
|
+
// FUSION_WEAK_SCORE, >= FUSION_MIN_TOKENS tokens) is re-ranked by RRF over the scored list
|
|
220
|
+
// and a hashed-embedding lane (the retriever.js vector lane). Enabled by
|
|
221
|
+
// `.ukit/storage/config.json` -> index.fusion === true or UKIT_INDEX_FUSION=1. The flag is
|
|
222
|
+
// read only after the weak gate passes, and contentLane:false callers (hooks/resolveContext)
|
|
223
|
+
// never reach it. Never throws; async fs only.
|
|
224
|
+
const FUSION_WEAK_SCORE = 6;
|
|
225
|
+
const FUSION_MIN_TOKENS = 4;
|
|
226
|
+
const FUSION_RRF_K = 5;
|
|
227
|
+
const FUSION_VECTOR_WEIGHT = 1;
|
|
228
|
+
const FUSION_LANE_LIMIT = 100;
|
|
229
|
+
const FUSION_DOC_VECTORS = new WeakMap();
|
|
230
|
+
|
|
231
|
+
// Inlined copy of src/core/codeintel/vectorProvider.js hashVectorize/cosine (256 dims, FNV-1a
|
|
232
|
+
// word + trigram features, L2-normalized) so the shipped index-core.mjs stays dependency-free.
|
|
233
|
+
function fusionFnv1a(str) {
|
|
234
|
+
let h = 0x811c9dc5;
|
|
235
|
+
for (let i = 0; i < str.length; i += 1) {
|
|
236
|
+
h ^= str.charCodeAt(i);
|
|
237
|
+
h = Math.imul(h, 0x01000193) >>> 0;
|
|
238
|
+
}
|
|
239
|
+
return h >>> 0;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function hashVectorize(text) {
|
|
243
|
+
const dims = 256;
|
|
244
|
+
const vec = new Array(dims).fill(0);
|
|
245
|
+
for (const token of String(text ?? '').split(/[^A-Za-z0-9_$]+/).map((t) => t.toLowerCase()).filter(Boolean)) {
|
|
246
|
+
vec[fusionFnv1a(`w:${token}`) % dims] += 1;
|
|
247
|
+
const padded = `#${token}#`;
|
|
248
|
+
for (let i = 0; i + 3 <= padded.length; i += 1) vec[fusionFnv1a(`t:${padded.slice(i, i + 3)}`) % dims] += 0.1;
|
|
249
|
+
}
|
|
250
|
+
const norm = Math.sqrt(vec.reduce((sum, v) => sum + v * v, 0));
|
|
251
|
+
if (norm > 0) for (let i = 0; i < dims; i += 1) vec[i] /= norm;
|
|
252
|
+
return vec;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function cosineSimilarity(a, b) {
|
|
256
|
+
let dot = 0;
|
|
257
|
+
for (let i = 0; i < a.length; i += 1) dot += a[i] * b[i];
|
|
258
|
+
return dot;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
async function isFusionEnabled(absoluteRoot) {
|
|
262
|
+
if (process.env.UKIT_INDEX_FUSION === '1') return true;
|
|
263
|
+
if (process.env.UKIT_INDEX_FUSION === '0') return false;
|
|
264
|
+
try {
|
|
265
|
+
const config = JSON.parse(await fs.readFile(path.join(absoluteRoot, '.ukit', 'storage', 'config.json'), 'utf8'));
|
|
266
|
+
return config?.index?.fusion === true;
|
|
267
|
+
} catch {
|
|
268
|
+
return false;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
async function fuseWeakQuery({ absoluteRoot, query, ranked, searchDescriptorsByFile, includeLikelyTestFiles }) {
|
|
273
|
+
try {
|
|
274
|
+
if (!(await isFusionEnabled(absoluteRoot))) return null;
|
|
275
|
+
let docVectors = FUSION_DOC_VECTORS.get(searchDescriptorsByFile);
|
|
276
|
+
if (!docVectors) {
|
|
277
|
+
docVectors = new Map();
|
|
278
|
+
for (const [filePath, descriptor] of searchDescriptorsByFile) {
|
|
279
|
+
docVectors.set(filePath, hashVectorize(`${filePath} ${(descriptor.symbols ?? []).map((s) => s.name).join(' ')}`));
|
|
280
|
+
}
|
|
281
|
+
FUSION_DOC_VECTORS.set(searchDescriptorsByFile, docVectors);
|
|
282
|
+
}
|
|
283
|
+
const queryVector = hashVectorize(query);
|
|
284
|
+
const vectorLane = [];
|
|
285
|
+
for (const [filePath, vector] of docVectors) {
|
|
286
|
+
if (isLikelyTestFilePath(filePath) && !includeLikelyTestFiles) continue;
|
|
287
|
+
const similarity = cosineSimilarity(queryVector, vector);
|
|
288
|
+
if (similarity > 0) vectorLane.push([filePath, similarity]);
|
|
289
|
+
}
|
|
290
|
+
vectorLane.sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]));
|
|
291
|
+
const vectorPaths = vectorLane.slice(0, FUSION_LANE_LIMIT).map(([filePath]) => filePath);
|
|
292
|
+
const indexPaths = ranked.slice(0, FUSION_LANE_LIMIT).map((entry) => entry.filePath);
|
|
293
|
+
const rrf = new Map();
|
|
294
|
+
indexPaths.forEach((filePath, i) => rrf.set(filePath, (rrf.get(filePath) ?? 0) + 1 / (FUSION_RRF_K + i + 1)));
|
|
295
|
+
vectorPaths.forEach((filePath, i) => rrf.set(filePath, (rrf.get(filePath) ?? 0) + FUSION_VECTOR_WEIGHT / (FUSION_RRF_K + i + 1)));
|
|
296
|
+
const byPath = new Map(ranked.map((entry) => [entry.filePath, entry]));
|
|
297
|
+
const order = [...rrf.entries()].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).map(([filePath]) => filePath);
|
|
298
|
+
const floor = ranked[ranked.length - 1].score;
|
|
299
|
+
const merged = order.map((filePath) => byPath.get(filePath)
|
|
300
|
+
?? { filePath, score: Math.min(0.01, floor), reasons: ['fusion:vector'], tests: [] });
|
|
301
|
+
await emitFusionTelemetry(absoluteRoot, { query, indexPaths, vectorPaths, mergedPaths: merged.map((e) => e.filePath) });
|
|
302
|
+
return merged;
|
|
303
|
+
} catch {
|
|
304
|
+
return null;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// Same event shape and file as retriever.js emitRetrieverLaneTelemetry (query stored as sha256).
|
|
309
|
+
async function emitFusionTelemetry(absoluteRoot, { query, indexPaths, vectorPaths, mergedPaths }) {
|
|
310
|
+
try {
|
|
311
|
+
const event = {
|
|
312
|
+
ts: Date.now(),
|
|
313
|
+
query: createHash('sha256').update(String(query ?? '')).digest('hex'),
|
|
314
|
+
mode: 'index-query',
|
|
315
|
+
lanes: {
|
|
316
|
+
index: { hits: indexPaths.length, weightUsed: 1, paths: indexPaths },
|
|
317
|
+
vector: { hits: vectorPaths.length, weightUsed: FUSION_VECTOR_WEIGHT, paths: vectorPaths },
|
|
318
|
+
},
|
|
319
|
+
mergedPaths: mergedPaths.slice(0, 100),
|
|
320
|
+
merge: 'rrf',
|
|
321
|
+
};
|
|
322
|
+
const filePath = path.join(absoluteRoot, '.ukit', 'storage', 'cache', 'retriever-lanes.jsonl');
|
|
323
|
+
await fs.mkdir(path.dirname(filePath), { recursive: true });
|
|
324
|
+
await withFileLock(filePath, async () => {
|
|
325
|
+
try {
|
|
326
|
+
const st = await fs.stat(filePath);
|
|
327
|
+
if (st.size > 256 * 1024) {
|
|
328
|
+
const kept = (await fs.readFile(filePath, 'utf8')).split('\n').filter(Boolean).slice(-2000);
|
|
329
|
+
await fs.writeFile(filePath, kept.length ? `${kept.join('\n')}\n` : '', 'utf8');
|
|
330
|
+
}
|
|
331
|
+
} catch {
|
|
332
|
+
// Missing file is fine; append below recreates it.
|
|
333
|
+
}
|
|
334
|
+
await fs.appendFile(filePath, `${JSON.stringify(event)}\n`, 'utf8');
|
|
335
|
+
});
|
|
336
|
+
} catch {
|
|
337
|
+
// Telemetry is advisory.
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
214
341
|
// The `callable` symbol regex matches any `const x = (`, so it also captures plain
|
|
215
342
|
// parenthesised expressions such as `const rows = (items ?? [])`. Harmless for fuzzy
|
|
216
343
|
// ranking, misleading in an outline that is read as a map of the file's API. Those rows
|
|
@@ -417,7 +544,7 @@ const BOOST_LIFT_RATIO = 0.2; // import/hotspot/archetype boosts may add at most
|
|
|
417
544
|
const CONTENT_LANE_CONFIDENT_SCORE = 30; // a best direct score at/above this (exact symbol or path hit) skips the content lane
|
|
418
545
|
const CONTENT_LANE_MIN_TOKENS = 3; // shorter queries are names, not messages
|
|
419
546
|
const CONTENT_LANE_LIMIT = 40; // candidates only share tokens somewhere in the file; the same-line check below keeps the real ones
|
|
420
|
-
const CONTENT_LANE_CODE_EXT = /\.(?:m?js|cjs|jsx?|tsx?|vue|sql|sh)$/i; // docs/data files quote queries verbatim (baselines, logs); only source carries error strings
|
|
547
|
+
const CONTENT_LANE_CODE_EXT = /\.(?:m?js|cjs|jsx?|tsx?|vue|svelte|sql|sh|py|go|java|cs|php|rb|rs)$/i; // docs/data files quote queries verbatim (baselines, logs); only source carries error strings
|
|
421
548
|
const CONTENT_LANE_BONUS = 14; // added to a file that already has a direct score
|
|
422
549
|
const CONTENT_LANE_ONLY_SCORE = 13; // base for a file found only by content; below CONTENT_LANE_CONFIDENT_SCORE by design
|
|
423
550
|
const CONTENT_LANE_MAX_FILES = 1500; // files read per query, in priority order (primary bound)
|