@@ -181,6 +181,52 @@ export class EventStore {
181181 ) ;
182182 }
183183
184+ recordTerminalOutcome ( outcome : {
185+ goal_id : string ;
186+ repo_id ?: string ;
187+ status : "completed" | "failed" | "cancelled" | "blocked" | "budget_exhausted" ;
188+ evidence : string [ ] ;
189+ summary : string ;
190+ candidate ?: {
191+ id : string ;
192+ lesson_type : string ;
193+ title : string ;
194+ summary : string ;
195+ confidence : string ;
196+ } ;
197+ } ) : boolean {
198+ if ( ! outcome . goal_id . trim ( ) || ! outcome . summary . trim ( ) || outcome . evidence . length === 0 ) {
199+ throw new Error ( "Terminal outcomes require goal id, summary, and evidence." ) ;
200+ }
201+ const now = new Date ( ) . toISOString ( ) ;
202+ const transaction = this . db . transaction ( ( ) => {
203+ const inserted = this . db . prepare ( `
204+ INSERT OR IGNORE INTO terminal_outcomes (goal_id, repo_id, status, evidence_json, summary, created_at)
205+ VALUES (?, ?, ?, ?, ?, ?)
206+ ` ) . run ( outcome . goal_id , outcome . repo_id || null , outcome . status , JSON . stringify ( outcome . evidence ) , outcome . summary , now ) ;
207+ if ( inserted . changes === 0 ) return false ;
208+ if ( outcome . candidate ) {
209+ this . recordLesson ( {
210+ id : outcome . candidate . id ,
211+ repo_id : outcome . repo_id ,
212+ lesson_type : outcome . candidate . lesson_type ,
213+ title : outcome . candidate . title ,
214+ summary : outcome . candidate . summary ,
215+ evidence_json : JSON . stringify ( outcome . evidence ) ,
216+ confidence : outcome . candidate . confidence ,
217+ source : "terminal_outcome" ,
218+ approved : 0 ,
219+ } ) ;
220+ }
221+ return true ;
222+ } ) ;
223+ return transaction ( ) ;
224+ }
225+
226+ getTerminalOutcome ( goalId : string ) : any | undefined {
227+ return this . db . prepare ( `SELECT * FROM terminal_outcomes WHERE goal_id = ?` ) . get ( goalId ) ;
228+ }
229+
184230 linkCommitToExecution ( executionId : string , commitId : string ) {
185231 const stmt = this . db . prepare ( `
186232 INSERT OR IGNORE INTO execution_commits (execution_id, commit_id)
0 commit comments