shrub/pkg/arvo/app/dojo.hoon

1770 lines
56 KiB
Plaintext
Raw Normal View History

2019-09-06 22:34:04 +03:00
:: :: ::
:::: /hoon/dojo/app :: ::::
:: :: ::
/? 309 :: arvo kelvin
2019-11-05 10:42:59 +03:00
/- *sole, lens :: console structures
/+ sole, pprint, dprint, ::
2019-11-05 10:42:59 +03:00
auto=language-server-complete, ::
easy-print=language-server-easy-print ::
2019-09-06 22:34:04 +03:00
:: :: ::
:::: :: ::::
:: :: ::
=> |% :: external structures
+$ id sole-id :: session id
+$ house :: all state
$: %9
egg=@u :: command count
hoc=(map id session) :: conversations
acl=(set ship) :: remote access whitelist
2019-09-06 22:34:04 +03:00
== ::
+$ session :: per conversation
$: say=sole-share :: command-line state
dir=beam :: active path
poy=(unit dojo-project) :: working
2019-09-06 22:34:04 +03:00
$: :: sur: structure imports
::
2020-05-14 10:22:39 +03:00
sur=(list cable:clay)
2019-09-06 22:34:04 +03:00
:: lib: library imports
::
2020-05-14 10:22:39 +03:00
lib=(list cable:clay)
2019-09-06 22:34:04 +03:00
==
var=(map term cage) :: variable state
old=(set term) :: used TLVs
buf=tape :: multiline buffer
2019-09-06 22:34:04 +03:00
== ::
+$ monkey :: per conversation
$: say=sole-share :: command-line state
dir=beam :: active path
poy=(unit dojo-project) :: working
var=(map term cage) :: variable state
old=(set term) :: used TLVs
buf=tape :: multiline buffer
2019-09-06 22:34:04 +03:00
== ::
+$ dojo-command ::
2019-09-06 22:34:04 +03:00
$^ (pair dojo-sink dojo-source) :: route value
[%brev p=term] :: unbind variable
2019-09-06 22:34:04 +03:00
::
+$ dojo-sink ::
$% [%flat p=path] :: atom to unix
[%pill p=path] :: noun to unix pill
:: [%tree p=path] :: noun to unix tree
[%file p=beam] :: save to clay
$: %http :: http outbound
p=?(%post %put)
r=@t
2019-09-06 22:34:04 +03:00
==
[%poke p=goal] :: poke app
[%help p=(list term)] :: doccords
[%show p=?(%0 %1 %2 %3 %4 %5)] :: val/type/hoon/xray
[%verb p=term] :: store variable
2019-09-06 22:34:04 +03:00
== ::
+$ dojo-source :: construction node
$: p=@ud :: assembly index
q=dojo-build :: general build
2019-09-06 22:34:04 +03:00
== ::
+$ dojo-build :: one arvo step
2019-09-06 22:34:04 +03:00
$~ [%ex *hoon]
$% [%ur p=@t] :: http GET request
[%ge p=dojo-model] :: generator
[%te p=[=desk =term] q=(list dojo-source)] :: thread
[%dv p=beak q=path] :: core from source
[%ex p=hoon] :: hoon expression
[%sa p=mark] :: example mark value
[%as p=mark q=dojo-source] :: simple transmute
[%do p=hoon q=dojo-source] :: gate apply
[%tu p=(list dojo-source)] :: tuple
2019-09-06 22:34:04 +03:00
== ::
+$ dojo-model :: data construction
$: p=dojo-server :: core source
q=dojo-config :: configuration
2019-09-06 22:34:04 +03:00
== ::
+$ dojo-server :: numbered device
$: p=@ud :: assembly index
q=[=desk =path] :: gate location
2019-09-06 22:34:04 +03:00
== ::
+$ dojo-config :: configuration
$: p=(list dojo-source) :: by order
q=(map term (unit dojo-source)) :: by keyword
2019-09-06 22:34:04 +03:00
== ::
+$ dojo-project :: construction state
$: mad=dojo-command :: operation
num=@ud :: number of tasks
cud=(unit dojo-source) :: now solving
pux=(unit path) :: working
pro=(unit vase) :: prompting loop
per=(unit sole-edit) :: pending reverse
job=(map @ud dojo-build) :: problems
rez=(map @ud cage) :: results
2019-09-06 22:34:04 +03:00
== ::
+$ bead [p=(set beam) q=cage] :: computed result
+$ goal [p=ship q=term] :: flat application
2019-09-06 22:34:04 +03:00
--
=>
|%
:: TODO: move to zuse? copied from clay
::
++ with-face |=([face=@tas =vase] vase(p [%face face p.vase]))
++ with-faces
=| res=(unit vase)
|= vaz=(list [face=@tas =vase])
^- vase
?~ vaz (need res)
=/ faz (with-face i.vaz)
=. res `?~(res faz (slop faz u.res))
$(vaz t.vaz)
2019-09-06 22:34:04 +03:00
:: |parser-at: parsers for dojo expressions using :dir as working directory
::
++ parser-at
|= [our=ship dir=beam]
|%
++ default-app %hood
2020-12-06 12:03:12 +03:00
++ hoon-parser (vang | (en-beam dir))
2019-09-06 22:34:04 +03:00
++ our p.dir
::
++ parse-command-line ;~(sfix parse-command (star ace) (just '\0a'))
::
++ to-command
|= [gol=goal mod=dojo-model]
^- dojo-command
=/ =desk
::TODO maybe should recognize if the user specified a desk explicitly.
:: currently eats the :app|desk#gen case.
=+ gop=(en-beam dir(q q.gol, s /$))
?. .^(? %gu gop)
q.dir
.^(desk %gd gop)
[[%poke gol] [0 [%ge mod(q.p [desk q.gol path.q.p.mod])]]]
2019-09-06 22:34:04 +03:00
::
++ parse-variable
|* [sym=rule src=rule]
%+ cook
|= [a=term b=(unit dojo-source)]
2019-09-06 22:34:04 +03:00
^- dojo-command
?~(b [%brev a] [[%verb a] u.b])
;~(plug sym (punt src))
::
++ parse-command
:: =< ;~(less |-(;~(pose (jest '|*') ;~(pfix next (knee ** |.(^$))))) .)
%+ knee *dojo-command |. ~+
;~ pose
;~ pfix bar
%+ cook to-command
(stag `goal`[our default-app] parse-model)
==
::
;~ pfix col
%+ cook
|= [a=goal b=$^(dojo-model dojo-source)]
2019-09-06 22:34:04 +03:00
?@ -.b [[%poke a] b]
(to-command a b)
;~ plug
parse-goal
;~ pose
;~(pfix bar parse-model)
;~(pfix ace parse-source)
==
==
==
::
;~ pfix tis
;~ pose
(parse-variable (jest %dir) ;~(pfix ace :(stag 0 %ex parse-rood)))
(parse-variable sym ;~(pfix ace parse-source))
==
==
::
2020-05-28 14:58:18 +03:00
;~ pfix fas
2019-09-06 22:34:04 +03:00
;~ pose
2022-07-06 08:29:23 +03:00
(parse-variable (cold %sur hep) ;~(pfix gap (parse-cables %sur)))
(parse-variable (cold %lib lus) ;~(pfix gap (parse-cables %lib)))
;~(pfix tis gap (parse-variable sym ;~(pfix gap parse-path)))
;~(pfix cen gap (parse-variable sym ;~(pfix gap parse-mark)))
2019-09-06 22:34:04 +03:00
==
==
::
;~ pfix hax
;~ pose
;~ pfix ace
%+ cook
|= a=(list term)
2022-07-07 00:19:44 +03:00
[[%help (flop a)] 0 %ex [%cnts p=~[[%.y p=1]] q=~]]
(most fas sym)
==
(easy [[%help ~[%$]] 0 %ex [%cnts p=~[[%.y p=1]] q=~]])
==
==
2019-09-06 22:34:04 +03:00
::
;~((glue ace) parse-sink parse-source)
(stag [%show %0] parse-source)
==
::
++ parse-sink
;~ pose
;~(plug (cold %file tar) parse-beam)
2020-05-28 14:58:18 +03:00
;~(plug (cold %flat pat) (most fas sym))
;~(plug (cold %pill dot) (most fas sym))
2019-09-06 22:34:04 +03:00
;~(plug (cold %http lus) (stag %post parse-url))
;~(plug (cold %http hep) (stag %put parse-url))
(stag %show (cook $?(%1 %2 %3 %4 %5) (cook lent (stun [1 5] wut))))
2019-09-06 22:34:04 +03:00
==
::
++ parse-cables
|= base-path=@ta
%- cook :_ (most ;~(plug com gaw) parse-cable)
|= cables=(list cable:clay)
:+ 0 %tu
::
%+ turn cables
|= cable=cable:clay
^- dojo-source
=+ add-face=?~(face.cable "|*(n=* n)" ;:(weld "|*(n=* ^=(" (trip u.face.cable) " n))"))
:^ 0 %do (scan add-face parse-hoon)
:+ 0 %dv [-.dir `path`[base-path file-path.cable ~]]
2019-09-06 22:34:04 +03:00
::
++ parse-cable
2020-05-14 10:22:39 +03:00
%+ cook |=(a=cable:clay a)
2019-09-06 22:34:04 +03:00
;~ pose
(stag ~ ;~(pfix tar sym))
(cook |=([face=term tis=@ file=term] [`face file]) ;~(plug sym tis sym))
(cook |=(a=term [`a a]) sym)
==
2022-07-06 08:29:23 +03:00
::
++ parse-mark
%- cook :_ ;~(pfix cen sym)
|= mark=@tas
[0 %dv -.dir `path`[~.mar mark ~]]
::
++ parse-path
%+ cook |=(=path [0 %dv -.dir path])
;~(pfix fas (more fas sym))
::
2019-09-06 22:34:04 +03:00
++ parse-source (stag 0 parse-build)
++ parse-build
%+ knee *dojo-build |. ~+
;~ pose
;~(plug (cold %ur lus) parse-url)
;~(plug (cold %ge lus) parse-model)
;~(plug (cold %te hep) parse-thread (star ;~(pfix ace parse-source)))
2020-11-15 08:08:52 +03:00
;~(plug (cold %as pam) sym ;~(pfix ace parse-source))
2019-09-06 22:34:04 +03:00
;~(plug (cold %do cab) parse-hoon ;~(pfix ace parse-source))
parse-value
==
::
++ parse-goal
%+ cook |=(a=goal a)
2019-09-06 22:34:04 +03:00
;~ pose
;~ plug
;~(pfix sig fed:ag)
2020-05-28 14:58:18 +03:00
;~(pose ;~(pfix fas sym) (easy default-app))
2019-09-06 22:34:04 +03:00
==
%+ stag our
;~(pose sym (easy default-app))
==
::
++ parse-beam
%+ cook
|= a=path
:: hack: fixup paths that come out of the hoon parser
::
:: We currently invoke the hoon parser to read relative paths from
:: the command line, and this parser will produce leading ~ path
:: components with paths that start with a `/`.
::
:: This entire path is nuts and we shouldn't be representing paths
:: as arbitrary hoons.
::
=? a &(?=(^ a) =('' i.a))
t.a
2020-12-06 12:03:12 +03:00
(fall (de-beam a) [`beak`[p q r]:dir a])
2019-09-06 22:34:04 +03:00
=+ vez=hoon-parser
(sear plex:vez (stag %clsg poor:vez))
::
++ parse-iden-url
%+ cook
|=([a=(unit knot) b=purl:eyre] [`(fall a *knot) b])
auru:de-purl:html
::
++ parse-url
%+ cook
|=(a=purl:eyre (crip (en-purl:html a)))
auri:de-purl:html
::
++ parse-model ;~(plug parse-server parse-config)
::
++ parse-server
%+ stag 0
;~ plug
;~(pose ;~(sfix sym zap) (easy q.dir))
(most fas sym)
==
::
++ parse-thread
;~ plug
;~(pose ;~(sfix sym zap) (easy q.dir))
sym
==
::
2019-09-06 22:34:04 +03:00
++ parse-hoon tall:hoon-parser
::
++ parse-rood
:: XX should this use +hoon-parser instead to normalize the case?
::
2020-12-06 12:03:12 +03:00
=> (vang | (en-beam dir))
2019-09-06 22:34:04 +03:00
;~ pose
rood
::
:: XX refactor ++scat
::
=- ;~(pfix cen (stag %clsg -))
%+ sear |=([a=@ud b=tyke] (posh ~ ~ a b))
;~ pose
porc
(cook |=(a=(list) [(lent a) ~]) (star cen))
==
==
++ parse-value
;~ pose
2020-10-23 06:47:53 +03:00
;~(plug (cold %as pam) sym ;~(pfix ace parse-source))
2020-05-28 10:06:00 +03:00
(stag %sa ;~(pfix tar pam sym))
2019-09-06 22:34:04 +03:00
(stag %ex parse-hoon)
2020-05-28 14:14:23 +03:00
(stag %tu (ifix [sel ser] (most ace parse-source)))
2019-09-06 22:34:04 +03:00
==
::
++ parse-config
;~ plug
(star ;~(pfix ace (stag 0 parse-value)))
%+ cook
~(gas by *(map term (unit dojo-source)))
%- star
;~ plug
;~(pfix com ace tis sym)
(punt ;~(pfix ace (stag 0 parse-value)))
==
==
--
--
:: ::
:::: ::
:: ::
=, gall
=+ foo=*monkey
=| house :: program state
=* state -
2019-09-10 06:00:56 +03:00
=> |%
::
++ xskol `$-(type tank)`type-to-tank:pprint
++ xsell `$-(vase tank)`vase-to-tank:pprint
::
2019-09-06 22:34:04 +03:00
++ he :: per session
|_ [hid=bowl:gall =id moz=(list card:agent:gall) session]
2019-09-06 22:34:04 +03:00
::
++ he-beam
^- beam
?. =([%ud 0] r.dir)
dir
dir(r [%da now.hid])
::
++ he-beak `beak`[p q r]:he-beam
++ he-parser (parser-at our.hid he-beam)
::
++ dy :: project work
|_ dojo-project ::
++ dy-abet +>(poy `+<) :: resolve
++ dy-amok +>(poy ~) :: terminate
:: +dy-sing: make a clay read request
::
++ dy-sing
|= [way=wire =care:clay =beak =path]
2019-09-06 22:34:04 +03:00
^+ +>+>
?> ?=(~ pux)
2019-09-06 22:34:04 +03:00
%- he-card(poy `+>+<(pux `way))
=/ [=ship =desk =case:clay] beak
[%pass way %arvo %c %warp ship desk ~ %sing care case path]
2019-09-06 22:34:04 +03:00
::
++ dy-request
|= [way=wire =request:http]
^+ +>+>
?> ?=(~ pux)
%- he-card(poy `+>+<(pux `way))
[%pass way %arvo %i %request request *outbound-config:iris]
2019-09-06 22:34:04 +03:00
::
++ dy-stop :: stop work
^+ +>
=. poy ~
?~ pux +>
%. [%txt "! cancel {<u.pux>}"]
=< he-diff
%- he-card
?: =(/wool u.pux)
:: really shoud stop the thread as well
::
2020-04-21 08:05:05 +03:00
[%pass u.pux %agent [our.hid %spider] %leave ~]
2020-05-14 10:22:39 +03:00
=/ [=ship =desk =case:clay] he-beak
[%pass u.pux %arvo %c %warp ship desk ~]
2019-09-06 22:34:04 +03:00
::
++ dy-errd :: reject change, abet
|= [rev=(unit sole-edit) err=@u]
2019-09-06 22:34:04 +03:00
^+ +>+>
(he-errd(poy `+>+<) rev err)
::
++ dy-diff :: send effects, abet
|= fec=sole-effect
2019-09-06 22:34:04 +03:00
^+ +>+>
(he-diff(poy `+>+<) fec)
::
++ dy-rash :: send effects, amok
|= fec=sole-effect
2019-09-06 22:34:04 +03:00
^+ +>+>
(he-diff(poy ~) fec)
::
++ dy-init-command :: ++dojo-command
|= mad=dojo-command
2019-09-06 22:34:04 +03:00
^+ [mad +>]
?@ -.mad [mad +>.$]
=. q.mad
?+(-.p.mad q.mad %http [0 %as %mime q.mad])
2019-09-06 22:34:04 +03:00
=^ src +>.$ (dy-init-source q.mad)
[mad(q src) +>.$]
::
++ dy-init-source :: ++dojo-source
|= src=dojo-source
2019-09-06 22:34:04 +03:00
^+ [src +>]
=^ bul +> (dy-init-build q.src)
=: p.src num
q.src bul
==
[src +>.$(num +(num), job (~(put by job) -.src +.src))]
::
++ dy-init-source-unit :: (unit dojo-source)
|= urc=(unit dojo-source)
2019-09-06 22:34:04 +03:00
^+ [urc +>]
?~ urc [~ +>]
=^ src +> (dy-init-source u.urc)
[`src +>.$]
::
++ dy-init-build :: ++dojo-build
|= bul=dojo-build
2019-09-06 22:34:04 +03:00
^+ [bul +>]
?- -.bul
%ex [bul +>.$]
%dv [bul +>.$]
%sa [bul +>.$]
%as =^(mor +>.$ (dy-init-source q.bul) [bul(q mor) +>.$])
%do =^(mor +>.$ (dy-init-source q.bul) [bul(q mor) +>.$])
%ge =^(mod +>.$ (dy-init-model p.bul) [[%ge mod] +>.$])
%te =^(mod +>.$ (dy-init-ordered q.bul) [bul(q mod) +>.$])
%ur [bul +>.$]
%tu =^(dof +>.$ (dy-init-ordered p.bul) [[%tu dof] +>.$])
2019-09-06 22:34:04 +03:00
==
::
++ dy-init-model :: ++dojo-model
|= mol=dojo-model
2019-09-06 22:34:04 +03:00
^+ [mol +>]
=^ one +>.$ (dy-init-server p.mol)
=^ two +>.$ (dy-init-config q.mol)
[[one two] +>.$]
::
++ dy-init-server :: ++dojo-server
|= srv=dojo-server
2019-09-06 22:34:04 +03:00
=. p.srv num
=/ bek=beak he-beak
:- srv
%_ +>.$
num +(num)
job %+ ~(put by job) num
[%dv bek(q desk.q.srv) [%gen path.q.srv]]
==
2019-09-06 22:34:04 +03:00
::
++ dy-init-config :: prepare config
|= cig=dojo-config
2019-09-06 22:34:04 +03:00
^+ [cig +>]
=^ ord +>.$ (dy-init-ordered p.cig)
=^ key +>.$ (dy-init-named q.cig)
[[ord key] +>.$]
::
++ dy-init-ordered :: (list dojo-source)
|= ord=(list dojo-source)
2019-09-06 22:34:04 +03:00
^+ [ord +>]
?~ ord [~ +>.$]
=^ fir +>.$ (dy-init-source i.ord)
=^ mor +>.$ $(ord t.ord)
[[fir mor] +>.$]
::
++ dy-init-named :: (map @tas dojo-src)
|= key=(map term (unit dojo-source))
2019-09-06 22:34:04 +03:00
^+ [key +>.$]
?~ key [~ +>.$]
=^ top +>.$ (dy-init-source-unit q.n.key)
=^ lef +>.$ $(key l.key)
=^ rit +>.$ $(key r.key)
[[[p.n.key top] lef rit] +>.$]
::
++ dy-init :: full initialize
^+ .
=^(dam . (dy-init-command mad) +(mad dam))
::
++ dy-hand :: complete step
|= cag=cage
2019-09-06 22:34:04 +03:00
^+ +>+>
?> ?=(^ cud)
(dy-step(cud ~, rez (~(put by rez) p.u.cud cag)) +(p.u.cud))
::
++ dy-meal :: vase to cage
|= vax=vase
2019-09-06 22:34:04 +03:00
?. &(?=(@ -.q.vax) ((sane %tas) -.q.vax))
~& %dy-meal-cage
(dy-rash %bel ~)
(dy-hand -.q.vax (slot 3 vax))
::
++ dy-made-edit :: sole edit
|= cag=cage
2019-09-06 22:34:04 +03:00
^+ +>+>
?> ?=(^ per)
?: ?| ?=(^ q.q.cag)
=((lent buf.say) q.q.cag)
!&(?=(%del -.u.per) =(+(p.u.per) (lent buf.say)))
2019-09-06 22:34:04 +03:00
==
dy-abet(per ~)
(dy-errd(per ~) per q.q.cag)
::
++ dy-done :: dialog submit
|= txt=tape
2019-09-06 22:34:04 +03:00
?: |(?=(^ per) ?=(^ pux) ?=(~ pro))
~& %dy-no-prompt
(dy-diff %bel ~)
=/ res (mule |.((slam u.pro !>(txt))))
?: ?=(%| -.res)
%- (slog >%dy-done< p.res)
(dy-rash %bel ~) :: TODO: or +dy-abet(per ~) ?
(dy-made-dial %noun p.res)
2019-09-06 22:34:04 +03:00
::
++ dy-cast
|* [typ=_* bun=vase]
|= a=vase ^- typ
2019-09-06 22:34:04 +03:00
~| [p.bun p.a]
?> (~(nest ut p.bun) & p.a)
;;(typ q.a)
::
++ dy-over :: finish construction
^+ +>
:: XX needs filter
::
?: ?=([%show %3] -.mad)
2020-08-14 02:40:20 +03:00
(dy-rash %tan (dy-show-source q.mad) ~)
?: ?=(%brev -.mad)
?: ?=(?(%eny %now %our) p.mad)
(dy-rash %tan (cat 3 p.mad ' is immutable') ~)
2019-09-06 22:34:04 +03:00
=. var (~(del by var) p.mad)
=< dy-amok
?+ p.mad .
2021-07-14 01:53:04 +03:00
%dir .(dir [[our.hid %base ud+0] /])
2019-09-06 22:34:04 +03:00
==
=+ cay=(~(got by rez) p.q.mad)
?- -.p.mad
%verb
?: ?=(?(%eny %now %our) p.p.mad)
(dy-rash %tan (cat 3 p.p.mad ' is immutable') ~)
2019-09-06 22:34:04 +03:00
=. var (~(put by var) p.p.mad cay)
~| bad-set+[p.p.mad p.q.cay]
=< dy-amok
?+ p.p.mad .
2022-10-14 07:17:39 +03:00
%dir
=/ bem=beam
%- need %- de-beam
=+ pax=((dy-cast path !>(*path)) q.cay)
?: ?=(~ pax) ~[(scot %p our.hid) %base '0']
?: ?=([@ ~] pax) ~[i.pax %base '0']
?: ?=([@ @ ~] pax) ~[i.pax i.t.pax '0']
pax
?: =(~ .^((list path) %ct (en-beam he-beam(dir bem))))
+(..dy (he-diff %tan 'dojo: dir does not exist' ~))
=. dir bem
=- +>(..dy (he-diff %tan - ~))
rose+[" " `~]^~[leaf+"=%" (smyt (en-beam he-beak s.dir))]
2019-09-06 22:34:04 +03:00
==
::
%poke
2019-09-06 22:34:04 +03:00
%- he-card(poy ~)
:* %pass
2020-01-04 00:06:42 +03:00
/poke
%agent
p.p.mad
2019-09-06 22:34:04 +03:00
%poke
cay
==
::
%file
2019-09-06 22:34:04 +03:00
%- he-card(poy ~)
:* %pass /file %arvo %c
2020-12-06 12:03:12 +03:00
%info (foal:space:userlib (en-beam p.p.mad) cay)
2019-09-06 22:34:04 +03:00
==
::
%flat
2019-09-06 22:34:04 +03:00
?^ q.q.cay
(dy-rash %tan [%leaf "not an atom"]~)
(dy-rash %sav p.p.mad q.q.cay)
::
%pill
2019-09-06 22:34:04 +03:00
(dy-rash %sag p.p.mad q.q.cay)
::
%http
?> ?=(%mime p.cay)
2019-09-06 22:34:04 +03:00
=+ mim=;;(mime q.q.cay)
%+ dy-request /show
:* ?:(=(%put p.p.mad) %'PUT' %'POST')
r.p.mad
~[['content-type' (en-mite:mimes:html p.mim)]]
`q.mim
==
::
%show
2019-09-06 22:34:04 +03:00
|^ (prnt cay note)
++ prnt ?: (gte p.p.mad 4)
dy-xprint
dy-print
++ note ^- tang
?- p.p.mad
%0 ~
%1 [[%rose [~ " " ~] (skol p.q.cay) ~] maar]
%2 [[%rose [~ " " ~] (dy-show-type-noun p.q.cay) ~] maar]
::%3 handled above
2019-09-06 22:34:04 +03:00
%4 ~
%5 [[%rose [~ " " ~] (xskol p.q.cay) ~] maar]
==
++ maar ?: =(%noun p.cay) ~
[[%rose [~ " " ~] >p.cay< ~] ~]
--
::
%help
(dy-inspect p.p.mad p.q.cay)
2019-09-06 22:34:04 +03:00
==
::
++ dy-show |=(cay=cage (dy-print cay ~))
2019-09-06 22:34:04 +03:00
::
:: Print a value (given as a cage) and a note (given as a tang).
::
++ dy-xprint
|= [cay=cage tan=tang]
2019-09-06 22:34:04 +03:00
%+ dy-rash %tan
%- welp :_ tan
?+ p.cay [(xsell q.cay)]~
%tang ;;(tang q.q.cay)
%httr
2019-09-06 22:34:04 +03:00
=+ hit=;;(httr:eyre q.q.cay)
=- (flop (turn `wall`- |=(a=tape leaf+(dash:us a '' ~))))
2019-09-06 22:34:04 +03:00
:- "HTTP {<p.hit>}"
%+ weld
(turn q.hit |=([a=@t b=@t] "{(trip a)}: {(trip b)}"))
2019-09-06 22:34:04 +03:00
:- i=""
t=(turn `wain`?~(r.hit ~ (to-wain:format q.u.r.hit)) trip)
==
::
:: Print a value (given as a cage) and a note (given as a tang).
::
++ dy-print
|= [cay=cage tan=tang]
2019-09-06 22:34:04 +03:00
%+ dy-rash %tan
%- welp :_ tan
?+ p.cay [(sell q.cay)]~
%tang ;;(tang q.q.cay)
%httr
2019-09-06 22:34:04 +03:00
=+ hit=;;(httr:eyre q.q.cay)
=- (flop (turn `wall`- |=(a=tape leaf+(dash:us a '' ~))))
2019-09-06 22:34:04 +03:00
:- "HTTP {<p.hit>}"
%+ weld
(turn q.hit |=([a=@t b=@t] "{(trip a)}: {(trip b)}"))
2019-09-06 22:34:04 +03:00
:- i=""
t=(turn `wain`?~(r.hit ~ (to-wain:format q.u.r.hit)) trip)
==
::
++ dy-inspect
|= [topics=(list term) sut=type]
%+ dy-rash %mor
2023-01-12 23:53:15 +03:00
=+ to-display=(mule |.((find-item-in-type:dprint (flop topics) sut)))
?: ?=(%| -.to-display)
[%tan [%leaf "Could not find help A"] p.to-display]~
?~ p.to-display
[%tan [%leaf "Could not find help B"]~]~
=/ item (mule |.((print-item:dprint u.p.to-display)))
?: ?=(%| -.item)
[%tan [%leaf "Could not find help C"] p.item]~
p.item
::
2020-08-25 23:45:32 +03:00
++ dy-show-type-noun
|= a=type ^- tank
=- >[-]<
|- ^- $? $% [%atom @tas (unit @)]
[%cell _$ _$]
[%face $@(term tune) _$]
[%fork (set _$)]
[%hold _$ hoon]
==
wain :: "<|core|>"
$?(%noun %void)
==
?+ a a
[%face ^] a(q $(a q.a))
[%cell ^] a(p $(a p.a), q $(a q.a))
[%fork *] a(p (silt (turn ~(tap in p.a) |=(b=type ^$(a b)))))
[%hint *] ?+ q.p.a $(a q.a)
[%know *]
2022-06-24 20:55:09 +03:00
?@ p.q.p.a [(cat 3 '#' mark.p.q.p.a)]~
[(rap 3 '#' auth.p.q.p.a '+' (spat type.p.q.p.a) ~)]~
2022-06-24 20:55:09 +03:00
::
[%help *]
2022-06-24 20:55:09 +03:00
[summary.crib.p.q.p.a]~
==
[%core ^] `wain`/core
2022-06-24 20:55:09 +03:00
[%hold *] $(a (~(play ut p.a) q.a))
==
::
:: XX needs filter
::
++ dy-shown
=/ jank-bucwut :: FIXME just $? fishes when defined for some reason
|* [a=mold b=mold]
|=(c=_`*`*a ?:(& (a c) (b c)))
::
::$? hoon
;: jank-bucwut
hoon
$^ [dy-shown dy-shown]
$% [%ur cord]
[%sa mark]
[%as mark dy-shown]
[%do hoon dy-shown]
[%te [desk term] (list dy-shown)]
[%ge [desk path] (list dy-shown) (map term (unit dy-shown))]
[%dv beak path]
==
==
::
++ dy-show-source
|= a=dojo-source ^- tank
=- >[-]<
=+ `[@ bil=dojo-build]`a
|- ^- dy-shown
2020-08-14 02:40:20 +03:00
?- -.bil
$?(%ur %dv %sa) bil
%ex ?. ?=([%cltr *] p.bil) p.bil
|- ^- hoon
?~ p.p.bil !!
?~ t.p.p.bil i.p.p.bil
[i.p.p.bil $(p.p.bil t.p.p.bil)]
%tu ?~ p.bil !!
|-
?~ t.p.bil ^$(bil q.i.p.bil)
[^$(bil q.i.p.bil) $(p.bil t.p.bil)]
%as bil(q $(bil q.q.bil))
%do bil(q $(bil q.q.bil))
%te bil(q (turn q.bil ..$))
%ge :+ %ge q.p.p.bil
[(turn p.q.p.bil ..$) (~(run by q.q.p.bil) (lift ..$))]
==
2019-09-06 22:34:04 +03:00
::
++ dy-edit :: handle edit
|= cal=sole-change
2019-09-06 22:34:04 +03:00
^+ +>+>
=^ dat say (~(transceive sole say) cal)
?: |(?=(^ per) ?=(^ pux) ?=(~ pro))
=^ lic say (~(transmit sole say) dat)
=/ tip=@t 'dojo: busy (press backspace to abort)'
(dy-diff %mor [%det lic] [%bel ~] [%tan [tip ~]] ~)
=> .(per `dat)
=/ res (mule |.((slam u.pro !>((tufa buf.say)))))
?: ?=(%| -.res)
%- (slog >%dy-edit< p.res)
(dy-rash %bel ~) :: TODO: or +dy-abet(per ~) ?
(dy-made-edit %noun p.res)
2019-09-06 22:34:04 +03:00
::
++ dy-type :: sole action
|= act=sole-action
2019-11-22 03:51:52 +03:00
?- -.dat.act
%det (dy-edit +.dat.act)
%ret (dy-done (tufa buf.say))
%clr dy-stop
%tab +>+>
2019-09-06 22:34:04 +03:00
==
::
++ dy-cage |=(num=@ud (~(got by rez) num)) :: known cage
++ dy-vase |=(num=@ud q:(dy-cage num)) :: known vase
::
++ dy-some
|= src=(list dojo-source)
^- vase
?~ src !>(~)
%+ slop !>(~)
|-
?~ t.src (dy-vase p.i.src)
(slop (dy-vase p.i.src) $(src t.src))
::
++ dy-sore
|= src=(list dojo-source)
^- vase
?~ src
!>(~)
(slop (dy-vase p.i.src) $(src t.src))
::
++ dy-run-generator
2020-06-20 10:45:53 +03:00
!.
|= [cay=cage cig=dojo-config]
^+ +>+>
2019-09-06 22:34:04 +03:00
?. (~(nest ut [%cell [%atom %$ ~] %noun]) | p.q.cay)
:: naked generator; takes one argument
2019-09-06 22:34:04 +03:00
::
?. &(?=([* ~] p.cig) ?=(~ q.cig))
2019-09-06 22:34:04 +03:00
~|(%one-argument !!)
2020-06-25 07:13:53 +03:00
=/ res (mule |.((slam q.cay (dy-vase p.i.p.cig))))
?: ?=(%| -.res)
:: TODO: or +dy-rash ?
(he-diff(poy ~) %tan leaf+"dojo: naked generator failure" p.res)
(dy-hand %noun p.res)
2019-09-06 22:34:04 +03:00
:: normal generator
::
:: A normal generator takes as arguments:
:: - event args: date, entropy, beak (network location)
:: - positional arguments, as a list
:: - optional keyword arguments, as name-value pairs
::
:: The generator is a pair of a result mark and a gate.
2020-05-22 08:53:04 +03:00
:: TODO: test %ask generators
::
=/ wat (mule |.(!<(?(%ask %say) (slot 2 q.cay))))
?: ?=(%| -.wat)
(he-diff(poy ~) %tan leaf+"dojo: generator neither %ask nor %say" p.wat)
=- =/ res (mule -)
?: ?=(%| -.res)
2020-06-20 10:45:53 +03:00
(he-diff(poy ~) %tan leaf+"dojo: generator failure" p.res)
?- p.wat
%ask (dy-made-dial %noun p.res)
%say (dy-made-gent %noun p.res)
2019-09-06 22:34:04 +03:00
==
2020-06-25 22:38:15 +03:00
:: gat: generator gate
:: som: default gat sample
:: ven: event arguments
:: poz: positional arguments
:: kev: key-value named arguments
:: kuv: default keyword arguments
:: sam: fully populated sample
:: rog: default gat sample
::
|. ^- vase
2020-05-22 08:53:04 +03:00
=/ gat=vase (slot 3 q.cay)
2020-06-25 22:38:15 +03:00
=/ som=vase (slot 6 gat)
=/ ven=vase !>([now=now.hid eny=eny.hid bec=he-beak])
=/ poz=vase (dy-sore p.cig)
=/ kev=vase
=/ kuv=(unit vase) (slew 7 som)
=/ soz=(list [var=term vax=vase])
%~ tap by
%- ~(run by q.cig)
|=(val=(unit dojo-source) ?~(val !>([~ ~]) (dy-vase p.u.val)))
:: if the generator takes a named argument "drum-session",
:: then if a value isn't already supplied, we set it to the session
:: that this dojo instance is being run in.
:: (dojo is, indeed, quite coupled with drum.)
::
=? soz
?& ?=(^ kuv)
(slab %both %drum-session p.u.kuv)
!(~(has by q.cig) %drum-session)
==
[[%drum-session !>(ses.id)] soz] ::TODO does the who matter?
?: =(~ soz)
(fall kuv !>(~))
2020-06-25 22:38:15 +03:00
~| keyword-arg-failure+~(key by q.cig)
%+ slap
(with-faces kuv+(need kuv) rep+(with-faces soz) ~)
:+ %cncb [%kuv]~
%+ turn soz
|= [var=term *]
^- [wing hoon]
[[var]~ [%wing var %rep ~]]
::
=/ sam=vase :(slop ven poz kev)
?. (~(nest ut p.som) | p.sam)
~> %slog.1^leaf+"dojo: nest-need"
~> %slog.0^(skol p.som)
~> %slog.1^leaf+"dojo: nest-have"
~> %slog.0^(skol p.sam)
!!
(slam gat sam)
2019-09-06 22:34:04 +03:00
::
++ dy-made-dial :: dialog product
|= cag=cage
2019-09-06 22:34:04 +03:00
^+ +>+>
?. ?=(^ q.q.cag)
(dy-errd ~ q.q.cag)
=+ tan=((list tank) +2.q.q.cag)
=. +>+>.$ (he-diff %tan tan)
=+ vax=(sped (slot 3 q.cag))
?+ -.q.vax !!
%&
?~ +.q.vax
~& %dy-made-dial-abort
(dy-rash %bel ~)
(dy-meal (slot 7 vax))
::
%|
=< he-pone
%- dy-diff(pro `(slap (slot 7 vax) [%limb %q]))
=+ pom=(sole-prompt +<.q.vax)
[%pro pom(cad [':' ' ' cad.pom])]
==
::
++ dy-made-gent :: generator product
|= cag=cage
2019-09-06 22:34:04 +03:00
(dy-meal q.cag)
::
++ dy-made-noun :: generator product
|= cag=cage
2019-09-06 22:34:04 +03:00
(dy-hand %noun q.cag)
::
++ dy-wool-poke
|= [[=desk =term] src=(list dojo-source)]
^+ +>+>
?> ?=(~ pux)
=/ tid (scot %ta (cat 3 'dojo_' (scot %uv (sham eny.hid))))
=. poy `+>+<.$(pux `/wool)
=. +>+>.$
%- he-card
2020-04-21 08:05:05 +03:00
[%pass /wool %agent [our.hid %spider] %watch /thread-result/[tid]]
%- he-card
=/ =cage :: also sub
::TODO would be nice if spider supported starting from paths,
:: for semantics/abilities/code closer to generators.
[%spider-start !>([~ `tid he-beak(q.dir desk) term (dy-some src)])]
2020-04-21 08:05:05 +03:00
[%pass /wool %agent [our.hid %spider] %poke cage]
::
2019-09-06 22:34:04 +03:00
++ dy-make :: build step
^+ +>
?> ?=(^ cud)
=/ bil q.u.cud
?- -.bil
%ur (dy-request /hand `request:http`[%'GET' p.bil ~ ~])
%te (dy-wool-poke p.bil q.bil)
%ex (dy-mere p.bil)
%dv (dy-sing hand+q.bil %a p.bil (snoc q.bil %hoon))
%ge (dy-run-generator (dy-cage p.p.p.bil) q.p.bil)
%sa
=/ has-mark .?((get-fit:clay he-beak %mar p.bil))
?. has-mark
(he-diff(poy ~) %tan leaf+"dojo: %{(trip p.bil)} missing" ~)
2020-12-06 12:03:12 +03:00
=+ .^(=dais:clay cb+(en-beam he-beak /[p.bil]))
2021-03-06 00:53:35 +03:00
(dy-hand p.bil *vale:dais)
::
%as
=/ cag=cage (dy-cage p.q.bil)
2021-07-16 21:45:46 +03:00
=/ has-mark .?((get-fit:clay he-beak %mar p.bil))
?. has-mark :: yolo
(dy-hand p.bil q.cag)
2021-11-09 23:03:49 +03:00
=/ res
=+ .^(=tube:clay cc+(en-beam he-beak /[p.cag]/[p.bil]))
(mule |.((tube q.cag)))
?: ?=(%| -.res)
(he-diff(poy ~) %tan leaf+"dojo: %as %{(trip p.bil)} failed" p.res)
(dy-hand p.bil p.res)
::
%do
=/ gat (dy-eval p.bil)
?: ?=(%| -.gat)
(he-diff(poy ~) %tan leaf+"dojo: %do create gate failed" p.gat)
=/ res (mule |.((slam q.p.gat (dy-vase p.q.bil))))
?: ?=(%| -.res)
(he-diff(poy ~) %tan leaf+"dojo: %do execute failed" p.res)
(dy-hand %noun p.res)
::
%tu
%+ dy-hand %noun
|- ^- vase
?~ p.bil !!
=/ hed (dy-vase p.i.p.bil)
?~ t.p.bil hed
(slop hed $(p.bil t.p.bil))
2019-09-06 22:34:04 +03:00
==
:: +dy-hoon-var: if input is a dojo variable lookup, perform it
2019-09-06 22:34:04 +03:00
::
:: If the expression is a bare reference to a Dojo variable,
:: produce that variable's value; otherwise, produce ~.
::
++ dy-hoon-var
2019-09-06 22:34:04 +03:00
=+ ^= ope
|= gen=hoon ^- hoon
?: ?=(?(%sggl %sggr) -.gen)
2019-09-06 22:34:04 +03:00
$(gen q.gen)
=+ ~(open ap gen)
?.(=(gen -) $(gen -) gen)
|= gen=hoon ^- (unit cage)
2019-09-06 22:34:04 +03:00
=. gen (ope gen)
?: ?=([%cnts [@ ~] ~] gen)
(~(get by var) i.p.gen)
2019-09-06 22:34:04 +03:00
~
:: +dy-mere: execute hoon and complete construction step
::
++ dy-mere
|= =hoon
=/ res (dy-eval hoon)
?: ?=(%| -.res)
(he-diff(poy ~) %tan leaf+"dojo: hoon expression failed" p.res)
(dy-hand p.res)
:: +dy-eval: run hoon source against the dojo subject
::
:: TODO: use /lib and /sur imports to construct subject
2019-09-06 22:34:04 +03:00
::
++ dy-eval
|= =hoon
^- (each cage tang)
?^ val=(dy-hoon-var hoon)
&+u.val
2020-06-20 10:45:53 +03:00
!.
%- mule |.
2020-05-12 10:01:46 +03:00
:- %noun
=/ vaz=(list [term vase])
(turn ~(tap by var) |=([lal=term cag=cage] [lal q.cag]))
=/ sut (slop !>([our=our now=now eny=eny]:hid) !>(..zuse))
=? sut ?=(^ vaz) (slop (with-faces vaz) sut)
(slap sut hoon)
2019-09-06 22:34:04 +03:00
::
++ dy-step :: advance project
|= nex=@ud
2019-09-06 22:34:04 +03:00
^+ +>+>
?> ?=(~ cud)
?: =(nex num)
dy-over
?: =([%show %3] -.mad) :: just show source
dy-over
2019-09-06 22:34:04 +03:00
dy-make(cud `[nex (~(got by job) nex)])
--
::
++ he-dope
|= txt=tape ::
2019-09-06 22:34:04 +03:00
^- (each (unit (each dojo-command tape)) hair) :: prefix+result
=+ len=+((lent txt)) :: line length
=. txt (weld buf `tape`(weld txt "\0a")) ::
=+ vex=((full parse-command-line:he-parser) [1 1] txt)
?: =(q.p.vex len) :: matched to line end
[%& ~] ::
?: =(p.p.vex +((lent (skim txt |=(a=@ =(10 a)))))) :: parsed all lines
2019-09-06 22:34:04 +03:00
[%& ~ ?~(q.vex [%| txt] [%& p.u.q.vex])] :: new buffer+complete
[%| p.p.vex (dec q.p.vex)] :: syntax error
::
++ he-duke :: ++he-dope variant
|= txt=tape
2019-09-06 22:34:04 +03:00
^- (each (unit (each dojo-command tape)) @ud)
=+ foy=(he-dope txt)
?- -.foy
%| [%| q.p.foy]
%& [%& p.foy]
==
::
++ he-abet :: resolve
2019-11-14 03:16:36 +03:00
[(flop moz) %_(state hoc (~(put by hoc) id +<+>+))]
2019-09-06 22:34:04 +03:00
::
++ he-card :: emit gift
2019-11-19 07:36:21 +03:00
|= =card:agent:gall
2019-09-06 22:34:04 +03:00
^+ +>
2019-11-14 03:16:36 +03:00
=? card ?=(%pass -.card)
^- card:agent:gall
card(p [(scot %p who.id) ses.id p.card])
%_(+> moz [card moz])
2019-09-06 22:34:04 +03:00
::
++ he-diff :: emit update
|= fec=sole-effect
2019-09-06 22:34:04 +03:00
^+ +>
(he-card %give %fact ~[(id-to-path:sole id)] %sole-effect !>(fec))
2019-09-06 22:34:04 +03:00
::
++ he-stop :: abort work
^+ .
?~(poy . ~(dy-stop dy u.poy))
::
++ he-peer :: subscribe to
|= pax=path
2019-09-10 06:00:56 +03:00
?>(=(~ pax) he-prom)
2019-09-06 22:34:04 +03:00
::
++ he-pine :: restore prompt
^+ .
?^ poy .
he-prom:he-pone
::
++ he-errd :: reject update
|= [rev=(unit sole-edit) err=@u] ^+ +>
2019-09-06 22:34:04 +03:00
=+ red=(fall rev [%nop ~]) :: required for error location sync
=^ lic say (~(transmit sole say) red)
(he-diff %mor [%det lic] [%err err] ~)
::
++ he-pone :: clear prompt
^+ .
=^ cal say (~(transmit sole say) [%set ~])
(he-diff %mor [%det cal] ~)
::
++ he-prow :: where we are
^- tape
2021-07-14 01:53:04 +03:00
?: &(=(our.hid p.dir) =(%base q.dir) =([%ud 0] r.dir) =(~ s.dir)) ~
2019-09-06 22:34:04 +03:00
%+ weld
?: &(=(our.hid p.dir) =([%ud 0] r.dir))
(weld "/" (trip q.dir))
;: weld
"/" ?:(=(our.hid p.dir) "=" (scow %p p.dir))
2021-07-14 01:53:04 +03:00
"/" ?:(=(%base q.dir) "=" (trip q.dir))
2019-09-06 22:34:04 +03:00
"/" ?:(=([%ud 0] r.dir) "=" (scow r.dir))
==
?:(=(~ s.dir) "" (spud s.dir))
2019-09-06 22:34:04 +03:00
::
++ he-prom :: send prompt
%- he-diff
:- %pro
[& %$ (weld he-prow ?~(buf "> " "< "))]
::
++ he-writ
|= [way=wire =riot:clay]
2019-09-06 22:34:04 +03:00
^+ +>
?> ?=(^ poy)
=< he-pine
2020-05-04 14:17:38 +03:00
?+ way !!
[%hand *]
?~ riot
2021-07-16 21:45:46 +03:00
~> %slog.0^leaf/"dojo: %writ fail {<way>}"
2020-05-04 14:17:38 +03:00
(he-diff(poy ~) %tan >%generator-build-fail< >(snoc t.way %hoon)< ~)
(~(dy-hand dy u.poy(pux ~)) noun+!<(vase q.r.u.riot))
==
2019-09-06 22:34:04 +03:00
::
++ he-unto :: result from agent
|= [way=wire cit=sign:agent:gall]
2019-09-06 22:34:04 +03:00
^+ +>
?. ?=(%poke-ack -.cit)
2019-09-06 22:34:04 +03:00
~& [%strange-unto cit]
+>
?~ p.cit
(he-diff %txt ">=")
(he-diff %tan leaf+"dojo: app poke failed" u.p.cit)
::
++ he-wool
2019-11-19 07:36:21 +03:00
|= [way=wire =sign:agent:gall]
^+ +>
?- -.sign
%poke-ack
?~ p.sign
+>.$
=. +>.$ (he-diff(poy ~) %tan leaf+"dojo: thread poke failed" u.p.sign)
2020-04-21 08:05:05 +03:00
(he-card %pass /wool %agent [our.hid %spider] %leave ~)
::
%watch-ack
?~ p.sign
+>.$
(he-diff(poy ~) %tan leaf+"dojo: thread watch failed" u.p.sign)
::
%fact
?+ p.cage.sign ~|([%dojo-thread-bad-mark-result p.cage.sign] !!)
%thread-fail
=+ !<([=term =tang] q.cage.sign)
%+ he-diff(poy ~) %tan
(flop `^tang`[leaf+"thread failed: {<term>}" tang])
::
%thread-done
?> ?=(^ poy)
:: print the vase as a tang if it nests in tang
=/ =mark
?: (~(nest ut -:!>(*tang)) | p.q.cage.sign)
%tang
%noun
(~(dy-hand dy u.poy(pux ~)) mark q.cage.sign)
==
::
%kick +>.$
==
2019-09-06 22:34:04 +03:00
:: +he-http-response: result from http-client
::
++ he-http-response
|= [way=wire response=client-response:iris]
^+ +>
?> ?=(^ poy)
=< he-pine
?. ?=(%finished -.response)
~& %dojo-received-http-progress
+>
::
~! response
%. [%httr !>((to-httr:iris response-header.response full-file.response))]
=+ dye=~(. dy u.poy(pux ~))
?+ way !!
[%hand ~] dy-hand:dye
[%show ~] dy-show:dye
2019-09-06 22:34:04 +03:00
==
::
++ he-lens
|= com=command:lens
2019-09-06 22:34:04 +03:00
^+ +>
=/ source=dojo-source
=| num=@
=- ?. ?=(%send-api -.sink.com) :: XX num is incorrect
2019-09-06 22:34:04 +03:00
sor
:- 0
:+ %as `mark`(cat 3 api.sink.com '-poke')
:- 1
:+ %do
^- hoon
:+ %brtr [%base %noun]
:^ %clls [%rock %tas %post]
[%rock %$ endpoint.sink.com]
[%cnts [%& 6]~ ~]
sor
^= sor
|- ^- dojo-source
:- num
?- -.source.com
%data [%ex %sand %t data.source.com]
%dojo
2019-09-06 22:34:04 +03:00
%+ rash command.source.com
(ifix [(punt gap) (punt gap)] parse-build:he-parser)
::
%clay
2019-09-06 22:34:04 +03:00
:- %ex
^- hoon
:+ %dtkt
[%base %noun]
:+ %clhp
[%rock %tas %cx]
%+ rash pax.source.com
2021-07-14 01:53:04 +03:00
rood:(vang | /(scot %p our.hid)/base/(scot %da now.hid))
2019-09-06 22:34:04 +03:00
::
%url [%ur (crip (en-purl:html url.source.com))]
%api !!
%get-api
2019-09-06 22:34:04 +03:00
:- %ex
^- hoon
:+ %dtkt
[%like ~[%json] ~]
:* %clsg
[%rock %tas %gx]
[%sand %ta (scot %p our.hid)]
[%sand %tas api.source.com]
[%sand %ta (scot %da now.hid)]
(turn endpoint.source.com |=(a=@t [%sand %ta a]))
2019-09-06 22:34:04 +03:00
==
::
%listen-api !!
%export !!
%import !!
%export-all !!
%import-all !!
2021-05-29 22:53:23 +03:00
%cancel !!
%as
2019-09-06 22:34:04 +03:00
:* %as mar.source.com
$(num +(num), source.com next.source.com)
==
::
%hoon
2019-09-06 22:34:04 +03:00
:* %do
%+ rash code.source.com
2021-07-14 01:53:04 +03:00
tall:(vang | /(scot %p our.hid)/base/(scot %da now.hid))
2019-09-06 22:34:04 +03:00
$(num +(num), source.com next.source.com)
==
::
%tuple
2019-09-06 22:34:04 +03:00
:- %tu
|- ^- (list dojo-source)
?~ next.source.com
~
=. num +(num)
:- ^$(source.com i.next.source.com)
$(next.source.com t.next.source.com)
==
=+ |- ^- sink=dojo-sink
2019-09-06 22:34:04 +03:00
?- -.sink.com
%stdout [%show %0]
%output-file $(sink.com [%command (cat 3 '@' pax.sink.com)])
%output-pill $(sink.com [%command (cat 3 '.' pax.sink.com)])
2020-12-06 12:03:12 +03:00
%output-clay [%file (need (de-beam pax.sink.com))]
%url [%http %post (crip (en-purl:html url.sink.com))]
%to-api !!
%send-api [%poke our.hid api.sink.com]
%command (rash command.sink.com parse-sink:he-parser)
%app [%poke our.hid app.sink.com]
2019-09-06 22:34:04 +03:00
==
(he-plan sink source)
::
++ he-like :: accept line
|= buf=(list @c)
2019-09-06 22:34:04 +03:00
=(%& -:(he-dope (tufa buf)))
::
++ he-stir :: apply change
|= cal=sole-change
2019-09-06 22:34:04 +03:00
^+ +>
:: ~& [%his-clock ler.cal]
:: ~& [%our-clock ven.say]
=^ dat say (~(transceive sole say) cal)
?. ?& ?=(%del -.dat)
2019-09-06 22:34:04 +03:00
=(+(p.dat) (lent buf.say))
==
+>.$
=+ foy=(he-dope (tufa buf.say))
?: ?=(%& -.foy) +>.$
:: ~& [%bad-change dat ted.cal]
:: ~& [%our-leg leg.say]
(he-errd `dat q.p.foy)
::
++ he-plan :: execute command
|= mad=dojo-command
2019-09-06 22:34:04 +03:00
^+ +>
?> ?=(~ poy)
he-pine:(dy-step:~(dy-init dy %*(. *dojo-project mad mad)) 0)
::
++ he-done :: parse command
|= txt=tape
2019-09-06 22:34:04 +03:00
^+ +>
?~ txt
=< he-prom(buf ~)
%- he-diff
:~ %mor
[%txt "> "]
[%nex ~]
==
=+ doy=(he-duke txt)
?- -.doy
%| (he-errd ~ p.doy)
%&
?~ p.doy
(he-errd ~ (lent txt))
=+ old=(weld ?~(buf "> " " ") (tufa buf.say))
=^ cal say (~(transmit sole say) [%set ~])
=. +>.$ (he-diff %mor txt+old nex+~ det+cal ~)
?- -.u.p.doy
%& (he-plan(buf ~) p.u.p.doy)
%| he-prom(buf p.u.p.doy)
==
==
::
++ he-tab
|= pos=@ud
^+ +>
=* res +>
=/ [back-pos=@ud fore-pos=@ud txt=tape]
(insert-magic:auto (add (lent buf) pos) :(weld buf (tufa buf.say)))
=/ id-len (sub fore-pos back-pos)
=/ fore-pos-diff (sub fore-pos pos)
=+ vex=((full parse-command-line:he-parser) [1 1] txt)
?. ?=([* ~ [* @ %ex *] *] vex)
(he-tab-not-hoon pos :(weld buf (tufa buf.say) "\0a"))
=/ typ p:(slop q:he-hoon-head !>(..zuse))
=/ tl (tab-list-hoon:auto typ p.q.q.p.u.q.vex)
=/ advance (advance-hoon:auto typ p.q.q.p.u.q.vex)
=? res ?=(^ advance)
=/ to-send
(trip (rsh [3 (sub pos back-pos)] u.advance))
=| fxs=(list sole-effect)
=. .
|- ^+ +.$
?. (gth fore-pos-diff 0)
+.$
=^ lic say (~(transmit sole say) %del pos)
%= $
fxs [det+lic fxs]
fore-pos-diff (dec fore-pos-diff)
==
:: =. pos (add pos fore-pos-diff)
|- ^+ res
?~ to-send
(he-diff %mor (flop fxs))
=^ lic say (~(transmit sole say) %ins pos `@c`i.to-send)
$(to-send t.to-send, fxs [`sole-effect`det+lic fxs], pos +(pos))
:: If couldn't search (eg cursor not in appropriate position), do
:: nothing.
::
2020-01-04 00:06:42 +03:00
?: ?=(~ tl)
res
:: If no options, ring the bell
::
2020-01-04 00:06:42 +03:00
?: =([~ ~] tl)
(he-diff %bel ~)
:: If only one option, don't print unless the option is already
:: typed in.
::
?: &(?=([* ~] u.tl) !=((met 3 (need advance)) id-len))
res
:: Else, print results
::
=/ lots (gth (lent u.tl) 10)
%+ he-diff %tab
%+ turn u.tl
|= [=term =type]
~| term
:- term
?: lots
*tank
:: +perk is broken because *perk crashes.
::
?: =(%perk term)
*tank
~(duck easy-print type)
::
:: Full tab complete for all Dojo sinks and sources is a madmans job.
:: Instead, we try to parse limited but common forms we know we can
:: autocomplete correctly
++ he-tab-not-hoon
|= [pos=@ud txt=tape]
^+ +>
=* res +>
|^
=/ naked-poke=(unit term)
%+ rust txt
(full (ifix [col (just `@`10)] ;~(pose sym (easy %$))))
?^ naked-poke
(complete-naked-poke u.naked-poke)
=/ variable=(unit term)
%+ rust txt
(full (ifix [tis (just `@`10)] ;~(pose sym (easy %$))))
?^ variable
(complete-variable u.variable)
=/ gen-poke-to-app=(unit [term term])
%+ rust txt
;~ sfix
;~ (glue bar)
;~(pose ;~(pfix col sym) (easy %$))
;~(pose sym (easy %$))
==
(just `@`10)
==
?^ gen-poke-to-app
(complete-gen-poke-to-app u.gen-poke-to-app)
=/ naked-gen=(unit term)
%+ rust txt
(full (ifix [lus (just `@`10)] ;~(pose sym (easy %$))))
?~ naked-gen
res
(complete-naked-gen u.naked-gen)
::
++ complete-naked-poke
|= app=term
=/ pax=path
/(scot %p our.hid)/[q:he-beam]/(scot %da now.hid)/app
%+ complete (cat 3 ':' app)
%+ murn ~(tap by dir:.^(arch %cy pax))
|= [=term ~]
^- (unit [^term tank])
?. =(app (end [3 (met 3 app)] term))
~
?~ =<(fil .^(arch %cy (weld pax ~[term %hoon])))
~
`[(cat 3 ':' term) *tank]
::
++ complete-variable
|= variable=term
%+ complete variable
%+ murn ~(tap by var)
|= [name=term =cage]
^- (unit [term tank])
?. =(variable (end [3 (met 3 variable)] name))
~
`[name (sell q.cage)]
::
++ complete-gen-poke-to-app
|= [app=term gen=term]
2020-04-01 05:29:14 +03:00
=. app
?:(?=(%$ app) %hood app)
%+ complete
?: =(%hood app)
(cat 3 '|' gen)
:((cury cat 3) ':' app '|' gen)
=/ pfix=path
/(scot %p our.hid)/[q:he-beam]/(scot %da now.hid)/gen/[app]
::
%^ tab-generators:auto pfix `app
%+ murn
~(tap by dir:.^(arch %cy pfix))
|= [=term ~]
?. =(gen (end [3 (met 3 gen)] term))
~
?~ =<(fil .^(arch %cy (weld pfix ~[term %hoon])))
~
(some term)
::
++ complete-naked-gen
|= gen=term
%+ complete (cat 3 '+' gen)
=/ pax=path
/(scot %p our.hid)/[q:he-beam]/(scot %da now.hid)/gen
%^ tab-generators:auto pax ~
%+ murn
~(tap by dir:.^(arch %cy pax))
|= [=term ~]
?. =(gen (end [3 (met 3 gen)] term))
~
?~ =<(fil .^(arch %cy (weld pax ~[term %hoon])))
~
(some term)
::
++ complete
|= [completing=term options=(list [term tank])]
?~ options
res
=/ advance
(longest-match:auto options)
=. pos
(dec (lent txt)) :: lock cursor at end
=/ back-pos
(sub pos (met 3 completing))
=/ to-send
(trip (rsh [3 (sub pos back-pos)] advance))
=| fxs=(list sole-effect)
::
:: Cursor is guaranteed to be at end so we don't worry about the
:: backwards case
::
=. res
|- ^+ res
?~ to-send
(he-diff %mor (flop fxs))
=^ lic say (~(transmit sole say) %ins pos `@c`i.to-send)
$(to-send t.to-send, fxs [`sole-effect`det+lic fxs], pos +(pos))
:: If no options, ring the bell
::
?: =(~ options)
(he-diff %bel ~)
:: If only one option, don't print unless the option is already
:: typed in.
::
?: &(?=([* ~] options) !=((met 3 advance) (met 3 completing)))
res
:: Else, print results
::
%+ he-diff %tab
options
--
::
2019-09-06 22:34:04 +03:00
++ he-type :: apply input
|= act=sole-action
2019-09-06 22:34:04 +03:00
^+ +>
?^ poy
he-pine:(~(dy-type dy u.poy) act)
2019-11-22 03:51:52 +03:00
?- -.dat.act
%det (he-stir +.dat.act)
%ret (he-done (tufa buf.say))
%clr he-pine(buf "")
%tab (he-tab +.dat.act)
2019-09-06 22:34:04 +03:00
==
::
++ he-lame :: handle error
|= [wut=term why=tang]
2019-09-06 22:34:04 +03:00
^+ +>
%- (slog (flop `tang`[>%dojo-lame wut< why]))
?^ poy
he-pine:~(dy-amok dy u.poy)
he-pine :: XX give mean to original keystroke
::
++ he-hoon-head :: dynamic state
:: todo: how do i separate the toplevel 'dojo state' comment?
:: dojo state
::
:: our: the name of this urbit
:: now: the current time
:: eny: a piece of random entropy
::
^- cage
:- %noun
=+ sloop=|=([a=vase b=vase] ?:(=(*vase a) b ?:(=(*vase b) a (slop a b))))
%+ sloop
%- ~(rep by var)
|= [[a=term @ b=vase] c=vase] ^- vase
(sloop b(p face+[a p.b]) c)
!>([our=our now=now eny=eny]:hid)
2019-09-06 22:34:04 +03:00
--
--
2019-11-19 07:36:21 +03:00
^- agent:gall
|_ hid=bowl:gall
2019-11-07 09:19:32 +03:00
++ on-init
`..on-init
2019-09-06 22:34:04 +03:00
::
2019-11-07 09:19:32 +03:00
++ on-save
!>(state)
::
2019-11-07 09:19:32 +03:00
++ on-load
|= ole=vase
^- (quip card:agent:gall _..on-init)
|^ =+ old=!<(house-any ole)
=? old ?=(%5 -.old)
^- house-any
^- house-6
(house-5-to-6 old)
=? old ?=(?(%6 %7) -.old)
(house-6-7-to-8 +.old)
=^ caz old
?. ?=(%8 -.old) [~ old]
(house-8-to-9 old)
?> ?=(%9 -.old)
[caz ..on-init(state old)]
::
+$ house-any $%(house house-8 house-7 house-6 house-5)
::
+$ id-8 @tasession
+$ house-8
$: %8
egg=@u
hoc=(map id-8 session)
acl=(set ship)
==
++ house-8-to-9
|= old=house-8
^- (quip card:agent:gall house)
:- %+ turn ~(tap in ~(key by hoc.old))
|= id=@ta
^- card:agent:gall
[%give %kick ~[/sole/[id]] ~]
=- [%9 egg.old - acl.old]
%- ~(gas by *(map sole-id session))
%+ murn ~(tap by hoc.old)
|= [id=@ta s=session]
(bind (upgrade-id:sole id) (late s))
::
+$ house-7 [%7 house-6-7]
+$ house-6 [%6 house-6-7]
+$ house-6-7
$: egg=@u :: command count
hoc=(map id-8 session-6) :: conversations
acl=(set ship) :: remote access whitelist
== ::
+$ session-6 :: per conversation
$: say=sole-share :: command-line state
dir=beam :: active path
poy=(unit *) :: working
$: :: sur: structure imports
::
sur=(list cable:clay)
:: lib: library imports
::
lib=(list cable:clay)
==
var=(map term cage) :: variable state
old=(set term) :: used TLVs
buf=tape :: multiline buffer
== ::
++ house-6-7-to-8
|= old=house-6-7
[%8 egg.old (~(run by hoc.old) session-6-to-8) acl.old]
++ session-6-to-8
|= old=session-6
~? ?=(^ poy.old) [dap.hid %cancelling-for-load]
old(poy ~, -.dir [our.hid %base ud+0])
::
+$ house-5
[%5 egg=@u hoc=(map id-8 session-6)]
++ house-5-to-6
|= old=house-5
^- house-6
[%6 egg.old hoc.old *(set ship)]
--
2019-09-06 22:34:04 +03:00
::
2019-11-07 09:19:32 +03:00
++ on-poke
2019-09-06 22:34:04 +03:00
|= [=mark =vase]
2019-11-19 07:36:21 +03:00
^- (quip card:agent:gall _..on-init)
2019-09-06 22:34:04 +03:00
=^ moves state
2019-11-19 07:36:21 +03:00
^- (quip card:agent:gall house)
2019-09-06 22:34:04 +03:00
?+ mark ~|([%dojo-poke-bad-mark mark] !!)
2020-05-06 21:35:47 +03:00
::
2019-11-14 03:16:36 +03:00
%sole-action
2019-11-22 03:51:52 +03:00
=/ act !<(sole-action vase)
he-abet:(~(he-type he hid id.act ~ (~(got by hoc) id.act)) act)
2019-11-14 03:16:36 +03:00
::
%lens-command
=+ !<([ses=@ta =command:lens] vase)
=/ =id [our.hid ses]
2019-11-14 03:16:36 +03:00
he-abet:(~(he-lens he hid id ~ (~(got by hoc) id)) command)
::
2020-05-08 07:53:21 +03:00
%allow-remote-login
2020-05-06 21:35:47 +03:00
=/ who !<(@p vase)
`state(acl (~(put in acl) who))
::
2020-05-08 07:53:21 +03:00
%revoke-remote-login
2020-05-06 21:35:47 +03:00
=/ who !<(@p vase)
:_ state(acl (~(del in acl) who))
2020-05-08 04:12:57 +03:00
[%give %kick ~ `who]~
2020-05-06 21:35:47 +03:00
::
2020-05-08 07:53:21 +03:00
%list-remote-logins
2020-05-06 21:35:47 +03:00
~& acl
2019-11-14 03:16:36 +03:00
`state
::
2019-09-06 22:34:04 +03:00
%wipe
~& %dojo-wipe
=. hoc
%- ~(run by hoc)
|= =session
%_ session
sur ~
lib ~
var ~
old ~
==
[~ state]
==
::
2019-11-07 09:19:32 +03:00
[moves ..on-init]
2019-09-06 22:34:04 +03:00
::
2019-11-07 09:19:32 +03:00
++ on-watch
2019-09-06 22:34:04 +03:00
|= =path
2019-11-19 07:36:21 +03:00
^- (quip card:agent:gall _..on-init)
2020-05-06 21:35:47 +03:00
?> ?| (team:title our.hid src.hid)
(~(has in acl) src.hid)
==
=/ =id (need (path-to-id:sole path))
2019-11-14 03:16:36 +03:00
=? hoc (~(has by hoc) id)
~& [%dojo-peer-replaced id]
(~(del by hoc) id)
2021-07-14 01:53:04 +03:00
=/ =session %*(. *session -.dir [our.hid %base ud+0])
2019-12-04 04:18:09 +03:00
=^ moves state
he-abet:~(he-prom he hid id ~ session)
[moves ..on-init]
2019-09-06 22:34:04 +03:00
::
2019-11-07 09:19:32 +03:00
++ on-leave
2019-11-14 03:16:36 +03:00
|= =path
?> ?=([%sole *] path)
=. hoc (~(del by hoc) (need (path-to-id:sole path)))
2019-11-14 03:16:36 +03:00
[~ ..on-init]
2019-09-06 22:34:04 +03:00
::
2019-11-07 09:19:32 +03:00
++ on-peek
2019-09-06 22:34:04 +03:00
|= path
*(unit (unit cage))
::
2019-11-07 09:19:32 +03:00
++ on-agent
2019-11-19 07:36:21 +03:00
|= [=wire =sign:agent:gall]
^- (quip card:agent:gall _..on-init)
?> ?=([@ @ @ *] wire)
=/ =id [(slav %p i.wire) i.t.wire]
=/ =session (~(got by hoc) id)
=/ he-full ~(. he hid id ~ session)
2019-09-06 22:34:04 +03:00
=^ moves state
=< he-abet
^+ he
?+ i.t.t.wire ~|([%dojo-bad-on-agent wire -.sign] !!)
%poke (he-unto:he-full t.wire sign)
%wool (he-wool:he-full t.wire sign)
==
2019-11-07 09:19:32 +03:00
[moves ..on-init]
2019-09-06 22:34:04 +03:00
::
2019-11-07 09:19:32 +03:00
++ on-arvo
|= [=wire =sign-arvo]
^- (quip card:agent:gall _..on-init)
?> ?=([@ @ *] wire)
=/ =id [(slav %p i.wire) i.t.wire]
=/ =session (~(got by hoc) id)
=/ he-full ~(. he hid id ~ session)
2019-09-06 22:34:04 +03:00
=^ moves state
=< he-abet
?+ +<.sign-arvo ~|([%dojo-bad-take +<.sign-arvo] !!)
%writ (he-writ:he-full t.t.wire +>.sign-arvo)
%http-response (he-http-response:he-full t.t.wire +>.sign-arvo)
2019-09-06 22:34:04 +03:00
==
2019-11-07 09:19:32 +03:00
[moves ..on-init]
:: if dojo fails unexpectedly, kill whatever each session is working on
2019-09-06 22:34:04 +03:00
::
2019-11-07 09:19:32 +03:00
++ on-fail
2019-09-06 22:34:04 +03:00
|= [=term =tang]
=/ sessions=(list (pair id session)) ~(tap by hoc)
2019-11-19 07:36:21 +03:00
|- ^- (quip card:agent:gall _..on-init)
?~ sessions
[~ ..on-init]
=^ cards-1 state
he-abet:(~(he-lame he hid p.i.sessions ~ q.i.sessions) term tang)
=^ cards-2 ..on-init
$(sessions t.sessions)
[(weld cards-1 cards-2) ..on-init]
2019-09-06 22:34:04 +03:00
--