@vmise/aipi-companion 0.4.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Akhil Kolli
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 ADDED
@@ -0,0 +1,260 @@
1
+ # AIPI (AI-Programming Interface)
2
+
3
+ AIPI is a local-first API integration intelligence workspace for Codex, Cursor, and GitHub Copilot. It discovers endpoints, reproduces failures locally, diagnoses the responsible code from evidence, and generates native regression tests. The dashboard is an inspection surface; your existing agent remains the control plane.
4
+
5
+ ## Why AIPI
6
+
7
+ Developers building with Codex often create APIs and edge functions faster than they can test, organize, and reuse them. AIPI keeps exploratory requests, repeatable collections, assertions, documentation, and failure evidence in one local workspace that both the developer and Codex can use.
8
+
9
+ ## Product architecture
10
+
11
+ ```text
12
+ AI editor / Codex
13
+ │
14
+ ├─ Local Companion (developer machine)
15
+ │ ├─ traffic proxy or Node fetch hook
16
+ │ ├─ route + schema tracer
17
+ │ ├─ contract diff and local diagnostic
18
+ │ ├─ Vitest fixture generator
19
+ │ └─ inspection dashboard
20
+ │
21
+ └─ Remote MCP Service (authenticated team context)
22
+ ├─ Supabase contract registry with RLS
23
+ ├─ cross-repository blast-radius check
24
+ └─ CI contract guardrail
25
+ ```
26
+
27
+ The local companion does not replace the editor. It supplies deterministic evidence and lets Codex handle chat, repository edits, review, and verification. The remote service stores contracts and consumer locations—not captured payload bodies.
28
+
29
+ The implementation decisions, evidence pipeline, deferred adapters, and two-engineer ownership split are documented in `docs/TECHNICAL-ARCHITECTURE.md`.
30
+
31
+ ## Dashboard
32
+
33
+ Ask Codex to **open my AIPI dashboard**, run `aipi open`, or run `npm run dashboard` while developing the plugin. Open the returned loopback URL in Codex's browser panel and toggle that panel while coding. The Project, APIs, Map, and Logs routes include:
34
+
35
+ - Projects, requests, environments, and variables
36
+ - Bearer, Basic, and API-key authentication
37
+ - Params, headers, JSON/text/form bodies, and tests
38
+ - CA certificates and mTLS client credentials
39
+ - Pre-request and post-response scripts
40
+ - Request documentation
41
+ - OpenAPI 3.x and Swagger 2 JSON/YAML import from a file, pasted document, or URL
42
+ - Persistent history, response details, Codex-oriented diagnosis, and automatic retry
43
+ - Local source folders grouped as frontend, backend, database, schemas, tests, or documentation
44
+ - Automatic recognition of common frontend calls, backend routes, database tables, and integration gaps
45
+ - A living Project summary separating backend problems, frontend corrections, schema issues, evidence freshness, goals, tasks, and iteration history
46
+
47
+ The local companion binds only to `127.0.0.1` and defaults to `http://127.0.0.1:49152`. `aipi open` starts or reuses the daemon, creates a short-lived session token, and opens the cloud dashboard with the local connection parameters. Visiting `/dashboard/` directly shows the shell only; use `aipi open` so the URL includes `#port=...&token=...`.
48
+
49
+ ## Deployment and installation model
50
+
51
+ AIPI is local-first by design. Cloudflare hosts the public website, documentation, and dashboard shell. The local AIPI Companion runs the MCP server, scans source code, executes API requests, and stores logs and evidence on the developer's machine. An optional outbound pairing bridge can connect the cloud dashboard to an approved local companion without opening an inbound port.
52
+
53
+ Install and initialize the companion:
54
+
55
+ ```bash
56
+ cd /path/to/your/project
57
+ npx @vmise/aipi-companion init
58
+ npx @vmise/aipi-companion open --app https://aipi.website/dashboard/
59
+ ```
60
+
61
+ For one-off execution, use:
62
+
63
+ ```bash
64
+ npx @vmise/aipi-companion open --app https://aipi.website/dashboard/
65
+ ```
66
+
67
+ Register the local MCP server in the IDE:
68
+
69
+ ```json
70
+ {
71
+ "mcpServers": {
72
+ "aipi": {
73
+ "command": "aipi",
74
+ "args": ["mcp"]
75
+ }
76
+ }
77
+ }
78
+ ```
79
+
80
+ `aipi init` writes `.aipirc.json`, detects common source roots such as `apps/web`, `apps/api`, `prisma`, and `supabase`, and injects the AIPI MCP entry into local Cursor and VS Code config. `aipi daemon` owns the loopback server, while `aipi mcp` is a thin client: it reuses an existing daemon or starts one silently before serving MCP over stdio.
81
+
82
+ See the hosted [installation guide](https://aipi.website/install.html) for the cloud dashboard, pairing flow, data boundary, and troubleshooting model.
83
+
84
+ ## Codex tools
85
+
86
+ - `open_dashboard`
87
+ - `api_request`
88
+ - `run_collection`
89
+ - `list_projects`
90
+ - `create_project`
91
+ - `select_project`
92
+ - `get_project`
93
+ - `scan_project`
94
+ - `list_endpoints`
95
+ - `get_project_summary`
96
+ - `get_project_timeline`
97
+ - `record_project_event`
98
+ - `analyze_and_repair_contract`
99
+ - `get_history`
100
+ - `diagnose_failure`
101
+ - `retry_request`
102
+ - `get_endpoint_context`
103
+ - `list_integration_issues`
104
+ - `create_request`
105
+ - `run_request`
106
+ - `get_run_evidence`
107
+ - `trace_route`
108
+ - `diff_contract`
109
+ - `run_local_diagnostic`
110
+ - `generate_fixture`
111
+ - `check_blast_radius`
112
+ - `compare_runs`
113
+ - `create_fix_plan`
114
+ - `run_correction_workflow`
115
+ - `generate_regression_test`
116
+ - `verify_changes`
117
+ - `export_project`
118
+
119
+ The tools remain fully usable without the UI. This lets Codex trace actual traffic, compare observed response contracts with database schema, generate editor-ready fixtures, and summarize cross-layer corrections directly in conversation. `get_project_timeline` provides bounded, high-signal context instead of sending entire logs or repositories into the model, while `record_project_event` preserves agent decisions and implemented changes as redacted local evidence. Fixture generation returns content without writing files so the developer's AI editor stays in control of repository changes.
120
+
121
+ `run_correction_workflow` is the closed-loop entry point. Its first call returns the failing evidence, affected files, Git freshness, fix plan, and a non-writing regression fixture. After the editor applies the correction, call it again with `verify_after_changes=true` to rerun the saved request, persist new evidence, and compare the result with the original run. State-changing methods remain blocked until `allow_state_change=true` is explicitly authorized.
122
+
123
+ ## Local Companion
124
+
125
+ The prototype now includes shared packages for redaction and evidence, repository serialization, the Integration Map, and native test generation. Exported projects use ordinary JSON files under `.api-forge/`; JSON was selected for the first portable schema because it is deterministic, dependency-free, and valid YAML 1.2 input for future YAML tooling.
126
+
127
+ ```text
128
+ packages/
129
+ ├── core/ redaction, route normalization, run comparison, fix plans
130
+ ├── collection-schema/ repository-native project/request serialization
131
+ ├── contract-engine/ Next.js + Zod route tracing and deterministic type diffs
132
+ ├── integration-map/ endpoint context and issue model
133
+ ├── local-observer/ redacted loopback request/response capture
134
+ ├── remote-registry/ file/Supabase registry and blast-radius engine
135
+ ├── test-generators/ Vitest/Jest regression tests
136
+ └── cli/ repository export and inspection
137
+ ```
138
+
139
+ CLI examples:
140
+
141
+ ```bash
142
+ npm run cli -- inspect /path/to/project
143
+ npm run cli -- export ~/.api-forge/workspace.json <project-id> /path/to/project
144
+ npm run cli -- trace /api/users POST /path/to/project
145
+ npm run cli -- diff src/create-user.ts /api/users POST /path/to/project
146
+ npm run cli -- diagnose /api/users POST /path/to/project
147
+ npm run cli -- fixture /api/users POST /path/to/project
148
+ npm run cli -- guard /path/to/project
149
+ ```
150
+
151
+ ### Capture actual local traffic
152
+
153
+ Run an explicit proxy in front of an already-running local app:
154
+
155
+ ```bash
156
+ npm run observe -- --target http://127.0.0.1:3000 --port 43128 --root /path/to/project
157
+ ```
158
+
159
+ Point the frontend at `http://127.0.0.1:43128`. Redacted request/response evidence is appended to `.api-forge/tmp/traffic.ndjson`.
160
+
161
+ For Node applications whose traffic uses global `fetch`, load the zero-config hook instead:
162
+
163
+ ```bash
164
+ AIPI_OBSERVER_ROOT=/path/to/project \
165
+ node --import /absolute/path/to/API-Forge/scripts/aipi-observer-hook.mjs server.mjs
166
+ ```
167
+
168
+ The observer removes authorization, cookies, API keys, passwords, tokens, and common secret fields. Captured evidence is still sensitive local data and should not be committed.
169
+
170
+ The example in `fixtures/next-contract-mismatch` contains a Next.js App Router handler, Zod validation, Prisma model, and an intentional frontend `number` versus backend `uuid` mismatch.
171
+
172
+ ## CI contract guardrail
173
+
174
+ The repository ships a composite GitHub Action and a working example workflow. In another repository:
175
+
176
+ ```yaml
177
+ steps:
178
+ - uses: actions/checkout@v4
179
+ - uses: akhil92kolli-hub/AIPI@main
180
+ with:
181
+ root: .
182
+ ```
183
+
184
+ The guard scans supported frontend/backend pairs, emits GitHub annotations for exact mismatches, and exits non-zero when a contract is violated. Pin a release tag or commit SHA in production.
185
+
186
+ ## Remote MCP service
187
+
188
+ For a zero-infrastructure demo, run the Node Streamable HTTP server backed by a local JSON registry:
189
+
190
+ ```bash
191
+ npm run mcp:remote
192
+ # http://127.0.0.1:8788/mcp
193
+ ```
194
+
195
+ Set `AIPI_REGISTRY_FILE` to move the demo registry or `AIPI_REMOTE_TOKEN` to require a static bearer token. For server-side Supabase access, set `SUPABASE_URL` and `SUPABASE_SECRET_KEY`; never expose that secret to an editor client.
196
+
197
+ The production remote service lives in `cloud/worker.ts`: Hono hosts the official MCP v2 Streamable HTTP handler on Cloudflare Workers and forwards the caller's Supabase access token to the Data API, so row-level security limits every contract to an organization owned by that user. `supabase/functions/aipi-mcp` remains a Supabase Edge Function deployment adapter for teams that prefer to keep compute and data on one platform.
198
+
199
+ ```bash
200
+ supabase db push
201
+ supabase functions deploy aipi-mcp
202
+ # or deploy the Hono worker after setting its Supabase secrets
203
+ wrangler secret put SUPABASE_URL
204
+ wrangler secret put SUPABASE_PUBLISHABLE_KEY
205
+ npx wrangler deploy
206
+ ```
207
+
208
+ The deployed function is available at `https://<project-ref>.supabase.co/functions/v1/aipi-mcp`. A public Codex/ChatGPT marketplace release should place a stable custom HTTPS `/mcp` endpoint in front of it and complete OAuth, domain verification, publisher verification, privacy/terms metadata, and OpenAI review. The checked-in implementation is deployment-ready infrastructure, not evidence that those external approvals have been completed.
209
+
210
+ Remote client configuration is illustrated in `.mcp.remote.example.json`. The local Codex plugin continues to use `.mcp.json` and requires no cloud account.
211
+
212
+ ## Develop and test
213
+
214
+ AIPI requires Node.js 22 or later. Production dependencies are deliberately limited to the official MCP v2 server, `ts-morph`, MSW interceptors, AJV, Zod, and Hono. The Codex plugin launches a self-contained bundle, so it does not depend on `node_modules` being copied into the plugin cache.
215
+
216
+ ```bash
217
+ npm run validate
218
+ npm run build
219
+ npm test
220
+ npm run benchmark:startup
221
+ npm run demo:aipi
222
+ npm run dashboard
223
+ ```
224
+
225
+ The self-test starts disposable local and remote APIs, captures traffic, traces the demo Next.js route, detects its Zod contract mismatch, diagnoses a runtime failure, generates a Vitest fixture, verifies cross-repository blast radius, exercises both MCP handshakes, loads the dashboard, and imports an OpenAPI document.
226
+
227
+ Source scans now capture the Git commit, branch, working-tree state, and changed files for every configured root. Project summaries and verification tools report whether the current repository still matches the evidence baseline.
228
+
229
+ `npm run demo:aipi` prints a deterministic product story: the traced handler/schema/model, the local `number → uuid` mismatch, and both registered consumer repositories affected by the proposed breaking change.
230
+
231
+ `npm run benchmark:startup` enforces the Local Companion's cold MCP handshake target of under two seconds.
232
+
233
+ ## Plugin architecture
234
+
235
+ ```text
236
+ Codex / ChatGPT
237
+ ├─ API testing skill
238
+ └─ local MCP server
239
+ ├─ agent tools and structured results
240
+ ├─ shared workspace store
241
+ └─ loopback dashboard
242
+ ```
243
+
244
+ The bundled dashboard is exposed as an MCP Apps UI resource and also runs on loopback for local development. Ask Codex actions use the native chat bridge when hosted by Codex and copy redacted context when opened standalone.
245
+
246
+ ## Install for local Codex testing
247
+
248
+ Place the project in a local plugin marketplace, install `api-forge`, then start a new Codex task so the skill and MCP tools are loaded. The plugin manifest is in `.codex-plugin/plugin.json`, and the local MCP process is configured by `.mcp.json`.
249
+
250
+ ## Storage and security
251
+
252
+ Workspace data is stored in the plugin data directory with user-only file permissions. Saved environment secrets, request authentication values, and mTLS client private keys use the native credential facility available on the host: macOS Keychain, Linux Secret Service through `secret-tool`, or Windows Credential Manager through the built-in Windows PowerShell API bridge. All providers use the `com.aipi.companion` service identity. `workspace.json` contains only opaque `aipi-secret://...` references, and AIPI has no plaintext credential fallback. Existing plaintext values are migrated the next time the workspace is saved. Use the `get_secret_storage_status` MCP tool to verify the active provider.
253
+
254
+ Request bodies, response logs, public certificates, and scripts remain local workspace data and may still be sensitive. Remove sensitive payloads before sharing plugin data. Scripts should be treated as trusted local code. Linux installations need the `secret-tool` executable and an unlocked desktop keyring. On an unsupported or unavailable provider, AIPI refuses to persist new credential values.
255
+
256
+ AIPI requires Node.js 22+ for the local companion and MSW's current socket-level HTTP interceptor.
257
+
258
+ ## License
259
+
260
+ MIT
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@vmise/aipi-companion",
3
+ "version": "0.4.0",
4
+ "description": "AIPI local companion and MCP server for AI-powered API intelligence.",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/akhil92kolli-hub/AIPI.git"
8
+ },
9
+ "homepage": "https://aipi.website",
10
+ "bugs": {
11
+ "url": "https://github.com/akhil92kolli-hub/AIPI/issues"
12
+ },
13
+ "type": "module",
14
+ "bin": {
15
+ "api-forge": "./scripts/aipi-cli-bundle.mjs",
16
+ "aipi": "./scripts/aipi-cli-bundle.mjs"
17
+ },
18
+ "files": [
19
+ "scripts/aipi-cli-bundle.mjs",
20
+ "README.md",
21
+ "LICENSE"
22
+ ],
23
+ "publishConfig": {
24
+ "access": "public",
25
+ "registry": "https://registry.npmjs.org"
26
+ },
27
+ "engines": {
28
+ "node": ">=22"
29
+ },
30
+ "scripts": {
31
+ "build": "npm run typecheck && npm run build:local && npm run build:cli",
32
+ "pack:release": "npm run build:cli && npm pack --dry-run",
33
+ "build:local": "esbuild src/local-mcp.ts --bundle --platform=node --format=esm --target=node22 --banner:js=\"import { createRequire as _aipiCreateRequire } from 'node:module'; import { fileURLToPath as _aipiFileURLToPath } from 'node:url'; import { dirname as _aipiDirname } from 'node:path'; const require = _aipiCreateRequire(import.meta.url); const __filename = _aipiFileURLToPath(import.meta.url); const __dirname = _aipiDirname(__filename);\" --outfile=scripts/aipi-mcp-bundle.mjs",
34
+ "build:cli": "esbuild packages/cli/bin/api-forge.mjs --bundle --platform=node --format=esm --target=node22 --banner:js=\"import { createRequire as _aipiCreateRequire } from 'node:module'; import { fileURLToPath as _aipiFileURLToPath } from 'node:url'; import { dirname as _aipiDirname } from 'node:path'; const require = _aipiCreateRequire(import.meta.url); const __filename = _aipiFileURLToPath(import.meta.url); const __dirname = _aipiDirname(__filename);\" --outfile=scripts/aipi-cli-bundle.mjs",
35
+ "typecheck": "tsc --noEmit",
36
+ "showcase": "node scripts/showcase-server.mjs",
37
+ "demo:aipi": "node scripts/full-aipi-demo.mjs",
38
+ "benchmark:startup": "node scripts/startup-benchmark.mjs",
39
+ "dashboard": "node scripts/start-dashboard.mjs",
40
+ "mcp": "node scripts/aipi-mcp-bundle.mjs",
41
+ "mcp:dev": "tsx src/local-mcp.ts",
42
+ "mcp:remote": "node scripts/remote-mcp-server.mjs",
43
+ "observe": "node packages/cli/bin/api-forge.mjs observe",
44
+ "guard": "node packages/cli/bin/api-forge.mjs guard",
45
+ "cli": "node packages/cli/bin/api-forge.mjs",
46
+ "test": "node scripts/self-test.mjs && tsx scripts/cloud-smoke.ts",
47
+ "validate": "node scripts/validate-project.mjs"
48
+ },
49
+ "license": "MIT",
50
+ "dependencies": {
51
+ "@modelcontextprotocol/server": "^2.0.0",
52
+ "@mswjs/interceptors": "^0.45.0",
53
+ "ajv": "^8.20.0",
54
+ "hono": "^4.13.8",
55
+ "ts-morph": "^28.0.0",
56
+ "zod": "^4.6.5"
57
+ },
58
+ "devDependencies": {
59
+ "@types/node": "^26.6.2",
60
+ "esbuild": "^0.28.2",
61
+ "tsx": "^4.23.15",
62
+ "typescript": "^7.0.2",
63
+ "wrangler": "^4.136.3"
64
+ }
65
+ }