@agentuity/cli 2.0.11 → 2.0.13

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 (274) hide show
  1. package/dist/cache/resource-region.d.ts.map +1 -1
  2. package/dist/cache/resource-region.js +48 -25
  3. package/dist/cache/resource-region.js.map +1 -1
  4. package/dist/cli.d.ts.map +1 -1
  5. package/dist/cli.js +15 -8
  6. package/dist/cli.js.map +1 -1
  7. package/dist/cmd/build/vite/bun-dev-server.d.ts +20 -0
  8. package/dist/cmd/build/vite/bun-dev-server.d.ts.map +1 -1
  9. package/dist/cmd/build/vite/bun-dev-server.js +62 -4
  10. package/dist/cmd/build/vite/bun-dev-server.js.map +1 -1
  11. package/dist/cmd/build/vite/index.d.ts +0 -1
  12. package/dist/cmd/build/vite/index.d.ts.map +1 -1
  13. package/dist/cmd/build/vite/index.js +0 -1
  14. package/dist/cmd/build/vite/index.js.map +1 -1
  15. package/dist/cmd/build/vite/static-renderer.d.ts +17 -0
  16. package/dist/cmd/build/vite/static-renderer.d.ts.map +1 -1
  17. package/dist/cmd/build/vite/static-renderer.js +18 -6
  18. package/dist/cmd/build/vite/static-renderer.js.map +1 -1
  19. package/dist/cmd/build/vite/vite-asset-server-config.d.ts.map +1 -1
  20. package/dist/cmd/build/vite/vite-asset-server-config.js +34 -27
  21. package/dist/cmd/build/vite/vite-asset-server-config.js.map +1 -1
  22. package/dist/cmd/build/vite/vite-asset-server.d.ts +9 -0
  23. package/dist/cmd/build/vite/vite-asset-server.d.ts.map +1 -1
  24. package/dist/cmd/build/vite/vite-asset-server.js +5 -1
  25. package/dist/cmd/build/vite/vite-asset-server.js.map +1 -1
  26. package/dist/cmd/build/vite/vite-builder.d.ts.map +1 -1
  27. package/dist/cmd/build/vite/vite-builder.js +12 -1
  28. package/dist/cmd/build/vite/vite-builder.js.map +1 -1
  29. package/dist/cmd/build/vite/ws-proxy.d.ts +15 -1
  30. package/dist/cmd/build/vite/ws-proxy.d.ts.map +1 -1
  31. package/dist/cmd/build/vite/ws-proxy.js +33 -0
  32. package/dist/cmd/build/vite/ws-proxy.js.map +1 -1
  33. package/dist/cmd/cloud/deploy.d.ts.map +1 -1
  34. package/dist/cmd/cloud/deploy.js +98 -39
  35. package/dist/cmd/cloud/deploy.js.map +1 -1
  36. package/dist/cmd/cloud/sandbox/checkpoint/create.d.ts.map +1 -1
  37. package/dist/cmd/cloud/sandbox/checkpoint/create.js +3 -4
  38. package/dist/cmd/cloud/sandbox/checkpoint/create.js.map +1 -1
  39. package/dist/cmd/cloud/sandbox/checkpoint/delete.d.ts.map +1 -1
  40. package/dist/cmd/cloud/sandbox/checkpoint/delete.js +3 -4
  41. package/dist/cmd/cloud/sandbox/checkpoint/delete.js.map +1 -1
  42. package/dist/cmd/cloud/sandbox/checkpoint/list.d.ts.map +1 -1
  43. package/dist/cmd/cloud/sandbox/checkpoint/list.js +3 -4
  44. package/dist/cmd/cloud/sandbox/checkpoint/list.js.map +1 -1
  45. package/dist/cmd/cloud/sandbox/checkpoint/restore.d.ts.map +1 -1
  46. package/dist/cmd/cloud/sandbox/checkpoint/restore.js +3 -4
  47. package/dist/cmd/cloud/sandbox/checkpoint/restore.js.map +1 -1
  48. package/dist/cmd/cloud/sandbox/create.d.ts.map +1 -1
  49. package/dist/cmd/cloud/sandbox/create.js +13 -4
  50. package/dist/cmd/cloud/sandbox/create.js.map +1 -1
  51. package/dist/cmd/cloud/sandbox/delete.d.ts.map +1 -1
  52. package/dist/cmd/cloud/sandbox/delete.js +3 -4
  53. package/dist/cmd/cloud/sandbox/delete.js.map +1 -1
  54. package/dist/cmd/cloud/sandbox/env.d.ts.map +1 -1
  55. package/dist/cmd/cloud/sandbox/env.js +3 -5
  56. package/dist/cmd/cloud/sandbox/env.js.map +1 -1
  57. package/dist/cmd/cloud/sandbox/exec.d.ts.map +1 -1
  58. package/dist/cmd/cloud/sandbox/exec.js +114 -41
  59. package/dist/cmd/cloud/sandbox/exec.js.map +1 -1
  60. package/dist/cmd/cloud/sandbox/execution/list.d.ts.map +1 -1
  61. package/dist/cmd/cloud/sandbox/execution/list.js +3 -5
  62. package/dist/cmd/cloud/sandbox/execution/list.js.map +1 -1
  63. package/dist/cmd/cloud/sandbox/fs/cp.d.ts.map +1 -1
  64. package/dist/cmd/cloud/sandbox/fs/cp.js +61 -113
  65. package/dist/cmd/cloud/sandbox/fs/cp.js.map +1 -1
  66. package/dist/cmd/cloud/sandbox/fs/download.d.ts.map +1 -1
  67. package/dist/cmd/cloud/sandbox/fs/download.js +11 -22
  68. package/dist/cmd/cloud/sandbox/fs/download.js.map +1 -1
  69. package/dist/cmd/cloud/sandbox/fs/ls.d.ts.map +1 -1
  70. package/dist/cmd/cloud/sandbox/fs/ls.js +3 -5
  71. package/dist/cmd/cloud/sandbox/fs/ls.js.map +1 -1
  72. package/dist/cmd/cloud/sandbox/fs/mkdir.d.ts.map +1 -1
  73. package/dist/cmd/cloud/sandbox/fs/mkdir.js +3 -5
  74. package/dist/cmd/cloud/sandbox/fs/mkdir.js.map +1 -1
  75. package/dist/cmd/cloud/sandbox/fs/rm.d.ts.map +1 -1
  76. package/dist/cmd/cloud/sandbox/fs/rm.js +3 -5
  77. package/dist/cmd/cloud/sandbox/fs/rm.js.map +1 -1
  78. package/dist/cmd/cloud/sandbox/fs/rmdir.d.ts.map +1 -1
  79. package/dist/cmd/cloud/sandbox/fs/rmdir.js +3 -5
  80. package/dist/cmd/cloud/sandbox/fs/rmdir.js.map +1 -1
  81. package/dist/cmd/cloud/sandbox/fs/upload.d.ts.map +1 -1
  82. package/dist/cmd/cloud/sandbox/fs/upload.js +7 -8
  83. package/dist/cmd/cloud/sandbox/fs/upload.js.map +1 -1
  84. package/dist/cmd/cloud/sandbox/get.d.ts.map +1 -1
  85. package/dist/cmd/cloud/sandbox/get.js +21 -7
  86. package/dist/cmd/cloud/sandbox/get.js.map +1 -1
  87. package/dist/cmd/cloud/sandbox/job/create.d.ts.map +1 -1
  88. package/dist/cmd/cloud/sandbox/job/create.js +3 -4
  89. package/dist/cmd/cloud/sandbox/job/create.js.map +1 -1
  90. package/dist/cmd/cloud/sandbox/job/destroy.d.ts.map +1 -1
  91. package/dist/cmd/cloud/sandbox/job/destroy.js +3 -4
  92. package/dist/cmd/cloud/sandbox/job/destroy.js.map +1 -1
  93. package/dist/cmd/cloud/sandbox/job/get.d.ts.map +1 -1
  94. package/dist/cmd/cloud/sandbox/job/get.js +3 -4
  95. package/dist/cmd/cloud/sandbox/job/get.js.map +1 -1
  96. package/dist/cmd/cloud/sandbox/job/list.d.ts.map +1 -1
  97. package/dist/cmd/cloud/sandbox/job/list.js +3 -4
  98. package/dist/cmd/cloud/sandbox/job/list.js.map +1 -1
  99. package/dist/cmd/cloud/sandbox/job/logs.d.ts.map +1 -1
  100. package/dist/cmd/cloud/sandbox/job/logs.js +4 -4
  101. package/dist/cmd/cloud/sandbox/job/logs.js.map +1 -1
  102. package/dist/cmd/cloud/sandbox/pause.d.ts.map +1 -1
  103. package/dist/cmd/cloud/sandbox/pause.js +21 -5
  104. package/dist/cmd/cloud/sandbox/pause.js.map +1 -1
  105. package/dist/cmd/cloud/sandbox/resume.d.ts.map +1 -1
  106. package/dist/cmd/cloud/sandbox/resume.js +3 -4
  107. package/dist/cmd/cloud/sandbox/resume.js.map +1 -1
  108. package/dist/cmd/cloud/sandbox/run.d.ts.map +1 -1
  109. package/dist/cmd/cloud/sandbox/run.js +36 -7
  110. package/dist/cmd/cloud/sandbox/run.js.map +1 -1
  111. package/dist/cmd/cloud/sandbox/snapshot/create.js +4 -4
  112. package/dist/cmd/cloud/sandbox/snapshot/create.js.map +1 -1
  113. package/dist/cmd/cloud/sandbox/util.d.ts +19 -0
  114. package/dist/cmd/cloud/sandbox/util.d.ts.map +1 -1
  115. package/dist/cmd/cloud/sandbox/util.js +40 -2
  116. package/dist/cmd/cloud/sandbox/util.js.map +1 -1
  117. package/dist/cmd/coder/create.js +7 -7
  118. package/dist/cmd/coder/create.js.map +1 -1
  119. package/dist/cmd/coder/start.d.ts.map +1 -1
  120. package/dist/cmd/coder/start.js +3 -0
  121. package/dist/cmd/coder/start.js.map +1 -1
  122. package/dist/cmd/coder/tui-init.js +1 -1
  123. package/dist/cmd/coder/tui-init.js.map +1 -1
  124. package/dist/cmd/coder/update.js +8 -8
  125. package/dist/cmd/coder/update.js.map +1 -1
  126. package/dist/cmd/coder/workspace/common.d.ts +29 -0
  127. package/dist/cmd/coder/workspace/common.d.ts.map +1 -0
  128. package/dist/cmd/coder/workspace/common.js +83 -0
  129. package/dist/cmd/coder/workspace/common.js.map +1 -0
  130. package/dist/cmd/coder/workspace/create.d.ts.map +1 -1
  131. package/dist/cmd/coder/workspace/create.js +57 -32
  132. package/dist/cmd/coder/workspace/create.js.map +1 -1
  133. package/dist/cmd/coder/workspace/get.d.ts.map +1 -1
  134. package/dist/cmd/coder/workspace/get.js +2 -5
  135. package/dist/cmd/coder/workspace/get.js.map +1 -1
  136. package/dist/cmd/coder/workspace/index.d.ts.map +1 -1
  137. package/dist/cmd/coder/workspace/index.js +11 -1
  138. package/dist/cmd/coder/workspace/index.js.map +1 -1
  139. package/dist/cmd/coder/workspace/list.d.ts.map +1 -1
  140. package/dist/cmd/coder/workspace/list.js +4 -0
  141. package/dist/cmd/coder/workspace/list.js.map +1 -1
  142. package/dist/cmd/coder/workspace/refresh.d.ts +2 -0
  143. package/dist/cmd/coder/workspace/refresh.d.ts.map +1 -0
  144. package/dist/cmd/coder/workspace/refresh.js +59 -0
  145. package/dist/cmd/coder/workspace/refresh.js.map +1 -0
  146. package/dist/cmd/coder/workspace/update.d.ts +2 -0
  147. package/dist/cmd/coder/workspace/update.d.ts.map +1 -0
  148. package/dist/cmd/coder/workspace/update.js +131 -0
  149. package/dist/cmd/coder/workspace/update.js.map +1 -0
  150. package/dist/cmd/coder/workspace/validate-dependencies.d.ts +2 -0
  151. package/dist/cmd/coder/workspace/validate-dependencies.d.ts.map +1 -0
  152. package/dist/cmd/coder/workspace/validate-dependencies.js +70 -0
  153. package/dist/cmd/coder/workspace/validate-dependencies.js.map +1 -0
  154. package/dist/cmd/dev/dev-lock.d.ts.map +1 -1
  155. package/dist/cmd/dev/dev-lock.js +43 -17
  156. package/dist/cmd/dev/dev-lock.js.map +1 -1
  157. package/dist/cmd/dev/index.d.ts.map +1 -1
  158. package/dist/cmd/dev/index.js +211 -125
  159. package/dist/cmd/dev/index.js.map +1 -1
  160. package/dist/cmd/dev/process-manager.d.ts +41 -1
  161. package/dist/cmd/dev/process-manager.d.ts.map +1 -1
  162. package/dist/cmd/dev/process-manager.js +160 -31
  163. package/dist/cmd/dev/process-manager.js.map +1 -1
  164. package/dist/cmd/project/create.d.ts.map +1 -1
  165. package/dist/cmd/project/create.js +0 -2
  166. package/dist/cmd/project/create.js.map +1 -1
  167. package/dist/cmd/project/index.d.ts.map +1 -1
  168. package/dist/cmd/project/index.js +0 -3
  169. package/dist/cmd/project/index.js.map +1 -1
  170. package/dist/cmd/project/random-name.d.ts +17 -0
  171. package/dist/cmd/project/random-name.d.ts.map +1 -0
  172. package/dist/cmd/project/random-name.js +144 -0
  173. package/dist/cmd/project/random-name.js.map +1 -0
  174. package/dist/cmd/project/template-flow.d.ts +0 -1
  175. package/dist/cmd/project/template-flow.d.ts.map +1 -1
  176. package/dist/cmd/project/template-flow.js +180 -275
  177. package/dist/cmd/project/template-flow.js.map +1 -1
  178. package/dist/composite-logger.d.ts.map +1 -1
  179. package/dist/composite-logger.js +19 -0
  180. package/dist/composite-logger.js.map +1 -1
  181. package/dist/config.d.ts +18 -16
  182. package/dist/config.d.ts.map +1 -1
  183. package/dist/config.js +46 -16
  184. package/dist/config.js.map +1 -1
  185. package/dist/tui/prompt.d.ts +29 -0
  186. package/dist/tui/prompt.d.ts.map +1 -1
  187. package/dist/tui/prompt.js +180 -8
  188. package/dist/tui/prompt.js.map +1 -1
  189. package/package.json +7 -7
  190. package/src/cache/resource-region.ts +68 -44
  191. package/src/cli.ts +30 -8
  192. package/src/cmd/ai/prompt/web.md +43 -17
  193. package/src/cmd/build/vite/bun-dev-server.ts +92 -6
  194. package/src/cmd/build/vite/index.ts +0 -1
  195. package/src/cmd/build/vite/static-renderer.ts +18 -7
  196. package/src/cmd/build/vite/vite-asset-server-config.ts +37 -27
  197. package/src/cmd/build/vite/vite-asset-server.ts +5 -1
  198. package/src/cmd/build/vite/vite-builder.ts +12 -1
  199. package/src/cmd/build/vite/ws-proxy.ts +52 -3
  200. package/src/cmd/cloud/deploy.ts +117 -49
  201. package/src/cmd/cloud/sandbox/checkpoint/create.ts +10 -4
  202. package/src/cmd/cloud/sandbox/checkpoint/delete.ts +10 -4
  203. package/src/cmd/cloud/sandbox/checkpoint/list.ts +10 -4
  204. package/src/cmd/cloud/sandbox/checkpoint/restore.ts +10 -4
  205. package/src/cmd/cloud/sandbox/create.ts +14 -4
  206. package/src/cmd/cloud/sandbox/delete.ts +10 -4
  207. package/src/cmd/cloud/sandbox/env.ts +10 -5
  208. package/src/cmd/cloud/sandbox/exec.ts +157 -42
  209. package/src/cmd/cloud/sandbox/execution/list.ts +10 -5
  210. package/src/cmd/cloud/sandbox/fs/cp.ts +94 -126
  211. package/src/cmd/cloud/sandbox/fs/download.ts +18 -25
  212. package/src/cmd/cloud/sandbox/fs/ls.ts +10 -5
  213. package/src/cmd/cloud/sandbox/fs/mkdir.ts +10 -5
  214. package/src/cmd/cloud/sandbox/fs/rm.ts +10 -5
  215. package/src/cmd/cloud/sandbox/fs/rmdir.ts +10 -5
  216. package/src/cmd/cloud/sandbox/fs/upload.ts +14 -8
  217. package/src/cmd/cloud/sandbox/get.ts +28 -7
  218. package/src/cmd/cloud/sandbox/job/create.ts +10 -4
  219. package/src/cmd/cloud/sandbox/job/destroy.ts +10 -4
  220. package/src/cmd/cloud/sandbox/job/get.ts +10 -4
  221. package/src/cmd/cloud/sandbox/job/list.ts +10 -4
  222. package/src/cmd/cloud/sandbox/job/logs.ts +11 -4
  223. package/src/cmd/cloud/sandbox/pause.ts +31 -5
  224. package/src/cmd/cloud/sandbox/resume.ts +10 -4
  225. package/src/cmd/cloud/sandbox/run.ts +49 -11
  226. package/src/cmd/cloud/sandbox/snapshot/create.ts +6 -6
  227. package/src/cmd/cloud/sandbox/util.ts +63 -2
  228. package/src/cmd/coder/create.ts +8 -8
  229. package/src/cmd/coder/start.ts +3 -0
  230. package/src/cmd/coder/tui-init.ts +1 -1
  231. package/src/cmd/coder/update.ts +7 -7
  232. package/src/cmd/coder/workspace/common.ts +103 -0
  233. package/src/cmd/coder/workspace/create.ts +84 -37
  234. package/src/cmd/coder/workspace/get.ts +2 -5
  235. package/src/cmd/coder/workspace/index.ts +13 -1
  236. package/src/cmd/coder/workspace/list.ts +4 -0
  237. package/src/cmd/coder/workspace/refresh.ts +63 -0
  238. package/src/cmd/coder/workspace/update.ts +154 -0
  239. package/src/cmd/coder/workspace/validate-dependencies.ts +75 -0
  240. package/src/cmd/dev/dev-lock.ts +50 -16
  241. package/src/cmd/dev/index.ts +249 -134
  242. package/src/cmd/dev/process-manager.ts +173 -33
  243. package/src/cmd/project/create.ts +0 -2
  244. package/src/cmd/project/index.ts +0 -3
  245. package/src/cmd/project/random-name.ts +152 -0
  246. package/src/cmd/project/template-flow.ts +196 -305
  247. package/src/composite-logger.ts +20 -0
  248. package/src/config.ts +69 -19
  249. package/src/tui/prompt.ts +214 -8
  250. package/dist/cmd/build/vite/public-asset-path-plugin.d.ts +0 -45
  251. package/dist/cmd/build/vite/public-asset-path-plugin.d.ts.map +0 -1
  252. package/dist/cmd/build/vite/public-asset-path-plugin.js +0 -166
  253. package/dist/cmd/build/vite/public-asset-path-plugin.js.map +0 -1
  254. package/dist/cmd/project/auth/generate.d.ts +0 -5
  255. package/dist/cmd/project/auth/generate.d.ts.map +0 -1
  256. package/dist/cmd/project/auth/generate.js +0 -102
  257. package/dist/cmd/project/auth/generate.js.map +0 -1
  258. package/dist/cmd/project/auth/index.d.ts +0 -2
  259. package/dist/cmd/project/auth/index.d.ts.map +0 -1
  260. package/dist/cmd/project/auth/index.js +0 -21
  261. package/dist/cmd/project/auth/index.js.map +0 -1
  262. package/dist/cmd/project/auth/init.d.ts +0 -2
  263. package/dist/cmd/project/auth/init.d.ts.map +0 -1
  264. package/dist/cmd/project/auth/init.js +0 -213
  265. package/dist/cmd/project/auth/init.js.map +0 -1
  266. package/dist/cmd/project/auth/shared.d.ts +0 -93
  267. package/dist/cmd/project/auth/shared.d.ts.map +0 -1
  268. package/dist/cmd/project/auth/shared.js +0 -475
  269. package/dist/cmd/project/auth/shared.js.map +0 -1
  270. package/src/cmd/build/vite/public-asset-path-plugin.ts +0 -209
  271. package/src/cmd/project/auth/generate.ts +0 -116
  272. package/src/cmd/project/auth/index.ts +0 -21
  273. package/src/cmd/project/auth/init.ts +0 -256
  274. package/src/cmd/project/auth/shared.ts +0 -591
@@ -0,0 +1,154 @@
1
+ import { z } from 'zod';
2
+ import { APIError, ValidationInputError, ValidationOutputError } from '@agentuity/core';
3
+ import {
4
+ CoderClient,
5
+ CoderUpdateWorkspaceRequestSchema,
6
+ type CoderUpdateWorkspaceRequest,
7
+ } from '@agentuity/core/coder';
8
+ import { createSubcommand } from '../../../types';
9
+ import * as tui from '../../../tui';
10
+ import { getCommand } from '../../../command-prefix';
11
+ import { ErrorCode } from '../../../errors';
12
+ import { resolveGitHubRepo } from '../resolve-repo';
13
+ import {
14
+ formatWorkspaceValidationMessage,
15
+ hasWorkspaceUpdate,
16
+ parseCommaList,
17
+ printWorkspaceSummary,
18
+ readSetupScript,
19
+ } from './common';
20
+
21
+ export const updateWorkspaceSubcommand = createSubcommand({
22
+ name: 'update',
23
+ aliases: ['edit', 'patch'],
24
+ description: 'Update a Coder workspace',
25
+ tags: ['mutating', 'requires-auth'],
26
+ requires: { auth: true, org: true },
27
+ examples: [
28
+ {
29
+ command: getCommand('coder workspace update ws_abc123 --dependency git,nodejs'),
30
+ description: 'Update workspace dependencies',
31
+ },
32
+ {
33
+ command: getCommand('coder workspace update ws_abc123 --setup-script-file ./setup.sh'),
34
+ description: 'Update the workspace setup script',
35
+ },
36
+ ],
37
+ schema: {
38
+ args: z.object({
39
+ workspaceId: z.string().describe('Workspace ID to update'),
40
+ }),
41
+ options: z.object({
42
+ url: z.string().optional().describe('Coder API URL override'),
43
+ name: z.string().optional().describe('Workspace name'),
44
+ description: z.string().optional().describe('Workspace description'),
45
+ scope: z.string().optional().describe('Workspace scope: user or org'),
46
+ repo: z.string().optional().describe('Repository URL to set'),
47
+ repoBranch: z.string().optional().describe('Branch for the repository'),
48
+ dependency: z
49
+ .string()
50
+ .optional()
51
+ .describe('Comma-separated APT dependencies to install into workspace snapshots'),
52
+ setupScript: z
53
+ .string()
54
+ .optional()
55
+ .describe('Inline shell script to run while preparing workspace snapshots'),
56
+ setupScriptFile: z
57
+ .string()
58
+ .optional()
59
+ .describe('Path to a shell script to run while preparing workspace snapshots'),
60
+ enabledAgents: z
61
+ .string()
62
+ .optional()
63
+ .describe('Comma-separated built-in/custom agents to include'),
64
+ }),
65
+ },
66
+ async handler(ctx) {
67
+ const { args, opts, options } = ctx;
68
+ const client = new CoderClient({
69
+ apiKey: ctx.auth.apiKey,
70
+ url: opts?.url,
71
+ orgId: ctx.orgId,
72
+ });
73
+
74
+ const body: CoderUpdateWorkspaceRequest = {
75
+ ...(opts?.name && { name: opts.name }),
76
+ ...(opts?.description && { description: opts.description }),
77
+ ...(opts?.scope && { scope: opts.scope as 'user' | 'org' }),
78
+ };
79
+
80
+ if (opts?.repo) {
81
+ if (!options.json) tui.output('Resolving repository...');
82
+ try {
83
+ const resolved = await resolveGitHubRepo(client, opts.repo, opts?.repoBranch);
84
+ body.repos = [resolved];
85
+ } catch (err) {
86
+ const msg = err instanceof Error ? err.message : String(err);
87
+ tui.fatal(`Failed to resolve repository: ${msg}`, ErrorCode.VALIDATION_FAILED);
88
+ return;
89
+ }
90
+ }
91
+ if (opts?.dependency) {
92
+ body.dependencies = parseCommaList(opts.dependency);
93
+ }
94
+ try {
95
+ const setupScript = await readSetupScript({
96
+ setupScript: opts?.setupScript,
97
+ setupScriptFile: opts?.setupScriptFile,
98
+ });
99
+ if (setupScript !== undefined) body.setupScript = setupScript;
100
+ } catch (err) {
101
+ const msg = err instanceof Error ? err.message : String(err);
102
+ tui.fatal(`Failed to read setup script: ${msg}`, ErrorCode.VALIDATION_FAILED);
103
+ return;
104
+ }
105
+ if (opts?.enabledAgents) {
106
+ body.enabledAgents = parseCommaList(opts.enabledAgents);
107
+ }
108
+ if (!hasWorkspaceUpdate(body)) {
109
+ tui.fatal(
110
+ 'Failed to update workspace: At least one field must be provided.',
111
+ ErrorCode.VALIDATION_FAILED
112
+ );
113
+ }
114
+
115
+ const validationResult = CoderUpdateWorkspaceRequestSchema.safeParse(body);
116
+ if (!validationResult.success) {
117
+ ctx.logger.trace(
118
+ 'Validation issues: %s',
119
+ JSON.stringify(validationResult.error.issues, null, 2)
120
+ );
121
+ tui.fatal(
122
+ `Failed to update workspace: ${formatWorkspaceValidationMessage(validationResult.error.issues)}`,
123
+ ErrorCode.VALIDATION_FAILED
124
+ );
125
+ }
126
+
127
+ try {
128
+ const updated = await client.updateWorkspace(args.workspaceId, validationResult.data);
129
+
130
+ if (options.json) {
131
+ return updated;
132
+ }
133
+
134
+ tui.success(`Workspace ${updated.id} updated.`);
135
+ tui.newline();
136
+ printWorkspaceSummary(updated);
137
+ return updated;
138
+ } catch (err) {
139
+ if (err instanceof ValidationInputError || err instanceof ValidationOutputError) {
140
+ ctx.logger.trace('Validation response URL: %s', err.url ?? 'unknown');
141
+ ctx.logger.trace('Validation issues: %s', JSON.stringify(err.issues, null, 2));
142
+ tui.fatal(
143
+ `Failed to update workspace: ${formatWorkspaceValidationMessage(err.issues)}`,
144
+ ErrorCode.VALIDATION_FAILED
145
+ );
146
+ }
147
+ if (err instanceof APIError && err.status >= 400 && err.status < 500) {
148
+ tui.fatal(`Failed to update workspace: ${err.message}`, ErrorCode.VALIDATION_FAILED);
149
+ }
150
+ const msg = err instanceof Error ? err.message : String(err);
151
+ tui.fatal(`Failed to update workspace: ${msg}`, ErrorCode.NETWORK_ERROR);
152
+ }
153
+ },
154
+ });
@@ -0,0 +1,75 @@
1
+ import { z } from 'zod';
2
+ import { APIError, ValidationOutputError } from '@agentuity/core';
3
+ import { CoderClient } from '@agentuity/core/coder';
4
+ import { createSubcommand } from '../../../types';
5
+ import * as tui from '../../../tui';
6
+ import { getCommand } from '../../../command-prefix';
7
+ import { ErrorCode } from '../../../errors';
8
+ import { parseCommaList } from './common';
9
+
10
+ export const validateWorkspaceDependenciesSubcommand = createSubcommand({
11
+ name: 'validate-dependencies',
12
+ aliases: ['validate-deps'],
13
+ description: 'Validate APT dependencies for Coder workspace snapshots',
14
+ tags: ['read-only', 'requires-auth'],
15
+ idempotent: true,
16
+ requires: { auth: true, org: true },
17
+ examples: [
18
+ {
19
+ command: getCommand('coder workspace validate-dependencies git,nodejs'),
20
+ description: 'Validate dependency package names',
21
+ },
22
+ ],
23
+ schema: {
24
+ args: z.object({
25
+ dependencies: z.string().describe('Comma-separated APT dependencies to validate'),
26
+ }),
27
+ options: z.object({
28
+ url: z.string().optional().describe('Coder API URL override'),
29
+ }),
30
+ },
31
+ async handler(ctx) {
32
+ const { args, opts, options } = ctx;
33
+ const dependencies = parseCommaList(args.dependencies);
34
+ if (dependencies.length === 0) {
35
+ tui.fatal('At least one dependency is required.', ErrorCode.VALIDATION_FAILED);
36
+ }
37
+
38
+ const client = new CoderClient({
39
+ apiKey: ctx.auth.apiKey,
40
+ url: opts?.url,
41
+ orgId: ctx.orgId,
42
+ });
43
+
44
+ try {
45
+ const result = await client.validateWorkspaceDependencies(dependencies);
46
+ if (options.json) {
47
+ return result;
48
+ }
49
+
50
+ if (result.valid.length > 0) {
51
+ tui.success(`Valid dependencies: ${result.valid.join(', ')}`);
52
+ }
53
+ if (result.invalid.length > 0) {
54
+ tui.error(`Invalid dependencies: ${result.invalid.length}`);
55
+ for (const invalid of result.invalid) {
56
+ tui.output(` - ${invalid.package}: ${invalid.error}`);
57
+ }
58
+ }
59
+ return result;
60
+ } catch (err) {
61
+ if (err instanceof ValidationOutputError) {
62
+ ctx.logger.trace('Validation response URL: %s', err.url ?? 'unknown');
63
+ ctx.logger.trace('Validation issues: %s', JSON.stringify(err.issues, null, 2));
64
+ }
65
+ if (err instanceof APIError && err.status >= 400 && err.status < 500) {
66
+ tui.fatal(
67
+ `Failed to validate dependencies: ${err.message}`,
68
+ ErrorCode.VALIDATION_FAILED
69
+ );
70
+ }
71
+ const msg = err instanceof Error ? err.message : String(err);
72
+ tui.fatal(`Failed to validate dependencies: ${msg}`, ErrorCode.NETWORK_ERROR);
73
+ }
74
+ },
75
+ });
@@ -71,35 +71,69 @@ function pidExists(pid: number): boolean {
71
71
  }
72
72
 
73
73
  /**
74
- * Kill a process by PID with SIGTERM, then SIGKILL if still alive
74
+ * Send a signal to a process group (negative PID) with fallback to direct PID.
75
+ * Returns true if the signal was sent successfully.
75
76
  */
76
- async function killPid(pid: number, logger: LoggerLike): Promise<void> {
77
- if (!pidExists(pid)) return;
77
+ function killProcessTree(pid: number, signal: NodeJS.Signals, logger: LoggerLike): boolean {
78
+ // Safety: never send signals to PID 0 (own process group), PID 1 (init/systemd),
79
+ // or other dangerously low PIDs. process.kill(-1) would signal every process
80
+ // the user owns, which would crash the entire desktop session.
81
+ if (pid <= 1) {
82
+ logger.debug('Refusing to kill dangerous pid %d, skipping process tree kill', pid);
83
+ return false;
84
+ }
78
85
 
86
+ // Try process group kill first (kills all children too)
79
87
  try {
80
- process.kill(pid, 'SIGTERM');
81
- logger.debug('Sent SIGTERM to pid %d', pid);
88
+ process.kill(-pid, signal);
89
+ logger.debug('Sent %s to process group -%d', signal, pid);
90
+ return true;
82
91
  } catch (err: unknown) {
83
92
  const error = err as NodeJS.ErrnoException;
84
- if (error.code === 'ESRCH') return;
85
- logger.debug('Error sending SIGTERM to pid %d: %s', pid, error.message);
93
+ if (error.code !== 'ESRCH') {
94
+ logger.debug(
95
+ 'Process group kill failed for pid %d (%s), falling back to direct',
96
+ pid,
97
+ error.code
98
+ );
99
+ }
86
100
  }
87
101
 
88
- // Give it a moment to exit gracefully
89
- await new Promise((r) => setTimeout(r, 500));
90
-
91
- if (!pidExists(pid)) return;
92
-
93
- // Force kill
102
+ // Fall back to direct PID kill
94
103
  try {
95
- process.kill(pid, 'SIGKILL');
96
- logger.debug('Sent SIGKILL to pid %d', pid);
104
+ process.kill(pid, signal);
105
+ logger.debug('Sent %s to pid %d (direct)', signal, pid);
106
+ return true;
97
107
  } catch (err: unknown) {
98
108
  const error = err as NodeJS.ErrnoException;
99
109
  if (error.code !== 'ESRCH') {
100
- logger.debug('Error sending SIGKILL to pid %d: %s', pid, error.message);
110
+ logger.debug('Direct kill failed for pid %d: %s', pid, error.code);
101
111
  }
112
+ return false;
102
113
  }
114
+ }
115
+
116
+ /**
117
+ * Kill a process by PID with SIGTERM, then SIGKILL if still alive.
118
+ * Targets the entire process tree to prevent orphaned child processes.
119
+ */
120
+ async function killPid(pid: number, logger: LoggerLike): Promise<void> {
121
+ if (!pidExists(pid)) return;
122
+
123
+ // Send SIGTERM to process tree
124
+ const sent = killProcessTree(pid, 'SIGTERM', logger);
125
+ if (!sent) return;
126
+
127
+ // Give it a moment to exit gracefully
128
+ await new Promise((r) => setTimeout(r, 500));
129
+
130
+ // Always attempt SIGKILL on the process tree even if the leader has exited.
131
+ // On Unix, process groups persist after the leader exits and signaling via
132
+ // negative PGID still reaches remaining members. killProcessTree() handles
133
+ // ESRCH gracefully if the group no longer exists.
134
+
135
+ // Force kill the entire process tree
136
+ killProcessTree(pid, 'SIGKILL', logger);
103
137
 
104
138
  // Wait for process to fully terminate
105
139
  await new Promise((r) => setTimeout(r, 100));