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
- Variables
- func DetectTaskCycle(deps map[string][]string) string
- func IsStorageFailure(err error) bool
- type ArtifactRollup
- type ArtifactView
- type ChangeSetRecovery
- type DB
- func (db *DB) AddTaskDependencies(ctx context.Context, initiativeID, taskID string, depTaskIDs []string) error
- func (db *DB) AnswerQuestion(ctx context.Context, questionID, answerDigest, actor string) error
- func (db *DB) AppendJournal(ctx context.Context, e *domain.ApplyJournalEntry) error
- func (db *DB) AppendSuggestedAnswers(ctx context.Context, initiativeID string, answers []domain.SuggestedAnswer) error
- func (db *DB) Apply(ctx context.Context, ev Event, fn func(tx *sql.Tx) error) error
- func (db *DB) ApplyNoop(ctx context.Context, ev Event) error
- func (db *DB) ApproveRequirements(ctx context.Context, initiativeID, actor string) error
- func (db *DB) AuditGraphEdges(ctx context.Context, initiativeID string) ([]domain.Finding, error)
- func (db *DB) CancelOperationStatus(ctx context.Context, opID string) error
- func (db *DB) ClaimInitiativeRunning(ctx context.Context, initiativeID string, from ...domain.InitiativeStatus) error
- func (db *DB) ClearVerificationEvidence(ctx context.Context, requirementID, actor string) error
- func (db *DB) Close() error
- func (db *DB) CompleteInitiative(ctx context.Context, initiativeID, actor string) error
- func (db *DB) CountChangeSetsByHumanID(ctx context.Context, humanID string) (int, error)
- func (db *DB) CreateArtifact(ctx context.Context, a *domain.Artifact, v *domain.ArtifactVersion) error
- func (db *DB) CreateAssertion(ctx context.Context, a *domain.Assertion) error
- func (db *DB) CreateChangeSet(ctx context.Context, cs *domain.ChangeSet) error
- func (db *DB) CreateContextBundle(ctx context.Context, bundleID, runID, digest string, ...) error
- func (db *DB) CreateContextDoc(ctx context.Context, doc *domain.ContextDoc) error
- func (db *DB) CreateDecision(ctx context.Context, d *domain.Decision) error
- func (db *DB) CreateDecisionDiscussion(ctx context.Context, m *domain.DecisionDiscussion) error
- func (db *DB) CreateDissent(ctx context.Context, d *domain.DecisionDissent) error
- func (db *DB) CreateDocComment(ctx context.Context, c *domain.DocComment) error
- func (db *DB) CreateFinding(ctx context.Context, f *domain.Finding) error
- func (db *DB) CreateInitiative(ctx context.Context, ini *domain.Initiative) error
- func (db *DB) CreateOperation(ctx context.Context, projectID, initiativeID, opType string) (string, error)
- func (db *DB) CreateQuestion(ctx context.Context, q *domain.Question) error
- func (db *DB) CreateRequirement(ctx context.Context, r *domain.Requirement) error
- func (db *DB) CreateRun(ctx context.Context, kind domain.RunKind, stageRunID, actor string) (string, error)
- func (db *DB) CreateRunManifest(ctx context.Context, m *domain.RunManifest) error
- func (db *DB) CreateTask(ctx context.Context, t *domain.Task, implementsRequirementID string, ...) error
- func (db *DB) CreateVerificationEvidence(ctx context.Context, e *domain.VerificationEvidence) error
- func (db *DB) CreateVerificationTask(ctx context.Context, t *domain.Task, requirementID string) error
- func (db *DB) DeleteTask(ctx context.Context, initiativeID, taskID string) error
- func (db *DB) DeleteTasksForInitiative(ctx context.Context, initiativeID string) error
- func (db *DB) DispositionOpenFindings(ctx context.Context, initiativeID string, disp domain.Disposition, ...) error
- func (db *DB) DispositionUnclaimedFindingsByTarget(ctx context.Context, initiativeID, targetType, targetID string, ...) error
- func (db *DB) FailInitiative(ctx context.Context, initiativeID, reason string) error
- func (db *DB) GetArtifactVersion(ctx context.Context, versionID string) (ArtifactView, error)
- func (db *DB) GetChangeSet(ctx context.Context, changeSetID string) (*domain.ChangeSet, error)
- func (db *DB) GetChangeSetByRef(ctx context.Context, ref string) (*domain.ChangeSet, error)
- func (db *DB) GetContextDoc(ctx context.Context, id string) (*domain.ContextDoc, error)
- func (db *DB) GetDecision(ctx context.Context, decisionID string) (*domain.Decision, error)
- func (db *DB) GetDocComment(ctx context.Context, commentID string) (*domain.DocComment, error)
- func (db *DB) GetInitiative(ctx context.Context, initiativeID string) (domain.Initiative, error)
- func (db *DB) GetOperation(ctx context.Context, opID string) (domain.Operation, error)
- func (db *DB) GetProject(ctx context.Context, projectID string) (ProjectRecord, error)
- func (db *DB) GetReadCursor(ctx context.Context, scope string) (int64, error)
- func (db *DB) GetRequirementByRef(ctx context.Context, initiativeID, ref string) (*domain.Requirement, error)
- func (db *DB) GetRunManifest(ctx context.Context, runID string) (domain.RunManifest, error)
- func (db *DB) GetTask(ctx context.Context, taskID string) (*domain.Task, error)
- func (db *DB) HasDissent(ctx context.Context, decisionID string) (bool, error)
- func (db *DB) InTx(ctx context.Context, fn func(tx *sql.Tx) error) error
- func (db *DB) JournalSnapshotDigest(ctx context.Context, changeSetID string) (string, error)
- func (db *DB) ListArtifactVersions(ctx context.Context, initiativeID string) ([]domain.ArtifactVersion, error)
- func (db *DB) ListArtifacts(ctx context.Context, initiativeID string) ([]ArtifactView, error)
- func (db *DB) ListAssertions(ctx context.Context, initiativeID string) ([]domain.Assertion, error)
- func (db *DB) ListChangeSets(ctx context.Context, initiativeID string) ([]domain.ChangeSet, error)
- func (db *DB) ListChangeSetsByTask(ctx context.Context, taskID string) ([]domain.ChangeSet, error)
- func (db *DB) ListContextDocs(ctx context.Context, initiativeID string) ([]domain.ContextDoc, error)
- func (db *DB) ListDecisionDiscussions(ctx context.Context, decisionID string) ([]domain.DecisionDiscussion, error)
- func (db *DB) ListDecisions(ctx context.Context, initiativeID string) ([]domain.Decision, error)
- func (db *DB) ListDissents(ctx context.Context, decisionID string) ([]domain.DecisionDissent, error)
- func (db *DB) ListDocComments(ctx context.Context, artifactVersionID string) ([]domain.DocComment, error)
- func (db *DB) ListEvents(ctx context.Context, sinceSeq int64, limit int) ([]EventRow, error)
- func (db *DB) ListEvidenceByRequirement(ctx context.Context, requirementID string) ([]domain.VerificationEvidence, error)
- func (db *DB) ListFindings(ctx context.Context, reviewRunID string) ([]domain.Finding, error)
- func (db *DB) ListFindingsByInitiative(ctx context.Context, initiativeID string) ([]domain.Finding, error)
- func (db *DB) ListFindingsByTarget(ctx context.Context, targetType, targetID string) ([]domain.Finding, error)
- func (db *DB) ListGraphEdges(ctx context.Context, initiativeID string) ([]domain.GraphEdge, error)
- func (db *DB) ListGraphEdgesFrom(ctx context.Context, initiativeID, fromType, fromID string) ([]domain.GraphEdge, error)
- func (db *DB) ListGraphEdgesTo(ctx context.Context, initiativeID, toType, toID string) ([]domain.GraphEdge, error)
- func (db *DB) ListInitiativeRollups(ctx context.Context) ([]InitiativeRollup, error)
- func (db *DB) ListInitiatives(ctx context.Context) ([]domain.Initiative, error)
- func (db *DB) ListJournal(ctx context.Context, changeSetID string) ([]domain.ApplyJournalEntry, error)
- func (db *DB) ListOperationsByInitiative(ctx context.Context, initiativeID string) ([]domain.Operation, error)
- func (db *DB) ListProjects(ctx context.Context) ([]ProjectRecord, error)
- func (db *DB) ListQuestions(ctx context.Context, initiativeID string) ([]domain.Question, error)
- func (db *DB) ListRequirements(ctx context.Context, initiativeID string) ([]domain.Requirement, error)
- func (db *DB) ListSuggestedAnswers(ctx context.Context, initiativeID string) ([]domain.SuggestedAnswer, error)
- func (db *DB) ListTasks(ctx context.Context, initiativeID string) ([]domain.Task, error)
- func (db *DB) ListUnfinishedOperations(ctx context.Context) ([]domain.Operation, error)
- func (db *DB) MarkChangeSetApplied(ctx context.Context, changeSetID, workspaceSnapshotDigest, actor string) error
- func (db *DB) MarkChangeSetReverted(ctx context.Context, changeSetID, actor string) error
- func (db *DB) MarkDocCommentPromoted(ctx context.Context, commentID, questionID string) error
- func (db *DB) MarkRequirementFailed(ctx context.Context, requirementID, actor string) error
- func (db *DB) MarkRequirementVerified(ctx context.Context, requirementID, actor string) error
- func (db *DB) MarkRequirementWaived(ctx context.Context, requirementID, actor string) error
- func (db *DB) MaxEventSeq(ctx context.Context) (int64, error)
- func (db *DB) NeedsHumanJudgment(ctx context.Context, initiativeID string, reason domain.JudgmentReason, ...) error
- func (db *DB) PassedCriterionKeys(ctx context.Context, requirementID string) (map[string]bool, error)
- func (db *DB) ReconcileChangeSets(ctx context.Context) ([]ChangeSetRecovery, error)
- func (db *DB) RegisterProject(ctx context.Context, name, rootPath, projectID string) (string, error)
- func (db *DB) ReopenDecision(ctx context.Context, decisionID, actor string) error
- func (db *DB) ReorderTasks(ctx context.Context, initiativeID string, orderedIDs []string) error
- func (db *DB) ReplaceSuggestedAnswers(ctx context.Context, initiativeID string, answers []domain.SuggestedAnswer) error
- func (db *DB) ResolveDecision(ctx context.Context, decisionID, resolution, actor string) error
- func (db *DB) SQL() *sql.DB
- func (db *DB) SaveRiskProfile(ctx context.Context, p *domain.RiskProfile) error
- func (db *DB) SetChangeSetCommit(ctx context.Context, changeSetID, sha, actor string) error
- func (db *DB) SetChangeSetReview(ctx context.Context, changeSetID, reviewID, actor string) error
- func (db *DB) SetContextDocDescription(ctx context.Context, id, descriptionDigest string) error
- func (db *DB) SetDecisionRecommendation(ctx context.Context, decisionID, rec, convergedBy, actor string) error
- func (db *DB) SetFindingDisposition(ctx context.Context, findingID string, disp domain.Disposition, actor string) error
- func (db *DB) SetFindingNote(ctx context.Context, findingID, note, actor string) error
- func (db *DB) SetInitiativeStatus(ctx context.Context, initiativeID string, status domain.InitiativeStatus, ...) error
- func (db *DB) SetOperationStatus(ctx context.Context, opID string, status domain.OperationStatus, ...) error
- func (db *DB) SetReadCursor(ctx context.Context, scope string, seq int64) error
- func (db *DB) SetRunStatus(ctx context.Context, runID string, status domain.RunStatus, actor string) error
- func (db *DB) SetTaskStatus(ctx context.Context, taskID string, status domain.TaskStatus) error
- func (db *DB) SupersedeAssertions(ctx context.Context, initiativeID, supersededBy string) error
- func (db *DB) SupersedeRequirements(ctx context.Context, initiativeID, supersededBy string) error
- func (db *DB) TransitionChangeSet(ctx context.Context, changeSetID string, from, to domain.ChangeSetStatus, ...) error
- func (db *DB) TransitionInitiative(ctx context.Context, initiativeID string, to domain.InitiativeStatus, ...) error
- func (db *DB) UnverifyRequirement(ctx context.Context, requirementID, actor string) error
- func (db *DB) UpdateTask(ctx context.Context, initiativeID, taskID, title, statement string, ...) error
- func (db *DB) WireDecisionDerivedFromQuestion(ctx context.Context, initiativeID, decisionID, questionID string) error
- func (db *DB) WireDocConsumes(ctx context.Context, initiativeID, runID string, docIDs []string) error
- func (db *DB) WireRequirementDerivedFromDecision(ctx context.Context, initiativeID, requirementID, decisionID string) error
- type EdgeToWrite
- type Event
- type EventRow
- type InitiativeRollup
- type NotFoundError
- type ProjectRecord
Constants ¶
const ActorOrchestrator = "orchestrator"
ActorOrchestrator is the default event actor for deterministic workflow steps.
const HumanActor = "human"
HumanActor is the actor identity for human actions (§11, §15).
Variables ¶
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.
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
AnswerQuestion records a human answer (human_approved) and resolves the question.
func (*DB) AppendJournal ¶
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 ¶
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) ApproveRequirements ¶
ApproveRequirements transitions all draft requirements of an initiative to approved (§17). Called when the PRD review passes or a human approves.
func (*DB) AuditGraphEdges ¶
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 ¶
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 ¶
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) CompleteInitiative ¶ added in v0.4.0
CompleteInitiative writes `complete`, but never over a failed initiative.
This is a guard on the write, not an enumeration of the states it accepts. InitiativeStatus has six values, so listing the other five would be the exact complement of the one refusal -- and a seventh status added later would be silently excluded, turning a legitimate completion into a refusal with no test failing. The invariant is "not failed", so that is what the SQL says.
The defect: VerifyInitiative concluded `complete` for an initiative with no requirements at all (the gate loop never runs, so allVerified stays true) and wrote it with SetInitiativeStatus, unconditionally. DX audit 7 reproduced a bare `idea verify` on an initiative that failed at framing with a 401 -- zero requirements, zero tasks, zero change sets -- printing `✓ verified status: complete`, exiting 0, and discarding the failure_reason.
Runtime.RunVerificationGate refuses the request synchronously; this refuses the write, which covers any future caller that does not go through the Runtime and the window where a concurrent FailInitiative lands.
The predicate is failure_reason, not just status, and that is load-bearing. Five entry points -- apply, revert, revise, retry, reopen-phase -- claim `running` FROM `failed` by design, and ClaimInitiativeRunning deliberately leaves failure_reason intact so the release can restore it. During any of them the row is a failed initiative wearing a running status: a status-only guard passes, this write lands, and it clears the reason PERMANENTLY, since the release only writes the status back. A commit review caught it by reproducing exactly that against the real handler. `failed` is a transient display of the status; the recorded reason is the durable fact.
func (*DB) CountChangeSetsByHumanID ¶ added in v0.4.0
CountChangeSetsByHumanID reports how many change sets in this project share a human id.
Human ids are assigned per initiative, so CHG-1 exists once per initiative while apply/review/change resolve project-wide. `idea next` printed the human id unconditionally and so prescribed `idea apply CHG-1`, which refuses as ambiguous the moment a project has two initiatives with change sets. Callers use this to print the full id in exactly that case, and the friendly one otherwise.
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 ¶
CreateAssertion inserts an assertion and appends its event.
func (*DB) CreateChangeSet ¶
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 ¶
CreateContextDoc inserts a context document and appends its creation event.
func (*DB) CreateDecision ¶
CreateDecision inserts a decision with code DEC-xx.
func (*DB) CreateDecisionDiscussion ¶
CreateDecisionDiscussion appends one message to a decision discussion thread.
func (*DB) CreateDissent ¶
CreateDissent preserves a dissenting view (§8).
func (*DB) CreateDocComment ¶
CreateDocComment inserts one human comment anchored to an artifact version.
func (*DB) CreateFinding ¶
CreateFinding inserts a review finding.
func (*DB) CreateInitiative ¶
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 ¶
CreateQuestion inserts an open question.
func (*DB) CreateRequirement ¶
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 ¶
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 ¶
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 ¶
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 ¶
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) DispositionUnclaimedFindingsByTarget ¶ added in v0.4.0
func (db *DB) DispositionUnclaimedFindingsByTarget(ctx context.Context, initiativeID, targetType, targetID string, disp domain.Disposition, actor string) error
DispositionUnclaimedFindingsByTarget dispositions the undisposed findings targeting one node that carry NO deny code, in a single event.
Three constraints, each of which a simpler call gets wrong:
- Target-scoped. DispositionOpenFindings is `WHERE initiative_id = ?`, so using it to accept a change set's findings would also sign off every open finding on the initiative -- including the PRD review's.
- `code = ”`. Every producer that raises a system deny stamps a DenyCode: secret_sweep, pii, host_exec, blob_digest_mismatch. Only the adversarial reviewer leaves it empty (review.ParseFindings never sets it). So this cannot sign off a credential detection, whatever the caller intends, and "system deny beats human approve" survives.
- accepted_risk requires a human. SetFindingDisposition enforces that and DispositionOpenFindings does not; a bulk path that skipped it would let an automated actor forge the one disposition the reviewer is forbidden to set.
One event rather than N: a loop of SetFindingDisposition is not atomic, and a partial write here leaves a change set half-accepted.
func (*DB) FailInitiative ¶
FailInitiative marks an initiative failed with a reason.
func (*DB) GetArtifactVersion ¶
GetArtifactVersion returns one artifact version by its version id.
func (*DB) GetChangeSet ¶
GetChangeSet returns one change set by id, or nil if not found.
func (*DB) GetChangeSetByRef ¶
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 ¶
GetContextDoc returns a single context document by id.
func (*DB) GetDecision ¶
GetDecision returns a single decision by id.
func (*DB) GetDocComment ¶
GetDocComment returns one comment by id.
func (*DB) GetInitiative ¶
GetInitiative returns one initiative by id.
func (*DB) GetOperation ¶
GetOperation returns an operation.
func (*DB) GetProject ¶
GetProject returns a project by its project_id.
func (*DB) GetReadCursor ¶
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 ¶
GetRunManifest returns a manifest by run id.
func (*DB) HasDissent ¶
HasDissent reports whether a decision has any preserved dissent (§8).
func (*DB) JournalSnapshotDigest ¶
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 ¶
ListArtifacts returns artifact versions (with kind) for an initiative.
func (*DB) ListAssertions ¶
ListAssertions returns assertions for an initiative.
func (*DB) ListChangeSets ¶
ListChangeSets returns change sets for an initiative, oldest first.
func (*DB) ListChangeSetsByTask ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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) ListUnfinishedOperations ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
MaxEventSeq returns the current maximum event sequence (0 if empty).
func (*DB) NeedsHumanJudgment ¶ added in v0.4.0
func (db *DB) NeedsHumanJudgment(ctx context.Context, initiativeID string, reason domain.JudgmentReason, actor string) error
NeedsHumanJudgment parks an initiative for a human and records why, in one statement. The two must move together: a status without a reason is what left `idea next` guessing from artifact presence, and a reason without the status would be read by nothing.
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 ¶
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 ¶
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 ¶
ResolveDecision records a human decision (immutable once resolved).
func (*DB) SaveRiskProfile ¶
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 ¶
SetChangeSetCommit records the git commit SHA for a change set.
func (*DB) SetChangeSetReview ¶
SetChangeSetReview records the review id for a change set.
func (*DB) SetContextDocDescription ¶
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 ¶
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) SetOperationStatus ¶
func (db *DB) SetOperationStatus(ctx context.Context, opID string, status domain.OperationStatus, resultRef string) error
SetOperationStatus transitions an operation.
func (*DB) SetReadCursor ¶
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 ¶
SetTaskStatus updates a task's status (domain methods only, §13).
func (*DB) SupersedeAssertions ¶
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 ¶
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) TransitionInitiative ¶ added in v0.4.0
func (db *DB) TransitionInitiative(ctx context.Context, initiativeID string, to domain.InitiativeStatus, actor string, from ...domain.InitiativeStatus) error
TransitionInitiative is the compare-and-swap for a status change that is not a claim.
SetInitiativeStatus is an unconditional UPDATE, so guarding it with a GetInitiative first is the check-then-act this package already rejected for ClaimInitiativeRunning: the read and the write are not atomic with each other. `Approve` did exactly that -- it had no check at all and simply overwrote the status, releasing a claim a running advance was holding, so two advances ran concurrently on one initiative. A guard that reads first would have narrowed that window without closing it.
func (*DB) UnverifyRequirement ¶
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.
type InitiativeRollup ¶
type InitiativeRollup struct {
ID string `json:"id"`
Title string `json:"title"`
Status domain.InitiativeStatus `json:"status"`
// JudgmentReason is why the initiative is parked. All four reasons share
// `needs_human_judgment`, so the status alone cannot tell a PRD-review park
// from a plan-stage one -- and ProductHome derives its phase rail from this
// rollup, so without it that page has to guess from artifact presence, which
// is wrong for exactly the plan_dependencies case.
JudgmentReason domain.JudgmentReason `json:"judgment_reason,omitempty"`
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.