domain

package
v0.1.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 22, 2026 License: MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package domain defines the versioned, text-persisted project records.

Package domain — work item status state machine (§6).

The state machine is conservative: transitions that lower completion ("completed" → earlier) are reserved for the repair path; the normal path only walks forward or steps sideways (blocked ↔ resume). Terminal states reject any further transition except a repair.

Index

Constants

View Source
const (
	StatusDraft   = "draft"
	StatusBacklog = "backlog"
	StatusReady   = "ready"
	// StatusRetryQueued is the state a failed or stalled attempt returns to
	// while it waits for its next attempt (方案 §15.4).
	StatusRetryQueued  = "retry_queued"
	StatusInProgress   = "in_progress"
	StatusBlocked      = "blocked"
	StatusReview       = "review"
	StatusVerification = "verification"
	StatusDone         = "done"
	StatusCancelled    = "cancelled"
)

Work item status values (§6.1). All nine are valid; Create allows a restricted subset (UnclaimedInitial), Transition enforces the graph below.

View Source
const (
	SchedulingUnclaimed   = "unclaimed"
	SchedulingClaimed     = "claimed"
	SchedulingRunning     = "running"
	SchedulingRetryQueued = "retry_queued"
	SchedulingReleased    = "released"
)

Scheduling states (§6.4): separate from the work item status. The lease files under .devsys/scheduling/<id>.mirror of "claimed/running" while unclaimed/released map to absence.

View Source
const SchemaVersion = 1

Variables

UnclaimedInitial lists statuses a Create call may use as the initial status. These all map to the unclaimed scheduling state (§6.4 table).

Functions

func AllStatuses

func AllStatuses() []string

AllStatuses lists every defined status for validation.

func AllowedFrom

func AllowedFrom(current string) []string

AllowedFrom lists every legal next status from current, sorted. Used to build the "allowed: [a, b, c]" hint on transition errors.

func DecodeJSON

func DecodeJSON(data []byte, v any) error

func DecodeYAML

func DecodeYAML(data []byte, v any) error

func EncodeJSON

func EncodeJSON(v any) ([]byte, error)

func EncodeYAML

func EncodeYAML(v any) ([]byte, error)

EncodeYAML preserves null collections as well as empty collections. yaml.v3's default slice encoding conflates them, which would lose record information.

func IsResumeLegal

func IsResumeLegal(from, to, previous string) bool

IsResumeLegal checks the blocked → previous-completion edge: from blocked, resuming into the status the work item held when it was blocked is legal regardless of the static graph. Other blocked targets must come from IsTransitionLegal.

func IsTerminal

func IsTerminal(status string) bool

IsTerminal reports whether status is a terminal state (no normal outgoing edges). Used by Create to forbid initial states that don't exist.

func IsTransitionLegal

func IsTransitionLegal(from, to string) bool

IsTransitionLegal reports whether from → to is allowed by the conservative graph. blocked is special-cased via IsResumeLegal.

Types

type Approval

type Approval struct {
	SchemaVersion int    `json:"schema_version" yaml:"schema_version"`
	ID            string `json:"id" yaml:"id"`
	ProjectID     string `json:"project_id" yaml:"project_id"`
	Scope         string `json:"scope" yaml:"scope"`
	// Stage is the gate stage this approval targets (required for
	// scope=stage_gate; 方案 §4.9 门禁阶段).
	Stage string `json:"stage" yaml:"stage"`
	// RequestedStatus is the work item status when the approval was
	// requested. The approval is only valid while the work item is still in
	// that status: leaving the stage invalidates it (方案 §4.9).
	RequestedStatus string     `json:"requested_status" yaml:"requested_status"`
	WorkItemID      string     `json:"workitem_id" yaml:"workitem_id"`
	RunID           *string    `json:"run_id" yaml:"run_id"`
	RequestedBy     string     `json:"requested_by" yaml:"requested_by"`
	RequestedAt     time.Time  `json:"requested_at" yaml:"requested_at"`
	Status          string     `json:"status" yaml:"status"`
	DecidedBy       *string    `json:"decided_by" yaml:"decided_by"`
	DecidedAt       *time.Time `json:"decided_at" yaml:"decided_at"`
	Comment         *string    `json:"comment" yaml:"comment"`
	ConsumedAt      *time.Time `json:"consumed_at" yaml:"consumed_at"`
	// InvalidatedAt marks an unconsumed approval whose request stage was
	// left; such an approval can never be decided into use or consumed, and a
	// re-entered stage needs a fresh request (方案 §4.9).
	InvalidatedAt *time.Time `json:"invalidated_at" yaml:"invalidated_at"`
	CreatedAt     time.Time  `json:"created_at" yaml:"created_at"`
	UpdatedAt     time.Time  `json:"updated_at" yaml:"updated_at"`
}

type Artifact

type Artifact struct {
	SchemaVersion    int       `json:"schema_version" yaml:"schema_version"`
	ID               string    `json:"id" yaml:"id"`
	ProjectID        string    `json:"project_id" yaml:"project_id"`
	Type             string    `json:"type" yaml:"type"`
	Name             string    `json:"name" yaml:"name"`
	Path             string    `json:"path" yaml:"path"`
	Source           string    `json:"source" yaml:"source"`
	CreatedByRunID   string    `json:"created_by_run_id" yaml:"created_by_run_id"`
	Status           string    `json:"status" yaml:"status"`
	Version          int       `json:"version" yaml:"version"`
	PreviousID       *string   `json:"previous_id" yaml:"previous_id"`
	RelatedWorkItems []string  `json:"related_workitems" yaml:"related_workitems"`
	CreatedAt        time.Time `json:"created_at" yaml:"created_at"`
	UpdatedAt        time.Time `json:"updated_at" yaml:"updated_at"`
}

type Claim

type Claim struct {
	HeadSHA     string     `json:"head_sha" yaml:"head_sha"`
	ClaimedAt   *time.Time `json:"claimed_at" yaml:"claimed_at"`
	LeaseUntil  *time.Time `json:"lease_until" yaml:"lease_until"`
	HeartbeatAt *time.Time `json:"heartbeat_at" yaml:"heartbeat_at"`
}

type ContextSnapshot

type ContextSnapshot struct {
	ProjectStateVersion int      `json:"project_state_version" yaml:"project_state_version"`
	WorkItemVersion     int      `json:"workitem_version" yaml:"workitem_version"`
	ArtifactVersions    []string `json:"artifact_versions" yaml:"artifact_versions"`
	KnowledgeRevision   string   `json:"knowledge_revision" yaml:"knowledge_revision"`
	WorkspaceHead       string   `json:"workspace_head" yaml:"workspace_head"`
	DecisionIDs         []string `json:"decision_ids" yaml:"decision_ids"`
}

ContextSnapshot records what the agent actually saw when a run started (方案 §11.3): the versions of everything the run's context was built from, so later reads can reconstruct the view and trace stale-context errors.

type CurrentState

type CurrentState struct {
	Summary   string   `json:"summary" yaml:"summary"`
	Risks     []string `json:"risks" yaml:"risks"`
	Blockers  []string `json:"blockers" yaml:"blockers"`
	NextFocus []string `json:"next_focus" yaml:"next_focus"`
}

type CurrentStateFile

type CurrentStateFile struct {
	SchemaVersion int `json:"schema_version" yaml:"schema_version"`
	CurrentState  `json:",inline" yaml:",inline"`
}

type Decision

type Decision struct {
	SchemaVersion    int       `json:"schema_version" yaml:"schema_version"`
	ID               string    `json:"id" yaml:"id"`
	ProjectID        string    `json:"project_id" yaml:"project_id"`
	Title            string    `json:"title" yaml:"title"`
	Context          string    `json:"context" yaml:"context"`
	Options          []string  `json:"options" yaml:"options"`
	Decision         string    `json:"decision" yaml:"decision"`
	Reasoning        string    `json:"reasoning" yaml:"reasoning"`
	Consequences     []string  `json:"consequences" yaml:"consequences"`
	Status           string    `json:"status" yaml:"status"`
	CreatedBy        string    `json:"created_by" yaml:"created_by"`
	ApprovedBy       string    `json:"approved_by" yaml:"approved_by"`
	RelatedWorkItems []string  `json:"related_workitems" yaml:"related_workitems"`
	CreatedAt        time.Time `json:"created_at" yaml:"created_at"`
}

type Event

type Event struct {
	SchemaVersion int         `json:"schema_version" yaml:"schema_version"`
	ID            string      `json:"id" yaml:"id"`
	ProjectID     string      `json:"project_id" yaml:"project_id"`
	Type          string      `json:"type" yaml:"type"`
	Subject       Reference   `json:"subject" yaml:"subject"`
	Time          time.Time   `json:"time" yaml:"time"`
	Actor         string      `json:"actor" yaml:"actor"`
	Related       []Reference `json:"related" yaml:"related"`
	Content       string      `json:"content" yaml:"content"`
	ReplyTo       *string     `json:"reply_to" yaml:"reply_to"`
}

type Finding

type Finding struct {
	SchemaVersion      int      `json:"schema_version" yaml:"schema_version"`
	ID                 string   `json:"id" yaml:"id"`
	ProjectID          string   `json:"project_id" yaml:"project_id"`
	Type               string   `json:"type" yaml:"type"`
	Title              string   `json:"title" yaml:"title"`
	Description        string   `json:"description" yaml:"description"`
	Evidence           []string `json:"evidence" yaml:"evidence"`
	Severity           string   `json:"severity" yaml:"severity"`
	Status             string   `json:"status" yaml:"status"`
	DiscoveredByRunID  string   `json:"discovered_by_run_id" yaml:"discovered_by_run_id"`
	RelatedWorkItems   []string `json:"related_workitems" yaml:"related_workitems"`
	RecommendedActions []string `json:"recommended_actions" yaml:"recommended_actions"`
}

type Milestone

type Milestone struct {
	ID     string `json:"id" yaml:"id"`
	Name   string `json:"name" yaml:"name"`
	Status string `json:"status" yaml:"status"`
}

type MilestonesFile

type MilestonesFile struct {
	SchemaVersion int         `json:"schema_version" yaml:"schema_version"`
	Milestones    []Milestone `json:"milestones" yaml:"milestones"`
}

type Project

type Project struct {
	SchemaVersion       int          `json:"schema_version" yaml:"schema_version"`
	ID                  string       `json:"id" yaml:"id"`
	Name                string       `json:"name" yaml:"name"`
	Description         string       `json:"description" yaml:"description"`
	Status              string       `json:"status" yaml:"status"`
	CurrentPhase        string       `json:"current_phase" yaml:"current_phase"`
	Goals               []string     `json:"goals" yaml:"goals"`
	Scope               Scope        `json:"scope" yaml:"scope"`
	Constraints         []string     `json:"constraints" yaml:"constraints"`
	TechStack           []string     `json:"tech_stack" yaml:"tech_stack"`
	Milestones          []Milestone  `json:"milestones" yaml:"milestones"`
	CurrentState        CurrentState `json:"current_state" yaml:"current_state"`
	BlueprintArtifactID string       `json:"blueprint_artifact_id" yaml:"blueprint_artifact_id"`
	CreatedAt           time.Time    `json:"created_at" yaml:"created_at"`
	UpdatedAt           time.Time    `json:"updated_at" yaml:"updated_at"`
}

type Reference

type Reference struct {
	Type string `json:"type" yaml:"type"`
	ID   string `json:"id" yaml:"id"`
}

type Run

type Run struct {
	SchemaVersion    int              `json:"schema_version" yaml:"schema_version"`
	ID               string           `json:"id" yaml:"id"`
	ProjectID        string           `json:"project_id" yaml:"project_id"`
	WorkItemID       string           `json:"workitem_id" yaml:"workitem_id"`
	WorkflowID       string           `json:"workflow_id" yaml:"workflow_id"`
	Agent            RunAgent         `json:"agent" yaml:"agent"`
	Workspace        Workspace        `json:"workspace" yaml:"workspace"`
	Claim            Claim            `json:"claim" yaml:"claim"`
	Verification     Verification     `json:"verification" yaml:"verification"`
	Status           string           `json:"status" yaml:"status"`
	Attempt          int              `json:"attempt" yaml:"attempt"`
	Phase            string           `json:"phase" yaml:"phase"`
	StartedAt        time.Time        `json:"started_at" yaml:"started_at"`
	FinishedAt       *time.Time       `json:"finished_at" yaml:"finished_at"`
	InputContextRefs []string         `json:"input_context_refs" yaml:"input_context_refs"`
	ChangedFiles     []string         `json:"changed_files" yaml:"changed_files"`
	Commands         []string         `json:"commands" yaml:"commands"`
	Tests            []string         `json:"tests" yaml:"tests"`
	Logs             []string         `json:"logs" yaml:"logs"`
	Result           RunResult        `json:"result" yaml:"result"`
	RetryCount       int              `json:"retry_count" yaml:"retry_count"`
	ContextSnapshot  *ContextSnapshot `json:"context_snapshot" yaml:"context_snapshot"`
}

type RunAgent

type RunAgent struct {
	ID      string `json:"id" yaml:"id"`
	Harness string `json:"harness" yaml:"harness"`
	Model   string `json:"model" yaml:"model"`
}

type RunResult

type RunResult struct {
	Summary           *string  `json:"summary" yaml:"summary"`
	Errors            []string `json:"errors" yaml:"errors"`
	Findings          []string `json:"findings" yaml:"findings"`
	Decisions         []string `json:"decisions" yaml:"decisions"`
	FollowUpWorkItems []string `json:"follow_up_workitems" yaml:"follow_up_workitems"`
}

type SchedulingLease

type SchedulingLease struct {
	SchemaVersion int       `json:"schema_version" yaml:"schema_version"`
	WorkItemID    string    `json:"workitem_id" yaml:"workitem_id"`
	Owner         string    `json:"owner" yaml:"owner"`
	Token         string    `json:"token" yaml:"token"`
	ClaimedAt     time.Time `json:"claimed_at" yaml:"claimed_at"`
	LeaseUntil    time.Time `json:"lease_until" yaml:"lease_until"`
	HeartbeatAt   time.Time `json:"heartbeat_at" yaml:"heartbeat_at"`
	HeadSHA       string    `json:"head_sha" yaml:"head_sha"`
	RunID         string    `json:"run_id" yaml:"run_id"`
	AgentID       string    `json:"agent_id" yaml:"agent_id"`
	AgentHarness  string    `json:"agent_harness" yaml:"agent_harness"`
}

type Scope

type Scope struct {
	In  []string `json:"in" yaml:"in"`
	Out []string `json:"out" yaml:"out"`
}

type TransitionError

type TransitionError struct {
	From    string
	To      string
	Allowed []string
	Reason  string // e.g. "from is terminal", "blocked resume target unknown"
}

TransitionError describes an illegal transition with the allowed list, so the caller (CLI/MCP) can render "draft → done is not allowed; next: ..." without re-deriving the graph.

func (*TransitionError) Error

func (e *TransitionError) Error() string

type Verification

type Verification struct {
	Advanced          *bool   `json:"advanced" yaml:"advanced"`
	HeadSHAAtComplete string  `json:"head_sha_at_complete" yaml:"head_sha_at_complete"`
	VerifiedBy        *string `json:"verified_by" yaml:"verified_by"`
}

type WorkItem

type WorkItem struct {
	SchemaVersion       int               `json:"schema_version" yaml:"schema_version"`
	ID                  string            `json:"id" yaml:"id"`
	ProjectID           string            `json:"project_id" yaml:"project_id"`
	ParentID            *string           `json:"parent_id" yaml:"parent_id"`
	Type                string            `json:"type" yaml:"type"`
	Title               string            `json:"title" yaml:"title"`
	Description         string            `json:"description" yaml:"description"`
	Status              string            `json:"status" yaml:"status"`
	Priority            int               `json:"priority" yaml:"priority"`
	Dependencies        []string          `json:"dependencies" yaml:"dependencies"`
	AcceptanceCriteria  []string          `json:"acceptance_criteria" yaml:"acceptance_criteria"`
	Constraints         []string          `json:"constraints" yaml:"constraints"`
	ContextRefs         []string          `json:"context_refs" yaml:"context_refs"`
	ArtifactRefs        []string          `json:"artifact_refs" yaml:"artifact_refs"`
	CreatedFrom         *Reference        `json:"created_from" yaml:"created_from"`
	Reason              string            `json:"reason" yaml:"reason"`
	ProposedBy          string            `json:"proposed_by" yaml:"proposed_by"`
	ApprovalRequired    bool              `json:"approval_required" yaml:"approval_required"`
	ClarificationNeeded bool              `json:"clarification_needed" yaml:"clarification_needed"`
	Workflow            *WorkflowInstance `json:"workflow" yaml:"workflow"`
	AssignedAgent       *string           `json:"assigned_agent" yaml:"assigned_agent"`
	AssignedHarness     *string           `json:"assigned_harness" yaml:"assigned_harness"`
	SchedulingState     string            `json:"scheduling_state" yaml:"scheduling_state"`
	LeaseOwner          string            `json:"lease_owner" yaml:"lease_owner"`
	LeaseToken          string            `json:"lease_token" yaml:"lease_token"`
	LeaseClaimedAt      *time.Time        `json:"lease_claimed_at" yaml:"lease_claimed_at"`
	LeaseUntil          *time.Time        `json:"lease_until" yaml:"lease_until"`
	HeartbeatAt         *time.Time        `json:"heartbeat_at" yaml:"heartbeat_at"`
	PreviousStatus      string            `json:"previous_status" yaml:"previous_status"`
	ActiveRunID         string            `json:"active_run_id" yaml:"active_run_id"`
	NextAttemptAt       *time.Time        `json:"next_attempt_at" yaml:"next_attempt_at"`
	CreatedAt           time.Time         `json:"created_at" yaml:"created_at"`
	UpdatedAt           time.Time         `json:"updated_at" yaml:"updated_at"`
}

type WorkflowInstance

type WorkflowInstance struct {
	ID            string    `json:"id" yaml:"id"`
	Step          string    `json:"step" yaml:"step"`
	StepEnteredAt time.Time `json:"step_entered_at" yaml:"step_entered_at"`
	// Paused holds the instance while its step must not advance (实施计划
	// M3.6); the work item status and scheduling state stay untouched.
	Paused bool `json:"paused" yaml:"paused"`
}

type Workspace

type Workspace struct {
	Path     string `json:"path" yaml:"path"`
	Branch   string `json:"branch" yaml:"branch"`
	Worktree string `json:"worktree" yaml:"worktree"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL