daemon

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2026 License: Apache-2.0 Imports: 43 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 daemon implements the localhost control-plane HTTP server (§28–§29): token-authenticated, project-scoped REST + SSE over one user-level daemon.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultStateRoot

func DefaultStateRoot() string

DefaultStateRoot returns the global state directory (§30), overridable via IDEA_HARNESS_STATE for tests.

func Run

func Run(addr, stateRoot string, log *slog.Logger, onReady func()) error

Run starts the daemon HTTP server on addr (loopback) and blocks until the server exits. onReady, if set, runs once this process owns the address and the state directory -- the point at which it is THE daemon -- and is where the caller records its pid.

Types

type InitiativeDocInput

type InitiativeDocInput struct {
	Content string
	Kind    string
	Title   string
}

InitiativeDocInput is one context doc supplied atomically at initiative creation (idea new --doc).

type PreconditionError

type PreconditionError struct {
	Reason string
}

PreconditionError marks an error as the caller asking for something the current state does not allow -- "initiative is already running", "advance requires an approved PRD". It exists so writeErr can answer 409 without each handler remembering to.

The audit found handleAdvance and handleRevise mapping every error to 500, including those two, while their four siblings -- retry, approve-plan, reopen-phase, revise-plan -- returned 409 for the identical class. Hand-mapping a sixth handler would have left the seventh to get it wrong; this makes the classification travel with the error instead.

Deliberately narrow. Only Runtime.* precondition checks return this type, never internal/workflow. Handler call sites pass http.StatusBadRequest for engine errors; retyping an error those paths can surface would silently flip a 400 into a 409, so the type is applied to an enumerated set and TestPrecondition pins both halves.

Runtime.RunVerificationGate joined that set when `idea verify` stopped being able to complete a failed initiative. Note what did and did not change: Engine.VerifyInitiative's own errors still reach writeErr as plain errors and still answer 400. What carries this type is the Runtime's own read of the status, and the translation of store.ErrInitiativeNotClaimable, both of which are preconditions on the request rather than failures inside the gate.

func (*PreconditionError) Error

func (e *PreconditionError) Error() string

type Runtime

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

Runtime owns the global registry, the per-install token, and lazily-opened per-project runtimes.

func NewRuntime

func NewRuntime(stateRoot string, log *slog.Logger) (*Runtime, error)

NewRuntime opens (creating if needed) the global state and token.

func (*Runtime) AdvanceInitiative

func (r *Runtime) AdvanceInitiative(ctx context.Context, projectID, initiativeID string) (string, error)

AdvanceInitiative runs the M2 slice (Design → Execution Plan → plan review) asynchronously. Returns the operation id.

func (*Runtime) ApplyChangeSetInitiative

func (r *Runtime) ApplyChangeSetInitiative(ctx context.Context, projectID, initiativeID, changeSetID string) (string, error)

ApplyChangeSetInitiative applies an approved change set asynchronously.

func (*Runtime) ApproveInitiative added in v0.4.0

func (r *Runtime) ApproveInitiative(ctx context.Context, projectID, initiativeID string) (domain.InitiativeStatus, error)

ApproveInitiative records human approval of the reviewed PRD.

A Runtime wrapper rather than a direct engine call from the handler, and that is deliberate: preconditionf is what writeErr turns into a 409, and it is also what `make api-check`'s conflict axis scans for. Calling the engine straight from the handler and mapping the error to 409 there would have produced the right status code and a spec that silently never declared it -- the checker only sees preconditionf inside Runtime methods.

func (*Runtime) ApprovePlanInitiative

func (r *Runtime) ApprovePlanInitiative(ctx context.Context, projectID, initiativeID string) (string, error)

ApprovePlanInitiative accepts the execution plan, findings and all.

func (*Runtime) CancelOperation

func (r *Runtime) CancelOperation(ctx context.Context, opID string) error

CancelOperation interrupts a running asynchronous operation (M3, §16): it cancels the operation's context so the in-flight model/command call unwinds, and marks the operation cancelled so callers observe the terminal state immediately. Returns an error when no live handle exists (already settled or orphaned after a daemon restart).

func (*Runtime) Close

func (r *Runtime) Close() error

Close releases global resources.

func (*Runtime) CreateProject

func (r *Runtime) CreateProject(ctx context.Context, rootPath string) (string, error)

CreateProject initializes .idea-harness/ in rootPath and registers it.

func (*Runtime) EnsureProject

func (r *Runtime) EnsureProject(ctx context.Context, projectID string) (*projectRuntime, error)

EnsureProject returns (opening if needed) the runtime for a project id. Construction is single-flight: r.mu is held across the whole build so two concurrent first-opens cannot open two *store.DB handles for one project (full-platform review: project-runtime race).

func (*Runtime) ExecuteInitiative

func (r *Runtime) ExecuteInitiative(ctx context.Context, projectID, initiativeID string) (string, error)

ExecuteInitiative runs the M3 execute pipeline for the next ready task asynchronously, producing a change set. Returns the operation id.

func (*Runtime) ListProjects

func (r *Runtime) ListProjects(ctx context.Context) ([]store.ProjectRecord, error)

ListProjects returns the registry entries.

func (*Runtime) ReloadProject

func (r *Runtime) ReloadProject(ctx context.Context, projectID string) (*projectRuntime, error)

ReloadProject drops the cached runtime so the next EnsureProject re-reads config and rebuilds the provider registry (§40). It rebuilds the and rebuilds the provider registry (§40). It builds a NEW *projectRuntime reusing the same *store.DB (no second DB handle) and swaps the pointer under r.mu, so a reload never mutates fields that a concurrent reader/operation is using (review: project-runtime / field-swap race). Reconciliation does not re-run (reconciled flag stays set).

func (*Runtime) ReopenPhaseInitiative

func (r *Runtime) ReopenPhaseInitiative(ctx context.Context, projectID, initiativeID, phase string) (string, error)

ReopenPhaseInitiative re-runs a design phase and everything downstream (cascade) asynchronously. Returns the operation id.

func (*Runtime) ResumeInitiative added in v0.4.0

func (r *Runtime) ResumeInitiative(ctx context.Context, projectID, initiativeID string) (domain.InitiativeStatus, error)

ResumeInitiative re-runs the review loop for an initiative parked on a human.

func (*Runtime) RetryConflictedApply

func (r *Runtime) RetryConflictedApply(ctx context.Context, projectID, initiativeID, changeSetID string) (string, error)

RetryConflictedApply resets a conflicted change set to approved and re-runs the existing async apply path. Returns the operation id.

func (*Runtime) RetryInitiative

func (r *Runtime) RetryInitiative(ctx context.Context, projectID, initiativeID, model string) (string, error)

RetryInitiative re-runs a failed initiative's workflow under a chosen model (retry-with-a-different-model). Returns the operation id.

func (*Runtime) RevertChangeSetInitiative

func (r *Runtime) RevertChangeSetInitiative(ctx context.Context, projectID, initiativeID, changeSetID string) (string, error)

RevertChangeSetInitiative records a rolled-back journal entry for a change set asynchronously.

func (*Runtime) ReviseInitiative

func (r *Runtime) ReviseInitiative(ctx context.Context, projectID, initiativeID string) (string, error)

ReviseInitiative applies the human's decisions by re-running product definition + review asynchronously (§8, §11).

func (*Runtime) RevisePlanInitiative

func (r *Runtime) RevisePlanInitiative(ctx context.Context, projectID, initiativeID string) (string, error)

RevisePlanInitiative regenerates the execution plan (and its review) asynchronously, keeping the PRD/design artifacts. Returns the operation id.

func (*Runtime) RunVerificationGate added in v0.4.0

func (r *Runtime) RunVerificationGate(ctx context.Context, projectID, initiativeID, requirement string,
	disposition domain.VerificationStatus, note string) (domain.InitiativeStatus, []workflow.Coverage, error)

RunVerificationGate records any human evidence in the request and then runs the verification gate, refusing an initiative that has already failed.

Verify was the one state-writing path that never went through the Runtime: handleVerify called the engine directly, with no running check, no claim and no state precondition -- which is why `verifyInitiative` declared no 409 and the conflict axis correctly agreed there was nothing to declare.

`failed` only. `running` is deliberately NOT refused: `idea apply` does not wait for its operation, and the initiative reads `running` until the release that follows the change set being marked applied -- so the documented apply-then-verify sequence (docs/demo-greenfield.md, and scripts/smoke.sh, which polls the change set and then verifies) runs inside that window. Refusing it there would break the flow this fix is not about.

The residual that leaves: a `complete` written during an in-flight apply can be reverted by that apply's release, which writes priorStatus unconditionally. Pre-existing, recorded in docs/plans/deferred.md, and not closed here.

func (*Runtime) Shutdown added in v0.5.0

func (r *Runtime) Shutdown(ctx context.Context) error

Shutdown cancels every running operation and waits, until ctx expires, for them to finish.

Go exits at once on SIGTERM, which is what `idea daemon stop` sends, so no deferred cleanup ran: an agent container kept running with the provider key, network access and auto-approve, writing into the work root, until something happened to load the project again. Cancelling an operation's context is what makes the engine remove its container.

func (*Runtime) StartInitiative

func (r *Runtime) StartInitiative(ctx context.Context, projectID, title, description string) (string, string, error)

StartInitiative creates an initiative + operation and runs the workflow asynchronously (§34). Returns the initiative and operation ids.

func (*Runtime) StartInitiativeWithDocs

func (r *Runtime) StartInitiativeWithDocs(ctx context.Context, projectID, title, description string, docs []InitiativeDocInput) (string, string, error)

StartInitiativeWithDocs creates an initiative, ingests its context docs, and only THEN launches the M1 run — so `idea new --doc` grounds framing/research/ PRD in the supplied material. Docs are size-checked, credential-swept and validated BEFORE the initiative is created, so a rejected doc never leaves a half-created row; anything that fails after creation marks the initiative failed rather than stranding it in `running`.

func (*Runtime) StateRoot

func (r *Runtime) StateRoot() string

StateRoot returns the global state directory.

func (*Runtime) SuggestAnswersInitiative

func (r *Runtime) SuggestAnswersInitiative(ctx context.Context, projectID, initiativeID string) (string, error)

SuggestAnswersInitiative generates AI answers for open questions asynchronously and persists them. Returns the operation id.

func (*Runtime) Token

func (r *Runtime) Token() string

Token returns the per-install API token.

type Server

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

Server is the localhost HTTP API.

func NewServer

func NewServer(rt *Runtime) *Server

NewServer builds the API server.

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler returns the authenticated, loopback-hardened handler.

Jump to

Keyboard shortcuts

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