Unified Agent + reusable Go agent core.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor: remove unused runtime wrappers and dead helpers

Lyric 12d67c3b a4165e67

-396
-4
cmd/mistermorph/daemoncmd/daemon_types.go
··· 20 20 type SubmitTaskResponse = daemonruntime.SubmitTaskResponse 21 21 22 22 type TaskInfo = daemonruntime.TaskInfo 23 - 24 - func ParseTaskStatus(raw string) (TaskStatus, bool) { 25 - return daemonruntime.ParseTaskStatus(raw) 26 - }
-15
cmd/mistermorph/slackcmd/run.go
··· 1 - package slackcmd 2 - 3 - import ( 4 - "context" 5 - 6 - slackruntime "github.com/quailyquaily/mistermorph/internal/channelruntime/slack" 7 - ) 8 - 9 - // RunOptions configures the reusable Slack runtime entrypoint. 10 - type RunOptions = slackruntime.RunOptions 11 - 12 - // Run starts slack runtime with explicit options. 13 - func Run(ctx context.Context, d Dependencies, opts RunOptions) error { 14 - return slackruntime.Run(ctx, slackruntime.Dependencies(d), slackruntime.RunOptions(opts)) 15 - }
-16
cmd/mistermorph/telegramcmd/run.go
··· 1 - package telegramcmd 2 - 3 - import ( 4 - "context" 5 - 6 - telegramruntime "github.com/quailyquaily/mistermorph/internal/channelruntime/telegram" 7 - ) 8 - 9 - // RunOptions configures the reusable telegram runtime entrypoint. 10 - type RunOptions = telegramruntime.RunOptions 11 - 12 - // Run starts telegram runtime with explicit options. 13 - func Run(ctx context.Context, d Dependencies, opts RunOptions) error { 14 - deps := buildTelegramRuntimeDeps(d, d.RuntimeToolsConfig) 15 - return telegramruntime.Run(ctx, deps, telegramruntime.RunOptions(opts)) 16 - }
-14
contacts/service.go
··· 179 179 return s.contactStore.GetContact(ctx, contactID) 180 180 } 181 181 182 - func (s *Service) SetContactStatus(ctx context.Context, contactID string, status Status) (Contact, error) { 183 - if s == nil || !s.ready() { 184 - return Contact{}, fmt.Errorf("nil contacts service") 185 - } 186 - contactID = strings.TrimSpace(contactID) 187 - if contactID == "" { 188 - return Contact{}, fmt.Errorf("contact_id is required") 189 - } 190 - if err := s.ensureStore.Ensure(ctx); err != nil { 191 - return Contact{}, err 192 - } 193 - return s.contactStore.SetContactStatus(ctx, contactID, status) 194 - } 195 - 196 182 func (s *Service) SendDecision(ctx context.Context, now time.Time, decision ShareDecision, sender Sender) (ShareOutcome, error) { 197 183 if s == nil || !s.ready() { 198 184 return ShareOutcome{}, fmt.Errorf("nil contacts service")
-7
internal/bus/adapters/inbound_flow.go
··· 55 55 }, nil 56 56 } 57 57 58 - func (f *InboundFlow) Channel() string { 59 - if f == nil { 60 - return "" 61 - } 62 - return f.channel 63 - } 64 - 65 58 // PublishValidatedInbound applies the shared inbound path: 66 59 // validate+publish via bus, inbox dedupe by (channel, platform_message_id), and persist seen record. 67 60 func (f *InboundFlow) PublishValidatedInbound(ctx context.Context, platformMessageID string, msg busruntime.BusMessage) (bool, error) {
-4
internal/bus/conversation_key.go
··· 27 27 return BuildConversationKey(ChannelSlack, channelID) 28 28 } 29 29 30 - func BuildDiscordChannelConversationKey(channelID string) (string, error) { 31 - return BuildConversationKey(ChannelDiscord, channelID) 32 - } 33 - 34 30 func isValidChannel(channel Channel) bool { 35 31 switch channel { 36 32 case ChannelTelegram, ChannelSlack, ChannelDiscord:
-11
internal/configutil/flag_viper.go
··· 51 51 return v 52 52 } 53 53 54 - func FlagOrViperInt64(cmd *cobra.Command, flagName, viperKey string) int64 { 55 - v, _ := cmd.Flags().GetInt64(flagName) 56 - if cmd.Flags().Changed(flagName) { 57 - return v 58 - } 59 - if viperKey != "" && viper.IsSet(viperKey) { 60 - return viper.GetInt64(viperKey) 61 - } 62 - return v 63 - } 64 - 65 54 func FlagOrViperDuration(cmd *cobra.Command, flagName, viperKey string) time.Duration { 66 55 v, _ := cmd.Flags().GetDuration(flagName) 67 56 if cmd.Flags().Changed(flagName) {
-102
internal/healthcheck/server.go
··· 1 - package healthcheck 2 - 3 - import ( 4 - "context" 5 - "encoding/json" 6 - "errors" 7 - "log/slog" 8 - "net" 9 - "net/http" 10 - "strings" 11 - "time" 12 - ) 13 - 14 - const ( 15 - DefaultListen = "0.0.0.0:8787" 16 - ) 17 - 18 - func NormalizeListen(listen string) string { 19 - return strings.TrimSpace(listen) 20 - } 21 - 22 - func RegisterHealthEndpoint(mux *http.ServeMux, mode string) { 23 - if mux == nil { 24 - return 25 - } 26 - mode = strings.TrimSpace(mode) 27 - mux.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) { 28 - switch r.Method { 29 - case http.MethodGet, http.MethodHead: 30 - default: 31 - w.Header().Set("Allow", "GET, HEAD") 32 - http.Error(w, "method not allowed", http.StatusMethodNotAllowed) 33 - return 34 - } 35 - 36 - payload := map[string]any{ 37 - "ok": true, 38 - "time": time.Now().Format(time.RFC3339Nano), 39 - } 40 - if mode != "" { 41 - payload["mode"] = mode 42 - } 43 - 44 - w.Header().Set("Content-Type", "application/json; charset=utf-8") 45 - w.WriteHeader(http.StatusOK) 46 - if r.Method == http.MethodHead { 47 - return 48 - } 49 - _ = json.NewEncoder(w).Encode(payload) 50 - }) 51 - } 52 - 53 - func StartServer(ctx context.Context, logger *slog.Logger, listen string, mode string) (*http.Server, error) { 54 - if ctx == nil { 55 - ctx = context.Background() 56 - } 57 - if logger == nil { 58 - logger = slog.Default() 59 - } 60 - listen = NormalizeListen(listen) 61 - if listen == "" { 62 - return nil, errors.New("empty health listen address") 63 - } 64 - 65 - mux := http.NewServeMux() 66 - RegisterHealthEndpoint(mux, mode) 67 - mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { 68 - w.Header().Set("Content-Type", "text/plain; charset=utf-8") 69 - w.WriteHeader(http.StatusOK) 70 - if r.Method == http.MethodHead { 71 - return 72 - } 73 - _, _ = w.Write([]byte("ok\n")) 74 - }) 75 - 76 - ln, err := net.Listen("tcp", listen) 77 - if err != nil { 78 - return nil, err 79 - } 80 - 81 - srv := &http.Server{ 82 - Addr: listen, 83 - Handler: mux, 84 - ReadHeaderTimeout: 5 * time.Second, 85 - } 86 - 87 - go func() { 88 - <-ctx.Done() 89 - shutdownCtx, cancel := context.WithTimeout(context.Background(), 2*time.Second) 90 - _ = srv.Shutdown(shutdownCtx) 91 - cancel() 92 - }() 93 - 94 - go func() { 95 - if err := srv.Serve(ln); err != nil && !errors.Is(err, http.ErrServerClosed) { 96 - logger.Error("health_server_error", "addr", listen, "error", err.Error()) 97 - } 98 - }() 99 - 100 - logger.Info("health_server_start", "addr", listen, "health_path", "/health", "mode", strings.TrimSpace(mode)) 101 - return srv, nil 102 - }
-30
internal/llmutil/llmutil.go
··· 54 54 return RuntimeValuesFromReader(viper.GetViper()) 55 55 } 56 56 57 - func ProviderFromViper() string { 58 - return strings.TrimSpace(RuntimeValuesFromViper().Provider) 59 - } 60 - 61 - func EndpointFromViper() string { 62 - values := RuntimeValuesFromViper() 63 - return EndpointForProviderWithValues(values.Provider, values) 64 - } 65 - 66 - func APIKeyFromViper() string { 67 - values := RuntimeValuesFromViper() 68 - return APIKeyForProviderWithValues(values.Provider, values) 69 - } 70 - 71 57 func ModelFromViper() string { 72 58 values := RuntimeValuesFromViper() 73 59 return ModelForProviderWithValues(values.Provider, values) 74 60 } 75 61 76 - func EndpointForProvider(provider string) string { 77 - return EndpointForProviderWithValues(provider, RuntimeValuesFromViper()) 78 - } 79 - 80 62 func EndpointForProviderWithValues(provider string, values RuntimeValues) string { 81 63 provider = normalizeProvider(provider) 82 64 switch provider { ··· 91 73 } 92 74 } 93 75 94 - func APIKeyForProvider(provider string) string { 95 - return APIKeyForProviderWithValues(provider, RuntimeValuesFromViper()) 96 - } 97 - 98 76 func APIKeyForProviderWithValues(provider string, values RuntimeValues) string { 99 77 provider = normalizeProvider(provider) 100 78 switch provider { ··· 105 83 } 106 84 } 107 85 108 - func ModelForProvider(provider string) string { 109 - return ModelForProviderWithValues(provider, RuntimeValuesFromViper()) 110 - } 111 - 112 86 func ModelForProviderWithValues(provider string, values RuntimeValues) string { 113 87 provider = normalizeProvider(provider) 114 88 switch provider { ··· 120 94 default: 121 95 return strings.TrimSpace(values.Model) 122 96 } 123 - } 124 - 125 - func ClientFromConfig(cfg llmconfig.ClientConfig) (llm.Client, error) { 126 - return ClientFromConfigWithValues(cfg, RuntimeValuesFromViper()) 127 97 } 128 98 129 99 func ClientFromConfigWithValues(cfg llmconfig.ClientConfig, values RuntimeValues) (llm.Client, error) {
-10
internal/promptprofile/identity.go
··· 35 35 ) 36 36 } 37 37 38 - // Backward-compatible wrappers for existing call sites. 39 - func AppendIdentityPromptBlock(spec *agent.PromptSpec, log *slog.Logger) { 40 - ApplyPersonaIdentity(spec, log) 41 - } 42 - 43 - // Backward-compatible wrappers for existing call sites. 44 - func AppendSoulPromptBlock(spec *agent.PromptSpec, log *slog.Logger) { 45 - ApplyPersonaIdentity(spec, log) 46 - } 47 - 48 38 func identityPath() string { 49 39 return filepath.Join(statepaths.FileStateDir(), "IDENTITY.md") 50 40 }
-4
internal/todo/ops.go
··· 55 55 }, nil 56 56 } 57 57 58 - func (s *Store) AddWithChannel(ctx context.Context, raw string, channel string) (UpdateResult, error) { 59 - return s.AddWithChatID(ctx, raw, channel) 60 - } 61 - 62 58 func (s *Store) Complete(ctx context.Context, raw string) (UpdateResult, error) { 63 59 query, err := normalizeCompleteQuery(raw) 64 60 if err != nil {
-27
memory/identity.go
··· 1 - package memory 2 - 3 - import ( 4 - "context" 5 - "fmt" 6 - ) 7 - 8 - type Identity struct { 9 - Enabled bool 10 - ExternalKey string 11 - SubjectID string 12 - } 13 - 14 - type IdentityResolver interface { 15 - ResolveTelegram(ctx context.Context, userID int64) (Identity, error) 16 - } 17 - 18 - type Resolver struct{} 19 - 20 - func (r *Resolver) ResolveTelegram(_ context.Context, userID int64) (Identity, error) { 21 - if userID <= 0 { 22 - return Identity{Enabled: false}, nil 23 - } 24 - ext := fmt.Sprintf("telegram:%d", userID) 25 - subject := "ext:" + ext 26 - return Identity{Enabled: true, ExternalKey: ext, SubjectID: subject}, nil 27 - }
-115
skills/select.go
··· 1 - package skills 2 - 3 - import ( 4 - "context" 5 - "encoding/json" 6 - "fmt" 7 - "strings" 8 - 9 - "github.com/quailyquaily/mistermorph/internal/jsonutil" 10 - "github.com/quailyquaily/mistermorph/internal/llminspect" 11 - "github.com/quailyquaily/mistermorph/llm" 12 - ) 13 - 14 - type SelectOptions struct { 15 - Model string 16 - MaxLoad int 17 - PreviewBytes int64 18 - CatalogLimit int 19 - } 20 - 21 - type Selection struct { 22 - SkillsToLoad []string `json:"skills_to_load"` 23 - Reasoning string `json:"reasoning"` 24 - } 25 - 26 - func Select(ctx context.Context, client llm.Client, task string, all []Skill, opts SelectOptions) (Selection, error) { 27 - if client == nil { 28 - return Selection{}, fmt.Errorf("missing llm client") 29 - } 30 - task = strings.TrimSpace(task) 31 - if task == "" { 32 - return Selection{}, fmt.Errorf("missing task") 33 - } 34 - if opts.MaxLoad <= 0 { 35 - opts.MaxLoad = 3 36 - } 37 - if opts.PreviewBytes <= 0 { 38 - opts.PreviewBytes = 2048 39 - } 40 - if opts.CatalogLimit <= 0 { 41 - opts.CatalogLimit = 200 42 - } 43 - if opts.Model == "" { 44 - opts.Model = "gpt-5.2" 45 - } 46 - 47 - type skillInfo struct { 48 - ID string `json:"id"` 49 - Name string `json:"name"` 50 - Preview string `json:"preview"` 51 - } 52 - 53 - limited := all 54 - if len(limited) > opts.CatalogLimit { 55 - limited = limited[:opts.CatalogLimit] 56 - } 57 - 58 - catalog := make([]skillInfo, 0, len(limited)) 59 - for _, s := range limited { 60 - preview, err := LoadPreview(s, opts.PreviewBytes) 61 - if err != nil { 62 - continue 63 - } 64 - catalog = append(catalog, skillInfo{ 65 - ID: s.ID, 66 - Name: s.Name, 67 - Preview: strings.TrimSpace(preview.Contents), 68 - }) 69 - } 70 - 71 - payload := map[string]any{ 72 - "task": task, 73 - "max_skills": opts.MaxLoad, 74 - "available_skills": catalog, 75 - } 76 - payloadJSON, _ := json.Marshal(payload) 77 - 78 - sys := fmt.Sprintf(strings.TrimSpace(` 79 - You are a router that selects which skills (if any) should be loaded to best complete a task. 80 - 81 - Rules: 82 - - Only choose skills from available_skills (use the "id" field). 83 - - Choose at most %d skills. 84 - - If none are helpful, choose an empty list. 85 - 86 - Return JSON: 87 - { 88 - "skills_to_load": ["id1", "id2"], 89 - "reasoning": "short" 90 - } 91 - `), opts.MaxLoad) 92 - 93 - res, err := client.Chat(llminspect.WithModelScene(ctx, "skills.select"), llm.Request{ 94 - Model: opts.Model, 95 - ForceJSON: true, 96 - Messages: []llm.Message{ 97 - {Role: "system", Content: sys}, 98 - {Role: "user", Content: string(payloadJSON)}, 99 - }, 100 - }) 101 - if err != nil { 102 - return Selection{}, err 103 - } 104 - 105 - var out Selection 106 - if err := jsonutil.DecodeWithFallback(res.Text, &out); err != nil { 107 - return Selection{}, err 108 - } 109 - 110 - if len(out.SkillsToLoad) > opts.MaxLoad { 111 - out.SkillsToLoad = out.SkillsToLoad[:opts.MaxLoad] 112 - } 113 - 114 - return out, nil 115 - }
-37
skills/skills.go
··· 2 2 3 3 import ( 4 4 "fmt" 5 - "io" 6 5 "io/fs" 7 6 "os" 8 7 "path/filepath" ··· 117 116 }) 118 117 119 118 return out, firstErr 120 - } 121 - 122 - func Load(skill Skill, maxBytes int64) (Skill, error) { 123 - data, err := os.ReadFile(skill.SkillMD) 124 - if err != nil { 125 - return Skill{}, err 126 - } 127 - if maxBytes > 0 && int64(len(data)) > maxBytes { 128 - data = data[:maxBytes] 129 - } 130 - skill.Contents = string(data) 131 - if fm, ok := ParseFrontmatter(skill.Contents); ok { 132 - skill = applyFrontmatter(skill, fm) 133 - } 134 - return skill, nil 135 - } 136 - 137 - func LoadPreview(skill Skill, maxBytes int64) (Skill, error) { 138 - f, err := os.Open(skill.SkillMD) 139 - if err != nil { 140 - return Skill{}, err 141 - } 142 - defer f.Close() 143 - 144 - if maxBytes <= 0 { 145 - maxBytes = 2048 146 - } 147 - data, err := io.ReadAll(io.LimitReader(f, maxBytes)) 148 - if err != nil { 149 - return Skill{}, err 150 - } 151 - skill.Contents = string(data) 152 - if fm, ok := ParseFrontmatter(skill.Contents); ok { 153 - skill = applyFrontmatter(skill, fm) 154 - } 155 - return skill, nil 156 119 } 157 120 158 121 // LoadFrontmatter loads only metadata parsed from SKILL.md frontmatter.