store

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: Apache-2.0 Imports: 12 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 store provides SQLite persistence with atomic state+event appends (§32). Relational state is authoritative; events are appended in the same transaction as the state mutation they describe.

Index

Constants

View Source
const ActorOrchestrator = "orchestrator"

ActorOrchestrator is the default event actor for deterministic workflow steps.

View Source
const HumanActor = "human"

HumanActor is the actor identity for human actions (§11, §15).

Variables

View Source
var ErrInitiativeNotClaimable = errors.New("store: initiative is not in a claimable state")

ErrInitiativeNotClaimable reports that an initiative could not be claimed: another request holds it, or it is not in a state the operation runs from.

View Source
var ErrOperationNotLive = errors.New("store: operation is not pending or running")

ErrOperationNotLive reports that a cancel found no pending-or-running row: the operation had already finished, or the id does not exist. Callers report it as "not cancellable" rather than treating it as a write failure.

Functions

func DetectTaskCycle

func DetectTaskCycle(deps map[string][]string) string

DetectTaskCycle returns the id of a task that participates in a dependency cycle, or "" (three-color DFS). It is the single canonical cycle detector, shared by the plan checks and the doctor edge audit.

func IsStorageFailure

func IsStorageFailure(err error) bool

IsStorageFailure reports whether err came from the database driver or the filesystem, rather than from a domain rule. Those errors carry schema names, constraint text and absolute state paths, so callers must not show them to a client verbatim.

This is a type check, not a search for substrings: "UNIQUE constraint failed: change_sets.id", "attempt to write a readonly database" and "open /Users/<name>/.local/share/…: permission denied" share no vocabulary, and a list of markers will always be one driver message behind.

Types

type ArtifactRollup

type ArtifactRollup struct {
	Kind    string `json:"kind"`
	Version int    `json:"version"`
}

ArtifactRollup is the minimal artifact info phase derivation needs.

type ArtifactView

type ArtifactView struct {
	VersionID     string              `json:"id"`
	ArtifactID    string              `json:"artifact_id"`
	InitiativeID  string              `json:"initiative_id"`
	Kind          domain.ArtifactKind `json:"kind"`
	Version       int                 `json:"version"`
	Status        string              `json:"status"`
	BodyDigest    string              `json:"body_digest"`
	ProducedByRun string              `json:"produced_by_run"`
	CreatedAt     time.Time           `json:"created_at"`
}

ArtifactView is an artifact version joined with its family kind + initiative.

type ChangeSetRecovery

type ChangeSetRecovery struct {
	ChangeSetID  string
	InitiativeID string
	Status       domain.ChangeSetStatus
	TaskID       string
	// LatestJournalState is the most recent apply-journal state, or "" if none.
	LatestJournalState domain.ApplyState
	// PreImageDigest is the workspace pre-image to restore (workspace_mutated
	// rows only); empty when no mutation was recorded.
	PreImageDigest string
}

ChangeSetRecovery describes a change set stuck in a non-terminal state that startup reconciliation must move to a terminal state (and, for an interrupted apply, restore the workspace).

type DB

type DB struct {
	// contains filtered or unexported fields
}

DB wraps a SQLite connection pool with the schema and event helpers.

func Open

func Open(path string) (*DB, error)

Open opens (or creates) the SQLite database at path, applies migrations, and configures WAL + foreign keys + busy timeout. The daemon is the single writer (§4 D1), so the pool is deliberately small to avoid SQLITE_BUSY.

func OpenGlobal

func OpenGlobal(path string) (*DB, error)

OpenGlobal opens the global registry database (projects, daemon_meta).

func (*DB) AddTaskDependencies

func (db *DB) AddTaskDependencies(ctx context.Context, initiativeID, taskID string, depTaskIDs []string) error

AddTaskDependencies wires depends_on edges from taskID to each depTaskID in one transaction. Used by the execution-plan two-pass resolution so backward (and normalized) dependency references resolve after all tasks exist.

func (*DB) AnswerQuestion

func (db *DB) AnswerQuestion(ctx context.Context, questionID, answerDigest, actor string) error

AnswerQuestion records a human answer (human_approved) and resolves the question.

func (*DB) AppendJournal

func (db *DB) AppendJournal(ctx context.Context, e *domain.ApplyJournalEntry) error

AppendJournal inserts one apply-journal record (§39).

func (*DB) AppendSuggestedAnswers

func (db *DB) AppendSuggestedAnswers(ctx context.Context, initiativeID string, answers []domain.SuggestedAnswer) error

AppendSuggestedAnswers appends a batch of AI-suggested answers (used for incremental, chunked generation so progress is observable).

func (*DB) Apply

func (db *DB) Apply(ctx context.Context, ev Event, fn func(tx *sql.Tx) error) error

Apply runs fn and appends ev in a single transaction. If fn returns an error, neither the state mutation nor the event is persisted (§32 atomicity).

func (*DB) ApplyNoop

func (db *DB) ApplyNoop(ctx context.Context, ev Event) error

ApplyNoop appends an event with no accompanying state mutation.

func (*DB) ApproveRequirements

func (db *DB) ApproveRequirements(ctx context.Context, initiativeID, actor string) error

ApproveRequirements transitions all draft requirements of an initiative to approved (§17). Called when the PRD review passes or a human approves.

func (*DB) AuditGraphEdges

func (db *DB) AuditGraphEdges(ctx context.Context, initiativeID string) ([]domain.Finding, error)

AuditGraphEdges reports traceability gaps for an initiative (§M2 tail): each task missing an `implements` edge, each requirement/assertion/artifact missing a `produced_by` edge, and cyclic task dependencies (DFS cycle check). It is read-only and returns findings rather than persisting them.

func (*DB) CancelOperationStatus

func (db *DB) CancelOperationStatus(ctx context.Context, opID string) error

CancelOperationStatus marks an operation cancelled, but only while it is still pending or running.

Separate from SetOperationStatus, and compare-and-swap, because the two writers are not equals. The operation's own goroutine knows what actually happened and must be able to record it unconditionally; a cancel is a request, and a request that arrives after the work finished has to lose.

Both used to be unconditional, so they raced and whichever reached SQLite last won -- an apply that had already committed files and marked the change set applied could be recorded as cancelled, the operation log disagreeing with the disk. Guarding only the cancel side fixes that in both orders: a late cancel is a no-op, and a cancel during a run is overwritten by the goroutine's terminal write when the work turns out to have completed anyway.

Modelled on TransitionChangeSet, the CAS precedent in this package.

func (*DB) ClaimInitiativeRunning

func (db *DB) ClaimInitiativeRunning(ctx context.Context, initiativeID string, from ...domain.InitiativeStatus) error

ClaimInitiativeRunning marks an initiative running, but only from one of the states given. It reports ErrInitiativeNotClaimable when no row matched.

This is the atomic half of "is it already running?". Seven Runtime entry points asked that question and four of them never set the flag, so two concurrent requests both passed the check -- a double-clicked "Revise plan" let one goroutine delete and recreate the task set while the other wrote dependency edges to task ids that no longer existed, after which every later revise was refused.

A Go-level GetInitiative-then-set cannot fix that: the read and the write are not atomic with each other, which is the same check-then-act the finding is about. SetInitiativeStatus is an unconditional UPDATE and cannot be used for a claim. TransitionChangeSet has been the compare-and-swap precedent in this package all along, and this follows it.

func (*DB) ClearVerificationEvidence

func (db *DB) ClearVerificationEvidence(ctx context.Context, requirementID, actor string) error

ClearVerificationEvidence deletes every evidence row for a requirement. A new human judgment (pass/fail/waived) supersedes all prior evidence for the requirement's criteria — otherwise a stale pass row would resurrect a requirement that a human has since failed or waived (evidence is otherwise append-only and PassedCriterionKeys counts every pass regardless of newer rows).

func (*DB) Close

func (db *DB) Close() error

Close closes the underlying database.

func (*DB) CreateArtifact

func (db *DB) CreateArtifact(ctx context.Context, a *domain.Artifact, v *domain.ArtifactVersion) error

CreateArtifact inserts an artifact family and its first version.

func (*DB) CreateAssertion

func (db *DB) CreateAssertion(ctx context.Context, a *domain.Assertion) error

CreateAssertion inserts an assertion and appends its event.

func (*DB) CreateChangeSet

func (db *DB) CreateChangeSet(ctx context.Context, cs *domain.ChangeSet) error

CreateChangeSet inserts a change set, assigning its HumanID "CHG-N" from the per-initiative change_sets counter, and appends its creation event.

func (*DB) CreateContextBundle

func (db *DB) CreateContextBundle(ctx context.Context, bundleID, runID, digest string, entries []domain.ContextEntry) error

CreateContextBundle persists a context bundle and its entries.

func (*DB) CreateContextDoc

func (db *DB) CreateContextDoc(ctx context.Context, doc *domain.ContextDoc) error

CreateContextDoc inserts a context document and appends its creation event.

func (*DB) CreateDecision

func (db *DB) CreateDecision(ctx context.Context, d *domain.Decision) error

CreateDecision inserts a decision with code DEC-xx.

func (*DB) CreateDecisionDiscussion

func (db *DB) CreateDecisionDiscussion(ctx context.Context, m *domain.DecisionDiscussion) error

CreateDecisionDiscussion appends one message to a decision discussion thread.

func (*DB) CreateDissent

func (db *DB) CreateDissent(ctx context.Context, d *domain.DecisionDissent) error

CreateDissent preserves a dissenting view (§8).

func (*DB) CreateDocComment

func (db *DB) CreateDocComment(ctx context.Context, c *domain.DocComment) error

CreateDocComment inserts one human comment anchored to an artifact version.

func (*DB) CreateFinding

func (db *DB) CreateFinding(ctx context.Context, f *domain.Finding) error

CreateFinding inserts a review finding.

func (*DB) CreateInitiative

func (db *DB) CreateInitiative(ctx context.Context, ini *domain.Initiative) error

CreateInitiative inserts an initiative and appends its creation event.

func (*DB) CreateOperation

func (db *DB) CreateOperation(ctx context.Context, projectID, initiativeID, opType string) (string, error)

CreateOperation creates a durable operation and returns its id.

func (*DB) CreateQuestion

func (db *DB) CreateQuestion(ctx context.Context, q *domain.Question) error

CreateQuestion inserts an open question.

func (*DB) CreateRequirement

func (db *DB) CreateRequirement(ctx context.Context, r *domain.Requirement) error

CreateRequirement inserts a requirement with a project-scoped code (REQ-xx).

func (*DB) CreateRun

func (db *DB) CreateRun(ctx context.Context, kind domain.RunKind, stageRunID, actor string) (string, error)

CreateRun creates a run row and returns its id. actor is the producing agent (role name) and is recorded on the run.created event (§14 actor separation).

func (*DB) CreateRunManifest

func (db *DB) CreateRunManifest(ctx context.Context, m *domain.RunManifest) error

CreateRunManifest records immutable run provenance (§36).

func (*DB) CreateTask

func (db *DB) CreateTask(ctx context.Context, t *domain.Task, implementsRequirementID string, dependsOn []string) error

CreateTask inserts an execution-plan task and wires its `implements` (task → requirement) and `depends_on` (task → task) edges in the same transaction.

func (*DB) CreateVerificationEvidence

func (db *DB) CreateVerificationEvidence(ctx context.Context, e *domain.VerificationEvidence) error

CreateVerificationEvidence inserts one evidence row (§70, review B4/B10).

func (*DB) CreateVerificationTask

func (db *DB) CreateVerificationTask(ctx context.Context, t *domain.Task, requirementID string) error

CreateVerificationTask creates a plan task whose purpose is verifying a requirement, wired with a `verifies` edge (task → requirement).

func (*DB) DeleteTask

func (db *DB) DeleteTask(ctx context.Context, initiativeID, taskID string) error

DeleteTask removes a task and all of its graph edges in one transaction. Callers must first reject deletion when the task has change sets or other tasks depend on it (checked at the handler layer).

func (*DB) DeleteTasksForInitiative

func (db *DB) DeleteTasksForInitiative(ctx context.Context, initiativeID string) error

DeleteTasksForInitiative removes every task (and its edges) for an initiative. Used by plan revision, which regenerates the task list fresh. Callers must reject when any task has a change set.

func (*DB) DispositionOpenFindings

func (db *DB) DispositionOpenFindings(ctx context.Context, initiativeID string, disp domain.Disposition, actor string) error

DispositionOpenFindings sets the disposition of every still-open finding for an initiative in one atomic step. Used when a review cycle passes so prior cycles' blocking findings cannot wedge the verify gate (full-platform review).

func (*DB) FailInitiative

func (db *DB) FailInitiative(ctx context.Context, initiativeID, reason string) error

FailInitiative marks an initiative failed with a reason.

func (*DB) GetArtifactVersion

func (db *DB) GetArtifactVersion(ctx context.Context, versionID string) (ArtifactView, error)

GetArtifactVersion returns one artifact version by its version id.

func (*DB) GetChangeSet

func (db *DB) GetChangeSet(ctx context.Context, changeSetID string) (*domain.ChangeSet, error)

GetChangeSet returns one change set by id, or nil if not found.

func (*DB) GetChangeSetByRef

func (db *DB) GetChangeSetByRef(ctx context.Context, ref string) (*domain.ChangeSet, error)

GetChangeSetByRef resolves a change set by its UUID or its HumanID (CHG-N), so CLI/UI can reference change sets by the human-facing id. HumanID is only unique per-initiative, so a bare CHG-N that matches more than one initiative fails closed with an ambiguity error instead of silently returning an arbitrary (possibly wrong) change set — review: full-platform authorization.

func (*DB) GetContextDoc

func (db *DB) GetContextDoc(ctx context.Context, id string) (*domain.ContextDoc, error)

GetContextDoc returns a single context document by id.

func (*DB) GetDecision

func (db *DB) GetDecision(ctx context.Context, decisionID string) (*domain.Decision, error)

GetDecision returns a single decision by id.

func (*DB) GetDocComment

func (db *DB) GetDocComment(ctx context.Context, commentID string) (*domain.DocComment, error)

GetDocComment returns one comment by id.

func (*DB) GetInitiative

func (db *DB) GetInitiative(ctx context.Context, initiativeID string) (domain.Initiative, error)

GetInitiative returns one initiative by id.

func (*DB) GetOperation

func (db *DB) GetOperation(ctx context.Context, opID string) (domain.Operation, error)

GetOperation returns an operation.

func (*DB) GetProject

func (db *DB) GetProject(ctx context.Context, projectID string) (ProjectRecord, error)

GetProject returns a project by its project_id.

func (*DB) GetReadCursor

func (db *DB) GetReadCursor(ctx context.Context, scope string) (int64, error)

GetReadCursor returns the last-seen event seq for a scope (0 if none).

func (*DB) GetRequirementByRef

func (db *DB) GetRequirementByRef(ctx context.Context, initiativeID, ref string) (*domain.Requirement, error)

GetRequirementByRef resolves a requirement by its UUID or its Code (REQ-N) within an initiative.

func (*DB) GetRunManifest

func (db *DB) GetRunManifest(ctx context.Context, runID string) (domain.RunManifest, error)

GetRunManifest returns a manifest by run id.

func (*DB) GetTask

func (db *DB) GetTask(ctx context.Context, taskID string) (*domain.Task, error)

GetTask returns a single task by id.

func (*DB) HasDissent

func (db *DB) HasDissent(ctx context.Context, decisionID string) (bool, error)

HasDissent reports whether a decision has any preserved dissent (§8).

func (*DB) InTx

func (db *DB) InTx(ctx context.Context, fn func(tx *sql.Tx) error) error

InTx runs fn inside a transaction.

func (*DB) JournalSnapshotDigest

func (db *DB) JournalSnapshotDigest(ctx context.Context, changeSetID string) (string, error)

JournalSnapshotDigest returns the workspace_snapshot_digest of the most recent committed journal entry for a change set (the pre-image to restore on revert).

func (*DB) ListArtifactVersions

func (db *DB) ListArtifactVersions(ctx context.Context, initiativeID string) ([]domain.ArtifactVersion, error)

ListArtifactVersions returns versions for an initiative's artifacts.

func (*DB) ListArtifacts

func (db *DB) ListArtifacts(ctx context.Context, initiativeID string) ([]ArtifactView, error)

ListArtifacts returns artifact versions (with kind) for an initiative.

func (*DB) ListAssertions

func (db *DB) ListAssertions(ctx context.Context, initiativeID string) ([]domain.Assertion, error)

ListAssertions returns assertions for an initiative.

func (*DB) ListChangeSets

func (db *DB) ListChangeSets(ctx context.Context, initiativeID string) ([]domain.ChangeSet, error)

ListChangeSets returns change sets for an initiative, oldest first.

func (*DB) ListChangeSetsByTask

func (db *DB) ListChangeSetsByTask(ctx context.Context, taskID string) ([]domain.ChangeSet, error)

ListChangeSetsByTask returns change sets for a task, oldest first.

func (*DB) ListContextDocs

func (db *DB) ListContextDocs(ctx context.Context, initiativeID string) ([]domain.ContextDoc, error)

ListContextDocs returns context documents for an initiative, oldest first.

func (*DB) ListDecisionDiscussions

func (db *DB) ListDecisionDiscussions(ctx context.Context, decisionID string) ([]domain.DecisionDiscussion, error)

ListDecisionDiscussions returns the discussion thread for a decision.

func (*DB) ListDecisions

func (db *DB) ListDecisions(ctx context.Context, initiativeID string) ([]domain.Decision, error)

ListDecisions returns decisions for an initiative.

func (*DB) ListDissents

func (db *DB) ListDissents(ctx context.Context, decisionID string) ([]domain.DecisionDissent, error)

ListDissents returns the dissenting views for a decision.

func (*DB) ListDocComments

func (db *DB) ListDocComments(ctx context.Context, artifactVersionID string) ([]domain.DocComment, error)

ListDocComments returns comments for an artifact version, oldest first.

func (*DB) ListEvents

func (db *DB) ListEvents(ctx context.Context, sinceSeq int64, limit int) ([]EventRow, error)

ListEvents returns events with seq >= sinceSeq ordered by seq ascending.

func (*DB) ListEvidenceByRequirement

func (db *DB) ListEvidenceByRequirement(ctx context.Context, requirementID string) ([]domain.VerificationEvidence, error)

ListEvidenceByRequirement returns evidence for a requirement, oldest first.

func (*DB) ListFindings

func (db *DB) ListFindings(ctx context.Context, reviewRunID string) ([]domain.Finding, error)

ListFindings returns findings for a review run.

func (*DB) ListFindingsByInitiative

func (db *DB) ListFindingsByInitiative(ctx context.Context, initiativeID string) ([]domain.Finding, error)

ListFindingsByInitiative returns all findings for an initiative.

func (*DB) ListFindingsByTarget

func (db *DB) ListFindingsByTarget(ctx context.Context, targetType, targetID string) ([]domain.Finding, error)

ListFindingsByTarget returns all findings targeting a specific node (e.g. a change set), used by the review_open_blocking deny gate at approve time.

func (*DB) ListGraphEdges

func (db *DB) ListGraphEdges(ctx context.Context, initiativeID string) ([]domain.GraphEdge, error)

ListGraphEdges returns every edge for an initiative, oldest first.

func (*DB) ListGraphEdgesFrom

func (db *DB) ListGraphEdgesFrom(ctx context.Context, initiativeID, fromType, fromID string) ([]domain.GraphEdge, error)

ListGraphEdgesFrom returns outgoing edges from a node.

func (*DB) ListGraphEdgesTo

func (db *DB) ListGraphEdgesTo(ctx context.Context, initiativeID, toType, toID string) ([]domain.GraphEdge, error)

ListGraphEdgesTo returns incoming edges to a node.

func (*DB) ListInitiativeRollups

func (db *DB) ListInitiativeRollups(ctx context.Context) ([]InitiativeRollup, error)

ListInitiativeRollups returns one rollup per initiative in the project DB.

func (*DB) ListInitiatives

func (db *DB) ListInitiatives(ctx context.Context) ([]domain.Initiative, error)

ListInitiatives returns all initiatives ordered by creation.

func (*DB) ListJournal

func (db *DB) ListJournal(ctx context.Context, changeSetID string) ([]domain.ApplyJournalEntry, error)

ListJournal returns apply-journal records for a change set, oldest first.

func (*DB) ListOperationsByInitiative

func (db *DB) ListOperationsByInitiative(ctx context.Context, initiativeID string) ([]domain.Operation, error)

ListOperationsByInitiative returns an initiative's operations, most recent first, so the UI can find the running one and show elapsed time.

func (*DB) ListProjects

func (db *DB) ListProjects(ctx context.Context) ([]ProjectRecord, error)

ListProjects returns all registered projects.

func (*DB) ListQuestions

func (db *DB) ListQuestions(ctx context.Context, initiativeID string) ([]domain.Question, error)

ListQuestions returns questions for an initiative.

func (*DB) ListRequirements

func (db *DB) ListRequirements(ctx context.Context, initiativeID string) ([]domain.Requirement, error)

ListRequirements returns requirements for an initiative.

func (*DB) ListSuggestedAnswers

func (db *DB) ListSuggestedAnswers(ctx context.Context, initiativeID string) ([]domain.SuggestedAnswer, error)

ListSuggestedAnswers returns the stored AI-suggested answers for an initiative.

func (*DB) ListTasks

func (db *DB) ListTasks(ctx context.Context, initiativeID string) ([]domain.Task, error)

ListTasks returns tasks for an initiative, oldest first.

func (*DB) ListUnfinishedOperations

func (db *DB) ListUnfinishedOperations(ctx context.Context) ([]domain.Operation, error)

ListUnfinishedOperations returns operations not in a terminal state (for daemon restart reconciliation, §16).

func (*DB) MarkChangeSetApplied

func (db *DB) MarkChangeSetApplied(ctx context.Context, changeSetID, workspaceSnapshotDigest, actor string) error

MarkChangeSetApplied atomically advances applying→applied and appends the committed journal entry (carrying the pre-image workspace snapshot digest) in one transaction, so the change set status and the apply journal can never diverge (§39).

func (*DB) MarkChangeSetReverted

func (db *DB) MarkChangeSetReverted(ctx context.Context, changeSetID, actor string) error

MarkChangeSetReverted atomically advances applied→reverted and appends a rolled_back journal entry in one transaction, so the change set status and the apply journal can never diverge (§39).

func (*DB) MarkDocCommentPromoted

func (db *DB) MarkDocCommentPromoted(ctx context.Context, commentID, questionID string) error

MarkDocCommentPromoted records the question a comment was promoted into. The update is conditional on the comment being unpromoted, so a concurrent or duplicate promote affects zero rows and fails rather than overwriting the first link (last-writer-wins).

func (*DB) MarkRequirementFailed

func (db *DB) MarkRequirementFailed(ctx context.Context, requirementID, actor string) error

MarkRequirementFailed transitions a requirement to failed from any approvable state (approved/verified/waived/failed — re-issue is idempotent). A failed requirement stays in the active set and blocks completion until a human re-records a pass.

func (*DB) MarkRequirementVerified

func (db *DB) MarkRequirementVerified(ctx context.Context, requirementID, actor string) error

MarkRequirementVerified transitions a requirement approved/failed/waived→verified and stamps verified_at. A human re-pass clears a prior fail or waiver and returns the requirement to the verified set. It fails if the requirement is not in one of those three source states.

func (*DB) MarkRequirementWaived

func (db *DB) MarkRequirementWaived(ctx context.Context, requirementID, actor string) error

MarkRequirementWaived transitions a requirement to waived from any approvable state (approved/verified/failed/waived — re-issue is idempotent). A waived requirement is excluded from the completion gate (like removed) but remains visible and recorded as a human judgment, not a deletion.

func (*DB) MaxEventSeq

func (db *DB) MaxEventSeq(ctx context.Context) (int64, error)

MaxEventSeq returns the current maximum event sequence (0 if empty).

func (*DB) PassedCriterionKeys

func (db *DB) PassedCriterionKeys(ctx context.Context, requirementID string) (map[string]bool, error)

PassedCriterionKeys returns the set of criterion keys that have at least one pass evidence for a requirement.

func (*DB) ReconcileChangeSets

func (db *DB) ReconcileChangeSets(ctx context.Context) ([]ChangeSetRecovery, error)

ReconcileChangeSets finds change sets stuck in applying/checks_running and marks the non-terminal journal rows of the applying ones recovery_required. It only touches change sets that are themselves non-terminal, so the journal history of already-applied/reverted change sets is left intact.

func (*DB) RegisterProject

func (db *DB) RegisterProject(ctx context.Context, name, rootPath, projectID string) (string, error)

RegisterProject inserts or updates a project registry entry and returns the project id. The global registry has no event log, so this is a direct upsert.

func (*DB) ReopenDecision

func (db *DB) ReopenDecision(ctx context.Context, decisionID, actor string) error

ReopenDecision returns a decided decision to open and clears its resolution, so the human can choose again. Dissent is preserved (never erased, §8).

func (*DB) ReorderTasks

func (db *DB) ReorderTasks(ctx context.Context, initiativeID string, orderedIDs []string) error

ReorderTasks assigns 0..n-1 positions to the given task ids, which must be exactly a permutation of the initiative's current tasks. Idempotent and transactional.

func (*DB) ReplaceSuggestedAnswers

func (db *DB) ReplaceSuggestedAnswers(ctx context.Context, initiativeID string, answers []domain.SuggestedAnswer) error

ReplaceSuggestedAnswers replaces the stored AI-suggested answers for an initiative with a fresh set.

func (*DB) ResolveDecision

func (db *DB) ResolveDecision(ctx context.Context, decisionID, resolution, actor string) error

ResolveDecision records a human decision (immutable once resolved).

func (*DB) SQL

func (db *DB) SQL() *sql.DB

SQL exposes the underlying *sql.DB for repository methods.

func (*DB) SaveRiskProfile

func (db *DB) SaveRiskProfile(ctx context.Context, p *domain.RiskProfile) error

SaveRiskProfile persists a deterministic risk profile for an initiative. A profile is append-only history: every computed profile is retained.

Currently unused, deliberately. handleRisk called this on a GET, so every read appended a row and an event without bound; nothing ever read them back (risk_profiles has no SELECT anywhere). ComputeRiskProfile is a pure function of the change-set patches, so a profile is recomputable on demand and the history bought nothing. Kept -- with the table -- for whenever a durable profile gains an actual reader, which is the thing to add first.

func (*DB) SetChangeSetCommit

func (db *DB) SetChangeSetCommit(ctx context.Context, changeSetID, sha, actor string) error

SetChangeSetCommit records the git commit SHA for a change set.

func (*DB) SetChangeSetReview

func (db *DB) SetChangeSetReview(ctx context.Context, changeSetID, reviewID, actor string) error

SetChangeSetReview records the review id for a change set.

func (*DB) SetContextDocDescription

func (db *DB) SetContextDocDescription(ctx context.Context, id, descriptionDigest string) error

SetContextDocDescription records the vision-generated description digest for an image doc.

func (*DB) SetDecisionRecommendation

func (db *DB) SetDecisionRecommendation(ctx context.Context, decisionID, rec, convergedBy, actor string) error

SetDecisionRecommendation overwrites a decision's recommendation with a synthesized value (the orchestrator convergence, §M2 tail) and appends a decision event recording the synthesis.

func (*DB) SetFindingDisposition

func (db *DB) SetFindingDisposition(ctx context.Context, findingID string, disp domain.Disposition, actor string) error

SetFindingDisposition records a disposition from a distinct actor.

func (*DB) SetFindingNote

func (db *DB) SetFindingNote(ctx context.Context, findingID, note, actor string) error

SetFindingNote records (or clears) a human free-text note on a finding. The note is fed back to the model on the next revise so the human can "discuss" a finding rather than only disposition it.

func (*DB) SetInitiativeStatus

func (db *DB) SetInitiativeStatus(ctx context.Context, initiativeID string, status domain.InitiativeStatus, actor string) error

func (*DB) SetOperationStatus

func (db *DB) SetOperationStatus(ctx context.Context, opID string, status domain.OperationStatus, resultRef string) error

SetOperationStatus transitions an operation.

func (*DB) SetReadCursor

func (db *DB) SetReadCursor(ctx context.Context, scope string, seq int64) error

SetReadCursor records the last-seen event seq for a scope.

func (*DB) SetRunStatus

func (db *DB) SetRunStatus(ctx context.Context, runID string, status domain.RunStatus, actor string) error

SetRunStatus transitions a run's status.

func (*DB) SetTaskStatus

func (db *DB) SetTaskStatus(ctx context.Context, taskID string, status domain.TaskStatus) error

SetTaskStatus updates a task's status (domain methods only, §13).

func (*DB) SupersedeAssertions

func (db *DB) SupersedeAssertions(ctx context.Context, initiativeID, supersededBy string) error

SupersedeAssertions marks every active assertion of an initiative as superseded, mirroring SupersedeRequirements, so a full workflow retry does not accumulate duplicate framing/research assumptions.

func (*DB) SupersedeRequirements

func (db *DB) SupersedeRequirements(ctx context.Context, initiativeID, supersededBy string) error

SupersedeRequirements marks every active requirement of an initiative as removed and records the superseding run. Used by the revise step (§11).

func (*DB) TransitionChangeSet

func (db *DB) TransitionChangeSet(ctx context.Context, changeSetID string, from, to domain.ChangeSetStatus, actor string) error

TransitionChangeSet advances a change set from status `from` to status `to`, enforcing the legal transition matrix. Both the transition legality and the current-state precondition are checked; an illegal or stale transition fails with a clear error and mutates nothing.

func (*DB) UnverifyRequirement

func (db *DB) UnverifyRequirement(ctx context.Context, requirementID, actor string) error

UnverifyRequirement resets a verified requirement back to approved and clears verified_at (e.g. when the change set that verified it is reverted).

func (*DB) UpdateTask

func (db *DB) UpdateTask(ctx context.Context, initiativeID, taskID, title, statement string, priority domain.RequirementPriority, estimate string) error

UpdateTask edits a task's human-editable fields. Guarded at the handler layer (only while the plan is editable and the task is not done/cancelled).

func (*DB) WireDecisionDerivedFromQuestion

func (db *DB) WireDecisionDerivedFromQuestion(ctx context.Context, initiativeID, decisionID, questionID string) error

WireDecisionDerivedFromQuestion links a decision to the open question it resolves (decision derived_from question), so the decision's provenance is traceable through why/impact.

func (*DB) WireDocConsumes

func (db *DB) WireDocConsumes(ctx context.Context, initiativeID, runID string, docIDs []string) error

WireDocConsumes records that a run consumed a set of context documents (run --consumes--> context_doc). This is deterministic provenance: the engine knows exactly which docs it injected into a run's inputs, so no model attribution is required. It wires the edges atomically with a run event.

func (*DB) WireRequirementDerivedFromDecision

func (db *DB) WireRequirementDerivedFromDecision(ctx context.Context, initiativeID, requirementID, decisionID string) error

WireRequirementDerivedFromDecision links a requirement to the decision that shaped it (requirement derived_from decision), so an open decision's impact ("blocks N") is the set of requirements waiting on its resolution.

type EdgeToWrite

type EdgeToWrite struct {
	FromType string
	FromID   string
	EdgeType domain.EdgeType
	ToType   string
	ToID     string
}

EdgeToWrite describes one Product Graph edge to write within a transaction.

type Event

type Event struct {
	ID            string
	AggregateType string
	AggregateID   string
	Actor         string
	CorrelationID string
	CausationID   string
	Operation     string
	EventType     string
	PayloadDigest string
}

Event is an append-only event record (§32). PayloadDigest references a blob already stored (and redacted) by the caller.

type EventRow

type EventRow struct {
	Seq           int64  `json:"seq"`
	ID            string `json:"id"`
	AggregateType string `json:"aggregate_type"`
	AggregateID   string `json:"aggregate_id"`
	Actor         string `json:"actor"`
	CorrelationID string `json:"correlation_id"`
	CausationID   string `json:"causation_id"`
	Operation     string `json:"operation"`
	EventType     string `json:"event_type"`
	PayloadDigest string `json:"payload_digest"`
	CreatedAtMS   int64  `json:"created_at_ms"`
}

EventRow is a materialized event.

func (EventRow) CreatedAt

func (e EventRow) CreatedAt() time.Time

CreatedAt converts the stored unix-ms timestamp to time.Time.

type InitiativeRollup

type InitiativeRollup struct {
	ID                   string                  `json:"id"`
	Title                string                  `json:"title"`
	Status               domain.InitiativeStatus `json:"status"`
	Artifacts            []ArtifactRollup        `json:"artifacts"`
	TaskStatuses         []string                `json:"task_statuses"`
	ChangeSetStatuses    []string                `json:"change_set_statuses"`
	OpenDecisions        int                     `json:"open_decisions"`
	OpenQuestions        int                     `json:"open_questions"`
	OpenFindings         int                     `json:"open_findings"`
	VerifiedRequirements int                     `json:"verified_requirements"`
}

InitiativeRollup is a cross-initiative summary: the phase-derivation inputs (artifacts/tasks/change sets) plus the open-item counts for the attention inbox, gathered with a handful of grouped queries instead of one round trip per initiative per entity (the ProductHome N+1).

type NotFoundError

type NotFoundError struct {
	Kind string // "change set", "initiative", "requirement", …
	Ref  string // what the caller asked for
}

NotFoundError is the store's answer for a lookup that matched nothing. It carries the kind and the reference the caller asked for, so every layer above can render "no change set matching \"CHG-99\"" instead of the driver's "sql: no rows in result set", and the daemon can map it to 404.

It unwraps to sql.ErrNoRows so existing errors.Is checks keep working.

func (*NotFoundError) Error

func (e *NotFoundError) Error() string

func (*NotFoundError) Unwrap

func (e *NotFoundError) Unwrap() error

type ProjectRecord

type ProjectRecord struct {
	ID        string    `json:"id"`
	Name      string    `json:"name"`
	RootPath  string    `json:"root_path"`
	ProjectID string    `json:"project_id"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

ProjectRecord is a registered project in global.db.

Jump to

Keyboard shortcuts

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