Commit Graph

2 Commits

Author SHA1 Message Date
opencode-agent d0f31023bd sqlite: render results as Markdown tables for the TUI
OpenCode's tool content schema (Tool.Content = TextContent | FileContent)
gives a server plugin no metadata channel — the TUI's only view of tool
output is the content string. So: format the result as a Markdown
table, which the TUI's built-in markdown renderer already displays as
a real table.

- sqlite_query gains format = 'table' (default) | 'json' | 'both'.
  'table' is the new default and renders a header line, a separator
  row, and one row per record with pipes/newlines/backslashes escaped.
  'json' keeps the old behaviour for callers that need raw rows.
- Every tool that runs SQL echoes 'SQL: <stmt>  params: [...]' as the
  first line of its output, so the user sees what was executed
  including the bound values.
- Every tool that runs a statement pushes context.progress() at start
  and end, which surfaces in the TUI status bar.
- cellToMarkdown caps each cell at 80 chars to keep wide BLOBs from
  blowing up the TUI column width.

End-to-end verified via Code Mode (no model in the loop):
- format=table renders correctly with edge cases (| in text, \n in
  text, \ in text)
- format=both appends the JSON view below the table
- exec echoes the bound params as a JSON array
- write+read round-trip persists (UPDATE → SELECT sees the new value)
2026-10-08 17:36:44 +08:00
opencode-agent 9aef200ac9 Add sqlite plugin: open/query/exec/script against .db files
Adds a single-file V2 plugin that exposes eight tools under the
`sqlite` namespace (open, close, list, query, exec, script, tables,
schema) so a model can read and write SQLite databases from a session.

- OpenCode discovers it automatically from ~/.config/opencode/plugins/.
- New runtime dependency: better-sqlite3 (installed in this repo's
  node_modules so the host's module resolution picks it up).
- README documents install, copy-to-another-machine, options, and
  troubleshooting; SETUP.md is a copy-paste checklist.
- Schema/options were trimmed down while authoring: the initial draft
  registered a no-op SQLite function on every open as a 'future hook';
  removed, it was dead code.
2026-10-08 17:03:48 +08:00