Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
50d0bd2
ADFA-7302 sqlite-debugger: get_template_variables
claude Nov 26, 2026
757e9e1
ADFA-7302 templates: one place for the project templates' Pebble sett…
claude Nov 26, 2026
1f31f95
ADFA-7302 plugin API: SqlTemplateService renders the project's SQL te…
claude Nov 26, 2026
78d659d
ADFA-7302 style: spotlessApply, no functional change
davidschachterADFA Nov 26, 2026
cff5a5b
ADFA-7302 sql templates: a stopped render ends, and range is capped
davidschachterADFA Nov 26, 2026
743a9e6
ADFA-7302 sqlite debugger: get_template_variables reports every datab…
davidschachterADFA Nov 26, 2026
d6fcb42
ADFA-7302 sqlite debugger: only Room's own tables are Room's own_tables
davidschachterADFA Nov 26, 2026
11d0b34
ADFA-7302 sqlite debugger: an empty page that says more follows marks…
davidschachterADFA Nov 26, 2026
0fb8da0
ADFA-7302 sql templates: quote negatives, refuse named arguments, rea…
davidschachterADFA Nov 26, 2026
8e972de
ADFA-7302 sql templates: read a template only as a regular file, and …
davidschachterADFA Nov 26, 2026
23a6dfc
ADFA-7302 plugin manager: close SqlTemplateService when its plugin is…
davidschachterADFA Nov 26, 2026
21955e6
ADFA-7302 sql templates: one bad schema file is skipped, and the 2,00…
davidschachterADFA Nov 26, 2026
5ba05e2
ADFA-7302 docs: render closing delimiters in the Javadoc, and say a f…
davidschachterADFA Nov 26, 2026
594079c
ADFA-7302 tests: SqlTemplateService close and reopen
davidschachterADFA Nov 26, 2026
0edd649
ADFA-7302 tests: schema nesting bound and the sorted 2,000-entry cut
davidschachterADFA Nov 26, 2026
5ad33e9
ADFA-7302 Merge sqlite-debugger/ADFA-7301 at 1133a58b4 into sqlite-de…
davidschachterADFA Nov 26, 2026
2760274
ADFA-7302 Merge sqlite-debugger/ADFA-7301 at c8bf92110 into sqlite-de…
davidschachterADFA Nov 27, 2026
39daeac
ADFA-7302 ProjectSqlFiles: read a file without readNBytes, which is A…
davidschachterADFA Nov 27, 2026
0ff47e4
ADFA-7302 SQL templates: stop a recursive macro or include at the tim…
davidschachterADFA Nov 27, 2026
c1df230
ADFA-7302 test: the API-33 guard reads method references, and covers …
davidschachterADFA Nov 27, 2026
298a36f
ADFA-7302 SQL templates: bound the strings and lists a template build…
davidschachterADFA Nov 30, 2026
34879cc
ADFA-7302 ProjectSqlFiles: one rule for linked schemas and templates,…
davidschachterADFA Nov 30, 2026
2e8a324
ADFA-7302 get_template_variables: one unreadable table no longer blan…
davidschachterADFA Nov 30, 2026
72a526b
ADFA-7302 SqlTemplateFunction: say what types the arguments really have
davidschachterADFA Nov 30, 2026
26595ae
ADFA-7302 SQL templates: spotlessApply formatting of the review fixes
davidschachterADFA Nov 30, 2026
cdbaab6
ADFA-7302 review follow-ups: fall back per table only for a per-table…
davidschachterADFA Nov 30, 2026
8c56eb2
ADFA-7302 SqlTemplateService: the limit failure names the operation
davidschachterADFA Nov 30, 2026
6c82b69
ADFA-7302 review follow-ups 2: bound arrays, apply the failure check …
davidschachterADFA Nov 30, 2026
d2d7d02
ADFA-7302 SQL templates: split counts its pieces before building them
davidschachterADFA Nov 30, 2026
7f7ab25
Merge sqlite-debugger/ADFA-7301 (#2323, with #2311 at 5d8acf62d) into…
davidschachterADFA Dec 1, 2026
b5791f6
Merge sqlite-debugger/ADFA-7301 (#2323 at 64ff110b7, #2311's README n…
davidschachterADFA Dec 1, 2026
236a52f
Merge sqlite-debugger/ADFA-7301 (#2323 at e3033cfe3: ADFA-7379 from #…
davidschachterADFA Dec 1, 2026
bc03f42
Merge p26/ADFA-7301 (#2323 at 1b2e2d4b1: ADFA-7379 review fixes from …
davidschachterADFA Dec 2, 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.itsaky.androidide.templates

import io.pebbletemplates.pebble.PebbleEngine
import io.pebbletemplates.pebble.lexer.Syntax
import io.pebbletemplates.pebble.loader.StringLoader

/**
* The Pebble settings of Code on the Go's project templates, shared with the SQL templates the SQLite debugger's
* `.read` renders (ADFA-7302), so both read a template the same way.
*/
object ProjectTemplatePebble {
const val PRINT_OPEN = "\${{"
const val PRINT_CLOSE = "}}"
const val EXECUTE_OPEN = "\${%"
const val EXECUTE_CLOSE = "%}"
const val COMMENT_OPEN = "\${#"
const val COMMENT_CLOSE = "#}"

fun syntax(): Syntax =
Syntax
.Builder()
.setPrintOpenDelimiter(PRINT_OPEN)
.setPrintCloseDelimiter(PRINT_CLOSE)
.setExecuteOpenDelimiter(EXECUTE_OPEN)
.setExecuteCloseDelimiter(EXECUTE_CLOSE)
.setCommentOpenDelimiter(COMMENT_OPEN)
.setCommentCloseDelimiter(COMMENT_CLOSE)
.build()

/** A template is its own text ([StringLoader]), an unknown variable is an error, and newline trimming is Pebble's default (on). */
fun engineBuilder(): PebbleEngine.Builder =
PebbleEngine
.Builder()
.loader(StringLoader())
.strictVariables(true)
.syntax(syntax())
}
22 changes: 22 additions & 0 deletions docs/PLUGIN_API_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,28 @@ milestone. **[verified]** = read from the checked-in ABI dump. **[reconstructed]
= diffed from `plugin-api/src` history (predates the dump; symbol-accurate).

### 26.48 — unreleased
- **added — Render the project's SQL templates for the SQLite debugger** _(ADFA-7302)_ **[verified]**
`SqlTemplateService.render(templatePath, variables, functions, timeoutMillis)` renders a Pebble template of the open
project (a path relative to its root, ending in `.peb`, inside it once links are resolved) and returns the SQL, at
most 4 Mi characters. It uses the engine and settings of Code on the Go's project templates: the `${{ }}`, `${% %}`
and `${# #}` delimiters, strict variables and Pebble's newline trimming. One difference: autoescaping is off. Two
filters quote what a template splices in: `sql_ident` (`"..."`) and `sql_literal` (`'...'`, a number as is but a
negative one in parentheses, a boolean as 1 or 0, null as `NULL`). Every render gets `project` (`name`, `path`) and
`render_time` (ISO 8601, UTC); a caller may not pass those names. A variable may be a `java.util.function.Supplier`,
read the first time the template uses it and never when it does not, and a `SqlTemplateFunction` runs each time the
template calls it, with its arguments in order (a named argument fails the render). The render runs on a thread of its
own under one time limit (at most `MAX_TIMEOUT_MILLIS`, 120 s); when it passes, the thread is interrupted (a function
that ignores that keeps running). A function that fails, or a template error, throws the checked
`SqlTemplateException` with a message to show as it is. Pebble's `range` is limited to 100,000 values here (more fails
the render), so is a string a template builds past 4 MiB (4,194,304 characters) or a list or map past 1,000,000
entries (the render fails, naming the operation and the limit). That does not make a render safe: chaining filters in one
expression (such as `base64encode` or `urlencode` repeated many times on a long string) or nesting a list in itself
and printing or joining it can still run the app out of memory, so render only templates you trust. A `for` loop, a macro and an include end when the render is stopped. `listTemplates()` lists the
project's `*.sql.peb` files, and `getRoomSchemas()` the schemas Room exported (`RoomSchema`: class name from the
folder, version, identity hash, path, entities and views with Room's JSON keys, `indices`, `foreignKeys` and `views`
present even where Room left them out). Both skip build output and hidden folders. Every call needs
`debugger.endpoints` and throws `SecurityException` without it, and `IllegalStateException` on the main thread. Both
lists stop at 2,000 entries (the first in their order). Floor `plugin.min_ide_version` at `26.48`.
- **added — Show the IDE's own documentation from a plugin** _(ADFA-7134)_
`IdeTooltipService.showTooltip(anchorView, category, tag)` now reads the IDE's documentation
when `category` is `ide`, `java`, `kotlin` or `xml`, for example
Expand Down
2 changes: 1 addition & 1 deletion docs/PLUGIN_AUTHORING.md
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ Defined by `PluginPermission` in `plugin-api/src/main/kotlin/com/itsaky/androidi
| `project.structure` | Modify project structure |
| `native.code` | Execute native machine code |
| `ide.environment.write` | Write to IDE-managed directories (Android SDK, NDK, cache) |
| `debugger.endpoints` | Read the port and token of the open project's SQLite debugger servers, and so query the apps' databases (read-only for now) |
| `debugger.endpoints` | Read the port and token of the open project's SQLite debugger servers, and so query the apps' databases (read-only for now); render the project's SQL templates (`SqlTemplateService`) |

Plugins run in Code on the Go's process. A permission declares what a plugin means to do, and the
services check it on every call, but it cannot stop a plugin that reaches into the host by
Expand Down
2 changes: 1 addition & 1 deletion docs/plugin-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The surface a plugin binds to is broader than one module. All of the following a
- **The `:plugin-api` module** — package `com.itsaky.androidide.plugins.*`:
- Core: `IPlugin` (lifecycle), `PluginContext`, `PluginLogger`, `ServiceRegistry`, `ResourceManager`.
- Extension interfaces plugins **implement**: `UIExtension`, `EditorExtension`, `EditorTabExtension`, `DocumentationExtension`, `BuildActionExtension`, `SnippetExtension`, `ProjectExtension`, `FileOpenExtension`, `SettingsExtension`, `LanguageExtension`.
- IDE service interfaces plugins **call** (via `ServiceRegistry.get(X::class.java)`): `IdeProjectService`, `IdeEditorService`, `IdeFileService`, `IdeEnvironmentService`, `IdeArchiveService`, `IdeBuildService`, `IdeLogService`, `IdeUIService`, `IdeEditorTabService`, `IdeTooltipService`, `IdeThemeService`, `IdeFeatureFlagService` (the overall experiments switch only - see [EXPERIMENTS.md](../EXPERIMENTS.md#plugins)), `IdeCommandService`, `IdeTerminalService`, `IdeTemplateService`, `IdeSnippetService`, `IdeSidebarService`, `DebuggerEndpointService` (with `DebuggerEndpoint`, the value type it returns: one app's SQLite debugger port and token).
- IDE service interfaces plugins **call** (via `ServiceRegistry.get(X::class.java)`): `IdeProjectService`, `IdeEditorService`, `IdeFileService`, `IdeEnvironmentService`, `IdeArchiveService`, `IdeBuildService`, `IdeLogService`, `IdeUIService`, `IdeEditorTabService`, `IdeTooltipService`, `IdeThemeService`, `IdeFeatureFlagService` (the overall experiments switch only - see [EXPERIMENTS.md](../EXPERIMENTS.md#plugins)), `IdeCommandService`, `IdeTerminalService`, `IdeTemplateService`, `IdeSnippetService`, `IdeSidebarService`, `DebuggerEndpointService` (with `DebuggerEndpoint`, the value type it returns: one app's SQLite debugger port and token), `SqlTemplateService` (with `SqlTemplateFunction`, `SqlTemplateException` and `RoomSchema`: renders the project's SQL templates for the SQLite debugger's `.read`).
- Cross-plugin service interfaces, where **one plugin implements what another calls** (via `SharedServices`): `LlmInferenceService` — implemented by ai-core, called by every AI plugin — together with the types nested in it that a *backend* plugin implements (`LlmBackend`, `HistoryCapableBackend`, `ToolCallingBackend`, `CancellableBackend`, `ConfigurableBackend`, `EmbeddingBackend`) and the value types either side constructs (`ChatMessage`, `LlmConfig`, `LlmResponse`, `SystemPromptRequest`, `ToolDefinition`, `ToolCallRequest`). Also `ToolSourceRegistry` — implemented by ai-core, called by any plugin contributing tools to the agent — with `ToolSource` and `ToolSpec`, which a *contributing* plugin implements, `ToolInvocation`, which ai-core constructs and passes to `ToolSource.invoke`, and `ToolOutcome`, which the source returns.
- Utility classes plugins **instantiate**: `KeystoreSecretStore` (AES/GCM over the Android Keystore, alias supplied by the caller); the AI prompt config engine in `ai.prompt` (`PromptTemplateEngine`, `PromptConfigLoader`, `PromptConfigStore`, `PromptConfigDocument`, `PromptConfigObject`, `AssetPromptConfigSource`), generic over a plugin's own config type through `PromptConfigParser` and `PromptConfigProvider`, which a plugin implements; and the settings-pane helpers in `ai.ui` (`SecretRevealController` with `RevealToggle`, `applyPaneStyling` with `PaneStyle`, `ButtonColors` and `FieldColors`). Host-side implementations rather than interfaces, so plugins share one copy in the process instead of compiling their own.
- Data classes plugins **construct** (e.g. `MenuItem`, `TabItem`, `EditorTabItem`, `NavigationItem`, `ToolbarAction`, `FabAction`, `PluginBuildAction`, `SnippetContribution`, `PluginTooltipEntry`, `PluginSettingsEntry`, `LanguageDefinition`, `TreeSitterGrammar`, `LanguageServerDefinition`).
Expand Down
29 changes: 29 additions & 0 deletions plugin-api/api/plugin-api.api
Original file line number Diff line number Diff line change
Expand Up @@ -2421,6 +2421,19 @@ public final class com/itsaky/androidide/plugins/services/QuickBuildUnavailableR
public static fun values ()[Lcom/itsaky/androidide/plugins/services/QuickBuildUnavailableReason;
}

public final class com/itsaky/androidide/plugins/services/RoomSchema {
public fun <init> (Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;Ljava/util/List;Ljava/util/List;)V
public fun equals (Ljava/lang/Object;)Z
public fun getClassName ()Ljava/lang/String;
public fun getEntities ()Ljava/util/List;
public fun getIdentityHash ()Ljava/lang/String;
public fun getPath ()Ljava/lang/String;
public fun getVersion ()I
public fun getViews ()Ljava/util/List;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class com/itsaky/androidide/plugins/services/SelectionRange {
public fun <init> (IIII)V
public final fun component1 ()I
Expand All @@ -2446,6 +2459,22 @@ public final class com/itsaky/androidide/plugins/services/SharedServices {
public final fun unregister (Ljava/lang/Class;)V
}

public class com/itsaky/androidide/plugins/services/SqlTemplateException : java/lang/Exception {
public fun <init> (Ljava/lang/String;Ljava/lang/Throwable;)V
}

public abstract interface class com/itsaky/androidide/plugins/services/SqlTemplateFunction {
public abstract fun call (Ljava/util/List;)Ljava/lang/Object;
}

public abstract interface class com/itsaky/androidide/plugins/services/SqlTemplateService {
public static final field CONTRACT_VERSION I
public static final field MAX_TIMEOUT_MILLIS J
public abstract fun getRoomSchemas ()Ljava/util/List;
public abstract fun listTemplates ()Ljava/util/List;
public abstract fun render (Ljava/lang/String;Ljava/util/Map;Ljava/util/Map;J)Ljava/lang/String;
}

public abstract class com/itsaky/androidide/plugins/services/TerminalCommandResult {
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
package com.itsaky.androidide.plugins.services;

import androidx.annotation.NonNull;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
* One schema file Room exported into the open project ({@code exportSchema} on): {@code <schemaLocation>/<class>/<version>.json}. Immutable.
*
* <p>
* The entities and views keep Room's own JSON keys, so a template reads them as Room writes them: an entity has {@code tableName}, {@code createSql} (with {@code ${TABLE_NAME}} for the table name), {@code fields} (each with {@code fieldPath}, {@code columnName}, {@code affinity}, {@code notNull}), {@code primaryKey} ({@code autoGenerate}, {@code columnNames}), {@code indices} and {@code foreignKeys}; a view has {@code viewName} and {@code createSql}. Room leaves out {@code indices}, {@code foreignKeys} and {@code views} when they are empty; here they are always present, as empty lists. JSON numbers are {@link Long} or {@link Double}, objects {@link Map} and arrays {@link List}, none of them modifiable.
*/
public final class RoomSchema {

private final String className;
private final int version;
private final String identityHash;
private final String path;
private final List<Map<String, Object>> entities;
private final List<Map<String, Object>> views;

/**
* Creates a schema. The lists are kept as given, so pass unmodifiable ones.
*
* @param className
* the database class, from the folder name (Room does not write it into the JSON)
* @param version
* {@code database.version}
* @param identityHash
* {@code database.identityHash}
* @param path
* the file, relative to the project root, with {@code /} separators
* @param entities
* {@code database.entities}
* @param views
* {@code database.views}, empty when the file has none
*/
public RoomSchema(@NonNull String className, int version, @NonNull String identityHash, @NonNull String path, @NonNull List<Map<String, Object>> entities, @NonNull List<Map<String, Object>> views) {
this.className = Objects.requireNonNull(className, "className");
this.version = version;
this.identityHash = Objects.requireNonNull(identityHash, "identityHash");
this.path = Objects.requireNonNull(path, "path");
this.entities = Collections.unmodifiableList(Objects.requireNonNull(entities, "entities"));
this.views = Collections.unmodifiableList(Objects.requireNonNull(views, "views"));
}

@Override
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (!(other instanceof RoomSchema)) {
return false;
}
final RoomSchema that = (RoomSchema) other;
return version == that.version && className.equals(that.className) && identityHash.equals(that.identityHash) && path.equals(that.path) && entities.equals(that.entities) && views.equals(that.views);
}

/**
* Gets the database class, such as {@code com.example.AppDatabase}.
*
* @return the class name, from the folder that holds the file (never null)
*/
@NonNull
public String getClassName() {
return className;
}

/**
* Gets the entities.
*
* @return {@code database.entities}, each with {@code indices} and {@code foreignKeys} present (never null)
*/
@NonNull
public List<Map<String, Object>> getEntities() {
return entities;
}

/**
* Gets the identity hash Room keeps in {@code room_master_table} of a database created with this schema.
*
* @return {@code database.identityHash} (never null)
*/
@NonNull
public String getIdentityHash() {
return identityHash;
}

/**
* Gets where the file is.
*
* @return the path relative to the project root, with {@code /} separators (never null)
*/
@NonNull
public String getPath() {
return path;
}

/**
* Gets the schema version, which a database created with this schema has as its {@code user_version}.
*
* @return {@code database.version}
*/
public int getVersion() {
return version;
}

/**
* Gets the views.
*
* @return {@code database.views}, empty when the file has none (never null)
*/
@NonNull
public List<Map<String, Object>> getViews() {
return views;
}

@Override
public int hashCode() {
return Objects.hash(className, version, identityHash, path);
}

@Override
public String toString() {
return "RoomSchema{" + className + " v" + version + ", " + path + "}";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.itsaky.androidide.plugins.services;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

/**
* A SQL template could not be rendered: the file could not be read, the template has a syntax error or uses a variable it was not given, a {@link SqlTemplateFunction} failed, a filter was given a value it cannot quote, or the time limit passed. The message says which, with the template's line where Pebble gives one, and is meant to be shown to the user or the agent as it is.
*/
public class SqlTemplateException extends Exception {

private static final long serialVersionUID = 1L;

/**
* Creates the exception.
*
* @param message
* what went wrong (must not be null)
* @param cause
* the underlying failure, or null
*/
public SqlTemplateException(@NonNull String message, @Nullable Throwable cause) {
super(message, cause);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.itsaky.androidide.plugins.services;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.util.List;

/**
* A function a SQL template calls, such as {@code row_count(db, "users")}, passed to {@link SqlTemplateService#render}. It runs only when the template calls it, on the render's thread, once per call.
*/
@FunctionalInterface
public interface SqlTemplateFunction {

/**
* Runs the function.
*
* @param args
* the arguments in the order the template wrote them, as Pebble evaluated them (never null; empty when there are none). A literal in the template is a {@link Long}, a {@link Double}, a {@link String} or a {@link Boolean}, or null. A value that comes from a variable or another function keeps the type the caller gave it, so a number can be any {@link Number} (an {@link Integer} or a {@link java.math.BigDecimal}, say) and a {@link RoomSchema} stays a {@link RoomSchema}. A {@link java.util.Map} or {@link List} arrives as a read-only view, not the caller's own object, and its entries follow these same rules
* @return the value the template sees: null, a {@link String}, a {@link Number}, a {@link Boolean}, a {@link java.util.Map} or a {@link List}
* @throws Exception
* to stop the render: {@link SqlTemplateService#render} then throws {@link SqlTemplateException} with this function's name and the exception's message. Stop when the thread is interrupted: the render's time limit interrupts it
*/
@Nullable
Object call(@NonNull List<Object> args) throws Exception;
}
Loading
Loading