Files
goclaw/internal/store/run_context.go
T
viettranx ee9f5b8aaf feat(team): share leader memory with team members (read-only)
Team members dispatched via team tasks can now read the leader's memory
files (MEMORY.md, memory/*.md) as a fallback when they have no own
memory. Memory writes are blocked for members — only the leader can
save memory files. This follows the existing team_workspace context
propagation pattern: dispatch metadata → RunRequest → context → tools.

Affected tools: read_file (interceptor), memory_get, memory_search,
list_files (interceptor). All include leader fallback with per-user →
global scope cascade.
2026-03-27 22:45:40 +07:00

68 lines
1.9 KiB
Go

package store
import (
"context"
"github.com/google/uuid"
"github.com/nextlevelbuilder/goclaw/internal/config"
"github.com/nextlevelbuilder/goclaw/internal/sandbox"
)
// runContextKey is the context key for RunContext.
type runContextKey struct{}
// RunContext consolidates all agent-loop-injected context values into a single
// typed struct. This replaces 27 individual context.WithValue calls with one
// WithRunContext call, improving readability and making it trivial to add new
// scope fields (e.g. ProjectID).
//
// Consumers can read via RunContextFromCtx() or continue using existing
// accessor functions (which fall back to individual keys when RunContext is absent).
type RunContext struct {
// Identity
AgentID uuid.UUID
AgentKey string
TenantID uuid.UUID
UserID string
AgentType string
SenderID string
// Flags
SelfEvolve bool
SharedMemory bool
SharedKG bool
RestrictToWorkspace bool
// Tool configuration
BuiltinToolSettings map[string][]byte
ChannelType string
SubagentsCfg *config.SubagentsConfig
ParentModel string
ParentProvider string
MemoryCfg *config.MemoryConfig
SandboxCfg *sandbox.Config
ShellDenyGroups map[string]bool
// Workspace
Workspace string
TeamWorkspace string
TeamID string
WorkspaceChannel string
WorkspaceChatID string
TeamTaskID string
LeaderAgentID string // leader's agent UUID for member memory read fallback
AgentToolKey string // tool-level agent key for registry routing
}
// WithRunContext stores a RunContext on the context.
func WithRunContext(ctx context.Context, rc *RunContext) context.Context {
return context.WithValue(ctx, runContextKey{}, rc)
}
// RunContextFromCtx extracts RunContext from context. Returns nil if not set.
func RunContextFromCtx(ctx context.Context) *RunContext {
rc, _ := ctx.Value(runContextKey{}).(*RunContext)
return rc
}