refactor: replace hardcoded "dragonscale" string literals with pkg.NAME
Follow-up to the pkg/name.go introduction. All packages that previously contained inline string literals "dragonscale" (used as agent IDs, originator tags, KV prefixes, or directory names) now import pkg and reference pkg.NAME. - cmd/dragonscale/main.go: builtinSkillsDir, cron delegate ID, obligation tool ID, MigrateFileSessions call, agent.WithChannelManager functional option - pkg/auth/oauth.go: OpenAI originator param - pkg/channels/dingtalk.go: markdown reply title - pkg/fantasy/factory.go: providerNameOrDefault fallback - pkg/state/state.go: kvAgentID (const → var to allow pkg.NAME reference) - pkg/tools/focus.go: focusAgentID (const → var) - pkg/memory/delegate/sqlite_integration_test.go: test agent ID strings - pkg/memory/migrate_sessions_test.go: test agent ID strings - pkg/runtime/runtime_test.go: test agent ID strings - pkg/tools/map_runtime_integration_test.go: test agent ID strings
This commit is contained in:
parent
99c9052308
commit
0f994ede65
10 changed files with 39 additions and 26 deletions
|
|
@ -21,6 +21,7 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/ZanzyTHEbar/dragonscale/pkg"
|
||||
"github.com/ZanzyTHEbar/dragonscale/pkg/agent"
|
||||
"github.com/ZanzyTHEbar/dragonscale/pkg/auth"
|
||||
"github.com/ZanzyTHEbar/dragonscale/pkg/bus"
|
||||
|
|
@ -159,7 +160,7 @@ func main() {
|
|||
installer := skills.NewSkillInstaller(skillsDir)
|
||||
cfgDir, _ := config.ConfigDir()
|
||||
globalSkillsDir := filepath.Join(cfgDir, "skills")
|
||||
builtinSkillsDir := filepath.Join(cfgDir, "dragonscale", "skills")
|
||||
builtinSkillsDir := filepath.Join(cfgDir, pkg.NAME, "skills")
|
||||
skillsLoader := skills.NewSkillsLoader(skillsDir, globalSkillsDir, builtinSkillsDir)
|
||||
|
||||
switch subcommand {
|
||||
|
|
@ -611,7 +612,7 @@ func gatewayCmd() {
|
|||
execTimeout := time.Duration(cfg.Tools.Cron.ExecTimeoutMinutes) * time.Minute
|
||||
var cronOpts []cron.CronOption
|
||||
if del := agentLoop.MemoryDelegate(); del != nil {
|
||||
cronOpts = append(cronOpts, cron.WithCronDelegate(del, "dragonscale"))
|
||||
cronOpts = append(cronOpts, cron.WithCronDelegate(del, pkg.NAME))
|
||||
}
|
||||
cronService := setupCronTool(appCtx, agentLoop, msgBus, cfg.SandboxPath(), cfg.RestrictToSandbox(), execTimeout, cronOpts...)
|
||||
|
||||
|
|
@ -644,7 +645,7 @@ func gatewayCmd() {
|
|||
return tools.SilentResult(response)
|
||||
})
|
||||
if del := agentLoop.MemoryDelegate(); del != nil {
|
||||
obligations := tools.NewObligationTool(del, "dragonscale")
|
||||
obligations := tools.NewObligationTool(del, pkg.NAME)
|
||||
heartbeatService.SetDueContextProvider(func(now time.Time) (string, error) {
|
||||
ctx, cancel := context.WithTimeout(appCtx, 10*time.Second)
|
||||
defer cancel()
|
||||
|
|
@ -685,7 +686,7 @@ func gatewayCmd() {
|
|||
}
|
||||
|
||||
// Inject channel manager into agent loop for command handling
|
||||
agentLoop.SetChannelManager(channelManager)
|
||||
agent.WithChannelManager(channelManager)(agentLoop)
|
||||
|
||||
var transcriber *voice.GroqTranscriber
|
||||
if cfg.Providers.Groq.APIKey != "" {
|
||||
|
|
@ -832,7 +833,7 @@ func memoryMigrateSessions() {
|
|||
}
|
||||
|
||||
sessionsDir := filepath.Join(cfg.SandboxPath(), "sessions")
|
||||
stats, err := picomemory.MigrateFileSessions(ctx, del, "dragonscale", sessionsDir)
|
||||
stats, err := picomemory.MigrateFileSessions(ctx, del, pkg.NAME, sessionsDir)
|
||||
if err != nil {
|
||||
fmt.Printf("Migration error: %v\n", err)
|
||||
os.Exit(1)
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/ZanzyTHEbar/dragonscale/pkg"
|
||||
jsonv2 "github.com/go-json-experiment/json"
|
||||
"github.com/go-json-experiment/json/jsontext"
|
||||
)
|
||||
|
|
@ -313,7 +314,7 @@ func buildAuthorizeURL(cfg OAuthProviderConfig, pkce PKCECodes, state, redirectU
|
|||
"state": {state},
|
||||
}
|
||||
if strings.Contains(strings.ToLower(cfg.Issuer), "auth.openai.com") {
|
||||
params.Set("originator", "dragonscale")
|
||||
params.Set("originator", pkg.NAME)
|
||||
}
|
||||
if cfg.Originator != "" {
|
||||
params.Set("originator", cfg.Originator)
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import (
|
|||
"fmt"
|
||||
"sync"
|
||||
|
||||
"github.com/ZanzyTHEbar/dragonscale/pkg"
|
||||
"github.com/ZanzyTHEbar/dragonscale/pkg/bus"
|
||||
"github.com/ZanzyTHEbar/dragonscale/pkg/config"
|
||||
"github.com/ZanzyTHEbar/dragonscale/pkg/logger"
|
||||
|
|
@ -175,7 +176,7 @@ func (c *DingTalkChannel) SendDirectReply(ctx context.Context, sessionWebhook, c
|
|||
|
||||
// Convert string content to []byte for the API
|
||||
contentBytes := []byte(content)
|
||||
titleBytes := []byte("DragonScale")
|
||||
titleBytes := []byte(pkg.NAME)
|
||||
|
||||
// Send markdown formatted reply
|
||||
err := replier.SimpleReplyMarkdown(
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import (
|
|||
|
||||
"charm.land/fantasy"
|
||||
"charm.land/fantasy/providers/openaicompat"
|
||||
"github.com/ZanzyTHEbar/dragonscale/pkg"
|
||||
"github.com/ZanzyTHEbar/dragonscale/pkg/config"
|
||||
"github.com/openai/openai-go/v2/option"
|
||||
)
|
||||
|
|
@ -333,7 +334,7 @@ func defaultIfEmpty(val, fallback string) string {
|
|||
|
||||
func providerNameOrDefault(name string) string {
|
||||
if name == "" {
|
||||
return "dragonscale"
|
||||
return pkg.NAME
|
||||
}
|
||||
return name
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,9 +2,11 @@ package delegate
|
|||
|
||||
import (
|
||||
"context"
|
||||
jsonv2 "github.com/go-json-experiment/json"
|
||||
"testing"
|
||||
|
||||
jsonv2 "github.com/go-json-experiment/json"
|
||||
|
||||
"github.com/ZanzyTHEbar/dragonscale/pkg"
|
||||
"github.com/ZanzyTHEbar/dragonscale/pkg/ids"
|
||||
"github.com/ZanzyTHEbar/dragonscale/pkg/memory"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
|
@ -14,7 +16,7 @@ import (
|
|||
func TestCronKVBackend_Roundtrip(t *testing.T) {
|
||||
d := newTestDelegate(t)
|
||||
ctx := context.Background()
|
||||
agentID := "dragonscale"
|
||||
agentID := pkg.NAME
|
||||
kvKey := "cron:store"
|
||||
|
||||
type cronStore struct {
|
||||
|
|
@ -61,7 +63,7 @@ func TestCronKVBackend_Roundtrip(t *testing.T) {
|
|||
func TestCronKVBackend_UpdatePreservesShape(t *testing.T) {
|
||||
d := newTestDelegate(t)
|
||||
ctx := context.Background()
|
||||
agentID := "dragonscale"
|
||||
agentID := pkg.NAME
|
||||
kvKey := "cron:store"
|
||||
|
||||
v1 := `{"version":1,"jobs":[{"id":"j1","name":"test","enabled":true}]}`
|
||||
|
|
@ -78,7 +80,7 @@ func TestCronKVBackend_UpdatePreservesShape(t *testing.T) {
|
|||
func TestCronKVBackend_PrefixScan(t *testing.T) {
|
||||
d := newTestDelegate(t)
|
||||
ctx := context.Background()
|
||||
agentID := "dragonscale"
|
||||
agentID := pkg.NAME
|
||||
|
||||
require.NoError(t, d.UpsertKV(ctx, agentID, "cron:store", "{}"))
|
||||
require.NoError(t, d.UpsertKV(ctx, agentID, "cron:lock", "held"))
|
||||
|
|
|
|||
|
|
@ -2,12 +2,14 @@ package memory
|
|||
|
||||
import (
|
||||
"context"
|
||||
jsonv2 "github.com/go-json-experiment/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
jsonv2 "github.com/go-json-experiment/json"
|
||||
|
||||
"github.com/ZanzyTHEbar/dragonscale/pkg"
|
||||
"github.com/ZanzyTHEbar/dragonscale/pkg/ids"
|
||||
)
|
||||
|
||||
|
|
@ -134,7 +136,7 @@ func TestMigrateFileSessions_Basic(t *testing.T) {
|
|||
},
|
||||
})
|
||||
|
||||
result, err := MigrateFileSessions(context.Background(), del, "dragonscale", sessDir)
|
||||
result, err := MigrateFileSessions(t.Context(), del, pkg.NAME, sessDir)
|
||||
if err != nil {
|
||||
t.Fatalf("MigrateFileSessions: %v", err)
|
||||
}
|
||||
|
|
@ -170,7 +172,7 @@ func TestMigrateFileSessions_Basic(t *testing.T) {
|
|||
}
|
||||
|
||||
// Check summary was stored as working context
|
||||
wc, err := del.GetWorkingContext(context.Background(), "dragonscale", "session-2")
|
||||
wc, err := del.GetWorkingContext(t.Context(), pkg.NAME, "session-2")
|
||||
if err != nil {
|
||||
t.Fatalf("GetWorkingContext: %v", err)
|
||||
}
|
||||
|
|
@ -191,7 +193,7 @@ func TestMigrateFileSessions_Idempotent(t *testing.T) {
|
|||
})
|
||||
|
||||
// First run
|
||||
result1, err := MigrateFileSessions(context.Background(), del, "dragonscale", sessDir)
|
||||
result1, err := MigrateFileSessions(t.Context(), del, pkg.NAME, sessDir)
|
||||
if err != nil {
|
||||
t.Fatalf("first migration: %v", err)
|
||||
}
|
||||
|
|
@ -200,7 +202,7 @@ func TestMigrateFileSessions_Idempotent(t *testing.T) {
|
|||
}
|
||||
|
||||
// Second run should be a no-op (marker file exists)
|
||||
result2, err := MigrateFileSessions(context.Background(), del, "dragonscale", sessDir)
|
||||
result2, err := MigrateFileSessions(t.Context(), del, pkg.NAME, sessDir)
|
||||
if err != nil {
|
||||
t.Fatalf("second migration: %v", err)
|
||||
}
|
||||
|
|
@ -218,7 +220,7 @@ func TestMigrateFileSessions_EmptyDir(t *testing.T) {
|
|||
sessDir := t.TempDir()
|
||||
del := newMockDelegate()
|
||||
|
||||
result, err := MigrateFileSessions(context.Background(), del, "dragonscale", sessDir)
|
||||
result, err := MigrateFileSessions(t.Context(), del, pkg.NAME, sessDir)
|
||||
if err != nil {
|
||||
t.Fatalf("MigrateFileSessions: %v", err)
|
||||
}
|
||||
|
|
@ -230,7 +232,7 @@ func TestMigrateFileSessions_EmptyDir(t *testing.T) {
|
|||
func TestMigrateFileSessions_NonexistentDir(t *testing.T) {
|
||||
del := newMockDelegate()
|
||||
|
||||
result, err := MigrateFileSessions(context.Background(), del, "dragonscale", "/nonexistent/path")
|
||||
result, err := MigrateFileSessions(t.Context(), del, pkg.NAME, "/nonexistent/path")
|
||||
if err != nil {
|
||||
t.Fatalf("MigrateFileSessions: %v", err)
|
||||
}
|
||||
|
|
@ -252,7 +254,7 @@ func TestMigrateFileSessions_SkipsEmptyMessages(t *testing.T) {
|
|||
},
|
||||
})
|
||||
|
||||
result, err := MigrateFileSessions(context.Background(), del, "dragonscale", sessDir)
|
||||
result, err := MigrateFileSessions(t.Context(), del, pkg.NAME, sessDir)
|
||||
if err != nil {
|
||||
t.Fatalf("MigrateFileSessions: %v", err)
|
||||
}
|
||||
|
|
@ -273,7 +275,7 @@ func TestMigrateFileSessions_FallbackKey(t *testing.T) {
|
|||
},
|
||||
})
|
||||
|
||||
result, err := MigrateFileSessions(context.Background(), del, "dragonscale", sessDir)
|
||||
result, err := MigrateFileSessions(t.Context(), del, pkg.NAME, sessDir)
|
||||
if err != nil {
|
||||
t.Fatalf("MigrateFileSessions: %v", err)
|
||||
}
|
||||
|
|
@ -300,7 +302,7 @@ func TestMigrateFileSessions_MalformedJSON(t *testing.T) {
|
|||
},
|
||||
})
|
||||
|
||||
result, err := MigrateFileSessions(context.Background(), del, "dragonscale", sessDir)
|
||||
result, err := MigrateFileSessions(t.Context(), del, pkg.NAME, sessDir)
|
||||
if err != nil {
|
||||
t.Fatalf("MigrateFileSessions: %v", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/ZanzyTHEbar/dragonscale/pkg"
|
||||
"github.com/ZanzyTHEbar/dragonscale/pkg/bus"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
|
@ -31,7 +32,7 @@ func TestResolveBaseConfigPath_PrefersXDGOverLegacy(t *testing.T) {
|
|||
t.Setenv("HOME", home)
|
||||
t.Setenv("XDG_CONFIG_HOME", xdg)
|
||||
|
||||
xdgPath := filepath.Join(xdg, "dragonscale", "config.json")
|
||||
xdgPath := filepath.Join(xdg, pkg.NAME, "config.json")
|
||||
legacyPath := filepath.Join(home, ".dragonscale", "config.json")
|
||||
require.NoError(t, os.MkdirAll(filepath.Dir(xdgPath), 0o755))
|
||||
require.NoError(t, os.MkdirAll(filepath.Dir(legacyPath), 0o755))
|
||||
|
|
|
|||
|
|
@ -12,10 +12,11 @@ import (
|
|||
jsonv2 "github.com/go-json-experiment/json"
|
||||
"github.com/go-json-experiment/json/jsontext"
|
||||
|
||||
"github.com/ZanzyTHEbar/dragonscale/pkg"
|
||||
"github.com/ZanzyTHEbar/dragonscale/pkg/memory"
|
||||
)
|
||||
|
||||
const kvAgentID = "dragonscale"
|
||||
var kvAgentID = pkg.NAME
|
||||
|
||||
// State represents the persistent state for a workspace.
|
||||
// It includes information about the last active channel/chat.
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import (
|
|||
|
||||
jsonv2 "github.com/go-json-experiment/json"
|
||||
|
||||
"github.com/ZanzyTHEbar/dragonscale/pkg"
|
||||
"github.com/ZanzyTHEbar/dragonscale/pkg/logger"
|
||||
"github.com/ZanzyTHEbar/dragonscale/pkg/messages"
|
||||
"github.com/ZanzyTHEbar/dragonscale/pkg/session"
|
||||
|
|
@ -23,9 +24,10 @@ type KVStore interface {
|
|||
const (
|
||||
focusKVPrefix = "focus:"
|
||||
knowledgeKVPrefix = "knowledge:"
|
||||
focusAgentID = "dragonscale"
|
||||
)
|
||||
|
||||
var focusAgentID = pkg.NAME
|
||||
|
||||
// FocusState tracks an active focus investigation.
|
||||
type FocusState struct {
|
||||
Topic string `json:"topic"`
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/ZanzyTHEbar/dragonscale/pkg"
|
||||
"github.com/ZanzyTHEbar/dragonscale/pkg/bus"
|
||||
"github.com/ZanzyTHEbar/dragonscale/pkg/ids"
|
||||
"github.com/ZanzyTHEbar/dragonscale/pkg/memory/delegate"
|
||||
|
|
@ -76,7 +77,7 @@ func newMapRuntimeForTest(t *testing.T, llm fantasy.LanguageModel, manager *Suba
|
|||
require.NoError(t, d.Init(context.Background()))
|
||||
t.Cleanup(func() { _ = d.Close() })
|
||||
|
||||
return NewMapRuntime(d.Queries(), "dragonscale", llm, "mock-map-llm", manager)
|
||||
return NewMapRuntime(d.Queries(), pkg.NAME, llm, "mock-map-llm", manager)
|
||||
}
|
||||
|
||||
func decodeResultMap(t *testing.T, result *ToolResult) map[string]interface{} {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue