nx 21.7.0-canary.20250930-e144408 → 21.7.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.

Potentially problematic release.


This version of nx might be problematic. Click here for more details.

Files changed (136) hide show
  1. package/README.md +1 -1
  2. package/bin/nx.js +0 -1
  3. package/generators.json +0 -6
  4. package/package.json +12 -12
  5. package/schemas/nx-schema.json +1 -15
  6. package/src/adapter/ngcli-adapter.d.ts.map +1 -1
  7. package/src/adapter/ngcli-adapter.js +8 -21
  8. package/src/command-line/format/format.js +1 -5
  9. package/src/command-line/graph/graph.d.ts.map +1 -1
  10. package/src/command-line/graph/graph.js +14 -37
  11. package/src/command-line/init/command-object.js +0 -6
  12. package/src/command-line/init/init-v2.d.ts +0 -2
  13. package/src/command-line/init/init-v2.d.ts.map +1 -1
  14. package/src/command-line/init/init-v2.js +0 -20
  15. package/src/command-line/migrate/command-object.js +1 -1
  16. package/src/command-line/migrate/migrate.d.ts +2 -3
  17. package/src/command-line/migrate/migrate.d.ts.map +1 -1
  18. package/src/command-line/migrate/migrate.js +7 -37
  19. package/src/command-line/nx-cloud/fix-ci/command-object.d.ts.map +1 -1
  20. package/src/command-line/nx-cloud/fix-ci/command-object.js +1 -4
  21. package/src/command-line/nx-cloud/login/command-object.d.ts.map +1 -1
  22. package/src/command-line/nx-cloud/login/command-object.js +1 -4
  23. package/src/command-line/nx-cloud/logout/command-object.d.ts.map +1 -1
  24. package/src/command-line/nx-cloud/logout/command-object.js +1 -4
  25. package/src/command-line/nx-cloud/record/command-object.d.ts.map +1 -1
  26. package/src/command-line/nx-cloud/record/command-object.js +1 -4
  27. package/src/command-line/nx-cloud/start-ci-run/command-object.d.ts.map +1 -1
  28. package/src/command-line/nx-cloud/start-ci-run/command-object.js +1 -4
  29. package/src/command-line/nx-commands.d.ts.map +1 -1
  30. package/src/command-line/nx-commands.js +15 -17
  31. package/src/command-line/release/config/config.d.ts.map +1 -1
  32. package/src/command-line/release/config/config.js +0 -3
  33. package/src/command-line/release/publish.d.ts.map +1 -1
  34. package/src/command-line/release/publish.js +0 -8
  35. package/src/command-line/release/version/release-group-processor.d.ts +2 -1
  36. package/src/command-line/release/version/release-group-processor.d.ts.map +1 -1
  37. package/src/command-line/release/version/release-group-processor.js +50 -13
  38. package/src/command-line/run/run-one.d.ts.map +1 -1
  39. package/src/command-line/run/run-one.js +9 -9
  40. package/src/config/misc-interfaces.d.ts +0 -1
  41. package/src/config/misc-interfaces.d.ts.map +1 -1
  42. package/src/config/nx-json.d.ts +0 -9
  43. package/src/config/nx-json.d.ts.map +1 -1
  44. package/src/config/workspace-json-project-json.d.ts +1 -7
  45. package/src/config/workspace-json-project-json.d.ts.map +1 -1
  46. package/src/core/graph/index.html +2 -4
  47. package/src/core/graph/main.js +1 -1
  48. package/src/core/graph/styles.css +1 -1
  49. package/src/core/graph/styles.js +1 -1
  50. package/src/daemon/client/client.d.ts.map +1 -1
  51. package/src/daemon/client/client.js +5 -8
  52. package/src/daemon/server/server.js +1 -1
  53. package/src/daemon/server/shutdown-utils.d.ts.map +1 -1
  54. package/src/daemon/server/shutdown-utils.js +2 -6
  55. package/src/devkit-internals.d.ts +1 -1
  56. package/src/devkit-internals.d.ts.map +1 -1
  57. package/src/devkit-internals.js +1 -2
  58. package/src/executors/run-script/run-script.impl.d.ts.map +1 -1
  59. package/src/executors/run-script/run-script.impl.js +8 -33
  60. package/src/hasher/hash-task.js +1 -1
  61. package/src/native/index.d.ts +0 -15
  62. package/src/native/native-bindings.js +0 -4
  63. package/src/native/nx.wasi.cjs +45 -53
  64. package/src/native/nx.wasm32-wasi.wasm +0 -0
  65. package/src/nx-cloud/generators/connect-to-nx-cloud/connect-to-nx-cloud.d.ts.map +1 -1
  66. package/src/nx-cloud/generators/connect-to-nx-cloud/connect-to-nx-cloud.js +4 -5
  67. package/src/plugins/js/lock-file/npm-parser.d.ts.map +1 -1
  68. package/src/plugins/js/lock-file/npm-parser.js +1 -4
  69. package/src/plugins/js/project-graph/build-dependencies/explicit-package-json-dependencies.js +7 -7
  70. package/src/plugins/js/project-graph/build-dependencies/target-project-locator.d.ts +1 -1
  71. package/src/plugins/js/project-graph/build-dependencies/target-project-locator.d.ts.map +1 -1
  72. package/src/plugins/js/project-graph/build-dependencies/target-project-locator.js +2 -33
  73. package/src/plugins/js/versions.d.ts +1 -1
  74. package/src/plugins/js/versions.js +1 -1
  75. package/src/plugins/package-json/create-nodes.d.ts.map +1 -1
  76. package/src/plugins/package-json/create-nodes.js +3 -2
  77. package/src/project-graph/build-project-graph.d.ts.map +1 -1
  78. package/src/project-graph/build-project-graph.js +21 -28
  79. package/src/project-graph/nx-deps-cache.d.ts +3 -4
  80. package/src/project-graph/nx-deps-cache.d.ts.map +1 -1
  81. package/src/project-graph/nx-deps-cache.js +2 -7
  82. package/src/project-graph/plugins/loaded-nx-plugin.d.ts.map +1 -1
  83. package/src/project-graph/plugins/public-api.d.ts +0 -4
  84. package/src/project-graph/plugins/public-api.d.ts.map +1 -1
  85. package/src/project-graph/utils/project-configuration-utils.d.ts.map +1 -1
  86. package/src/project-graph/utils/project-configuration-utils.js +6 -5
  87. package/src/tasks-runner/create-task-graph.d.ts.map +1 -1
  88. package/src/tasks-runner/create-task-graph.js +3 -17
  89. package/src/tasks-runner/fork.js +5 -31
  90. package/src/tasks-runner/life-cycle.d.ts.map +1 -1
  91. package/src/tasks-runner/life-cycles/task-history-life-cycle.d.ts.map +1 -1
  92. package/src/tasks-runner/life-cycles/task-history-life-cycle.js +4 -3
  93. package/src/tasks-runner/run-command.d.ts.map +1 -1
  94. package/src/tasks-runner/run-command.js +9 -19
  95. package/src/tasks-runner/task-orchestrator.d.ts.map +1 -1
  96. package/src/tasks-runner/task-orchestrator.js +5 -8
  97. package/src/tasks-runner/utils.d.ts.map +1 -1
  98. package/src/tasks-runner/utils.js +1 -3
  99. package/src/utils/nx-console-prompt.d.ts.map +1 -1
  100. package/src/utils/nx-console-prompt.js +0 -8
  101. package/src/utils/package-json.d.ts +0 -4
  102. package/src/utils/package-json.d.ts.map +1 -1
  103. package/src/utils/package-json.js +1 -52
  104. package/src/utils/package-manager.d.ts +1 -6
  105. package/src/utils/package-manager.d.ts.map +1 -1
  106. package/src/utils/package-manager.js +4 -15
  107. package/src/utils/split-target.d.ts.map +1 -1
  108. package/src/utils/split-target.js +6 -46
  109. package/src/utils/task-history.js +1 -1
  110. package/telemetry.js +198 -0
  111. package/src/ai/constants.d.ts +0 -15
  112. package/src/ai/constants.d.ts.map +0 -1
  113. package/src/ai/constants.js +0 -53
  114. package/src/ai/set-up-ai-agents/get-agent-rules.d.ts +0 -2
  115. package/src/ai/set-up-ai-agents/get-agent-rules.d.ts.map +0 -1
  116. package/src/ai/set-up-ai-agents/get-agent-rules.js +0 -26
  117. package/src/ai/set-up-ai-agents/schema.d.ts +0 -9
  118. package/src/ai/set-up-ai-agents/schema.json +0 -34
  119. package/src/ai/set-up-ai-agents/set-up-ai-agents.d.ts +0 -11
  120. package/src/ai/set-up-ai-agents/set-up-ai-agents.d.ts.map +0 -1
  121. package/src/ai/set-up-ai-agents/set-up-ai-agents.js +0 -213
  122. package/src/ai/utils.d.ts +0 -20
  123. package/src/ai/utils.d.ts.map +0 -1
  124. package/src/ai/utils.js +0 -187
  125. package/src/command-line/configure-ai-agents/command-object.d.ts +0 -9
  126. package/src/command-line/configure-ai-agents/command-object.d.ts.map +0 -1
  127. package/src/command-line/configure-ai-agents/command-object.js +0 -32
  128. package/src/command-line/configure-ai-agents/configure-ai-agents.d.ts +0 -4
  129. package/src/command-line/configure-ai-agents/configure-ai-agents.d.ts.map +0 -1
  130. package/src/command-line/configure-ai-agents/configure-ai-agents.js +0 -231
  131. package/src/command-line/init/ai-agent-prompts.d.ts +0 -3
  132. package/src/command-line/init/ai-agent-prompts.d.ts.map +0 -1
  133. package/src/command-line/init/ai-agent-prompts.js +0 -28
  134. package/src/utils/provenance.d.ts +0 -48
  135. package/src/utils/provenance.d.ts.map +0 -1
  136. package/src/utils/provenance.js +0 -84
package/src/ai/utils.js DELETED
@@ -1,187 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.agentDisplayMap = exports.supportedAgents = void 0;
4
- exports.getAgentConfigurations = getAgentConfigurations;
5
- exports.configureAgents = configureAgents;
6
- const fs_1 = require("fs");
7
- const path_1 = require("path");
8
- const configuration_1 = require("../config/configuration");
9
- const tree_1 = require("../generators/tree");
10
- const native_1 = require("../native");
11
- const fileutils_1 = require("../utils/fileutils");
12
- const nx_cloud_utils_1 = require("../utils/nx-cloud-utils");
13
- const output_1 = require("../utils/output");
14
- const constants_1 = require("./constants");
15
- const set_up_ai_agents_1 = require("./set-up-ai-agents/set-up-ai-agents");
16
- // when adding new agents, be sure to also update the list in
17
- // packages/create-nx-workspace/src/create-workspace-options.ts
18
- exports.supportedAgents = [
19
- 'claude',
20
- 'codex',
21
- 'copilot',
22
- 'cursor',
23
- 'gemini',
24
- ];
25
- exports.agentDisplayMap = {
26
- claude: 'Claude Code',
27
- gemini: 'Gemini',
28
- codex: 'OpenAI Codex',
29
- copilot: 'GitHub Copilot for VSCode',
30
- cursor: 'Cursor',
31
- };
32
- async function getAgentConfigurations(agentsToConsider, workspaceRoot) {
33
- const nonConfiguredAgents = [];
34
- const partiallyConfiguredAgents = [];
35
- const fullyConfiguredAgents = [];
36
- const disabledAgents = [];
37
- const agentConfigurations = new Map();
38
- for (const agent of agentsToConsider) {
39
- const configured = await getAgentConfiguration(agent, workspaceRoot);
40
- if (configured.disabled) {
41
- disabledAgents.push(agent);
42
- continue;
43
- }
44
- agentConfigurations.set(agent, configured);
45
- if (configured.mcp && configured.rules) {
46
- fullyConfiguredAgents.push(agent);
47
- }
48
- else if (!configured.mcp && !configured.rules) {
49
- nonConfiguredAgents.push(agent);
50
- }
51
- else {
52
- partiallyConfiguredAgents.push(agent);
53
- }
54
- }
55
- return {
56
- nonConfiguredAgents,
57
- partiallyConfiguredAgents,
58
- fullyConfiguredAgents,
59
- disabledAgents,
60
- agentConfigurations,
61
- };
62
- }
63
- async function getAgentConfiguration(agent, workspaceRoot) {
64
- let agentConfiguration;
65
- switch (agent) {
66
- case 'claude': {
67
- const mcpPath = (0, constants_1.claudeMcpPath)(workspaceRoot);
68
- let mcpConfigured;
69
- try {
70
- const mcpContents = (0, fileutils_1.readJsonFile)(mcpPath);
71
- mcpConfigured = !!mcpContents?.['mcpServers']?.['nx-mcp'];
72
- }
73
- catch {
74
- mcpConfigured = false;
75
- }
76
- const rulesPath = (0, constants_1.claudeMdPath)(workspaceRoot);
77
- const rulesExists = (0, fs_1.existsSync)(rulesPath);
78
- agentConfiguration = {
79
- rules: rulesExists,
80
- mcp: mcpConfigured,
81
- rulesPath: rulesPath,
82
- mcpPath: mcpPath,
83
- };
84
- break;
85
- }
86
- case 'gemini': {
87
- const geminiRulePath = (0, constants_1.geminiMdPath)(workspaceRoot);
88
- const geminiMdExists = (0, fs_1.existsSync)(geminiRulePath);
89
- const settingsPath = (0, constants_1.geminiSettingsPath)(workspaceRoot);
90
- let mcpConfigured;
91
- const geminiSettings = (0, constants_1.parseGeminiSettings)(workspaceRoot);
92
- const customContextFilePath = geminiSettings?.contextFileName;
93
- const customContextFilePathExists = customContextFilePath
94
- ? (0, fs_1.existsSync)((0, path_1.resolve)(workspaceRoot, customContextFilePath))
95
- : false;
96
- mcpConfigured = geminiSettings?.['mcpServers']?.['nx-mcp'];
97
- agentConfiguration = {
98
- rules: (!customContextFilePath && geminiMdExists) ||
99
- (customContextFilePath && customContextFilePathExists),
100
- mcp: mcpConfigured,
101
- rulesPath: customContextFilePath ?? geminiRulePath,
102
- mcpPath: settingsPath,
103
- };
104
- break;
105
- }
106
- case 'copilot': {
107
- const rulesPath = (0, constants_1.agentsMdPath)(workspaceRoot);
108
- const hasInstalledVSCode = (0, native_1.isEditorInstalled)(0 /* SupportedEditor.VSCode */);
109
- const hasInstalledVSCodeInsiders = (0, native_1.isEditorInstalled)(1 /* SupportedEditor.VSCodeInsiders */);
110
- const hasInstalledNxConsoleForVSCode = hasInstalledVSCode &&
111
- !(0, native_1.canInstallNxConsoleForEditor)(0 /* SupportedEditor.VSCode */);
112
- const hasInstalledNxConsoleForVSCodeInsiders = hasInstalledVSCodeInsiders &&
113
- !(0, native_1.canInstallNxConsoleForEditor)(1 /* SupportedEditor.VSCodeInsiders */);
114
- const agentsMdExists = (0, fs_1.existsSync)(rulesPath);
115
- agentConfiguration = {
116
- mcp: hasInstalledNxConsoleForVSCode ||
117
- hasInstalledNxConsoleForVSCodeInsiders,
118
- rules: agentsMdExists,
119
- rulesPath,
120
- mcpPath: null,
121
- disabled: !hasInstalledVSCode && !hasInstalledVSCodeInsiders,
122
- };
123
- break;
124
- }
125
- case 'cursor': {
126
- const rulesPath = (0, constants_1.agentsMdPath)(workspaceRoot);
127
- const hasInstalledCursor = (0, native_1.isEditorInstalled)(2 /* SupportedEditor.Cursor */);
128
- const hasInstalledNxConsole = !(0, native_1.canInstallNxConsoleForEditor)(2 /* SupportedEditor.Cursor */);
129
- const agentsMdExists = (0, fs_1.existsSync)(rulesPath);
130
- agentConfiguration = {
131
- mcp: hasInstalledCursor ? hasInstalledNxConsole : false,
132
- rules: agentsMdExists,
133
- rulesPath,
134
- mcpPath: null,
135
- disabled: !hasInstalledCursor,
136
- };
137
- break;
138
- }
139
- case 'codex': {
140
- const rulesPath = (0, constants_1.agentsMdPath)(workspaceRoot);
141
- const agentsMdExists = (0, fs_1.existsSync)(rulesPath);
142
- let mcpConfigured;
143
- if ((0, fs_1.existsSync)(constants_1.codexConfigTomlPath)) {
144
- const tomlContents = (0, fs_1.readFileSync)(constants_1.codexConfigTomlPath, 'utf-8');
145
- mcpConfigured = tomlContents.includes(constants_1.nxMcpTomlHeader);
146
- }
147
- else {
148
- mcpConfigured = false;
149
- }
150
- agentConfiguration = {
151
- mcp: mcpConfigured,
152
- rules: agentsMdExists,
153
- rulesPath,
154
- mcpPath: constants_1.codexConfigTomlPath,
155
- };
156
- break;
157
- }
158
- }
159
- return {
160
- ...agentConfiguration,
161
- outdated: await isAgentOutdated(agent, workspaceRoot),
162
- };
163
- }
164
- async function isAgentOutdated(agent, workspaceRoot) {
165
- const tree = new tree_1.FsTree(workspaceRoot, false);
166
- const callback = await (0, set_up_ai_agents_1.default)(tree, {
167
- directory: '.',
168
- agents: [agent],
169
- writeNxCloudRules: (0, nx_cloud_utils_1.isNxCloudUsed)((0, configuration_1.readNxJson)()),
170
- }, true);
171
- const modificationResults = await callback(true);
172
- return (tree.listChanges().length > 0 || modificationResults.messages.length > 0);
173
- }
174
- async function configureAgents(agents, workspaceRoot, useLatest) {
175
- const writeNxCloudRules = (0, nx_cloud_utils_1.isNxCloudUsed)((0, configuration_1.readNxJson)());
176
- const tree = new tree_1.FsTree(workspaceRoot, false);
177
- const callback = await (0, set_up_ai_agents_1.default)(tree, {
178
- directory: '.',
179
- agents,
180
- writeNxCloudRules,
181
- }, !useLatest);
182
- // changes that are out of scope for the generator itself because they do more than modify the tree
183
- (0, tree_1.flushChanges)(workspaceRoot, tree.listChanges());
184
- const modificationResults = await callback();
185
- modificationResults.messages.forEach((message) => output_1.output.log(message));
186
- modificationResults.errors.forEach((error) => output_1.output.error(error));
187
- }
@@ -1,9 +0,0 @@
1
- import { CommandModule } from 'yargs';
2
- export interface ConfigureAiAgentsOptions {
3
- agents?: string[];
4
- interactive?: boolean;
5
- verbose?: boolean;
6
- check?: boolean;
7
- }
8
- export declare const yargsConfigureAiAgentsCommand: CommandModule<{}, ConfigureAiAgentsOptions>;
9
- //# sourceMappingURL=command-object.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"command-object.d.ts","sourceRoot":"","sources":["../../../../../../packages/nx/src/command-line/configure-ai-agents/command-object.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAGtC,MAAM,WAAW,wBAAwB;IACvC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,eAAO,MAAM,6BAA6B,EAAE,aAAa,CACvD,EAAE,EACF,wBAAwB,CA6CzB,CAAC"}
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.yargsConfigureAiAgentsCommand = void 0;
4
- const shared_options_1 = require("../yargs-utils/shared-options");
5
- exports.yargsConfigureAiAgentsCommand = {
6
- command: 'configure-ai-agents',
7
- describe: 'Configure and update AI agent configurations for your workspace.',
8
- builder: (yargs) => (0, shared_options_1.withVerbose)(yargs)
9
- .option('agents', {
10
- type: 'array',
11
- string: true,
12
- description: 'List of AI agents to set up.',
13
- choices: ['claude', 'codex', 'copilot', 'cursor', 'gemini'],
14
- })
15
- .option('interactive', {
16
- type: 'boolean',
17
- description: 'When false disables interactive input prompts for options.',
18
- default: true,
19
- })
20
- .option('check', {
21
- type: 'boolean',
22
- description: 'Check if any configured agents are out of date and need to be updated. Does not make any changes.',
23
- default: false,
24
- })
25
- .example('$0 configure-ai-agents', 'Interactively select AI agents to update and configure')
26
- .example('$0 configure-ai-agents --agents claude gemini', 'Prompts for updates and and configuration of Claude and Gemini AI agents')
27
- .example('$0 configure-ai-agents --check', 'Checks if any configured agents are out of date and need to be updated')
28
- .example('$0 configure-ai-agents --agents claude gemini --no-interactive', 'Configures and updates Claude and Gemini AI agents without prompts'),
29
- handler: async (args) => {
30
- await (await Promise.resolve().then(() => require('./configure-ai-agents'))).configureAiAgentsHandler(args);
31
- },
32
- };
@@ -1,4 +0,0 @@
1
- import { ConfigureAiAgentsOptions } from './command-object';
2
- export declare function configureAiAgentsHandler(args: ConfigureAiAgentsOptions, inner?: boolean): Promise<void>;
3
- export declare function configureAiAgentsHandlerImpl(options: ConfigureAiAgentsOptions): Promise<void>;
4
- //# sourceMappingURL=configure-ai-agents.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"configure-ai-agents.d.ts","sourceRoot":"","sources":["../../../../../../packages/nx/src/command-line/configure-ai-agents/configure-ai-agents.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAI5D,wBAAsB,wBAAwB,CAC5C,IAAI,EAAE,wBAAwB,EAC9B,KAAK,UAAQ,GACZ,OAAO,CAAC,IAAI,CAAC,CA+Bf;AAED,wBAAsB,4BAA4B,CAChD,OAAO,EAAE,wBAAwB,GAChC,OAAO,CAAC,IAAI,CAAC,CAgNf"}
@@ -1,231 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.configureAiAgentsHandler = configureAiAgentsHandler;
4
- exports.configureAiAgentsHandlerImpl = configureAiAgentsHandlerImpl;
5
- const enquirer_1 = require("enquirer");
6
- const output_1 = require("../../utils/output");
7
- const provenance_1 = require("../../utils/provenance");
8
- const chalk = require("chalk");
9
- const utils_1 = require("../../ai/utils");
10
- const devkit_internals_1 = require("../../devkit-internals");
11
- const workspace_root_1 = require("../../utils/workspace-root");
12
- const ora = require("ora");
13
- const path_1 = require("path");
14
- async function configureAiAgentsHandler(args, inner = false) {
15
- // Use environment variable to force local execution
16
- if (process.env.NX_AI_FILES_USE_LOCAL === 'true' || inner) {
17
- return await configureAiAgentsHandlerImpl(args);
18
- }
19
- let cleanup;
20
- try {
21
- await (0, provenance_1.ensurePackageHasProvenance)('nx', 'latest');
22
- const packageInstallResults = (0, devkit_internals_1.installPackageToTmp)('nx', 'latest');
23
- cleanup = packageInstallResults.cleanup;
24
- let modulePath = require.resolve('nx/src/command-line/configure-ai-agents/configure-ai-agents.js', { paths: [packageInstallResults.tempDir] });
25
- const module = await Promise.resolve(`${modulePath}`).then(s => require(s));
26
- const configureAiAgentsResult = await module.configureAiAgentsHandler(args, true);
27
- cleanup();
28
- return configureAiAgentsResult;
29
- }
30
- catch (error) {
31
- if (cleanup) {
32
- cleanup();
33
- }
34
- // Fall back to local implementation
35
- return configureAiAgentsHandlerImpl(args);
36
- }
37
- }
38
- async function configureAiAgentsHandlerImpl(options) {
39
- const normalizedOptions = normalizeOptions(options);
40
- const { nonConfiguredAgents, partiallyConfiguredAgents, fullyConfiguredAgents, disabledAgents, agentConfigurations, } = await (0, utils_1.getAgentConfigurations)(normalizedOptions.agents, workspace_root_1.workspaceRoot);
41
- if (disabledAgents.length > 0) {
42
- const commandNames = disabledAgents.map((a) => {
43
- if (a === 'cursor')
44
- return '"cursor"';
45
- if (a === 'copilot')
46
- return '"code"/"code-insiders"';
47
- return a;
48
- });
49
- const title = commandNames.length === 1
50
- ? `${commandNames[0]} command not available.`
51
- : `CLI commands ${commandNames
52
- .map((c) => `${c}`)
53
- .join('/')} not available.`;
54
- output_1.output.log({
55
- title,
56
- bodyLines: [
57
- chalk.dim('To manually configure the Nx MCP in your editor, install Nx Console (https://nx.dev/getting-started/editor-setup)'),
58
- ],
59
- });
60
- }
61
- if (normalizedOptions.agents.filter((a) => !disabledAgents.includes(a))
62
- .length === 0) {
63
- output_1.output.error({
64
- title: 'Please select at least one AI agent to configure.',
65
- });
66
- process.exit(1);
67
- }
68
- if (options.check) {
69
- if (fullyConfiguredAgents.length === 0) {
70
- output_1.output.log({
71
- title: 'No AI agents are configured',
72
- bodyLines: [
73
- 'You can configure AI agents by running `nx configure-ai-agents`.',
74
- ],
75
- });
76
- process.exit(0);
77
- }
78
- const outOfDateAgents = fullyConfiguredAgents.filter((a) => agentConfigurations.get(a)?.outdated);
79
- if (outOfDateAgents.length === 0) {
80
- output_1.output.success({
81
- title: 'All configured AI agents are up to date',
82
- bodyLines: fullyConfiguredAgents.map((a) => `- ${utils_1.agentDisplayMap[a]}`),
83
- });
84
- process.exit(0);
85
- }
86
- else {
87
- output_1.output.log({
88
- title: 'The following AI agents are out of date:',
89
- bodyLines: [
90
- ...outOfDateAgents.map((a) => {
91
- const rulesPath = agentConfigurations.get(a).rulesPath;
92
- const displayPath = rulesPath.startsWith(workspace_root_1.workspaceRoot)
93
- ? (0, path_1.relative)(workspace_root_1.workspaceRoot, rulesPath)
94
- : rulesPath;
95
- return `- ${utils_1.agentDisplayMap[a]} (${displayPath})`;
96
- }),
97
- '',
98
- 'You can update them by running `nx configure-ai-agents`.',
99
- ],
100
- });
101
- process.exit(1);
102
- }
103
- }
104
- // first, prompt for partially configured agents and out of date agents
105
- const agentsToUpdate = [];
106
- partiallyConfiguredAgents.forEach((a) => {
107
- agentsToUpdate.push(getAgentChoiceForPrompt(a, true, false));
108
- });
109
- for (const a of fullyConfiguredAgents) {
110
- if (agentConfigurations.get(a).outdated) {
111
- agentsToUpdate.push(getAgentChoiceForPrompt(a, false, true));
112
- }
113
- }
114
- let updateResult = [];
115
- let updateSucceeded = true;
116
- if (agentsToUpdate.length > 0) {
117
- if (options.interactive !== false) {
118
- try {
119
- updateResult = (await (0, enquirer_1.prompt)({
120
- type: 'multiselect',
121
- name: 'agents',
122
- message: 'The following agents are not configured completely or are out of date. Which would you like to update?',
123
- choices: agentsToUpdate,
124
- initial: agentsToUpdate.map((_, i) => i),
125
- required: true,
126
- })).agents;
127
- }
128
- catch {
129
- process.exit(1);
130
- }
131
- }
132
- else {
133
- // in non-interactive mode, update all
134
- updateResult = agentsToUpdate.map((a) => a.name);
135
- }
136
- if (updateResult?.length > 0) {
137
- const updateSpinner = ora(`Updating agent configurations...`).start();
138
- try {
139
- await (0, utils_1.configureAgents)(updateResult, workspace_root_1.workspaceRoot, false);
140
- updateSpinner.succeed('Agent configurations updated.');
141
- }
142
- catch {
143
- updateSpinner.fail('Failed to update agent configurations.');
144
- updateSucceeded = false;
145
- }
146
- }
147
- }
148
- // then prompt for non-configured agents
149
- if (nonConfiguredAgents.length === 0) {
150
- const usingAllAgents = normalizedOptions.agents.length === utils_1.supportedAgents.length;
151
- const configuredOrUpdatedAgents = [
152
- ...new Set([
153
- ...fullyConfiguredAgents,
154
- ...(updateSucceeded ? updateResult : []),
155
- ]),
156
- ];
157
- output_1.output.success({
158
- title: `No new agents to configure. All ${!usingAllAgents ? 'selected' : 'supported'} AI agents are already configured:`,
159
- bodyLines: configuredOrUpdatedAgents.map((agent) => `- ${utils_1.agentDisplayMap[agent]}`),
160
- });
161
- process.exit(0);
162
- }
163
- let configurationResult;
164
- if (options.interactive !== false) {
165
- try {
166
- configurationResult = (await (0, enquirer_1.prompt)({
167
- type: 'multiselect',
168
- name: 'agents',
169
- message: 'Which AI agents would you like to configure? (space to select, enter to confirm)',
170
- choices: nonConfiguredAgents.map((a) => getAgentChoiceForPrompt(a, false, false)),
171
- required: true,
172
- })).agents;
173
- }
174
- catch {
175
- process.exit(1);
176
- }
177
- }
178
- else {
179
- // in non-interactive mode, configure all
180
- configurationResult = nonConfiguredAgents;
181
- }
182
- if (configurationResult?.length === 0) {
183
- output_1.output.log({
184
- title: 'No agents selected',
185
- });
186
- process.exit(0);
187
- }
188
- try {
189
- await (0, utils_1.configureAgents)(configurationResult, workspace_root_1.workspaceRoot, false);
190
- const configuredOrUpdatedAgents = [
191
- ...new Set([
192
- ...fullyConfiguredAgents,
193
- ...(updateSucceeded ? updateResult : []),
194
- ...configurationResult,
195
- ]),
196
- ];
197
- output_1.output.success({
198
- title: 'AI agents set up successfully. Configured agents:',
199
- bodyLines: configuredOrUpdatedAgents.map((agent) => `- ${utils_1.agentDisplayMap[agent]}`),
200
- });
201
- return;
202
- }
203
- catch (e) {
204
- output_1.output.error({
205
- title: 'Failed to set up AI agents',
206
- bodyLines: [e.message],
207
- });
208
- process.exit(1);
209
- }
210
- }
211
- function getAgentChoiceForPrompt(agent, partiallyConfigured, outdated) {
212
- let message = utils_1.agentDisplayMap[agent];
213
- if (partiallyConfigured) {
214
- message += ' (partially configured)';
215
- }
216
- else if (outdated) {
217
- message += ' (out of date)';
218
- }
219
- return {
220
- name: agent,
221
- message,
222
- };
223
- }
224
- function normalizeOptions(options) {
225
- const agents = (options.agents ?? utils_1.supportedAgents).filter((a) => utils_1.supportedAgents.includes(a));
226
- return {
227
- ...options,
228
- agents,
229
- check: options.check ?? false,
230
- };
231
- }
@@ -1,3 +0,0 @@
1
- import { Agent } from '../../ai/utils';
2
- export declare function determineAiAgents(aiAgents?: Agent[], interactive?: boolean): Promise<Agent[]>;
3
- //# sourceMappingURL=ai-agent-prompts.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ai-agent-prompts.d.ts","sourceRoot":"","sources":["../../../../../../packages/nx/src/command-line/init/ai-agent-prompts.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAoC,MAAM,gBAAgB,CAAC;AAEzE,wBAAsB,iBAAiB,CACrC,QAAQ,CAAC,EAAE,KAAK,EAAE,EAClB,WAAW,CAAC,EAAE,OAAO,GACpB,OAAO,CAAC,KAAK,EAAE,CAAC,CASlB"}
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.determineAiAgents = determineAiAgents;
4
- const enquirer_1 = require("enquirer");
5
- const is_ci_1 = require("../../utils/is-ci");
6
- const utils_1 = require("../../ai/utils");
7
- async function determineAiAgents(aiAgents, interactive) {
8
- if (interactive === false || (0, is_ci_1.isCI)()) {
9
- return aiAgents ?? [];
10
- }
11
- if (aiAgents) {
12
- return aiAgents;
13
- }
14
- return await aiAgentsPrompt();
15
- }
16
- async function aiAgentsPrompt() {
17
- return (await (0, enquirer_1.prompt)([
18
- {
19
- name: 'agents',
20
- message: 'Which AI agents would you like to set up? (space to select, enter to confirm)',
21
- type: 'multiselect',
22
- choices: utils_1.supportedAgents.map((a) => ({
23
- name: a,
24
- message: utils_1.agentDisplayMap[a],
25
- })),
26
- },
27
- ])).agents;
28
- }
@@ -1,48 +0,0 @@
1
- export declare function ensurePackageHasProvenance(packageName: string, packageVersion: string): Promise<void>;
2
- export declare class ProvenanceError extends Error {
3
- constructor(packageName: string, packageVersion: string, error?: string);
4
- }
5
- export declare function getNxPackageGroup(): string[];
6
- export type DecodedAttestationPayload = {
7
- _type: 'https://in-toto.io/Statement/v1';
8
- subject: unknown[];
9
- predicateType: 'https://slsa.dev/provenance/v1';
10
- predicate: {
11
- buildDefinition: {
12
- buildType: string;
13
- externalParameters: Record<string, any>;
14
- internalParameters?: Record<string, any>;
15
- resolvedDependencies?: ResourceDescriptor[];
16
- };
17
- runDetails: {
18
- builder: {
19
- id: string;
20
- builderDependencies?: ResourceDescriptor[];
21
- version?: Record<string, string>;
22
- };
23
- metadata?: {
24
- invocationId?: string;
25
- startedOn?: string;
26
- finishedOn?: string;
27
- };
28
- byproducts?: ResourceDescriptor[];
29
- };
30
- };
31
- };
32
- export interface ResourceDescriptor {
33
- uri?: string;
34
- digest?: {
35
- sha256?: string;
36
- sha512?: string;
37
- gitCommit?: string;
38
- [key: string]: string | undefined;
39
- };
40
- name?: string;
41
- downloadLocation?: string;
42
- mediaType?: string;
43
- content?: string;
44
- annotations?: {
45
- [key: string]: any;
46
- };
47
- }
48
- //# sourceMappingURL=provenance.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"provenance.d.ts","sourceRoot":"","sources":["../../../../../packages/nx/src/utils/provenance.ts"],"names":[],"mappings":"AAaA,wBAAsB,0BAA0B,CAC9C,WAAW,EAAE,MAAM,EACnB,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,IAAI,CAAC,CA8Gf;AAED,qBAAa,eAAgB,SAAQ,KAAK;gBAC5B,WAAW,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM;CAOxE;AAED,wBAAgB,iBAAiB,IAAI,MAAM,EAAE,CAa5C;AAoBD,MAAM,MAAM,yBAAyB,GAAG;IACtC,KAAK,EAAE,iCAAiC,CAAC;IACzC,OAAO,EAAE,OAAO,EAAE,CAAC;IACnB,aAAa,EAAE,gCAAgC,CAAC;IAChD,SAAS,EAAE;QACT,eAAe,EAAE;YACf,SAAS,EAAE,MAAM,CAAC;YAClB,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;YACxC,kBAAkB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;YACzC,oBAAoB,CAAC,EAAE,kBAAkB,EAAE,CAAC;SAC7C,CAAC;QACF,UAAU,EAAE;YACV,OAAO,EAAE;gBACP,EAAE,EAAE,MAAM,CAAC;gBACX,mBAAmB,CAAC,EAAE,kBAAkB,EAAE,CAAC;gBAC3C,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;aAClC,CAAC;YACF,QAAQ,CAAC,EAAE;gBACT,YAAY,CAAC,EAAE,MAAM,CAAC;gBACtB,SAAS,CAAC,EAAE,MAAM,CAAC;gBACnB,UAAU,CAAC,EAAE,MAAM,CAAC;aACrB,CAAC;YACF,UAAU,CAAC,EAAE,kBAAkB,EAAE,CAAC;SACnC,CAAC;KACH,CAAC;CACH,CAAC;AAEF,MAAM,WAAW,kBAAkB;IACjC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE;QACP,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;KACnC,CAAC;IACF,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE;QACZ,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,CAAC;CACH"}
@@ -1,84 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ProvenanceError = void 0;
4
- exports.ensurePackageHasProvenance = ensurePackageHasProvenance;
5
- exports.getNxPackageGroup = getNxPackageGroup;
6
- const child_process_1 = require("child_process");
7
- const path_1 = require("path");
8
- const util_1 = require("util");
9
- const fileutils_1 = require("./fileutils");
10
- /*
11
- * Verifies that the given npm package has provenance attestations
12
- * generated by the GitHub Actions workflow at .github/workflows/publish.yml
13
- * in the nrwl/nx repository.
14
- *
15
- * Will throw if the package does not have valid provenance.
16
- */
17
- async function ensurePackageHasProvenance(packageName, packageVersion) {
18
- // this is used for locally released versions without provenance
19
- // do not set this for other reasons or you might be exposed to security risks
20
- if (process.env.NX_SKIP_PROVENANCE_CHECK) {
21
- return;
22
- }
23
- const execAsync = (0, util_1.promisify)(child_process_1.exec);
24
- try {
25
- const result = await execAsync(`npm view ${packageName}@${packageVersion} --json --silent`, {
26
- timeout: 20000,
27
- });
28
- const npmViewResult = JSON.parse(result.stdout.trim());
29
- const attURL = npmViewResult.dist?.attestations?.url;
30
- if (!attURL)
31
- throw new ProvenanceError(packageName, packageVersion, 'No attestation URL found');
32
- const response = await fetch(attURL);
33
- if (!response.ok) {
34
- throw new ProvenanceError(packageName, packageVersion, `HTTP ${response.status}: ${response.statusText}`);
35
- }
36
- const attestations = (await response.json());
37
- const provenanceAttestation = attestations?.attestations?.find((a) => a.predicateType === 'https://slsa.dev/provenance/v1');
38
- const dsseEnvelopePayload = JSON.parse(Buffer.from(provenanceAttestation.bundle.dsseEnvelope.payload, 'base64').toString());
39
- const workflowParameters = dsseEnvelopePayload?.predicate?.buildDefinition?.externalParameters
40
- ?.workflow;
41
- // verify that provenance was actually generated from the right publishing workflow
42
- if (!workflowParameters) {
43
- throw new ProvenanceError(packageName, packageVersion, 'Missing workflow parameters in attestation');
44
- }
45
- if (workflowParameters.repository !== 'https://github.com/nrwl/nx') {
46
- throw new ProvenanceError(packageName, packageVersion, 'Repository does not match nrwl/nx');
47
- }
48
- if (workflowParameters.path !== '.github/workflows/publish.yml') {
49
- throw new ProvenanceError(packageName, packageVersion, 'Publishing workflow does not match .github/workflows/publish.yml');
50
- }
51
- if (workflowParameters.ref !== `refs/tags/${npmViewResult.version}`) {
52
- throw new ProvenanceError(packageName, packageVersion, `Version ref does not match refs/tags/${npmViewResult.version}`);
53
- }
54
- // verify that provenance was generated from the exact same artifact as the one we are installing
55
- const distSha = Buffer.from(npmViewResult.dist.integrity.replace('sha512-', ''), 'base64').toString('hex');
56
- const attestationSha = dsseEnvelopePayload.subject[0].digest.sha512;
57
- if (distSha !== attestationSha) {
58
- throw new ProvenanceError(packageName, packageVersion, 'Integrity hash does not match attestation hash');
59
- }
60
- return;
61
- }
62
- catch (error) {
63
- if (error instanceof ProvenanceError) {
64
- throw error;
65
- }
66
- throw new ProvenanceError(packageName, packageVersion, error.message || error);
67
- }
68
- }
69
- class ProvenanceError extends Error {
70
- constructor(packageName, packageVersion, error) {
71
- super(`An error occurred while checking the provenance of ${packageName}@${packageVersion}. This could indicate a security risk. Please double check https://www.npmjs.com/package/${packageName} to see if the package is published correctly or file an issue at https://github.com/nrwl/nx/issues. To disable this check at your own risk, you can set the NX_SKIP_PROVENANCE_CHECK environment variable to true. \n Error: ${error ?? ''}`);
72
- }
73
- }
74
- exports.ProvenanceError = ProvenanceError;
75
- function getNxPackageGroup() {
76
- const packageJsonPath = (0, path_1.join)(__dirname, '../../package.json');
77
- const packageJson = (0, fileutils_1.readJsonFile)(packageJsonPath);
78
- if (!packageJson['nx-migrations']?.packageGroup) {
79
- return ['nx'];
80
- }
81
- const packages = packageJson['nx-migrations'].packageGroup.filter((dep) => typeof dep === 'string' && dep.startsWith('@nx/'));
82
- packages.push('nx');
83
- return packages;
84
- }