daemon

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: 39 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) error

Run starts the daemon HTTP server on addr (loopback) and blocks until the server exits.

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.*Initiative precondition checks return this type, never internal/workflow. Fourteen handler call sites pass http.StatusBadRequest for engine errors (ReviewChangeSet and VerifyInitiative among them); 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.

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) ApprovePlanInitiative

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

ApprovePlanInitiative re-runs the execution-plan review asynchronously.

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) 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) 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 credential-swept/validated BEFORE the initiative is created, so a rejected doc never leaves a half-created row.

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