Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
fb59c32
ADFA-7147 AI-Core: let "Always Allow" cover a contributed tool declar…
davidschachterADFA Nov 16, 2026
419945e
ADFA-7147 AI-Core: a contributed tool's grant covers its description …
davidschachterADFA Nov 17, 2026
2cd8171
ADFA-7147 AI-Core: say whose read-only claim "Always Allow" rests on
davidschachterADFA Nov 17, 2026
d376979
ADFA-7147 AI-Core: "Always Allow" ends with the chat, for every tool
davidschachterADFA Nov 17, 2026
97a63d3
ADFA-7147 AI-Core: correct the help text this PR made untrue
davidschachterADFA Nov 17, 2026
0bd787f
ADFA-7147 AI-Core: keep every approval button reachable at any font s…
davidschachterADFA Nov 17, 2026
a1a2671
ADFA-7147 AI-Core: stack the approval buttons in the stock order, pri…
davidschachterADFA Nov 17, 2026
083078c
ADFA-7147 AI-Core: stack the approval buttons against the end edge, a…
davidschachterADFA Nov 17, 2026
6acce32
Revert "ADFA-7147 AI-Core: stack the approval buttons against the end…
davidschachterADFA Nov 17, 2026
2e1f398
Revert "ADFA-7147 AI-Core: stack the approval buttons in the stock or…
davidschachterADFA Nov 17, 2026
a27863d
Revert "ADFA-7147 AI-Core: keep every approval button reachable at an…
davidschachterADFA Nov 17, 2026
e71f36e
ADFA-7147 AI-Core: keep the approval buttons on screen by bounding th…
davidschachterADFA Nov 17, 2026
72971fd
ADFA-7147 AI-Core: cap the approval message so the stock buttons keep…
davidschachterADFA Nov 17, 2026
9bc42f2
ADFA-7147 AI-Core: reserve the buttons' height only on the first meas…
davidschachterADFA Nov 17, 2026
3502af1
ADFA-7147 AI-Core: restore the scroll indicators on the approval message
davidschachterADFA Nov 17, 2026
3cc8757
ADFA-7147 AI-Core: treat an unspecified height as unlimited and resto…
davidschachterADFA Nov 17, 2026
aa9fafd
ADFA-7147 AI-Core: start a new measure sequence when the approval mes…
davidschachterADFA Nov 17, 2026
e2f2a66
ADFA-7147 AI-Core: open the approval message with the tool's full nam…
davidschachterADFA Nov 18, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions plugins/AI-Core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,32 @@ Four rules the store applies, each of which was a bug before it was a rule:
Contributed tools run inside the contributing plugin, under *its* permissions, and
outside the `PathGuard` containment that covers this plugin's own handlers — so the
approval dialog names the source plugin, and `allowsSessionApproval` is false for
every contributed tool: "Always Allow" is downgraded to a single approval.
every contributed tool that may change something: "Always Allow" is downgraded to a
single approval. A tool its provider declares read-only (`ToolSpec.isReadOnly`) may
be allowed for the session (ADFA-7147): still one explicit approval per tool, and the
grant is keyed by provider, the tool's own name and a SHA-256 of its description and
input schema rather than by the registered name, which can pass to another plugin's tool
when the sources change. A tool its provider republishes under the same name with
another description or schema therefore asks again. The grant lapses if the tool stops
declaring itself read-only, and every grant, built-in or contributed, ends with the chat:
`ChatViewModel` clears them whenever the current chat changes (new, opened, imported, or
deleted and replaced) or is cleared, since its `ToolApprovalManager` lives as long as the
plugin. The declaration is the provider's own and nothing checks it,
so a dialog offering "Always Allow" for a contributed tool says exactly that
(`ApprovalRequest.readOnlyOnProvidersWord`).

For the same reason a source's own `requiresApproval = false` is ignored:
`ensureApproved` returns early on it, before `allowsSessionApproval` is ever
consulted, so honouring it would let a provider decline the only control there is
by asking. The dialog's title is the *registered* name, and all three
provider-supplied strings on it — the tool's own name, its description and the
source's label — are flattened and capped first, at the `ContributedToolHandler`
boundary rather than in each provider. A remote `displayName` carrying a newline
and a copy of the dialog's own header could otherwise forge structure the user
then trusts. Contributing plugins therefore ship no sanitising of their own and
depend on the installed `ai-core` for it; the two version independently.
by asking. The dialog's message opens with the *registered* name, whole, under a
short generic title (the stock title is one line, two at most, and cut a long name
off at font scale 2.0). All three provider-supplied strings on it — the tool's own
name, its description and the source's label — are flattened and capped first, at
the `ContributedToolHandler` boundary rather than in each provider. A remote
`displayName` carrying a newline and a copy of the dialog's own lines could
otherwise forge structure the user then trusts. Contributing plugins therefore
ship no sanitising of their own and depend on the installed `ai-core` for it; the
two version independently.

## System prompt config

Expand Down
7 changes: 4 additions & 3 deletions plugins/AI-Core/ai-core.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,10 @@ <h2>Core functionality</h2>
<code>edit_file</code>; one that arrives with a name already in use is
offered under a provider-prefixed name instead of being dropped.</li>
<li><b>Approval with provenance</b> — the approval dialog names the plugin a
tool came from, and a contributed tool can never be blanket-approved for the
session: it asks every time, because it runs outside the path containment
that covers the agent's own tools.</li>
tool came from, and a contributed tool asks on every call, because it runs
outside the path containment that covers the agent's own tools. The one
exception is a tool its plugin says only reads: it may be allowed for the
rest of the chat, and the dialog says Code on the Go cannot check that claim.</li>
<li>Text completion, chat with history, and streaming responses, plus a
single cancellation path so <b>Stop</b> reaches whichever backend is
running.</li>
Expand Down
17 changes: 11 additions & 6 deletions plugins/AI-Core/src/main/assets/docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,17 @@ <h2>Tools from other plugins</h2>
<p>These tools are treated more cautiously than the agent's own, because only
the plugin that supplied one knows what it does:</p>
<ul>
<li><b>They ask every time.</b> The approval dialog names the plugin the tool
came from — <i>From MCP servers</i>, for example — and does not offer
<b>Always Allow</b>. A plugin cannot waive this for
its own tools, and the title shows the name the agent registered rather than
the one the tool came with, so a remote tool cannot pass itself off as a
built-in one.</li>
<li><b>The dialog names where they come from.</b> The approval dialog names the
plugin the tool came from — <i>From MCP servers</i>, for example. A plugin cannot
skip this dialog for its own tools. The dialog's first line, <i>Tool:</i>,
shows the whole name the agent registered rather than the one the tool came
with, so a remote tool cannot pass itself off as a built-in one.</li>
<li><b>Most ask every time.</b> The dialog offers <b>Always Allow</b> only for
a tool its plugin says only reads, and then says that Code on the Go cannot
check that. Allowing it stops the questions for that tool, whatever its
arguments, until you start a new chat, open another one or clear this one.
If the plugin changes the tool's description or inputs, you are asked again.
Every other tool from a plugin asks on every call.</li>
<li><b>They are not confined to the project root.</b> A contributed tool runs
inside its own plugin, under the permissions that plugin declared, so one
from a plugin with network access can send what it is given off the device.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
package com.itsaky.androidide.plugins.aicore.fragments

import android.app.Dialog
import android.content.Context
import android.content.res.Resources
import android.os.Bundle
import android.text.InputType
import android.view.View
import android.view.ViewGroup
import android.widget.EditText
import android.util.TypedValue
import android.widget.FrameLayout
import android.widget.TextView
import androidx.appcompat.app.AlertDialog
import androidx.core.content.res.use
import androidx.core.view.ViewCompat
import androidx.core.widget.NestedScrollView
import androidx.fragment.app.DialogFragment
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.itsaky.androidide.plugins.aicore.plugin.AiCorePlugin
Expand Down Expand Up @@ -53,13 +60,16 @@ class ApprovalDialogFragment : DialogFragment() {
}

companion object {
/** The least the approval message is given (about three lines), whatever the buttons need. */
private const val MESSAGE_FLOOR_DP = 96
private const val ARG_TOOL_NAME = "tool_name"
private const val ARG_PROVIDER_NAME = "provider_name"
private const val ARG_SOURCE = "source"
private const val ARG_DESCRIPTION = "description"
private const val ARG_ARGS = "args"
private const val ARG_PREVIEW = "preview"
private const val ARG_ALLOWS_ALWAYS_ALLOW = "allows_always_allow"
private const val ARG_READ_ONLY_ON_PROVIDERS_WORD = "read_only_on_providers_word"

/**
* Builds the dialog. Everything it needs is in [getArguments], so the framework can
Expand All @@ -83,6 +93,7 @@ class ApprovalDialogFragment : DialogFragment() {
putString(ARG_PREVIEW, preview.name)
putString(ARG_ARGS, ApprovalPresentation.format(preview, request.args, resources))
putBoolean(ARG_ALLOWS_ALWAYS_ALLOW, request.allowsSessionApproval)
putBoolean(ARG_READ_ONLY_ON_PROVIDERS_WORD, request.readOnlyOnProvidersWord)
}
}
}
Expand All @@ -97,33 +108,26 @@ class ApprovalDialogFragment : DialogFragment() {
val preview = ApprovalPresentation.named(arguments?.getString(ARG_PREVIEW))
val isEdit = preview == ApprovalPreview.EDIT
val allowsAlwaysAllow = arguments?.getBoolean(ARG_ALLOWS_ALWAYS_ALLOW) ?: false
// An edit never offers it, whatever the request allows; see the buttons below.
val offersAlwaysAllow = allowsAlwaysAllow && !isEdit
val readOnlyOnProvidersWord = arguments?.getBoolean(ARG_READ_ONLY_ON_PROVIDERS_WORD) ?: false

val message = buildString {
append(getString(R.string.approval_header))
append("\n\n")
// Provenance before the description: a tool that leaves the device is a different
// decision from a local edit, and only the source says which this is.
if (!source.isNullOrBlank()) {
append(getString(R.string.approval_source, source))
append("\n")
// Both names, when they differ: the title says what runs, this says what the
// source calls it, so neither can be passed off as the other.
if (!providerName.isNullOrBlank()) {
append(getString(R.string.approval_provider_name, providerName))
append("\n")
}
append("\n")
}
append(description)
append("\n\n")
append(getString(ApprovalPresentation.argsLabel(preview)))
append("\n")
append(argsText)
}
// The full name opens the message, not the title, which a long name overflows; see message().
val message = ApprovalPresentation.message(
toolName = toolName,
source = source,
providerName = providerName,
readOnlyClaim = offersAlwaysAllow && readOnlyOnProvidersWord,
description = description,
preview = preview,
argsText = argsText,
resources = resources,
)

val builder = MaterialAlertDialogBuilder(requireContext())
.setTitle(getString(R.string.approval_confirm_title, toolName))
.setMessage(message)
builder
.setTitle(getString(R.string.approval_confirm_title))
.setView(messageView(builder.context, message))
.setNegativeButton(getString(R.string.approval_decline)) { _, _ ->
decide(ApprovalResult.DENIED)
dismiss()
Expand All @@ -144,7 +148,7 @@ class ApprovalDialogFragment : DialogFragment() {
decide(ApprovalResult.APPROVED_ONCE)
dismiss()
}
if (allowsAlwaysAllow) {
if (offersAlwaysAllow) {
builder.setNeutralButton(getString(R.string.approval_always_allow)) { _, _ ->
decide(ApprovalResult.APPROVED_FOR_SESSION)
dismiss()
Expand Down Expand Up @@ -188,6 +192,89 @@ class ApprovalDialogFragment : DialogFragment() {
return dialog
}

/**
* The message as a scrolling view bounded by [BoundedScrollView]. The stock layout gives the middle
* panel its height before the buttons get more than their minimum, so a long message squeezed the
* stacked buttons off screen at a large font scale; the bound leaves the buttons their full height.
* The text looks like the stock message: it takes the dialog theme's own `materialAlertDialogBodyTextStyle`
* and `dialogPreferredPadding`, from [context] (the builder's, so it carries the dialog theme overlay).
*/
private fun messageView(context: Context, message: CharSequence): View {
val style = TypedValue()
val styleRes = if (context.theme.resolveAttribute(
com.google.android.material.R.attr.materialAlertDialogBodyTextStyle, style, true,
)
) style.resourceId else 0
val padding = context.obtainStyledAttributes(
intArrayOf(androidx.appcompat.R.attr.dialogPreferredPadding),
).use { it.getDimensionPixelSize(0, 0) }
val text = TextView(context, null, 0, styleRes).apply {
this.text = message
setPadding(padding, paddingTop, padding, paddingBottom)
Comment thread
davidschachterADFA marked this conversation as resolved.
Resolved
}
// The stock layout puts this gap (titleDividerNoCustom) between the title and a message
// it owns; a custom view loses it, so it is restored as top padding on the scroll view.
val gap = context.resources.getDimensionPixelSize(androidx.appcompat.R.dimen.abc_dialog_title_divider_material)
return BoundedScrollView(context).apply {
setPadding(paddingLeft, gap, paddingRight, paddingBottom)
// The stock content panel shows these edge indicators while it can scroll; setView drops them.
scrollIndicators = View.SCROLL_INDICATOR_TOP or View.SCROLL_INDICATOR_BOTTOM
addView(text)
}
}

/**
* A [NestedScrollView] capped by [ApprovalPresentation.messageMaxHeightPx] so the stock button panel
* keeps its full height. `AlertDialogLayout.tryOnMeasure` measures the button panel (unspecified, so
* at its full height) before it measures this view, counts only its minimum, then may measure this
* view again with the height left over once the buttons took theirs, and `forceUniformWidth` may
* measure it a third time. Only the first measure of a sequence reserves room for the buttons;
* [firstOffered] remembers that offer so the later ones are recognised. [onLayout] ends the sequence,
* and so does a larger offer, which is a new measure pass before any layout
* ([ApprovalPresentation.sequenceFirstOfferPx]).
*/
private class BoundedScrollView(context: Context) : NestedScrollView(context) {
private var firstOffered: Int? = null

override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
val unlimited = View.MeasureSpec.getMode(heightMeasureSpec) == View.MeasureSpec.UNSPECIFIED
val offered = if (unlimited) Int.MAX_VALUE else View.MeasureSpec.getSize(heightMeasureSpec)
val panel = rootView?.findViewById<View>(androidx.appcompat.R.id.buttonPanel)
?.takeIf { it.visibility == View.VISIBLE && it.measuredHeight > 0 }
val metrics = resources.displayMetrics
firstOffered = ApprovalPresentation.sequenceFirstOfferPx(firstOffered, offered)
val cap = ApprovalPresentation.messageMaxHeightPx(
Comment thread
davidschachterADFA marked this conversation as resolved.
Resolved
windowHeightPx = metrics.heightPixels,
offeredPx = offered,
buttonsFullPx = panel?.measuredHeight,
buttonsMinPx = panel?.let(::minimumHeightOf) ?: 0,
floorPx = (MESSAGE_FLOOR_DP * metrics.density).toInt(),
firstOfferedPx = firstOffered,
)
super.onMeasure(
widthMeasureSpec,
View.MeasureSpec.makeMeasureSpec(minOf(cap, offered), View.MeasureSpec.AT_MOST),
)
}

override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) {
firstOffered = null
super.onLayout(changed, l, t, r, b)
}

override fun onDetachedFromWindow() {
firstOffered = null
super.onDetachedFromWindow()
}

/** Mirrors `AlertDialogLayout.resolveMinimumHeight`: the view's own, else its only child's. */
private fun minimumHeightOf(view: View): Int {
val own = ViewCompat.getMinimumHeight(view)
if (own > 0) return own
return if (view is ViewGroup && view.childCount == 1) minimumHeightOf(view.getChildAt(0)) else 0
}
}

/**
* Delivers the outcome to the host fragment.
*
Expand Down
Loading
Loading