mirror of
https://github.com/Twigpine/zero.git
synced 2026-11-11 23:40:28 -10:00
* chore: remove code unreachable on every supported platform The Security and code health job's advisory deadcode step reports 152 unreachable functions on main. Running the same check under GOOS=linux, windows, and darwin shows 13 of those are false positives whose callers live in windows build-tagged files, so only functions unreachable on all three platforms are touched. Functions with no references anywhere are deleted, including the internal/reasoning package, which nothing imports. Functions that only tests reference move into per-package export_test.go files so tests keep their seams while the production binary sheds the code. Test call sites of deleted convenience wrappers are ported to the live APIs (scoped tool constructors, tools.DeferredSource, FinishReason checks). Kept despite the report: cron.Store.Runs (only reader of runs.jsonl, which production writes), and agenteval.TraceEventKeys and MissingTraceEvents (used across packages by the trace contract test). * docs(config): correct ValidateFile's errors.As claim Message is a flattened string (.Error() already called on the parse error), not a wrapped error, so callers can't recover the concrete json error type via errors.As. Fix the comment to match. Co-Authored-By: Claude Sonnet 5 <[email protected]> * chore(trace,skills): drop obsolete Sink adapters and fix stale doc references The dead-code pass removed the Emit methods but left Sink, NDJSONSink, and TextSink exported with a contract nothing implements; remove the types with their contract. Also remove the stray blank line at EOF of trace.go flagged by gofmt, and update skills package docs and HOW_ZERO_WORKS.md to stop directing callers to DiscoveryRoots/Duplicates, which are now test seams. Co-Authored-By: Claude Fable 5 <[email protected]> * chore: clean up remaining review nits on dead code removal Replace a pointless fmt.Errorf(...%w...).Error() with fmt.Sprintf using %v, since the wrapped error was discarded immediately anyway. Remove a comment block that was duplicated verbatim. * docs(skills): drop remaining references to test-only List/Get Load and MergedSkills comments still named List/Get as production entry points after they moved to export_test.go. Point callers at Load and ListFromRoots instead. * chore: remove now-unreferenced export_test.go seams execSessionManager.len() and likelySandboxDenied/sandboxDenialKind had no remaining callers after the sandbox unify-command-execution rebase; the production code they wrapped for tests no longer exists. --------- Co-authored-by: Claude Sonnet 5 <[email protected]>
73 lines
2.6 KiB
Go
73 lines
2.6 KiB
Go
// Test seams: helpers only test code uses, kept out of the production binary.
|
|
package config
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
// ToolsOverride builds a ToolsConfig that explicitly overrides the deferred-tool
|
|
// threshold (including to 0, which disables deferral). Use this for programmatic
|
|
// Overrides — a bare ToolsConfig{DeferThreshold: 0} is indistinguishable from
|
|
// "unset" and will not override.
|
|
func ToolsOverride(deferThreshold int) ToolsConfig {
|
|
return ToolsConfig{DeferThreshold: deferThreshold, deferThresholdSet: true}
|
|
}
|
|
|
|
// ValidateFile reads and parses path as a Zero FileConfig and runs the same
|
|
// semantic provider/model rules used during resolution. It returns the parsed
|
|
// config (zero value on parse failure) plus any structured issues. A parse
|
|
// failure yields a single issue whose Message is the underlying JSON error's
|
|
// text (already flattened via Error(), not chained — callers cannot recover
|
|
// the original *json.SyntaxError / *json.UnmarshalTypeError via errors.As).
|
|
func ValidateFile(path string) (FileConfig, []Issue) {
|
|
data, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return FileConfig{}, []Issue{{Message: fmt.Sprintf("read config %s: %v", path, err)}}
|
|
}
|
|
|
|
var cfg FileConfig
|
|
if err := json.Unmarshal(data, &cfg); err != nil {
|
|
return FileConfig{}, []Issue{{Message: fmt.Sprintf("invalid config JSON %s: %v", path, err)}}
|
|
}
|
|
|
|
issues := validateSemantics(cfg)
|
|
issues = append(issues, unknownFieldIssues(data)...)
|
|
return cfg, issues
|
|
}
|
|
|
|
// SetProviderDescription sets a provider's description VERBATIM — including to
|
|
// empty. The generic UpsertProvider merge treats empty fields as "leave
|
|
// unchanged", so clearing a description needs this dedicated setter.
|
|
func SetProviderDescription(path string, name string, description string) (FileConfig, error) {
|
|
path = strings.TrimSpace(path)
|
|
if path == "" {
|
|
return FileConfig{}, fmt.Errorf("config path is required")
|
|
}
|
|
name = strings.TrimSpace(name)
|
|
if name == "" {
|
|
return FileConfig{}, fmt.Errorf("provider name is required")
|
|
}
|
|
|
|
data, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return FileConfig{}, fmt.Errorf("read config %s: %w", path, err)
|
|
}
|
|
cfg := FileConfig{}
|
|
if err := json.Unmarshal(data, &cfg); err != nil {
|
|
return FileConfig{}, fmt.Errorf("invalid config JSON %s: %w", path, err)
|
|
}
|
|
for index := range cfg.Providers {
|
|
if strings.EqualFold(strings.TrimSpace(cfg.Providers[index].Name), name) {
|
|
cfg.Providers[index].Description = strings.TrimSpace(description)
|
|
if err := writeConfigFile(path, cfg); err != nil {
|
|
return FileConfig{}, err
|
|
}
|
|
return cfg, nil
|
|
}
|
|
}
|
|
return FileConfig{}, fmt.Errorf("provider %q not found", name)
|
|
}
|