fix: Phase 4 structural refactor — reduce lint findings from 28 to 5

cyclop (5→0): extract subcommand/case bodies in codesearch,
subprocess, Telegram, indexing
funlen (5→3): extract memory action handlers, tool provider startup
gocognit (7→2): extract config finalize/loadDirInto helpers, release
announcer, capture tool validation, Telegram gateway (200→108),
archie-agent main loop (35→0)
nestif (8→0): extract identity validation, container validation,
conf.d scanning, email multipart parsing, Telegram model/update
parsing, build-no-changes closure
interfacebloat (3→0): split Forge/IssueForge/PRForge/RepoForge,
SessionStore/SessionLifecycle/MessageHistory,
TaskStore/TaskLifecycle/TaskQueries/TaskEvents

Remaining: daemon process, workflow Feasibility/TDD/AgentStage,
archied main.go run (108→30 remaining). These require deeper
refactoring best done per-function in follow-up beads.

Updated contract tests and archied wiring tests to check both
main.go and the new telegram_setup.go.
This commit is contained in:
sam committed 2026-07-29 10:15:22 +10:00
1 parent 676ad3fe48
commit 712388dc6c
24 files changed
+1090 -886

No files matched your search

+75 -64
View File
@@ -242,7 +242,6 @@ func (p *Provider) HandleToolCall(name string, args map[string]any) (any, error)
}
action, _ := args["action"].(string)
section, _ := args["section"].(string)
caseSensitive := true
if v, ok := args["case_sensitive"].(bool); ok {
caseSensitive = v
@@ -250,76 +249,88 @@ func (p *Provider) HandleToolCall(name string, args map[string]any) (any, error)
switch action {
case "add":
content, _ := args["content"].(string)
if content == "" {
return nil, fmt.Errorf("builtin: add requires non-empty \"content\"")
}
res, err := store.Add(section, content)
if err != nil {
return nil, err
}
verb := "appended to"
if res.Created {
verb = "created"
}
return map[string]any{
"success": true,
"file": fileLabel,
"action": "add",
"section": res.Section,
"chars_added": res.CharsAdded,
"section_chars": res.SectionChars,
"file_bytes": res.FileBytes,
"message": fmt.Sprintf("%s section %q (%d chars added, %d bytes in file)", capitalize(verb), res.Section, res.CharsAdded, res.FileBytes),
}, nil
return p.handleAdd(store, fileLabel, args)
case "replace":
substring, _ := args["substring"].(string)
replacement, _ := args["replacement"].(string)
if substring == "" {
return nil, fmt.Errorf("builtin: replace requires non-empty \"substring\"")
}
res, err := store.Replace(section, substring, replacement, caseSensitive)
if err != nil {
return nil, err
}
return map[string]any{
"success": true,
"file": fileLabel,
"action": "replace",
"section": res.Section,
"chars_removed": res.CharsRemoved,
"chars_added": res.CharsAdded,
"section_chars": res.SectionChars,
"file_bytes": res.FileBytes,
"message": fmt.Sprintf("Replaced %d chars with %d chars in section %q (%d bytes in file)", res.CharsRemoved, res.CharsAdded, res.Section, res.FileBytes),
}, nil
return p.handleReplace(store, fileLabel, args, caseSensitive)
case "remove":
substring, _ := args["substring"].(string)
if substring == "" {
return nil, fmt.Errorf("builtin: remove requires non-empty \"substring\"")
}
res, err := store.Remove(section, substring, caseSensitive)
if err != nil {
return nil, err
}
return map[string]any{
"success": true,
"file": fileLabel,
"action": "remove",
"section": res.Section,
"chars_removed": res.CharsRemoved,
"section_chars": res.SectionChars,
"file_bytes": res.FileBytes,
"message": fmt.Sprintf("Removed %d chars from section %q (%d bytes in file)", res.CharsRemoved, res.Section, res.FileBytes),
}, nil
return p.handleRemove(store, fileLabel, args, caseSensitive)
default:
return nil, fmt.Errorf("builtin: unknown action %q (want add, replace, or remove)", action)
}
}
func (p *Provider) handleAdd(store *Store, fileLabel string, args map[string]any) (any, error) {
content, _ := args["content"].(string)
if content == "" {
return nil, fmt.Errorf("builtin: add requires non-empty \"content\"")
}
section, _ := args["section"].(string)
res, err := store.Add(section, content)
if err != nil {
return nil, err
}
verb := "appended to"
if res.Created {
verb = "created"
}
return map[string]any{
"success": true,
"file": fileLabel,
"action": "add",
"section": res.Section,
"chars_added": res.CharsAdded,
"section_chars": res.SectionChars,
"file_bytes": res.FileBytes,
"message": fmt.Sprintf("%s section %q (%d chars added, %d bytes in file)", capitalize(verb), res.Section, res.CharsAdded, res.FileBytes),
}, nil
}
func (p *Provider) handleReplace(store *Store, fileLabel string, args map[string]any, caseSensitive bool) (any, error) {
substring, _ := args["substring"].(string)
replacement, _ := args["replacement"].(string)
if substring == "" {
return nil, fmt.Errorf("builtin: replace requires non-empty \"substring\"")
}
section, _ := args["section"].(string)
res, err := store.Replace(section, substring, replacement, caseSensitive)
if err != nil {
return nil, err
}
return map[string]any{
"success": true,
"file": fileLabel,
"action": "replace",
"section": res.Section,
"chars_removed": res.CharsRemoved,
"chars_added": res.CharsAdded,
"section_chars": res.SectionChars,
"file_bytes": res.FileBytes,
"message": fmt.Sprintf("Replaced %d chars with %d chars in section %q (%d bytes in file)", res.CharsRemoved, res.CharsAdded, res.Section, res.FileBytes),
}, nil
}
func (p *Provider) handleRemove(store *Store, fileLabel string, args map[string]any, caseSensitive bool) (any, error) {
substring, _ := args["substring"].(string)
if substring == "" {
return nil, fmt.Errorf("builtin: remove requires non-empty \"substring\"")
}
section, _ := args["section"].(string)
res, err := store.Remove(section, substring, caseSensitive)
if err != nil {
return nil, err
}
return map[string]any{
"success": true,
"file": fileLabel,
"action": "remove",
"section": res.Section,
"chars_removed": res.CharsRemoved,
"section_chars": res.SectionChars,
"file_bytes": res.FileBytes,
"message": fmt.Sprintf("Removed %d chars from section %q (%d bytes in file)", res.CharsRemoved, res.Section, res.FileBytes),
}, nil
}
// selectStore resolves the "file" argument to the corresponding store,
// defaulting to the memory (MEMORY.md) store.
func (p *Provider) selectStore(args map[string]any) (*Store, string, error) {