@useconvoy/cli 0.63.0 → 0.81.1

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 (232) hide show
  1. package/README.md +98 -0
  2. package/dist/bin/convoy.js +13 -1
  3. package/dist/bin/convoy.js.map +1 -1
  4. package/dist/src/agent/app/chunk-scrub.js +12 -0
  5. package/dist/src/agent/app/chunk-scrub.js.map +1 -1
  6. package/dist/src/agent/app/runner.d.ts +2 -0
  7. package/dist/src/agent/app/runner.js +2 -1
  8. package/dist/src/agent/app/runner.js.map +1 -1
  9. package/dist/src/agent/app/thread-processor.js +38 -10
  10. package/dist/src/agent/app/thread-processor.js.map +1 -1
  11. package/dist/src/agent/app/worktree-op-processor.js +28 -2
  12. package/dist/src/agent/app/worktree-op-processor.js.map +1 -1
  13. package/dist/src/agent/runtimes/claudeCode/interactions.d.ts +5 -1
  14. package/dist/src/agent/runtimes/claudeCode/interactions.js +36 -0
  15. package/dist/src/agent/runtimes/claudeCode/interactions.js.map +1 -1
  16. package/dist/src/agent/runtimes/claudeCode/models.d.ts +1 -1
  17. package/dist/src/agent/runtimes/claudeCode/models.js +1 -0
  18. package/dist/src/agent/runtimes/claudeCode/models.js.map +1 -1
  19. package/dist/src/agent/runtimes/claudeCode/runner.js +110 -51
  20. package/dist/src/agent/runtimes/claudeCode/runner.js.map +1 -1
  21. package/dist/src/agent/runtimes/codex/app-server-runner.d.ts +2 -0
  22. package/dist/src/agent/runtimes/codex/app-server-runner.js +75 -44
  23. package/dist/src/agent/runtimes/codex/app-server-runner.js.map +1 -1
  24. package/dist/src/agent/runtimes/codex/auth.d.ts +9 -0
  25. package/dist/src/agent/runtimes/codex/auth.js +90 -0
  26. package/dist/src/agent/runtimes/codex/auth.js.map +1 -0
  27. package/dist/src/agent/runtimes/codex/errors.d.ts +7 -0
  28. package/dist/src/agent/runtimes/codex/errors.js +60 -0
  29. package/dist/src/agent/runtimes/codex/errors.js.map +1 -0
  30. package/dist/src/agent/runtimes/codex/interactions.js +2 -52
  31. package/dist/src/agent/runtimes/codex/interactions.js.map +1 -1
  32. package/dist/src/agent/runtimes/codex/lifecycle.d.ts +12 -1
  33. package/dist/src/agent/runtimes/codex/lifecycle.js +97 -6
  34. package/dist/src/agent/runtimes/codex/lifecycle.js.map +1 -1
  35. package/dist/src/agent/runtimes/codex/runtime.js +2 -1
  36. package/dist/src/agent/runtimes/codex/runtime.js.map +1 -1
  37. package/dist/src/agent/runtimes/contracts.d.ts +4 -0
  38. package/dist/src/agent/runtimes/contracts.js.map +1 -1
  39. package/dist/src/agent/runtimes/cursor/models.js +1 -0
  40. package/dist/src/agent/runtimes/cursor/models.js.map +1 -1
  41. package/dist/src/agent/runtimes/message-format.js +3 -1
  42. package/dist/src/agent/runtimes/message-format.js.map +1 -1
  43. package/dist/src/agent/runtimes/registry.js +17 -1
  44. package/dist/src/agent/runtimes/registry.js.map +1 -1
  45. package/dist/src/agent/runtimes/validators.d.ts +4 -0
  46. package/dist/src/agent/runtimes/validators.js +101 -0
  47. package/dist/src/agent/runtimes/validators.js.map +1 -0
  48. package/dist/src/cli.js +10 -0
  49. package/dist/src/cli.js.map +1 -1
  50. package/dist/src/commands/browser/command.d.ts +2 -0
  51. package/dist/src/commands/browser/command.js +42 -0
  52. package/dist/src/commands/browser/command.js.map +1 -0
  53. package/dist/src/commands/browser/smoke.d.ts +10 -0
  54. package/dist/src/commands/browser/smoke.js +67 -0
  55. package/dist/src/commands/browser/smoke.js.map +1 -0
  56. package/dist/src/commands/browser/validators.d.ts +18 -0
  57. package/dist/src/commands/browser/validators.js +2 -0
  58. package/dist/src/commands/browser/validators.js.map +1 -0
  59. package/dist/src/commands/browser/workflow.d.ts +4 -0
  60. package/dist/src/commands/browser/workflow.js +86 -0
  61. package/dist/src/commands/browser/workflow.js.map +1 -0
  62. package/dist/src/commands/connect/command.js +1 -0
  63. package/dist/src/commands/connect/command.js.map +1 -1
  64. package/dist/src/commands/connect/workflow.d.ts +7 -0
  65. package/dist/src/commands/connect/workflow.js +68 -4
  66. package/dist/src/commands/connect/workflow.js.map +1 -1
  67. package/dist/src/commands/devcontainer/command.js +3 -1
  68. package/dist/src/commands/devcontainer/command.js.map +1 -1
  69. package/dist/src/commands/devcontainer/install.d.ts +1 -0
  70. package/dist/src/commands/devcontainer/install.js +17 -7
  71. package/dist/src/commands/devcontainer/install.js.map +1 -1
  72. package/dist/src/commands/environment/command.d.ts +5 -0
  73. package/dist/src/commands/environment/command.js +123 -0
  74. package/dist/src/commands/environment/command.js.map +1 -0
  75. package/dist/src/commands/environment/docker.d.ts +13 -0
  76. package/dist/src/commands/environment/docker.js +65 -0
  77. package/dist/src/commands/environment/docker.js.map +1 -0
  78. package/dist/src/commands/environment/index.d.ts +60 -0
  79. package/dist/src/commands/environment/index.js +36 -0
  80. package/dist/src/commands/environment/index.js.map +1 -0
  81. package/dist/src/commands/environment/paths.d.ts +6 -0
  82. package/dist/src/commands/environment/paths.js +58 -0
  83. package/dist/src/commands/environment/paths.js.map +1 -0
  84. package/dist/src/commands/environment/projects.d.ts +3 -0
  85. package/dist/src/commands/environment/projects.js +46 -0
  86. package/dist/src/commands/environment/projects.js.map +1 -0
  87. package/dist/src/commands/environment/resolution.d.ts +11 -0
  88. package/dist/src/commands/environment/resolution.js +4 -0
  89. package/dist/src/commands/environment/resolution.js.map +1 -0
  90. package/dist/src/commands/environment/setup-entrypoint.d.ts +1 -0
  91. package/dist/src/commands/environment/setup-entrypoint.js +17 -0
  92. package/dist/src/commands/environment/setup-entrypoint.js.map +1 -0
  93. package/dist/src/commands/environment/validators.d.ts +65 -0
  94. package/dist/src/commands/environment/validators.js +36 -0
  95. package/dist/src/commands/environment/validators.js.map +1 -0
  96. package/dist/src/commands/environment/workflow.d.ts +48 -0
  97. package/dist/src/commands/environment/workflow.js +172 -0
  98. package/dist/src/commands/environment/workflow.js.map +1 -0
  99. package/dist/src/commands/keys/command.js +99 -13
  100. package/dist/src/commands/keys/command.js.map +1 -1
  101. package/dist/src/commands/keys/workflow.d.ts +68 -0
  102. package/dist/src/commands/keys/workflow.js +147 -0
  103. package/dist/src/commands/keys/workflow.js.map +1 -0
  104. package/dist/src/commands/project/command.d.ts +2 -0
  105. package/dist/src/commands/project/command.js +53 -0
  106. package/dist/src/commands/project/command.js.map +1 -0
  107. package/dist/src/commands/project/launcher.d.ts +44 -0
  108. package/dist/src/commands/project/launcher.js +100 -0
  109. package/dist/src/commands/project/launcher.js.map +1 -0
  110. package/dist/src/commands/project/validators.d.ts +87 -0
  111. package/dist/src/commands/project/validators.js +53 -0
  112. package/dist/src/commands/project/validators.js.map +1 -0
  113. package/dist/src/commands/project/worker.d.ts +2 -0
  114. package/dist/src/commands/project/worker.js +90 -0
  115. package/dist/src/commands/project/worker.js.map +1 -0
  116. package/dist/src/commands/project/workflow.d.ts +47 -0
  117. package/dist/src/commands/project/workflow.js +238 -0
  118. package/dist/src/commands/project/workflow.js.map +1 -0
  119. package/dist/src/commands/service/attach.d.ts +3 -0
  120. package/dist/src/commands/service/attach.js +155 -0
  121. package/dist/src/commands/service/attach.js.map +1 -0
  122. package/dist/src/commands/service/bridge.d.ts +3 -0
  123. package/dist/src/commands/service/bridge.js +105 -0
  124. package/dist/src/commands/service/bridge.js.map +1 -0
  125. package/dist/src/commands/service/client.d.ts +26 -0
  126. package/dist/src/commands/service/client.js +154 -0
  127. package/dist/src/commands/service/client.js.map +1 -0
  128. package/dist/src/commands/service/command.d.ts +3 -0
  129. package/dist/src/commands/service/command.js +186 -0
  130. package/dist/src/commands/service/command.js.map +1 -0
  131. package/dist/src/commands/service/errors.d.ts +9 -0
  132. package/dist/src/commands/service/errors.js +13 -0
  133. package/dist/src/commands/service/errors.js.map +1 -0
  134. package/dist/src/commands/service/formatters.d.ts +5 -0
  135. package/dist/src/commands/service/formatters.js +58 -0
  136. package/dist/src/commands/service/formatters.js.map +1 -0
  137. package/dist/src/commands/service/logs.d.ts +19 -0
  138. package/dist/src/commands/service/logs.js +64 -0
  139. package/dist/src/commands/service/logs.js.map +1 -0
  140. package/dist/src/commands/service/output.d.ts +18 -0
  141. package/dist/src/commands/service/output.js +60 -0
  142. package/dist/src/commands/service/output.js.map +1 -0
  143. package/dist/src/commands/service/parsers.d.ts +4 -0
  144. package/dist/src/commands/service/parsers.js +41 -0
  145. package/dist/src/commands/service/parsers.js.map +1 -0
  146. package/dist/src/commands/service/paths.d.ts +7 -0
  147. package/dist/src/commands/service/paths.js +44 -0
  148. package/dist/src/commands/service/paths.js.map +1 -0
  149. package/dist/src/commands/service/resolution.d.ts +5 -0
  150. package/dist/src/commands/service/resolution.js +36 -0
  151. package/dist/src/commands/service/resolution.js.map +1 -0
  152. package/dist/src/commands/service/runs.d.ts +3 -0
  153. package/dist/src/commands/service/runs.js +58 -0
  154. package/dist/src/commands/service/runs.js.map +1 -0
  155. package/dist/src/commands/service/server.d.ts +7 -0
  156. package/dist/src/commands/service/server.js +206 -0
  157. package/dist/src/commands/service/server.js.map +1 -0
  158. package/dist/src/commands/service/service-entrypoint.d.ts +1 -0
  159. package/dist/src/commands/service/service-entrypoint.js +32 -0
  160. package/dist/src/commands/service/service-entrypoint.js.map +1 -0
  161. package/dist/src/commands/service/validators.d.ts +257 -0
  162. package/dist/src/commands/service/validators.js +48 -0
  163. package/dist/src/commands/service/validators.js.map +1 -0
  164. package/dist/src/commands/service/workflow.d.ts +12 -0
  165. package/dist/src/commands/service/workflow.js +355 -0
  166. package/dist/src/commands/service/workflow.js.map +1 -0
  167. package/dist/src/commands/setup/command.js +5 -0
  168. package/dist/src/commands/setup/command.js.map +1 -1
  169. package/dist/src/commands/setup/prompts.d.ts +1 -1
  170. package/dist/src/commands/setup/prompts.js +3 -1
  171. package/dist/src/commands/setup/prompts.js.map +1 -1
  172. package/dist/src/commands/setup/resolution.d.ts +14 -0
  173. package/dist/src/commands/setup/resolution.js +87 -0
  174. package/dist/src/commands/setup/resolution.js.map +1 -0
  175. package/dist/src/commands/setup/validators.d.ts +15 -0
  176. package/dist/src/commands/setup/validators.js +15 -0
  177. package/dist/src/commands/setup/validators.js.map +1 -0
  178. package/dist/src/commands/setup/workflow.d.ts +3 -1
  179. package/dist/src/commands/setup/workflow.js +56 -47
  180. package/dist/src/commands/setup/workflow.js.map +1 -1
  181. package/dist/src/commands/threads/done.d.ts +2 -0
  182. package/dist/src/commands/threads/done.js +20 -0
  183. package/dist/src/commands/threads/done.js.map +1 -0
  184. package/dist/src/commands/threads/index.js +3 -1
  185. package/dist/src/commands/threads/index.js.map +1 -1
  186. package/dist/src/lib/config/convex-client.d.ts +5 -0
  187. package/dist/src/lib/config/convex-client.js +27 -1
  188. package/dist/src/lib/config/convex-client.js.map +1 -1
  189. package/dist/src/lib/config/credentials/resolution.d.ts +11 -0
  190. package/dist/src/lib/config/credentials/resolution.js +101 -0
  191. package/dist/src/lib/config/credentials/resolution.js.map +1 -0
  192. package/dist/src/lib/config/credentials/store.d.ts +9 -0
  193. package/dist/src/lib/config/credentials/store.js +147 -0
  194. package/dist/src/lib/config/credentials/store.js.map +1 -0
  195. package/dist/src/lib/config/credentials/validators.d.ts +152 -0
  196. package/dist/src/lib/config/credentials/validators.js +87 -0
  197. package/dist/src/lib/config/credentials/validators.js.map +1 -0
  198. package/dist/src/lib/config/index.d.ts +1 -1
  199. package/dist/src/lib/config/index.js +1 -1
  200. package/dist/src/lib/config/index.js.map +1 -1
  201. package/dist/src/lib/config/toml.d.ts +4 -4
  202. package/dist/src/lib/config/toml.js +149 -83
  203. package/dist/src/lib/config/toml.js.map +1 -1
  204. package/dist/src/lib/config/types.d.ts +8 -0
  205. package/dist/src/lib/config/types.js +5 -0
  206. package/dist/src/lib/config/types.js.map +1 -1
  207. package/dist/src/lib/connect-events.d.ts +5 -0
  208. package/dist/src/lib/connect-events.js.map +1 -1
  209. package/dist/src/lib/git/checkpoint.d.ts +18 -3
  210. package/dist/src/lib/git/checkpoint.js +57 -24
  211. package/dist/src/lib/git/checkpoint.js.map +1 -1
  212. package/dist/src/lib/git/index.d.ts +1 -0
  213. package/dist/src/lib/git/index.js +1 -0
  214. package/dist/src/lib/git/index.js.map +1 -1
  215. package/dist/src/lib/git/working-tree.d.ts +12 -0
  216. package/dist/src/lib/git/working-tree.js +38 -0
  217. package/dist/src/lib/git/working-tree.js.map +1 -0
  218. package/dist/templates/devcontainer/Dockerfile +7 -0
  219. package/dist/templates/devcontainer/README.md +17 -0
  220. package/dist/templates/project-isolation/Dockerfile +28 -0
  221. package/dist/templates/project-isolation/README.md +206 -0
  222. package/dist/templates/project-isolation/devcontainer.json +20 -0
  223. package/dist/templates/project-isolation/environment.py +257 -0
  224. package/dist/templates/project-isolation/environment.test.py +156 -0
  225. package/dist/templates/project-isolation/install.py +69 -0
  226. package/dist/templates/project-isolation/launcher.py +401 -0
  227. package/dist/templates/project-isolation/launcher.test.py +265 -0
  228. package/dist/templates/project-isolation/seccomp-source.md +20 -0
  229. package/dist/templates/project-isolation/seccomp.LICENSE +202 -0
  230. package/dist/templates/project-isolation/seccomp.json +1173 -0
  231. package/dist/templates/project-isolation/start.sh +8 -0
  232. package/package.json +3 -2
@@ -0,0 +1,100 @@
1
+ import { spawn, spawnSync } from "node:child_process";
2
+ import { existsSync } from "node:fs";
3
+ import { projectEnvironmentSchema, projectRegistrationSchema } from "./validators.js";
4
+ export const PROJECT_LAUNCHER = "/usr/local/libexec/convoy-project-launcher";
5
+ export function isProjectEnvironment() {
6
+ return process.platform === "linux" && existsSync("/etc/convoy-projects.json");
7
+ }
8
+ export function projectRequest(request) {
9
+ if (process.platform !== "linux")
10
+ throw new Error("Project isolation requires the configured Linux execution environment.");
11
+ const result = spawnSync("sudo", ["-n", PROJECT_LAUNCHER], {
12
+ input: JSON.stringify(request), encoding: "utf8", maxBuffer: 1024 * 1024,
13
+ env: { PATH: "/usr/bin:/bin", LANG: "C.UTF-8" },
14
+ });
15
+ if (result.error || result.status !== 0) {
16
+ throw new Error(result.stderr?.trim() || "Linux project launcher unavailable. Follow the project-isolation setup instructions.");
17
+ }
18
+ return JSON.parse(result.stdout);
19
+ }
20
+ /** Poll without blocking control requests while the registry is locked. */
21
+ export async function inspectProjectEnvironmentAsync() {
22
+ const child = spawn("sudo", ["-n", PROJECT_LAUNCHER], {
23
+ stdio: "pipe", env: { PATH: "/usr/bin:/bin", LANG: "C.UTF-8" },
24
+ });
25
+ let output = "";
26
+ child.stdin.on("error", () => { });
27
+ child.stderr.resume();
28
+ child.stdin.end(JSON.stringify({ action: "list" }) + "\n");
29
+ return new Promise((resolve, reject) => {
30
+ const fail = () => { clearTimeout(deadline); child.kill("SIGKILL"); reject(new Error("Cannot inspect project registry. Check launcher setup and registry lock.")); };
31
+ const deadline = setTimeout(fail, 12000);
32
+ child.stdout.on("data", (chunk) => { output += chunk.toString("utf8"); if (Buffer.byteLength(output) > 1024 * 1024)
33
+ fail(); });
34
+ child.once("error", fail);
35
+ child.once("close", (code) => {
36
+ clearTimeout(deadline);
37
+ if (code !== 0) {
38
+ fail();
39
+ return;
40
+ }
41
+ try {
42
+ resolve(projectEnvironmentSchema.parse(JSON.parse(output)));
43
+ }
44
+ catch {
45
+ fail();
46
+ }
47
+ });
48
+ });
49
+ }
50
+ export function inspectProjectEnvironment() {
51
+ return projectEnvironmentSchema.parse(projectRequest({ action: "list" }));
52
+ }
53
+ export function prepareProject(request) {
54
+ return projectRegistrationSchema.parse(projectRequest({ ...request, action: "add" }));
55
+ }
56
+ /** Shared invocation; callers choose output routing and own the control pipe. */
57
+ export function spawnProjectLauncher(identity, config, output, capabilityChecked = false) {
58
+ if (config.codexAuth && !capabilityChecked && !inspectProjectEnvironment().capabilities?.includes("credentials-v1"))
59
+ throw new Error("Managed credentials require an updated project launcher. Reinstall it before connecting.");
60
+ const child = spawn("sudo", ["-n", PROJECT_LAUNCHER], {
61
+ stdio: ["pipe", output, output], cwd: "/",
62
+ env: { PATH: "/usr/bin:/bin", LANG: "C.UTF-8" },
63
+ });
64
+ child.stdin.on("error", () => { });
65
+ child.stdin.write(`${JSON.stringify({ action: "connect", identity, config })}\n`);
66
+ return child;
67
+ }
68
+ /** The root launcher owns the lease and watches this control process's pipe. */
69
+ export async function launchProject(identity, payload) {
70
+ const child = spawnProjectLauncher(identity, payload.config, "inherit");
71
+ const stop = () => child.stdin.end();
72
+ process.once("SIGINT", stop);
73
+ process.once("SIGTERM", stop);
74
+ process.once("SIGHUP", stop);
75
+ try {
76
+ const status = await new Promise((resolve, reject) => {
77
+ child.once("error", reject);
78
+ child.once("exit", (code) => resolve(code ?? 1));
79
+ });
80
+ if (status !== 0)
81
+ throw new Error(`Project connection ended with status ${status}. Files were retained. If another connection or service owns this project, check 'convoy service status' and stop that owner before retrying.`);
82
+ }
83
+ finally {
84
+ process.removeListener("SIGINT", stop);
85
+ process.removeListener("SIGTERM", stop);
86
+ process.removeListener("SIGHUP", stop);
87
+ }
88
+ }
89
+ export async function projectShell(identity) {
90
+ const child = spawn("sudo", ["-n", PROJECT_LAUNCHER, "shell", identity], {
91
+ stdio: "inherit", env: { PATH: "/usr/bin:/bin", LANG: "C.UTF-8" },
92
+ });
93
+ const code = await new Promise((resolve, reject) => {
94
+ child.once("error", reject);
95
+ child.once("exit", (value) => resolve(value ?? 1));
96
+ });
97
+ if (code !== 0)
98
+ throw new Error(`Project shell exited with status ${code}.`);
99
+ }
100
+ //# sourceMappingURL=launcher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"launcher.js","sourceRoot":"","sources":["../../../../src/commands/project/launcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,wBAAwB,EAAE,yBAAyB,EAA2B,MAAM,iBAAiB,CAAC;AAE/G,MAAM,CAAC,MAAM,gBAAgB,GAAG,4CAA4C,CAAC;AAE7E,MAAM,UAAU,oBAAoB;IAClC,OAAO,OAAO,CAAC,QAAQ,KAAK,OAAO,IAAI,UAAU,CAAC,2BAA2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C,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC5B,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC;IACrD,CAAC,CAAC,CAAC;IACH,IAAI,IAAI,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,oCAAoC,IAAI,GAAG,CAAC,CAAC;AAC/E,CAAC"}
@@ -0,0 +1,87 @@
1
+ import { z } from "zod";
2
+ export declare const projectRegistrationSchema: z.ZodObject<{
3
+ identity: z.ZodString;
4
+ path: z.ZodString;
5
+ uid: z.ZodNumber;
6
+ active: z.ZodBoolean;
7
+ clone: z.ZodOptional<z.ZodNullable<z.ZodString>>;
8
+ status: z.ZodOptional<z.ZodEnum<{
9
+ pending: "pending";
10
+ stopped: "stopped";
11
+ removed: "removed";
12
+ }>>;
13
+ }, z.core.$strip>;
14
+ export declare const projectEnvironmentSchema: z.ZodObject<{
15
+ capabilities: z.ZodOptional<z.ZodArray<z.ZodString>>;
16
+ workspace: z.ZodString;
17
+ registrations: z.ZodArray<z.ZodObject<{
18
+ identity: z.ZodString;
19
+ path: z.ZodString;
20
+ uid: z.ZodNumber;
21
+ active: z.ZodBoolean;
22
+ clone: z.ZodOptional<z.ZodNullable<z.ZodString>>;
23
+ status: z.ZodOptional<z.ZodEnum<{
24
+ pending: "pending";
25
+ stopped: "stopped";
26
+ removed: "removed";
27
+ }>>;
28
+ }, z.core.$strip>>;
29
+ }, z.core.$strip>;
30
+ export type ProjectEnvironment = z.infer<typeof projectEnvironmentSchema>;
31
+ export declare function assertDeploymentUrl(url: string): URL;
32
+ export declare function projectIdentity(url: string, organizationId: string, projectId: string): string;
33
+ export declare function requireProjectScope(scope: {
34
+ kind: string;
35
+ organizationId?: string;
36
+ projectIds?: string[];
37
+ } | null, organizationId: string, projectId: string): void;
38
+ export declare const profileKeySchema: z.ZodString;
39
+ export declare function validateProfileKey(key: string): void;
40
+ export declare const workerConfigSchema: z.ZodObject<{
41
+ convexUrl: z.ZodString;
42
+ apiKey: z.ZodString;
43
+ projectId: z.ZodString;
44
+ organizationId: z.ZodString;
45
+ projectIdentity: z.ZodString;
46
+ paths: z.ZodArray<z.ZodString>;
47
+ profileKey: z.ZodString;
48
+ connectionName: z.ZodOptional<z.ZodString>;
49
+ force: z.ZodOptional<z.ZodBoolean>;
50
+ concurrency: z.ZodOptional<z.ZodNumber>;
51
+ partialStreaming: z.ZodOptional<z.ZodBoolean>;
52
+ isolated: z.ZodOptional<z.ZodBoolean>;
53
+ codexAuth: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
54
+ mode: z.ZodLiteral<"managed">;
55
+ secret: z.ZodString;
56
+ }, z.core.$strict>, z.ZodObject<{
57
+ mode: z.ZodLiteral<"disabled">;
58
+ }, z.core.$strict>, z.ZodObject<{
59
+ mode: z.ZodLiteral<"native">;
60
+ }, z.core.$strict>], "mode">>;
61
+ codexAppServer: z.ZodOptional<z.ZodBoolean>;
62
+ jsonEvents: z.ZodOptional<z.ZodBoolean>;
63
+ }, z.core.$strict>;
64
+ export declare const workerLaunchConfigSchema: z.ZodObject<{
65
+ organizationId: z.ZodString;
66
+ profileKey: z.ZodString;
67
+ convexUrl: z.ZodString;
68
+ apiKey: z.ZodString;
69
+ projectId: z.ZodString;
70
+ connectionName: z.ZodOptional<z.ZodString>;
71
+ force: z.ZodOptional<z.ZodBoolean>;
72
+ concurrency: z.ZodOptional<z.ZodNumber>;
73
+ partialStreaming: z.ZodOptional<z.ZodBoolean>;
74
+ isolated: z.ZodOptional<z.ZodBoolean>;
75
+ codexAuth: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
76
+ mode: z.ZodLiteral<"managed">;
77
+ secret: z.ZodString;
78
+ }, z.core.$strict>, z.ZodObject<{
79
+ mode: z.ZodLiteral<"disabled">;
80
+ }, z.core.$strict>, z.ZodObject<{
81
+ mode: z.ZodLiteral<"native">;
82
+ }, z.core.$strict>], "mode">>;
83
+ codexAppServer: z.ZodOptional<z.ZodBoolean>;
84
+ jsonEvents: z.ZodOptional<z.ZodBoolean>;
85
+ }, z.core.$strict>;
86
+ export type WorkerConfig = z.infer<typeof workerConfigSchema>;
87
+ export type WorkerLaunchConfig = z.infer<typeof workerLaunchConfigSchema>;
@@ -0,0 +1,53 @@
1
+ import { createHash } from "node:crypto";
2
+ import { codexAuthSchema } from "../../lib/config/credentials/validators.js";
3
+ import { z } from "zod";
4
+ export const projectRegistrationSchema = z.object({
5
+ identity: z.string().regex(/^[a-f0-9]{64}$/),
6
+ path: z.string(),
7
+ uid: z.number().int().min(20000),
8
+ active: z.boolean(),
9
+ clone: z.string().nullable().optional(),
10
+ status: z.enum(["pending", "stopped", "removed"]).optional(),
11
+ });
12
+ export const projectEnvironmentSchema = z.object({
13
+ capabilities: z.array(z.string()).optional(),
14
+ workspace: z.string(),
15
+ registrations: z.array(projectRegistrationSchema),
16
+ });
17
+ export function assertDeploymentUrl(url) {
18
+ const deployment = new URL(url);
19
+ if (deployment.protocol !== "https:" || deployment.username || deployment.password || deployment.search || deployment.hash) {
20
+ throw new Error("Project deployments must use HTTPS without embedded credentials, query or fragment.");
21
+ }
22
+ return deployment;
23
+ }
24
+ export function projectIdentity(url, organizationId, projectId) {
25
+ const deployment = assertDeploymentUrl(url);
26
+ return createHash("sha256")
27
+ .update(JSON.stringify([deployment.href.replace(/\/$/, ""), organizationId, projectId]))
28
+ .digest("hex");
29
+ }
30
+ export function requireProjectScope(scope, organizationId, projectId) {
31
+ if (scope?.kind !== "organization" || scope.organizationId !== organizationId ||
32
+ scope.projectIds?.length !== 1 || scope.projectIds[0] !== projectId) {
33
+ throw new Error("Use an API key restricted to this one project. Create it in Convoy settings; an account-wide or organization-wide key cannot be given to an isolated worker.");
34
+ }
35
+ }
36
+ export const profileKeySchema = z.string().regex(/^[a-z][a-z0-9_-]{0,79}$/);
37
+ export function validateProfileKey(key) {
38
+ if (!profileKeySchema.safeParse(key).success) {
39
+ throw new Error("Invalid profile key. Use at most 80 lowercase letters, digits, underscores or hyphens, starting with a letter.");
40
+ }
41
+ }
42
+ export const workerConfigSchema = z.object({
43
+ convexUrl: z.string().url(), apiKey: z.string().min(1), projectId: z.string().min(1),
44
+ organizationId: z.string().min(1), projectIdentity: z.string(),
45
+ paths: z.array(z.string()).length(1), profileKey: profileKeySchema,
46
+ connectionName: z.string().optional(), force: z.boolean().optional(),
47
+ concurrency: z.number().int().min(1).max(50).optional(),
48
+ partialStreaming: z.boolean().optional(), isolated: z.boolean().optional(),
49
+ codexAuth: codexAuthSchema.optional(),
50
+ codexAppServer: z.boolean().optional(), jsonEvents: z.boolean().optional(),
51
+ }).strict();
52
+ export const workerLaunchConfigSchema = workerConfigSchema.omit({ paths: true, projectIdentity: true });
53
+ //# sourceMappingURL=validators.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validators.js","sourceRoot":"","sources":["../../../../src/commands/project/validators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,4CAA4C,CAAC;AAC7E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,CAAC,MAAM,CAAC;IAChD,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,gBAAgB,CAAC;IAC5C,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC;IAChC,MAAM,EAAE,CAAC,CAAC,OAAO,EAAE;IACnB,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE;IACvC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,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,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IAC1E,SAAS,EAAE,eAAe,CAAC,QAAQ,EAAE;IACrC,cAAc,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;CAC3E,CAAC,CAAC,MAAM,EAAE,CAAC;AACZ,MAAM,CAAC,MAAM,wBAAwB,GAAG,kBAAkB,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,eAAe,EAAE,IAAI,EAAE,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ import type { Readable } from "node:stream";
2
+ export declare function runProjectWorker(inputStream?: Readable): Promise<void>;
@@ -0,0 +1,90 @@
1
+ import { pathToFileURL } from "node:url";
2
+ import { api } from "../../convex/_generated/api.js";
3
+ import { createConvexClient } from "../../lib/config/convex-client.js";
4
+ import { setProfile } from "../../lib/config/toml.js";
5
+ import { runConnect } from "../connect/workflow.js";
6
+ import { projectIdentity, requireProjectScope, workerConfigSchema } from "./validators.js";
7
+ export async function runProjectWorker(inputStream = process.stdin) {
8
+ const shutdown = new AbortController();
9
+ const onEnd = () => shutdown.abort();
10
+ inputStream.once("end", onEnd);
11
+ inputStream.once("error", onEnd);
12
+ try {
13
+ let config;
14
+ try {
15
+ const frame = await new Promise((resolve, reject) => {
16
+ let buffer = Buffer.alloc(0);
17
+ const fail = () => { cleanup(); reject(new Error("Invalid isolated worker configuration.")); };
18
+ const data = (chunk) => {
19
+ buffer = Buffer.concat([buffer, Buffer.from(chunk)]);
20
+ if (buffer.length > 65536)
21
+ return fail();
22
+ const newline = buffer.indexOf(10);
23
+ if (newline < 0)
24
+ return;
25
+ cleanup();
26
+ resolve(buffer.subarray(0, newline).toString("utf8"));
27
+ };
28
+ const cleanup = () => {
29
+ inputStream.off("data", data);
30
+ inputStream.off("end", fail);
31
+ inputStream.off("error", fail);
32
+ };
33
+ inputStream.on("data", data);
34
+ inputStream.once("end", fail);
35
+ inputStream.once("error", fail);
36
+ });
37
+ config = workerConfigSchema.parse(JSON.parse(frame));
38
+ }
39
+ catch {
40
+ throw new Error("Invalid isolated worker configuration. Reinstall matching CLI and launcher versions.");
41
+ }
42
+ if (shutdown.signal.aborted)
43
+ return;
44
+ if (process.getuid?.() === 0 || config.projectIdentity !== process.env.CONVOY_PROJECT_IDENTITY ||
45
+ projectIdentity(config.convexUrl, config.organizationId, config.projectId) !== config.projectIdentity) {
46
+ throw new Error("Project identity does not match the Linux boundary.");
47
+ }
48
+ try {
49
+ const client = createConvexClient({ url: config.convexUrl, apiKey: config.apiKey });
50
+ try {
51
+ requireProjectScope(await client.query(api.apiKeys.core.currentScope, {}), config.organizationId, config.projectId);
52
+ }
53
+ finally {
54
+ await client.close();
55
+ }
56
+ }
57
+ catch {
58
+ throw new Error("Project scope verification failed. Check the project-scoped API key and backend currentScope query.");
59
+ }
60
+ if (shutdown.signal.aborted)
61
+ return;
62
+ try {
63
+ setProfile(config.profileKey, {
64
+ name: config.profileKey, url: config.convexUrl, api_key: config.apiKey,
65
+ project_id: config.projectId, paths: config.paths,
66
+ });
67
+ }
68
+ catch {
69
+ throw new Error("Cannot save the private project profile. Check private HOME permissions and config.toml.");
70
+ }
71
+ try {
72
+ await runConnect({ ...config, nonInteractive: true, shutdownSignal: shutdown.signal });
73
+ }
74
+ catch {
75
+ throw new Error("Isolated worker connection failed. See the preceding connection diagnostic.");
76
+ }
77
+ }
78
+ finally {
79
+ inputStream.off("end", onEnd);
80
+ inputStream.off("error", onEnd);
81
+ inputStream.pause();
82
+ }
83
+ }
84
+ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href)
85
+ runProjectWorker().catch((error) => {
86
+ console.error(error instanceof Error ? error.message : "Isolated worker failed.");
87
+ process.stdin.destroy();
88
+ process.exitCode = 1;
89
+ });
90
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AM,CAAC;YACP,MAAM,IAAI,KAAK,CAAC,6EAA6E,CAAC,CAAC;QACjG,CAAC;IACH,CAAC;YAAS,CAAC;QACT,WAAW,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QAC9B,WAAW,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QAChC,WAAW,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;AACH,CAAC;AAED,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI;IAAE,gBAAgB,EAAE,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;QAC1H,OAAO,CAAC,KAAK,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,yBAAyB,CAAC,CAAC;QAClF,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;QACxB,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACvB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,47 @@
1
+ import type { ProjectRegistration } from "../service/validators.js";
2
+ import type { ConfigFile } from "../../lib/config/types.js";
3
+ import { type ProjectSelectionOptions } from "../setup/resolution.js";
4
+ export interface ProjectAddOptions extends ProjectSelectionOptions {
5
+ url?: string;
6
+ apiKey?: string;
7
+ project?: string;
8
+ profileKey?: string;
9
+ reuse?: boolean;
10
+ clone?: string;
11
+ nonInteractive?: boolean;
12
+ }
13
+ export declare function addProject(directory: string, options: ProjectAddOptions): Promise<void>;
14
+ export declare function listProjects(json: boolean): Promise<void>;
15
+ export declare function removeProject(key: string, yes: boolean, interrupt?: boolean): Promise<void>;
16
+ export declare function validateRegistration(config: ConfigFile, registration: ProjectRegistration): {
17
+ name: string;
18
+ url: string;
19
+ api_key: string;
20
+ project_id: string;
21
+ paths: string[];
22
+ streaming?: boolean | undefined;
23
+ isolated?: boolean | undefined;
24
+ concurrency?: number | undefined;
25
+ provider_key?: string | undefined;
26
+ project_isolation?: {
27
+ identity: string;
28
+ organization_id: string;
29
+ } | undefined;
30
+ };
31
+ export declare function saveProjectRegistration(registration: ProjectRegistration, environment?: {
32
+ workspace: string;
33
+ registrations: {
34
+ identity: string;
35
+ path: string;
36
+ uid: number;
37
+ active: boolean;
38
+ clone?: string | null | undefined;
39
+ status?: "pending" | "stopped" | "removed" | undefined;
40
+ }[];
41
+ capabilities?: string[] | undefined;
42
+ }): void;
43
+ export declare function projectRemoval(key: string): {
44
+ identity: string;
45
+ last: boolean;
46
+ };
47
+ export declare function unregisterProject(key: string, expectedIdentity?: string): void;
@@ -0,0 +1,238 @@
1
+ import { createHash } from "node:crypto";
2
+ import * as path from "node:path";
3
+ import { confirm } from "@inquirer/prompts";
4
+ import { serviceRequest } from "../service/client.js";
5
+ import { servicePaths } from "../service/paths.js";
6
+ import { ServiceUnavailableError } from "../service/errors.js";
7
+ import { serviceSnapshot } from "../service/resolution.js";
8
+ import { api } from "../../convex/_generated/api.js";
9
+ import { createConvexClient } from "../../lib/config/convex-client.js";
10
+ import { mutateConfig, readConfig } from "../../lib/config/toml.js";
11
+ import { normalizeConvexUrl } from "../../lib/url.js";
12
+ import { resolveSetupProject, validateProjectSelection } from "../setup/resolution.js";
13
+ import { promptApiKey, promptProfileKey, promptUrl } from "../setup/prompts.js";
14
+ import { inspectProjectEnvironment, prepareProject, projectRequest } from "./launcher.js";
15
+ import { assertDeploymentUrl, validateProfileKey, projectIdentity, requireProjectScope } from "./validators.js";
16
+ export async function addProject(directory, options) {
17
+ if (directory.split(/[\\/]/).some((part) => part === "." || part === "..")) {
18
+ throw new Error("Project paths cannot contain traversal components.");
19
+ }
20
+ const environment = inspectProjectEnvironment();
21
+ const interactive = !options.nonInteractive && Boolean(process.stdin.isTTY);
22
+ validateProjectSelection(options, interactive);
23
+ if (!interactive && (!options.url || !options.apiKey || (!options.project && !options.create) || !options.profileKey)) {
24
+ throw new Error("Non-interactive add requires --url, --api-key, --project (or --create with creation inputs) and --profile-key.");
25
+ }
26
+ const target = path.resolve(environment.workspace, directory);
27
+ if (path.dirname(target) !== environment.workspace)
28
+ throw new Error("Project path must be a direct child of the workspace.");
29
+ if (options.profileKey)
30
+ validateProfileKey(options.profileKey);
31
+ const url = normalizeConvexUrl(options.url ?? await promptUrl());
32
+ assertDeploymentUrl(url);
33
+ const apiKey = options.apiKey ?? await promptApiKey();
34
+ const client = createConvexClient({ url, apiKey });
35
+ try {
36
+ let profileKey = options.profileKey;
37
+ let sourceChecked = false;
38
+ const selection = { ...options };
39
+ const project = await resolveSetupProject(client, selection, interactive, undefined, async () => {
40
+ profileKey ??= await promptProfileKey(path.basename(target).toLowerCase());
41
+ if (!options.profileKey)
42
+ validateProfileKey(profileKey);
43
+ selection.profileKey = profileKey;
44
+ const config = readConfig();
45
+ if (config.profiles[profileKey])
46
+ throw new Error("Profile already exists. Choose another profile key before creating a project.");
47
+ validateWorkspaceOverlap(config, target);
48
+ await client.query(api.apiKeys.core.validateWorkerSetupKey, {});
49
+ sourceChecked = true;
50
+ });
51
+ const scope = await client.query(api.apiKeys.core.currentScope, {});
52
+ const broadScope = scope?.kind === "unscoped" || (scope?.kind === "organization" && scope.projectIds.length === 0);
53
+ if (!broadScope)
54
+ requireProjectScope(scope, project.organizationId, project._id);
55
+ const identity = projectIdentity(url, project.organizationId, project._id);
56
+ const promptedAfterSelection = !profileKey;
57
+ profileKey ??= await promptProfileKey(project.alias.toLowerCase());
58
+ if (promptedAfterSelection)
59
+ validateProfileKey(profileKey);
60
+ const profile = {
61
+ name: project.name, url, api_key: apiKey, project_id: project._id, paths: [target],
62
+ project_isolation: { identity, organization_id: project.organizationId },
63
+ };
64
+ const registration = { key: profileKey, profile };
65
+ validateRegistration(readConfig(), registration);
66
+ if (broadScope && !sourceChecked)
67
+ await client.query(api.apiKeys.core.validateWorkerSetupKey, {});
68
+ const ready = environment.registrations.find((entry) => entry.identity === identity && entry.path === target && entry.status !== "pending" && entry.status !== "removed");
69
+ if (ready && options.clone && ready.clone !== options.clone)
70
+ throw new Error("Project already exists with a different clone source.");
71
+ if (!ready) {
72
+ const prepared = prepareProject({ identity, path: target, reuse: options.reuse ?? false, clone: options.clone });
73
+ if (prepared.path !== target)
74
+ throw new Error("Launcher returned a different workspace path.");
75
+ }
76
+ let workerKey = apiKey;
77
+ if (broadScope) {
78
+ const candidates = Object.values(readConfig().profiles).filter(saved => saved.project_isolation?.identity === identity && saved.url === url && saved.project_id === project._id);
79
+ let reusableKey;
80
+ for (const saved of candidates) {
81
+ const reusable = await client.query(api.apiKeys.core.canReuseProjectKey, {
82
+ projectId: project._id, keyHash: createHash("sha256").update(saved.api_key).digest("hex"),
83
+ });
84
+ if (reusable) {
85
+ reusableKey = saved.api_key;
86
+ break;
87
+ }
88
+ }
89
+ if (reusableKey) {
90
+ workerKey = reusableKey;
91
+ }
92
+ else {
93
+ const issued = await client.mutation(api.apiKeys.core.createProjectKey, { projectId: project._id });
94
+ workerKey = issued.key;
95
+ console.log(`Issued project worker key ${issued.id}. Manage it in Convoy API Keys; it is retained if registration fails.`);
96
+ }
97
+ const workerClient = createConvexClient({ url, apiKey: workerKey });
98
+ try {
99
+ requireProjectScope(await workerClient.query(api.apiKeys.core.currentScope, {}), project.organizationId, project._id);
100
+ }
101
+ finally {
102
+ await workerClient.close();
103
+ }
104
+ }
105
+ profile.api_key = workerKey;
106
+ const response = await serviceRequest(servicePaths(undefined, false).socket, { op: "project.add", registration })
107
+ .catch((error) => {
108
+ if (!(error instanceof ServiceUnavailableError))
109
+ throw error;
110
+ saveProjectRegistration(registration);
111
+ return undefined;
112
+ });
113
+ console.log(response
114
+ ? `Registered ${profileKey}. ${response.applied ? "Service applied the registration; inspect project list for connection status." : "Service application is pending; inspect project list and service status."} Runtime authentication belongs in this project's private HOME.`
115
+ : `Registered ${profileKey} offline. Run convoy service start -b or convoy connect --profile ${profileKey}. Runtime authentication belongs in this project's private HOME.`);
116
+ }
117
+ finally {
118
+ await client.close();
119
+ }
120
+ }
121
+ function overlaps(left, right) {
122
+ const a = path.resolve(left), b = path.resolve(right);
123
+ return a === b || a.startsWith(`${b}${path.sep}`) || b.startsWith(`${a}${path.sep}`);
124
+ }
125
+ function registrationStatus(registration) {
126
+ if (!registration)
127
+ return "missing";
128
+ if (registration.active)
129
+ return "running";
130
+ return registration.status ?? "stopped";
131
+ }
132
+ export async function listProjects(json) {
133
+ const live = await serviceRequest(servicePaths(undefined, false).socket, { op: "status" }).catch((error) => {
134
+ if (!(error instanceof ServiceUnavailableError))
135
+ throw error;
136
+ return undefined;
137
+ });
138
+ const environment = inspectProjectEnvironment();
139
+ const profiles = readConfig().profiles;
140
+ const rows = Object.entries(profiles).flatMap(([key, profile]) => {
141
+ if (!profile.project_isolation)
142
+ return [];
143
+ const registration = environment.registrations.find((item) => item.identity === profile.project_isolation?.identity);
144
+ const worker = live?.profiles?.find((item) => item.identity === profile.project_isolation?.identity || item.profile === key);
145
+ return [{ profile: key, path: profile.paths[0], uid: registration?.uid,
146
+ status: worker?.status ?? registrationStatus(registration), service: Boolean(live),
147
+ activeRuns: worker?.activeRuns, pending: worker?.pending, configurationError: live?.configurationError }];
148
+ });
149
+ for (const registration of environment.registrations) {
150
+ if (Object.values(profiles).some((profile) => profile.project_isolation?.identity === registration.identity))
151
+ continue;
152
+ rows.push({ profile: "(no profile)", path: registration.path, uid: registration.uid,
153
+ status: registrationStatus(registration), service: Boolean(live), activeRuns: undefined, pending: undefined, configurationError: live?.configurationError });
154
+ }
155
+ if (json)
156
+ console.log(JSON.stringify(rows));
157
+ else if (!rows.length)
158
+ console.log("No registered projects.");
159
+ else
160
+ console.table(rows);
161
+ }
162
+ export async function removeProject(key, yes, interrupt = false) {
163
+ if (!yes && (!process.stdin.isTTY || !await confirm({ message: `Unregister ${key}? Files and private state will remain.`, default: false }))) {
164
+ throw new Error("Removal cancelled. Use --yes for non-interactive removal.");
165
+ }
166
+ const response = await serviceRequest(servicePaths(undefined, false).socket, { op: "project.remove", profile: key, interrupt })
167
+ .catch((error) => {
168
+ if (!(error instanceof ServiceUnavailableError))
169
+ throw error;
170
+ unregisterProject(key);
171
+ return undefined;
172
+ });
173
+ if (response && !response.applied)
174
+ throw new Error("Registration removed; service application is pending. Inspect service status.");
175
+ console.log(`Unregistered ${key}. Workspace, worktrees and private state retained.`);
176
+ }
177
+ function validateWorkspaceOverlap(config, target, identity) {
178
+ for (const entry of Object.values(config.profiles)) {
179
+ if (identity && entry.project_isolation?.identity === identity)
180
+ continue;
181
+ if (entry.paths.some((root) => overlaps(root, target) || overlaps(`${root}-worktrees`, target) || overlaps(root, `${target}-worktrees`))) {
182
+ throw new Error("Workspace overlaps an existing profile or its worktree directory.");
183
+ }
184
+ }
185
+ }
186
+ export function validateRegistration(config, registration) {
187
+ const { key: profileKey, profile } = registration;
188
+ const identity = profile.project_isolation?.identity;
189
+ const target = profile.paths[0];
190
+ if (Buffer.byteLength(JSON.stringify(profile)) > 32768)
191
+ throw new Error("Project registration is too large.");
192
+ const existing = config.profiles[profileKey];
193
+ if (existing && (existing.project_isolation?.identity !== identity || existing.paths.length !== 1 || existing.paths[0] !== target)) {
194
+ throw new Error(`Profile "${profileKey}" already belongs to a different registration.`);
195
+ }
196
+ validateWorkspaceOverlap(config, target, identity);
197
+ return existing;
198
+ }
199
+ export function saveProjectRegistration(registration, environment = inspectProjectEnvironment()) {
200
+ const { profile, key } = registration;
201
+ const isolation = profile.project_isolation;
202
+ const ready = environment.registrations.find((entry) => entry.identity === isolation?.identity);
203
+ if (!isolation || projectIdentity(profile.url, isolation.organization_id, profile.project_id) !== isolation.identity ||
204
+ profile.paths.length !== 1 || !ready || ready.status === "pending" || ready.status === "removed" ||
205
+ ready.path !== profile.paths[0] || path.dirname(ready.path) !== environment.workspace || profile.provider_key) {
206
+ throw new Error("Registration changed or preparation is incomplete. Repeat project add.");
207
+ }
208
+ mutateConfig((config) => {
209
+ const existing = validateRegistration(config, registration);
210
+ config.profiles[key] = { ...existing, ...profile };
211
+ serviceSnapshot(config, environment);
212
+ });
213
+ }
214
+ export function projectRemoval(key) {
215
+ const config = readConfig();
216
+ const profile = config.profiles[key];
217
+ if (!profile?.project_isolation)
218
+ throw new Error("No isolated registration with that profile key.");
219
+ const identity = profile.project_isolation.identity;
220
+ return { identity, last: !Object.entries(config.profiles).some(([otherKey, other]) => otherKey !== key && other.project_isolation?.identity === identity) };
221
+ }
222
+ export function unregisterProject(key, expectedIdentity) {
223
+ mutateConfig((config) => {
224
+ const profile = config.profiles[key];
225
+ if (!profile?.project_isolation)
226
+ throw new Error("No isolated registration with that profile key.");
227
+ const identity = profile.project_isolation.identity;
228
+ if (expectedIdentity && expectedIdentity !== identity)
229
+ throw new Error("Registration changed. Inspect project list before retrying.");
230
+ const hasOtherProfile = Object.entries(config.profiles).some(([otherKey, other]) => otherKey !== key && other.project_isolation?.identity === identity);
231
+ if (!hasOtherProfile)
232
+ projectRequest({ action: "remove", identity });
233
+ delete config.profiles[key];
234
+ if (config.settings?.default_profile === key)
235
+ delete config.settings.default_profile;
236
+ });
237
+ }
238
+ //# sourceMappingURL=workflow.js.map