@agentuity/cli 1.0.0 → 1.0.2
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/AGENTS.md +40 -24
- package/bin/cli.ts +47 -22
- package/dist/agent-detection.d.ts +23 -38
- package/dist/agent-detection.d.ts.map +1 -1
- package/dist/agent-detection.js +412 -153
- package/dist/agent-detection.js.map +1 -1
- package/dist/ai-help.d.ts +23 -0
- package/dist/ai-help.d.ts.map +1 -0
- package/dist/ai-help.js +328 -0
- package/dist/ai-help.js.map +1 -0
- package/dist/api.js +1 -1
- package/dist/api.js.map +1 -1
- package/dist/auth.d.ts +10 -1
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +176 -16
- package/dist/auth.js.map +1 -1
- package/dist/banner.d.ts.map +1 -1
- package/dist/banner.js +5 -0
- package/dist/banner.js.map +1 -1
- package/dist/cache/agent-intro.d.ts +13 -0
- package/dist/cache/agent-intro.d.ts.map +1 -0
- package/dist/cache/agent-intro.js +54 -0
- package/dist/cache/agent-intro.js.map +1 -0
- package/dist/cache/index.d.ts +1 -0
- package/dist/cache/index.d.ts.map +1 -1
- package/dist/cache/index.js +1 -0
- package/dist/cache/index.js.map +1 -1
- package/dist/cache/resource-region.d.ts +3 -2
- package/dist/cache/resource-region.d.ts.map +1 -1
- package/dist/cache/resource-region.js +13 -4
- package/dist/cache/resource-region.js.map +1 -1
- package/dist/catalyst.d.ts +7 -0
- package/dist/catalyst.d.ts.map +1 -0
- package/dist/catalyst.js +15 -0
- package/dist/catalyst.js.map +1 -0
- package/dist/cli.d.ts +12 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +290 -67
- package/dist/cli.js.map +1 -1
- package/dist/cmd/ai/detect.d.ts +3 -0
- package/dist/cmd/ai/detect.d.ts.map +1 -0
- package/dist/cmd/ai/detect.js +49 -0
- package/dist/cmd/ai/detect.js.map +1 -0
- package/dist/cmd/ai/index.d.ts.map +1 -1
- package/dist/cmd/ai/index.js +11 -1
- package/dist/cmd/ai/index.js.map +1 -1
- package/dist/cmd/ai/intro.d.ts +7 -0
- package/dist/cmd/ai/intro.d.ts.map +1 -0
- package/dist/cmd/ai/intro.js +141 -0
- package/dist/cmd/ai/intro.js.map +1 -0
- package/dist/cmd/ai/opencode/run.d.ts.map +1 -1
- package/dist/cmd/ai/opencode/run.js +5 -0
- package/dist/cmd/ai/opencode/run.js.map +1 -1
- package/dist/cmd/build/ast.d.ts.map +1 -1
- package/dist/cmd/build/ast.js +79 -0
- package/dist/cmd/build/ast.js.map +1 -1
- package/dist/cmd/build/vite/bun-dev-server.d.ts.map +1 -1
- package/dist/cmd/build/vite/bun-dev-server.js +2 -0
- package/dist/cmd/build/vite/bun-dev-server.js.map +1 -1
- package/dist/cmd/build/vite/docs-generator.d.ts.map +1 -1
- package/dist/cmd/build/vite/docs-generator.js +15 -1
- package/dist/cmd/build/vite/docs-generator.js.map +1 -1
- package/dist/cmd/build/vite/env-types-generator.d.ts +26 -0
- package/dist/cmd/build/vite/env-types-generator.d.ts.map +1 -0
- package/dist/cmd/build/vite/env-types-generator.js +110 -0
- package/dist/cmd/build/vite/env-types-generator.js.map +1 -0
- package/dist/cmd/build/vite/index.d.ts +2 -0
- package/dist/cmd/build/vite/index.d.ts.map +1 -1
- package/dist/cmd/build/vite/index.js +12 -1
- package/dist/cmd/build/vite/index.js.map +1 -1
- package/dist/cmd/build/vite/public-asset-path-plugin.d.ts.map +1 -1
- package/dist/cmd/build/vite/public-asset-path-plugin.js.map +1 -1
- package/dist/cmd/build/vite/vite-builder.d.ts +2 -0
- package/dist/cmd/build/vite/vite-builder.d.ts.map +1 -1
- package/dist/cmd/build/vite/vite-builder.js +10 -1
- package/dist/cmd/build/vite/vite-builder.js.map +1 -1
- package/dist/cmd/cloud/db/create.js.map +1 -1
- package/dist/cmd/cloud/db/delete.js.map +1 -1
- package/dist/cmd/cloud/db/get.d.ts.map +1 -1
- package/dist/cmd/cloud/db/get.js +27 -12
- package/dist/cmd/cloud/db/get.js.map +1 -1
- package/dist/cmd/cloud/deploy-fork.d.ts.map +1 -1
- package/dist/cmd/cloud/deploy-fork.js +2 -0
- package/dist/cmd/cloud/deploy-fork.js.map +1 -1
- package/dist/cmd/cloud/deploy.d.ts.map +1 -1
- package/dist/cmd/cloud/deploy.js +17 -0
- package/dist/cmd/cloud/deploy.js.map +1 -1
- package/dist/cmd/cloud/env/import.js.map +1 -1
- package/dist/cmd/cloud/env/list.js.map +1 -1
- package/dist/cmd/cloud/env/push.js.map +1 -1
- package/dist/cmd/cloud/keyvalue/util.d.ts.map +1 -1
- package/dist/cmd/cloud/keyvalue/util.js +3 -3
- package/dist/cmd/cloud/keyvalue/util.js.map +1 -1
- package/dist/cmd/cloud/machine/list.js +3 -3
- package/dist/cmd/cloud/machine/list.js.map +1 -1
- package/dist/cmd/cloud/region/index.js.map +1 -1
- package/dist/cmd/cloud/region-lookup.d.ts +7 -4
- package/dist/cmd/cloud/region-lookup.d.ts.map +1 -1
- package/dist/cmd/cloud/region-lookup.js +59 -14
- package/dist/cmd/cloud/region-lookup.js.map +1 -1
- package/dist/cmd/cloud/sandbox/cp.d.ts.map +1 -1
- package/dist/cmd/cloud/sandbox/cp.js +7 -5
- package/dist/cmd/cloud/sandbox/cp.js.map +1 -1
- package/dist/cmd/cloud/sandbox/create.js +1 -1
- package/dist/cmd/cloud/sandbox/create.js.map +1 -1
- package/dist/cmd/cloud/sandbox/delete.d.ts.map +1 -1
- package/dist/cmd/cloud/sandbox/delete.js +8 -7
- package/dist/cmd/cloud/sandbox/delete.js.map +1 -1
- package/dist/cmd/cloud/sandbox/download.d.ts.map +1 -1
- package/dist/cmd/cloud/sandbox/download.js +7 -5
- package/dist/cmd/cloud/sandbox/download.js.map +1 -1
- package/dist/cmd/cloud/sandbox/env.d.ts.map +1 -1
- package/dist/cmd/cloud/sandbox/env.js +7 -5
- package/dist/cmd/cloud/sandbox/env.js.map +1 -1
- package/dist/cmd/cloud/sandbox/exec.d.ts.map +1 -1
- package/dist/cmd/cloud/sandbox/exec.js +7 -5
- package/dist/cmd/cloud/sandbox/exec.js.map +1 -1
- package/dist/cmd/cloud/sandbox/get.d.ts.map +1 -1
- package/dist/cmd/cloud/sandbox/get.js +12 -7
- package/dist/cmd/cloud/sandbox/get.js.map +1 -1
- package/dist/cmd/cloud/sandbox/list.d.ts.map +1 -1
- package/dist/cmd/cloud/sandbox/list.js +40 -63
- package/dist/cmd/cloud/sandbox/list.js.map +1 -1
- package/dist/cmd/cloud/sandbox/ls.d.ts.map +1 -1
- package/dist/cmd/cloud/sandbox/ls.js +7 -5
- package/dist/cmd/cloud/sandbox/ls.js.map +1 -1
- package/dist/cmd/cloud/sandbox/mkdir.d.ts.map +1 -1
- package/dist/cmd/cloud/sandbox/mkdir.js +7 -5
- package/dist/cmd/cloud/sandbox/mkdir.js.map +1 -1
- package/dist/cmd/cloud/sandbox/rm.d.ts.map +1 -1
- package/dist/cmd/cloud/sandbox/rm.js +7 -5
- package/dist/cmd/cloud/sandbox/rm.js.map +1 -1
- package/dist/cmd/cloud/sandbox/rmdir.d.ts.map +1 -1
- package/dist/cmd/cloud/sandbox/rmdir.js +7 -5
- package/dist/cmd/cloud/sandbox/rmdir.js.map +1 -1
- package/dist/cmd/cloud/sandbox/run.js +1 -1
- package/dist/cmd/cloud/sandbox/run.js.map +1 -1
- package/dist/cmd/cloud/sandbox/snapshot/build.js.map +1 -1
- package/dist/cmd/cloud/sandbox/snapshot/get.js.map +1 -1
- package/dist/cmd/cloud/sandbox/upload.d.ts.map +1 -1
- package/dist/cmd/cloud/sandbox/upload.js +7 -5
- package/dist/cmd/cloud/sandbox/upload.js.map +1 -1
- package/dist/cmd/cloud/sandbox/util.d.ts +2 -2
- package/dist/cmd/cloud/sandbox/util.d.ts.map +1 -1
- package/dist/cmd/cloud/sandbox/util.js +14 -13
- package/dist/cmd/cloud/sandbox/util.js.map +1 -1
- package/dist/cmd/cloud/ssh.d.ts.map +1 -1
- package/dist/cmd/cloud/ssh.js +3 -3
- package/dist/cmd/cloud/ssh.js.map +1 -1
- package/dist/cmd/cloud/storage/create.js.map +1 -1
- package/dist/cmd/cloud/storage/delete.js.map +1 -1
- package/dist/cmd/cloud/storage/get.d.ts.map +1 -1
- package/dist/cmd/cloud/storage/get.js +5 -11
- package/dist/cmd/cloud/storage/get.js.map +1 -1
- package/dist/cmd/cloud/storage/list.d.ts.map +1 -1
- package/dist/cmd/cloud/storage/list.js +6 -6
- package/dist/cmd/cloud/storage/list.js.map +1 -1
- package/dist/cmd/cloud/stream/create.d.ts.map +1 -1
- package/dist/cmd/cloud/stream/create.js +7 -4
- package/dist/cmd/cloud/stream/create.js.map +1 -1
- package/dist/cmd/cloud/stream/delete.d.ts.map +1 -1
- package/dist/cmd/cloud/stream/delete.js +25 -4
- package/dist/cmd/cloud/stream/delete.js.map +1 -1
- package/dist/cmd/cloud/stream/get.d.ts.map +1 -1
- package/dist/cmd/cloud/stream/get.js +91 -62
- package/dist/cmd/cloud/stream/get.js.map +1 -1
- package/dist/cmd/cloud/stream/list.d.ts.map +1 -1
- package/dist/cmd/cloud/stream/list.js +66 -38
- package/dist/cmd/cloud/stream/list.js.map +1 -1
- package/dist/cmd/cloud/stream/util.d.ts +20 -0
- package/dist/cmd/cloud/stream/util.d.ts.map +1 -1
- package/dist/cmd/cloud/stream/util.js +27 -3
- package/dist/cmd/cloud/stream/util.js.map +1 -1
- package/dist/cmd/cloud/vector/util.d.ts.map +1 -1
- package/dist/cmd/cloud/vector/util.js +3 -3
- package/dist/cmd/cloud/vector/util.js.map +1 -1
- package/dist/cmd/dev/index.js.map +1 -1
- package/dist/cmd/git/account/add.js.map +1 -1
- package/dist/cmd/git/list.js.map +1 -1
- package/dist/cmd/project/add/database.d.ts +2 -0
- package/dist/cmd/project/add/database.d.ts.map +1 -0
- package/dist/cmd/project/add/database.js +123 -0
- package/dist/cmd/project/add/database.js.map +1 -0
- package/dist/cmd/project/add/domain.d.ts +2 -0
- package/dist/cmd/project/add/domain.d.ts.map +1 -0
- package/dist/cmd/project/add/domain.js +152 -0
- package/dist/cmd/project/add/domain.js.map +1 -0
- package/dist/cmd/project/add/index.d.ts +2 -0
- package/dist/cmd/project/add/index.d.ts.map +1 -0
- package/dist/cmd/project/add/index.js +35 -0
- package/dist/cmd/project/add/index.js.map +1 -0
- package/dist/cmd/project/add/storage.d.ts +2 -0
- package/dist/cmd/project/add/storage.d.ts.map +1 -0
- package/dist/cmd/project/add/storage.js +123 -0
- package/dist/cmd/project/add/storage.js.map +1 -0
- package/dist/cmd/project/auth/init.js.map +1 -1
- package/dist/cmd/project/index.d.ts.map +1 -1
- package/dist/cmd/project/index.js +7 -0
- package/dist/cmd/project/index.js.map +1 -1
- package/dist/cmd/project/reconcile.d.ts.map +1 -1
- package/dist/cmd/project/reconcile.js +32 -0
- package/dist/cmd/project/reconcile.js.map +1 -1
- package/dist/cmd/support/report.js.map +1 -1
- package/dist/cmd/support/system.js +2 -2
- package/dist/cmd/support/system.js.map +1 -1
- package/dist/config.d.ts +6 -3
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +31 -7
- package/dist/config.js.map +1 -1
- package/dist/errors.d.ts +2 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +5 -0
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/repl.js +2 -1
- package/dist/repl.js.map +1 -1
- package/dist/tui/box.d.ts +3 -1
- package/dist/tui/box.d.ts.map +1 -1
- package/dist/tui/box.js +22 -7
- package/dist/tui/box.js.map +1 -1
- package/dist/tui/colors.d.ts +0 -3
- package/dist/tui/colors.d.ts.map +1 -1
- package/dist/tui/colors.js +76 -23
- package/dist/tui/colors.js.map +1 -1
- package/dist/tui/prompt.d.ts +2 -0
- package/dist/tui/prompt.d.ts.map +1 -1
- package/dist/tui/prompt.js +44 -3
- package/dist/tui/prompt.js.map +1 -1
- package/dist/tui/symbols.d.ts +0 -4
- package/dist/tui/symbols.d.ts.map +1 -1
- package/dist/tui/symbols.js +5 -0
- package/dist/tui/symbols.js.map +1 -1
- package/dist/tui.d.ts +8 -0
- package/dist/tui.d.ts.map +1 -1
- package/dist/tui.js +54 -9
- package/dist/tui.js.map +1 -1
- package/dist/types.d.ts +37 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -1
- package/dist/version-check.d.ts.map +1 -1
- package/dist/version-check.js +5 -0
- package/dist/version-check.js.map +1 -1
- package/package.json +6 -6
- package/src/agent-detection.ts +457 -160
- package/src/ai-help.ts +391 -0
- package/src/api.ts +1 -1
- package/src/auth.ts +226 -17
- package/src/banner.ts +5 -0
- package/src/cache/agent-intro.ts +61 -0
- package/src/cache/index.ts +2 -0
- package/src/cache/resource-region.ts +28 -7
- package/src/catalyst.ts +16 -0
- package/src/cli.ts +375 -93
- package/src/cmd/ai/detect.ts +52 -0
- package/src/cmd/ai/index.ts +11 -1
- package/src/cmd/ai/intro.ts +154 -0
- package/src/cmd/ai/opencode/run.ts +5 -0
- package/src/cmd/build/ast.ts +97 -0
- package/src/cmd/build/vite/bun-dev-server.ts +2 -0
- package/src/cmd/build/vite/docs-generator.ts +15 -1
- package/src/cmd/build/vite/env-types-generator.ts +145 -0
- package/src/cmd/build/vite/index.ts +15 -0
- package/src/cmd/build/vite/public-asset-path-plugin.ts +8 -2
- package/src/cmd/build/vite/vite-builder.ts +31 -11
- package/src/cmd/cloud/db/create.ts +16 -16
- package/src/cmd/cloud/db/delete.ts +19 -19
- package/src/cmd/cloud/db/get.ts +32 -17
- package/src/cmd/cloud/deploy-fork.ts +2 -0
- package/src/cmd/cloud/deploy.ts +17 -0
- package/src/cmd/cloud/env/import.ts +6 -6
- package/src/cmd/cloud/env/list.ts +11 -11
- package/src/cmd/cloud/env/push.ts +6 -6
- package/src/cmd/cloud/keyvalue/util.ts +3 -3
- package/src/cmd/cloud/machine/list.ts +3 -3
- package/src/cmd/cloud/region/index.ts +3 -3
- package/src/cmd/cloud/region-lookup.ts +82 -22
- package/src/cmd/cloud/sandbox/cp.ts +9 -4
- package/src/cmd/cloud/sandbox/create.ts +1 -1
- package/src/cmd/cloud/sandbox/delete.ts +10 -7
- package/src/cmd/cloud/sandbox/download.ts +8 -5
- package/src/cmd/cloud/sandbox/env.ts +8 -5
- package/src/cmd/cloud/sandbox/exec.ts +10 -5
- package/src/cmd/cloud/sandbox/get.ts +13 -7
- package/src/cmd/cloud/sandbox/list.ts +47 -73
- package/src/cmd/cloud/sandbox/ls.ts +9 -5
- package/src/cmd/cloud/sandbox/mkdir.ts +9 -5
- package/src/cmd/cloud/sandbox/rm.ts +9 -5
- package/src/cmd/cloud/sandbox/rmdir.ts +9 -5
- package/src/cmd/cloud/sandbox/run.ts +1 -1
- package/src/cmd/cloud/sandbox/snapshot/build.ts +31 -31
- package/src/cmd/cloud/sandbox/snapshot/get.ts +17 -17
- package/src/cmd/cloud/sandbox/upload.ts +8 -5
- package/src/cmd/cloud/sandbox/util.ts +15 -14
- package/src/cmd/cloud/ssh.ts +2 -4
- package/src/cmd/cloud/storage/create.ts +16 -16
- package/src/cmd/cloud/storage/delete.ts +19 -19
- package/src/cmd/cloud/storage/get.ts +5 -16
- package/src/cmd/cloud/storage/list.ts +12 -6
- package/src/cmd/cloud/stream/create.ts +8 -4
- package/src/cmd/cloud/stream/delete.ts +28 -4
- package/src/cmd/cloud/stream/get.ts +102 -64
- package/src/cmd/cloud/stream/list.ts +76 -44
- package/src/cmd/cloud/stream/util.ts +39 -3
- package/src/cmd/cloud/vector/util.ts +3 -3
- package/src/cmd/dev/index.ts +4 -4
- package/src/cmd/git/account/add.ts +5 -5
- package/src/cmd/git/list.ts +7 -7
- package/src/cmd/project/add/database.ts +145 -0
- package/src/cmd/project/add/domain.ts +181 -0
- package/src/cmd/project/add/index.ts +35 -0
- package/src/cmd/project/add/storage.ts +147 -0
- package/src/cmd/project/auth/init.ts +6 -6
- package/src/cmd/project/index.ts +7 -0
- package/src/cmd/project/reconcile.ts +40 -0
- package/src/cmd/support/report.ts +5 -5
- package/src/cmd/support/system.ts +2 -2
- package/src/config.ts +40 -12
- package/src/errors.ts +7 -0
- package/src/index.ts +11 -0
- package/src/repl.ts +4 -1
- package/src/tui/box.ts +24 -9
- package/src/tui/colors.ts +83 -26
- package/src/tui/prompt.ts +55 -3
- package/src/tui/symbols.ts +6 -0
- package/src/tui.ts +55 -9
- package/src/types.ts +46 -2
- package/src/version-check.ts +6 -0
package/src/ai-help.ts
ADDED
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI Help Generator - dashdash specification implementation
|
|
3
|
+
*
|
|
4
|
+
* Generates AI-optimized help output in dashdash format (https://github.com/visionik/dashdash)
|
|
5
|
+
* for improved discoverability and usability by AI agents.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { CLISchema, SchemaCommand } from './schema-generator';
|
|
9
|
+
|
|
10
|
+
export interface DashdashConfig {
|
|
11
|
+
name: string;
|
|
12
|
+
description: string;
|
|
13
|
+
accessLevel: 'read' | 'browse' | 'interact' | 'full';
|
|
14
|
+
webUrl: string;
|
|
15
|
+
apiUrl: string;
|
|
16
|
+
docsUrl: string;
|
|
17
|
+
mcpUrl?: string;
|
|
18
|
+
homepage: string;
|
|
19
|
+
repository: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const DEFAULT_CONFIG: DashdashConfig = {
|
|
23
|
+
name: 'agentuity',
|
|
24
|
+
description: `CLI for building, deploying, and managing AI agents on the Agentuity platform.
|
|
25
|
+
Use when user asks to create agents, deploy projects, or interact with Agentuity cloud services.`,
|
|
26
|
+
accessLevel: 'interact',
|
|
27
|
+
webUrl: 'https://app.agentuity.com',
|
|
28
|
+
apiUrl: 'https://api.agentuity.com',
|
|
29
|
+
docsUrl: 'https://agentuity.dev',
|
|
30
|
+
homepage: 'https://agentuity.com',
|
|
31
|
+
repository: 'https://github.com/agentuity/sdk',
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Generate dashdash-compliant AI help output
|
|
36
|
+
*/
|
|
37
|
+
export function generateAIHelp(schema: CLISchema, config: DashdashConfig = DEFAULT_CONFIG): string {
|
|
38
|
+
const frontMatter = buildFrontMatter(schema, config);
|
|
39
|
+
const content = buildContent(schema, config);
|
|
40
|
+
|
|
41
|
+
return `${frontMatter}\n${content}`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Build YAML front matter per dashdash spec
|
|
46
|
+
*/
|
|
47
|
+
function buildFrontMatter(schema: CLISchema, config: DashdashConfig): string {
|
|
48
|
+
const lines = [
|
|
49
|
+
'---',
|
|
50
|
+
`name: ${config.name}`,
|
|
51
|
+
'description: >',
|
|
52
|
+
...config.description.split('\n').map((line) => ` ${line.trim()}`),
|
|
53
|
+
'',
|
|
54
|
+
'spec-url: https://github.com/visionik/dashdash',
|
|
55
|
+
'spec-version: 0.2.0',
|
|
56
|
+
'',
|
|
57
|
+
'subcommand-help: true',
|
|
58
|
+
`access-level: ${config.accessLevel}`,
|
|
59
|
+
'',
|
|
60
|
+
`web-url: ${config.webUrl}`,
|
|
61
|
+
`api-url: ${config.apiUrl}`,
|
|
62
|
+
`mcp-url: ${config.mcpUrl ?? 'none'}`,
|
|
63
|
+
'',
|
|
64
|
+
'install:',
|
|
65
|
+
' npm: "@agentuity/cli"',
|
|
66
|
+
' bun: "@agentuity/cli"',
|
|
67
|
+
'',
|
|
68
|
+
'requires:',
|
|
69
|
+
' auth:',
|
|
70
|
+
' - api-key',
|
|
71
|
+
' env:',
|
|
72
|
+
' - AGENTUITY_API_KEY',
|
|
73
|
+
'',
|
|
74
|
+
'invocation:',
|
|
75
|
+
' model-invocable: true',
|
|
76
|
+
' user-invocable: true',
|
|
77
|
+
'',
|
|
78
|
+
`homepage: ${config.homepage}`,
|
|
79
|
+
`repository: ${config.repository}`,
|
|
80
|
+
`content-version: ${schema.version}`,
|
|
81
|
+
'---',
|
|
82
|
+
];
|
|
83
|
+
|
|
84
|
+
return lines.join('\n');
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Build markdown content
|
|
89
|
+
*/
|
|
90
|
+
function buildContent(schema: CLISchema, config: DashdashConfig): string {
|
|
91
|
+
const sections = [
|
|
92
|
+
buildHeader(config),
|
|
93
|
+
buildWhenToUse(),
|
|
94
|
+
buildQuickReference(schema),
|
|
95
|
+
buildCommandReference(schema),
|
|
96
|
+
buildGlobalOptions(schema),
|
|
97
|
+
buildAuthentication(),
|
|
98
|
+
buildExitCodes(schema),
|
|
99
|
+
buildAlternativeAccess(config),
|
|
100
|
+
];
|
|
101
|
+
|
|
102
|
+
return sections.join('\n\n');
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function buildHeader(config: DashdashConfig): string {
|
|
106
|
+
return `# ${config.name}
|
|
107
|
+
|
|
108
|
+
> ${config.description.split('\n')[0]?.trim()}`;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function buildWhenToUse(): string {
|
|
112
|
+
return `## When to Use
|
|
113
|
+
|
|
114
|
+
Use this CLI when the user asks to:
|
|
115
|
+
- Create, build, or deploy AI agents
|
|
116
|
+
- Manage Agentuity projects and organizations
|
|
117
|
+
- Access cloud services (KV, Vector, Postgres, Storage, Sandboxes)
|
|
118
|
+
- Debug or troubleshoot agent deployments
|
|
119
|
+
- Run agents locally in development mode
|
|
120
|
+
- Manage environment variables and secrets
|
|
121
|
+
- View deployment logs or rollback deployments
|
|
122
|
+
|
|
123
|
+
Do NOT use this CLI for:
|
|
124
|
+
- Non-Agentuity projects or general Node.js/Bun development
|
|
125
|
+
- General file operations (use filesystem tools instead)
|
|
126
|
+
- Non-AI/agent related tasks
|
|
127
|
+
- Direct database queries (use the SDK or cloud console)`;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Build Quick Reference with 15-20 most common operations
|
|
132
|
+
*/
|
|
133
|
+
function buildQuickReference(schema: CLISchema): string {
|
|
134
|
+
const quickCommands = collectQuickReferenceCommands(schema);
|
|
135
|
+
|
|
136
|
+
const lines = ['## Quick Reference', ''];
|
|
137
|
+
|
|
138
|
+
for (const cmd of quickCommands) {
|
|
139
|
+
lines.push(`- **${cmd.label}:** \`${cmd.command}\``);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return lines.join('\n');
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
interface QuickCommand {
|
|
146
|
+
label: string;
|
|
147
|
+
command: string;
|
|
148
|
+
priority: number;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Collect the most important commands for quick reference
|
|
153
|
+
*/
|
|
154
|
+
function collectQuickReferenceCommands(schema: CLISchema): QuickCommand[] {
|
|
155
|
+
const commands: QuickCommand[] = [];
|
|
156
|
+
|
|
157
|
+
// Define priority commands explicitly for better curation
|
|
158
|
+
const priorityCommands: Array<{ path: string; label: string; priority: number }> = [
|
|
159
|
+
{ path: 'login', label: 'Login', priority: 1 },
|
|
160
|
+
{ path: 'project create', label: 'Create project', priority: 2 },
|
|
161
|
+
{ path: 'dev', label: 'Run locally', priority: 3 },
|
|
162
|
+
{ path: 'deploy', label: 'Deploy', priority: 4 },
|
|
163
|
+
{ path: 'cloud logs', label: 'View logs', priority: 5 },
|
|
164
|
+
{ path: 'cloud sandbox list', label: 'List sandboxes', priority: 6 },
|
|
165
|
+
{ path: 'cloud sandbox create', label: 'Create sandbox', priority: 7 },
|
|
166
|
+
{ path: 'cloud sandbox exec', label: 'Execute in sandbox', priority: 8 },
|
|
167
|
+
{ path: 'cloud kv get', label: 'KV get', priority: 9 },
|
|
168
|
+
{ path: 'cloud kv set', label: 'KV set', priority: 10 },
|
|
169
|
+
{ path: 'cloud vector search', label: 'Vector search', priority: 11 },
|
|
170
|
+
{ path: 'cloud db list', label: 'List databases', priority: 12 },
|
|
171
|
+
{ path: 'cloud db exec', label: 'Execute SQL', priority: 13 },
|
|
172
|
+
{ path: 'env list', label: 'List env vars', priority: 14 },
|
|
173
|
+
{ path: 'env set', label: 'Set env var', priority: 15 },
|
|
174
|
+
{ path: 'cloud deployment list', label: 'List deployments', priority: 16 },
|
|
175
|
+
{ path: 'cloud deployment rollback', label: 'Rollback deployment', priority: 17 },
|
|
176
|
+
{ path: 'project list', label: 'List projects', priority: 18 },
|
|
177
|
+
{ path: 'auth whoami', label: 'Show current user', priority: 19 },
|
|
178
|
+
{ path: 'version', label: 'Show version', priority: 20 },
|
|
179
|
+
];
|
|
180
|
+
|
|
181
|
+
// Build command signatures from schema
|
|
182
|
+
const commandMap = buildCommandMap(schema.commands);
|
|
183
|
+
|
|
184
|
+
for (const pc of priorityCommands) {
|
|
185
|
+
const schemaCmd = commandMap.get(pc.path);
|
|
186
|
+
if (schemaCmd) {
|
|
187
|
+
const signature = buildCommandSignature(pc.path, schemaCmd);
|
|
188
|
+
commands.push({
|
|
189
|
+
label: pc.label,
|
|
190
|
+
command: `agentuity ${signature}`,
|
|
191
|
+
priority: pc.priority,
|
|
192
|
+
});
|
|
193
|
+
} else {
|
|
194
|
+
// Fallback for commands that might not be in schema yet
|
|
195
|
+
commands.push({
|
|
196
|
+
label: pc.label,
|
|
197
|
+
command: `agentuity ${pc.path}`,
|
|
198
|
+
priority: pc.priority,
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return commands.sort((a, b) => a.priority - b.priority);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Build a map of command paths to their schema definitions
|
|
208
|
+
*/
|
|
209
|
+
function buildCommandMap(
|
|
210
|
+
commands: SchemaCommand[],
|
|
211
|
+
prefix: string = ''
|
|
212
|
+
): Map<string, SchemaCommand> {
|
|
213
|
+
const map = new Map<string, SchemaCommand>();
|
|
214
|
+
|
|
215
|
+
for (const cmd of commands) {
|
|
216
|
+
const path = prefix ? `${prefix} ${cmd.name}` : cmd.name;
|
|
217
|
+
map.set(path, cmd);
|
|
218
|
+
|
|
219
|
+
if (cmd.subcommands) {
|
|
220
|
+
const subMap = buildCommandMap(cmd.subcommands, path);
|
|
221
|
+
for (const [subPath, subCmd] of subMap) {
|
|
222
|
+
map.set(subPath, subCmd);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return map;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Build a command signature with arguments
|
|
232
|
+
*/
|
|
233
|
+
function buildCommandSignature(path: string, cmd: SchemaCommand): string {
|
|
234
|
+
let signature = path;
|
|
235
|
+
|
|
236
|
+
if (cmd.arguments) {
|
|
237
|
+
for (const arg of cmd.arguments) {
|
|
238
|
+
if (arg.variadic) {
|
|
239
|
+
signature += arg.required ? ` <${arg.name}...>` : ` [${arg.name}...]`;
|
|
240
|
+
} else {
|
|
241
|
+
signature += arg.required ? ` <${arg.name}>` : ` [${arg.name}]`;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
return signature;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Build full command reference
|
|
251
|
+
*/
|
|
252
|
+
function buildCommandReference(schema: CLISchema): string {
|
|
253
|
+
const lines = ['## Command Reference', ''];
|
|
254
|
+
|
|
255
|
+
for (const cmd of schema.commands) {
|
|
256
|
+
lines.push(...buildCommandSection(cmd, 'agentuity'));
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
return lines.join('\n');
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Build a command section recursively
|
|
264
|
+
*/
|
|
265
|
+
function buildCommandSection(cmd: SchemaCommand, prefix: string, depth: number = 3): string[] {
|
|
266
|
+
const lines: string[] = [];
|
|
267
|
+
const fullPath = `${prefix} ${cmd.name}`;
|
|
268
|
+
const heading = '#'.repeat(Math.min(depth, 6));
|
|
269
|
+
|
|
270
|
+
// Skip hidden/internal commands
|
|
271
|
+
if (cmd.tags?.includes('hidden') || cmd.skipSkill) {
|
|
272
|
+
return lines;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
lines.push(`${heading} ${fullPath}`);
|
|
276
|
+
lines.push('');
|
|
277
|
+
lines.push(cmd.description);
|
|
278
|
+
lines.push('');
|
|
279
|
+
|
|
280
|
+
// Arguments
|
|
281
|
+
if (cmd.arguments && cmd.arguments.length > 0) {
|
|
282
|
+
lines.push('**Arguments:**');
|
|
283
|
+
for (const arg of cmd.arguments) {
|
|
284
|
+
const req = arg.required ? '(required)' : '(optional)';
|
|
285
|
+
lines.push(`- \`${arg.name}\` ${req}${arg.description ? ` - ${arg.description}` : ''}`);
|
|
286
|
+
}
|
|
287
|
+
lines.push('');
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// Options
|
|
291
|
+
if (cmd.options && cmd.options.length > 0) {
|
|
292
|
+
lines.push('**Options:**');
|
|
293
|
+
for (const opt of cmd.options) {
|
|
294
|
+
const flag = `--${camelToKebab(opt.name)}`;
|
|
295
|
+
const defaultVal = opt.default !== undefined ? ` (default: ${JSON.stringify(opt.default)})` : '';
|
|
296
|
+
lines.push(`- \`${flag}\`${defaultVal}${opt.description ? ` - ${opt.description}` : ''}`);
|
|
297
|
+
}
|
|
298
|
+
lines.push('');
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// Requirements
|
|
302
|
+
const reqs: string[] = [];
|
|
303
|
+
if (cmd.requires?.auth) reqs.push('authentication');
|
|
304
|
+
if (cmd.requires?.project) reqs.push('project');
|
|
305
|
+
if (cmd.requires?.org) reqs.push('organization');
|
|
306
|
+
if (cmd.requires?.region) reqs.push('region');
|
|
307
|
+
|
|
308
|
+
if (reqs.length > 0) {
|
|
309
|
+
lines.push(`**Requires:** ${reqs.join(', ')}`);
|
|
310
|
+
lines.push('');
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// Examples
|
|
314
|
+
if (cmd.examples && cmd.examples.length > 0) {
|
|
315
|
+
lines.push('**Examples:**');
|
|
316
|
+
lines.push('```bash');
|
|
317
|
+
for (const ex of cmd.examples.slice(0, 3)) {
|
|
318
|
+
lines.push(`# ${ex.description}`);
|
|
319
|
+
lines.push(ex.command);
|
|
320
|
+
}
|
|
321
|
+
lines.push('```');
|
|
322
|
+
lines.push('');
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// Subcommands
|
|
326
|
+
if (cmd.subcommands && cmd.subcommands.length > 0) {
|
|
327
|
+
for (const sub of cmd.subcommands) {
|
|
328
|
+
lines.push(...buildCommandSection(sub, fullPath, depth + 1));
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
return lines;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Build global options section
|
|
337
|
+
*/
|
|
338
|
+
function buildGlobalOptions(schema: CLISchema): string {
|
|
339
|
+
const lines = ['## Global Options', '', 'These options can be used with any command:', ''];
|
|
340
|
+
|
|
341
|
+
for (const opt of schema.globalOptions) {
|
|
342
|
+
const flag = `--${camelToKebab(opt.name)}`;
|
|
343
|
+
const defaultVal = opt.default !== undefined ? ` (default: ${JSON.stringify(opt.default)})` : '';
|
|
344
|
+
lines.push(`- \`${flag}\`${defaultVal}${opt.description ? ` - ${opt.description}` : ''}`);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
return lines.join('\n');
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
function buildAuthentication(): string {
|
|
351
|
+
return `## Authentication
|
|
352
|
+
|
|
353
|
+
Most commands require authentication. Set the \`AGENTUITY_API_KEY\` environment variable or run:
|
|
354
|
+
|
|
355
|
+
\`\`\`bash
|
|
356
|
+
agentuity login
|
|
357
|
+
\`\`\`
|
|
358
|
+
|
|
359
|
+
To check your current authentication status:
|
|
360
|
+
|
|
361
|
+
\`\`\`bash
|
|
362
|
+
agentuity auth whoami
|
|
363
|
+
\`\`\``;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
function buildExitCodes(schema: CLISchema): string {
|
|
367
|
+
const lines = ['## Exit Codes', ''];
|
|
368
|
+
|
|
369
|
+
for (const [code, description] of Object.entries(schema.exitCodes)) {
|
|
370
|
+
lines.push(`- \`${code}\` - ${description}`);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
return lines.join('\n');
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
function buildAlternativeAccess(config: DashdashConfig): string {
|
|
377
|
+
return `## Alternative Access Methods
|
|
378
|
+
|
|
379
|
+
- **Web Console:** ${config.webUrl}
|
|
380
|
+
- **API Documentation:** ${config.docsUrl}`;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Convert camelCase to kebab-case
|
|
385
|
+
*/
|
|
386
|
+
function camelToKebab(str: string): string {
|
|
387
|
+
return str
|
|
388
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1-$2')
|
|
389
|
+
.replace(/([A-Z]+)([A-Z][a-z])/g, '$1-$2')
|
|
390
|
+
.toLowerCase();
|
|
391
|
+
}
|
package/src/api.ts
CHANGED
|
@@ -101,5 +101,5 @@ export function getGravityDevModeURL(region: string, config?: Config | null): st
|
|
|
101
101
|
if (config?.name === 'local') {
|
|
102
102
|
return 'grpc://gravity.agentuity.io:8443';
|
|
103
103
|
}
|
|
104
|
-
return
|
|
104
|
+
return 'grpc://devmode-us.agentuity.com';
|
|
105
105
|
}
|
package/src/auth.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import enquirer from 'enquirer';
|
|
2
2
|
import { getDefaultConfigPath, getAuth, saveConfig, loadConfig, saveOrgId } from './config';
|
|
3
|
+
import { getResourceInfo, type ResourceType } from './cache';
|
|
3
4
|
import { getCommand } from './command-prefix';
|
|
4
|
-
import type { CommandContext, AuthData } from './types';
|
|
5
|
+
import type { CommandContext, AuthData, Config } from './types';
|
|
5
6
|
import * as tui from './tui';
|
|
6
7
|
import { defaultProfileName } from './config';
|
|
7
8
|
import { listOrganizations } from '@agentuity/server';
|
|
@@ -11,6 +12,119 @@ export function isTTY(): boolean {
|
|
|
11
12
|
return process.stdin.isTTY === true && process.stdout.isTTY === true;
|
|
12
13
|
}
|
|
13
14
|
|
|
15
|
+
const ORG_ID_ENV_VAR = 'AGENTUITY_CLOUD_ORG_ID';
|
|
16
|
+
const NON_INTERACTIVE_ORG_ERROR =
|
|
17
|
+
'Cannot select organization in non-interactive mode. ' +
|
|
18
|
+
`Use --org-id, set ${ORG_ID_ENV_VAR}, or run interactively.`;
|
|
19
|
+
|
|
20
|
+
const RESOURCE_PREFIXES: Array<{ prefix: string; type: ResourceType }> = [
|
|
21
|
+
{ prefix: 'sbx_', type: 'sandbox' },
|
|
22
|
+
{ prefix: 'proj_', type: 'project' },
|
|
23
|
+
{ prefix: 'db_', type: 'db' },
|
|
24
|
+
{ prefix: 'deploy_', type: 'deployment' },
|
|
25
|
+
{ prefix: 'machine_', type: 'machine' },
|
|
26
|
+
{ prefix: 'que_', type: 'queue' },
|
|
27
|
+
{ prefix: 'vec_', type: 'vector' },
|
|
28
|
+
{ prefix: 'kv_', type: 'kv' },
|
|
29
|
+
{ prefix: 'stream_', type: 'stream' },
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
function getResourceTypeFromId(id: string): ResourceType | undefined {
|
|
33
|
+
for (const entry of RESOURCE_PREFIXES) {
|
|
34
|
+
if (id.startsWith(entry.prefix)) {
|
|
35
|
+
return entry.type;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function collectPrefixedIds(values?: Record<string, unknown> | unknown[]): string[] {
|
|
42
|
+
if (!values) {
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
const ids = new Set<string>();
|
|
46
|
+
const addValue = (value: unknown) => {
|
|
47
|
+
if (typeof value === 'string') {
|
|
48
|
+
const resourceType = getResourceTypeFromId(value);
|
|
49
|
+
if (resourceType) {
|
|
50
|
+
ids.add(value);
|
|
51
|
+
}
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (Array.isArray(value)) {
|
|
55
|
+
for (const entry of value) {
|
|
56
|
+
if (typeof entry === 'string') {
|
|
57
|
+
const resourceType = getResourceTypeFromId(entry);
|
|
58
|
+
if (resourceType) {
|
|
59
|
+
ids.add(entry);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
for (const value of Object.values(values)) {
|
|
67
|
+
addValue(value);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return Array.from(ids);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function hasPrefixedResourceId(
|
|
74
|
+
args?: Record<string, unknown> | unknown[],
|
|
75
|
+
opts?: Record<string, unknown> | unknown[]
|
|
76
|
+
): boolean {
|
|
77
|
+
return collectPrefixedIds(args).length > 0 || collectPrefixedIds(opts).length > 0;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async function resolveCachedOrgId(ctx: {
|
|
81
|
+
config: Config | null;
|
|
82
|
+
args?: Record<string, unknown> | unknown[];
|
|
83
|
+
opts?: Record<string, unknown> | unknown[];
|
|
84
|
+
}): Promise<string | undefined> {
|
|
85
|
+
const profileName = ctx.config?.name ?? defaultProfileName;
|
|
86
|
+
const candidateIds = [...collectPrefixedIds(ctx.args), ...collectPrefixedIds(ctx.opts)];
|
|
87
|
+
|
|
88
|
+
for (const candidateId of candidateIds) {
|
|
89
|
+
const resourceType = getResourceTypeFromId(candidateId);
|
|
90
|
+
if (!resourceType) {
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
const cachedInfo = await getResourceInfo(resourceType, profileName, candidateId);
|
|
94
|
+
if (cachedInfo?.orgId) {
|
|
95
|
+
return cachedInfo.orgId;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export async function resolveOrgIdWithoutPrompt(ctx: {
|
|
103
|
+
options: { orgId?: string };
|
|
104
|
+
config: Config | null;
|
|
105
|
+
args?: Record<string, unknown> | unknown[];
|
|
106
|
+
opts?: Record<string, unknown> | unknown[];
|
|
107
|
+
}): Promise<string | undefined> {
|
|
108
|
+
const { options, config, args, opts } = ctx;
|
|
109
|
+
const envOrgId = process.env[ORG_ID_ENV_VAR];
|
|
110
|
+
const flagOrgId = options.orgId && options.orgId !== envOrgId ? options.orgId : undefined;
|
|
111
|
+
|
|
112
|
+
if (flagOrgId) {
|
|
113
|
+
return flagOrgId;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (envOrgId) {
|
|
117
|
+
return envOrgId;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const preferredOrgId = config?.preferences?.orgId;
|
|
121
|
+
if (preferredOrgId) {
|
|
122
|
+
return preferredOrgId;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return resolveCachedOrgId({ config, args, opts });
|
|
126
|
+
}
|
|
127
|
+
|
|
14
128
|
export async function hasLoggedInBefore(): Promise<boolean> {
|
|
15
129
|
const configPath = getDefaultConfigPath();
|
|
16
130
|
return await Bun.file(configPath).exists();
|
|
@@ -231,11 +345,37 @@ export async function requireOrg(
|
|
|
231
345
|
ctx: CommandContext & { apiClient: APIClientType },
|
|
232
346
|
autoSelect?: boolean
|
|
233
347
|
): Promise<string> {
|
|
234
|
-
const { options, config, apiClient } = ctx
|
|
348
|
+
const { options, config, apiClient, args, opts } = ctx as CommandContext & {
|
|
349
|
+
apiClient: APIClientType;
|
|
350
|
+
args?: Record<string, unknown>;
|
|
351
|
+
opts?: Record<string, unknown>;
|
|
352
|
+
};
|
|
353
|
+
const interactive = isTTY();
|
|
354
|
+
const envOrgId = process.env[ORG_ID_ENV_VAR];
|
|
355
|
+
const flagOrgId = options.orgId && options.orgId !== envOrgId ? options.orgId : undefined;
|
|
356
|
+
|
|
357
|
+
// 1. --org-id flag
|
|
358
|
+
if (flagOrgId) {
|
|
359
|
+
return flagOrgId;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
// 2. Environment variable
|
|
363
|
+
if (envOrgId) {
|
|
364
|
+
return envOrgId;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// 3. Config preference (TTY: prompt with pre-selected, non-TTY: use directly)
|
|
368
|
+
const preferredOrgId = config?.preferences?.orgId;
|
|
369
|
+
if (preferredOrgId && (!interactive || autoSelect)) {
|
|
370
|
+
return preferredOrgId;
|
|
371
|
+
}
|
|
235
372
|
|
|
236
|
-
//
|
|
237
|
-
if (
|
|
238
|
-
|
|
373
|
+
// Cache lookup for prefixed resource IDs
|
|
374
|
+
if (!preferredOrgId) {
|
|
375
|
+
const cachedOrgId = await resolveCachedOrgId({ config, args, opts });
|
|
376
|
+
if (cachedOrgId) {
|
|
377
|
+
return cachedOrgId;
|
|
378
|
+
}
|
|
239
379
|
}
|
|
240
380
|
|
|
241
381
|
// Fetch organizations
|
|
@@ -251,13 +391,33 @@ export async function requireOrg(
|
|
|
251
391
|
tui.fatal('No organizations found for your account');
|
|
252
392
|
}
|
|
253
393
|
|
|
254
|
-
//
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
394
|
+
// 4. Single-org auto-select
|
|
395
|
+
if (orgs.length === 1 && orgs[0]) {
|
|
396
|
+
const orgId = orgs[0].id;
|
|
397
|
+
if (orgId !== preferredOrgId) {
|
|
398
|
+
await saveOrgId(orgId);
|
|
399
|
+
}
|
|
400
|
+
return orgId;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
// Auto-select mode (--confirm flag or explicit autoSelect)
|
|
404
|
+
if (autoSelect) {
|
|
405
|
+
const orgId = await tui.selectOrganization(orgs, preferredOrgId, true);
|
|
406
|
+
if (orgId !== preferredOrgId) {
|
|
407
|
+
await saveOrgId(orgId);
|
|
408
|
+
}
|
|
409
|
+
return orgId;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
// 5. Interactive prompt (TTY) / Error (no TTY)
|
|
413
|
+
if (!interactive) {
|
|
414
|
+
return tui.fatal(NON_INTERACTIVE_ORG_ERROR);
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
const orgId = await tui.selectOrganization(orgs, preferredOrgId, false);
|
|
258
418
|
|
|
259
419
|
// Save selected org to config if different
|
|
260
|
-
if (orgId !==
|
|
420
|
+
if (orgId !== preferredOrgId) {
|
|
261
421
|
await saveOrgId(orgId);
|
|
262
422
|
}
|
|
263
423
|
|
|
@@ -268,7 +428,15 @@ export async function optionalOrg(
|
|
|
268
428
|
ctx: CommandContext & { apiClient?: APIClientType; auth?: AuthData },
|
|
269
429
|
autoSelect?: boolean
|
|
270
430
|
): Promise<string | undefined> {
|
|
271
|
-
const { options, config, apiClient, auth } = ctx
|
|
431
|
+
const { options, config, apiClient, auth, args, opts } = ctx as CommandContext & {
|
|
432
|
+
apiClient?: APIClientType;
|
|
433
|
+
auth?: AuthData;
|
|
434
|
+
args?: Record<string, unknown>;
|
|
435
|
+
opts?: Record<string, unknown>;
|
|
436
|
+
};
|
|
437
|
+
const interactive = isTTY();
|
|
438
|
+
const envOrgId = process.env[ORG_ID_ENV_VAR];
|
|
439
|
+
const flagOrgId = options.orgId && options.orgId !== envOrgId ? options.orgId : undefined;
|
|
272
440
|
|
|
273
441
|
// If not authenticated or no API client, skip org selection
|
|
274
442
|
if (!auth || !apiClient) {
|
|
@@ -282,9 +450,28 @@ export async function optionalOrg(
|
|
|
282
450
|
|
|
283
451
|
// Note: --no-register check is handled in cli.ts before calling this function
|
|
284
452
|
|
|
285
|
-
//
|
|
286
|
-
if (
|
|
287
|
-
return
|
|
453
|
+
// 1. --org-id flag
|
|
454
|
+
if (flagOrgId) {
|
|
455
|
+
return flagOrgId;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
// 2. Environment variable
|
|
459
|
+
if (envOrgId) {
|
|
460
|
+
return envOrgId;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
// 3. Config preference (TTY: prompt with pre-selected, non-TTY: use directly)
|
|
464
|
+
const preferredOrgId = config?.preferences?.orgId;
|
|
465
|
+
if (preferredOrgId && (!interactive || autoSelect)) {
|
|
466
|
+
return preferredOrgId;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
// Cache lookup for prefixed resource IDs
|
|
470
|
+
if (!preferredOrgId) {
|
|
471
|
+
const cachedOrgId = await resolveCachedOrgId({ config, args, opts });
|
|
472
|
+
if (cachedOrgId) {
|
|
473
|
+
return cachedOrgId;
|
|
474
|
+
}
|
|
288
475
|
}
|
|
289
476
|
|
|
290
477
|
// Fetch organizations
|
|
@@ -300,12 +487,34 @@ export async function optionalOrg(
|
|
|
300
487
|
return undefined;
|
|
301
488
|
}
|
|
302
489
|
|
|
490
|
+
// 4. Single-org auto-select
|
|
491
|
+
if (orgs.length === 1 && orgs[0]) {
|
|
492
|
+
const orgId = orgs[0].id;
|
|
493
|
+
if (orgId !== preferredOrgId) {
|
|
494
|
+
await saveOrgId(orgId);
|
|
495
|
+
}
|
|
496
|
+
return orgId;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
// Auto-select mode (--confirm flag or explicit autoSelect)
|
|
500
|
+
if (autoSelect) {
|
|
501
|
+
const orgId = await tui.selectOrganization(orgs, preferredOrgId, true);
|
|
502
|
+
if (orgId !== preferredOrgId) {
|
|
503
|
+
await saveOrgId(orgId);
|
|
504
|
+
}
|
|
505
|
+
return orgId;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
// 5. Interactive prompt (TTY) / Error (no TTY)
|
|
509
|
+
if (!interactive) {
|
|
510
|
+
return tui.fatal(NON_INTERACTIVE_ORG_ERROR);
|
|
511
|
+
}
|
|
512
|
+
|
|
303
513
|
// Prompt for org selection (use saved preference as initial/default)
|
|
304
|
-
|
|
305
|
-
const orgId = await tui.selectOrganization(orgs, config?.preferences?.orgId, autoSelect);
|
|
514
|
+
const orgId = await tui.selectOrganization(orgs, preferredOrgId, false);
|
|
306
515
|
|
|
307
516
|
// Save selected org to config if different
|
|
308
|
-
if (orgId !==
|
|
517
|
+
if (orgId !== preferredOrgId) {
|
|
309
518
|
await saveOrgId(orgId);
|
|
310
519
|
}
|
|
311
520
|
|
package/src/banner.ts
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
getDisplayWidth,
|
|
8
8
|
stripAnsi,
|
|
9
9
|
} from './tui';
|
|
10
|
+
import { getExecutingAgent } from './agent-detection';
|
|
10
11
|
|
|
11
12
|
export function generateBanner(version?: string, compact?: true): string {
|
|
12
13
|
const _version = version ?? getVersion();
|
|
@@ -83,5 +84,9 @@ export function generateBanner(version?: string, compact?: true): string {
|
|
|
83
84
|
}
|
|
84
85
|
|
|
85
86
|
export function showBanner(version?: string, compact?: true): void {
|
|
87
|
+
// Skip banner when running from an AI coding agent
|
|
88
|
+
if (getExecutingAgent()) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
86
91
|
console.log(generateBanner(version, compact));
|
|
87
92
|
}
|