recker 1.0.15-next.3794a15 → 1.0.15-next.c7370be
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/dist/bench/generator.d.ts.map +1 -1
- package/dist/bench/generator.js +2 -1
- package/dist/bench/stats.d.ts +15 -1
- package/dist/bench/stats.d.ts.map +1 -1
- package/dist/bench/stats.js +84 -5
- package/dist/cli/index.js +21 -0
- package/dist/cli/tui/load-dashboard.d.ts.map +1 -1
- package/dist/cli/tui/load-dashboard.js +62 -8
- package/dist/cli/tui/scroll-buffer.d.ts +43 -0
- package/dist/cli/tui/scroll-buffer.d.ts.map +1 -0
- package/dist/cli/tui/scroll-buffer.js +162 -0
- package/dist/cli/tui/search-panel.d.ts +41 -0
- package/dist/cli/tui/search-panel.d.ts.map +1 -0
- package/dist/cli/tui/search-panel.js +419 -0
- package/dist/cli/tui/shell.d.ts +11 -0
- package/dist/cli/tui/shell.d.ts.map +1 -1
- package/dist/cli/tui/shell.js +189 -30
- package/dist/contract/index.js +3 -2
- package/dist/dns/index.d.ts +1 -0
- package/dist/dns/index.d.ts.map +1 -1
- package/dist/dns/index.js +1 -0
- package/dist/dns/propagation.d.ts +19 -0
- package/dist/dns/propagation.d.ts.map +1 -0
- package/dist/dns/propagation.js +129 -0
- package/dist/mcp/embeddings-loader.d.ts +18 -0
- package/dist/mcp/embeddings-loader.d.ts.map +1 -0
- package/dist/mcp/embeddings-loader.js +152 -0
- package/dist/mcp/index.d.ts +1 -0
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +1 -0
- package/dist/mcp/search/hybrid-search.d.ts.map +1 -1
- package/dist/mcp/search/hybrid-search.js +7 -21
- package/dist/mcp/server.d.ts +2 -0
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +8 -1
- package/dist/utils/colors.d.ts +16 -0
- package/dist/utils/colors.d.ts.map +1 -1
- package/dist/utils/colors.js +16 -0
- package/package.json +2 -2
- package/dist/mcp/data/embeddings.json +0 -1
package/dist/cli/tui/shell.js
CHANGED
|
@@ -12,6 +12,8 @@ import { rdap } from '../../utils/rdap.js';
|
|
|
12
12
|
import { ScrapeDocument } from '../../scrape/document.js';
|
|
13
13
|
import colors from '../../utils/colors.js';
|
|
14
14
|
import { getShellSearch } from './shell-search.js';
|
|
15
|
+
import { openSearchPanel } from './search-panel.js';
|
|
16
|
+
import { ScrollBuffer, parseScrollKey, parseMouseScroll, enableMouseReporting, disableMouseReporting } from './scroll-buffer.js';
|
|
15
17
|
let highlight;
|
|
16
18
|
async function initDependencies() {
|
|
17
19
|
if (!highlight) {
|
|
@@ -36,11 +38,16 @@ export class RekShell {
|
|
|
36
38
|
initialized = false;
|
|
37
39
|
currentDoc = null;
|
|
38
40
|
currentDocUrl = '';
|
|
41
|
+
scrollBuffer;
|
|
42
|
+
originalStdoutWrite = null;
|
|
43
|
+
inScrollMode = false;
|
|
39
44
|
constructor() {
|
|
40
45
|
this.client = createClient({
|
|
41
46
|
baseUrl: 'http://localhost',
|
|
42
|
-
checkHooks: false
|
|
47
|
+
checkHooks: false,
|
|
48
|
+
http2: true
|
|
43
49
|
});
|
|
50
|
+
this.scrollBuffer = new ScrollBuffer({ maxLines: 10000 });
|
|
44
51
|
}
|
|
45
52
|
async ensureInitialized() {
|
|
46
53
|
if (this.initialized)
|
|
@@ -85,7 +92,7 @@ export class RekShell {
|
|
|
85
92
|
const commands = [
|
|
86
93
|
'get', 'post', 'put', 'delete', 'patch', 'head', 'options',
|
|
87
94
|
'ws', 'udp', 'load', 'chat', 'ai',
|
|
88
|
-
'whois', 'tls', 'ssl', 'dns', 'rdap', 'ping',
|
|
95
|
+
'whois', 'tls', 'ssl', 'dns', 'dns:propagate', 'rdap', 'ping',
|
|
89
96
|
'scrap', '$', '$text', '$attr', '$html', '$links', '$images', '$scripts', '$css', '$sourcemaps', '$unmap', '$unmap:view', '$unmap:save', '$beautify', '$beautify:save', '$table',
|
|
90
97
|
'?', 'search', 'suggest', 'example',
|
|
91
98
|
'help', 'clear', 'exit', 'set', 'url', 'vars', 'env'
|
|
@@ -95,9 +102,11 @@ export class RekShell {
|
|
|
95
102
|
}
|
|
96
103
|
async start() {
|
|
97
104
|
await this.ensureInitialized();
|
|
105
|
+
this.setupScrollCapture();
|
|
98
106
|
console.clear();
|
|
99
107
|
console.log(colors.bold(colors.cyan('Rek Console')));
|
|
100
108
|
console.log(colors.gray('Chat with your APIs. Type "help" for magic.'));
|
|
109
|
+
console.log(colors.gray('Page Up/Down or mouse scroll to view history.'));
|
|
101
110
|
console.log(colors.gray('--------------------------------------------\n'));
|
|
102
111
|
this.prompt();
|
|
103
112
|
this.rl.on('line', async (line) => {
|
|
@@ -112,15 +121,159 @@ export class RekShell {
|
|
|
112
121
|
this.rl.close();
|
|
113
122
|
});
|
|
114
123
|
this.rl.on('close', () => {
|
|
124
|
+
this.cleanupScrollCapture();
|
|
115
125
|
console.log(colors.gray('\nSee ya.'));
|
|
116
126
|
process.exit(0);
|
|
117
127
|
});
|
|
128
|
+
process.stdout.on('resize', () => {
|
|
129
|
+
this.scrollBuffer.updateViewport();
|
|
130
|
+
});
|
|
131
|
+
this.setupScrollKeyHandler();
|
|
132
|
+
}
|
|
133
|
+
setupScrollCapture() {
|
|
134
|
+
this.originalStdoutWrite = process.stdout.write.bind(process.stdout);
|
|
135
|
+
const self = this;
|
|
136
|
+
process.stdout.write = function (chunk, encodingOrCallback, callback) {
|
|
137
|
+
const content = typeof chunk === 'string' ? chunk : chunk.toString();
|
|
138
|
+
self.scrollBuffer.write(content);
|
|
139
|
+
if (!self.inScrollMode && self.originalStdoutWrite) {
|
|
140
|
+
return self.originalStdoutWrite(chunk, encodingOrCallback, callback);
|
|
141
|
+
}
|
|
142
|
+
return true;
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
cleanupScrollCapture() {
|
|
146
|
+
if (this.originalStdoutWrite) {
|
|
147
|
+
process.stdout.write = this.originalStdoutWrite;
|
|
148
|
+
this.originalStdoutWrite = null;
|
|
149
|
+
}
|
|
150
|
+
disableMouseReporting();
|
|
151
|
+
}
|
|
152
|
+
setupScrollKeyHandler() {
|
|
153
|
+
enableMouseReporting();
|
|
154
|
+
if (process.stdin.isTTY) {
|
|
155
|
+
process.stdin.on('data', (data) => {
|
|
156
|
+
const scrollKey = parseScrollKey(data);
|
|
157
|
+
if (scrollKey) {
|
|
158
|
+
this.handleScrollKey(scrollKey);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
const mouseScroll = parseMouseScroll(data);
|
|
162
|
+
if (mouseScroll) {
|
|
163
|
+
this.handleScrollKey(mouseScroll);
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
handleScrollKey(key) {
|
|
170
|
+
let needsRedraw = false;
|
|
171
|
+
switch (key) {
|
|
172
|
+
case 'pageUp':
|
|
173
|
+
if (!this.inScrollMode) {
|
|
174
|
+
this.enterScrollMode();
|
|
175
|
+
}
|
|
176
|
+
needsRedraw = this.scrollBuffer.pageUp();
|
|
177
|
+
break;
|
|
178
|
+
case 'pageDown':
|
|
179
|
+
needsRedraw = this.scrollBuffer.pageDown();
|
|
180
|
+
if (!this.scrollBuffer.isScrolledUp && this.inScrollMode) {
|
|
181
|
+
this.exitScrollMode();
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
break;
|
|
185
|
+
case 'scrollUp':
|
|
186
|
+
if (!this.inScrollMode) {
|
|
187
|
+
this.enterScrollMode();
|
|
188
|
+
}
|
|
189
|
+
needsRedraw = this.scrollBuffer.scrollUp(3);
|
|
190
|
+
break;
|
|
191
|
+
case 'scrollDown':
|
|
192
|
+
needsRedraw = this.scrollBuffer.scrollDown(3);
|
|
193
|
+
if (!this.scrollBuffer.isScrolledUp && this.inScrollMode) {
|
|
194
|
+
this.exitScrollMode();
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
break;
|
|
198
|
+
case 'home':
|
|
199
|
+
if (!this.inScrollMode) {
|
|
200
|
+
this.enterScrollMode();
|
|
201
|
+
}
|
|
202
|
+
this.scrollBuffer.scrollToTop();
|
|
203
|
+
needsRedraw = true;
|
|
204
|
+
break;
|
|
205
|
+
case 'end':
|
|
206
|
+
this.scrollBuffer.scrollToBottom();
|
|
207
|
+
if (this.inScrollMode) {
|
|
208
|
+
this.exitScrollMode();
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
break;
|
|
212
|
+
case 'escape':
|
|
213
|
+
if (this.inScrollMode) {
|
|
214
|
+
this.exitScrollMode();
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
break;
|
|
218
|
+
}
|
|
219
|
+
if (needsRedraw && this.inScrollMode) {
|
|
220
|
+
this.renderScrollView();
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
enterScrollMode() {
|
|
224
|
+
if (this.inScrollMode)
|
|
225
|
+
return;
|
|
226
|
+
this.inScrollMode = true;
|
|
227
|
+
this.rl.pause();
|
|
228
|
+
if (this.originalStdoutWrite) {
|
|
229
|
+
this.originalStdoutWrite('\x1b[?25l');
|
|
230
|
+
}
|
|
231
|
+
this.renderScrollView();
|
|
232
|
+
}
|
|
233
|
+
exitScrollMode() {
|
|
234
|
+
if (!this.inScrollMode)
|
|
235
|
+
return;
|
|
236
|
+
this.inScrollMode = false;
|
|
237
|
+
if (this.originalStdoutWrite) {
|
|
238
|
+
this.originalStdoutWrite('\x1b[?25h');
|
|
239
|
+
this.originalStdoutWrite('\x1b[2J\x1b[H');
|
|
240
|
+
}
|
|
241
|
+
const recentLines = this.scrollBuffer.getVisibleLines();
|
|
242
|
+
if (this.originalStdoutWrite) {
|
|
243
|
+
this.originalStdoutWrite(recentLines.join('\n') + '\n');
|
|
244
|
+
}
|
|
245
|
+
this.rl.resume();
|
|
246
|
+
this.prompt();
|
|
247
|
+
}
|
|
248
|
+
renderScrollView() {
|
|
249
|
+
if (!this.originalStdoutWrite)
|
|
250
|
+
return;
|
|
251
|
+
const rows = process.stdout.rows || 24;
|
|
252
|
+
const cols = process.stdout.columns || 80;
|
|
253
|
+
const visibleLines = this.scrollBuffer.getVisibleLines();
|
|
254
|
+
const info = this.scrollBuffer.getScrollInfo();
|
|
255
|
+
this.originalStdoutWrite('\x1b[2J\x1b[H');
|
|
256
|
+
for (let i = 0; i < visibleLines.length && i < rows - 1; i++) {
|
|
257
|
+
const line = visibleLines[i] || '';
|
|
258
|
+
const truncated = line.length > cols ? line.slice(0, cols - 1) + '…' : line;
|
|
259
|
+
this.originalStdoutWrite(truncated + '\n');
|
|
260
|
+
}
|
|
261
|
+
const scrollInfo = this.scrollBuffer.isScrolledUp
|
|
262
|
+
? colors.yellow(`↑ ${this.scrollBuffer.position} lines | ${info.percent}% | `)
|
|
263
|
+
: '';
|
|
264
|
+
const helpText = colors.gray('Page Up/Down • Home/End • Esc to exit');
|
|
265
|
+
const statusBar = `\x1b[${rows};1H\x1b[7m ${scrollInfo}${helpText} \x1b[0m`;
|
|
266
|
+
this.originalStdoutWrite(statusBar);
|
|
118
267
|
}
|
|
119
268
|
prompt() {
|
|
120
269
|
this.rl.setPrompt(this.getPrompt());
|
|
121
270
|
this.rl.prompt();
|
|
122
271
|
}
|
|
123
272
|
async handleCommand(input) {
|
|
273
|
+
if (input.endsWith('?') && !input.startsWith('?') && input.length > 1) {
|
|
274
|
+
await this.runSearch(input.slice(0, -1).trim());
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
124
277
|
if (input.includes('=') && !input.includes(' ') && !input.startsWith('http')) {
|
|
125
278
|
}
|
|
126
279
|
const parts = this.parseLine(input);
|
|
@@ -165,6 +318,9 @@ export class RekShell {
|
|
|
165
318
|
case 'dns':
|
|
166
319
|
await this.runDNS(parts[1]);
|
|
167
320
|
return;
|
|
321
|
+
case 'dns:propagate':
|
|
322
|
+
await this.runDNSPropagation(parts[1], parts[2]);
|
|
323
|
+
return;
|
|
168
324
|
case 'rdap':
|
|
169
325
|
await this.runRDAP(parts[1]);
|
|
170
326
|
return;
|
|
@@ -736,6 +892,27 @@ export class RekShell {
|
|
|
736
892
|
}
|
|
737
893
|
console.log('');
|
|
738
894
|
}
|
|
895
|
+
async runDNSPropagation(domain, type = 'A') {
|
|
896
|
+
if (!domain) {
|
|
897
|
+
domain = this.getBaseDomain() || '';
|
|
898
|
+
if (!domain) {
|
|
899
|
+
console.log(colors.yellow('Usage: dns:propagate <domain> [type]'));
|
|
900
|
+
console.log(colors.gray(' Examples: dns:propagate google.com | dns:propagate github.com TXT'));
|
|
901
|
+
console.log(colors.gray(' Or set a base URL first: url https://example.com'));
|
|
902
|
+
return;
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
console.log(colors.gray(`Checking DNS propagation for ${domain} (${type})...`));
|
|
906
|
+
try {
|
|
907
|
+
const { checkPropagation, formatPropagationReport } = await import('../../dns/propagation.js');
|
|
908
|
+
const results = await checkPropagation(domain, type);
|
|
909
|
+
console.log(formatPropagationReport(results, domain, type));
|
|
910
|
+
this.lastResponse = results;
|
|
911
|
+
}
|
|
912
|
+
catch (error) {
|
|
913
|
+
console.error(colors.red(`Propagation check failed: ${error.message}`));
|
|
914
|
+
}
|
|
915
|
+
}
|
|
739
916
|
async runRDAP(domain) {
|
|
740
917
|
if (!domain) {
|
|
741
918
|
domain = this.getRootDomain() || '';
|
|
@@ -1660,38 +1837,14 @@ export class RekShell {
|
|
|
1660
1837
|
console.log('');
|
|
1661
1838
|
}
|
|
1662
1839
|
async runSearch(query) {
|
|
1663
|
-
if (!query.trim()) {
|
|
1664
|
-
console.log(colors.yellow('Usage: ? <query> or search <query>'));
|
|
1665
|
-
console.log(colors.gray(' Examples:'));
|
|
1666
|
-
console.log(colors.gray(' ? retry exponential backoff'));
|
|
1667
|
-
console.log(colors.gray(' search cache configuration'));
|
|
1668
|
-
return;
|
|
1669
|
-
}
|
|
1670
|
-
console.log(colors.gray('Searching documentation...'));
|
|
1671
1840
|
try {
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
console.log(colors.yellow(`No results for: "${query}"`));
|
|
1676
|
-
console.log(colors.gray('Try different keywords like: retry, cache, streaming, websocket, pagination'));
|
|
1677
|
-
return;
|
|
1678
|
-
}
|
|
1679
|
-
console.log(colors.bold(colors.cyan(`\nFound ${results.length} results for "${query}":\n`)));
|
|
1680
|
-
for (let i = 0; i < results.length; i++) {
|
|
1681
|
-
const result = results[i];
|
|
1682
|
-
const score = Math.round(result.score * 100);
|
|
1683
|
-
console.log(` ${colors.green(`${i + 1}.`)} ${colors.bold(result.title)} ${colors.gray(`(${score}%)`)}`);
|
|
1684
|
-
console.log(` ${colors.gray(result.path)}`);
|
|
1685
|
-
if (result.snippet) {
|
|
1686
|
-
const snippet = result.snippet.slice(0, 120).replace(/\n/g, ' ');
|
|
1687
|
-
console.log(` ${colors.gray(snippet)}${result.snippet.length > 120 ? '...' : ''}`);
|
|
1688
|
-
}
|
|
1689
|
-
console.log('');
|
|
1690
|
-
}
|
|
1691
|
-
console.log(colors.gray(' Tip: Use "get_doc <path>" to read full documentation'));
|
|
1841
|
+
this.rl.pause();
|
|
1842
|
+
await openSearchPanel(query.trim() || undefined);
|
|
1843
|
+
this.rl.resume();
|
|
1692
1844
|
}
|
|
1693
1845
|
catch (error) {
|
|
1694
1846
|
console.error(colors.red(`Search failed: ${error.message}`));
|
|
1847
|
+
this.rl.resume();
|
|
1695
1848
|
}
|
|
1696
1849
|
}
|
|
1697
1850
|
async runSuggest(useCase) {
|
|
@@ -1834,6 +1987,12 @@ export class RekShell {
|
|
|
1834
1987
|
${colors.green('suggest <use-case>')} Get implementation suggestions.
|
|
1835
1988
|
${colors.green('example <feature>')} Get code examples for a feature.
|
|
1836
1989
|
|
|
1990
|
+
${colors.bold('Navigation:')}
|
|
1991
|
+
${colors.green('Page Up/Down')} Scroll through command history.
|
|
1992
|
+
${colors.green('Home/End')} Jump to top/bottom of history.
|
|
1993
|
+
${colors.green('Mouse Scroll')} Scroll with mouse wheel.
|
|
1994
|
+
${colors.green('Escape')} Exit scroll mode.
|
|
1995
|
+
|
|
1837
1996
|
${colors.bold('Examples:')}
|
|
1838
1997
|
› url httpbin.org
|
|
1839
1998
|
› get /json
|
package/dist/contract/index.js
CHANGED
|
@@ -49,14 +49,15 @@ export function createContract(client, contract) {
|
|
|
49
49
|
if (endpoint.errors && err instanceof HttpError && err.response) {
|
|
50
50
|
const schema = endpoint.errors[err.status];
|
|
51
51
|
if (schema) {
|
|
52
|
+
let parsedError;
|
|
52
53
|
try {
|
|
53
54
|
const errorBody = await err.response.json();
|
|
54
|
-
|
|
55
|
-
throw new ContractError(err.status, parsedError, err);
|
|
55
|
+
parsedError = schema.parse(errorBody);
|
|
56
56
|
}
|
|
57
57
|
catch (parseErr) {
|
|
58
58
|
throw err;
|
|
59
59
|
}
|
|
60
|
+
throw new ContractError(err.status, parsedError, err);
|
|
60
61
|
}
|
|
61
62
|
}
|
|
62
63
|
throw err;
|
package/dist/dns/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { type DnsSecurityRecords } from '../utils/dns-toolkit.js';
|
|
|
2
2
|
export { createLookupFunction, customDNSLookup } from '../utils/dns.js';
|
|
3
3
|
export { createDoHLookup } from '../utils/doh.js';
|
|
4
4
|
export { getSecurityRecords, type DnsSecurityRecords } from '../utils/dns-toolkit.js';
|
|
5
|
+
export { checkPropagation, type PropagationResult, type DnsRecord, formatPropagationReport } from './propagation.js';
|
|
5
6
|
export type { DNSOptions } from '../types/index.js';
|
|
6
7
|
export type RecordType = 'A' | 'AAAA' | 'CNAME' | 'MX' | 'TXT' | 'NS' | 'SOA' | 'SRV' | 'CAA' | 'PTR';
|
|
7
8
|
export type DoHProvider = 'cloudflare' | 'google' | 'quad9' | 'system';
|
package/dist/dns/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/dns/index.ts"],"names":[],"mappings":"AA4BA,OAAO,EAA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,CAAC,kBAAkB,CAAC;CAItE;AA0BD,wBAAgB,SAAS,CAAC,OAAO,CAAC,EAAE,gBAAgB,GAAG,SAAS,CAE/D"}
|
package/dist/dns/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import { getSecurityRecords as getSecurityRecordsUtil } from '../utils/dns-toolk
|
|
|
3
3
|
export { createLookupFunction, customDNSLookup } from '../utils/dns.js';
|
|
4
4
|
export { createDoHLookup } from '../utils/doh.js';
|
|
5
5
|
export { getSecurityRecords } from '../utils/dns-toolkit.js';
|
|
6
|
+
export { checkPropagation, formatPropagationReport } from './propagation.js';
|
|
6
7
|
export class DNSClient {
|
|
7
8
|
options;
|
|
8
9
|
constructor(options = {}) {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface DnsRecord {
|
|
2
|
+
name: string;
|
|
3
|
+
type: number;
|
|
4
|
+
TTL: number;
|
|
5
|
+
data: string;
|
|
6
|
+
}
|
|
7
|
+
export interface PropagationResult {
|
|
8
|
+
id: string;
|
|
9
|
+
provider: string;
|
|
10
|
+
status: 'ok' | 'error';
|
|
11
|
+
records: string[];
|
|
12
|
+
rawRecords: DnsRecord[];
|
|
13
|
+
latency: number;
|
|
14
|
+
error?: string;
|
|
15
|
+
location?: string;
|
|
16
|
+
}
|
|
17
|
+
export declare function checkPropagation(domain: string, type?: string): Promise<PropagationResult[]>;
|
|
18
|
+
export declare function formatPropagationReport(results: PropagationResult[], domain: string, type: string): string;
|
|
19
|
+
//# sourceMappingURL=propagation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"propagation.d.ts","sourceRoot":"","sources":["../../src/dns/propagation.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,IAAI,GAAG,OAAO,CAAC;IACvB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,UAAU,EAAE,SAAS,EAAE,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AA8BD,wBAAsB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,GAAE,MAAY,GAAG,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAyEvG;AAED,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,iBAAiB,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAqD1G"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { request } from 'undici';
|
|
2
|
+
import pc from '../utils/colors.js';
|
|
3
|
+
const PROVIDERS = [
|
|
4
|
+
{ id: 'google', name: 'Google DNS', url: 'https://dns.google/resolve' },
|
|
5
|
+
{ id: 'cloudflare', name: 'Cloudflare', url: 'https://cloudflare-dns.com/dns-query' },
|
|
6
|
+
{ id: 'quad9', name: 'Quad9', url: 'https://dns.quad9.net:5053/dns-query' },
|
|
7
|
+
{ id: 'alidns', name: 'AliDNS (China)', url: 'https://dns.alidns.com/resolve' },
|
|
8
|
+
];
|
|
9
|
+
const TYPE_MAP = {
|
|
10
|
+
'A': '1',
|
|
11
|
+
'AAAA': '28',
|
|
12
|
+
'CNAME': '5',
|
|
13
|
+
'MX': '15',
|
|
14
|
+
'NS': '2',
|
|
15
|
+
'TXT': '16',
|
|
16
|
+
'PTR': '12',
|
|
17
|
+
'SRV': '33',
|
|
18
|
+
'SOA': '6',
|
|
19
|
+
'CAA': '257'
|
|
20
|
+
};
|
|
21
|
+
const TYPE_ID_MAP = Object.entries(TYPE_MAP).reduce((acc, [k, v]) => {
|
|
22
|
+
acc[Number(v)] = k;
|
|
23
|
+
return acc;
|
|
24
|
+
}, {});
|
|
25
|
+
export async function checkPropagation(domain, type = 'A') {
|
|
26
|
+
const typeId = TYPE_MAP[type.toUpperCase()] || type;
|
|
27
|
+
const queries = PROVIDERS.map(async (provider) => {
|
|
28
|
+
const start = performance.now();
|
|
29
|
+
try {
|
|
30
|
+
const url = new URL(provider.url);
|
|
31
|
+
url.searchParams.set('name', domain);
|
|
32
|
+
url.searchParams.set('type', typeId);
|
|
33
|
+
const { body, statusCode } = await request(url, {
|
|
34
|
+
method: 'GET',
|
|
35
|
+
headers: { 'Accept': 'application/dns-json' }
|
|
36
|
+
});
|
|
37
|
+
if (statusCode !== 200) {
|
|
38
|
+
throw new Error(`HTTP ${statusCode}`);
|
|
39
|
+
}
|
|
40
|
+
const json = await body.json();
|
|
41
|
+
const duration = performance.now() - start;
|
|
42
|
+
if (json.Status !== 0) {
|
|
43
|
+
const statusMap = {
|
|
44
|
+
1: 'FormErr', 2: 'ServFail', 3: 'NXDomain', 4: 'NotImp', 5: 'Refused'
|
|
45
|
+
};
|
|
46
|
+
const errorName = statusMap[json.Status] || `Code ${json.Status}`;
|
|
47
|
+
return {
|
|
48
|
+
id: provider.id,
|
|
49
|
+
provider: provider.name,
|
|
50
|
+
status: 'error',
|
|
51
|
+
records: [],
|
|
52
|
+
rawRecords: [],
|
|
53
|
+
latency: duration,
|
|
54
|
+
error: errorName
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
const answers = (json.Answer || []);
|
|
58
|
+
const records = answers.map(r => r.data);
|
|
59
|
+
return {
|
|
60
|
+
id: provider.id,
|
|
61
|
+
provider: provider.name,
|
|
62
|
+
status: 'ok',
|
|
63
|
+
records,
|
|
64
|
+
rawRecords: answers,
|
|
65
|
+
latency: duration
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
catch (err) {
|
|
69
|
+
return {
|
|
70
|
+
id: provider.id,
|
|
71
|
+
provider: provider.name,
|
|
72
|
+
status: 'error',
|
|
73
|
+
records: [],
|
|
74
|
+
rawRecords: [],
|
|
75
|
+
latency: performance.now() - start,
|
|
76
|
+
error: err.message
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
return Promise.all(queries);
|
|
81
|
+
}
|
|
82
|
+
export function formatPropagationReport(results, domain, type) {
|
|
83
|
+
let output = '';
|
|
84
|
+
output += `
|
|
85
|
+
${pc.bold(pc.cyan('🌍 Global DNS Propagation Check'))}
|
|
86
|
+
`;
|
|
87
|
+
output += `${pc.gray('Domain:')} ${pc.white(domain)} ${pc.gray('Type:')} ${pc.white(type.toUpperCase())}
|
|
88
|
+
|
|
89
|
+
`;
|
|
90
|
+
const consensus = {};
|
|
91
|
+
results.forEach(res => {
|
|
92
|
+
const key = res.status === 'ok' ? res.records.sort().join(', ') : `Error: ${res.error}`;
|
|
93
|
+
consensus[key] = (consensus[key] || 0) + 1;
|
|
94
|
+
const statusIcon = res.status === 'ok' ? pc.green('✔') : pc.red('✖');
|
|
95
|
+
const latencyColor = res.latency < 50 ? pc.green : res.latency < 200 ? pc.yellow : pc.red;
|
|
96
|
+
const latencyText = latencyColor(`${Math.round(res.latency)}ms`.padStart(5));
|
|
97
|
+
const providerName = pc.bold(res.provider.padEnd(15));
|
|
98
|
+
let recordsText = '';
|
|
99
|
+
if (res.status === 'ok') {
|
|
100
|
+
if (res.records.length === 0) {
|
|
101
|
+
recordsText = pc.yellow('(No records)');
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
recordsText = res.records.join(', ');
|
|
105
|
+
if (recordsText.length > 60)
|
|
106
|
+
recordsText = recordsText.substring(0, 57) + '...';
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
recordsText = pc.red(res.error || 'Unknown Error');
|
|
111
|
+
}
|
|
112
|
+
output += ` ${statusIcon} ${providerName} ${latencyText} ${recordsText}
|
|
113
|
+
`;
|
|
114
|
+
});
|
|
115
|
+
output += '\n';
|
|
116
|
+
const distinctAnswers = Object.keys(consensus);
|
|
117
|
+
if (distinctAnswers.length === 1) {
|
|
118
|
+
if (distinctAnswers[0].startsWith('Error')) {
|
|
119
|
+
output += pc.red('❌ All providers returned error.\n');
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
output += pc.green('✅ All providers returned the same records. Propagation is complete.\n');
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
else if (distinctAnswers.length > 1) {
|
|
126
|
+
output += pc.yellow('⚠ Inconsistent results detected (Propagation in progress or Split-Horizon DNS).\n');
|
|
127
|
+
}
|
|
128
|
+
return output;
|
|
129
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { EmbeddingsData } from './search/types.js';
|
|
2
|
+
declare function getPackageVersion(): string;
|
|
3
|
+
export declare function getEmbeddingsCachePath(version?: string): string;
|
|
4
|
+
export declare function hasLocalEmbeddings(version?: string): boolean;
|
|
5
|
+
export declare function loadLocalEmbeddings(version?: string): EmbeddingsData | null;
|
|
6
|
+
export declare function saveLocalEmbeddings(data: EmbeddingsData, version?: string): void;
|
|
7
|
+
export declare function downloadEmbeddings(version?: string): Promise<EmbeddingsData>;
|
|
8
|
+
export declare function loadBundledEmbeddings(): Promise<EmbeddingsData | null>;
|
|
9
|
+
export interface LoadEmbeddingsOptions {
|
|
10
|
+
forceDownload?: boolean;
|
|
11
|
+
version?: string;
|
|
12
|
+
offline?: boolean;
|
|
13
|
+
debug?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare function loadEmbeddings(options?: LoadEmbeddingsOptions): Promise<EmbeddingsData | null>;
|
|
16
|
+
export declare function clearEmbeddingsCache(version?: string): void;
|
|
17
|
+
export { getPackageVersion };
|
|
18
|
+
//# sourceMappingURL=embeddings-loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embeddings-loader.d.ts","sourceRoot":"","sources":["../../src/mcp/embeddings-loader.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AA+BxD,iBAAS,iBAAiB,IAAI,MAAM,CAKnC;AAyBD,wBAAgB,sBAAsB,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAI/D;AAKD,wBAAgB,kBAAkB,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAE5D;AAKD,wBAAgB,mBAAmB,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,cAAc,GAAG,IAAI,CAa3E;AAKD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,cAAc,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAUhF;AAKD,wBAAsB,kBAAkB,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAoBlF;AAKD,wBAAsB,qBAAqB,IAAI,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAsB5E;AAED,MAAM,WAAW,qBAAqB;IAEpC,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAsBD,wBAAsB,cAAc,CAAC,OAAO,GAAE,qBAA0B,GAAG,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAsCxG;AAKD,wBAAgB,oBAAoB,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAW3D;AAKD,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
|
|
2
|
+
import { join, dirname } from 'path';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
4
|
+
function getPackageVersionFromPkg() {
|
|
5
|
+
try {
|
|
6
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
const paths = [
|
|
8
|
+
join(__dirname, '..', '..', 'package.json'),
|
|
9
|
+
join(__dirname, '..', '..', '..', 'package.json'),
|
|
10
|
+
join(process.cwd(), 'package.json'),
|
|
11
|
+
];
|
|
12
|
+
for (const pkgPath of paths) {
|
|
13
|
+
if (existsSync(pkgPath)) {
|
|
14
|
+
const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));
|
|
15
|
+
if (pkg.name === 'recker') {
|
|
16
|
+
return pkg.version;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
}
|
|
23
|
+
return '1.0.15';
|
|
24
|
+
}
|
|
25
|
+
let _packageVersion = null;
|
|
26
|
+
function getPackageVersion() {
|
|
27
|
+
if (!_packageVersion) {
|
|
28
|
+
_packageVersion = getPackageVersionFromPkg();
|
|
29
|
+
}
|
|
30
|
+
return _packageVersion;
|
|
31
|
+
}
|
|
32
|
+
const GITHUB_RELEASE_URL = 'https://github.com/forattini-dev/recker/releases/download';
|
|
33
|
+
function getCacheDir() {
|
|
34
|
+
const homeDir = process.env.HOME || process.env.USERPROFILE || '';
|
|
35
|
+
if (homeDir) {
|
|
36
|
+
return join(homeDir, '.cache', 'recker');
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
40
|
+
return join(__dirname, '..', '..', 'node_modules', '.cache', 'recker');
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return join(process.cwd(), 'node_modules', '.cache', 'recker');
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export function getEmbeddingsCachePath(version) {
|
|
47
|
+
const cacheDir = getCacheDir();
|
|
48
|
+
const ver = version || getPackageVersion();
|
|
49
|
+
return join(cacheDir, `embeddings-${ver}.json`);
|
|
50
|
+
}
|
|
51
|
+
export function hasLocalEmbeddings(version) {
|
|
52
|
+
return existsSync(getEmbeddingsCachePath(version));
|
|
53
|
+
}
|
|
54
|
+
export function loadLocalEmbeddings(version) {
|
|
55
|
+
const cachePath = getEmbeddingsCachePath(version);
|
|
56
|
+
if (!existsSync(cachePath)) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
const data = readFileSync(cachePath, 'utf-8');
|
|
61
|
+
return JSON.parse(data);
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
export function saveLocalEmbeddings(data, version) {
|
|
68
|
+
const cachePath = getEmbeddingsCachePath(version);
|
|
69
|
+
const cacheDir = dirname(cachePath);
|
|
70
|
+
if (!existsSync(cacheDir)) {
|
|
71
|
+
mkdirSync(cacheDir, { recursive: true });
|
|
72
|
+
}
|
|
73
|
+
writeFileSync(cachePath, JSON.stringify(data));
|
|
74
|
+
}
|
|
75
|
+
export async function downloadEmbeddings(version) {
|
|
76
|
+
const ver = version || getPackageVersion();
|
|
77
|
+
const url = `${GITHUB_RELEASE_URL}/v${ver}/embeddings.json`;
|
|
78
|
+
try {
|
|
79
|
+
const response = await fetch(url);
|
|
80
|
+
if (!response.ok) {
|
|
81
|
+
throw new Error(`Failed to download embeddings: ${response.status} ${response.statusText}`);
|
|
82
|
+
}
|
|
83
|
+
const data = await response.json();
|
|
84
|
+
saveLocalEmbeddings(data, ver);
|
|
85
|
+
return data;
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
throw new Error(`Failed to download embeddings from ${url}: ${error}`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
export async function loadBundledEmbeddings() {
|
|
92
|
+
try {
|
|
93
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
94
|
+
const bundledPath = join(__dirname, 'data', 'embeddings.json');
|
|
95
|
+
if (existsSync(bundledPath)) {
|
|
96
|
+
const data = readFileSync(bundledPath, 'utf-8');
|
|
97
|
+
return JSON.parse(data);
|
|
98
|
+
}
|
|
99
|
+
const srcPath = join(__dirname, '..', 'mcp', 'data', 'embeddings.json');
|
|
100
|
+
if (existsSync(srcPath)) {
|
|
101
|
+
const data = readFileSync(srcPath, 'utf-8');
|
|
102
|
+
return JSON.parse(data);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
}
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
export async function loadEmbeddings(options = {}) {
|
|
110
|
+
const { forceDownload = false, version, offline = false, debug = false } = options;
|
|
111
|
+
const log = (msg) => {
|
|
112
|
+
if (debug)
|
|
113
|
+
console.log(`[embeddings-loader] ${msg}`);
|
|
114
|
+
};
|
|
115
|
+
if (!forceDownload) {
|
|
116
|
+
const cached = loadLocalEmbeddings(version);
|
|
117
|
+
if (cached) {
|
|
118
|
+
log(`Loaded from cache: ${getEmbeddingsCachePath(version)}`);
|
|
119
|
+
return cached;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
const bundled = await loadBundledEmbeddings();
|
|
123
|
+
if (bundled) {
|
|
124
|
+
log('Loaded bundled embeddings');
|
|
125
|
+
return bundled;
|
|
126
|
+
}
|
|
127
|
+
if (!offline) {
|
|
128
|
+
try {
|
|
129
|
+
log(`Downloading embeddings v${version || getPackageVersion()}...`);
|
|
130
|
+
const downloaded = await downloadEmbeddings(version);
|
|
131
|
+
log(`Downloaded and cached: ${downloaded.documents?.length || 0} documents`);
|
|
132
|
+
return downloaded;
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
log(`Download failed: ${error}`);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
log('No embeddings available');
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
export function clearEmbeddingsCache(version) {
|
|
142
|
+
const cachePath = getEmbeddingsCachePath(version);
|
|
143
|
+
try {
|
|
144
|
+
const fs = require('fs');
|
|
145
|
+
if (fs.existsSync(cachePath)) {
|
|
146
|
+
fs.unlinkSync(cachePath);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
catch {
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
export { getPackageVersion };
|