Skip to content

Your phone, on your command. Gotcha is world's first fully on-device AI copilot for Android that turns natural language into real device actions — safely.

feat(skills): inject a skill only when its tools are callable

Durganshu Mishraad05bedc5e74
diff --git a/app/src/main/assets/skills/calendar.json b/app/src/main/assets/skills/calendar.json
index 6d33e04..7f6006e 100644
--- a/app/src/main/assets/skills/calendar.json
+++ b/app/src/main/assets/skills/calendar.json
@@ -3,5 +3,5 @@
"targetPackageNames": ["com.google.android.calendar", "com.microsoft.office.outlook"],
"name": "Calendar Skills",
"description": "Prefer the calendar connector tools over driving the Calendar app UI.",
- "instructions": "Never automate a calendar app's UI to view or manage events — use the dedicated tools instead, which read/write calendar accounts directly:\n1. list_calendar_events supports date ranges and text search, and shows reminders and attendees per event.\n2. create_calendar_event supports all_day, calendar_name (to pick a specific account like 'Work'), attendees (real invites on a synced Google calendar), and recurrence (daily/weekly/monthly/yearly with recurrence_count or recurrence_until).\n3. edit_calendar_event updates only the fields you provide; get the event_id from list_calendar_events first.\n4. delete_calendar_event always asks the user to confirm before removing anything — irreversible.\n\nChoosing a source: list_calendar_events and create_calendar_event default to source='device' (the phone's own calendar accounts) and that is almost always right. Only pass source='google' or source='microsoft' when the user asks about an account that is not synced to this phone, or when the device calendar clearly does not contain what they described.\n\nEvent ids differ by source: device events have bare numeric ids, connector events are prefixed 'gcal:' or 'ms:'. edit_calendar_event and delete_calendar_event work on device ids only — for a connector event, tell the user it must be changed in that account's own app.\n\nFor 'am I free', 'when can we meet', or scheduling around existing commitments, use check_availability rather than listing events and reasoning about the gaps yourself. It needs a connected Google (with Calendar) or Microsoft account; if none is connected, fall back to list_calendar_events and say you are reading the device calendar only.\n\nOnly fall back to UI automation (open_app + navigate_app) for things these tools can't do, e.g. the app's own settings."
+ "instructions": "Never automate a calendar app's UI to view or manage events — use the dedicated tools instead, which read/write calendar accounts directly:\n1. list_calendar_events supports date ranges and text search, and shows reminders and attendees per event.\n2. create_calendar_event supports all_day, calendar_name (to pick a specific account like 'Work'), attendees (real invites on a synced Google calendar), and recurrence (daily/weekly/monthly/yearly with recurrence_count or recurrence_until).\n3. edit_calendar_event updates only the fields you provide; get the event_id from list_calendar_events first.\n4. delete_calendar_event always asks the user to confirm before removing anything — irreversible.\nThese four work with no connector at all: they read and write the phone's own calendar accounts.\n\nChoosing a source: list_calendar_events and create_calendar_event default to source='device' (the phone's own calendar accounts) and that is almost always right. Only pass source='google' or source='microsoft' when the user asks about an account that is not synced to this phone, or when the device calendar clearly does not contain what they described.\n\nEvent ids differ by source: device events have bare numeric ids, connector events are prefixed 'gcal:' or 'ms:'. edit_calendar_event and delete_calendar_event work on device ids only — for a connector event, tell the user it must be changed in that account's own app.\n\nFor 'am I free', 'when can we meet', or scheduling around existing commitments, use check_availability when it is in your tool list — it reads real free/busy data, which beats listing events and reasoning about the gaps yourself. If it is not listed, no Google or Microsoft account is connected: fall back to list_calendar_events, say you are reading the device calendar only, and mention that connecting an account in the drawer menu ▸ Connectors gives proper availability.\n\nOnly fall back to UI automation (open_app + navigate_app) for things these tools can't do, e.g. the app's own settings."
}
diff --git a/app/src/main/assets/skills/gmail.json b/app/src/main/assets/skills/gmail.json
deleted file mode 100644
index e891ce9..0000000
--- a/app/src/main/assets/skills/gmail.json
+++ /dev/null
@@ -1,7 +0,0 @@
-{
- "id": "gmail_operations",
- "targetPackageNames": ["com.google.android.gm"],
- "name": "Gmail Skills",
- "description": "Prefer the email connector tools over driving the Gmail UI.",
- "instructions": "Never automate the Gmail app's UI (tapping, scrolling, typing) to read or send email — it's slow and fragile compared to the official tools. Instead:\n1. To read, search, or check unread email: use list_emails and read_email. These work with either a connected Gmail account (menu ▸ Connectors ▸ Gmail BYO OAuth) or an IMAP account.\n2. To send email: use send_email. It always shows the user a confirmation dialog with recipient/subject/body before anything is sent — you don't need to ask permission separately.\n3. If no email connector is connected, list_emails/send_email will say so — in that case use compose_email to open the user's email app with a pre-filled draft, or suggest they connect an account in the drawer menu ▸ Connectors for full read/write access.\n4. To mark messages read/unread, use mark_email_read with the id from list_emails.\n5. For real-time 'did I get an email from X' questions when notifications are enabled, read_notifications with app='gmail' can be faster than list_emails.\nOnly fall back to UI automation (open_app + navigate_app) for things the tools genuinely can't do, e.g. Gmail-specific settings screens."
-}
diff --git a/app/src/main/assets/skills/gmail_connector.json b/app/src/main/assets/skills/gmail_connector.json
new file mode 100644
index 0000000..c0acfba
--- /dev/null
+++ b/app/src/main/assets/skills/gmail_connector.json
@@ -0,0 +1,8 @@
+{
+ "id": "gmail_connector",
+ "targetPackageNames": ["com.google.android.gm"],
+ "name": "Gmail Connector Skills",
+ "description": "Use the email connector tools instead of driving the Gmail UI.",
+ "requiresTools": ["list_emails", "send_email"],
+ "instructions": "An email account is connected, so never automate the Gmail app's UI to read or send mail — it is slow and fragile compared to the official tools.\n1. To read, search, or check unread email: use list_emails and read_email.\n2. To send email: use send_email. It always shows the user a confirmation dialog with recipient/subject/body before anything is sent — you don't need to ask permission separately.\n3. To mark messages read/unread, use mark_email_read with the id from list_emails.\n4. For real-time 'did I get an email from X' questions when notifications are enabled, read_notifications with app='gmail' can be faster than list_emails."
+}
diff --git a/app/src/main/assets/skills/gmail_ui.json b/app/src/main/assets/skills/gmail_ui.json
new file mode 100644
index 0000000..66e8103
--- /dev/null
+++ b/app/src/main/assets/skills/gmail_ui.json
@@ -0,0 +1,7 @@
+{
+ "id": "gmail_ui",
+ "targetPackageNames": ["com.google.android.gm"],
+ "name": "Gmail UI Skills",
+ "description": "How to handle Gmail when the email tools can't do the job.",
+ "instructions": "Reading and sending mail belongs to the email tools whenever they are in your tool list. Use the Gmail app's UI only for what they cannot do:\n1. If list_emails and send_email are NOT in your tool list, no email account is connected. Use compose_email to open a pre-filled draft in the user's own mail app, and tell them they can connect an account in the drawer menu ▸ Connectors for full read access. Do not try to read the inbox by tapping through the app to work around this.\n2. For Gmail's own settings screens (signatures, swipe actions, notification settings, adding an account), drive the UI with open_app + navigate_app — no tool covers those.\n3. When you do drive the UI, expect the conversation list to be dense: prefer navigate_app over raw taps so the sub-agent can read the screen between steps."
+}
diff --git a/app/src/main/assets/skills/health.json b/app/src/main/assets/skills/health.json
index dc029a0..8667039 100644
--- a/app/src/main/assets/skills/health.json
+++ b/app/src/main/assets/skills/health.json
@@ -3,5 +3,6 @@
"targetPackageNames": ["com.google.android.apps.healthdata", "com.google.android.apps.fitness"],
"name": "Health and Fitness Skills",
"description": "Read health and fitness data through Health Connect rather than a fitness app's UI.",
+ "requiresTools": ["get_health_summary", "get_health_records"],
"instructions": "Never automate a fitness app's UI to read step counts, sleep or workouts. Health Connect aggregates what every fitness app on the phone writes, and two tools read it:\n1. get_health_summary(days) — totals and averages over a window: steps, distance, active calories, sleep, average/peak/resting heart rate, weight. Use this for 'how did I sleep this week', 'how active have I been'.\n2. get_health_records(type, days) — individual records, for questions the summary cannot answer such as 'which days did I hit 10000 steps' or 'when did I work out'. Types: steps, distance, calories, sleep, heart_rate, resting_heart_rate, weight, exercise.\n\nBoth are read-only — the agent never writes to the user's health record.\n\nIf a metric is missing from the summary it means no app wrote that data in the window; say so rather than reporting zero. If the tool asks for permission, the Health Connect permission screen has been opened — ask the user to allow the data types they are comfortable sharing. On Android 13 and below Health Connect is a separate app that may need installing from the Play Store.\n\nThis is personal health information. Report what the data says; do not diagnose, and suggest seeing a clinician for anything that reads as a medical concern."
}
diff --git a/app/src/main/assets/skills/notion.json b/app/src/main/assets/skills/notion.json
deleted file mode 100644
index c093607..0000000
--- a/app/src/main/assets/skills/notion.json
+++ /dev/null
@@ -1,7 +0,0 @@
-{
- "id": "notion_workspace",
- "targetPackageNames": ["notion.id"],
- "name": "Notion Skills",
- "description": "Use the Notion connector tools instead of automating the Notion app UI.",
- "instructions": "Never automate the Notion app's UI. When the Notion connector is set up (drawer menu ▸ Connectors) use these tools:\n1. notion_search finds pages by title. Always start here — the other tools need a page id from it.\n2. notion_read_page returns the page's text as Markdown.\n3. notion_create_page needs a parent_page_id: Notion gives integrations no workspace root to write into, so find a parent with notion_search first.\n4. notion_append_to_page adds to the end of a page and never overwrites existing content.\n\nThe one thing that trips users up: an integration can only see pages that have been explicitly shared with it (open the page in Notion → ⋯ → Connections → add the integration). If a search comes back empty or a read returns 'could not find page', that is almost always the cause — tell the user to share the page rather than concluding it does not exist.\n\nNotion is the right destination for notes, meeting summaries, research write-ups and reference material the user wants to keep. For short-lived items with a due date, prefer create_task (Microsoft To Do); for the agent's own working plan use todowrite."
-}
diff --git a/app/src/main/assets/skills/notion_connector.json b/app/src/main/assets/skills/notion_connector.json
new file mode 100644
index 0000000..29b49ae
--- /dev/null
+++ b/app/src/main/assets/skills/notion_connector.json
@@ -0,0 +1,8 @@
+{
+ "id": "notion_connector",
+ "targetPackageNames": ["notion.id"],
+ "name": "Notion Connector Skills",
+ "description": "Use the Notion connector tools instead of automating the Notion app UI.",
+ "requiresTools": ["notion_search"],
+ "instructions": "The Notion connector is set up, so never automate the Notion app's UI. Use these tools:\n1. notion_search finds pages by title. Always start here — the other tools need a page id from it.\n2. notion_read_page returns the page's text as Markdown.\n3. notion_create_page needs a parent_page_id: Notion gives integrations no workspace root to write into, so find a parent with notion_search first.\n4. notion_append_to_page adds to the end of a page and never overwrites existing content.\n\nThe one thing that trips users up: an integration can only see pages that have been explicitly shared with it (open the page in Notion → ⋯ → Connections → add the integration). If a search comes back empty or a read returns 'could not find page', that is almost always the cause — tell the user to share the page rather than concluding it does not exist.\n\nNotion is the right destination for notes, meeting summaries, research write-ups and reference material the user wants to keep. For short-lived items with a due date, prefer create_task (Microsoft To Do); for the agent's own working plan use todowrite."
+}
diff --git a/app/src/main/assets/skills/notion_ui.json b/app/src/main/assets/skills/notion_ui.json
new file mode 100644
index 0000000..11c16ea
--- /dev/null
+++ b/app/src/main/assets/skills/notion_ui.json
@@ -0,0 +1,7 @@
+{
+ "id": "notion_ui",
+ "targetPackageNames": ["notion.id"],
+ "name": "Notion UI Skills",
+ "description": "How to handle Notion when the connector tools aren't available.",
+ "instructions": "If the notion_* tools are NOT in your tool list, no Notion integration is connected. In that case:\n1. Say so plainly and point the user at the drawer menu ▸ Connectors ▸ Notion — connecting takes an internal integration token from notion.so/my-integrations and gives you real search/read/write.\n2. Only drive the app's UI with open_app + navigate_app if the user asks you to anyway. It is slow and the editor is awkward to automate: prefer reading over writing, and never try to restructure a page by tapping.\n3. Notion's app search is the reliable entry point once inside — open the app, tap search, type the page title, rather than scrolling the sidebar."
+}
diff --git a/app/src/main/assets/skills/outlook.json b/app/src/main/assets/skills/outlook.json
deleted file mode 100644
index ea8b165..0000000
--- a/app/src/main/assets/skills/outlook.json
+++ /dev/null
@@ -1,7 +0,0 @@
-{
- "id": "outlook_microsoft",
- "targetPackageNames": ["com.microsoft.office.outlook", "com.microsoft.todos"],
- "name": "Outlook and Microsoft To Do Skills",
- "description": "Use the Microsoft Graph connector tools instead of automating Outlook or To Do.",
- "instructions": "Never automate the Outlook or Microsoft To Do UI. When the Microsoft connector is set up (drawer menu ▸ Connectors), these tools talk to the account directly:\n\nMail — the ordinary email tools cover Outlook, no separate tools exist:\n1. list_emails returns rows whose ids start with 'ms:' when Outlook is the active backend.\n2. read_email and mark_email_read route by that id prefix, so ids stay valid.\n3. send_email always shows the user a confirmation dialog before anything leaves the device.\nNote the backend order: if a Gmail connector is also set up, Gmail is used for new listings and sends. Existing 'ms:' ids still resolve to Outlook.\n\nTasks — list_tasks, create_task and complete_task read and write the user's real Microsoft To Do lists, which sync to their other devices. These are NOT the same as todowrite: todowrite is your own scratch plan for the current conversation and disappears afterwards. If the user says 'remind me to…', 'add to my to-do list', or 'put it on my list', they mean create_task. Use todowrite only to track your own steps through a multi-part request.\n\nCalendar — use list_calendar_events / create_calendar_event with source='microsoft', and check_availability for free/busy questions.\n\nIf a tool reports that the sign-in expired or needs reconnecting, tell the user to reconnect in the drawer menu ▸ Connectors; do not try to work around it through the UI."
-}
diff --git a/app/src/main/assets/skills/outlook_connector.json b/app/src/main/assets/skills/outlook_connector.json
new file mode 100644
index 0000000..69ae43d
--- /dev/null
+++ b/app/src/main/assets/skills/outlook_connector.json
@@ -0,0 +1,8 @@
+{
+ "id": "outlook_connector",
+ "targetPackageNames": ["com.microsoft.office.outlook", "com.microsoft.todos"],
+ "name": "Outlook and Microsoft To Do Connector Skills",
+ "description": "Use the Microsoft Graph connector tools instead of automating Outlook or To Do.",
+ "requiresTools": ["list_emails", "list_tasks"],
+ "instructions": "A Microsoft account is connected, so never automate the Outlook or Microsoft To Do UI. These tools talk to the account directly:\n\nMail — the ordinary email tools cover Outlook, no separate tools exist:\n1. list_emails returns rows whose ids start with 'ms:' when Outlook is the active backend.\n2. read_email and mark_email_read route by that id prefix, so ids stay valid.\n3. send_email always shows the user a confirmation dialog before anything leaves the device.\nNote the backend order: if a Gmail connector is also set up, Gmail is used for new listings and sends. Existing 'ms:' ids still resolve to Outlook.\n\nTasks — list_tasks, create_task and complete_task read and write the user's real Microsoft To Do lists, which sync to their other devices. These are NOT the same as todowrite: todowrite is your own scratch plan for the current conversation and disappears afterwards. If the user says 'remind me to…', 'add to my to-do list', or 'put it on my list', they mean create_task. Use todowrite only to track your own steps through a multi-part request.\n\nCalendar — use list_calendar_events / create_calendar_event with source='microsoft', and check_availability for free/busy questions.\n\nIf a tool reports that the sign-in expired or needs reconnecting, tell the user to reconnect in the drawer menu ▸ Connectors; do not try to work around it through the UI."
+}
diff --git a/app/src/main/assets/skills/outlook_ui.json b/app/src/main/assets/skills/outlook_ui.json
new file mode 100644
index 0000000..cdfcb19
--- /dev/null
+++ b/app/src/main/assets/skills/outlook_ui.json
@@ -0,0 +1,7 @@
+{
+ "id": "outlook_ui",
+ "targetPackageNames": ["com.microsoft.office.outlook", "com.microsoft.todos"],
+ "name": "Outlook and Microsoft To Do UI Skills",
+ "description": "How to handle Outlook and To Do when the Microsoft connector isn't available.",
+ "instructions": "If list_emails or list_tasks are NOT in your tool list, no Microsoft account is connected. In that case:\n1. For mail, use compose_email to open a pre-filled draft in the user's own mail app. Mention that connecting Microsoft in the drawer menu ▸ Connectors adds inbox reading, sending and To Do.\n2. For to-dos, do NOT silently substitute todowrite — it is your own scratch plan for this conversation and vanishes afterwards, so the user's reminder would be lost. Say the list isn't connected, then offer either connecting it or driving the To Do app's UI.\n3. When driving either app's UI, use open_app + navigate_app. Outlook's own settings screens (signatures, swipe actions, account setup) always need the UI even when the connector is available."
+}
diff --git a/app/src/main/java/com/gotcha/agent/AgentEngine.kt b/app/src/main/java/com/gotcha/agent/AgentEngine.kt
index b006371..4718605 100644
--- a/app/src/main/java/com/gotcha/agent/AgentEngine.kt
+++ b/app/src/main/java/com/gotcha/agent/AgentEngine.kt
@@ -847,7 +847,7 @@ class AgentEngine(
private fun activeSkillsMessages(): List<ChatMessage> {
val currentPackage = ScreenPerception.getCurrentPackageName() ?: return emptyList()
val disabledSkills = settingsProvider().disabledSkills
- val activeSkills = SkillRegistry.getSkillsForPackage(currentPackage)
+ val activeSkills = SkillRegistry.getSkillsForPackage(currentPackage, hiddenConnectorTools())
.filter { !disabledSkills.contains(it.id) }
val communityIds = SkillRegistry.getCommunitySkills().map { it.id }.toSet()
val message = SkillPromptBuilder.build(currentPackage, activeSkills, communityIds)
diff --git a/app/src/main/java/com/gotcha/agent/skills/Skill.kt b/app/src/main/java/com/gotcha/agent/skills/Skill.kt
index 1cef4e8..e643df1 100644
--- a/app/src/main/java/com/gotcha/agent/skills/Skill.kt
+++ b/app/src/main/java/com/gotcha/agent/skills/Skill.kt
@@ -8,5 +8,23 @@ data class Skill(
val targetPackageNames: List<String> = emptyList(),
val instructions: String,
val description: String = "",
- val title: String = ""
-)
+ val title: String = "",
+ /**
+ * Tools this skill teaches. The skill is only injected when at least one of
+ * them is currently callable — advice for a tool the agent cannot reach
+ * costs tokens and invites a doomed tool call.
+ *
+ * Empty (the default) means always eligible, so skills that teach UI
+ * automation or device tools need no annotation, and existing community
+ * skills keep working unchanged.
+ *
+ * Named as tools rather than as a connector on purpose: `list_emails` is
+ * served by Gmail *or* Microsoft *or* IMAP, so naming one connector would be
+ * wrong for the other two, and this also covers permission-gated tools.
+ */
+ val requiresTools: List<String> = emptyList()
+) {
+ /** True when nothing this skill teaches is currently withheld from the model. */
+ fun isAvailable(hiddenTools: Set<String>): Boolean =
+ requiresTools.isEmpty() || requiresTools.any { it !in hiddenTools }
+}
diff --git a/app/src/main/java/com/gotcha/agent/skills/SkillImportValidator.kt b/app/src/main/java/com/gotcha/agent/skills/SkillImportValidator.kt
index 6ec1cd0..94cdead 100644
--- a/app/src/main/java/com/gotcha/agent/skills/SkillImportValidator.kt
+++ b/app/src/main/java/com/gotcha/agent/skills/SkillImportValidator.kt
@@ -10,12 +10,14 @@ object SkillImportValidator {
private val ID_REGEX = Regex("^[a-z][a-z0-9_]{2,63}$")
private val PACKAGE_REGEX = Regex("^[a-zA-Z][a-zA-Z0-9_]*(\\.[a-zA-Z0-9_]+)+$")
+ private val TOOL_NAME_REGEX = Regex("^[a-z][a-z0-9_]{1,63}$")
const val MAX_ID_LENGTH = 64
const val MAX_TITLE_LENGTH = 120
const val MAX_DESCRIPTION_LENGTH = 1024
const val MAX_INSTRUCTIONS_LENGTH = 32 * 1024
const val MAX_TARGET_PACKAGES = 32
+ const val MAX_REQUIRED_TOOLS = 32
const val MAX_TOTAL_INSTRUCTIONS = 64 * 1024
fun validate(skill: Skill) {
@@ -50,6 +52,16 @@ object SkillImportValidator {
throw SkillValidationException("invalid target package name: $pkg")
}
}
+ if (skill.requiresTools.size > MAX_REQUIRED_TOOLS) {
+ throw SkillValidationException("requiresTools exceeds $MAX_REQUIRED_TOOLS entries")
+ }
+ // Names only — an unknown name simply never matches, which fails closed
+ // (the skill stays hidden) rather than exposing anything.
+ skill.requiresTools.forEach { tool ->
+ if (!TOOL_NAME_REGEX.matches(tool)) {
+ throw SkillValidationException("invalid tool name in requiresTools: $tool")
+ }
+ }
if (containsControlChars(skill.instructions)) {
throw SkillValidationException("instructions contains control characters")
}
diff --git a/app/src/main/java/com/gotcha/agent/skills/SkillRegistry.kt b/app/src/main/java/com/gotcha/agent/skills/SkillRegistry.kt
index 35b28ea..ed2121d 100644
--- a/app/src/main/java/com/gotcha/agent/skills/SkillRegistry.kt
+++ b/app/src/main/java/com/gotcha/agent/skills/SkillRegistry.kt
@@ -108,20 +108,33 @@ object SkillRegistry {
fun getSkillById(id: String): Skill? = merged.find { it.id == id }
- fun getSkillsForPackage(packageName: String): List<Skill> {
+ /**
+ * Skills targeting [packageName], minus any whose tools are all withheld
+ * this turn (see [Skill.requiresTools]). [hiddenTools] defaults to empty, so
+ * callers that do not gate get every matching skill as before.
+ */
+ fun getSkillsForPackage(
+ packageName: String,
+ hiddenTools: Set<String> = emptySet()
+ ): List<Skill> {
return merged.filter { skill ->
- skill.targetPackageNames.contains(packageName) ||
- skill.targetPackageNames.contains("*")
+ (
+ skill.targetPackageNames.contains(packageName) ||
+ skill.targetPackageNames.contains("*")
+ ) && skill.isAvailable(hiddenTools)
}
}
- fun searchSkills(query: String): List<Skill> {
+ /** Same gating as [getSkillsForPackage] — a hidden skill is unreachable by both channels. */
+ fun searchSkills(query: String, hiddenTools: Set<String> = emptySet()): List<Skill> {
val q = query.lowercase()
return merged.filter { skill ->
- skill.id.lowercase().contains(q) ||
- skill.description.lowercase().contains(q) ||
- skill.title.lowercase().contains(q) ||
- skill.targetPackageNames.any { it.lowercase().contains(q) }
+ (
+ skill.id.lowercase().contains(q) ||
+ skill.description.lowercase().contains(q) ||
+ skill.title.lowercase().contains(q) ||
+ skill.targetPackageNames.any { it.lowercase().contains(q) }
+ ) && skill.isAvailable(hiddenTools)
}
}
diff --git a/app/src/main/java/com/gotcha/tools/SubAgentSession.kt b/app/src/main/java/com/gotcha/tools/SubAgentSession.kt
index 6561256..0c58357 100644
--- a/app/src/main/java/com/gotcha/tools/SubAgentSession.kt
+++ b/app/src/main/java/com/gotcha/tools/SubAgentSession.kt
@@ -62,7 +62,7 @@ class SubAgentSession(
val messages = buildList {
addAll(history)
- addAll(activeSkillsMessages(settings.disabledSkills))
+ addAll(activeSkillsMessages(settings.disabledSkills, hiddenTools))
}
val response = try {
@@ -275,9 +275,12 @@ class SubAgentSession(
}
}
- private fun activeSkillsMessages(disabledSkills: Set<String>): List<ChatMessage> {
+ private fun activeSkillsMessages(
+ disabledSkills: Set<String>,
+ hiddenTools: Set<String>
+ ): List<ChatMessage> {
val currentPackage = ScreenPerception.getCurrentPackageName() ?: return emptyList()
- val activeSkills = SkillRegistry.getSkillsForPackage(currentPackage)
+ val activeSkills = SkillRegistry.getSkillsForPackage(currentPackage, hiddenTools)
.filter { !disabledSkills.contains(it.id) }
val communityIds = SkillRegistry.getCommunitySkills().map { it.id }.toSet()
val message = SkillPromptBuilder.build(currentPackage, activeSkills, communityIds)
diff --git a/app/src/main/java/com/gotcha/tools/ToolExecutor.kt b/app/src/main/java/com/gotcha/tools/ToolExecutor.kt
index a1d53ab..594c35b 100644
--- a/app/src/main/java/com/gotcha/tools/ToolExecutor.kt
+++ b/app/src/main/java/com/gotcha/tools/ToolExecutor.kt
@@ -103,7 +103,7 @@ class ToolExecutor(
)
}
val result = try {
- withContext(Dispatchers.IO) { dispatch(name, args) }
+ withContext(Dispatchers.IO) { dispatch(name, args, hiddenTools) }
} catch (e: CancellationException) {
throw e
} catch (e: Exception) {
@@ -159,7 +159,7 @@ class ToolExecutor(
// Single when-dispatch over the entire fixed tool catalog; size and branch count are
// inherent to the design (see AGENTS.md).
@Suppress("CyclomaticComplexMethod", "LongMethod")
- private suspend fun dispatch(name: String, args: JsonObject): ToolResult {
+ private suspend fun dispatch(name: String, args: JsonObject, hidden: Set<String>): ToolResult {
com.gotcha.connectors.ConnectorRegistry.toolHandler(name)?.let { return it.invoke(name, args) }
return when (name) {
"dial_number" -> phoneTool.dialNumber(args.requireString("number") ?: return missing("number"))
@@ -489,7 +489,9 @@ class ToolExecutor(
)
"search_skills" -> {
val query = args.requireString("query") ?: return missing("query")
- val results = SkillRegistry.searchSkills(query)
+ // Same gating as the auto-injected skills: never hand back advice
+ // for tools the model cannot currently call.
+ val results = SkillRegistry.searchSkills(query, hidden)
if (results.isEmpty()) {
ToolResult.ok("No skills found matching '$query'.")
} else {
diff --git a/app/src/test/java/com/gotcha/agent/skills/SkillGatingTest.kt b/app/src/test/java/com/gotcha/agent/skills/SkillGatingTest.kt
new file mode 100644
index 0000000..f9a58b4
--- /dev/null
+++ b/app/src/test/java/com/gotcha/agent/skills/SkillGatingTest.kt
@@ -0,0 +1,130 @@
+package com.gotcha.agent.skills
+
+import com.gotcha.connectors.ConnectorCatalog
+import com.gotcha.testsupport.RepoPaths
+import com.gotcha.tools.ToolRegistry
+import kotlinx.serialization.json.Json
+import org.junit.Assert.assertEquals
+import org.junit.Assert.assertFalse
+import org.junit.Assert.assertTrue
+import org.junit.Test
+
+/**
+ * The connector↔skill link: a skill is only eligible when at least one tool it
+ * teaches is currently callable. Reads the bundled skill assets straight off
+ * disk so the annotations on the shipped files are covered too.
+ */
+class SkillGatingTest {
+
+ private val json = Json { ignoreUnknownKeys = true }
+
+ private fun bundled(): List<Skill> =
+ RepoPaths.file("app/src/main/assets/skills")
+ .walkTopDown()
+ .filter { it.isFile && it.extension == "json" }
+ .map { json.decodeFromString(Skill.serializer(), it.readText()) }
+ .toList()
+
+ @Test
+ fun `a skill with no requiresTools is always eligible`() {
+ val skill = Skill(id = "x", instructions = "do a thing")
+ assertTrue(skill.isAvailable(emptySet()))
+ assertTrue(skill.isAvailable(ConnectorCatalog.allOwnedTools))
+ }
+
+ @Test
+ fun `a skill is hidden only when every tool it teaches is hidden`() {
+ val skill = Skill(
+ id = "x",
+ instructions = "use email",
+ requiresTools = listOf("list_emails", "send_email")
+ )
+ assertTrue("one tool left is enough", skill.isAvailable(setOf("send_email")))
+ assertFalse(skill.isAvailable(setOf("list_emails", "send_email")))
+ }
+
+ @Test
+ fun `bundled skills parse and their requiresTools name real tools`() {
+ val skills = bundled()
+ assertTrue(skills.isNotEmpty())
+ skills.forEach { skill ->
+ skill.requiresTools.forEach { tool ->
+ assertTrue(
+ "skill '${skill.id}' requires unknown tool '$tool'",
+ ToolRegistry.contains(tool)
+ )
+ }
+ }
+ }
+
+ @Test
+ fun `bundled skill ids are unique`() {
+ val ids = bundled().map { it.id }
+ assertEquals(ids.size, ids.toSet().size)
+ }
+
+ @Test
+ fun `connector skills are split so the UI half survives the connector going away`() {
+ val skills = bundled().associateBy { it.id }
+ listOf("gmail", "notion", "outlook").forEach { family ->
+ val connectorHalf = skills["${family}_connector"]
+ val uiHalf = skills["${family}_ui"]
+ assertTrue("$family connector skill missing", connectorHalf != null)
+ assertTrue("$family UI skill missing", uiHalf != null)
+ assertTrue(
+ "$family connector skill must be gated",
+ connectorHalf!!.requiresTools.isNotEmpty()
+ )
+ assertTrue(
+ "$family UI skill must stay available with no connector",
+ uiHalf!!.requiresTools.isEmpty()
+ )
+ // Both halves target the same apps, so the split is invisible to the user.
+ assertEquals(connectorHalf.targetPackageNames, uiHalf.targetPackageNames)
+ }
+ }
+
+ @Test
+ fun `with nothing connected only the UI halves survive`() {
+ val hidden = ConnectorCatalog.hiddenTools(emptySet())
+ val eligible = bundled().filter { it.isAvailable(hidden) }.map { it.id }.toSet()
+
+ assertTrue("gmail_ui" in eligible)
+ assertTrue("notion_ui" in eligible)
+ assertTrue("outlook_ui" in eligible)
+ assertFalse("gmail_connector" in eligible)
+ assertFalse("notion_connector" in eligible)
+ assertFalse("outlook_connector" in eligible)
+ // Device-backed skills are unaffected.
+ assertTrue("calendar_operations" in eligible)
+ }
+
+ @Test
+ fun `connecting a mail backend brings back the mail skills only`() {
+ val hidden = ConnectorCatalog.hiddenTools(setOf("imap"))
+ val eligible = bundled().filter { it.isAvailable(hidden) }.map { it.id }.toSet()
+
+ assertTrue("gmail_connector" in eligible)
+ assertTrue("outlook_connector" in eligible) // gated on list_emails OR list_tasks
+ assertFalse("notion_connector" in eligible)
+ }
+
+ @Test
+ fun `validator accepts requiresTools and rejects malformed entries`() {
+ SkillImportValidator.validate(
+ Skill(id = "abc", instructions = "hi", requiresTools = listOf("list_emails"))
+ )
+ val bad = Skill(id = "abc", instructions = "hi", requiresTools = listOf("Not A Tool"))
+ val error = runCatching { SkillImportValidator.validate(bad) }.exceptionOrNull()
+ assertTrue(error is SkillValidationException)
+ }
+
+ @Test
+ fun `an unknown required tool fails closed`() {
+ // Never matches anything, so the skill simply stays hidden rather than
+ // becoming unconditionally visible.
+ val skill = Skill(id = "x", instructions = "hi", requiresTools = listOf("no_such_tool"))
+ assertTrue(skill.isAvailable(emptySet()))
+ assertFalse(skill.isAvailable(setOf("no_such_tool")))
+ }
+}