1
/**2
* Pure types of the goal domain: the ONE home of the `goal` projection-key3
* declaration plus the durable payload vocabulary it carries, free of this4
* package's host-side imports (cordis events, dsh-agent, dsh-llm, the5
* service). Two namespace projections serve it — `./types` for host6
* consumers, `./client` (the browser half-entry's re-export) for client7
* aggregates — with zero content duplication. Host-coupled domain8
* vocabulary (message sources, events, fold shapes) lives in ./domain.ts.9
*10
* @module @deepseek-ai/dsh-goal/types11
*/13
import type { Branded } from '@deepseek-ai/dsh-brand'14
import type { SessionId } from '@deepseek-ai/dsh-session/types'16
/** Identifies one goal across its durable revisions. */17
export type GoalId = Branded<'GoalId'>19
/** Compare-and-set identity for one exact goal revision. */20
export interface GoalRef {21
/** Stable goal identity. */22
readonly id: GoalId23
/** Positive revision; every durable mutation increments it. */24
readonly revision: number25
}27
/** Input whose omitted round cap is resolved by the service configuration. */28
export interface CreateGoalRequest {29
readonly objective: string30
readonly maxGoalRounds?: number31
}33
/** Wire-safe acknowledgement of one created goal. */34
export interface CreateGoalResult {35
readonly ref: GoalRef36
}38
/** Fields changed by an edit; at least one must be present. */39
export interface EditGoalRequest {40
readonly objective?: string41
readonly maxGoalRounds?: number42
}44
/** Durable continuation phase. Activation is process-local and separate. */45
export type GoalPhase =46
| 'active'47
| 'paused'48
| 'blocked'49
| 'complete'51
/** Machine-routable and human-readable explanation for a blocked goal. */52
export interface GoalBlockReason {53
/** Stable lower-kebab-case classification chosen by the blocking policy. */54
readonly code: string55
/** Non-empty explanation shown to humans and models. */56
readonly message: string57
}59
/** Full durable state written by every non-clear goal mutation. */60
export interface GoalSnapshot extends GoalRef {61
/** Human-requested completion objective. */62
readonly objective: string63
/** Durable lifecycle phase. */64
readonly phase: GoalPhase65
/** Present exactly while `phase` is `blocked`. */66
readonly blockedReason?: GoalBlockReason67
/** Total admitted goal-round cap. */68
readonly maxGoalRounds: number69
}71
/** Whether this live process may automatically continue an active goal. */72
export type GoalActivation = 'armed' | 'disarmed'74
/** Live process-local activation update forwarded to UI clients. */75
export interface GoalActivationChanged {76
/** Session whose live goal activation changed. */77
readonly sessionId: SessionId78
/** Current exact activation, absent when no goal is current. */79
readonly goal?: {80
/** Exact current goal identity. */81
readonly id: GoalId82
/** Exact current goal revision. */83
readonly revision: number84
/** Current process-local continuation state. */85
readonly activation: GoalActivation86
}87
}89
/** Current goal projection, including values derived from the session log. */90
export interface GoalView extends GoalSnapshot {91
/** Highest admitted round number for this goal. */92
readonly roundsStarted: number93
/** Epoch milliseconds of the create mutation. */94
readonly createdAt: number95
/** Epoch milliseconds of the latest mutation. */96
readonly updatedAt: number97
/** Process-local continuation eligibility; never persisted. */98
readonly activation: GoalActivation99
}101
/**102
* The `goal` projection value: the current durable goal with its replay103
* counters, including admitted goal rounds.104
* Activation is process-local (never persisted) and deliberately absent —105
* the projection reflects durable phase only.106
*/107
export interface GoalProjection {108
/** Current durable goal snapshot (the CAS ref for mutations rides on it). */109
readonly goal: GoalSnapshot110
/** Highest admitted round number for this goal. */111
readonly roundsStarted: number112
/** Epoch milliseconds of the create mutation. */113
readonly createdAt: number114
/** Epoch milliseconds of the latest mutation. */115
readonly updatedAt: number116
}118
/** Strict checkpoint state used to derive the current goal client value. */119
export interface GoalProjectionState {120
/** Latest valid current goal, or null before creation and after clear. */121
readonly current: GoalProjection | null122
/** Goal identities already created in this Session, retained to reject reuse. */123
readonly seenGoalIds: GoalId[]124
/** First strict replay failure, or null while the durable stream is valid. */125
readonly failure: string | null126
}128
declare module '@deepseek-ai/dsh-session-projection/types' {129
interface SessionProjectionStateMap {130
goal: GoalProjectionState131
}132
interface SessionProjectionMap {133
/**134
* The session's current goal and admitted-round count, or135
* `null` before the first create and after a clear tombstone.136
* `goal/change` supplies the whole lifecycle value; matching admitted137
* `user/message` events advance `roundsStarted`.138
*/139
goal: GoalProjection | null140
}141
}143
declare module '@deepseek-ai/cordis' {144
interface Events {145
/**146
* Process-local goal activation changed for one session.147
* @mode emit148
* @param payload - session id and the exact current goal activation, or no goal after a clear.149
*/150
'goal/activation-changed'(payload: GoalActivationChanged): void151
}152
}