Generate SSD sync tree orchestration from typed Jerboa

ober

8b03d0b837a8c4089a224fccef6a65ccb2df327d

diff --git a/templates/ssd-review.ss b/templates/ssd-review.ss
index 8b9be9d..bb07dcb 100644
--- a/templates/ssd-review.ss
+++ b/templates/ssd-review.ss
@@ -15598,6 +15598,7 @@
                 truthStoreExportToTreeLocal
                 truthStoreImportFromTreeLocal
                 truthStoreImportTreeDirLocal
+                truthStoreSyncTreeLocal
                 truthStoreEnsureTreeDirLocal
                 truthStoreWriteTreeFileLocal
                 truthStoreReadResponseTextLocal
@@ -15921,6 +15922,10 @@
         (extern (truthStoreDocumentListFiles
                   (file : DocumentFile)) : (Array DocumentFile)
           (kotlin-member-call listFiles))
+        (extern (truthStoreDocumentFileFromTreeUri
+                  (context : Context)
+                  (uri : Uri)) : (Nullable DocumentFile)
+          (kotlin-call DocumentFile fromTreeUri))
         (extern (truthStoreDocumentFindFile
                   (file : DocumentFile)
                   (name : String)) : (Nullable DocumentFile)
@@ -17292,6 +17297,28 @@
                        tree
                        budget
                        "reviews"))))))
+        (def (truthStoreSyncTreeLocal
+               (store : TruthStore)
+               (treeUri : Uri)) : (Pair Int32 Int32)
+          (let ((maybeTree
+                  (truthStoreDocumentFileFromTreeUri
+                    (truthStoreContext store)
+                    treeUri)))
+            (if (documentFilePresent maybeTree)
+              (let ((tree (nullable-get maybeTree)))
+                (let ((imported
+                        (truthStoreImportFromTreeLocal
+                          store
+                          tree)))
+                  (begin
+                    (if (positiveCount imported)
+                      (truthStoreInvalidateTruthIndexLocal store)
+                      (begin))
+                    (truthStoreRebuildLearnedExamplesLocal store)
+                    (pair
+                      imported
+                      (truthStoreExportToTreeLocal store tree)))))
+              (pair (int32 0) (int32 0)))))
         (def (truthStoreSeedBundledTruthLocal
                (store : TruthStore)
                (context : Context)) : Int32
@@ -18120,16 +18147,8 @@
        "    private fun validateImportedText(name: String, text: String) ="
        "        truthStoreValidateImportedTextLocal(name, text)"
        ""
-       "    fun syncTree(treeUri: Uri): Pair<Int, Int> {"
-       "        val maybeTree = DocumentFile.fromTreeUri(context, treeUri)"
-       "        if (!documentFilePresent(maybeTree)) return 0 to 0"
-       "        val tree = checkNotNull(maybeTree)"
-       "        val imported = importFromTree(tree)"
-       "        if (positiveCount(imported)) invalidateTruthIndex()"
-       "        rebuildLearnedExamples()"
-       "        val exported = exportToTree(tree)"
-       "        return imported to exported"
-       "    }"
+       "    fun syncTree(treeUri: Uri): Pair<Int, Int> ="
+       "        truthStoreSyncTreeLocal(this, treeUri)"
        ""
        "    fun pullRemoteDump(): Int ="
        "        truthStorePullRemoteDumpLocal(this)"