-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
fix(cli): resolve non-interactive install defaults for directory and output_folder #1963
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jschulte
wants to merge
8
commits into
bmad-code-org:main
Choose a base branch
from
jschulte:fix/non-interactive-install-defaults
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+157
−17
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1cdc7f4
fix(cli): resolve non-interactive install defaults for directory and …
jschulte fe2cbe9
Merge branch 'main' into fix/non-interactive-install-defaults
jschulte ac04378
Merge remote-tracking branch 'upstream/main' into fix/non-interactive…
jschulte d2e7158
Merge branch 'fix/non-interactive-install-defaults' of github.com:jsc…
jschulte 7422d3a
fix(cli): address PR review feedback for non-interactive install defa…
jschulte 5c0dfd8
Merge branch 'main' into fix/non-interactive-install-defaults
jschulte 1571a3c
Merge branch 'main' into fix/non-interactive-install-defaults
jschulte 8927e20
fix(cli): extract core-config-defaults module and centralize fallback…
jschulte File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| const os = require('node:os'); | ||
| const fs = require('fs-extra'); | ||
| const yaml = require('yaml'); | ||
| const prompts = require('./prompts'); | ||
| const { getModulePath } = require('./project-root'); | ||
|
|
||
| let cachedCoreConfigDefaults = null; | ||
|
|
||
| function getFallbackUsername() { | ||
| let safeUsername; | ||
| try { | ||
| safeUsername = os.userInfo().username; | ||
| } catch { | ||
| safeUsername = process.env.USER || process.env.USERNAME || 'User'; | ||
| } | ||
|
|
||
| if (typeof safeUsername !== 'string' || safeUsername.trim() === '') { | ||
| return 'User'; | ||
| } | ||
|
|
||
| const normalizedUsername = safeUsername.trim(); | ||
| return normalizedUsername.charAt(0).toUpperCase() + normalizedUsername.slice(1); | ||
| } | ||
|
|
||
| function normalizeDefaultString(value, fallback) { | ||
| return typeof value === 'string' && value.trim() !== '' ? value.trim() : fallback; | ||
| } | ||
|
|
||
| function isMissingOrUnresolvedCoreConfigValue(value) { | ||
| return value == null || (typeof value === 'string' && (value.trim() === '' || /^\{[^}]+\}$/.test(value.trim()))); | ||
| } | ||
|
|
||
| function applyDefaultCoreConfig(coreConfig = {}, defaults = {}) { | ||
| const normalizedConfig = { ...coreConfig }; | ||
| let appliedDefaults = false; | ||
|
|
||
| for (const [key, value] of Object.entries(defaults)) { | ||
| if (isMissingOrUnresolvedCoreConfigValue(normalizedConfig[key])) { | ||
| normalizedConfig[key] = value; | ||
| appliedDefaults = true; | ||
| } | ||
| } | ||
|
|
||
| return { coreConfig: normalizedConfig, appliedDefaults }; | ||
| } | ||
|
|
||
| async function getDefaultCoreConfig() { | ||
| if (cachedCoreConfigDefaults) { | ||
| return { ...cachedCoreConfigDefaults }; | ||
| } | ||
|
|
||
| const fallbackDefaults = { | ||
| user_name: getFallbackUsername(), | ||
| communication_language: 'English', | ||
| document_output_language: 'English', | ||
| output_folder: '_bmad-output', | ||
| }; | ||
|
|
||
| try { | ||
| const moduleYamlPath = getModulePath('core', 'module.yaml'); | ||
| const moduleConfig = yaml.parse(await fs.readFile(moduleYamlPath, 'utf8')) || {}; | ||
|
|
||
| cachedCoreConfigDefaults = { | ||
| user_name: normalizeDefaultString(moduleConfig.user_name?.default, fallbackDefaults.user_name), | ||
| communication_language: normalizeDefaultString(moduleConfig.communication_language?.default, fallbackDefaults.communication_language), | ||
| document_output_language: normalizeDefaultString( | ||
| moduleConfig.document_output_language?.default, | ||
| fallbackDefaults.document_output_language, | ||
| ), | ||
| output_folder: normalizeDefaultString(moduleConfig.output_folder?.default, fallbackDefaults.output_folder), | ||
| }; | ||
| } catch (error) { | ||
| await prompts.log.warn(`Failed to load module.yaml, falling back to defaults: ${error.message}`); | ||
| cachedCoreConfigDefaults = fallbackDefaults; | ||
| } | ||
|
|
||
| return { ...cachedCoreConfigDefaults }; | ||
| } | ||
|
|
||
| function clearCoreConfigDefaultsCache() { | ||
| cachedCoreConfigDefaults = null; | ||
| } | ||
|
|
||
| module.exports = { | ||
| applyDefaultCoreConfig, | ||
| clearCoreConfigDefaultsCache, | ||
| getDefaultCoreConfig, | ||
| isMissingOrUnresolvedCoreConfigValue, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ const path = require('node:path'); | |
| const os = require('node:os'); | ||
| const fs = require('fs-extra'); | ||
| const { CLIUtils } = require('./cli-utils'); | ||
| const { applyDefaultCoreConfig, getDefaultCoreConfig: loadDefaultCoreConfig } = require('./core-config-defaults'); | ||
| const { CustomHandler } = require('../installers/lib/custom/handler'); | ||
| const { ExternalModuleManager } = require('../installers/lib/modules/external-manager'); | ||
| const prompts = require('./prompts'); | ||
|
|
@@ -47,6 +48,21 @@ class UI { | |
| } | ||
| confirmedDirectory = expandedDir; | ||
| await prompts.log.info(`Using directory from command-line: ${confirmedDirectory}`); | ||
| } else if (options.yes) { | ||
| // Default to current directory when --yes flag is set | ||
| let cwd; | ||
| try { | ||
| cwd = process.cwd(); | ||
| } catch (error) { | ||
| await prompts.log.error(`Failed to resolve current directory (--yes flag): ${error.message}`); | ||
| throw new Error(`Unable to determine current directory: ${error.message}`); | ||
| } | ||
| const validation = this.validateDirectorySync(cwd); | ||
| if (validation) { | ||
| throw new Error(`Invalid current directory: ${validation}`); | ||
| } | ||
| confirmedDirectory = cwd; | ||
| await prompts.log.info(`Using current directory (--yes flag): ${confirmedDirectory}`); | ||
| } else { | ||
| confirmedDirectory = await this.getConfirmedDirectory(); | ||
| } | ||
|
|
@@ -823,6 +839,14 @@ class UI { | |
| return { existingInstall, installedModuleIds, bmadDir }; | ||
| } | ||
|
|
||
| /** | ||
| * Get default core config values by reading from src/core/module.yaml | ||
| * @returns {Object} Default core config with user_name, communication_language, document_output_language, output_folder | ||
| */ | ||
| async getDefaultCoreConfig() { | ||
| return loadDefaultCoreConfig(); | ||
| } | ||
|
|
||
| /** | ||
| * Collect core configuration | ||
| * @param {string} directory - Installation directory | ||
|
|
@@ -866,27 +890,21 @@ class UI { | |
| (!options.userName || !options.communicationLanguage || !options.documentOutputLanguage || !options.outputFolder) | ||
| ) { | ||
| await configCollector.collectModuleConfig('core', directory, false, true); | ||
| } else if (options.yes) { | ||
| const defaults = await this.getDefaultCoreConfig(); | ||
| const normalizedConfig = applyDefaultCoreConfig(configCollector.collectedConfig.core, defaults); | ||
| configCollector.collectedConfig.core = normalizedConfig.coreConfig; | ||
| if (normalizedConfig.appliedDefaults) { | ||
| await prompts.log.info('Using default configuration (--yes flag)'); | ||
| } | ||
|
Comment on lines
+893
to
+899
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Backfill predicate still lets unresolved placeholders survive.
Proposed fix- for (const [key, value] of Object.entries(defaults)) {
- if (!configCollector.collectedConfig.core[key]) {
- configCollector.collectedConfig.core[key] = value;
- }
- }
+ const isMissingOrUnresolved = (v) =>
+ v == null ||
+ (typeof v === 'string' && (v.trim() === '' || /^\{[^}]+\}$/.test(v.trim())));
+
+ for (const [key, value] of Object.entries(defaults)) {
+ if (isMissingOrUnresolved(configCollector.collectedConfig.core[key])) {
+ configCollector.collectedConfig.core[key] = value;
+ }
+ }🤖 Prompt for AI Agents |
||
| } | ||
| } else if (options.yes) { | ||
| // Use all defaults when --yes flag is set | ||
| await configCollector.loadExistingConfig(directory); | ||
| const existingConfig = configCollector.collectedConfig.core || {}; | ||
|
|
||
| // If no existing config, use defaults | ||
| if (Object.keys(existingConfig).length === 0) { | ||
| let safeUsername; | ||
| try { | ||
| safeUsername = os.userInfo().username; | ||
| } catch { | ||
| safeUsername = process.env.USER || process.env.USERNAME || 'User'; | ||
| } | ||
| const defaultUsername = safeUsername.charAt(0).toUpperCase() + safeUsername.slice(1); | ||
| configCollector.collectedConfig.core = { | ||
| user_name: defaultUsername, | ||
| communication_language: 'English', | ||
| document_output_language: 'English', | ||
| output_folder: '_bmad-output', | ||
| }; | ||
| const defaults = await this.getDefaultCoreConfig(); | ||
| const normalizedConfig = applyDefaultCoreConfig(existingConfig, defaults); | ||
| configCollector.collectedConfig.core = normalizedConfig.coreConfig; | ||
| if (normalizedConfig.appliedDefaults) { | ||
| await prompts.log.info('Using default configuration (--yes flag)'); | ||
| } | ||
|
Comment on lines
901
to
909
|
||
| } else { | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guard
process.cwd()in non-interactive mode.If the working directory was removed between process start and this call,
process.cwd()can throw and crash this path without installer-level context.🤖 Prompt for AI Agents
Validate the
--yesdefault directory before proceeding.This branch skips
validateDirectorySync, so non-writable or invalid cwd fails later with less actionable errors.Proposed fix
🤖 Prompt for AI Agents