├── venter ├── sys.kelvin ├── mar │ ├── txt.hoon │ ├── bill.hoon │ ├── goof.hoon │ ├── hoon.hoon │ ├── json.hoon │ ├── kelvin.hoon │ ├── mime.hoon │ ├── noun.hoon │ ├── tang.hoon │ ├── thread-done.hoon │ ├── thread-fail.hoon │ ├── vent-package.hoon │ ├── vent-request.hoon │ └── example │ │ ├── transition.hoon │ │ ├── vent.hoon │ │ └── action.hoon ├── lib │ ├── dbug.hoon │ ├── strand.hoon │ ├── verb.hoon │ ├── skeleton.hoon │ ├── strandio.hoon │ ├── default-agent.hoon │ ├── bout.hoon │ ├── vent.hoon │ └── ventio.hoon ├── sur │ ├── spider.hoon │ ├── verb.hoon │ └── example.hoon ├── ted │ ├── venter.hoon │ ├── tube-warmer.hoon │ ├── test.hoon │ └── vines │ │ └── venter-example.hoon ├── app │ ├── venter-venter.hoon │ └── venter-example.hoon ├── desk.bill └── delete-log.txt ├── archive ├── desk │ ├── lib │ │ ├── strand.hoon │ │ ├── venter.hoon │ │ ├── skeleton.hoon │ │ ├── default-agent.hoon │ │ ├── verb.hoon │ │ ├── dbug.hoon │ │ ├── ventio.hoon │ │ └── strandio.hoon │ ├── sys.kelvin │ ├── desk.bill │ ├── mar │ │ ├── thread-done.hoon │ │ ├── thread-fail.hoon │ │ ├── vent-request.hoon │ │ ├── venter │ │ │ ├── request.hoon │ │ │ ├── response.hoon │ │ │ ├── vent.hoon │ │ │ └── action.hoon │ │ ├── goof.hoon │ │ ├── noun.hoon │ │ ├── vent-package.hoon │ │ ├── kelvin.hoon │ │ ├── json.hoon │ │ ├── mime.hoon │ │ ├── tang.hoon │ │ ├── bill.hoon │ │ ├── hoon.hoon │ │ └── txt.hoon │ ├── sur │ │ ├── verb.hoon │ │ ├── venter.hoon │ │ └── spider.hoon │ ├── ted │ │ ├── venter.hoon │ │ └── vines │ │ │ └── vent-example.hoon │ └── app │ │ ├── venter.hoon │ │ └── vent-example.hoon └── README.md ├── bare-desk ├── ted │ ├── venter.hoon │ └── tube-warmer.hoon ├── lib │ ├── dbug.hoon │ ├── verb.hoon │ ├── agentio.hoon │ ├── server.hoon │ ├── strand.hoon │ ├── skeleton.hoon │ ├── strandio.hoon │ ├── default-agent.hoon │ ├── bout.hoon │ ├── vent.hoon │ ├── bind.hoon │ └── ventio.hoon ├── mar │ ├── bill.hoon │ ├── hoon.hoon │ ├── json.hoon │ ├── mime.hoon │ ├── noun.hoon │ ├── tang.hoon │ ├── txt.hoon │ ├── kelvin.hoon │ ├── thread-done.hoon │ ├── thread-fail.hoon │ ├── vent-request.hoon │ ├── goof.hoon │ └── vent-package.hoon ├── sur │ ├── verb.hoon │ └── spider.hoon └── app │ └── venter-venter.hoon ├── diagrams ├── .gitignore └── images │ ├── vine.png │ ├── venter_pattern.png │ ├── venter_thread.png │ ├── ideal_poke_forwarding.png │ ├── poke_forwarding_nack.png │ ├── generate_ID_client_side.png │ ├── server_side_normal_sync.png │ └── ideal_ID_request_response.png ├── interface ├── src │ ├── react-app-env.d.ts │ ├── setupTests.ts │ ├── App.test.tsx │ ├── index.css │ ├── reportWebVitals.ts │ ├── index.tsx │ ├── App.css │ ├── App.tsx │ ├── logo.svg │ └── api.ts ├── public │ ├── robots.txt │ ├── favicon.ico │ ├── logo192.png │ ├── logo512.png │ ├── manifest.json │ └── index.html ├── .gitignore ├── tsconfig.json ├── package.json └── README.md ├── .gitmodules └── README.md /venter/sys.kelvin: -------------------------------------------------------------------------------- 1 | [%zuse 412] 2 | -------------------------------------------------------------------------------- /archive/desk/lib/strand.hoon: -------------------------------------------------------------------------------- 1 | rand 2 | -------------------------------------------------------------------------------- /archive/desk/sys.kelvin: -------------------------------------------------------------------------------- 1 | [%zuse 413] 2 | -------------------------------------------------------------------------------- /venter/mar/txt.hoon: -------------------------------------------------------------------------------- 1 | ../../bare-desk/mar/txt.hoon -------------------------------------------------------------------------------- /bare-desk/ted/venter.hoon: -------------------------------------------------------------------------------- 1 | /+ *ventio 2 | venter 3 | -------------------------------------------------------------------------------- /diagrams/.gitignore: -------------------------------------------------------------------------------- 1 | venv/ 2 | .ipynb_checkpoints/ 3 | -------------------------------------------------------------------------------- /venter/lib/dbug.hoon: -------------------------------------------------------------------------------- 1 | ../../bare-desk/lib/dbug.hoon -------------------------------------------------------------------------------- /venter/lib/strand.hoon: -------------------------------------------------------------------------------- 1 | ../../bare-desk/lib/strand.hoon -------------------------------------------------------------------------------- /venter/lib/verb.hoon: -------------------------------------------------------------------------------- 1 | ../../bare-desk/lib/verb.hoon -------------------------------------------------------------------------------- /venter/mar/bill.hoon: -------------------------------------------------------------------------------- 1 | ../../bare-desk/mar/bill.hoon -------------------------------------------------------------------------------- /venter/mar/goof.hoon: -------------------------------------------------------------------------------- 1 | ../../bare-desk/mar/goof.hoon -------------------------------------------------------------------------------- /venter/mar/hoon.hoon: -------------------------------------------------------------------------------- 1 | ../../bare-desk/mar/hoon.hoon -------------------------------------------------------------------------------- /venter/mar/json.hoon: -------------------------------------------------------------------------------- 1 | ../../bare-desk/mar/json.hoon -------------------------------------------------------------------------------- /venter/mar/kelvin.hoon: -------------------------------------------------------------------------------- 1 | ../../bare-desk/mar/kelvin.hoon -------------------------------------------------------------------------------- /venter/mar/mime.hoon: -------------------------------------------------------------------------------- 1 | ../../bare-desk/mar/mime.hoon -------------------------------------------------------------------------------- /venter/mar/noun.hoon: -------------------------------------------------------------------------------- 1 | ../../bare-desk/mar/noun.hoon -------------------------------------------------------------------------------- /venter/mar/tang.hoon: -------------------------------------------------------------------------------- 1 | ../../bare-desk/mar/tang.hoon -------------------------------------------------------------------------------- /venter/sur/spider.hoon: -------------------------------------------------------------------------------- 1 | ../../bare-desk/sur/spider.hoon -------------------------------------------------------------------------------- /venter/sur/verb.hoon: -------------------------------------------------------------------------------- 1 | ../../bare-desk/sur/verb.hoon -------------------------------------------------------------------------------- /venter/ted/venter.hoon: -------------------------------------------------------------------------------- 1 | ../../bare-desk/ted/venter.hoon -------------------------------------------------------------------------------- /venter/lib/skeleton.hoon: -------------------------------------------------------------------------------- 1 | ../../bare-desk/lib/skeleton.hoon -------------------------------------------------------------------------------- /venter/lib/strandio.hoon: -------------------------------------------------------------------------------- 1 | ../../bare-desk/lib/strandio.hoon -------------------------------------------------------------------------------- /bare-desk/lib/dbug.hoon: -------------------------------------------------------------------------------- 1 | ../../urbit/pkg/base-dev/lib/dbug.hoon -------------------------------------------------------------------------------- /bare-desk/lib/verb.hoon: -------------------------------------------------------------------------------- 1 | ../../urbit/pkg/base-dev/lib/verb.hoon -------------------------------------------------------------------------------- /bare-desk/mar/bill.hoon: -------------------------------------------------------------------------------- 1 | ../../urbit/pkg/base-dev/mar/bill.hoon -------------------------------------------------------------------------------- /bare-desk/mar/hoon.hoon: -------------------------------------------------------------------------------- 1 | ../../urbit/pkg/base-dev/mar/hoon.hoon -------------------------------------------------------------------------------- /bare-desk/mar/json.hoon: -------------------------------------------------------------------------------- 1 | ../../urbit/pkg/base-dev/mar/json.hoon -------------------------------------------------------------------------------- /bare-desk/mar/mime.hoon: -------------------------------------------------------------------------------- 1 | ../../urbit/pkg/base-dev/mar/mime.hoon -------------------------------------------------------------------------------- /bare-desk/mar/noun.hoon: -------------------------------------------------------------------------------- 1 | ../../urbit/pkg/base-dev/mar/noun.hoon -------------------------------------------------------------------------------- /bare-desk/mar/tang.hoon: -------------------------------------------------------------------------------- 1 | ../../urbit/pkg/base-dev/mar/tang.hoon -------------------------------------------------------------------------------- /bare-desk/mar/txt.hoon: -------------------------------------------------------------------------------- 1 | ../../urbit/pkg/base-dev/mar/txt.hoon -------------------------------------------------------------------------------- /bare-desk/sur/verb.hoon: -------------------------------------------------------------------------------- 1 | ../../urbit/pkg/base-dev/sur/verb.hoon -------------------------------------------------------------------------------- /venter/mar/thread-done.hoon: -------------------------------------------------------------------------------- 1 | ../../bare-desk/mar/thread-done.hoon -------------------------------------------------------------------------------- /venter/mar/thread-fail.hoon: -------------------------------------------------------------------------------- 1 | ../../bare-desk/mar/thread-fail.hoon -------------------------------------------------------------------------------- /venter/ted/tube-warmer.hoon: -------------------------------------------------------------------------------- 1 | ../../bare-desk/ted/tube-warmer.hoon -------------------------------------------------------------------------------- /archive/desk/desk.bill: -------------------------------------------------------------------------------- 1 | :~ %vent-example 2 | %venter 3 | == 4 | -------------------------------------------------------------------------------- /bare-desk/lib/agentio.hoon: -------------------------------------------------------------------------------- 1 | ../../urbit/pkg/base-dev/lib/agentio.hoon -------------------------------------------------------------------------------- /bare-desk/lib/server.hoon: -------------------------------------------------------------------------------- 1 | ../../urbit/pkg/base-dev/lib/server.hoon -------------------------------------------------------------------------------- /bare-desk/lib/strand.hoon: -------------------------------------------------------------------------------- 1 | ../../urbit/pkg/base-dev/lib/strand.hoon -------------------------------------------------------------------------------- /bare-desk/mar/kelvin.hoon: -------------------------------------------------------------------------------- 1 | ../../urbit/pkg/base-dev/mar/kelvin.hoon -------------------------------------------------------------------------------- /bare-desk/sur/spider.hoon: -------------------------------------------------------------------------------- 1 | ../../urbit/pkg/base-dev/sur/spider.hoon -------------------------------------------------------------------------------- /venter/app/venter-venter.hoon: -------------------------------------------------------------------------------- 1 | ../../bare-desk/app/venter-venter.hoon -------------------------------------------------------------------------------- /venter/lib/default-agent.hoon: -------------------------------------------------------------------------------- 1 | ../../bare-desk/lib/default-agent.hoon -------------------------------------------------------------------------------- /venter/mar/vent-package.hoon: -------------------------------------------------------------------------------- 1 | ../../bare-desk/mar/vent-package.hoon -------------------------------------------------------------------------------- /venter/mar/vent-request.hoon: -------------------------------------------------------------------------------- 1 | ../../bare-desk/mar/vent-request.hoon -------------------------------------------------------------------------------- /bare-desk/lib/skeleton.hoon: -------------------------------------------------------------------------------- 1 | ../../urbit/pkg/base-dev/lib/skeleton.hoon -------------------------------------------------------------------------------- /bare-desk/lib/strandio.hoon: -------------------------------------------------------------------------------- 1 | ../../urbit/pkg/base-dev/lib/strandio.hoon -------------------------------------------------------------------------------- /venter/desk.bill: -------------------------------------------------------------------------------- 1 | :~ %venter-example 2 | %venter-venter 3 | == 4 | -------------------------------------------------------------------------------- /bare-desk/mar/thread-done.hoon: -------------------------------------------------------------------------------- 1 | ../../urbit/pkg/base-dev/mar/thread-done.hoon -------------------------------------------------------------------------------- /bare-desk/mar/thread-fail.hoon: -------------------------------------------------------------------------------- 1 | ../../urbit/pkg/base-dev/mar/thread-fail.hoon -------------------------------------------------------------------------------- /interface/src/react-app-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /bare-desk/lib/default-agent.hoon: -------------------------------------------------------------------------------- 1 | ../../urbit/pkg/base-dev/lib/default-agent.hoon -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "urbit"] 2 | path = urbit 3 | url = https://github.com/urbit/urbit.git 4 | -------------------------------------------------------------------------------- /interface/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /diagrams/images/vine.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/niblyx-malnus/venter-pattern/HEAD/diagrams/images/vine.png -------------------------------------------------------------------------------- /interface/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/niblyx-malnus/venter-pattern/HEAD/interface/public/favicon.ico -------------------------------------------------------------------------------- /interface/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/niblyx-malnus/venter-pattern/HEAD/interface/public/logo192.png -------------------------------------------------------------------------------- /interface/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/niblyx-malnus/venter-pattern/HEAD/interface/public/logo512.png -------------------------------------------------------------------------------- /diagrams/images/venter_pattern.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/niblyx-malnus/venter-pattern/HEAD/diagrams/images/venter_pattern.png -------------------------------------------------------------------------------- /diagrams/images/venter_thread.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/niblyx-malnus/venter-pattern/HEAD/diagrams/images/venter_thread.png -------------------------------------------------------------------------------- /diagrams/images/ideal_poke_forwarding.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/niblyx-malnus/venter-pattern/HEAD/diagrams/images/ideal_poke_forwarding.png -------------------------------------------------------------------------------- /diagrams/images/poke_forwarding_nack.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/niblyx-malnus/venter-pattern/HEAD/diagrams/images/poke_forwarding_nack.png -------------------------------------------------------------------------------- /diagrams/images/generate_ID_client_side.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/niblyx-malnus/venter-pattern/HEAD/diagrams/images/generate_ID_client_side.png -------------------------------------------------------------------------------- /diagrams/images/server_side_normal_sync.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/niblyx-malnus/venter-pattern/HEAD/diagrams/images/server_side_normal_sync.png -------------------------------------------------------------------------------- /diagrams/images/ideal_ID_request_response.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/niblyx-malnus/venter-pattern/HEAD/diagrams/images/ideal_ID_request_response.png -------------------------------------------------------------------------------- /archive/desk/mar/thread-done.hoon: -------------------------------------------------------------------------------- 1 | |_ res=* 2 | ++ grab 3 | |% 4 | ++ noun * 5 | -- 6 | ++ grow 7 | |% 8 | ++ noun res 9 | -- 10 | ++ grad %noun 11 | -- 12 | -------------------------------------------------------------------------------- /archive/desk/mar/thread-fail.hoon: -------------------------------------------------------------------------------- 1 | |_ err=* 2 | ++ grab 3 | |% 4 | ++ noun (pair term tang) 5 | -- 6 | ++ grow 7 | |% 8 | ++ noun err 9 | -- 10 | ++ grad %noun 11 | -- 12 | -------------------------------------------------------------------------------- /bare-desk/mar/vent-request.hoon: -------------------------------------------------------------------------------- 1 | /+ *ventio 2 | |_ req=request 3 | ++ grow 4 | |% 5 | ++ noun req 6 | -- 7 | ++ grab 8 | |% 9 | ++ noun request 10 | -- 11 | ++ grad %noun 12 | -- 13 | -------------------------------------------------------------------------------- /archive/desk/mar/vent-request.hoon: -------------------------------------------------------------------------------- 1 | /+ *ventio 2 | |_ req=request 3 | ++ grow 4 | |% 5 | ++ noun req 6 | -- 7 | ++ grab 8 | |% 9 | ++ noun request 10 | -- 11 | ++ grad %noun 12 | -- 13 | -------------------------------------------------------------------------------- /archive/desk/mar/venter/request.hoon: -------------------------------------------------------------------------------- 1 | /- *venter 2 | |_ req=request 3 | ++ grow 4 | |% 5 | ++ noun req 6 | -- 7 | ++ grab 8 | |% 9 | ++ noun request 10 | -- 11 | ++ grad %noun 12 | -- 13 | -------------------------------------------------------------------------------- /venter/delete-log.txt: -------------------------------------------------------------------------------- 1 | =============================================================================== 2 | VENTER EXAMPLE DELETE LOG 3 | =============================================================================== -------------------------------------------------------------------------------- /venter/mar/example/transition.hoon: -------------------------------------------------------------------------------- 1 | /- *example 2 | |_ tan=transition 3 | ++ grow 4 | |% 5 | ++ noun tan 6 | -- 7 | ++ grab 8 | |% 9 | ++ noun transition 10 | -- 11 | ++ grad %noun 12 | -- 13 | -------------------------------------------------------------------------------- /archive/desk/mar/venter/response.hoon: -------------------------------------------------------------------------------- 1 | /- *venter 2 | |_ rep=response 3 | ++ grow 4 | |% 5 | ++ noun rep 6 | -- 7 | ++ grab 8 | |% 9 | ++ noun response 10 | -- 11 | ++ grad %noun 12 | -- 13 | 14 | -------------------------------------------------------------------------------- /archive/desk/mar/venter/vent.hoon: -------------------------------------------------------------------------------- 1 | /+ *venter 2 | |_ =vent 3 | ++ grow 4 | |% 5 | ++ noun vent 6 | ++ json (vent:enjs vent) 7 | -- 8 | ++ grab 9 | |% 10 | ++ noun ^vent 11 | -- 12 | ++ grad %noun 13 | -- 14 | -------------------------------------------------------------------------------- /archive/desk/mar/venter/action.hoon: -------------------------------------------------------------------------------- 1 | /+ *venter 2 | |_ act=action 3 | ++ grow 4 | |% 5 | ++ noun act 6 | -- 7 | ++ grab 8 | |% 9 | ++ noun action 10 | ++ json action:dejs 11 | -- 12 | ++ grad %noun 13 | -- 14 | -------------------------------------------------------------------------------- /interface/src/setupTests.ts: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom'; 6 | -------------------------------------------------------------------------------- /archive/desk/sur/verb.hoon: -------------------------------------------------------------------------------- 1 | |% 2 | +$ event 3 | $% [%on-init ~] 4 | [%on-load ~] 5 | [%on-poke =mark] 6 | [%on-watch =path] 7 | [%on-leave =path] 8 | [%on-agent =wire sign=term] 9 | [%on-arvo =wire vane=term sign=term] 10 | [%on-fail =term] 11 | == 12 | -- -------------------------------------------------------------------------------- /interface/src/App.test.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { render, screen } from '@testing-library/react'; 3 | import App from './App'; 4 | 5 | test('renders learn react link', () => { 6 | render(); 7 | const linkElement = screen.getByText(/learn react/i); 8 | expect(linkElement).toBeInTheDocument(); 9 | }); 10 | -------------------------------------------------------------------------------- /archive/desk/sur/venter.hoon: -------------------------------------------------------------------------------- 1 | |% 2 | +$ id @uv 3 | +$ datum @t 4 | +$ vent-id (pair @p @da) 5 | +$ vent 6 | $% [%new-id =id] 7 | [%ack ~] 8 | == 9 | +$ action 10 | $% [%create-datum =@t] 11 | [%delete-datum =id] 12 | == 13 | +$ request (pair vent-id action) 14 | +$ response (pair vent-id vent) 15 | -- 16 | -------------------------------------------------------------------------------- /archive/desk/ted/venter.hoon: -------------------------------------------------------------------------------- 1 | /- spider 2 | /+ *ventio 3 | =, strand=strand:spider 4 | ^- thread:spider 5 | |= arg=vase 6 | =/ m (strand ,vase) 7 | ^- form:m 8 | =/ pak=(unit package) !<((unit package) arg) 9 | ?~ pak (strand-fail %no-arg ~) 10 | =+ u.pak :: expose dock, input, output, and body 11 | ;< =page bind:m (unpackage body input) 12 | ((vent-dyn output) dock page) 13 | -------------------------------------------------------------------------------- /venter/ted/test.hoon: -------------------------------------------------------------------------------- 1 | /- *example, spider 2 | /+ *ventio 3 | =, strand=strand:spider 4 | ^- thread:spider 5 | |= arg=vase 6 | =/ m (strand ,vase) 7 | ^- form:m 8 | =+ !<(axn=(unit action) arg) 9 | ?~ axn (strand-fail %no-arg ~) 10 | ;< our=@p bind:m get-our 11 | ;< vnt=example-vent bind:m 12 | ((vent ,example-vent) [our %venter-example] example-action+u.axn) 13 | (pure:m !>(vnt)) 14 | -------------------------------------------------------------------------------- /venter/sur/example.hoon: -------------------------------------------------------------------------------- 1 | |% 2 | +$ id @uv 3 | +$ datum @t 4 | +$ example-vent 5 | $@ ~ 6 | $% [%new-id =id] 7 | [%dlog log=@t] :: returns the current delete log 8 | == 9 | +$ transition 10 | $% [%create-datum =id =@t] 11 | [%delete-datum =id] 12 | == 13 | +$ action 14 | $% [%create-datum =@t] 15 | [%delete-datum =id] 16 | [%create-and-delete =@t] 17 | == 18 | -- 19 | -------------------------------------------------------------------------------- /interface/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /interface/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 12 | monospace; 13 | } 14 | -------------------------------------------------------------------------------- /bare-desk/mar/goof.hoon: -------------------------------------------------------------------------------- 1 | |_ guf=goof 2 | ++ grow 3 | |% 4 | ++ noun guf 5 | ++ json 6 | =/ res=(each (list ^json) tang) 7 | (mule |.((turn tang.guf tank:enjs:format))) 8 | ?- -.res 9 | %& o/(malt `(list [@t ^json])`[mote+s/mote.guf tang+a/p.res ~]) 10 | %| a+[a+[%s '[[output rendering error]]']~]~ 11 | == 12 | -- 13 | ++ grab 14 | |% 15 | ++ noun goof 16 | -- 17 | ++ grad %noun 18 | -- 19 | -------------------------------------------------------------------------------- /venter/mar/example/vent.hoon: -------------------------------------------------------------------------------- 1 | /- *example 2 | |_ vnt=example-vent 3 | ++ grow 4 | |% 5 | ++ noun vnt 6 | ++ json 7 | =, enjs:format 8 | %. vnt 9 | |= vnt=example-vent 10 | ^- ^json 11 | ?~ vnt ~ 12 | ?- -.vnt 13 | %dlog s+log.vnt 14 | %new-id s+(scot %uv id.vnt) 15 | == 16 | -- 17 | ++ grab 18 | |% 19 | ++ noun example-vent 20 | -- 21 | ++ grad %noun 22 | -- 23 | 24 | 25 | -------------------------------------------------------------------------------- /archive/desk/mar/goof.hoon: -------------------------------------------------------------------------------- 1 | |_ guf=goof 2 | ++ grow 3 | |% 4 | ++ noun guf 5 | ++ json 6 | =/ res=(each (list ^json) tang) 7 | (mule |.((turn tang.guf tank:enjs:format))) 8 | ?- -.res 9 | %& o/(malt `(list [@t ^json])`[mote+s/mote.guf tang+a/p.res ~]) 10 | %| a+[a+[%s '[[output rendering error]]']~]~ 11 | == 12 | -- 13 | ++ grab 14 | |% 15 | ++ noun goof 16 | -- 17 | ++ grad %noun 18 | -- 19 | -------------------------------------------------------------------------------- /venter/mar/example/action.hoon: -------------------------------------------------------------------------------- 1 | /- *example 2 | |_ axn=action 3 | ++ grow 4 | |% 5 | ++ noun axn 6 | -- 7 | ++ grab 8 | |% 9 | ++ noun action 10 | ++ json 11 | =, dejs:format 12 | |= jon=json 13 | ^- action 14 | %. jon 15 | %- of 16 | :~ [%create-datum (ot ~[t+so])] 17 | [%delete-datum (ot ~[id+(cu (cury slav %uv) so)])] 18 | [%create-and-delete (ot ~[t+so])] 19 | == 20 | 21 | -- 22 | ++ grad %noun 23 | -- 24 | -------------------------------------------------------------------------------- /archive/desk/lib/venter.hoon: -------------------------------------------------------------------------------- 1 | /- *venter 2 | |% 3 | ++ enjs 4 | =, enjs:format 5 | |% 6 | ++ vent 7 | |= =^vent 8 | ?- -.vent 9 | %ack s+%ack 10 | %new-id (frond %new-id s+(scot %uv id.vent)) 11 | == 12 | -- 13 | ++ dejs 14 | =, dejs:format 15 | |% 16 | ++ action 17 | ^- $-(json ^action) 18 | %- of 19 | :~ [%create-datum (ot ~[t+so])] 20 | [%delete-datum (ot ~[id+(cu (cury slav %uv) so)])] 21 | == 22 | -- 23 | -- 24 | -------------------------------------------------------------------------------- /interface/src/reportWebVitals.ts: -------------------------------------------------------------------------------- 1 | import { ReportHandler } from 'web-vitals'; 2 | 3 | const reportWebVitals = (onPerfEntry?: ReportHandler) => { 4 | if (onPerfEntry && onPerfEntry instanceof Function) { 5 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { 6 | getCLS(onPerfEntry); 7 | getFID(onPerfEntry); 8 | getFCP(onPerfEntry); 9 | getLCP(onPerfEntry); 10 | getTTFB(onPerfEntry); 11 | }); 12 | } 13 | }; 14 | 15 | export default reportWebVitals; 16 | -------------------------------------------------------------------------------- /archive/desk/mar/noun.hoon: -------------------------------------------------------------------------------- 1 | :: 2 | :::: /hoon/noun/mar 3 | :: 4 | /? 310 5 | !: 6 | :::: A minimal noun mark 7 | |_ non=* 8 | ++ grab |% 9 | ++ noun * 10 | -- 11 | ++ grow |% 12 | ++ mime [/application/x-urb-jam (as-octs:mimes:html (jam non))] 13 | -- 14 | ++ grad 15 | |% 16 | ++ form %noun 17 | ++ diff |=(* +<) 18 | ++ pact |=(* +<) 19 | ++ join |=([* *] *(unit *)) 20 | ++ mash |=([[ship desk *] [ship desk *]] `*`~|(%noun-mash !!)) 21 | -- 22 | -- 23 | -------------------------------------------------------------------------------- /bare-desk/mar/vent-package.hoon: -------------------------------------------------------------------------------- 1 | /+ *ventio 2 | |_ pak=package 3 | ++ grow 4 | |% 5 | ++ noun pak 6 | -- 7 | ++ grab 8 | |% 9 | ++ noun package 10 | ++ json 11 | =, dejs:format 12 | |^ ^- $-(json package) 13 | %- ot 14 | :~ [%dock (ot ~[ship+(su fed:ag) dude+san])] 15 | [%input (ot ~[desk+san mark+san])] 16 | [%output (ot ~[desk+san mark+san])] 17 | [%body same] 18 | == 19 | ++ san (cu |=(=@t ?>(((sane %tas) t) t)) so) 20 | -- 21 | -- 22 | ++ grad %noun 23 | -- 24 | -------------------------------------------------------------------------------- /archive/desk/mar/vent-package.hoon: -------------------------------------------------------------------------------- 1 | /+ *ventio 2 | |_ pak=package 3 | ++ grow 4 | |% 5 | ++ noun pak 6 | -- 7 | ++ grab 8 | |% 9 | ++ noun package 10 | ++ json 11 | =, dejs:format 12 | |^ ^- $-(json package) 13 | %- ot 14 | :~ [%dock (ot ~[ship+(su fed:ag) dude+san])] 15 | [%input (ot ~[desk+san mark+san])] 16 | [%output (ot ~[desk+san mark+san])] 17 | [%body same] 18 | == 19 | ++ san (cu |=(=@t ?>(((sane %tas) t) t)) so) 20 | -- 21 | -- 22 | ++ grad %noun 23 | -- 24 | -------------------------------------------------------------------------------- /interface/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /archive/desk/sur/spider.hoon: -------------------------------------------------------------------------------- 1 | /+ libstrand=strand 2 | =, strand=strand:libstrand 3 | |% 4 | +$ thread $-(vase shed:khan) 5 | +$ input [=tid =cage] 6 | +$ tid tid:strand 7 | +$ bowl bowl:strand 8 | +$ http-error 9 | $? %bad-request :: 400 10 | %forbidden :: 403 11 | %nonexistent :: 404 12 | %offline :: 504 13 | == 14 | +$ start-args 15 | $: parent=(unit tid) 16 | use=(unit tid) 17 | =beak 18 | file=term 19 | =vase 20 | == 21 | +$ inline-args 22 | $: parent=(unit tid) 23 | use=(unit tid) 24 | =beak 25 | =shed:khan 26 | == 27 | -- 28 | -------------------------------------------------------------------------------- /interface/src/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom/client'; 3 | import './index.css'; 4 | import App from './App'; 5 | import reportWebVitals from './reportWebVitals'; 6 | 7 | const root = ReactDOM.createRoot( 8 | document.getElementById('root') as HTMLElement 9 | ); 10 | root.render( 11 | 12 | 13 | 14 | ); 15 | 16 | // If you want to start measuring performance in your app, pass a function 17 | // to log results (for example: reportWebVitals(console.log)) 18 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 19 | reportWebVitals(); 20 | -------------------------------------------------------------------------------- /interface/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": [ 5 | "dom", 6 | "dom.iterable", 7 | "esnext" 8 | ], 9 | "allowJs": true, 10 | "skipLibCheck": true, 11 | "esModuleInterop": true, 12 | "allowSyntheticDefaultImports": true, 13 | "strict": true, 14 | "forceConsistentCasingInFileNames": true, 15 | "noFallthroughCasesInSwitch": true, 16 | "module": "esnext", 17 | "moduleResolution": "node", 18 | "resolveJsonModule": true, 19 | "isolatedModules": true, 20 | "noEmit": true, 21 | "jsx": "react-jsx" 22 | }, 23 | "include": [ 24 | "src" 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /archive/desk/mar/kelvin.hoon: -------------------------------------------------------------------------------- 1 | |_ kal=waft:clay 2 | ++ grow 3 | |% 4 | ++ mime `^mime`[/text/x-kelvin (as-octs:mimes:html hoon)] 5 | ++ noun kal 6 | ++ hoon 7 | %+ rap 3 8 | %+ turn 9 | %+ sort 10 | ~(tap in (waft-to-wefts:clay kal)) 11 | |= [a=weft b=weft] 12 | ?: =(lal.a lal.b) 13 | (gte num.a num.b) 14 | (gte lal.a lal.b) 15 | |= =weft 16 | (rap 3 '[%' (scot %tas lal.weft) ' ' (scot %ud num.weft) ']\0a' ~) 17 | :: 18 | ++ txt (to-wain:format hoon) 19 | -- 20 | ++ grab 21 | |% 22 | ++ noun waft:clay 23 | ++ mime 24 | |= [=mite len=@ud tex=@] 25 | (cord-to-waft:clay tex) 26 | -- 27 | ++ grad %noun 28 | -- 29 | -------------------------------------------------------------------------------- /archive/desk/mar/json.hoon: -------------------------------------------------------------------------------- 1 | :: 2 | :::: /hoon/json/mar 3 | :: 4 | /? 310 5 | :: 6 | :::: compute 7 | :: 8 | =, eyre 9 | =, format 10 | =, html 11 | |_ jon=^json 12 | :: 13 | ++ grow :: convert to 14 | |% 15 | ++ mime [/application/json (as-octs:mimes -:txt)] :: convert to %mime 16 | ++ txt [(en:json jon)]~ 17 | -- 18 | ++ grab 19 | |% :: convert from 20 | ++ mime |=([p=mite q=octs] (fall (de:json (@t q.q)) *^json)) 21 | ++ noun ^json :: clam from %noun 22 | ++ numb numb:enjs 23 | ++ time time:enjs 24 | -- 25 | ++ grad %mime 26 | -- 27 | -------------------------------------------------------------------------------- /archive/desk/mar/mime.hoon: -------------------------------------------------------------------------------- 1 | :: 2 | :::: /hoon/mime/mar 3 | :: 4 | /? 310 5 | :: 6 | |_ own=mime 7 | ++ grow 8 | ^? 9 | |% 10 | ++ jam `@`q.q.own 11 | -- 12 | :: 13 | ++ grab :: convert from 14 | ^? 15 | |% 16 | ++ noun mime :: clam from %noun 17 | ++ tape 18 | |=(a=_"" [/application/x-urb-unknown (as-octt:mimes:html a)]) 19 | -- 20 | ++ grad 21 | ^? 22 | |% 23 | ++ form %mime 24 | ++ diff |=(mime +<) 25 | ++ pact |=(mime +<) 26 | ++ join |=([mime mime] `(unit mime)`~) 27 | ++ mash 28 | |= [[ship desk mime] [ship desk mime]] 29 | ^- mime 30 | ~|(%mime-mash !!) 31 | -- 32 | -- 33 | -------------------------------------------------------------------------------- /interface/src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | height: 40vmin; 7 | pointer-events: none; 8 | } 9 | 10 | @media (prefers-reduced-motion: no-preference) { 11 | .App-logo { 12 | animation: App-logo-spin infinite 20s linear; 13 | } 14 | } 15 | 16 | .App-header { 17 | background-color: #282c34; 18 | min-height: 100vh; 19 | display: flex; 20 | flex-direction: column; 21 | align-items: center; 22 | justify-content: center; 23 | font-size: calc(10px + 2vmin); 24 | color: white; 25 | } 26 | 27 | .App-link { 28 | color: #61dafb; 29 | } 30 | 31 | @keyframes App-logo-spin { 32 | from { 33 | transform: rotate(0deg); 34 | } 35 | to { 36 | transform: rotate(360deg); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /archive/desk/mar/tang.hoon: -------------------------------------------------------------------------------- 1 | :: 2 | :::: /hoon/tang/mar 3 | :: 4 | /? 310 5 | :: 6 | =, format 7 | |_ tan=(list tank) 8 | ++ grad %noun 9 | ++ grow 10 | |% 11 | ++ noun tan 12 | ++ json 13 | =/ result=(each (list ^json) tang) 14 | (mule |.((turn tan tank:enjs:format))) 15 | ?- -.result 16 | %& a+p.result 17 | %| a+[a+[%s '[[output rendering error]]']~]~ 18 | == 19 | :: 20 | ++ elem 21 | =- ;pre:code:"{(of-wall -)}" 22 | ^- wall %- zing ^- (list wall) 23 | (turn (flop tan) |=(a=tank (wash 0^160 a))) 24 | -- 25 | ++ grab :: convert from 26 | |% 27 | ++ noun (list ^tank) :: clam from %noun 28 | ++ tank |=(a=^tank [a]~) 29 | -- 30 | -- 31 | -------------------------------------------------------------------------------- /archive/desk/mar/bill.hoon: -------------------------------------------------------------------------------- 1 | |_ bil=(list dude:gall) 2 | ++ grow 3 | |% 4 | ++ mime `^mime`[/text/x-bill (as-octs:mimes:html hoon)] 5 | ++ noun bil 6 | ++ hoon 7 | ^- @t 8 | |^ (crip (of-wall:format (wrap-lines (spit-duz bil)))) 9 | :: 10 | ++ wrap-lines 11 | |= taz=wall 12 | ^- wall 13 | ?~ taz ["~"]~ 14 | :- (weld ":~ " i.taz) 15 | %- snoc :_ "==" 16 | (turn t.taz |=(t=tape (weld " " t))) 17 | :: 18 | ++ spit-duz 19 | |= duz=(list dude:gall) 20 | ^- wall 21 | (turn duz |=(=dude:gall ['%' (trip dude)])) 22 | -- 23 | ++ txt (to-wain:format hoon) 24 | -- 25 | ++ grab 26 | |% 27 | ++ noun (list dude:gall) 28 | ++ mime 29 | |= [=mite len=@ud tex=@] 30 | ~_ tex 31 | !<((list dude:gall) (slap !>(~) (ream tex))) 32 | -- 33 | ++ grad %noun 34 | -- 35 | -------------------------------------------------------------------------------- /archive/desk/lib/skeleton.hoon: -------------------------------------------------------------------------------- 1 | :: Similar to default-agent except crashes everywhere 2 | ^- agent:gall 3 | |_ bowl:gall 4 | ++ on-init 5 | ^- (quip card:agent:gall agent:gall) 6 | !! 7 | :: 8 | ++ on-save 9 | ^- vase 10 | !! 11 | :: 12 | ++ on-load 13 | |~ old-state=vase 14 | ^- (quip card:agent:gall agent:gall) 15 | !! 16 | :: 17 | ++ on-poke 18 | |~ in-poke-data=cage 19 | ^- (quip card:agent:gall agent:gall) 20 | !! 21 | :: 22 | ++ on-watch 23 | |~ path 24 | ^- (quip card:agent:gall agent:gall) 25 | !! 26 | :: 27 | ++ on-leave 28 | |~ path 29 | ^- (quip card:agent:gall agent:gall) 30 | !! 31 | :: 32 | ++ on-peek 33 | |~ path 34 | ^- (unit (unit cage)) 35 | !! 36 | :: 37 | ++ on-agent 38 | |~ [wire sign:agent:gall] 39 | ^- (quip card:agent:gall agent:gall) 40 | !! 41 | :: 42 | ++ on-arvo 43 | |~ [wire =sign-arvo] 44 | ^- (quip card:agent:gall agent:gall) 45 | !! 46 | :: 47 | ++ on-fail 48 | |~ [term tang] 49 | ^- (quip card:agent:gall agent:gall) 50 | !! 51 | -- 52 | -------------------------------------------------------------------------------- /interface/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "venter", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^5.17.0", 7 | "@testing-library/react": "^13.4.0", 8 | "@testing-library/user-event": "^13.5.0", 9 | "@types/jest": "^27.5.2", 10 | "@types/node": "^16.18.66", 11 | "@types/react": "^18.2.39", 12 | "@types/react-dom": "^18.2.17", 13 | "@urbit/http-api": "^2.3.0", 14 | "lodash": "^4.17.21", 15 | "react": "^18.2.0", 16 | "react-dom": "^18.2.0", 17 | "react-scripts": "5.0.1", 18 | "typescript": "^4.9.5", 19 | "web-vitals": "^2.1.4" 20 | }, 21 | "scripts": { 22 | "start": "react-scripts start", 23 | "build": "react-scripts build", 24 | "test": "react-scripts test", 25 | "eject": "react-scripts eject" 26 | }, 27 | "eslintConfig": { 28 | "extends": [ 29 | "react-app", 30 | "react-app/jest" 31 | ] 32 | }, 33 | "browserslist": { 34 | "production": [ 35 | ">0.2%", 36 | "not dead", 37 | "not op_mini all" 38 | ], 39 | "development": [ 40 | "last 1 chrome version", 41 | "last 1 firefox version", 42 | "last 1 safari version" 43 | ] 44 | }, 45 | "devDependencies": { 46 | "@types/lodash": "^4.14.202" 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /archive/desk/app/venter.hoon: -------------------------------------------------------------------------------- 1 | /+ vio=ventio, dbug, verb, default-agent 2 | :: There's no way around this. Threads can't do state. 3 | :: The venter needs STATE in order to enforce uniqueness on its vent-ids. 4 | :: 5 | |% 6 | +$ state-0 [%0 =vents:vio] 7 | +$ card card:agent:gall 8 | +$ vent-id vent-id:vio 9 | -- 10 | %- agent:dbug 11 | %+ verb | 12 | =| state-0 13 | =* state - 14 | ^- agent:gall 15 | |_ =bowl:gall 16 | +* this . 17 | def ~(. (default-agent this %|) bowl) 18 | ++ on-init 19 | ^- (quip card _this) 20 | `this 21 | :: 22 | ++ on-save !>(state) 23 | :: 24 | ++ on-load 25 | |= ole=vase 26 | ^- (quip card _this) 27 | =/ old=state-0 !<(state-0 ole) 28 | =. state old 29 | `this 30 | :: 31 | ++ on-poke 32 | |= [=mark =vase] 33 | ^- (quip card _this) 34 | ?> =(src our):bowl 35 | ?+ mark (on-poke:def mark vase) 36 | %tally-vent 37 | ~& %tallying 38 | =+ !<([=dock vid=vent-id] vase) 39 | `this(vents (~(put ju vents) dock vid)) 40 | :: 41 | %clear-vent 42 | ~& %clearing 43 | =+ !<([=dock vid=vent-id] vase) 44 | `this(vents (~(del ju vents) dock vid)) 45 | == 46 | :: 47 | ++ on-watch on-watch:def 48 | ++ on-leave on-leave:def 49 | :: 50 | ++ on-peek 51 | |= =(pole knot) 52 | ^- (unit (unit cage)) 53 | ?+ pole (on-peek:def pole) 54 | [%x %vents ~] ``noun+!>(vents) 55 | == 56 | :: 57 | ++ on-agent on-agent:def 58 | ++ on-arvo on-arvo:def 59 | ++ on-fail on-fail:def 60 | -- 61 | -------------------------------------------------------------------------------- /archive/desk/lib/default-agent.hoon: -------------------------------------------------------------------------------- 1 | /+ skeleton 2 | |* [agent=* help=*] 3 | ?: ?=(%& help) 4 | ~| %default-agent-helpfully-crashing 5 | skeleton 6 | |_ =bowl:gall 7 | ++ on-init 8 | `agent 9 | :: 10 | ++ on-save 11 | !>(~) 12 | :: 13 | ++ on-load 14 | |= old-state=vase 15 | `agent 16 | :: 17 | ++ on-poke 18 | |= =cage 19 | ~| "unexpected poke to {} with mark {}" 20 | !! 21 | :: 22 | ++ on-watch 23 | |= =path 24 | ~| "unexpected subscription to {} on path {}" 25 | !! 26 | :: 27 | ++ on-leave 28 | |= path 29 | `agent 30 | :: 31 | ++ on-peek 32 | |= =path 33 | ~| "unexpected scry into {} on path {}" 34 | !! 35 | :: 36 | ++ on-agent 37 | |= [=wire =sign:agent:gall] 38 | ^- (quip card:agent:gall _agent) 39 | ?- -.sign 40 | %poke-ack 41 | ?~ p.sign 42 | `agent 43 | %- (slog leaf+"poke failed from {} on wire {}" u.p.sign) 44 | `agent 45 | :: 46 | %watch-ack 47 | ?~ p.sign 48 | `agent 49 | =/ =tank leaf+"subscribe failed from {} on wire {}" 50 | %- (slog tank u.p.sign) 51 | `agent 52 | :: 53 | %kick `agent 54 | %fact 55 | ~| "unexpected subscription update to {} on wire {}" 56 | ~| "with mark {}" 57 | !! 58 | == 59 | :: 60 | ++ on-arvo 61 | |= [=wire =sign-arvo] 62 | ~| "unexpected system response {<-.sign-arvo>} to {} on wire {}" 63 | !! 64 | :: 65 | ++ on-fail 66 | |= [=term =tang] 67 | %- (slog leaf+"error in {}" >term< tang) 68 | `agent 69 | -- 70 | -------------------------------------------------------------------------------- /archive/desk/mar/hoon.hoon: -------------------------------------------------------------------------------- 1 | :::: /hoon/hoon/mar 2 | :: 3 | /? 310 4 | :: 5 | =, eyre 6 | |_ own=@t 7 | :: 8 | ++ grow :: convert to 9 | |% 10 | ++ mime `^mime`[/text/x-hoon (as-octs:mimes:html own)] :: convert to %mime 11 | ++ elem :: convert to %html 12 | ;div:pre(urb_codemirror "", mode "hoon"):"{(trip own)}" 13 | :: =+ gen-id="src-{<`@ui`(mug own)>}" 14 | :: ;div 15 | :: ;textarea(id "{gen-id}"):"{(trip own)}" 16 | :: ;script:""" 17 | :: CodeMirror.fromTextArea( 18 | :: window[{}], 19 | :: \{lineNumbers:true, readOnly:true} 20 | :: ) 21 | :: """ 22 | :: == 23 | ++ hymn 24 | :: ;html:(head:title:"Source" "+{elem}") 25 | ;html 26 | ;head 27 | ;title:"Source" 28 | ;script@"//cdnjs.cloudflare.com/ajax/libs/codemirror/4.3.0/codemirror.js"; 29 | ;script@"/lib/syntax/hoon.js"; 30 | ;link(rel "stylesheet", href "//cdnjs.cloudflare.com/ajax/libs/". 31 | "codemirror/4.3.0/codemirror.min.css"); 32 | ;link/"/lib/syntax/codemirror.css"(rel "stylesheet"); 33 | == 34 | ;body 35 | ;textarea#src:"{(trip own)}" 36 | ;script:'CodeMirror.fromTextArea(src, {lineNumbers:true, readOnly:true})' 37 | == 38 | == 39 | ++ txt 40 | (to-wain:format own) 41 | -- 42 | ++ grab 43 | |% :: convert from 44 | ++ mime |=([p=mite q=octs] q.q) 45 | ++ noun @t :: clam from %noun 46 | ++ txt of-wain:format 47 | -- 48 | ++ grad %txt 49 | -- 50 | -------------------------------------------------------------------------------- /venter/app/venter-example.hoon: -------------------------------------------------------------------------------- 1 | /- *example 2 | /+ vent, bout, dbug, verb, default-agent 3 | /= x /ted/vines/venter-example 4 | /= x /ted/test 5 | /= x /mar/example/transition 6 | /= x /mar/example/action 7 | /= x /mar/example/vent 8 | |% 9 | +$ state-0 [%0 data=(map id datum)] 10 | +$ card card:agent:gall 11 | -- 12 | =| state-0 13 | =* state - 14 | :: apply the venter agent transformer 15 | :: 16 | :: %- agent:bout 17 | %- agent:vent 18 | %- agent:dbug 19 | %+ verb | 20 | ^- agent:gall 21 | |_ =bowl:gall 22 | +* this . 23 | def ~(. (default-agent this %|) bowl) 24 | :: use the venter utils to redirect raw pokes to vents 25 | :: 26 | vnt ~(. (utils:vent this) bowl) 27 | :: 28 | ++ on-init 29 | ^- (quip card _this) 30 | `this 31 | :: 32 | ++ on-save !>(state) 33 | :: 34 | ++ on-load 35 | |= ole=vase 36 | ^- (quip card _this) 37 | =/ old=state-0 !<(state-0 ole) 38 | =. state old 39 | `this 40 | :: 41 | ++ on-poke 42 | |= [=mark =vase] 43 | ^- (quip card _this) 44 | ?+ mark (on-poke:def mark vase) 45 | %example-action (poke-to-vent:vnt mark vase) 46 | :: 47 | %example-transition 48 | ?> =(src our):bowl 49 | =+ !<(tan=transition vase) 50 | ?- -.tan 51 | %delete-datum `this(data (~(del by data) id.tan)) 52 | %create-datum `this(data (~(put by data) [id t]:tan)) 53 | == 54 | == 55 | :: 56 | ++ on-peek 57 | |= =(pole knot) 58 | ^- (unit (unit cage)) 59 | ?+ pole (on-peek:def pole) 60 | [%x %data ~] ``noun+!>(data) 61 | == 62 | :: 63 | ++ on-watch on-watch:def 64 | ++ on-leave on-leave:def 65 | ++ on-agent on-agent:def 66 | ++ on-arvo on-arvo:def 67 | ++ on-fail on-fail:def 68 | -- 69 | -------------------------------------------------------------------------------- /venter/lib/bout.hoon: -------------------------------------------------------------------------------- 1 | |% 2 | ++ agent 3 | |= =agent:gall 4 | ^- agent:gall 5 | !. 6 | |_ =bowl:gall 7 | +* this . 8 | ag ~(. agent bowl) 9 | :: 10 | ++ on-poke 11 | |= [=mark =vase] 12 | ~> %bout.[0 (cat 3 dap.bowl ' +on-poke')] 13 | =^ cards agent (on-poke:ag mark vase) 14 | [cards this] 15 | :: 16 | ++ on-peek 17 | |= =path 18 | ~> %bout.[0 (cat 3 dap.bowl ' +on-peek')] 19 | (on-peek:ag path) 20 | :: 21 | ++ on-init 22 | ~> %bout.[0 (cat 3 dap.bowl ' +on-init')] 23 | =^ cards agent on-init:ag 24 | [cards this] 25 | :: 26 | ++ on-save ~>(%bout.[0 (cat 3 dap.bowl ' +on-save')] on-save:ag) 27 | :: 28 | ++ on-load 29 | |= old-state=vase 30 | ~> %bout.[0 (cat 3 dap.bowl ' +on-load')] 31 | =^ cards agent (on-load:ag old-state) 32 | [cards this] 33 | :: 34 | ++ on-watch 35 | |= =path 36 | ~> %bout.[0 (cat 3 dap.bowl ' +on-watch')] 37 | =^ cards agent (on-watch:ag path) 38 | [cards this] 39 | :: 40 | ++ on-leave 41 | |= =path 42 | ~> %bout.[0 (cat 3 dap.bowl ' +on-leave')] 43 | =^ cards agent (on-leave:ag path) 44 | [cards this] 45 | :: 46 | ++ on-agent 47 | |= [=wire =sign:agent:gall] 48 | ~> %bout.[0 (cat 3 dap.bowl ' +on-agent')] 49 | =^ cards agent (on-agent:ag wire sign) 50 | [cards this] 51 | :: 52 | ++ on-arvo 53 | |= [=wire =sign-arvo] 54 | ~> %bout.[0 (cat 3 dap.bowl ' +on-arvo')] 55 | =^ cards agent (on-arvo:ag wire sign-arvo) 56 | [cards this] 57 | :: 58 | ++ on-fail 59 | |= [=term =tang] 60 | ~> %bout.[0 (cat 3 dap.bowl ' +on-fail')] 61 | =^ cards agent (on-fail:ag term tang) 62 | [cards this] 63 | -- 64 | -- 65 | -------------------------------------------------------------------------------- /interface/src/App.tsx: -------------------------------------------------------------------------------- 1 | import React, { useState } from 'react'; 2 | import api from './api'; 3 | 4 | function App() { 5 | const [createInput, setCreateInput] = useState(''); 6 | const [deleteInput, setDeleteInput] = useState(''); 7 | const [createDeleteInput, setCreateDeleteInput] = useState(''); 8 | const [result, setResult] = useState(''); 9 | 10 | const handleCreate = async () => { 11 | setResult(await api.createDatum(createInput)); 12 | }; 13 | 14 | const handleDelete = async () => { 15 | setResult(await api.deleteDatum(deleteInput)); 16 | }; 17 | 18 | const handleCreateAndDelete = async () => { 19 | setResult(await api.createAndDelete(createDeleteInput)); 20 | }; 21 | 22 | return ( 23 |
24 |
25 | setCreateInput(e.target.value)} 29 | placeholder="Enter some text" 30 | /> 31 | 32 |
33 |
34 | setDeleteInput(e.target.value)} 38 | placeholder="Enter a datum ID" 39 | /> 40 | 41 |
42 |
43 | setCreateDeleteInput(e.target.value)} 47 | placeholder="Enter some text" 48 | /> 49 | 50 |
51 |
52 |

API Result:

53 |
{result}
54 |
55 |
56 | ); 57 | } 58 | 59 | export default App; -------------------------------------------------------------------------------- /bare-desk/lib/bout.hoon: -------------------------------------------------------------------------------- 1 | :: bout: agent wrapper for printing profiling information 2 | :: 3 | :: usage: %-(agent:bout your-agent) 4 | :: 5 | |% 6 | ++ agent 7 | |= =agent:gall 8 | ^- agent:gall 9 | !. 10 | |_ =bowl:gall 11 | +* this . 12 | ag ~(. agent bowl) 13 | :: 14 | ++ on-poke 15 | |= [=mark =vase] 16 | ~> %bout.[0 (cat 3 dap.bowl ' +on-poke')] 17 | =^ cards agent (on-poke:ag mark vase) 18 | [cards this] 19 | :: 20 | ++ on-peek 21 | |= =path 22 | ~> %bout.[0 (cat 3 dap.bowl ' +on-peek')] 23 | (on-peek:ag path) 24 | :: 25 | ++ on-init 26 | ~> %bout.[0 (cat 3 dap.bowl ' +on-init')] 27 | =^ cards agent on-init:ag 28 | [cards this] 29 | :: 30 | ++ on-save ~>(%bout.[0 (cat 3 dap.bowl ' +on-save')] on-save:ag) 31 | :: 32 | ++ on-load 33 | |= old-state=vase 34 | ~> %bout.[0 (cat 3 dap.bowl ' +on-load')] 35 | =^ cards agent (on-load:ag old-state) 36 | [cards this] 37 | :: 38 | ++ on-watch 39 | |= =path 40 | ~> %bout.[0 (cat 3 dap.bowl ' +on-watch')] 41 | =^ cards agent (on-watch:ag path) 42 | [cards this] 43 | :: 44 | ++ on-leave 45 | |= =path 46 | ~> %bout.[0 (cat 3 dap.bowl ' +on-leave')] 47 | =^ cards agent (on-leave:ag path) 48 | [cards this] 49 | :: 50 | ++ on-agent 51 | |= [=wire =sign:agent:gall] 52 | ~> %bout.[0 (cat 3 dap.bowl ' +on-agent')] 53 | =^ cards agent (on-agent:ag wire sign) 54 | [cards this] 55 | :: 56 | ++ on-arvo 57 | |= [=wire =sign-arvo] 58 | ~> %bout.[0 (cat 3 dap.bowl ' +on-arvo')] 59 | =^ cards agent (on-arvo:ag wire sign-arvo) 60 | [cards this] 61 | :: 62 | ++ on-fail 63 | |= [=term =tang] 64 | ~> %bout.[0 (cat 3 dap.bowl ' +on-fail')] 65 | =^ cards agent (on-fail:ag term tang) 66 | [cards this] 67 | -- 68 | -- 69 | -------------------------------------------------------------------------------- /interface/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /interface/README.md: -------------------------------------------------------------------------------- 1 | # Getting Started with Create React App 2 | 3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 4 | 5 | ## Available Scripts 6 | 7 | In the project directory, you can run: 8 | 9 | ### `npm start` 10 | 11 | Runs the app in the development mode.\ 12 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 13 | 14 | The page will reload if you make edits.\ 15 | You will also see any lint errors in the console. 16 | 17 | ### `npm test` 18 | 19 | Launches the test runner in the interactive watch mode.\ 20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 21 | 22 | ### `npm run build` 23 | 24 | Builds the app for production to the `build` folder.\ 25 | It correctly bundles React in production mode and optimizes the build for the best performance. 26 | 27 | The build is minified and the filenames include the hashes.\ 28 | Your app is ready to be deployed! 29 | 30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 31 | 32 | ### `npm run eject` 33 | 34 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 35 | 36 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 37 | 38 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. 39 | 40 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. 41 | 42 | ## Learn More 43 | 44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 45 | 46 | To learn React, check out the [React documentation](https://reactjs.org/). 47 | -------------------------------------------------------------------------------- /interface/src/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /archive/desk/app/vent-example.hoon: -------------------------------------------------------------------------------- 1 | /- *venter 2 | /+ vio=ventio, dbug, verb, default-agent 3 | |% 4 | +$ state-0 [%0 data=(map id datum)] 5 | +$ card card:agent:gall 6 | -- 7 | =| state-0 8 | =* state - 9 | %- agent:dbug 10 | %+ verb | 11 | ^- agent:gall 12 | |_ =bowl:gall 13 | +* this . 14 | def ~(. (default-agent this %|) bowl) 15 | ++ on-init 16 | ^- (quip card _this) 17 | `this 18 | ++ on-save !>(state) 19 | :: 20 | ++ on-load 21 | |= ole=vase 22 | ^- (quip card _this) 23 | =/ old=state-0 !<(state-0 ole) 24 | =. state old 25 | `this 26 | :: 27 | ++ on-poke 28 | |= [=mark =vase] 29 | ^- (quip card _this) 30 | ?+ mark (on-poke:def mark vase) 31 | %venter-action 32 | :: unwrapped actions are re-interpreted as requests 33 | :: 34 | =/ =request [[our now]:bowl !<(action vase)] 35 | =/ =cage venter-request+!>(request) 36 | :_(this [%pass / %agent [our dap]:bowl %poke cage]~) 37 | :: 38 | %venter-request 39 | |^ 40 | ?> =(src our):bowl 41 | =/ [vid=vent-id axn=action] !<(request vase) 42 | :: handle request, then kick the vent subscription 43 | :: 44 | =^ cards state (handle-request vid axn) 45 | =/ kick=card [%give %kick ~[(en-path:vio vid)] ~] 46 | :_(this (welp cards [kick]~)) 47 | :: process the request and optionally send a vent update 48 | :: 49 | ++ handle-request 50 | |= [vid=vent-id axn=action] 51 | ?- -.axn 52 | %delete-datum `state(data (~(del by data) id.axn)) 53 | :: 54 | %create-datum 55 | =/ =id (sham eny.bowl) 56 | :_ state(data (~(put by data) id t.axn)) 57 | [%give %fact ~[(en-path:vio vid)] venter-vent+!>([%new-id id])]~ 58 | == 59 | -- 60 | :: 61 | %venter-response 62 | :: If you want to delegate the responsibilities of a poke 63 | :: out to a thread, the thread can poke back in with a 64 | :: %venter-response to send a vent along the appropriate 65 | :: vent-id path. 66 | :: 67 | ?> =(src our):bowl 68 | =/ [vid=vent-id =vent] !<(response vase) 69 | :_ this 70 | :~ [%give %fact ~[(en-path:vio vid)] venter-vent+!>(vent)] 71 | [%give %kick ~[(en-path:vio vid)] ~] 72 | == 73 | == 74 | :: 75 | ++ on-watch 76 | |= =(pole knot) 77 | ^- (quip card _this) 78 | ?+ pole (on-watch:def pole) 79 | [%vent p=@ q=@ ~] 80 | ?> =(src.bowl (slav %p p.pole)) 81 | `this 82 | == 83 | 84 | ++ on-leave on-leave:def 85 | ++ on-peek on-peek:def 86 | ++ on-agent on-agent:def 87 | ++ on-arvo on-arvo:def 88 | ++ on-fail on-fail:def 89 | -- 90 | -------------------------------------------------------------------------------- /interface/src/api.ts: -------------------------------------------------------------------------------- 1 | import memoize from "lodash/memoize"; 2 | import Urbit from "@urbit/http-api"; 3 | 4 | const ship = "tomsug-nalwet-niblyx-malnus"; 5 | 6 | const api = { 7 | createApi: memoize(() => { 8 | const urb = new Urbit("http://localhost:8080", ""); 9 | urb.ship = ship; 10 | urb.onError = (message) => console.log("onError: " + message); 11 | urb.onOpen = () => console.log("urbit onOpen"); 12 | urb.onRetry = () => console.log("urbit onRetry"); 13 | urb.connect(); 14 | return urb; 15 | }), 16 | scry: async (app: string, path: string) => { 17 | return api.createApi().scry({ app: app, path: path}); 18 | }, 19 | poke: async (app: string, mark: string, json: any) => { 20 | try { 21 | return api.createApi().poke({ 22 | app: app, 23 | mark: mark, 24 | json: json, 25 | }); 26 | } catch (e) { 27 | console.log("poke error"); 28 | } 29 | }, 30 | vent: async (vnt: any, desk: string) => { 31 | const result: any = await api.createApi().thread({ 32 | inputMark: 'vent-package', // input to thread, contains poke 33 | outputMark: 'json', 34 | threadName: 'venter', 35 | body: { 36 | dock: { 37 | ship: vnt.ship, 38 | dude: vnt.dude, 39 | }, 40 | input: { 41 | desk: vnt.inputDesk, 42 | mark: vnt.inputMark, // mark of the poke itself 43 | }, 44 | output: { 45 | desk: vnt.outputDesk, 46 | mark: vnt.outputMark, 47 | }, 48 | body: vnt.body, 49 | }, 50 | desk: desk, 51 | }); 52 | if ( 53 | result !== null && 54 | result.term && 55 | result.tang && 56 | Array.isArray(result.tang) 57 | ) { 58 | throw new Error(`\n${result.term}\n${result.tang.join('\n')}`); 59 | } else { 60 | return result; 61 | } 62 | }, 63 | exampleAction: async (json: any) => { 64 | return await api.vent({ 65 | ship: ship, // the ship to poke 66 | dude: 'venter-example', // the agent to poke 67 | inputDesk: 'venter', // where does the input mark live 68 | inputMark: 'example-action', // name of input mark 69 | outputDesk: 'venter', // where does the output mark live 70 | outputMark: 'example-vent', // name of output mark 71 | body: json, // the actual poke content 72 | }, 'venter'); 73 | }, 74 | createDatum: async (t: string) => { 75 | const json = { "create-datum": { t: t } }; 76 | return await api.exampleAction(json); 77 | }, 78 | deleteDatum: async (id: string) => { 79 | const json = { "delete-datum": { id: id } }; 80 | return await api.exampleAction(json); 81 | }, 82 | createAndDelete: async (t: string) => { 83 | const json = { "create-and-delete": { t: t } }; 84 | return await api.exampleAction(json); 85 | }, 86 | } 87 | 88 | export default api; -------------------------------------------------------------------------------- /archive/README.md: -------------------------------------------------------------------------------- 1 | # the "venter" pattern 2 | 3 | Use this pattern to get an immediate response from a poke. 4 | 5 | ## The Fundamental Pattern 6 | 1. Accept a vent-id as well as an action in on-poke. 7 | 2. Make a vent subscription path available in on-watch. 8 | 3. In on-poke, process the action and send a vent update along this path. 9 | 4. From the frontend, pass an action to a venter thread specialized to get a poke response. 10 | 5. The thread creates a vent-id. 11 | 6. The thread follows the subscription path of that vent-id. 12 | 7. The thread pokes the agent with the vent-id and action. 13 | 8. The thread awaits a single fact and/or a single kick from that path and returns the results. 14 | 15 | ## Important Files 16 | - `/app/venter.hoon` 17 | - `/ted/venter.hoon` 18 | - `/lib/ventio.hoon` 19 | - `/sur/venter.hoon` 20 | 21 | ## Installation 22 | 1. Clone this repo. 23 | 2. Boot up a ship (fakezod or moon or whatever you use). 24 | 4. `|new-desk %venter` to create a new desk called `%venter`. 25 | 5. `|mount %venter` to access the `%venter` desk from the unix command line. 26 | 6. At the unix command line `rm -rf [ship-name]/venter/*` to empty out the contents of the desk. 27 | 7. `cp -r venter/* [ship-name]/venter` to copy the contents of this repo into your new desk. 28 | 8. At the dojo command line `|commit %venter`. 29 | 9. Install with `|install our %venter`. 30 | 31 | ## Test it Out 32 | 1. Enter `-venter!venter [%create-datum 'hello!']` in the dojo. 33 | 34 | You should get a response like: `vent=[%new-id id=0v6.4mje9.todhv.940lu.p1k2d.hqcco]` 35 | 36 | 3. Check the state of the agent with `:venter +dbug` 37 | 38 | You should see: 39 | 40 | `[%0 data=[n=[p=0v6.4mje9.todhv.940lu.p1k2d.hqcco q='hello!'] l=~ r=~]]` 41 | 42 | 4. Now, using the `id` you received in step 2, try: 43 | 44 | `-venter!venter [%delete-datum 0v6.4mje9.todhv.940lu.p1k2d.hqcco]` 45 | 46 | You should get a response that says: `ack` 47 | 48 | 5. Check the state of the agent with `:venter +dbug` 49 | 50 | Your state should be empty again: `[%0 data=~]` 51 | 52 | ## Use in your app 53 | 1. Copy `lib/ventio.hoon` into your desk. 54 | 2. Copy and modify `ted/venter.hoon` to suit your needs. 55 | - The main helper gate `send-vent-request` accepts: 56 | - the `mark` associated with your `request` type 57 | - the `dock` (`[ship agent]`) you want to send your `request` to 58 | - the `action` you want to send as a `request` 59 | 4. Define the `$vent-id` type as a `(pair @p @da)`. 60 | 5. Define the `$request` type as a `(pair vent-id action)` for your action. 61 | 6. Define your custom `$vent` update type, making sure it has an `[%ack ~]` case. 62 | 7. Create marks in the `mar` folder corresponding to `$request`, `$action` and `$vent`. 63 | 8. Replicate the request-handling logic in `app/venter.hoon` in your agent. 64 | 9. Replicate the `on-watch` subscription logic in `app/venter.hoon` in your agent. 65 | -------------------------------------------------------------------------------- /archive/desk/ted/vines/vent-example.hoon: -------------------------------------------------------------------------------- 1 | /- spider, *synapse 2 | /+ *ventio, synapse 3 | => |% 4 | +$ state-0 [%0 data=(map id datum)] 5 | +$ card card:agent:gall 6 | +$ dude dude:gall 7 | +$ gowl bowl:gall 8 | +$ sowl bowl:spider 9 | -- 10 | =, strand=strand:spider 11 | ^- thread:spider 12 | |= arg=vase 13 | =/ m (strand ,vase) 14 | ^- form:m 15 | :: 16 | =/ req=(unit [gowl request]) !<((unit [gowl request]) arg) 17 | ?~ req (strand-fail %no-arg ~) 18 | =/ [=gowl vid=vent-id =mark =noun] u.req 19 | ;< =vase bind:m (unpage mark noun) 20 | ;< =sowl bind:m get-bowl 21 | :: only you can command your own %synapse 22 | :: 23 | ?> =(src our):gowl 24 | :: scry the whole state 25 | :: 26 | =+ .^ state-0 %gx 27 | /(scot %p our.sowl)/[dap.gowl]/(scot %da now.sowl)/state/noun 28 | == 29 | =* state - 30 | =* syn ~(. synapse [gowl state]) 31 | :: 32 | |^ 33 | ?+ mark (punt [our dap]:gowl mark vase) :: poke normally 34 | %synapse-vent-read 35 | (pure:m !>((handle-vent-read:syn !<(vent-read vase)))) 36 | :: 37 | %synapse-async-create 38 | =+ !<(cmd=async-create vase) 39 | ?- -.cmd 40 | %tag 41 | =/ =tag-id (unique-tag-id name.cmd) 42 | :: poke %synapse to create tag with new id 43 | :: 44 | =+ synapse-tag-command+!>([tag-id %create [name description]:cmd]) 45 | ;< ~ bind:m (poke [our dap]:gowl -) 46 | :: vent the id 47 | :: 48 | (pure:m !>(tag-id+tag-id)) 49 | :: 50 | %pin 51 | =/ =pin (unique-pin ship.cmd) 52 | :: poke %synapse to create tag with new id 53 | :: 54 | =+ synapse-pin-command+!>([[ship.cmd pin] %create-pin weight.cmd]) 55 | ;< ~ bind:m (poke [our dap]:gowl -) 56 | :: vent the id 57 | :: 58 | (pure:m !>(pin+pin)) 59 | == 60 | == 61 | ++ unique-pin 62 | |= =ship 63 | ^- pin 64 | =/ get (~(get by source) ship) 65 | |- 66 | =/ =pin (sham [now eny]:sowl) 67 | ?~ get pin 68 | ?. (~(has by weights.u.get) pin) 69 | pin 70 | $(now.sowl +(now.sowl)) 71 | :: 72 | ++ unique-tag-id 73 | |= name=@t 74 | |^ `tag-id`(uniquify (tasify name)) 75 | ++ uniquify 76 | |= =term 77 | ^- tag-id 78 | ?. (~(has by tags) [our.sowl term]) 79 | [our.sowl term] 80 | =/ num=@t (numb (end 4 eny.sowl)) 81 | $(term (rap 3 term '-' num ~)) :: add random number to end 82 | ++ numb :: from numb:enjs:format 83 | |= a=@u 84 | ?: =(0 a) '0' 85 | %- crip 86 | %- flop 87 | |- ^- ^tape 88 | ?:(=(0 a) ~ [(add '0' (mod a 10)) $(a (div a 10))]) 89 | ++ tasify 90 | |= name=@t 91 | ^- term 92 | =/ =tape 93 | %+ turn (cass (trip name)) 94 | |=(=@t `@t`?~(c=(rush t ;~(pose nud low)) '-' u.c)) 95 | =/ =term 96 | ?~ tape %$ 97 | ?^ f=(rush i.tape low) 98 | (crip tape) 99 | (crip ['x' '-' tape]) 100 | ?>(((sane %tas) term) term) 101 | -- 102 | -- 103 | -------------------------------------------------------------------------------- /archive/desk/lib/verb.hoon: -------------------------------------------------------------------------------- 1 | :: Print what your agent is doing. 2 | :: 3 | /- verb 4 | :: 5 | |= [loud=? =agent:gall] 6 | =| bowl-print=_| 7 | ^- agent:gall 8 | |^ !. 9 | |_ =bowl:gall 10 | +* this . 11 | ag ~(. agent bowl) 12 | :: 13 | ++ on-init 14 | ^- (quip card:agent:gall agent:gall) 15 | %- (print bowl |.("{}: on-init")) 16 | =^ cards agent on-init:ag 17 | [[(emit-event %on-init ~) cards] this] 18 | :: 19 | ++ on-save 20 | ^- vase 21 | %- (print bowl |.("{}: on-save")) 22 | on-save:ag 23 | :: 24 | ++ on-load 25 | |= old-state=vase 26 | ^- (quip card:agent:gall agent:gall) 27 | %- (print bowl |.("{}: on-load")) 28 | =^ cards agent (on-load:ag old-state) 29 | [[(emit-event %on-load ~) cards] this] 30 | :: 31 | ++ on-poke 32 | |= [=mark =vase] 33 | ^- (quip card:agent:gall agent:gall) 34 | %- (print bowl |.("{}: on-poke with mark {}")) 35 | ?: ?=(%verb mark) 36 | ?- !<(?(%loud %bowl) vase) 37 | %loud `this(loud !loud) 38 | %bowl `this(bowl-print !bowl-print) 39 | == 40 | =^ cards agent (on-poke:ag mark vase) 41 | [[(emit-event %on-poke mark) cards] this] 42 | :: 43 | ++ on-watch 44 | |= =path 45 | ^- (quip card:agent:gall agent:gall) 46 | %- (print bowl |.("{}: on-watch on path {}")) 47 | =^ cards agent 48 | ?: ?=([%verb %events ~] path) 49 | [~ agent] 50 | (on-watch:ag path) 51 | [[(emit-event %on-watch path) cards] this] 52 | :: 53 | ++ on-leave 54 | |= =path 55 | ^- (quip card:agent:gall agent:gall) 56 | %- (print bowl |.("{}: on-leave on path {}")) 57 | ?: ?=([%verb %event ~] path) 58 | [~ this] 59 | =^ cards agent (on-leave:ag path) 60 | [[(emit-event %on-leave path) cards] this] 61 | :: 62 | ++ on-peek 63 | |= =path 64 | ^- (unit (unit cage)) 65 | %- (print bowl |.("{}: on-peek on path {}")) 66 | (on-peek:ag path) 67 | :: 68 | ++ on-agent 69 | |= [=wire =sign:agent:gall] 70 | ^- (quip card:agent:gall agent:gall) 71 | %- (print bowl |.("{}: on-agent on wire {}, {<-.sign>}")) 72 | =^ cards agent (on-agent:ag wire sign) 73 | [[(emit-event %on-agent wire -.sign) cards] this] 74 | :: 75 | ++ on-arvo 76 | |= [=wire =sign-arvo] 77 | ^- (quip card:agent:gall agent:gall) 78 | %- %+ print bowl |. 79 | "{}: on-arvo on wire {}, {<[- +<]:sign-arvo>}" 80 | =^ cards agent (on-arvo:ag wire sign-arvo) 81 | [[(emit-event %on-arvo wire [- +<]:sign-arvo) cards] this] 82 | :: 83 | ++ on-fail 84 | |= [=term =tang] 85 | ^- (quip card:agent:gall agent:gall) 86 | %- (print bowl |.("{}: on-fail with term {}")) 87 | =^ cards agent (on-fail:ag term tang) 88 | [[(emit-event %on-fail term) cards] this] 89 | -- 90 | :: 91 | ++ print 92 | |= [=bowl:gall render=(trap tape)] 93 | ^+ same 94 | =? . bowl-print 95 | %- (slog >bowl< ~) 96 | . 97 | ?. loud same 98 | %- (slog [%leaf $:render] ~) 99 | same 100 | :: 101 | ++ emit-event 102 | |= =event:verb 103 | ^- card:agent:gall 104 | [%give %fact ~[/verb/events] %verb-event !>(event)] 105 | -- 106 | -------------------------------------------------------------------------------- /venter/ted/vines/venter-example.hoon: -------------------------------------------------------------------------------- 1 | /- *example, spider 2 | /+ *ventio 3 | =, strand=strand:spider 4 | ^- thread:spider 5 | :: 6 | =< 7 | :: a $vine accepts a bowl:gall, vent-id and a cage 8 | :: and returns a shed:khan (a _*form:(strand ,vase)) 9 | :: +vine-thread takes a $vine and returns a $thread 10 | :: 11 | %- vine-thread 12 | |= [=gowl vid=vent-id =mark =vase] 13 | =/ m (strand ,^vase) 14 | ^- form:m 15 | ?+ mark (just-poke [our dap]:gowl mark vase) :: poke normally 16 | %example-action 17 | ?> =(src our):gowl 18 | =+ !<(axn=action vase) 19 | ?- -.axn 20 | %create-datum 21 | :: generate a unique id 22 | :: 23 | ;< =id bind:m get-unique-id 24 | :: poke the %venter-example agent to create the datum 25 | :: 26 | =/ =cage example-transition+!>([%create-datum id t.axn]) 27 | ;< ~ bind:m (poke [our dap]:gowl cage) 28 | :: return the new id 29 | :: 30 | (pure:m !>(new-id+id)) 31 | :: 32 | %delete-datum 33 | :: grab the datum associated with the id 34 | :: 35 | ;< data=(map id datum) bind:m get-data :: data in agent state 36 | =/ =datum (~(got by data) id.axn) :: get datum 37 | :: delete the datum associated with the id 38 | :: 39 | =/ =cage example-transition+!>([%delete-datum id.axn]) 40 | ;< ~ bind:m (poke [our dap]:gowl cage) 41 | :: log the deletion of the datum in /delete-log.txt 42 | :: 43 | :: read the current /delete-log.txt file 44 | :: 45 | =/ dlog=path /delete-log/txt 46 | ;< =sowl bind:m get-bowl :: spider bowl 47 | ;< =^cage bind:m (read-file byk.sowl dlog) 48 | =+ !<(file=wain q.cage) 49 | :: append a new line logging the deletion 50 | :: 51 | =. file 52 | %+ snoc file 53 | %+ rap 3 54 | :~ (scot %uv id.axn) ' | ' 55 | (scot %da now.sowl) ' | ' 56 | datum 57 | == 58 | ;< ~ bind:m (mutate-file q.byk.sowl dlog txt+!>(file)) 59 | :: return a copy of the current delete-log 60 | :: 61 | (pure:m !>(dlog+(of-wain:format file))) 62 | :: create and then delete a datum, logging the deletion 63 | :: (useless, but showcases the utility of "venting" in a "vine") 64 | :: 65 | %create-and-delete 66 | :: create a datum and get the id of the created id 67 | :: like a poke, but it returns a value 68 | :: (it also takes a page instead of a cage) 69 | :: 70 | =/ =page example-action+[%create-datum t.axn] 71 | ;< vnt=example-vent bind:m 72 | ((vent ,example-vent) [our dap]:gowl page) 73 | :: delete the datum associated with the created id 74 | :: 75 | ?> ?=(%new-id -.vnt) 76 | =/ =^page example-action+[%delete-datum id.vnt] 77 | ;< vnt=example-vent bind:m 78 | ((vent ,example-vent) [our dap]:gowl page) 79 | :: return the copy of the delete log 80 | :: 81 | (pure:m !>(vnt)) 82 | == 83 | == 84 | :: 85 | |% 86 | ++ get-data 87 | =/ m (strand ,(map id datum)) 88 | ^- form:m 89 | :: a scry which won't crash %spider; see /lib/ventio.hoon 90 | (scry-hard ,(map id datum) /gx/venter-example/data/noun) 91 | :: 92 | ++ get-unique-id 93 | =/ m (strand ,id) 94 | ^- form:m 95 | ;< data=(map id datum) bind:m get-data 96 | ;< now=@da bind:m get-time 97 | |- 98 | =/ =id (sham now) 99 | ?. (~(has by data) id) 100 | (pure:m id) 101 | $(now (add now ~s0..0001)) 102 | -- 103 | -------------------------------------------------------------------------------- /venter/lib/vent.hoon: -------------------------------------------------------------------------------- 1 | :: vent: agent wrapper for venter pattern 2 | :: 3 | :: usage: %-(agent:vent your-agent) 4 | :: 5 | /+ vio=ventio, default-agent 6 | |% 7 | ++ utils 8 | |* agent=* 9 | |_ =bowl:gall 10 | :: forward vent requests directly to the vine 11 | :: 12 | ++ to-vine 13 | |= [vid=vent-id:vio =page] 14 | ^- (quip card:agent:gall _agent) 15 | =/ args=cage noun+!>(`[bowl vid page]) 16 | :: vine must have same desk and same name as agent in /ted/vines 17 | :: 18 | =/ =(fyrd:khan cage) [q.byk.bowl (cat 3 'vines-' dap.bowl) args] 19 | :_(agent [%pass (en-path:vio vid) %arvo %k %fard fyrd]~) 20 | :: re-interpret a poke as a vent-request 21 | :: 22 | ++ poke-to-vent 23 | |= [=mark =vase] 24 | ^- (quip card:agent:gall _agent) 25 | (to-vine [[our *@tatid now]:bowl mark q.vase]) 26 | :: return the vine output on the vent path 27 | :: 28 | ++ vent-arow 29 | |= [=path arow=(avow:khan cage)] 30 | ^- (quip card:agent:gall _agent) 31 | =/ vid=vent-id:vio (de-path:vio path) 32 | =/ =cage ?-(-.arow %& p.arow, %| goof+!>(p.arow)) 33 | %- (slog ?:(?=(%.y -.arow) ~ p.arow)) 34 | :_ agent 35 | :~ [%give %fact ~[path] cage] 36 | [%give %kick ~[path] ~] 37 | == 38 | -- 39 | :: 40 | ++ agent 41 | |= =agent:gall 42 | ^- agent:gall 43 | !. 44 | |_ =bowl:gall 45 | +* this . 46 | def ~(. (default-agent this %.n) bowl) 47 | vnt ~(. (utils this) bowl) 48 | ag ~(. agent bowl) 49 | :: 50 | ++ on-poke 51 | |= [=mark =vase] 52 | ^- (quip card:agent:gall agent:gall) 53 | :: forward vent requests directly to the vine 54 | :: 55 | ?+ mark 56 | =^ cards agent (on-poke:ag mark vase) 57 | [cards this] 58 | :: 59 | %vent-request (to-vine:vnt !<(request:vio vase)) 60 | :: 61 | %send-cards 62 | ?> =(our src):bowl 63 | [;;((list card:agent:gall) q.vase) this] 64 | == 65 | :: 66 | ++ on-peek 67 | |= =path 68 | ^- (unit (unit cage)) 69 | (on-peek:ag path) 70 | :: 71 | ++ on-init 72 | ^- (quip card:agent:gall agent:gall) 73 | =^ cards agent on-init:ag 74 | [cards this] 75 | :: 76 | ++ on-save on-save:ag 77 | :: 78 | ++ on-load 79 | |= old-state=vase 80 | ^- (quip card:agent:gall agent:gall) 81 | =^ cards agent (on-load:ag old-state) 82 | [cards this] 83 | :: 84 | ++ on-watch 85 | |= =path 86 | ^- (quip card:agent:gall agent:gall) 87 | ?+ path 88 | =^ cards agent (on-watch:ag path) 89 | [cards this] 90 | [%vent @ta @ta @ta ~] ?>(=(src.bowl (slav %p i.t.path)) `this) 91 | [%vent-on-arvo ~] ?>(=(our src):bowl `this) 92 | [%vent-on-agent ~] ?>(=(our src):bowl `this) 93 | == 94 | :: 95 | ++ on-leave 96 | |= =path 97 | ^- (quip card:agent:gall agent:gall) 98 | =^ cards agent (on-leave:ag path) 99 | [cards this] 100 | :: 101 | ++ on-agent 102 | |= [=wire =sign:agent:gall] 103 | ^- (quip card:agent:gall agent:gall) 104 | =^ cards agent (on-agent:ag wire sign) 105 | =; =card:agent:gall 106 | [[card cards] this] 107 | (agent-update wire sign bowl) 108 | :: 109 | ++ on-arvo 110 | |= [=wire =sign-arvo] 111 | ^- (quip card:agent:gall agent:gall) 112 | =^ cards agent 113 | ?. ?=([%vent @ @ @ ~] wire) 114 | (on-arvo:ag wire sign-arvo) 115 | ?. ?=([%khan %arow *] sign-arvo) 116 | (on-arvo:def wire sign-arvo) 117 | (vent-arow:vnt wire p.sign-arvo) 118 | =; =card:agent:gall 119 | [[card cards] this] 120 | (arvo-update wire sign-arvo bowl) 121 | :: 122 | ++ on-fail 123 | |= [=term =tang] 124 | ^- (quip card:agent:gall agent:gall) 125 | =^ cards agent (on-fail:ag term tang) 126 | [cards this] 127 | -- 128 | :: 129 | ++ agent-update 130 | |= [=wire =sign:agent:gall =bowl:gall] 131 | ^- card:agent:gall 132 | [%give %fact ~[/vent-on-agent] %noun !>(`noun`[bowl wire sign])] 133 | :: 134 | ++ arvo-update 135 | |= [=wire =sign-arvo =bowl:gall] 136 | ^- card:agent:gall 137 | [%give %fact ~[/vent-on-arvo] %noun !>(`noun`[bowl wire sign-arvo])] 138 | -- 139 | -------------------------------------------------------------------------------- /bare-desk/lib/vent.hoon: -------------------------------------------------------------------------------- 1 | :: vent: agent wrapper for venter pattern 2 | :: 3 | :: usage: %-(agent:vent your-agent) 4 | :: 5 | /+ vio=ventio, default-agent 6 | |% 7 | ++ utils 8 | |* agent=* 9 | |_ =bowl:gall 10 | :: forward vent requests directly to the vine 11 | :: 12 | ++ to-vine 13 | |= [vid=vent-id:vio =page] 14 | ^- (quip card:agent:gall _agent) 15 | =/ args=cage noun+!>(`[bowl vid page]) 16 | :: vine must have same desk and same name as agent in /ted/vines 17 | :: 18 | =/ =(fyrd:khan cage) [q.byk.bowl (cat 3 'vines-' dap.bowl) args] 19 | :_(agent [%pass (en-path:vio vid) %arvo %k %fard fyrd]~) 20 | :: re-interpret a poke as a vent-request 21 | :: 22 | ++ poke-to-vent 23 | |= [=mark =vase] 24 | ^- (quip card:agent:gall _agent) 25 | (to-vine [[our *@tatid now]:bowl mark q.vase]) 26 | :: return the vine output on the vent path 27 | :: 28 | ++ vent-arow 29 | |= [=path arow=(avow:khan cage)] 30 | ^- (quip card:agent:gall _agent) 31 | =/ vid=vent-id:vio (de-path:vio path) 32 | =/ =cage ?-(-.arow %& p.arow, %| goof+!>(p.arow)) 33 | %- (slog ?:(?=(%.y -.arow) ~ p.arow)) 34 | :_ agent 35 | :~ [%give %fact ~[path] cage] 36 | [%give %kick ~[path] ~] 37 | == 38 | -- 39 | :: 40 | ++ agent 41 | |= =agent:gall 42 | ^- agent:gall 43 | !. 44 | |_ =bowl:gall 45 | +* this . 46 | def ~(. (default-agent this %.n) bowl) 47 | vnt ~(. (utils this) bowl) 48 | ag ~(. agent bowl) 49 | :: 50 | ++ on-poke 51 | |= [=mark =vase] 52 | ^- (quip card:agent:gall agent:gall) 53 | :: forward vent requests directly to the vine 54 | :: 55 | ?+ mark 56 | =^ cards agent (on-poke:ag mark vase) 57 | [cards this] 58 | :: 59 | %vent-request (to-vine:vnt !<(request:vio vase)) 60 | :: 61 | %send-cards 62 | ?> =(our src):bowl 63 | [;;((list card:agent:gall) q.vase) this] 64 | == 65 | :: 66 | ++ on-peek 67 | |= =path 68 | ^- (unit (unit cage)) 69 | (on-peek:ag path) 70 | :: 71 | ++ on-init 72 | ^- (quip card:agent:gall agent:gall) 73 | =^ cards agent on-init:ag 74 | [cards this] 75 | :: 76 | ++ on-save on-save:ag 77 | :: 78 | ++ on-load 79 | |= old-state=vase 80 | ^- (quip card:agent:gall agent:gall) 81 | =^ cards agent (on-load:ag old-state) 82 | [cards this] 83 | :: 84 | ++ on-watch 85 | |= =path 86 | ^- (quip card:agent:gall agent:gall) 87 | ?+ path 88 | =^ cards agent (on-watch:ag path) 89 | [cards this] 90 | [%vent @ta @ta @ta ~] ?>(=(src.bowl (slav %p i.t.path)) `this) 91 | [%vent-on-arvo ~] ?>(=(our src):bowl `this) 92 | [%vent-on-agent ~] ?>(=(our src):bowl `this) 93 | == 94 | :: 95 | ++ on-leave 96 | |= =path 97 | ^- (quip card:agent:gall agent:gall) 98 | =^ cards agent (on-leave:ag path) 99 | [cards this] 100 | :: 101 | ++ on-agent 102 | |= [=wire =sign:agent:gall] 103 | ^- (quip card:agent:gall agent:gall) 104 | =^ cards agent (on-agent:ag wire sign) 105 | =; =card:agent:gall 106 | [[card cards] this] 107 | (agent-update wire sign bowl) 108 | :: 109 | ++ on-arvo 110 | |= [=wire =sign-arvo] 111 | ^- (quip card:agent:gall agent:gall) 112 | =^ cards agent 113 | ?. ?=([%vent @ @ @ ~] wire) 114 | (on-arvo:ag wire sign-arvo) 115 | ?. ?=([%khan %arow *] sign-arvo) 116 | (on-arvo:def wire sign-arvo) 117 | (vent-arow:vnt wire p.sign-arvo) 118 | =; =card:agent:gall 119 | [[card cards] this] 120 | (arvo-update wire sign-arvo bowl) 121 | :: 122 | ++ on-fail 123 | |= [=term =tang] 124 | ^- (quip card:agent:gall agent:gall) 125 | =^ cards agent (on-fail:ag term tang) 126 | [cards this] 127 | -- 128 | :: 129 | ++ agent-update 130 | |= [=wire =sign:agent:gall =bowl:gall] 131 | ^- card:agent:gall 132 | [%give %fact ~[/vent-on-agent] %noun !>(`noun`[bowl wire sign])] 133 | :: 134 | ++ arvo-update 135 | |= [=wire =sign-arvo =bowl:gall] 136 | ^- card:agent:gall 137 | [%give %fact ~[/vent-on-arvo] %noun !>(`noun`[bowl wire sign-arvo])] 138 | -- 139 | -------------------------------------------------------------------------------- /bare-desk/app/venter-venter.hoon: -------------------------------------------------------------------------------- 1 | /+ vio=ventio, dbug, verb, default-agent 2 | :: There is no way around this. Threads cannot do state. 3 | :: The venter needs STATE in order to enforce uniqueness on its vent-ids. 4 | :: 5 | :: %venter is also responsible for warming this desk's tubes.... 6 | :: improves vent performance when using /ted/vent.hoon 7 | :: https://github.com/tinnus-napbus/tube-warmer 8 | :: 9 | |% 10 | +$ state-0 [%0 =vents:vio tube-verb=_|] 11 | +$ card card:agent:gall 12 | +$ vent-id vent-id:vio 13 | -- 14 | %- agent:dbug 15 | %+ verb | 16 | =| state-0 17 | =* state - 18 | ^- agent:gall 19 | |_ =bowl:gall 20 | +* this . 21 | def ~(. (default-agent this %|) bowl) 22 | ++ on-init 23 | ^- (quip card _this) 24 | =/ =@ud +(ud:.^(cass:clay %cw /(scot %p our.bowl)/[q.byk.bowl]/(scot %da now.bowl))) 25 | :_ this 26 | :~ [%pass /next %arvo %c %warp our.bowl q.byk.bowl ~ %many %.y ud+ud ud+ud /] 27 | [%pass /tube-warmer %arvo %k %fard q.byk.bowl %tube-warmer noun+!>(`[q.byk.bowl tube-verb])] 28 | == 29 | :: 30 | ++ on-save !>(state) 31 | :: 32 | ++ on-load 33 | |= ole=vase 34 | ^- (quip card _this) 35 | =/ old=state-0 !<(state-0 ole) 36 | =. state old 37 | =/ =@ud +(ud:.^(cass:clay %cw /(scot %p our.bowl)/[q.byk.bowl]/(scot %da now.bowl))) 38 | :_ this 39 | :~ [%pass /next %arvo %c %warp our.bowl q.byk.bowl ~ %many %.y ud+ud ud+ud /] 40 | [%pass /tube-warmer %arvo %k %fard q.byk.bowl %tube-warmer noun+!>(`[q.byk.bowl tube-verb])] 41 | == 42 | :: 43 | ++ on-poke 44 | |= [=mark =vase] 45 | ^- (quip card _this) 46 | ?> =(src our):bowl 47 | ?+ mark (on-poke:def mark vase) 48 | %noun `this(tube-verb (tail !<([%verb ?] vase))) 49 | :: 50 | %tally-vent 51 | :: ~& %venter-tallying 52 | =+ !<([=dock vid=vent-id] vase) 53 | `this(vents (~(put ju vents) dock vid)) 54 | :: 55 | %clear-vent 56 | :: ~& %venter-clearing 57 | =+ !<([=dock vid=vent-id] vase) 58 | `this(vents (~(del ju vents) dock vid)) 59 | :: 60 | %clear-dead 61 | =+ .^(pats=(list path) %gx /(scot %p our.bowl)/spider/(scot %da now.bowl)/tree/noun) 62 | =/ tids=(set tid:rand) (~(gas in *(set tid:rand)) (turn pats rear)) 63 | :- ~ 64 | %= this 65 | vents 66 | %- ~(gas by *vents:vio) 67 | %+ murn ~(tap by vents) 68 | |= [=dock vids=(set vent-id)] 69 | =; new=(set vent-id) 70 | ?:(?=(~ new) ~ `[dock new]) 71 | %- ~(gas in *(set vent-id)) 72 | %+ murn ~(tap in vids) 73 | |= vid=vent-id 74 | ?.((~(has in tids) q.vid) ~ `vid) 75 | == 76 | :: gives a vent response directly from this agent 77 | :: 78 | %vent-request 79 | =+ !<([vid=vent-id:vio req=page] vase) 80 | =/ =path (en-path:vio vid) 81 | ?+ p.req (on-poke:def mark vase) 82 | %scry 83 | =+ ;;(scry=^path q.req) 84 | ?> ?=(^ scry) 85 | ?> ?=(^ t.scry) 86 | =+ .^(p=* i.scry (scot %p our.bowl) i.t.scry (scot %da now.bowl) t.t.scry) 87 | :_ this 88 | :~ [%give %fact ~[path] noun+!>(p)] 89 | [%give %kick ~[path] ~] 90 | == 91 | == 92 | == 93 | :: 94 | ++ on-peek 95 | |= =(pole knot) 96 | ^- (unit (unit cage)) 97 | ?+ pole (on-peek:def pole) 98 | [%x %vents ~] ``noun+!>(vents) 99 | == 100 | :: 101 | ++ on-watch 102 | |= =(pole knot) 103 | ^- (quip card _this) 104 | ?+ pole (on-watch:def pole) 105 | [%vent @ @ @ ~] ?>(=(src our):bowl `this) 106 | == 107 | :: 108 | ++ on-leave on-leave:def 109 | ++ on-agent on-agent:def 110 | :: 111 | ++ on-arvo 112 | |= [=(pole knot) sign=sign-arvo] 113 | ^- (quip card _this) 114 | ?+ pole (on-arvo:def pole sign) 115 | [%tube-warmer ~] 116 | ?. ?=([%khan %arow *] sign) (on-arvo:def pole sign) 117 | %- (slog ?:(?=(%.y -.p.sign) ~ p.p.sign)) 118 | `this 119 | :: 120 | [%next ~] 121 | ?. ?=([%clay %writ ~] sign) `this 122 | =/ =@ud +(ud:.^(cass:clay %cw /(scot %p our.bowl)/[q.byk.bowl]/(scot %da now.bowl))) 123 | :_ this 124 | :~ [%pass /next %arvo %c %warp our.bowl q.byk.bowl ~ %many %.y ud+ud ud+ud /] 125 | [%pass /tube-warmer %arvo %k %fard q.byk.bowl %tube-warmer noun+!>(`[q.byk.bowl tube-verb])] 126 | == 127 | == 128 | :: 129 | ++ on-fail on-fail:def 130 | -- 131 | -------------------------------------------------------------------------------- /archive/desk/lib/dbug.hoon: -------------------------------------------------------------------------------- 1 | :: dbug: agent wrapper for generic debugging tools 2 | :: 3 | :: usage: %-(agent:dbug your-agent) 4 | :: 5 | |% 6 | +$ poke 7 | $% [%bowl ~] 8 | [%state grab=cord] 9 | [%incoming =about] 10 | [%outgoing =about] 11 | == 12 | :: 13 | +$ about 14 | $@ ~ 15 | $% [%ship =ship] 16 | [%path =path] 17 | [%wire =wire] 18 | [%term =term] 19 | == 20 | :: 21 | ++ agent 22 | |= =agent:gall 23 | ^- agent:gall 24 | !. 25 | |_ =bowl:gall 26 | +* this . 27 | ag ~(. agent bowl) 28 | :: 29 | ++ on-poke 30 | |= [=mark =vase] 31 | ^- (quip card:agent:gall agent:gall) 32 | ?. ?=(%dbug mark) 33 | =^ cards agent (on-poke:ag mark vase) 34 | [cards this] 35 | =/ dbug 36 | !<(poke vase) 37 | =; =tang 38 | ((%*(. slog pri 1) tang) [~ this]) 39 | ?- -.dbug 40 | %bowl [(sell !>(bowl))]~ 41 | :: 42 | %state 43 | =? grab.dbug =('' grab.dbug) '-' 44 | =; product=^vase 45 | [(sell product)]~ 46 | =/ state=^vase 47 | :: if the underlying app has implemented a /dbug/state scry endpoint, 48 | :: use that vase in place of +on-save's. 49 | :: 50 | =/ result=(each ^vase tang) 51 | (mule |.(q:(need (need (on-peek:ag /x/dbug/state))))) 52 | ?:(?=(%& -.result) p.result on-save:ag) 53 | %+ slap 54 | (slop state !>([bowl=bowl ..zuse])) 55 | (ream grab.dbug) 56 | :: 57 | %incoming 58 | =; =tang 59 | ?^ tang tang 60 | [%leaf "no matching subscriptions"]~ 61 | %+ murn 62 | %+ sort ~(tap by sup.bowl) 63 | |= [[* a=[=ship =path]] [* b=[=ship =path]]] 64 | (aor [path ship]:a [path ship]:b) 65 | |= [=duct [=ship =path]] 66 | ^- (unit tank) 67 | =; relevant=? 68 | ?. relevant ~ 69 | `>[path=path from=ship duct=duct]< 70 | ?: ?=(~ about.dbug) & 71 | ?- -.about.dbug 72 | %ship =(ship ship.about.dbug) 73 | %path ?=(^ (find path.about.dbug path)) 74 | %wire %+ lien duct 75 | |=(=wire ?=(^ (find wire.about.dbug wire))) 76 | %term !! 77 | == 78 | :: 79 | %outgoing 80 | =; =tang 81 | ?^ tang tang 82 | [%leaf "no matching subscriptions"]~ 83 | %+ murn 84 | %+ sort ~(tap by wex.bowl) 85 | |= [[[a=wire *] *] [[b=wire *] *]] 86 | (aor a b) 87 | |= [[=wire =ship =term] [acked=? =path]] 88 | ^- (unit tank) 89 | =; relevant=? 90 | ?. relevant ~ 91 | `>[wire=wire agnt=[ship term] path=path ackd=acked]< 92 | ?: ?=(~ about.dbug) & 93 | ?- -.about.dbug 94 | %ship =(ship ship.about.dbug) 95 | %path ?=(^ (find path.about.dbug path)) 96 | %wire ?=(^ (find wire.about.dbug wire)) 97 | %term =(term term.about.dbug) 98 | == 99 | == 100 | :: 101 | ++ on-peek 102 | |= =path 103 | ^- (unit (unit cage)) 104 | ?. ?=([@ %dbug *] path) 105 | (on-peek:ag path) 106 | ?+ path [~ ~] 107 | [%u %dbug ~] ``noun+!>(&) 108 | [%x %dbug %state ~] ``noun+!>(on-save:ag) 109 | [%x %dbug %subscriptions ~] ``noun+!>([wex sup]:bowl) 110 | == 111 | :: 112 | ++ on-init 113 | ^- (quip card:agent:gall agent:gall) 114 | =^ cards agent on-init:ag 115 | [cards this] 116 | :: 117 | ++ on-save on-save:ag 118 | :: 119 | ++ on-load 120 | |= old-state=vase 121 | ^- (quip card:agent:gall agent:gall) 122 | =^ cards agent (on-load:ag old-state) 123 | [cards this] 124 | :: 125 | ++ on-watch 126 | |= =path 127 | ^- (quip card:agent:gall agent:gall) 128 | =^ cards agent (on-watch:ag path) 129 | [cards this] 130 | :: 131 | ++ on-leave 132 | |= =path 133 | ^- (quip card:agent:gall agent:gall) 134 | =^ cards agent (on-leave:ag path) 135 | [cards this] 136 | :: 137 | ++ on-agent 138 | |= [=wire =sign:agent:gall] 139 | ^- (quip card:agent:gall agent:gall) 140 | =^ cards agent (on-agent:ag wire sign) 141 | [cards this] 142 | :: 143 | ++ on-arvo 144 | |= [=wire =sign-arvo] 145 | ^- (quip card:agent:gall agent:gall) 146 | =^ cards agent (on-arvo:ag wire sign-arvo) 147 | [cards this] 148 | :: 149 | ++ on-fail 150 | |= [=term =tang] 151 | ^- (quip card:agent:gall agent:gall) 152 | =^ cards agent (on-fail:ag term tang) 153 | [cards this] 154 | -- 155 | -- 156 | -------------------------------------------------------------------------------- /bare-desk/ted/tube-warmer.hoon: -------------------------------------------------------------------------------- 1 | :: https://github.com/tinnus-napbus/tube-warmer 2 | :: Tube-warming measurably boosts performance where several successive 3 | :: mark conversions happen with high frequency. 4 | :: See marks building with: |pass [%c %stir %verb 1] 5 | :: 6 | /- spider 7 | /+ *strandio 8 | =, strand=strand:spider 9 | =< 10 | :: 11 | ^- thread:spider 12 | |= arg=vase 13 | =/ m (strand ,vase) 14 | ^- form:m 15 | :: 16 | ;< =bowl:rand bind:m get-bowl 17 | :: accepts a desk as argument; can warm tubes of any desk 18 | :: 19 | =/ [=desk verb=?] (need !<((unit [desk ?]) arg)) 20 | :: get list of mark file names of hoon files from desk's mar directory 21 | :: 22 | ;< paths=(list path) bind:m (scry (list path) %ct /[desk]/mar) 23 | =. paths (turn (skim (turn paths flop) |=(=path ?=([%hoon *] path))) flop) 24 | :: build the mark files 25 | :: 26 | ;< files=(map path vase) bind:m 27 | (build-all-files our.bowl desk now.bowl paths) 28 | :: get list of all possible mark conversions (tubes) in the desk 29 | :: 30 | =/ marks=(list mark) (turn paths en-fit) 31 | =/ mars=(list mars:clay) 32 | %~ tap in 33 | %- ~(gas in *(set mars:clay)) 34 | %- zing 35 | %+ turn ~(tap by files) 36 | (mark-pairs (sy marks)) 37 | :: warm all the tubes 38 | :: 39 | ;< ~ bind:m (build-all-tubes verb our.bowl desk now.bowl mars) 40 | :: warm all dais 41 | :: 42 | ;< ~ bind:m (build-all-dais verb our.bowl desk now.bowl marks) 43 | :: end thread 44 | :: 45 | (pure:m !>(~)) 46 | :: 47 | |% 48 | ++ build-all-files 49 | |= [our=@p des=desk now=@da paths=(list path)] 50 | =| cores=(map path vase) 51 | |- 52 | =/ m (strand ,(map path vase)) 53 | ^- form:m 54 | =* loop $ 55 | ?~ paths (pure:m cores) 56 | ;< vus=(unit vase) bind:m (build-file [our des da+now] i.paths) 57 | ?~ vus loop(paths t.paths) 58 | loop(cores (~(put by cores) i.paths u.vus), paths t.paths) 59 | :: 60 | ++ get-marks 61 | |= =vase 62 | ^- [grab=(list mark) grow=(list mark)] 63 | :: if the grab/grow arm exists (slob), 64 | :: run it (slap) and list its arms (sloe) 65 | :: 66 | :- ?. (slob %grab -:vase) ~ 67 | (sloe -:(slap vase [%limb %grab])) 68 | ?. (slob %grow -:vase) ~ 69 | (sloe -:(slap vase [%limb %grow])) 70 | :: remove mar and hoon from /mar/foo/.../bar/hoon 71 | :: 72 | ++ en-fit 73 | |= =path 74 | ^- @tas 75 | =. path ?>(?=([%mar *] path) (flop t.path)) 76 | =. path ?>(?=([%hoon *] path) (flop t.path)) 77 | (rap 3 (join '-' path)) 78 | :: takes a mark filepath name 79 | :: and the corresponding mark core as a vase 80 | :: returns pairs 81 | :: - from mark to grab arms 82 | :: - to mark from grow arms 83 | :: 84 | ++ mark-pairs 85 | |= marks=(set mark) 86 | |= [=path =vase] 87 | ^- (list mars:clay) 88 | =/ fit=mark (en-fit path) 89 | =/ [grab=(list mark) grow=(list mark)] 90 | (get-marks vase) 91 | ;: weld [fit fit]~ 92 | (murn grab |=(=mark ?.((~(has in marks) mark) ~ `[mark fit]))) 93 | (murn grow |=(=mark ?.((~(has in marks) mark) ~ `[fit mark]))) 94 | == 95 | :: 96 | ++ build-tube-soft 97 | |= [[=ship =desk =case] =mars:clay] 98 | =/ m (strand ,(unit tube:clay)) 99 | ^- form:m 100 | ;< =riot:clay bind:m 101 | (warp ship desk ~ %sing %c case /[a.mars]/[b.mars]) 102 | ?~ riot 103 | (pure:m ~) 104 | ?> =(%tube p.r.u.riot) 105 | (pure:m `!<(tube:clay q.r.u.riot)) 106 | :: 107 | ++ build-dais-soft 108 | |= [[=ship =desk =case] mak=mark] 109 | =/ m (strand ,(unit dais:clay)) 110 | ^- form:m 111 | ;< =riot:clay bind:m 112 | (warp ship desk ~ %sing %b case /[mak]) 113 | ?~ riot 114 | (pure:m ~) 115 | ?> =(%dais p.r.u.riot) 116 | (pure:m `!<(dais:clay q.r.u.riot)) 117 | :: 118 | ++ build-all-tubes 119 | |= [verb=? our=@p des=desk now=@da mars=(list mars:clay)] 120 | |- 121 | =/ m (strand ,~) 122 | ^- form:m 123 | =* loop $ 124 | ?~ mars (pure:m ~) 125 | ;< tub=(unit tube:clay) bind:m 126 | (build-tube-soft [our des da+now] i.mars) 127 | ?~ tub 128 | ~? >>> verb [%build-tube-failed i.mars] 129 | loop(mars t.mars) 130 | ~? > verb [%built-tube i.mars] 131 | loop(mars t.mars) 132 | :: 133 | ++ build-all-dais 134 | |= [verb=? our=@p des=desk now=@da marks=(list mark)] 135 | |- 136 | =/ m (strand ,~) 137 | ^- form:m 138 | =* loop $ 139 | ?~ marks (pure:m ~) 140 | ;< das=(unit dais:clay) bind:m 141 | (build-dais-soft [our des da+now] i.marks) 142 | ?~ das 143 | ~? >>> verb [%build-dais-failed i.marks] 144 | loop(marks t.marks) 145 | ~? > verb [%built-dais i.marks] 146 | loop(marks t.marks) 147 | -- 148 | -------------------------------------------------------------------------------- /archive/desk/lib/ventio.hoon: -------------------------------------------------------------------------------- 1 | /- spider 2 | /+ *strandio 3 | |% 4 | +$ vent-id (pair @p @da) 5 | +$ request (pair vent-id page) 6 | +$ package 7 | $: =dock :: destination ship/agent 8 | input=[=desk =mark] :: mark of input and its location 9 | output=[=desk =mark] :: mark of output and its location 10 | body=json :: actual data to send to agent in vent-request 11 | == 12 | :: track your vents so you can make unique vent-ids 13 | :: 14 | +$ vents (jug dock vent-id) 15 | :: 16 | ++ en-path 17 | |= vid=vent-id 18 | ^- path 19 | /vent/(scot %p p.vid)/(scot %da q.vid) 20 | :: 21 | ++ de-path 22 | |= =path 23 | ^- vent-id 24 | =+ ;;([%vent p=@ta q=@ta ~] path) 25 | [(slav %p p.-) (slav %da q.-)] 26 | :: forward vent requests directly to the vine 27 | :: 28 | ++ to-vine 29 | |= [=vase =bowl:gall] 30 | ^- card:agent:gall 31 | =/ [vid=vent-id =mark =noun] !<(request vase) 32 | =/ args=cage noun+!>((some bowl vid mark noun)) 33 | :: vine must have same desk and same name as agent in /ted/vines 34 | :: 35 | =/ =(fyrd:khan cage) [q.byk.bowl (cat 3 'vines-' dap.bowl) args] 36 | [%pass (en-path vid) %arvo %k %fard fyrd] 37 | :: 38 | ++ en-arow |*(a=* `sign-arvo`[%khan %arow %& %noun !>(a)]) 39 | ++ en-eror |=(=goof `sign-arvo`[%khan %arow %| goof]) 40 | :: 41 | ++ vent-arow 42 | |= [=path arow=(avow:khan cage)] 43 | ^- (list card:agent:gall) 44 | =/ vid=vent-id (de-path path) 45 | =/ =cage ?-(-.arow %& p.arow, %| goof+!>(p.arow)) 46 | :~ [%give %fact ~[path] cage] 47 | [%give %kick ~[path] ~] 48 | == 49 | :: translates poke-ack to vent for regular poke 50 | :: 51 | ++ punt 52 | |= [=dock =cage] 53 | =/ m (strand ,vase) 54 | ^- form:m 55 | ;< ~ bind:m (poke dock cage) 56 | (pure:m !>(~)) 57 | :: 58 | ++ unpackage 59 | |= [body=json =desk =mark] 60 | =/ m (strand ,page) 61 | ^- form:m 62 | ;< =tube:clay bind:m (scry tube:clay /cc/[desk]/json/[mark]) 63 | (pure:m [mark q:(tube !>(body))]) 64 | :: 65 | ++ vent 66 | |* a=mold 67 | =/ m (strand ,a) 68 | :: accept a cage for historical reasons; 69 | :: nested vases don't do well when converting between marks 70 | :: so ultimately a page is used instead of a cage here 71 | :: 72 | |= [=dock =cage] 73 | ^- form:m 74 | ;< =vase bind:m (vent-raw dock p.cage q.q.cage) 75 | (pure:m ;;(a q.vase)) 76 | :: 77 | ++ unpage 78 | |= =page 79 | =/ m (strand ,vase) 80 | ^- form:m 81 | ;< byk=beak:spider bind:m get-beak 82 | ;< =tube:clay bind:m (scry tube:clay /cc/[q.byk]/noun/[p.page]) 83 | ;< ~ bind:m (trace (cat 3 'mark: ' p.page) ~) 84 | (pure:m (tube !>(q.page))) 85 | :: 86 | ++ vent-dyn 87 | |= [=desk =mark] 88 | |= [=dock =page] 89 | =/ m (strand ,vase) 90 | ^- form:m 91 | ;< =vase bind:m (vent-raw dock page) 92 | ;< =tube:clay bind:m (scry tube:clay /cc/[desk]/noun/[mark]) 93 | (pure:m (tube vase)) 94 | :: 95 | ++ vent-raw 96 | |= [=dock req=page] 97 | =/ m (strand ,vase) 98 | ^- form:m 99 | :: get existing vents 100 | :: 101 | ;< =vents bind:m (scry vents /gx/venter/vents/noun) 102 | :: define the vent id 103 | :: 104 | ;< =bowl:strand bind:m get-bowl 105 | =/ vid=vent-id (unique-vent dock vents [our now]:bowl) 106 | :: listen for updates along this path 107 | :: 108 | =/ vent-path=path (en-path vid) 109 | ;< ~ bind:m (watch vent-path dock vent-path) 110 | :: tally the vent-path 111 | :: 112 | ;< ~ bind:m (poke [our.bowl %venter] tally-vent+!>([dock vid])) 113 | :: poke the agent on the destination ship with the vent id and page 114 | :: 115 | ;< ~ bind:m (poke dock vent-request+!>([vid req])) 116 | :: take vent update on vent-path 117 | :: 118 | ;< rep=cage bind:m (take-fact vent-path) 119 | ;< ~ bind:m (take-kick vent-path) 120 | :: clear the vent-path 121 | :: 122 | ;< ~ bind:m (poke [our.bowl %venter] clear-vent+!>([dock vid])) 123 | :: return vent result or strand-fail on error 124 | :: 125 | ?. ?=(%goof p.rep) 126 | (pure:m q.rep) 127 | (strand-fail !<(goof q.rep)) 128 | :: 129 | ++ unique-vent 130 | |= [=dock =vents our=@p now=@da] 131 | ^- vent-id 132 | ?. (~(has ju vents) dock [our now]) 133 | [our now] 134 | $(now +(now)) 135 | :: miscellaneous utils 136 | :: 137 | ++ take-special-fact 138 | |* [=wire =mark =mold] 139 | |= take=$-(mold ?) 140 | =/ m (strand ,mold) 141 | ^- form:m 142 | |= tin=strand-input:strand 143 | ?+ in.tin `[%skip ~] 144 | ~ `[%wait ~] 145 | [~ %agent * %fact *] 146 | ?. =(watch+wire wire.u.in.tin) 147 | `[%skip ~] 148 | ?. =(mark p.cage.sign.u.in.tin) 149 | `[%skip ~] 150 | =+ !<(a=mold q.cage.sign.u.in.tin) 151 | ?. (take a) 152 | `[%skip ~] 153 | `[%done a] 154 | == 155 | -- 156 | -------------------------------------------------------------------------------- /bare-desk/lib/bind.hoon: -------------------------------------------------------------------------------- 1 | :: bind: agent wrapper to connect your agent to %eyre bindings 2 | :: 3 | :: initialize agent-bind somewhere: 4 | :: |% ++ agent-bind (agent:bind & ~[[`/path &]]) -- 5 | :: +agent:bind accepts a verbosity flag and a list of 6 | :: $binding / force-flag pairs. 7 | :: %.y to forcefully overwrite a binding which already exists. 8 | :: 9 | :: usage: %-(agent-bind your-agent) 10 | :: 11 | /+ server, agentio, default-agent 12 | |% 13 | +$ card card:agent:gall 14 | :: 15 | ++ binding-to-cord 16 | |= binding:eyre 17 | ^- cord 18 | (rap 3 ?~(site '' u.site) '/' (join '/' path)) 19 | :: 20 | ++ existing 21 | |= =bowl:gall 22 | ^- (map binding:eyre [duct action:eyre]) 23 | =+ .^ bindings=(list [binding:eyre duct action:eyre]) 24 | %e /(scot %p our.bowl)/bindings/(scot %da now.bowl) 25 | == 26 | (~(gas by *(map binding:eyre [duct action:eyre])) bindings) 27 | :: 28 | ++ ours 29 | |= =bowl:gall 30 | ^- (set binding:eyre) 31 | =+ .^ bindings=(list [binding:eyre duct action:eyre]) 32 | %e /(scot %p our.bowl)/bindings/(scot %da now.bowl) 33 | == 34 | %- ~(gas in *(set binding:eyre)) 35 | %+ murn bindings 36 | |= [=binding:eyre * =action:eyre] 37 | ^- (unit binding:eyre) 38 | ?. ?=(%app -.action) ~ 39 | ?. =(dap.bowl app.action) ~ 40 | `binding 41 | :: 42 | ++ bind-cards 43 | |= $: verb=? 44 | =bowl:gall 45 | cards=(list card) 46 | bindings=(list [=binding:eyre force=?]) 47 | == 48 | ^- (list card) 49 | ?~ bindings 50 | cards 51 | =+ i.bindings 52 | ?: (~(has in (ours bowl)) binding) 53 | ~? >> verb 54 | `@t`(rap 3 dap.bowl ': ' (binding-to-cord binding) ' is already bound to us' ~) 55 | $(bindings t.bindings) 56 | =/ bound=? (~(has by (existing bowl)) binding) 57 | ~? >> &(verb bound) 58 | `@t`(rap 3 dap.bowl ': ' (binding-to-cord binding) ' is already bound to something else' ~) 59 | ~? >> &(verb force bound) 'overriding binding' 60 | ~? >> &(verb !force bound) 'not overriding binding' 61 | =? cards |(force !bound) 62 | :_(cards (~(connect ~(pass agentio bowl) /connect) binding dap.bowl)) 63 | $(bindings t.bindings) 64 | :: 65 | ++ agent 66 | |= [verb=? bindings=(list [=binding:eyre force=?])] 67 | |= =agent:gall 68 | ^- agent:gall 69 | !. 70 | |_ =bowl:gall 71 | +* this . 72 | ag ~(. agent bowl) 73 | def ~(. (default-agent this %|) bowl) 74 | :: 75 | ++ on-init 76 | =^ cards agent on-init:ag 77 | :_(this (bind-cards verb bowl cards bindings)) 78 | :: 79 | ++ on-save on-save:ag 80 | :: 81 | ++ on-load 82 | |= old-state=vase 83 | =^ cards agent (on-load:ag old-state) 84 | =/ new-cards (bind-cards verb bowl cards bindings) 85 | [new-cards this] 86 | :: 87 | ++ on-poke 88 | |= [=mark =vase] 89 | ?. ?=(%handle-http-response mark) 90 | =^ cards agent (on-poke:ag mark vase) 91 | [cards this] 92 | =+ !<([eyre-id=@ta pay=simple-payload:http] vase) 93 | :_(this (give-simple-payload:app:server eyre-id pay)) 94 | :: 95 | ++ on-peek 96 | |= =path 97 | ^- (unit (unit cage)) 98 | ?. ?=([@ %bind *] path) 99 | (on-peek:ag path) 100 | ?+ path [~ ~] 101 | [%x %bind %our ~] 102 | :- ~ :- ~ :- %json !> 103 | :- %a 104 | %+ turn ~(tap in (ours bowl)) 105 | |= =binding:eyre 106 | ^- json 107 | [%s (binding-to-cord binding)] 108 | :: 109 | [%x %bind %all ~] 110 | :- ~ :- ~ :- %json !> 111 | %- pairs:enjs:format 112 | %+ turn ~(tap by (existing bowl)) 113 | |= [=binding:eyre * =action:eyre] 114 | ^- [@t json] 115 | :- (binding-to-cord binding) 116 | ?- -.action 117 | %gen [%s (crip "desk: {}")] 118 | %app [%s (crip "app: {}")] 119 | %authentication [%s '%authentication'] 120 | %logout [%s '%logout'] 121 | %channel [%s '%channel'] 122 | %scry [%s '%scry'] 123 | %name [%s '%name'] 124 | %four-oh-four [%s '%four-oh-four'] 125 | %eauth [%s '%eauth'] 126 | %host [%s '%host'] 127 | == 128 | == 129 | :: 130 | ++ on-watch 131 | |= =path 132 | ?: ?=([%http-response *] path) 133 | [~ this] 134 | =^ cards agent (on-watch:ag path) 135 | [cards this] 136 | :: 137 | ++ on-leave 138 | |= =path 139 | =^ cards agent (on-leave:ag path) 140 | [cards this] 141 | :: 142 | ++ on-agent 143 | |= [=wire =sign:agent:gall] 144 | =^ cards agent (on-agent:ag wire sign) 145 | [cards this] 146 | :: 147 | ++ on-arvo 148 | |= [=wire =sign-arvo] 149 | ?. ?=([%eyre %bound *] sign-arvo) 150 | =^ cards agent (on-arvo:ag wire sign-arvo) 151 | [cards this] 152 | ~? >> verb 153 | ^- @t 154 | ?: accepted.sign-arvo 155 | %: rap 3 156 | dap.bowl ': ' 157 | (binding-to-cord binding.sign-arvo) 158 | ' successfully bound!' 159 | ~ 160 | == 161 | %: rap 3 162 | dap.bowl ': ' 163 | (binding-to-cord binding.sign-arvo) 164 | ' failed to bind!' 165 | ~ 166 | == 167 | [~ this] 168 | :: 169 | ++ on-fail 170 | |= [=term =tang] 171 | =^ cards agent (on-fail:ag term tang) 172 | [cards this] 173 | -- 174 | -- 175 | -------------------------------------------------------------------------------- /archive/desk/mar/txt.hoon: -------------------------------------------------------------------------------- 1 | :: 2 | :::: /hoon/txt/mar 3 | :: 4 | /? 310 5 | :: 6 | =, clay 7 | =, differ 8 | =, format 9 | =, mimes:html 10 | |_ txt=wain 11 | :: 12 | ++ grab :: convert from 13 | |% 14 | ++ mime |=((pair mite octs) (to-wain q.q)) 15 | ++ noun wain :: clam from %noun 16 | -- 17 | ++ grow 18 | => v=. 19 | |% 20 | ++ mime => v [/text/plain (as-octs (of-wain txt))] 21 | ++ elem => v ;pre: {(trip (of-wain txt))} 22 | -- 23 | ++ grad 24 | |% 25 | ++ form %txt-diff 26 | ++ diff 27 | |= tyt=wain 28 | ^- (urge cord) 29 | (lusk txt tyt (loss txt tyt)) 30 | :: 31 | ++ pact 32 | |= dif=(urge cord) 33 | ~| [%pacting dif] 34 | ^- wain 35 | (lurk txt dif) 36 | :: 37 | ++ join 38 | |= [ali=(urge cord) bob=(urge cord)] 39 | ^- (unit (urge cord)) 40 | |^ 41 | =. ali (clean ali) 42 | =. bob (clean bob) 43 | |- ^- (unit (urge cord)) 44 | ?~ ali `bob 45 | ?~ bob `ali 46 | ?- -.i.ali 47 | %& 48 | ?- -.i.bob 49 | %& 50 | ?: =(p.i.ali p.i.bob) 51 | %+ bind $(ali t.ali, bob t.bob) 52 | |=(cud=(urge cord) [i.ali cud]) 53 | ?: (gth p.i.ali p.i.bob) 54 | %+ bind $(p.i.ali (sub p.i.ali p.i.bob), bob t.bob) 55 | |=(cud=(urge cord) [i.bob cud]) 56 | %+ bind $(ali t.ali, p.i.bob (sub p.i.bob p.i.ali)) 57 | |=(cud=(urge cord) [i.ali cud]) 58 | :: 59 | %| 60 | ?: =(p.i.ali (lent p.i.bob)) 61 | %+ bind $(ali t.ali, bob t.bob) 62 | |=(cud=(urge cord) [i.bob cud]) 63 | ?: (gth p.i.ali (lent p.i.bob)) 64 | %+ bind $(p.i.ali (sub p.i.ali (lent p.i.bob)), bob t.bob) 65 | |=(cud=(urge cord) [i.bob cud]) 66 | ~ 67 | == 68 | :: 69 | %| 70 | ?- -.i.bob 71 | %| 72 | ?. =(i.ali i.bob) 73 | ~ 74 | %+ bind $(ali t.ali, bob t.bob) 75 | |=(cud=(urge cord) [i.ali cud]) 76 | :: 77 | %& 78 | ?: =(p.i.bob (lent p.i.ali)) 79 | %+ bind $(ali t.ali, bob t.bob) 80 | |=(cud=(urge cord) [i.ali cud]) 81 | ?: (gth p.i.bob (lent p.i.ali)) 82 | %+ bind $(ali t.ali, p.i.bob (sub p.i.bob (lent p.i.ali))) 83 | |=(cud=(urge cord) [i.ali cud]) 84 | ~ 85 | == 86 | == 87 | ++ clean :: clean 88 | |= wig=(urge cord) 89 | ^- (urge cord) 90 | ?~ wig ~ 91 | ?~ t.wig wig 92 | ?: ?=(%& -.i.wig) 93 | ?: ?=(%& -.i.t.wig) 94 | $(wig [[%& (add p.i.wig p.i.t.wig)] t.t.wig]) 95 | [i.wig $(wig t.wig)] 96 | ?: ?=(%| -.i.t.wig) 97 | $(wig [[%| (welp p.i.wig p.i.t.wig) (welp q.i.wig q.i.t.wig)] t.t.wig]) 98 | [i.wig $(wig t.wig)] 99 | -- 100 | :: 101 | ++ mash 102 | |= $: [als=ship ald=desk ali=(urge cord)] 103 | [bos=ship bod=desk bob=(urge cord)] 104 | == 105 | ^- (urge cord) 106 | |^ 107 | =. ali (clean ali) 108 | =. bob (clean bob) 109 | |- ^- (urge cord) 110 | ?~ ali bob 111 | ?~ bob ali 112 | ?- -.i.ali 113 | %& 114 | ?- -.i.bob 115 | %& 116 | ?: =(p.i.ali p.i.bob) 117 | [i.ali $(ali t.ali, bob t.bob)] 118 | ?: (gth p.i.ali p.i.bob) 119 | [i.bob $(p.i.ali (sub p.i.ali p.i.bob), bob t.bob)] 120 | [i.ali $(ali t.ali, p.i.bob (sub p.i.bob p.i.ali))] 121 | :: 122 | %| 123 | ?: =(p.i.ali (lent p.i.bob)) 124 | [i.bob $(ali t.ali, bob t.bob)] 125 | ?: (gth p.i.ali (lent p.i.bob)) 126 | [i.bob $(p.i.ali (sub p.i.ali (lent p.i.bob)), bob t.bob)] 127 | =/ [fic=(unce cord) ali=(urge cord) bob=(urge cord)] 128 | (resolve ali bob) 129 | [fic $(ali ali, bob bob)] 130 | :: ~ :: here, alice is good for a while, but not for the whole 131 | == :: length of bob's changes 132 | :: 133 | %| 134 | ?- -.i.bob 135 | %| 136 | =/ [fic=(unce cord) ali=(urge cord) bob=(urge cord)] 137 | (resolve ali bob) 138 | [fic $(ali ali, bob bob)] 139 | :: 140 | %& 141 | ?: =(p.i.bob (lent p.i.ali)) 142 | [i.ali $(ali t.ali, bob t.bob)] 143 | ?: (gth p.i.bob (lent p.i.ali)) 144 | [i.ali $(ali t.ali, p.i.bob (sub p.i.bob (lent p.i.ali)))] 145 | =/ [fic=(unce cord) ali=(urge cord) bob=(urge cord)] 146 | (resolve ali bob) 147 | [fic $(ali ali, bob bob)] 148 | == 149 | == 150 | :: 151 | ++ annotate :: annotate conflict 152 | |= $: ali=(list @t) 153 | bob=(list @t) 154 | bas=(list @t) 155 | == 156 | ^- (list @t) 157 | %- zing 158 | ^- (list (list @t)) 159 | %- flop 160 | ^- (list (list @t)) 161 | :- :_ ~ 162 | %^ cat 3 '<<<<<<<<<<<<' 163 | %^ cat 3 ' ' 164 | %^ cat 3 `@t`(scot %p bos) 165 | %^ cat 3 '/' 166 | bod 167 | 168 | :- bob 169 | :- ~['------------'] 170 | :- bas 171 | :- ~['++++++++++++'] 172 | :- ali 173 | :- :_ ~ 174 | %^ cat 3 '>>>>>>>>>>>>' 175 | %^ cat 3 ' ' 176 | %^ cat 3 `@t`(scot %p als) 177 | %^ cat 3 '/' 178 | ald 179 | ~ 180 | :: 181 | ++ clean :: clean 182 | |= wig=(urge cord) 183 | ^- (urge cord) 184 | ?~ wig ~ 185 | ?~ t.wig wig 186 | ?: ?=(%& -.i.wig) 187 | ?: ?=(%& -.i.t.wig) 188 | $(wig [[%& (add p.i.wig p.i.t.wig)] t.t.wig]) 189 | [i.wig $(wig t.wig)] 190 | ?: ?=(%| -.i.t.wig) 191 | $(wig [[%| (welp p.i.wig p.i.t.wig) (welp q.i.wig q.i.t.wig)] t.t.wig]) 192 | [i.wig $(wig t.wig)] 193 | :: 194 | ++ resolve 195 | |= [ali=(urge cord) bob=(urge cord)] 196 | ^- [fic=[%| p=(list cord) q=(list cord)] ali=(urge cord) bob=(urge cord)] 197 | =- [[%| bac (annotate alc boc bac)] ali bob] 198 | |- ^- $: $: bac=(list cord) 199 | alc=(list cord) 200 | boc=(list cord) 201 | == 202 | ali=(urge cord) 203 | bob=(urge cord) 204 | == 205 | ?~ ali [[~ ~ ~] ali bob] 206 | ?~ bob [[~ ~ ~] ali bob] 207 | ?- -.i.ali 208 | %& 209 | ?- -.i.bob 210 | %& [[~ ~ ~] ali bob] :: no conflict 211 | %| 212 | =+ lob=(lent p.i.bob) 213 | ?: =(lob p.i.ali) 214 | [[p.i.bob p.i.bob q.i.bob] t.ali t.bob] 215 | ?: (lth lob p.i.ali) 216 | [[p.i.bob p.i.bob q.i.bob] [[%& (sub p.i.ali lob)] t.ali] t.bob] 217 | =+ wat=(scag (sub lob p.i.ali) p.i.bob) 218 | =+ ^= res 219 | %= $ 220 | ali t.ali 221 | bob [[%| (scag (sub lob p.i.ali) p.i.bob) ~] t.bob] 222 | == 223 | :* :* (welp bac.res wat) 224 | (welp alc.res wat) 225 | (welp boc.res q.i.bob) 226 | == 227 | ali.res 228 | bob.res 229 | == 230 | == 231 | :: 232 | %| 233 | ?- -.i.bob 234 | %& 235 | =+ loa=(lent p.i.ali) 236 | ?: =(loa p.i.bob) 237 | [[p.i.ali q.i.ali p.i.ali] t.ali t.bob] 238 | ?: (lth loa p.i.bob) 239 | [[p.i.ali q.i.ali p.i.ali] t.ali [[%& (sub p.i.bob loa)] t.bob]] 240 | =+ wat=(slag (sub loa p.i.bob) p.i.ali) 241 | =+ ^= res 242 | %= $ 243 | ali [[%| (scag (sub loa p.i.bob) p.i.ali) ~] t.ali] 244 | bob t.bob 245 | == 246 | :* :* (welp bac.res wat) 247 | (welp alc.res q.i.ali) 248 | (welp boc.res wat) 249 | == 250 | ali.res 251 | bob.res 252 | == 253 | :: 254 | %| 255 | =+ loa=(lent p.i.ali) 256 | =+ lob=(lent p.i.bob) 257 | ?: =(loa lob) 258 | [[p.i.ali q.i.ali q.i.bob] t.ali t.bob] 259 | =+ ^= res 260 | ?: (gth loa lob) 261 | $(ali [[%| (scag (sub loa lob) p.i.ali) ~] t.ali], bob t.bob) 262 | ~& [%scagging loa=loa pibob=p.i.bob slag=(scag loa p.i.bob)] 263 | $(ali t.ali, bob [[%| (scag (sub lob loa) p.i.bob) ~] t.bob]) 264 | :* :* (welp bac.res ?:((gth loa lob) p.i.bob p.i.ali)) 265 | (welp alc.res q.i.ali) 266 | (welp boc.res q.i.bob) 267 | == 268 | ali.res 269 | bob.res 270 | == 271 | == 272 | == 273 | -- 274 | -- 275 | -- 276 | -------------------------------------------------------------------------------- /bare-desk/lib/ventio.hoon: -------------------------------------------------------------------------------- 1 | /- spider 2 | /+ *strandio 3 | =, tid=tid:rand 4 | |% 5 | +$ vent-id (trel @p tid @da) 6 | :: 7 | +$ request (pair vent-id page) 8 | +$ package 9 | $: =dock :: destination ship/agent 10 | input=[=desk =mark] :: mark of input and its location 11 | output=[=desk =mark] :: mark of output and its location 12 | body=json :: actual data to send to agent in vent-request 13 | == 14 | :: track your vents so you can make unique vent-ids 15 | :: 16 | +$ vents (jug dock vent-id) 17 | :: 18 | ++ unique-vent 19 | |= [=dock =vents our=@p =tid now=@da] 20 | ^- vent-id 21 | ?. (~(has ju vents) dock [our tid now]) 22 | [our tid now] 23 | $(now +(now)) 24 | :: 25 | ++ en-path 26 | |= vid=vent-id 27 | ^- path 28 | /vent/(scot %p p.vid)/[q.vid]/(scot %da r.vid) 29 | :: 30 | ++ de-path 31 | |= =path 32 | ^- vent-id 33 | =+ ;;([%vent p=@ta q=@ta r=@ta ~] path) 34 | [(slav %p p.-) q.- (slav %da r.-)] 35 | :: translates poke-ack to vent for regular poke 36 | :: 37 | ++ just-poke 38 | |= [=dock =cage] 39 | =/ m (strand ,vase) 40 | ^- form:m 41 | ;< ~ bind:m (poke dock cage) 42 | (pure:m !>(~)) 43 | :: 44 | ++ unpackage 45 | |= [body=json =desk =mark] 46 | =/ m (strand ,page) 47 | ^- form:m 48 | ;< =tube:clay bind:m (build-our-tube desk %json mark) 49 | (pure:m [mark q:(tube !>(body))]) 50 | :: 51 | ++ unpage 52 | |= =page 53 | =/ m (strand ,vase) 54 | ^- form:m 55 | =/ warning 56 | ?: ?=(~ (mole |.(;;(type -.q.page)))) [0 ~] 57 | [2 leaf+"WARNING: unpage may be passing cage"] 58 | ~> %slog.warning 59 | ;< byk=beak:spider bind:m get-beak 60 | ;< =tube:clay bind:m (build-our-tube q.byk %noun p.page) 61 | ;< ~ bind:m (trace (cat 3 'mark: ' p.page) ~) 62 | (pure:m (tube !>(q.page))) 63 | :: vap (local venter agent) must be %[desk-name]-venter 64 | :: 65 | ++ get-vap 66 | =/ m (strand ,dude:gall) 67 | ^- form:m 68 | ;< =desk bind:m get-desk 69 | =/ vap=dude:gall (cat 3 desk '-venter') 70 | ;< dudes=(set [=dude:gall live=?]) bind:m 71 | (scry ,(set [dude:gall ?]) /ge/[desk]/$) 72 | ?: (~(has in dudes) [vap &]) 73 | (pure:m vap) 74 | ~|("{(trip vap)} is not running" !!) 75 | :: 76 | ++ vent-soft 77 | |= [=dock req=page] 78 | =/ m (strand ,thread-result) 79 | ^- form:m 80 | ;< vap=dude:gall bind:m get-vap :: get local venter agent 81 | :: get existing vents 82 | :: 83 | ;< =vents bind:m (scry vents /gx/[vap]/vents/noun) 84 | :: define the vent id 85 | :: 86 | ;< =bowl:strand bind:m get-bowl 87 | =/ vid=vent-id (unique-vent dock vents [our tid now]:bowl) 88 | :: listen for updates along this path 89 | :: 90 | =/ vent-path=path (en-path vid) 91 | ;< ~ bind:m (watch vent-path dock vent-path) 92 | :: tally the vent-path 93 | :: 94 | ;< ~ bind:m (poke [our.bowl vap] tally-vent+!>([dock vid])) 95 | :: poke the agent on the destination ship with the vent id and page 96 | :: 97 | ;< p=(unit tang) bind:m (poke-soft dock vent-request+!>([vid req])) 98 | ?^ p 99 | :: clear the vent-path 100 | :: 101 | ;< ~ bind:m (poke [our.bowl vap] clear-vent+!>([dock vid])) 102 | (pure:m %| [%vent-request-poke-fail u.p]) 103 | :: take vent update on vent-path 104 | :: 105 | ;< rep=cage bind:m (take-fact vent-path) 106 | ;< ~ bind:m (take-kick vent-path) 107 | :: clear the vent-path 108 | :: 109 | ;< ~ bind:m (poke [our.bowl vap] clear-vent+!>([dock vid])) 110 | :: 111 | :: return vent result or error 112 | :: 113 | ?. ?=(%goof p.rep) 114 | ~? >>> !?=(%noun p.rep) 115 | %venting-unexpected-mark 116 | (pure:m %& q.rep) 117 | (pure:m %| !<(goof q.rep)) 118 | :: 119 | ++ vent-raw 120 | |= [=dock req=page] 121 | =/ m (strand ,vase) 122 | ^- form:m 123 | ;< =thread-result bind:m (vent-soft dock req) 124 | ?- -.thread-result 125 | %& (pure:m p.thread-result) 126 | %| (strand-fail p.thread-result) 127 | == 128 | :: 129 | ++ vent-as-mark 130 | |= [=desk =mark] 131 | |= [=dock =page] 132 | =/ m (strand ,vase) 133 | ^- form:m 134 | ;< =vase bind:m (vent-raw dock page) 135 | ;< =tube:clay bind:m (build-our-tube desk %noun mark) 136 | (pure:m (tube vase)) 137 | :: 138 | ++ vent 139 | |* a=mold 140 | =/ m (strand ,a) 141 | |= [=dock =page] 142 | ^- form:m 143 | ;< =vase bind:m (vent-raw dock p.page q.page) 144 | (pure:m ;;(a q.vase)) 145 | :: generic thread for vent-based "thread-pokes": 146 | :: flexible but less performant 147 | :: performance issues SIGNIFICANTLY ameliorated with tube-warming: 148 | :: https://github.com/tinnus-napbus/tube-warmer 149 | :: check this with: |pass [%c %stir %verb 1] 150 | :: /ted/venter.hoon 151 | :: /+ *ventio 152 | :: venter 153 | :: 154 | ++ venter 155 | =, strand=strand:spider 156 | ^- thread:spider 157 | |= arg=vase 158 | =/ m (strand ,vase) 159 | ^- form:m 160 | =/ pak=(unit package) !<((unit package) arg) 161 | ?~ pak (strand-fail %no-arg ~) 162 | =+ u.pak :: expose dock, input, output, and body 163 | ;< =page bind:m (unpackage body input) 164 | ;< =vase bind:m ((vent-as-mark output) dock page) 165 | :: convert to json - this allows for generic 166 | :: /spider/realm/venter-package/vent/json thread format 167 | :: 168 | ;< =tube:clay bind:m (build-our-tube desk.output mark.output %json) 169 | (pure:m (tube vase)) 170 | :: 171 | +$ vine $-([gowl vent-id cage] shed:khan) 172 | :: 173 | ++ vine-thread 174 | |= =vine 175 | =, strand=strand:spider 176 | ^- thread:spider 177 | |= arg=vase 178 | =/ m (strand ,vase) 179 | ^- form:m 180 | =+ !<(req=(unit [gowl request]) arg) 181 | ?~ req (strand-fail %no-arg ~) 182 | =/ [=gowl vid=vent-id =mark =noun] u.req 183 | ;< =vase bind:m (unpage mark noun) 184 | (vine gowl vid mark vase) 185 | :: miscellaneous utils 186 | :: 187 | +$ gowl bowl:gall :: gall bowl alias 188 | +$ sowl bowl:spider :: spider bowl alias 189 | :: common vase strand functions 190 | :: 191 | ++ vand (strand ,vase) 192 | ++ form-m form:vand 193 | ++ bind-m bind:vand 194 | ++ pure-m pure:vand 195 | :: 196 | ++ get-tid 197 | =/ m (strand ,tid) 198 | ^- form:m 199 | |= tin=strand-input:strand 200 | `[%done tid.bowl.tin] 201 | :: 202 | ++ get-desk 203 | =/ m (strand ,desk) 204 | ^- form:m 205 | |= tin=strand-input:strand 206 | `[%done q.byk.bowl.tin] 207 | :: only works for agents which use lib/vent.hoon agent transformer 208 | :: 209 | ++ agent-send-cards 210 | |= [=dude:gall cards=(list card:agent:gall)] 211 | =/ m (strand ,~) 212 | ^- form:m 213 | ;< our=@p bind:m get-our 214 | (poke [our dude] send-cards+!>(`noun`cards)) 215 | :: 216 | ++ agent-send-card 217 | |= [=dude:gall =card:agent:gall] 218 | =/ m (strand ,~) 219 | ^- form:m 220 | (agent-send-cards dude ~[card]) 221 | :: watch from an agent (goes into wex.bowl) 222 | :: 223 | ++ agent-watch-path 224 | |= [=dude:gall =wire =dock =path] 225 | =/ m (strand ,~) 226 | ^- form:m 227 | |^ 228 | :: watch dude for on-agent updates 229 | :: 230 | ;< our=ship bind:m get-our 231 | ;< ~ bind:m (watch /[dude]/vent-on-agent [our dude] /vent-on-agent) 232 | :: send %watch card 233 | :: 234 | =/ =card:agent:gall [%pass wire %agent dock %watch path] 235 | ;< ~ bind:m (agent-send-card dude card) 236 | :: catch the %watch-ack 237 | :: 238 | ;< [=bowl:gall wyre=^wire =sign:agent:gall] bind:m take-watch-ack 239 | ?> ?=(%watch-ack -.sign) 240 | ?~ p.sign 241 | (pure:m ~) 242 | (strand-fail %agent-watch-ack-fail u.p.sign) 243 | :: 244 | ++ take-watch-ack 245 | %- %^ take-special-fact 246 | /[dude]/vent-on-agent 247 | %noun 248 | ,[bowl:gall ^wire sign:agent:gall] 249 | |= [=bowl:gall wyre=^wire =sign:agent:gall] 250 | &(=(wyre wire) ?=(%watch-ack -.sign)) 251 | -- 252 | :: 253 | ++ take-special-fact 254 | |* [=wire =mark =mold] 255 | |= take=$-(mold ?) 256 | =/ m (strand ,mold) 257 | ^- form:m 258 | |= tin=strand-input:strand 259 | ?+ in.tin `[%skip ~] 260 | ~ `[%wait ~] 261 | [~ %agent * %fact *] 262 | ?. =(watch+wire wire.u.in.tin) 263 | `[%skip ~] 264 | ?. =(mark p.cage.sign.u.in.tin) 265 | `[%skip ~] 266 | =+ ;;(a=mold q.cage.sign.u.in.tin) 267 | ?. (take a) 268 | `[%skip ~] 269 | `[%done a] 270 | == 271 | :: 272 | ++ build-our-tube 273 | |= [des=desk =mars:clay] 274 | =/ m (strand ,tube:clay) 275 | ^- form:m 276 | ;< our=ship bind:m get-our 277 | ;< now=time bind:m get-time 278 | (build-tube [our des da+now] mars) 279 | :: this works -- strandio's +await-thread doesn't seem to... 280 | :: 281 | ++ run-thread-soft 282 | |= [=desk file=term args=vase] 283 | =/ m (strand ,thread-result) 284 | ^- form:m 285 | ;< =bowl:spider bind:m get-bowl 286 | =/ tid (scot %ta (cat 3 'strand_' (scot %uv (sham desk file eny.bowl)))) 287 | =. q.byk.bowl desk 288 | =/ poke-vase !>(`start-args:spider`[`tid.bowl `tid byk.bowl file args]) 289 | ;< ~ bind:m (watch-our /awaiting/[tid] %spider /thread-result/[tid]) 290 | ;< ~ bind:m (poke-our %spider %spider-start poke-vase) 291 | ;< =cage bind:m (take-fact /awaiting/[tid]) 292 | ;< ~ bind:m (take-kick /awaiting/[tid]) 293 | ?+ p.cage ~|([%strange-thread-result p.cage file tid] !!) 294 | %thread-done (pure:m %& q.cage) 295 | %thread-fail (pure:m %| ;;([term tang] q.q.cage)) 296 | == 297 | :: 298 | ++ run-thread 299 | |= [=desk file=term args=vase] 300 | =/ m (strand ,vase) 301 | ^- form:m 302 | ;< =thread-result bind:m (run-thread-soft desk file args) 303 | ?- -.thread-result 304 | %& (pure:m p.thread-result) 305 | %| (strand-fail p.thread-result) 306 | == 307 | :: printf utils 308 | :: 309 | ++ vase-to-wain |=(=vase `wain`(turn (wash [0 80] (sell vase)) crip)) 310 | ++ vase-to-cord |=(=vase (of-wain:format (vase-to-wain vase))) 311 | :: TODO: FIX: continues to pulse when thread dies? 312 | :: 313 | ++ pulse-message 314 | |* computation-result=mold 315 | =/ m (strand ,computation-result) 316 | |= [=cord time=@dr computation=form:m] 317 | ^- form:m 318 | ;< now=@da bind:m get-time 319 | =/ when (add now time) 320 | =/ =card:agent:gall 321 | [%pass /pulse/(scot %da when) %arvo %b %wait when] 322 | ;< ~ bind:m (send-raw-card card) 323 | |= tin=strand-input:strand 324 | =/ c-res (computation tin) 325 | :: if done or failed, cancel timer and return result 326 | :: 327 | ?: ?=(?(%done %fail) -.next.c-res) 328 | =/ =card:agent:gall 329 | [%pass /pulse/(scot %da when) %arvo %b %rest when] 330 | c-res(cards [card cards.c-res]) 331 | :: received pulse timer wake 332 | :: 333 | ?. ?& ?=([~ %sign [%pulse @ ~] %behn %wake *] in.tin) 334 | =((scot %da when) i.t.wire.u.in.tin) 335 | == 336 | :: if continuing, modify self to be like this code 337 | :: 338 | =? c-res ?=(%cont -.next.c-res) 339 | c-res(self.next ..$(computation self.next.c-res)) 340 | c-res 341 | :: print the message 342 | :: 343 | %- (slog cord ~) 344 | :: set a new pulse timer 345 | :: 346 | =. when (add now.bowl.tin time) 347 | =/ =card:agent:gall 348 | [%pass /pulse/(scot %da when) %arvo %b %wait when] 349 | =. cards.c-res [card cards.c-res] 350 | :: propagate state changes (when) 351 | :: 352 | ?- -.next.c-res 353 | %cont c-res(self.next ..$(computation self.next.c-res)) 354 | ?(%skip %wait) c-res(next [%cont ..$]) 355 | == 356 | :: 357 | ++ take-poke-ack-soft 358 | |= =wire 359 | =/ m (strand ,(unit tang)) 360 | ^- form:m 361 | |= tin=strand-input:strand 362 | ?+ in.tin `[%skip ~] 363 | ~ `[%wait ~] 364 | [~ %agent * %poke-ack *] 365 | ?. =(wire wire.u.in.tin) 366 | `[%skip ~] 367 | `[%done p.sign.u.in.tin] 368 | == 369 | :: 370 | ++ poke-soft 371 | |= [=dock =cage] 372 | =/ m (strand ,(unit tang)) 373 | ^- form:m 374 | =/ =card:agent:gall [%pass /poke %agent dock %poke cage] 375 | ;< ~ bind:m (send-raw-card card) 376 | (take-poke-ack-soft /poke) 377 | :: These won't crash spider if the scry fails 378 | :: (Because a different agent, %venter, is responsible for scrying...) 379 | :: 380 | ++ scry-soft 381 | |* [=mold =path] 382 | =/ m (strand ,(each mold goof)) 383 | ^- form:m 384 | ;< vap=dude:gall bind:m get-vap :: get local venter agent 385 | ;< our=@p bind:m get-our 386 | ;< =thread-result bind:m (vent-soft [our vap] scry+path) 387 | ?- -.thread-result 388 | %| (pure:m %| p.thread-result) 389 | %& 390 | =/ res (mole |.(;;(mold q.p.thread-result))) 391 | ?~ res (pure:m %| %error-molding-scry-result ~) 392 | (pure:m %& u.res) 393 | == 394 | :: 395 | ++ scry-hard 396 | |* [=mold =path] 397 | =/ m (strand ,mold) 398 | ^- form:m 399 | ;< a=(each mold goof) bind:m (scry-soft mold path) 400 | ?- -.a 401 | %& (pure:m p.a) 402 | %| (strand-fail p.a) 403 | == 404 | :: 405 | ++ unit-scry 406 | |* [=mold =path] 407 | =/ m (strand ,(unit mold)) 408 | ^- form:m 409 | ;< a=(each mold goof) bind:m (scry-soft mold path) 410 | ?. -.a 411 | (pure:m ~) 412 | (pure:m `p.a) 413 | :: 414 | ++ pass-arvo 415 | |= [=wire =note-arvo] 416 | =/ m (strand ,~) 417 | ^- form:m 418 | (send-raw-card %pass wire %arvo note-arvo) 419 | :: 420 | ++ take-sign 421 | |= =wire 422 | =/ m (strand ,sign-arvo) 423 | ^- form:m 424 | |= tin=strand-input:strand 425 | ?+ in.tin `[%skip ~] 426 | ~ `[%wait ~] 427 | [~ %sign *] 428 | ?. =(wire wire.u.in.tin) 429 | `[%skip ~] 430 | `[%done sign-arvo.u.in.tin] 431 | == 432 | :: 433 | ++ take-fact-or-kick 434 | |= =wire 435 | =/ m (strand ,(unit cage)) 436 | ^- form:m 437 | |= tin=strand-input:strand 438 | ?+ in.tin `[%skip ~] 439 | ~ `[%wait ~] 440 | :: 441 | [~ %agent * %fact *] 442 | ?. =(watch+wire wire.u.in.tin) 443 | `[%skip ~] 444 | `[%done `cage.sign.u.in.tin] 445 | :: 446 | [~ %agent * %kick *] 447 | ?. =(watch+wire wire.u.in.tin) 448 | `[%skip ~] 449 | `[%done ~] 450 | == 451 | :: 452 | +$ iris-response [=response-header:http data=(unit mime)] 453 | :: 454 | ++ de-mite |=(=@t `(unit mite)`(rush (cat 3 '/' t) stap)) 455 | :: 456 | ++ send-iris-request 457 | |= [=request:http lag=@dr] 458 | =/ m (strand ,iris-response) 459 | ^- form:m 460 | %+ (set-timeout ,iris-response) lag 461 | =/ =task:iris [%request request *outbound-config:iris] 462 | =/ =card:agent:gall [%pass /http-req %arvo %i task] 463 | ;< ~ bind:m (send-raw-card card) 464 | ;< =sign-arvo bind:m (take-sign /http-req) 465 | ?. ?=([%iris %http-response %finished *] sign-arvo) 466 | (strand-fail:strand %bad-sign ~) 467 | =+ client-response.sign-arvo 468 | ?~ full-file 469 | (pure:m [response-header ~]) 470 | =/ =mite (fall (de-mite type.u.full-file) /text/plain) 471 | (pure:m [response-header `[mite data.u.full-file]]) 472 | :: Write to Clay 473 | :: 474 | ++ insert-file 475 | |= [=desk =path =cage] 476 | =/ m (strand ,~) 477 | ^- form:m 478 | (send-raw-card %pass /info %arvo %c %info desk %& [path %ins cage]~) 479 | :: 480 | ++ mutate-file 481 | |= [=desk =path =cage] 482 | =/ m (strand ,~) 483 | ^- form:m 484 | (send-raw-card %pass /info %arvo %c %info desk %& [path %mut cage]~) 485 | -- 486 | -------------------------------------------------------------------------------- /venter/lib/ventio.hoon: -------------------------------------------------------------------------------- 1 | /- spider 2 | /+ *strandio 3 | =, tid=tid:rand 4 | |% 5 | +$ vent-id (trel @p tid @da) 6 | :: 7 | +$ request (pair vent-id page) 8 | +$ package 9 | $: =dock :: destination ship/agent 10 | input=[=desk =mark] :: mark of input and its location 11 | output=[=desk =mark] :: mark of output and its location 12 | body=json :: actual data to send to agent in vent-request 13 | == 14 | :: track your vents so you can make unique vent-ids 15 | :: 16 | +$ vents (jug dock vent-id) 17 | :: 18 | ++ unique-vent 19 | |= [=dock =vents our=@p =tid now=@da] 20 | ^- vent-id 21 | ?. (~(has ju vents) dock [our tid now]) 22 | [our tid now] 23 | $(now +(now)) 24 | :: 25 | ++ en-path 26 | |= vid=vent-id 27 | ^- path 28 | /vent/(scot %p p.vid)/[q.vid]/(scot %da r.vid) 29 | :: 30 | ++ de-path 31 | |= =path 32 | ^- vent-id 33 | =+ ;;([%vent p=@ta q=@ta r=@ta ~] path) 34 | [(slav %p p.-) q.- (slav %da r.-)] 35 | :: translates poke-ack to vent for regular poke 36 | :: 37 | ++ just-poke 38 | |= [=dock =cage] 39 | =/ m (strand ,vase) 40 | ^- form:m 41 | ;< ~ bind:m (poke dock cage) 42 | (pure:m !>(~)) 43 | :: 44 | ++ unpackage 45 | |= [body=json =desk =mark] 46 | =/ m (strand ,page) 47 | ^- form:m 48 | ;< =tube:clay bind:m (build-our-tube desk %json mark) 49 | (pure:m [mark q:(tube !>(body))]) 50 | :: 51 | ++ unpage 52 | |= =page 53 | =/ m (strand ,vase) 54 | ^- form:m 55 | =/ warning 56 | ?: ?=(~ (mole |.(;;(type -.q.page)))) [0 ~] 57 | [2 leaf+"WARNING: unpage may be passing cage"] 58 | ~> %slog.warning 59 | ;< byk=beak:spider bind:m get-beak 60 | ;< =tube:clay bind:m (build-our-tube q.byk %noun p.page) 61 | ;< ~ bind:m (trace (cat 3 'mark: ' p.page) ~) 62 | (pure:m (tube !>(q.page))) 63 | :: vap (local venter agent) must be %[desk-name]-venter 64 | :: 65 | ++ get-vap 66 | =/ m (strand ,dude:gall) 67 | ^- form:m 68 | ;< =desk bind:m get-desk 69 | =/ vap=dude:gall (cat 3 desk '-venter') 70 | ;< dudes=(set [=dude:gall live=?]) bind:m 71 | (scry ,(set [dude:gall ?]) /ge/[desk]/$) 72 | ?: (~(has in dudes) [vap &]) 73 | (pure:m vap) 74 | ~|("{(trip vap)} is not running" !!) 75 | :: 76 | ++ vent-soft 77 | |= [=dock req=page] 78 | =/ m (strand ,thread-result) 79 | ^- form:m 80 | ;< vap=dude:gall bind:m get-vap :: get local venter agent 81 | :: get existing vents 82 | :: 83 | ;< =vents bind:m (scry vents /gx/[vap]/vents/noun) 84 | :: define the vent id 85 | :: 86 | ;< =bowl:strand bind:m get-bowl 87 | =/ vid=vent-id (unique-vent dock vents [our tid now]:bowl) 88 | :: listen for updates along this path 89 | :: 90 | =/ vent-path=path (en-path vid) 91 | ;< ~ bind:m (watch vent-path dock vent-path) 92 | :: tally the vent-path 93 | :: 94 | ;< ~ bind:m (poke [our.bowl vap] tally-vent+!>([dock vid])) 95 | :: poke the agent on the destination ship with the vent id and page 96 | :: 97 | ;< p=(unit tang) bind:m (poke-soft dock vent-request+!>([vid req])) 98 | ?^ p 99 | :: clear the vent-path 100 | :: 101 | ;< ~ bind:m (poke [our.bowl vap] clear-vent+!>([dock vid])) 102 | (pure:m %| [%vent-request-poke-fail u.p]) 103 | :: take vent update on vent-path 104 | :: 105 | ;< rep=cage bind:m (take-fact vent-path) 106 | ;< ~ bind:m (take-kick vent-path) 107 | :: clear the vent-path 108 | :: 109 | ;< ~ bind:m (poke [our.bowl vap] clear-vent+!>([dock vid])) 110 | :: 111 | :: return vent result or error 112 | :: 113 | ?. ?=(%goof p.rep) 114 | ~? >>> !?=(%noun p.rep) 115 | %venting-unexpected-mark 116 | (pure:m %& q.rep) 117 | (pure:m %| !<(goof q.rep)) 118 | :: 119 | ++ vent-raw 120 | |= [=dock req=page] 121 | =/ m (strand ,vase) 122 | ^- form:m 123 | ;< =thread-result bind:m (vent-soft dock req) 124 | ?- -.thread-result 125 | %& (pure:m p.thread-result) 126 | %| (strand-fail p.thread-result) 127 | == 128 | :: 129 | ++ vent-as-mark 130 | |= [=desk =mark] 131 | |= [=dock =page] 132 | =/ m (strand ,vase) 133 | ^- form:m 134 | ;< =vase bind:m (vent-raw dock page) 135 | ;< =tube:clay bind:m (build-our-tube desk %noun mark) 136 | (pure:m (tube vase)) 137 | :: 138 | ++ vent 139 | |* a=mold 140 | =/ m (strand ,a) 141 | |= [=dock =page] 142 | ^- form:m 143 | ;< =vase bind:m (vent-raw dock p.page q.page) 144 | (pure:m ;;(a q.vase)) 145 | :: generic thread for vent-based "thread-pokes": 146 | :: flexible but less performant 147 | :: performance issues SIGNIFICANTLY ameliorated with tube-warming: 148 | :: https://github.com/tinnus-napbus/tube-warmer 149 | :: check this with: |pass [%c %stir %verb 1] 150 | :: /ted/venter.hoon 151 | :: /+ *ventio 152 | :: venter 153 | :: 154 | ++ venter 155 | =, strand=strand:spider 156 | ^- thread:spider 157 | |= arg=vase 158 | =/ m (strand ,vase) 159 | ^- form:m 160 | =/ pak=(unit package) !<((unit package) arg) 161 | ?~ pak (strand-fail %no-arg ~) 162 | =+ u.pak :: expose dock, input, output, and body 163 | ;< =page bind:m (unpackage body input) 164 | ;< =vase bind:m ((vent-as-mark output) dock page) 165 | :: convert to json - this allows for generic 166 | :: /spider/realm/venter-package/vent/json thread format 167 | :: 168 | ;< =tube:clay bind:m (build-our-tube desk.output mark.output %json) 169 | (pure:m (tube vase)) 170 | :: 171 | +$ vine $-([gowl vent-id cage] shed:khan) 172 | :: 173 | ++ vine-thread 174 | |= =vine 175 | =, strand=strand:spider 176 | ^- thread:spider 177 | |= arg=vase 178 | =/ m (strand ,vase) 179 | ^- form:m 180 | =+ !<(req=(unit [gowl request]) arg) 181 | ?~ req (strand-fail %no-arg ~) 182 | =/ [=gowl vid=vent-id =mark =noun] u.req 183 | ;< =vase bind:m (unpage mark noun) 184 | (vine gowl vid mark vase) 185 | :: miscellaneous utils 186 | :: 187 | +$ gowl bowl:gall :: gall bowl alias 188 | +$ sowl bowl:spider :: spider bowl alias 189 | :: common vase strand functions 190 | :: 191 | ++ vand (strand ,vase) 192 | ++ form-m form:vand 193 | ++ bind-m bind:vand 194 | ++ pure-m pure:vand 195 | :: 196 | ++ get-tid 197 | =/ m (strand ,tid) 198 | ^- form:m 199 | |= tin=strand-input:strand 200 | `[%done tid.bowl.tin] 201 | :: 202 | ++ get-desk 203 | =/ m (strand ,desk) 204 | ^- form:m 205 | |= tin=strand-input:strand 206 | `[%done q.byk.bowl.tin] 207 | :: only works for agents which use lib/vent.hoon agent transformer 208 | :: 209 | ++ agent-send-cards 210 | |= [=dude:gall cards=(list card:agent:gall)] 211 | =/ m (strand ,~) 212 | ^- form:m 213 | ;< our=@p bind:m get-our 214 | (poke [our dude] send-cards+!>(`noun`cards)) 215 | :: 216 | ++ agent-send-card 217 | |= [=dude:gall =card:agent:gall] 218 | =/ m (strand ,~) 219 | ^- form:m 220 | (agent-send-cards dude ~[card]) 221 | :: watch from an agent (goes into wex.bowl) 222 | :: 223 | ++ agent-watch-path 224 | |= [=dude:gall =wire =dock =path] 225 | =/ m (strand ,~) 226 | ^- form:m 227 | |^ 228 | :: watch dude for on-agent updates 229 | :: 230 | ;< our=ship bind:m get-our 231 | ;< ~ bind:m (watch /[dude]/vent-on-agent [our dude] /vent-on-agent) 232 | :: send %watch card 233 | :: 234 | =/ =card:agent:gall [%pass wire %agent dock %watch path] 235 | ;< ~ bind:m (agent-send-card dude card) 236 | :: catch the %watch-ack 237 | :: 238 | ;< [=bowl:gall wyre=^wire =sign:agent:gall] bind:m take-watch-ack 239 | ?> ?=(%watch-ack -.sign) 240 | ?~ p.sign 241 | (pure:m ~) 242 | (strand-fail %agent-watch-ack-fail u.p.sign) 243 | :: 244 | ++ take-watch-ack 245 | %- %^ take-special-fact 246 | /[dude]/vent-on-agent 247 | %noun 248 | ,[bowl:gall ^wire sign:agent:gall] 249 | |= [=bowl:gall wyre=^wire =sign:agent:gall] 250 | &(=(wyre wire) ?=(%watch-ack -.sign)) 251 | -- 252 | :: 253 | ++ take-special-fact 254 | |* [=wire =mark =mold] 255 | |= take=$-(mold ?) 256 | =/ m (strand ,mold) 257 | ^- form:m 258 | |= tin=strand-input:strand 259 | ?+ in.tin `[%skip ~] 260 | ~ `[%wait ~] 261 | [~ %agent * %fact *] 262 | ?. =(watch+wire wire.u.in.tin) 263 | `[%skip ~] 264 | ?. =(mark p.cage.sign.u.in.tin) 265 | `[%skip ~] 266 | =+ ;;(a=mold q.cage.sign.u.in.tin) 267 | ?. (take a) 268 | `[%skip ~] 269 | `[%done a] 270 | == 271 | :: 272 | ++ build-our-tube 273 | |= [des=desk =mars:clay] 274 | =/ m (strand ,tube:clay) 275 | ^- form:m 276 | ;< our=ship bind:m get-our 277 | ;< now=time bind:m get-time 278 | (build-tube [our des da+now] mars) 279 | :: this works -- strandio's +await-thread doesn't seem to... 280 | :: 281 | ++ run-thread-soft 282 | |= [=desk file=term args=vase] 283 | =/ m (strand ,thread-result) 284 | ^- form:m 285 | ;< =bowl:spider bind:m get-bowl 286 | =/ tid (scot %ta (cat 3 'strand_' (scot %uv (sham desk file eny.bowl)))) 287 | =. q.byk.bowl desk 288 | =/ poke-vase !>(`start-args:spider`[`tid.bowl `tid byk.bowl file args]) 289 | ;< ~ bind:m (watch-our /awaiting/[tid] %spider /thread-result/[tid]) 290 | ;< ~ bind:m (poke-our %spider %spider-start poke-vase) 291 | ;< =cage bind:m (take-fact /awaiting/[tid]) 292 | ;< ~ bind:m (take-kick /awaiting/[tid]) 293 | ?+ p.cage ~|([%strange-thread-result p.cage file tid] !!) 294 | %thread-done (pure:m %& q.cage) 295 | %thread-fail (pure:m %| ;;([term tang] q.q.cage)) 296 | == 297 | :: 298 | ++ run-thread 299 | |= [=desk file=term args=vase] 300 | =/ m (strand ,vase) 301 | ^- form:m 302 | ;< =thread-result bind:m (run-thread-soft desk file args) 303 | ?- -.thread-result 304 | %& (pure:m p.thread-result) 305 | %| (strand-fail p.thread-result) 306 | == 307 | :: printf utils 308 | :: 309 | ++ vase-to-wain |=(=vase `wain`(turn (wash [0 80] (sell vase)) crip)) 310 | ++ vase-to-cord |=(=vase (of-wain:format (vase-to-wain vase))) 311 | :: TODO: FIX: continues to pulse when thread dies? 312 | :: 313 | ++ pulse-message 314 | |* computation-result=mold 315 | =/ m (strand ,computation-result) 316 | |= [=cord time=@dr computation=form:m] 317 | ^- form:m 318 | ;< now=@da bind:m get-time 319 | =/ when (add now time) 320 | =/ =card:agent:gall 321 | [%pass /pulse/(scot %da when) %arvo %b %wait when] 322 | ;< ~ bind:m (send-raw-card card) 323 | |= tin=strand-input:strand 324 | =/ c-res (computation tin) 325 | :: if done or failed, cancel timer and return result 326 | :: 327 | ?: ?=(?(%done %fail) -.next.c-res) 328 | =/ =card:agent:gall 329 | [%pass /pulse/(scot %da when) %arvo %b %rest when] 330 | c-res(cards [card cards.c-res]) 331 | :: received pulse timer wake 332 | :: 333 | ?. ?& ?=([~ %sign [%pulse @ ~] %behn %wake *] in.tin) 334 | =((scot %da when) i.t.wire.u.in.tin) 335 | == 336 | :: if continuing, modify self to be like this code 337 | :: 338 | =? c-res ?=(%cont -.next.c-res) 339 | c-res(self.next ..$(computation self.next.c-res)) 340 | c-res 341 | :: print the message 342 | :: 343 | %- (slog cord ~) 344 | :: set a new pulse timer 345 | :: 346 | =. when (add now.bowl.tin time) 347 | =/ =card:agent:gall 348 | [%pass /pulse/(scot %da when) %arvo %b %wait when] 349 | =. cards.c-res [card cards.c-res] 350 | :: propagate state changes (when) 351 | :: 352 | ?- -.next.c-res 353 | %cont c-res(self.next ..$(computation self.next.c-res)) 354 | ?(%skip %wait) c-res(next [%cont ..$]) 355 | == 356 | :: 357 | ++ take-poke-ack-soft 358 | |= =wire 359 | =/ m (strand ,(unit tang)) 360 | ^- form:m 361 | |= tin=strand-input:strand 362 | ?+ in.tin `[%skip ~] 363 | ~ `[%wait ~] 364 | [~ %agent * %poke-ack *] 365 | ?. =(wire wire.u.in.tin) 366 | `[%skip ~] 367 | `[%done p.sign.u.in.tin] 368 | == 369 | :: 370 | ++ poke-soft 371 | |= [=dock =cage] 372 | =/ m (strand ,(unit tang)) 373 | ^- form:m 374 | =/ =card:agent:gall [%pass /poke %agent dock %poke cage] 375 | ;< ~ bind:m (send-raw-card card) 376 | (take-poke-ack-soft /poke) 377 | :: These won't crash spider if the scry fails 378 | :: (Because a different agent, %venter, is responsible for scrying...) 379 | :: 380 | ++ scry-soft 381 | |* [=mold =path] 382 | =/ m (strand ,(each mold goof)) 383 | ^- form:m 384 | ;< vap=dude:gall bind:m get-vap :: get local venter agent 385 | ;< our=@p bind:m get-our 386 | ;< =thread-result bind:m (vent-soft [our vap] scry+path) 387 | ?- -.thread-result 388 | %| (pure:m %| p.thread-result) 389 | %& 390 | =/ res (mole |.(;;(mold q.p.thread-result))) 391 | ?~ res (pure:m %| %error-molding-scry-result ~) 392 | (pure:m %& u.res) 393 | == 394 | :: 395 | ++ scry-hard 396 | |* [=mold =path] 397 | =/ m (strand ,mold) 398 | ^- form:m 399 | ;< a=(each mold goof) bind:m (scry-soft mold path) 400 | ?- -.a 401 | %& (pure:m p.a) 402 | %| (strand-fail p.a) 403 | == 404 | :: 405 | ++ unit-scry 406 | |* [=mold =path] 407 | =/ m (strand ,(unit mold)) 408 | ^- form:m 409 | ;< a=(each mold goof) bind:m (scry-soft mold path) 410 | ?. -.a 411 | (pure:m ~) 412 | (pure:m `p.a) 413 | :: 414 | ++ pass-arvo 415 | |= [=wire =note-arvo] 416 | =/ m (strand ,~) 417 | ^- form:m 418 | (send-raw-card %pass wire %arvo note-arvo) 419 | :: 420 | ++ take-sign 421 | |= =wire 422 | =/ m (strand ,sign-arvo) 423 | ^- form:m 424 | |= tin=strand-input:strand 425 | ?+ in.tin `[%skip ~] 426 | ~ `[%wait ~] 427 | [~ %sign *] 428 | ?. =(wire wire.u.in.tin) 429 | `[%skip ~] 430 | `[%done sign-arvo.u.in.tin] 431 | == 432 | :: 433 | ++ take-fact-or-kick 434 | |= =wire 435 | =/ m (strand ,(unit cage)) 436 | ^- form:m 437 | |= tin=strand-input:strand 438 | ?+ in.tin `[%skip ~] 439 | ~ `[%wait ~] 440 | :: 441 | [~ %agent * %fact *] 442 | ?. =(watch+wire wire.u.in.tin) 443 | `[%skip ~] 444 | `[%done `cage.sign.u.in.tin] 445 | :: 446 | [~ %agent * %kick *] 447 | ?. =(watch+wire wire.u.in.tin) 448 | `[%skip ~] 449 | `[%done ~] 450 | == 451 | :: 452 | +$ iris-response [=response-header:http data=(unit mime)] 453 | :: 454 | ++ de-mite |=(=@t `(unit mite)`(rush (cat 3 '/' t) stap)) 455 | :: 456 | ++ send-iris-request 457 | |= [=request:http lag=@dr] 458 | =/ m (strand ,iris-response) 459 | ^- form:m 460 | %+ (set-timeout ,iris-response) lag 461 | =/ =task:iris [%request request *outbound-config:iris] 462 | =/ =card:agent:gall [%pass /http-req %arvo %i task] 463 | ;< ~ bind:m (send-raw-card card) 464 | ;< =sign-arvo bind:m (take-sign /http-req) 465 | ?. ?=([%iris %http-response %finished *] sign-arvo) 466 | (strand-fail:strand %bad-sign ~) 467 | =+ client-response.sign-arvo 468 | ?~ full-file 469 | (pure:m [response-header ~]) 470 | =/ =mite (fall (de-mite type.u.full-file) /text/plain) 471 | (pure:m [response-header `[mite data.u.full-file]]) 472 | :: Write to Clay 473 | :: 474 | ++ insert-file 475 | |= [=desk =path =cage] 476 | =/ m (strand ,~) 477 | ^- form:m 478 | (send-raw-card %pass /info %arvo %c %info desk %& [path %ins cage]~) 479 | :: 480 | ++ mutate-file 481 | |= [=desk =path =cage] 482 | =/ m (strand ,~) 483 | ^- form:m 484 | (send-raw-card %pass /info %arvo %c %info desk %& [path %mut cage]~) 485 | -- 486 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### WARNING: README under construction 2 | 3 | # the "venter" pattern 4 | 5 | ## Table of Contents 6 | 1. [Important Files](#important-files) 7 | 2. [Principles](#principles) 8 | 3. [Motivating Use Cases](#motivating-use-cases) 9 | 4. [Core Ideas](#core-ideas) 10 | 5. [Explaining the Example](#explaining-the-example) 11 | 6. [Install and test it out](#install-and-test-it-out) 12 | 7. [Use in your app](#use-in-your-app) 13 | 14 | ## Important Files 15 | - For The Venter Pattern 16 | - `/lib/ventio.hoon` 17 | - `/lib/vent.hoon` 18 | - `/ted/vines/...` 19 | - `/app/[desk-name]-venter.hoon` 20 | - `/ted/venter.hoon` 21 | - `/mar/vent-package.hoon` 22 | - `/mar/vent-request.hoon` 23 | - `/mar/goof.hoon` 24 | - `/ted/tube-warmer.hoon` 25 | - For This Example 26 | - `/sur/example.hoon` 27 | - `/app/venter-example.hoon` 28 | - `/ted/vines/venter-example.hoon` 29 | - `/ted/test.hoon` 30 | 31 | ## Principles 32 | 1. [Agents are state machines](https://urbit.org/blog/io-in-hoon), and this is 33 | ALL they should be. 34 | 2. "Actions" (i.e. things you want an agent to "do" for you) usually involve 35 | asynchronous computation, especially when the agent interacts with and 36 | composes with other agents. 37 | 3. "Actions" should be able to return a response with meaningful data. 38 | 4. Crashes which occur while an "action" is being performed should be 39 | propagated to whoever called the "action" -- even if the crash occurs in a 40 | computation which has been delegated to another agent or vane. 41 | 42 | ## Motivating Use Cases 43 | 44 | ### Agent-side ID creation 45 | Because writing request-response cycles on urbit is currently effortful, 46 | clumsy, and mildly complicated, it is common when adding data to an urbit 47 | "database" to require that a unique ID be 48 | given with a new piece of data, instead of generating a unique ID and returning 49 | it as a response. It would be more convenient on the client side to not have 50 | to worry about the generation of a unique id (or worse, to wait to learn the 51 | new id from a subscription update) and instead to be able to simply create 52 | something and receive a response with the new ID. 53 | 54 | ![Generating ID Client-Side](https://raw.githubusercontent.com/niblyx-malnus/venter-pattern/main/diagrams/images/generate_ID_client_side.png "Generating ID Client-Side") 55 | 56 | The above is the typical scenario for creating a datum with an ID on urbit. 57 | 58 | ![Generating ID Server-Side; Normal Sync Subscription](https://raw.githubusercontent.com/niblyx-malnus/venter-pattern/main/diagrams/images/server_side_normal_sync.png "Generating ID Server-Side; Normal Sync Subscription") 59 | 60 | This can happen as well, where you don't generate an ID from the client, but you try to recognize an incoming update as the datum you created and retrieve the ID from that update. 61 | 62 | ![Ideal ID Request-Response Cycle](https://raw.githubusercontent.com/niblyx-malnus/venter-pattern/main/diagrams/images/ideal_ID_request_response.png "Ideal ID Request-Response Cycle") 63 | 64 | This is the ideal case of generating an ID server-side and immediately returning it. 65 | 66 | ### Remote crash forwarding to the client 67 | It is common to forward pokes relevant to data hosted on another ship to that 68 | ship. However, in so doing, the client can no longer learn about crashes 69 | related to that poke and only learns of the success or failure of its poke 70 | to the local agent. A full request-response cycle that passes the remote 71 | failure along to the original client would be more ideal. 72 | 73 | ![Poke Forwarding With Nack](https://raw.githubusercontent.com/niblyx-malnus/venter-pattern/main/diagrams/images/poke_forwarding_nack.png "Poke Forwarding With Nack") 74 | ![Ideal Poke Forwarding](https://raw.githubusercontent.com/niblyx-malnus/venter-pattern/main/diagrams/images/ideal_poke_forwarding.png "Ideal Poke Forwarding") 75 | 76 | ### Arbitrary nesting of complete request-response cycles 77 | Once we can conceive of these complete request-response cycles, we naturally 78 | want to make them available to one another, so one request-response cycle 79 | can call maybe several others, which can call still more, and which always 80 | guarantee either a substantive response or a crash. 81 | 82 | ## Core Ideas 83 | 84 | ### Venting 85 | 86 | - The [Urbit Precepts](https://urbit.org/blog/precepts) specify that, in Urbit, 87 | "everything should be CQRS." CQRS stands for Command-Query Responsibility 88 | Segregation. In other words, Urbit organizes its program interfaces such that 89 | commands or "actions" are strongly differentiated from the retrieval of data 90 | from those programs. 91 | 92 | - Gall agents satisfy CQRS in that pokes return only a n/ack and substantive 93 | data can only be retrieved from an agent via scries or subscriptions. 94 | 95 | - Urbit's CQRS approach to program interfaces is versatile but can be 96 | impractical. A simple request-response pattern is often more ideal for 97 | routine tasks. 98 | 99 | - Scries adhere to the request-response pattern, but they are limited. 100 | They cannot alter any underlying data and they are not well-suited to 101 | "actions" which require communication and coordination between multiple 102 | programs. 103 | 104 | - The most common approach to creating a request-response cycle which can have 105 | effects within urbit and which can perform asynchronous communication is 106 | something we have taken to calling "venting". It's a pattern which exists 107 | in Eyre and in the `%spider` agent. In the context of a gall agent, it goes 108 | like this: 109 | 1. Subscribe to a path along which a response is anticipated. 110 | 2. Poke the agent, providing some data about where you are listening for a 111 | response. 112 | 3. The agent performs the relevant computations, then returns one or more 113 | facts and a kick on the relevant subscription path. 114 | 115 | - We formalize this like so: 116 | 1. Subscribe to a "vent-path" `/vent/[vent-id]` on the agent. 117 | 2. Poke the agent with a `$vent-request`, a pair of a `$vent-id` and your 118 | action. 119 | 3. The agent performs the relevant computations and returns exactly one fact 120 | and a kick on the "vent-path". The fact contains a "vent", which is 121 | defined by the programmer and can be either `~` or a head-tagged union. 122 | The null case should be interpreted as a simple "ack". 123 | 124 | ![Venter Pattern](https://raw.githubusercontent.com/niblyx-malnus/venter-pattern/main/diagrams/images/venter_pattern.png "Venter Pattern") 125 | 126 | ### Introducing Threads 127 | The whole pattern as we have described it is a tangled asynchronous rigmarole 128 | which is tedious to perform directly from a client. By its asynchronous nature 129 | it lends itself to a thread. Threads can be called via Eyre's external API and 130 | are already set up as an intuitive request-response cycle. Therefore we can 131 | call into a dedicated thread which is responsible for making "vent-request" to 132 | agents and returning their responses. 133 | 134 | ![Venter Thread](https://raw.githubusercontent.com/niblyx-malnus/venter-pattern/main/diagrams/images/venter_thread.png "Venter Thread") 135 | 136 | The Thread in this diagram is equivalent to `/ted/venter.hoon`. 137 | 138 | 139 | ### Vines 140 | The idea of vines emerges now from two sources. First, suppose we want agents 141 | in the process of "venting" to be able to make "vent-requests" to other agents. 142 | We have already seen that the simplest way to contain this "venting" logic is 143 | to delegate it to a thread. But we also notice that "venting" may not be the 144 | only asynchronous logic we may want an action to result in. It is common for us 145 | to want an agent to be responsible for an "action" which triggers multiple 146 | asynchronous events. In the most complicated cases, it is already common to 147 | delegate these to a thread. This suggests something interesting: the entire 148 | "vented" logic can be placed in a dedicated thread. 149 | 150 | It looks like this: 151 | 1. When an agent receives a $vent-request, it forwards it to a dedicated thread. 152 | 2. In the thread, we can switch on the "action" like we would in the case of a 153 | normal poke. 154 | 3. The thread returns a "vent". When the agent receives this result in its 155 | on-arvo, it returns it along the vent-path. If it receives a crash, it 156 | forwards this too. 157 | 158 | If all venting agents do things this way, the result is that arbitrarily nested 159 | "venting" request-response cycles will be guaranteed to either return a 160 | response, to return a crash or to hang (hangs can be avoided with timeouts). 161 | It also allows to start thinking in terms of asynchronous actions that agents 162 | are "responsible for." The thread dedicated to a given agent is called a 163 | "vine". 164 | 165 | ![Vine](https://raw.githubusercontent.com/niblyx-malnus/venter-pattern/main/diagrams/images/vine.png "Vine") 166 | 167 | Our agent delegates the handling of this action to its vine because the vine, 168 | as a thread, makes asynchronous computation much easier to reason about. 169 | 170 | ## Explaining The Example 171 | `[Description and explanation of the example code, adding, deleting datum, etc]` 172 | 173 | ## Install and test it out 174 | ### Installation 175 | 1. Clone this repo. 176 | 2. Pull in the [urbit repo](https://github.com/urbit/urbit) submodule: 177 | ``` 178 | # have `git pull` also get the pinned commit of the Urbit submodule 179 | $: git config --global submodule.recurse true 180 | # init submodule, and then pull it 181 | $: git submodule update --init --recursive 182 | $: git pull 183 | ``` 184 | 3. Boot up a ship (fakezod or moon or whatever you use). 185 | 4. `|new-desk %venter` to create a new desk called `%venter`. 186 | 5. `|mount %venter` to access the `%venter` desk from the unix command line. 187 | 6. At the unix command line `rm -rf [ship-name]/venter/*` to empty out the contents of the desk. 188 | 7. `cp -rL venter/* [ship-name]/venter` to copy the contents of this repo into your new desk. 189 | 8. At the dojo command line `|commit %venter`. 190 | 9. Install with `|install our %venter`. 191 | 192 | ### Test From the Dojo 193 | 1. run `-venter!test create-datum+'some text'` in the dojo 194 | 2. receive `[%new-id id=0v6.00rd2.b1hl8.q2v45.k5vln.20tit]` with some ID of type `@uv` 195 | 3. run `-venter!test delete-datum+0v6.00rd2.b1hl8.q2v45.k5vln.20tit` with that ID 196 | 4. receive: 197 | ``` 198 | : /~tomsug-nalwet-niblyx-malnus/venter/50/delete-log/txt 199 | [ %dlog 200 | log 201 | '===============================================================================\0aVENTER EXAMPLE DELETE LOG\0a===============================================================================\0a0v6.00rd2.b1hl8.q2v45.k5vln.20tit | ~2 202 | 023.11.29..21.36.54..0bc2 | hello' 203 | ] 204 | ``` 205 | This shows that the file `/delete-log.txt` has been changed and returns its contents. 206 | 207 | ### Test From the Client 208 | 1. Go to the interface directory. 209 | 2. Edit the information `/src/api.ts` in `ship` and in `const urb` to reflect your ship and url setup. 210 | 3. Run `npm install`. 211 | 4. Run `nom start`. 212 | 5. Follow instructions in the interface. 213 | 214 | ## Use in your app 215 | 216 | ### Summary 217 | 1. Copy `/lib/vent.hoon` and `/lib/ventio.hoon` into your `/lib` directory. 218 | 2. Copy `/app/venter-venter.hoon` into your `/app` directory and change its 219 | name to be `[your-desk-name]-venter.hoon`, then put this name in your 220 | `desk.bill`. 221 | 3. Copy `/ted/venter.hoon` into your `/ted` directory. 222 | 4. Copy `/mar/vent-package.hoon`, `/mar/vent-request.hoon` and `/mar/goof.hoon` 223 | into your `/mar` directory. 224 | 5. Create your own marks in the `/mar` directory for your actions, as per usual. 225 | 6. Create a file in `/ted/vines` which shares the same name as your agent and 226 | modify it as described below. 227 | 7. Import the `/lib/vent.hoon` library into your agent and add `%- agent:vent` 228 | immediately above or below where you typically put `%- agent:dbug`. 229 | 8. Copy `/ted/tube-warmer.hoon` into your `/ted` directory. 230 | 9. Copy `/sur/spider.hoon`, `/lib/strand.hoon` and `/lib/strandio.hoon` into 231 | your `/sur` and `/lib` directories respectively. 232 | 10. Copy `/mar/thread-done.hoon`, `/mar/thread-fail.hoon` and `/mar/tang.hoon` 233 | into your `/mar` directory. 234 | 235 | ### The Libraries 236 | Copy `/lib/vent.hoon` and `/lib/ventio.hoon` into your `/lib` directory. 237 | - `/lib/vent.hoon` is a library which contains an agent transformer and some 238 | helpers which you can apply to any agent in which you want to implement the 239 | venter pattern. 240 | - `/lib/ventio.hoon` contains most of the actual venting logic and some strand 241 | functions that extend `/lib/strandio.hoon`. 242 | 243 | ### The %venter Agent 244 | Copy `/app/venter-venter.hoon` into your `/app` directory and change its name 245 | to be `[your-desk-name]-venter.hoon`, then put this name in your `desk.bill`. 246 | `/app/[your-desk-name]-venter.hoon` is responsible for making sure `vent-id`s 247 | are unique so that requests to the same agent from the same thread don't get 248 | confused. Would it be nice to have a single canonical `%venter` agent? 249 | Probably. Will this happen tomorrow? No. Would this be a hurdle to the adoption 250 | and improvement of this pattern? Yes. Therefore, keep your own desk-specific 251 | venter agent. This way it will never conflict with other venter agents that 252 | adhere to this convention. 253 | 254 | ### Client Utilities 255 | Copy `/ted/venter.hoon` into your `/ted` directory. This allows you to easily 256 | make vent-requests to agents from the frontend and receive json responses. 257 | 258 | ### The Vent Marks 259 | Copy `/mar/vent-package.hoon`, `/mar/vent-request.hoon` and `/mar/goof.hoon` 260 | into your `/mar` directory. `vent-package.hoon` is a mark for the data 261 | structure you give to the `/ted/venter.hoon` thread to make a `vent-request` 262 | from the client. `vent-request.hoon` is a mark for the `vent-request` itself. 263 | `goof.hoon` is a mark for the output of a typical crash report. 264 | 265 | ### Your Own Action and Vent Marks 266 | Create your own marks in the `/mar` directory for your actions, as per usual. 267 | Create your own marks for the `vent`s, i.e. the responses you want to return. 268 | By convention `vent`s should be either `~` or a head-tagged union. 269 | 270 | ### Vines 271 | Create a file in `/ted/vines` which shares the same name as your agent. If 272 | your agent is in `/app/some-agent.hoon`, then your vine must be 273 | `/ted/vines/some-agent.hoon`. Import the `ventio` library. You can write your 274 | thread as a thread that takes a `[bowl:gall vent-id cage]` instead of a `vase` 275 | and then pass it to `ventio`'s `vine-thread` function. The vine should return 276 | a `vent` (`~` or head-tagged union, for which you have a mark). 277 | 278 | ### Modifying Your Agent 279 | Import the `/lib/vent.hoon` library into your agent and add `%- agent:vent` 280 | immediately above or below where you typically put `%- agent:dbug`. 281 | 282 | ### `+just-poke`s and `+poke-to-vent`s 283 | If you want a poke to be redirected to a vine, add 284 | `vnt ~(. (utils:vent this) bowl)` under your agent's `+* this .` and use 285 | `(poke-to-vent:vnt mark vase)`. If you want a `vent-request` in your 286 | `/ted/vines/[agent-name].hoon` to simply poke an agent and do nothing else, 287 | use the `(just-poke dock mark vase)` to poke the agent and return a `~` on 288 | success. If you use these in tandem, take care not to create infinite loops. 289 | 290 | ### Tube Warming 291 | Copy `/ted/tube-warmer.hoon` into your `/ted` directory. Because this pattern 292 | involves a lot of mark conversions, performance is significantly improved when 293 | these conversions are already built and available. The `[desk]-venter` agent 294 | runs the `tube-warmer` thread everytime the desk changes. 295 | 296 | ### Dependencies 297 | - Copy `/sur/spider.hoon`, `/lib/strand.hoon` and `/lib/strandio.hoon` into your 298 | `/sur` and `/lib` directories respectively. 299 | - Copy `/mar/thread-done.hoon`, `/mar/thread-fail.hoon` and `/mar/tang.hoon` 300 | into your `/mar` directory. These are useful thread related marks. These 301 | should be the same as the ones in `%base`. (These may have once been actively 302 | used as part of the venter pattern, they're not anymore...) 303 | 304 | ### Constraints 305 | - The venter agent must be named `%[your-desk]-venter`. 306 | - The `vine` associated with your agent must be in the `/ted/vines` directory 307 | and it must have the same name as its corresponding agent. 308 | 309 | ## Interfacing From the Client 310 | `/interface/src/api.ts` shows how to create a simple API for venting from 311 | an agent. 312 | -------------------------------------------------------------------------------- /archive/desk/lib/strandio.hoon: -------------------------------------------------------------------------------- 1 | /- spider 2 | /+ libstrand=strand 3 | =, strand=strand:libstrand 4 | =, strand-fail=strand-fail:libstrand 5 | |% 6 | ++ send-raw-cards 7 | |= cards=(list =card:agent:gall) 8 | =/ m (strand ,~) 9 | ^- form:m 10 | |= strand-input:strand 11 | [cards %done ~] 12 | :: 13 | ++ send-raw-card 14 | |= =card:agent:gall 15 | =/ m (strand ,~) 16 | ^- form:m 17 | (send-raw-cards card ~) 18 | :: 19 | ++ ignore 20 | |= tin=strand-input:strand 21 | `[%fail %ignore ~] 22 | :: 23 | ++ get-bowl 24 | =/ m (strand ,bowl:strand) 25 | ^- form:m 26 | |= tin=strand-input:strand 27 | `[%done bowl.tin] 28 | :: 29 | ++ get-beak 30 | =/ m (strand ,beak) 31 | ^- form:m 32 | |= tin=strand-input:strand 33 | `[%done [our q.byk da+now]:bowl.tin] 34 | :: 35 | ++ get-time 36 | =/ m (strand ,@da) 37 | ^- form:m 38 | |= tin=strand-input:strand 39 | `[%done now.bowl.tin] 40 | :: 41 | ++ get-our 42 | =/ m (strand ,ship) 43 | ^- form:m 44 | |= tin=strand-input:strand 45 | `[%done our.bowl.tin] 46 | :: 47 | ++ get-entropy 48 | =/ m (strand ,@uvJ) 49 | ^- form:m 50 | |= tin=strand-input:strand 51 | `[%done eny.bowl.tin] 52 | :: 53 | :: Convert skips to %ignore failures. 54 | :: 55 | :: This tells the main loop to try the next handler. 56 | :: 57 | ++ handle 58 | |* a=mold 59 | =/ m (strand ,a) 60 | |= =form:m 61 | ^- form:m 62 | |= tin=strand-input:strand 63 | =/ res (form tin) 64 | =? next.res ?=(%skip -.next.res) 65 | [%fail %ignore ~] 66 | res 67 | :: 68 | :: Wait for a poke with a particular mark 69 | :: 70 | ++ take-poke 71 | |= =mark 72 | =/ m (strand ,vase) 73 | ^- form:m 74 | |= tin=strand-input:strand 75 | ?+ in.tin `[%skip ~] 76 | ~ 77 | `[%wait ~] 78 | :: 79 | [~ %poke @ *] 80 | ?. =(mark p.cage.u.in.tin) 81 | `[%skip ~] 82 | `[%done q.cage.u.in.tin] 83 | == 84 | :: 85 | ++ take-sign-arvo 86 | =/ m (strand ,[wire sign-arvo]) 87 | ^- form:m 88 | |= tin=strand-input:strand 89 | ?+ in.tin `[%skip ~] 90 | ~ 91 | `[%wait ~] 92 | :: 93 | [~ %sign *] 94 | `[%done [wire sign-arvo]:u.in.tin] 95 | == 96 | :: 97 | :: Wait for a subscription update on a wire 98 | :: 99 | ++ take-fact-prefix 100 | |= =wire 101 | =/ m (strand ,[path cage]) 102 | ^- form:m 103 | |= tin=strand-input:strand 104 | ?+ in.tin `[%skip ~] 105 | ~ `[%wait ~] 106 | [~ %agent * %fact *] 107 | ?. =(watch+wire (scag +((lent wire)) wire.u.in.tin)) 108 | `[%skip ~] 109 | `[%done (slag (lent wire) wire.u.in.tin) cage.sign.u.in.tin] 110 | == 111 | :: 112 | :: Wait for a subscription update on a wire 113 | :: 114 | ++ take-fact 115 | |= =wire 116 | =/ m (strand ,cage) 117 | ^- form:m 118 | |= tin=strand-input:strand 119 | ?+ in.tin `[%skip ~] 120 | ~ `[%wait ~] 121 | [~ %agent * %fact *] 122 | ?. =(watch+wire wire.u.in.tin) 123 | `[%skip ~] 124 | `[%done cage.sign.u.in.tin] 125 | == 126 | :: 127 | :: Wait for a subscription close 128 | :: 129 | ++ take-kick 130 | |= =wire 131 | =/ m (strand ,~) 132 | ^- form:m 133 | |= tin=strand-input:strand 134 | ?+ in.tin `[%skip ~] 135 | ~ `[%wait ~] 136 | [~ %agent * %kick *] 137 | ?. =(watch+wire wire.u.in.tin) 138 | `[%skip ~] 139 | `[%done ~] 140 | == 141 | :: 142 | ++ echo 143 | =/ m (strand ,~) 144 | ^- form:m 145 | %- (main-loop ,~) 146 | :~ |= ~ 147 | ^- form:m 148 | ;< =vase bind:m ((handle ,vase) (take-poke %echo)) 149 | =/ message=tape !<(tape vase) 150 | %- (slog leaf+"{message}..." ~) 151 | ;< ~ bind:m (sleep ~s2) 152 | %- (slog leaf+"{message}.." ~) 153 | (pure:m ~) 154 | :: 155 | |= ~ 156 | ^- form:m 157 | ;< =vase bind:m ((handle ,vase) (take-poke %over)) 158 | %- (slog leaf+"over..." ~) 159 | (pure:m ~) 160 | == 161 | :: 162 | ++ take-watch 163 | =/ m (strand ,path) 164 | |= tin=strand-input:strand 165 | ?+ in.tin `[%skip ~] 166 | ~ `[%wait ~] 167 | [~ %watch *] 168 | `[%done path.u.in.tin] 169 | == 170 | :: 171 | ++ take-wake 172 | |= until=(unit @da) 173 | =/ m (strand ,~) 174 | ^- form:m 175 | |= tin=strand-input:strand 176 | ?+ in.tin `[%skip ~] 177 | ~ `[%wait ~] 178 | [~ %sign [%wait @ ~] %behn %wake *] 179 | ?. |(?=(~ until) =(`u.until (slaw %da i.t.wire.u.in.tin))) 180 | `[%skip ~] 181 | ?~ error.sign-arvo.u.in.tin 182 | `[%done ~] 183 | `[%fail %timer-error u.error.sign-arvo.u.in.tin] 184 | == 185 | :: 186 | ++ take-tune 187 | |= =wire 188 | =/ m (strand ,[spar:ames (unit roar:ames)]) 189 | ^- form:m 190 | |= tin=strand-input:strand 191 | ?+ in.tin `[%skip ~] 192 | ~ `[%wait ~] 193 | :: 194 | [~ %sign * %ames %tune ^ *] 195 | ?. =(wire wire.u.in.tin) 196 | `[%skip ~] 197 | `[%done +>.sign-arvo.u.in.tin] 198 | == 199 | :: 200 | ++ take-poke-ack 201 | |= =wire 202 | =/ m (strand ,~) 203 | ^- form:m 204 | |= tin=strand-input:strand 205 | ?+ in.tin `[%skip ~] 206 | ~ `[%wait ~] 207 | [~ %agent * %poke-ack *] 208 | ?. =(wire wire.u.in.tin) 209 | `[%skip ~] 210 | ?~ p.sign.u.in.tin 211 | `[%done ~] 212 | `[%fail %poke-fail u.p.sign.u.in.tin] 213 | == 214 | :: 215 | ++ take-watch-ack 216 | |= =wire 217 | =/ m (strand ,~) 218 | ^- form:m 219 | |= tin=strand-input:strand 220 | ?+ in.tin `[%skip ~] 221 | ~ `[%wait ~] 222 | [~ %agent * %watch-ack *] 223 | ?. =(watch+wire wire.u.in.tin) 224 | `[%skip ~] 225 | ?~ p.sign.u.in.tin 226 | `[%done ~] 227 | `[%fail %watch-ack-fail u.p.sign.u.in.tin] 228 | == 229 | :: 230 | ++ poke 231 | |= [=dock =cage] 232 | =/ m (strand ,~) 233 | ^- form:m 234 | =/ =card:agent:gall [%pass /poke %agent dock %poke cage] 235 | ;< ~ bind:m (send-raw-card card) 236 | (take-poke-ack /poke) 237 | :: 238 | ++ raw-poke 239 | |= [=dock =cage] 240 | =/ m (strand ,~) 241 | ^- form:m 242 | =/ =card:agent:gall [%pass /poke %agent dock %poke cage] 243 | ;< ~ bind:m (send-raw-card card) 244 | =/ m (strand ,~) 245 | ^- form:m 246 | |= tin=strand-input:strand 247 | ?+ in.tin `[%skip ~] 248 | ~ 249 | `[%wait ~] 250 | :: 251 | [~ %agent * %poke-ack *] 252 | ?. =(/poke wire.u.in.tin) 253 | `[%skip ~] 254 | `[%done ~] 255 | == 256 | :: 257 | ++ raw-poke-our 258 | |= [app=term =cage] 259 | =/ m (strand ,~) 260 | ^- form:m 261 | ;< =bowl:spider bind:m get-bowl 262 | (raw-poke [our.bowl app] cage) 263 | :: 264 | ++ poke-our 265 | |= [=term =cage] 266 | =/ m (strand ,~) 267 | ^- form:m 268 | ;< our=@p bind:m get-our 269 | (poke [our term] cage) 270 | :: 271 | ++ watch 272 | |= [=wire =dock =path] 273 | =/ m (strand ,~) 274 | ^- form:m 275 | =/ =card:agent:gall [%pass watch+wire %agent dock %watch path] 276 | ;< ~ bind:m (send-raw-card card) 277 | (take-watch-ack wire) 278 | :: 279 | ++ watch-one 280 | |= [=wire =dock =path] 281 | =/ m (strand ,cage) 282 | ^- form:m 283 | ;< ~ bind:m (watch wire dock path) 284 | ;< =cage bind:m (take-fact wire) 285 | ;< ~ bind:m (take-kick wire) 286 | (pure:m cage) 287 | :: 288 | ++ watch-our 289 | |= [=wire =term =path] 290 | =/ m (strand ,~) 291 | ^- form:m 292 | ;< our=@p bind:m get-our 293 | (watch wire [our term] path) 294 | :: 295 | ++ scry 296 | |* [=mold =path] 297 | =/ m (strand ,mold) 298 | ^- form:m 299 | ?> ?=(^ path) 300 | ?> ?=(^ t.path) 301 | ;< =bowl:spider bind:m get-bowl 302 | %- pure:m 303 | .^(mold i.path (scot %p our.bowl) i.t.path (scot %da now.bowl) t.t.path) 304 | :: 305 | ++ leave 306 | |= [=wire =dock] 307 | =/ m (strand ,~) 308 | ^- form:m 309 | =/ =card:agent:gall [%pass watch+wire %agent dock %leave ~] 310 | (send-raw-card card) 311 | :: 312 | ++ leave-our 313 | |= [=wire =term] 314 | =/ m (strand ,~) 315 | ^- form:m 316 | ;< our=@p bind:m get-our 317 | (leave wire [our term]) 318 | :: 319 | ++ rewatch 320 | |= [=wire =dock =path] 321 | =/ m (strand ,~) 322 | ;< ~ bind:m ((handle ,~) (take-kick wire)) 323 | ;< ~ bind:m (flog-text "rewatching {} {}") 324 | ;< ~ bind:m (watch wire dock path) 325 | (pure:m ~) 326 | :: 327 | ++ wait 328 | |= until=@da 329 | =/ m (strand ,~) 330 | ^- form:m 331 | ;< ~ bind:m (send-wait until) 332 | (take-wake `until) 333 | :: 334 | ++ keen 335 | |= [=wire =spar:ames] 336 | =/ m (strand ,~) 337 | ^- form:m 338 | (send-raw-card %pass wire %arvo %a %keen spar) 339 | :: 340 | ++ sleep 341 | |= for=@dr 342 | =/ m (strand ,~) 343 | ^- form:m 344 | ;< now=@da bind:m get-time 345 | (wait (add now for)) 346 | :: 347 | ++ send-wait 348 | |= until=@da 349 | =/ m (strand ,~) 350 | ^- form:m 351 | =/ =card:agent:gall 352 | [%pass /wait/(scot %da until) %arvo %b %wait until] 353 | (send-raw-card card) 354 | :: 355 | ++ map-err 356 | |* computation-result=mold 357 | =/ m (strand ,computation-result) 358 | |= [f=$-([term tang] [term tang]) computation=form:m] 359 | ^- form:m 360 | |= tin=strand-input:strand 361 | =* loop $ 362 | =/ c-res (computation tin) 363 | ?: ?=(%cont -.next.c-res) 364 | c-res(self.next ..loop(computation self.next.c-res)) 365 | ?. ?=(%fail -.next.c-res) 366 | c-res 367 | c-res(err.next (f err.next.c-res)) 368 | :: 369 | ++ set-timeout 370 | |* computation-result=mold 371 | =/ m (strand ,computation-result) 372 | |= [time=@dr computation=form:m] 373 | ^- form:m 374 | ;< now=@da bind:m get-time 375 | =/ when (add now time) 376 | =/ =card:agent:gall 377 | [%pass /timeout/(scot %da when) %arvo %b %wait when] 378 | ;< ~ bind:m (send-raw-card card) 379 | |= tin=strand-input:strand 380 | =* loop $ 381 | ?: ?& ?=([~ %sign [%timeout @ ~] %behn %wake *] in.tin) 382 | =((scot %da when) i.t.wire.u.in.tin) 383 | == 384 | `[%fail %timeout ~] 385 | =/ c-res (computation tin) 386 | ?: ?=(%cont -.next.c-res) 387 | c-res(self.next ..loop(computation self.next.c-res)) 388 | ?: ?=(%done -.next.c-res) 389 | =/ =card:agent:gall 390 | [%pass /timeout/(scot %da when) %arvo %b %rest when] 391 | c-res(cards [card cards.c-res]) 392 | c-res 393 | :: 394 | ++ send-request 395 | |= =request:http 396 | =/ m (strand ,~) 397 | ^- form:m 398 | (send-raw-card %pass /request %arvo %i %request request *outbound-config:iris) 399 | :: 400 | ++ send-cancel-request 401 | =/ m (strand ,~) 402 | ^- form:m 403 | (send-raw-card %pass /request %arvo %i %cancel-request ~) 404 | :: 405 | ++ take-client-response 406 | =/ m (strand ,client-response:iris) 407 | ^- form:m 408 | |= tin=strand-input:strand 409 | ?+ in.tin `[%skip ~] 410 | ~ `[%wait ~] 411 | :: 412 | [~ %sign [%request ~] %iris %http-response %cancel *] 413 | ::NOTE iris does not (yet?) retry after cancel, so it means failure 414 | :- ~ 415 | :+ %fail 416 | %http-request-cancelled 417 | ['http request was cancelled by the runtime']~ 418 | :: 419 | [~ %sign [%request ~] %iris %http-response %finished *] 420 | `[%done client-response.sign-arvo.u.in.tin] 421 | == 422 | :: 423 | :: Wait until we get an HTTP response or cancelation and unset contract 424 | :: 425 | ++ take-maybe-sigh 426 | =/ m (strand ,(unit httr:eyre)) 427 | ^- form:m 428 | ;< rep=(unit client-response:iris) bind:m 429 | take-maybe-response 430 | ?~ rep 431 | (pure:m ~) 432 | :: XX s/b impossible 433 | :: 434 | ?. ?=(%finished -.u.rep) 435 | (pure:m ~) 436 | (pure:m (some (to-httr:iris +.u.rep))) 437 | :: 438 | ++ take-maybe-response 439 | =/ m (strand ,(unit client-response:iris)) 440 | ^- form:m 441 | |= tin=strand-input:strand 442 | ?+ in.tin `[%skip ~] 443 | ~ `[%wait ~] 444 | [~ %sign [%request ~] %iris %http-response %cancel *] 445 | `[%done ~] 446 | [~ %sign [%request ~] %iris %http-response %finished *] 447 | `[%done `client-response.sign-arvo.u.in.tin] 448 | == 449 | :: 450 | ++ extract-body 451 | |= =client-response:iris 452 | =/ m (strand ,cord) 453 | ^- form:m 454 | ?> ?=(%finished -.client-response) 455 | %- pure:m 456 | ?~ full-file.client-response '' 457 | q.data.u.full-file.client-response 458 | :: 459 | ++ fetch-cord 460 | |= url=tape 461 | =/ m (strand ,cord) 462 | ^- form:m 463 | =/ =request:http [%'GET' (crip url) ~ ~] 464 | ;< ~ bind:m (send-request request) 465 | ;< =client-response:iris bind:m take-client-response 466 | (extract-body client-response) 467 | :: 468 | ++ fetch-json 469 | |= url=tape 470 | =/ m (strand ,json) 471 | ^- form:m 472 | ;< =cord bind:m (fetch-cord url) 473 | =/ json=(unit json) (de-json:html cord) 474 | ?~ json 475 | (strand-fail %json-parse-error ~) 476 | (pure:m u.json) 477 | :: 478 | ++ hiss-request 479 | |= =hiss:eyre 480 | =/ m (strand ,(unit httr:eyre)) 481 | ^- form:m 482 | ;< ~ bind:m (send-request (hiss-to-request:html hiss)) 483 | take-maybe-sigh 484 | :: 485 | :: +build-file: build the source file at the specified $beam 486 | :: 487 | ++ build-file 488 | |= [[=ship =desk =case] =spur] 489 | =* arg +< 490 | =/ m (strand ,(unit vase)) 491 | ^- form:m 492 | ;< =riot:clay bind:m 493 | (warp ship desk ~ %sing %a case spur) 494 | ?~ riot 495 | (pure:m ~) 496 | ?> =(%vase p.r.u.riot) 497 | (pure:m (some !<(vase q.r.u.riot))) 498 | :: 499 | ++ build-file-hard 500 | |= [[=ship =desk =case] =spur] 501 | =* arg +< 502 | =/ m (strand ,vase) 503 | ^- form:m 504 | ;< =riot:clay 505 | bind:m 506 | (warp ship desk ~ %sing %a case spur) 507 | ?> ?=(^ riot) 508 | ?> ?=(%vase p.r.u.riot) 509 | (pure:m !<(vase q.r.u.riot)) 510 | :: +build-mark: build a mark definition to a $dais 511 | :: 512 | ++ build-mark 513 | |= [[=ship =desk =case] mak=mark] 514 | =* arg +< 515 | =/ m (strand ,dais:clay) 516 | ^- form:m 517 | ;< =riot:clay bind:m 518 | (warp ship desk ~ %sing %b case /[mak]) 519 | ?~ riot 520 | (strand-fail %build-mark >arg< ~) 521 | ?> =(%dais p.r.u.riot) 522 | (pure:m !<(dais:clay q.r.u.riot)) 523 | :: +build-tube: build a mark conversion gate ($tube) 524 | :: 525 | ++ build-tube 526 | |= [[=ship =desk =case] =mars:clay] 527 | =* arg +< 528 | =/ m (strand ,tube:clay) 529 | ^- form:m 530 | ;< =riot:clay bind:m 531 | (warp ship desk ~ %sing %c case /[a.mars]/[b.mars]) 532 | ?~ riot 533 | (strand-fail %build-tube >arg< ~) 534 | ?> =(%tube p.r.u.riot) 535 | (pure:m !<(tube:clay q.r.u.riot)) 536 | :: 537 | :: +build-nave: build a mark definition to a $nave 538 | :: 539 | ++ build-nave 540 | |= [[=ship =desk =case] mak=mark] 541 | =* arg +< 542 | =/ m (strand ,vase) 543 | ^- form:m 544 | ;< =riot:clay bind:m 545 | (warp ship desk ~ %sing %e case /[mak]) 546 | ?~ riot 547 | (strand-fail %build-nave >arg< ~) 548 | ?> =(%nave p.r.u.riot) 549 | (pure:m q.r.u.riot) 550 | :: +build-cast: build a mark conversion gate (static) 551 | :: 552 | ++ build-cast 553 | |= [[=ship =desk =case] =mars:clay] 554 | =* arg +< 555 | =/ m (strand ,vase) 556 | ^- form:m 557 | ;< =riot:clay bind:m 558 | (warp ship desk ~ %sing %f case /[a.mars]/[b.mars]) 559 | ?~ riot 560 | (strand-fail %build-cast >arg< ~) 561 | ?> =(%cast p.r.u.riot) 562 | (pure:m q.r.u.riot) 563 | :: 564 | :: Read from Clay 565 | :: 566 | ++ warp 567 | |= [=ship =riff:clay] 568 | =/ m (strand ,riot:clay) 569 | ;< ~ bind:m (send-raw-card %pass /warp %arvo %c %warp ship riff) 570 | (take-writ /warp) 571 | :: 572 | ++ read-file 573 | |= [[=ship =desk =case] =spur] 574 | =* arg +< 575 | =/ m (strand ,cage) 576 | ;< =riot:clay bind:m (warp ship desk ~ %sing %x case spur) 577 | ?~ riot 578 | (strand-fail %read-file >arg< ~) 579 | (pure:m r.u.riot) 580 | :: 581 | ++ check-for-file 582 | |= [[=ship =desk =case] =spur] 583 | =/ m (strand ,?) 584 | ;< =riot:clay bind:m (warp ship desk ~ %sing %x case spur) 585 | (pure:m ?=(^ riot)) 586 | :: 587 | ++ list-tree 588 | |= [[=ship =desk =case] =spur] 589 | =* arg +< 590 | =/ m (strand ,(list path)) 591 | ;< =riot:clay bind:m (warp ship desk ~ %sing %t case spur) 592 | ?~ riot 593 | (strand-fail %list-tree >arg< ~) 594 | (pure:m !<((list path) q.r.u.riot)) 595 | :: 596 | :: Take Clay read result 597 | :: 598 | ++ take-writ 599 | |= =wire 600 | =/ m (strand ,riot:clay) 601 | ^- form:m 602 | |= tin=strand-input:strand 603 | ?+ in.tin `[%skip ~] 604 | ~ `[%wait ~] 605 | [~ %sign * ?(%behn %clay) %writ *] 606 | ?. =(wire wire.u.in.tin) 607 | `[%skip ~] 608 | `[%done +>.sign-arvo.u.in.tin] 609 | == 610 | :: +check-online: require that peer respond before timeout 611 | :: 612 | ++ check-online 613 | |= [who=ship lag=@dr] 614 | =/ m (strand ,~) 615 | ^- form:m 616 | %+ (map-err ,~) |=(* [%offline *tang]) 617 | %+ (set-timeout ,~) lag 618 | ;< ~ bind:m 619 | (poke [who %hood] %helm-hi !>(~)) 620 | (pure:m ~) 621 | :: 622 | ++ eval-hoon 623 | |= [gen=hoon bez=(list beam)] 624 | =/ m (strand ,vase) 625 | ^- form:m 626 | =/ sut=vase !>(..zuse) 627 | |- 628 | ?~ bez 629 | (pure:m (slap sut gen)) 630 | ;< vax=vase bind:m (build-file-hard i.bez) 631 | $(bez t.bez, sut (slop vax sut)) 632 | :: 633 | ++ send-thread 634 | |= [=bear:khan =shed:khan =wire] 635 | =/ m (strand ,~) 636 | ^- form:m 637 | (send-raw-card %pass wire %arvo %k %lard bear shed) 638 | :: 639 | :: Queue on skip, try next on fail %ignore 640 | :: 641 | ++ main-loop 642 | |* a=mold 643 | =/ m (strand ,~) 644 | =/ m-a (strand ,a) 645 | =| queue=(qeu (unit input:strand)) 646 | =| active=(unit [in=(unit input:strand) =form:m-a forms=(list $-(a form:m-a))]) 647 | =| state=a 648 | |= forms=(lest $-(a form:m-a)) 649 | ^- form:m 650 | |= tin=strand-input:strand 651 | =* top `form:m`..$ 652 | =. queue (~(put to queue) in.tin) 653 | |^ (continue bowl.tin) 654 | :: 655 | ++ continue 656 | |= =bowl:strand 657 | ^- output:m 658 | ?> =(~ active) 659 | ?: =(~ queue) 660 | `[%cont top] 661 | =^ in=(unit input:strand) queue ~(get to queue) 662 | ^- output:m 663 | =. active `[in (i.forms state) t.forms] 664 | ^- output:m 665 | (run bowl in) 666 | :: 667 | ++ run 668 | ^- form:m 669 | |= tin=strand-input:strand 670 | ^- output:m 671 | ?> ?=(^ active) 672 | =/ res (form.u.active tin) 673 | =/ =output:m 674 | ?- -.next.res 675 | %wait `[%wait ~] 676 | %skip `[%cont ..$(queue (~(put to queue) in.tin))] 677 | %cont `[%cont ..$(active `[in.u.active self.next.res forms.u.active])] 678 | %done (continue(active ~, state value.next.res) bowl.tin) 679 | %fail 680 | ?: &(?=(^ forms.u.active) ?=(%ignore p.err.next.res)) 681 | %= $ 682 | active `[in.u.active (i.forms.u.active state) t.forms.u.active] 683 | in.tin in.u.active 684 | == 685 | `[%fail err.next.res] 686 | == 687 | [(weld cards.res cards.output) next.output] 688 | -- 689 | :: 690 | ++ retry 691 | |* result=mold 692 | |= [crash-after=(unit @ud) computation=_*form:(strand (unit result))] 693 | =/ m (strand ,result) 694 | =| try=@ud 695 | |- ^- form:m 696 | =* loop $ 697 | ?: =(crash-after `try) 698 | (strand-fail %retry-too-many ~) 699 | ;< ~ bind:m (backoff try ~m1) 700 | ;< res=(unit result) bind:m computation 701 | ?^ res 702 | (pure:m u.res) 703 | loop(try +(try)) 704 | :: 705 | ++ backoff 706 | |= [try=@ud limit=@dr] 707 | =/ m (strand ,~) 708 | ^- form:m 709 | ;< eny=@uvJ bind:m get-entropy 710 | %- sleep 711 | %+ min limit 712 | ?: =(0 try) ~s0 713 | %+ add 714 | (mul ~s1 (bex (dec try))) 715 | (mul ~s0..0001 (~(rad og eny) 1.000)) 716 | :: 717 | :: ---- 718 | :: 719 | :: Output 720 | :: 721 | ++ flog 722 | |= =flog:dill 723 | =/ m (strand ,~) 724 | ^- form:m 725 | (send-raw-card %pass / %arvo %d %flog flog) 726 | :: 727 | ++ flog-text 728 | |= =tape 729 | =/ m (strand ,~) 730 | ^- form:m 731 | (flog %text tape) 732 | :: 733 | ++ flog-tang 734 | |= =tang 735 | =/ m (strand ,~) 736 | ^- form:m 737 | =/ =wall 738 | (zing (turn (flop tang) (cury wash [0 80]))) 739 | |- ^- form:m 740 | =* loop $ 741 | ?~ wall 742 | (pure:m ~) 743 | ;< ~ bind:m (flog-text i.wall) 744 | loop(wall t.wall) 745 | :: 746 | ++ trace 747 | |= =tang 748 | =/ m (strand ,~) 749 | ^- form:m 750 | (pure:m ((slog tang) ~)) 751 | :: 752 | ++ app-message 753 | |= [app=term =cord =tang] 754 | =/ m (strand ,~) 755 | ^- form:m 756 | =/ msg=tape :(weld (trip app) ": " (trip cord)) 757 | ;< ~ bind:m (flog-text msg) 758 | (flog-tang tang) 759 | :: 760 | :: ---- 761 | :: 762 | :: Handle domains 763 | :: 764 | ++ install-domain 765 | |= =turf 766 | =/ m (strand ,~) 767 | ^- form:m 768 | (send-raw-card %pass / %arvo %e %rule %turf %put turf) 769 | :: 770 | :: ---- 771 | :: 772 | :: Threads 773 | :: 774 | ++ start-thread 775 | |= file=term 776 | =/ m (strand ,tid:spider) 777 | ;< =bowl:spider bind:m get-bowl 778 | (start-thread-with-args byk.bowl file *vase) 779 | :: 780 | ++ start-thread-with-args 781 | |= [=beak file=term args=vase] 782 | =/ m (strand ,tid:spider) 783 | ^- form:m 784 | ;< =bowl:spider bind:m get-bowl 785 | =/ tid 786 | (scot %ta (cat 3 (cat 3 'strand_' file) (scot %uv (sham file eny.bowl)))) 787 | =/ poke-vase !>(`start-args:spider`[`tid.bowl `tid beak file args]) 788 | ;< ~ bind:m (poke-our %spider %spider-start poke-vase) 789 | ;< ~ bind:m (sleep ~s0) :: wait for thread to start 790 | (pure:m tid) 791 | :: 792 | +$ thread-result 793 | (each vase [term tang]) 794 | :: 795 | ++ await-thread 796 | |= [file=term args=vase] 797 | =/ m (strand ,thread-result) 798 | ^- form:m 799 | ;< =bowl:spider bind:m get-bowl 800 | =/ tid (scot %ta (cat 3 'strand_' (scot %uv (sham file eny.bowl)))) 801 | =/ poke-vase !>(`start-args:spider`[`tid.bowl `tid byk.bowl file args]) 802 | ;< ~ bind:m (watch-our /awaiting/[tid] %spider /thread-result/[tid]) 803 | ;< ~ bind:m (poke-our %spider %spider-start poke-vase) 804 | ;< ~ bind:m (sleep ~s0) :: wait for thread to start 805 | ;< =cage bind:m (take-fact /awaiting/[tid]) 806 | ;< ~ bind:m (take-kick /awaiting/[tid]) 807 | ?+ p.cage ~|([%strange-thread-result p.cage file tid] !!) 808 | %thread-done (pure:m %& q.cage) 809 | %thread-fail (pure:m %| ;;([term tang] q.q.cage)) 810 | == 811 | -- 812 | --------------------------------------------------------------------------------