Reduce ls spam: cap output at 100 entries, steer generated-code toward glob/grep

ober

a4bf094f0145a18a01ea7761f6f884d1b6d645ed

diff --git a/lib/jcode/core/agent.sls b/lib/jcode/core/agent.sls
index 6596110..740965d 100644
--- a/lib/jcode/core/agent.sls
+++ b/lib/jcode/core/agent.sls
@@ -19,7 +19,7 @@
   (def current-model-override (make-parameter #f))
   (def (system-prompt)
        (format
-         "You are an expert AI coding assistant. You help users with software development tasks.\nWorking directory: ~a\nCurrent mode: ~a\n\nYou have access to these tools:\n- read, write, edit, multi-edit: Read and modify files\n- glob, grep, ls: Search and list files\n- bash: Execute shell commands\n- fetch: HTTP requests\n- batch: Run multiple tool calls in parallel\n- git_status, git_diff, git_log, git_show, git_commit: Git operations\n\n~a\n\nWhen the user asks you to do something:\n1. Think about what tools you need\n2. Use tools to gather information or make changes\n3. Report back with results\n\nBe concise and helpful. When editing files, make minimal targeted changes.\nPrefer using the edit tool over write for modifying existing files."
+         "You are an expert AI coding assistant. You help users with software development tasks.\nWorking directory: ~a\nCurrent mode: ~a\n\nYou have access to these tools:\n- read, write, edit, multi-edit: Read and modify files\n- glob, grep: Search files by pattern or content (prefer these over ls)\n- ls: List directory contents (use sparingly — prefer glob/grep to explore)\n- bash: Execute shell commands\n- fetch: HTTP requests\n- batch: Run multiple tool calls in parallel\n- git_status, git_diff, git_log, git_show, git_commit: Git operations\n\n~a\n\nIMPORTANT: Do NOT call the same tool repeatedly with the same or similar arguments.\nIf you already retrieved information, use what you have. Use batch to parallelize.\nUse glob to find files by pattern instead of exploring directory by directory with ls.\n\nWhen the user asks you to do something:\n1. Think about what tools you need\n2. Use tools to gather information or make changes\n3. Report back with results\n\nBe concise and helpful. When editing files, make minimal targeted changes.\nPrefer using the edit tool over write for modifying existing files."
          (current-directory)
          (mode-label (current-mode))
          (mode-instructions (current-mode))))
diff --git a/lib/jcode/tool/file.sls b/lib/jcode/tool/file.sls
index fe2e0c1..1a25ab9 100644
--- a/lib/jcode/tool/file.sls
+++ b/lib/jcode/tool/file.sls
@@ -126,9 +126,16 @@
                                        (string-append e "/")
                                        e)))
                                sorted)])
-              (if (null? lines)
-                  "(empty directory)"
-                  (string-join lines "\n")))])))
+              (let ([total (length lines)])
+                (cond
+                  [(null? lines) "(empty directory)"]
+                  [(<= total 100) (string-join lines "\n")]
+                  [else
+                   (string-append
+                     (string-join (take lines 100) "\n")
+                     (format
+                       "\n... (~a more entries, use glob to search)"
+                       (- total 100)))])))])))
   (def (handle-read args)
        (let ([path (hash-ref args "path" #f)])
          (unless path
diff --git a/src/jcode/core/agent.ss b/src/jcode/core/agent.ss
index 0a349c2..2798ab9 100644
--- a/src/jcode/core/agent.ss
+++ b/src/jcode/core/agent.ss
@@ -30,7 +30,8 @@ Current mode: ~a
 
 You have access to these tools:
 - read, write, edit, multi-edit: Read and modify files
-- glob, grep, ls: Search and list files
+- glob, grep: Search files by pattern or content (prefer these over ls)
+- ls: List directory contents (use sparingly — prefer glob/grep to explore)
 - bash: Execute shell commands
 - fetch: HTTP requests
 - batch: Run multiple tool calls in parallel
@@ -38,6 +39,10 @@ You have access to these tools:
 
 ~a
 
+IMPORTANT: Do NOT call the same tool repeatedly with the same or similar arguments.
+If you already retrieved information, use what you have. Use batch to parallelize.
+Use glob to find files by pattern instead of exploring directory by directory with ls.
+
 When the user asks you to do something:
 1. Think about what tools you need
 2. Use tools to gather information or make changes
diff --git a/src/jcode/tool/file.ss b/src/jcode/tool/file.ss
index 935ec83..5a8ddc2 100644
--- a/src/jcode/tool/file.ss
+++ b/src/jcode/tool/file.ss
@@ -83,9 +83,15 @@
                                   (string-append e "/")
                                   e)))
                             sorted)))
-         (if (null? lines)
-           "(empty directory)"
-           (string-join lines "\n")))))))
+         (let ((total (length lines)))
+           (cond
+             ((null? lines) "(empty directory)")
+             ((<= total 100)
+              (string-join lines "\n"))
+             (else
+              (string-append
+                (string-join (take lines 100) "\n")
+                (format "\n... (~a more entries, use glob to search)" (- total 100)))))))))))
 
 ;;; READ ;;;