summaryrefslogtreecommitdiff
path: root/Omni/Lint.hs
diff options
context:
space:
mode:
authorBen Sima <ben@bensima.com>2025-12-01 18:50:03 -0500
committerBen Sima <ben@bensima.com>2025-12-01 18:50:03 -0500
commitd78a9a5038fb95f4035812b4ef5b0c25036aae4a (patch)
tree5396bac2ced88607aa17f10baeed0e83b760515c /Omni/Lint.hs
parentdbbad7cff74411b39db6d619a2a1ad6512aad634 (diff)
Add lint warning for large files (>1000 lines)
Large files cause agent token bloat and edit_file failures. This adds a warning (not error) to encourage splitting. Task-Id: t-228
Diffstat (limited to 'Omni/Lint.hs')
-rwxr-xr-xOmni/Lint.hs31
1 files changed, 30 insertions, 1 deletions
diff --git a/Omni/Lint.hs b/Omni/Lint.hs
index c6b6878..7a0a888 100755
--- a/Omni/Lint.hs
+++ b/Omni/Lint.hs
@@ -260,7 +260,36 @@ data Result
| NoOp Namespace.Ext
run :: Mode -> Map Namespace.Ext [Namespace] -> IO [Result]
-run mode nsmap = nsmap |> Map.assocs |> traverse (runOne mode) /> concat
+run mode nsmap = do
+ -- Run large file check first (warns but doesn't fail)
+ let allNamespaces = concat (Map.elems nsmap)
+ largeFileResults <- checkLargeFiles allNamespaces
+ traverse_ printResult largeFileResults
+ -- Then run per-extension linters
+ lintResults <- nsmap |> Map.assocs |> traverse (runOne mode) /> concat
+ pure (largeFileResults ++ lintResults)
+
+-- | Check for files exceeding the line limit
+-- Large files cause agent token bloat and edit_file failures
+checkLargeFiles :: [Namespace] -> IO [Result]
+checkLargeFiles ns's = catMaybes </ traverse checkOne ns's
+ where
+ maxLines = 1000 :: Int
+ checkOne ns = do
+ let path = Namespace.toPath ns
+ contents <- readFile path
+ let lineCount = length (lines contents)
+ if lineCount > maxLines
+ then do
+ let msg =
+ Text.pack path
+ <> " has "
+ <> tshow lineCount
+ <> " lines (max "
+ <> tshow maxLines
+ <> "), consider splitting"
+ pure (Just (Warn msg))
+ else pure Nothing
runOne :: Mode -> (Ext, [Namespace]) -> IO [Result]
runOne mode (ext, ns's) = results +> traverse printResult