@aivin-labs/cli 1.0.3 → 1.0.5
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/bin/cli.mjs +47 -7
- package/bin/lib/browserAutomation.mjs +117 -65
- package/bin/lib/browserTui.mjs +251 -0
- package/bin/lib/codegen.mjs +61 -5
- package/bin/lib/connectors.mjs +55 -21
- package/bin/lib/deploy.mjs +25 -2
- package/bin/lib/mcpProxy.mjs +140 -20
- package/bin/lib/mission.mjs +13 -1
- package/bin/lib/missionStream.mjs +44 -9
- package/bin/lib/pluginAuthResolve.mjs +127 -0
- package/bin/lib/pluginTrigger.mjs +235 -87
- package/bin/lib/store.mjs +16 -2
- package/bin/lib/tasks.mjs +52 -8
- package/bin/lib/util.mjs +34 -0
- package/docs/CLI.md +25 -0
- package/package.json +5 -2
package/bin/lib/tasks.mjs
CHANGED
|
@@ -161,10 +161,26 @@ export async function updateTaskById(id, options) {
|
|
|
161
161
|
console.log(chalk.gray(` Status: ${task.status}`));
|
|
162
162
|
}
|
|
163
163
|
|
|
164
|
-
|
|
164
|
+
// ✅ FIX: had no confirmation at all before - unlike every other destructive command in this CLI
|
|
165
|
+
// (`plugin delete`, `pluginstore rm`/`rm-node`), a typo'd id here deleted immediately with nothing
|
|
166
|
+
// to catch it. Same `-y/--yes` escape hatch for scripts/CI as those commands.
|
|
167
|
+
export async function deleteTaskById(id, options = {}) {
|
|
165
168
|
const serverUrl = missionServerUrl();
|
|
166
169
|
const authHeaders = missionAuthHeaders();
|
|
167
170
|
|
|
171
|
+
if (!options.yes) {
|
|
172
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY) {
|
|
173
|
+
throw new Error('Refusing to delete without confirmation in a non-interactive session - pass --yes to delete anyway.');
|
|
174
|
+
}
|
|
175
|
+
const { confirm } = await inquirer.prompt([
|
|
176
|
+
{ type: 'confirm', name: 'confirm', message: `Delete task "${id}"? This can't be undone.`, default: false },
|
|
177
|
+
]);
|
|
178
|
+
if (!confirm) {
|
|
179
|
+
console.log(chalk.gray('Cancelled.'));
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
168
184
|
try {
|
|
169
185
|
await axios.delete(`${serverUrl}/task/${id}/delete`, authHeaders);
|
|
170
186
|
} catch (error) {
|
|
@@ -175,6 +191,23 @@ export async function deleteTaskById(id) {
|
|
|
175
191
|
console.log(chalk.green(`✅ Task ${id} deleted.`));
|
|
176
192
|
}
|
|
177
193
|
|
|
194
|
+
/**
|
|
195
|
+
* Pure assembly of `POST /task/create`'s body, split out of createTask() so it's unit-testable
|
|
196
|
+
* without stubbing axios/inquirer. Backend's TaskService._sanitizeCreateTaskInput whitelists
|
|
197
|
+
* `description`, not `content` - sending the wrong key here used to look like success (200 + a
|
|
198
|
+
* task id back) while silently dropping the user's actual text, which is exactly the kind of drift
|
|
199
|
+
* a regression test on this function's output shape catches going forward.
|
|
200
|
+
*/
|
|
201
|
+
export function buildCreateTaskPayload(description, workspaceId, options = {}) {
|
|
202
|
+
return {
|
|
203
|
+
title: description.length > 80 ? `${description.slice(0, 77)}...` : description,
|
|
204
|
+
description,
|
|
205
|
+
workspace_id: workspaceId,
|
|
206
|
+
project_id: options.project,
|
|
207
|
+
assign_id: options.assignee,
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
|
|
178
211
|
export async function createTask(description, options) {
|
|
179
212
|
const serverUrl = missionServerUrl();
|
|
180
213
|
const authHeaders = missionAuthHeaders();
|
|
@@ -188,13 +221,7 @@ export async function createTask(description, options) {
|
|
|
188
221
|
try {
|
|
189
222
|
response = await axios.post(
|
|
190
223
|
`${serverUrl}/task/create`,
|
|
191
|
-
|
|
192
|
-
title: description.length > 80 ? `${description.slice(0, 77)}...` : description,
|
|
193
|
-
content: description,
|
|
194
|
-
workspace_id: workspace.id || workspace._id,
|
|
195
|
-
project_id: options.project,
|
|
196
|
-
assign_id: options.assignee,
|
|
197
|
-
},
|
|
224
|
+
buildCreateTaskPayload(description, workspace.id || workspace._id, options),
|
|
198
225
|
authHeaders,
|
|
199
226
|
);
|
|
200
227
|
} catch (error) {
|
|
@@ -336,9 +363,26 @@ export async function updateProjectCmd(projectId, options) {
|
|
|
336
363
|
console.log(chalk.green(`✅ Project ${projectId} updated.`));
|
|
337
364
|
}
|
|
338
365
|
|
|
366
|
+
// ✅ FIX: had no confirmation at all before, and deleting a project is more consequential than
|
|
367
|
+
// deleting a single task (its tasks go with it) - same missing-protection issue as deleteTaskById
|
|
368
|
+
// above, same `-y/--yes` fix.
|
|
339
369
|
export async function deleteProjectCmd(projectId, options) {
|
|
340
370
|
const serverUrl = missionServerUrl();
|
|
341
371
|
const authHeaders = missionAuthHeaders();
|
|
372
|
+
|
|
373
|
+
if (!options.yes) {
|
|
374
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY) {
|
|
375
|
+
throw new Error('Refusing to delete without confirmation in a non-interactive session - pass --yes to delete anyway.');
|
|
376
|
+
}
|
|
377
|
+
const { confirm } = await inquirer.prompt([
|
|
378
|
+
{ type: 'confirm', name: 'confirm', message: `Delete project "${projectId}"? Its tasks go with it. This can't be undone.`, default: false },
|
|
379
|
+
]);
|
|
380
|
+
if (!confirm) {
|
|
381
|
+
console.log(chalk.gray('Cancelled.'));
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
342
386
|
const workspace = await resolveWorkspace(serverUrl, authHeaders, options.workspace);
|
|
343
387
|
await deleteProjectById(serverUrl, authHeaders, { workspaceId: workspace.id || workspace._id, projectId });
|
|
344
388
|
console.log(chalk.green(`✅ Project ${projectId} deleted.`));
|
package/bin/lib/util.mjs
CHANGED
|
@@ -2,6 +2,14 @@ import chalk from 'chalk';
|
|
|
2
2
|
import readline from 'readline';
|
|
3
3
|
import inquirer from 'inquirer';
|
|
4
4
|
|
|
5
|
+
// ✅ FIX: several axios calls across the CLI (store.mjs, connectors.mjs, deploy.mjs's main deploy
|
|
6
|
+
// POST) had no `timeout` at all - a network glitch/overloaded backend left the spinner spinning
|
|
7
|
+
// forever with no way out short of Ctrl+C, which is especially costly for a call like `connector
|
|
8
|
+
// register` where the whole interactive form (including a typed-in OAuth client_secret) would have
|
|
9
|
+
// to be re-entered from scratch afterwards. A generous but finite default so a genuinely slow-but-
|
|
10
|
+
// alive backend still succeeds, while a truly hung connection eventually surfaces as a normal error.
|
|
11
|
+
export const DEFAULT_API_TIMEOUT_MS = 30000;
|
|
12
|
+
|
|
5
13
|
// Same spinner deployPlugin has always had, factored out so other long-running network calls
|
|
6
14
|
// (AI codegen, connector register) get the same "still working, not hung" feedback instead of a
|
|
7
15
|
// static line that just sits there for however many seconds the request takes.
|
|
@@ -25,6 +33,32 @@ export async function withSpinner(label, fn) {
|
|
|
25
33
|
}
|
|
26
34
|
}
|
|
27
35
|
|
|
36
|
+
// Same as withSpinner but also renders a stage/percent readout that changes over time — for calls
|
|
37
|
+
// where the backend publishes realtime progress (e.g. `plugin trigger`'s cold-start Docker install,
|
|
38
|
+
// which can take 60-150s+ with zero feedback otherwise). `getCurrent()` is polled every tick and
|
|
39
|
+
// should return the latest `{ stage, percent, message }` received (or null before anything arrives).
|
|
40
|
+
export async function withProgressSpinner(label, getCurrent, fn) {
|
|
41
|
+
if (!process.stdout.isTTY) {
|
|
42
|
+
console.log(chalk.blue(`${label}...`));
|
|
43
|
+
return fn();
|
|
44
|
+
}
|
|
45
|
+
const frames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
|
|
46
|
+
let i = 0;
|
|
47
|
+
const timer = setInterval(() => {
|
|
48
|
+
const current = getCurrent?.();
|
|
49
|
+
const suffix = current?.percent != null ? ` ${current.message || current.stage} ${current.percent}%` : '...';
|
|
50
|
+
process.stdout.write(`\r${chalk.cyan(frames[i])} ${label}${suffix}`);
|
|
51
|
+
i = (i + 1) % frames.length;
|
|
52
|
+
}, 100);
|
|
53
|
+
try {
|
|
54
|
+
return await fn();
|
|
55
|
+
} finally {
|
|
56
|
+
clearInterval(timer);
|
|
57
|
+
readline.cursorTo(process.stdout, 0);
|
|
58
|
+
readline.clearLine(process.stdout, 0);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
28
62
|
// Positional CLI args are declared optional ([arg]) everywhere, not required (<arg>), so Commander
|
|
29
63
|
// never hard-fails before the action() runs - every command instead calls this to fill a missing
|
|
30
64
|
// value interactively. Falls back to throwing `usage` when there's no TTY to prompt on (scripts/
|
package/docs/CLI.md
CHANGED
|
@@ -508,6 +508,8 @@ Options:
|
|
|
508
508
|
--agent <id> Agent id to run as, if the plugin needs one for
|
|
509
509
|
HIL/confirm behavior to be accurate
|
|
510
510
|
--watch-logs Also stream the chosen plugin's own live console output inline
|
|
511
|
+
--no-auth-prompt Don't offer to connect/configure a missing connector
|
|
512
|
+
interactively - just print the needs_auth result and exit
|
|
511
513
|
--save Write this run's result to .test/trigger/<ts>.json
|
|
512
514
|
--compare <file> Diff this run against a previously --save'd file
|
|
513
515
|
```
|
|
@@ -543,6 +545,8 @@ Options:
|
|
|
543
545
|
needed. Requires permission to view that plugin's logs;
|
|
544
546
|
most store plugins from other orgs just fall back to
|
|
545
547
|
the REST result only.
|
|
548
|
+
--no-auth-prompt Don't offer to connect/configure a missing connector
|
|
549
|
+
interactively - just print the needs_auth result and exit
|
|
546
550
|
--save Write this run's result to .test/trigger/<ts>.json
|
|
547
551
|
--compare <file> Diff this run against a previously --save'd file
|
|
548
552
|
```
|
|
@@ -599,6 +603,27 @@ print `(--watch-logs: no live console output - ...)` and fall back to the REST r
|
|
|
599
603
|
no way around that from the CLI, raw container stdout isn't something the platform exposes across
|
|
600
604
|
org boundaries.
|
|
601
605
|
|
|
606
|
+
### Missing a connector? `trigger` sets it up for you, right there
|
|
607
|
+
|
|
608
|
+
If the plugin needs a connector (OAuth account, or a plain credential form like SMTP
|
|
609
|
+
host/user/pass) that isn't configured yet, `/plugins/execute` comes back `needs_auth` instead of
|
|
610
|
+
running. In an interactive terminal, `trigger`/`ask` catch that and offer to fix it on the spot
|
|
611
|
+
instead of just printing the failure and making you go set it up in the web app:
|
|
612
|
+
|
|
613
|
+
- **OAuth connector** - asks "Open your browser to connect now?", then opens the same
|
|
614
|
+
authorize-flow the web app's "Connect" button uses (falls back to printing the URL if it can't
|
|
615
|
+
launch a browser), and polls in the background until you've finished. No timeout hunting - it
|
|
616
|
+
waits up to 3 minutes, then retries the trigger automatically.
|
|
617
|
+
- **Credential-form connector** (SMTP, or any custom `credential_form` connector registered via
|
|
618
|
+
`aivin connector register`) - prompts for each declared field right in the terminal (masked for
|
|
619
|
+
`secret` fields), saves it, then retries.
|
|
620
|
+
|
|
621
|
+
Either way, you get exactly one automatic retry after setup - if it still needs auth after that
|
|
622
|
+
(e.g. you declined, or the OAuth flow timed out), the `needs_auth` result just prints as-is. Pass
|
|
623
|
+
`--no-auth-prompt` to skip all of this and always just print the result (useful for scripts/CI,
|
|
624
|
+
where there's no one to answer the prompt anyway - it's also skipped automatically whenever stdin/
|
|
625
|
+
stdout isn't a real TTY).
|
|
626
|
+
|
|
602
627
|
### Turning ad-hoc tries into a regression check: `--save` / `--compare`
|
|
603
628
|
|
|
604
629
|
```bash
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aivin-labs/cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "aivin CLI - scaffold, run, and deploy Aivin plugins built on @aivin-labs/sdk",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -21,12 +21,15 @@
|
|
|
21
21
|
"author": "Aivin Team",
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@aivin-labs/sdk": "^1.1.
|
|
24
|
+
"@aivin-labs/sdk": "^1.1.2",
|
|
25
25
|
"axios": "^1.18.1",
|
|
26
26
|
"chalk": "^5.6.2",
|
|
27
27
|
"commander": "^15.0.0",
|
|
28
28
|
"dotenv": "^17.4.2",
|
|
29
|
+
"ink": "^7.1.1",
|
|
30
|
+
"ink-text-input": "^6.0.0",
|
|
29
31
|
"inquirer": "^14.0.2",
|
|
32
|
+
"react": "^19.2.8",
|
|
30
33
|
"socket.io-client": "^4.8.3",
|
|
31
34
|
"ws": "^8.18.0"
|
|
32
35
|
},
|