Move SSD UI status and IO clamps to typed Kotlin

ober

72481a576aa31ba565ef603d1b6e65d7ae8b1b14

diff --git a/templates/ssd-review.ss b/templates/ssd-review.ss
index 1cee625..089588e 100644
--- a/templates/ssd-review.ss
+++ b/templates/ssd-review.ss
@@ -1269,7 +1269,7 @@
                 StorageStats-files StorageStats-files-set!
                 StorageStats-bytes StorageStats-bytes-set!
                 storageSummaryText compressionRatioBudget boundedTreeReadLimit
-                mergedJsonLinesText)
+                boundedReadInitialCapacity mergedJsonLinesText)
         (type Int32)
         (record ImportBudget
           ((mut entries : Int32)
@@ -1294,6 +1294,8 @@
           (maxIntValue floorBytes (* compressedBytes ratio)))
         (def (boundedTreeReadLimit (entryLimit : Int) (remaining : Int)) : Int
           (minIntValue entryLimit remaining))
+        (def (boundedReadInitialCapacity (limit : Int)) : Int
+          (minIntValue limit (int 65536)))
         (def (mergedJsonLinesText (lines : (Set String))) : String
           (joinStringSet
             lines
@@ -3696,7 +3698,8 @@
                 selectedGroupStatus sessionCountsStatus rotatedPageStatus
                 manualGroupLabel manualCellCount editedGroupCount
                 clampPageIndex shiftPageIndex displayGroupCanvasLabel
-                dropdownHeight dialogPageNumber nullableLowercaseOrEmpty)
+                dropdownHeight dialogPageNumber nullableLowercaseOrEmpty
+                selectModeStatus selectionResultStatus)
         (type Int32)
         (def (normalizeFiringArc (value : String)) : String
           (string-uppercase (string-trim value)))
@@ -3834,6 +3837,27 @@
             (if (> third (int32 620))
               (int32 620)
               third)))
+        (def (selectModeStatus (ssdAreaMode : Bool)
+                               (appendMode : Bool)
+                               (selectMode : Bool)) : String
+          (if ssdAreaMode
+            "SSD area mode: drag around the ship SSD; tags outside that area will be removed"
+            (if appendMode
+              "Append mode: drag boxes to add to the selected group"
+              (if selectMode
+                "Select mode: drag a loose box around SSD boxes"
+                "Pan mode"))))
+        (def (selectionResultStatus (snapSelectionToCells : Bool)
+                                    (matchingCount : Int32)) : String
+          (if (not snapSelectionToCells)
+            "SSD area selected"
+            (if (> matchingCount (int32 0))
+              (string-append
+                "Snapped to "
+                (string-append
+                  (int32->string matchingCount)
+                  " detected boxes"))
+              "Shrank rough selection to SSD boxes")))
         (def (editedGroupCount (count : (Nullable Int32))
                                (fallback : Int32)) : Int32
           (if (nullable-null? count)
@@ -5091,14 +5115,7 @@
 	       "            reviewView.snapSelectionToCells = true"
 	       "        }"
 	       "        reviewView.selectMode = enabled"
-	       "        setStatus("
-	       "            when {"
-	       "                ssdAreaMode -> \"SSD area mode: drag around the ship SSD; tags outside that area will be removed\""
-	       "                appendMode -> \"Append mode: drag boxes to add to the selected group\""
-	       "                reviewView.selectMode -> \"Select mode: drag a loose box around SSD boxes\""
-       "                else -> \"Pan mode\""
-       "            }"
-       "        )"
+	       "        setStatus(selectModeStatus(ssdAreaMode, appendMode, reviewView.selectMode))"
        "    }"
        ""
 	       "    private fun finishSelectInteraction() {"
@@ -6836,13 +6853,7 @@
        "                    ?: shrinkRectToInk(it, rect)"
        "            } ?: rect"
        "        }"
-	       "        onStatus?.invoke("
-	       "            when {"
-	       "                !snapSelectionToCells -> \"SSD area selected\""
-	       "                matching.isNotEmpty() -> \"Snapped to ${matching.size} detected boxes\""
-	       "                else -> \"Shrank rough selection to SSD boxes\""
-	       "            }"
-	       "        )"
+	       "        onStatus?.invoke(selectionResultStatus(snapSelectionToCells, matching.size))"
        "        onAreaSelected?.invoke(snapped, cellIdsForSelection(matching))"
        "        invalidate()"
        "    }"
@@ -7231,7 +7242,7 @@
        ""
        "    private fun readBoundedBytes(input: InputStream, limit: Long): ByteArray {"
        "        require(limit in 1..Int.MAX_VALUE.toLong())"
-       "        val output = ByteArrayOutputStream(minOf(limit, 64L * 1024L).toInt())"
+       "        val output = ByteArrayOutputStream(boundedReadInitialCapacity(limit).toInt())"
        "        val buffer = ByteArray(32 * 1024)"
        "        var total = 0L"
        "        while (true) {"