glob ex:match-cpp

This commit is contained in:
lovebird 2025-06-03 21:46:06 +02:00
parent 1e6624ce4d
commit 8c3b4b09f9
11 changed files with 90 additions and 11 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -16,6 +16,8 @@ export declare const E_AppendMode: z.ZodEnum<["concat", "merge"]>;
export type E_AppendModeType = z.infer<typeof E_AppendMode>;
export declare const E_WrapMode: z.ZodEnum<["meta", "none"]>;
export type E_WrapModeType = z.infer<typeof E_WrapMode>;
export declare const E_GlobExtension: z.ZodEnum<["match-cpp"]>;
export type E_GlobExtensionType = z.infer<typeof E_GlobExtension>;
export type OptionsSchemaMeta = Record<string, unknown>;
export { fetchOpenRouterModels, listModelsAsStrings as listOpenRouterModelsAsStrings } from './models/openrouter.js';
export { fetchOpenAIModels, listModelsAsStrings as listOpenAIModelsAsStrings } from './models/openai.js';

File diff suppressed because one or more lines are too long

View File

@ -23,6 +23,8 @@ export interface IKBotOptions {
include?: string[] | undefined;
/** Comma separated glob patterns or paths, eg --exclude=src/*.tsx,src/*.ts --exclude=package.json */
exclude?: string[] | undefined;
/** Specify a glob extension behavior. e.g., "match-cpp" to automatically include corresponding .cpp files for .h files. */
globExtension?: string | undefined;
/** Explicit API key to use */
api_key?: string | undefined;
/** AI model to use for processing. Available models:

View File

@ -98,6 +98,10 @@
},
"description": "Comma separated glob patterns or paths, eg --exclude=src/*.tsx,src/*.ts --exclude=package.json"
},
"globExtension": {
"type": "string",
"description": "Specify a glob extension behavior. e.g., \"match-cpp\" to automatically include corresponding .cpp files for .h files."
},
"api_key": {
"type": "string",
"description": "Explicit API key to use"

View File

@ -70,6 +70,10 @@
"ui:description": "Comma separated glob patterns or paths, eg --exclude=src/*.tsx,src/*.ts --exclude=package.json",
"ui:title": "Exclude"
},
"globExtension": {
"ui:description": "Specify a glob extension behavior. e.g., \"match-cpp\" to automatically include corresponding .cpp files for .h files.",
"ui:title": "Globextension"
},
"api_key": {
"ui:description": "Explicit API key to use",
"ui:title": "Api_key"

View File

@ -379,7 +379,20 @@ export const run = async (opts: IKBotTask): Promise<ProcessRunResult[]> => {
if (model) {
itemOpts.model = item
}
itemOpts.include = [...opts.include, ...[forward_slash(item)]]
let currentItemSpecificIncludes = [forward_slash(item)];
const itemPathInfo = path.parse(item);
// Only add corresponding .cpp if --glob-extension=match-cpp is set
if (opts.globExtension === 'match-cpp' && itemPathInfo.ext === '.h') {
const cppFilePath = path.join(itemPathInfo.dir, `${itemPathInfo.name}.cpp`);
if (exists(cppFilePath) && isFile(cppFilePath)) {
currentItemSpecificIncludes.push(forward_slash(cppFilePath));
}
}
itemOpts.include = [...opts.include, ...currentItemSpecificIncludes];
const result = await processRun(itemOpts)
if (result !== undefined) {
ret.push(result)

View File

@ -139,10 +139,25 @@ export async function get(
include: string[] = [],
options: IKBotTask
): Promise<Array<IHandlerResult>> {
const { files, webUrls } = glob(projectPath, include, options.exclude)
const { files: initialFiles, webUrls } = glob(projectPath, include, options.exclude)
// Process file contents
const fileResults = files.map((fullPath) => {
const filesToProcess = new Set<string>(initialFiles.map(f => forward_slash(f)));
// Only add corresponding .cpp if options.globExtension is 'match-cpp'
if (options.globExtension === 'match-cpp') {
for (const initialFile of initialFiles) {
const itemPathInfo = path.parse(initialFile);
if (itemPathInfo.ext === '.h') {
const cppFilePath = path.join(itemPathInfo.dir, `${itemPathInfo.name}.cpp`);
if (exists(cppFilePath) && isFile(cppFilePath)) {
filesToProcess.add(forward_slash(cppFilePath));
}
}
}
}
// Process file contents from the final list of files
const fileResults = Array.from(filesToProcess).map((fullPath) => {
try {
const relativePath = forward_slash(path.relative(projectPath, fullPath))
if (isFile(fullPath) && exists(fullPath)) {

View File

@ -46,6 +46,10 @@ export type E_AppendModeType = z.infer<typeof E_AppendMode>
export const E_WrapMode = z.enum(['meta', 'none'])
export type E_WrapModeType = z.infer<typeof E_WrapMode>
// Define the new enum for glob extensions
export const E_GlobExtension = z.enum(['match-cpp']);
export type E_GlobExtensionType = z.infer<typeof E_GlobExtension>;
export type OptionsSchemaMeta = Record<string, unknown>
export { fetchOpenRouterModels, listModelsAsStrings as listOpenRouterModelsAsStrings } from './models/openrouter.js'
@ -135,6 +139,12 @@ export const OptionsSchema = (opts?: any): any => {
.optional()
.describe('Comma separated glob patterns or paths, eg --exclude=src/*.tsx,src/*.ts --exclude=package.json')
)
.add(
'globExtension',
E_GlobExtension
.optional()
.describe(`Specify a glob extension behavior. Available: ${E_GlobExtension.options.join(', ')}. e.g., "match-cpp" to automatically include corresponding .cpp files for .h files.`)
)
.add(
'api_key',
z.string()

View File

@ -23,6 +23,8 @@ export interface IKBotOptions {
include?: string[] | undefined;
/** Comma separated glob patterns or paths, eg --exclude=src/*.tsx,src/*.ts --exclude=package.json */
exclude?: string[] | undefined;
/** Specify a glob extension behavior. e.g., "match-cpp" to automatically include corresponding .cpp files for .h files. */
globExtension?: string | undefined;
/** Explicit API key to use */
api_key?: string | undefined;
/** AI model to use for processing. Available models: