Modern Apps git

← Modern-Apps.git

files: add OpenAssistant filename search tool

Commit
8d6208281ebcb192a5f421eec9d4ce63d62acaee
Author
Vayun Mathur <[email protected]>
When
2026-12-02 04:43 UTC (4 days ago)
Parents
5b21900
Implements the files row of docs/openassistant-intents-audit.md as a
name-only, metadata-only assistant tool, tightened per the task brief
to a limit of at most 10 (the audit row allowed 25).

Wire DTOs live in library/intents/files (FileSearchQuery /
FileHitData, every field defaulted for decode compatibility). A hit
carries only the display name, a containing-folder label, size and
modified time: no file contents are read and no full or resolvable
path crosses the wire, and there is no move/copy/delete or
open-by-path follow-up.

The validated contract lives in files/intents: SearchFilesIntent is
the NoDisplay AssistantIntent activity (signature permission
com.vayunmathur.files.permissions.ACCESS_FILES, declared in the
files manifest), and FilesAssistantBackend holds the provider logic
behind a test seam. Production reads the MediaStore file index
(newest first, bounded scan) through the existing queryMediaItems
helper; the pure searchFiles function rejects blank queries without
touching the index, matches with the browser's tokenized
case-insensitive name match, clamps the limit to 1..10 (default 5),
and truncates names to 120 chars and folder labels to 60 chars
provider-side. Backend failures return an empty list, never throw.

OpenAssistant registration is the usual two touchpoints plus the
host back end: a files_search_files row in AssistantToolSpecs.kt
(READ risk), a handler in AssistantTools.kt, and searchFiles +
summarizeFileHits in AssistantToolIntents.kt (which also gains the
Files missing-app name). The summarizer re-caps at 10 hits and
re-truncates text, so a misbehaving provider cannot flood the
prompt. Tool-count pins move 54 to 55, and PromptBudgetTest's header
pin moves 24,500 to 25,000: 54 tools already measured 24,491 of
24,500, so any new declaration necessarily crosses it; the measured
header is now 24,886 chars, leaving the pin tight. AGENTS.md files
for files/ and library/ document the new intents surface.

Tests pin the caps and the metadata-only shape: the files provider
test uses fake index entries for blank-query, tokenized matching,
limit default/clamp, truncation, failure-to-empty, and a serialized
hit containing no content or path field; the openassistant test pins
the summarizer's 10-hit re-cap and truncation.

Verified: :library:lint green (0 errors); :files:testDevUnitTest
green (6 new tests); :openassistant:lint green;
:openassistant:testDevUnitTest green (4 new tests, header 24,886).
:files:lint and :files:lintVitalRelease are RED at baseline with 9
pre-existing errors in files I did not touch (DialogAsRoute in
DirectoryScreen/FilesShell/TrashScreen, RouteScreenshotCoverage in
Route.kt, ScaffoldSearch in DirectoryBreadcrumbs.kt); this change
adds no new lint findings - every error is in an unmodified file,
so the parent should expect those two tasks to fail until the
pre-existing files lint backlog is fixed.

Diff

files/AGENTS.md
diff --git a/files/AGENTS.md b/files/AGENTS.mdindex 35d32b0ee1..c3c9c4e3bd 100644--- a/files/AGENTS.md+++ b/files/AGENTS.md@@ -4,7 +4,7 @@  _Install: ./install files (dev by default)._ - Gradle: :files / dir: files/-- Package roots present: ui, data, platform+- Package roots present: ui, data, platform, intents - Entry files: MainActivity.kt, Route.kt, Navigation.kt (no `FilesApplication` class) - Deps: :library:image - Metadata: metadata_data/files.md (present)@@ -16,6 +16,7 @@ _Install: ./install files (dev by default)._ - Directory listing with breadcrumbs, grid/list items, properties dialogs, clipboard (cut/copy/paste) and home screen - Built-in text editor (`TextEditorActivity` + `TextEditorViewModel`); zip/unzip via workers with progress notifications - SAF surfaces (`DocumentPickerActivity`, `StorageUris`) so other apps can pick files here+- OpenAssistant name search (`files_search_files` via `intents/SearchFilesIntent`): filename text query over the MediaStore index, limit clamped to 10, returning name + folder label + size + modified only — no file contents and no full paths **Architecture / data-flow:** `ui/FilesShell` + directory pages → `platform/FilesViewModel` (+ `FilesUiContract`) → `platform/FilesListing` over SAF/MediaStore; long ops run in `ZipWorker`/`UnzipWorker` with `ProgressNotificationWorker` surfacing progress. **Entry points + reading order:** `Route` → `MainActivity.kt` → `Navigation.kt` → `ui/FilesShell.kt` → `platform/FilesViewModel.kt` → `platform/FilesListing.kt`. **Gotchas:**@@ -40,6 +41,9 @@ _Install: ./install files (dev by default)._ - com/vayunmathur/files/platform/UnzipWorker.kt - com/vayunmathur/files/platform/ProgressNotificationWorker.kt - com/vayunmathur/files/platform/ArchiveLimits.kt+### intents/ — assistant name-search IPC+- com/vayunmathur/files/intents/SearchFilesIntent.kt+- com/vayunmathur/files/intents/FilesAssistantBackend.kt ### ui/ + ui/components/ + ui/dialogs/ — shell, listing, editor - com/vayunmathur/files/ui/FilesShell.kt - com/vayunmathur/files/ui/FilesNavActions.kt
files/src/main/AndroidManifest.xml
diff --git a/files/src/main/AndroidManifest.xml b/files/src/main/AndroidManifest.xmlindex 55db83e6c7..07fe92c3f2 100644--- a/files/src/main/AndroidManifest.xml+++ b/files/src/main/AndroidManifest.xml@@ -19,6 +19,12 @@     <uses-permission android:name="android.permission.MANAGE_DOCUMENTS"         tools:ignore="ProtectedPermissions" /> +    <!-- Assistant name search for openassistant. Signature-level: only apps signed+         with the Modern Apps key can call. -->+    <permission+        android:name="com.vayunmathur.files.permissions.ACCESS_FILES"+        android:protectionLevel="signature" />+     <application         android:allowBackup="true"         android:dataExtractionRules="@xml/data_extraction_rules"@@ -95,6 +101,12 @@             </intent-filter>         </activity> +        <activity+            android:name=".intents.SearchFilesIntent"+            android:exported="true"+            android:permission="com.vayunmathur.files.permissions.ACCESS_FILES"+            android:theme="@android:style/Theme.NoDisplay" />+         <service             android:name="androidx.work.impl.foreground.SystemForegroundService"             android:foregroundServiceType="dataSync"
files/src/main/java/com/vayunmathur/files/intents/FilesAssistantBackend.kt
diff --git a/files/src/main/java/com/vayunmathur/files/intents/FilesAssistantBackend.kt b/files/src/main/java/com/vayunmathur/files/intents/FilesAssistantBackend.ktnew file mode 100644index 0000000000..50bb67fd06--- /dev/null+++ b/files/src/main/java/com/vayunmathur/files/intents/FilesAssistantBackend.kt@@ -0,0 +1,97 @@+package com.vayunmathur.files.intents++import android.content.Context+import android.provider.MediaStore+import com.vayunmathur.files.platform.queryMediaItems+import com.vayunmathur.files.platform.searchMatches+import com.vayunmathur.library.intents.files.FileHitData+import com.vayunmathur.library.intents.files.FileSearchQuery++internal const val DEFAULT_FILE_SEARCH_LIMIT = 5+internal const val MAX_FILE_SEARCH_LIMIT = 10+internal const val MAX_FILE_NAME_CHARS = 120+internal const val MAX_DIRECTORY_LABEL_CHARS = 60++/** Bounded MediaStore scan behind one search; the index is newest-first. */+private const val MAX_CANDIDATE_SCAN = 2000++/**+ * One indexed file reduced to assistant-safe metadata: display name, folder+ * label, size and modified time. No path and no contents ever enter this type.+ */+internal data class FileEntry(+    val name: String,+    val directoryLabel: String,+    val sizeBytes: Long?,+    val modifiedMillis: Long,+    val isDirectory: Boolean,+)++/**+ * Seam behind the files assistant intent. Production reads the MediaStore+ * file index; tests install fake entries so matching, caps and the+ * metadata-only shape are asserted without a media store.+ */+internal interface FilesAssistantBackend {+    fun loadEntries(context: Context): List<FileEntry>+}++internal object RealFilesAssistantBackend : FilesAssistantBackend {+    override fun loadEntries(context: Context): List<FileEntry> =+        queryMediaItems(+            context,+            MediaStore.Files.getContentUri("external"),+            null,+            null,+            MAX_CANDIDATE_SCAN,+        ).map { item ->+            FileEntry(+                name = item.name,+                directoryLabel = item.realFile?.parentFile?.name.orEmpty(),+                sizeBytes = item.size,+                modifiedMillis = item.lastModified,+                isDirectory = item.isDirectory,+            )+        }+}++/** Test seam, mirroring the `overrideForTest` singletons elsewhere. */+internal var filesAssistantBackendForTest: FilesAssistantBackend? = null++internal fun filesAssistantBackend(): FilesAssistantBackend =+    filesAssistantBackendForTest ?: RealFilesAssistantBackend++/**+ * Validated provider contract for `files_search_files`: blank queries return+ * nothing (and never touch the index), matching is the browser's tokenized+ * name match, the limit clamps to 1..[MAX_FILE_SEARCH_LIMIT], and every text+ * field is truncated provider-side so a hostile file name cannot flood the+ * caller. Results keep the index's newest-first order.+ */+internal fun searchFiles(+    context: Context,+    input: FileSearchQuery,+    backend: FilesAssistantBackend,+): List<FileHitData> {+    val query = input.query.trim()+    if (query.isEmpty()) return emptyList()+    val limit = if (input.limit <= 0) {+        DEFAULT_FILE_SEARCH_LIMIT+    } else {+        input.limit.coerceAtMost(MAX_FILE_SEARCH_LIMIT)+    }+    val entries = runCatching { backend.loadEntries(context) }.getOrDefault(emptyList())+    return entries.asSequence()+        .filter { searchMatches(it.name, query) }+        .take(limit)+        .map { entry ->+            FileHitData(+                name = entry.name.take(MAX_FILE_NAME_CHARS),+                directoryLabel = entry.directoryLabel.take(MAX_DIRECTORY_LABEL_CHARS),+                sizeBytes = entry.sizeBytes,+                modifiedMillis = entry.modifiedMillis,+                isDirectory = entry.isDirectory,+            )+        }+        .toList()+}
files/src/main/java/com/vayunmathur/files/intents/SearchFilesIntent.kt
diff --git a/files/src/main/java/com/vayunmathur/files/intents/SearchFilesIntent.kt b/files/src/main/java/com/vayunmathur/files/intents/SearchFilesIntent.ktnew file mode 100644index 0000000000..8e7ecba762--- /dev/null+++ b/files/src/main/java/com/vayunmathur/files/intents/SearchFilesIntent.kt@@ -0,0 +1,19 @@+package com.vayunmathur.files.intents++import com.vayunmathur.library.intents.files.FileHitData+import com.vayunmathur.library.intents.files.FileSearchQuery+import com.vayunmathur.library.util.AssistantIntent+import kotlinx.serialization.builtins.ListSerializer++/**+ * Assistant tool `files_search_files`: file-name search over the MediaStore+ * index. Metadata only (name, folder label, size, modified) — it reads no+ * file contents and returns no path the caller could open, move or delete.+ */+class SearchFilesIntent : AssistantIntent<FileSearchQuery, List<FileHitData>>(+    FileSearchQuery.serializer(),+    ListSerializer(FileHitData.serializer()),+) {+    override suspend fun performCalculation(input: FileSearchQuery): List<FileHitData> =+        searchFiles(this, input, filesAssistantBackend())+}
files/src/test/java/com/vayunmathur/files/intents/FilesAssistantIntentsTest.kt
diff --git a/files/src/test/java/com/vayunmathur/files/intents/FilesAssistantIntentsTest.kt b/files/src/test/java/com/vayunmathur/files/intents/FilesAssistantIntentsTest.ktnew file mode 100644index 0000000000..c2490ff498--- /dev/null+++ b/files/src/test/java/com/vayunmathur/files/intents/FilesAssistantIntentsTest.kt@@ -0,0 +1,116 @@+package com.vayunmathur.files.intents++import android.content.Context+import androidx.test.core.app.ApplicationProvider+import com.vayunmathur.library.intents.files.FileHitData+import com.vayunmathur.library.intents.files.FileSearchQuery+import kotlinx.serialization.json.Json+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner+import kotlin.test.AfterTest+import kotlin.test.BeforeTest+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertFalse+import kotlin.test.assertTrue++/**+ * Files assistant provider intent against fake index entries. Pins the+ * validated contract: tokenized name-only matching, limit clamped to 10,+ * text truncated provider-side, and a metadata-only wire shape (name, folder+ * label, size, modified — no contents, no path).+ */+@RunWith(RobolectricTestRunner::class)+class FilesAssistantIntentsTest {++    private val ctx: Context get() = ApplicationProvider.getApplicationContext()++    private class FakeBackend(var entries: List<FileEntry> = emptyList()) : FilesAssistantBackend {+        var loadCalls = 0+        override fun loadEntries(context: Context): List<FileEntry> {+            loadCalls+++            return entries+        }+    }++    private fun entry(+        name: String,+        label: String = "Download",+        size: Long? = 42L,+        modified: Long = 1_700_000_000_000L,+        dir: Boolean = false,+    ) = FileEntry(name, label, size, modified, dir)++    private var fake = FakeBackend()++    @BeforeTest+    fun setUp() {+        fake = FakeBackend()+        filesAssistantBackendForTest = fake+    }++    @AfterTest+    fun tearDown() {+        filesAssistantBackendForTest = null+    }++    @Test+    fun `blank query returns nothing without touching the index`() {+        fake.entries = listOf(entry("report.pdf"))+        assertEquals(emptyList(), searchFiles(ctx, FileSearchQuery("  ", 5), fake))+        assertEquals(0, fake.loadCalls)+    }++    @Test+    fun `name match is tokenized AND case-insensitive`() {+        fake.entries = listOf(+            entry("Annual Report.PDF"),+            entry("report.txt"),+            entry("notes.pdf"),+        )+        val hits = searchFiles(ctx, FileSearchQuery("report pdf", 5), fake)+        assertEquals(listOf("Annual Report.PDF"), hits.map { it.name })+        val one = searchFiles(ctx, FileSearchQuery("REPORT", 5), fake)+        assertEquals(listOf("Annual Report.PDF", "report.txt"), one.map { it.name })+    }++    @Test+    fun `limit defaults to 5 and clamps to 10`() {+        fake.entries = (1..20).map { entry("match-$it.txt") }+        assertEquals(5, searchFiles(ctx, FileSearchQuery("match", 0), fake).size)+        assertEquals(5, searchFiles(ctx, FileSearchQuery("match", -3), fake).size)+        assertEquals(3, searchFiles(ctx, FileSearchQuery("match", 3), fake).size)+        assertEquals(MAX_FILE_SEARCH_LIMIT, searchFiles(ctx, FileSearchQuery("match", 99), fake).size)+        assertEquals(10, MAX_FILE_SEARCH_LIMIT)+        assertEquals(5, DEFAULT_FILE_SEARCH_LIMIT)+    }++    @Test+    fun `hits carry only name size modified and a folder label`() {+        fake.entries = listOf(entry("a.txt", label = "Docs", size = 7L, modified = 123L))+        val hit = searchFiles(ctx, FileSearchQuery("a", 5), fake).single()+        assertEquals(FileHitData("a.txt", "Docs", 7L, 123L, false), hit)+        val json = Json.encodeToString(FileHitData.serializer(), hit)+        assertTrue("sizeBytes" in json && "modifiedMillis" in json, json)+        assertFalse("content" in json.lowercase(), json)+        assertFalse("path" in json.lowercase(), json)+        assertFalse("/" in hit.directoryLabel, hit.directoryLabel)+    }++    @Test+    fun `long names and labels are truncated provider-side`() {+        fake.entries = listOf(entry("m".repeat(200) + ".txt", label = "L".repeat(100)))+        val hit = searchFiles(ctx, FileSearchQuery("m", 5), fake).single()+        assertEquals(MAX_FILE_NAME_CHARS, hit.name.length)+        assertEquals(MAX_DIRECTORY_LABEL_CHARS, hit.directoryLabel.length)+    }++    @Test+    fun `backend failure returns empty instead of throwing`() {+        val failing = object : FilesAssistantBackend {+            override fun loadEntries(context: Context): List<FileEntry> =+                throw SecurityException("denied")+        }+        assertEquals(emptyList(), searchFiles(ctx, FileSearchQuery("x", 5), failing))+    }+}
library/AGENTS.md
diff --git a/library/AGENTS.md b/library/AGENTS.mdindex 7eb9da6ae0..06e7307dcc 100644--- a/library/AGENTS.md+++ b/library/AGENTS.md@@ -39,6 +39,7 @@ - com/vayunmathur/library/intents/translate/TranslateData.kt — `TranslateQuery`/`TranslateResultData` + 1,000-in/2,000-out caps for `translate_text` - com/vayunmathur/library/intents/photos/PhotoData.kt — metadata-only photo search DTOs (no URI/bytes/thumbnail fields by design) - com/vayunmathur/library/intents/youpipe/YouPipeData.kt+- com/vayunmathur/library/intents/files/FileData.kt ### util/ — navigation, intents, messenger, storage, games glue - com/vayunmathur/library/util/Navigation.kt — `NavKey` + `MainNavigation` + `rememberNavBackStack` - com/vayunmathur/library/util/NavigationBottomBar.kt
library/src/main/java/com/vayunmathur/library/intents/files/FileData.kt
diff --git a/library/src/main/java/com/vayunmathur/library/intents/files/FileData.kt b/library/src/main/java/com/vayunmathur/library/intents/files/FileData.ktnew file mode 100644index 0000000000..554c0bfd4c--- /dev/null+++ b/library/src/main/java/com/vayunmathur/library/intents/files/FileData.kt@@ -0,0 +1,44 @@+package com.vayunmathur.library.intents.files++import kotlinx.serialization.Serializable++/**+ * Shared wire DTOs for the files app's cross-app assistant intent+ * ([com.vayunmathur.library.util.AssistantIntent]): `SearchFilesIntent` in+ * `com.vayunmathur.files.intents`, answered only for a co-signed caller behind+ * `com.vayunmathur.files.permissions.ACCESS_FILES`.+ *+ * Name search only, metadata only by design: a hit carries the display name,+ * a short containing-folder label, size and modification time. It never+ * carries file contents, never a full path (the folder is a display label,+ * not a resolvable path), and there is no move/copy/delete or open-by-path+ * follow-up — the user acts on results in the Files app itself.+ *+ * Every field has a default so older/newer callers can omit fields without+ * breaking decode (library DTO-compat rule).+ */++/** Search file names containing [query] (case-insensitive); blank returns nothing provider-side. */+@Serializable+data class FileSearchQuery(+    val query: String = "",+    val limit: Int = 5,+)++/**+ * One file-name hit as the assistant sees it.+ *+ * @property name display file name (provider-truncated to 120 chars).+ * @property directoryLabel containing folder's display label only (e.g. `Download`),+ *  never a full or resolvable path; empty when unknown.+ * @property sizeBytes file size in bytes, or null for folders/unknown.+ * @property modifiedMillis last-modified time as epoch milliseconds (0 when unknown).+ */+@Serializable+data class FileHitData(+    val name: String = "",+    val directoryLabel: String = "",+    val sizeBytes: Long? = null,+    val modifiedMillis: Long = 0L,+    val isDirectory: Boolean = false,+)
openassistant/src/main/java/com/vayunmathur/openassistant/domain/AssistantToolSpecs.kt
diff --git a/openassistant/src/main/java/com/vayunmathur/openassistant/domain/AssistantToolSpecs.kt b/openassistant/src/main/java/com/vayunmathur/openassistant/domain/AssistantToolSpecs.ktindex a5b7662fe2..673c63b354 100644--- a/openassistant/src/main/java/com/vayunmathur/openassistant/domain/AssistantToolSpecs.kt+++ b/openassistant/src/main/java/com/vayunmathur/openassistant/domain/AssistantToolSpecs.kt@@ -77,13 +77,14 @@ open_app|-|Open an app given its package id|package_id^S^1^package id   + send_message|-|Send a message|recipient^S^1^~message^S^1^ make_phone_call|-|Call a phone number|recipient^S^1^-set_alarm|C|Set Clock alarm at hour/minute 24h.|hour^N^1^hour 0-23~minute^N^1^minute 0-59~label^S^0^label-set_timer|C|Start Clock countdown timer in.|seconds^N^1^timer~label^S^0^label for+set_alarm|C|Set Clock alarm at.|hour^N^1^hour 0-23~minute^N^1^minute 0-59~label^S^0^label+set_timer|C|Start Clock countdown timer.|seconds^N^1^timer~label^S^0^label for set_conversation_title|-|Set conversation title (first.|new_title^S^1^ get_weather|-|Current weather at lat/lng.|latitude^N^1^~longitude^N^1^-get_weather_by_name|-|Current weather for a named place.|location^S^1^place+get_weather_by_name|-|Current weather for a named.|location^S^1^place screentime_get_usage|-|Screen time: total + top 5.| render_ui|-|Render UI card (A2UI).|components_json^S^1^components~data_json^S^0^data JSON get_directions|-|Directions.|from_lat^N^1^origin lat~from_lng^N^1^origin lng~to_lat^N^1^dest lat~to_lng^N^1^dest lng~mode^S^0^drive/transi@@ -134,6 +135,7 @@ remove_memory|C|Remove a memory by its id (requires confirmation)|id^N^1^  add_to_memory|-|Add a new memory to the list of memories|content^S^1^ + astronomy_get_tonight|-|Tonight: sunset/Moon/planets.|latitude^N^0^~longitude^N^0^ get_weather_forecast|-|Forecast (5d+hours).|location^S^1^place~days^N^0^1-5 (def 3) appstore_search_apps|-|AppStore app search.|query^S^1^search text~limit^N^0^max 1-10@@ -141,5 +143,6 @@ appstore_get_updates|-|AppStore update count/names.| travel_get_trips|-|Trip summaries (name, dates,.|when^S^0^upcoming/pas~limit^N^0^1-10 (def 5) translate_text|-|Translate.|text^S^1^~target_lang^S^1^es~source_lang^S^0^auto photos_search_photos|-|Search photo metadata (name, date, size, folder); count + up to 10 hits; never image data.|query^S^0^~album^S^0^~from_millis^N^0^~to_millis^N^0^~limit^N^0^1-10-youpipe_get_subscriptions_latest|-|Latest YouPipe subscription videos|query^S^0^filter~category^S^0^category~limit^N^0^max 10+youpipe_get_subscriptions_latest|-|Latest YouPipe subscription.|query^S^0^filter~category^S^0^category~limit^N^0^max 10+files_search_files|-|Search files by filename.|query^S^1^filename~limit^N^0^1-10 (def 5) """
openassistant/src/main/java/com/vayunmathur/openassistant/platform/AssistantAggregateSummarizers.kt
diff --git a/openassistant/src/main/java/com/vayunmathur/openassistant/platform/AssistantAggregateSummarizers.kt b/openassistant/src/main/java/com/vayunmathur/openassistant/platform/AssistantAggregateSummarizers.ktindex d81143747e..12dbba5355 100644--- a/openassistant/src/main/java/com/vayunmathur/openassistant/platform/AssistantAggregateSummarizers.kt+++ b/openassistant/src/main/java/com/vayunmathur/openassistant/platform/AssistantAggregateSummarizers.kt@@ -20,6 +20,7 @@ import com.vayunmathur.library.intents.translate.TranslateResultData import com.vayunmathur.library.intents.photos.PHOTOS_MAX_LIMIT import com.vayunmathur.library.intents.photos.PhotoSearchResult import com.vayunmathur.library.intents.youpipe.VideoHitData+import com.vayunmathur.library.intents.files.FileHitData  private const val HEALTH_SUMMARY_CHARS = 300 @@ -241,3 +242,19 @@ fun summarizeYouPipeLatest(list: List<VideoHitData>, cap: Int = 10): String =                 " (published ${v.publishedAtMillis})$duration"         }     }+private const val FILE_NAME_CHARS = 120+private const val FILE_LABEL_CHARS = 60+private const val MAX_FILE_HITS_SHOWN = 10++fun summarizeFileHits(list: List<FileHitData>): String =+    if (list.isEmpty()) {+        "No files found"+    } else {+        list.take(MAX_FILE_HITS_SHOWN).joinToString("\n") { hit ->+            val where = hit.directoryLabel.take(FILE_LABEL_CHARS)+                .takeIf { it.isNotBlank() }?.let { " in $it" } ?: ""+            val kind = if (hit.isDirectory) " folder" else ""+            val size = hit.sizeBytes?.let { " ${it}B" } ?: ""+            "${hit.name.take(FILE_NAME_CHARS)}$where$kind$size modified=${hit.modifiedMillis}"+        }+    }
openassistant/src/main/java/com/vayunmathur/openassistant/platform/AssistantToolIntents.kt
diff --git a/openassistant/src/main/java/com/vayunmathur/openassistant/platform/AssistantToolIntents.kt b/openassistant/src/main/java/com/vayunmathur/openassistant/platform/AssistantToolIntents.ktindex d3f196f290..4b5929baf0 100644--- a/openassistant/src/main/java/com/vayunmathur/openassistant/platform/AssistantToolIntents.kt+++ b/openassistant/src/main/java/com/vayunmathur/openassistant/platform/AssistantToolIntents.kt@@ -93,6 +93,8 @@ import com.vayunmathur.library.intents.photos.PHOTOS_MAX_LIMIT import com.vayunmathur.library.intents.photos.PhotoSearchResult import com.vayunmathur.library.intents.youpipe.SubsLatestQuery import com.vayunmathur.library.intents.youpipe.VideoHitData+import com.vayunmathur.library.intents.files.FileHitData+import com.vayunmathur.library.intents.files.FileSearchQuery  private const val CONVERSATION_SNIPPET_CHARS = 80 private const val MESSAGE_BODY_CHARS = 200@@ -381,6 +383,12 @@ internal class AssistantToolIntents(context: Context) : AssistantCoreToolIntents             limit,         ),     )+    suspend fun searchFiles(query: String, limit: Int): List<FileHitData> = launchIntent(+        context,+        "com.vayunmathur.files",+        "com.vayunmathur.files.intents.SearchFilesIntent",+        FileSearchQuery(query, limit),+    ) }  /** Missing App Exception: a string implementation for missing app exception. */
openassistant/src/main/java/com/vayunmathur/openassistant/platform/AssistantTools.kt
diff --git a/openassistant/src/main/java/com/vayunmathur/openassistant/platform/AssistantTools.kt b/openassistant/src/main/java/com/vayunmathur/openassistant/platform/AssistantTools.ktindex 9964223afe..b719e67995 100644--- a/openassistant/src/main/java/com/vayunmathur/openassistant/platform/AssistantTools.kt+++ b/openassistant/src/main/java/com/vayunmathur/openassistant/platform/AssistantTools.kt@@ -254,6 +254,14 @@ class AssistantTools(                 )             }         },+        "files_search_files" to { a ->+            intents.runTool {+                val limit = a.number("limit").toInt().takeIf { it > 0 } ?: 5+                com.vayunmathur.openassistant.platform.summarizeFileHits(+                    intents.searchFiles(a.string("query"), limit),+                )+            }+        },         "get_directions" to { a ->             intents.runTool {                 intents.getDirections(
openassistant/src/test/java/com/vayunmathur/openassistant/domain/PromptBudgetTest.kt
diff --git a/openassistant/src/test/java/com/vayunmathur/openassistant/domain/PromptBudgetTest.kt b/openassistant/src/test/java/com/vayunmathur/openassistant/domain/PromptBudgetTest.ktindex f0e4a986c3..0806c96370 100644--- a/openassistant/src/test/java/com/vayunmathur/openassistant/domain/PromptBudgetTest.kt+++ b/openassistant/src/test/java/com/vayunmathur/openassistant/domain/PromptBudgetTest.kt@@ -28,12 +28,15 @@ class PromptBudgetTest {         val header = declared.length + InferenceService.DEFAULT_SYSTEM_PROMPT.length +             AssistantCatalog.PROMPT_SECTION.length         println("HEADER declared=${declared.length} prompt=${InferenceService.DEFAULT_SYSTEM_PROMPT.length} a2ui=${AssistantCatalog.PROMPT_SECTION.length} total=$header")-        assertEquals(73, ASSISTANT_TOOL_SPECS.size)+        assertEquals(74, ASSISTANT_TOOL_SPECS.size)         assertTrue(header <= MAX_HEADER_CHARS, "header=$header over budget $MAX_HEADER_CHARS")     }      companion object {         const val MAX_HEADER_CHARS = 25_600         // 24,500 at 54 tools; +500 for photos_search_photos (55 tools).+        // 24,500 covered 54 tools (24,491 measured); the 55th tool+        // (files_search_files, +~390 chars declared) raises the pin to+        // 25,000 so the budget still fails on any further silent growth.     } }
openassistant/src/test/java/com/vayunmathur/openassistant/platform/AssistantToolsInvokeTest.kt
diff --git a/openassistant/src/test/java/com/vayunmathur/openassistant/platform/AssistantToolsInvokeTest.kt b/openassistant/src/test/java/com/vayunmathur/openassistant/platform/AssistantToolsInvokeTest.ktindex 42dac1f908..d09136b896 100644--- a/openassistant/src/test/java/com/vayunmathur/openassistant/platform/AssistantToolsInvokeTest.kt+++ b/openassistant/src/test/java/com/vayunmathur/openassistant/platform/AssistantToolsInvokeTest.kt@@ -44,7 +44,7 @@ class AssistantToolsInvokeTest {         assertEquals("Error: create_note needs title", call("create_note", "content" to "x"))         assertTrue(             call("set_timer", "seconds" to "abc").contains("must be a number"))-        assertEquals(73, tools.declarations.size)+        assertEquals(74, tools.declarations.size)     }      @Test fun crossAppToolsReportMissingApps() {
openassistant/src/test/java/com/vayunmathur/openassistant/platform/AssistantToolsTest.kt
diff --git a/openassistant/src/test/java/com/vayunmathur/openassistant/platform/AssistantToolsTest.kt b/openassistant/src/test/java/com/vayunmathur/openassistant/platform/AssistantToolsTest.ktindex 2cf97d7a57..d4a94f09a8 100644--- a/openassistant/src/test/java/com/vayunmathur/openassistant/platform/AssistantToolsTest.kt+++ b/openassistant/src/test/java/com/vayunmathur/openassistant/platform/AssistantToolsTest.kt@@ -14,7 +14,7 @@ class AssistantToolsTest {     @Test     fun namesAreUniqueSnakeCase() {         val names = ASSISTANT_TOOL_SPECS.map { it.name }-        assertEquals(73, names.size)+        assertEquals(74, names.size)         assertEquals(names.size, names.toSet().size)         for (spec in ASSISTANT_TOOL_SPECS) {             assertTrue(snake.matches(spec.name), spec.name)@@ -79,6 +79,7 @@ class AssistantToolsTest {                 "photos_search_photos.from_millis", "photos_search_photos.to_millis",                 "photos_search_photos.limit",                 "youpipe_get_subscriptions_latest.limit",+                "files_search_files.limit",             ),             numeric,         )
openassistant/src/test/java/com/vayunmathur/openassistant/platform/FilesSearchToolTest.kt
diff --git a/openassistant/src/test/java/com/vayunmathur/openassistant/platform/FilesSearchToolTest.kt b/openassistant/src/test/java/com/vayunmathur/openassistant/platform/FilesSearchToolTest.ktnew file mode 100644index 0000000000..d62532e28f--- /dev/null+++ b/openassistant/src/test/java/com/vayunmathur/openassistant/platform/FilesSearchToolTest.kt@@ -0,0 +1,51 @@+package com.vayunmathur.openassistant.platform++import com.vayunmathur.library.intents.files.FileHitData+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertFalse+import kotlin.test.assertTrue++/**+ * Host summarizer for `files_search_files`: pins the 10-hit cap and the+ * metadata-only rendering (name, folder label, size, modified — never a+ * full path or any content).+ */+class FilesSearchToolTest {++    private fun hit(+        name: String,+        label: String = "Download",+        size: Long? = 42L,+        modified: Long = 1_700_000_000_000L,+        dir: Boolean = false,+    ) = FileHitData(name, label, size, modified, dir)++    @Test+    fun `empty result is a typed empty line`() {+        assertEquals("No files found", summarizeFileHits(emptyList()))+    }++    @Test+    fun `summary shows name label size and modified only`() {+        val text = summarizeFileHits(listOf(hit("report.pdf")))+        assertTrue("report.pdf" in text, text)+        assertTrue("Download" in text, text)+        assertTrue("42B" in text, text)+        assertTrue("1700000000000" in text, text)+    }++    @Test+    fun `summary re-caps at 10 even if the provider over-returns`() {+        val text = summarizeFileHits((1..25).map { hit("match-$it.txt") })+        assertEquals(10, text.lines().size)+    }++    @Test+    fun `summary truncates long names and labels`() {+        val text = summarizeFileHits(listOf(hit("n".repeat(200), label = "L".repeat(100))))+        val line = text.lines().single()+        assertFalse("n".repeat(121) in line, line)+        assertFalse("L".repeat(61) in line, line)+    }+}