ainecto 0.0.0-stage → 0.5.0

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.
package/README.md CHANGED
@@ -1,3 +1,320 @@
1
- # Temporary Holding Version
1
+ # ainecto — AiNecto CLI and MCP connector
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
+ Published as `ainecto`, `@ainecto/mcp` and `@ainecto/cli` — the same code. Command: `ainecto`.
4
+ The older names (`ai-erd`, `@ai-erd/mcp`, `@ai-erd/cli`, command `ai-erd`) still get the same code and
5
+ still work.
6
+
7
+ **In a terminal, from your repository root:** `npx -y ainecto@latest init` — it asks which role this
8
+ repository's AI sessions should have and which AiNecto project to use, and signs you in through the
9
+ browser if needed.
10
+
11
+ ## For AI agents
12
+
13
+ **Ask the user which role this repository's AI sessions should have — Design, Development, Test, or Validation. Never pick one yourself. Then, from the repository root: `npx -y ainecto@latest init --role <role>` (it signs the user in through the browser if needed).**
14
+
15
+ - Use a long command timeout (at least 6 minutes): sign-in waits up to 5 minutes for the user.
16
+ - If `init` lists projects, ask the user which one and re-run with `--project <uuid>`. If it says
17
+ this is not the repository root, re-run from the folder it names.
18
+ - **No restart is needed.** Right after `init`, keep working in the same session through the CLI:
19
+ `ainecto` commands run from the repository read its role on every call (read `.ainecto/HARNESS.md`,
20
+ then `ainecto tools list` and `ainecto tools call <tool> '<json>'`). Do not use MCP tools the session
21
+ started with for that work — they keep the role (or no role) the session started with.
22
+ - A new session is optional and only adds the role's MCP tools (Claude Code: exit, then `claude -c`
23
+ in this folder to keep the conversation; approve the `ainecto` server from `.mcp.json` when asked).
24
+ Codex: save the profile `init` prints and start with `codex -p <role>`.
25
+ - **A server added during a session is not available in that session.** In our test, a server added
26
+ with `claude mcp add` while Claude Code was running did not attach to the running session — that is
27
+ why the CLI is the way to keep going. `/mcp` shows what the current session actually loaded.
28
+ - Inside the repository, `ainecto` commands (`ainecto tools call …`) use the repository's role
29
+ automatically — do not pass `--role`; a different `--role` is refused.
30
+ - Claude Code's auto mode may block running an external package with `npx`. If it does, ask the user
31
+ to allow the command.
32
+
33
+ To connect AiNecto without a repository role (for example before `init`), add the remote server at
34
+ **user scope** under the name `ainecto` — a local-scope entry would hide the `.mcp.json` that `init`
35
+ writes, and a different name would sit next to it as a second server with no role:
36
+
37
+ ```bash
38
+ claude mcp add --scope user --transport http ainecto https://ainecto.com/mcp # Claude Code
39
+ codex mcp add ainecto --url https://ainecto.com/mcp # Codex
40
+ ```
41
+
42
+ The client signs the user in on first use. That session has no role until `init` runs and a new
43
+ session starts.
44
+
45
+ ## Upgrading from ai-erd (0.4.x)
46
+
47
+ Version 0.5.0 renamed what `init` writes into a repository. A repository set up by 0.4.x keeps
48
+ working: the CLI reads the `ai-erd` server entry, the `.ai-erd/` folder, the `<!-- ai-erd:begin -->`
49
+ block and `AI_ERD_ROLE` as its own. Running `npx -y ainecto@latest init` again moves them to the new
50
+ names — nothing is left behind twice:
51
+
52
+ | 0.4.x | 0.5.0 |
53
+ | --- | --- |
54
+ | server entry `"ai-erd"` (`npx -y @ai-erd/mcp --role …`) | `"ainecto"` (`npx -y @ainecto/mcp --role …`) — the old entry is replaced |
55
+ | folder `.ai-erd/` (`HARNESS.md`, `config.json`, `init-record.json`) | `.ainecto/` — moved, and the old folder removed if 0.4.x created it |
56
+ | block `<!-- ai-erd:begin -->` … `<!-- ai-erd:end -->` | `<!-- ainecto:begin -->` … — replaced in place |
57
+ | `AI_ERD_ROLE` | `AINECTO_ROLE` — both are read; when both are set, `AINECTO_ROLE` wins |
58
+
59
+ `ainecto init --undo` still puts back what was there before the 0.4.x `init`, with or without that
60
+ second `init`. Not renamed: the role header and OAuth scope the server reads, and the sign-in on
61
+ this machine.
62
+
63
+ - If you added AiNecto earlier as `ai-erd` at Claude Code **user** scope or in Codex, remove it
64
+ (`claude mcp remove ai-erd -s user`, `codex mcp remove ai-erd`) and add it as `ainecto` as above:
65
+ under a different name it no longer hides behind the repository's entry.
66
+ - Claude Code shows the tools as `mcp__ainecto__…` instead of `mcp__ai-erd__…` — update any allow
67
+ list that names the old prefix.
68
+ - An `ai-erd` 0.4.x installed globally does not know the new names: inside a repository set up by
69
+ 0.5.0 it finds no role (so no restriction), and running its `init` there adds a second entry, block
70
+ and folder. Update it (`npm install -g ai-erd@latest` gets this same code). If that already
71
+ happened, 0.5.0 stops and says how to undo it (`npx -y -p @ai-erd/mcp@0.4.6 ai-erd init --undo`).
72
+
73
+ ## Set up a repository (roles)
74
+
75
+ ```bash
76
+ npx -y ainecto@latest init # in a terminal: asks for the role and the project
77
+ npx -y ainecto@latest init --role development # agents, scripts, CI: nothing is asked
78
+ ```
79
+
80
+ In a terminal (stdin and stdout both a TTY, no `--json`, and not under an agent or CI — `CLAUDECODE`,
81
+ `CI`, `GEMINI_CLI`, `CODEX_SANDBOX`, `CURSOR_AGENT`) `init` asks for what was not given:
82
+ - the role, unless `--role` or `AINECTO_ROLE` is set — by number, with no default. The role already
83
+ set on the repository is the default only when there is one (if its agent configs disagree, there
84
+ is no default);
85
+ - the project, unless `--project` is set — by number; «Create a new project» is offered to Design only.
86
+
87
+ Ctrl+C or Ctrl+D at a question cancels without writing repository files (Ctrl+D exits with 130). A
88
+ sign-in you already completed stays saved, and choosing «Create a new project» creates it right away.
89
+ Anywhere else (an agent's shell, CI) it asks nothing. In both cases:
90
+
91
+ - If this machine is not signed in to AiNecto yet, `init` opens a browser and continues once the user
92
+ approves — **once per machine** (per server), not per role. The sign-in URL is printed first (with
93
+ `--json`, as one JSON line on stderr: `{"event":"login_url","url":…}`), and sign-in gives up after
94
+ 5 minutes. It fails at once
95
+ when the command that opens the browser is missing, or (except on Windows, where the exit code is
96
+ not reliable) exits with an error.
97
+ - Outside a terminal, with no `--role`/`AINECTO_ROLE` it uses the role already set on the repository.
98
+ If there is none (or the repository's agent configs disagree) it stops and says to ask the user —
99
+ it never picks a role for you. If the account has more than one project it lists them and stops;
100
+ re-run with `--project <uuid>`. With no project yet,
101
+ only a Design session can create one (`--yes`, optionally `--project-name <name>`); in any other
102
+ role it asks you to have the user create the project, then re-run with the same role.
103
+ - It stops when run from a sub-folder of a git repository, and tells you the root.
104
+ - It writes one `ainecto` server entry carrying `--role` into `.mcp.json` (Claude Code) and
105
+ `.cursor/mcp.json` (Cursor), and prints the Codex profile to use (`codex -p <role>`).
106
+ - `ainecto` commands in the repository use the new role **at once**; MCP tools pick it up in a **new
107
+ session** (a running session's MCP tools keep the role they started with). Roles are a working
108
+ guardrail, not a security boundary.
109
+ - `ainecto init --dry-run` shows what would change (it does not sign in or refresh a sign-in);
110
+ `ainecto init --undo` removes what it wrote.
111
+
112
+ ## Commands
113
+
114
+ Prefer `npx -y ainecto@latest <command>`. To install once instead, use `npm install -g ainecto` — but
115
+ install only **one** of `ainecto`, `@ainecto/mcp`, `@ainecto/cli`, `ai-erd`, `@ai-erd/mcp` and
116
+ `@ai-erd/cli` globally: they are the same code and ship the same commands, so a second global install
117
+ conflicts. (`ainecto` and `ai-erd` carry both commands, `ainecto` and `ai-erd`; `@ainecto/cli` carries
118
+ only `ainecto`, `@ai-erd/cli` only `ai-erd`.)
119
+
120
+ ```bash
121
+ ainecto auth login # once per machine (and per --env); not per role
122
+ ainecto auth status
123
+ ainecto auth logout
124
+
125
+ ainecto tools list
126
+ ainecto tools call list_projects --json
127
+ ainecto tools call erd_apply_changes -f changes.json --json
128
+ cat payload.json | ainecto tools call erd_apply_changes --json
129
+
130
+ ainecto projects list
131
+ ainecto erd apply-changes -f erd-operations.json --yes
132
+ ```
133
+
134
+ `ai-erd` is the same command under its older name — every `ainecto …` line works as `ai-erd …`.
135
+
136
+ **The role comes from the repository.** Inside a folder set up with `ainecto init` (the command looks
137
+ from the current folder upward for the first `.mcp.json`/`.cursor/mcp.json` with an `ainecto` entry —
138
+ or, from 0.4.x, an `ai-erd` entry), every command uses that folder's role without `--role`. A `--role`
139
+ or `AINECTO_ROLE` (or `AI_ERD_ROLE`) that differs from it is refused — the role changes only with
140
+ `ainecto init --role <role>`, after asking the user. If the role there cannot be read (the
141
+ `@ainecto/mcp` bridge entry without a valid `--role`, configs that disagree, an `ainecto` and an
142
+ `ai-erd` bridge with different roles, broken JSON that mentions `ainecto` or `ai-erd`, a link that
143
+ points outside the folder), the command stops. An entry that is not this bridge (for example an HTTP
144
+ `url` or `mcp-remote` entry) means no role there. Your home folder itself is never read as a
145
+ repository (`~/.cursor/mcp.json` is Cursor's global config). Outside such a folder there is no role
146
+ (no restriction), and `--role` narrows it.
147
+ Tool names are the server's own names (`list_projects`, `erd_apply_changes`, …). Your AI client
148
+ shows them with its own prefix, for example `mcp__ainecto__list_projects` in Claude Code
149
+ (`mcp__ai-erd__…` for a 0.4.x setup); the CLI does not use that prefix. A tool name that starts with
150
+ the server's older `mcp__ainecto__` prefix is still accepted.
151
+
152
+ Every command takes `--env dev` for `https://dev.ai-erd.com/mcp`. Endpoint resolution priority:
153
+
154
+ 1. `--endpoint <url>`
155
+ 2. `AINECTO_MCP_ENDPOINT`
156
+ 3. `--env dev`
157
+ 4. production default, `https://ainecto.com/mcp`
158
+
159
+ Endpoint URLs must use `https:`. Plain `http:` is accepted only for localhost loopback targets such
160
+ as `127.0.0.1`. When `AINECTO_TOKEN` is set, the CLI only sends it to the default prod/dev endpoints
161
+ unless `AINECTO_ALLOW_CUSTOM_ENDPOINT_TOKEN=1` is set for an explicitly trusted custom endpoint.
162
+
163
+ The commands are `ainecto` and `ai-erd` (the same CLI), `ai-erd-mcp`, and `mcp` (which
164
+ `npx -y @ainecto/mcp` runs). The `AINECTO_*` environment variables above are the **only** names for
165
+ those settings — there is no `AI_ERD_*` equivalent, so do not guess one. (The one `AI_ERD_*` variable
166
+ is `AI_ERD_ROLE`, the older name of `AINECTO_ROLE`.)
167
+
168
+ ## Generated Friendly Commands
169
+
170
+ Every checked-in generated catalog tool is reachable through its deterministic command path. Scalar
171
+ schema fields are exposed as flags, with both kebab-case and schema-case accepted:
172
+
173
+ ```bash
174
+ ainecto documents list --project-uuid <projectUuid>
175
+ ainecto documents list --projectUuid <projectUuid>
176
+ ```
177
+
178
+ Array or object payloads use the first-party CLI JSON payload reader:
179
+
180
+ ```bash
181
+ ainecto documents create -f create-documents.json
182
+ cat erd-operations.json | ainecto erd apply-changes --json
183
+ ```
184
+
185
+ Destructive generated commands prompt in human mode unless `--yes` is supplied. In `--json` mode
186
+ they fail with a structured error unless `--yes` is present.
187
+
188
+ Attachment file upload is available through a bespoke command that performs the upload-token, raw
189
+ PUT, and attachment registration flow:
190
+
191
+ ```bash
192
+ ainecto attachments upload --document-uuid <documentUuid> ./diagram.png ./notes.pdf
193
+ ```
194
+
195
+ The generated `request_upload_token` and `upload_attachments` paths remain raw MCP argument-contract
196
+ commands and do not read local files.
197
+
198
+ ## Connector Mode
199
+
200
+ ```bash
201
+ ainecto mcp --role <design|development|test|validation> [--env dev]
202
+ ```
203
+
204
+ The package doubles as a stdio-to-HTTP proxy for the resolved `/mcp` endpoint. It proxies
205
+ `initialize`, `tools/list`, and `tools/call`, does not rewrite remote schemas, and does not interpret
206
+ local file references. It uses this machine's one sign-in (`ainecto auth login`, or the sign-in
207
+ `ainecto init` performs) and never opens a browser on its own. Its role comes only from `--role` (or
208
+ `AINECTO_ROLE`, or the older `AI_ERD_ROLE`) and is sent with every request; the server applies it.
209
+
210
+ This is the entry `ainecto init` writes into a repository's MCP config — you normally do not add it
211
+ by hand:
212
+
213
+ ```json
214
+ {
215
+ "mcpServers": {
216
+ "ainecto": {
217
+ "command": "npx",
218
+ "args": ["-y", "@ainecto/mcp", "--role", "development"]
219
+ }
220
+ }
221
+ }
222
+ ```
223
+
224
+ A bridge without a role has no restriction. If a session inside a set-up repository still has no role,
225
+ another `ainecto` entry (for example Claude Code's local scope) is usually hiding the one `init` wrote —
226
+ check with `claude mcp get ainecto`. An entry under another name (an older `ai-erd` one, say) does not
227
+ hide it but adds a second server with no role — remove it.
228
+
229
+ ### MCP Registry
230
+
231
+ `server.json` is the Registry entry `io.github.codelives/ainecto` (same as `package.json#mcpName`). It
232
+ lists only the npm package `@ainecto/mcp` — the per-repository role bridge `init` writes. Registry
233
+ publication requires the npm version it references to carry that `mcpName`, so publish npm first.
234
+ Registration is done by a person:
235
+
236
+ 1. `npm run release -- --otp=<code>` (below) so that `@ainecto/mcp@<version>` is on npm.
237
+ 2. GitHub org namespace login as a `codelives` org **Owner** — a classic PAT with only `read:org`
238
+ works where the browser login did not: `MCP_GITHUB_TOKEN=<pat> mcp-publisher login github`.
239
+ 3. `mcp-publisher publish` from this folder. The new version simply replaces the package identifier
240
+ (`@ai-erd/mcp` up to 0.4.x → `@ainecto/mcp`); the server name does not change.
241
+
242
+ Leave the other entry, `com.ai-erd/ai-erd` (the remote `https://ai-erd.com/mcp`, ai-erd.com domain
243
+ namespace), as it is. One remote URL can belong to one server only; listing `https://ainecto.com/mcp`
244
+ as a remote here, or a `com.ainecto/*` name, would need ainecto.com domain auth
245
+ (`mcp-publisher login dns|http --domain ainecto.com`) and is not part of this release.
246
+
247
+ ## Development
248
+
249
+ ```bash
250
+ npm install
251
+ npm run typecheck
252
+ npm test
253
+ npm run build
254
+ npm link # puts `ainecto` (and `ai-erd`) on your PATH
255
+ ```
256
+
257
+ ### Catalog Sync
258
+
259
+ `sync:tools --check` is intended for publish-time live drift checks. It fails fast when
260
+ `AINECTO_CATALOG_SYNC_TOKEN` is missing, so automatic publish cannot silently fall back to fixtures.
261
+ For local development, `sync:tools` can also use credentials from `ainecto auth login --env <env>`.
262
+
263
+ ```bash
264
+ AINECTO_CATALOG_SYNC_TOKEN=... npm run sync:tools -- --env prod --check
265
+ AINECTO_CATALOG_SYNC_TOKEN=... npm run sync:tools -- --env dev --check
266
+ ```
267
+
268
+ The checked-in generated catalogs are deterministic output from `tools/list`, live-synced from
269
+ `https://ainecto.com/mcp` and `https://dev.ai-erd.com/mcp`. Presentation metadata lives separately in
270
+ `src/core/catalog/enrichments.ts`. `ainecto tools catalog` prints the local generated catalog.
271
+
272
+ ### Local Tarball Smoke
273
+
274
+ ```bash
275
+ npm pack
276
+ npm exec --package ./ainecto-mcp-<version>.tgz -- ainecto --help
277
+ ```
278
+
279
+ ### Live Dev MCP Smoke
280
+
281
+ This requires an authenticated dev token from `ainecto auth login --env dev` or a local developer
282
+ `AINECTO_TOKEN`.
283
+
284
+ ```bash
285
+ npm run smoke:mcp -- --env dev
286
+ ```
287
+
288
+ The smoke initializes MCP, reads `tools/list`, calls `list_projects`, and prints only aggregate
289
+ metadata such as tool count and Task tool exposure.
290
+
291
+ ### Local Attachment Upload Smoke
292
+
293
+ This exercises the full `attachments upload` flow against a local API dev server: OAuth MCP token
294
+ issue, REST fixture document creation, CLI upload, `list_attachments`, and server filesystem byte
295
+ verification.
296
+
297
+ ```bash
298
+ npm run smoke:attachments -- --base-url http://localhost:8080 --endpoint http://localhost:8080/mcp --api-root <path-to-api-repo>
299
+ ```
300
+
301
+ The smoke creates a temporary user/workspace/project/document and removes the fixture account, local
302
+ temp file, and stored upload file unless `--keep` is supplied.
303
+
304
+ ### Releasing
305
+
306
+ `npm run release -- --otp=<code>` runs typecheck, test and build once, then publishes that build under
307
+ six names: `@ainecto/mcp` (primary), `ainecto`, `@ainecto/cli` (only the `ainecto` command), and the
308
+ older `@ai-erd/mcp`, `ai-erd`, `@ai-erd/cli` (only the `ai-erd` command). `--dry-run` shows what would
309
+ go out. An already-published name is skipped, so a retry after an expired code is safe.
310
+
311
+ Before the first 0.5.0 release, by hand: the npm account needs write access to both the `@ainecto` and
312
+ `@ai-erd` orgs (the script checks), and `@ainecto/mcp` versions up to 0.3.0 still carry the 2026-09-29
313
+ deprecation «moved to @ai-erd/mcp» — replace it, for example
314
+ `npm deprecate "@ainecto/mcp@<=0.3.0" "Old version — use @ainecto/mcp@latest"` (new versions are not
315
+ deprecated). Do not unpublish any name.
316
+
317
+ ## Known Limitations
318
+
319
+ - The MCP connector implements newline-delimited stdio JSON-RPC to HTTP JSON-RPC. Streamable HTTP SSE
320
+ responses and `MCP-Session-Id` session handling are not implemented.