@agentuity/cli 0.0.43 → 0.0.45

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 (209) hide show
  1. package/AGENTS.md +1 -1
  2. package/README.md +1 -1
  3. package/dist/api.d.ts +3 -3
  4. package/dist/api.d.ts.map +1 -1
  5. package/dist/auth.d.ts +10 -2
  6. package/dist/auth.d.ts.map +1 -1
  7. package/dist/banner.d.ts.map +1 -1
  8. package/dist/cli.d.ts.map +1 -1
  9. package/dist/cmd/auth/api.d.ts +4 -4
  10. package/dist/cmd/auth/api.d.ts.map +1 -1
  11. package/dist/cmd/auth/index.d.ts.map +1 -1
  12. package/dist/cmd/auth/login.d.ts.map +1 -1
  13. package/dist/cmd/auth/signup.d.ts.map +1 -1
  14. package/dist/cmd/auth/ssh/add.d.ts +2 -0
  15. package/dist/cmd/auth/ssh/add.d.ts.map +1 -0
  16. package/dist/cmd/auth/ssh/api.d.ts +16 -0
  17. package/dist/cmd/auth/ssh/api.d.ts.map +1 -0
  18. package/dist/cmd/auth/ssh/delete.d.ts +2 -0
  19. package/dist/cmd/auth/ssh/delete.d.ts.map +1 -0
  20. package/dist/cmd/auth/ssh/index.d.ts +3 -0
  21. package/dist/cmd/auth/ssh/index.d.ts.map +1 -0
  22. package/dist/cmd/auth/ssh/list.d.ts +2 -0
  23. package/dist/cmd/auth/ssh/list.d.ts.map +1 -0
  24. package/dist/cmd/auth/whoami.d.ts.map +1 -1
  25. package/dist/cmd/bundle/ast.d.ts +14 -3
  26. package/dist/cmd/bundle/ast.d.ts.map +1 -1
  27. package/dist/cmd/bundle/ast.test.d.ts +2 -0
  28. package/dist/cmd/bundle/ast.test.d.ts.map +1 -0
  29. package/dist/cmd/bundle/bundler.d.ts +6 -1
  30. package/dist/cmd/bundle/bundler.d.ts.map +1 -1
  31. package/dist/cmd/bundle/file.d.ts.map +1 -1
  32. package/dist/cmd/bundle/fix-duplicate-exports.d.ts +2 -0
  33. package/dist/cmd/bundle/fix-duplicate-exports.d.ts.map +1 -0
  34. package/dist/cmd/bundle/fix-duplicate-exports.test.d.ts +2 -0
  35. package/dist/cmd/bundle/fix-duplicate-exports.test.d.ts.map +1 -0
  36. package/dist/cmd/bundle/plugin.d.ts +2 -0
  37. package/dist/cmd/bundle/plugin.d.ts.map +1 -1
  38. package/dist/cmd/cloud/deploy.d.ts.map +1 -1
  39. package/dist/cmd/cloud/domain.d.ts +17 -0
  40. package/dist/cmd/cloud/domain.d.ts.map +1 -0
  41. package/dist/cmd/cloud/index.d.ts.map +1 -1
  42. package/dist/cmd/cloud/resource/add.d.ts +2 -0
  43. package/dist/cmd/cloud/resource/add.d.ts.map +1 -0
  44. package/dist/cmd/cloud/resource/delete.d.ts +2 -0
  45. package/dist/cmd/cloud/resource/delete.d.ts.map +1 -0
  46. package/dist/cmd/cloud/resource/index.d.ts +3 -0
  47. package/dist/cmd/cloud/resource/index.d.ts.map +1 -0
  48. package/dist/cmd/cloud/resource/list.d.ts +2 -0
  49. package/dist/cmd/cloud/resource/list.d.ts.map +1 -0
  50. package/dist/cmd/cloud/scp/download.d.ts +2 -0
  51. package/dist/cmd/cloud/scp/download.d.ts.map +1 -0
  52. package/dist/cmd/cloud/scp/index.d.ts +3 -0
  53. package/dist/cmd/cloud/scp/index.d.ts.map +1 -0
  54. package/dist/cmd/cloud/scp/upload.d.ts +2 -0
  55. package/dist/cmd/cloud/scp/upload.d.ts.map +1 -0
  56. package/dist/cmd/cloud/ssh.d.ts +2 -0
  57. package/dist/cmd/cloud/ssh.d.ts.map +1 -0
  58. package/dist/cmd/dev/api.d.ts +18 -0
  59. package/dist/cmd/dev/api.d.ts.map +1 -0
  60. package/dist/cmd/dev/download.d.ts +11 -0
  61. package/dist/cmd/dev/download.d.ts.map +1 -0
  62. package/dist/cmd/dev/index.d.ts.map +1 -1
  63. package/dist/cmd/dev/templates.d.ts +3 -0
  64. package/dist/cmd/dev/templates.d.ts.map +1 -0
  65. package/dist/cmd/env/delete.d.ts.map +1 -1
  66. package/dist/cmd/env/get.d.ts.map +1 -1
  67. package/dist/cmd/env/import.d.ts.map +1 -1
  68. package/dist/cmd/env/list.d.ts.map +1 -1
  69. package/dist/cmd/env/pull.d.ts.map +1 -1
  70. package/dist/cmd/env/push.d.ts.map +1 -1
  71. package/dist/cmd/env/set.d.ts.map +1 -1
  72. package/dist/cmd/profile/show.d.ts.map +1 -1
  73. package/dist/cmd/project/create.d.ts.map +1 -1
  74. package/dist/cmd/project/delete.d.ts.map +1 -1
  75. package/dist/cmd/project/list.d.ts.map +1 -1
  76. package/dist/cmd/project/show.d.ts.map +1 -1
  77. package/dist/cmd/project/template-flow.d.ts +4 -0
  78. package/dist/cmd/project/template-flow.d.ts.map +1 -1
  79. package/dist/cmd/secret/delete.d.ts.map +1 -1
  80. package/dist/cmd/secret/get.d.ts.map +1 -1
  81. package/dist/cmd/secret/import.d.ts.map +1 -1
  82. package/dist/cmd/secret/list.d.ts.map +1 -1
  83. package/dist/cmd/secret/pull.d.ts.map +1 -1
  84. package/dist/cmd/secret/push.d.ts.map +1 -1
  85. package/dist/cmd/secret/set.d.ts.map +1 -1
  86. package/dist/config.d.ts +9 -3
  87. package/dist/config.d.ts.map +1 -1
  88. package/dist/crypto/box.d.ts +65 -0
  89. package/dist/crypto/box.d.ts.map +1 -0
  90. package/dist/crypto/box.test.d.ts +2 -0
  91. package/dist/crypto/box.test.d.ts.map +1 -0
  92. package/dist/download.d.ts.map +1 -1
  93. package/dist/steps.d.ts +4 -1
  94. package/dist/steps.d.ts.map +1 -1
  95. package/dist/terminal.d.ts.map +1 -1
  96. package/dist/tui.d.ts +31 -1
  97. package/dist/tui.d.ts.map +1 -1
  98. package/dist/types.d.ts +249 -126
  99. package/dist/types.d.ts.map +1 -1
  100. package/dist/utils/detectSubagent.d.ts +15 -0
  101. package/dist/utils/detectSubagent.d.ts.map +1 -0
  102. package/dist/utils/zip.d.ts +7 -0
  103. package/dist/utils/zip.d.ts.map +1 -0
  104. package/package.json +11 -3
  105. package/src/api-errors.md +2 -2
  106. package/src/api.ts +12 -7
  107. package/src/auth.ts +116 -7
  108. package/src/banner.ts +13 -6
  109. package/src/cli.ts +695 -63
  110. package/src/cmd/auth/api.ts +10 -16
  111. package/src/cmd/auth/index.ts +2 -1
  112. package/src/cmd/auth/login.ts +24 -8
  113. package/src/cmd/auth/signup.ts +15 -11
  114. package/src/cmd/auth/ssh/add.ts +263 -0
  115. package/src/cmd/auth/ssh/api.ts +94 -0
  116. package/src/cmd/auth/ssh/delete.ts +102 -0
  117. package/src/cmd/auth/ssh/index.ts +10 -0
  118. package/src/cmd/auth/ssh/list.ts +74 -0
  119. package/src/cmd/auth/whoami.ts +13 -13
  120. package/src/cmd/bundle/ast.test.ts +565 -0
  121. package/src/cmd/bundle/ast.ts +457 -44
  122. package/src/cmd/bundle/bundler.ts +255 -57
  123. package/src/cmd/bundle/file.ts +6 -12
  124. package/src/cmd/bundle/fix-duplicate-exports.test.ts +387 -0
  125. package/src/cmd/bundle/fix-duplicate-exports.ts +204 -0
  126. package/src/cmd/bundle/index.ts +9 -9
  127. package/src/cmd/bundle/patch/aisdk.ts +1 -1
  128. package/src/cmd/bundle/plugin.ts +373 -53
  129. package/src/cmd/cloud/deploy.ts +300 -93
  130. package/src/cmd/cloud/domain.ts +92 -0
  131. package/src/cmd/cloud/index.ts +4 -1
  132. package/src/cmd/cloud/resource/add.ts +56 -0
  133. package/src/cmd/cloud/resource/delete.ts +120 -0
  134. package/src/cmd/cloud/resource/index.ts +11 -0
  135. package/src/cmd/cloud/resource/list.ts +69 -0
  136. package/src/cmd/cloud/scp/download.ts +59 -0
  137. package/src/cmd/cloud/scp/index.ts +9 -0
  138. package/src/cmd/cloud/scp/upload.ts +62 -0
  139. package/src/cmd/cloud/ssh.ts +68 -0
  140. package/src/cmd/dev/api.ts +46 -0
  141. package/src/cmd/dev/download.ts +111 -0
  142. package/src/cmd/dev/index.ts +360 -34
  143. package/src/cmd/dev/templates.ts +84 -0
  144. package/src/cmd/env/delete.ts +5 -20
  145. package/src/cmd/env/get.ts +5 -18
  146. package/src/cmd/env/import.ts +5 -20
  147. package/src/cmd/env/list.ts +5 -18
  148. package/src/cmd/env/pull.ts +10 -23
  149. package/src/cmd/env/push.ts +5 -23
  150. package/src/cmd/env/set.ts +5 -20
  151. package/src/cmd/index.ts +2 -2
  152. package/src/cmd/profile/show.ts +15 -6
  153. package/src/cmd/project/create.ts +7 -2
  154. package/src/cmd/project/delete.ts +75 -18
  155. package/src/cmd/project/download.ts +2 -2
  156. package/src/cmd/project/list.ts +8 -8
  157. package/src/cmd/project/show.ts +3 -7
  158. package/src/cmd/project/template-flow.ts +170 -72
  159. package/src/cmd/secret/delete.ts +5 -20
  160. package/src/cmd/secret/get.ts +5 -18
  161. package/src/cmd/secret/import.ts +5 -20
  162. package/src/cmd/secret/list.ts +5 -18
  163. package/src/cmd/secret/pull.ts +10 -23
  164. package/src/cmd/secret/push.ts +5 -23
  165. package/src/cmd/secret/set.ts +5 -20
  166. package/src/config.ts +224 -24
  167. package/src/crypto/box.test.ts +431 -0
  168. package/src/crypto/box.ts +477 -0
  169. package/src/download.ts +1 -0
  170. package/src/env-util.test.ts +1 -1
  171. package/src/steps.ts +65 -6
  172. package/src/terminal.ts +24 -23
  173. package/src/tui.ts +192 -61
  174. package/src/types.ts +291 -201
  175. package/src/utils/detectSubagent.ts +31 -0
  176. package/src/utils/zip.ts +38 -0
  177. package/dist/cmd/example/create-user.d.ts +0 -2
  178. package/dist/cmd/example/create-user.d.ts.map +0 -1
  179. package/dist/cmd/example/create.d.ts +0 -2
  180. package/dist/cmd/example/create.d.ts.map +0 -1
  181. package/dist/cmd/example/deploy.d.ts +0 -2
  182. package/dist/cmd/example/deploy.d.ts.map +0 -1
  183. package/dist/cmd/example/index.d.ts +0 -2
  184. package/dist/cmd/example/index.d.ts.map +0 -1
  185. package/dist/cmd/example/list.d.ts +0 -2
  186. package/dist/cmd/example/list.d.ts.map +0 -1
  187. package/dist/cmd/example/optional-auth.d.ts +0 -3
  188. package/dist/cmd/example/optional-auth.d.ts.map +0 -1
  189. package/dist/cmd/example/run-command.d.ts +0 -2
  190. package/dist/cmd/example/run-command.d.ts.map +0 -1
  191. package/dist/cmd/example/sound.d.ts +0 -3
  192. package/dist/cmd/example/sound.d.ts.map +0 -1
  193. package/dist/cmd/example/spinner.d.ts +0 -2
  194. package/dist/cmd/example/spinner.d.ts.map +0 -1
  195. package/dist/cmd/example/steps.d.ts +0 -2
  196. package/dist/cmd/example/steps.d.ts.map +0 -1
  197. package/dist/cmd/example/version.d.ts +0 -2
  198. package/dist/cmd/example/version.d.ts.map +0 -1
  199. package/src/cmd/example/create-user.ts +0 -38
  200. package/src/cmd/example/create.ts +0 -31
  201. package/src/cmd/example/deploy.ts +0 -36
  202. package/src/cmd/example/index.ts +0 -29
  203. package/src/cmd/example/list.ts +0 -32
  204. package/src/cmd/example/optional-auth.ts +0 -38
  205. package/src/cmd/example/run-command.ts +0 -45
  206. package/src/cmd/example/sound.ts +0 -14
  207. package/src/cmd/example/spinner.ts +0 -44
  208. package/src/cmd/example/steps.ts +0 -66
  209. package/src/cmd/example/version.ts +0 -13
@@ -1,16 +1,31 @@
1
- import { join, resolve } from 'node:path';
2
- import { cpSync, existsSync, rmSync } from 'node:fs';
3
- import AgentuityBundler from './plugin';
1
+ import { $ } from 'bun';
2
+ import { join, relative, resolve, dirname } from 'node:path';
3
+ import { cpSync, existsSync, mkdirSync, rmSync } from 'node:fs';
4
+ import gitParseUrl from 'git-url-parse';
5
+ import AgentuityBundler, { getBuildMetadata } from './plugin';
4
6
  import { getFilesRecursively } from './file';
5
7
  import { getVersion } from '../../version';
8
+ import type { Project } from '../../types';
9
+ import { fixDuplicateExportsInDirectory } from './fix-duplicate-exports';
6
10
 
7
11
  export interface BundleOptions {
8
12
  rootDir: string;
9
13
  dev?: boolean;
10
14
  env?: Map<string, string>;
15
+ orgId?: string;
16
+ projectId?: string;
17
+ deploymentId?: string;
18
+ project?: Project;
11
19
  }
12
20
 
13
- export async function bundle({ dev = false, rootDir }: BundleOptions) {
21
+ export async function bundle({
22
+ orgId,
23
+ projectId,
24
+ deploymentId,
25
+ dev = false,
26
+ rootDir,
27
+ project,
28
+ }: BundleOptions) {
14
29
  const appFile = join(rootDir, 'app.ts');
15
30
  if (!existsSync(appFile)) {
16
31
  throw new Error(`App file not found at expected location: ${appFile}`);
@@ -37,21 +52,33 @@ export async function bundle({ dev = false, rootDir }: BundleOptions) {
37
52
  }
38
53
  appEntrypoints.push(appFile);
39
54
 
40
- const webDir = join(srcDir, 'web');
41
-
42
55
  if (existsSync(outDir)) {
43
56
  rmSync(outDir, { recursive: true, force: true });
44
57
  }
58
+ // Ensure output directory and subdirectories exist before building
59
+ mkdirSync(outDir, { recursive: true });
60
+ mkdirSync(join(outDir, 'chunk'), { recursive: true });
61
+ mkdirSync(join(outDir, 'asset'), { recursive: true });
45
62
 
46
- const pkgFile = Bun.file('./package.json');
63
+ const pkgFile = Bun.file(join(rootDir, 'package.json'));
47
64
  const pkgContents = JSON.parse(await pkgFile.text());
48
65
  const isProd = !dev;
49
66
 
50
- const define = {
67
+ const define: Record<string, string> = {
51
68
  'process.env.AGENTUITY_CLOUD_SDK_VERSION': JSON.stringify(getVersion() ?? '1.0.0'),
52
69
  'process.env.NODE_ENV': JSON.stringify(isProd ? 'production' : 'development'),
53
70
  };
54
71
 
72
+ if (orgId) {
73
+ define['process.env.AGENTUITY_CLOUD_ORG_ID'] = JSON.stringify(orgId);
74
+ }
75
+ if (projectId) {
76
+ define['process.env.AGENTUITY_CLOUD_PROJECT_ID'] = JSON.stringify(projectId);
77
+ }
78
+ if (deploymentId) {
79
+ define['process.env.AGENTUITY_CLOUD_DEPLOYMENT_ID'] = JSON.stringify(deploymentId);
80
+ }
81
+
55
82
  await (async () => {
56
83
  const config: Bun.BuildConfig = {
57
84
  entrypoints: appEntrypoints,
@@ -64,78 +91,249 @@ export async function bundle({ dev = false, rootDir }: BundleOptions) {
64
91
  target: 'bun',
65
92
  format: 'esm',
66
93
  banner: `// Generated file. DO NOT EDIT`,
67
- minify: isProd,
94
+ // Disable minify for server bundle (keep code readable for debugging)
95
+ // Enable splitting to reduce bundle size by extracting common code
96
+ minify: false,
68
97
  drop: isProd ? ['debugger'] : undefined,
98
+ splitting: true,
69
99
  conditions: [isProd ? 'production' : 'development', 'bun'],
100
+ naming: {
101
+ entry: '[dir]/[name].[ext]',
102
+ chunk: 'chunk/[name]-[hash].[ext]',
103
+ asset: 'asset/[name]-[hash].[ext]',
104
+ },
70
105
  };
71
106
  try {
72
107
  await Bun.build(config);
108
+ // Fix duplicate exports caused by Bun splitting bug
109
+ // See: https://github.com/oven-sh/bun/issues/5344
110
+ await fixDuplicateExportsInDirectory(outDir, false);
73
111
  } catch (ex) {
74
112
  console.error(ex);
75
113
  process.exit(1);
76
114
  }
77
115
  })();
78
116
 
79
- await (async () => {
80
- // Find workspace root for monorepo support
81
- let workspaceRoot = rootDir;
82
- let currentDir = rootDir;
83
- while (true) {
84
- const pkgPath = join(currentDir, 'package.json');
85
- if (existsSync(pkgPath)) {
86
- const pkg = JSON.parse(await Bun.file(pkgPath).text());
87
- if (pkg.workspaces) {
88
- workspaceRoot = currentDir;
89
- break;
117
+ const buildmetadata = getBuildMetadata();
118
+ buildmetadata.assets = [];
119
+ buildmetadata.project = {
120
+ id: projectId ?? '',
121
+ name: pkgContents.name,
122
+ version: pkgContents.version,
123
+ orgId: orgId ?? '',
124
+ };
125
+ buildmetadata.deployment = {
126
+ ...(project?.deployment ?? {}),
127
+ build: {
128
+ bun: Bun.version,
129
+ agentuity: '',
130
+ arch: process.arch,
131
+ platform: process.platform,
132
+ },
133
+ date: new Date().toUTCString(),
134
+ id: deploymentId ?? '',
135
+ };
136
+ if (!dev) {
137
+ // try local first
138
+ const agNMPackage = join(rootDir, 'node_modules', '@agentuity', 'cli', 'package.json');
139
+ if (existsSync(agNMPackage)) {
140
+ try {
141
+ const npmpkg = await Bun.file(agNMPackage).json();
142
+ if (npmpkg.version) {
143
+ buildmetadata.deployment.build.agentuity = npmpkg.version;
90
144
  }
145
+ } catch {
146
+ // Ignore malformed package.json
147
+ }
148
+ } else {
149
+ try {
150
+ // now try the global
151
+ const r = $`bunx @agentuity/cli version`.quiet().nothrow();
152
+ if (r) {
153
+ const version = await r.text();
154
+ if (version) {
155
+ buildmetadata.deployment.build.agentuity = version.trim();
156
+ }
157
+ }
158
+ } catch {
159
+ // ignore error from bunx
91
160
  }
92
- const parent = resolve(currentDir, '..');
93
- if (parent === currentDir) break; // reached filesystem root
94
- currentDir = parent;
95
161
  }
162
+ }
96
163
 
97
- // Make webEntrypoints - just the HTML files themselves
98
- const webEntrypoints = [...new Bun.Glob('**.html').scanSync(webDir)].map((htmlFile) =>
99
- resolve(webDir, htmlFile)
100
- );
164
+ // web folder is optional
165
+ const webDir = join(srcDir, 'web');
166
+ if (existsSync(webDir)) {
167
+ await (async () => {
168
+ // Find workspace root for monorepo support
169
+ let workspaceRoot = rootDir;
170
+ let currentDir = rootDir;
171
+ while (true) {
172
+ const pkgPath = join(currentDir, 'package.json');
173
+ if (existsSync(pkgPath)) {
174
+ const pkg = JSON.parse(await Bun.file(pkgPath).text());
175
+ if (pkg.workspaces) {
176
+ workspaceRoot = currentDir;
177
+ break;
178
+ }
179
+ }
180
+ const parent = resolve(currentDir, '..');
181
+ if (parent === currentDir) break; // reached filesystem root
182
+ currentDir = parent;
183
+ }
101
184
 
102
- const config: Bun.BuildConfig = {
103
- entrypoints: webEntrypoints,
104
- root: webDir,
105
- outdir: join(outDir, 'web'),
106
- define,
107
- sourcemap: dev ? 'inline' : 'linked',
108
- env: 'AGENTUITY_PUBLIC_*',
109
- plugins: [AgentuityBundler],
110
- target: 'browser',
111
- format: 'cjs',
112
- banner: `// Generated file. DO NOT EDIT`,
113
- minify: isProd,
114
- drop: isProd ? ['debugger'] : undefined,
115
- naming: {
116
- entry: '[name].js',
117
- chunk: 'chunk/[name]-[hash].js',
118
- asset: 'asset/[name]-[hash].[ext]',
119
- },
120
- packages: 'bundle',
121
- external: workspaceRoot !== rootDir ? [] : undefined,
185
+ // Make webEntrypoints - just the HTML files themselves
186
+ const webEntrypoints = [...new Bun.Glob('**.html').scanSync(webDir)].map((htmlFile) =>
187
+ resolve(webDir, htmlFile)
188
+ );
189
+
190
+ if (webEntrypoints.length) {
191
+ const config: Bun.BuildConfig = {
192
+ entrypoints: webEntrypoints,
193
+ root: webDir,
194
+ outdir: join(outDir, 'web'),
195
+ define,
196
+ sourcemap: dev ? 'inline' : 'linked',
197
+ env: 'AGENTUITY_PUBLIC_*',
198
+ plugins: [AgentuityBundler],
199
+ target: 'browser',
200
+ format: 'esm',
201
+ banner: `// Generated file. DO NOT EDIT`,
202
+ minify: true,
203
+ drop: isProd ? ['debugger'] : undefined,
204
+ splitting: true,
205
+ packages: 'bundle',
206
+ external: workspaceRoot !== rootDir ? [] : undefined,
207
+ publicPath:
208
+ isProd && deploymentId
209
+ ? `https://static.agentuity.com/${deploymentId}/`
210
+ : undefined,
211
+ naming: {
212
+ entry: '[dir]/[name].[ext]',
213
+ chunk: 'web/chunk/[name]-[hash].[ext]',
214
+ asset: 'web/asset/[name]-[hash].[ext]',
215
+ },
216
+ };
217
+ try {
218
+ const result = await Bun.build(config);
219
+ if (result.success) {
220
+ // Fix duplicate exports caused by Bun splitting bug
221
+ // See: https://github.com/oven-sh/bun/issues/5344
222
+ await fixDuplicateExportsInDirectory(join(outDir, 'web'), false);
223
+
224
+ if (!dev && buildmetadata?.assets) {
225
+ const assets = buildmetadata.assets;
226
+ result.outputs
227
+ // Filter for deployable assets: sourcemaps (hash '00000000') and content-addressed files
228
+ .filter((x) => x.hash === '00000000' || (x.hash && x.path.includes(x.hash)))
229
+ .forEach((artifact) => {
230
+ const r = relative(join(outDir, 'web'), artifact.path);
231
+ assets.push({
232
+ filename: r,
233
+ kind: artifact.kind,
234
+ contentType: artifact.type,
235
+ size: artifact.size,
236
+ });
237
+ });
238
+ }
239
+ } else {
240
+ console.error(result.logs.join('\n'));
241
+ process.exit(1);
242
+ }
243
+ } catch (ex) {
244
+ console.error(ex);
245
+ process.exit(1);
246
+ }
247
+ }
248
+ })();
249
+
250
+ if (!dev && buildmetadata) {
251
+ const webPublicDir = join(webDir, 'public');
252
+ if (existsSync(webPublicDir)) {
253
+ const assets = buildmetadata.assets;
254
+ const webOutPublicDir = join(outDir, 'web', 'public');
255
+ cpSync(webPublicDir, webOutPublicDir, { recursive: true });
256
+ [...new Bun.Glob('**.*').scanSync(webOutPublicDir)].forEach((f) => {
257
+ const bf = Bun.file(join(webOutPublicDir, f));
258
+ assets.push({
259
+ filename: join('public', f),
260
+ kind: 'static',
261
+ contentType: bf.type,
262
+ size: bf.size,
263
+ });
264
+ });
265
+ }
266
+ }
267
+ }
268
+
269
+ if (!dev && Bun.which('git') && buildmetadata?.deployment) {
270
+ buildmetadata.deployment.git = {
271
+ commit: process.env.GIT_SHA || process.env.GITHUB_SHA,
272
+ branch: process.env.GITHUB_REF ? process.env.GITHUB_REF.replace('refs/heads/', '') : '',
273
+ repo: process.env.GITHUB_REPOSITORY
274
+ ? gitParseUrl(process.env.GITHUB_REPOSITORY).toString('https')
275
+ : '',
122
276
  };
277
+ // pull out the git information if we have it
123
278
  try {
124
- await Bun.build(config);
125
- } catch (ex) {
126
- console.error(ex);
127
- process.exit(1);
279
+ let gitDir = join(rootDir, '.git');
280
+ let parentDir = dirname(dirname(gitDir));
281
+ while (!existsSync(gitDir) && parentDir !== dirname(parentDir) && gitDir !== '/') {
282
+ gitDir = join(parentDir, '.git');
283
+ parentDir = dirname(parentDir);
284
+ }
285
+ if (existsSync(gitDir)) {
286
+ const tag = $`git tag -l --points-at HEAD`.nothrow().quiet();
287
+ if (tag) {
288
+ const tags = await tag.text();
289
+ buildmetadata.deployment.git.tags = tags
290
+ .trim()
291
+ .split(/\n/)
292
+ .map((s) => s.trim())
293
+ .filter(Boolean);
294
+ }
295
+ const branch = $`git branch --show-current`.nothrow().quiet();
296
+ if (branch) {
297
+ const _branch = await branch.text();
298
+ if (_branch) {
299
+ buildmetadata.deployment.git.branch = _branch.trim();
300
+ }
301
+ }
302
+ const commit = $`git rev-parse HEAD`.nothrow().quiet();
303
+ if (commit) {
304
+ const sha = await commit.text();
305
+ if (sha) {
306
+ buildmetadata.deployment.git.commit = sha.trim();
307
+ const msg = $`git log --pretty=format:%s -n1 ${buildmetadata.deployment.git.commit}`;
308
+ if (msg) {
309
+ const _msg = await msg.text();
310
+ if (_msg) {
311
+ buildmetadata.deployment.git.message = _msg.trim();
312
+ }
313
+ }
314
+ const origin = $`git config --get remote.origin.url`.nothrow().quiet();
315
+ if (origin) {
316
+ const _origin = await origin.text();
317
+ if (_origin) {
318
+ const _url = gitParseUrl(_origin.trim());
319
+ buildmetadata.deployment.git.repo = _url.toString('https');
320
+ }
321
+ }
322
+ }
323
+ }
324
+ }
325
+ } catch {
326
+ // ignore errors
128
327
  }
129
- })();
130
-
131
- const webPublicDir = join(webDir, 'public');
132
- if (existsSync(webPublicDir)) {
133
- const webOutPublicDir = join(outDir, 'web', 'public');
134
- cpSync(webPublicDir, webOutPublicDir, { recursive: true });
135
328
  }
136
329
 
137
330
  await Bun.write(
138
331
  `${outDir}/package.json`,
139
332
  JSON.stringify({ name: pkgContents.name, version: pkgContents.version }, null, 2)
140
333
  );
334
+
335
+ await Bun.write(
336
+ `${outDir}/agentuity.metadata.json`,
337
+ dev ? JSON.stringify(buildmetadata, null, 2) : JSON.stringify(buildmetadata)
338
+ );
141
339
  }
@@ -1,16 +1,10 @@
1
- import fs from 'node:fs';
2
1
  import { resolve } from 'node:path';
3
- import { promisify } from 'node:util';
4
-
5
- const readdir = promisify(fs.readdir);
6
2
 
7
3
  export async function getFilesRecursively(dir: string): Promise<string[]> {
8
- const subdirs = await readdir(dir, { withFileTypes: true });
9
- const files = await Promise.all(
10
- subdirs.map(async (dirent: fs.Dirent) => {
11
- const res = resolve(dir, dirent.name);
12
- return dirent.isDirectory() ? getFilesRecursively(res) : res;
13
- })
14
- );
15
- return files.flat();
4
+ const glob = new Bun.Glob('**/*');
5
+ const files: string[] = [];
6
+ for await (const file of glob.scan({ cwd: dir, onlyFiles: true, absolute: false })) {
7
+ files.push(resolve(dir, file));
8
+ }
9
+ return files;
16
10
  }