@@ -224,8 +224,10 @@ func (a *Agent) CheckStoriesState(e *am.Event) {
224224 continue
225225 }
226226
227- // add to the list
228- if mach .Is1 (s .State ) && ! activate || mach .Not1 (s .State ) && activate {
227+ // add to the list after a passed "impossibility check"
228+ if mach .Is1 (s .State ) && ! activate && ! amhelp .CantRemove1 (mach , s .State , nil ) ||
229+ mach .Not1 (s .State ) && activate && ! amhelp .CantAdd1 (mach , s .State , nil ) {
230+
229231 if isDebug {
230232 a .Log ("story changed" , "story" , s .State )
231233 }
@@ -264,7 +266,8 @@ func (a *Agent) StoryChangedState(e *am.Event) {
264266 // deactivate
265267 if mach .Is1 (s .State ) && ! activate {
266268 res := mach .EvRemove1 (e , s .State , nil )
267- // TODO handle Queued? use CanRemove1, when available
269+
270+ // TODO handle Queued?
268271 if res != am .Canceled {
269272 s .Cook .TimeDeactivated = mach .Time (nil )
270273 s .Memory .TimeDeactivated = a .mem .Time (nil )
@@ -276,7 +279,8 @@ func (a *Agent) StoryChangedState(e *am.Event) {
276279 // activate
277280 } else if mach .Not1 (s .State ) && activate {
278281 res := mach .EvAdd1 (e , s .State , nil )
279- // TODO handle Queued? use CanAdd1, when available
282+
283+ // TODO handle Queued?
280284 if res != am .Canceled {
281285 s .Cook .TimeActivated = mach .Time (nil )
282286 s .Memory .TimeActivated = a .mem .Time (nil )
@@ -324,7 +328,7 @@ func (a *Agent) ReadyState(e *am.Event) {
324328// TODO enter
325329
326330func (a * Agent ) UISessConnState (e * am.Event ) {
327- mach := e . Machine ()
331+ mach := a . Mach ()
328332 args := ParseArgs (e .Args )
329333 sess := args .SSHSess
330334 done := args .Done
@@ -658,7 +662,9 @@ func (a *Agent) OrientingState(e *am.Event) {
658662 prompt := ParseArgs (e .Args ).Prompt
659663
660664 // possible moves: all cooking steps, most stories and some states
661- moves := map [string ]string {}
665+
666+ // moves from stories
667+ movesStories := map [string ]string {}
662668 for _ , name := range mach .StateNames () {
663669 state := cookSchema [name ]
664670
@@ -671,18 +677,25 @@ func (a *Agent) OrientingState(e *am.Event) {
671677 desc = a .Stories [name ].Desc
672678 }
673679
674- // TODO check CanAdd1 for the stories
675680 if isTrigger || (isStory && ! isManual ) {
676- moves [name ] = desc
681+ impossible := amhelp .CantAdd1 (mach , name , nil )
682+ if ! impossible {
683+ movesStories [name ] = desc
684+ }
677685 }
678686 }
679687
688+ // collect and filter cooking moves
689+ movesCooking := a .mem .StateNamesMatch (schema .MatchSteps )
690+ movesCooking = slices .DeleteFunc (movesCooking , func (state string ) bool {
691+ return amhelp .CantAdd1 (a .mem , state , nil )
692+ })
693+
680694 // build params
681695 params := schema.ParamsOrienting {
682- Prompt : prompt ,
683- // TODO check CanAdd1 for the steps
684- MovesCooking : a .mem .StateNamesMatch (schema .MatchSteps ),
685- MovesStories : moves ,
696+ Prompt : prompt ,
697+ MovesCooking : movesCooking ,
698+ MovesStories : movesStories ,
686699 }
687700
688701 // unblock
@@ -1142,7 +1155,7 @@ func (a *Agent) StoryCookingStartedEnd(e *am.Event) {
11421155}
11431156
11441157func (a * Agent ) StoryJokeEnter (e * am.Event ) bool {
1145- return a .canJoke ()
1158+ return a .hasJokes ()
11461159}
11471160
11481161func (a * Agent ) StoryJokeState (e * am.Event ) {
0 commit comments