This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
# artifact
|
||||
|
||||
**Owns:** Artifact metadata and lineage 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 artifact-owned use cases through explicit ports.
|
||||
@@ -0,0 +1,3 @@
|
||||
package domain
|
||||
|
||||
// Package domain contains artifact domain meaning only. It must not import adapters or runtime packages.
|
||||
@@ -0,0 +1,4 @@
|
||||
package artifact
|
||||
|
||||
// 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 artifact-owned external dependencies. Ports must be narrow and semantic.
|
||||
@@ -0,0 +1,7 @@
|
||||
# authority
|
||||
|
||||
**Owns:** Scope and authority grant/validation 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 authority-owned use cases through explicit ports.
|
||||
@@ -0,0 +1,22 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"git.cin.su/m/Assistant/contracts/authority"
|
||||
"git.cin.su/m/Assistant/contracts/identity"
|
||||
)
|
||||
|
||||
var ErrInvalidCreatorGrant = errors.New("creator grant must be active, global, and revisioned")
|
||||
|
||||
// ValidateCreatorGrant validates the narrow bootstrap authority used by
|
||||
// Domovoy. Execution paths must still perform their own target/revision checks.
|
||||
func ValidateCreatorGrant(binding identity.PrincipalBinding, scope authority.Scope, grant authority.AuthorityGrant) error {
|
||||
if binding.ActorID == "" || binding.PrincipalID == "" || !binding.Active ||
|
||||
!scope.Global || scope.ID == "" ||
|
||||
grant.ID == "" || grant.Class != authority.GrantClassCreator || !grant.Active || grant.Revision == 0 ||
|
||||
grant.ActorID != binding.ActorID || grant.PrincipalID != binding.PrincipalID || grant.ScopeID != scope.ID {
|
||||
return ErrInvalidCreatorGrant
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
package domain
|
||||
|
||||
// Package domain contains authority domain meaning only. It must not import adapters or runtime packages.
|
||||
@@ -0,0 +1,19 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"git.cin.su/m/Assistant/contracts/authority"
|
||||
"git.cin.su/m/Assistant/contracts/identity"
|
||||
)
|
||||
|
||||
var ErrInvalidGrant = errors.New("authority grant is not currently valid for actor, principal, and scope")
|
||||
|
||||
func ValidateGrant(binding identity.PrincipalBinding, scope authority.Scope, grant authority.AuthorityGrant) error {
|
||||
if binding.ActorID == "" || binding.PrincipalID == "" || !binding.Active ||
|
||||
scope.ID == "" || grant.ID == "" || grant.Revision == 0 || !grant.Active ||
|
||||
grant.ActorID != binding.ActorID || grant.PrincipalID != binding.PrincipalID || grant.ScopeID != scope.ID {
|
||||
return ErrInvalidGrant
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package authority
|
||||
|
||||
// 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 authority-owned external dependencies. Ports must be narrow and semantic.
|
||||
@@ -0,0 +1,7 @@
|
||||
# capability
|
||||
|
||||
**Owns:** Capability, binding and health 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 capability-owned use cases through explicit ports.
|
||||
@@ -0,0 +1,3 @@
|
||||
package domain
|
||||
|
||||
// Package domain contains capability domain meaning only. It must not import adapters or runtime packages.
|
||||
@@ -0,0 +1,41 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"git.cin.su/m/Assistant/contracts/capability"
|
||||
)
|
||||
|
||||
var ErrInvalidHealth = errors.New("invalid capability health")
|
||||
var ErrUnsupportedHealthVersion = errors.New("unsupported capability health semantic version")
|
||||
|
||||
func ValidateHealth(health capability.Health) error {
|
||||
if health.CapabilityID == "" || health.Revision < 1 {
|
||||
return ErrInvalidHealth
|
||||
}
|
||||
switch health.SemanticVersion {
|
||||
case capability.HealthV1:
|
||||
if health.ObservedAtUnixMillis != nil {
|
||||
return ErrInvalidHealth
|
||||
}
|
||||
case capability.HealthV2:
|
||||
if health.ObservedAtUnixMillis == nil || *health.ObservedAtUnixMillis < 1 {
|
||||
return ErrInvalidHealth
|
||||
}
|
||||
default:
|
||||
return ErrUnsupportedHealthVersion
|
||||
}
|
||||
switch health.State {
|
||||
case capability.HealthAvailable:
|
||||
if health.Reason != capability.ReasonNone {
|
||||
return ErrInvalidHealth
|
||||
}
|
||||
case capability.HealthDegraded, capability.HealthUnavailable:
|
||||
if health.Reason == capability.ReasonNone || health.Reason == "" {
|
||||
return ErrInvalidHealth
|
||||
}
|
||||
default:
|
||||
return ErrInvalidHealth
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package capability
|
||||
|
||||
// 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 capability-owned external dependencies. Ports must be narrow and semantic.
|
||||
@@ -0,0 +1,13 @@
|
||||
package ports
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.cin.su/m/Assistant/contracts/capability"
|
||||
)
|
||||
|
||||
type Repository interface {
|
||||
SaveHealth(context.Context, capability.Health) error
|
||||
LoadHealth(context.Context, capability.CapabilityID) (capability.Health, error)
|
||||
RebuildHealthProjection(context.Context) (int64, error)
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
# commit
|
||||
|
||||
**Owns:** Action proposal, authorization/commit protocol and attempt records.
|
||||
|
||||
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 commit-owned use cases through explicit ports.
|
||||
@@ -0,0 +1,78 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"git.cin.su/m/Assistant/contracts/authority"
|
||||
"git.cin.su/m/Assistant/contracts/capability"
|
||||
commitcontract "git.cin.su/m/Assistant/contracts/commit"
|
||||
"git.cin.su/m/Assistant/modules/commit/ports"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrInvalidProposal = errors.New("action proposal lacks target, revision, capability, or operation")
|
||||
ErrUnknownOutcome = errors.New("unknown outcome requires reconciliation before retry")
|
||||
ErrInvalidReconciliation = errors.New("reconciliation requires the matching UNKNOWN_OUTCOME attempt and a new attempt identity")
|
||||
)
|
||||
|
||||
type AuthorizationContext = authority.AuthorizationContext
|
||||
|
||||
// Reconcile verifies an UNKNOWN_OUTCOME through a read-only external query.
|
||||
// It never invokes Executor.Execute and therefore cannot repeat the effect.
|
||||
func Reconcile(action commitcontract.AuthorizedAction, previous commitcontract.ActionAttempt, attemptID commitcontract.ActionAttemptID, reconciler ports.Reconciler) (commitcontract.ActionAttempt, error) {
|
||||
if action.State != commitcontract.ActionAuthorized || previous.State != commitcontract.ActionUnknownOutcome ||
|
||||
previous.AuthorizedID != action.ID || previous.IntentID != action.Proposal.IntentID || attemptID == "" || attemptID == previous.ID {
|
||||
return commitcontract.ActionAttempt{}, ErrInvalidReconciliation
|
||||
}
|
||||
attempt := commitcontract.ActionAttempt{ID: attemptID, AuthorizedID: action.ID, IntentID: action.Proposal.IntentID, State: commitcontract.ActionExecuting}
|
||||
result := reconciler.Reconcile(action)
|
||||
if !result.Known {
|
||||
attempt.State = commitcontract.ActionUnknownOutcome
|
||||
return attempt, ErrUnknownOutcome
|
||||
}
|
||||
if result.Succeeded {
|
||||
attempt.State = commitcontract.ActionSucceeded
|
||||
return attempt, nil
|
||||
}
|
||||
attempt.State = commitcontract.ActionFailed
|
||||
return attempt, nil
|
||||
}
|
||||
|
||||
// Authorize is the Commit boundary. A proposal alone never reaches Executor.
|
||||
func Authorize(proposal commitcontract.ActionProposal, context AuthorizationContext, validator ports.AuthorityValidator, authorizedID commitcontract.AuthorizedActionID) (commitcontract.AuthorizedAction, error) {
|
||||
if proposal.IntentID == "" || proposal.ActorID == "" || proposal.CapabilityID == capability.CapabilityID("") ||
|
||||
proposal.Target.TaskID == "" || proposal.Target.GoalID == "" || proposal.Target.ScopeID == "" || proposal.Target.Revision == 0 || proposal.Operation == "" {
|
||||
return commitcontract.AuthorizedAction{}, ErrInvalidProposal
|
||||
}
|
||||
if proposal.ActorID != context.Binding.ActorID || proposal.Target.ScopeID != context.Scope.ID {
|
||||
return commitcontract.AuthorizedAction{}, ErrInvalidProposal
|
||||
}
|
||||
if err := validator.Validate(context); err != nil {
|
||||
return commitcontract.AuthorizedAction{}, err
|
||||
}
|
||||
if authorizedID == "" {
|
||||
return commitcontract.AuthorizedAction{}, ErrInvalidProposal
|
||||
}
|
||||
proposal.State = commitcontract.ActionProposed
|
||||
return commitcontract.AuthorizedAction{ID: authorizedID, Proposal: proposal, GrantID: context.Grant.ID, ScopeID: context.Scope.ID, State: commitcontract.ActionAuthorized}, nil
|
||||
}
|
||||
|
||||
// Execute records UNKNOWN_OUTCOME rather than silently retrying an ambiguous
|
||||
// external mutation.
|
||||
func Execute(action commitcontract.AuthorizedAction, attemptID commitcontract.ActionAttemptID, executor ports.Executor) (commitcontract.ActionAttempt, error) {
|
||||
if action.State != commitcontract.ActionAuthorized || attemptID == "" {
|
||||
return commitcontract.ActionAttempt{}, ErrUnknownOutcome
|
||||
}
|
||||
attempt := commitcontract.ActionAttempt{ID: attemptID, AuthorizedID: action.ID, IntentID: action.Proposal.IntentID, State: commitcontract.ActionExecuting}
|
||||
result := executor.Execute(action)
|
||||
if !result.Known {
|
||||
attempt.State = commitcontract.ActionUnknownOutcome
|
||||
return attempt, ErrUnknownOutcome
|
||||
}
|
||||
if result.Succeeded {
|
||||
attempt.State = commitcontract.ActionSucceeded
|
||||
return attempt, nil
|
||||
}
|
||||
attempt.State = commitcontract.ActionFailed
|
||||
return attempt, nil
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
package domain
|
||||
|
||||
// Package domain contains commit domain meaning only. It must not import adapters or runtime packages.
|
||||
@@ -0,0 +1,4 @@
|
||||
package commit
|
||||
|
||||
// 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 commit-owned external dependencies. Ports must be narrow and semantic.
|
||||
@@ -0,0 +1,27 @@
|
||||
package ports
|
||||
|
||||
import (
|
||||
"git.cin.su/m/Assistant/contracts/authority"
|
||||
"git.cin.su/m/Assistant/contracts/commit"
|
||||
)
|
||||
|
||||
// Executor is the only commit-owned port permitted to reach an external world.
|
||||
// Its implementation belongs in an isolated adapter/runtime, never in domain.
|
||||
type Executor interface {
|
||||
Execute(commit.AuthorizedAction) ExecutionResult
|
||||
}
|
||||
|
||||
// Reconciler verifies an ambiguous effect without applying it again.
|
||||
type Reconciler interface {
|
||||
Reconcile(commit.AuthorizedAction) ExecutionResult
|
||||
}
|
||||
|
||||
type ExecutionResult struct {
|
||||
Succeeded bool
|
||||
Known bool
|
||||
}
|
||||
|
||||
// AuthorityValidator is the remote-capable boundary to the Authority owner.
|
||||
type AuthorityValidator interface {
|
||||
Validate(authority.AuthorizationContext) error
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
# continuity
|
||||
|
||||
**Owns:** Commitment and ProspectiveItem 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 continuity-owned use cases through explicit ports.
|
||||
@@ -0,0 +1,3 @@
|
||||
package domain
|
||||
|
||||
// Package domain contains continuity domain meaning only. It must not import adapters or runtime packages.
|
||||
@@ -0,0 +1,90 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
contract "git.cin.su/m/Assistant/contracts/continuity"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrProspectiveNotFound = errors.New("prospective item not found")
|
||||
ErrProspectiveRevision = errors.New("prospective item revision conflict")
|
||||
ErrInvalidTransition = errors.New("invalid prospective item transition")
|
||||
)
|
||||
|
||||
type Store struct {
|
||||
items map[contract.ProspectiveItemID]contract.ProspectiveItem
|
||||
}
|
||||
|
||||
func Recover(items []contract.ProspectiveItem) Store {
|
||||
stored := make(map[contract.ProspectiveItemID]contract.ProspectiveItem, len(items))
|
||||
for _, item := range items {
|
||||
stored[item.ID] = item
|
||||
}
|
||||
return Store{items: stored}
|
||||
}
|
||||
|
||||
func (s *Store) Snapshot() []contract.ProspectiveItem {
|
||||
items := make([]contract.ProspectiveItem, 0, len(s.items))
|
||||
for _, item := range s.items {
|
||||
items = append(items, item)
|
||||
}
|
||||
return items
|
||||
}
|
||||
|
||||
func (s *Store) Trigger(id contract.ProspectiveItemID, revision contract.ProspectiveRevision) (contract.ProspectiveItem, error) {
|
||||
item, err := s.current(id, revision)
|
||||
if err != nil {
|
||||
return contract.ProspectiveItem{}, err
|
||||
}
|
||||
if item.State != contract.ProspectiveArmed {
|
||||
return contract.ProspectiveItem{}, ErrInvalidTransition
|
||||
}
|
||||
item.State = contract.ProspectiveTriggered
|
||||
item.Revision++
|
||||
s.items[id] = item
|
||||
return item, nil
|
||||
}
|
||||
|
||||
func (s *Store) BeginRevalidation(id contract.ProspectiveItemID, revision contract.ProspectiveRevision) (contract.ProspectiveItem, error) {
|
||||
item, err := s.current(id, revision)
|
||||
if err != nil {
|
||||
return contract.ProspectiveItem{}, err
|
||||
}
|
||||
if item.State != contract.ProspectiveTriggered {
|
||||
return contract.ProspectiveItem{}, ErrInvalidTransition
|
||||
}
|
||||
item.State = contract.ProspectiveRevalidating
|
||||
item.Revision++
|
||||
s.items[id] = item
|
||||
return item, nil
|
||||
}
|
||||
|
||||
func (s *Store) FinishRevalidation(id contract.ProspectiveItemID, revision contract.ProspectiveRevision, relevant bool) (contract.ProspectiveItem, error) {
|
||||
item, err := s.current(id, revision)
|
||||
if err != nil {
|
||||
return contract.ProspectiveItem{}, err
|
||||
}
|
||||
if item.State != contract.ProspectiveRevalidating {
|
||||
return contract.ProspectiveItem{}, ErrInvalidTransition
|
||||
}
|
||||
if relevant {
|
||||
item.State = contract.ProspectiveDelivered
|
||||
} else {
|
||||
item.State = contract.ProspectiveSuppressed
|
||||
}
|
||||
item.Revision++
|
||||
s.items[id] = item
|
||||
return item, nil
|
||||
}
|
||||
|
||||
func (s *Store) current(id contract.ProspectiveItemID, revision contract.ProspectiveRevision) (contract.ProspectiveItem, error) {
|
||||
item, ok := s.items[id]
|
||||
if !ok {
|
||||
return contract.ProspectiveItem{}, ErrProspectiveNotFound
|
||||
}
|
||||
if item.Revision != revision {
|
||||
return contract.ProspectiveItem{}, ErrProspectiveRevision
|
||||
}
|
||||
return item, nil
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package continuity
|
||||
|
||||
// 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 continuity-owned external dependencies. Ports must be narrow and semantic.
|
||||
@@ -0,0 +1,12 @@
|
||||
package ports
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.cin.su/m/Assistant/contracts/continuity"
|
||||
)
|
||||
|
||||
type Repository interface {
|
||||
Save(context.Context, continuity.ProspectiveItem) error
|
||||
Load(context.Context, continuity.ProspectiveItemID) (continuity.ProspectiveItem, error)
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
# epistemics
|
||||
|
||||
**Owns:** Observation, Claim, Belief and Provenance 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 epistemics-owned use cases through explicit ports.
|
||||
@@ -0,0 +1,3 @@
|
||||
package domain
|
||||
|
||||
// Package domain contains epistemics domain meaning only. It must not import adapters or runtime packages.
|
||||
@@ -0,0 +1,4 @@
|
||||
package epistemics
|
||||
|
||||
// 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 epistemics-owned external dependencies. Ports must be narrow and semantic.
|
||||
@@ -0,0 +1,7 @@
|
||||
# identity
|
||||
|
||||
**Owns:** Identity, Actor and Principal 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 identity-owned use cases through explicit ports.
|
||||
@@ -0,0 +1,17 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"git.cin.su/m/Assistant/contracts/identity"
|
||||
)
|
||||
|
||||
var ErrInvalidCreatorBinding = errors.New("creator actor and principal binding must be explicit and active")
|
||||
|
||||
// ValidateCreatorBinding makes the Creator's two semantic roles explicit.
|
||||
func ValidateCreatorBinding(binding identity.PrincipalBinding) error {
|
||||
if binding.ActorID == "" || binding.PrincipalID == "" || !binding.Active {
|
||||
return ErrInvalidCreatorBinding
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
package domain
|
||||
|
||||
// Package domain contains identity domain meaning only. It must not import adapters or runtime packages.
|
||||
@@ -0,0 +1,54 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"crypto/hmac"
|
||||
"crypto/sha256"
|
||||
"crypto/subtle"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.cin.su/m/Assistant/contracts/identity"
|
||||
)
|
||||
|
||||
var ErrInvalidCreatorSession = errors.New("invalid creator session")
|
||||
|
||||
func IssueCreatorSession(secret []byte, now time.Time, ttl time.Duration) (string, identity.CreatorSession, error) {
|
||||
if len(secret) < 32 || ttl <= 0 {
|
||||
return "", identity.CreatorSession{}, ErrInvalidCreatorSession
|
||||
}
|
||||
session := identity.CreatorSession{ActorID: "domovoy-creator-actor", PrincipalID: "domovoy-creator-principal", ExpiresAtUnix: now.Add(ttl).Unix()}
|
||||
payload, err := json.Marshal(session)
|
||||
if err != nil {
|
||||
return "", identity.CreatorSession{}, err
|
||||
}
|
||||
encoded := base64.RawURLEncoding.EncodeToString(payload)
|
||||
return encoded + "." + signature(secret, encoded), session, nil
|
||||
}
|
||||
|
||||
func ValidateCreatorSession(secret []byte, token string, now time.Time) (identity.CreatorSession, error) {
|
||||
parts := strings.Split(token, ".")
|
||||
if len(parts) != 2 || len(secret) < 32 || subtle.ConstantTimeCompare([]byte(signature(secret, parts[0])), []byte(parts[1])) != 1 {
|
||||
return identity.CreatorSession{}, ErrInvalidCreatorSession
|
||||
}
|
||||
payload, err := base64.RawURLEncoding.DecodeString(parts[0])
|
||||
if err != nil {
|
||||
return identity.CreatorSession{}, ErrInvalidCreatorSession
|
||||
}
|
||||
var session identity.CreatorSession
|
||||
if json.Unmarshal(payload, &session) != nil || session.ActorID != "domovoy-creator-actor" || session.PrincipalID != "domovoy-creator-principal" || now.Unix() >= session.ExpiresAtUnix {
|
||||
return identity.CreatorSession{}, ErrInvalidCreatorSession
|
||||
}
|
||||
return session, nil
|
||||
}
|
||||
|
||||
func BootstrapMatches(expected, supplied string) bool {
|
||||
return expected != "" && supplied != "" && subtle.ConstantTimeCompare([]byte(expected), []byte(supplied)) == 1
|
||||
}
|
||||
func signature(secret []byte, payload string) string {
|
||||
mac := hmac.New(sha256.New, secret)
|
||||
mac.Write([]byte(payload))
|
||||
return base64.RawURLEncoding.EncodeToString(mac.Sum(nil))
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package identity
|
||||
|
||||
// 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 identity-owned external dependencies. Ports must be narrow and semantic.
|
||||
@@ -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.
|
||||
@@ -0,0 +1,7 @@
|
||||
# work
|
||||
|
||||
**Owns:** Goal, Task and Decision 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 work-owned use cases through explicit ports.
|
||||
@@ -0,0 +1,3 @@
|
||||
package domain
|
||||
|
||||
// Package domain contains work domain meaning only. It must not import adapters or runtime packages.
|
||||
@@ -0,0 +1,51 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"git.cin.su/m/Assistant/contracts/authority"
|
||||
contract "git.cin.su/m/Assistant/contracts/work"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrTaskNotFound = errors.New("task not found")
|
||||
ErrTaskTargetMismatch = errors.New("task target does not match canonical task")
|
||||
ErrRevisionConflict = errors.New("task revision conflict")
|
||||
)
|
||||
|
||||
type Task struct {
|
||||
ID contract.TaskID
|
||||
GoalID contract.GoalID
|
||||
ScopeID authority.ScopeID
|
||||
Revision contract.TaskRevision
|
||||
}
|
||||
|
||||
// Store models owner-local task state for the walking skeleton. A caller must
|
||||
// present all target integrity fields; no cross-owner lookup is performed.
|
||||
type Store struct {
|
||||
tasks map[contract.TaskID]Task
|
||||
}
|
||||
|
||||
func NewStore(tasks []Task) Store {
|
||||
stored := make(map[contract.TaskID]Task, len(tasks))
|
||||
for _, task := range tasks {
|
||||
stored[task.ID] = task
|
||||
}
|
||||
return Store{tasks: stored}
|
||||
}
|
||||
|
||||
func (s *Store) Commit(target contract.TaskTarget) (Task, error) {
|
||||
task, ok := s.tasks[target.TaskID]
|
||||
if !ok {
|
||||
return Task{}, ErrTaskNotFound
|
||||
}
|
||||
if task.GoalID != target.GoalID || task.ScopeID != target.ScopeID {
|
||||
return Task{}, ErrTaskTargetMismatch
|
||||
}
|
||||
if task.Revision != target.Revision {
|
||||
return Task{}, ErrRevisionConflict
|
||||
}
|
||||
task.Revision++
|
||||
s.tasks[task.ID] = task
|
||||
return task, nil
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package work
|
||||
|
||||
// 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 work-owned external dependencies. Ports must be narrow and semantic.
|
||||
Reference in New Issue
Block a user