mulesoft-anypoint-cli-agent-fabric-plugin 1.4.0 → 1.6.0

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 (237) hide show
  1. package/GETTING_STARTED.md +396 -0
  2. package/README.md +61 -23
  3. package/TROUBLESHOOTING.md +468 -0
  4. package/dist/commands/agent-network/project/agent-console.d.ts +3 -2
  5. package/dist/commands/agent-network/project/agent-console.js +3 -1
  6. package/dist/commands/agent-network/project/agent-console.js.map +1 -1
  7. package/dist/commands/agent-network/project/broker/create.d.ts +3 -2
  8. package/dist/commands/agent-network/project/broker/create.js +3 -1
  9. package/dist/commands/agent-network/project/broker/create.js.map +1 -1
  10. package/dist/commands/agent-network/project/build.d.ts +4 -3
  11. package/dist/commands/agent-network/project/build.js +13 -8
  12. package/dist/commands/agent-network/project/build.js.map +1 -1
  13. package/dist/commands/agent-network/project/create.d.ts +11 -6
  14. package/dist/commands/agent-network/project/create.js +52 -16
  15. package/dist/commands/agent-network/project/create.js.map +1 -1
  16. package/dist/commands/agent-network/project/deploy.d.ts +4 -2
  17. package/dist/commands/agent-network/project/deploy.js +45 -26
  18. package/dist/commands/agent-network/project/deploy.js.map +1 -1
  19. package/dist/commands/agent-network/project/export-logs.d.ts +3 -2
  20. package/dist/commands/agent-network/project/export-logs.js +3 -2
  21. package/dist/commands/agent-network/project/export-logs.js.map +1 -1
  22. package/dist/commands/agent-network/project/mcp/introspect.d.ts +7 -3
  23. package/dist/commands/agent-network/project/mcp/introspect.js +14 -9
  24. package/dist/commands/agent-network/project/mcp/introspect.js.map +1 -1
  25. package/dist/commands/agent-network/project/publish.d.ts +3 -4
  26. package/dist/commands/agent-network/project/publish.js +11 -14
  27. package/dist/commands/agent-network/project/publish.js.map +1 -1
  28. package/dist/commands/agent-network/project/run-local.d.ts +14 -2
  29. package/dist/commands/agent-network/project/run-local.js +339 -60
  30. package/dist/commands/agent-network/project/run-local.js.map +1 -1
  31. package/dist/commands/agent-network/project/secrets.d.ts +3 -2
  32. package/dist/commands/agent-network/project/secrets.js +3 -1
  33. package/dist/commands/agent-network/project/secrets.js.map +1 -1
  34. package/dist/commands/agent-network/project/stop-local.d.ts +3 -2
  35. package/dist/commands/agent-network/project/stop-local.js +3 -2
  36. package/dist/commands/agent-network/project/stop-local.js.map +1 -1
  37. package/dist/commands/agent-network/project/undeploy.d.ts +3 -2
  38. package/dist/commands/agent-network/project/undeploy.js +19 -12
  39. package/dist/commands/agent-network/project/undeploy.js.map +1 -1
  40. package/dist/commands/agent-network/project/unpublish.d.ts +3 -2
  41. package/dist/commands/agent-network/project/unpublish.js +26 -19
  42. package/dist/commands/agent-network/project/unpublish.js.map +1 -1
  43. package/dist/commands/agent-network/setup/dependencies.d.ts +4 -3
  44. package/dist/commands/agent-network/setup/dependencies.js +7 -4
  45. package/dist/commands/agent-network/setup/dependencies.js.map +1 -1
  46. package/dist/commands/agent-network/setup/gateways.d.ts +3 -2
  47. package/dist/commands/agent-network/setup/gateways.js +3 -3
  48. package/dist/commands/agent-network/setup/gateways.js.map +1 -1
  49. package/dist/errors/base-error.d.ts +6 -0
  50. package/dist/errors/base-error.js +49 -20
  51. package/dist/errors/base-error.js.map +1 -1
  52. package/dist/errors/error-factory.d.ts +62 -4
  53. package/dist/errors/error-factory.js +341 -13
  54. package/dist/errors/error-factory.js.map +1 -1
  55. package/dist/helpers/connection.d.ts +6 -2
  56. package/dist/helpers/connection.js +13 -6
  57. package/dist/helpers/connection.js.map +1 -1
  58. package/dist/helpers/dependency-manager.d.ts +14 -5
  59. package/dist/helpers/dependency-manager.js +185 -51
  60. package/dist/helpers/dependency-manager.js.map +1 -1
  61. package/dist/helpers/policy-helper.js +256 -26
  62. package/dist/helpers/policy-helper.js.map +1 -1
  63. package/dist/helpers/project/constants.d.ts +1 -1
  64. package/dist/helpers/proxy-agent.d.ts +2 -0
  65. package/dist/helpers/proxy-agent.js +26 -0
  66. package/dist/helpers/proxy-agent.js.map +1 -0
  67. package/dist/helpers/proxy-fetch.d.ts +5 -0
  68. package/dist/helpers/proxy-fetch.js +102 -0
  69. package/dist/helpers/proxy-fetch.js.map +1 -0
  70. package/dist/helpers/request-logging.d.ts +4 -0
  71. package/dist/helpers/request-logging.js +96 -2
  72. package/dist/helpers/request-logging.js.map +1 -1
  73. package/dist/helpers/types.d.ts +5 -0
  74. package/dist/helpers/utils.d.ts +1 -0
  75. package/dist/helpers/utils.js +16 -1
  76. package/dist/helpers/utils.js.map +1 -1
  77. package/dist/hooks/init/check-node-version.d.ts +6 -0
  78. package/dist/hooks/init/check-node-version.js +34 -0
  79. package/dist/hooks/init/check-node-version.js.map +1 -0
  80. package/dist/resources/runtime-dependencies.json +5 -1
  81. package/dist/resources/schemas/broker-deployment-settings.schema.json +4 -0
  82. package/dist/resources/schemas/runtime-dependencies-schema.json +21 -0
  83. package/dist/types/agent-network-v2.d.ts +55 -9
  84. package/dist/types/agent-network-v2.js.map +1 -1
  85. package/dist/types/agent-network.d.ts +0 -4
  86. package/dist/types/agent-network.js.map +1 -1
  87. package/dist/types/types.d.ts +25 -3
  88. package/dist/utils/agent-fabric-commands.d.ts +24 -0
  89. package/dist/utils/agent-fabric-commands.js +39 -0
  90. package/dist/utils/agent-fabric-commands.js.map +1 -0
  91. package/dist/utils/builders/builder.d.ts +2 -0
  92. package/dist/utils/builders/builder.js +22 -1
  93. package/dist/utils/builders/builder.js.map +1 -1
  94. package/dist/utils/builders/common/connection-facet-helpers.d.ts +2 -0
  95. package/dist/utils/builders/common/connection-facet-helpers.js +4 -1
  96. package/dist/utils/builders/common/connection-facet-helpers.js.map +1 -1
  97. package/dist/utils/builders/common/network-builder-helpers.d.ts +5 -0
  98. package/dist/utils/builders/common/network-builder-helpers.js +8 -0
  99. package/dist/utils/builders/common/network-builder-helpers.js.map +1 -1
  100. package/dist/utils/builders/common/network-metadata.js +1 -1
  101. package/dist/utils/builders/common/network-metadata.js.map +1 -1
  102. package/dist/utils/builders/common/types.d.ts +1 -1
  103. package/dist/utils/builders/local-space-resolver.d.ts +13 -3
  104. package/dist/utils/builders/local-space-resolver.js +16 -3
  105. package/dist/utils/builders/local-space-resolver.js.map +1 -1
  106. package/dist/utils/builders/policies-factory.d.ts +6 -2
  107. package/dist/utils/builders/policies-factory.js +106 -8
  108. package/dist/utils/builders/policies-factory.js.map +1 -1
  109. package/dist/utils/builders/project-builder-impl.d.ts +20 -1
  110. package/dist/utils/builders/project-builder-impl.js +40 -4
  111. package/dist/utils/builders/project-builder-impl.js.map +1 -1
  112. package/dist/utils/builders/project-builder.d.ts +18 -3
  113. package/dist/utils/builders/project-builder.js +4 -2
  114. package/dist/utils/builders/project-builder.js.map +1 -1
  115. package/dist/utils/builders/remote-space-resolver.d.ts +3 -3
  116. package/dist/utils/builders/remote-space-resolver.js +47 -32
  117. package/dist/utils/builders/remote-space-resolver.js.map +1 -1
  118. package/dist/utils/builders/space-serializer.d.ts +2 -0
  119. package/dist/utils/builders/space-serializer.js +12 -2
  120. package/dist/utils/builders/space-serializer.js.map +1 -1
  121. package/dist/utils/builders/v1/broker-builder.d.ts +1 -0
  122. package/dist/utils/builders/v1/broker-builder.js +45 -9
  123. package/dist/utils/builders/v1/broker-builder.js.map +1 -1
  124. package/dist/utils/builders/v1/connections-builder.js +3 -0
  125. package/dist/utils/builders/v1/connections-builder.js.map +1 -1
  126. package/dist/utils/builders/v1/network-builder.js +22 -4
  127. package/dist/utils/builders/v1/network-builder.js.map +1 -1
  128. package/dist/utils/builders/v2/broker-builder.js +1 -1
  129. package/dist/utils/builders/v2/broker-builder.js.map +1 -1
  130. package/dist/utils/builders/v2/connection-interfaces.d.ts +5 -0
  131. package/dist/utils/builders/v2/connection-interfaces.js +68 -0
  132. package/dist/utils/builders/v2/connection-interfaces.js.map +1 -0
  133. package/dist/utils/builders/v2/connections-builder.d.ts +5 -1
  134. package/dist/utils/builders/v2/connections-builder.js +120 -20
  135. package/dist/utils/builders/v2/connections-builder.js.map +1 -1
  136. package/dist/utils/builders/v2/llm-builder.js +17 -6
  137. package/dist/utils/builders/v2/llm-builder.js.map +1 -1
  138. package/dist/utils/builders/v2/network-builder.js +10 -1
  139. package/dist/utils/builders/v2/network-builder.js.map +1 -1
  140. package/dist/utils/constants.d.ts +22 -1
  141. package/dist/utils/constants.js +26 -4
  142. package/dist/utils/constants.js.map +1 -1
  143. package/dist/utils/deployment-settings.d.ts +1 -0
  144. package/dist/utils/deployment-settings.js.map +1 -1
  145. package/dist/utils/dry-run/dry-run-render.d.ts +1 -0
  146. package/dist/utils/dry-run/dry-run-render.js +23 -13
  147. package/dist/utils/dry-run/dry-run-render.js.map +1 -1
  148. package/dist/utils/exchange.d.ts +1 -0
  149. package/dist/utils/exchange.js +20 -0
  150. package/dist/utils/exchange.js.map +1 -1
  151. package/dist/utils/facets/agent-graph-facet.d.ts +1 -1
  152. package/dist/utils/facets/agent-graph-facet.js +10 -9
  153. package/dist/utils/facets/agent-graph-facet.js.map +1 -1
  154. package/dist/utils/facets/api-instance-facet.d.ts +2 -0
  155. package/dist/utils/facets/api-instance-facet.js +75 -19
  156. package/dist/utils/facets/api-instance-facet.js.map +1 -1
  157. package/dist/utils/facets/apim-policy-helpers.d.ts +29 -2
  158. package/dist/utils/facets/apim-policy-helpers.js +19 -5
  159. package/dist/utils/facets/apim-policy-helpers.js.map +1 -1
  160. package/dist/utils/facets/asset-facet.d.ts +2 -0
  161. package/dist/utils/facets/asset-facet.js +75 -40
  162. package/dist/utils/facets/asset-facet.js.map +1 -1
  163. package/dist/utils/facets/connection-facet.d.ts +6 -0
  164. package/dist/utils/facets/connection-facet.js +202 -22
  165. package/dist/utils/facets/connection-facet.js.map +1 -1
  166. package/dist/utils/facets/deployment-helpers.d.ts +2 -1
  167. package/dist/utils/facets/deployment-helpers.js +28 -21
  168. package/dist/utils/facets/deployment-helpers.js.map +1 -1
  169. package/dist/utils/facets/deployment-runner.js +88 -6
  170. package/dist/utils/facets/deployment-runner.js.map +1 -1
  171. package/dist/utils/facets/facets.d.ts +6 -0
  172. package/dist/utils/facets/facets.js +56 -9
  173. package/dist/utils/facets/facets.js.map +1 -1
  174. package/dist/utils/facets/mule-application-facet.js +2 -2
  175. package/dist/utils/facets/mule-application-facet.js.map +1 -1
  176. package/dist/utils/facets/publication-metadata-patcher.d.ts +7 -1
  177. package/dist/utils/facets/publication-metadata-patcher.js +32 -17
  178. package/dist/utils/facets/publication-metadata-patcher.js.map +1 -1
  179. package/dist/utils/facets/secret-manager-client.d.ts +29 -0
  180. package/dist/utils/facets/secret-manager-client.js +172 -0
  181. package/dist/utils/facets/secret-manager-client.js.map +1 -0
  182. package/dist/utils/facets/secret-ref-validator.d.ts +11 -0
  183. package/dist/utils/facets/secret-ref-validator.js +80 -0
  184. package/dist/utils/facets/secret-ref-validator.js.map +1 -0
  185. package/dist/utils/facets/secret-tls-validator.d.ts +6 -0
  186. package/dist/utils/facets/secret-tls-validator.js +59 -0
  187. package/dist/utils/facets/secret-tls-validator.js.map +1 -0
  188. package/dist/utils/gateway.d.ts +3 -0
  189. package/dist/utils/gateway.js +70 -1
  190. package/dist/utils/gateway.js.map +1 -1
  191. package/dist/utils/logger.js +1 -1
  192. package/dist/utils/logger.js.map +1 -1
  193. package/dist/utils/maven-proxy.d.ts +10 -0
  194. package/dist/utils/maven-proxy.js +118 -0
  195. package/dist/utils/maven-proxy.js.map +1 -0
  196. package/dist/utils/registry/registry-errors.d.ts +4 -0
  197. package/dist/utils/registry/registry-errors.js +36 -0
  198. package/dist/utils/registry/registry-errors.js.map +1 -0
  199. package/dist/utils/registry/registry-response.d.ts +46 -0
  200. package/dist/utils/registry/registry-response.js +264 -0
  201. package/dist/utils/registry/registry-response.js.map +1 -0
  202. package/dist/utils/request-executor.d.ts +9 -1
  203. package/dist/utils/request-executor.js +6 -3
  204. package/dist/utils/request-executor.js.map +1 -1
  205. package/dist/utils/run-local/build-status.js +4 -2
  206. package/dist/utils/run-local/build-status.js.map +1 -1
  207. package/dist/utils/run-local/index.d.ts +1 -1
  208. package/dist/utils/run-local/index.js +2 -1
  209. package/dist/utils/run-local/index.js.map +1 -1
  210. package/dist/utils/run-local/local-a2a-upstream.d.ts +1 -0
  211. package/dist/utils/run-local/local-a2a-upstream.js +5 -4
  212. package/dist/utils/run-local/local-a2a-upstream.js.map +1 -1
  213. package/dist/utils/run-local/local-tls-model.d.ts +18 -0
  214. package/dist/utils/run-local/local-tls-model.js +97 -0
  215. package/dist/utils/run-local/local-tls-model.js.map +1 -0
  216. package/dist/utils/run-local/local-tls.d.ts +37 -0
  217. package/dist/utils/run-local/local-tls.js +245 -0
  218. package/dist/utils/run-local/local-tls.js.map +1 -0
  219. package/dist/utils/run-local/policy-resolver.js +5 -0
  220. package/dist/utils/run-local/policy-resolver.js.map +1 -1
  221. package/dist/utils/run-local/runtime-environment-manager.d.ts +23 -2
  222. package/dist/utils/run-local/runtime-environment-manager.js +236 -6
  223. package/dist/utils/run-local/runtime-environment-manager.js.map +1 -1
  224. package/dist/utils/run-local/secrets-manager.d.ts +1 -0
  225. package/dist/utils/run-local/secrets-manager.js +2 -1
  226. package/dist/utils/run-local/secrets-manager.js.map +1 -1
  227. package/dist/utils/sanitize.d.ts +3 -0
  228. package/dist/utils/sanitize.js +45 -0
  229. package/dist/utils/sanitize.js.map +1 -0
  230. package/dist/utils/variables.d.ts +28 -6
  231. package/dist/utils/variables.js +114 -14
  232. package/dist/utils/variables.js.map +1 -1
  233. package/package.json +12 -10
  234. package/scripts/extract-error-catalog.js +88 -0
  235. package/templates/agentic-network/agent-network.yaml.template +1 -7
  236. package/templates/agentic-network/brokers/broker1.agent.template +1 -1
  237. package/templates/agentic-network/exchange.json.template +9 -1
@@ -1,30 +1,38 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RunLocal = exports.COMPOSE_SETTLE_TIMEOUT_MS = void 0;
4
+ exports.assertLocalRunSupported = assertLocalRunSupported;
5
+ exports.assertLocalRunSchema = assertLocalRunSchema;
4
6
  const tslib_1 = require("tslib");
5
7
  const core_1 = require("@oclif/core");
6
8
  const anypoint_cli_command_lib_1 = require("anypoint-cli-command-lib");
9
+ const agent_fabric_commands_1 = require("../../../utils/agent-fabric-commands");
7
10
  const node_fs_1 = require("node:fs");
8
11
  const fs = tslib_1.__importStar(require("fs-extra"));
9
12
  const node_net_1 = require("node:net");
13
+ const node_os_1 = require("node:os");
10
14
  const node_path_1 = require("node:path");
15
+ const yaml_1 = require("yaml");
16
+ const base_error_1 = require("../../../errors/base-error");
11
17
  const error_factory_1 = require("../../../errors/error-factory");
12
18
  const space_serializer_1 = require("../../../utils/builders/space-serializer");
13
19
  const facets_1 = require("../../../utils/facets/facets");
14
20
  const project_builder_1 = require("../../../utils/builders/project-builder");
15
21
  const project_builder_impl_1 = require("../../../utils/builders/project-builder-impl");
16
22
  const variables_1 = require("../../../utils/variables");
23
+ const constants_1 = require("../../../helpers/project/constants");
17
24
  const utils_1 = require("../../../helpers/utils");
18
- const constants_1 = require("../../../utils/constants");
25
+ const constants_2 = require("../../../utils/constants");
19
26
  const naming_1 = require("../../../utils/naming");
20
27
  const network_lock_1 = require("../../../utils/builders/network-lock");
21
28
  const run_local_1 = require("../../../utils/run-local");
29
+ const local_tls_1 = require("../../../utils/run-local/local-tls");
30
+ const local_tls_model_1 = require("../../../utils/run-local/local-tls-model");
22
31
  const GITIGNORE_FILE = '.gitignore';
23
32
  const LOCAL_RUN_GITIGNORE_ENTRY = `${run_local_1.CHAT_ROOT_DIR}/`;
24
33
  const LOCAL_RUN_GITIGNORE_COMMENT = '# .deployment — local render output and remote deploy descriptors; may contain secret material (e.g. the encrypted secrets store)';
25
34
  const TARGET_DIR = 'target';
26
35
  const VARIABLES_CACHE_FILE = 'variables.json';
27
- const STORED_SECRET_PLACEHOLDER = '__KEYCHAIN__';
28
36
  /**
29
37
  * What the masked prompt rejects with on Ctrl+C: raw-mode stdin sees a keystroke, not a signal.
30
38
  * The literal is thrown by the `password-prompt` package (`reject(new Error('SIGINT'))`), reached via
@@ -36,12 +44,138 @@ const RAW_MODE_SIGINT_MESSAGE = 'SIGINT';
36
44
  exports.COMPOSE_SETTLE_TIMEOUT_MS = 30000;
37
45
  /** Debounce window collapsing a burst of file-change events into a single rebuild. */
38
46
  const WATCH_DEBOUNCE_MS = 500;
39
- class RunLocal extends anypoint_cli_command_lib_1.AuthenticationBaseCommand {
47
+ /** `exchange.json` classifier written by the v1 project template. */
48
+ const V1_EXCHANGE_CLASSIFIER = 'agent-network';
49
+ // Rejects a local run before build when exchange.json names a project local run cannot start.
50
+ // A missing descriptor, unreadable JSON, or a blank classifier keeps today's path so older
51
+ // descriptors are not rejected here (build still reports 1013 for a real unknown schema version).
52
+ function assertLocalRunSupported(projectPath) {
53
+ var _a;
54
+ const exchangeJsonPath = (0, node_path_1.join)(projectPath, constants_2.DESCRIPTOR_FILE);
55
+ if (!fs.existsSync(exchangeJsonPath)) {
56
+ return;
57
+ }
58
+ let classifier;
59
+ try {
60
+ classifier = (_a = (0, utils_1.safeJsonFileParse)(exchangeJsonPath).jsonObject) === null || _a === void 0 ? void 0 : _a.classifier;
61
+ }
62
+ catch {
63
+ return;
64
+ }
65
+ if (typeof classifier !== 'string' || classifier.trim().length === 0) {
66
+ return;
67
+ }
68
+ const normalized = classifier.trim();
69
+ if (normalized === constants_1.AgentNetworkClassifiers.AGENTIC_NETWORK) {
70
+ return;
71
+ }
72
+ if (normalized === V1_EXCHANGE_CLASSIFIER) {
73
+ throw error_factory_1.ErrorFactory.v1NotSupportedForLocalRun();
74
+ }
75
+ throw error_factory_1.ErrorFactory.localRunUnsupportedProjectType(normalized);
76
+ }
77
+ const LOCAL_RUN_SCHEMA_V1 = '1.0.0';
78
+ function isEnoent(error) {
79
+ return error instanceof Error && error.code === 'ENOENT';
80
+ }
81
+ // `relative` returns `..agent.yaml` for an in-project file of that name. Only a
82
+ // `..` segment (or an absolute result, such as another Windows drive) is outside.
83
+ function pathEscapesProject(rel) {
84
+ return (0, node_path_1.isAbsolute)(rel) || rel.split(/[/\\]/).includes('..');
85
+ }
86
+ function declaredLocalRunMain(projectPath) {
87
+ var _a;
88
+ const exchangeJsonPath = (0, node_path_1.join)(projectPath, constants_2.DESCRIPTOR_FILE);
89
+ // No descriptor: build opens agent-network.yaml. Classify that file.
90
+ if (!fs.existsSync(exchangeJsonPath)) {
91
+ return 'agent-network.yaml';
92
+ }
93
+ let declared;
94
+ try {
95
+ declared = (_a = (0, utils_1.safeJsonFileParse)(exchangeJsonPath).jsonObject) === null || _a === void 0 ? void 0 : _a.main;
96
+ }
97
+ catch (error) {
98
+ // Invalid or unreadable JSON is a descriptor failure, not a schema one.
99
+ // Do not invent a main and classify whatever agent-network.yaml happens to say.
100
+ if (error instanceof SyntaxError || isEnoent(error)) {
101
+ return undefined;
102
+ }
103
+ throw error;
104
+ }
105
+ if (typeof declared === 'string' && declared.trim().length > 0) {
106
+ return declared.trim();
107
+ }
108
+ // A descriptor with no main is 8505 later. Do not inspect a default file first.
109
+ return undefined;
110
+ }
111
+ function yamlInsideProject(projectPath, main) {
112
+ const candidate = (0, node_path_1.resolve)(projectPath, main);
113
+ try {
114
+ const root = fs.realpathSync(projectPath);
115
+ const real = fs.realpathSync(candidate);
116
+ const rel = (0, node_path_1.relative)(root, real);
117
+ if (pathEscapesProject(rel) || !fs.statSync(real).isFile()) {
118
+ return undefined;
119
+ }
120
+ return real;
121
+ }
122
+ catch (error) {
123
+ // The main is absent. Any other I/O error is not "skip schema classification".
124
+ if (isEnoent(error)) {
125
+ return undefined;
126
+ }
127
+ throw error;
128
+ }
129
+ }
130
+ // APB throws UnrecognizedSpecException before the builder can raise 1013. That
131
+ // exception is not a BaseError, so the status file would record kind "unexpected".
132
+ // A document headed by agentNetwork stays on the build path so a spec error remains 1002.
133
+ function assertLocalRunSchema(projectPath) {
134
+ const main = declaredLocalRunMain(projectPath);
135
+ if (!main) {
136
+ return;
137
+ }
138
+ const yamlPath = yamlInsideProject(projectPath, main);
139
+ if (!yamlPath) {
140
+ return;
141
+ }
142
+ let raw;
143
+ try {
144
+ raw = (0, yaml_1.parse)(fs.readFileSync(yamlPath, 'utf8'));
145
+ }
146
+ catch (error) {
147
+ // Invalid YAML stays on the build path. A read error does not.
148
+ if (error instanceof yaml_1.YAMLParseError) {
149
+ return;
150
+ }
151
+ throw error;
152
+ }
153
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw)) {
154
+ return;
155
+ }
156
+ const document = raw;
157
+ const agentNetwork = typeof document.agentNetwork === 'string' ? document.agentNetwork.trim() : '';
158
+ if (agentNetwork.length > 0) {
159
+ return;
160
+ }
161
+ const schemaVersion = typeof document.schemaVersion === 'string' ? document.schemaVersion.trim() : '';
162
+ // `schemaVersion: 2.0.0` is a builder key, not a V2 document. V2 documents are
163
+ // headed by `agentNetwork`. Leaving this through makes APB throw a non-BaseError.
164
+ if (schemaVersion.length === 0) {
165
+ return;
166
+ }
167
+ if (schemaVersion === LOCAL_RUN_SCHEMA_V1) {
168
+ throw error_factory_1.ErrorFactory.v1NotSupportedForLocalRun();
169
+ }
170
+ throw error_factory_1.ErrorFactory.unsupportedLocalRunSchema(schemaVersion);
171
+ }
172
+ class RunLocal extends agent_fabric_commands_1.AgentFabricAuthenticationCommand {
40
173
  constructor() {
41
174
  super(...arguments);
42
175
  this.secretsManager = (0, run_local_1.createSecretsManager)();
43
176
  this.runtimeManager = new run_local_1.DockerComposeEnvironmentManager();
44
177
  this.localRunManager = new run_local_1.DefaultLocalRunManager();
178
+ this.localTlsEnv = {};
45
179
  // True while a masked secret prompt is open. password-prompt resets raw mode synchronously before
46
180
  // its Ctrl+C rejection surfaces, so this is the only signal the rebuild catch has to tell an
47
181
  // interrupted prompt from a genuine failure once the recognized SIGINT literal drifts.
@@ -72,6 +206,8 @@ class RunLocal extends anypoint_cli_command_lib_1.AuthenticationBaseCommand {
72
206
  host: flags.host,
73
207
  dockerPort,
74
208
  };
209
+ assertLocalRunSupported(projectPath);
210
+ assertLocalRunSchema(projectPath);
75
211
  if (flags.build) {
76
212
  this.buildStatus.writeRunning('building');
77
213
  await this.buildProject(projectPath, flags.host);
@@ -110,7 +246,7 @@ class RunLocal extends anypoint_cli_command_lib_1.AuthenticationBaseCommand {
110
246
  }
111
247
  async render(options) {
112
248
  var _a, _b;
113
- const { projectPath, targetDir, localRenderDir, host, dockerPort } = options;
249
+ const { projectPath, targetDir, localRenderDir, host, dockerPort, properties: propertyFlags } = options;
114
250
  const totalStart = Date.now();
115
251
  (_a = this.buildStatus) === null || _a === void 0 ? void 0 : _a.writeRunning('rendering');
116
252
  try {
@@ -124,13 +260,28 @@ class RunLocal extends anypoint_cli_command_lib_1.AuthenticationBaseCommand {
124
260
  }
125
261
  const localVersionVariables = RunLocal.deriveLocalVersionVariables(space);
126
262
  (0, network_lock_1.validateNoReservedVersionVariableDeclarations)(Object.keys(variables_1.VariablesHelper.flattenVariables((_b = space.variables) !== null && _b !== void 0 ? _b : {})));
263
+ const tlsVariables = (0, local_tls_1.buildTlsVariableDefinitions)(space);
264
+ RunLocal.validateNoSecretInGatewayRoutingFields(space, tlsVariables);
127
265
  RunLocal.validateReferencedVariablesDeclared(space, localVersionVariables);
128
- RunLocal.validateNoSecretInGatewayRoutingFields(space);
129
- RunLocal.validateNoEnvVarNameCollisions(space, [key => this.secretsManager.toEnvVarName(key), naming_1.toAgentGraphEnvVarName]);
266
+ this.assertNoEnvVarNameCollisions(space);
267
+ const knownVariables = {
268
+ ...localVersionVariables,
269
+ ...RunLocal.loadVariablesCache(localRenderDir),
270
+ ...variables_1.VariablesHelper.propertiesArrayToObject(propertyFlags),
271
+ };
272
+ (0, local_tls_1.assertLocalTlsUpstreamsHttps)(space, knownVariables, true);
273
+ const promptTlsVariables = (0, local_tls_1.buildTlsVariableDefinitions)(space, knownVariables);
274
+ const sessionTls = this.localTlsSession;
130
275
  this.localRunManager.validateExchangeAssets(space, targetDir);
131
276
  fs.mkdirpSync(localRenderDir);
132
277
  RunLocal.protectLocalRunInGitIgnore(projectPath);
133
- const collectedProperties = await this.collectVariables(space, options);
278
+ const collectedProperties = await this.collectVariables(space, options, sessionTls ? {} : promptTlsVariables);
279
+ const resolvedVariables = { ...localVersionVariables, ...collectedProperties.properties, ...collectedProperties.securedProperties };
280
+ (0, local_tls_1.assertLocalTlsUpstreamsHttps)(space, resolvedVariables);
281
+ const localTls = sessionTls ?
282
+ this.reuseLocalTls(sessionTls, (0, local_tls_1.localTlsConnectionIds)(space, resolvedVariables)) :
283
+ (0, local_tls_1.resolveLocalTlsForSpace)(space, resolvedVariables, projectPath, name => this.secretsManager.toEnvVarName(name));
284
+ this.commitPendingTlsSecrets(projectPath, Object.keys(localTls));
134
285
  const descriptor = RunLocal.loadDescriptor(projectPath);
135
286
  const mainFile = descriptor.main;
136
287
  if (!mainFile) {
@@ -141,9 +292,13 @@ class RunLocal extends anypoint_cli_command_lib_1.AuthenticationBaseCommand {
141
292
  this.localRunManager.setup({ projectPath, targetDir, localRenderDir, space, dockerPort });
142
293
  anypoint_cli_command_lib_1.Logger.cliEnd(`(${Date.now() - setupStart}ms) ✅`);
143
294
  const policyResolver = new run_local_1.ExchangePolicyResolver({ req: this.req, localRenderDir, session: this.session, host });
144
- const renderVariables = await this.stepRenderFacets(space, collectedProperties, localRenderDir, policyResolver, dockerPort, localVersionVariables);
295
+ const localTlsEnv = Object.assign({}, ...Object.values(localTls).map(resolution => resolution.secureEnv));
296
+ const bindings = Object.fromEntries(Object.entries(localTls).map(([id, resolution]) => [id, resolution.bindingConfig]));
297
+ const renderVariables = await this.stepRenderFacets(space, collectedProperties, localRenderDir, policyResolver, dockerPort, localVersionVariables, { bindings, variables: tlsVariables });
145
298
  await this.stepDownloadPolicies(policyResolver, localRenderDir);
146
- this.stepWriteRuntimeConfig(localRenderDir, space, mainFile, dockerPort, renderVariables);
299
+ this.stepWriteRuntimeConfig(localRenderDir, space, mainFile, dockerPort, renderVariables, Object.keys(localTlsEnv));
300
+ this.localTlsSession = { ...this.localTlsSession, ...localTls };
301
+ this.localTlsEnv = localTlsEnv;
147
302
  }
148
303
  catch (error) {
149
304
  anypoint_cli_command_lib_1.Logger.cliEndFailed();
@@ -156,10 +311,10 @@ class RunLocal extends anypoint_cli_command_lib_1.AuthenticationBaseCommand {
156
311
  async startRuntime(options) {
157
312
  var _a, _b, _c, _d;
158
313
  const space = this.loadBuiltSpace(options.targetDir);
159
- RunLocal.validateNoEnvVarNameCollisions(space, [key => this.secretsManager.toEnvVarName(key), naming_1.toAgentGraphEnvVarName]);
314
+ this.assertNoEnvVarNameCollisions(space);
160
315
  (_a = this.buildStatus) === null || _a === void 0 ? void 0 : _a.writeRunning('deploying');
161
316
  this.runtimeManager.assertAgentGraphImage();
162
- const env = this.runtimeManager.buildEnv(this.secretsManager, options.projectPath, space);
317
+ const env = this.runtimeManager.buildEnv(this.secretsManager, options.projectPath, space, this.localTlsEnv);
163
318
  try {
164
319
  await this.runtimeManager.start(options.localRenderDir, env);
165
320
  // Attached compose exited cleanly (containers stopped) — treat as graceful stop.
@@ -178,7 +333,7 @@ class RunLocal extends anypoint_cli_command_lib_1.AuthenticationBaseCommand {
178
333
  runWithWatch(options) {
179
334
  // Extracted into WatchSession so each unit of the watch state machine stays independently
180
335
  // readable; the closures previously shared ~10 mutable locals folded into one method.
181
- return new WatchSession(options, this.runtimeManager, this.secretsManager, (projectPath, host) => this.buildProject(projectPath, host), opts => this.render(opts), targetDir => this.loadBuiltSpace(targetDir), () => this.maskedPromptOpen, (pending, timeoutMs) => RunLocal.settleOrTimeout(pending, timeoutMs), this.buildStatus).run();
336
+ return new WatchSession(options, this.runtimeManager, this.secretsManager, (projectPath, host) => this.buildProject(projectPath, host), opts => this.render(opts), targetDir => this.loadBuiltSpace(targetDir), () => this.maskedPromptOpen, (pending, timeoutMs) => RunLocal.settleOrTimeout(pending, timeoutMs), this.buildStatus, () => this.localTlsEnv).run();
182
337
  }
183
338
  // Never rejects, so teardown can sequence on it unconditionally. Timer unref'd to not hold the loop.
184
339
  static settleOrTimeout(pending, timeoutMs) {
@@ -199,23 +354,71 @@ class RunLocal extends anypoint_cli_command_lib_1.AuthenticationBaseCommand {
199
354
  }
200
355
  return space;
201
356
  }
357
+ assertNoEnvVarNameCollisions(space) {
358
+ RunLocal.validateNoEnvVarNameCollisions(space, [
359
+ { fn: key => this.secretsManager.toEnvVarName(key), extraKeys: (0, local_tls_1.localTlsSecretKeys)(space) },
360
+ { fn: naming_1.toAgentGraphEnvVarName },
361
+ ]);
362
+ }
363
+ reuseLocalTls(session, connectionIds) {
364
+ return Object.fromEntries(connectionIds.map(id => {
365
+ if (!session[id]) {
366
+ throw error_factory_1.ErrorFactory.localTlsAddedWhileWatching(id);
367
+ }
368
+ return [id, session[id]];
369
+ }));
370
+ }
202
371
  seedStoredSecretPlaceholders(variables, mergedDefaults, projectPath) {
203
372
  const flatVars = variables_1.VariablesHelper.flattenVariables(variables);
204
373
  for (const [key, varDef] of Object.entries(flatVars)) {
205
- if (!variables_1.VariablesHelper.isSecret(varDef)) {
374
+ if (!variables_1.VariablesHelper.isLocallySecured(varDef)) {
206
375
  continue;
207
376
  }
208
377
  if (mergedDefaults[key]) {
209
378
  continue;
210
379
  }
211
380
  if (this.secretsManager.exists(projectPath, key)) {
212
- mergedDefaults[key] = STORED_SECRET_PLACEHOLDER;
381
+ mergedDefaults[key] = run_local_1.STORED_SECRET_PLACEHOLDER;
213
382
  }
214
383
  }
215
384
  }
216
- hydrateOrPersistSecuredProperties(collectedProperties, projectPath) {
385
+ auditSecretEvent(action, projectPath, key, outcome) {
386
+ anypoint_cli_command_lib_1.Logger.info(JSON.stringify({
387
+ event: 'local-secret-change',
388
+ actor: (0, node_os_1.userInfo)().username,
389
+ action,
390
+ project: projectPath,
391
+ key,
392
+ outcome,
393
+ timestamp: new Date().toISOString(),
394
+ }));
395
+ }
396
+ persistSecret(projectPath, key, value) {
397
+ const stored = this.secretsManager.store(projectPath, key, value);
398
+ this.auditSecretEvent('store', projectPath, key, stored ? 'success' : 'failure');
399
+ if (!stored) {
400
+ anypoint_cli_command_lib_1.Logger.warn(`Could not persist secret '${key}' to the secrets backend; ` +
401
+ 'it will be used for this run but will not be available on the next run.');
402
+ }
403
+ }
404
+ commitPendingTlsSecrets(projectPath, resolvedIds) {
405
+ var _a;
406
+ const { store, remove } = (_a = this.pendingTlsSecrets) !== null && _a !== void 0 ? _a : { store: {}, remove: [] };
407
+ this.pendingTlsSecrets = undefined;
408
+ const resolvedKeys = (0, local_tls_model_1.tlsKeysFor)(resolvedIds);
409
+ for (const [key, value] of Object.entries(store)) {
410
+ if (resolvedKeys.has(key)) {
411
+ this.persistSecret(projectPath, key, value);
412
+ }
413
+ }
414
+ for (const key of remove) {
415
+ const deleted = this.secretsManager.delete(projectPath, key);
416
+ this.auditSecretEvent('delete', projectPath, key, deleted ? 'success' : 'failure');
417
+ }
418
+ }
419
+ hydrateOrPersistSecuredProperties(collectedProperties, projectPath, deferredKeys, pending) {
217
420
  for (const [key, value] of Object.entries(collectedProperties.securedProperties)) {
218
- if (value === STORED_SECRET_PLACEHOLDER) {
421
+ if (value === run_local_1.STORED_SECRET_PLACEHOLDER) {
219
422
  // Fail loud rather than write a blank key: a null value means the keychain entry
220
423
  // was deleted or the secrets file failed to decrypt.
221
424
  const stored = this.secretsManager.retrieve(projectPath, key);
@@ -224,44 +427,57 @@ class RunLocal extends anypoint_cli_command_lib_1.AuthenticationBaseCommand {
224
427
  }
225
428
  collectedProperties.securedProperties[key] = stored;
226
429
  }
227
- else {
228
- const stored = this.secretsManager.store(projectPath, key, value);
229
- if (!stored) {
230
- anypoint_cli_command_lib_1.Logger.warn(`Could not persist secret '${key}' to the secrets backend; ` +
231
- 'it will be used for this run but will not be available on the next run.');
430
+ else if (key in deferredKeys) {
431
+ if (value !== '') {
432
+ pending.store[key] = value;
232
433
  }
233
434
  }
435
+ else {
436
+ this.persistSecret(projectPath, key, value);
437
+ }
234
438
  }
235
439
  }
236
- async collectVariables(space, options) {
237
- var _a, _b;
440
+ async collectVariables(space, options, tlsVariables) {
441
+ var _a, _b, _c, _d;
442
+ this.pendingTlsSecrets = undefined;
238
443
  let collectedProperties = { properties: {}, securedProperties: {} };
239
- const variables = space.variables;
240
- if (!variables) {
444
+ if (Object.keys({ ...space.variables, ...tlsVariables }).length === 0) {
241
445
  return collectedProperties;
242
446
  }
243
447
  const cachedVars = RunLocal.loadVariablesCache(options.localRenderDir);
244
448
  const flagVars = variables_1.VariablesHelper.propertiesArrayToObject(options.properties);
245
- const mergedDefaults = { ...cachedVars, ...flagVars };
246
- this.seedStoredSecretPlaceholders(variables, mergedDefaults, options.projectPath);
247
- const needsPrompts = variables_1.VariablesHelper.checkIfPromptsNeeded(variables, mergedDefaults);
449
+ const cachedUserVars = Object.fromEntries(Object.entries(cachedVars).filter(([key]) => !(key in tlsVariables)));
450
+ const mergedDefaults = { ...cachedUserVars, ...flagVars };
451
+ this.seedStoredSecretPlaceholders((_a = space.variables) !== null && _a !== void 0 ? _a : {}, mergedDefaults, options.projectPath);
452
+ const variables = { ...space.variables, ...(0, local_tls_1.withCachedTlsDefaults)(tlsVariables, cachedVars) };
453
+ const promptOptions = { promptSecretRefs: true };
454
+ const needsPrompts = variables_1.VariablesHelper.checkIfPromptsNeeded(variables, mergedDefaults, '', flagVars, promptOptions);
248
455
  if (needsPrompts) {
249
456
  anypoint_cli_command_lib_1.Logger.print('Please provide values for the following variables:');
250
- (_a = this.buildStatus) === null || _a === void 0 ? void 0 : _a.writeRunning('waiting_for_input');
457
+ (_b = this.buildStatus) === null || _b === void 0 ? void 0 : _b.writeRunning('waiting_for_input');
251
458
  }
252
459
  // Only while a prompt is actually open: a throw after a no-prompt collect must be `failed`, not Ctrl+C.
253
460
  this.maskedPromptOpen = needsPrompts;
254
- collectedProperties = await variables_1.VariablesHelper.promptForVariables(variables, mergedDefaults);
461
+ collectedProperties = await variables_1.VariablesHelper.promptForVariables(variables, mergedDefaults, '', flagVars, promptOptions);
255
462
  this.maskedPromptOpen = false;
256
463
  if (needsPrompts) {
257
- (_b = this.buildStatus) === null || _b === void 0 ? void 0 : _b.writeRunning('rendering');
464
+ (_c = this.buildStatus) === null || _c === void 0 ? void 0 : _c.writeRunning('rendering');
258
465
  }
259
- this.hydrateOrPersistSecuredProperties(collectedProperties, options.projectPath);
260
- RunLocal.saveVariablesCache(options.localRenderDir, collectedProperties);
466
+ const pending = {
467
+ store: {},
468
+ remove: (0, local_tls_1.applyTlsOptionalAnswers)({ collected: collectedProperties, tlsVariables, flagVars, projectPath: options.projectPath, secretsManager: this.secretsManager }),
469
+ };
470
+ this.hydrateOrPersistSecuredProperties(collectedProperties, options.projectPath, tlsVariables, pending);
471
+ this.pendingTlsSecrets = pending;
472
+ const currentTlsIds = [...new Set([...(0, local_tls_1.localTlsConnectionIds)(space), ...Object.keys((_d = this.localTlsSession) !== null && _d !== void 0 ? _d : {})])];
473
+ RunLocal.saveVariablesCache(options.localRenderDir, {
474
+ properties: { ...(0, local_tls_1.retainedTlsAnswers)(cachedVars, currentTlsIds, collectedProperties), ...collectedProperties.properties },
475
+ securedProperties: collectedProperties.securedProperties,
476
+ });
261
477
  return collectedProperties;
262
478
  }
263
479
  /** Returns the redaction map the facets rendered against. Built after the stage: facets inject variables while it runs. */
264
- async stepRenderFacets(space, properties, localRenderDir, policyResolver, dockerPort, localVersionVariables = {}) {
480
+ async stepRenderFacets(space, properties, localRenderDir, policyResolver, dockerPort, localVersionVariables, tls) {
265
481
  anypoint_cli_command_lib_1.Logger.cliStart('Rendering gateway and agent-graph configuration');
266
482
  const start = Date.now();
267
483
  const stageContext = new project_builder_impl_1.DefaultStageContextBuilder(this.req)
@@ -269,13 +485,14 @@ class RunLocal extends anypoint_cli_command_lib_1.AuthenticationBaseCommand {
269
485
  .withLocalRenderDir(localRenderDir)
270
486
  .withPolicyResolver(policyResolver)
271
487
  .withDockerPort(dockerPort)
488
+ .withLocalTls(tls.bindings)
272
489
  .build();
273
490
  for (const [key, version] of Object.entries(localVersionVariables)) {
274
491
  stageContext.stageResultRegistry.withVariable(key, version);
275
492
  }
276
493
  await facets_1.ProjectFacets.execute(project_builder_1.Stages.LocalRender, space, stageContext);
277
494
  anypoint_cli_command_lib_1.Logger.cliEnd(`(${Date.now() - start}ms) ✅`);
278
- return variables_1.VariablesHelper.buildSecretRedactionMap(space.variables, variables_1.VariablesHelper.getAllVariablesFromContext(stageContext));
495
+ return variables_1.VariablesHelper.buildSecretRedactionMap({ ...space.variables, ...tls.variables }, variables_1.VariablesHelper.getAllVariablesFromContext(stageContext));
279
496
  }
280
497
  async stepDownloadPolicies(policyResolver, localRenderDir) {
281
498
  anypoint_cli_command_lib_1.Logger.cliStart('Downloading custom policies');
@@ -288,7 +505,7 @@ class RunLocal extends anypoint_cli_command_lib_1.AuthenticationBaseCommand {
288
505
  anypoint_cli_command_lib_1.Logger.cliEnd(`(${Date.now() - start}ms) ✅`);
289
506
  }
290
507
  }
291
- stepWriteRuntimeConfig(localRenderDir, space, mainFile, dockerPort, renderVariables) {
508
+ stepWriteRuntimeConfig(localRenderDir, space, mainFile, dockerPort, renderVariables, tlsEnvNames) {
292
509
  anypoint_cli_command_lib_1.Logger.cliStart('Writing runtime configuration');
293
510
  const start = Date.now();
294
511
  // Every secret reaches its container through env-var indirection, never baked into on-disk
@@ -304,9 +521,9 @@ class RunLocal extends anypoint_cli_command_lib_1.AuthenticationBaseCommand {
304
521
  });
305
522
  runtimeManager.addGateway({
306
523
  side: 'egress',
307
- port: constants_1.EGRESS_GW_PORT,
524
+ port: constants_2.EGRESS_GW_PORT,
308
525
  configDir: './egress/config',
309
- securedEnvPassthrough: gatewayEnvPassthrough,
526
+ securedEnvPassthrough: { ...gatewayEnvPassthrough, ...RunLocal.buildTlsEnvPassthrough(tlsEnvNames) },
310
527
  });
311
528
  runtimeManager.addStaticServer({
312
529
  assetsDir: './exchange',
@@ -346,7 +563,7 @@ class RunLocal extends anypoint_cli_command_lib_1.AuthenticationBaseCommand {
346
563
  const gatewayEnvPassthrough = {};
347
564
  const flatVars = variables_1.VariablesHelper.flattenVariables((_a = space.variables) !== null && _a !== void 0 ? _a : {});
348
565
  for (const [key, varDef] of Object.entries(flatVars)) {
349
- if (!variables_1.VariablesHelper.isSecret(varDef)) {
566
+ if (!variables_1.VariablesHelper.isLocallySecured(varDef)) {
350
567
  continue;
351
568
  }
352
569
  const secureName = this.secretsManager.toEnvVarName(key);
@@ -356,17 +573,20 @@ class RunLocal extends anypoint_cli_command_lib_1.AuthenticationBaseCommand {
356
573
  }
357
574
  return { agentGraphEnvPassthrough, gatewayEnvPassthrough };
358
575
  }
576
+ static buildTlsEnvPassthrough(tlsEnvNames) {
577
+ return Object.fromEntries(tlsEnvNames.map(name => [name, `\${${name}:-}`]));
578
+ }
359
579
  /** Platforms (e.g. 'gemini') a broker's LLM connections use, for selecting its placeholder api-key env var. */
360
580
  static resolveLlmPlatforms(space, agentGraph) {
361
581
  var _a;
362
582
  const platforms = new Set();
363
583
  for (const connection of agentGraph.connections) {
364
- if (connection.type !== constants_1.LLM_ASSET_TYPE) {
584
+ if (connection.type !== constants_2.LLM_ASSET_TYPE) {
365
585
  continue;
366
586
  }
367
587
  for (const component of Object.values(space.components)) {
368
588
  for (const asset of Object.values(component.assets)) {
369
- if (asset.type === constants_1.LLM_ASSET_TYPE && asset.assetId === connection.asset.assetId && ((_a = asset.properties) === null || _a === void 0 ? void 0 : _a.platform)) {
589
+ if (asset.type === constants_2.LLM_ASSET_TYPE && asset.assetId === connection.asset.assetId && ((_a = asset.properties) === null || _a === void 0 ? void 0 : _a.platform)) {
370
590
  platforms.add(asset.properties.platform);
371
591
  }
372
592
  }
@@ -443,7 +663,7 @@ class RunLocal extends anypoint_cli_command_lib_1.AuthenticationBaseCommand {
443
663
  });
444
664
  }
445
665
  static loadDescriptor(projectPath) {
446
- const exchangeJsonPath = (0, node_path_1.join)(projectPath, constants_1.DESCRIPTOR_FILE);
666
+ const exchangeJsonPath = (0, node_path_1.join)(projectPath, constants_2.DESCRIPTOR_FILE);
447
667
  return (0, utils_1.safeJsonFileParse)(exchangeJsonPath).jsonObject;
448
668
  }
449
669
  static hasV2Components(space) {
@@ -533,10 +753,9 @@ class RunLocal extends anypoint_cli_command_lib_1.AuthenticationBaseCommand {
533
753
  throw error_factory_1.ErrorFactory.secretUpstreamAddress(connection.id, inUpstream);
534
754
  }
535
755
  }
536
- static validateNoSecretInGatewayRoutingFields(space) {
537
- var _a;
538
- const secretKeys = new Set(Object.entries(variables_1.VariablesHelper.flattenVariables((_a = space.variables) !== null && _a !== void 0 ? _a : {}))
539
- .filter(([, varDef]) => variables_1.VariablesHelper.isSecret(varDef))
756
+ static validateNoSecretInGatewayRoutingFields(space, generatedVariables = {}) {
757
+ const secretKeys = new Set(Object.entries(variables_1.VariablesHelper.flattenVariables({ ...space.variables, ...generatedVariables }))
758
+ .filter(([, varDef]) => variables_1.VariablesHelper.isLocallySecured(varDef))
540
759
  .map(([key]) => key));
541
760
  if (secretKeys.size === 0) {
542
761
  return;
@@ -560,11 +779,12 @@ class RunLocal extends anypoint_cli_command_lib_1.AuthenticationBaseCommand {
560
779
  static validateNoEnvVarNameCollisions(space, normalizers) {
561
780
  var _a;
562
781
  const secretKeys = Object.entries(variables_1.VariablesHelper.flattenVariables((_a = space.variables) !== null && _a !== void 0 ? _a : {}))
563
- .filter(([, varDef]) => variables_1.VariablesHelper.isSecret(varDef))
782
+ .filter(([, varDef]) => variables_1.VariablesHelper.isLocallySecured(varDef))
564
783
  .map(([key]) => key);
565
- for (const normalize of normalizers) {
784
+ for (const { fn: normalize, extraKeys = [] } of normalizers) {
785
+ const keys = [...secretKeys, ...extraKeys];
566
786
  const seen = new Map();
567
- for (const key of secretKeys) {
787
+ for (const key of keys) {
568
788
  const envVarName = normalize(key);
569
789
  const existing = seen.get(envVarName);
570
790
  if (existing !== undefined) {
@@ -588,7 +808,7 @@ RunLocal.examples = [
588
808
  '$ agent-network project run-local --path ./my-project --property myAgent.url:https://api.example.com',
589
809
  ];
590
810
  RunLocal.flags = {
591
- ...anypoint_cli_command_lib_1.AuthenticationBaseCommand.flags,
811
+ ...agent_fabric_commands_1.AgentFabricAuthenticationCommand.flags,
592
812
  path: core_1.Flags.file({
593
813
  description: 'The path to the project.',
594
814
  default: '.',
@@ -620,7 +840,7 @@ RunLocal.flags = {
620
840
  * thunks so no `RunLocal` member visibility has to widen.
621
841
  */
622
842
  class WatchSession {
623
- constructor(options, runtimeManager, secretsManager, buildProject, render, loadBuiltSpace, isMaskedPromptOpen, settleOrTimeout, buildStatus) {
843
+ constructor(options, runtimeManager, secretsManager, buildProject, render, loadBuiltSpace, isMaskedPromptOpen, settleOrTimeout, buildStatus, localTlsEnv) {
624
844
  this.options = options;
625
845
  this.runtimeManager = runtimeManager;
626
846
  this.secretsManager = secretsManager;
@@ -630,6 +850,7 @@ class WatchSession {
630
850
  this.isMaskedPromptOpen = isMaskedPromptOpen;
631
851
  this.settleOrTimeout = settleOrTimeout;
632
852
  this.buildStatus = buildStatus;
853
+ this.localTlsEnv = localTlsEnv;
633
854
  this.pendingRebuild = false;
634
855
  this.shuttingDown = false;
635
856
  this.debounceTimer = null;
@@ -653,7 +874,7 @@ class WatchSession {
653
874
  async run() {
654
875
  var _a, _b;
655
876
  const { projectPath, targetDir, localRenderDir } = this.options;
656
- const env = this.runtimeManager.buildEnv(this.secretsManager, projectPath, this.loadBuiltSpace(targetDir));
877
+ const env = this.runtimeManager.buildEnv(this.secretsManager, projectPath, this.loadBuiltSpace(targetDir), this.localTlsEnv());
657
878
  // With compose detached, nothing else keeps the command alive: only a signal ends the session.
658
879
  const session = new Promise(resolveFn => {
659
880
  this.resolveSession = resolveFn;
@@ -680,13 +901,17 @@ class WatchSession {
680
901
  await session;
681
902
  }
682
903
  catch (error) {
683
- // Either a partial `up` (containers holding the ingress port) or a post-start throw from
684
- // fingerprinting/watcher setup with the detached environment up. Route the teardown through
685
- // shutdown() so its `shuttingDown` guard owns the single `compose down` even if a signal races
686
- // in; await session (rethrowing would skip it and oclif exits mid-`down`).
904
+ // A partial `up` holds the ingress port. Name the unhealthy service only for that compose
905
+ // failure, and only when teardown has not already started: a signal or an image-missing
906
+ // BaseError must not wait on `docker compose logs` or rewrite a non-compose error.
907
+ const explained = this.shuttingDown || !isDetachedComposeFailure(error) ?
908
+ error :
909
+ await this.explainComposeFailure(error);
910
+ // Route the teardown through shutdown() so its `shuttingDown` guard owns the single `compose down`
911
+ // even if a signal races in; await session (rethrowing would skip it and oclif exits mid-`down`).
687
912
  this.shutdown('error');
688
913
  await session;
689
- throw error;
914
+ throw explained;
690
915
  }
691
916
  }
692
917
  finally {
@@ -735,6 +960,8 @@ class WatchSession {
735
960
  async runRebuild() {
736
961
  var _a, _b, _c, _d, _e, _f, _g;
737
962
  const { projectPath, targetDir, localRenderDir, host } = this.options;
963
+ // Set only around applyChanges, so a build or render failure does not ask docker for a diagnosis.
964
+ let composeApplyFailed = false;
738
965
  anypoint_cli_command_lib_1.Logger.print('');
739
966
  anypoint_cli_command_lib_1.Logger.info('Change detected, rebuilding...');
740
967
  // Stopped for the whole rebuild so inherited container output can't drown a masked secret prompt.
@@ -746,12 +973,14 @@ class WatchSession {
746
973
  (_c = this.buildStatus) === null || _c === void 0 ? void 0 : _c.beginWatchGeneration();
747
974
  (_d = this.buildStatus) === null || _d === void 0 ? void 0 : _d.writeRunning('building');
748
975
  try {
976
+ assertLocalRunSupported(projectPath);
977
+ assertLocalRunSchema(projectPath);
749
978
  await this.buildProject(projectPath, host);
750
979
  await this.render(this.options);
751
980
  anypoint_cli_command_lib_1.Logger.info('Applying changes to the local environment...');
752
981
  // Re-read: this render may have declared a variable the pre-loop env doesn't carry.
753
982
  const space = this.loadBuiltSpace(targetDir);
754
- const env = this.runtimeManager.buildEnv(this.secretsManager, projectPath, space);
983
+ const env = this.runtimeManager.buildEnv(this.secretsManager, projectPath, space, this.localTlsEnv());
755
984
  if (this.shuttingDown) {
756
985
  return;
757
986
  }
@@ -760,7 +989,9 @@ class WatchSession {
760
989
  // forward so the next rebuild diffs against the state this one just applied.
761
990
  const { services, fingerprints } = (0, run_local_1.selectBrokersToRecreate)(space, localRenderDir, this.priorFingerprints);
762
991
  (_e = this.buildStatus) === null || _e === void 0 ? void 0 : _e.writeRunning('deploying');
992
+ composeApplyFailed = true;
763
993
  await this.trackCompose(() => this.runtimeManager.applyChanges(localRenderDir, env, services));
994
+ composeApplyFailed = false;
764
995
  // Advanced only after the apply resolves: a failed recreate must leave the baseline at the
765
996
  // last-applied state so the next rebuild re-selects the still-pending broker.
766
997
  this.priorFingerprints = fingerprints;
@@ -781,8 +1012,13 @@ class WatchSession {
781
1012
  if (this.shuttingDown) {
782
1013
  return;
783
1014
  }
784
- (_g = this.buildStatus) === null || _g === void 0 ? void 0 : _g.writeFailed(error);
785
- anypoint_cli_command_lib_1.Logger.error(`Rebuild failed: ${error.message}`);
1015
+ // Containers are still up on a failed apply. Read them before the session re-attaches logs,
1016
+ // and do not `compose down` — a rebuild failure keeps the previous environment.
1017
+ const reported = composeApplyFailed && isDetachedComposeFailure(error) ?
1018
+ await this.explainComposeFailure(error) :
1019
+ error;
1020
+ (_g = this.buildStatus) === null || _g === void 0 ? void 0 : _g.writeFailed(reported);
1021
+ anypoint_cli_command_lib_1.Logger.error(`Rebuild failed: ${reported instanceof Error ? reported.message : String(reported)}`);
786
1022
  }
787
1023
  finally {
788
1024
  // Every way out of the rebuild left the follower stopped; a session without one stays silent.
@@ -793,6 +1029,30 @@ class WatchSession {
793
1029
  }
794
1030
  }
795
1031
  }
1032
+ /**
1033
+ * Prints a bounded compose diagnosis, then returns `error` with the failing service names appended.
1034
+ * The log text stays out of build-status.json: that file stores phase and kind only.
1035
+ */
1036
+ async explainComposeFailure(error) {
1037
+ let failingServices = [];
1038
+ let text = '';
1039
+ try {
1040
+ const diagnosis = await this.runtimeManager.diagnoseComposeFailure(this.options.localRenderDir);
1041
+ failingServices = diagnosis.failingServices;
1042
+ text = diagnosis.text;
1043
+ }
1044
+ catch {
1045
+ // Advisory. A docker failure here must not skip teardown or hide the original error.
1046
+ }
1047
+ // A signal during the await has already started teardown. Do not print logs for that cancel.
1048
+ if (this.shuttingDown) {
1049
+ return error;
1050
+ }
1051
+ if (text.length > 0) {
1052
+ anypoint_cli_command_lib_1.Logger.error(text);
1053
+ }
1054
+ return annotateComposeFailure(error, failingServices);
1055
+ }
796
1056
  shutdown(reason) {
797
1057
  var _a, _b, _c, _d, _e;
798
1058
  // Both signals may arrive, or a second Ctrl+C: re-entry would run a concurrent `compose down`.
@@ -822,4 +1082,23 @@ class WatchSession {
822
1082
  Promise.allSettled([composeTornDown, followerStopped]).finally(() => this.resolveSession());
823
1083
  }
824
1084
  }
1085
+ /** A plain `docker compose … exited with code` error. Signals and BaseError stay untouched. */
1086
+ function isDetachedComposeFailure(error) {
1087
+ return error instanceof Error &&
1088
+ !(error instanceof base_error_1.BaseError) &&
1089
+ !(0, run_local_1.isComposeSignalExit)(error) &&
1090
+ error.message.startsWith('docker compose ');
1091
+ }
1092
+ /** Keeps the original exit-code text and names the services `ps` reported, when it reported any. */
1093
+ function annotateComposeFailure(error, failingServices) {
1094
+ if (failingServices.length === 0 || !isDetachedComposeFailure(error)) {
1095
+ return error;
1096
+ }
1097
+ const note = `(${failingServices.join(', ')} failed)`;
1098
+ if (error.message.includes(note)) {
1099
+ return error;
1100
+ }
1101
+ error.message = `${error.message} ${note}`;
1102
+ return error;
1103
+ }
825
1104
  //# sourceMappingURL=run-local.js.map