@agentuity/cli 0.1.14 → 0.1.16

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.
Files changed (158) hide show
  1. package/dist/auth.d.ts.map +1 -1
  2. package/dist/auth.js +7 -6
  3. package/dist/auth.js.map +1 -1
  4. package/dist/cli.d.ts.map +1 -1
  5. package/dist/cli.js +69 -11
  6. package/dist/cli.js.map +1 -1
  7. package/dist/cmd/ai/index.d.ts.map +1 -1
  8. package/dist/cmd/ai/index.js +6 -1
  9. package/dist/cmd/ai/index.js.map +1 -1
  10. package/dist/cmd/ai/opencode/index.d.ts +3 -0
  11. package/dist/cmd/ai/opencode/index.d.ts.map +1 -0
  12. package/dist/cmd/ai/opencode/index.js +27 -0
  13. package/dist/cmd/ai/opencode/index.js.map +1 -0
  14. package/dist/cmd/ai/opencode/install.d.ts +3 -0
  15. package/dist/cmd/ai/opencode/install.d.ts.map +1 -0
  16. package/dist/cmd/ai/opencode/install.js +102 -0
  17. package/dist/cmd/ai/opencode/install.js.map +1 -0
  18. package/dist/cmd/ai/opencode/run.d.ts +3 -0
  19. package/dist/cmd/ai/opencode/run.d.ts.map +1 -0
  20. package/dist/cmd/ai/opencode/run.js +88 -0
  21. package/dist/cmd/ai/opencode/run.js.map +1 -0
  22. package/dist/cmd/ai/opencode/uninstall.d.ts +3 -0
  23. package/dist/cmd/ai/opencode/uninstall.d.ts.map +1 -0
  24. package/dist/cmd/ai/opencode/uninstall.js +82 -0
  25. package/dist/cmd/ai/opencode/uninstall.js.map +1 -0
  26. package/dist/cmd/build/vite/beacon-plugin.d.ts.map +1 -1
  27. package/dist/cmd/build/vite/beacon-plugin.js.map +1 -1
  28. package/dist/cmd/build/vite/vite-builder.d.ts.map +1 -1
  29. package/dist/cmd/build/vite/vite-builder.js +1 -1
  30. package/dist/cmd/build/vite/vite-builder.js.map +1 -1
  31. package/dist/cmd/cloud/env/delete.d.ts.map +1 -1
  32. package/dist/cmd/cloud/env/delete.js +87 -34
  33. package/dist/cmd/cloud/env/delete.js.map +1 -1
  34. package/dist/cmd/cloud/env/get.d.ts.map +1 -1
  35. package/dist/cmd/cloud/env/get.js +50 -16
  36. package/dist/cmd/cloud/env/get.js.map +1 -1
  37. package/dist/cmd/cloud/env/import.d.ts.map +1 -1
  38. package/dist/cmd/cloud/env/import.js +76 -32
  39. package/dist/cmd/cloud/env/import.js.map +1 -1
  40. package/dist/cmd/cloud/env/index.d.ts.map +1 -1
  41. package/dist/cmd/cloud/env/index.js +6 -2
  42. package/dist/cmd/cloud/env/index.js.map +1 -1
  43. package/dist/cmd/cloud/env/list.d.ts.map +1 -1
  44. package/dist/cmd/cloud/env/list.js +94 -23
  45. package/dist/cmd/cloud/env/list.js.map +1 -1
  46. package/dist/cmd/cloud/env/org-util.d.ts +16 -0
  47. package/dist/cmd/cloud/env/org-util.d.ts.map +1 -0
  48. package/dist/cmd/cloud/env/org-util.js +28 -0
  49. package/dist/cmd/cloud/env/org-util.js.map +1 -0
  50. package/dist/cmd/cloud/env/pull.d.ts.map +1 -1
  51. package/dist/cmd/cloud/env/pull.js +61 -29
  52. package/dist/cmd/cloud/env/pull.js.map +1 -1
  53. package/dist/cmd/cloud/env/push.d.ts.map +1 -1
  54. package/dist/cmd/cloud/env/push.js +69 -23
  55. package/dist/cmd/cloud/env/push.js.map +1 -1
  56. package/dist/cmd/cloud/env/set.d.ts.map +1 -1
  57. package/dist/cmd/cloud/env/set.js +69 -26
  58. package/dist/cmd/cloud/env/set.js.map +1 -1
  59. package/dist/cmd/cloud/keyvalue/create-namespace.js +1 -1
  60. package/dist/cmd/cloud/keyvalue/create-namespace.js.map +1 -1
  61. package/dist/cmd/cloud/keyvalue/delete-namespace.js +2 -2
  62. package/dist/cmd/cloud/keyvalue/delete-namespace.js.map +1 -1
  63. package/dist/cmd/cloud/keyvalue/delete.js +1 -1
  64. package/dist/cmd/cloud/keyvalue/delete.js.map +1 -1
  65. package/dist/cmd/cloud/keyvalue/get.js +1 -1
  66. package/dist/cmd/cloud/keyvalue/get.js.map +1 -1
  67. package/dist/cmd/cloud/keyvalue/index.js +1 -1
  68. package/dist/cmd/cloud/keyvalue/index.js.map +1 -1
  69. package/dist/cmd/cloud/keyvalue/keys.js +1 -1
  70. package/dist/cmd/cloud/keyvalue/keys.js.map +1 -1
  71. package/dist/cmd/cloud/keyvalue/list-namespaces.js +1 -1
  72. package/dist/cmd/cloud/keyvalue/list-namespaces.js.map +1 -1
  73. package/dist/cmd/cloud/keyvalue/repl.d.ts.map +1 -1
  74. package/dist/cmd/cloud/keyvalue/repl.js +8 -5
  75. package/dist/cmd/cloud/keyvalue/repl.js.map +1 -1
  76. package/dist/cmd/cloud/keyvalue/search.js +1 -1
  77. package/dist/cmd/cloud/keyvalue/search.js.map +1 -1
  78. package/dist/cmd/cloud/keyvalue/set.js +1 -1
  79. package/dist/cmd/cloud/keyvalue/set.js.map +1 -1
  80. package/dist/cmd/cloud/keyvalue/stats.js +1 -1
  81. package/dist/cmd/cloud/keyvalue/stats.js.map +1 -1
  82. package/dist/cmd/cloud/keyvalue/util.d.ts +4 -4
  83. package/dist/cmd/cloud/keyvalue/util.d.ts.map +1 -1
  84. package/dist/cmd/cloud/keyvalue/util.js +4 -9
  85. package/dist/cmd/cloud/keyvalue/util.js.map +1 -1
  86. package/dist/cmd/project/create.d.ts.map +1 -1
  87. package/dist/cmd/project/create.js +20 -2
  88. package/dist/cmd/project/create.js.map +1 -1
  89. package/dist/cmd/project/download.d.ts +3 -1
  90. package/dist/cmd/project/download.d.ts.map +1 -1
  91. package/dist/cmd/project/download.js +5 -0
  92. package/dist/cmd/project/download.js.map +1 -1
  93. package/dist/cmd/project/template-flow.d.ts +5 -0
  94. package/dist/cmd/project/template-flow.d.ts.map +1 -1
  95. package/dist/cmd/project/template-flow.js +188 -79
  96. package/dist/cmd/project/template-flow.js.map +1 -1
  97. package/dist/cmd/setup/index.d.ts.map +1 -1
  98. package/dist/cmd/setup/index.js +2 -1
  99. package/dist/cmd/setup/index.js.map +1 -1
  100. package/dist/onboarding/agentPrompt.d.ts +8 -0
  101. package/dist/onboarding/agentPrompt.d.ts.map +1 -0
  102. package/dist/onboarding/agentPrompt.js +263 -0
  103. package/dist/onboarding/agentPrompt.js.map +1 -0
  104. package/dist/schema-generator.d.ts +1 -1
  105. package/dist/schema-generator.d.ts.map +1 -1
  106. package/dist/schema-parser.d.ts +1 -1
  107. package/dist/schema-parser.d.ts.map +1 -1
  108. package/dist/schema-parser.js +36 -1
  109. package/dist/schema-parser.js.map +1 -1
  110. package/dist/tui/prompt.d.ts.map +1 -1
  111. package/dist/tui/prompt.js +7 -1
  112. package/dist/tui/prompt.js.map +1 -1
  113. package/dist/tui.d.ts.map +1 -1
  114. package/dist/tui.js +91 -28
  115. package/dist/tui.js.map +1 -1
  116. package/dist/types.d.ts.map +1 -1
  117. package/dist/types.js.map +1 -1
  118. package/package.json +7 -7
  119. package/src/auth.ts +7 -6
  120. package/src/cli.ts +84 -11
  121. package/src/cmd/ai/index.ts +6 -1
  122. package/src/cmd/ai/opencode/index.ts +28 -0
  123. package/src/cmd/ai/opencode/install.ts +120 -0
  124. package/src/cmd/ai/opencode/run.ts +103 -0
  125. package/src/cmd/ai/opencode/uninstall.ts +90 -0
  126. package/src/cmd/build/vite/beacon-plugin.ts +3 -1
  127. package/src/cmd/build/vite/vite-builder.ts +5 -1
  128. package/src/cmd/cloud/env/delete.ts +100 -41
  129. package/src/cmd/cloud/env/get.ts +53 -16
  130. package/src/cmd/cloud/env/import.ts +86 -37
  131. package/src/cmd/cloud/env/index.ts +6 -2
  132. package/src/cmd/cloud/env/list.ts +102 -27
  133. package/src/cmd/cloud/env/org-util.ts +37 -0
  134. package/src/cmd/cloud/env/pull.ts +67 -31
  135. package/src/cmd/cloud/env/push.ts +81 -28
  136. package/src/cmd/cloud/env/set.ts +82 -33
  137. package/src/cmd/cloud/keyvalue/create-namespace.ts +1 -1
  138. package/src/cmd/cloud/keyvalue/delete-namespace.ts +2 -2
  139. package/src/cmd/cloud/keyvalue/delete.ts +1 -1
  140. package/src/cmd/cloud/keyvalue/get.ts +1 -1
  141. package/src/cmd/cloud/keyvalue/index.ts +1 -1
  142. package/src/cmd/cloud/keyvalue/keys.ts +1 -1
  143. package/src/cmd/cloud/keyvalue/list-namespaces.ts +1 -1
  144. package/src/cmd/cloud/keyvalue/repl.ts +8 -5
  145. package/src/cmd/cloud/keyvalue/search.ts +1 -1
  146. package/src/cmd/cloud/keyvalue/set.ts +1 -1
  147. package/src/cmd/cloud/keyvalue/stats.ts +1 -1
  148. package/src/cmd/cloud/keyvalue/util.ts +8 -17
  149. package/src/cmd/project/create.ts +21 -2
  150. package/src/cmd/project/download.ts +7 -1
  151. package/src/cmd/project/template-flow.ts +215 -80
  152. package/src/cmd/setup/index.ts +2 -1
  153. package/src/onboarding/agentPrompt.ts +263 -0
  154. package/src/schema-generator.ts +1 -1
  155. package/src/schema-parser.ts +42 -3
  156. package/src/tui/prompt.ts +10 -3
  157. package/src/tui.ts +95 -31
  158. package/src/types.ts +1 -0
@@ -1,7 +1,7 @@
1
1
  import { z } from 'zod';
2
2
  import { createSubcommand } from '../../../types';
3
3
  import * as tui from '../../../tui';
4
- import { projectEnvUpdate } from '@agentuity/server';
4
+ import { projectEnvUpdate, orgEnvUpdate } from '@agentuity/server';
5
5
  import {
6
6
  findExistingEnvFile,
7
7
  readEnvFile,
@@ -13,20 +13,23 @@ import {
13
13
  PUBLIC_VAR_PREFIXES,
14
14
  } from '../../../env-util';
15
15
  import { getCommand } from '../../../command-prefix';
16
+ import { resolveOrgId, isOrgScope } from './org-util';
16
17
 
17
18
  const EnvSetResponseSchema = z.object({
18
19
  success: z.boolean().describe('Whether the operation succeeded'),
19
20
  key: z.string().describe('Environment variable key'),
20
- path: z.string().describe('Local file path where env var was saved'),
21
+ path: z.string().optional().describe('Local file path where env var was saved (project scope only)'),
21
22
  secret: z.boolean().describe('Whether the value was stored as a secret'),
23
+ scope: z.enum(['project', 'org']).describe('The scope where the variable was set'),
22
24
  });
23
25
 
24
26
  export const setSubcommand = createSubcommand({
25
27
  name: 'set',
26
28
  description: 'Set an environment variable or secret',
27
- tags: ['mutating', 'updates-resource', 'slow', 'requires-auth', 'requires-project'],
29
+ tags: ['mutating', 'updates-resource', 'slow', 'requires-auth'],
28
30
  idempotent: true,
29
- requires: { auth: true, project: true, apiClient: true },
31
+ requires: { auth: true, apiClient: true },
32
+ optional: { project: true },
30
33
  examples: [
31
34
  {
32
35
  command: getCommand('env set NODE_ENV production'),
@@ -37,6 +40,10 @@ export const setSubcommand = createSubcommand({
37
40
  command: getCommand('env set API_KEY "sk_..." --secret'),
38
41
  description: 'Set a secret value',
39
42
  },
43
+ {
44
+ command: getCommand('env set OPENAI_API_KEY "sk_..." --secret --org'),
45
+ description: 'Set an organization-wide secret',
46
+ },
40
47
  ],
41
48
  schema: {
42
49
  args: z.object({
@@ -48,12 +55,23 @@ export const setSubcommand = createSubcommand({
48
55
  .boolean()
49
56
  .default(false)
50
57
  .describe('store as a secret (encrypted and masked in UI)'),
58
+ org: z
59
+ .union([z.boolean(), z.string()])
60
+ .optional()
61
+ .describe('set at organization level (use --org for default org, or --org <orgId> for specific org)'),
51
62
  }),
52
63
  response: EnvSetResponseSchema,
53
64
  },
54
65
 
55
66
  async handler(ctx) {
56
- const { args, opts, apiClient, project, projectDir } = ctx;
67
+ const { args, opts, apiClient, project, projectDir, config } = ctx;
68
+ const useOrgScope = isOrgScope(opts?.org);
69
+
70
+ // Require project context if not using org scope
71
+ if (!useOrgScope && !project) {
72
+ tui.fatal('Project context required. Run from a project directory or use --org for organization scope.');
73
+ }
74
+
57
75
  let isSecret = opts?.secret ?? false;
58
76
  const isPublic = isPublicVarKey(args.key);
59
77
 
@@ -81,34 +99,65 @@ export const setSubcommand = createSubcommand({
81
99
  }
82
100
  }
83
101
 
84
- // Set in cloud
85
- const updatePayload = isSecret
86
- ? { id: project.projectId, secrets: { [args.key]: args.value } }
87
- : { id: project.projectId, env: { [args.key]: args.value } };
88
-
89
102
  const label = isSecret ? 'secret' : 'environment variable';
90
- await tui.spinner(`Setting ${label} in cloud`, () => {
91
- return projectEnvUpdate(apiClient, updatePayload);
92
- });
93
-
94
- // Update local .env file
95
- const envFilePath = await findExistingEnvFile(projectDir);
96
- const currentEnv = await readEnvFile(envFilePath);
97
- currentEnv[args.key] = args.value;
98
-
99
- // Filter out AGENTUITY_ keys before writing
100
- const filteredEnv = filterAgentuitySdkKeys(currentEnv);
101
- await writeEnvFile(envFilePath, filteredEnv);
102
-
103
- tui.success(
104
- `${isSecret ? 'Secret' : 'Environment variable'} '${args.key}' set successfully (cloud + ${envFilePath})`
105
- );
106
-
107
- return {
108
- success: true,
109
- key: args.key,
110
- path: envFilePath,
111
- secret: isSecret,
112
- };
103
+
104
+ if (useOrgScope) {
105
+ // Organization scope
106
+ const orgId = await resolveOrgId(apiClient, config, opts!.org!);
107
+
108
+ const updatePayload = isSecret
109
+ ? { id: orgId, secrets: { [args.key]: args.value } }
110
+ : { id: orgId, env: { [args.key]: args.value } };
111
+
112
+ await tui.spinner(`Setting organization ${label} in cloud`, () => {
113
+ return orgEnvUpdate(apiClient, updatePayload);
114
+ });
115
+
116
+ tui.success(
117
+ `Organization ${isSecret ? 'secret' : 'environment variable'} '${args.key}' set successfully (affects all projects in org)`
118
+ );
119
+
120
+ return {
121
+ success: true,
122
+ key: args.key,
123
+ secret: isSecret,
124
+ scope: 'org' as const,
125
+ };
126
+ } else {
127
+ // Project scope (existing behavior)
128
+ const updatePayload = isSecret
129
+ ? { id: project!.projectId, secrets: { [args.key]: args.value } }
130
+ : { id: project!.projectId, env: { [args.key]: args.value } };
131
+
132
+ await tui.spinner(`Setting ${label} in cloud`, () => {
133
+ return projectEnvUpdate(apiClient, updatePayload);
134
+ });
135
+
136
+ // Update local .env file only if we have a project directory
137
+ // (not when using --project-id without being in a project folder)
138
+ let envFilePath: string | undefined;
139
+ if (projectDir) {
140
+ envFilePath = await findExistingEnvFile(projectDir);
141
+ const currentEnv = await readEnvFile(envFilePath);
142
+ currentEnv[args.key] = args.value;
143
+
144
+ // Filter out AGENTUITY_ keys before writing
145
+ const filteredEnv = filterAgentuitySdkKeys(currentEnv);
146
+ await writeEnvFile(envFilePath, filteredEnv);
147
+ }
148
+
149
+ const successMsg = envFilePath
150
+ ? `${isSecret ? 'Secret' : 'Environment variable'} '${args.key}' set successfully (cloud + ${envFilePath})`
151
+ : `${isSecret ? 'Secret' : 'Environment variable'} '${args.key}' set successfully (cloud only)`;
152
+ tui.success(successMsg);
153
+
154
+ return {
155
+ success: true,
156
+ key: args.key,
157
+ path: envFilePath,
158
+ secret: isSecret,
159
+ scope: 'project' as const,
160
+ };
161
+ }
113
162
  },
114
163
  });
@@ -9,7 +9,7 @@ export const createNamespaceSubcommand = createCommand({
9
9
  description: 'Create a new keyvalue namespace',
10
10
  tags: ['mutating', 'creates-resource', 'slow', 'requires-auth'],
11
11
  idempotent: false,
12
- requires: { auth: true, project: true },
12
+ requires: { auth: true },
13
13
  examples: [
14
14
  {
15
15
  command: getCommand('kv create-namespace production'),
@@ -8,9 +8,9 @@ export const deleteNamespaceSubcommand = createCommand({
8
8
  name: 'delete-namespace',
9
9
  aliases: ['rm-namespace'],
10
10
  description: 'Delete a keyvalue namespace and all its keys',
11
- tags: ['destructive', 'deletes-resource', 'slow', 'requires-auth', 'requires-project'],
11
+ tags: ['destructive', 'deletes-resource', 'slow', 'requires-auth'],
12
12
  idempotent: true,
13
- requires: { auth: true, project: true },
13
+ requires: { auth: true },
14
14
  examples: [
15
15
  {
16
16
  command: getCommand('kv delete-namespace staging'),
@@ -16,7 +16,7 @@ export const deleteSubcommand = createCommand({
16
16
  description: 'Delete a key from the keyvalue storage',
17
17
  tags: ['destructive', 'deletes-resource', 'slow', 'requires-auth'],
18
18
  idempotent: true,
19
- requires: { auth: true, project: true },
19
+ requires: { auth: true },
20
20
  examples: [
21
21
  { command: getCommand('kv delete production user:123'), description: 'Delete user data' },
22
22
  { command: getCommand('kv delete cache session:abc'), description: 'Delete cached session' },
@@ -14,7 +14,7 @@ export const getSubcommand = createCommand({
14
14
  name: 'get',
15
15
  description: 'Get a value from the keyvalue storage',
16
16
  tags: ['read-only', 'fast', 'requires-auth'],
17
- requires: { auth: true, project: true },
17
+ requires: { auth: true },
18
18
  examples: [
19
19
  { command: getCommand('kv get production user:123'), description: 'Get user data' },
20
20
  { command: getCommand('kv get cache session:abc'), description: 'Get cached session' },
@@ -35,6 +35,6 @@ export const command = createCommand({
35
35
  createNamespaceSubcommand,
36
36
  deleteNamespaceSubcommand,
37
37
  ],
38
- requires: { auth: true, project: true },
38
+ requires: { auth: true },
39
39
  });
40
40
  export default command;
@@ -13,7 +13,7 @@ export const keysSubcommand = createCommand({
13
13
  aliases: ['ls', 'list'],
14
14
  description: 'List all keys in a keyvalue namespace',
15
15
  tags: ['read-only', 'slow', 'requires-auth'],
16
- requires: { auth: true, project: true },
16
+ requires: { auth: true },
17
17
  idempotent: true,
18
18
  examples: [
19
19
  { command: getCommand('kv keys production'), description: 'List all keys in production' },
@@ -10,7 +10,7 @@ export const listNamespacesSubcommand = createCommand({
10
10
  aliases: ['namespaces', 'ns'],
11
11
  description: 'List all keyvalue namespaces',
12
12
  tags: ['read-only', 'fast', 'requires-auth'],
13
- requires: { auth: true, project: true },
13
+ requires: { auth: true },
14
14
  examples: [
15
15
  { command: getCommand('kv list-namespaces'), description: 'List all namespaces' },
16
16
  { command: getCommand('kv namespaces'), description: 'List namespaces (using alias)' },
@@ -11,16 +11,19 @@ export const replSubcommand = createCommand({
11
11
  description: 'Start an interactive repl for working with keyvalue database',
12
12
  tags: ['slow', 'requires-auth'],
13
13
  idempotent: false,
14
- requires: { auth: true, project: true },
14
+ requires: { auth: true },
15
+ optional: { project: true },
15
16
  examples: [{ command: getCommand('kv repl'), description: 'Start interactive KV session' }],
16
17
 
17
18
  async handler(ctx) {
18
19
  showBanner(undefined, true);
19
- tui.info('Managing keyvalue store for project');
20
- tui.newline();
21
- console.log(tui.bold('Org:'.padEnd(10, ' ')), ' ', tui.muted(ctx.project.orgId));
22
- console.log(tui.bold('Project:'.padEnd(10, ' ')), ' ', tui.muted(ctx.project.projectId));
20
+ tui.info('Managing keyvalue store');
23
21
  tui.newline();
22
+ if (ctx.project) {
23
+ console.log(tui.bold('Org:'.padEnd(10, ' ')), ' ', tui.muted(ctx.project.orgId));
24
+ console.log(tui.bold('Project:'.padEnd(10, ' ')), ' ', tui.muted(ctx.project.projectId));
25
+ tui.newline();
26
+ }
24
27
 
25
28
  const storage = await createStorageAdapter(ctx);
26
29
 
@@ -20,7 +20,7 @@ export const searchSubcommand = createCommand({
20
20
  name: 'search',
21
21
  description: 'Search for keys matching a keyword in a keyvalue namespace',
22
22
  tags: ['read-only', 'slow', 'requires-auth'],
23
- requires: { auth: true, project: true },
23
+ requires: { auth: true },
24
24
  idempotent: true,
25
25
  examples: [
26
26
  {
@@ -19,7 +19,7 @@ export const setSubcommand = createCommand({
19
19
  description: 'Set a key and value in the keyvalue storage',
20
20
  tags: ['mutating', 'updates-resource', 'slow', 'requires-auth'],
21
21
  idempotent: true,
22
- requires: { auth: true, project: true },
22
+ requires: { auth: true },
23
23
  examples: [
24
24
  {
25
25
  command: getCommand(
@@ -26,7 +26,7 @@ export const statsSubcommand = createCommand({
26
26
  name: 'stats',
27
27
  description: 'Get statistics for keyvalue storage',
28
28
  tags: ['read-only', 'fast', 'requires-auth'],
29
- requires: { auth: true, project: true },
29
+ requires: { auth: true },
30
30
  idempotent: true,
31
31
  examples: [
32
32
  { command: getCommand('kv stats'), description: 'Show stats for all namespaces' },
@@ -1,34 +1,25 @@
1
- import { KeyValueStorageService, Logger } from '@agentuity/core';
1
+ import { KeyValueStorageService, type Logger } from '@agentuity/core';
2
2
  import { createServerFetchAdapter, getServiceUrls } from '@agentuity/server';
3
- import { loadProjectSDKKey } from '../../../config';
4
- import { ErrorCode } from '../../../errors';
5
- import type { Config } from '../../../types';
6
- import * as tui from '../../../tui';
3
+ import { getDefaultRegion } from '../../../config';
4
+ import type { AuthData, Config } from '../../../types';
7
5
 
8
6
  export async function createStorageAdapter(ctx: {
9
7
  logger: Logger;
10
- projectDir: string;
11
8
  config: Config | null;
12
- project: { region: string };
9
+ auth: AuthData;
10
+ project?: { region: string };
13
11
  }) {
14
- const sdkKey = await loadProjectSDKKey(ctx.logger, ctx.projectDir);
15
- if (!sdkKey) {
16
- tui.fatal(
17
- `Couldn't find the AGENTUITY_SDK_KEY in ${ctx.projectDir} .env file`,
18
- ErrorCode.CONFIG_NOT_FOUND
19
- );
20
- }
21
-
22
12
  const adapter = createServerFetchAdapter(
23
13
  {
24
14
  headers: {
25
- Authorization: `Bearer ${sdkKey}`,
15
+ Authorization: `Bearer ${ctx.auth.apiKey}`,
26
16
  },
27
17
  },
28
18
  ctx.logger
29
19
  );
30
20
 
31
- const urls = getServiceUrls(ctx.project.region);
21
+ const region = ctx.project?.region || (await getDefaultRegion(ctx.config?.name, ctx.config));
22
+ const urls = getServiceUrls(region);
32
23
  const baseUrl = urls.catalyst;
33
24
  return new KeyValueStorageService(baseUrl, adapter);
34
25
  }
@@ -6,6 +6,7 @@ import type { APIClient as APIClientType } from '../../api';
6
6
 
7
7
  const ProjectCreateResponseSchema = z.object({
8
8
  success: z.boolean().describe('Whether the operation succeeded'),
9
+ error: z.string().optional().describe('Error message if setup failed'),
9
10
  name: z.string().describe('Project name'),
10
11
  path: z.string().describe('Project directory path'),
11
12
  projectId: z.string().optional().describe('Project ID if registered'),
@@ -68,12 +69,21 @@ export const createProjectSubcommand = createSubcommand({
68
69
  .default(true)
69
70
  .optional()
70
71
  .describe('Register the project, if authenticated (use --no-register to skip)'),
72
+ database: z
73
+ .string()
74
+ .optional()
75
+ .describe('Database action: "skip", "new", or existing database name'),
76
+ storage: z
77
+ .string()
78
+ .optional()
79
+ .describe('Storage action: "skip", "new", or existing bucket name'),
80
+ enableAuth: z.boolean().optional().describe('Enable Agentuity Auth'),
71
81
  }),
72
82
  response: ProjectCreateResponseSchema,
73
83
  },
74
84
 
75
85
  async handler(ctx) {
76
- const { logger, opts, auth, config, apiClient, region } = ctx;
86
+ const { logger, opts, auth, config, apiClient, region, options } = ctx;
77
87
 
78
88
  // Only get org if registering
79
89
  let orgId: string | undefined;
@@ -100,10 +110,19 @@ export const createProjectSubcommand = createSubcommand({
100
110
  apiClient,
101
111
  orgId: opts.register === true ? orgId : undefined,
102
112
  region,
113
+ database: opts.database,
114
+ storage: opts.storage,
115
+ enableAuth: opts.enableAuth,
103
116
  });
104
117
 
118
+ // Exit with error code if setup failed and not in JSON mode
119
+ if (!result.success && !options.json) {
120
+ process.exitCode = 1;
121
+ }
122
+
105
123
  return {
106
- success: true,
124
+ success: result.success,
125
+ error: result.error,
107
126
  name: result.name,
108
127
  path: result.path,
109
128
  projectId: result.projectId,
@@ -328,8 +328,9 @@ export async function downloadTemplate(options: DownloadOptions): Promise<void>
328
328
  }
329
329
  }
330
330
 
331
- export async function setupProject(options: SetupOptions): Promise<void> {
331
+ export async function setupProject(options: SetupOptions): Promise<{ success: boolean }> {
332
332
  const { dest, projectName, dirName, noInstall, noBuild, logger } = options;
333
+ let hasError = false;
333
334
 
334
335
  // Replace {{PROJECT_NAME}} in files
335
336
  tui.info(`🔧 Setting up ${projectName}...`);
@@ -345,6 +346,7 @@ export async function setupProject(options: SetupOptions): Promise<void> {
345
346
  });
346
347
  if (exitCode !== 0) {
347
348
  logger.error('Failed to install dependencies');
349
+ hasError = true;
348
350
  }
349
351
  }
350
352
 
@@ -361,6 +363,7 @@ export async function setupProject(options: SetupOptions): Promise<void> {
361
363
  });
362
364
  if (exitCode !== 0) {
363
365
  logger.error('Template setup script failed');
366
+ hasError = true;
364
367
  }
365
368
  } finally {
366
369
  // Always delete the setup script after running (or attempting to run)
@@ -382,12 +385,15 @@ export async function setupProject(options: SetupOptions): Promise<void> {
382
385
  });
383
386
  if (exitCode !== 0) {
384
387
  logger.error('Failed to build project');
388
+ hasError = true;
385
389
  }
386
390
  }
387
391
 
388
392
  // Generate and write AGENTS.md files for the CLI and source folders
389
393
  // Always overwrite during project setup to ensure fresh content
390
394
  await writeAgentsDocs(dest);
395
+
396
+ return { success: !hasError };
391
397
  }
392
398
 
393
399
  export async function initGitRepo(dest: string): Promise<void> {