mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-04 09:13:08 +00:00
refactor: improve agent file model validation and settings source deduplication
- Enhanced model parsing in agent discovery to validate against allowed values and log warnings for invalid models. - Refactored settingSources construction in AgentService to utilize Set for automatic deduplication, simplifying the merging of user and project settings with skills sources. - Updated tests to reflect changes in allowedTools for improved functionality. These changes enhance the robustness of agent configuration and streamline settings management.
This commit is contained in:
@@ -68,12 +68,21 @@ async function parseAgentFile(
|
|||||||
.filter((t) => t && t !== '')
|
.filter((t) => t && t !== '')
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
// Parse model (optional)
|
// Parse model (optional) - validate against allowed values
|
||||||
const modelMatch = frontmatter.match(/model:\s*(\w+)/);
|
const modelMatch = frontmatter.match(/model:\s*(\w+)/);
|
||||||
const model = modelMatch
|
const modelValue = modelMatch?.[1]?.trim();
|
||||||
? (modelMatch[1].trim() as 'sonnet' | 'opus' | 'haiku' | 'inherit')
|
const validModels = ['sonnet', 'opus', 'haiku', 'inherit'] as const;
|
||||||
|
const model =
|
||||||
|
modelValue && validModels.includes(modelValue as (typeof validModels)[number])
|
||||||
|
? (modelValue as 'sonnet' | 'opus' | 'haiku' | 'inherit')
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
|
if (modelValue && !model) {
|
||||||
|
logger.warn(
|
||||||
|
`Invalid model "${modelValue}" in agent file: ${filePath}. Expected one of: ${validModels.join(', ')}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
description,
|
description,
|
||||||
prompt: prompt.trim(),
|
prompt: prompt.trim(),
|
||||||
|
|||||||
@@ -289,25 +289,12 @@ export class AgentService {
|
|||||||
const maxTurns = sdkOptions.maxTurns;
|
const maxTurns = sdkOptions.maxTurns;
|
||||||
let allowedTools = sdkOptions.allowedTools as string[] | undefined;
|
let allowedTools = sdkOptions.allowedTools as string[] | undefined;
|
||||||
|
|
||||||
// Build merged settingSources array (filter to only 'user' and 'project')
|
// Build merged settingSources array using Set for automatic deduplication
|
||||||
const settingSources: Array<'user' | 'project'> = [];
|
const sdkSettingSources = (sdkOptions.settingSources ?? []).filter(
|
||||||
if (sdkOptions.settingSources) {
|
(source): source is 'user' | 'project' => source === 'user' || source === 'project'
|
||||||
sdkOptions.settingSources.forEach((source) => {
|
);
|
||||||
if (source === 'user' || source === 'project') {
|
const skillSettingSources = skillsConfig.enabled ? skillsConfig.sources : [];
|
||||||
if (!settingSources.includes(source)) {
|
const settingSources = [...new Set([...sdkSettingSources, ...skillSettingSources])];
|
||||||
settingSources.push(source);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
// Merge skills sources (avoid duplicates)
|
|
||||||
if (skillsConfig.enabled && skillsConfig.sources.length > 0) {
|
|
||||||
skillsConfig.sources.forEach((source) => {
|
|
||||||
if (!settingSources.includes(source)) {
|
|
||||||
settingSources.push(source);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enhance allowedTools with Skills and Subagents tools
|
// Enhance allowedTools with Skills and Subagents tools
|
||||||
if (allowedTools) {
|
if (allowedTools) {
|
||||||
|
|||||||
@@ -96,7 +96,17 @@ describe('claude-provider.ts', () => {
|
|||||||
expect(sdk.query).toHaveBeenCalledWith({
|
expect(sdk.query).toHaveBeenCalledWith({
|
||||||
prompt: 'Test',
|
prompt: 'Test',
|
||||||
options: expect.objectContaining({
|
options: expect.objectContaining({
|
||||||
allowedTools: ['Read', 'Write', 'Edit', 'Glob', 'Grep', 'Bash', 'WebSearch', 'WebFetch'],
|
allowedTools: [
|
||||||
|
'Read',
|
||||||
|
'Write',
|
||||||
|
'Edit',
|
||||||
|
'Glob',
|
||||||
|
'Grep',
|
||||||
|
'Bash',
|
||||||
|
'WebSearch',
|
||||||
|
'WebFetch',
|
||||||
|
'Skill',
|
||||||
|
],
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user