@pvidaal07/heydb 0.0.0-stage → 2.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/LICENSE +21 -0
  3. package/README.md +153 -2
  4. package/extensions/commands.ts +732 -0
  5. package/extensions/context.ts +37 -0
  6. package/extensions/deps.ts +32 -0
  7. package/extensions/heydb.ts +20 -0
  8. package/extensions/secret-input.ts +120 -0
  9. package/extensions/tools.ts +402 -0
  10. package/lib/about.ts +7 -0
  11. package/lib/config/operations.ts +75 -0
  12. package/lib/config/store.ts +73 -0
  13. package/lib/config/types.ts +37 -0
  14. package/lib/config/validate.ts +136 -0
  15. package/lib/engines/index.ts +66 -0
  16. package/lib/engines/mysql/catalog.ts +371 -0
  17. package/lib/engines/mysql/introspect.ts +186 -0
  18. package/lib/engines/postgres/catalog.ts +390 -0
  19. package/lib/engines/postgres/introspect.ts +240 -0
  20. package/lib/knowledge/operations.ts +223 -0
  21. package/lib/knowledge/query.ts +129 -0
  22. package/lib/knowledge/types.ts +64 -0
  23. package/lib/knowledge/validate.ts +151 -0
  24. package/lib/model/diff.ts +218 -0
  25. package/lib/model/hash.ts +88 -0
  26. package/lib/model/names.ts +141 -0
  27. package/lib/model/order.ts +47 -0
  28. package/lib/model/references.ts +251 -0
  29. package/lib/model/snapshot.ts +128 -0
  30. package/lib/model/stats.ts +97 -0
  31. package/lib/model/validate.ts +240 -0
  32. package/lib/render/markdown.ts +508 -0
  33. package/lib/search.ts +530 -0
  34. package/lib/secrets.ts +149 -0
  35. package/lib/store/envfile.ts +124 -0
  36. package/lib/store/files.ts +57 -0
  37. package/lib/store/guards.ts +68 -0
  38. package/lib/store/knowledge.ts +139 -0
  39. package/lib/store/project.ts +28 -0
  40. package/lib/store/snapshots.ts +143 -0
  41. package/lib/usecases/author.ts +51 -0
  42. package/lib/usecases/code-scan.ts +435 -0
  43. package/lib/usecases/init.ts +111 -0
  44. package/lib/usecases/knowledge.ts +214 -0
  45. package/lib/usecases/project.ts +377 -0
  46. package/lib/usecases/resolve.ts +186 -0
  47. package/lib/usecases/sharing.ts +83 -0
  48. package/lib/usecases/status.ts +37 -0
  49. package/lib/usecases/sync.ts +33 -0
  50. package/package.json +69 -5
  51. package/skills/heydb/SKILL.md +67 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,19 @@
1
+ # Changelog
2
+
3
+ ## [2.0.0-beta.1]
4
+
5
+ - Documentation, the bundled skill and tests use generic examples only.
6
+ - Releases are published from GitHub Actions through npm trusted publishing.
7
+
8
+ ## [2.0.0-beta.0]
9
+
10
+ heydb is rebuilt from scratch in TypeScript as a [Pi](https://pi.dev) package. The Go CLI and MCP server (v1) are archived at tag `v1.3.1`.
11
+
12
+ - Read-only introspection of MySQL, MariaDB and PostgreSQL 14+: tables, views, materialized views, columns, keys, indexes, composite and cross-database foreign keys, triggers, routines and view definitions, with warnings for whatever the user's privileges hide.
13
+ - Snapshot shared as `.heydb/snapshots/<connection>.json.gz`, rewritten only when the structure changes.
14
+ - Notes on the project, databases, tables and columns, and implicit relationships, also across connections, stored in `.heydb/knowledge/` for the team.
15
+ - Drift detection with `/heydb:status`.
16
+ - Agent tools that never connect to the database: `heydb_overview`, `heydb_table`, `heydb_search`, `heydb_annotate`, `heydb_relate`, `heydb_edit_note`, `heydb_forget`.
17
+ - Commands: `/heydb:init`, `/heydb:connect`, `/heydb:password`, `/heydb:connections`, `/heydb:sync`, `/heydb:status`, `/heydb:learn-code`, `/heydb:about`.
18
+ - Learning from the project's code after a sync, including legacy code (Harbour, Delphi, VB…), with notes that cite their source file.
19
+ - Passwords asked in a masked input and kept in `.heydb/.env`, which git always ignores; `config.json` holds references only.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 pvidaal07
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,154 @@
1
- # Temporary Holding Version
1
+ # heydb
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ **Database schema context for AI agents, built for legacy databases.**
4
+
5
+ heydb reads the structure of your MySQL, MariaDB or PostgreSQL database (never its data), keeps a snapshot in your repository, and lets you and your agent write down what tables and columns really mean. Your agent understands the database without ever connecting to it, and your team gets that knowledge with a `git pull`.
6
+
7
+ It is a [Pi](https://pi.dev) package: Pi gets agent tools, slash commands and a skill.
8
+
9
+ > [!NOTE]
10
+ > **v2 is in beta.** The previous Go CLI and MCP server (v1) are archived at tag [`v1.3.1`](https://github.com/pvidaal07/heydb/releases/tag/v1.3.1) and no longer maintained.
11
+
12
+ ## Why
13
+
14
+ On a legacy database the agent guesses. A table called `art` "looks like" artwork and turns out to hold the articles; `estado = 3` means something only the team knows; half the joins have no foreign key. heydb gives the agent the evidence instead of the name:
15
+
16
+ - the structure, read-only and complete, with warnings for anything your privileges hide;
17
+ - who references each table and how those columns are commented (`ref_art` "Artículo" ×12 says more than the name `art`);
18
+ - the notes your team and your agent saved, each with its author and its source.
19
+
20
+ The agent is told to present inferences as inferences and ask before saving them.
21
+
22
+ ## Install
23
+
24
+ ```sh
25
+ pi install npm:@pvidaal07/heydb
26
+ ```
27
+
28
+ npm only accepts the name under its owner's scope (plain `heydb` is too close to an existing package); the package, its commands and tools are still called heydb.
29
+
30
+ From the repository instead (latest commit): `pi install git:github.com/pvidaal07/heydb`.
31
+
32
+ Requires Pi and Node.js 22.19 or later.
33
+
34
+ ## Quick start
35
+
36
+ In Pi, from your project folder:
37
+
38
+ 1. `/heydb:init` creates `.heydb/`.
39
+ 2. `/heydb:connect` asks for a name, engine, host, port, user and databases, and last for the password in a masked input.
40
+ 3. `/heydb:sync` captures the schema and, if the project contains code that queries those tables, offers to let the agent read it and take notes.
41
+
42
+ Then just work: ask your agent about the database. It reads the snapshot with the heydb tools and saves what it learns from you and from the code.
43
+
44
+ ## Supported databases
45
+
46
+ | Engine | Tested in CI | Notes |
47
+ |---|---|---|
48
+ | MySQL | 8.0 | 5.7 used on a schema with about 1,500 tables |
49
+ | MariaDB | 10.6 | 10.2 or later expected |
50
+ | PostgreSQL | 16 | 14 or later expected; one connection reaches one database, choose schemas inside it |
51
+
52
+ Captured: databases and schemas; tables, views and materialized views with their SQL; columns (type, nullability, default, comment, collation, auto-increment or identity, generated); primary keys in key order; indexes; foreign keys, composite and across databases, with `ON DELETE`/`ON UPDATE`; triggers; routine names; approximate row counts. Never row data.
53
+
54
+ Every session is read-only, even for a user with write privileges.
55
+
56
+ ## Commands
57
+
58
+ | Command | What it does |
59
+ |---|---|
60
+ | `/heydb:init` | Create `.heydb/` in the project |
61
+ | `/heydb:connect` | Add a connection; the password goes to `.heydb/.env` |
62
+ | `/heydb:password [connection]` | Change a connection's password |
63
+ | `/heydb:connections [use <name> \| remove <name>]` | List connections, set the default, remove one (its snapshot and notes stay) |
64
+ | `/heydb:sync [connection]` | Capture the schema; the snapshot is rewritten only when the structure changed |
65
+ | `/heydb:status [connection]` | Show whether the live database drifted from the snapshot, and what changed |
66
+ | `/heydb:learn-code [connection] [path]` | Let the agent read the code that queries the tables and note what it shows |
67
+ | `/heydb:about` | Show the version |
68
+
69
+ ## Agent tools
70
+
71
+ None of them connects to the database; they read and write files in `.heydb/`.
72
+
73
+ | Tool | What it does |
74
+ |---|---|
75
+ | `heydb_overview` | Size, comment coverage, name prefixes, most referenced tables, warnings and project notes |
76
+ | `heydb_table` | One table: evidence of meaning first (comment, notes, who references it), then keys, relationships and up to 60 columns, with a column filter |
77
+ | `heydb_search` | Search names, comments, view definitions and notes, ignoring case, accents and plurals; finds tables by what references them, marked as inferred |
78
+ | `heydb_annotate` | Save a note on the project, a database, table or column |
79
+ | `heydb_relate` | Record a join that has no foreign key, also across connections |
80
+ | `heydb_edit_note`, `heydb_forget` | Fix or remove a note or relationship by id |
81
+
82
+ Notes saved by the agent are signed `<your git user.name> (via agent)` and end with their source: `(code: src/Models/Order.php)` or `(told by the user)`.
83
+
84
+ ## Learning from code
85
+
86
+ After a sync, heydb looks for code in the project that uses the synced tables. It walks the folders, including ones git ignores (a reference copy of another repository, for example), and skips `node_modules`, `vendor`, build output, CI folders and lockfiles. It reads modern and legacy languages: PHP, TypeScript, JavaScript, Python, Java, C#, Go, Ruby, SQL, Kotlin, Scala, Harbour/Clipper, Delphi, Visual Basic, COBOL, ABL and RPG.
87
+
88
+ A table only counts in database context: SQL with its statement verb (`SELECT … FROM art`, `UPDATE art … SET`, `INSERT INTO art`), including SQL whose database prefix is built by code (`"FROM " + cDb + ".art"`), or a table declaration (`protected $table = 'art'`, `cTabla := "art"`, `@Table(name = "art")`, `__tablename__`, `DB::table('art')`…). A table called `config` is not matched by every comment that says "config".
89
+
90
+ If it finds such code it asks first, because reading it costs tokens. The agent then notes only what the code makes explicit (valid values, units, joins without a foreign key), stops after about 20 notes and leaves what remains unclear as questions. `/heydb:learn-code acme ../legacy-app` reads code that lives in another folder. The scan stops after 10 seconds or 50 MB on very large codebases.
91
+
92
+ Without such code, notes come from your conversations: tell the agent what a table means and it saves it.
93
+
94
+ ## Several connections
95
+
96
+ A project can have as many connections as it needs: `dev` and `prod`, or one per service. Commands and tools use the default unless you name one (`/heydb:sync prod`). Each connection has its own snapshot and notes.
97
+
98
+ - **Across connections:** when `crm.clientes.cod_erp` holds codes of `erp`'s `cus.cod`, the agent records it with `heydb_relate` and `to_connection: "erp"`, and `heydb_table cus` on `erp` shows it.
99
+ - **Project notes:** facts about the whole system ("one database per client; the central one is acme") are saved with `scope: "project"` and shown first by `heydb_overview`.
100
+ - **Microservices:** give each service its own `.heydb/`; heydb uses the nearest one above the folder Pi runs in.
101
+
102
+ ## Passwords
103
+
104
+ `/heydb:connect` and `/heydb:password` save the password in `.heydb/.env` as `HEYDB_<NAME>_PASSWORD`, readable only by your user. heydb makes sure git ignores that file before writing, and refuses to write if git already tracks it. `config.json` only names the variable. You can also set it in your shell, which wins over the file:
105
+
106
+ ```sh
107
+ export HEYDB_PROD_PASSWORD='…'
108
+ ```
109
+
110
+ This keeps passwords out of git and out of the chat, not away from your own user account.
111
+
112
+ ## What gets committed
113
+
114
+ | Path | Commit it? |
115
+ |---|---|
116
+ | `.heydb/config.json` | Yes: connections, with password references only |
117
+ | `.heydb/snapshots/*.json.gz` | Yes: the schema, compressed (a schema with about 1,500 tables is about 470 KB) |
118
+ | `.heydb/knowledge/` | Yes: the team's notes and relationships |
119
+ | `.heydb/.env` | Never: local passwords |
120
+
121
+ If your project's `.gitignore` excludes `.heydb/`, notes stay on your machine; heydb tells you when it saves one. To see snapshot diffs in git, add `*.json.gz diff=gzip` to `.gitattributes` and run `git config diff.gzip.textconv "gzip -dc"`.
122
+
123
+ ## Not yet
124
+
125
+ - Running queries or reading row data.
126
+ - Redis and other engines (Redis is next).
127
+ - A CLI or MCP server for agents outside Pi.
128
+ - Suggesting relationships on its own, beyond the name-pattern hints in `heydb_table`.
129
+ - Listing orphaned notes (notes whose table or column disappeared) from a tool.
130
+ - Storing passwords in the system keychain.
131
+
132
+ Ideas and bugs are welcome in [issues](https://github.com/pvidaal07/heydb/issues).
133
+
134
+ ## Contributing
135
+
136
+ Contributions are welcome: open an issue, wait for `status:approved`, then fork and send a pull request to `main` that says `Closes #<issue>`. [CONTRIBUTING.md](CONTRIBUTING.md) explains the workflow, the setup and how the code is organized. Security problems go to a [private advisory](https://github.com/pvidaal07/heydb/security/advisories/new).
137
+
138
+ ## Development
139
+
140
+ ```sh
141
+ corepack enable
142
+ pnpm install
143
+ pnpm check # typecheck + unit tests
144
+ node --run db:up # MySQL 8.0, MariaDB 10.6 and PostgreSQL 16 in Docker
145
+ node --run test:integration
146
+ node --run db:down
147
+ pi -e . # try the local copy in Pi
148
+ ```
149
+
150
+ Releases (maintainers): bump `version` in `package.json`, add the entry to `CHANGELOG.md`, merge, and push a tag `vX.Y.Z` on `main`; the publish workflow tests, stages the version on npm through trusted publishing and creates the GitHub release. The version becomes public once a maintainer approves it on npmjs.com (Staged Packages) with 2FA.
151
+
152
+ ## License
153
+
154
+ MIT