@@ -8,13 +8,13 @@ import type {
88} from "./index" ;
99import { timeSpecsEqual } from "./time-spec" ;
1010
11- type ScheduleSlot = "day" | "time" | "duration" ;
11+ type ScheduleFieldKey = "day" | "time" | "duration" ;
1212
1313export type CommitPolicyInput = {
1414 turnType : TurnInterpretation [ "turnType" ] ;
15- extractedValues : Partial < Record < ScheduleSlot , unknown > > ;
16- confidence : Partial < Record < ScheduleSlot , number > > ;
17- unresolvable : ScheduleSlot [ ] ;
15+ extractedValues : Partial < Record < ScheduleFieldKey , unknown > > ;
16+ confidence : Partial < Record < ScheduleFieldKey , number > > ;
17+ unresolvable : ScheduleFieldKey [ ] ;
1818 operationKind : OperationKind ;
1919 priorPendingWriteOperation ?: PendingWriteOperation | undefined ;
2020 currentTargetEntityId ?: string ;
@@ -28,7 +28,7 @@ export type CommitPolicyOutput = {
2828 workflowChanged : boolean ;
2929} ;
3030
31- export const SLOT_COMMITTING_TURN_TYPES = new Set <
31+ export const FIELD_COMMITTING_TURN_TYPES = new Set <
3232 TurnInterpretation [ "turnType" ]
3333> ( [ "clarification_answer" , "planning_request" , "edit_request" ] ) ;
3434
@@ -39,7 +39,7 @@ const CORRECTION_THRESHOLD = 0.9;
3939// Contract derivation lives here rather than as a pre-extraction gate.
4040function requiredFieldsForOperation (
4141 operationKind : OperationKind ,
42- ) : ScheduleSlot [ ] {
42+ ) : ScheduleFieldKey [ ] {
4343 switch ( operationKind ) {
4444 case "plan" :
4545 return [ "day" , "time" ] ;
@@ -77,53 +77,54 @@ export function applyCommitPolicy(
7777 ( operationKind !== priorPendingWriteOperation . operationKind ||
7878 targetChanged ) ;
7979
80- const priorScheduleFields : Partial < Record < ScheduleSlot , unknown > > =
80+ const priorScheduleFields : Partial < Record < ScheduleFieldKey , unknown > > =
8181 operationChanged
8282 ? { }
8383 : {
8484 ...( priorPendingWriteOperation ?. resolvedFields . scheduleFields ?? { } ) ,
8585 } ;
8686
8787 const needsClarification : string [ ] = [ ] ;
88- const committedSchedule : Partial < Record < ScheduleSlot , unknown > > = {
88+ const committedScheduleFields : Partial < Record < ScheduleFieldKey , unknown > > = {
8989 ...priorScheduleFields ,
9090 } ;
9191
92- if ( SLOT_COMMITTING_TURN_TYPES . has ( turnType ) ) {
93- const slotKeys = Object . keys ( extractedValues ) as ScheduleSlot [ ] ;
92+ if ( FIELD_COMMITTING_TURN_TYPES . has ( turnType ) ) {
93+ const extractedFieldKeys = Object . keys ( extractedValues ) as ScheduleFieldKey [ ] ;
9494
95- for ( const slot of slotKeys ) {
96- const value = extractedValues [ slot ] ;
95+ for ( const fieldKey of extractedFieldKeys ) {
96+ const value = extractedValues [ fieldKey ] ;
9797 if ( value === undefined ) continue ;
9898
99- if ( unresolvable . includes ( slot ) ) {
100- needsClarification . push ( `scheduleFields.${ slot } ` ) ;
99+ if ( unresolvable . includes ( fieldKey ) ) {
100+ needsClarification . push ( `scheduleFields.${ fieldKey } ` ) ;
101101 continue ;
102102 }
103103
104- const slotConfidence = confidence [ slot ] ?? 0 ;
105- if ( slotConfidence < CONFIDENCE_THRESHOLD ) {
106- needsClarification . push ( `scheduleFields.${ slot } ` ) ;
104+ const fieldConfidence = confidence [ fieldKey ] ?? 0 ;
105+ if ( fieldConfidence < CONFIDENCE_THRESHOLD ) {
106+ needsClarification . push ( `scheduleFields.${ fieldKey } ` ) ;
107107 continue ;
108108 }
109109
110- const priorValue = priorScheduleFields [ slot ] ;
110+ const priorValue = priorScheduleFields [ fieldKey ] ;
111111 const isCorrection =
112- priorValue !== undefined && ! slotValuesEqual ( slot , priorValue , value ) ;
113- if ( isCorrection && slotConfidence < CORRECTION_THRESHOLD ) {
114- needsClarification . push ( `scheduleFields.${ slot } ` ) ;
112+ priorValue !== undefined &&
113+ ! scheduleFieldValuesEqual ( fieldKey , priorValue , value ) ;
114+ if ( isCorrection && fieldConfidence < CORRECTION_THRESHOLD ) {
115+ needsClarification . push ( `scheduleFields.${ fieldKey } ` ) ;
115116 continue ;
116117 }
117118
118- committedSchedule [ slot ] = value ;
119+ committedScheduleFields [ fieldKey ] = value ;
119120 }
120121
121- for ( const slot of unresolvable ) {
122- const dotPath = `scheduleFields.${ slot } ` ;
122+ for ( const fieldKey of unresolvable ) {
123+ const dotPath = `scheduleFields.${ fieldKey } ` ;
123124 if (
124- ! slotKeys . includes ( slot ) &&
125+ ! extractedFieldKeys . includes ( fieldKey ) &&
125126 ! needsClarification . includes ( dotPath ) &&
126- committedSchedule [ slot ] === undefined
127+ committedScheduleFields [ fieldKey ] === undefined
127128 ) {
128129 needsClarification . push ( dotPath ) ;
129130 }
@@ -132,15 +133,15 @@ export function applyCommitPolicy(
132133
133134 const resolvedFields : ResolvedFields = {
134135 scheduleFields :
135- Object . keys ( committedSchedule ) . length > 0
136- ? ( committedSchedule as ResolvedFields [ "scheduleFields" ] )
136+ Object . keys ( committedScheduleFields ) . length > 0
137+ ? ( committedScheduleFields as ResolvedFields [ "scheduleFields" ] )
137138 : undefined ,
138139 } ;
139140
140- const requiredSlots = requiredFieldsForOperation ( operationKind ) ;
141- const missingFields = requiredSlots
142- . filter ( ( slot ) => committedSchedule [ slot ] === undefined )
143- . map ( ( slot ) => `scheduleFields.${ slot } ` ) ;
141+ const requiredFieldKeys = requiredFieldsForOperation ( operationKind ) ;
142+ const missingFields = requiredFieldKeys
143+ . filter ( ( fieldKey ) => committedScheduleFields [ fieldKey ] === undefined )
144+ . map ( ( fieldKey ) => `scheduleFields.${ fieldKey } ` ) ;
144145
145146 // Carry forward the prior target unless this turn introduced a new one.
146147 const resolvedTargetRef : TargetRef = currentTargetEntityId
@@ -156,8 +157,12 @@ export function applyCommitPolicy(
156157 } ;
157158}
158159
159- function slotValuesEqual ( slot : ScheduleSlot , a : unknown , b : unknown ) : boolean {
160- if ( slot === "time" && a && b ) {
160+ function scheduleFieldValuesEqual (
161+ fieldKey : ScheduleFieldKey ,
162+ a : unknown ,
163+ b : unknown ,
164+ ) : boolean {
165+ if ( fieldKey === "time" && a && b ) {
161166 return timeSpecsEqual ( a as TimeSpec , b as TimeSpec ) ;
162167 }
163168 return a === b ;
0 commit comments