@aivin-labs/cli 1.0.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.
@@ -0,0 +1,234 @@
1
+ # Getting Started with @aivin-labs/cli
2
+
3
+ End-to-end walkthrough: from an empty folder to a deployed, discoverable Aivin plugin, using the
4
+ `aivin` command this package provides. For the full flag-by-flag reference of every command, see
5
+ [CLI.md](./CLI.md) instead — this doc is the narrative path through the same ground.
6
+
7
+ If you're looking for how to actually *write* the handler (the SDK API: `ai`, `vector`, `store`,
8
+ `ctx`, response shapes, testing with mocks, best practices) rather than how to drive the CLI, that
9
+ lives in [`@aivin-labs/sdk`'s own docs](https://github.com/aivin-labs/AIVIN-SDK/tree/main/docs) —
10
+ this guide links out to the relevant page at each step instead of duplicating it.
11
+
12
+ ## 1. Prerequisites
13
+
14
+ | | |
15
+ | --- | --- |
16
+ | **Node.js** | ≥ 22.0.0 — the SDK relies on Node's native TypeScript support to load `src/main.ts` directly, no build step. Stable from Node 22.6, default from Node 24. |
17
+ | **This package** | `npm install -g @aivin-labs/cli` — gives you the `aivin` command used throughout this guide. |
18
+ | **Account** | An Aivin account, for `aivin login` / `aivin deploy` / `aivin test` (not needed for `aivin create`/`aivin start`, which are fully local). |
19
+ | **Docker** | Not required locally — the platform builds and runs your container remotely on `aivin deploy`. |
20
+
21
+ ```bash
22
+ npm install -g @aivin-labs/cli
23
+ aivin --version
24
+ ```
25
+
26
+ ## 2. Create the plugin
27
+
28
+ Two starting points, depending on whether you want AI to write the first draft of your business
29
+ logic or you'd rather write it by hand:
30
+
31
+ ```bash
32
+ # Guided, AI-assisted: asks what the plugin should do, then scaffolds AND generates real code
33
+ aivin init my-plugin
34
+ cd my-plugin && npm install
35
+ ```
36
+
37
+ ```bash
38
+ # Blank scaffold, no AI step: one src/main.ts you write by hand
39
+ aivin create my-plugin
40
+ cd my-plugin && npm install
41
+ ```
42
+
43
+ `aivin init` writes `src/service.ts` (the AI-generated business logic — a plain
44
+ `execute(input, ctx)` function, no protocol boilerplate) plus a thin, static `src/main.ts` wrapper
45
+ that packages its result into the platform's response shape. `aivin create` writes one
46
+ `src/main.ts` you edit directly, exporting `main(mission, input, ctx)`. Regenerate either later
47
+ with `aivin plugin make "<description>"` — it targets whichever file your project actually uses.
48
+
49
+ Either way, you get:
50
+
51
+ ```
52
+ my-plugin/
53
+ ├── manifest.json # shared fields + plugins[] — identity, input/output description, triggers
54
+ ├── src/
55
+ │ └── main.ts # (+ service.ts, if you used `aivin init`)
56
+ ├── package.json # depends only on @aivin-labs/sdk; "start" runs `aivin-server` directly
57
+ ├── tsconfig.json # editor/type-checking config (not used to build anything at deploy time)
58
+ ├── AGENTS.md # orientation for a coding agent (Claude Code, Cursor, ...) working in this project
59
+ ├── test/ # a real, runnable example test using createMockSDK
60
+ ├── .env # local-only config (see step 4)
61
+ └── .gitignore
62
+ ```
63
+
64
+ `manifest.json`'s `description` is what the AI planner reads to decide when to use your plugin —
65
+ fill it in precisely. Full field reference:
66
+ [MANIFEST.md](https://github.com/aivin-labs/AIVIN-SDK/blob/main/docs/MANIFEST.md) (in the sdk
67
+ repo — this is a runtime contract the SDK itself parses/validates, not a CLI concern).
68
+
69
+ Already have a project instead of a description to work from?
70
+
71
+ ```bash
72
+ cd your-existing-project
73
+ aivin plugin convert
74
+ ```
75
+
76
+ This scans your project's tree on demand (never uploads full file contents up front), plans
77
+ single-file vs. multi-file/multi-entry based on what it actually finds — including porting a
78
+ non-TypeScript project's real logic (e.g. Python) rather than editing it in place — then verifies
79
+ the result with a real `tsc` run plus a sandboxed smoke test before calling it done. See
80
+ [CLI.md#aivin-plugin-convert](./CLI.md#aivin-plugin-convert-hint) for the full loop,
81
+ overwrite-safety behavior, and `--force` (re-run conversion on a project already converted before).
82
+
83
+ Not sure something like this doesn't already exist? Check first:
84
+
85
+ ```bash
86
+ aivin plugin search "what you're trying to build"
87
+ ```
88
+
89
+ ## 3. Write (or regenerate) the handler
90
+
91
+ This part is SDK API, not CLI — see:
92
+
93
+ - [PLUGIN_DEVELOPMENT_GUIDE.md](https://github.com/aivin-labs/AIVIN-SDK/blob/main/docs/PLUGIN_DEVELOPMENT_GUIDE.md) — writing `main()`/`execute()`, the `ctx` argument, best practices, idempotency
94
+ - [SDK.md](https://github.com/aivin-labs/AIVIN-SDK/blob/main/docs/SDK.md) — every namespace (`ai`, `vector`, `store`, `task`, ...) and how to call them
95
+ - [EXAMPLES.md](https://github.com/aivin-labs/AIVIN-SDK/blob/main/docs/EXAMPLES.md) — real plugins across common use cases
96
+
97
+ Or let AI write it from a description:
98
+
99
+ ```bash
100
+ aivin plugin make "Summarize a support ticket and tag its urgency"
101
+ ```
102
+
103
+ Review the output before relying on it — generated code is a strong starting point, not a
104
+ guarantee.
105
+
106
+ ## 4. Test locally
107
+
108
+ ### Unit tests — no network, no running server
109
+
110
+ ```bash
111
+ npm test
112
+ ```
113
+
114
+ `aivin create`/`aivin init` already scaffold a real, runnable test using `createMockSDK`/
115
+ `withMockSDK` — no real backend, no gRPC round trip. Keep it in sync as you change what your
116
+ handler calls/returns.
117
+
118
+ ### Running it for real
119
+
120
+ ```bash
121
+ aivin start
122
+ ```
123
+
124
+ This starts two things:
125
+
126
+ 1. A real gRPC server on `:50051` — the same protocol the production host uses to trigger your
127
+ plugin. You generally won't call this directly.
128
+ 2. An HTTP test shim on `:4001` for quick manual testing:
129
+
130
+ ```bash
131
+ curl -X POST http://localhost:4001/invoke \
132
+ -H 'content-type: application/json' \
133
+ -d '{"input": {"text": "Some text to summarize"}}'
134
+ ```
135
+
136
+ Want to see every SDK call as it happens instead of just a summary at the end?
137
+
138
+ ```bash
139
+ aivin start --debug # human-readable, live, one line per call
140
+ aivin start --debug-json # same, one JSON object per line - easier for a script/coding agent to parse
141
+ ```
142
+
143
+ `--no-watch` disables hot-reload (on by default — editing `src/`/`manifest.json` restarts your
144
+ handler in place, no Ctrl+C needed).
145
+
146
+ **SDK calls made during local testing default to the production backend** (`api.aivin.cloud`) if
147
+ `SDK_ENDPOINT` isn't set in `.env` — so `ai.prompt(...)` etc. work out of the box, against real
148
+ production data. Point `.env` at a local/dev backend instead if you don't want that:
149
+
150
+ ```bash
151
+ # .env
152
+ SDK_ENDPOINT=localhost:50051
153
+ SDK_SECRET=
154
+ ```
155
+
156
+ A one-time warning is logged whenever the production default is used, so it's never silent.
157
+
158
+ Under the hood, `aivin start` spawns your project's own installed `@aivin-labs/sdk`'s
159
+ `bin/server.mjs` (via its `aivin-server` bin entry) with a couple of extra env vars for the flags
160
+ above — the exact same process a deployed container runs via `npm start`. Running `npm start`
161
+ yourself locally works too; you just lose the `--debug`/`--no-watch` conveniences `aivin start`
162
+ adds on top.
163
+
164
+ ## 5. Deploy
165
+
166
+ ```bash
167
+ aivin login # once per machine - saves an API key to ~/.aivin/credentials
168
+ aivin test # deploy to a non-production test instance first
169
+ aivin deploy # ship to your org
170
+ ```
171
+
172
+ `aivin test` uses the same payload as `aivin deploy` but a different, non-production-only endpoint
173
+ — real container, real gRPC, real SDK calls, but not visible to anyone yet. It goes a step
174
+ further than a plain deploy: it generates sample input from your `manifest.json`'s `input` schema,
175
+ actually invokes the plugin, and writes a pass/fail report to `.test/<timestamp>.json`. Pass
176
+ `--workspace <id>` to pick which workspace it runs against, or `--no-smoke-test` to skip this and
177
+ just deploy.
178
+
179
+ Each successful deploy auto-increments `manifest.json`'s patch version.
180
+
181
+ Not every plugin needs custom code — `aivin mcp create <name>` scaffolds a manifest-only plugin
182
+ that proxies to an external [MCP](https://modelcontextprotocol.io) server's tool/resource/prompt
183
+ instead. `aivin deploy`/`aivin test` detect this automatically and skip the code upload entirely.
184
+ See
185
+ [MANIFEST.md#mcp-proxy-plugins](https://github.com/aivin-labs/AIVIN-SDK/blob/main/docs/MANIFEST.md#mcp-proxy-plugins).
186
+
187
+ ## 6. Use the deployed plugin
188
+
189
+ ```bash
190
+ aivin plugin trigger "summarize this" '{"text":"..."}'
191
+ aivin plugin trigger -a "Summarize this ticket: customer can't log in after the last update"
192
+ aivin plugin logs
193
+ ```
194
+
195
+ `aivin plugin trigger` invokes it directly and prints the result — the exact same
196
+ `/plugins/execute` the platform's own Playground uses, so it's a real invocation, not a
197
+ simulation. `-a`/`--auto` skips writing structured JSON yourself — give it a free-text prompt and
198
+ the backend maps it onto `manifest.json`'s `input` schema for you. `aivin plugin logs` tails the
199
+ deployed plugin's own console output live.
200
+
201
+ ## 7. Beyond one plugin
202
+
203
+ `aivin` is also how you drive your Aivin workspace directly, not just build plugins:
204
+
205
+ - `aivin connector register` — register a reusable connector (OAuth app / credential namespace)
206
+ for a `manifest.json` `connection_id`; `aivin connector search`/`list` to find one that already
207
+ exists instead of creating a duplicate.
208
+ - `aivin do "<goal>"` — have an AI Staff agent work toward a goal in the background, not a
209
+ specific deployed plugin.
210
+ - `aivin browser "<mission>"` — run an AI Browser mission, driving your own local browser (own
211
+ profile, own cookies — log in once, watch missions run live from then on).
212
+ - `aivin task "<description>"` — create a task from a plain-language description.
213
+ - `aivin workspace` / `aivin agent` / `aivin project` — browse workspaces, projects, and AI Staff
214
+ agents, and pick one to use with `--workspace`/`--project`/`--agent` elsewhere.
215
+
216
+ Full flag reference for all of these: [CLI.md](./CLI.md).
217
+
218
+ ## 8. Troubleshooting
219
+
220
+ | Symptom | Likely cause |
221
+ | --- | --- |
222
+ | `aivin start` fails with `EADDRINUSE` on the gRPC port | Something else (possibly another plugin instance) already owns `:50051`. Set `SDK_GRPC_SERVER_BIND=127.0.0.1:<other-port>`. |
223
+ | Local HTTP test shim didn't start, but the gRPC server did | The shim failing to bind (e.g. port `:4001` taken) never takes down the real server — check the log line, set `LOCAL_TEST_PORT` to something free. |
224
+ | `aivin start` fails with "Could not find @aivin-labs/sdk installed" | Run `npm install` in the plugin project first — `aivin start` resolves `bin/server.mjs` from *this project's own* installed `@aivin-labs/sdk`, not from the CLI's own install location. |
225
+ | `aivin deploy`/`aivin test` fails with 401/403 | Run `aivin login` again — it saves a fresh key to `~/.aivin/credentials`, shared by every project on this machine. |
226
+ | SDK calls seem to hit production unexpectedly | Expected if `SDK_ENDPOINT` isn't set in `.env` — it defaults to `api.aivin.cloud`. Set it to a local/dev backend if that's not what you want — see step 4. |
227
+ | Generated code from `aivin plugin make` doesn't compile/looks wrong | Review and edit — it's AI-generated, treat it like a first draft from a junior contributor. |
228
+ | `command not found: aivin` after `npm install` (not `-g`) in a plugin project | Only `@aivin-labs/sdk` is a dependency of a scaffolded plugin project, by design (the deployed container never needs the CLI) — `@aivin-labs/cli` is meant to be installed globally on your own machine, not per-project. |
229
+
230
+ ## See also
231
+
232
+ - [CLI.md](./CLI.md) — every `aivin` command, option, and environment variable
233
+ - [SDK docs](https://github.com/aivin-labs/AIVIN-SDK/tree/main/docs) — everything your handler can call, `manifest.json`'s full field reference, `ctx`, examples
234
+ - [ARCHITECTURE.md (sdk repo)](https://github.com/aivin-labs/AIVIN-SDK/blob/main/docs/ARCHITECTURE.md) — how the transport/runtime works, for the curious
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@aivin-labs/cli",
3
+ "version": "1.0.0",
4
+ "description": "aivin CLI - scaffold, run, and deploy Aivin plugins built on @aivin-labs/sdk",
5
+ "type": "module",
6
+ "bin": {
7
+ "aivin": "bin/cli.mjs"
8
+ },
9
+ "scripts": {
10
+ "lint": "eslint .",
11
+ "format": "prettier --write .",
12
+ "test": "node --test test/cli.validate.test.mjs"
13
+ },
14
+ "keywords": [
15
+ "aivin",
16
+ "plugin",
17
+ "cli",
18
+ "sdk",
19
+ "scaffold"
20
+ ],
21
+ "author": "Aivin Team",
22
+ "license": "MIT",
23
+ "dependencies": {
24
+ "@aivin-labs/sdk": "^1.1.0",
25
+ "axios": "^1.18.1",
26
+ "chalk": "^5.6.2",
27
+ "commander": "^15.0.0",
28
+ "dotenv": "^17.4.2",
29
+ "inquirer": "^14.0.2",
30
+ "socket.io-client": "^4.8.3",
31
+ "ws": "^8.18.0"
32
+ },
33
+ "devDependencies": {
34
+ "@eslint/js": "^10.0.1",
35
+ "eslint": "^10.8.0",
36
+ "eslint-config-prettier": "^10.1.8",
37
+ "globals": "^17.7.0",
38
+ "prettier": "^3.9.6"
39
+ },
40
+ "files": [
41
+ "bin/**/*",
42
+ "docs/**/*",
43
+ "README.md"
44
+ ],
45
+ "publishConfig": {
46
+ "access": "public"
47
+ },
48
+ "engines": {
49
+ "node": ">=22.0.0"
50
+ },
51
+ "repository": {
52
+ "type": "git",
53
+ "url": "git+https://github.com/aivin-labs/cli.git"
54
+ },
55
+ "bugs": {
56
+ "url": "https://github.com/aivin-labs/cli/issues"
57
+ },
58
+ "homepage": "https://github.com/aivin-labs/cli#readme"
59
+ }