mirror of
https://github.com/giancarloerra/socraticode.git
synced 2026-07-03 14:05:21 +02:00
feat: support global config fallback and configurable batch size
- loadConfig: fall back to ~/.claude/arch (or SOCRATICODE_GLOBAL_CONFIG_DIR env var) when project root has no .socraticodecontextartifacts.json - BATCH_SIZE: configurable via EMBEDDING_BATCH_SIZE env var, default 32 (validates positive integer, throws on invalid input)
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
|
||||
import { createHash } from "node:crypto";
|
||||
import fsp from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { glob } from "glob";
|
||||
import { contextCollectionName, projectIdFromPath } from "../config.js";
|
||||
@@ -52,14 +53,25 @@ export interface SocratiCodeConfig {
|
||||
*/
|
||||
export async function loadConfig(projectPath: string): Promise<SocratiCodeConfig | null> {
|
||||
const configPath = path.join(path.resolve(projectPath), CONFIG_FILENAME);
|
||||
// Fall back to a global config location when no project-level config exists.
|
||||
// Configurable via env var SOCRATICODE_GLOBAL_CONFIG_DIR; defaults to ~/.claude/arch.
|
||||
const globalConfigDir =
|
||||
process.env.SOCRATICODE_GLOBAL_CONFIG_DIR || path.join(os.homedir(), ".claude", "arch");
|
||||
const globalConfigPath = path.join(globalConfigDir, CONFIG_FILENAME);
|
||||
let actualPath = configPath;
|
||||
|
||||
try {
|
||||
await fsp.access(configPath);
|
||||
} catch {
|
||||
return null; // file doesn't exist — that's fine
|
||||
try {
|
||||
await fsp.access(globalConfigPath);
|
||||
actualPath = globalConfigPath;
|
||||
} catch {
|
||||
return null; // neither project nor global file exists — that's fine
|
||||
}
|
||||
}
|
||||
|
||||
const raw = await fsp.readFile(configPath, "utf-8");
|
||||
const raw = await fsp.readFile(actualPath, "utf-8");
|
||||
let parsed: unknown;
|
||||
try {
|
||||
parsed = JSON.parse(raw);
|
||||
|
||||
@@ -5,7 +5,19 @@ import { getEmbeddingConfig } from "./embedding-config.js";
|
||||
import { getEmbeddingProvider } from "./embedding-provider.js";
|
||||
import { logger } from "./logger.js";
|
||||
|
||||
const BATCH_SIZE = 32; // Number of texts to embed per provider request
|
||||
// Number of texts to embed per provider request.
|
||||
// Configurable via env var EMBEDDING_BATCH_SIZE (positive integer); defaults to 32.
|
||||
const BATCH_SIZE: number = (() => {
|
||||
const raw = process.env.EMBEDDING_BATCH_SIZE;
|
||||
if (!raw) return 32;
|
||||
const parsed = Number.parseInt(raw, 10);
|
||||
if (!Number.isFinite(parsed) || parsed <= 0) {
|
||||
throw new Error(
|
||||
`Invalid EMBEDDING_BATCH_SIZE: "${raw}". Must be a positive integer.`,
|
||||
);
|
||||
}
|
||||
return parsed;
|
||||
})();
|
||||
const MAX_RETRIES = 3;
|
||||
const BASE_DELAY_MS = 500;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user