Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/daily-code-metrics.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/workflow/compiler_orchestrator_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ func (c *Compiler) extractAdditionalConfigurations(
if err != nil {
return err
}
repoMemoryConfig, err := c.extractRepoMemoryConfig(toolsConfig)
repoMemoryConfig, err := c.extractRepoMemoryConfig(toolsConfig, workflowData.WorkflowID)
if err != nil {
return err
}
Expand Down
31 changes: 24 additions & 7 deletions pkg/workflow/repo_memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@ func validateBranchPrefix(prefix string) error {
return nil
}

// extractRepoMemoryConfig extracts repo-memory configuration from tools section
func (c *Compiler) extractRepoMemoryConfig(toolsConfig *ToolsConfig) (*RepoMemoryConfig, error) {
// extractRepoMemoryConfig extracts repo-memory configuration from tools section.
// workflowID is used to qualify the default branch name (e.g. "memory/{workflowID}").
func (c *Compiler) extractRepoMemoryConfig(toolsConfig *ToolsConfig, workflowID string) (*RepoMemoryConfig, error) {
// Check if repo-memory tool is configured
if toolsConfig == nil || toolsConfig.RepoMemory == nil {
return nil, nil
Expand All @@ -110,13 +111,22 @@ func (c *Compiler) extractRepoMemoryConfig(toolsConfig *ToolsConfig) (*RepoMemor
}
repoMemoryValue := toolsConfig.RepoMemory.Raw

// defaultMemoryBranchID returns workflowID when set, otherwise "default".
// This qualifies the default branch name by workflow, e.g. "memory/repo-assist".
defaultMemoryBranchID := func() string {
if workflowID != "" {
return workflowID
}
return "default"
}

// Handle nil value (simple enable with defaults) - same as true
if repoMemoryValue == nil {
repoMemoryLog.Print("Using default repo-memory configuration (nil value)")
config.Memories = []RepoMemoryEntry{
{
ID: "default",
BranchName: generateDefaultBranchName("default", config.BranchPrefix),
BranchName: generateDefaultBranchName(defaultMemoryBranchID(), config.BranchPrefix),
MaxFileSize: 10240, // 10KB
MaxFileCount: 100,
CreateOrphan: true,
Expand All @@ -134,7 +144,7 @@ func (c *Compiler) extractRepoMemoryConfig(toolsConfig *ToolsConfig) (*RepoMemor
config.Memories = []RepoMemoryEntry{
{
ID: "default",
BranchName: generateDefaultBranchName("default", config.BranchPrefix),
BranchName: generateDefaultBranchName(defaultMemoryBranchID(), config.BranchPrefix),
MaxFileSize: 10240, // 10KB
MaxFileCount: 100,
CreateOrphan: true,
Expand Down Expand Up @@ -178,9 +188,11 @@ func (c *Compiler) extractRepoMemoryConfig(toolsConfig *ToolsConfig) (*RepoMemor
}

// ID is required for array notation
explicitID := false
if id, exists := memoryMap["id"]; exists {
if idStr, ok := id.(string); ok {
entry.ID = idStr
explicitID = true
}
}
// Use "default" if no ID specified
Expand All @@ -201,9 +213,14 @@ func (c *Compiler) extractRepoMemoryConfig(toolsConfig *ToolsConfig) (*RepoMemor
entry.BranchName = branchStr
}
}
// Set default branch name if not specified
// Set default branch name if not specified.
// When no explicit ID was provided (defaulted to "default"), qualify the branch by workflow ID.
if entry.BranchName == "" {
entry.BranchName = generateDefaultBranchName(entry.ID, config.BranchPrefix)
branchID := entry.ID
if !explicitID {
branchID = defaultMemoryBranchID()
}
entry.BranchName = generateDefaultBranchName(branchID, config.BranchPrefix)
}

// Parse file-glob
Expand Down Expand Up @@ -311,7 +328,7 @@ func (c *Compiler) extractRepoMemoryConfig(toolsConfig *ToolsConfig) (*RepoMemor

entry := RepoMemoryEntry{
ID: "default",
BranchName: generateDefaultBranchName("default", config.BranchPrefix),
BranchName: generateDefaultBranchName(defaultMemoryBranchID(), config.BranchPrefix),
MaxFileSize: 10240, // 10KB default
MaxFileCount: 100, // 100 files default
CreateOrphan: true, // create orphan by default
Expand Down
30 changes: 15 additions & 15 deletions pkg/workflow/repo_memory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestRepoMemoryConfigDefault(t *testing.T) {
}

compiler := NewCompiler()
config, err := compiler.extractRepoMemoryConfig(toolsConfig)
config, err := compiler.extractRepoMemoryConfig(toolsConfig, "my-workflow")
if err != nil {
t.Fatalf("Failed to extract repo-memory config: %v", err)
}
Expand All @@ -40,8 +40,8 @@ func TestRepoMemoryConfigDefault(t *testing.T) {
t.Errorf("Expected ID 'default', got '%s'", memory.ID)
}

if memory.BranchName != "memory/default" {
t.Errorf("Expected branch name 'memory/default', got '%s'", memory.BranchName)
if memory.BranchName != "memory/my-workflow" {
t.Errorf("Expected branch name 'memory/my-workflow', got '%s'", memory.BranchName)
}

if memory.MaxFileSize != 10240 {
Expand Down Expand Up @@ -74,7 +74,7 @@ func TestRepoMemoryConfigObject(t *testing.T) {
}

compiler := NewCompiler()
config, err := compiler.extractRepoMemoryConfig(toolsConfig)
config, err := compiler.extractRepoMemoryConfig(toolsConfig, "")
if err != nil {
t.Fatalf("Failed to extract repo-memory config: %v", err)
}
Expand Down Expand Up @@ -127,7 +127,7 @@ func TestRepoMemoryConfigArray(t *testing.T) {
}

compiler := NewCompiler()
config, err := compiler.extractRepoMemoryConfig(toolsConfig)
config, err := compiler.extractRepoMemoryConfig(toolsConfig, "")
if err != nil {
t.Fatalf("Failed to extract repo-memory config: %v", err)
}
Expand Down Expand Up @@ -183,7 +183,7 @@ func TestRepoMemoryConfigDuplicateIDs(t *testing.T) {
}

compiler := NewCompiler()
_, err = compiler.extractRepoMemoryConfig(toolsConfig)
_, err = compiler.extractRepoMemoryConfig(toolsConfig, "")
if err == nil {
t.Fatal("Expected error for duplicate memory IDs, got nil")
}
Expand Down Expand Up @@ -395,7 +395,7 @@ func TestRepoMemoryMaxFileSizeValidation(t *testing.T) {
}

compiler := NewCompiler()
config, err := compiler.extractRepoMemoryConfig(toolsConfig)
config, err := compiler.extractRepoMemoryConfig(toolsConfig, "")

if tt.wantError {
if err == nil {
Expand Down Expand Up @@ -465,7 +465,7 @@ func TestRepoMemoryMaxFileSizeValidationArray(t *testing.T) {
}

compiler := NewCompiler()
config, err := compiler.extractRepoMemoryConfig(toolsConfig)
config, err := compiler.extractRepoMemoryConfig(toolsConfig, "")

if tt.wantError {
if err == nil {
Expand Down Expand Up @@ -554,7 +554,7 @@ func TestRepoMemoryMaxFileCountValidation(t *testing.T) {
}

compiler := NewCompiler()
config, err := compiler.extractRepoMemoryConfig(toolsConfig)
config, err := compiler.extractRepoMemoryConfig(toolsConfig, "")

if tt.wantError {
if err == nil {
Expand Down Expand Up @@ -624,7 +624,7 @@ func TestRepoMemoryMaxFileCountValidationArray(t *testing.T) {
}

compiler := NewCompiler()
config, err := compiler.extractRepoMemoryConfig(toolsConfig)
config, err := compiler.extractRepoMemoryConfig(toolsConfig, "")

if tt.wantError {
if err == nil {
Expand Down Expand Up @@ -778,15 +778,15 @@ func TestBranchPrefixInConfig(t *testing.T) {
require.NoError(t, err, "Failed to parse tools config")

compiler := NewCompiler()
config, err := compiler.extractRepoMemoryConfig(toolsConfig)
config, err := compiler.extractRepoMemoryConfig(toolsConfig, "my-workflow")
require.NoError(t, err, "Failed to extract repo-memory config")
require.NotNil(t, config, "Expected non-nil config")

assert.Equal(t, "campaigns", config.BranchPrefix, "Expected branch-prefix 'campaigns'")
assert.Len(t, config.Memories, 1, "Expected 1 memory")

memory := config.Memories[0]
assert.Equal(t, "campaigns/default", memory.BranchName, "Expected branch name 'campaigns/default'")
assert.Equal(t, "campaigns/my-workflow", memory.BranchName, "Expected branch name 'campaigns/my-workflow'")
}

// TestBranchPrefixInArrayConfig tests branch-prefix in array configuration
Expand All @@ -807,7 +807,7 @@ func TestBranchPrefixInArrayConfig(t *testing.T) {
require.NoError(t, err, "Failed to parse tools config")

compiler := NewCompiler()
config, err := compiler.extractRepoMemoryConfig(toolsConfig)
config, err := compiler.extractRepoMemoryConfig(toolsConfig, "")
require.NoError(t, err, "Failed to extract repo-memory config")
require.NotNil(t, config, "Expected non-nil config")

Expand All @@ -832,7 +832,7 @@ func TestBranchPrefixWithExplicitBranchName(t *testing.T) {
require.NoError(t, err, "Failed to parse tools config")

compiler := NewCompiler()
config, err := compiler.extractRepoMemoryConfig(toolsConfig)
config, err := compiler.extractRepoMemoryConfig(toolsConfig, "")
require.NoError(t, err, "Failed to extract repo-memory config")
require.NotNil(t, config, "Expected non-nil config")

Expand Down Expand Up @@ -866,7 +866,7 @@ func TestInvalidBranchPrefixRejectsConfig(t *testing.T) {
require.NoError(t, err, "Failed to parse tools config")

compiler := NewCompiler()
config, err := compiler.extractRepoMemoryConfig(toolsConfig)
config, err := compiler.extractRepoMemoryConfig(toolsConfig, "")
require.Error(t, err, "Expected error for invalid branch-prefix: %s", tt.prefix)
assert.Nil(t, config, "Expected nil config on error")
})
Expand Down
Loading