Repository navigation
ADFA-7302 | AI-Agent-MCP: read_sql_template, .read with a Pebble SQL template - #184
davidschachterADFA wants to merge 16 commits into
Conversation
A tool of this plugin's own on each SQLite debugger entry whose server has get_template_variables. It: - fetches the variables from the app; - adds the project's Room schemas and, per database, schema_matches and room_schema; - has Code on the Go render the template (SqlTemplateService); - returns the SQL, unrun. The template functions are tool calls to the same app, made only when called, on the call's session and handle: row_count (count(*)), distinct_values, sample_rows, integrity, suggest_indexes and lint_foreign_keys. Without a template it lists the project's *.sql.peb files. It starts switched on, last of the entry's five default tools, so in compact mode it is the one AI-Core drops. The help page has an example template, checked by rendering it with the host's renderer. Version 3.0.0 (MAJOR): it needs the plugin API of Code on the Go 26.48, whose libs/plugin-api.jar must be refreshed from CodeOnTheGo sqlite-debugger/ADFA-7302 before this builds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba
…gger/ADFA-7302 Brings in the #178 review fixes (the writes switch save, the hint KDoc). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
davidschachterADFA
left a comment
There was a problem hiding this comment.
Review of #184 at 0ac56909f5. Stacked on addons #178 (P2-5); host side is CodeOnTheGo #2329.
IMPORTANT
- plugins/AI-Agent-MCP/src/main/kotlin/com/itsaky/androidide/plugins/aiagentmcp/debugger/SqlTemplateRead.kt:178 - sample_rows/distinct_values accept limits up to 1000 but the query call sends no max_rows, so the server returns 100 rows
MINOR
- plugins/AI-Agent-MCP/build.gradle.kts:19 - versionName 3.0.0 is a MAJOR bump for a backwards-compatible feature
- plugins/AI-Agent-MCP/src/main/kotlin/com/itsaky/androidide/plugins/aiagentmcp/debugger/SqlTemplateRead.kt:204 - a function's tool failure is flattened to a message by the host, so the endpoint retry and the app-not-answering message are bypassed
NITPICK - 1 inline, not listed
Verdict: COMMENT. This PR is authored by the account posting the review, and GitHub refuses APPROVE and REQUEST_CHANGES on your own PR. Severity rules: CodeOnTheGo REVIEW.md and CLAUDE.md (a ticket moves to QA with no outstanding critical, high or medium findings); addons has no written rule, so the default applied.
Generated by Claude Code
…le limit Both accept a limit up to 1000, but their query call sent no max_rows, so the server returned its default of 100 rows and set has_more, which they ignored: sample_rows(db, "t", 500) handed the template 100 rows with no error, and a value the server cut (truncated_cells) was spliced as if whole (review of #184, ADFA-7131 comment 41657). They now send max_rows equal to the limit, and fail, with the reason, when has_more or truncated_cells is set. row_count and the tools that return their whole result are unchanged. Before the fix the new tests find max_rows absent ([null, null, null]) and a cut result rendered. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
… caller When a function's tool call threw (the app relaunched or went to the background after the variables were fetched: ConnectException, a 401, a timeout, or a cancel), the host passed on only its message as a SqlTemplateException, so the read failed with "row_count(...) failed: Read timed out" instead of being retried on the app's new address by EndpointRetry and worded by McpErrorFormatter, as the variables call's own failure is (review of #184, ADFA-7131 comment 41657). The first exception a function's call throws is now kept and rethrown from run() when the render fails. A failed result, the server answering with an error, still fails the read with the server's message. Before the fix the new test gets a failed result where it expects the ConnectException. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
read_sql_template is a backwards-compatible feature and min_ide_version stays at 26.48, so this is a MINOR bump from 2.1.0 (CLAUDE.md); versionCode 5 is unchanged (review of #184, ADFA-7131 comment 41657; David). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
read_sql_template made CORE_TOOLS five, but the test was still named for four (review of #184, ADFA-7131 comment 41657), and so were the CORE_TOOLS KDoc's budget reasoning, McpServer's KDoc, the plugin description, the help page, the gallery page, addon.json and the README. They now say five (two apps use 10 of AI-Core's 12 tools). AutomaticServersTest's "four core tools" is left: its server has no get_template_variables, so four is right there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
… any column sample_rows is SELECT *, and since 149be65 it fails rather than hand the template a value the server cut (text over 4096 bytes, a BLOB over 1024), so one long value in any column fails the whole template. The tool description, the help page and the README now say so (follow-up from the re-check, ADFA-7131 comment 41663; David). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
|
@hal-eisen-adfa A new commit since you were asked to review: d846124, docs only, a follow-up from the cloud agent's re-check (ADFA-7131 comment 41663). The tool description, the help page and the README now say that |
|
@hal-eisen-adfa This PR is ready for review now (David, 2026-11-28). ADFA-7302's device check passed on the Note 20 (ADFA-7302 comment 41698), and the description now records it. The Code on the Go side, CodeOnTheGo #2329, is ready too. Head: d846124. Its CI still fails to compile until #2329 is on |
…rs, check limits The review of #184 found several ways a read could look complete or blame the wrong party. - A database that failed or was skipped at the time limit was missing from databases with no sign: the returned SQL now starts with one "-- not read: <database>: <reason>" line per such database, and a "-- truncated" line when the server cut a list. database_errors and truncated are variables. A call that names a database which was not read fails with the server's reason. - distinct_values asks for one row more than its limit and fails when it comes back (its limit stops at 999), instead of silently returning the first rows. column may be a column map. - A limit that is not a whole number fails; an absent or null one is the default. - A failure of Code on the Go's own service (permission, cancellation, state) is a failed result, not an exception that marks the debugger degraded. A listing, a missing SqlTemplateService (also NoClassDefFoundError) and such a failure no longer record the app as available or degraded. - A failed function's message reaches the caller whatever wording the host gives it. - Tests for each, and for the database argument, a failed or non-JSON variables call, argument errors, an IllegalArgumentException render, and McpToolSource dispatch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
…as, and what read_sql_template returns The README, both help pages and the manifest comment said the plugin cannot read the project. read_sql_template reads the project's *.sql.peb templates and Room schemas through Code on the Go's SqlTemplateService, under debugger.endpoints; they now say so, and that the plugin has no filesystem or shell access of its own. They also document database_errors and truncated and the comment lines, that sample_rows returns at most its limit while distinct_values fails past its limit, that schema_matches ignores the Room class, and that values are the server's JSON (large integers as strings, BLOBs as maps). The help example checks database_errors. The stale tool counts (the server's 13 read-only tools; six tools per app with writes on) are fixed in the README and ReadOnlyTrust. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
… read where no database was read fails The help example printed each database_errors entry's raw error into a comment, so a multi-line error left its later lines as live SQL, and it repeated the "-- not read" lines the plugin already adds. It now only counts them, and the help text says the plugin adds those lines. With no database named and none read, db did not exist and a template failed on Pebble's strict-variables error without the reason. The read now fails with the server's reasons, one line each. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
039e6b7 left a colon that no longer introduced what followed it. The paragraph now says the SQL starts with the -- not read and -- truncated lines first, then that a template should not print an error itself. Text only. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
|
@hal-eisen-adfa Four new commits since you were asked to review (David, 2026-11-28), answering an independent review of this PR: ba9ece9, a8037e1, 039e6b7 and 6c58c17. The description's Commits section lists what each does. In short:
392 tests, |
The gallery and help pages said project content reaches a server only in a tool argument the model writes and you approve. read_sql_template's template functions also send text from the template, such as a table name or the SQL suggest_indexes analyses, to the app's SQLite debugger on the device, under the one approval of read_sql_template. Both pages now say so. Found by the cloud session's check of 2026-11-29 (ADFA-7131 comment 41718). Text only. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
…eds, one-line errors, a helpful error when db is not set AI Core keeps only the first 200 characters of a tool description, and the description began with background. It now begins with what the tool does, that nothing is run, how to run the SQL, and that -- not read and -- truncated mean incomplete; a test holds those words in the first 200 characters. The "was not read" error put the server's multi-line reason in as it was; it is now one line like the other errors. distinct_values reported a value the server cut when the extra row held one, though the real reason is more distinct values than the limit. The limit is now reported first. A template that reads db on an app with two or more databases and no database argument failed with Pebble's "Root attribute [db] does not exist". It now says db is set only when database is given or the app has one database, lists the databases, and asks to call again with database set. Templates that never read db, and other unknown variables, behave as before. README and help say so. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
|
@hal-eisen-adfa Two more commits since my last note, from a check by David's cloud session (ADFA-7131 comments 41718 and 41719): 468ce45 and 2aee424.
397 tests, |
…d Code on the Go 26.49 #178 merged #166 at 265fd64, which merged main at 7c7e333 (main's plugin-api.jar, which has the SQLite debugger API from stage) and raised plugin.min_ide_version from 26.48 to 26.49, because 26.48 was released before CodeOnTheGo#2261 merged. No conflicts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
…th SqlTemplateService The README said read_sql_template needs Code on the Go 26.48 or later. It needs the first release with SqlTemplateService (CodeOnTheGo#2329, not merged yet). On an older Code on the Go, down to the plugin's minimum (now 26.49), the tool is listed and each call answers that this version cannot render SQL templates (mcp_error_templates_unavailable). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
|
@hal-eisen-adfa two commits:
At e6811a8, against a |
…nd which database it read On a phone, Claude Haiku rendered a template successfully with no database, then called again with database set to the app's package or notes.db, which failed with "Unknown database", and then asked for list_databases. Nothing told the model that database is optional or which database the first call had read. F28: the database parameter's description now says it is optional: omit it to use the app's only database, give a list_databases path only when the app has more than one, and it is a database file path, not the app or package. It stays out of required. F29: AI Core shows only the first 200 characters of a tool description, and the default sat after them. The start of the description now says database is optional and defaults to the app's only one, keeping what the test of those 200 characters already required (it now requires "database" and "optional" too). The rest of the guidance is kept, including that an incomplete result must not be trusted. F30: every successful result starts with "-- database: <path> (the app's only database)" when no database was given, or "-- database: <path> (given)" when one was, ahead of the -- not read and -- truncated lines. With two or more databases and none given no database is selected, so there is no such line. Tests: the exact-output tests carry the new line; new tests cover the schema text and both forms of the line. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
|
Hal, one new commit on #184 (e6811a8..1c44692), from the Note 20 run of 2026-12-01: after every successful
|
ADFA-7302
Phase 2, P2-7 of the SQLite debugger (ADFA-7131), client side: AI-Agent-MCP reads a project's Pebble SQL templates through Code on the Go. Stacked on #178 (P2-5). The Code on the Go side is CodeOnTheGo #2329 (stacked on #2323), which adds
get_template_variablesand the plugin APISqlTemplateService.What it adds (
plugins/AI-Agent-MCP, 2.2.0, versionCode 5)read_sql_template, the plugin's own tool, appears on each debugger entry whose server listsget_template_variables.room_schemas;schema_matchesandroom_schema.schema_matchesis true, false, or null when no schema of that version is exported.db: the named database, or the only one.SqlTemplateServiceand returns the SQL without running it. The model runs it one statement at a time withqueryorexecute, binding user values asargs.template, it lists the project's*.sql.pebfiles.row_count(count(*)),distinct_values,sample_rows,integrity,suggest_indexesandlint_foreign_keys. A function runs only when the template calls it.distinct_valuesasks for one row more than its limit (at most 999) and fails when the column has more distinct values than that.sample_rowsreturns at most its limit (at most 1000). Both fail on a value the server cut. A function's call that throws fails the read with that exception, as the variables call does, so it is retried on the app's new address and worded the same way.assets/docs/index.html) has an example template. It was rendered with the real renderer before the review fixes; its newdatabase_errorsline hasn't been rendered on a device yet.-- not read: <name>: <reason>line for it, and with-- truncated: ...when a list stopped at the server's 20,000 rows. A named database that wasn't read, or a read where no database was read, fails with the server's reasons.Decisions (David; ADFA-7302's description):
read_sql_templateis on by default, fifth per app. Two apps now use 10 of AI-Core's 12 tools, and in compact mode it's the one dropped.debugger.endpointsis reused, so the plugin declares no new permission.min_ide_versionis 26.49, from ADFA-7139: AI-Agent-MCP connects to the SQLite debugger automatically #166 through ADFA-7300: AI-Agent-MCP switch to let the Agent change app databases #178 (merged in as aa2b62c): 26.48 shipped without the SQLite debugger API.read_sql_templateitself needs the first release withSqlTemplateService(#2329, not merged yet). On an older Code on the Go, each call answers that this version cannot render SQL templates; the README says so (e6811a8).Commits
62d2d28, from the cloud session.
0ac5690 merges ADFA-7300: AI-Agent-MCP switch to let the Agent change app databases #178 at 3ef6bac, its 2026-11-26 review fixes, with no conflicts.
For the 2026-11-27 review (ADFA-7131 comment 41657; David approved fixing all four):
distinct_valuesandsample_rowssendmax_rows= their limit, and fail onhas_moreortruncated_cells(before, the server returned its default 100 rows and the plugin ignoredhas_more).EndpointRetryandMcpErrorFormatterhandle it, instead of a flattened message.sample_rowsreads every column, so one value the server cuts (text over 4,096 bytes, a BLOB over 1,024) in any column fails the template.McpServer's KDoc, the plugin description, the help page, the gallery page,addon.jsonand the README.For the 2026-11-28 independent review (13 findings, 3 IMPORTANT; David approved fixing them, and documenting three), each re-checked:
truncatedlines above;distinct_valuesfails past its limit; Code on the Go's own errors (listing, schemas, render, a plugin disabled mid-call) come back as failed results that don't mark the app degraded; listing templates no longer marks the app available; a Code on the Go withoutSqlTemplateServicegets the "templates unavailable" text;distinct_valuestakes a column map; a limit must be a whole number in range.*.sql.pebtemplates and reads the Room schemas forread_sql_template, underdebugger.endpoints, and the plugin has no filesystem or shell access of its own. Also documented:database_errors,truncated, thatschema_matchesmatches by version only (the server gives no class name), and the lossy JSON values (integers past 2^53 as strings, BLOBs as maps). Stale tool counts are fixed (the server has 13 read-only tools).From the cloud session's check of these commits (ADFA-7131 comments 41718 and 41719):
read_sql_templatecall, whose template functions then send text from the template (a table name, or the SQLsuggest_indexesanalyses) to the app's SQLite debugger on the device without asking again.distinct_valuesreports "more than the limit" before a cut value in its extra row; and a template that readsdbon an app with two or more databases, with nodatabasegiven, gets an error naming the databases and saying to call again with one (David's decision, 41719). A template that doesn't readdbrenders as before, and no default is picked.2026-11-30, at David's request: aa2b62c merges ADFA-7300: AI-Agent-MCP switch to let the Agent change app databases #178 at c5caa68 (main and 26.49, from ADFA-7139: AI-Agent-MCP connects to the SQLite debugger automatically #166), with no conflicts; this PR's own diff is unchanged (same patch-id). e6811a8: the README's requirement line above.
1c44692 (2026-12-01, after the Note 20 run p31):
read_sql_template'sdatabaseargument says it is optional (omit it for the app's only database; a database file path fromlist_databasesonly when the app has several; not the app or its package), the description's first 200 characters, which are all AI Core shows the model, say so too, and every successful result starts with-- database: <path> (the app's only database)or(given). In p31 the model called again with the app's package ornotes.dbafter every successful render, because nothing saiddatabasewas optional or which database had been read (ADFA-7302 41812). With several databases and none given, no database is selected and no such line is written.Tests
plugin-api.jarbuilt from #2329 bc03f42e6 (its API unchanged since d2d7d0216):testDebugUnitTest(399 tests, 2 new and one extended),assemblePluginandaddons checkpass. With onlySqlTemplateRead.ktreverted, 7 tests fail: the two new ones, the extended first-200-characters test and four exact-output tests.plugin-api.jarbuilt from #2329 (its API matches d2d7d0216; later changes are Javadoc only):testDebugUnitTest(397 tests),assemblePluginandaddons checkpass; the.cgprecords 26.49 to 26.99.plugin-api.jarbuilt from #2329 c1df2304e:testDebugUnitTest(397 tests),assemblePluginandaddons checkpass. With 2aee424's change toSqlTemplateRead.ktreverted, its four new tests fail. 468ce45 is page text only;addons checkpasses.plugin-api.jarbuilt from #2329 c1df2304e:testDebugUnitTest(392 tests, 16 new, includingReadSqlTemplateDispatchTestforMcpToolSource),assemblePluginandaddons checkpass. With the fixes reverted, 11 of the 25SqlTemplateReadand dispatch tests fail, and 039e6b7's test fails on its own. 6c58c17 is help text only;addons checkpasses.plugin-api.jarbuilt from #2329 c1df2304e:testDebugUnitTest(376 tests),assemblePluginandaddons checkpass.plugin-api.jarbuilt from #2329's head 0ff47e417, copied intolibs/for the build only:testDebugUnitTest(376 tests),assemblePluginandaddons checkpass. Revert proofs: before the fixes, the new tests findmax_rowsabsent, a cut result rendered, and a failed result where theConnectExceptionwas expected.plugin-api.jarbuilt from #2329's head 5ad33e91c, copied intolibs/for the build only:testDebugUnitTest(373 tests),assemblePluginandaddons checkpass.plugin-api.jarbuilt from #2329's head 0edd649c3 and copied intolibs/for the build only (not committed):testDebugUnitTest(372 tests),assemblePluginandaddons checkpass. Against the committedlibs/,compileDebugKotlinfails on the missingSqlTemplateServicetypes, as expected.SqlTemplateReadTesttests andaddons check.Device check, after the review fixes (2026-12-01, p31; ADFA-7302 41812): with C-d-1130-0617 (#2262 bee421cc8 + #2329 d2d7d0216), this PR at e6811a8 and AI Core from #188, on Claude haiku: the example rendered
-- notes.db: Room schema matcheswith the expected lines, andRoom schema differs or is not exportedwith the identity hash changed; each time the model then called again with a wrongdatabase(fixed by 1c44692, not yet rechecked on a device).Device check (ADFA-7302's description), before the 2026-11-28 review fixes: on the Galaxy Note 20, with Code on the Go built from #2262 and #2329, AI-Agent-MCP 2.2.0 and AI Core 3.7.2 from addons #188 (ADFA-7340), in a Room app with
exportSchemaon:-- notes.db: Room schema matches, one row count per table, and theordersline with:id.schema_matchesboth ways: with the project's schema identity hash changed, the example rendersRoom schema differs or is not exported, and a template readingschema_matchesshowstrueon the unchanged project.sample_rowsrendered once. The model then called again with the app's package name asdatabase, which failed, and AI Core's stock failure message hid its answer (ADFA-7318).Not done here:
libs/is not refreshed in this PR. PR CI builds against the committedlibs/, which lackSqlTemplateService, so this PR's CI fails to compile until #2329 is on CodeOnTheGostageand Update libs from CodeOnTheGo has run. Publishing also needs the API in aplugin-api-latestrelease (plugins/README.md).Merging: after #178, and after a Code on the Go release with #2329 and the
libs/refresh.🤖 Generated with Claude Code
https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn