diff options
| author | Ben Sima <ben@bensima.com> | 2025-12-01 18:50:03 -0500 |
|---|---|---|
| committer | Ben Sima <ben@bensima.com> | 2025-12-01 18:50:03 -0500 |
| commit | d78a9a5038fb95f4035812b4ef5b0c25036aae4a (patch) | |
| tree | 5396bac2ced88607aa17f10baeed0e83b760515c /Omni/Lint.hs | |
| parent | dbbad7cff74411b39db6d619a2a1ad6512aad634 (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-x | Omni/Lint.hs | 31 |
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 |
