refactor(detekt): extract magic-number constants, wrap long lines, drop legit suppressions
Mechanical detekt cleanup across apps/core/infrastructure (behavior-preserving): - MagicNumber 62->10: named constants + removed 'legit' MagicNumber suppressions (Tier level from ordinal, ReplayInferenceProvider CHARS_PER_TOKEN, ConfigLoader DEFAULT_* consts, capability scores, HTTP ranges, column widths, etc.) - MaxLineLength cut to ~0 in production modules (line wraps, no logic change) - Dropped one dead parameter (ConfigLoader.parseArray lineNum) Structural findings (ReturnCount/LongMethod/Complexity/LargeClass) left for a deliberate decomposition pass. Full build + detekt gate green.
This commit is contained in:
@@ -104,7 +104,10 @@ internal object SimpleToml {
|
||||
ch == '\\' && inQuotes && quoteChar == '"' -> { current.append(ch); escaped = true }
|
||||
(ch == '"' || ch == '\'') && !inQuotes -> { inQuotes = true; quoteChar = ch; current.append(ch) }
|
||||
ch == quoteChar && inQuotes -> { inQuotes = false; current.append(ch) }
|
||||
ch == ',' && !inQuotes -> { result.add(stripQuotes(current.toString().trim())); current = StringBuilder() }
|
||||
ch == ',' && !inQuotes -> {
|
||||
result.add(stripQuotes(current.toString().trim()))
|
||||
current = StringBuilder()
|
||||
}
|
||||
else -> current.append(ch)
|
||||
}
|
||||
}
|
||||
@@ -181,6 +184,46 @@ object ProfileLoader {
|
||||
}
|
||||
|
||||
object ConfigLoader {
|
||||
private const val DEFAULT_SERVER_PORT = 8080
|
||||
private const val DEFAULT_SESSION_LIST_LIMIT = 5
|
||||
private const val DEFAULT_EMBEDDER_DIMENSION = 1536
|
||||
private const val DEFAULT_L3_DIM = 1536
|
||||
private const val DEFAULT_L3_BIT_WIDTH = 4
|
||||
private const val DEFAULT_GENERATION_TEMPERATURE = 0.7
|
||||
private const val DEFAULT_GENERATION_TOP_P = 0.9
|
||||
private const val DEFAULT_GENERATION_MAX_TOKENS = 512
|
||||
private const val DEFAULT_NARRATION_TEMPERATURE = 0.7
|
||||
private const val DEFAULT_NARRATION_TOP_P = 0.9
|
||||
private const val DEFAULT_NARRATION_MAX_TOKENS = 4096
|
||||
private const val DEFAULT_NARRATION_MAX_PER_RUN = 100
|
||||
private const val DEFAULT_CONVERSATION_KEEP_LAST = 6
|
||||
private const val DEFAULT_RETRIEVAL_K = 5
|
||||
private const val DEFAULT_TOKEN_BUDGET = 4096
|
||||
private const val DEFAULT_MODEL_CONTEXT_SIZE = 8192
|
||||
private const val DEFAULT_PROJECT_MEMORY_K = 5
|
||||
private const val DEFAULT_PROJECT_MAX_DEPTH = 4
|
||||
private const val DEFAULT_PROJECT_INJECT_TOP_K = 30
|
||||
private const val DEFAULT_STAGE_TIMEOUT_MS = 180_000L
|
||||
private const val DEFAULT_JOURNAL_COMPACTION_TOKEN_THRESHOLD = 2_000
|
||||
private const val DEFAULT_RESUME_ABANDONED_MAX_AGE_MINUTES = 1_440L
|
||||
private const val DEFAULT_COMPRESSION_LEVEL = 4
|
||||
private const val DEFAULT_MAX_TOOL_ROUNDS = 30
|
||||
private const val DEFAULT_READ_LOOP_NUDGE_THRESHOLD = 3
|
||||
private const val DEFAULT_REJECTION_LOOP_NUDGE_THRESHOLD = 3
|
||||
private const val DEFAULT_MAX_FEEDBACK_ISSUES = 3
|
||||
private const val DEFAULT_REPO_MAP_INJECT_TOP_K = 30
|
||||
private const val DEFAULT_REPO_MAP_FILES_PER_DIR = 8
|
||||
private const val DEFAULT_DOCS_CATALOG_MAX = 20
|
||||
private const val DEFAULT_MAX_CLARIFICATION_ROUNDS = 3
|
||||
private const val DEFAULT_REVIEW_BLOCK_MIN_CONFIDENCE = 0.7
|
||||
private const val DEFAULT_REVIEW_BLOCK_RETRY_CAP = 20
|
||||
private const val DEFAULT_MAX_REFINEMENT = 3
|
||||
private const val DEFAULT_RECOVERY_ROUTE_BUDGET = 2
|
||||
private const val DEFAULT_INTENT_ROUTE_BUDGET = 2
|
||||
private const val DEFAULT_MODELS_PORT = 10000
|
||||
private const val DEFAULT_SAMPLING_TOP_P = 1.0
|
||||
private const val DEFAULT_SAMPLING_TEMPERATURE = 0.7
|
||||
|
||||
fun load(): CorrexConfig {
|
||||
val path = configPath()
|
||||
if (!Files.exists(path)) {
|
||||
@@ -302,7 +345,7 @@ object ConfigLoader {
|
||||
}
|
||||
// JSON-style array: ["item1", "item2"]
|
||||
valueStr.startsWith("[") && valueStr.endsWith("]") -> {
|
||||
parseArray(valueStr, lineNum)
|
||||
parseArray(valueStr)
|
||||
}
|
||||
// CSV fallback for backward compat (detect by "," and "=" pattern without brackets)
|
||||
valueStr.contains(",") && valueStr.contains("=") && !valueStr.startsWith("\"") -> {
|
||||
@@ -336,7 +379,7 @@ object ConfigLoader {
|
||||
return result
|
||||
}
|
||||
|
||||
private fun parseArray(arrayStr: String, lineNum: Int): List<String> {
|
||||
private fun parseArray(arrayStr: String): List<String> {
|
||||
val result = mutableListOf<String>()
|
||||
val content = arrayStr.substring(1, arrayStr.length - 1).trim()
|
||||
if (content.isEmpty()) return result
|
||||
@@ -430,12 +473,12 @@ object ConfigLoader {
|
||||
|
||||
val server = ServerConfig(
|
||||
host = asString(serverSection["host"], "localhost"),
|
||||
port = asInt(serverSection["port"], 8080),
|
||||
port = asInt(serverSection["port"], DEFAULT_SERVER_PORT),
|
||||
)
|
||||
|
||||
val tui = TuiConfig(
|
||||
theme = asString(tuiSection["theme"], "dark"),
|
||||
sessionListLimit = asInt(tuiSection["session_list_limit"], 5),
|
||||
sessionListLimit = asInt(tuiSection["session_list_limit"], DEFAULT_SESSION_LIST_LIMIT),
|
||||
)
|
||||
|
||||
val cli = CliConfig(
|
||||
@@ -447,7 +490,9 @@ object ConfigLoader {
|
||||
val shellEnabled = when {
|
||||
toolsShellSection.containsKey("enabled") -> asBoolean(toolsShellSection["enabled"], true)
|
||||
toolsSection.containsKey("shell_enabled") -> {
|
||||
System.err.println("Warning: 'shell_enabled' in [tools] is deprecated, use [tools.shell] enabled instead")
|
||||
System.err.println(
|
||||
"Warning: 'shell_enabled' in [tools] is deprecated, use [tools.shell] enabled instead"
|
||||
)
|
||||
asBoolean(toolsSection["shell_enabled"], true)
|
||||
}
|
||||
else -> true
|
||||
@@ -456,7 +501,9 @@ object ConfigLoader {
|
||||
val fileReadEnabled = when {
|
||||
toolsFileReadSection.containsKey("enabled") -> asBoolean(toolsFileReadSection["enabled"], true)
|
||||
toolsSection.containsKey("file_read_enabled") -> {
|
||||
System.err.println("Warning: 'file_read_enabled' in [tools] is deprecated, use [tools.file_read] enabled instead")
|
||||
System.err.println(
|
||||
"Warning: 'file_read_enabled' in [tools] is deprecated, use [tools.file_read] enabled instead"
|
||||
)
|
||||
asBoolean(toolsSection["file_read_enabled"], true)
|
||||
}
|
||||
else -> true
|
||||
@@ -465,7 +512,9 @@ object ConfigLoader {
|
||||
val fileWriteEnabled = when {
|
||||
toolsFileWriteSection.containsKey("enabled") -> asBoolean(toolsFileWriteSection["enabled"], true)
|
||||
toolsSection.containsKey("file_write_enabled") -> {
|
||||
System.err.println("Warning: 'file_write_enabled' in [tools] is deprecated, use [tools.file_write] enabled instead")
|
||||
System.err.println(
|
||||
"Warning: 'file_write_enabled' in [tools] is deprecated, use [tools.file_write] enabled instead"
|
||||
)
|
||||
asBoolean(toolsSection["file_write_enabled"], true)
|
||||
}
|
||||
else -> true
|
||||
@@ -474,7 +523,9 @@ object ConfigLoader {
|
||||
val fileEditEnabled = when {
|
||||
toolsFileEditSection.containsKey("enabled") -> asBoolean(toolsFileEditSection["enabled"], true)
|
||||
toolsSection.containsKey("file_edit_enabled") -> {
|
||||
System.err.println("Warning: 'file_edit_enabled' in [tools] is deprecated, use [tools.file_edit] enabled instead")
|
||||
System.err.println(
|
||||
"Warning: 'file_edit_enabled' in [tools] is deprecated, use [tools.file_edit] enabled instead"
|
||||
)
|
||||
asBoolean(toolsSection["file_edit_enabled"], true)
|
||||
}
|
||||
else -> true
|
||||
@@ -491,7 +542,9 @@ object ConfigLoader {
|
||||
val1 is String -> {
|
||||
// Backward compat: check if it's CSV or already a single item
|
||||
if (val1.contains(",")) {
|
||||
System.err.println("Warning: CSV format 'shell_allowed_executables' is deprecated, use JSON array instead")
|
||||
System.err.println(
|
||||
"Warning: CSV format 'shell_allowed_executables' is deprecated, use JSON array instead"
|
||||
)
|
||||
val1.split(",").map { it.trim() }.filter { it.isNotEmpty() }
|
||||
} else {
|
||||
listOf(val1)
|
||||
@@ -547,7 +600,7 @@ object ConfigLoader {
|
||||
|
||||
val embedder = EmbedderConfig(
|
||||
backend = asString(routerEmbedderSection["backend"], "noop"),
|
||||
dimension = asInt(routerEmbedderSection["dimension"], 1536),
|
||||
dimension = asInt(routerEmbedderSection["dimension"], DEFAULT_EMBEDDER_DIMENSION),
|
||||
url = asStringOrNull(routerEmbedderSection["url"]),
|
||||
modelId = asStringOrNull(routerEmbedderSection["model_id"]),
|
||||
)
|
||||
@@ -557,30 +610,30 @@ object ConfigLoader {
|
||||
persistPath = asStringOrNull(routerL3Section["persist_path"]),
|
||||
pythonExecutable = asString(routerL3Section["python_executable"], "python3"),
|
||||
scriptPath = asStringOrNull(routerL3Section["script_path"]),
|
||||
dim = asInt(routerL3Section["dim"], 1536),
|
||||
bitWidth = asInt(routerL3Section["bit_width"], 4),
|
||||
dim = asInt(routerL3Section["dim"], DEFAULT_L3_DIM),
|
||||
bitWidth = asInt(routerL3Section["bit_width"], DEFAULT_L3_BIT_WIDTH),
|
||||
)
|
||||
|
||||
val generation = GenerationSettings(
|
||||
temperature = asDouble(routerGenerationSection["temperature"], 0.7),
|
||||
topP = asDouble(routerGenerationSection["top_p"], 0.9),
|
||||
maxTokens = asInt(routerGenerationSection["max_tokens"], 512),
|
||||
temperature = asDouble(routerGenerationSection["temperature"], DEFAULT_GENERATION_TEMPERATURE),
|
||||
topP = asDouble(routerGenerationSection["top_p"], DEFAULT_GENERATION_TOP_P),
|
||||
maxTokens = asInt(routerGenerationSection["max_tokens"], DEFAULT_GENERATION_MAX_TOKENS),
|
||||
)
|
||||
|
||||
val narration = NarrationSettings(
|
||||
temperature = asDouble(routerNarrationSection["temperature"], 0.7),
|
||||
topP = asDouble(routerNarrationSection["top_p"], 0.9),
|
||||
maxTokens = asInt(routerNarrationSection["max_tokens"], 4096),
|
||||
maxPerRun = asInt(routerNarrationSection["max_per_run"], 100),
|
||||
temperature = asDouble(routerNarrationSection["temperature"], DEFAULT_NARRATION_TEMPERATURE),
|
||||
topP = asDouble(routerNarrationSection["top_p"], DEFAULT_NARRATION_TOP_P),
|
||||
maxTokens = asInt(routerNarrationSection["max_tokens"], DEFAULT_NARRATION_MAX_TOKENS),
|
||||
maxPerRun = asInt(routerNarrationSection["max_per_run"], DEFAULT_NARRATION_MAX_PER_RUN),
|
||||
modelId = asStringOrNull(routerNarrationSection["model_id"]),
|
||||
)
|
||||
|
||||
val router = TalkieConfig(
|
||||
embedder = embedder,
|
||||
l3 = l3,
|
||||
conversationKeepLast = asInt(routerSection["conversation_keep_last"], 6),
|
||||
retrievalK = asInt(routerSection["retrieval_k"], 5),
|
||||
tokenBudget = asInt(routerSection["token_budget"], 4096),
|
||||
conversationKeepLast = asInt(routerSection["conversation_keep_last"], DEFAULT_CONVERSATION_KEEP_LAST),
|
||||
retrievalK = asInt(routerSection["retrieval_k"], DEFAULT_RETRIEVAL_K),
|
||||
tokenBudget = asInt(routerSection["token_budget"], DEFAULT_TOKEN_BUDGET),
|
||||
generation = generation,
|
||||
narration = narration,
|
||||
)
|
||||
@@ -588,7 +641,7 @@ object ConfigLoader {
|
||||
val models = modelsList.mapNotNull { modelMap ->
|
||||
val id = asString(modelMap["id"]) ?: return@mapNotNull null
|
||||
val modelPath = asString(modelMap["model_path"]) ?: return@mapNotNull null
|
||||
val contextSize = asInt(modelMap["context_size"], 8192)
|
||||
val contextSize = asInt(modelMap["context_size"], DEFAULT_MODEL_CONTEXT_SIZE)
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val params = (modelMap["params"] as? Map<String, Any>)
|
||||
?.mapValues { it.value.toString() }
|
||||
@@ -614,42 +667,53 @@ object ConfigLoader {
|
||||
val project = ProjectConfig(
|
||||
enabled = asBoolean(projectSection["enabled"], false),
|
||||
root = asString(projectSection["root"], ""),
|
||||
memoryK = asInt(projectSection["memory_k"], 5),
|
||||
maxDepth = asInt(projectSection["max_depth"], 4),
|
||||
memoryK = asInt(projectSection["memory_k"], DEFAULT_PROJECT_MEMORY_K),
|
||||
maxDepth = asInt(projectSection["max_depth"], DEFAULT_PROJECT_MAX_DEPTH),
|
||||
ignoreGlobs = asStringList(projectSection["ignore_globs"]).ifEmpty { ProjectConfig.DEFAULT_IGNORES },
|
||||
injectTopK = asInt(projectSection["inject_top_k"], 30),
|
||||
injectTopK = asInt(projectSection["inject_top_k"], DEFAULT_PROJECT_INJECT_TOP_K),
|
||||
)
|
||||
|
||||
val orchestrationSection = sections["orchestration"] ?: emptyMap()
|
||||
val orchestration = OrchestrationKnobs(
|
||||
stageTimeoutMs = asLong(orchestrationSection["stage_timeout_ms"], 180_000),
|
||||
journalCompactionTokenThreshold =
|
||||
asInt(orchestrationSection["journal_compaction_token_threshold"], 2_000),
|
||||
resumeAbandonedMaxAgeMinutes =
|
||||
asLong(orchestrationSection["resume_abandoned_max_age_minutes"], 1_440),
|
||||
compressionLevel = asInt(orchestrationSection["compression_level"], 4),
|
||||
stageTimeoutMs = asLong(orchestrationSection["stage_timeout_ms"], DEFAULT_STAGE_TIMEOUT_MS),
|
||||
journalCompactionTokenThreshold = asInt(
|
||||
orchestrationSection["journal_compaction_token_threshold"],
|
||||
DEFAULT_JOURNAL_COMPACTION_TOKEN_THRESHOLD,
|
||||
),
|
||||
resumeAbandonedMaxAgeMinutes = asLong(
|
||||
orchestrationSection["resume_abandoned_max_age_minutes"],
|
||||
DEFAULT_RESUME_ABANDONED_MAX_AGE_MINUTES,
|
||||
),
|
||||
compressionLevel = asInt(orchestrationSection["compression_level"], DEFAULT_COMPRESSION_LEVEL),
|
||||
tokenPrunerUrl =
|
||||
asString(orchestrationSection["token_pruner_url"], "http://127.0.0.1:8199"),
|
||||
maxToolRounds = asInt(orchestrationSection["max_tool_rounds"], 30),
|
||||
readLoopNudgeThreshold = asInt(orchestrationSection["read_loop_nudge_threshold"], 3),
|
||||
rejectionLoopNudgeThreshold = asInt(orchestrationSection["rejection_loop_nudge_threshold"], 3),
|
||||
maxFeedbackIssues = asInt(orchestrationSection["max_feedback_issues"], 3),
|
||||
repoMapInjectTopK = asInt(orchestrationSection["repo_map_inject_top_k"], 30),
|
||||
repoMapFilesPerDir = asInt(orchestrationSection["repo_map_files_per_dir"], 8),
|
||||
docsCatalogMax = asInt(orchestrationSection["docs_catalog_max"], 20),
|
||||
maxClarificationRounds = asInt(orchestrationSection["max_clarification_rounds"], 3),
|
||||
reviewBlockMinConfidence = asDouble(orchestrationSection["review_block_min_confidence"], 0.7),
|
||||
reviewBlockRetryCap = asInt(orchestrationSection["review_block_retry_cap"], 20),
|
||||
defaultMaxRefinement = asInt(orchestrationSection["default_max_refinement"], 3),
|
||||
recoveryRouteBudget = asInt(orchestrationSection["recovery_route_budget"], 2),
|
||||
intentRouteBudget = asInt(orchestrationSection["intent_route_budget"], 2),
|
||||
maxToolRounds = asInt(orchestrationSection["max_tool_rounds"], DEFAULT_MAX_TOOL_ROUNDS),
|
||||
readLoopNudgeThreshold =
|
||||
asInt(orchestrationSection["read_loop_nudge_threshold"], DEFAULT_READ_LOOP_NUDGE_THRESHOLD),
|
||||
rejectionLoopNudgeThreshold = asInt(
|
||||
orchestrationSection["rejection_loop_nudge_threshold"],
|
||||
DEFAULT_REJECTION_LOOP_NUDGE_THRESHOLD,
|
||||
),
|
||||
maxFeedbackIssues = asInt(orchestrationSection["max_feedback_issues"], DEFAULT_MAX_FEEDBACK_ISSUES),
|
||||
repoMapInjectTopK = asInt(orchestrationSection["repo_map_inject_top_k"], DEFAULT_REPO_MAP_INJECT_TOP_K),
|
||||
repoMapFilesPerDir =
|
||||
asInt(orchestrationSection["repo_map_files_per_dir"], DEFAULT_REPO_MAP_FILES_PER_DIR),
|
||||
docsCatalogMax = asInt(orchestrationSection["docs_catalog_max"], DEFAULT_DOCS_CATALOG_MAX),
|
||||
maxClarificationRounds =
|
||||
asInt(orchestrationSection["max_clarification_rounds"], DEFAULT_MAX_CLARIFICATION_ROUNDS),
|
||||
reviewBlockMinConfidence =
|
||||
asDouble(orchestrationSection["review_block_min_confidence"], DEFAULT_REVIEW_BLOCK_MIN_CONFIDENCE),
|
||||
reviewBlockRetryCap = asInt(orchestrationSection["review_block_retry_cap"], DEFAULT_REVIEW_BLOCK_RETRY_CAP),
|
||||
defaultMaxRefinement = asInt(orchestrationSection["default_max_refinement"], DEFAULT_MAX_REFINEMENT),
|
||||
recoveryRouteBudget = asInt(orchestrationSection["recovery_route_budget"], DEFAULT_RECOVERY_ROUTE_BUDGET),
|
||||
intentRouteBudget = asInt(orchestrationSection["intent_route_budget"], DEFAULT_INTENT_ROUTE_BUDGET),
|
||||
)
|
||||
|
||||
val modelsSettings = ModelsSettings(
|
||||
defaultModel = asStringOrNull(modelsSection["default_model"]),
|
||||
llamaServerBin = asString(modelsSection["llama_server_bin"], "llama-server"),
|
||||
host = asString(modelsSection["host"], "127.0.0.1"),
|
||||
port = asInt(modelsSection["port"], 10000),
|
||||
port = asInt(modelsSection["port"], DEFAULT_MODELS_PORT),
|
||||
)
|
||||
|
||||
val artifacts = artifactsList.mapNotNull { artifactMap ->
|
||||
@@ -664,8 +728,8 @@ object ConfigLoader {
|
||||
|
||||
val samplingSection = sections["sampling"] ?: emptyMap()
|
||||
val sampling = SamplingConfig(
|
||||
temperature = asDouble(samplingSection["temperature"], 0.7),
|
||||
topP = asDouble(samplingSection["top_p"], 1.0),
|
||||
temperature = asDouble(samplingSection["temperature"], DEFAULT_SAMPLING_TEMPERATURE),
|
||||
topP = asDouble(samplingSection["top_p"], DEFAULT_SAMPLING_TOP_P),
|
||||
topK = samplingSection["top_k"]?.let { asInt(it) },
|
||||
minP = samplingSection["min_p"]?.let { asDouble(it) },
|
||||
repeatPenalty = samplingSection["repeat_penalty"]?.let { asDouble(it) },
|
||||
|
||||
@@ -184,7 +184,11 @@ object EditableConfig {
|
||||
"orchestration.resume_abandoned_max_age_minutes", ConfigFieldType.LONG,
|
||||
getString = { it.orchestration.resumeAbandonedMaxAgeMinutes.toString() },
|
||||
withString = { c, v ->
|
||||
orc(c) { it.copy(resumeAbandonedMaxAgeMinutes = lng("orchestration.resume_abandoned_max_age_minutes", v)) }
|
||||
orc(c) {
|
||||
it.copy(
|
||||
resumeAbandonedMaxAgeMinutes = lng("orchestration.resume_abandoned_max_age_minutes", v)
|
||||
)
|
||||
}
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
@@ -17,7 +17,9 @@ object OperatorProfileWriter {
|
||||
}
|
||||
|
||||
val prefs = profile.preferences
|
||||
val hasPrefs = prefs.approvalMode.isNotBlank() || prefs.preferredModels.isNotEmpty() || prefs.conventions.isNotEmpty()
|
||||
val hasPrefs = prefs.approvalMode.isNotBlank() ||
|
||||
prefs.preferredModels.isNotEmpty() ||
|
||||
prefs.conventions.isNotEmpty()
|
||||
if (hasPrefs) {
|
||||
if (b.isNotEmpty()) b.append('\n')
|
||||
b.append("[preferences]\n")
|
||||
|
||||
Reference in New Issue
Block a user