@agentuity/cli 0.0.101 → 0.0.103

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 (210) hide show
  1. package/AGENTS.md +19 -188
  2. package/bin/cli.ts +21 -14
  3. package/dist/cli.d.ts.map +1 -1
  4. package/dist/cli.js +41 -12
  5. package/dist/cli.js.map +1 -1
  6. package/dist/cmd/ai/index.d.ts.map +1 -1
  7. package/dist/cmd/ai/index.js +6 -1
  8. package/dist/cmd/ai/index.js.map +1 -1
  9. package/dist/cmd/ai/prompt/agent.d.ts +7 -0
  10. package/dist/cmd/ai/prompt/agent.d.ts.map +1 -1
  11. package/dist/cmd/ai/prompt/agent.js +12 -323
  12. package/dist/cmd/ai/prompt/agent.js.map +1 -1
  13. package/dist/cmd/ai/prompt/api.d.ts +7 -0
  14. package/dist/cmd/ai/prompt/api.d.ts.map +1 -1
  15. package/dist/cmd/ai/prompt/api.js +12 -260
  16. package/dist/cmd/ai/prompt/api.js.map +1 -1
  17. package/dist/cmd/ai/prompt/version.d.ts +35 -0
  18. package/dist/cmd/ai/prompt/version.d.ts.map +1 -0
  19. package/dist/cmd/ai/prompt/version.js +55 -0
  20. package/dist/cmd/ai/prompt/version.js.map +1 -0
  21. package/dist/cmd/ai/prompt/web.d.ts +7 -0
  22. package/dist/cmd/ai/prompt/web.d.ts.map +1 -1
  23. package/dist/cmd/ai/prompt/web.js +12 -283
  24. package/dist/cmd/ai/prompt/web.js.map +1 -1
  25. package/dist/cmd/ai/skills/generate.d.ts +3 -0
  26. package/dist/cmd/ai/skills/generate.d.ts.map +1 -0
  27. package/dist/cmd/ai/skills/generate.js +65 -0
  28. package/dist/cmd/ai/skills/generate.js.map +1 -0
  29. package/dist/cmd/ai/skills/generator.d.ts +4 -0
  30. package/dist/cmd/ai/skills/generator.d.ts.map +1 -0
  31. package/dist/cmd/ai/skills/generator.js +402 -0
  32. package/dist/cmd/ai/skills/generator.js.map +1 -0
  33. package/dist/cmd/ai/skills/index.d.ts +4 -0
  34. package/dist/cmd/ai/skills/index.d.ts.map +1 -0
  35. package/dist/cmd/ai/skills/index.js +21 -0
  36. package/dist/cmd/ai/skills/index.js.map +1 -0
  37. package/dist/cmd/auth/signup.d.ts.map +1 -1
  38. package/dist/cmd/auth/signup.js +1 -0
  39. package/dist/cmd/auth/signup.js.map +1 -1
  40. package/dist/cmd/build/entry-generator.d.ts.map +1 -1
  41. package/dist/cmd/build/entry-generator.js +40 -5
  42. package/dist/cmd/build/entry-generator.js.map +1 -1
  43. package/dist/cmd/build/vite/bun-dev-server.d.ts +7 -1
  44. package/dist/cmd/build/vite/bun-dev-server.d.ts.map +1 -1
  45. package/dist/cmd/build/vite/bun-dev-server.js +30 -26
  46. package/dist/cmd/build/vite/bun-dev-server.js.map +1 -1
  47. package/dist/cmd/build/vite/metadata-generator.d.ts.map +1 -1
  48. package/dist/cmd/build/vite/metadata-generator.js +58 -7
  49. package/dist/cmd/build/vite/metadata-generator.js.map +1 -1
  50. package/dist/cmd/build/vite/prompt-generator.d.ts +23 -0
  51. package/dist/cmd/build/vite/prompt-generator.d.ts.map +1 -0
  52. package/dist/cmd/build/vite/prompt-generator.js +123 -0
  53. package/dist/cmd/build/vite/prompt-generator.js.map +1 -0
  54. package/dist/cmd/build/vite/registry-generator.d.ts.map +1 -1
  55. package/dist/cmd/build/vite/registry-generator.js +28 -11
  56. package/dist/cmd/build/vite/registry-generator.js.map +1 -1
  57. package/dist/cmd/build/vite/server-bundler.d.ts +4 -0
  58. package/dist/cmd/build/vite/server-bundler.d.ts.map +1 -1
  59. package/dist/cmd/build/vite/server-bundler.js +45 -16
  60. package/dist/cmd/build/vite/server-bundler.js.map +1 -1
  61. package/dist/cmd/build/vite/vite-asset-server-config.d.ts.map +1 -1
  62. package/dist/cmd/build/vite/vite-asset-server-config.js +4 -0
  63. package/dist/cmd/build/vite/vite-asset-server-config.js.map +1 -1
  64. package/dist/cmd/build/vite/vite-builder.d.ts.map +1 -1
  65. package/dist/cmd/build/vite/vite-builder.js +99 -87
  66. package/dist/cmd/build/vite/vite-builder.js.map +1 -1
  67. package/dist/cmd/cloud/deploy.d.ts.map +1 -1
  68. package/dist/cmd/cloud/deploy.js +80 -27
  69. package/dist/cmd/cloud/deploy.js.map +1 -1
  70. package/dist/cmd/cloud/keyvalue/create-namespace.d.ts.map +1 -1
  71. package/dist/cmd/cloud/keyvalue/create-namespace.js +3 -1
  72. package/dist/cmd/cloud/keyvalue/create-namespace.js.map +1 -1
  73. package/dist/cmd/cloud/keyvalue/delete-namespace.d.ts.map +1 -1
  74. package/dist/cmd/cloud/keyvalue/delete-namespace.js +3 -1
  75. package/dist/cmd/cloud/keyvalue/delete-namespace.js.map +1 -1
  76. package/dist/cmd/cloud/keyvalue/delete.d.ts.map +1 -1
  77. package/dist/cmd/cloud/keyvalue/delete.js +3 -1
  78. package/dist/cmd/cloud/keyvalue/delete.js.map +1 -1
  79. package/dist/cmd/cloud/keyvalue/set.d.ts.map +1 -1
  80. package/dist/cmd/cloud/keyvalue/set.js +4 -2
  81. package/dist/cmd/cloud/keyvalue/set.js.map +1 -1
  82. package/dist/cmd/cloud/stream/get.d.ts.map +1 -1
  83. package/dist/cmd/cloud/stream/get.js +2 -13
  84. package/dist/cmd/cloud/stream/get.js.map +1 -1
  85. package/dist/cmd/cloud/vector/delete-namespace.d.ts +3 -0
  86. package/dist/cmd/cloud/vector/delete-namespace.d.ts.map +1 -0
  87. package/dist/cmd/cloud/vector/delete-namespace.js +77 -0
  88. package/dist/cmd/cloud/vector/delete-namespace.js.map +1 -0
  89. package/dist/cmd/cloud/vector/index.d.ts.map +1 -1
  90. package/dist/cmd/cloud/vector/index.js +21 -4
  91. package/dist/cmd/cloud/vector/index.js.map +1 -1
  92. package/dist/cmd/cloud/vector/list-namespaces.d.ts +3 -0
  93. package/dist/cmd/cloud/vector/list-namespaces.d.ts.map +1 -0
  94. package/dist/cmd/cloud/vector/list-namespaces.js +42 -0
  95. package/dist/cmd/cloud/vector/list-namespaces.js.map +1 -0
  96. package/dist/cmd/cloud/vector/stats.d.ts +3 -0
  97. package/dist/cmd/cloud/vector/stats.d.ts.map +1 -0
  98. package/dist/cmd/cloud/vector/stats.js +142 -0
  99. package/dist/cmd/cloud/vector/stats.js.map +1 -0
  100. package/dist/cmd/cloud/vector/upsert.d.ts +3 -0
  101. package/dist/cmd/cloud/vector/upsert.d.ts.map +1 -0
  102. package/dist/cmd/cloud/vector/upsert.js +192 -0
  103. package/dist/cmd/cloud/vector/upsert.js.map +1 -0
  104. package/dist/cmd/dev/file-watcher.d.ts.map +1 -1
  105. package/dist/cmd/dev/file-watcher.js +90 -31
  106. package/dist/cmd/dev/file-watcher.js.map +1 -1
  107. package/dist/cmd/dev/index.d.ts.map +1 -1
  108. package/dist/cmd/dev/index.js +244 -64
  109. package/dist/cmd/dev/index.js.map +1 -1
  110. package/dist/cmd/dev/skills.d.ts +10 -0
  111. package/dist/cmd/dev/skills.d.ts.map +1 -0
  112. package/dist/cmd/dev/skills.js +57 -0
  113. package/dist/cmd/dev/skills.js.map +1 -0
  114. package/dist/cmd/dev/sync.js +7 -7
  115. package/dist/cmd/dev/sync.js.map +1 -1
  116. package/dist/cmd/index.d.ts.map +1 -1
  117. package/dist/cmd/index.js +1 -0
  118. package/dist/cmd/index.js.map +1 -1
  119. package/dist/cmd/project/create.d.ts.map +1 -1
  120. package/dist/cmd/project/create.js +3 -0
  121. package/dist/cmd/project/create.js.map +1 -1
  122. package/dist/cmd/project/template-flow.d.ts +1 -0
  123. package/dist/cmd/project/template-flow.d.ts.map +1 -1
  124. package/dist/cmd/project/template-flow.js +30 -5
  125. package/dist/cmd/project/template-flow.js.map +1 -1
  126. package/dist/cmd/setup/index.d.ts.map +1 -1
  127. package/dist/cmd/setup/index.js +1 -0
  128. package/dist/cmd/setup/index.js.map +1 -1
  129. package/dist/cmd/upgrade/index.d.ts +15 -0
  130. package/dist/cmd/upgrade/index.d.ts.map +1 -1
  131. package/dist/cmd/upgrade/index.js +59 -4
  132. package/dist/cmd/upgrade/index.js.map +1 -1
  133. package/dist/domain.d.ts +45 -0
  134. package/dist/domain.d.ts.map +1 -0
  135. package/dist/domain.js +200 -0
  136. package/dist/domain.js.map +1 -0
  137. package/dist/schema-generator.d.ts +2 -0
  138. package/dist/schema-generator.d.ts.map +1 -1
  139. package/dist/schema-generator.js +18 -0
  140. package/dist/schema-generator.js.map +1 -1
  141. package/dist/steps.d.ts +1 -1
  142. package/dist/steps.d.ts.map +1 -1
  143. package/dist/steps.js +16 -5
  144. package/dist/steps.js.map +1 -1
  145. package/dist/tui/prompt.d.ts +1 -2
  146. package/dist/tui/prompt.d.ts.map +1 -1
  147. package/dist/tui/prompt.js +8 -4
  148. package/dist/tui/prompt.js.map +1 -1
  149. package/dist/tui.d.ts +16 -0
  150. package/dist/tui.d.ts.map +1 -1
  151. package/dist/tui.js +23 -2
  152. package/dist/tui.js.map +1 -1
  153. package/dist/types.d.ts +9 -2
  154. package/dist/types.d.ts.map +1 -1
  155. package/dist/types.js +3 -3
  156. package/dist/types.js.map +1 -1
  157. package/package.json +4 -4
  158. package/src/cli.ts +47 -12
  159. package/src/cmd/ai/index.ts +6 -1
  160. package/src/cmd/ai/prompt/agent.md +306 -0
  161. package/src/cmd/ai/prompt/agent.ts +12 -322
  162. package/src/cmd/ai/prompt/api.md +360 -0
  163. package/src/cmd/ai/prompt/api.ts +13 -260
  164. package/src/cmd/ai/prompt/version.ts +61 -0
  165. package/src/cmd/ai/prompt/web.md +509 -0
  166. package/src/cmd/ai/prompt/web.ts +12 -282
  167. package/src/cmd/ai/skills/generate.ts +75 -0
  168. package/src/cmd/ai/skills/generator.ts +519 -0
  169. package/src/cmd/ai/skills/index.ts +23 -0
  170. package/src/cmd/auth/signup.ts +1 -0
  171. package/src/cmd/build/entry-generator.ts +43 -7
  172. package/src/cmd/build/vite/bun-dev-server.ts +31 -28
  173. package/src/cmd/build/vite/metadata-generator.ts +73 -7
  174. package/src/cmd/build/vite/prompt-generator.ts +169 -0
  175. package/src/cmd/build/vite/registry-generator.ts +33 -10
  176. package/src/cmd/build/vite/server-bundler.ts +53 -22
  177. package/src/cmd/build/vite/vite-asset-server-config.ts +5 -0
  178. package/src/cmd/build/vite/vite-builder.ts +107 -87
  179. package/src/cmd/cloud/deploy.ts +103 -31
  180. package/src/cmd/cloud/keyvalue/create-namespace.ts +3 -1
  181. package/src/cmd/cloud/keyvalue/delete-namespace.ts +3 -1
  182. package/src/cmd/cloud/keyvalue/delete.ts +3 -1
  183. package/src/cmd/cloud/keyvalue/set.ts +4 -2
  184. package/src/cmd/cloud/stream/get.ts +2 -9
  185. package/src/cmd/cloud/vector/delete-namespace.ts +89 -0
  186. package/src/cmd/cloud/vector/index.ts +21 -4
  187. package/src/cmd/cloud/vector/list-namespaces.ts +46 -0
  188. package/src/cmd/cloud/vector/stats.ts +160 -0
  189. package/src/cmd/cloud/vector/upsert.ts +216 -0
  190. package/src/cmd/dev/file-watcher.ts +101 -32
  191. package/src/cmd/dev/index.ts +343 -115
  192. package/src/cmd/dev/skills.ts +82 -0
  193. package/src/cmd/dev/sync.ts +7 -7
  194. package/src/cmd/index.ts +1 -0
  195. package/src/cmd/project/create.ts +3 -0
  196. package/src/cmd/project/template-flow.ts +37 -5
  197. package/src/cmd/setup/index.ts +1 -0
  198. package/src/cmd/upgrade/index.ts +68 -4
  199. package/src/domain.ts +273 -0
  200. package/src/schema-generator.ts +23 -0
  201. package/src/steps.ts +16 -5
  202. package/src/tui/prompt.ts +11 -5
  203. package/src/tui.ts +21 -2
  204. package/src/types/md.d.ts +8 -0
  205. package/src/types.ts +12 -3
  206. package/dist/cmd/cloud/domain.d.ts +0 -17
  207. package/dist/cmd/cloud/domain.d.ts.map +0 -1
  208. package/dist/cmd/cloud/domain.js +0 -79
  209. package/dist/cmd/cloud/domain.js.map +0 -1
  210. package/src/cmd/cloud/domain.ts +0 -100
@@ -1,22 +1,39 @@
1
1
  import { createCommand } from '../../../types';
2
2
  import { deleteSubcommand } from './delete';
3
+ import { deleteNamespaceSubcommand } from './delete-namespace';
3
4
  import { getSubcommand } from './get';
5
+ import { listNamespacesSubcommand } from './list-namespaces';
4
6
  import { searchSubcommand } from './search';
7
+ import { statsSubcommand } from './stats';
8
+ import { upsertSubcommand } from './upsert';
5
9
  import { getCommand } from '../../../command-prefix';
6
10
 
7
11
  export const vectorCommand = createCommand({
8
12
  name: 'vector',
9
13
  aliases: ['vec'],
10
14
  description: 'Manage vector storage for your projects',
11
- tags: ['requires-auth', 'destructive', 'deletes-resource', 'slow'],
15
+ tags: ['requires-auth', 'slow'],
12
16
  examples: [
13
17
  {
14
- command: getCommand('cloud vector search "query text"'),
18
+ command: getCommand('cloud vector search products "query text"'),
15
19
  description: 'Search vector storage',
16
20
  },
17
- { command: getCommand('cloud vec get <id>'), description: 'Get vector by ID' },
21
+ {
22
+ command: getCommand('cloud vec upsert products doc1 --document "text"'),
23
+ description: 'Upsert a vector',
24
+ },
25
+ { command: getCommand('cloud vec get products doc1'), description: 'Get vector by key' },
26
+ { command: getCommand('cloud vec stats'), description: 'Show namespace statistics' },
27
+ ],
28
+ subcommands: [
29
+ upsertSubcommand,
30
+ searchSubcommand,
31
+ getSubcommand,
32
+ deleteSubcommand,
33
+ statsSubcommand,
34
+ listNamespacesSubcommand,
35
+ deleteNamespaceSubcommand,
18
36
  ],
19
- subcommands: [searchSubcommand, getSubcommand, deleteSubcommand],
20
37
  requires: { auth: true, project: true },
21
38
  });
22
39
 
@@ -0,0 +1,46 @@
1
+ import { z } from 'zod';
2
+ import { createCommand } from '../../../types';
3
+ import * as tui from '../../../tui';
4
+ import { createStorageAdapter } from './util';
5
+ import { getCommand } from '../../../command-prefix';
6
+
7
+ const NamespaceListResponseSchema = z.array(z.string().describe('Namespace name'));
8
+
9
+ export const listNamespacesSubcommand = createCommand({
10
+ name: 'list-namespaces',
11
+ aliases: ['namespaces', 'ns'],
12
+ description: 'List all vector namespaces',
13
+ tags: ['read-only', 'fast', 'requires-auth'],
14
+ requires: { auth: true, project: true },
15
+ examples: [
16
+ { command: getCommand('vector list-namespaces'), description: 'List all namespaces' },
17
+ { command: getCommand('vector namespaces'), description: 'List namespaces (using alias)' },
18
+ { command: getCommand('vector ns'), description: 'List namespaces (short alias)' },
19
+ ],
20
+ schema: {
21
+ response: NamespaceListResponseSchema,
22
+ },
23
+ webUrl: '/services/vector',
24
+ idempotent: true,
25
+
26
+ async handler(ctx) {
27
+ const { options } = ctx;
28
+ const storage = await createStorageAdapter(ctx);
29
+ const namespaces = await storage.getNamespaces();
30
+
31
+ if (!options.json) {
32
+ if (namespaces.length === 0) {
33
+ tui.info('No vector namespaces found');
34
+ } else {
35
+ tui.info(`Found ${namespaces.length} namespace(s):`);
36
+ for (const name of namespaces) {
37
+ tui.arrow(name);
38
+ }
39
+ }
40
+ }
41
+
42
+ return namespaces;
43
+ },
44
+ });
45
+
46
+ export default listNamespacesSubcommand;
@@ -0,0 +1,160 @@
1
+ import { z } from 'zod';
2
+ import { createCommand } from '../../../types';
3
+ import * as tui from '../../../tui';
4
+ import { createStorageAdapter } from './util';
5
+ import { getCommand } from '../../../command-prefix';
6
+
7
+ const VectorItemStatsSchema = z.object({
8
+ embedding: z.array(z.number()).optional().describe('The embedding vector'),
9
+ document: z.string().optional().describe('Original document text'),
10
+ size: z.number().describe('Size in bytes'),
11
+ metadata: z.record(z.string(), z.unknown()).optional().describe('Metadata'),
12
+ firstUsed: z.number().describe('First access timestamp (ms)'),
13
+ lastUsed: z.number().describe('Last access timestamp (ms)'),
14
+ count: z.number().optional().describe('Access count (only available in cloud storage)'),
15
+ });
16
+
17
+ const VectorNamespaceStatsSchema = z.object({
18
+ sum: z.number().describe('Total size in bytes'),
19
+ count: z.number().describe('Number of vectors'),
20
+ createdAt: z.number().optional().describe('Creation timestamp (ms)'),
21
+ lastUsed: z.number().optional().describe('Last used timestamp (ms)'),
22
+ });
23
+
24
+ const VectorStatsResponseSchema = z.union([
25
+ VectorNamespaceStatsSchema.extend({
26
+ namespace: z.string().describe('Namespace name'),
27
+ sampledResults: z.record(z.string(), VectorItemStatsSchema).optional(),
28
+ }),
29
+ z.record(z.string(), VectorNamespaceStatsSchema),
30
+ ]);
31
+
32
+ export const statsSubcommand = createCommand({
33
+ name: 'stats',
34
+ description: 'Get statistics for vector storage',
35
+ tags: ['read-only', 'fast', 'requires-auth'],
36
+ requires: { auth: true, project: true },
37
+ idempotent: true,
38
+ examples: [
39
+ { command: getCommand('vector stats'), description: 'Show stats for all namespaces' },
40
+ {
41
+ command: getCommand('vector stats products'),
42
+ description: 'Show detailed stats for products namespace',
43
+ },
44
+ { command: getCommand('vector stats embeddings'), description: 'Show stats for embeddings' },
45
+ ],
46
+ schema: {
47
+ args: z.object({
48
+ name: z.string().optional().describe('the vector namespace (optional)'),
49
+ }),
50
+ response: VectorStatsResponseSchema,
51
+ },
52
+ webUrl: (ctx) =>
53
+ ctx.args.name ? `/services/vector/${encodeURIComponent(ctx.args.name)}` : '/services/vector',
54
+
55
+ async handler(ctx) {
56
+ const { args, options } = ctx;
57
+ const storage = await createStorageAdapter(ctx);
58
+
59
+ if (args.name) {
60
+ const stats = await storage.getStats(args.name);
61
+
62
+ if (!options.json) {
63
+ if (stats.count === 0 && stats.sum === 0) {
64
+ tui.info(`Namespace ${tui.bold(args.name)} is empty or does not exist`);
65
+ } else {
66
+ tui.info(`Statistics for ${tui.bold(args.name)}:`);
67
+ tui.info(` Vectors: ${stats.count}`);
68
+ const sizeDisplay =
69
+ stats.sum < 1024 * 1024
70
+ ? `${stats.sum.toLocaleString()} bytes`
71
+ : `${(stats.sum / (1024 * 1024)).toFixed(2)} MB`;
72
+ tui.info(` Total size: ${sizeDisplay}`);
73
+
74
+ if (stats.createdAt) {
75
+ tui.info(` Created: ${new Date(stats.createdAt).toLocaleString()}`);
76
+ }
77
+ if (stats.lastUsed) {
78
+ tui.info(` Last used: ${new Date(stats.lastUsed).toLocaleString()}`);
79
+ }
80
+
81
+ if (stats.sampledResults && Object.keys(stats.sampledResults).length > 0) {
82
+ tui.info('');
83
+ tui.info(` Sample vectors (${Object.keys(stats.sampledResults).length}):`);
84
+
85
+ const tableData = Object.entries(stats.sampledResults).map(([key, item]) => {
86
+ const docPreview = item.document
87
+ ? item.document.length > 30
88
+ ? item.document.substring(0, 27) + '...'
89
+ : item.document
90
+ : '-';
91
+ return {
92
+ Key: key,
93
+ Size: `${item.size} bytes`,
94
+ Accesses: item.count ?? '-',
95
+ 'Last Used': new Date(item.lastUsed).toLocaleDateString(),
96
+ Document: docPreview,
97
+ };
98
+ });
99
+
100
+ tui.table(tableData, [
101
+ { name: 'Key', alignment: 'left' },
102
+ { name: 'Size', alignment: 'right' },
103
+ { name: 'Accesses', alignment: 'right' },
104
+ { name: 'Last Used', alignment: 'left' },
105
+ { name: 'Document', alignment: 'left' },
106
+ ]);
107
+ }
108
+ }
109
+ }
110
+
111
+ return {
112
+ namespace: args.name,
113
+ ...stats,
114
+ };
115
+ } else {
116
+ const allStats = await storage.getAllStats();
117
+ const entries = Object.entries(allStats);
118
+
119
+ if (!options.json) {
120
+ if (entries.length === 0) {
121
+ tui.info('No vector namespaces found');
122
+ } else {
123
+ tui.info(
124
+ `Found ${entries.length} ${tui.plural(entries.length, 'namespace', 'namespaces')}:`
125
+ );
126
+
127
+ const tableData = entries.map(([name, stats]) => {
128
+ const sizeDisplay =
129
+ stats.sum < 1024 * 1024
130
+ ? `${stats.sum.toLocaleString()} bytes`
131
+ : `${(stats.sum / (1024 * 1024)).toFixed(2)} MB`;
132
+ return {
133
+ Namespace: name,
134
+ Vectors: stats.count,
135
+ Size: sizeDisplay,
136
+ Created: stats.createdAt
137
+ ? new Date(stats.createdAt).toLocaleDateString()
138
+ : '-',
139
+ 'Last Used': stats.lastUsed
140
+ ? new Date(stats.lastUsed).toLocaleDateString()
141
+ : '-',
142
+ };
143
+ });
144
+
145
+ tui.table(tableData, [
146
+ { name: 'Namespace', alignment: 'left' },
147
+ { name: 'Vectors', alignment: 'right' },
148
+ { name: 'Size', alignment: 'right' },
149
+ { name: 'Created', alignment: 'left' },
150
+ { name: 'Last Used', alignment: 'left' },
151
+ ]);
152
+ }
153
+ }
154
+
155
+ return allStats;
156
+ }
157
+ },
158
+ });
159
+
160
+ export default statsSubcommand;
@@ -0,0 +1,216 @@
1
+ import { z } from 'zod';
2
+ import { createCommand } from '../../../types';
3
+ import * as tui from '../../../tui';
4
+ import { createStorageAdapter } from './util';
5
+ import { getCommand } from '../../../command-prefix';
6
+ import type { VectorUpsertParams } from '@agentuity/core';
7
+
8
+ const VectorUpsertResponseSchema = z.object({
9
+ success: z.boolean().describe('Whether the operation succeeded'),
10
+ namespace: z.string().describe('Namespace name'),
11
+ count: z.number().describe('Number of vectors upserted'),
12
+ results: z
13
+ .array(
14
+ z.object({
15
+ key: z.string().describe('Vector key'),
16
+ id: z.string().describe('Vector ID'),
17
+ })
18
+ )
19
+ .describe('Upsert results with key-to-id mappings'),
20
+ durationMs: z.number().describe('Operation duration in milliseconds'),
21
+ });
22
+
23
+ export const upsertSubcommand = createCommand({
24
+ name: 'upsert',
25
+ aliases: ['put', 'add'],
26
+ description: 'Add or update vectors in the vector storage',
27
+ tags: ['mutating', 'updates-resource', 'slow', 'requires-auth'],
28
+ idempotent: true,
29
+ requires: { auth: true, project: true },
30
+ examples: [
31
+ {
32
+ command: getCommand('vector upsert products doc1 --document "Comfortable office chair"'),
33
+ description: 'Upsert a single vector with document text',
34
+ },
35
+ {
36
+ command: getCommand(
37
+ 'vector upsert products doc1 --document "Chair" --metadata \'{"category":"furniture"}\''
38
+ ),
39
+ description: 'Upsert with metadata',
40
+ },
41
+ {
42
+ command: getCommand('vector upsert embeddings vec1 --embeddings "[0.1, 0.2, 0.3]"'),
43
+ description: 'Upsert with pre-computed embeddings',
44
+ },
45
+ {
46
+ command: getCommand('vector upsert products --file vectors.json'),
47
+ description: 'Bulk upsert from JSON file',
48
+ },
49
+ {
50
+ command: `cat vectors.json | ${getCommand('vector upsert products -')}`,
51
+ description: 'Bulk upsert from stdin',
52
+ },
53
+ ],
54
+ schema: {
55
+ args: z.object({
56
+ namespace: z.string().min(1).describe('the vector storage namespace'),
57
+ key: z
58
+ .string()
59
+ .optional()
60
+ .describe('the key for single vector upsert (not used with --file or stdin)'),
61
+ }),
62
+ options: z.object({
63
+ document: z.string().optional().describe('document text to embed'),
64
+ embeddings: z.string().optional().describe('pre-computed embeddings as JSON array'),
65
+ metadata: z.string().optional().describe('metadata as JSON object'),
66
+ file: z
67
+ .string()
68
+ .optional()
69
+ .describe('path to JSON file containing vectors, or "-" for stdin'),
70
+ }),
71
+ response: VectorUpsertResponseSchema,
72
+ },
73
+ webUrl: (ctx) => `/services/vector/${encodeURIComponent(ctx.args.namespace)}`,
74
+
75
+ async handler(ctx) {
76
+ const { args, opts, options, logger } = ctx;
77
+ const storage = await createStorageAdapter(ctx);
78
+
79
+ let documents: VectorUpsertParams[] = [];
80
+
81
+ // Check if reading from file or stdin
82
+ const fileArg = opts.file || (args.key === '-' ? '-' : undefined);
83
+
84
+ if (fileArg) {
85
+ let content: string;
86
+
87
+ if (fileArg === '-') {
88
+ // Read from stdin
89
+ const chunks: Uint8Array[] = [];
90
+ const reader = Bun.stdin.stream().getReader();
91
+
92
+ while (true) {
93
+ const { done, value } = await reader.read();
94
+ if (done) break;
95
+ chunks.push(value);
96
+ }
97
+
98
+ const decoder = new TextDecoder();
99
+ content = chunks.map((chunk) => decoder.decode(chunk, { stream: true })).join('');
100
+ } else {
101
+ // Read from file
102
+ const file = Bun.file(fileArg);
103
+ if (!(await file.exists())) {
104
+ tui.fatal(`File not found: ${fileArg}`);
105
+ }
106
+ content = await file.text();
107
+ }
108
+
109
+ try {
110
+ const parsed = JSON.parse(content.trim());
111
+ if (Array.isArray(parsed)) {
112
+ documents = parsed as VectorUpsertParams[];
113
+ } else {
114
+ documents = [parsed as VectorUpsertParams];
115
+ }
116
+ } catch {
117
+ tui.fatal('Invalid JSON in input file/stdin');
118
+ }
119
+
120
+ // Validate documents
121
+ for (const doc of documents) {
122
+ if (!doc.key || typeof doc.key !== 'string') {
123
+ tui.fatal('Each document must have a non-empty "key" property');
124
+ }
125
+ if (!doc.document && !('embeddings' in doc)) {
126
+ tui.fatal(
127
+ `Document with key "${doc.key}" must have either "document" or "embeddings" property`
128
+ );
129
+ }
130
+ }
131
+ } else {
132
+ // Single vector upsert via command line arguments
133
+ if (!args.key) {
134
+ tui.fatal('Key is required for single vector upsert. Use --file for bulk upsert.');
135
+ }
136
+
137
+ if (!opts.document && !opts.embeddings) {
138
+ tui.fatal('Either --document or --embeddings is required');
139
+ }
140
+
141
+ if (opts.document && opts.embeddings) {
142
+ tui.fatal('Cannot use both --document and --embeddings');
143
+ }
144
+
145
+ let metadata: Record<string, unknown> | undefined;
146
+ if (opts.metadata) {
147
+ try {
148
+ metadata = JSON.parse(opts.metadata);
149
+ } catch {
150
+ tui.fatal('Invalid JSON in --metadata');
151
+ }
152
+ }
153
+
154
+ if (opts.document) {
155
+ documents = [
156
+ {
157
+ key: args.key,
158
+ document: opts.document,
159
+ metadata,
160
+ },
161
+ ];
162
+ } else if (opts.embeddings) {
163
+ let embeddings: number[];
164
+ try {
165
+ embeddings = JSON.parse(opts.embeddings);
166
+ if (!Array.isArray(embeddings) || !embeddings.every((n) => typeof n === 'number')) {
167
+ throw new Error('Not an array of numbers');
168
+ }
169
+ } catch {
170
+ tui.fatal('Invalid embeddings: must be a JSON array of numbers');
171
+ }
172
+
173
+ documents = [
174
+ {
175
+ key: args.key,
176
+ embeddings,
177
+ metadata,
178
+ },
179
+ ];
180
+ }
181
+ }
182
+
183
+ if (documents.length === 0) {
184
+ tui.fatal('No documents to upsert');
185
+ }
186
+
187
+ const started = Date.now();
188
+
189
+ logger.debug(`Upserting ${documents.length} vector(s) to ${args.namespace}`);
190
+
191
+ const results = await storage.upsert(args.namespace, ...documents);
192
+ const durationMs = Date.now() - started;
193
+
194
+ if (!options.json) {
195
+ tui.success(
196
+ `Upserted ${results.length} vector(s) to ${tui.bold(args.namespace)} (${durationMs}ms)`
197
+ );
198
+
199
+ if (results.length <= 10) {
200
+ for (const result of results) {
201
+ tui.arrow(`${result.key} → ${result.id}`);
202
+ }
203
+ }
204
+ }
205
+
206
+ return {
207
+ success: true,
208
+ namespace: args.namespace,
209
+ count: results.length,
210
+ results,
211
+ durationMs,
212
+ };
213
+ },
214
+ });
215
+
216
+ export default upsertSubcommand;
@@ -5,8 +5,8 @@
5
5
  * Handles both backend (API, agents, lib) and generates restart signals.
6
6
  */
7
7
 
8
- import { watch, type FSWatcher, statSync, readdirSync } from 'node:fs';
9
- import { resolve } from 'node:path';
8
+ import { watch, type FSWatcher, statSync, readdirSync, lstatSync } from 'node:fs';
9
+ import { resolve, relative } from 'node:path';
10
10
  import type { Logger } from '../../types';
11
11
  import { createAgentTemplates, createAPITemplates } from './templates';
12
12
 
@@ -34,13 +34,29 @@ export function createFileWatcher(options: FileWatcherOptions): FileWatcherManag
34
34
  let paused = false;
35
35
  let buildCooldownTimer: NodeJS.Timeout | null = null;
36
36
 
37
- // Watch the entire root directory recursively
38
- // This is simpler and more reliable than watching individual paths
39
- const watchDirs = [rootDir];
37
+ // Directories to ignore - these are NEVER traversed into
38
+ // This prevents EMFILE errors from symlink cycles in node_modules
39
+ const ignoreDirs = new Set([
40
+ '.agentuity',
41
+ '.agents',
42
+ '.claude',
43
+ '.code',
44
+ '.opencode',
45
+ 'node_modules',
46
+ '.git',
47
+ 'dist',
48
+ 'build',
49
+ '.next',
50
+ '.turbo',
51
+ ]);
40
52
 
41
- // Directories to ignore
53
+ // Paths to ignore for file change events (but may still be traversed)
42
54
  const ignorePaths = [
43
55
  '.agentuity',
56
+ '.agents',
57
+ '.claude',
58
+ '.code',
59
+ '.opencode',
44
60
  'node_modules',
45
61
  '.git',
46
62
  'dist',
@@ -168,47 +184,100 @@ export function createFileWatcher(options: FileWatcherOptions): FileWatcherManag
168
184
  }
169
185
 
170
186
  /**
171
- * Start watching files
187
+ * Recursively collect all directories to watch, skipping ignored directories.
188
+ * This prevents EMFILE errors from symlink cycles in node_modules.
172
189
  */
173
- function start() {
174
- logger.debug('Starting file watchers for hot reload...');
190
+ function collectWatchDirs(dir: string, visited: Set<string> = new Set()): string[] {
191
+ const dirs: string[] = [dir];
175
192
 
176
- // Watch root directory (already absolute path)
177
- for (const watchPath of watchDirs) {
178
- try {
179
- logger.trace('Setting up watcher for: %s', watchPath);
193
+ try {
194
+ // Use lstat to check for symlinks - get the real path to detect cycles
195
+ const stat = lstatSync(dir);
180
196
 
181
- const watcher = watch(watchPath, { recursive: true }, (eventType, changedFile) => {
182
- handleFileChange(eventType, changedFile, watchPath);
183
- });
197
+ // Skip symlinks to prevent following circular symlinks
198
+ if (stat.isSymbolicLink()) {
199
+ logger.trace('Skipping symlink: %s', dir);
200
+ return [];
201
+ }
184
202
 
185
- watchers.push(watcher);
186
- logger.trace('Watcher started for: %s', watchPath);
187
- } catch (error) {
188
- logger.warn('Failed to start watcher for %s: %s', watchPath, error);
203
+ // Track visited inodes to detect cycles
204
+ const key = `${stat.dev}:${stat.ino}`;
205
+ if (visited.has(key)) {
206
+ logger.trace('Skipping already visited directory (cycle detected): %s', dir);
207
+ return [];
208
+ }
209
+ visited.add(key);
210
+
211
+ const entries = readdirSync(dir, { withFileTypes: true });
212
+
213
+ for (const entry of entries) {
214
+ if (!entry.isDirectory()) continue;
215
+
216
+ const name = entry.name;
217
+
218
+ // Skip ignored directories entirely - this is the key fix
219
+ if (ignoreDirs.has(name)) {
220
+ logger.trace('Skipping ignored directory: %s', resolve(dir, name));
221
+ continue;
222
+ }
223
+
224
+ // Skip hidden directories (except specific ones like .env folders)
225
+ if (name.startsWith('.')) {
226
+ logger.trace('Skipping hidden directory: %s', resolve(dir, name));
227
+ continue;
228
+ }
229
+
230
+ const fullPath = resolve(dir, name);
231
+ dirs.push(...collectWatchDirs(fullPath, visited));
189
232
  }
233
+ } catch (error) {
234
+ logger.trace('Error reading directory %s: %s', dir, error);
190
235
  }
191
236
 
192
- // Watch additional paths if provided
237
+ return dirs;
238
+ }
239
+
240
+ /**
241
+ * Start watching files
242
+ */
243
+ function start() {
244
+ logger.debug('Starting file watchers for hot reload...');
245
+
246
+ // Collect all directories to watch, excluding node_modules and other ignored dirs
247
+ const allDirs = collectWatchDirs(rootDir);
248
+
249
+ // Add additional paths
193
250
  if (additionalPaths && additionalPaths.length > 0) {
194
251
  for (const additionalPath of additionalPaths) {
195
252
  const fullPath = resolve(rootDir, additionalPath);
196
- try {
197
- logger.trace('Setting up watcher for additional path: %s', fullPath);
253
+ allDirs.push(...collectWatchDirs(fullPath));
254
+ }
255
+ }
198
256
 
199
- const watcher = watch(fullPath, { recursive: true }, (eventType, changedFile) => {
200
- handleFileChange(eventType, changedFile, fullPath);
201
- });
257
+ // De-duplicate directories
258
+ const uniqueDirs = [...new Set(allDirs)];
202
259
 
203
- watchers.push(watcher);
204
- logger.trace('Watcher started for additional path: %s', fullPath);
205
- } catch (error) {
206
- logger.warn('Failed to start watcher for %s: %s', fullPath, error);
207
- }
260
+ logger.debug('Collected %d directories to watch', uniqueDirs.length);
261
+
262
+ // Watch each directory non-recursively
263
+ for (const watchPath of uniqueDirs) {
264
+ try {
265
+ // Use non-recursive watch to avoid traversing into node_modules
266
+ const watcher = watch(watchPath, { recursive: false }, (eventType, changedFile) => {
267
+ // Construct relative path from rootDir for consistent handling
268
+ const relPath = changedFile
269
+ ? relative(rootDir, resolve(watchPath, changedFile))
270
+ : relative(rootDir, watchPath);
271
+ handleFileChange(eventType, relPath || changedFile, rootDir);
272
+ });
273
+
274
+ watchers.push(watcher);
275
+ } catch (error) {
276
+ logger.trace('Failed to start watcher for %s: %s', watchPath, error);
208
277
  }
209
278
  }
210
279
 
211
- logger.debug('File watchers started (%d paths)', watchers.length);
280
+ logger.debug('File watchers started (%d directories)', watchers.length);
212
281
  }
213
282
 
214
283
  /**