Balance tiny-context compaction

ober

4c44d748ae3f45577ad51c10550089ed6ffa2d61

diff --git a/src/jcode/core/agent.ss b/src/jcode/core/agent.ss
index 485acaa..df600c1 100644
--- a/src/jcode/core/agent.ss
+++ b/src/jcode/core/agent.ss
@@ -297,7 +297,7 @@ Be concise. Prefer edit over write for modifying existing files.
 (def *max-tool-rounds* 100)
 (def *max-tool-lines* 2000)
 (def *max-tool-bytes* 51200)  ;; 50KB
-(def *local-max-tool-bytes* 768)
+(def *local-max-tool-bytes* 512)
 
 (def (refresh-system-prompt messages)
   "Replace the leading system message (if any) with a fresh one reflecting
diff --git a/src/jcode/core/compaction-strategy.ss b/src/jcode/core/compaction-strategy.ss
index 8e31694..cfb1f69 100644
--- a/src/jcode/core/compaction-strategy.ss
+++ b/src/jcode/core/compaction-strategy.ss
@@ -246,6 +246,12 @@
 (def (default-compaction-strategy-name budget)
   (if (and budget (<= budget 1024)) "sliding" "tiered"))
 
+(def (default-compaction-keep-recent budget)
+  (cond
+    ((and budget (<= budget 1024)) 2)
+    ((and budget (<= budget 4096)) 1)
+    (else 2)))
+
 (def (run-configured-compaction messages budget)
   "Pick the strategy from jcode.json (compaction.strategy). Tiny budgets
    default to sliding; larger budgets default to tiered. Run it against
@@ -253,7 +259,7 @@
   (let* ((name  (compaction-block-ref "strategy"
                   (default-compaction-strategy-name budget)))
          (keep  (compaction-block-ref "strategy_keep_recent"
-                  (if (and budget (<= budget 4096)) 1 2)))
+                  (default-compaction-keep-recent budget)))
          (thr   (compaction-block-ref "strategy_threshold" 0.75))
          (strat (compaction-strategy-by-name name keep thr))
          (res   (strat messages budget))
diff --git a/test/run.ss b/test/run.ss
index 80967f2..acc2250 100644
--- a/test/run.ss
+++ b/test/run.ss
@@ -841,7 +841,7 @@
   (check! "sliding keeps sys+user+protected" (length (car r)) 3)
   (check! "sliding head is system" (message-role (car (car r))) "system"))
 (let ([r (run-configured-compaction hist-tier 572)])
-  (check! "configured small budget uses sliding" (length r) 3))
+  (check! "configured small budget uses sliding" (length r) 5))
 
 ;; Tiered phase transitions (keep=1, uniform 0.75 threshold).
 ;; budgets: 4000→t3000 (p0), 1200→t900 (p1), 800→t600 (p2), 600→t450 (p3)