From dc8375567f23ec4436be8eb511e82d0853f201d6 Mon Sep 17 00:00:00 2001 From: Willie Ruemmele Date: Fri, 16 Jan 2026 14:55:56 -0700 Subject: [PATCH 1/2] fix: add 'Default Agent Spec' as option when prompted --- .../agent/generate/authoring-bundle.ts | 9 +++++---- src/flags.ts | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/commands/agent/generate/authoring-bundle.ts b/src/commands/agent/generate/authoring-bundle.ts index 284b0d8..3d2c9dd 100644 --- a/src/commands/agent/generate/authoring-bundle.ts +++ b/src/commands/agent/generate/authoring-bundle.ts @@ -22,7 +22,7 @@ import { AgentJobSpec, ScriptAgent } from '@salesforce/agents'; import YAML from 'yaml'; import { input as inquirerInput } from '@inquirer/prompts'; import { theme } from '../../../inquirer-theme.js'; -import { FlaggablePrompt, promptForFlag, promptForYamlFile } from '../../../flags.js'; +import { FlaggablePrompt, promptForFlag, promptForSpecYaml } from '../../../flags.js'; Messages.importMessagesDirectoryFromMetaUrl(import.meta.url); const messages = Messages.loadMessages('@salesforce/plugin-agent', 'agent.generate.authoring-bundle'); @@ -105,7 +105,7 @@ export default class AgentGenerateAuthoringBundle extends SfCommand => promptForFileByExtensions(flagDef, ['.yml', '.yaml']); +export const promptForSpecYaml = async (flagDef: FlaggablePrompt): Promise => { + const hiddenDirs = await getHiddenDirs(); + const dirsToTraverse = [process.cwd()]; + const files = traverseForFiles(dirsToTraverse, ['AgentSpec.yml', 'AgentSpec.yaml'], ['node_modules', ...hiddenDirs]); + return autocomplete({ + message: flagDef.promptMessage ?? flagDef.message.replace(/\.$/, ''), + // eslint-disable-next-line @typescript-eslint/require-await + source: async (input) => { + const arr = [ + ...files.map((o) => ({ name: relative(process.cwd(), o), value: o })), + { name: 'Default Agent Spec', value: undefined }, + ]; + + if (!input) return arr; + return arr.filter((o) => o.name.includes(input)); + }, + }); +}; + export const promptForFlag = async (flagDef: FlaggablePrompt): Promise => { const message = flagDef.promptMessage ?? flagDef.message.replace(/\.$/, ''); if (flagDef.options) { From 32b4a1093ccf97e016fcda7568d2cf2a588f332d Mon Sep 17 00:00:00 2001 From: Willie Ruemmele Date: Wed, 21 Jan 2026 11:47:18 -0700 Subject: [PATCH 2/2] test: add UT --- test/flags.test.ts | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/test/flags.test.ts b/test/flags.test.ts index 736f9a9..4479647 100644 --- a/test/flags.test.ts +++ b/test/flags.test.ts @@ -14,10 +14,10 @@ * limitations under the License. */ -import { join } from 'node:path'; +import { join, relative } from 'node:path'; import { mkdir, writeFile, rm } from 'node:fs/promises'; import { expect } from 'chai'; -import { traverseForFiles } from '../src/flags.js'; +import { getHiddenDirs, traverseForFiles } from '../src/flags.js'; describe('traverseForFiles', () => { const testDir = join(process.cwd(), 'test-temp'); @@ -73,3 +73,37 @@ describe('traverseForFiles', () => { expect(results).to.have.lengthOf(6); }); }); + +describe('promptForSpecYaml', () => { + it('should include "Default Agent Spec" in the list of options', async () => { + // Test the source function logic directly by replicating what promptForSpecYaml does + + const hiddenDirs = await getHiddenDirs(); + const dirsToTraverse = [process.cwd()]; + const files = traverseForFiles( + dirsToTraverse, + ['AgentSpec.yml', 'AgentSpec.yaml'], + ['node_modules', ...hiddenDirs] + ); + + // Replicate the source function logic from promptForSpecYaml + const source = async (input?: string) => { + const arr = [ + ...files.map((o) => ({ name: relative(process.cwd(), o), value: o })), + { name: 'Default Agent Spec', value: undefined }, + ]; + + if (!input) return arr; + return arr.filter((o) => o.name.includes(input)); + }; + + // Call the source function with no input to get all options + const options = await source(); + + // Verify "Default Agent Spec" is in the list + const defaultAgentSpecOption = options.find((option) => option.name === 'Default Agent Spec'); + expect(defaultAgentSpecOption).to.be.ok; + expect(defaultAgentSpecOption?.name).to.equal('Default Agent Spec'); + expect(defaultAgentSpecOption?.value).to.be.undefined; + }); +});