- Introduce `-config-overlay` flag and `config.LoadOverlay()` to merge a base config with an overlay file, only overriding fields the overlay sets. This enables docker-compose to mount the base config from the host and apply only deployment-specific overrides. - Create `internal/natsrpc` package with reusable NATS request/reply primitives (Envelope, Client, Call, RegisterAll, Respond). Migrate storerpc, worktreerpc, and forgerpc to use it, eliminating duplicated marshal/unmarshal and error handling. - Create `internal/yaegiutil` package with shared interpreter construction (stdlib + extra symbols), generic export resolution (Resolve), and panic recovery (Safe). Migrate all Yaegi-based surfaces (gate scripts, daemon plugins, skill plugins, workflow stages, skill scripts) to use it, reducing boilerplate and centralizing panic safety. - Simplify `config.docker.toml` to contain only overlay fields (paths, container config) and remove the duplicated repos list – the base config is now the single source of truth. - Update docker-compose.yml to pass both -config and -config-overlay flags and mount the base config from the host. - Add tests for LoadOverlay, DockerConfigOverlaysExampleConfig, Envelope, and yaegiutil utilities.
51 lines
1.7 KiB
Go
51 lines
1.7 KiB
Go
// Package gateeval evaluates a repo's .archie/gate.go via Yaegi. Split
|
|
// from internal/gate (which only declares the GateContext/Finding types)
|
|
// because the generated symbol table in gateextract imports internal/gate —
|
|
// this package sits above both to avoid the resulting import cycle.
|
|
package gateeval
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"github.com/traefik/yaegi/interp"
|
|
|
|
"github.com/samcharles93/archie-core/internal/gate"
|
|
"github.com/samcharles93/archie-core/internal/gate/gateextract"
|
|
"github.com/samcharles93/archie-core/internal/yaegiutil"
|
|
)
|
|
|
|
// scriptPath is the per-repo custom gate script, relative to the
|
|
// worktree root.
|
|
const scriptPath = ".archie/gate.go"
|
|
|
|
// Evaluate loads and runs the repo's .archie/gate.go against gctx. A
|
|
// missing script is not an error — it returns (nil, nil), meaning no
|
|
// custom gate is configured for this repo. The script runs in-process
|
|
// (interpreted, not sandboxed), so a panic inside it — nil dereference,
|
|
// out-of-range index — is recovered and returned as an error rather than
|
|
// taking down the daemon.
|
|
func Evaluate(gctx gate.GateContext) ([]gate.Finding, error) {
|
|
src, err := os.ReadFile(filepath.Join(gctx.Dir, scriptPath))
|
|
if err != nil {
|
|
if errors.Is(err, os.ErrNotExist) {
|
|
return nil, nil
|
|
}
|
|
return nil, fmt.Errorf("read %s: %w", scriptPath, err)
|
|
}
|
|
|
|
return yaegiutil.Safe(scriptPath, func() ([]gate.Finding, error) {
|
|
i, err := yaegiutil.New(interp.Options{}, gateextract.Symbols)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
check, err := yaegiutil.Resolve[func(gate.GateContext) []gate.Finding](i, string(src), "gate.Check")
|
|
if err != nil {
|
|
return nil, fmt.Errorf("%s: %w", scriptPath, err)
|
|
}
|
|
return check(gctx), nil
|
|
})
|
|
}
|