appstore: add read-only OpenAssistant appstore tools
- Commit
fa92671fdf83c0c00b9f4e606a47456aa887f496- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-02 04:39 UTC (4 days ago)
- Parents
6bfe0f6
Add two READ-only OpenAssistant tools for the AppStore, following the appstore row of docs/openassistant-intents-audit.md with the tighter caps requested for this work. Users can now ask what apps the store offers and which installed apps have updates, without the assistant ever installing, updating, uninstalling or downloading anything. Library DTOs (library/intents/appstore/AppStoreData.kt): AppStoreSearchQuery (text query plus limit), AppHitData (packageName, name, summary) and AppUpdatesData (total update count plus names). Every field is defaulted for wire compatibility. Validated contract (appstore/intents/): SearchAppsIntent and GetUpdatesIntent are exported NoDisplay AssistantIntent activities behind the new signature permission com.vayunmathur.appstore.permissions.ACCESS_APPSTORE (also declared as a uses-permission in openassistant). AppStoreAssistantBackend is the seam over CatalogRepository.searchLocal and CatalogRepository.updatesFor over InstalledAppsRepository; it reads the local catalogue only, triggers no sync or download, and exposes no install path. Provider-side caps are enforced there, not just in catalogue text: search limit clamped to 1..10 (default 5), blank queries return nothing, summaries truncated to 120 chars, and the updates summary reports the full count with at most 10 names. Host (openassistant): appstore_search_apps and appstore_get_updates rows in AssistantToolSpecs plus handlers in AssistantTools delegating to AssistantToolIntents, whose summarizers re-cap hits, summaries and names on the host side too. App Store is added to the missing-app names. Tool count goes 54 to 56; existing catalogue descriptions were compressed (meaning preserved) so the pinned prompt header stays within budget (24265 of 24500 chars), rather than raising it. Tests: appstore AppStoreAssistantTest pins the limit clamp, blank query, 120-char summary and count-plus-10-names summary against a fake backend; openassistant AppStoreToolsTest pins the host caps and that both tools are READ with no install-like tool registered, AssistantToolsInvokeTest covers the missing-app path, and the 54-tool count pins move to 56. AGENTS.md files for appstore and library document the new intents and DTO. Verified in this worktree: ./gradlew :appstore:lint :appstore:lintVitalRelease :appstore:testDevUnitTest :openassistant:lint :openassistant:testDevUnitTest :library:lint all green (appstore 706 tests, openassistant 300 tests, 0 failures; header 24265/24500 in PromptBudgetTest).
Diff
appstore/AGENTS.md
diff --git a/appstore/AGENTS.md b/appstore/AGENTS.mdindex f80fb391e8..76e186c265 100644--- a/appstore/AGENTS.md+++ b/appstore/AGENTS.md@@ -4,7 +4,7 @@ _Install: ./install appstore (dev by default)._ - Gradle: :appstore / dir: appstore/-- Package roots present: ui, data, domain, platform+- Package roots present: ui, data, domain, platform, intents - Entry files: MainActivity.kt, Route.kt (home/library/search/sources/trust/updates tabs + Detail/Browse/Screenshots/UninstallDialog pushed routes) - Deps: :library:room, :library:network, :library:work, :library:image - Metadata: metadata_data/appstore.md (present)@@ -17,6 +17,7 @@ _Install: ./install appstore (dev by default)._ - Top filters filter by source (search/library) or category (home); there is no TV filter chip — catalogue results are limited to TV-compatible apps only when the device itself is a TV (`DeviceAttributesProvider.isTv`, applied by `CatalogRepository` on every read) - Install pipeline: `InstallCoordinator` → `SessionInstaller` → `InstallStatusReceiver`, verified by `InstallVerifier` (APK certs, signed-jar index, source stamps) before the system installer sees anything - `UpdateCheckWorker` background checks; outdated-target-API apps refused, not hidden+- OpenAssistant tools (read-only, in `intents/` behind the signature `ACCESS_APPSTORE` permission): `appstore_search_apps` searches the local catalogue (query, limit clamped to 10, summary capped at 120 chars) and `appstore_get_updates` returns an update count plus at most 10 app names; no install/update/uninstall action is exposed **Architecture / data-flow:** `ui/` home/search/detail/library/updates/sources/trust (+ `ui/dialogs/` stateless dialog contents for the `Route.UninstallDialog` / TV `UninstallDialog` routes) → `platform/AppStoreViewModel` (+ per-area `*Ops`, `AppStoreUiContract`) → `data/` providers per source (`*Repository`, Play/F-Droid/Accrescent clients) + `data/installer/` + `data/security/`; `domain/SearchRanking` is pure ranking. **Repo addresses:** our own F-Droid-format repos are consumed from the static R2 bucket — `DefaultRepos.MODERN_APPS` = `https://static.maproj.org/fdroid/repo`, `DefaultRepos.PROPRIETARY` = `https://static.maproj.org/proprietary/repo` (same signed indexes/APKs the server publishes on every build; signing fingerprint pinned as before). The legacy origin addresses (`maproj.org/fdroid/repo`, `maproj.org/proprietary/repo`) keep serving external F-Droid clients and are named only as `LEGACY_*_ORIGIN_URL` constants: stored repo records and cached rows are keyed by URL, so `CatalogRepository.ensureDefaultRepos` prunes rows written under the old addresses and the next sync re-imports under the static ones (no double-added repos). **Entry points + reading order:** `MainActivity.kt` → `Route.kt` → `ui/AppRoot.kt` → `ui/HomePage.kt` → `platform/AppStoreViewModel.kt` → `data/CatalogRepository.kt` → `data/installer/InstallCoordinator.kt` → `data/security/InstallVerifier.kt`.@@ -68,6 +69,10 @@ _Install: ./install appstore (dev by default)._ - com/vayunmathur/appstore/data/security/Signify.kt - com/vayunmathur/appstore/data/PlayStoreLinks.kt - com/vayunmathur/appstore/data/RestrictedPackages.kt+### intents/ — validated OpenAssistant contracts (read-only)+- com/vayunmathur/appstore/intents/SearchAppsIntent.kt+- com/vayunmathur/appstore/intents/GetUpdatesIntent.kt+- com/vayunmathur/appstore/intents/AppStoreAssistantBackend.kt — backend seam over `CatalogRepository.searchLocal`/`updatesFor` + the provider-side caps ### domain/ — pure ranking (no Android) - com/vayunmathur/appstore/domain/SearchRanking.kt ### platform/ — ViewModel + per-area ops
appstore/src/main/AndroidManifest.xml
diff --git a/appstore/src/main/AndroidManifest.xml b/appstore/src/main/AndroidManifest.xmlindex 62850fa168..9fe82f1a03 100644--- a/appstore/src/main/AndroidManifest.xml+++ b/appstore/src/main/AndroidManifest.xml@@ -7,6 +7,12 @@ <!-- Sensors permission at install instead of auto-granting it. --> <uses-permission android:name="com.vayunmathur.permission.SENSORS_OPTOUT" /> + <!-- Assistant tools (catalogue search / available updates) for openassistant.+ Signature-level: only apps signed with the Modern Apps key can call. -->+ <permission+ android:name="com.vayunmathur.appstore.permissions.ACCESS_APPSTORE"+ android:protectionLevel="signature" />+ <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />@@ -121,6 +127,19 @@ android:foregroundServiceType="dataSync" tools:node="merge" /> + <!-- Read-only assistant intents: catalogue search + available-updates+ summary. No install/update/uninstall activity is exported here. -->+ <activity+ android:name=".intents.SearchAppsIntent"+ android:exported="true"+ android:permission="com.vayunmathur.appstore.permissions.ACCESS_APPSTORE"+ android:theme="@android:style/Theme.NoDisplay" />+ <activity+ android:name=".intents.GetUpdatesIntent"+ android:exported="true"+ android:permission="com.vayunmathur.appstore.permissions.ACCESS_APPSTORE"+ android:theme="@android:style/Theme.NoDisplay" />+ <receiver android:name=".data.installer.InstallStatusReceiver" android:exported="false">
appstore/src/main/java/com/vayunmathur/appstore/intents/AppStoreAssistantBackend.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/intents/AppStoreAssistantBackend.kt b/appstore/src/main/java/com/vayunmathur/appstore/intents/AppStoreAssistantBackend.ktnew file mode 100644index 0000000000..b080948e84--- /dev/null+++ b/appstore/src/main/java/com/vayunmathur/appstore/intents/AppStoreAssistantBackend.kt@@ -0,0 +1,122 @@+package com.vayunmathur.appstore.intents++import android.content.Context+import com.vayunmathur.appstore.data.AppStoreDatabaseRepository+import com.vayunmathur.appstore.data.CatalogRepository+import com.vayunmathur.appstore.data.InstalledAppsRepository+import com.vayunmathur.appstore.data.UnifiedApp+import com.vayunmathur.library.intents.appstore.AppHitData+import com.vayunmathur.library.intents.appstore.AppStoreSearchQuery+import com.vayunmathur.library.intents.appstore.AppUpdatesData+import kotlinx.coroutines.CoroutineScope+import kotlinx.coroutines.Dispatchers+import kotlinx.coroutines.SupervisorJob+import kotlinx.coroutines.cancel++/** Default catalogue hits returned when the caller names no limit. */+internal const val DEFAULT_SEARCH_LIMIT = 5++/** Hard provider-side cap on catalogue hits; a larger request is clamped. */+internal const val MAX_SEARCH_LIMIT = 10++/** Hard provider-side cap on one hit's summary length. */+internal const val MAX_SUMMARY_CHARS = 120++/** Hard provider-side cap on app names in the available-updates summary. */+internal const val MAX_UPDATE_NAMES = 10++/**+ * Seam behind the appstore assistant intents. Production delegates to the+ * local catalogue (`CatalogRepository.searchLocal`) and the installed-app+ * update check (`CatalogRepository.updatesFor`); tests install a fake so+ * provider logic (limit clamp, summary truncation, update summary) is+ * asserted without a database or PackageManager.+ *+ * Read-only: this seam deliberately exposes no install, update, uninstall+ * or download call.+ */+internal interface AppStoreAssistantBackend {+ suspend fun search(query: String, limit: Int): List<UnifiedApp>+ suspend fun updates(): List<UnifiedApp>+}++internal class RealAppStoreAssistantBackend(context: Context) : AppStoreAssistantBackend {+ private val appContext = context.applicationContext++ override suspend fun search(query: String, limit: Int): List<UnifiedApp> {+ val scope = CoroutineScope(SupervisorJob() + Dispatchers.IO)+ try {+ val catalog = CatalogRepository(+ appContext,+ AppStoreDatabaseRepository.get(appContext).database,+ scope,+ )+ return catalog.searchLocal(query, limit)+ } finally {+ scope.cancel()+ }+ }++ override suspend fun updates(): List<UnifiedApp> {+ val scope = CoroutineScope(SupervisorJob() + Dispatchers.IO)+ try {+ val catalog = CatalogRepository(+ appContext,+ AppStoreDatabaseRepository.get(appContext).database,+ scope,+ )+ val installed = InstalledAppsRepository(appContext)+ installed.refresh()+ return catalog.updatesFor(installed.updatable.value)+ } finally {+ scope.cancel()+ }+ }+}++/** Test seam, mirroring the `overrideForTest` singletons elsewhere. */+internal var appStoreAssistantBackendForTest: AppStoreAssistantBackend? = null++internal fun appStoreAssistantBackend(context: Context): AppStoreAssistantBackend =+ appStoreAssistantBackendForTest ?: RealAppStoreAssistantBackend(context)++/** Clamps a requested limit into 1..[MAX_SEARCH_LIMIT]; non-positive means default. */+internal fun clampSearchLimit(limit: Int): Int =+ if (limit <= 0) DEFAULT_SEARCH_LIMIT else limit.coerceAtMost(MAX_SEARCH_LIMIT)++/** Maps one catalogue row to its wire hit, truncating the summary provider-side. */+internal fun UnifiedApp.toAppHit(): AppHitData = AppHitData(+ packageName = packageName,+ name = name,+ summary = summary.take(MAX_SUMMARY_CHARS),+)++/**+ * Validates and answers a catalogue search: a blank query returns nothing,+ * the limit is clamped to [MAX_SEARCH_LIMIT], and every summary is capped.+ * Reads the local catalogue only; never triggers a sync or a download.+ */+internal suspend fun searchApps(+ input: AppStoreSearchQuery,+ backend: AppStoreAssistantBackend,+): List<AppHitData> {+ val query = input.query.trim()+ if (query.isEmpty()) return emptyList()+ val limit = clampSearchLimit(input.limit)+ return backend.search(query, limit).take(limit).map { it.toAppHit() }+}++/**+ * Validates and answers the available-updates summary: [AppUpdatesData.count]+ * is the full number of apps with updates, while at most [MAX_UPDATE_NAMES]+ * names cross the wire. Read-only; applies no update.+ */+internal suspend fun getAppUpdates(+ backend: AppStoreAssistantBackend,+): AppUpdatesData {+ val updates = backend.updates()+ return AppUpdatesData(+ count = updates.size,+ names = updates.take(MAX_UPDATE_NAMES).map { it.name },+ )+}
appstore/src/main/java/com/vayunmathur/appstore/intents/GetUpdatesIntent.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/intents/GetUpdatesIntent.kt b/appstore/src/main/java/com/vayunmathur/appstore/intents/GetUpdatesIntent.ktnew file mode 100644index 0000000000..48573fb113--- /dev/null+++ b/appstore/src/main/java/com/vayunmathur/appstore/intents/GetUpdatesIntent.kt@@ -0,0 +1,14 @@+package com.vayunmathur.appstore.intents++import com.vayunmathur.library.intents.appstore.AppUpdatesData+import com.vayunmathur.library.util.AssistantIntent+import kotlinx.serialization.builtins.serializer++/** Assistant tool `appstore_get_updates`: update count + names. Read-only; applies nothing. */+class GetUpdatesIntent : AssistantIntent<Unit, AppUpdatesData>(+ Unit.serializer(),+ AppUpdatesData.serializer(),+) {+ override suspend fun performCalculation(input: Unit): AppUpdatesData =+ getAppUpdates(appStoreAssistantBackend(this))+}
appstore/src/main/java/com/vayunmathur/appstore/intents/SearchAppsIntent.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/intents/SearchAppsIntent.kt b/appstore/src/main/java/com/vayunmathur/appstore/intents/SearchAppsIntent.ktnew file mode 100644index 0000000000..d759b9606b--- /dev/null+++ b/appstore/src/main/java/com/vayunmathur/appstore/intents/SearchAppsIntent.kt@@ -0,0 +1,15 @@+package com.vayunmathur.appstore.intents++import com.vayunmathur.library.intents.appstore.AppHitData+import com.vayunmathur.library.intents.appstore.AppStoreSearchQuery+import com.vayunmathur.library.util.AssistantIntent+import kotlinx.serialization.builtins.ListSerializer++/** Assistant tool `appstore_search_apps`: catalogue search. Read-only; installs nothing. */+class SearchAppsIntent : AssistantIntent<AppStoreSearchQuery, List<AppHitData>>(+ AppStoreSearchQuery.serializer(),+ ListSerializer(AppHitData.serializer()),+) {+ override suspend fun performCalculation(input: AppStoreSearchQuery): List<AppHitData> =+ searchApps(input, appStoreAssistantBackend(this))+}
appstore/src/test/java/com/vayunmathur/appstore/intents/AppStoreAssistantTest.kt
diff --git a/appstore/src/test/java/com/vayunmathur/appstore/intents/AppStoreAssistantTest.kt b/appstore/src/test/java/com/vayunmathur/appstore/intents/AppStoreAssistantTest.ktnew file mode 100644index 0000000000..27fc2dcf40--- /dev/null+++ b/appstore/src/test/java/com/vayunmathur/appstore/intents/AppStoreAssistantTest.kt@@ -0,0 +1,105 @@+package com.vayunmathur.appstore.intents++import com.vayunmathur.appstore.data.AppSource+import com.vayunmathur.appstore.data.UnifiedApp+import com.vayunmathur.library.intents.appstore.AppStoreSearchQuery+import kotlinx.coroutines.runBlocking+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertTrue++/**+ * Provider-side caps and read-only shape of the AppStore assistant intents:+ * search limits, summary truncation and the updates summary are enforced+ * here, not just promised in the tool catalogue.+ */+class AppStoreAssistantTest {++ private class FakeBackend(+ private val searchResults: List<UnifiedApp> = emptyList(),+ private val updateResults: List<UnifiedApp> = emptyList(),+ ) : AppStoreAssistantBackend {+ var searchCalls = 0+ var lastQuery: String? = null+ var lastLimit: Int? = null++ override suspend fun search(query: String, limit: Int): List<UnifiedApp> {+ searchCalls+++ lastQuery = query+ lastLimit = limit+ return searchResults+ }++ override suspend fun updates(): List<UnifiedApp> = updateResults+ }++ private fun app(name: String, summary: String = "summary of $name") = UnifiedApp(+ packageName = "com.example.${name.lowercase()}",+ source = AppSource.FDROID,+ name = name,+ summary = summary,+ )++ @Test+ fun `search clamps limit to ten and trims the query`() = runBlocking {+ val backend = FakeBackend(searchResults = (1..15).map { app("App$it") })+ val hits = searchApps(AppStoreSearchQuery(" maps ", limit = 99), backend)+ assertEquals(1, backend.searchCalls)+ assertEquals("maps", backend.lastQuery)+ assertEquals(MAX_SEARCH_LIMIT, backend.lastLimit)+ assertEquals(10, hits.size)+ assertEquals("App1", hits.first().name)+ }++ @Test+ fun `search defaults a non-positive limit and honours a small one`() = runBlocking {+ val backend = FakeBackend(searchResults = (1..15).map { app("App$it") })+ assertEquals(DEFAULT_SEARCH_LIMIT, searchApps(AppStoreSearchQuery("a", limit = 0), backend).size)+ assertEquals(DEFAULT_SEARCH_LIMIT, backend.lastLimit)+ assertEquals(3, searchApps(AppStoreSearchQuery("a", limit = 3), backend).size)+ assertEquals(3, backend.lastLimit)+ }++ @Test+ fun `blank search returns nothing without touching the backend`() = runBlocking {+ val backend = FakeBackend(searchResults = listOf(app("App")))+ assertTrue(searchApps(AppStoreSearchQuery(" ", limit = 5), backend).isEmpty())+ assertEquals(0, backend.searchCalls)+ }++ @Test+ fun `search truncates summaries to 120 chars`() = runBlocking {+ val backend = FakeBackend(searchResults = listOf(app("Long", summary = "x".repeat(300))))+ val hits = searchApps(AppStoreSearchQuery("long", limit = 5), backend)+ assertEquals(1, hits.size)+ assertEquals(MAX_SUMMARY_CHARS, hits.single().summary.length)+ assertEquals("Long", hits.single().name)+ assertEquals("com.example.long", hits.single().packageName)+ }++ @Test+ fun `updates summary reports the full count with at most ten names`() = runBlocking {+ val backend = FakeBackend(updateResults = (1..15).map { app("Upd$it") })+ val updates = getAppUpdates(backend)+ assertEquals(15, updates.count)+ assertEquals(MAX_UPDATE_NAMES, updates.names.size)+ assertEquals("Upd1", updates.names.first())+ assertEquals("Upd10", updates.names.last())+ }++ @Test+ fun `updates summary is empty when nothing is stale`() = runBlocking {+ val updates = getAppUpdates(FakeBackend())+ assertEquals(0, updates.count)+ assertTrue(updates.names.isEmpty())+ }++ @Test+ fun `limit clamp stays inside the contract bounds`() {+ assertEquals(DEFAULT_SEARCH_LIMIT, clampSearchLimit(0))+ assertEquals(DEFAULT_SEARCH_LIMIT, clampSearchLimit(-3))+ assertEquals(1, clampSearchLimit(1))+ assertEquals(MAX_SEARCH_LIMIT, clampSearchLimit(MAX_SEARCH_LIMIT))+ assertEquals(MAX_SEARCH_LIMIT, clampSearchLimit(1_000))+ }+}
library/AGENTS.md
diff --git a/library/AGENTS.md b/library/AGENTS.mdindex d97746ac74..58071c63df 100644--- a/library/AGENTS.md+++ b/library/AGENTS.md@@ -17,6 +17,7 @@ ## Key files ### intents/ — shared IPC DTOs (one package per app)+- com/vayunmathur/library/intents/appstore/AppStoreData.kt - com/vayunmathur/library/intents/notes/NoteData.kt - com/vayunmathur/library/intents/notes/InsertNoteData.kt - com/vayunmathur/library/intents/calendar/EventData.kt
library/src/main/java/com/vayunmathur/library/intents/appstore/AppStoreData.kt
diff --git a/library/src/main/java/com/vayunmathur/library/intents/appstore/AppStoreData.kt b/library/src/main/java/com/vayunmathur/library/intents/appstore/AppStoreData.ktnew file mode 100644index 0000000000..0928889d49--- /dev/null+++ b/library/src/main/java/com/vayunmathur/library/intents/appstore/AppStoreData.kt@@ -0,0 +1,50 @@+package com.vayunmathur.library.intents.appstore++import kotlinx.serialization.Serializable++/**+ * Shared wire DTOs for appstore's cross-app assistant intents+ * ([com.vayunmathur.library.util.AssistantIntent]): `SearchAppsIntent` and+ * `GetUpdatesIntent` in `com.vayunmathur.appstore.intents`, answered only for+ * a co-signed caller behind+ * `com.vayunmathur.appstore.permissions.ACCESS_APPSTORE`.+ *+ * Read-only by design: these DTOs can search the local catalogue and report+ * which installed apps have updates. They carry no install, update,+ * uninstall, download or purchase action — installs stay signature-verified,+ * user-reviewed acts in the AppStore app itself.+ *+ * Every field has a default so older/newer callers can omit fields without+ * breaking decode (library DTO-compat rule). Caps (search limit, summary+ * length, update names) are enforced provider-side in the appstore intents,+ * not just in the tool catalogue text.+ */++/** Search the catalogue for [query]; the provider clamps [limit] to 1..10. */+@Serializable+data class AppStoreSearchQuery(+ val query: String = "",+ val limit: Int = 5,+)++/**+ * One catalogue hit: the app [name] plus a short [summary] (provider-capped+ * at 120 chars). [packageName] is the stable id of the listing.+ */+@Serializable+data class AppHitData(+ val packageName: String = "",+ val name: String = "",+ val summary: String = "",+)++/**+ * Available-updates summary: [count] is the total number of installed apps+ * with an update available; [names] holds at most the first 10 of their+ * names, so a large update list never floods the model.+ */+@Serializable+data class AppUpdatesData(+ val count: Int = 0,+ val names: List<String> = emptyList(),+)
openassistant/src/main/AndroidManifest.xml
diff --git a/openassistant/src/main/AndroidManifest.xml b/openassistant/src/main/AndroidManifest.xmlindex 0c3a462ec9..df424a257e 100644--- a/openassistant/src/main/AndroidManifest.xml+++ b/openassistant/src/main/AndroidManifest.xml@@ -38,6 +38,7 @@ <uses-permission android:name="android.permission.RECORD_AUDIO" /> <uses-permission android:name="com.vayunmathur.astronomy.permissions.ACCESS_ASTRONOMY" />+ <uses-permission android:name="com.vayunmathur.appstore.permissions.ACCESS_APPSTORE" /> <permission android:name="com.vayunmathur.openassistant.permission.ACCESS_INFERENCE"
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 94dff9f778..6a8df383ca 100644--- a/openassistant/src/main/java/com/vayunmathur/openassistant/domain/AssistantToolSpecs.kt+++ b/openassistant/src/main/java/com/vayunmathur/openassistant/domain/AssistantToolSpecs.kt@@ -60,6 +60,7 @@ create_todo|C|Create a task in Todo (requires confirmation, EXPLICIT request onl complete_todo|C|Mark a task done (requires confirmation). Should only be used with EXPLICIT request by user.|id^S^0^task id from get_todos~title^S^0^exact task title, used when no id is given get_contacts|-|Get contacts (max 50; prefer search_contacts)| + create_contact|C|Create a new contact (requires confirmation)|name^S^1^~phone_number^S^1^ get_calendar_events|-|Get calendar events (max 50; times are epoch ms)| create_calendar_event|C|Create a new calendar event (requires confirmation). Start and end times must be epoch milliseconds.|title^S^1^~start^N^1^start time as epoch milliseconds~end^N^1^end time as epoch milliseconds~location^S^0^@@ -79,15 +80,15 @@ set_timer|C|Start Clock countdown timer in seconds (confirmation).|seconds^N^1^t set_conversation_title|-|Set current conversation title. Mandatory first response.|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-screentime_get_usage|-|Today's screen time: total + top 5 apps.|-render_ui|-|Render UI card (A2UI) with reply; prefer over ```a2ui fence. components_json {"components":[...]}; data_json opt.|components_json^S^1^A2UI components JSON~data_json^S^0^data JSON-get_directions|-|Directions: distance, duration.|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/transit/walk/bicycle+screentime_get_usage|-|Screen time: total + top 5.|+render_ui|-|Render UI card (A2UI).|components_json^S^1^components JSON~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/transit/walk/bicycle maps_search_places|-|Maps places; returns lat/lng.|query^S^1^name/category~near_lat^N^0^near lat~near_lng^N^0^near lng~category^S^0^e.g. Cafe~limit^N^0^1-10 (def 5) maps_get_saved_places|-|Saved Maps places (name + coordinates).|query^S^0^filter~limit^N^0^max 1-10 (def 10)-get_ride_estimate|-|Taxi fare + ETA.|pickup_lat^N^1^pickup lat~pickup_lng^N^1^pickup lng~dest_lat^N^1^dest lat~dest_lng^N^1^dest lng~pickup_label^S^0^pickup label~dest_label^S^0^dest label+get_ride_estimate|-|Taxi fare/ETA.|pickup_lat^N^1^pickup lat~pickup_lng^N^1^pickup lng~dest_lat^N^1^dest lat~dest_lng^N^1^dest lng~pickup_label^S^0^pickup lbl~dest_label^S^0^dest lbl food_order_lookup|-|Restaurant orderable nearby? (FoodDelivery).|name^S^1^name~lat^N^1^lat~lng^N^1^lng~address^S^0^address calculator_evaluate|-|Evaluate math expression via Calculator (functions, pi/e, units 5km+2mi).|expression^S^1^expression (200 chars)-calculator_convert_unit|-|Convert a value between units via Calculator (incl. currency like USD).|value^N^1^value~from_unit^S^1^from: km, ft, degC, USD~to_unit^S^1^to: mi, m, degF, EUR+calculator_convert_unit|-|Convert units (incl. USD).|value^N^1^value~from_unit^S^1^from e.g. km/USD~to_unit^S^1^to e.g. mi/EUR search_contacts|-|Search contacts by name/phone substring (max 10).|query^S^1^name/phone substring web_search|-|Web search for current facts. Numbered results; web_read_result reads them.|query^S^1^search query~count^N^0^count 1-10 (def 5)~kind^S^0^text (def) or news web_read|-|Read a web page by URL and return its extracted text.|url^S^1^page URL to read@@ -99,13 +100,14 @@ send_message_v2|C|Send via Communicate (requires confirmation, EXPLICIT request find_restaurants|-|Find restaurants near a location via the FoodDelivery app, optionally filtered by name or tag.|query^S^0^optional name or tag filter~lat^N^1^latitude~lng^N^1^longitude~limit^N^0^optional max results (default 5) get_restaurant_menu|-|Get the menu of a restaurant (merchant_id from find_restaurants). Items carry ids, prices in cents, availability and modifier groups.|merchant_id^N^1^merchant id from find_restaurants + food_get_cart|-|Get the current FoodDelivery cart (items and total)|-food_set_cart|L|Replace cart with items_json [{itemId,qty,modifierIds}].|merchant_id^N^1^merchant~items_json^S^1^[{itemId,qty,modifierIds}]-food_prepare_order|-|Price cart; no order created.|merchant_id^N^1^merchant~is_pickup^N^0^1=pickup 0=delivery~address_id^S^0^address id~tip_cents^N^0^tip (cents)~promo^S^0^promo-place_food_order|H|Show the current cart's order summary. The user places and pays in FoodDelivery itself; this never creates an order or charges a card.|merchant_id^N^1^merchant+food_set_cart|L|Replace cart.|merchant_id^N^1^merchant~items_json^S^1^[{itemId,qty,modifierIds}]+food_prepare_order|-|Price cart.|merchant_id^N^1^merchant~is_pickup^N^0^1=pickup 0=delivery~address_id^S^0^addr id~tip_cents^N^0^tip cents~promo^S^0^promo+place_food_order|H|Order summary; user pays in app.|merchant_id^N^1^merchant get_food_orders|-|Get the user's past FoodDelivery orders| search_products|-|Search the Shop catalog. Each result is one purchasable variant with its variant_id, store and exact price.|query^S^1^search text~limit^N^0^max (def 5)-get_product_detail|-|Product variants. Confirm before cart.|shop_domain^S^1^domain~product_id^S^1^product~variant_id^S^0^variant+get_product_detail|-|Product variants.|shop_domain^S^1^domain~product_id^S^1^product~variant_id^S^0^variant shop_get_cart|-|Get the current Shop cart, grouped by store| shop_add_to_cart|L|Add exact variant to Shop cart (re-verified; no checkout).|shop_domain^S^1^domain~variant_id^S^1^exact variant id~quantity^N^0^qty 1-99 (def 1) shop_remove_from_cart|L|Remove a variant from the Shop cart; the cart is shown back to the user.|variant_id^S^1^variant id to remove@@ -121,6 +123,8 @@ health_get_metric_summary|-|Health summary aggregates only: latest/avg/min/max/t 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 (5 days + hours) for place.|location^S^1^place~days^N^0^1-5 (def 3)+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+appstore_get_updates|-|AppStore update count/names.| """
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 6905acbfc0..47d9384400 100644--- a/openassistant/src/main/java/com/vayunmathur/openassistant/platform/AssistantAggregateSummarizers.kt+++ b/openassistant/src/main/java/com/vayunmathur/openassistant/platform/AssistantAggregateSummarizers.kt@@ -1,5 +1,8 @@ package com.vayunmathur.openassistant.platform +import com.vayunmathur.library.intents.appstore.AppHitData+import com.vayunmathur.library.intents.appstore.AppStoreSearchQuery+import com.vayunmathur.library.intents.appstore.AppUpdatesData import com.vayunmathur.library.intents.astronomy.AstronomyTonightData import com.vayunmathur.library.intents.astronomy.MAX_TONIGHT_SUMMARY_CHARS import com.vayunmathur.library.intents.education.EducationProgressData@@ -133,6 +136,7 @@ fun summarizeAstronomyTonight(result: AstronomyTonightData): String = else -> result.summary.take(MAX_TONIGHT_SUMMARY_CHARS) } +private const val FORECAST_ERROR_CHARS = 200 private const val FORECAST_LOCATION_CHARS = 80 private const val FORECAST_CONDITION_CHARS = 60 private const val FORECAST_DAYS_SHOWN = 5@@ -158,3 +162,24 @@ fun summarizeWeatherForecast(result: WeatherForecastData): String { } return lines.joinToString("\n") }++private const val APPSTORE_SUMMARY_CHARS = 120+private const val APPSTORE_MAX_HITS = 10+private const val APPSTORE_MAX_UPDATE_NAMES = 10++fun summarizeAppStoreApps(list: List<AppHitData>): String =+ if (list.isEmpty()) {+ "No apps found"+ } else {+ list.take(APPSTORE_MAX_HITS).joinToString("\n") { hit ->+ "${hit.name}: ${hit.summary.take(APPSTORE_SUMMARY_CHARS)}"+ }+ }++fun summarizeAppStoreUpdates(updates: AppUpdatesData): String =+ if (updates.count <= 0 || updates.names.isEmpty()) {+ "No app updates available"+ } else {+ val names = updates.names.take(APPSTORE_MAX_UPDATE_NAMES).joinToString(", ")+ "${updates.count} app update(s) available: $names"+ }
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 5e9cd2eff1..6806e84b9b 100644--- a/openassistant/src/main/java/com/vayunmathur/openassistant/platform/AssistantToolIntents.kt+++ b/openassistant/src/main/java/com/vayunmathur/openassistant/platform/AssistantToolIntents.kt@@ -81,6 +81,9 @@ import com.vayunmathur.library.intents.news.NewsTopQuery import com.vayunmathur.library.intents.astronomy.AstronomyTonightData import com.vayunmathur.library.intents.astronomy.MAX_TONIGHT_SUMMARY_CHARS import com.vayunmathur.library.intents.weather.WeatherForecastData+import com.vayunmathur.library.intents.appstore.AppHitData+import com.vayunmathur.library.intents.appstore.AppStoreSearchQuery+import com.vayunmathur.library.intents.appstore.AppUpdatesData private const val CONVERSATION_SNIPPET_CHARS = 80 private const val MESSAGE_BODY_CHARS = 200@@ -140,6 +143,7 @@ internal class AssistantToolIntents(context: Context) : AssistantCoreToolIntents "com.vayunmathur.fooddelivery" to "FoodDelivery", "com.vayunmathur.communicate" to "Communicate", "com.vayunmathur.shop" to "Shop",+ "com.vayunmathur.appstore" to "App Store", "com.vayunmathur.astronomy" to "Astronomy", "com.vayunmathur.education" to "Education", "com.vayunmathur.health" to "Health",@@ -331,6 +335,21 @@ internal class AssistantToolIntents(context: Context) : AssistantCoreToolIntents NewsStoryQuery(storyId), ) + suspend fun searchAppStoreApps(query: String, limit: Int): List<AppHitData> = launchIntent(+ context,+ "com.vayunmathur.appstore",+ "com.vayunmathur.appstore.intents.SearchAppsIntent",+ AppStoreSearchQuery(query, limit),+ )++ suspend fun getAppStoreUpdates(): AppUpdatesData = launchIntent(+ context,+ "com.vayunmathur.appstore",+ "com.vayunmathur.appstore.intents.GetUpdatesIntent",+ Unit,+ )++ } /** 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 8fda259e3b..bbba6ad9a4 100644--- a/openassistant/src/main/java/com/vayunmathur/openassistant/platform/AssistantTools.kt+++ b/openassistant/src/main/java/com/vayunmathur/openassistant/platform/AssistantTools.kt@@ -544,6 +544,21 @@ class AssistantTools( com.vayunmathur.openassistant.platform.summarizeShopOrders(intents.getShopOrders()) } },+ "appstore_search_apps" to { a ->+ intents.runTool {+ val limit = a.number("limit").toInt().takeIf { it > 0 } ?: 5+ com.vayunmathur.openassistant.platform.summarizeAppStoreApps(+ intents.searchAppStoreApps(a.string("query"), limit),+ )+ }+ },+ "appstore_get_updates" to { _ ->+ intents.runTool {+ com.vayunmathur.openassistant.platform.summarizeAppStoreUpdates(+ intents.getAppStoreUpdates(),+ )+ }+ }, "web_search" to { a -> val count = a.number("count").toInt().takeIf { it > 0 } ?: 5 val result = runBlocking { webTools.webSearch(a.string("query"), count, a.string("kind", "text")) }
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 534b43139b..8efeb4704c 100644--- a/openassistant/src/test/java/com/vayunmathur/openassistant/domain/PromptBudgetTest.kt+++ b/openassistant/src/test/java/com/vayunmathur/openassistant/domain/PromptBudgetTest.kt@@ -22,7 +22,7 @@ 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(67, ASSISTANT_TOOL_SPECS.size)+ assertEquals(69, ASSISTANT_TOOL_SPECS.size) assertTrue(header <= MAX_HEADER_CHARS, "header=$header over budget $MAX_HEADER_CHARS") }
openassistant/src/test/java/com/vayunmathur/openassistant/platform/AppStoreToolsTest.kt
diff --git a/openassistant/src/test/java/com/vayunmathur/openassistant/platform/AppStoreToolsTest.kt b/openassistant/src/test/java/com/vayunmathur/openassistant/platform/AppStoreToolsTest.ktnew file mode 100644index 0000000000..bf824e91a9--- /dev/null+++ b/openassistant/src/test/java/com/vayunmathur/openassistant/platform/AppStoreToolsTest.kt@@ -0,0 +1,51 @@+package com.vayunmathur.openassistant.platform++import com.vayunmathur.library.intents.appstore.AppHitData+import com.vayunmathur.library.intents.appstore.AppUpdatesData+import com.vayunmathur.openassistant.domain.ASSISTANT_TOOL_SPECS+import com.vayunmathur.openassistant.domain.ToolRisk+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertTrue++/**+ * Host-side caps and read-only classification of the AppStore tools:+ * summaries are truncated on this side too, and no install/update/uninstall+ * tool may ever be registered for the appstore.+ */+class AppStoreToolsTest {++ @Test+ fun appStoreToolsAreReadOnlyAndInstallFree() {+ val appStore = ASSISTANT_TOOL_SPECS.filter { it.name.startsWith("appstore_") }+ assertEquals(setOf("appstore_search_apps", "appstore_get_updates"), appStore.map { it.name }.toSet())+ for (spec in appStore) {+ assertEquals(ToolRisk.READ, spec.risk, spec.name)+ }+ val forbidden = listOf("install", "uninstall", "download", "purchase", "checkout")+ for (spec in appStore) {+ for (word in forbidden) {+ assertTrue(word !in spec.name, spec.name)+ }+ }+ }++ @Test+ fun searchSummaryCapsHitsAndSummaryLength() {+ val hits = (1..15).map { AppHitData("com.example.$it", "App$it", "x".repeat(300)) }+ val lines = summarizeAppStoreApps(hits).lines()+ assertEquals(10, lines.size)+ assertTrue(lines.all { it.length <= "App10: ".length + 120 }, lines.first())+ assertEquals("No apps found", summarizeAppStoreApps(emptyList()))+ }++ @Test+ fun updatesSummaryShowsFullCountAndAtMostTenNames() {+ val updates = AppUpdatesData(count = 15, names = (1..15).map { "Upd$it" })+ val text = summarizeAppStoreUpdates(updates)+ assertTrue(text.startsWith("15 app update(s) available:"), text)+ assertTrue("Upd10" in text, text)+ assertTrue("Upd11" !in text, text)+ assertEquals("No app updates available", summarizeAppStoreUpdates(AppUpdatesData()))+ }+}
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 30d691367a..c5f923a3ae 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(67, tools.declarations.size)+ assertEquals(69, tools.declarations.size) } @Test fun crossAppToolsReportMissingApps() {@@ -272,6 +272,16 @@ class AssistantToolsInvokeTest { assertEquals(null, tools.specFor("create_checkout")) } + @Test fun appStoreToolsMissingAppAndReadOnly() {+ assertTrue(call("appstore_search_apps", "query" to "maps").startsWith("The App Store app is required"))+ assertTrue(call("appstore_get_updates").startsWith("The App Store app is required"))+ // Read-only: the tools execute without a confirmation gate, and no+ // install/uninstall/update-applying tool exists for the appstore.+ assertEquals(null, tools.specFor("appstore_install_app"))+ assertEquals(null, tools.specFor("appstore_uninstall_app"))+ assertEquals(null, tools.specFor("appstore_apply_updates"))+ }+ @Test fun riskClassificationMatchesDesign() { val gated = setOf("create_note", "create_todo", "complete_todo", "create_contact", "create_calendar_event", "create_location_share_link", "play_music",
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 c91429dd26..dab7265668 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(67, names.size)+ assertEquals(69, names.size) assertEquals(names.size, names.toSet().size) for (spec in ASSISTANT_TOOL_SPECS) { assertTrue(snake.matches(spec.name), spec.name)@@ -74,7 +74,7 @@ class AssistantToolsTest { "calculator_convert_unit.value", "news_search_headlines.limit", "news_top_stories.limit", "news_read_article.offset", "astronomy_get_tonight.latitude", "astronomy_get_tonight.longitude",- "astronomy_get_tonight.latitude", "astronomy_get_tonight.longitude",+ "appstore_search_apps.limit", ), numeric, )