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 ¶
- func DefaultStateRoot() string
- func Run(addr, stateRoot string, log *slog.Logger, onReady func()) error
- type ConfirmResult
- type ConfirmSkipped
- type InitiativeDocInput
- type PreconditionError
- type Runtime
- func (r *Runtime) AdvanceInitiative(ctx context.Context, projectID, initiativeID string) (string, error)
- func (r *Runtime) ApplyChangeSetInitiative(ctx context.Context, projectID, initiativeID, changeSetID string) (string, error)
- func (r *Runtime) ApproveInitiative(ctx context.Context, projectID, initiativeID string) (domain.InitiativeStatus, error)
- func (r *Runtime) ApprovePlanInitiative(ctx context.Context, projectID, initiativeID string) (string, error)
- func (r *Runtime) CancelOperation(ctx context.Context, opID string) error
- func (r *Runtime) Close() error
- func (r *Runtime) CreatePRForInitiative(ctx context.Context, projectID, initiativeID string) (string, error)
- func (r *Runtime) CreateProject(ctx context.Context, rootPath string) (string, error)
- func (r *Runtime) EnsureProject(ctx context.Context, projectID string) (*projectRuntime, error)
- func (r *Runtime) ExecuteInitiative(ctx context.Context, projectID, initiativeID string) (string, error)
- func (r *Runtime) ExecuteInitiativeFresh(ctx context.Context, projectID, initiativeID string, fresh bool) (string, error)
- func (r *Runtime) ExecuteInitiativeFreshWithNote(ctx context.Context, projectID, initiativeID string, fresh bool, note string) (string, error)
- func (r *Runtime) ListProjects(ctx context.Context) ([]store.ProjectRecord, error)
- func (r *Runtime) PRChecksForChangeSet(ctx context.Context, projectID, changeSetID string) (git.PRChecksResult, error)
- func (r *Runtime) ReloadProject(ctx context.Context, projectID string) (*projectRuntime, error)
- func (r *Runtime) ReopenPhaseInitiative(ctx context.Context, projectID, initiativeID, phase string) (string, error)
- func (r *Runtime) RerunChangeSetReviewInitiative(ctx context.Context, projectID, initiativeID, changeSetID string) (string, error)
- func (r *Runtime) ResumeInitiative(ctx context.Context, projectID, initiativeID string) (domain.InitiativeStatus, error)
- func (r *Runtime) RetryConflictedApply(ctx context.Context, projectID, initiativeID, changeSetID string) (string, error)
- func (r *Runtime) RetryInitiative(ctx context.Context, projectID, initiativeID, model string) (string, error)
- func (r *Runtime) RetryInitiativeWithNote(ctx context.Context, projectID, initiativeID, model, note string) (string, error)
- func (r *Runtime) RevertChangeSetInitiative(ctx context.Context, projectID, initiativeID, changeSetID string) (string, error)
- func (r *Runtime) ReviseInitiative(ctx context.Context, projectID, initiativeID string) (string, error)
- func (r *Runtime) RevisePlanInitiative(ctx context.Context, projectID, initiativeID string) (string, error)
- func (r *Runtime) RunVerificationGate(ctx context.Context, projectID, initiativeID, requirement string, ...) (domain.InitiativeStatus, []workflow.Coverage, error)
- func (r *Runtime) RunVerificationGateConfirmingTests(ctx context.Context, projectID, initiativeID, requirement string, ...) (domain.InitiativeStatus, []workflow.Coverage, *ConfirmResult, error)
- func (r *Runtime) Shutdown(ctx context.Context) error
- func (r *Runtime) StartInitiative(ctx context.Context, projectID, title, description string) (string, string, error)
- func (r *Runtime) StartInitiativeWithDocs(ctx context.Context, projectID, title, description string, ...) (string, string, error)
- func (r *Runtime) StateRoot() string
- func (r *Runtime) SuggestAnswersInitiative(ctx context.Context, projectID, initiativeID string) (string, error)
- func (r *Runtime) Token() string
- type Server
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.
Types ¶
type ConfirmResult ¶ added in v0.6.0
type ConfirmResult struct {
Confirmed []string `json:"confirmed"`
Skipped []ConfirmSkipped `json:"skipped"`
}
ConfirmResult reports what confirmPassingTests did (C3/H2, review fix): which requirement codes it actually confirmed, and which candidates it looked at but skipped, and why -- so a bad requirement never aborts the whole loop silently, and the caller (the HTTP handler, in turn the UI's confirm dialog) can show exactly what happened instead of a bare status.
type ConfirmSkipped ¶ added in v0.6.0
type ConfirmSkipped struct {
Requirement string `json:"requirement"`
Reason string `json:"reason"`
}
ConfirmSkipped names one requirement confirmPassingTests looked at but did not confirm, and why.
type InitiativeDocInput ¶
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 ¶
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 ¶
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) CreatePRForInitiative ¶ added in v0.6.0
func (r *Runtime) CreatePRForInitiative(ctx context.Context, projectID, initiativeID string) (string, error)
CreatePRForInitiative pushes the initiative's dedicated branch and opens a pull request via `gh pr create` (review C4 piece 3), synchronously: unlike apply/execute/revert it neither claims the initiative nor mutates the workspace tree, only git/GitHub state, so there is no long-running pipeline to run as a background operation. The three ways this can be refused -- no dedicated branch yet, `gh` not installed, or (PRChecksForChangeSet only) no PR yet -- are classified here as preconditions, never inside internal/workflow (see PreconditionError's doc comment), so a caller answers 409 with a message naming exactly which of the three it hit.
func (*Runtime) CreateProject ¶
CreateProject initializes .idea-harness/ in rootPath and registers it.
func (*Runtime) EnsureProject ¶
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).
Every HTTP handler resolves its project through here (Server.project), so this is also the single choke point for maybeAutoReload: a cached project whose harness.yaml has changed on disk since it was last loaded -- a hand edit, e.g. to test_cmd -- is reloaded before its (possibly stale) runtime is handed back (review defect #4).
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) ExecuteInitiativeFresh ¶ added in v0.5.1
func (r *Runtime) ExecuteInitiativeFresh(ctx context.Context, projectID, initiativeID string, fresh bool) (string, error)
ExecuteInitiativeFresh is ExecuteInitiative; with fresh, a stopped run's kept files are discarded once the run is accepted, so it starts from the workspace ("Start over").
func (*Runtime) ExecuteInitiativeFreshWithNote ¶ added in v0.6.0
func (r *Runtime) ExecuteInitiativeFreshWithNote(ctx context.Context, projectID, initiativeID string, fresh bool, note string) (string, error)
ExecuteInitiativeFreshWithNote is ExecuteInitiativeFresh, with an optional human note (D-a, wave 3 contract) that steers this one execute: appended to the implementer's brief and recorded on the agent run. Set on the engine BEFORE launching, and cleared by Execute itself once that run finishes, so it can never bleed into a later, unrelated execute of this initiative.
func (*Runtime) ListProjects ¶
ListProjects returns the registry entries.
func (*Runtime) PRChecksForChangeSet ¶ added in v0.6.0
func (r *Runtime) PRChecksForChangeSet(ctx context.Context, projectID, changeSetID string) (git.PRChecksResult, error)
PRChecksForChangeSet reports the latest CI status of changeSetID's initiative's pull request via `gh pr checks`. See CreatePRForInitiative's doc comment for why "no PR yet" and "no gh" are classified here.
func (*Runtime) ReloadProject ¶
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) RerunChangeSetReviewInitiative ¶ added in v0.6.0
func (r *Runtime) RerunChangeSetReviewInitiative(ctx context.Context, projectID, initiativeID, changeSetID string) (string, error)
RerunChangeSetReviewInitiative runs the adversarial reviewer again for a change set whose review never completed, as an async operation (ICP re-run D2). The review itself is a real model call -- observed 1m12s-1m38s across four founder-journey runs -- which used to run SYNCHRONOUSLY inside the HTTP handler (detached from the request's own cancellation, but not from the CLI's 60s http.Client timeout): the daemon always finished the work, but the CLI reported a timeout error on every single invocation of a brand-new command, because it was still blocked waiting for the response when its own client gave up. It now returns an operation id immediately, the same shape `idea apply`/`idea execute` use, so `idea review <id> rerun` can be waited on/watched/cancelled like any other long-running action instead of racing a fixed client timeout against a model call.
The two precondition checks that used to fail fast, synchronously, inside Engine.RerunChangeSetReview are duplicated here (read-only, no model call) so a wrong-state rerun still refuses immediately with a normal 4xx rather than an operation the caller must poll to learn failed instantly. Engine.RerunChangeSetReview re-checks both under its own lock regardless, which is the correctness boundary; this is purely for a fast, synchronous answer on the common misuse.
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. It stays synchronous (unlike Advance/RevisePlan/ReopenPhase below): callers get the final status directly, as before.
review H4: Resume used to run Engine.Resume with no operation row at all -- the only claiming entry point that didn't create one. That made it invisible to ListUnfinishedOperations, which both ReloadProject's "refuse to swap config while an operation is running" guard and reconcileStaleOperations key off: a reload could swap in a new redactor/registry/cfg mid-review-loop (a secret just added to harness.yaml would not be swept from the second half of the run), and a daemon crash mid-Resume stranded Engine.Resume's own ClaimInitiativeRunning claim with nothing for the sweep to find -- exactly what that claim's own comment already flagged. The operation row here is bookkeeping only: Resume still runs synchronously in this goroutine and still self-claims/self-releases inside Engine.Resume exactly as before (its own defer already restores needs_human_judgment on error); only ops visibility changes, so this operation's own status is recorded here rather than via failOperation (which would also fail the initiative -- Engine.Resume already decided that outcome).
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) RetryInitiativeWithNote ¶ added in v0.6.0
func (r *Runtime) RetryInitiativeWithNote(ctx context.Context, projectID, initiativeID, model, note string) (string, error)
RetryInitiativeWithNote is RetryInitiative, with an optional human note (D-a, wave 3 contract) that steers this one retry. Retry re-runs the framing→research→PRD→review pipeline rather than the implementer, so the note joins the framing prompt (see Engine.runFraming) instead of "the implementer's brief" the wave 3 contract names -- there is no implementer brief at this stage of the pipeline for it to join.
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) RunVerificationGateConfirmingTests ¶ added in v0.6.0
func (r *Runtime) RunVerificationGateConfirmingTests(ctx context.Context, projectID, initiativeID, requirement string, disposition domain.VerificationStatus, note string, confirmPassingTests bool) (domain.InitiativeStatus, []workflow.Coverage, *ConfirmResult, error)
RunVerificationGateConfirmingTests is RunVerificationGate, with confirmPassingTests (C2, wire contract: `POST .../verify {"confirm_passing_tests": true}`) additionally confirming, through the same human-evidence path (actor "human"), every requirement whose mapped tests all passed. Never runs without this explicit request -- nothing here is invoked from any other path. The returned *ConfirmResult is nil unless confirmPassingTests was requested.
func (*Runtime) Shutdown ¶ added in v0.5.0
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`.