Class DesignStore
plan_id and
optimization results keyed by the fingerprint of the spec they were run for, so the tools can be
chained (design_optimize then design_plan_deployment, design_get_plan,
design_plan_drift, design_export_terraform) without repeating work.
Scope: single-process only. Ids resolve only inside this server process; when
the MCP host restarts the server they are gone. A plan id is a content hash
(DeploymentPlan.planId()), so storing the same plan again refreshes its entry rather than
creating a second one.
Bounds and honesty: each kind keeps at most capacity() entries for
ttl() (default 60 minutes). Storing beyond capacity evicts the oldest entry of that kind and
putPlan(DeploymentPlan)/putOptimization(OptimizationResult) return what was evicted so the tool result can say so, as
the broker's ProposalStore does. Expired and evicted ids are remembered for one further TTL
window, so a later lookup answers DesignStore.Status.EXPIRED or DesignStore.Status.EVICTED instead of a bare
DesignStore.Status.UNKNOWN.
Thread-safe; every method synchronizes on the store. The clock is injectable for tests.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordA stored entry.static enumWhat a store entry holds.static final recordThe outcome of a lookup.static final recordThe outcome of a store.static enumHow a lookup resolved. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDefault maximum number of stored entries per kind.static final DurationDefault time-to-live of a stored plan or optimization result. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a store with the default TTL (60 minutes) and capacity (20 per kind).DesignStore(Clock clock, Duration ttl, int capacity) Creates a store with an explicit clock, TTL and capacity. -
Method Summary
Modifier and TypeMethodDescriptionintcapacity()explainMissing(DesignStore.Kind kind, String id, DesignStore.Status status) An instruction for the calling model when a lookup did not find a live entry.optimization(String specFingerprint) plans()putOptimization(OptimizationResult result) Stores an optimization result under its spec fingerprint.putPlan(DeploymentPlan plan) Stores a plan under its content-hash id.intsize(DesignStore.Kind kind) ttl()
-
Field Details
-
DEFAULT_TTL
Default time-to-live of a stored plan or optimization result. -
DEFAULT_CAPACITY
public static final int DEFAULT_CAPACITYDefault maximum number of stored entries per kind.- See Also:
-
-
Constructor Details
-
DesignStore
public DesignStore()Creates a store with the default TTL (60 minutes) and capacity (20 per kind). -
DesignStore
-
-
Method Details
-
putPlan
Stores a plan under its content-hash id.- Parameters:
plan- the plan- Returns:
- the id and any plans evicted to make room
-
putOptimization
Stores an optimization result under its spec fingerprint.- Parameters:
result- the result; itsspecFingerprintmust be set- Returns:
- the id and any results evicted to make room
-
plan
- Parameters:
planId- a plan id- Returns:
- the lookup outcome;
DesignStore.Lookup.entry()is set only whenDesignStore.Status.FOUND
-
optimization
- Parameters:
specFingerprint- a spec fingerprint- Returns:
- the lookup outcome;
DesignStore.Lookup.entry()is set only whenDesignStore.Status.FOUND
-
plans
- Returns:
- the live plans, oldest first
-
optimizations
- Returns:
- the live optimization results, oldest first
-
size
- Parameters:
kind- the kind- Returns:
- the number of live entries of that kind
-
ttl
- Returns:
- the time-to-live of an entry
-
capacity
public int capacity()- Returns:
- the maximum number of entries per kind
-
explainMissing
An instruction for the calling model when a lookup did not find a live entry.- Parameters:
kind- what was looked upid- the id that was givenstatus- the lookup status- Returns:
- a sentence saying what happened and how to recover
-