MCPcopy Create free account
hub / github.com/Chat2AnyLLM/code-agent-manager / Plan

Function Plan

internal/tools/configwriter.go:27–59  ·  view source on GitHub ↗

Plan resolves all placeholders and returns the ordered list of writes without touching disk. Used by --dry-run and Apply alike.

(tool Tool, endpoint providers.Endpoint, endpointName, model, apiKey string)

Source from the content-addressed store, hash-verified

25// Plan resolves all placeholders and returns the ordered list of writes
26// without touching disk. Used by --dry-run and Apply alike.
27func Plan(tool Tool, endpoint providers.Endpoint, endpointName, model, apiKey string) ([]PlannedWrite, error) {
28 if tool.ConfigTarget == nil {
29 return nil, nil
30 }
31 ct := tool.ConfigTarget
32
33 out := make([]PlannedWrite, 0, len(ct.Upsert)+len(ct.Remove))
34
35 // Upserts.
36 for rawKey, rawValue := range ct.Upsert {
37 // Never clobber an existing credential with a blank value: when a value
38 // template is the API-key placeholder but no key is configured, skip the
39 // write entirely so the agent's config keeps whatever token it already
40 // has (writing "" would wipe a working key/token).
41 if strings.Contains(rawValue, "{api_key}") && strings.TrimSpace(apiKey) == "" {
42 continue
43 }
44 key := expandConfigPlaceholders(rawKey, endpoint, endpointName, model, apiKey)
45 value := expandConfigPlaceholders(rawValue, endpoint, endpointName, model, apiKey)
46 out = append(out, PlannedWrite{KeyPath: key, Value: coerceScalar(value), Op: "upsert"})
47 }
48
49 // Removes.
50 for _, rawKey := range ct.Remove {
51 key := expandConfigPlaceholders(rawKey, endpoint, endpointName, model, apiKey)
52 out = append(out, PlannedWrite{KeyPath: key, Value: nil, Op: "remove"})
53 }
54
55 sort.Slice(out, func(i, j int) bool {
56 return out[i].KeyPath < out[j].KeyPath
57 })
58 return out, nil
59}
60
61// expandConfigPlaceholders substitutes the five recognised placeholders. It
62// is a superset of expandPlaceholders in launch.go (adds {endpoint_name} and

Calls 2

expandConfigPlaceholdersFunction · 0.85
coerceScalarFunction · 0.85