统一 Rust 与 TypeScript 格式化门禁
纳入 AGC Cargo workspace 的统一 rustfmt 检查与格式化入口 完成项目 TypeScript/Prettier 与 Rust 全量格式化 修复 Pingora expected executable 门禁的空白敏感误报 同步开发运维文档与 AGC skill pack 格式化忽略规则
This commit is contained in:
@@ -2,7 +2,10 @@ import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
|
||||
import { dirname, extname, join, relative, resolve } from 'node:path';
|
||||
import { fileURLToPath, pathToFileURL } from 'node:url';
|
||||
|
||||
export const repoRoot = resolve(dirname(fileURLToPath(import.meta.url)), '../..');
|
||||
export const repoRoot = resolve(
|
||||
dirname(fileURLToPath(import.meta.url)),
|
||||
'../..',
|
||||
);
|
||||
export const configPath = join(repoRoot, 'scripts/rag/rag-config.json');
|
||||
|
||||
export function readConfig() {
|
||||
@@ -28,7 +31,9 @@ export function getRuntimeNodeModules(config) {
|
||||
export function assertLocalRuntime(config) {
|
||||
const runtimeModules = getRuntimeNodeModules(config);
|
||||
const hasLance = existsSync(join(runtimeModules, '@lancedb/lancedb'));
|
||||
const hasTransformers = existsSync(join(runtimeModules, '@huggingface/transformers'));
|
||||
const hasTransformers = existsSync(
|
||||
join(runtimeModules, '@huggingface/transformers'),
|
||||
);
|
||||
|
||||
if (hasLance && hasTransformers) {
|
||||
return runtimeModules;
|
||||
@@ -56,7 +61,10 @@ export async function loadRagRuntime(config) {
|
||||
);
|
||||
const transformers = await import(
|
||||
pathToFileURL(
|
||||
join(runtimeModules, '@huggingface/transformers/dist/transformers.node.mjs'),
|
||||
join(
|
||||
runtimeModules,
|
||||
'@huggingface/transformers/dist/transformers.node.mjs',
|
||||
),
|
||||
).href
|
||||
);
|
||||
|
||||
@@ -129,7 +137,11 @@ function shouldReadFile(filePath, excluded) {
|
||||
if (excluded.some((prefix) => rel.startsWith(prefix))) {
|
||||
return false;
|
||||
}
|
||||
if (rel === 'AGENTS.md' || rel === 'CONTEXT.md' || rel.endsWith('/README.md')) {
|
||||
if (
|
||||
rel === 'AGENTS.md' ||
|
||||
rel === 'CONTEXT.md' ||
|
||||
rel.endsWith('/README.md')
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return new Set(['.md', '.txt']).has(extname(filePath).toLowerCase());
|
||||
@@ -156,7 +168,7 @@ export function chunkText(text, options) {
|
||||
};
|
||||
|
||||
for (const block of blocks) {
|
||||
if ((current.length + block.length + 2) <= maxChars) {
|
||||
if (current.length + block.length + 2 <= maxChars) {
|
||||
current = current ? `${current}\n\n${block}` : block;
|
||||
continue;
|
||||
}
|
||||
@@ -165,7 +177,11 @@ export function chunkText(text, options) {
|
||||
current = block;
|
||||
continue;
|
||||
}
|
||||
for (let start = 0; start < block.length; start += Math.max(1, maxChars - overlapChars)) {
|
||||
for (
|
||||
let start = 0;
|
||||
start < block.length;
|
||||
start += Math.max(1, maxChars - overlapChars)
|
||||
) {
|
||||
chunks.push(block.slice(start, start + maxChars).trim());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,8 @@ import {
|
||||
} from './rag-utils.mjs';
|
||||
|
||||
const config = readConfig();
|
||||
const query = readArg(process.argv, '--query') ?? process.argv.slice(2).join(' ');
|
||||
const query =
|
||||
readArg(process.argv, '--query') ?? process.argv.slice(2).join(' ');
|
||||
const limit = Number(readArg(process.argv, '--limit', '8'));
|
||||
const maxChars = Number(readArg(process.argv, '--max-chars', '12000'));
|
||||
const format = readArg(process.argv, '--format', 'context');
|
||||
@@ -30,7 +31,11 @@ if (!Number.isFinite(limit) || limit <= 0 || !Number.isInteger(limit)) {
|
||||
throw new Error(`Invalid --limit value: ${limit}`);
|
||||
}
|
||||
|
||||
if (!Number.isFinite(maxChars) || maxChars <= 0 || !Number.isInteger(maxChars)) {
|
||||
if (
|
||||
!Number.isFinite(maxChars) ||
|
||||
maxChars <= 0 ||
|
||||
!Number.isInteger(maxChars)
|
||||
) {
|
||||
throw new Error(`Invalid --max-chars value: ${maxChars}`);
|
||||
}
|
||||
|
||||
@@ -42,14 +47,23 @@ const db = await lancedb.connect(join(repoRoot, config.databaseDir));
|
||||
const table = await db.openTable(config.tableName);
|
||||
const rawResults = await table
|
||||
.vectorSearch(queryVector)
|
||||
.select(['id', 'path', 'title', 'chunk_index', 'source_weight', 'text', '_distance'])
|
||||
.select([
|
||||
'id',
|
||||
'path',
|
||||
'title',
|
||||
'chunk_index',
|
||||
'source_weight',
|
||||
'text',
|
||||
'_distance',
|
||||
])
|
||||
.limit(Math.max(limit * 3, limit))
|
||||
.toArray();
|
||||
|
||||
const results = rawResults
|
||||
.map((row) => ({
|
||||
...row,
|
||||
score: (1 / (1 + Number(row._distance ?? 0))) * Number(row.source_weight ?? 1),
|
||||
score:
|
||||
(1 / (1 + Number(row._distance ?? 0))) * Number(row.source_weight ?? 1),
|
||||
}))
|
||||
.sort((a, b) => b.score - a.score)
|
||||
.slice(0, limit);
|
||||
@@ -127,7 +141,10 @@ function capText(text, budget) {
|
||||
if (text.length <= budget) {
|
||||
return { text, truncated: false };
|
||||
}
|
||||
return { text: `${text.slice(0, Math.max(0, budget - 18)).trimEnd()}\n[TRUNCATED]`, truncated: true };
|
||||
return {
|
||||
text: `${text.slice(0, Math.max(0, budget - 18)).trimEnd()}\n[TRUNCATED]`,
|
||||
truncated: true,
|
||||
};
|
||||
}
|
||||
|
||||
function formatContextPack(payload) {
|
||||
@@ -176,13 +193,18 @@ function formatContextPack(payload) {
|
||||
}
|
||||
|
||||
function buildMarkdownFence(text) {
|
||||
const longest = Math.max(3, ...Array.from(text.matchAll(/`+/gu), (match) => match[0].length));
|
||||
const longest = Math.max(
|
||||
3,
|
||||
...Array.from(text.matchAll(/`+/gu), (match) => match[0].length),
|
||||
);
|
||||
return '`'.repeat(longest + 1);
|
||||
}
|
||||
|
||||
function printTextResults(rows) {
|
||||
for (const result of rows) {
|
||||
const preview = String(result.text ?? '').replace(/\s+/gu, ' ').slice(0, 260);
|
||||
const preview = String(result.text ?? '')
|
||||
.replace(/\s+/gu, ' ')
|
||||
.slice(0, 260);
|
||||
console.log(
|
||||
[
|
||||
`${result.rank}. ${result.source}`,
|
||||
|
||||
Reference in New Issue
Block a user