This PR refines the next-generation proxy internals and workspace
documentation:
- Reworks internal/logger to expose clearer slog-style APIs:
- Replaces Vf/Df/Wf/Ef with Info/Debug/Warn/Error.
- Adds structured key/value log arguments.
- Adds version to every log record.
- Uses standard slog level labels (DEBUG, INFO, WARN, ERROR).
- Keeps compatibility for existing printf-style messages.
- Renames proxy configuration abstractions:
- Environment → ProxyEnvironment.
- NewEnvironment → NewProxyEnvironment.
- Regenerates/renames the counterfeiter fake to FakeProxyEnvironment.
- Updates all proxy bootstrap, load balancer, protocol, signal, debug,
and utility call sites for the new logger and
environment APIs.
- Consolidates proxy codebase navigation:
- Deletes docs/proxy/proxy-files.md.
- Moves the useful file/module map details into
.openclaw/memory/srs-codebase-map.md.
- Replaces agent instruction symlinks with explicit workspace
instruction files for Claude, Codex, and Kiro.
- Updates OpenClaw tool notes with Codex commit-prefix guidance.
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
53 lines
1.0 KiB
Go
53 lines
1.0 KiB
Go
// Copyright (c) 2026 Winlin
|
|
//
|
|
// SPDX-License-Identifier: MIT
|
|
package signal
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"os/signal"
|
|
"syscall"
|
|
"time"
|
|
|
|
"srsx/internal/env"
|
|
"srsx/internal/errors"
|
|
"srsx/internal/logger"
|
|
)
|
|
|
|
// Indirections so tests can substitute signal delivery and process exit.
|
|
var (
|
|
signalNotify = signal.Notify
|
|
osExit = os.Exit
|
|
)
|
|
|
|
func InstallSignals(ctx context.Context, cancel context.CancelFunc) {
|
|
sc := make(chan os.Signal, 1)
|
|
signalNotify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
|
|
|
|
go func() {
|
|
for s := range sc {
|
|
logger.Debug(ctx, "Got signal %v", s)
|
|
cancel()
|
|
}
|
|
}()
|
|
}
|
|
|
|
func InstallForceQuit(ctx context.Context, environment env.ProxyEnvironment) error {
|
|
var forceTimeout time.Duration
|
|
timeoutStr := environment.ForceQuitTimeout()
|
|
if t, err := time.ParseDuration(timeoutStr); err != nil {
|
|
return errors.Wrapf(err, "parse force timeout %v", timeoutStr)
|
|
} else {
|
|
forceTimeout = t
|
|
}
|
|
|
|
go func() {
|
|
<-ctx.Done()
|
|
time.Sleep(forceTimeout)
|
|
logger.Warn(ctx, "Force to exit by timeout")
|
|
osExit(1)
|
|
}()
|
|
return nil
|
|
}
|