kiln: WIP state as tuple

This commit is contained in:
Ted Blackman 2020-06-16 03:29:17 -04:00
parent 11fa48f57b
commit 01eee03340
5 changed files with 155 additions and 308 deletions

View File

@ -1,51 +1,22 @@
:: :: ::
:::: /hoon/hood/app :: ::
:: :: ::
/? 310 :: zuse version
/- *sole
/+ sole :: libraries
:: XX these should really be separate apps, as
:: none of them interact with each other in
:: any fashion; however, to reduce boot-time
:: complexity and work around the current
:: non-functionality of end-to-end acknowledgments,
:: they have been bundled into :hood
::
:: |command handlers
/+ hood-helm, hood-kiln, hood-drum, hood-write
:: :: ::
:::: :: ::
:: :: ::
/+ sole, default-agent
/+ drum=hood-drum, helm=hood-helm, kiln=hood-kiln
::
|%
++ hood-module
:: each hood module follows this general shape
=> |%
+$ part [%module %0 pith]
+$ pith ~
++ take
|~ [wire sign-arvo]
*(quip card:agent:gall part)
++ take-agent
|~ [wire gift:agent:gall]
*(quip card:agent:gall part)
++ poke
|~ [mark vase]
*(quip card:agent:gall part)
--
|= [bowl:gall own=part]
|_ moz=(list card:agent:gall)
++ abet [(flop moz) own]
--
+$ state
$: %7
drum=state:drum
helm=state:helm
kiln=state:kiln
==
--
:: :: ::
:::: :: :: state handling
:: :: ::
!:
=> |% ::
::
=> |%
+$ any-state $%(state hood-old)
++ hood-old :: unified old-state
{?($1 $2 $3 $4 $5 $6) lac/(map @tas hood-part-old)}
++ hood-1 :: unified state
{$6 lac/(map @tas hood-part)} ::
{$6 lac/(map @tas hood-part)}
++ hood-good :: extract specific
=+ hed=$:hood-head
|@ ++ $
@ -57,183 +28,101 @@
$write ?>(?=($write -.paw) `part:hood-write`paw)
==
--
++ hood-head _-:$:hood-part :: initialize state
++ hood-make ::
=+ $:{our/@p hed/hood-head} ::
|@ ++ $
?- hed
$drum (make:hood-drum our)
$helm *part:hood-helm
$kiln *part:hood-kiln
$write *part:hood-write
==
--
++ hood-part-old
$% [%drum part-old:hood-drum]
[%helm part-old:hood-helm]
[%kiln part-old:hood-kiln]
[%write part-old:hood-write]
$% [%drum part-old:drum]
[%helm part-old:helm]
[%kiln part-old:kiln]
[%write part-old:write]
==
++ hood-part
$% {$drum $2 pith-2:drum}
{$helm $0 pith:helm}
{$kiln $0 pith:kiln}
{$write $0 pith:write}
==
++ hood-port :: state transition
|: paw=$:hood-part-old ^- hood-part ::
paw ::
:: ::
++ hood-part :: current module state
$% {$drum $2 pith-2:hood-drum} ::
{$helm $0 pith:hood-helm} ::
{$kiln $0 pith:hood-kiln} ::
{$write $0 pith:hood-write} ::
== ::
-- ::
:: :: ::
:::: :: :: app proper
:: :: ::
^- agent:gall
=| hood-1 :: module states
=> |%
++ help
|= hid/bowl:gall
|%
++ able :: find+make part
=+ hed=$:hood-head
|@ ++ $
=+ rep=(~(get by lac) hed)
=+ par=?^(rep u.rep `hood-part`(hood-make our.hid hed))
((hood-good hed) par)
--
::
++ ably :: save part
=+ $:{(list) hood-part}
|@ ++ $
[+<- (~(put by lac) +<+< +<+)]
--
:: :: ::
:::: :: :: generic handling
:: :: ::
++ prep
|= old/(unit hood-old) ^- (quip _!! _+>)
:- ~
?~ old +>
+>(lac (~(run by lac.u.old) hood-port))
::
++ poke-hood-load :: recover lost brain
|= dat/hood-part
?> =(our.hid src.hid)
~& loaded+-.dat
[~ (~(put by lac) -.dat dat)]
::
::
++ from-module :: create wrapper
|* _[identity=%module start=..$ finish=_abet]:(hood-module)
=- [wrap=- *start] :: usage (wrap handle-arm):from-foo
|* handle/_finish
|= a=_+<.handle
=. +>.handle (start hid (able identity))
^- (quip card:agent:gall _lac)
%- ably
^- (quip card:agent:gall hood-part)
(handle a)
:: per-module interface wrappers
++ from-drum (from-module %drum [..$ _se-abet]:(hood-drum))
++ from-helm (from-module %helm [..$ _abet]:(hood-helm))
++ from-kiln (from-module %kiln [..$ _abet]:(hood-kiln))
++ from-write (from-module %write [..$ _abet]:(hood-write))
--
--
|_ hid/bowl:gall :: gall environment
++ on-init
`..on-init
::
++ on-save
!>([%5 lac])
^- agent:gall
=| =state
|_ =bowl:gall
+* this .
def ~(. (default-agent this %|) bol)
drum-core (drum bowl drum.state)
helm-core (helm bowl helm.state)
kiln-core (kiln bowl kiln.state)
::
++ on-fail on-fail:def
++ on-init on-init:def
++ on-leave on-leave:def
++ on-peek on-peek:def
::
++ on-save !>(state)
++ on-load
|= =old-state=vase
=/ old-state !<(hood-old old-state-vase)
=^ cards lac
=. lac lac.old-state
?- -.old-state
%1 ((wrap on-load):from-drum:(help hid) %1)
%2 ((wrap on-load):from-drum:(help hid) %2)
%3 ((wrap on-load):from-drum:(help hid) %3)
%4 ((wrap on-load):from-drum:(help hid) %4)
%5
=/ start ..$:(from-kiln)
=/ old-kiln-part (~(got by lac.old-state) %kiln)
?> ?=(%kiln -.old-kiln-part)
%- ably
(on-load:(start hid *part:hood-kiln) old-kiln-part)
::
%6 `lac
==
[cards ..on-init]
=/ old-state !<(any-state old-state-vase)
:: TODO rewrite
[~ this]
:: =^ cards lac
:: =. lac lac.old-state
:: ?- -.old-state
:: %1 ((wrap on-load):from-drum:(help hid) %1)
:: %2 ((wrap on-load):from-drum:(help hid) %2)
:: %3 ((wrap on-load):from-drum:(help hid) %3)
:: %4 ((wrap on-load):from-drum:(help hid) %4)
:: %5
:: =/ start ..$:(from-kiln)
:: =/ old-kiln-part (~(got by lac.old-state) %kiln)
:: ?> ?=(%kiln -.old-kiln-part)
:: %- ably
:: (on-load:(start hid *part:hood-kiln) old-kiln-part)
:: ::
:: %6 `lac
:: ==
:: [cards ..on-init]
::
++ on-poke
|^
|= [=mark =vase]
^- (quip card:agent:gall agent:gall)
=/ h (help hid)
=^ cards lac
?: =(%helm (end 3 4 mark))
((wrap poke):from-helm:h mark vase)
?: =(%drum (end 3 4 mark))
((wrap poke):from-drum:h mark vase)
?: =(%kiln (end 3 4 mark))
((wrap poke):from-kiln:h mark vase)
?: =(%write (end 3 5 mark))
((wrap poke):from-write:h mark vase)
:: XX should rename and move to libs
::
?+ mark ~|([%poke-hood-bad-mark mark] !!)
%hood-load (poke-hood-load:h !<(hood-part vase))
%atom ((wrap poke-atom):from-helm:h !<(@ vase))
%dill-belt ((wrap poke-dill-belt):from-drum:h !<(dill-belt:dill vase))
%dill-blit ((wrap poke-dill-blit):from-drum:h !<(dill-blit:dill vase))
%hood-sync ((wrap poke-sync):from-kiln:h !<([desk ship desk] vase))
==
[cards ..on-init]
^- step:agent:gall
::
=/ fin (end 3 4 mark)
?: =(%drum fin) (poke-drum mark vase)
?: =(%helm fin) (poke-helm mark vase)
?: =(%kiln fin) (poke-kiln mark vase)
::
?+ mark (on-poke:def mark vase)
%atom (poke-helm %helm-atom vase)
%dill-belt (poke-drum %drum-dill-belt vase)
%dill-blit (poke-drum %drum-dill-blit vase)
%hood-sync (poke-kiln %kiln-sync vase)
==
++ poke-drum |=([mark vase] =^(c drum.state (poke:drum-core +<) [c this]))
++ poke-helm |=([mark vase] =^(c helm.state (poke:helm-core +<) [c this]))
++ poke-kiln |=([mark vase] =^(c kiln.state (poke:kiln-core +<) [c this]))
--
::
++ on-watch
|= =path
=/ h (help hid)
=^ cards lac
?+ path ~|([%hood-bad-path wire] !!)
[%drum *] ((wrap peer):from-drum:h t.path)
==
[cards ..on-init]
::
++ on-leave
|= path
`..on-init
::
++ on-peek
|= path
*(unit (unit cage))
^- step:agent:gall
?+ path (on-watch:def +<)
[%drum *] =^(c drum.state (peer:drum-core +<) [c this])
==
::
++ on-agent
|= [=wire =sign:agent:gall]
=/ h (help hid)
=^ cards lac
?+ wire ~|([%hood-bad-wire wire] !!)
[%helm *] ((wrap take-agent):from-helm:h wire sign)
[%kiln *] ((wrap take-agent):from-kiln:h wire sign)
[%drum *] ((wrap take-agent):from-drum:h wire sign)
[%write *] ((wrap take-agent):from-write:h wire sign)
==
[cards ..on-init]
^- step:agent:gall
?+ wire ~|([%hood-bad-wire wire] !!)
[%drum *] =^(c drum.state (take-agent:drum-core +<) [c this]))
[%helm *] =^(c helm.state (take-agent:helm-core +<) [c this]))
[%kiln *] =^(c kiln.state (take-agent:kiln-core +<) [c this]))
==
::
++ on-arvo
|= [=wire =sign-arvo]
=/ h (help hid)
=^ cards lac
?+ wire ~|([%hood-bad-wire wire] !!)
[%helm *] ((wrap take):from-helm:h t.wire sign-arvo)
[%drum *] ((wrap take):from-drum:h t.wire sign-arvo)
[%kiln *] ((wrap take-general):from-kiln:h t.wire sign-arvo)
[%write *] ((wrap take):from-write:h t.wire sign-arvo)
==
[cards ..on-init]
::
++ on-fail
|= [term tang]
`..on-init
|= [=wire sign=sign-arvo]
^- step:agent:gall
?+ wire ~|([%hood-bad-wire wire] !!)
[%drum *] =^(c drum.state (take-arvo:drum-core +<) [c this]))
[%helm *] =^(c helm.state (take-arvo:helm-core +<) [c this]))
[%kiln *] =^(c kiln.state (take-arvo:kiln-core +<) [c this]))
==
--

View File

@ -1,15 +0,0 @@
:: Hood, generic: load named hood component's state from backup
::
:::: /hoon/load/hood/gen
::
/? 310
::
::::
::
:- %say
|= $: {now/@da eny/@uvJ byk/beak}
{{dap/term pas/@uw ~} ~}
==
:- %hood-load
~| %hood-load-stub
!!

View File

@ -8,8 +8,8 @@
:::: :: ::
:: :: ::
|% :: ::
+$ part [%drum %2 pith-2] ::
+$ part-old ::
+$ state [%3 pith-2]
+$ state-old ::
$: %drum ::
$% [%1 pith-1] ::
[%2 pith-2] ::
@ -131,18 +131,16 @@
^- (list gill:gall)
[[our %dojo] [our %chat-cli]~]
::
++ make :: initial part
++ initial-state
|= our/ship
^- part
:* %drum
%2
^- state
:* %3
eel=(deft-fish our)
ray=~
fur=~
bin=~
==
::
::
++ en-gill :: gill to wire
|= gyl/gill:gall
^- wire
@ -152,10 +150,9 @@
|= way/wire ^- gill:gall
?>(?=({@ @ ~} way) [(slav %p i.way) i.t.way])
--
:: TODO: remove .ost
::
::::
::
|= {hid/bowl:gall part} :: main drum work
|: [bowl=*bowl:gall state=initial-state]
=/ ost 0
=+ (~(gut by bin) ost *source)
=* dev -
@ -220,12 +217,14 @@
++ poke
|= [=mark =vase]
?+ mark ~|([%poke-drum-bad-mark mark] !!)
%drum-put =;(f (f !<(_+<.f vase)) poke-put)
%drum-link =;(f (f !<(_+<.f vase)) poke-link)
%drum-unlink =;(f (f !<(_+<.f vase)) poke-unlink)
%drum-dill-belt =;(f (f !<(_+<.f vase)) poke-dill-belt)
%drum-dill-blit =;(f (f !<(_+<.f vase)) poke-dill-blit)
%drum-exit =;(f (f !<(_+<.f vase)) poke-exit)
%drum-start =;(f (f !<(_+<.f vase)) poke-start)
%drum-link =;(f (f !<(_+<.f vase)) poke-link)
%drum-put =;(f (f !<(_+<.f vase)) poke-put)
%drum-set-boot-apps =;(f (f !<(_+<.f vase)) poke-set-boot-apps)
%drum-start =;(f (f !<(_+<.f vase)) poke-start)
%drum-unlink =;(f (f !<(_+<.f vase)) poke-unlink)
==
::
++ on-load

View File

@ -1,56 +1,29 @@
:: :: ::
:::: /hoon/helm/hood/lib :: ::
:: :: ::
/? 310 :: version
/- sole
/+ pill
:: :: ::
:::: :: ::
:: :: ::
|% :: ::
+$ part {$helm $0 pith} :: helm state
+$ part-old part ::
++ pith :: helm content
$: hoc/(map bone session) :: consoles
== ::
++ session ::
$: say/sole-share:sole :: console state
=* card card:agent:gall
::
|%
+$ state
$: %3
say/sole-share:sole :: console state
mud/(unit (sole-dialog:sole @ud)) :: console dialog
mass-timer/{way/wire nex/@da tim/@dr}
== ::
:: :: ::
:::: :: ::
:: :: ::
++ hood-reset :: reset command
$~ ::
++ helm-verb :: reset command
$~ ::
++ hood-reload :: reload command
(list term) ::
-- ::
:: :: ::
:::: :: ::
:: :: ::
|: $:{bowl:gall part} :: main helm work
=/ ost 0
=+ sez=(~(gut by hoc) ost $:session)
=| moz=(list card:agent:gall)
==
--
::
|= [=bowl:gall =state]
=| moz=(list card)
|%
++ abet
[(flop moz) %_(+<+.$ hoc (~(put by hoc) ost sez))]
+* this .
++ abet [(flop moz) state]
++ flog |=(=flog:dill (emit %pass /di %arvo %d %flog flog))
++ emit |=(card this(moz [+< moz]))
:: +emil: emit multiple cards
::
++ emit
|= card:agent:gall
%_(+> moz [+< moz])
::
++ flog
|= =flog:dill
(emit %pass /di %arvo %d %flog flog)
::
++ emil :: return cards
|= (list card:agent:gall)
^+ +>
?~(+< +> $(+< t.+<, +> (emit i.+<)))
++ emil
|= caz=(list card)
^+ this
?~(caz this $(caz t.caz, this (emit i.caz)))
::
++ poke-rekey :: rotate private keys
|= des=@t
@ -61,17 +34,17 @@
=< abet
?~ sed
~& %invalid-private-key
+>.$
this
?. =(our who.u.sed)
~& [%wrong-private-key-ship who.u.sed]
+>.$
this
(emit %pass / %arvo %j %rekey lyf.u.sed key.u.sed)
::
++ poke-moon :: rotate moon keys
|= sed=(unit [=ship =udiff:point:able:jael])
=< abet
?~ sed
+>.$
this
(emit %pass / %arvo %j %moon u.sed)
::
++ poke-mass
@ -80,13 +53,13 @@
::
++ poke-automass
|= recur=@dr
=. mass-timer.sez
=. mass-timer.state
[/helm/automass (add now recur) recur]
abet:(emit %pass way.mass-timer.sez %arvo %b %wait nex.mass-timer.sez)
abet:(emit %pass way.mass-timer.state %arvo %b %wait nex.mass-timer.state)
::
++ poke-cancel-automass
|= ~
abet:(emit %pass way.mass-timer.sez %arvo %b %rest nex.mass-timer.sez)
abet:(emit %pass way.mass-timer.state %arvo %b %rest nex.mass-timer.state)
::
++ poke-pack
|= ~ =< abet
@ -98,11 +71,11 @@
%- (slog u.error)
~& %helm-wake-automass-fail
abet
=. nex.mass-timer.sez (add now tim.mass-timer.sez)
=. nex.mass-timer.state (add now tim.mass-timer.state)
=< abet
%- emil
:~ [%pass /heft %arvo %d %flog %crud %hax-heft ~]
[%pass way.mass-timer.sez %arvo %b %wait nex.mass-timer.sez]
[%pass way.mass-timer.state %arvo %b %wait nex.mass-timer.state]
==
::
++ poke-send-hi
@ -162,7 +135,7 @@
:: Trigger with |reset.
::
++ poke-reset
|= hood-reset
|= hood-reset=~
=< abet
%- emil
^- (list card:agent:gall)
@ -202,23 +175,24 @@
++ poke
|= [=mark =vase]
?+ mark ~|([%poke-helm-bad-mark mark] !!)
%helm-ames-sift =;(f (f !<(_+<.f vase)) poke-ames-sift)
%helm-ames-verb =;(f (f !<(_+<.f vase)) poke-ames-verb)
%helm-ames-wake =;(f (f !<(_+<.f vase)) poke-ames-wake)
%helm-atom =;(f (f !<(_+<.f vase)) poke-atom)
%helm-automass =;(f (f !<(_+<.f vase)) poke-automass)
%helm-cancel-automass =;(f (f !<(_+<.f vase)) poke-cancel-automass)
%helm-hi =;(f (f !<(_+<.f vase)) poke-hi)
%helm-knob =;(f (f !<(_+<.f vase)) poke-knob)
%helm-mass =;(f (f !<(_+<.f vase)) poke-mass)
%helm-moon =;(f (f !<(_+<.f vase)) poke-moon)
%helm-pack =;(f (f !<(_+<.f vase)) poke-pack)
%helm-rekey =;(f (f !<(_+<.f vase)) poke-rekey)
%helm-reload =;(f (f !<(_+<.f vase)) poke-reload)
%helm-reload-desk =;(f (f !<(_+<.f vase)) poke-reload-desk)
%helm-reset =;(f (f !<(_+<.f vase)) poke-reset)
%helm-send-hi =;(f (f !<(_+<.f vase)) poke-send-hi)
%helm-ames-sift =;(f (f !<(_+<.f vase)) poke-ames-sift)
%helm-ames-verb =;(f (f !<(_+<.f vase)) poke-ames-verb)
%helm-ames-wake =;(f (f !<(_+<.f vase)) poke-ames-wake)
%helm-verb =;(f (f !<(_+<.f vase)) poke-verb)
%helm-knob =;(f (f !<(_+<.f vase)) poke-knob)
%helm-rekey =;(f (f !<(_+<.f vase)) poke-rekey)
%helm-automass =;(f (f !<(_+<.f vase)) poke-automass)
%helm-cancel-automass =;(f (f !<(_+<.f vase)) poke-cancel-automass)
%helm-moon =;(f (f !<(_+<.f vase)) poke-moon)
%helm-serve =;(f (f !<(_+<.f vase)) poke-serve)
%helm-verb =;(f (f !<(_+<.f vase)) poke-verb)
==
::
++ take-agent
@ -232,7 +206,7 @@
|= [wir=wire success=? binding=binding:eyre] =< abet
(flog %text "bound: {<success>}")
::
++ take
++ take-arvo
|= [=wire =sign-arvo]
?+ wire ~|([%helm-bad-take-wire wire +<.sign-arvo] !!)
[%automass *] %+ take-wake-automass t.wire

View File

@ -407,25 +407,25 @@
++ poke
|= [=mark =vase]
?+ mark ~|([%poke-kiln-bad-mark mark] !!)
%kiln-commit =;(f (f !<(_+<.f vase)) poke-commit)
%kiln-autocommit =;(f (f !<(_+<.f vase)) poke-autocommit)
%kiln-cancel =;(f (f !<(_+<.f vase)) poke-cancel)
%kiln-cancel-autocommit =;(f (f !<(_+<.f vase)) poke-cancel-autocommit)
%kiln-commit =;(f (f !<(_+<.f vase)) poke-commit)
%kiln-gall-sear =;(f (f !<(_+<.f vase)) poke-gall-sear)
%kiln-goad-gall =;(f (f !<(_+<.f vase)) poke-goad-gall)
%kiln-info =;(f (f !<(_+<.f vase)) poke-info)
%kiln-label =;(f (f !<(_+<.f vase)) poke-label)
%kiln-cancel =;(f (f !<(_+<.f vase)) poke-cancel)
%kiln-merge =;(f (f !<(_+<.f vase)) poke-merge)
%kiln-mount =;(f (f !<(_+<.f vase)) poke-mount)
%kiln-ota =;(f (f !<(_+<.f vase)) poke:update)
%kiln-permission =;(f (f !<(_+<.f vase)) poke-permission)
%kiln-rm =;(f (f !<(_+<.f vase)) poke-rm)
%kiln-schedule =;(f (f !<(_+<.f vase)) poke-schedule)
%kiln-track =;(f (f !<(_+<.f vase)) poke-track)
%kiln-sync =;(f (f !<(_+<.f vase)) poke-sync)
%kiln-ota =;(f (f !<(_+<.f vase)) poke:update)
%kiln-syncs =;(f (f !<(_+<.f vase)) poke-syncs)
%kiln-goad-gall =;(f (f !<(_+<.f vase)) poke-goad-gall)
%kiln-gall-sear =;(f (f !<(_+<.f vase)) poke-gall-sear)
%kiln-track =;(f (f !<(_+<.f vase)) poke-track)
%kiln-unmount =;(f (f !<(_+<.f vase)) poke-unmount)
%kiln-unsync =;(f (f !<(_+<.f vase)) poke-unsync)
%kiln-permission =;(f (f !<(_+<.f vase)) poke-permission)
%kiln-cancel-autocommit =;(f (f !<(_+<.f vase)) poke-cancel-autocommit)
%kiln-merge =;(f (f !<(_+<.f vase)) poke-merge)
==
::
++ poke-goad-gall
@ -450,7 +450,7 @@
(take-coup-spam t.t.wire p.sign)
==
::
++ take-general
++ take-arvo
|= [=wire =sign-arvo]
?- wire
[%sync %merg *] %+ take-mere-sync t.t.wire