feat: Phase 9 gaps closed — ApprovalService.Decide convergence, execlog fold, execworker poller
- ApprovalService (core/app/approval.go) + ApprovalRepo (postgres adapter) with
full decide transaction: HMAC token verify, approval flip, execution un-gate,
session-scoped window keys (+session suffix matching GovernanceStore gate),
nomos session flip, audit+event on failure abort. httpapi DecideApproval now
a thin presenter delegating to the service. ListPending payload format fixed
(json.Unmarshal not raw-wrap).
- execlog folded into postgres adapter: internal/execlog deleted, NewExecutionLog
/ ReadExecutionLog live in the db package, callers updated (mcp, httpapi).
- execworker poller over ExecutionService.DispatchQueued: advisory lock leak
fixed (defer/recover per execution), correlation_id preserved via Finalize
event emission (ExecRunRepo.Finalize now emits execution.{status} with
correlation_id from the row).
- Phase 8 session export-rename completed: Store, New, and all 53 methods
exported; cmd/nomos/ agent.go fixed to use session.PendingContinuation etc.
- Coverage gates: ExecutionService.Submit 93.1%, PolicyService.Decide 100%.
- Plans index updated, VERSION bumped to 0.36.0.
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/dtoro/oikos/internal/core/domain"
|
||||
@@ -19,10 +20,10 @@ import (
|
||||
// (MCP `run`/`docker_exec` tools, and any future REST surface) converge
|
||||
// here — one policy, one audit trail (plan §4.A).
|
||||
type ExecutionService struct {
|
||||
policy *PolicyService
|
||||
exec ports.CommandExecutor
|
||||
resolver ports.TargetResolver
|
||||
recorder ports.ExecutionRecorder
|
||||
policy *PolicyService
|
||||
exec ports.CommandExecutor
|
||||
resolver ports.TargetResolver
|
||||
recorder ports.ExecutionRecorder
|
||||
}
|
||||
|
||||
// NewExecutionService wires the service.
|
||||
@@ -199,6 +200,31 @@ func (s *ExecutionService) finalize(ctx context.Context, execID domain.UUID, sta
|
||||
}
|
||||
}
|
||||
|
||||
// DispatchQueued runs a previously-recorded queued execution (status
|
||||
// 'proposed' or 'approved') over the CommandExecutor port. The command is
|
||||
// derived from the execution's action column the same way the legacy worker
|
||||
// did: "action_name:{json_params}" extracts params["command"], else the
|
||||
// action string is the raw command. Used by the execworker poller adapter.
|
||||
func (s *ExecutionService) DispatchQueued(ctx context.Context, execID domain.UUID, targetSlug, action string) (string, error) {
|
||||
return s.dispatch(ctx, execID, targetSlug, queuedCommand(action), nil, nil)
|
||||
}
|
||||
|
||||
// queuedCommand extracts the actual shell command from an execution's action
|
||||
// column. Format: "action_name:{json_params}" → params["command"]; otherwise
|
||||
// the action string is itself the raw command.
|
||||
func queuedCommand(action string) string {
|
||||
if idx := strings.Index(action, ":"); idx > 0 && idx < len(action)-1 {
|
||||
rawParams := action[idx+1:]
|
||||
var params map[string]any
|
||||
if json.Unmarshal([]byte(rawParams), ¶ms) == nil {
|
||||
if c, ok := params["command"].(string); ok && c != "" {
|
||||
return c
|
||||
}
|
||||
}
|
||||
}
|
||||
return action
|
||||
}
|
||||
|
||||
func jsonOutBytes(out string) []byte {
|
||||
b, _ := json.Marshal(map[string]any{"output": out})
|
||||
return b
|
||||
|
||||
Reference in New Issue
Block a user