From 9cced62fde5f2ca25e1997a0c2602297c5244507 Mon Sep 17 00:00:00 2001 From: Patrick O'Sullivan Date: Tue, 2 Aug 2022 12:03:21 -0500 Subject: [PATCH] Add desk-dev (garden-dev) --- desk-dev/lib/docket.hoon | 223 ++++++++++++++++++++++++++++++ desk-dev/lib/hark-store.hoon | 255 +++++++++++++++++++++++++++++++++++ desk-dev/lib/mip.hoon | 55 ++++++++ desk-dev/mar/docket-0.hoon | 25 ++++ desk-dev/sur/docket.hoon | 82 +++++++++++ desk-dev/sur/hark-store.hoon | 159 ++++++++++++++++++++++ desk-dev/sur/settings.hoon | 44 ++++++ 7 files changed, 843 insertions(+) create mode 100644 desk-dev/lib/docket.hoon create mode 100644 desk-dev/lib/hark-store.hoon create mode 100644 desk-dev/lib/mip.hoon create mode 100644 desk-dev/mar/docket-0.hoon create mode 100644 desk-dev/sur/docket.hoon create mode 100644 desk-dev/sur/hark-store.hoon create mode 100644 desk-dev/sur/settings.hoon diff --git a/desk-dev/lib/docket.hoon b/desk-dev/lib/docket.hoon new file mode 100644 index 0000000..ef39b7f --- /dev/null +++ b/desk-dev/lib/docket.hoon @@ -0,0 +1,223 @@ +/- *docket +|% +:: +++ mime + |% + +$ draft + $: title=(unit @t) + info=(unit @t) + color=(unit @ux) + glob-http=(unit [=url hash=@uvH]) + glob-ames=(unit [=ship hash=@uvH]) + base=(unit term) + site=(unit path) + image=(unit url) + version=(unit version) + website=(unit url) + license=(unit cord) + == + :: + ++ finalize + |= =draft + ^- (unit docket) + ?~ title.draft ~ + ?~ info.draft ~ + ?~ color.draft ~ + ?~ version.draft ~ + ?~ website.draft ~ + ?~ license.draft ~ + =/ href=(unit href) + ?^ site.draft `[%site u.site.draft] + ?~ base.draft ~ + ?^ glob-http.draft + `[%glob u.base hash.u.glob-http %http url.u.glob-http]:draft + ?~ glob-ames.draft + ~ + `[%glob u.base hash.u.glob-ames %ames ship.u.glob-ames]:draft + ?~ href ~ + =, draft + :- ~ + :* %1 + u.title + u.info + u.color + u.href + image + u.version + u.website + u.license + == + :: + ++ from-clauses + =| =draft + |= cls=(list clause) + ^- (unit docket) + =* loop $ + ?~ cls (finalize draft) + =* clause i.cls + =. draft + ?- -.clause + %title draft(title `title.clause) + %info draft(info `info.clause) + %color draft(color `color.clause) + %glob-http draft(glob-http `[url hash]:clause) + %glob-ames draft(glob-ames `[ship hash]:clause) + %base draft(base `base.clause) + %site draft(site `path.clause) + %image draft(image `url.clause) + %version draft(version `version.clause) + %website draft(website `website.clause) + %license draft(license `license.clause) + == + loop(cls t.cls) + :: + ++ to-clauses + |= d=docket + ^- (list clause) + %- zing + :~ :~ title+title.d + info+info.d + color+color.d + version+version.d + website+website.d + license+license.d + == + ?~ image.d ~ ~[image+u.image.d] + ?: ?=(%site -.href.d) ~[site+path.href.d] + =/ ref=glob-reference glob-reference.href.d + :~ base+base.href.d + ?- -.location.ref + %http [%glob-http url.location.ref hash.ref] + %ames [%glob-ames ship.location.ref hash.ref] + == == == + :: + ++ spit-clause + |= =clause + ^- tape + %+ weld " {(trip -.clause)}+" + ?+ -.clause "'{(trip +.clause)}'" + %color (scow %ux color.clause) + %site (spud path.clause) + :: + %glob-http + "['{(trip url.clause)}' {(scow %uv hash.clause)}]" + :: + %glob-ames + "[{(scow %p ship.clause)} {(scow %uv hash.clause)}]" + :: + %version + =, version.clause + "[{(scow %ud major)} {(scow %ud minor)} {(scow %ud patch)}]" + == + :: + ++ spit-docket + |= dock=docket + ^- tape + ;: welp + ":~\0a" + `tape`(zing (join "\0a" (turn (to-clauses dock) spit-clause))) + "\0a==" + == + -- +:: +++ enjs + =, enjs:format + |% + :: + ++ charge-update + |= u=^charge-update + ^- json + %+ frond -.u + ^- json + ?- -.u + %del-charge s+desk.u + :: + %initial + %- pairs + %+ turn ~(tap by initial.u) + |=([=desk c=^charge] [desk (charge c)]) + :: + %add-charge + %- pairs + :~ desk+s+desk.u + charge+(charge charge.u) + == + == + :: + ++ num + |= a=@u + ^- ^tape + =/ p=json (numb a) + ?> ?=(%n -.p) + (trip p.p) + :: + ++ version + |= v=^version + ^- json + :- %s + %- crip + "{(num major.v)}.{(num minor.v)}.{(num patch.v)}" + :: + ++ merge + |= [a=json b=json] + ^- json + ?> &(?=(%o -.a) ?=(%o -.b)) + [%o (~(uni by p.a) p.b)] + :: + ++ href + |= h=^href + %+ frond -.h + ?- -.h + %site s+(spat path.h) + %glob + %- pairs + :~ base+s+base.h + glob-reference+(glob-reference glob-reference.h) + == + == + :: + ++ glob-reference + |= ref=^glob-reference + %- pairs + :~ hash+s+(scot %uv hash.ref) + location+(glob-location location.ref) + == + :: + ++ glob-location + |= loc=^glob-location + ^- json + %+ frond -.loc + ?- -.loc + %http s+url.loc + %ames s+(scot %p ship.loc) + == + :: + ++ charge + |= c=^charge + %+ merge (docket docket.c) + %- pairs + :~ chad+(chad chad.c) + == + :: + ++ docket + |= d=^docket + ^- json + %- pairs + :~ title+s+title.d + info+s+info.d + color+s+(scot %ux color.d) + href+(href href.d) + image+?~(image.d ~ s+u.image.d) + version+(version version.d) + license+s+license.d + website+s+website.d + == + :: + ++ chad + |= c=^chad + %+ frond -.c + ?+ -.c ~ + %hung s+err.c + == + -- +-- diff --git a/desk-dev/lib/hark-store.hoon b/desk-dev/lib/hark-store.hoon new file mode 100644 index 0000000..23af6a6 --- /dev/null +++ b/desk-dev/lib/hark-store.hoon @@ -0,0 +1,255 @@ +/- sur=hark-store +^? +=, sur +=< [. sur] +|% + +++ enjs + =, enjs:format + |% + ++ update + |= upd=^update + ^- json + %+ frond -.upd + ?+ -.upd a+~ + %added (notification +.upd) + %add-note (add-note +.upd) + %timebox (timebox +.upd) + %more (more +.upd) + %read-each (read-each +.upd) + %read-count (place +.upd) + %unread-each (read-each +.upd) + %unread-count (unread-count +.upd) + %saw-place (saw-place +.upd) + %all-stats (all-stats +.upd) + %del-place (place +.upd) + ::%read-note (index +.upd) + ::%note-read (note-read +.upd) + %archived (archived +.upd) + == + :: + ++ add-note + |= [bi=^bin bo=^body] + %- pairs + :~ bin+(bin bi) + body+(body bo) + == + :: + ++ saw-place + |= [p=^place t=(unit ^time)] + %- pairs + :~ place+(place p) + time+?~(t ~ (time u.t)) + == + :: + ++ archived + |= [t=^time l=^lid n=^notification] + %- pairs + :~ lid+(lid l) + time+s+(scot %ud t) + notification+(notification n) + == + :: + ++ note-read + |= * + (pairs ~) + :: + ++ all-stats + |= places=(map ^place ^stats) + ^- json + :- %a + ^- (list json) + %+ turn ~(tap by places) + |= [p=^place s=^stats] + %- pairs + :~ stats+(stats s) + place+(place p) + + == + :: + ++ stats + |= s=^stats + ^- json + %- pairs + :~ each+a+(turn ~(tap in each.s) (cork spat (lead %s))) + last+(time last.s) + count+(numb count.s) + == + ++ more + |= upds=(list ^update) + ^- json + a+(turn upds update) + :: + ++ place + |= =^place + %- pairs + :~ desk+s+desk.place + path+s+(spat path.place) + == + :: + ++ bin + |= =^bin + %- pairs + :~ place+(place place.bin) + path+s+(spat path.bin) + == + ++ notification + |= ^notification + ^- json + %- pairs + :~ time+(time date) + bin+(^bin bin) + body+(bodies body) + == + ++ bodies + |= bs=(list ^body) + ^- json + a+(turn bs body) + :: + ++ contents + |= cs=(list ^content) + ^- json + a+(turn cs content) + :: + ++ content + |= c=^content + ^- json + %+ frond -.c + ?- -.c + %ship s+(scot %p ship.c) + %text s+cord.c + == + :: + ++ body + |= ^body + ^- json + %- pairs + :~ title+(contents title) + content+(contents content) + time+(^time time) + link+s+(spat link) + == + :: + ++ binned-notification + |= [=^bin =^notification] + %- pairs + :~ bin+(^bin bin) + notification+(^notification notification) + == + ++ lid + |= l=^lid + ^- json + %+ frond -.l + ?- -.l + ?(%seen %unseen) ~ + %archive s+(scot %ud time.l) + == + :: + ++ timebox + |= [li=^lid l=(list ^notification)] + ^- json + %- pairs + :~ lid+(lid li) + notifications+a+(turn l notification) + == + :: + ++ read-each + |= [p=^place pax=^path] + %- pairs + :~ place+(place p) + path+(path pax) + == + :: + ++ unread-count + |= [p=^place inc=? count=@ud] + %- pairs + :~ place+(place p) + inc+b+inc + count+(numb count) + == + -- +++ dejs + =, dejs:format + |% + ++ ship (su ;~(pfix sig fed:ag)) + :: TODO: fix +stab + :: + ++ pa + |= j=json + ^- path + ?> ?=(%s -.j) + ?: =('/' p.j) / + (stab p.j) + :: + ++ place + %- ot + :~ desk+so + path+pa + == + :: + ++ bin + %- ot + :~ path+pa + place+place + == + :: + ++ read-each + %- ot + :~ place+place + path+pa + == + :: + :: parse date as @ud + :: TODO: move to zuse + ++ sd + |= jon=json + ^- @da + ?> ?=(%s -.jon) + `@da`(rash p.jon dem:ag) + :: + ++ lid + %- of + :~ archive+sd + unseen+ul + seen+ul + == + :: + ++ archive + %- ot + :~ lid+lid + bin+bin + == + ++ content + %- of + :~ text+so + ship+ship + == + :: + ++ body + %- ot + :~ title+(ar content) + content+(ar content) + time+di + binned+pa + link+pa + == + :: + ++ add-note + %- ot + :~ bin+bin + body+body + == + :: + ++ action + ^- $-(json ^action) + %- of + :~ archive-all+ul + archive+archive + opened+ul + read-count+place + read-each+read-each + read-note+bin + add-note+add-note + == + -- +-- diff --git a/desk-dev/lib/mip.hoon b/desk-dev/lib/mip.hoon new file mode 100644 index 0000000..322a4c8 --- /dev/null +++ b/desk-dev/lib/mip.hoon @@ -0,0 +1,55 @@ +|% +++ mip :: map of maps + |$ [kex key value] + (map kex (map key value)) +:: +++ bi :: mip engine + =| a=(map * (map)) + |@ + ++ del + |* [b=* c=*] + =+ d=(~(gut by a) b ~) + =+ e=(~(del by d) c) + ?~ e + (~(del by a) b) + (~(put by a) b e) + :: + ++ get + |* [b=* c=*] + => .(b `_?>(?=(^ a) p.n.a)`b, c `_?>(?=(^ a) ?>(?=(^ q.n.a) p.n.q.n.a))`c) + ^- (unit _?>(?=(^ a) ?>(?=(^ q.n.a) q.n.q.n.a))) + (~(get by (~(gut by a) b ~)) c) + :: + ++ got + |* [b=* c=*] + (need (get b c)) + :: + ++ gut + |* [b=* c=* d=*] + (~(gut by (~(gut by a) b ~)) c d) + :: + ++ has + |* [b=* c=*] + !=(~ (get b c)) + :: + ++ key + |* b=* + ~(key by (~(gut by a) b ~)) + :: + ++ put + |* [b=* c=* d=*] + %+ ~(put by a) b + %. [c d] + %~ put by + (~(gut by a) b ~) + :: + ++ tap + ::NOTE naive turn-based implementation find-errors ): + =< $ + =+ b=`_?>(?=(^ a) *(list [x=_p.n.a _?>(?=(^ q.n.a) [y=p v=q]:n.q.n.a)]))`~ + |. ^+ b + ?~ a + b + $(a r.a, b (welp (turn ~(tap by q.n.a) (lead p.n.a)) $(a l.a))) + -- +-- diff --git a/desk-dev/mar/docket-0.hoon b/desk-dev/mar/docket-0.hoon new file mode 100644 index 0000000..911d34c --- /dev/null +++ b/desk-dev/mar/docket-0.hoon @@ -0,0 +1,25 @@ +/+ dock=docket +|_ =docket:dock +++ grow + |% + ++ mime + ^- ^mime + [/text/x-docket (as-octt:mimes:html (spit-docket:mime:dock docket))] + ++ noun docket + ++ json (docket:enjs:dock docket) + -- +++ grab + |% + :: + ++ mime + |= [=mite len=@ud tex=@] + ^- docket:dock + %- need + %- from-clauses:mime:dock + !<((list clause:dock) (slap !>(~) (ream tex))) + + :: + ++ noun docket:dock + -- +++ grad %noun +-- diff --git a/desk-dev/sur/docket.hoon b/desk-dev/sur/docket.hoon new file mode 100644 index 0000000..091c8c9 --- /dev/null +++ b/desk-dev/sur/docket.hoon @@ -0,0 +1,82 @@ +|% +:: ++$ version + [major=@ud minor=@ud patch=@ud] +:: ++$ glob (map path mime) +:: ++$ url cord +:: $glob-location: How to retrieve a glob +:: ++$ glob-reference + [hash=@uvH location=glob-location] +:: ++$ glob-location + $% [%http =url] + [%ames =ship] + == +:: $href: Where a tile links to +:: ++$ href + $% [%glob base=term =glob-reference] + [%site =path] + == +:: $chad: State of a docket +:: ++$ chad + $~ [%install ~] + $% :: Done + [%glob =glob] + [%site ~] + :: Waiting + [%install ~] + [%suspend glob=(unit glob)] + :: Error + [%hung err=cord] + == +:: +:: $charge: A realized $docket +:: ++$ charge + $: =docket + =chad + == +:: +:: $clause: A key and value, as part of a docket +:: +:: Only used to parse $docket +:: ++$ clause + $% [%title title=@t] + [%info info=@t] + [%color color=@ux] + [%glob-http url=cord hash=@uvH] + [%glob-ames =ship hash=@uvH] + [%image =url] + [%site =path] + [%base base=term] + [%version =version] + [%website website=url] + [%license license=cord] + == +:: +:: $docket: A description of JS bundles for a desk +:: ++$ docket + $: %1 + title=@t + info=@t + color=@ux + =href + image=(unit url) + =version + website=url + license=cord + == +:: ++$ charge-update + $% [%initial initial=(map desk charge)] + [%add-charge =desk =charge] + [%del-charge =desk] + == +-- diff --git a/desk-dev/sur/hark-store.hoon b/desk-dev/sur/hark-store.hoon new file mode 100644 index 0000000..4578393 --- /dev/null +++ b/desk-dev/sur/hark-store.hoon @@ -0,0 +1,159 @@ +^? +:: +:: %hark-store: Notification, unreads store +:: +:: Timeboxing & binning: +:: +:: Unread notifications accumulate in $unreads. They are grouped by +:: their $bin. A notification may become read by either: +:: a) being read by a %read-count or %read-each or %read-note +:: b) being read by a %seen +:: +:: If a) then we insert the corresponding bin into $reads at the +:: current timestamp +:: If b) then we empty $unreads and move all bins to $reads at the +:: current timestamp +:: +:: Unread tracking: +:: Unread tracking has two 'modes' which may be used concurrently, +:: if necessary. +:: +:: count: +:: This stores the unreads as a simple atom, describing the number +:: of unread items. May be increased with %unread-count and +:: set to zero with %read-count. Ideal for high-frequency linear +:: datastructures, e.g. chat +:: each: +:: This stores the unreads as a set of paths, describing the set of +:: unread items. Unreads may be added to the set with %unread-each +:: and removed with %read-each. Ideal for non-linear, low-frequency +:: datastructures, e.g. blogs +:: +|% +:: $place: A location, under which landscape stores stats +:: +:: .desk must match q.byk.bowl +:: Examples: +:: A chat: +:: [%landscape /~dopzod/urbit-help] +:: A note in a notebook: +:: [%landscape /~darrux-landes/feature-requests/12374893234232] +:: A group: +:: [%hark-group-hook /~bitbet-bolbel/urbit-community] +:: Comments on a link +:: [%landscape /~dabben-larbet/urbit-in-the-news/17014118450499614194868/2] +:: ++$ place [=desk =path] +:: +:: $bin: Identifier for grouping notifications +:: +:: Examples +:: A mention in a chat: +:: [/mention %landscape /~dopzod/urbit-help] +:: New messages in a chat +:: [/message %landscape /~dopzod/urbit-help] +:: A new comment in a notebook: +:: [/comment %landscape /~darrux-landes/feature-requests/12374893234232/2] +:: ++$ bin [=path =place] +:: +:: $lid: Reference to a timebox +:: ++$ lid + $% [%archive =time] + [%seen ~] + [%unseen ~] + == +:: $content: Notification content ++$ content + $% [%ship =ship] + [%text =cord] + == +:: +:: $body: A notification body +:: ++$ body + $: title=(list content) + content=(list content) + =time + binned=path + link=path + == +:: ++$ notification + [date=@da =bin body=(list body)] +:: $timebox: Group of notificatons ++$ timebox + (map bin notification) +:: $archive: Archived notifications, ordered by time ++$ archive + ((mop @da timebox) gth) +:: ++$ action + $% :: hook actions + :: + :: %add-note: add a notification + [%add-note =bin =body] + :: + :: %del-place: Underlying resource disappeared, remove all + :: associated notifications + [%del-place =place] + :: %unread-count: Change unread count by .count + [%unread-count =place inc=? count=@ud] + :: %unread-each: Add .path to list of unreads for .place + [%unread-each =place =path] + :: %saw-place: Update last-updated for .place to now.bowl + [%saw-place =place time=(unit time)] + :: store actions + :: + :: %archive: archive single notification + :: if .time is ~, then archiving unread notification + :: else, archiving read notification + [%archive =lid =bin] + :: %read-count: set unread count to zero + [%read-count =place] + :: %read-each: remove path from unreads for .place + [%read-each =place =path] + :: %read-note: Read note at .bin + [%read-note =bin] + :: %archive-all: Archive all notifications + [%archive-all ~] + :: %opened: User opened notifications, reset timeboxing logic. + :: + [%opened ~] + :: + :: XX: previously in hark-store, now deprecated + :: the hooks responsible for creating notifications may offer pokes + :: similar to this + :: [%read-graph =resource] + :: [%read-group =resource] + :: [%remove-graph =resource] + :: + == +:: .stats: Statistics for a .place +:: ++$ stats + $: count=@ud + each=(set path) + last=@da + timebox=(unit @da) + == +:: ++$ update + $% action + :: %more: more updates + [%archived =time =lid =notification] + [%more more=(list update)] + :: %note-read: note has been read with timestamp + [%note-read =time =bin] + [%added =notification] + :: %timebox: description of timebox. + :: + [%timebox =lid =(list notification)] + :: %place-stats: description of .stats for a .place + [%place-stats =place =stats] + :: %place-stats: stats for all .places + [%all-stats places=(map place stats)] + == +-- + diff --git a/desk-dev/sur/settings.hoon b/desk-dev/sur/settings.hoon new file mode 100644 index 0000000..53e8691 --- /dev/null +++ b/desk-dev/sur/settings.hoon @@ -0,0 +1,44 @@ +/+ *mip +|% +:: +++ settings-0 + =< settings + |% + +$ settings (map key bucket) + +$ bucket (map key val) + +$ val + $% [%s p=@t] + [%b p=?] + [%n p=@] + == + -- +:: +++ settings-1 + =< settings + |% + +$ settings (map key bucket) + -- ++$ bucket (map key val) ++$ key term ++$ val + $~ [%n 0] + $% [%s p=@t] + [%b p=?] + [%n p=@] + [%a p=(list val)] + == +:: ++$ settings (mip desk key bucket) ++$ event + $% [%put-bucket =desk =key =bucket] + [%del-bucket =desk =key] + [%put-entry =desk buc=key =key =val] + [%del-entry =desk buc=key =key] + == ++$ data + $% [%all =settings] + [%bucket =bucket] + [%desk desk=(map key bucket)] + [%entry =val] + == +--