This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
# situation
|
||||
|
||||
**Owns:** Situation and focus binding semantics.
|
||||
|
||||
See `architecture/architecture-registry.yaml` for allowed dependencies and DB schema.
|
||||
|
||||
This module may not write another owner's canonical state. Domain code does not import adapters/runtime/providers.
|
||||
@@ -0,0 +1,3 @@
|
||||
package application
|
||||
|
||||
// Package application coordinates situation-owned use cases through explicit ports.
|
||||
@@ -0,0 +1,3 @@
|
||||
package domain
|
||||
|
||||
// Package domain contains situation domain meaning only. It must not import adapters or runtime packages.
|
||||
@@ -0,0 +1,60 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
contract "git.cin.su/m/Assistant/contracts/situation"
|
||||
"git.cin.su/m/Assistant/contracts/work"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrNoActiveFocus = errors.New("no active focus binding")
|
||||
ErrStaleFocus = errors.New("stale focus binding")
|
||||
ErrAmbiguousFocus = errors.New("ambiguous focus binding")
|
||||
ErrTargetMismatch = errors.New("proposed target does not match resolved focus")
|
||||
)
|
||||
|
||||
// Resolver is a deterministic situation-owned resolver. It accepts runtime
|
||||
// bindings only; RequestText must never be used to select a project.
|
||||
type Resolver struct {
|
||||
bindings []contract.FocusBinding
|
||||
}
|
||||
|
||||
func NewResolver(bindings []contract.FocusBinding) Resolver {
|
||||
return Resolver{bindings: append([]contract.FocusBinding(nil), bindings...)}
|
||||
}
|
||||
|
||||
func (r Resolver) Resolve(runtime contract.RuntimeBinding) (contract.FocusBinding, error) {
|
||||
var matches []contract.FocusBinding
|
||||
var stale bool
|
||||
for _, binding := range r.bindings {
|
||||
if binding.SessionID != runtime.SessionID || binding.Workspace != runtime.Workspace {
|
||||
continue
|
||||
}
|
||||
if !binding.Active {
|
||||
stale = true
|
||||
continue
|
||||
}
|
||||
matches = append(matches, binding)
|
||||
}
|
||||
switch len(matches) {
|
||||
case 0:
|
||||
if stale {
|
||||
return contract.FocusBinding{}, ErrStaleFocus
|
||||
}
|
||||
return contract.FocusBinding{}, ErrNoActiveFocus
|
||||
case 1:
|
||||
return matches[0], nil
|
||||
default:
|
||||
return contract.FocusBinding{}, ErrAmbiguousFocus
|
||||
}
|
||||
}
|
||||
|
||||
// ValidateTaskTarget prevents cognition from redirecting a request outside the
|
||||
// resolved situation before a work owner considers its own revision guard.
|
||||
func ValidateTaskTarget(focus contract.FocusBinding, target work.TaskTarget) error {
|
||||
if focus.GoalID != target.GoalID || focus.ScopeID != target.ScopeID {
|
||||
return ErrTargetMismatch
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package situation
|
||||
|
||||
// Module is an intentionally minimal V1 composition handle. Do not turn it into a God service.
|
||||
type Module struct{}
|
||||
@@ -0,0 +1,3 @@
|
||||
package ports
|
||||
|
||||
// Package ports declares situation-owned external dependencies. Ports must be narrow and semantic.
|
||||
Reference in New Issue
Block a user