@acryldev/blends 0.0.0-stage → 1.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +73 -0
- package/README.md +424 -2
- package/bin/acrylblends.js +12 -0
- package/dist/index.d.ts +231 -0
- package/dist/index.js +4505 -0
- package/dist/index.js.map +1 -0
- package/lib/accept-B13wFRkc.js +193 -0
- package/lib/accepts-BN4uue4T.js +52 -0
- package/lib/accepts.d.ts +33 -0
- package/lib/accepts.js +2 -0
- package/lib/acryl-base.d.ts +2 -0
- package/lib/acryl-base.js +2 -0
- package/lib/adapter-Wt9Ntyhx.js +37 -0
- package/lib/adapter.d.ts +12 -0
- package/lib/adapter.js +2 -0
- package/lib/app-CM-rDcw6.js +26 -0
- package/lib/app-DGqSNBSd.d.ts +21 -0
- package/lib/app-base-BwplqlWX.js +332 -0
- package/lib/audit-B2H3sUfg.d.ts +136 -0
- package/lib/base-N-QVQhMZ.d.ts +783 -0
- package/lib/base-kl8P-za0.js +722 -0
- package/lib/basic-auth-ByZGvWGz.js +95 -0
- package/lib/basic-auth-CzulvSad.js +20 -0
- package/lib/basic-auth.d.ts +72 -0
- package/lib/basic-auth.js +2 -0
- package/lib/bearer-auth-CfR6YNqy.js +94 -0
- package/lib/bearer-auth.d.ts +89 -0
- package/lib/bearer-auth.js +2 -0
- package/lib/body-BQ-J23GI.js +94 -0
- package/lib/body-limit-DyO82Wes.js +66 -0
- package/lib/body-limit.d.ts +42 -0
- package/lib/body-limit.js +2 -0
- package/lib/browser/client.js +307 -0
- package/lib/browser/jsx-dom.js +1432 -0
- package/lib/browser/read-sse.js +84 -0
- package/lib/buffer-CWpxJrvI.js +51 -0
- package/lib/bun.d.ts +75 -0
- package/lib/bun.js +134 -0
- package/lib/cache-DllEV7kz.js +169 -0
- package/lib/cache.d.ts +43 -0
- package/lib/cache.js +2 -0
- package/lib/cell-wEBQA3d0.d.ts +32 -0
- package/lib/client-BMFCUlHG.js +143 -0
- package/lib/client-modules-ChLgW0l9.js +267 -0
- package/lib/client.d.ts +3 -0
- package/lib/client.js +3 -0
- package/lib/color-C26GR4OI.js +37 -0
- package/lib/combine-rXRCRMJx.js +137 -0
- package/lib/combine.d.ts +85 -0
- package/lib/combine.js +2 -0
- package/lib/common-CaqP5LIh.d.ts +46 -0
- package/lib/components-BZ8vBk_7.js +268 -0
- package/lib/components-Cq4hcRbo.js +24 -0
- package/lib/compose-DbuvN1rE.js +50 -0
- package/lib/compress-C7QjZM5f.js +11 -0
- package/lib/compress-CdDuP9-S.d.ts +11 -0
- package/lib/compress-T36YxGla.js +79 -0
- package/lib/compress.d.ts +38 -0
- package/lib/compress.js +3 -0
- package/lib/concurrent-B7z-2cwF.js +30 -0
- package/lib/connection-CzRPq1RP.d.ts +25 -0
- package/lib/connection-DLPx5pxD.js +24 -0
- package/lib/conninfo-BbxlV2HK.d.ts +11 -0
- package/lib/conninfo-CNYXEtnA.js +19 -0
- package/lib/conninfo.d.ts +3 -0
- package/lib/conninfo.js +2 -0
- package/lib/constants-D914mQY7.js +7 -0
- package/lib/constants-nJj4XhwC.js +4 -0
- package/lib/constants-vv1oZD_p.js +9 -0
- package/lib/context-BVI2RzT7.js +365 -0
- package/lib/context-Ca3uX_bh.d.ts +1234 -0
- package/lib/context-Dre4P1UW.d.ts +250 -0
- package/lib/context-storage-ClUlVtCZ.js +52 -0
- package/lib/context-storage.d.ts +38 -0
- package/lib/context-storage.js +2 -0
- package/lib/cookie-BqeGZ43j.d.ts +40 -0
- package/lib/cookie-DktnJ0tJ.js +82 -0
- package/lib/cookie-uMH6wAF3.js +125 -0
- package/lib/cookie.d.ts +24 -0
- package/lib/cookie.js +2 -0
- package/lib/cordis/db-sqlite.d.ts +56 -0
- package/lib/cordis/db-sqlite.js +66 -0
- package/lib/cordis/db.d.ts +8 -0
- package/lib/cordis/db.js +1 -0
- package/lib/cordis/door.d.ts +404 -0
- package/lib/cordis/door.js +1812 -0
- package/lib/cordis/inspect.d.ts +77 -0
- package/lib/cordis/inspect.js +149 -0
- package/lib/cordis/kv-db.d.ts +16 -0
- package/lib/cordis/kv-db.js +18 -0
- package/lib/cordis/kv-json.d.ts +16 -0
- package/lib/cordis/kv-json.js +52 -0
- package/lib/cordis/kv.d.ts +8 -0
- package/lib/cordis/kv.js +1 -0
- package/lib/cordis/node-server.d.ts +155 -0
- package/lib/cordis/node-server.js +4 -0
- package/lib/cordis/router-http.d.ts +85 -0
- package/lib/cordis/router-http.js +206 -0
- package/lib/cordis/router.d.ts +7 -0
- package/lib/cordis/router.js +6 -0
- package/lib/cordis/state/react.d.ts +6 -0
- package/lib/cordis/state/react.js +11 -0
- package/lib/cordis/state.d.ts +34 -0
- package/lib/cordis/state.js +527 -0
- package/lib/core-4oDBzv4Q.js +19 -0
- package/lib/cors-C0qqZ-O-.js +106 -0
- package/lib/cors.d.ts +52 -0
- package/lib/cors.js +2 -0
- package/lib/crypto-ciSjk9n3.js +34 -0
- package/lib/csrf-rMr2nM2c.js +101 -0
- package/lib/csrf.d.ts +75 -0
- package/lib/csrf.js +2 -0
- package/lib/css-Bd6tj88A.js +320 -0
- package/lib/css-CLgKjBuO.js +134 -0
- package/lib/css.d.ts +82 -0
- package/lib/css.js +3 -0
- package/lib/database-CyKvumAn.d.ts +44 -0
- package/lib/db/conformance.d.ts +15 -0
- package/lib/db/conformance.js +279 -0
- package/lib/db/sqlite.d.ts +3 -0
- package/lib/db/sqlite.js +2 -0
- package/lib/db.d.ts +3 -0
- package/lib/db.js +2 -0
- package/lib/dev-h25puJmg.js +50 -0
- package/lib/dev.d.ts +19 -0
- package/lib/dev.js +2 -0
- package/lib/dom-MsnhZjjn.js +74 -0
- package/lib/door/host.d.ts +24 -0
- package/lib/door/host.js +2 -0
- package/lib/door/page.d.ts +160 -0
- package/lib/door/page.js +1257 -0
- package/lib/door/protocol.d.ts +2 -0
- package/lib/door/protocol.js +2 -0
- package/lib/drivers.d.ts +77 -0
- package/lib/drivers.js +16 -0
- package/lib/encode-BbgU91Gc.js +33 -0
- package/lib/etag-DevxEjyU.js +135 -0
- package/lib/etag.d.ts +40 -0
- package/lib/etag.js +2 -0
- package/lib/factory-d6WBwm2j.js +30 -0
- package/lib/factory.d.ts +35 -0
- package/lib/factory.js +2 -0
- package/lib/handler-DXCHa3NV.js +12 -0
- package/lib/headers-DbujLUIi.d.ts +11 -0
- package/lib/helpers-qmReU164.js +5 -0
- package/lib/hooks-Bs7lFRjW.js +762 -0
- package/lib/html-1jTa7KN1.js +103 -0
- package/lib/html-CNr9FLdV.d.ts +46 -0
- package/lib/html-CoWdxS1u.js +31 -0
- package/lib/html.d.ts +3 -0
- package/lib/html.js +3 -0
- package/lib/http-exception-BKMYq4x6.js +54 -0
- package/lib/http-exception-Cm8QD9Fl.d.ts +57 -0
- package/lib/http-exception.d.ts +2 -0
- package/lib/http-exception.js +2 -0
- package/lib/http-status-uBFmbzzM.d.ts +35 -0
- package/lib/index-B_g6ECnm.d.ts +57 -0
- package/lib/index-BaOiJMWK.d.ts +31 -0
- package/lib/index-C5RhEyXO.d.ts +45 -0
- package/lib/index-C8xOqNUW.d.ts +71 -0
- package/lib/index-D1HlwHSL.d.ts +129 -0
- package/lib/index-DUYLk7OD.d.ts +44 -0
- package/lib/index-DYBSr8yW.d.ts +156 -0
- package/lib/index-Dv4qFsro.d.ts +94 -0
- package/lib/index-jdWVs88B.d.ts +6 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.js +4 -0
- package/lib/ip-restriction-C4TZKPKl.js +166 -0
- package/lib/ip-restriction.d.ts +68 -0
- package/lib/ip-restriction.js +2 -0
- package/lib/ipaddr-CTeN6kNw.js +238 -0
- package/lib/jsx/dom/client.d.ts +30 -0
- package/lib/jsx/dom/client.js +49 -0
- package/lib/jsx/dom/css.d.ts +84 -0
- package/lib/jsx/dom/css.js +2 -0
- package/lib/jsx/dom/jsx-dev-runtime.d.ts +3 -0
- package/lib/jsx/dom/jsx-dev-runtime.js +2 -0
- package/lib/jsx/dom/jsx-runtime.d.ts +3 -0
- package/lib/jsx/dom/jsx-runtime.js +3 -0
- package/lib/jsx/dom/server.d.ts +105 -0
- package/lib/jsx/dom/server.js +37 -0
- package/lib/jsx/dom.d.ts +5 -0
- package/lib/jsx/dom.js +6 -0
- package/lib/jsx/jsx-dev-runtime.d.ts +3 -0
- package/lib/jsx/jsx-dev-runtime.js +3 -0
- package/lib/jsx/jsx-runtime.d.ts +10 -0
- package/lib/jsx/jsx-runtime.js +30 -0
- package/lib/jsx/streaming.d.ts +2 -0
- package/lib/jsx/streaming.js +2 -0
- package/lib/jsx-C5-YJG0l.js +47 -0
- package/lib/jsx-dev-runtime-CPsrmbgy.d.ts +7 -0
- package/lib/jsx-dev-runtime-Cs-uV30u.js +14 -0
- package/lib/jsx-dev-runtime-DK4z4RD3.js +354 -0
- package/lib/jsx-dev-runtime-DSQ8vSCY.d.ts +6 -0
- package/lib/jsx-renderer-B2wHa9Y8.js +99 -0
- package/lib/jsx-renderer.d.ts +75 -0
- package/lib/jsx-renderer.js +2 -0
- package/lib/jsx-runtime-BVVgDSdq.d.ts +1 -0
- package/lib/jsx-runtime-brX0UliB.js +2 -0
- package/lib/jsx.d.ts +3 -0
- package/lib/jsx.js +6 -0
- package/lib/jwk-BbiXIYhg.js +117 -0
- package/lib/jwk.d.ts +52 -0
- package/lib/jwk.js +2 -0
- package/lib/jwt-BCS5hH1O.d.ts +51 -0
- package/lib/jwt-Culfq-8m.js +403 -0
- package/lib/jwt-DaOoWaF3.js +115 -0
- package/lib/jwt.d.ts +72 -0
- package/lib/jwt.js +3 -0
- package/lib/kv/conformance.d.ts +17 -0
- package/lib/kv/conformance.js +313 -0
- package/lib/kv/db.d.ts +3 -0
- package/lib/kv/db.js +2 -0
- package/lib/kv/json.d.ts +3 -0
- package/lib/kv/json.js +2 -0
- package/lib/kv-Kv6J9zqu.d.ts +39 -0
- package/lib/kv.d.ts +3 -0
- package/lib/kv.js +2 -0
- package/lib/language-anRiLd9a.js +198 -0
- package/lib/language.d.ts +88 -0
- package/lib/language.js +2 -0
- package/lib/linear-router-BUrYQxcv.js +96 -0
- package/lib/logger-CLvaB463.js +54 -0
- package/lib/logger.d.ts +22 -0
- package/lib/logger.js +2 -0
- package/lib/loopback-only-0nTL30Zt.js +131 -0
- package/lib/loopback-only.d.ts +73 -0
- package/lib/loopback-only.js +2 -0
- package/lib/method-not-allowed-B3nMAp1f.js +82 -0
- package/lib/method-not-allowed.d.ts +47 -0
- package/lib/method-not-allowed.js +2 -0
- package/lib/method-override-Dhd_EJD9.js +103 -0
- package/lib/method-override.d.ts +46 -0
- package/lib/method-override.js +2 -0
- package/lib/middleware-B8gJUDgl.js +12 -0
- package/lib/mime-B9GbsqnN.d.ts +72 -0
- package/lib/mime-C-r9WxjH.js +77 -0
- package/lib/mount-RGiNYj2l.js +67 -0
- package/lib/mount.d.ts +44 -0
- package/lib/mount.js +2 -0
- package/lib/node-server/conninfo.d.ts +2 -0
- package/lib/node-server/conninfo.js +2 -0
- package/lib/node-server/register.d.ts +1 -0
- package/lib/node-server/register.js +59 -0
- package/lib/node-server/serve-static.d.ts +2 -0
- package/lib/node-server/serve-static.js +2 -0
- package/lib/node-server.d.ts +134 -0
- package/lib/node-server.js +5 -0
- package/lib/open-BC_BGIQt.d.ts +12 -0
- package/lib/open-BpnCtiKf.js +224 -0
- package/lib/open-CEE2hyrs.d.ts +11 -0
- package/lib/open-CwA_ZiPl.js +57 -0
- package/lib/open-DFt0lT26.js +197 -0
- package/lib/open-DXxlFxS0.d.ts +27 -0
- package/lib/pattern-router-DlkDNR9e.js +41 -0
- package/lib/powered-by-B9ufDvKH.js +24 -0
- package/lib/powered-by.d.ts +28 -0
- package/lib/powered-by.js +2 -0
- package/lib/pretty-json-B_5MzYgk.js +39 -0
- package/lib/pretty-json.d.ts +40 -0
- package/lib/pretty-json.js +2 -0
- package/lib/protocol-8HjYa5OX.js +217 -0
- package/lib/protocol-DdQgl224.d.ts +160 -0
- package/lib/proxy-C02n8qaX.js +121 -0
- package/lib/proxy.d.ts +72 -0
- package/lib/proxy.js +2 -0
- package/lib/quick.d.ts +8 -0
- package/lib/quick.js +17 -0
- package/lib/read-sse.d.ts +33 -0
- package/lib/read-sse.js +84 -0
- package/lib/reg-exp-router-DT_H6W_j.js +363 -0
- package/lib/request-PoZjfrb4.js +323 -0
- package/lib/request-id-CWyCgzyD.js +34 -0
- package/lib/request-id.d.ts +45 -0
- package/lib/request-id.js +2 -0
- package/lib/request.d.ts +2 -0
- package/lib/request.js +2 -0
- package/lib/route-D1WQ4cOh.js +126 -0
- package/lib/route.d.ts +78 -0
- package/lib/route.js +2 -0
- package/lib/router/linear-router.d.ts +11 -0
- package/lib/router/linear-router.js +2 -0
- package/lib/router/pattern-router.d.ts +11 -0
- package/lib/router/pattern-router.js +2 -0
- package/lib/router/reg-exp-router.d.ts +35 -0
- package/lib/router/reg-exp-router.js +2 -0
- package/lib/router/smart-router.d.ts +15 -0
- package/lib/router/smart-router.js +2 -0
- package/lib/router/trie-router.d.ts +11 -0
- package/lib/router/trie-router.js +2 -0
- package/lib/router-0TlTAMdt.d.ts +99 -0
- package/lib/router-wWGf3FlK.js +35 -0
- package/lib/router.d.ts +2 -0
- package/lib/router.js +2 -0
- package/lib/schema-validator-DGAFbTcN.js +22 -0
- package/lib/schema-validator.d.ts +54 -0
- package/lib/schema-validator.js +2 -0
- package/lib/secure-headers-eLrZcjSr.js +163 -0
- package/lib/secure-headers.d.ts +125 -0
- package/lib/secure-headers.js +2 -0
- package/lib/serve-static-D97E4ERX.d.ts +18 -0
- package/lib/serve-static-YoUetEZ8.js +212 -0
- package/lib/serve-static-cnLZvaYu.js +77 -0
- package/lib/serve-static.d.ts +2 -0
- package/lib/serve-static.js +2 -0
- package/lib/smart-router-BF56Yf23.js +49 -0
- package/lib/snapshot-text-Cyl69OKv.js +597 -0
- package/lib/src-6T1gCSq3.js +427 -0
- package/lib/src-BycZ1HUQ.js +407 -0
- package/lib/src-CZ1JoBaO.js +90 -0
- package/lib/src-C_00jcuj.js +85 -0
- package/lib/ssg-D_StqyTO.js +389 -0
- package/lib/ssg.d.ts +2 -0
- package/lib/ssg.js +2 -0
- package/lib/stream-CJ_0BMG2.js +88 -0
- package/lib/stream-Oxo9JHC6.d.ts +34 -0
- package/lib/streaming-CL2i3hX_.js +96 -0
- package/lib/streaming.d.ts +23 -0
- package/lib/streaming.js +2 -0
- package/lib/testing-DnLmBGle.js +17 -0
- package/lib/testing.d.ts +10 -0
- package/lib/testing.js +2 -0
- package/lib/timeout-Bib1sxFc.js +42 -0
- package/lib/timeout.d.ts +30 -0
- package/lib/timeout.js +2 -0
- package/lib/timing-CkkBmV23.js +183 -0
- package/lib/timing.d.ts +130 -0
- package/lib/timing.js +2 -0
- package/lib/tiny.d.ts +8 -0
- package/lib/tiny.js +15 -0
- package/lib/trailing-slash-qJLAJrAH.js +85 -0
- package/lib/trailing-slash.d.ts +91 -0
- package/lib/trailing-slash.js +2 -0
- package/lib/transpile-Bc6rZPK-.js +105 -0
- package/lib/trie-router-DhF3wn5_.js +146 -0
- package/lib/types-Zy1OzMX7.d.ts +29 -0
- package/lib/types-akvg9vbH.d.ts +40 -0
- package/lib/types-cu7acft5.d.ts +195 -0
- package/lib/types-nO2Jov17.d.ts +114 -0
- package/lib/types.d.ts +2 -0
- package/lib/types.js +4 -0
- package/lib/upgrade-hub-7og-sHcQ.d.ts +138 -0
- package/lib/upgrade-hub-B4hca91Y.js +1554 -0
- package/lib/url-Cyyh7Fiw.js +197 -0
- package/lib/utils/accept.d.ts +9 -0
- package/lib/utils/accept.js +2 -0
- package/lib/utils/basic-auth.d.ts +8 -0
- package/lib/utils/basic-auth.js +2 -0
- package/lib/utils/body.d.ts +2 -0
- package/lib/utils/body.js +2 -0
- package/lib/utils/buffer.d.ts +19 -0
- package/lib/utils/buffer.js +2 -0
- package/lib/utils/color.d.ts +24 -0
- package/lib/utils/color.js +2 -0
- package/lib/utils/compress.d.ts +2 -0
- package/lib/utils/compress.js +2 -0
- package/lib/utils/concurrent.d.ts +17 -0
- package/lib/utils/concurrent.js +2 -0
- package/lib/utils/constants.d.ts +7 -0
- package/lib/utils/constants.js +2 -0
- package/lib/utils/cookie.d.ts +2 -0
- package/lib/utils/cookie.js +2 -0
- package/lib/utils/crypto.d.ts +14 -0
- package/lib/utils/crypto.js +2 -0
- package/lib/utils/encode.d.ts +11 -0
- package/lib/utils/encode.js +2 -0
- package/lib/utils/filepath.d.ts +14 -0
- package/lib/utils/filepath.js +25 -0
- package/lib/utils/handler.d.ts +9 -0
- package/lib/utils/handler.js +2 -0
- package/lib/utils/headers.d.ts +2 -0
- package/lib/utils/headers.js +1 -0
- package/lib/utils/html.d.ts +2 -0
- package/lib/utils/html.js +2 -0
- package/lib/utils/http-status.d.ts +2 -0
- package/lib/utils/http-status.js +1 -0
- package/lib/utils/ipaddr.d.ts +56 -0
- package/lib/utils/ipaddr.js +2 -0
- package/lib/utils/jwt.d.ts +24 -0
- package/lib/utils/jwt.js +2 -0
- package/lib/utils/mime.d.ts +2 -0
- package/lib/utils/mime.js +2 -0
- package/lib/utils/stream.d.ts +2 -0
- package/lib/utils/stream.js +2 -0
- package/lib/utils/types.d.ts +2 -0
- package/lib/utils/types.js +1 -0
- package/lib/utils/url.d.ts +46 -0
- package/lib/utils/url.js +2 -0
- package/lib/utils-CYdUlhw1.js +125 -0
- package/lib/utils-CnUrxRO-.js +4 -0
- package/lib/validator-DkpCsiJC.js +65 -0
- package/lib/validator.d.ts +42 -0
- package/lib/validator.js +2 -0
- package/lib/vitest-binding-CctNu3jT.d.ts +15 -0
- package/lib/vitest-binding-CrH7rKg2.js +17 -0
- package/lib/websocket-Cy4jtqHv.js +56 -0
- package/lib/ws.d.ts +2 -0
- package/lib/ws.js +2 -0
- package/package.json +463 -3
- package/shared/AGENTS.core.md +84 -0
- package/shared/DEFAULTS.md +49 -0
- package/shared/library-history-versions.json +48 -0
- package/shared/library-history.json +786 -0
- package/shared/skills/acryl-add-ui/SKILL.md +19 -0
- package/shared/skills/acryl-app/SKILL.md +13 -0
- package/shared/skills/acryl-build-plugin/SKILL.md +22 -0
- package/shared/skills/acryl-change-plugin/SKILL.md +14 -0
- package/shared/skills/acryl-diagnose-plugin/SKILL.md +13 -0
- package/shared/skills/acryl-fix-plugin/SKILL.md +13 -0
- package/shared/skills/acryl-remove-plugin/SKILL.md +12 -0
- package/shared/skills/acryl-share-plugin/SKILL.md +16 -0
- package/shared/skills/cordis-plugin/SKILL.md +26 -0
- package/templates/agent/.gitattributes +2 -0
- package/templates/agent/AGENTS.md +20 -0
- package/templates/agent/Dockerfile +15 -0
- package/templates/agent/README.md +52 -0
- package/templates/agent/blend.yaml +71 -0
- package/templates/agent/dockerignore +3 -0
- package/templates/agent/gitignore +6 -0
- package/templates/agent/package.json +31 -0
- package/templates/agent/src/app.ts +293 -0
- package/templates/agent/src/frame.ts +17 -0
- package/templates/agent/src/main.ts +27 -0
- package/templates/agent/src/routes.ts +163 -0
- package/templates/agent/template.json +22 -0
- package/templates/agent/test/agent.test.ts +51 -0
- package/templates/agent/test/app.test.ts +270 -0
- package/templates/agent/test/builder.test.ts +210 -0
- package/templates/agent/test/model.test.ts +94 -0
- package/templates/agent/tsconfig.json +68 -0
- package/templates/blank/.gitattributes +2 -0
- package/templates/blank/AGENTS.md +6 -0
- package/templates/blank/README.md +26 -0
- package/templates/blank/blend.yaml +37 -0
- package/templates/blank/gitignore +6 -0
- package/templates/blank/package.json +31 -0
- package/templates/blank/src/about.tsx +14 -0
- package/templates/blank/src/app.ts +160 -0
- package/templates/blank/src/door.ts +7 -0
- package/templates/blank/src/first-page.ts +5 -0
- package/templates/blank/src/frame.ts +17 -0
- package/templates/blank/src/main.ts +20 -0
- package/templates/blank/src/routes.ts +79 -0
- package/templates/blank/template.json +15 -0
- package/templates/blank/test/app.test.ts +177 -0
- package/templates/blank/tsconfig.json +19 -0
- package/templates/chat/.gitattributes +2 -0
- package/templates/chat/AGENTS.md +16 -0
- package/templates/chat/blend.yaml +36 -0
- package/templates/chat/gitignore +9 -0
- package/templates/chat/migrations/001-chat.sql +12 -0
- package/templates/chat/package.json +35 -0
- package/templates/chat/src/access.ts +110 -0
- package/templates/chat/src/app.ts +165 -0
- package/templates/chat/src/chat-app.ts +120 -0
- package/templates/chat/src/client/chat.tsx +117 -0
- package/templates/chat/src/client/tsconfig.json +26 -0
- package/templates/chat/src/db.ts +43 -0
- package/templates/chat/src/door.ts +7 -0
- package/templates/chat/src/frame.ts +17 -0
- package/templates/chat/src/llm.ts +48 -0
- package/templates/chat/src/main.ts +23 -0
- package/templates/chat/src/page.tsx +42 -0
- package/templates/chat/src/routes.ts +29 -0
- package/templates/chat/src/runtime.ts +23 -0
- package/templates/chat/template.json +15 -0
- package/templates/chat/test/chat.test.ts +322 -0
- package/templates/chat/test/server.test.ts +92 -0
- package/templates/chat/tsconfig.json +20 -0
- package/templates/nodejs/.gitattributes +2 -0
- package/templates/nodejs/AGENTS.md +9 -0
- package/templates/nodejs/blend.yaml +33 -0
- package/templates/nodejs/gitignore +6 -0
- package/templates/nodejs/package.json +32 -0
- package/templates/nodejs/src/app.ts +158 -0
- package/templates/nodejs/src/client/counter.tsx +12 -0
- package/templates/nodejs/src/client/tsconfig.json +26 -0
- package/templates/nodejs/src/door.ts +7 -0
- package/templates/nodejs/src/frame.ts +17 -0
- package/templates/nodejs/src/main.ts +20 -0
- package/templates/nodejs/src/page.tsx +29 -0
- package/templates/nodejs/src/routes.ts +59 -0
- package/templates/nodejs/template.json +14 -0
- package/templates/nodejs/test/app.test.ts +112 -0
- package/templates/nodejs/test/server.test.ts +97 -0
- package/templates/nodejs/tsconfig.json +20 -0
- package/templates/notes/.gitattributes +2 -0
- package/templates/notes/AGENTS.md +26 -0
- package/templates/notes/blend.yaml +36 -0
- package/templates/notes/gitignore +9 -0
- package/templates/notes/migrations/001-notes.sql +18 -0
- package/templates/notes/package.json +35 -0
- package/templates/notes/src/app.ts +165 -0
- package/templates/notes/src/auth.ts +57 -0
- package/templates/notes/src/client/counter.tsx +21 -0
- package/templates/notes/src/client/tsconfig.json +26 -0
- package/templates/notes/src/db.ts +50 -0
- package/templates/notes/src/door.ts +7 -0
- package/templates/notes/src/frame.ts +17 -0
- package/templates/notes/src/main.ts +23 -0
- package/templates/notes/src/notes-app.ts +212 -0
- package/templates/notes/src/routes.ts +21 -0
- package/templates/notes/src/runtime.ts +23 -0
- package/templates/notes/src/schema.ts +38 -0
- package/templates/notes/src/views.tsx +145 -0
- package/templates/notes/template.json +15 -0
- package/templates/notes/test/notes.test.ts +318 -0
- package/templates/notes/test/server.test.ts +92 -0
- package/templates/notes/tsconfig.json +20 -0
- package/templates/todo/.gitattributes +2 -0
- package/templates/todo/AGENTS.md +5 -0
- package/templates/todo/README.md +27 -0
- package/templates/todo/blend.yaml +28 -0
- package/templates/todo/gitignore +6 -0
- package/templates/todo/package.json +31 -0
- package/templates/todo/src/app.ts +145 -0
- package/templates/todo/src/door.ts +7 -0
- package/templates/todo/src/frame.ts +17 -0
- package/templates/todo/src/main.ts +21 -0
- package/templates/todo/src/page.ts +35 -0
- package/templates/todo/src/todo.ts +137 -0
- package/templates/todo/template.json +14 -0
- package/templates/todo/test/todo.test.ts +228 -0
- package/templates/todo/tsconfig.json +19 -0
|
@@ -0,0 +1,1812 @@
|
|
|
1
|
+
import { t as Acryl } from "../app-CM-rDcw6.js";
|
|
2
|
+
import { r as streamSSE } from "../streaming-CL2i3hX_.js";
|
|
3
|
+
import { o as pageAuthority } from "../loopback-only-0nTL30Zt.js";
|
|
4
|
+
import "../helpers-qmReU164.js";
|
|
5
|
+
import { n as clientModules } from "../client-modules-ChLgW0l9.js";
|
|
6
|
+
import { a as MAX_WAIT_MS, d as parseChannelToHost, l as UiControlError, p as parseUiRequest, r as MAX_SNAPSHOT_NODES, u as WINDOW_ID } from "../protocol-8HjYa5OX.js";
|
|
7
|
+
import { a as INVALID_JSON, c as operatorOnly, d as AuditLog, f as auditPath, i as DOOR_PREFIX, l as privateApi, o as error, p as UiChannel, r as pageChannelRoutes, s as jsonBody, t as renderSnapshot, u as readJson } from "../snapshot-text-Cyl69OKv.js";
|
|
8
|
+
import "../src-BycZ1HUQ.js";
|
|
9
|
+
import "../middleware-B8gJUDgl.js";
|
|
10
|
+
import { isAbsolute, join, relative, resolve } from "node:path";
|
|
11
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
12
|
+
import z from "@deepseek-ai/schemastery";
|
|
13
|
+
import { randomBytes } from "node:crypto";
|
|
14
|
+
import { spawnSync } from "node:child_process";
|
|
15
|
+
//#region ../../../plugins/door/src/page/base.ts
|
|
16
|
+
/**
|
|
17
|
+
* `path` (an app path, optionally with a query) under `base`: '/board' under '/app' is '/app/board'; the app's root is the base itself, so '/' is
|
|
18
|
+
* '/app' (its mount) and not '/app/'; without a base, the path as written.
|
|
19
|
+
*/
|
|
20
|
+
function underAppBase(base, path) {
|
|
21
|
+
if (base === "") return path;
|
|
22
|
+
const at = path.search(/[?#]/u);
|
|
23
|
+
const route = at === -1 ? path : path.slice(0, at);
|
|
24
|
+
const rest = at === -1 ? "" : path.slice(at);
|
|
25
|
+
if (route === base || route.startsWith(`${base}/`)) return path;
|
|
26
|
+
if (route === "/" || route === "") return `${base}${rest}`;
|
|
27
|
+
return `${base}${route.startsWith("/") ? "" : "/"}${route}${rest}`;
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region ../../../plugins/door/src/shell/protocol.ts
|
|
31
|
+
var ShellError = class extends Error {
|
|
32
|
+
code;
|
|
33
|
+
constructor(code, message) {
|
|
34
|
+
super(message);
|
|
35
|
+
this.code = code;
|
|
36
|
+
this.name = "ShellError";
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
/** A path of the app, as `act navigate` takes one: one leading `/`, and no other site. */
|
|
40
|
+
const APP_PATH = /^\/(?![/\\])[^\s\\]*$/u;
|
|
41
|
+
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
42
|
+
function only(value, allowed) {
|
|
43
|
+
const extra = Object.keys(value).filter((key) => key !== "op" && !allowed.includes(key));
|
|
44
|
+
if (extra.length > 0) throw new ShellError("invalid", `unknown field ${extra.join(", ")}`);
|
|
45
|
+
}
|
|
46
|
+
function windowId(value) {
|
|
47
|
+
if (typeof value.id !== "number" || !Number.isSafeInteger(value.id) || value.id < 1) throw new ShellError("invalid", "id must be the number `window list` prints for the window");
|
|
48
|
+
return value.id;
|
|
49
|
+
}
|
|
50
|
+
function size(value, key) {
|
|
51
|
+
const number = value[key];
|
|
52
|
+
if (typeof number !== "number" || !Number.isInteger(number) || number < 200 || number > 1e4) throw new ShellError("invalid", `${key} must be a whole number of pixels from 200 to 10000`);
|
|
53
|
+
return number;
|
|
54
|
+
}
|
|
55
|
+
/** @throws ShellError `invalid`. */
|
|
56
|
+
function parseShellRequest(op, input) {
|
|
57
|
+
const value = isRecord(input) ? input : {};
|
|
58
|
+
switch (op) {
|
|
59
|
+
case "window-list":
|
|
60
|
+
only(value, []);
|
|
61
|
+
return { op };
|
|
62
|
+
case "window-open":
|
|
63
|
+
only(value, ["path"]);
|
|
64
|
+
if (value.path === void 0) return { op };
|
|
65
|
+
if (typeof value.path !== "string" || !APP_PATH.test(value.path)) throw new ShellError("invalid", "path must be a path of this app, such as /settings (it starts with one /, and names no other site)");
|
|
66
|
+
return {
|
|
67
|
+
op,
|
|
68
|
+
path: value.path
|
|
69
|
+
};
|
|
70
|
+
case "window-focus":
|
|
71
|
+
only(value, ["id"]);
|
|
72
|
+
return {
|
|
73
|
+
op,
|
|
74
|
+
id: windowId(value)
|
|
75
|
+
};
|
|
76
|
+
case "window-close":
|
|
77
|
+
only(value, ["id", "force"]);
|
|
78
|
+
if (value.force !== void 0 && typeof value.force !== "boolean") throw new ShellError("invalid", "force must be true or false");
|
|
79
|
+
return {
|
|
80
|
+
op,
|
|
81
|
+
id: windowId(value),
|
|
82
|
+
...value.force === true ? { force: true } : {}
|
|
83
|
+
};
|
|
84
|
+
case "window-resize":
|
|
85
|
+
only(value, [
|
|
86
|
+
"id",
|
|
87
|
+
"width",
|
|
88
|
+
"height"
|
|
89
|
+
]);
|
|
90
|
+
return {
|
|
91
|
+
op,
|
|
92
|
+
id: windowId(value),
|
|
93
|
+
width: size(value, "width"),
|
|
94
|
+
height: size(value, "height")
|
|
95
|
+
};
|
|
96
|
+
case "menu-list":
|
|
97
|
+
only(value, []);
|
|
98
|
+
return { op };
|
|
99
|
+
case "menu-click":
|
|
100
|
+
only(value, ["path", "force"]);
|
|
101
|
+
if (typeof value.path !== "string" || value.path.trim() === "" || value.path.length > 300) throw new ShellError("invalid", "path is the labels from the top of the menu joined with >, e.g. \"File>New Note\" (`menu list` prints them)");
|
|
102
|
+
if (value.force !== void 0 && typeof value.force !== "boolean") throw new ShellError("invalid", "force must be true or false");
|
|
103
|
+
return {
|
|
104
|
+
op,
|
|
105
|
+
path: value.path,
|
|
106
|
+
...value.force === true ? { force: true } : {}
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/** @param value - one parsed POST body from the shell; null when it is not a well-formed answer. */
|
|
111
|
+
function parseShellAnswer(value) {
|
|
112
|
+
if (!isRecord(value) || typeof value.id !== "number" || !Number.isSafeInteger(value.id)) return null;
|
|
113
|
+
if (value.t === "result" && isRecord(value.value)) return {
|
|
114
|
+
t: "result",
|
|
115
|
+
id: value.id,
|
|
116
|
+
value: value.value
|
|
117
|
+
};
|
|
118
|
+
if (value.t === "error" && typeof value.code === "string" && typeof value.message === "string") return {
|
|
119
|
+
t: "error",
|
|
120
|
+
id: value.id,
|
|
121
|
+
code: value.code.slice(0, 40),
|
|
122
|
+
message: value.message.slice(0, 500)
|
|
123
|
+
};
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
/** Whatever code the shell used, as one the door knows (an unknown code is `failed`). */
|
|
127
|
+
function shellErrorCode(code) {
|
|
128
|
+
return [
|
|
129
|
+
"invalid",
|
|
130
|
+
"no-such-window",
|
|
131
|
+
"last-window",
|
|
132
|
+
"no-such-menu-item",
|
|
133
|
+
"disabled",
|
|
134
|
+
"quits-app"
|
|
135
|
+
].find((known) => known === code) ?? "failed";
|
|
136
|
+
}
|
|
137
|
+
//#endregion
|
|
138
|
+
//#region ../../../plugins/door/src/host/shell.ts
|
|
139
|
+
/**
|
|
140
|
+
* The desktop shell's channel: the Electron main process of `npm run desktop`, which reaches the door as a page does (an event stream down, a POST up) and answers calls about
|
|
141
|
+
* the app's windows and menu. One shell at a time: a new one replaces the old (the dev server restarted and the shell came back). It needs this run's secret, so no page can open it.
|
|
142
|
+
*/
|
|
143
|
+
const CALL_TIMEOUT_MS = 1e4;
|
|
144
|
+
/** What a verb says when no desktop shell is attached: one line a model can act on. */
|
|
145
|
+
const NO_DESKTOP = "no desktop window is attached; run npm run desktop";
|
|
146
|
+
var ShellChannel = class {
|
|
147
|
+
current;
|
|
148
|
+
pending = /* @__PURE__ */ new Map();
|
|
149
|
+
nextId = 1;
|
|
150
|
+
closed = false;
|
|
151
|
+
attachWaiters = /* @__PURE__ */ new Set();
|
|
152
|
+
get connected() {
|
|
153
|
+
return this.current !== void 0;
|
|
154
|
+
}
|
|
155
|
+
/** @returns the function to call when this stream ends. */
|
|
156
|
+
attach(stream) {
|
|
157
|
+
const previous = this.current;
|
|
158
|
+
const connection = { stream };
|
|
159
|
+
this.current = connection;
|
|
160
|
+
if (previous !== void 0) {
|
|
161
|
+
this.failAll(new ShellError("disconnected", "the desktop shell reconnected before it answered"));
|
|
162
|
+
previous.stream.close();
|
|
163
|
+
}
|
|
164
|
+
for (const waiter of [...this.attachWaiters]) waiter();
|
|
165
|
+
return () => {
|
|
166
|
+
if (this.current !== connection) return;
|
|
167
|
+
this.current = void 0;
|
|
168
|
+
this.failAll(new ShellError("disconnected", "the desktop shell went away before it answered"));
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
/** A promise for the shell connecting (it reconnects after the dev server restarted). */
|
|
172
|
+
waitForShell(timeoutMs) {
|
|
173
|
+
if (this.current !== void 0) return Promise.resolve(true);
|
|
174
|
+
return new Promise((resolve) => {
|
|
175
|
+
const done = (value) => {
|
|
176
|
+
clearTimeout(timer);
|
|
177
|
+
this.attachWaiters.delete(waiter);
|
|
178
|
+
resolve(value);
|
|
179
|
+
};
|
|
180
|
+
const waiter = () => {
|
|
181
|
+
done(true);
|
|
182
|
+
};
|
|
183
|
+
const timer = setTimeout(() => {
|
|
184
|
+
done(false);
|
|
185
|
+
}, timeoutMs);
|
|
186
|
+
this.attachWaiters.add(waiter);
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
receive(body) {
|
|
190
|
+
const answer = parseShellAnswer(body);
|
|
191
|
+
if (answer === null) return;
|
|
192
|
+
if (answer.t === "result") this.settle(answer.id, answer.value);
|
|
193
|
+
else this.settle(answer.id, void 0, new ShellError(shellErrorCode(answer.code), answer.message));
|
|
194
|
+
}
|
|
195
|
+
/** @throws ShellError `no-desktop` when no shell is attached, else what the shell refused with. */
|
|
196
|
+
call(request, options = {}) {
|
|
197
|
+
if (this.closed) return Promise.reject(new ShellError("unloaded", "the door was unloaded"));
|
|
198
|
+
const target = this.current;
|
|
199
|
+
if (target === void 0) return Promise.reject(new ShellError("no-desktop", NO_DESKTOP));
|
|
200
|
+
const signal = options.signal;
|
|
201
|
+
if (signal?.aborted === true) return Promise.reject(new ShellError("aborted", "the call was cancelled"));
|
|
202
|
+
const id = this.nextId;
|
|
203
|
+
this.nextId += 1;
|
|
204
|
+
return new Promise((resolve, reject) => {
|
|
205
|
+
const timer = setTimeout(() => {
|
|
206
|
+
this.settle(id, void 0, new ShellError("timeout", "the desktop shell did not answer in time"));
|
|
207
|
+
}, options.timeoutMs ?? CALL_TIMEOUT_MS);
|
|
208
|
+
const onAbort = () => {
|
|
209
|
+
this.settle(id, void 0, new ShellError("aborted", "the call was cancelled"));
|
|
210
|
+
};
|
|
211
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
212
|
+
this.pending.set(id, {
|
|
213
|
+
resolve,
|
|
214
|
+
reject,
|
|
215
|
+
timer,
|
|
216
|
+
cleanup: () => {
|
|
217
|
+
signal?.removeEventListener("abort", onAbort);
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
try {
|
|
221
|
+
target.stream.send(JSON.stringify({
|
|
222
|
+
t: "call",
|
|
223
|
+
id,
|
|
224
|
+
request
|
|
225
|
+
}));
|
|
226
|
+
} catch {
|
|
227
|
+
this.settle(id, void 0, new ShellError("disconnected", "the desktop shell could not be reached"));
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
close() {
|
|
232
|
+
this.closed = true;
|
|
233
|
+
this.failAll(new ShellError("unloaded", "the door was unloaded"));
|
|
234
|
+
this.current?.stream.close();
|
|
235
|
+
this.current = void 0;
|
|
236
|
+
}
|
|
237
|
+
failAll(failure) {
|
|
238
|
+
for (const id of [...this.pending.keys()]) this.settle(id, void 0, failure);
|
|
239
|
+
}
|
|
240
|
+
settle(id, value, failure) {
|
|
241
|
+
const entry = this.pending.get(id);
|
|
242
|
+
if (entry === void 0) return;
|
|
243
|
+
this.pending.delete(id);
|
|
244
|
+
clearTimeout(entry.timer);
|
|
245
|
+
entry.cleanup();
|
|
246
|
+
if (failure !== void 0) entry.reject(failure);
|
|
247
|
+
else entry.resolve(value);
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
/** How often a `ping` is written, so the shell knows a silent stream died and reconnects. */
|
|
251
|
+
const SHELL_HEARTBEAT_MS = 15e3;
|
|
252
|
+
/** `GET <prefix>/shell/events` is the shell's stream and `POST <prefix>/shell/answer` carries its answers: both need this run's secret. */
|
|
253
|
+
function shellRoutes(prefix, secret, channel, heartbeatMs = SHELL_HEARTBEAT_MS) {
|
|
254
|
+
return new Acryl().get(`${prefix}/shell/events`, operatorOnly(secret), (c) => {
|
|
255
|
+
const signal = c.req.raw.signal;
|
|
256
|
+
return streamSSE(c, async (stream) => {
|
|
257
|
+
let end = () => {};
|
|
258
|
+
const ended = new Promise((resolve) => {
|
|
259
|
+
end = resolve;
|
|
260
|
+
});
|
|
261
|
+
stream.onAbort(end);
|
|
262
|
+
signal.addEventListener("abort", end, { once: true });
|
|
263
|
+
const write = (event, data) => {
|
|
264
|
+
stream.writeSSE({
|
|
265
|
+
event,
|
|
266
|
+
data
|
|
267
|
+
}).catch(end);
|
|
268
|
+
};
|
|
269
|
+
const detach = channel.attach({
|
|
270
|
+
send: (data) => {
|
|
271
|
+
write("call", data);
|
|
272
|
+
},
|
|
273
|
+
close: end
|
|
274
|
+
});
|
|
275
|
+
const beat = setInterval(() => {
|
|
276
|
+
write("ping", "");
|
|
277
|
+
}, heartbeatMs);
|
|
278
|
+
try {
|
|
279
|
+
write("ready", "");
|
|
280
|
+
await ended;
|
|
281
|
+
} finally {
|
|
282
|
+
clearInterval(beat);
|
|
283
|
+
signal.removeEventListener("abort", end);
|
|
284
|
+
detach();
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
}).post(`${prefix}/shell/answer`, operatorOnly(secret), jsonBody, async (c) => {
|
|
288
|
+
const body = await readJson(c);
|
|
289
|
+
if (body === INVALID_JSON || typeof body !== "object" || body === null) return c.json(error("invalid request body"), 400);
|
|
290
|
+
channel.receive(body);
|
|
291
|
+
return c.json({ ok: true });
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
//#endregion
|
|
295
|
+
//#region ../../../plugins/door/src/host/verbs.ts
|
|
296
|
+
/**
|
|
297
|
+
* The one verb list (spec 049 slice 13). Every face of the door reads it: the operator client (`acryl <verb>`, its `verbs` and `brief`),
|
|
298
|
+
* MCP (`tools/list`) and the built-in chat (the `tools` registry). A verb added here is in all three, or the comparison test fails.
|
|
299
|
+
*/
|
|
300
|
+
/** Every verb, in the order `brief` lists them. */
|
|
301
|
+
/** The verbs that only use the page: what a page-only door (a production assistant) offers. */
|
|
302
|
+
const PAGE_VERBS = ["look", "act"];
|
|
303
|
+
const VERBS = [
|
|
304
|
+
"brief",
|
|
305
|
+
"look",
|
|
306
|
+
"act",
|
|
307
|
+
"plugin-list",
|
|
308
|
+
"plugin-add",
|
|
309
|
+
"plugin-pull",
|
|
310
|
+
"plugin-publish",
|
|
311
|
+
"plugin-remove",
|
|
312
|
+
"plugin-reload",
|
|
313
|
+
"tool-list",
|
|
314
|
+
"tool-call",
|
|
315
|
+
"window-list",
|
|
316
|
+
"window-open",
|
|
317
|
+
"window-focus",
|
|
318
|
+
"window-close",
|
|
319
|
+
"window-resize",
|
|
320
|
+
"menu-list",
|
|
321
|
+
"menu-click"
|
|
322
|
+
];
|
|
323
|
+
const none = {
|
|
324
|
+
type: "object",
|
|
325
|
+
properties: {},
|
|
326
|
+
additionalProperties: false
|
|
327
|
+
};
|
|
328
|
+
const VERB_SPECS = {
|
|
329
|
+
"brief": {
|
|
330
|
+
usage: "brief: this summary",
|
|
331
|
+
description: "What this app is, which files to read first, whether its page is open, and the verbs.",
|
|
332
|
+
arguments: none
|
|
333
|
+
},
|
|
334
|
+
"look": {
|
|
335
|
+
usage: "look [--window <n>] [--cursor <n>] [--max-nodes <n>]: the page as text, with refs",
|
|
336
|
+
description: "The open page as text: its roles, names, values and visible text, each with a ref to act on. A long page comes in parts (cursor).",
|
|
337
|
+
arguments: {
|
|
338
|
+
type: "object",
|
|
339
|
+
properties: {
|
|
340
|
+
cursor: {
|
|
341
|
+
type: "integer",
|
|
342
|
+
minimum: 0,
|
|
343
|
+
description: "where the previous part ended"
|
|
344
|
+
},
|
|
345
|
+
maxNodes: {
|
|
346
|
+
type: "integer",
|
|
347
|
+
minimum: 1,
|
|
348
|
+
maximum: MAX_SNAPSHOT_NODES
|
|
349
|
+
},
|
|
350
|
+
window: {
|
|
351
|
+
type: "integer",
|
|
352
|
+
minimum: 1,
|
|
353
|
+
description: "a desktop window (the id window-list prints); default: the page used last"
|
|
354
|
+
}
|
|
355
|
+
},
|
|
356
|
+
additionalProperties: false
|
|
357
|
+
}
|
|
358
|
+
},
|
|
359
|
+
"act": {
|
|
360
|
+
usage: "act click|type|select|press|scroll|wait|reload|navigate ...: do one thing on the page (refs from the latest look)",
|
|
361
|
+
description: "Do one thing on the page: click, type, select, press a key, scroll, wait for text or a control, reload the page, or navigate to another path of the app. Look again before the next act.",
|
|
362
|
+
arguments: {
|
|
363
|
+
type: "object",
|
|
364
|
+
properties: {
|
|
365
|
+
op: {
|
|
366
|
+
type: "string",
|
|
367
|
+
enum: [
|
|
368
|
+
"click",
|
|
369
|
+
"type",
|
|
370
|
+
"select",
|
|
371
|
+
"press",
|
|
372
|
+
"scroll",
|
|
373
|
+
"wait",
|
|
374
|
+
"reload",
|
|
375
|
+
"navigate"
|
|
376
|
+
]
|
|
377
|
+
},
|
|
378
|
+
path: {
|
|
379
|
+
type: "string",
|
|
380
|
+
description: "navigate: a path of this app, e.g. /demo (the page must load the door script to be controlled afterwards)"
|
|
381
|
+
},
|
|
382
|
+
ref: {
|
|
383
|
+
type: "string",
|
|
384
|
+
description: "a ref from the latest look, e.g. 3.12"
|
|
385
|
+
},
|
|
386
|
+
text: {
|
|
387
|
+
type: "string",
|
|
388
|
+
description: "type: what to type; wait: the text to wait for"
|
|
389
|
+
},
|
|
390
|
+
submit: {
|
|
391
|
+
type: "boolean",
|
|
392
|
+
description: "type: press Enter after"
|
|
393
|
+
},
|
|
394
|
+
clear: {
|
|
395
|
+
type: "boolean",
|
|
396
|
+
description: "type: false keeps what the field holds"
|
|
397
|
+
},
|
|
398
|
+
option: {
|
|
399
|
+
type: "string",
|
|
400
|
+
description: "select: the option to choose"
|
|
401
|
+
},
|
|
402
|
+
key: {
|
|
403
|
+
type: "string",
|
|
404
|
+
description: "press: a character or Enter, Escape, Tab, ArrowDown, ..."
|
|
405
|
+
},
|
|
406
|
+
direction: {
|
|
407
|
+
type: "string",
|
|
408
|
+
enum: [
|
|
409
|
+
"up",
|
|
410
|
+
"down",
|
|
411
|
+
"left",
|
|
412
|
+
"right"
|
|
413
|
+
]
|
|
414
|
+
},
|
|
415
|
+
amount: {
|
|
416
|
+
type: "number",
|
|
417
|
+
minimum: 1,
|
|
418
|
+
maximum: 1e4,
|
|
419
|
+
description: "scroll: pixels"
|
|
420
|
+
},
|
|
421
|
+
role: {
|
|
422
|
+
type: "string",
|
|
423
|
+
description: "wait: the role to wait for"
|
|
424
|
+
},
|
|
425
|
+
name: {
|
|
426
|
+
type: "string",
|
|
427
|
+
description: "wait: its name"
|
|
428
|
+
},
|
|
429
|
+
gone: {
|
|
430
|
+
type: "boolean",
|
|
431
|
+
description: "wait: until it is gone instead"
|
|
432
|
+
},
|
|
433
|
+
timeoutMs: {
|
|
434
|
+
type: "integer",
|
|
435
|
+
minimum: 0,
|
|
436
|
+
maximum: MAX_WAIT_MS
|
|
437
|
+
},
|
|
438
|
+
window: {
|
|
439
|
+
type: "integer",
|
|
440
|
+
minimum: 1,
|
|
441
|
+
description: "a desktop window (the id window-list prints); default: the page used last"
|
|
442
|
+
}
|
|
443
|
+
},
|
|
444
|
+
required: ["op"],
|
|
445
|
+
additionalProperties: false
|
|
446
|
+
}
|
|
447
|
+
},
|
|
448
|
+
"plugin-list": {
|
|
449
|
+
usage: "plugin list: the plugins installed while the app runs",
|
|
450
|
+
description: "The plugins installed into the running app.",
|
|
451
|
+
arguments: none
|
|
452
|
+
},
|
|
453
|
+
"plugin-add": {
|
|
454
|
+
usage: "plugin add <folder>: check, install and start a plugin folder, live",
|
|
455
|
+
description: "Check, install and start a plugin folder inside the app, without a restart.",
|
|
456
|
+
arguments: {
|
|
457
|
+
type: "object",
|
|
458
|
+
properties: { folder: {
|
|
459
|
+
type: "string",
|
|
460
|
+
description: "a folder inside the app, e.g. plugins/pomodoro"
|
|
461
|
+
} },
|
|
462
|
+
required: ["folder"],
|
|
463
|
+
additionalProperties: false
|
|
464
|
+
}
|
|
465
|
+
},
|
|
466
|
+
"plugin-pull": {
|
|
467
|
+
usage: "plugin pull <source> | --from <list>: fetch a plugin someone released (github:<owner>/<repo>[@<version>][@sha256:<digest>], or a .tgz), or every plugin of a group's list, check each and start it, live",
|
|
468
|
+
description: "Fetch a plugin someone released, without running anything; check its digest, that it works on every OS and that this app has the services it needs; then install and start it without a restart. A refusal says why and changes nothing. With from instead of source, pull every source of a group's list (one per line, # comments); each is pulled on its own, so a refused one is named with its reason and the others still come in.",
|
|
469
|
+
arguments: {
|
|
470
|
+
type: "object",
|
|
471
|
+
properties: {
|
|
472
|
+
source: {
|
|
473
|
+
type: "string",
|
|
474
|
+
description: "github:<owner>/<repo>[@<version>][@sha256:<digest>], or a .tgz path or https address"
|
|
475
|
+
},
|
|
476
|
+
from: {
|
|
477
|
+
type: "string",
|
|
478
|
+
description: "instead of source: a list of sources, a file in the app (e.g. group.txt) or an https address"
|
|
479
|
+
}
|
|
480
|
+
},
|
|
481
|
+
additionalProperties: false
|
|
482
|
+
}
|
|
483
|
+
},
|
|
484
|
+
"plugin-publish": {
|
|
485
|
+
usage: "plugin publish <name> [--owner <account>] [--license <id>]: show what publishing this plugin would send; in a person's own terminal, ask them",
|
|
486
|
+
description: "Show what publishing a plugin would send: the account, repository, version, license, files and the line a friend pulls it with. Sends nothing. Only a person can say yes, in their own terminal or with Share in the frame; tell them the plan and how.",
|
|
487
|
+
arguments: {
|
|
488
|
+
type: "object",
|
|
489
|
+
properties: {
|
|
490
|
+
name: {
|
|
491
|
+
type: "string",
|
|
492
|
+
description: "a plugin of plugins/"
|
|
493
|
+
},
|
|
494
|
+
owner: {
|
|
495
|
+
type: "string",
|
|
496
|
+
description: "the GitHub account or organization; the signed-in one when absent"
|
|
497
|
+
},
|
|
498
|
+
license: {
|
|
499
|
+
type: "string",
|
|
500
|
+
description: "an SPDX license id; MIT when absent"
|
|
501
|
+
}
|
|
502
|
+
},
|
|
503
|
+
required: ["name"],
|
|
504
|
+
additionalProperties: false
|
|
505
|
+
}
|
|
506
|
+
},
|
|
507
|
+
"plugin-remove": {
|
|
508
|
+
usage: "plugin remove <name>: stop and remove an installed plugin",
|
|
509
|
+
description: "Stop and remove an installed plugin.",
|
|
510
|
+
arguments: {
|
|
511
|
+
type: "object",
|
|
512
|
+
properties: { name: { type: "string" } },
|
|
513
|
+
required: ["name"],
|
|
514
|
+
additionalProperties: false
|
|
515
|
+
}
|
|
516
|
+
},
|
|
517
|
+
"plugin-reload": {
|
|
518
|
+
usage: "plugin reload: bring every installed plugin in line with its folder",
|
|
519
|
+
description: "Bring every installed plugin in line with its folder (after editing one).",
|
|
520
|
+
arguments: none
|
|
521
|
+
},
|
|
522
|
+
"tool-list": {
|
|
523
|
+
usage: "tool list: the app tools the door offers",
|
|
524
|
+
description: "The app's own tools that the door offers.",
|
|
525
|
+
arguments: none
|
|
526
|
+
},
|
|
527
|
+
"tool-call": {
|
|
528
|
+
usage: "tool call --tool <name> [--args <json>]: run one of them",
|
|
529
|
+
description: "Run one of the app tools that tool-list names.",
|
|
530
|
+
arguments: {
|
|
531
|
+
type: "object",
|
|
532
|
+
properties: {
|
|
533
|
+
tool: { type: "string" },
|
|
534
|
+
args: { description: "the tool's input" }
|
|
535
|
+
},
|
|
536
|
+
required: ["tool"],
|
|
537
|
+
additionalProperties: false
|
|
538
|
+
}
|
|
539
|
+
},
|
|
540
|
+
"window-list": {
|
|
541
|
+
usage: "window list: the windows of the desktop app",
|
|
542
|
+
description: "The windows of the desktop app: id, title, path, size, and which one is focused. Needs the desktop app (npm run desktop).",
|
|
543
|
+
arguments: none
|
|
544
|
+
},
|
|
545
|
+
"window-open": {
|
|
546
|
+
usage: "window open [--path <path of the app>]: open a new window",
|
|
547
|
+
description: "Open a new window of the desktop app on a path of the app (default: its start page). Answers with the new window's id; look and act take it as window.",
|
|
548
|
+
arguments: {
|
|
549
|
+
type: "object",
|
|
550
|
+
properties: { path: {
|
|
551
|
+
type: "string",
|
|
552
|
+
description: "a path of this app, e.g. /settings"
|
|
553
|
+
} },
|
|
554
|
+
additionalProperties: false
|
|
555
|
+
}
|
|
556
|
+
},
|
|
557
|
+
"window-focus": {
|
|
558
|
+
usage: "window focus --id <n>: bring a window to the front",
|
|
559
|
+
description: "Bring a window of the desktop app to the front. Look and act without a window then drive it.",
|
|
560
|
+
arguments: {
|
|
561
|
+
type: "object",
|
|
562
|
+
properties: { id: {
|
|
563
|
+
type: "integer",
|
|
564
|
+
minimum: 1,
|
|
565
|
+
description: "the id window-list prints"
|
|
566
|
+
} },
|
|
567
|
+
required: ["id"],
|
|
568
|
+
additionalProperties: false
|
|
569
|
+
}
|
|
570
|
+
},
|
|
571
|
+
"window-close": {
|
|
572
|
+
usage: "window close --id <n> [--force]: close a window",
|
|
573
|
+
description: "Close a window of the desktop app. The last window cannot be closed without force, because that ends the desktop app.",
|
|
574
|
+
arguments: {
|
|
575
|
+
type: "object",
|
|
576
|
+
properties: {
|
|
577
|
+
id: {
|
|
578
|
+
type: "integer",
|
|
579
|
+
minimum: 1
|
|
580
|
+
},
|
|
581
|
+
force: {
|
|
582
|
+
type: "boolean",
|
|
583
|
+
description: "allow closing the last window, which ends the desktop app"
|
|
584
|
+
}
|
|
585
|
+
},
|
|
586
|
+
required: ["id"],
|
|
587
|
+
additionalProperties: false
|
|
588
|
+
}
|
|
589
|
+
},
|
|
590
|
+
"window-resize": {
|
|
591
|
+
usage: "window resize --id <n> --width <px> --height <px>",
|
|
592
|
+
description: "Resize a window of the desktop app.",
|
|
593
|
+
arguments: {
|
|
594
|
+
type: "object",
|
|
595
|
+
properties: {
|
|
596
|
+
id: {
|
|
597
|
+
type: "integer",
|
|
598
|
+
minimum: 1
|
|
599
|
+
},
|
|
600
|
+
width: {
|
|
601
|
+
type: "integer",
|
|
602
|
+
minimum: 200,
|
|
603
|
+
maximum: 1e4
|
|
604
|
+
},
|
|
605
|
+
height: {
|
|
606
|
+
type: "integer",
|
|
607
|
+
minimum: 200,
|
|
608
|
+
maximum: 1e4
|
|
609
|
+
}
|
|
610
|
+
},
|
|
611
|
+
required: [
|
|
612
|
+
"id",
|
|
613
|
+
"width",
|
|
614
|
+
"height"
|
|
615
|
+
],
|
|
616
|
+
additionalProperties: false
|
|
617
|
+
}
|
|
618
|
+
},
|
|
619
|
+
"menu-list": {
|
|
620
|
+
usage: "menu list: the application menu",
|
|
621
|
+
description: "The desktop app's application menu as paths such as File>New Note, with the disabled items marked.",
|
|
622
|
+
arguments: none
|
|
623
|
+
},
|
|
624
|
+
"menu-click": {
|
|
625
|
+
usage: "menu click --path \"File>New Note\" [--force]: press a menu item",
|
|
626
|
+
description: "Press an item of the desktop app's application menu by its path (labels joined with >, as menu-list prints them). A disabled item is refused, and so is one that ends the app (Quit, Close Window on the last window) unless force is set.",
|
|
627
|
+
arguments: {
|
|
628
|
+
type: "object",
|
|
629
|
+
properties: {
|
|
630
|
+
path: {
|
|
631
|
+
type: "string",
|
|
632
|
+
description: "e.g. File>New Note"
|
|
633
|
+
},
|
|
634
|
+
force: {
|
|
635
|
+
type: "boolean",
|
|
636
|
+
description: "allow an item that ends the desktop app"
|
|
637
|
+
}
|
|
638
|
+
},
|
|
639
|
+
required: ["path"],
|
|
640
|
+
additionalProperties: false
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
};
|
|
644
|
+
/** A verb's name in the `tools` registry the built-in chat reads: prefixed, so it never meets an app tool's name. */
|
|
645
|
+
const chatToolName = (verb) => `door_${verb.replaceAll("-", "_")}`;
|
|
646
|
+
//#endregion
|
|
647
|
+
//#region ../../../plugins/door/src/host/door.ts
|
|
648
|
+
/**
|
|
649
|
+
* The door's verbs, one implementation for every face: `brief`, `look`, `act`, `plugin list|add|remove|reload` and `tool list|call`
|
|
650
|
+
* (`verbs.ts` lists them; the operator client, MCP and the built-in chat all call these). Each verb takes plain JSON arguments,
|
|
651
|
+
* returns a typed value and a text rendering, and fails with a {@link DoorError} or a {@link UiControlError} carrying a code.
|
|
652
|
+
*/
|
|
653
|
+
var DoorError = class extends Error {
|
|
654
|
+
code;
|
|
655
|
+
constructor(code, message) {
|
|
656
|
+
super(message);
|
|
657
|
+
this.code = code;
|
|
658
|
+
this.name = "DoorError";
|
|
659
|
+
}
|
|
660
|
+
};
|
|
661
|
+
/** What a plan says, for a person deciding. */
|
|
662
|
+
function renderPublishPlan(plan) {
|
|
663
|
+
return [
|
|
664
|
+
`Publish to ${plan.owner}/${plan.repo}${plan.createsRepository ? " (a new repository)" : ""}, ${plan.visibility}, version ${plan.version}, license ${plan.license}.`,
|
|
665
|
+
`Files: ${plan.files.join(", ")}.`,
|
|
666
|
+
`A friend gets exactly these bytes with: ${plan.pullLine}`
|
|
667
|
+
].join("\n");
|
|
668
|
+
}
|
|
669
|
+
/** Whether a `tools` service is DSH's registry rather than the framework agent's. */
|
|
670
|
+
const isDshTools = (tools) => typeof tools?.schemas === "function";
|
|
671
|
+
/** The tools a registry lists: DSH's `schemas()` or the framework agent's `list()`. */
|
|
672
|
+
const listedTools = (tools) => isDshTools(tools) ? tools.schemas() : tools.list();
|
|
673
|
+
/** A shell answer as text an agent reads: windows and menu items one to a line. */
|
|
674
|
+
function renderShell(result) {
|
|
675
|
+
if ("windows" in result) return result.windows.length === 0 ? "no windows are open" : result.windows.map((window) => `${String(window.id)} ${JSON.stringify(window.title)} ${window.path} ${String(window.width)}x${String(window.height)}${window.x === void 0 || window.y === void 0 ? "" : `@${String(window.x)},${String(window.y)}`}${window.focused ? " focused" : ""}`).join("\n");
|
|
676
|
+
if ("items" in result) return result.items.length === 0 ? "the app has no menu" : result.items.map((item) => `${item.path}${item.enabled ? "" : " (disabled)"}${item.ends === true ? " (ends the app; needs force)" : ""}`).join("\n");
|
|
677
|
+
return result.detail;
|
|
678
|
+
}
|
|
679
|
+
/** The files an agent should read first, when the app has them. */
|
|
680
|
+
const SELF_KNOWLEDGE = [
|
|
681
|
+
"AGENTS.md",
|
|
682
|
+
"CLAUDE.md",
|
|
683
|
+
".agents/skills",
|
|
684
|
+
".claude/skills",
|
|
685
|
+
"docs",
|
|
686
|
+
"plugins"
|
|
687
|
+
];
|
|
688
|
+
/** How long a reload or a move may take before the new page has connected to the door again. */
|
|
689
|
+
const PAGE_BACK_MS = 15e3;
|
|
690
|
+
var Door = class {
|
|
691
|
+
deps;
|
|
692
|
+
constructor(deps) {
|
|
693
|
+
this.deps = deps;
|
|
694
|
+
}
|
|
695
|
+
/** A run asked for from the panel of this page is going: its verbs that name no window are for that page. @returns the function to call when the run ends. */
|
|
696
|
+
driveFor(windowId) {
|
|
697
|
+
return this.deps.channel.driveFor(windowId);
|
|
698
|
+
}
|
|
699
|
+
/** Run one verb. @throws DoorError or UiControlError. */
|
|
700
|
+
async run(verb, args, signal, scope = {}) {
|
|
701
|
+
const input = typeof args === "object" && args !== null && !Array.isArray(args) ? args : {};
|
|
702
|
+
switch (verb) {
|
|
703
|
+
case "brief": return this.brief();
|
|
704
|
+
case "look": {
|
|
705
|
+
const snapshot = await this.look(input, signal, scope);
|
|
706
|
+
return {
|
|
707
|
+
value: snapshot,
|
|
708
|
+
text: renderSnapshot(snapshot, (cursor) => `run look --cursor ${String(cursor)}`)
|
|
709
|
+
};
|
|
710
|
+
}
|
|
711
|
+
case "act": {
|
|
712
|
+
const result = await this.act(input, signal, scope);
|
|
713
|
+
return {
|
|
714
|
+
value: result,
|
|
715
|
+
text: `done${result.target === void 0 ? "" : `: ${result.target.role} "${result.target.name}"`}${result.detail === void 0 ? "" : ` (${result.detail})`}; look again before the next act`
|
|
716
|
+
};
|
|
717
|
+
}
|
|
718
|
+
case "plugin-list": return this.plugin((plugins) => plugins.list(), false, this.installed());
|
|
719
|
+
case "plugin-add": return this.plugin((extensions) => extensions.install(this.insideApp(input.folder)));
|
|
720
|
+
case "plugin-pull": return input.from === void 0 ? this.pull(input.source) : this.pullList(input.from, input.source);
|
|
721
|
+
case "plugin-publish": return this.planPublish(input);
|
|
722
|
+
case "plugin-remove": {
|
|
723
|
+
const name = input.name;
|
|
724
|
+
if (typeof name !== "string" || name === "") throw new DoorError("invalid", "plugin remove needs a plugin name");
|
|
725
|
+
return this.plugin((plugins) => plugins.remove(name), true, this.installed());
|
|
726
|
+
}
|
|
727
|
+
case "plugin-reload": return this.plugin((extensions) => extensions.reload());
|
|
728
|
+
case "tool-list": {
|
|
729
|
+
const offered = this.offeredTools();
|
|
730
|
+
return {
|
|
731
|
+
value: offered,
|
|
732
|
+
text: offered.length === 0 ? "no app tools are offered through the door (tools.expose is empty)" : offered.map((tool) => `${tool.name}: ${tool.description}`).join("\n")
|
|
733
|
+
};
|
|
734
|
+
}
|
|
735
|
+
case "tool-call": return this.callTool(input);
|
|
736
|
+
case "window-list":
|
|
737
|
+
case "window-open":
|
|
738
|
+
case "window-focus":
|
|
739
|
+
case "window-close":
|
|
740
|
+
case "window-resize":
|
|
741
|
+
case "menu-list":
|
|
742
|
+
case "menu-click": return this.desktop(verb, input, signal);
|
|
743
|
+
default: throw new DoorError("unknown-verb", `unknown verb ${JSON.stringify(verb)}; the verbs are ${VERBS.join(", ")}`);
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
brief() {
|
|
747
|
+
const { name, root, url } = this.deps.app;
|
|
748
|
+
const read = SELF_KNOWLEDGE.filter((path) => existsSync(resolve(root, path)));
|
|
749
|
+
const value = {
|
|
750
|
+
app: name,
|
|
751
|
+
root,
|
|
752
|
+
...url === void 0 ? {} : { url },
|
|
753
|
+
read,
|
|
754
|
+
page: this.deps.channel.connected ? "open" : "not open",
|
|
755
|
+
plugins: this.deps.extensions() === void 0 ? "unavailable" : "available",
|
|
756
|
+
verbs: VERBS.map((verb) => VERB_SPECS[verb].usage)
|
|
757
|
+
};
|
|
758
|
+
return {
|
|
759
|
+
value,
|
|
760
|
+
text: [
|
|
761
|
+
`App ${name} in ${root}.`,
|
|
762
|
+
...url === void 0 ? [] : [`Address: ${url} (the running app; curl it to check a route).`],
|
|
763
|
+
read.length === 0 ? "No AGENTS.md or skill in the folder." : `Read first: ${read.join(", ")}.`,
|
|
764
|
+
`Page: ${value.page}${value.page === "not open" ? " (open the app in a browser to look and act)" : ""}.`,
|
|
765
|
+
`Live plugins: ${value.plugins}.`,
|
|
766
|
+
"Verbs:",
|
|
767
|
+
...value.verbs.map((line) => ` ${line}`)
|
|
768
|
+
].join("\n")
|
|
769
|
+
};
|
|
770
|
+
}
|
|
771
|
+
look(input, signal, scope = {}) {
|
|
772
|
+
const { window, rest } = this.windowOf(input, scope);
|
|
773
|
+
const request = this.parse({
|
|
774
|
+
...rest,
|
|
775
|
+
op: "snapshot"
|
|
776
|
+
});
|
|
777
|
+
return this.callPage("look", request, signal, window, scope.page);
|
|
778
|
+
}
|
|
779
|
+
async act(input, signal, scope = {}) {
|
|
780
|
+
if (input.op === "snapshot") throw new DoorError("invalid", "use look to see the page");
|
|
781
|
+
const { window, rest } = this.windowOf(input, scope);
|
|
782
|
+
const request = this.parse(rest);
|
|
783
|
+
const page = scope.page;
|
|
784
|
+
const moves = request.op === "reload" || request.op === "navigate";
|
|
785
|
+
if (!moves && request.op !== "click" && request.op !== "press" && request.op !== "type") return await this.callPage(`act ${String(input.op)}`, request, signal, window, page);
|
|
786
|
+
const backMs = this.deps.pageBackMs ?? PAGE_BACK_MS;
|
|
787
|
+
const stay = new AbortController();
|
|
788
|
+
const back = page === void 0 ? this.deps.channel.expectNewPage(backMs, stay.signal) : this.deps.channel.expectPageBack(page, backMs, stay.signal);
|
|
789
|
+
let answer;
|
|
790
|
+
let left = moves;
|
|
791
|
+
try {
|
|
792
|
+
answer = await this.callPage(`act ${request.op}`, request, signal, window, page);
|
|
793
|
+
left ||= answer.leaving === true;
|
|
794
|
+
} catch (cause) {
|
|
795
|
+
if (!(cause instanceof UiControlError && cause.code === "disconnected")) {
|
|
796
|
+
stay.abort();
|
|
797
|
+
throw cause;
|
|
798
|
+
}
|
|
799
|
+
answer = {
|
|
800
|
+
ok: true,
|
|
801
|
+
detail: request.op === "reload" ? "reloading" : request.op === "navigate" ? `going to ${request.path}` : "the page is going to another address"
|
|
802
|
+
};
|
|
803
|
+
left = true;
|
|
804
|
+
}
|
|
805
|
+
if (!left) {
|
|
806
|
+
stay.abort();
|
|
807
|
+
return answer;
|
|
808
|
+
}
|
|
809
|
+
const came = await back;
|
|
810
|
+
if (came !== void 0 && page === void 0) this.deps.channel.prefer(came);
|
|
811
|
+
if (came === void 0) throw new UiControlError("timeout", request.op === "reload" ? "the page did not come back after the reload" : request.op === "navigate" ? `the page did not come back after going to ${request.path}: is there a page at that path, and does it load the door's script?` : `the ${request.op} took the page to another address, and no page came back: does the page there load the door's script?`);
|
|
812
|
+
const landed = request.op === "navigate" ? await this.statusAt(request.path) : void 0;
|
|
813
|
+
return {
|
|
814
|
+
...answer,
|
|
815
|
+
detail: `${answer.detail ?? "done"}${landed === void 0 ? "" : `; ${landed}`}; the page is back: look again`
|
|
816
|
+
};
|
|
817
|
+
}
|
|
818
|
+
/**
|
|
819
|
+
* What the app answers at a path the page was sent to, so an agent that mistyped one is told ("404 at /nope") and not left to find out from a page it did not expect.
|
|
820
|
+
* A second GET of the same path (a page is read-only); nothing when the app has no address or does not answer in time.
|
|
821
|
+
*/
|
|
822
|
+
async statusAt(path) {
|
|
823
|
+
const base = this.deps.app.url;
|
|
824
|
+
if (base === void 0) return void 0;
|
|
825
|
+
try {
|
|
826
|
+
const target = underAppBase(this.deps.appBase ?? "", path);
|
|
827
|
+
const response = await fetch(new URL(target, base), {
|
|
828
|
+
headers: { accept: "text/html" },
|
|
829
|
+
signal: AbortSignal.timeout(3e3)
|
|
830
|
+
});
|
|
831
|
+
await response.body?.cancel();
|
|
832
|
+
return response.ok ? `${response.status} at ${path}` : `${response.status} at ${path}: the app serves no page there, look at what is shown and navigate to a path it does`;
|
|
833
|
+
} catch {
|
|
834
|
+
return;
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
/**
|
|
838
|
+
* The windows and the menu of the desktop app, through the shell. Every call is audited with the window it was about; a call with no shell attached answers one line that says what to run;
|
|
839
|
+
* closing the last window is refused unless the call says `force` (it ends the desktop app, and the session an agent works in with it).
|
|
840
|
+
*/
|
|
841
|
+
async desktop(verb, input, signal) {
|
|
842
|
+
const shell = this.deps.shell;
|
|
843
|
+
let request;
|
|
844
|
+
try {
|
|
845
|
+
request = parseShellRequest(verb, input);
|
|
846
|
+
} catch (cause) {
|
|
847
|
+
throw new DoorError("invalid", cause instanceof Error ? cause.message : "invalid request");
|
|
848
|
+
}
|
|
849
|
+
const windowId = "id" in request ? request.id : void 0;
|
|
850
|
+
const record = (outcome, detail, windowOf) => {
|
|
851
|
+
const id = windowOf ?? windowId;
|
|
852
|
+
this.deps.audit.record({
|
|
853
|
+
at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
854
|
+
tool: verb,
|
|
855
|
+
...request.op === "menu-click" ? { target: {
|
|
856
|
+
role: "menuitem",
|
|
857
|
+
name: request.path
|
|
858
|
+
} } : {},
|
|
859
|
+
...id === void 0 ? {} : { window: id },
|
|
860
|
+
outcome,
|
|
861
|
+
...detail === void 0 ? {} : { detail },
|
|
862
|
+
approval: "token"
|
|
863
|
+
});
|
|
864
|
+
};
|
|
865
|
+
try {
|
|
866
|
+
if (shell === void 0 || !shell.connected) throw new ShellError("no-desktop", NO_DESKTOP);
|
|
867
|
+
if (request.op === "window-close" && request.force !== true) {
|
|
868
|
+
const { windows } = await shell.call({ op: "window-list" }, { signal });
|
|
869
|
+
if (windows.length === 1 && windows[0]?.id === request.id) throw new ShellError("last-window", `window ${String(request.id)} is the app's last window: closing it ends the desktop app. Open another window first, or pass force to end it on purpose`);
|
|
870
|
+
}
|
|
871
|
+
const result = await shell.call(request, { signal });
|
|
872
|
+
record("ok", void 0, "id" in result ? result.id : void 0);
|
|
873
|
+
return {
|
|
874
|
+
value: result,
|
|
875
|
+
text: renderShell(result)
|
|
876
|
+
};
|
|
877
|
+
} catch (cause) {
|
|
878
|
+
if (!(cause instanceof ShellError)) throw cause;
|
|
879
|
+
record([
|
|
880
|
+
"invalid",
|
|
881
|
+
"no-such-window",
|
|
882
|
+
"last-window",
|
|
883
|
+
"no-such-menu-item",
|
|
884
|
+
"disabled",
|
|
885
|
+
"quits-app",
|
|
886
|
+
"no-desktop"
|
|
887
|
+
].includes(cause.code) ? "refused" : "failed", cause.code);
|
|
888
|
+
throw new DoorError(cause.code, cause.message);
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
/** `window` on look and act: the desktop window (the number `window list` prints) whose page the call is for; without it, the page used last. */
|
|
892
|
+
windowOf(input, scope = {}) {
|
|
893
|
+
const { window, ...rest } = input;
|
|
894
|
+
if (window === void 0) return {
|
|
895
|
+
window: void 0,
|
|
896
|
+
rest
|
|
897
|
+
};
|
|
898
|
+
if (scope.page !== void 0) throw new DoorError("invalid", "this run drives only the page it was asked from; window does not apply");
|
|
899
|
+
if (typeof window !== "number" || !Number.isSafeInteger(window) || window < 1) throw new DoorError("invalid", "window must be the number `window list` prints for the window");
|
|
900
|
+
return {
|
|
901
|
+
window,
|
|
902
|
+
rest
|
|
903
|
+
};
|
|
904
|
+
}
|
|
905
|
+
parse(input) {
|
|
906
|
+
try {
|
|
907
|
+
return parseUiRequest(input);
|
|
908
|
+
} catch (cause) {
|
|
909
|
+
throw new DoorError("invalid", cause instanceof Error ? cause.message : "invalid request");
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
/** Run one call on the page and record it. The audit holds which control was touched and how it ended, never what was typed. */
|
|
913
|
+
async callPage(verb, request, signal, window, page) {
|
|
914
|
+
const approval = "token";
|
|
915
|
+
try {
|
|
916
|
+
const value = await this.deps.channel.call(request, {
|
|
917
|
+
signal,
|
|
918
|
+
...window === void 0 ? {} : { window },
|
|
919
|
+
...page === void 0 ? {} : { page },
|
|
920
|
+
...request.op === "wait" ? { timeoutMs: (request.timeoutMs ?? 3e3) + 5e3 } : {}
|
|
921
|
+
});
|
|
922
|
+
const target = "target" in value ? value.target : void 0;
|
|
923
|
+
this.deps.audit.record({
|
|
924
|
+
at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
925
|
+
tool: verb,
|
|
926
|
+
...target === void 0 ? {} : { target },
|
|
927
|
+
...window === void 0 ? {} : { window },
|
|
928
|
+
outcome: "ok",
|
|
929
|
+
approval
|
|
930
|
+
});
|
|
931
|
+
return value;
|
|
932
|
+
} catch (cause) {
|
|
933
|
+
const code = cause instanceof UiControlError ? cause.code : "failed";
|
|
934
|
+
const refused = cause instanceof UiControlError && [
|
|
935
|
+
"protected",
|
|
936
|
+
"sensitive",
|
|
937
|
+
"killed",
|
|
938
|
+
"invalid",
|
|
939
|
+
"stale-ref",
|
|
940
|
+
"unknown-ref",
|
|
941
|
+
"not-actionable"
|
|
942
|
+
].includes(cause.code);
|
|
943
|
+
this.deps.audit.record({
|
|
944
|
+
at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
945
|
+
tool: verb,
|
|
946
|
+
...window === void 0 ? {} : { window },
|
|
947
|
+
outcome: refused ? "refused" : "failed",
|
|
948
|
+
detail: code,
|
|
949
|
+
approval
|
|
950
|
+
});
|
|
951
|
+
throw cause;
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
/**
|
|
955
|
+
* Who lists and removes the app's plugins: plugin-share where the app has it, as it knows where each pulled plugin came from and is the one app service
|
|
956
|
+
* the frame's host reaches (extensions stays in the app's own realm there); extensions elsewhere.
|
|
957
|
+
*/
|
|
958
|
+
installed() {
|
|
959
|
+
return this.deps.pluginShare?.() ?? this.deps.extensions();
|
|
960
|
+
}
|
|
961
|
+
async plugin(run, mutates = true, port = this.deps.extensions()) {
|
|
962
|
+
const extensions = port;
|
|
963
|
+
if (extensions === void 0) throw new DoorError("unavailable", "this door has no extensions plugin to drive. In ACRYL's frame none is needed: a saved change in src/ or plugins/ reloads the app by itself, so do not restart it. Elsewhere, the app has no way to install plugins while it runs");
|
|
964
|
+
const value = await run(extensions);
|
|
965
|
+
const unchanged = typeof value === "object" && value !== null && value.action === "unchanged";
|
|
966
|
+
if (mutates && !unchanged && this.deps.reloadOnChange !== false) await this.deps.channel.reloadAll();
|
|
967
|
+
return {
|
|
968
|
+
value,
|
|
969
|
+
text: JSON.stringify(value, null, 2)
|
|
970
|
+
};
|
|
971
|
+
}
|
|
972
|
+
share() {
|
|
973
|
+
const share = this.deps.pluginShare?.();
|
|
974
|
+
if (share === void 0) throw new DoorError("unavailable", "plugin-share is not running in this app. If the app just changed it is restarting, so try again in a moment. An app made by an older version, or from an older starter, does not have it, and upgrade does not add it: run `npx acrylblends add plugin-share`, which copies it and mounts it");
|
|
975
|
+
return share;
|
|
976
|
+
}
|
|
977
|
+
/** Only a plan: no argument of any verb can publish, so an agent never says yes for a person. */
|
|
978
|
+
async planPublish(input) {
|
|
979
|
+
const { name, owner, license } = input;
|
|
980
|
+
if (typeof name !== "string" || name === "") throw new DoorError("invalid", "plugin publish needs a plugin name, e.g. plugin publish pomodoro");
|
|
981
|
+
const value = await this.share().planPublish(name, {
|
|
982
|
+
...typeof owner === "string" && owner !== "" ? { owner } : {},
|
|
983
|
+
...typeof license === "string" && license !== "" ? { license } : {}
|
|
984
|
+
});
|
|
985
|
+
if ("ok" in value) throw new DoorError("refused", `${value.reason}. ${value.next}.`);
|
|
986
|
+
return {
|
|
987
|
+
value,
|
|
988
|
+
text: `${renderPublishPlan(value)}\nNothing was sent. Only a person can say yes: they run \`npm run acryl -- plugin publish ${name}\` in their own terminal, or press Share in the frame. \`--license <id>\` changes the license before the yes.`
|
|
989
|
+
};
|
|
990
|
+
}
|
|
991
|
+
/** The person's yes, from their own terminal. Not a verb: MCP and the chat do not have it. */
|
|
992
|
+
async publishConfirmed(name, confirmed, options) {
|
|
993
|
+
const value = await this.share().publish(name, confirmed, options);
|
|
994
|
+
this.deps.audit.record({
|
|
995
|
+
at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
996
|
+
tool: "plugin-publish",
|
|
997
|
+
target: {
|
|
998
|
+
role: "plugin",
|
|
999
|
+
name: `${confirmed.owner}/${confirmed.repo}@${confirmed.version}`
|
|
1000
|
+
},
|
|
1001
|
+
outcome: value.ok ? "ok" : "refused",
|
|
1002
|
+
approval: "token"
|
|
1003
|
+
});
|
|
1004
|
+
return value;
|
|
1005
|
+
}
|
|
1006
|
+
async pull(source) {
|
|
1007
|
+
if (typeof source !== "string" || source === "") throw new DoorError("invalid", "plugin pull needs a source, e.g. plugin pull github:someone/pomodoro@0.1.0");
|
|
1008
|
+
const value = await this.share().pull(source);
|
|
1009
|
+
if (!value.ok) throw new DoorError("refused", `${sentence(value.reason ?? "the pull was refused")} ${sentence(value.next ?? "nothing changed")}`);
|
|
1010
|
+
if (value.action !== "unchanged" && this.deps.reloadOnChange !== false) await this.deps.channel.reloadAll();
|
|
1011
|
+
return {
|
|
1012
|
+
value,
|
|
1013
|
+
text: JSON.stringify(value, null, 2)
|
|
1014
|
+
};
|
|
1015
|
+
}
|
|
1016
|
+
/** A group's list: every source is pulled on its own, so one refused plugin is named with its reason and the others still install and run. */
|
|
1017
|
+
async pullList(from, source) {
|
|
1018
|
+
if (source !== void 0) throw new DoorError("invalid", "plugin pull takes a source or --from <list>, not both");
|
|
1019
|
+
if (typeof from !== "string" || from === "") throw new DoorError("invalid", "plugin pull --from needs a list, e.g. plugin pull --from group.txt");
|
|
1020
|
+
const value = await this.share().pullList(from);
|
|
1021
|
+
if (!value.ok) throw new DoorError("refused", `${sentence(value.reason)} ${sentence(value.next)}`);
|
|
1022
|
+
if (value.entries.some((entry) => entry.result.ok && entry.result.action !== "unchanged") && this.deps.reloadOnChange !== false) await this.deps.channel.reloadAll();
|
|
1023
|
+
const lines = value.entries.map((entry) => `${entry.source}: ${pullLine(entry.result)}`);
|
|
1024
|
+
const refused = value.entries.filter((entry) => !entry.result.ok);
|
|
1025
|
+
const summary = `${String(value.entries.length - refused.length)} of ${String(value.entries.length)} from ${value.from} pulled`;
|
|
1026
|
+
if (refused.length > 0) throw new DoorError("refused", [`${summary}; ${String(refused.length)} refused, the others are in and running.`, ...lines].join("\n"));
|
|
1027
|
+
return {
|
|
1028
|
+
value,
|
|
1029
|
+
text: [`${summary}.`, ...lines].join("\n")
|
|
1030
|
+
};
|
|
1031
|
+
}
|
|
1032
|
+
/** A folder named by an agent, resolved from the app folder; it must be inside the app. */
|
|
1033
|
+
insideApp(folder) {
|
|
1034
|
+
if (typeof folder !== "string" || folder === "") throw new DoorError("invalid", "plugin add needs a folder, e.g. plugins/pomodoro");
|
|
1035
|
+
const root = this.deps.app.root;
|
|
1036
|
+
const full = resolve(root, folder);
|
|
1037
|
+
const path = relative(root, full);
|
|
1038
|
+
if (path === "" || path.startsWith("..") || isAbsolute(path)) throw new DoorError("outside-app", `${folder} is not a folder inside the app (${root})`);
|
|
1039
|
+
return full;
|
|
1040
|
+
}
|
|
1041
|
+
offeredTools() {
|
|
1042
|
+
const tools = this.deps.tools();
|
|
1043
|
+
if (tools === void 0) return [];
|
|
1044
|
+
const allowed = new Set(this.deps.expose);
|
|
1045
|
+
return listedTools(tools).filter((tool) => allowed.has(tool.name)).map(({ name, description }) => ({
|
|
1046
|
+
name,
|
|
1047
|
+
description
|
|
1048
|
+
}));
|
|
1049
|
+
}
|
|
1050
|
+
async callTool(input) {
|
|
1051
|
+
const name = input.tool;
|
|
1052
|
+
if (typeof name !== "string" || name === "") throw new DoorError("invalid", "tool call needs --tool <name>");
|
|
1053
|
+
if (!this.deps.expose.includes(name)) throw new DoorError("not-exposed", `${name} is not offered through the door`);
|
|
1054
|
+
const tools = this.deps.tools();
|
|
1055
|
+
if (tools === void 0 || !listedTools(tools).some((tool) => tool.name === name)) throw new DoorError("unavailable", `${name} is not available right now`);
|
|
1056
|
+
if (isDshTools(tools)) throw new DoorError("unavailable", `${name} is a tool of the app's chat agent; ask the chat to use it`);
|
|
1057
|
+
let value;
|
|
1058
|
+
try {
|
|
1059
|
+
value = await tools.call(name, input.args ?? {});
|
|
1060
|
+
} catch (cause) {
|
|
1061
|
+
throw new DoorError("failed", cause instanceof Error ? cause.message : String(cause));
|
|
1062
|
+
}
|
|
1063
|
+
return {
|
|
1064
|
+
value,
|
|
1065
|
+
text: typeof value === "string" ? value : JSON.stringify(value, null, 2)
|
|
1066
|
+
};
|
|
1067
|
+
}
|
|
1068
|
+
};
|
|
1069
|
+
/** One source's outcome in a list pull, as a person reads it. */
|
|
1070
|
+
function pullLine(result) {
|
|
1071
|
+
if (!result.ok) return `refused: ${sentence(result.reason ?? "the pull was refused")} ${sentence(result.next ?? "nothing changed")}`;
|
|
1072
|
+
return `${result.action ?? "pulled"}${result.name === void 0 ? "" : ` ${result.name}`}`;
|
|
1073
|
+
}
|
|
1074
|
+
/** A text as one sentence: the full stop added only when it has no closing punctuation of its own (a reason may end with one, a next step often does). */
|
|
1075
|
+
function sentence(text) {
|
|
1076
|
+
const trimmed = text.trim();
|
|
1077
|
+
return /[.!?]$/u.test(trimmed) ? trimmed : `${trimmed}.`;
|
|
1078
|
+
}
|
|
1079
|
+
//#endregion
|
|
1080
|
+
//#region ../../../plugins/door/src/host/chat-tools.ts
|
|
1081
|
+
/**
|
|
1082
|
+
* The door in the built-in chat: each verb registered in the app's `tools` registry (the one the chat's agent reads), as
|
|
1083
|
+
* `door_<verb>`. A tool answers the verb's text, what an agent reads in a terminal; a failed verb throws with its code, as the operator
|
|
1084
|
+
* client prints it.
|
|
1085
|
+
*/
|
|
1086
|
+
/** Register the verbs (default: every one). @returns the function that removes them all; it also aborts the calls still running. */
|
|
1087
|
+
function registerChatTools(tools, door, verbs = VERBS) {
|
|
1088
|
+
const running = new AbortController();
|
|
1089
|
+
const removers = [];
|
|
1090
|
+
const removeAll = () => {
|
|
1091
|
+
running.abort();
|
|
1092
|
+
for (const remove of removers.splice(0).reverse()) remove();
|
|
1093
|
+
};
|
|
1094
|
+
try {
|
|
1095
|
+
for (const verb of verbs) removers.push(tools.register(chatToolName(verb), {
|
|
1096
|
+
description: VERB_SPECS[verb].description,
|
|
1097
|
+
parameters: VERB_SPECS[verb].arguments,
|
|
1098
|
+
run: async (input, options) => {
|
|
1099
|
+
const signal = options?.signal === void 0 ? running.signal : AbortSignal.any([running.signal, options.signal]);
|
|
1100
|
+
try {
|
|
1101
|
+
return (await door.run(verb, input ?? {}, signal, options?.page === void 0 ? {} : { page: options.page })).text;
|
|
1102
|
+
} catch (cause) {
|
|
1103
|
+
if (cause instanceof DoorError || cause instanceof UiControlError) throw new Error(`${cause.code}: ${cause.message}`, { cause });
|
|
1104
|
+
throw cause;
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
}));
|
|
1108
|
+
} catch (cause) {
|
|
1109
|
+
removeAll();
|
|
1110
|
+
throw cause;
|
|
1111
|
+
}
|
|
1112
|
+
return removeAll;
|
|
1113
|
+
}
|
|
1114
|
+
/** Register the verbs in DSH's registry as `door_<verb>`, each answering the verb's text. @returns the function that removes them all. */
|
|
1115
|
+
function registerDshChatTools(tools, door, verbs = VERBS) {
|
|
1116
|
+
const running = new AbortController();
|
|
1117
|
+
const removers = [];
|
|
1118
|
+
const removeAll = () => {
|
|
1119
|
+
running.abort();
|
|
1120
|
+
for (const remove of removers.splice(0).reverse()) remove();
|
|
1121
|
+
};
|
|
1122
|
+
try {
|
|
1123
|
+
for (const verb of verbs) removers.push(tools.register({
|
|
1124
|
+
name: chatToolName(verb),
|
|
1125
|
+
description: VERB_SPECS[verb].description,
|
|
1126
|
+
parameters: VERB_SPECS[verb].arguments,
|
|
1127
|
+
output: {
|
|
1128
|
+
schema: { type: "string" },
|
|
1129
|
+
render: (_args, value) => [{
|
|
1130
|
+
type: "text",
|
|
1131
|
+
text: String(value)
|
|
1132
|
+
}]
|
|
1133
|
+
},
|
|
1134
|
+
execute: async (args, exec) => {
|
|
1135
|
+
const signal = exec.signal === void 0 ? running.signal : AbortSignal.any([running.signal, exec.signal]);
|
|
1136
|
+
try {
|
|
1137
|
+
return (await door.run(verb, args ?? {}, signal)).text;
|
|
1138
|
+
} catch (cause) {
|
|
1139
|
+
if (cause instanceof DoorError || cause instanceof UiControlError) throw new Error(`${cause.code}: ${cause.message}`, { cause });
|
|
1140
|
+
throw cause;
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
}));
|
|
1144
|
+
} catch (cause) {
|
|
1145
|
+
removeAll();
|
|
1146
|
+
throw cause;
|
|
1147
|
+
}
|
|
1148
|
+
return removeAll;
|
|
1149
|
+
}
|
|
1150
|
+
//#endregion
|
|
1151
|
+
//#region ../../../plugins/door/src/host/door-file.ts
|
|
1152
|
+
/**
|
|
1153
|
+
* The door's connection file, `<app>/.acryl/door.json`: where the running app listens and this run's secret, for the operator client in
|
|
1154
|
+
* the same folder. The secret is never on a command line or in an environment variable another process can read.
|
|
1155
|
+
*
|
|
1156
|
+
* Protection: on macOS and Linux the folder is `0700` and the file `0600`, so only the OS user who started the app can read it. On
|
|
1157
|
+
* Windows file modes mean nothing; the file is protected by where it lives, the app folder in the user's profile, whose ACL gives access
|
|
1158
|
+
* to that user, SYSTEM and Administrators only. The door does not widen it. The folder also carries its own `.gitignore` of `*`, so
|
|
1159
|
+
* `git add -A` never stages the secret even in an app whose `.gitignore` lacks the `.acryl/` line.
|
|
1160
|
+
*/
|
|
1161
|
+
/** The folder of the door's state below the app folder. */
|
|
1162
|
+
const STATE_DIR = ".acryl";
|
|
1163
|
+
const DOOR_FILE = "door.json";
|
|
1164
|
+
function stateDir(appRoot) {
|
|
1165
|
+
return join(appRoot, STATE_DIR);
|
|
1166
|
+
}
|
|
1167
|
+
function doorFilePath(appRoot) {
|
|
1168
|
+
return join(stateDir(appRoot), DOOR_FILE);
|
|
1169
|
+
}
|
|
1170
|
+
/** A fresh secret for this run; a restart rotates it. */
|
|
1171
|
+
function newSecret() {
|
|
1172
|
+
return randomBytes(24).toString("hex");
|
|
1173
|
+
}
|
|
1174
|
+
/** The state folder, private, with its own `.gitignore`. */
|
|
1175
|
+
function ensureStateDir(appRoot) {
|
|
1176
|
+
const dir = stateDir(appRoot);
|
|
1177
|
+
mkdirSync(dir, {
|
|
1178
|
+
recursive: true,
|
|
1179
|
+
mode: 448
|
|
1180
|
+
});
|
|
1181
|
+
if (process.platform !== "win32") chmodSync(dir, 448);
|
|
1182
|
+
const ignore = join(dir, ".gitignore");
|
|
1183
|
+
if (!existsSync(ignore)) writeFileSync(ignore, "# The door's state: this run's secret and the audit. Never commit it.\n*\n");
|
|
1184
|
+
return dir;
|
|
1185
|
+
}
|
|
1186
|
+
/** The connection file as written, or undefined when there is none or it does not parse. */
|
|
1187
|
+
function readDoorFile(appRoot) {
|
|
1188
|
+
try {
|
|
1189
|
+
const value = JSON.parse(readFileSync(doorFilePath(appRoot), "utf8"));
|
|
1190
|
+
if (value.version === 1 && typeof value.url === "string" && typeof value.secret === "string" && typeof value.pid === "number") return value;
|
|
1191
|
+
} catch {}
|
|
1192
|
+
}
|
|
1193
|
+
/** True while the process is alive (a process of another user still counts: `EPERM`). */
|
|
1194
|
+
function alive(pid) {
|
|
1195
|
+
try {
|
|
1196
|
+
process.kill(pid, 0);
|
|
1197
|
+
return true;
|
|
1198
|
+
} catch (cause) {
|
|
1199
|
+
return cause.code === "EPERM";
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1202
|
+
/**
|
|
1203
|
+
* Write this run's connection file, replacing a stale one.
|
|
1204
|
+
* @throws when another live process already serves this folder's door: two apps from one folder would race for one file.
|
|
1205
|
+
*/
|
|
1206
|
+
/** @throws when another live process already serves this folder's door: two apps from one folder would race for one file. */
|
|
1207
|
+
function assertDoorIsFree(appRoot) {
|
|
1208
|
+
const existing = readDoorFile(appRoot);
|
|
1209
|
+
if (existing !== void 0 && existing.pid !== process.pid && alive(existing.pid)) throw new Error(`@acryldev/door: another process (pid ${String(existing.pid)}) serves the door of ${appRoot}; stop it first`);
|
|
1210
|
+
}
|
|
1211
|
+
function writeDoorFile(appRoot, url, secret) {
|
|
1212
|
+
const dir = ensureStateDir(appRoot);
|
|
1213
|
+
assertDoorIsFree(appRoot);
|
|
1214
|
+
const file = doorFilePath(appRoot);
|
|
1215
|
+
const temporary = join(dir, `${DOOR_FILE}.${String(process.pid)}.tmp`);
|
|
1216
|
+
const content = {
|
|
1217
|
+
version: 1,
|
|
1218
|
+
url,
|
|
1219
|
+
secret,
|
|
1220
|
+
pid: process.pid
|
|
1221
|
+
};
|
|
1222
|
+
writeFileSync(temporary, `${JSON.stringify(content)}\n`, { mode: 384 });
|
|
1223
|
+
if (process.platform !== "win32") chmodSync(temporary, 384);
|
|
1224
|
+
renameSync(temporary, file);
|
|
1225
|
+
return file;
|
|
1226
|
+
}
|
|
1227
|
+
/** Remove the connection file, only when it is this run's: a newer run's file is left alone. */
|
|
1228
|
+
function removeDoorFile(appRoot, secret) {
|
|
1229
|
+
if (readDoorFile(appRoot)?.secret === secret) rmSync(doorFilePath(appRoot), { force: true });
|
|
1230
|
+
}
|
|
1231
|
+
//#endregion
|
|
1232
|
+
//#region ../../../plugins/door/src/host/mcp-routes.ts
|
|
1233
|
+
/**
|
|
1234
|
+
* The door over MCP: `POST <prefix>/mcp`, streamable HTTP in its request/response form (one JSON-RPC message or a batch in, its JSON
|
|
1235
|
+
* answer out, 202 for notifications only; no event stream is offered). Each verb is one tool, named as the verb, with the arguments the
|
|
1236
|
+
* operator client sends. The same guard as the operator's routes: loopback, this run's secret.
|
|
1237
|
+
*/
|
|
1238
|
+
const SUPPORTED_PROTOCOLS = [
|
|
1239
|
+
"2025-06-18",
|
|
1240
|
+
"2025-03-26",
|
|
1241
|
+
"2024-11-05"
|
|
1242
|
+
];
|
|
1243
|
+
const SERVER_INFO = {
|
|
1244
|
+
name: "acryl-door",
|
|
1245
|
+
version: "1"
|
|
1246
|
+
};
|
|
1247
|
+
function isRequest(value) {
|
|
1248
|
+
return typeof value === "object" && value !== null && value.jsonrpc === "2.0" && typeof value.method === "string";
|
|
1249
|
+
}
|
|
1250
|
+
const rpcError = (id, code, message) => ({
|
|
1251
|
+
jsonrpc: "2.0",
|
|
1252
|
+
id: id ?? null,
|
|
1253
|
+
error: {
|
|
1254
|
+
code,
|
|
1255
|
+
message
|
|
1256
|
+
}
|
|
1257
|
+
});
|
|
1258
|
+
const result = (id, value) => ({
|
|
1259
|
+
jsonrpc: "2.0",
|
|
1260
|
+
id: id ?? null,
|
|
1261
|
+
result: value
|
|
1262
|
+
});
|
|
1263
|
+
/** The verbs as MCP tools. */
|
|
1264
|
+
function mcpTools() {
|
|
1265
|
+
return VERBS.map((verb) => ({
|
|
1266
|
+
name: verb,
|
|
1267
|
+
description: VERB_SPECS[verb].description,
|
|
1268
|
+
inputSchema: VERB_SPECS[verb].arguments
|
|
1269
|
+
}));
|
|
1270
|
+
}
|
|
1271
|
+
const isVerb = (name) => typeof name === "string" && VERBS.includes(name);
|
|
1272
|
+
/** One JSON-RPC message; `undefined` for a notification (no answer owed). */
|
|
1273
|
+
async function answer(message, door, signal) {
|
|
1274
|
+
const isNotification = message.id === void 0;
|
|
1275
|
+
switch (message.method) {
|
|
1276
|
+
case "initialize": {
|
|
1277
|
+
const asked = message.params?.protocolVersion;
|
|
1278
|
+
const protocolVersion = SUPPORTED_PROTOCOLS.includes(asked) ? asked : SUPPORTED_PROTOCOLS[0];
|
|
1279
|
+
return result(message.id, {
|
|
1280
|
+
protocolVersion,
|
|
1281
|
+
capabilities: { tools: { listChanged: false } },
|
|
1282
|
+
serverInfo: SERVER_INFO
|
|
1283
|
+
});
|
|
1284
|
+
}
|
|
1285
|
+
case "ping": return isNotification ? void 0 : result(message.id, {});
|
|
1286
|
+
case "tools/list": return result(message.id, { tools: mcpTools() });
|
|
1287
|
+
case "tools/call": {
|
|
1288
|
+
const params = typeof message.params === "object" && message.params !== null ? message.params : {};
|
|
1289
|
+
if (!isVerb(params.name)) return rpcError(message.id, -32602, `unknown tool ${JSON.stringify(params.name)}; the tools are ${VERBS.join(", ")}`);
|
|
1290
|
+
try {
|
|
1291
|
+
const verbAnswer = await door.run(params.name, params.arguments ?? {}, signal);
|
|
1292
|
+
return result(message.id, {
|
|
1293
|
+
content: [{
|
|
1294
|
+
type: "text",
|
|
1295
|
+
text: verbAnswer.text
|
|
1296
|
+
}],
|
|
1297
|
+
structuredContent: { value: verbAnswer.value },
|
|
1298
|
+
isError: false
|
|
1299
|
+
});
|
|
1300
|
+
} catch (cause) {
|
|
1301
|
+
if (cause instanceof DoorError || cause instanceof UiControlError) return result(message.id, {
|
|
1302
|
+
content: [{
|
|
1303
|
+
type: "text",
|
|
1304
|
+
text: `${cause.code}: ${cause.message}`
|
|
1305
|
+
}],
|
|
1306
|
+
isError: true
|
|
1307
|
+
});
|
|
1308
|
+
throw cause;
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
default: return isNotification ? void 0 : rpcError(message.id, -32601, `method not found: ${message.method}`);
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
function mcpRoutes(prefix, secret, door, reportError) {
|
|
1315
|
+
return new Acryl().post(`${prefix}/mcp`, operatorOnly(secret), jsonBody, async (c) => {
|
|
1316
|
+
const body = await readJson(c);
|
|
1317
|
+
if (body === INVALID_JSON) return c.json(rpcError(null, -32700, "parse error"), 400);
|
|
1318
|
+
try {
|
|
1319
|
+
const messages = Array.isArray(body) ? body : [body];
|
|
1320
|
+
const answers = [];
|
|
1321
|
+
for (const message of messages) {
|
|
1322
|
+
if (!isRequest(message)) {
|
|
1323
|
+
answers.push(rpcError(null, -32600, "invalid request"));
|
|
1324
|
+
continue;
|
|
1325
|
+
}
|
|
1326
|
+
const response = await answer(message, door, c.req.raw.signal);
|
|
1327
|
+
if (response !== void 0) answers.push(response);
|
|
1328
|
+
}
|
|
1329
|
+
if (answers.length === 0) return c.body(null, 202);
|
|
1330
|
+
return c.json(Array.isArray(body) ? answers : answers[0]);
|
|
1331
|
+
} catch (cause) {
|
|
1332
|
+
reportError("answer an MCP request", cause);
|
|
1333
|
+
return c.json(rpcError(null, -32603, "internal error"), 500);
|
|
1334
|
+
}
|
|
1335
|
+
});
|
|
1336
|
+
}
|
|
1337
|
+
//#endregion
|
|
1338
|
+
//#region ../../../plugins/door/src/host/operator-routes.ts
|
|
1339
|
+
/**
|
|
1340
|
+
* The operator's routes: an agent's shell on this machine, through `.acryl/bin/acryl`. Loopback only, with this run's secret.
|
|
1341
|
+
*
|
|
1342
|
+
* `POST <prefix>/call` takes `{ verb, args }` and answers {@link CallResponse}; `GET <prefix>/verbs` lists the verbs. A caller that goes
|
|
1343
|
+
* away aborts its call through the request's signal.
|
|
1344
|
+
*/
|
|
1345
|
+
function operatorRoutes(prefix, secret, door, reportError) {
|
|
1346
|
+
return new Acryl().get(`${prefix}/verbs`, operatorOnly(secret), (c) => c.json({ verbs: VERBS })).post(`${prefix}/call`, operatorOnly(secret), jsonBody, async (c) => {
|
|
1347
|
+
const body = await readJson(c);
|
|
1348
|
+
if (body === INVALID_JSON || typeof body !== "object" || body === null || typeof body.verb !== "string") return c.json({
|
|
1349
|
+
ok: false,
|
|
1350
|
+
code: "invalid",
|
|
1351
|
+
message: "the body is { verb, args }"
|
|
1352
|
+
}, 400);
|
|
1353
|
+
const { verb, args } = body;
|
|
1354
|
+
try {
|
|
1355
|
+
const answer = await door.run(verb, args, c.req.raw.signal);
|
|
1356
|
+
return c.json({
|
|
1357
|
+
ok: true,
|
|
1358
|
+
value: answer.value,
|
|
1359
|
+
text: answer.text
|
|
1360
|
+
});
|
|
1361
|
+
} catch (cause) {
|
|
1362
|
+
if (cause instanceof UiControlError || cause instanceof DoorError) return c.json({
|
|
1363
|
+
ok: false,
|
|
1364
|
+
code: cause.code,
|
|
1365
|
+
message: cause.message
|
|
1366
|
+
}, cause.code === "invalid" || cause.code === "unknown-verb" ? 400 : 200);
|
|
1367
|
+
reportError(`run the door verb ${verb}`, cause);
|
|
1368
|
+
return c.json(error("the verb could not be run"), 500);
|
|
1369
|
+
}
|
|
1370
|
+
}).post(`${prefix}/publish-confirmed`, operatorOnly(secret), jsonBody, async (c) => {
|
|
1371
|
+
const body = await readJson(c);
|
|
1372
|
+
const { name, confirm, owner, license } = body === INVALID_JSON || typeof body !== "object" || body === null ? {} : body;
|
|
1373
|
+
if (typeof name !== "string" || typeof confirm !== "object" || confirm === null) return c.json({
|
|
1374
|
+
ok: false,
|
|
1375
|
+
code: "invalid",
|
|
1376
|
+
message: "the body is { name, confirm }"
|
|
1377
|
+
}, 400);
|
|
1378
|
+
try {
|
|
1379
|
+
const value = await door.publishConfirmed(name, confirm, {
|
|
1380
|
+
...typeof owner === "string" ? { owner } : {},
|
|
1381
|
+
...typeof license === "string" ? { license } : {}
|
|
1382
|
+
});
|
|
1383
|
+
return c.json({
|
|
1384
|
+
ok: true,
|
|
1385
|
+
value,
|
|
1386
|
+
text: JSON.stringify(value, null, 2)
|
|
1387
|
+
});
|
|
1388
|
+
} catch (cause) {
|
|
1389
|
+
if (cause instanceof DoorError) return c.json({
|
|
1390
|
+
ok: false,
|
|
1391
|
+
code: cause.code,
|
|
1392
|
+
message: cause.message
|
|
1393
|
+
}, 409);
|
|
1394
|
+
reportError("publish a plugin", cause);
|
|
1395
|
+
return c.json(error("the plugin could not be published"), 500);
|
|
1396
|
+
}
|
|
1397
|
+
});
|
|
1398
|
+
}
|
|
1399
|
+
/** The upgrade request comes from this app's own page: a loopback peer on this port (or the hosted app's trusted front), and an `Origin` that is exactly this app's origin. Nothing else is read as proof. */
|
|
1400
|
+
const ownOrigin = async (c, next) => {
|
|
1401
|
+
const authority = pageAuthority(c);
|
|
1402
|
+
const origin = c.req.header("origin");
|
|
1403
|
+
const site = c.req.header("sec-fetch-site");
|
|
1404
|
+
if (authority === void 0 || origin === void 0 || origin !== authority.origin || site !== void 0 && site !== "same-origin") return c.json(error("only this app's own page may open the channel"), 403);
|
|
1405
|
+
const windowId = c.req.query("window");
|
|
1406
|
+
if (windowId === void 0 || !WINDOW_ID.test(windowId)) return c.json(error("a window id is required"), 400);
|
|
1407
|
+
await next();
|
|
1408
|
+
};
|
|
1409
|
+
function pageSocketRoutes(channel, options) {
|
|
1410
|
+
const heartbeatMs = options.heartbeatMs ?? 15e3;
|
|
1411
|
+
const events = (c) => {
|
|
1412
|
+
const windowId = c.req.query("window");
|
|
1413
|
+
const focused = c.req.query("focused") === "1";
|
|
1414
|
+
const shellQuery = Number(c.req.query("shell"));
|
|
1415
|
+
const shellWindow = Number.isSafeInteger(shellQuery) && shellQuery > 0 ? shellQuery : void 0;
|
|
1416
|
+
const tabQuery = c.req.query("tab");
|
|
1417
|
+
const tab = tabQuery !== void 0 && WINDOW_ID.test(tabQuery) ? tabQuery : void 0;
|
|
1418
|
+
let detach;
|
|
1419
|
+
let beat;
|
|
1420
|
+
return {
|
|
1421
|
+
onOpen(_event, ws) {
|
|
1422
|
+
const write = (frame) => {
|
|
1423
|
+
ws.send(JSON.stringify(frame));
|
|
1424
|
+
};
|
|
1425
|
+
detach = channel.attach(windowId, focused, {
|
|
1426
|
+
send: (data) => {
|
|
1427
|
+
write({
|
|
1428
|
+
e: "call",
|
|
1429
|
+
d: data
|
|
1430
|
+
});
|
|
1431
|
+
},
|
|
1432
|
+
notify: (event, data) => {
|
|
1433
|
+
write({
|
|
1434
|
+
e: event,
|
|
1435
|
+
d: data
|
|
1436
|
+
});
|
|
1437
|
+
},
|
|
1438
|
+
close: () => {
|
|
1439
|
+
ws.close(1e3, "replaced");
|
|
1440
|
+
}
|
|
1441
|
+
}, shellWindow, tab);
|
|
1442
|
+
write({ e: "ready" });
|
|
1443
|
+
beat = setInterval(() => {
|
|
1444
|
+
try {
|
|
1445
|
+
write({ e: "ping" });
|
|
1446
|
+
} catch {}
|
|
1447
|
+
}, heartbeatMs);
|
|
1448
|
+
},
|
|
1449
|
+
onMessage(event) {
|
|
1450
|
+
if (typeof event.data !== "string") return;
|
|
1451
|
+
let message;
|
|
1452
|
+
try {
|
|
1453
|
+
message = JSON.parse(event.data);
|
|
1454
|
+
} catch {
|
|
1455
|
+
return;
|
|
1456
|
+
}
|
|
1457
|
+
const parsed = parseChannelToHost(message);
|
|
1458
|
+
if (parsed !== null) channel.receive(windowId, parsed);
|
|
1459
|
+
},
|
|
1460
|
+
onClose() {
|
|
1461
|
+
if (beat !== void 0) clearInterval(beat);
|
|
1462
|
+
detach?.();
|
|
1463
|
+
}
|
|
1464
|
+
};
|
|
1465
|
+
};
|
|
1466
|
+
return new Acryl().get(`${options.prefix}/channel/ws`, ownOrigin, async (c, next) => {
|
|
1467
|
+
const allow = options.upgrade();
|
|
1468
|
+
if (allow === void 0) return c.json(error("the page channel is not ready yet"), 503);
|
|
1469
|
+
return allow(events, { textOnly: true })(c, next);
|
|
1470
|
+
});
|
|
1471
|
+
}
|
|
1472
|
+
/** The oldest Node the client runs on (the framework's own floor). */
|
|
1473
|
+
const MIN_NODE = [22, 19];
|
|
1474
|
+
/**
|
|
1475
|
+
* A real Node for the command, when the app runs inside Electron: Electron can run the client as Node, but on macOS every such call prints a code-signing complaint on stderr,
|
|
1476
|
+
* which lands in an agent's transcript. A `node` on the PATH that is new enough is used instead; without one, Electron runs the client. `find` is replaceable for tests.
|
|
1477
|
+
*/
|
|
1478
|
+
function realNode(find = findNodeOnPath) {
|
|
1479
|
+
const found = find();
|
|
1480
|
+
if (found === void 0) return void 0;
|
|
1481
|
+
const [major = 0, minor = 0] = found.version.replace(/^v/u, "").split(".").map(Number);
|
|
1482
|
+
return major > MIN_NODE[0] || major === MIN_NODE[0] && minor >= MIN_NODE[1] ? found.path : void 0;
|
|
1483
|
+
}
|
|
1484
|
+
function findNodeOnPath() {
|
|
1485
|
+
const located = spawnSync(process.platform === "win32" ? "where" : "which", ["node"], {
|
|
1486
|
+
encoding: "utf8",
|
|
1487
|
+
env: {
|
|
1488
|
+
...process.env,
|
|
1489
|
+
ELECTRON_RUN_AS_NODE: void 0
|
|
1490
|
+
}
|
|
1491
|
+
});
|
|
1492
|
+
const path = located.status === 0 ? located.stdout.split(/\r?\n/u).find((line) => line.trim() !== "")?.trim() : void 0;
|
|
1493
|
+
if (path === void 0) return void 0;
|
|
1494
|
+
const asked = spawnSync(path, ["--version"], { encoding: "utf8" });
|
|
1495
|
+
return asked.status === 0 ? {
|
|
1496
|
+
path,
|
|
1497
|
+
version: asked.stdout.trim()
|
|
1498
|
+
} : void 0;
|
|
1499
|
+
}
|
|
1500
|
+
/** A word for `sh`: single-quoted, with each `'` closed, escaped and reopened. */
|
|
1501
|
+
function shWord(value) {
|
|
1502
|
+
return `'${value.replaceAll("'", "'\\''")}'`;
|
|
1503
|
+
}
|
|
1504
|
+
/** A word for `cmd.exe`: double-quoted; `%` doubled so a batch file does not expand it. A path cannot hold `"`. */
|
|
1505
|
+
function cmdWord(value) {
|
|
1506
|
+
return `"${value.replaceAll("%", "%%")}"`;
|
|
1507
|
+
}
|
|
1508
|
+
function posixShim(root, target) {
|
|
1509
|
+
const words = [
|
|
1510
|
+
target.node,
|
|
1511
|
+
...target.nodeOptions,
|
|
1512
|
+
target.client,
|
|
1513
|
+
"--dir",
|
|
1514
|
+
root
|
|
1515
|
+
].map(shWord).join(" ");
|
|
1516
|
+
return `#!/bin/sh\n# This app's door (@acryldev/door): reaches only the app running from this folder. Rewritten each time the app starts.\n${`${target.electron ? "export ELECTRON_RUN_AS_NODE=1\n" : ""}export MSYS_NO_PATHCONV=1\nexport MSYS2_ARG_CONV_EXCL='*'\n`}exec ${words} "$@"\n`;
|
|
1517
|
+
}
|
|
1518
|
+
function windowsShim(root, target) {
|
|
1519
|
+
const words = [
|
|
1520
|
+
target.node,
|
|
1521
|
+
...target.nodeOptions,
|
|
1522
|
+
target.client,
|
|
1523
|
+
"--dir",
|
|
1524
|
+
root
|
|
1525
|
+
].map(cmdWord).join(" ");
|
|
1526
|
+
return `@echo off\r\nsetlocal\r\nrem This app's door (@acryldev/door): reaches only the app running from this folder. Rewritten each time the app starts.\r\n${target.electron ? "set ELECTRON_RUN_AS_NODE=1\r\n" : ""}${words} %*\r\n`;
|
|
1527
|
+
}
|
|
1528
|
+
/** The error codes with which Windows refuses to replace a file that a running process (a `cmd.exe` executing the batch file) has open. */
|
|
1529
|
+
const LOCKED = /* @__PURE__ */ new Set([
|
|
1530
|
+
"EPERM",
|
|
1531
|
+
"EBUSY",
|
|
1532
|
+
"EACCES"
|
|
1533
|
+
]);
|
|
1534
|
+
const realFs = {
|
|
1535
|
+
rename: renameSync,
|
|
1536
|
+
pause: (ms) => {
|
|
1537
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
1538
|
+
}
|
|
1539
|
+
};
|
|
1540
|
+
/**
|
|
1541
|
+
* Write `content` to `file` so a reader never sees half of it. A shim that already holds this content is left alone: a restart of the app (the dev server restarts on a change)
|
|
1542
|
+
* rewrites the same text, and on Windows replacing a batch file that an agent's `acryl` call is running fails with EPERM, which stopped the app from starting. A file that
|
|
1543
|
+
* is held while its content differs is retried for about a second, and then reported: the old shim stays (it still works), and the app starts.
|
|
1544
|
+
*/
|
|
1545
|
+
function writeAtomically(file, content, mode, fs = realFs) {
|
|
1546
|
+
try {
|
|
1547
|
+
if (readFileSync(file, "utf8") === content) return;
|
|
1548
|
+
} catch {}
|
|
1549
|
+
const temporary = `${file}.${String(process.pid)}.tmp`;
|
|
1550
|
+
writeFileSync(temporary, content, { mode });
|
|
1551
|
+
if (process.platform !== "win32") chmodSync(temporary, mode);
|
|
1552
|
+
for (let attempt = 0;; attempt += 1) try {
|
|
1553
|
+
fs.rename(temporary, file);
|
|
1554
|
+
return;
|
|
1555
|
+
} catch (cause) {
|
|
1556
|
+
const code = cause.code;
|
|
1557
|
+
if (code === void 0 || !LOCKED.has(code) || attempt >= 10) {
|
|
1558
|
+
rmSync(temporary, { force: true });
|
|
1559
|
+
throw cause;
|
|
1560
|
+
}
|
|
1561
|
+
fs.pause(25 * (attempt + 1));
|
|
1562
|
+
}
|
|
1563
|
+
}
|
|
1564
|
+
/** Write `.acryl/bin/acryl` and `.acryl/bin/acryl.cmd` for the app at `root`. @returns the folder they are in. */
|
|
1565
|
+
function writeShims(root, target) {
|
|
1566
|
+
const bin = join(ensureStateDir(root), "bin");
|
|
1567
|
+
mkdirSync(bin, {
|
|
1568
|
+
recursive: true,
|
|
1569
|
+
mode: 448
|
|
1570
|
+
});
|
|
1571
|
+
if (process.platform !== "win32") chmodSync(bin, 448);
|
|
1572
|
+
writeAtomically(join(bin, "acryl"), posixShim(root, target), 448);
|
|
1573
|
+
writeAtomically(join(bin, "acryl.cmd"), windowsShim(root, target), 384);
|
|
1574
|
+
return bin;
|
|
1575
|
+
}
|
|
1576
|
+
//#endregion
|
|
1577
|
+
//#region ../../../plugins/door/src/index.ts
|
|
1578
|
+
/**
|
|
1579
|
+
* `@acryldev/door`: the Door of the five nouns, as a Cordis plugin of a framework app (spec 049 slice 9). An agent working in the app folder
|
|
1580
|
+
* looks at the running page, acts on it, and installs plugins live, through `.acryl/bin/acryl`; everything else it does with its own
|
|
1581
|
+
* file tools and shell.
|
|
1582
|
+
*
|
|
1583
|
+
* The page loads `/api/door/page.js` (one script tag) and keeps an event stream open to the Host; the Host sends it calls. An
|
|
1584
|
+
* operator on this machine reaches `/api/door/call` with the secret from `<app>/.acryl/door.json`. One effect owns the channel and
|
|
1585
|
+
* the audit, the routes are mounted after it, and a second effect writes the connection file last, so disposal removes the file first,
|
|
1586
|
+
* then the routes (their in-flight calls end), then closes the channel (every pending call settles).
|
|
1587
|
+
*/
|
|
1588
|
+
/** Stable Cordis plugin name, equal to the package name and the Loader row id. */
|
|
1589
|
+
const name = "acryl-door";
|
|
1590
|
+
const inject = ["router", "appInstance"];
|
|
1591
|
+
const Config = z.object({
|
|
1592
|
+
allowInProduction: z.boolean().default(false).description("Run in production too (NODE_ENV=production); ACRYL_DOOR=off still turns it off."),
|
|
1593
|
+
pageOnly: z.boolean().default(false).description("Only the page and the look and act chat tools (a production assistant); runs in production."),
|
|
1594
|
+
reloadOnChange: z.boolean().default(true).description("Reload the open pages after a plugin was added, removed or reloaded while the app runs."),
|
|
1595
|
+
hostIndex: z.boolean().default(true).description("Put the page script in the host's own index page too; off when that index is a frame around the app."),
|
|
1596
|
+
appBase: z.string().default("").description("The prefix the app pages are served under (the frame canvas), without a trailing slash; empty at the root."),
|
|
1597
|
+
tools: z.object({ expose: z.array(z.string().pattern(/^(?!door_)[A-Za-z][A-Za-z0-9_-]{0,63}$/u)).description("App tools (from the tools registry) the door offers; none by default.") })
|
|
1598
|
+
});
|
|
1599
|
+
/** The page module, served compiled from source by the app's own TypeScript. */
|
|
1600
|
+
const PAGE_DIR = join(import.meta.dirname, import.meta.url.endsWith(".ts") ? "page" : join("..", "src", "page"));
|
|
1601
|
+
/** The operator client this build runs: the source next to this file, or the built `cli.js`. */
|
|
1602
|
+
const CLIENT = import.meta.url.endsWith(".ts") ? join(import.meta.dirname, "cli", "acryl.ts") : join(import.meta.dirname, "cli.js");
|
|
1603
|
+
/** How the folder's `.acryl/bin/acryl` starts the client: with the Node that runs the app, and its type-stripping flag when run from source. */
|
|
1604
|
+
function shimTarget() {
|
|
1605
|
+
const fromSource = CLIENT.endsWith(".ts");
|
|
1606
|
+
const inElectron = process.versions.electron !== void 0;
|
|
1607
|
+
const node = inElectron ? realNode() : void 0;
|
|
1608
|
+
return {
|
|
1609
|
+
node: node ?? process.execPath,
|
|
1610
|
+
nodeOptions: fromSource ? process.execArgv.filter((option) => /^--experimental-(strip|transform)-types$/u.test(option)) : [],
|
|
1611
|
+
client: CLIENT,
|
|
1612
|
+
electron: inElectron && node === void 0
|
|
1613
|
+
};
|
|
1614
|
+
}
|
|
1615
|
+
/** A listening address as one the operator reaches: an any-address bind is reached on loopback. */
|
|
1616
|
+
function loopbackUrl(url) {
|
|
1617
|
+
const parsed = new URL(url);
|
|
1618
|
+
if (parsed.hostname === "0.0.0.0" || parsed.hostname === "[::]") parsed.hostname = "127.0.0.1";
|
|
1619
|
+
return parsed.origin;
|
|
1620
|
+
}
|
|
1621
|
+
const escapeHtml = (text) => text.replace(/[&<>"']/gu, (char) => `&#${char.charCodeAt(0)};`);
|
|
1622
|
+
/** The page of a path the app does not serve, development only: what is missing, a way back, and the door's script. */
|
|
1623
|
+
function notFoundPage(path, scriptTag) {
|
|
1624
|
+
return `<!doctype html><html lang="en"><head><meta charset="utf-8"><title>404 Not Found</title></head><body><main><h1>404 Not Found</h1><p>This app has no page at <code>${escapeHtml(path)}</code>.</p><p><a href="/">Back to the app</a></p></main>${scriptTag}</body></html>`;
|
|
1625
|
+
}
|
|
1626
|
+
function apply(ctx, rawConfig = {}) {
|
|
1627
|
+
const config = Config(rawConfig);
|
|
1628
|
+
const pageOnly = config.pageOnly === true;
|
|
1629
|
+
if (process.env.ACRYL_DOOR === "off" || process.env.NODE_ENV === "production" && config.allowInProduction !== true && !pageOnly) return;
|
|
1630
|
+
const app = ctx.get("appInstance");
|
|
1631
|
+
const carrier = () => {
|
|
1632
|
+
const web = ctx.get("acrylWeb");
|
|
1633
|
+
if (web !== void 0) return web;
|
|
1634
|
+
const node = ctx.get("nodeServer");
|
|
1635
|
+
if (typeof node?.url !== "string") return void 0;
|
|
1636
|
+
try {
|
|
1637
|
+
const parsed = new URL(node.url);
|
|
1638
|
+
return {
|
|
1639
|
+
host: parsed.hostname,
|
|
1640
|
+
port: Number(parsed.port)
|
|
1641
|
+
};
|
|
1642
|
+
} catch {
|
|
1643
|
+
return;
|
|
1644
|
+
}
|
|
1645
|
+
};
|
|
1646
|
+
if (typeof app?.root !== "string") throw new Error("@acryldev/door: the appInstance service has no app folder (root)");
|
|
1647
|
+
const reportError = (operation, cause) => {
|
|
1648
|
+
ctx.logger?.error?.(`@acryldev/door: failed to ${operation}: ${cause instanceof Error ? cause.message : String(cause)}`);
|
|
1649
|
+
};
|
|
1650
|
+
const address = { url: "" };
|
|
1651
|
+
if (!pageOnly) assertDoorIsFree(app.root);
|
|
1652
|
+
const secret = newSecret();
|
|
1653
|
+
const channel = new UiChannel({
|
|
1654
|
+
attachWaitMs: 2e3,
|
|
1655
|
+
requirePage: pageOnly
|
|
1656
|
+
});
|
|
1657
|
+
const shell = new ShellChannel();
|
|
1658
|
+
const audit = new AuditLog(auditPath(stateDir(app.root)));
|
|
1659
|
+
const rawBase = typeof config.appBase === "string" ? config.appBase.trim() : "";
|
|
1660
|
+
const appBase = rawBase.startsWith("/") && rawBase !== "/" ? rawBase.replace(/\/+$/u, "") : "";
|
|
1661
|
+
const door = new Door({
|
|
1662
|
+
channel,
|
|
1663
|
+
shell,
|
|
1664
|
+
audit,
|
|
1665
|
+
app: {
|
|
1666
|
+
name: app.name,
|
|
1667
|
+
root: app.root,
|
|
1668
|
+
get url() {
|
|
1669
|
+
return address.url;
|
|
1670
|
+
}
|
|
1671
|
+
},
|
|
1672
|
+
...appBase === "" ? {} : { appBase },
|
|
1673
|
+
extensions: () => ctx.get("extensions"),
|
|
1674
|
+
pluginShare: () => ctx.get("pluginShare"),
|
|
1675
|
+
tools: () => ctx.get("tools"),
|
|
1676
|
+
expose: config.tools?.expose ?? [],
|
|
1677
|
+
reloadOnChange: config.reloadOnChange !== false
|
|
1678
|
+
});
|
|
1679
|
+
ctx.effect(() => () => {
|
|
1680
|
+
channel.close();
|
|
1681
|
+
}, "@acryldev/door: page channel");
|
|
1682
|
+
ctx.effect(() => () => {
|
|
1683
|
+
shell.close();
|
|
1684
|
+
}, "@acryldev/door: desktop shell channel");
|
|
1685
|
+
const pageModule = new Acryl().get(`${DOOR_PREFIX}/page.js`, (c) => c.body(`import '${DOOR_PREFIX}/page/main.ts'\n`, 200, { "content-type": "text/javascript; charset=utf-8" })).route(`${DOOR_PREFIX}/page`, clientModules({
|
|
1686
|
+
root: PAGE_DIR,
|
|
1687
|
+
mount: `${DOOR_PREFIX}/page`
|
|
1688
|
+
}));
|
|
1689
|
+
const tag = `<script type="module" src="${DOOR_PREFIX}/page.js"><\/script>`;
|
|
1690
|
+
const meta = appBase === "" ? "" : `<meta name="acryl-app-base" content="${appBase}">`;
|
|
1691
|
+
const addScript = async (c, next) => {
|
|
1692
|
+
await next();
|
|
1693
|
+
if (!(c.res.headers.get("content-type") ?? "").includes("text/html")) {
|
|
1694
|
+
if (c.res.status === 404 && (c.req.header("accept") ?? "").includes("text/html") && !(c.res.headers.get("content-type") ?? "").includes("json")) c.res = new Response(notFoundPage(c.req.path, tag), {
|
|
1695
|
+
status: 404,
|
|
1696
|
+
headers: { "content-type": "text/html; charset=utf-8" }
|
|
1697
|
+
});
|
|
1698
|
+
return;
|
|
1699
|
+
}
|
|
1700
|
+
let html = await c.res.text();
|
|
1701
|
+
const headers = new Headers(c.res.headers);
|
|
1702
|
+
headers.delete("content-length");
|
|
1703
|
+
if (meta !== "" && !html.includes("name=\"acryl-app-base\"")) html = html.includes("</head>") ? html.replace("</head>", `${meta}</head>`) : meta + html;
|
|
1704
|
+
if (!html.includes(`/api/acryl-door/page.js`)) html = html.includes("</body>") ? html.replace("</body>", `${tag}</body>`) : html + tag;
|
|
1705
|
+
c.res = new Response(html, {
|
|
1706
|
+
status: c.res.status,
|
|
1707
|
+
headers
|
|
1708
|
+
});
|
|
1709
|
+
};
|
|
1710
|
+
const router = ctx.router;
|
|
1711
|
+
if (typeof router.wrap === "function") router.wrap(addScript);
|
|
1712
|
+
else ctx.router.route("/", new Acryl().use("*", addScript));
|
|
1713
|
+
if (config.hostIndex !== false) ctx.inject(["webServer"], (inner) => {
|
|
1714
|
+
inner.effect(() => {
|
|
1715
|
+
const taps = inner.get("webServer");
|
|
1716
|
+
if (typeof taps?.tapIndex !== "function") return () => {};
|
|
1717
|
+
return taps.tapIndex((html) => {
|
|
1718
|
+
if (html.includes(`/api/acryl-door/page.js`)) return html;
|
|
1719
|
+
return html.includes("</body>") ? html.replace("</body>", `${tag}</body>`) : html + tag;
|
|
1720
|
+
});
|
|
1721
|
+
}, "@acryldev/door: the page script in the host index");
|
|
1722
|
+
});
|
|
1723
|
+
let pageUpgrade;
|
|
1724
|
+
let nodeUpgrade;
|
|
1725
|
+
const endNodeOwner = () => {
|
|
1726
|
+
if (pageUpgrade === nodeUpgrade) pageUpgrade = void 0;
|
|
1727
|
+
nodeUpgrade = void 0;
|
|
1728
|
+
};
|
|
1729
|
+
const nodeFallback = () => {
|
|
1730
|
+
if (ctx.get("routerHttp") !== void 0 || nodeUpgrade !== void 0) return;
|
|
1731
|
+
try {
|
|
1732
|
+
const allow = ctx.get("nodeServer")?.upgrades?.();
|
|
1733
|
+
if (allow !== void 0) {
|
|
1734
|
+
nodeUpgrade = allow;
|
|
1735
|
+
pageUpgrade = allow;
|
|
1736
|
+
}
|
|
1737
|
+
} catch (cause) {
|
|
1738
|
+
reportError("open the page channel over a WebSocket (the pages use the event stream)", cause);
|
|
1739
|
+
}
|
|
1740
|
+
};
|
|
1741
|
+
ctx.inject(["routerHttp"], (inner) => {
|
|
1742
|
+
endNodeOwner();
|
|
1743
|
+
const http = inner.get("routerHttp");
|
|
1744
|
+
try {
|
|
1745
|
+
const allow = http?.upgrades?.();
|
|
1746
|
+
if (allow === void 0 || http === void 0 || typeof http.mount !== "function") return;
|
|
1747
|
+
pageUpgrade = allow;
|
|
1748
|
+
const remove = http.mount(DOOR_PREFIX, { upgrade: [`${DOOR_PREFIX}/channel/ws`] });
|
|
1749
|
+
inner.effect(() => () => {
|
|
1750
|
+
remove();
|
|
1751
|
+
if (pageUpgrade === allow) pageUpgrade = void 0;
|
|
1752
|
+
nodeFallback();
|
|
1753
|
+
}, "@acryldev/door: the page socket via routerHttp");
|
|
1754
|
+
} catch (cause) {
|
|
1755
|
+
reportError("open the page channel over a WebSocket (the pages use the event stream)", cause);
|
|
1756
|
+
}
|
|
1757
|
+
});
|
|
1758
|
+
ctx.inject(["nodeServer"], (inner) => {
|
|
1759
|
+
inner.effect(() => {
|
|
1760
|
+
nodeFallback();
|
|
1761
|
+
const onService = inner.on;
|
|
1762
|
+
const off = onService("internal/service", () => {
|
|
1763
|
+
if (ctx.get("routerHttp") !== void 0) endNodeOwner();
|
|
1764
|
+
else nodeFallback();
|
|
1765
|
+
});
|
|
1766
|
+
return () => {
|
|
1767
|
+
off();
|
|
1768
|
+
endNodeOwner();
|
|
1769
|
+
};
|
|
1770
|
+
}, "@acryldev/door: the page socket on the node server");
|
|
1771
|
+
});
|
|
1772
|
+
ctx.router.route("/", pageSocketRoutes(channel, {
|
|
1773
|
+
prefix: DOOR_PREFIX,
|
|
1774
|
+
upgrade: () => pageUpgrade
|
|
1775
|
+
}));
|
|
1776
|
+
ctx.router.route("/", privateApi(DOOR_PREFIX, pageModule, pageChannelRoutes(channel, { prefix: DOOR_PREFIX }), ...pageOnly ? [] : [
|
|
1777
|
+
shellRoutes(DOOR_PREFIX, secret, shell),
|
|
1778
|
+
operatorRoutes(DOOR_PREFIX, secret, door, reportError),
|
|
1779
|
+
mcpRoutes(DOOR_PREFIX, secret, door, reportError)
|
|
1780
|
+
]));
|
|
1781
|
+
ctx.inject(["tools"], (inner) => {
|
|
1782
|
+
inner.effect(() => {
|
|
1783
|
+
const tools = inner.get("tools");
|
|
1784
|
+
const verbs = pageOnly ? PAGE_VERBS : VERBS;
|
|
1785
|
+
return isDshTools(tools) ? registerDshChatTools(tools, door, verbs) : registerChatTools(tools, door, verbs);
|
|
1786
|
+
}, "@acryldev/door: the verbs in the tools registry");
|
|
1787
|
+
});
|
|
1788
|
+
ctx.effect(function* () {
|
|
1789
|
+
yield ctx.reflect.provide("door", door);
|
|
1790
|
+
}, "@acryldev/door: the door service");
|
|
1791
|
+
if (pageOnly) return;
|
|
1792
|
+
ctx.effect(async () => {
|
|
1793
|
+
let bound = carrier();
|
|
1794
|
+
for (let at = 0; at < 500 && (bound === void 0 || !(bound.port > 0)); at += 1) {
|
|
1795
|
+
await new Promise((done) => setTimeout(done, 10));
|
|
1796
|
+
bound = carrier();
|
|
1797
|
+
}
|
|
1798
|
+
if (bound === void 0) throw new Error("@acryldev/door: no carrier bound the app (neither acrylWeb nor nodeServer answered)");
|
|
1799
|
+
address.url = loopbackUrl(`http://${bound.host}:${String(bound.port)}`);
|
|
1800
|
+
writeDoorFile(app.root, address.url, secret);
|
|
1801
|
+
try {
|
|
1802
|
+
writeShims(app.root, shimTarget());
|
|
1803
|
+
} catch (cause) {
|
|
1804
|
+
reportError("write .acryl/bin", cause);
|
|
1805
|
+
}
|
|
1806
|
+
return () => {
|
|
1807
|
+
removeDoorFile(app.root, secret);
|
|
1808
|
+
};
|
|
1809
|
+
}, "@acryldev/door: .acryl/door.json and .acryl/bin/acryl");
|
|
1810
|
+
}
|
|
1811
|
+
//#endregion
|
|
1812
|
+
export { Config, DOOR_PREFIX, Door, DoorError, PAGE_VERBS, STATE_DIR, VERBS, VERB_SPECS, apply, assertDoorIsFree, chatToolName, doorFilePath, inject, mcpTools, name, notFoundPage, readDoorFile };
|