Commit d77d3cf
feat(sqlite3): translate dot-commands (.tables, .schema, .mode, .read, ...)
Real sqlite3 ships a family of dot-commands that are a feature of the CLI,
not the library. sql.js doesn't implement them, so agent scripts pasted
verbatim from a real sqlite3 session hit `near ".": syntax error` on the
first dot-command (.tables, .schema, .mode csv, .read seed.sql, ...).
Add a host-side preprocessor (commands/sqlite3/dot-commands.ts) that runs
before SQL reaches the worker. The scanner is char-level with state for
SQL string literals ('...', "...", including the doubled-quote escapes)
and comments (-- ..., /* ... */); a dot-command is recognized only at a
boundary (start-of-input, after `;`, or after `\n`) and only outside
strings/comments — `'a\n.tables'` round-trips intact, and
`.headers on; .mode csv; CREATE TABLE...` is three tokens on one line.
Each recognized dot-command resolves to one of:
- SQL replacement — .tables/.schema/.indexes/.databases/.help translate
to sqlite_master/PRAGMA queries (with shell-glob → SQL-LIKE conversion).
- Formatter mutation — .headers, .mode, .separator, .nullvalue adjust
output state for downstream SQL; bad args surface real-sqlite3-shaped
errors (e.g. "Error: unknown mode: parquet"). Last write wins.
- .read FILE — recursive scan of the included file, sharing formatter
state, capped at MAX_READ_DEPTH to prevent loops.
- .quit / .exit — terminate preprocessing; subsequent input is dropped.
- Silent drop — .echo, .timer, .changes, .bail, .show, .eqp, .width,
.prompt, .print, .explain are recognized and discarded.
- Not-implemented family — .dump, .save, .backup, .import, .clone,
.restore, .open, .output, .shell, .system, .cd, .load, .iotrace,
.log, .excel translate to `SELECT 'Error: ...' AS error` so the
message rides in stdout in script-order without aborting SQL.
- Passthrough — unknown dot-commands are left verbatim so sql.js
produces its native syntax error.
Pairs with two new CLI flags:
- `-init FILENAME` — read SQL from FILENAME before main SQL.
- `-batch` — no-op (just-bash is always non-interactive).
Dot-command errors are routed in-band to stdout alongside SQL errors when
-bail is unset (matches real sqlite3's single-channel reporting); with
-bail they go to stderr with exit 1.
Tests: 247 sqlite3 tests pass against the existing worker (no worker
changes needed — preprocessor runs entirely host-side). New test files:
- sqlite3.dot-commands.test.ts: comprehensive preprocessor coverage
- sqlite3.invocation-shapes.test.ts: pinned agent invocation patterns
- sqlite3.flags.test.ts: -init / -cmd / -batch flag behavior
- sqlite3.sql-features.test.ts: generic SQL features through the pipeline
Docs: packages/just-bash/docs/sqlite3-invocation-shapes.md catalogues the
canonical CLI invocation shapes agents use.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 1369b77 commit d77d3cf
8 files changed
Lines changed: 1969 additions & 9 deletions
File tree
- .changeset
- packages/just-bash
- docs
- src/commands/sqlite3
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
0 commit comments