Files
skillshare/cmd/skillshare/project_runtime.go
T
Willie 68d5eadc0b feat: support custom project source directories via sources map
Add ProjectSources struct to ProjectConfig with optional skills, agents,
and extras fields. When set, project-mode commands resolve source paths
from these values instead of hardcoded .skillshare/{skills,agents,extras}/.

Config example:
  sources:
    skills: ./docs/skills
    agents: ./docs/agents

Three EffectiveXxxSource(projectRoot) methods provide the central
resolution logic with fallback to defaults. The projectRuntime gateway
and server layer route through these methods, so most commands get
custom source support automatically.

Closes #153
2026-05-20 15:42:53 +08:00

63 lines
1.5 KiB
Go

package main
import (
"skillshare/internal/config"
"skillshare/internal/install"
)
type projectRuntime struct {
root string
config *config.ProjectConfig
skillsStore *install.MetadataStore
agentsStore *install.MetadataStore
sourcePath string
agentsSourcePath string
targets map[string]config.TargetConfig
}
func loadProjectRuntime(root string) (*projectRuntime, error) {
cfg, err := config.LoadProject(root)
if err != nil {
return nil, err
}
targets, err := config.ResolveProjectTargets(root, cfg)
if err != nil {
return nil, err
}
skillsDir := cfg.EffectiveSkillsSource(root)
agentsDir := cfg.EffectiveAgentsSource(root)
skillsStore, err := install.LoadMetadataWithMigration(skillsDir, "")
if err != nil {
return nil, err
}
agentsStore, err := install.LoadMetadataWithMigration(agentsDir, "agent")
if err != nil {
return nil, err
}
return &projectRuntime{
root: root,
config: cfg,
skillsStore: skillsStore,
agentsStore: agentsStore,
sourcePath: skillsDir,
agentsSourcePath: agentsDir,
targets: targets,
}, nil
}
// configFromProjectRuntime builds a minimal global Config from a project runtime,
// carrying host lists so that source parsing uses the project's azure_hosts / gitlab_hosts.
func configFromProjectRuntime(r *projectRuntime) *config.Config {
return &config.Config{
Source: r.sourcePath,
AgentsSource: r.agentsSourcePath,
GitLabHosts: r.config.GitLabHosts,
AzureHosts: r.config.AzureHosts,
}
}