Move SSD truth session JSON to typed Kotlin

ober

57ea0043a46af89a65a19923aa8fc1954c0f0fb7

diff --git a/.build.yml b/.build.yml
index 65757be..150bdd8 100644
--- a/.build.yml
+++ b/.build.yml
@@ -5,7 +5,7 @@ packages:
   - make=4.4.1-r4
 sources:
   # Build dependency: full immutable commit, mirrored in dependencies.lock.json.
-  - "https://git.sr.ht/~lisp/jerboa#f07bc095c3152b25cb4ad98cdc44208ea7201f4e"
+  - "https://git.sr.ht/~lisp/jerboa#c0e0f09a8e0082c2c2aeb08c5dfcac44dbc82bb3"
   # The second source is the build subject selected by the SourceHut submitter.
   - https://git.sr.ht/~lisp/jerboa-android
 tasks:
@@ -14,6 +14,6 @@ tasks:
       test "$(apk info -v chez-scheme)" = chez-scheme-10.3.0-r2
       test "$(apk info -v git)" = git-2.54.0-r0
       test "$(apk info -v make)" = make-4.4.1-r4
-      test "$(git -C ../jerboa rev-parse HEAD)" = f07bc095c3152b25cb4ad98cdc44208ea7201f4e
-      test "$(git -C ../jerboa rev-parse 'HEAD^{tree}')" = febf0f4fc474f964daa84a69295d8f0bb873619b
+      test "$(git -C ../jerboa rev-parse HEAD)" = c0e0f09a8e0082c2c2aeb08c5dfcac44dbc82bb3
+      test "$(git -C ../jerboa rev-parse 'HEAD^{tree}')" = 2e133170b097ee5b7857677a2d087d592439296b
       JERBOA="chez --libdirs .:../jerboa/lib --script" make test
diff --git a/dependencies.lock.json b/dependencies.lock.json
index cccd0f6..2d4f1db 100644
--- a/dependencies.lock.json
+++ b/dependencies.lock.json
@@ -11,8 +11,8 @@
   "generator_runtime": {
     "name": "jerboa",
     "repository": "https://git.sr.ht/~lisp/jerboa",
-    "commit": "f07bc095c3152b25cb4ad98cdc44208ea7201f4e",
-    "tree": "febf0f4fc474f964daa84a69295d8f0bb873619b"
+    "commit": "c0e0f09a8e0082c2c2aeb08c5dfcac44dbc82bb3",
+    "tree": "2e133170b097ee5b7857677a2d087d592439296b"
   },
   "assurance_tools": {
     "osv_scanner": {
diff --git a/scripts/verify-supply-chain.sh b/scripts/verify-supply-chain.sh
index 1878f6d..b63a301 100755
--- a/scripts/verify-supply-chain.sh
+++ b/scripts/verify-supply-chain.sh
@@ -3,8 +3,8 @@ set -eu
 
 repo=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd -P)
 lock="$repo/dependencies.lock.json"
-jerboa_commit=f07bc095c3152b25cb4ad98cdc44208ea7201f4e # gitsafe:ignore
-jerboa_tree=febf0f4fc474f964daa84a69295d8f0bb873619b # gitsafe:ignore
+jerboa_commit=c0e0f09a8e0082c2c2aeb08c5dfcac44dbc82bb3 # gitsafe:ignore
+jerboa_tree=2e133170b097ee5b7857677a2d087d592439296b # gitsafe:ignore
 gradle_sha=20f1b1176237254a6fc204d8434196fa11a4cfb387567519c61556e8710aed78
 jdk_macos_sha=8fa1eff40bb637a33613b2ccb8b12c70dc3661cc22cf8e784943715769a05336
 jdk_linux_sha=d8afc263758141a66e0e3aafc321e783f7016696f4eaea067d340a269037d331
diff --git a/templates/ssd-review.ss b/templates/ssd-review.ss
index f2cad5e..ab306ee 100644
--- a/templates/ssd-review.ss
+++ b/templates/ssd-review.ss
@@ -2285,6 +2285,34 @@
                         (= (json-object-opt-int32-default source "dpi" (int32 -1))
                            (SsdSession-dpi session)))))))))
 
+    (typed-kotlin-file "com/sfb/ssdreview/TruthSessionJson.kt"
+      (kotlin-imports (org json JSONObject))
+      (typed-library (com sfb ssdreview)
+        (export truthForSession)
+        (type JSONObject)
+        (def (truthSessionSourceObject (truth : JSONObject)) : JSONObject
+          (let ((source (json-object-opt-json-object truth "source")))
+            (if (nullable-null? source)
+                (json-object-empty)
+                (nullable-get source))))
+        (def (truthForSession (session : SsdSession) (truth : JSONObject)) : JSONObject
+          (let ((cached (json-object-copy truth)))
+            (begin
+              (json-object-put-string! cached "source_key" (SsdSession-sourceKey session))
+              (json-object-put-string!
+                cached
+                "source_sha1"
+                (string-substring-before (SsdSession-sourceKey session) "-p"))
+              (let ((source (truthSessionSourceObject cached)))
+                (begin
+                  (json-object-put-string! source "name" (SsdSession-sourceName session))
+                  (json-object-put-string! source "path" (SsdSession-sourceUri session))
+                  (json-object-put-int32! source "page" (SsdSession-page session))
+                  (json-object-put-int32! source "page_count" (SsdSession-pageCount session))
+                  (json-object-put-int32! source "dpi" (SsdSession-dpi session))
+                  (json-object-put-json-object! cached "source" source)
+                  cached)))))))
+
     (typed-kotlin-file "com/sfb/ssdreview/PathSafety.kt"
       (typed-library (com sfb ssdreview)
         (export safePathComponent safeLeaf safeZipEntryName validSourceKey validatedSourceKey)
@@ -5557,20 +5585,6 @@
        "        return input.use { readBoundedBytes(it, MAX_HTTP_TEXT_BYTES).decodeToString() }"
        "    }"
        ""
-       "    private fun truthForSession(session: SsdSession, truth: JSONObject): JSONObject {"
-       "        val cached = JSONObject(truth.toString())"
-       "            .put(\"source_key\", session.sourceKey)"
-       "            .put(\"source_sha1\", session.sourceKey.substringBefore(\"-p\"))"
-       "        val source = cached.optJSONObject(\"source\") ?: JSONObject()"
-       "        source.put(\"name\", session.sourceName)"
-       "            .put(\"path\", session.sourceUri)"
-       "            .put(\"page\", session.page)"
-       "            .put(\"page_count\", session.pageCount)"
-       "            .put(\"dpi\", session.dpi)"
-       "        cached.put(\"source\", source)"
-       "        return cached"
-       "    }"
-       ""
        "    private fun remapAndAddTruthCells("
        "        session: SsdSession,"
        "        group: SsdGroup,"