@yaks/browse 0.0.0-stage → 0.2.36

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.
Files changed (271) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +324 -2
  3. package/_dist/app.d.ts +8 -0
  4. package/_dist/app.d.ts.map +1 -0
  5. package/_dist/cli.d.ts +16 -0
  6. package/_dist/cli.d.ts.map +1 -0
  7. package/_dist/hosting.d.ts +24 -0
  8. package/_dist/hosting.d.ts.map +1 -0
  9. package/_dist/mod.d.ts +7 -0
  10. package/_dist/mod.d.ts.map +1 -0
  11. package/_dist/types.d.ts +5 -0
  12. package/_dist/types.d.ts.map +1 -0
  13. package/_dist/url.d.ts +2 -0
  14. package/_dist/url.d.ts.map +1 -0
  15. package/app.js +10 -0
  16. package/app.js.map +1 -0
  17. package/app.ts +10 -0
  18. package/browser-links.js +22 -0
  19. package/browser-links.js.map +1 -0
  20. package/browser-links.ts +28 -0
  21. package/cli.js +172 -0
  22. package/cli.js.map +1 -0
  23. package/cli.ts +168 -0
  24. package/client.js +748 -0
  25. package/client.js.map +1 -0
  26. package/client.ts +734 -0
  27. package/clipboard.js +18 -0
  28. package/clipboard.js.map +1 -0
  29. package/clipboard.ts +17 -0
  30. package/commands.js +1157 -0
  31. package/commands.js.map +1 -0
  32. package/commands.ts +1108 -0
  33. package/components/Ansi.tsx +160 -0
  34. package/components/App.tsx +446 -0
  35. package/components/Canvas.tsx +625 -0
  36. package/components/Card.tsx +276 -0
  37. package/components/Chat.tsx +205 -0
  38. package/components/Configuration.tsx +218 -0
  39. package/components/Decision.tsx +49 -0
  40. package/components/Dot.tsx +52 -0
  41. package/components/Entity.tsx +609 -0
  42. package/components/Fault.tsx +43 -0
  43. package/components/Filter.tsx +103 -0
  44. package/components/Keybindings.tsx +100 -0
  45. package/components/Keys.tsx +67 -0
  46. package/components/Markdown.tsx +90 -0
  47. package/components/Navigation.tsx +161 -0
  48. package/components/New.tsx +490 -0
  49. package/components/Peek.tsx +168 -0
  50. package/components/Prio.tsx +20 -0
  51. package/components/Run.tsx +263 -0
  52. package/components/Search.tsx +280 -0
  53. package/components/Stamp.tsx +44 -0
  54. package/components/Status.tsx +514 -0
  55. package/components/Sync.tsx +173 -0
  56. package/components/Tile.tsx +50 -0
  57. package/components/answered.js +23 -0
  58. package/components/answered.js.map +1 -0
  59. package/components/answered.ts +25 -0
  60. package/components/comp.js +11 -0
  61. package/components/comp.js.map +1 -0
  62. package/components/comp.ts +10 -0
  63. package/components/drag.js +173 -0
  64. package/components/drag.js.map +1 -0
  65. package/components/drag.ts +198 -0
  66. package/components/fields.tsx +90 -0
  67. package/components/fixtures/README.md +10 -0
  68. package/components/fixtures/archetypes.json +3646 -0
  69. package/components/hits.js +63 -0
  70. package/components/hits.js.map +1 -0
  71. package/components/hits.ts +84 -0
  72. package/components/icons.tsx +177 -0
  73. package/components/inspect.tsx +331 -0
  74. package/components/mount.ts +79 -0
  75. package/components/nav.tsx +479 -0
  76. package/components/offers.js +26 -0
  77. package/components/offers.js.map +1 -0
  78. package/components/offers.ts +54 -0
  79. package/components/page.js +21 -0
  80. package/components/page.js.map +1 -0
  81. package/components/page.ts +18 -0
  82. package/components/read.js +5 -0
  83. package/components/read.js.map +1 -0
  84. package/components/read.ts +7 -0
  85. package/components/registry.js +285 -0
  86. package/components/registry.js.map +1 -0
  87. package/components/registry.ts +317 -0
  88. package/components/session_status.tsx +115 -0
  89. package/components/subscriptions.js +149 -0
  90. package/components/subscriptions.js.map +1 -0
  91. package/components/subscriptions.ts +161 -0
  92. package/components/title.tsx +21 -0
  93. package/components/useQuery.js +166 -0
  94. package/components/useQuery.js.map +1 -0
  95. package/components/useQuery.ts +211 -0
  96. package/components/views/Board.tsx +450 -0
  97. package/components/views/BoardTile.tsx +65 -0
  98. package/components/views/Dashboard.tsx +148 -0
  99. package/components/views/Debug.tsx +445 -0
  100. package/components/views/Dependency.tsx +51 -0
  101. package/components/views/Entry.tsx +500 -0
  102. package/components/views/Gist.tsx +28 -0
  103. package/components/views/Inline.tsx +54 -0
  104. package/components/views/Json.tsx +19 -0
  105. package/components/views/Layout.tsx +211 -0
  106. package/components/views/List.tsx +238 -0
  107. package/components/views/Md.tsx +43 -0
  108. package/components/views/Media.tsx +48 -0
  109. package/components/views/Memory.tsx +32 -0
  110. package/components/views/Relate.tsx +205 -0
  111. package/components/views/Search.tsx +42 -0
  112. package/components/views/Session.tsx +850 -0
  113. package/components/views/SessionManage.tsx +127 -0
  114. package/components/views/Show.tsx +758 -0
  115. package/components/views/Shown.tsx +72 -0
  116. package/components/views/Split.tsx +58 -0
  117. package/components/views/TaskTile.tsx +37 -0
  118. package/components/views/Title.tsx +105 -0
  119. package/components/views/Wake.tsx +77 -0
  120. package/components/views/Web.tsx +49 -0
  121. package/components/wells.js +30 -0
  122. package/components/wells.js.map +1 -0
  123. package/components/wells.ts +33 -0
  124. package/configuration.js +38 -0
  125. package/configuration.js.map +1 -0
  126. package/configuration.ts +41 -0
  127. package/decision_sync.js +88 -0
  128. package/decision_sync.js.map +1 -0
  129. package/decision_sync.ts +93 -0
  130. package/deno.json +1 -0
  131. package/domain-host.tsx +108 -0
  132. package/edge.js +193 -0
  133. package/edge.js.map +1 -0
  134. package/edge.ts +196 -0
  135. package/entry_log.js +241 -0
  136. package/entry_log.js.map +1 -0
  137. package/entry_log.ts +214 -0
  138. package/failure.js +22 -0
  139. package/failure.js.map +1 -0
  140. package/failure.ts +34 -0
  141. package/front.json +61 -0
  142. package/highlight.js +143 -0
  143. package/highlight.js.map +1 -0
  144. package/highlight.ts +149 -0
  145. package/history.js +68 -0
  146. package/history.js.map +1 -0
  147. package/history.ts +72 -0
  148. package/host_commands.js +107 -0
  149. package/host_commands.js.map +1 -0
  150. package/host_commands.ts +38 -0
  151. package/hosting.js +53 -0
  152. package/hosting.js.map +1 -0
  153. package/hosting.ts +72 -0
  154. package/idb.js +14 -0
  155. package/idb.js.map +1 -0
  156. package/idb.ts +15 -0
  157. package/index.js +232 -0
  158. package/index.js.map +1 -0
  159. package/index.ts +252 -0
  160. package/keybindings.js +136 -0
  161. package/keybindings.js.map +1 -0
  162. package/keybindings.ts +37 -0
  163. package/kit.js +103 -0
  164. package/kit.js.map +1 -0
  165. package/kit.ts +119 -0
  166. package/layout.js +254 -0
  167. package/layout.js.map +1 -0
  168. package/layout.ts +210 -0
  169. package/legacy_outbox.js +53 -0
  170. package/legacy_outbox.js.map +1 -0
  171. package/legacy_outbox.ts +63 -0
  172. package/live.js +2883 -0
  173. package/live.js.map +1 -0
  174. package/live.ts +3334 -0
  175. package/live_archetypes.js +92 -0
  176. package/live_archetypes.js.map +1 -0
  177. package/live_archetypes.ts +113 -0
  178. package/live_client.js +145 -0
  179. package/live_client.js.map +1 -0
  180. package/live_client.ts +120 -0
  181. package/main.tsx +5 -0
  182. package/mod.js +7 -0
  183. package/mod.js.map +1 -0
  184. package/mod.ts +7 -0
  185. package/mount.tsx +50 -0
  186. package/navigation.js +120 -0
  187. package/navigation.js.map +1 -0
  188. package/navigation.ts +152 -0
  189. package/near.js +83 -0
  190. package/near.js.map +1 -0
  191. package/near.ts +83 -0
  192. package/new.js +295 -0
  193. package/new.js.map +1 -0
  194. package/new.ts +361 -0
  195. package/outbox.js +112 -0
  196. package/outbox.js.map +1 -0
  197. package/outbox.ts +129 -0
  198. package/owner.js +39 -0
  199. package/owner.js.map +1 -0
  200. package/owner.ts +37 -0
  201. package/package.json +81 -4
  202. package/paste.js +157 -0
  203. package/paste.js.map +1 -0
  204. package/paste.ts +122 -0
  205. package/props.js +303 -0
  206. package/props.js.map +1 -0
  207. package/props.ts +358 -0
  208. package/providers.js +136 -0
  209. package/providers.js.map +1 -0
  210. package/providers.ts +194 -0
  211. package/query.js +987 -0
  212. package/query.js.map +1 -0
  213. package/query.ts +1113 -0
  214. package/remote.js +37 -0
  215. package/remote.js.map +1 -0
  216. package/remote.ts +46 -0
  217. package/resolver.js +149 -0
  218. package/resolver.js.map +1 -0
  219. package/resolver.ts +213 -0
  220. package/rfc2047.js +37 -0
  221. package/rfc2047.js.map +1 -0
  222. package/rfc2047.ts +40 -0
  223. package/row_holds.js +107 -0
  224. package/row_holds.js.map +1 -0
  225. package/row_holds.ts +93 -0
  226. package/served.ts +42 -0
  227. package/session_worktree.js +7 -0
  228. package/session_worktree.js.map +1 -0
  229. package/session_worktree.ts +16 -0
  230. package/sessions.js +57 -0
  231. package/sessions.js.map +1 -0
  232. package/sessions.ts +53 -0
  233. package/sha.js +161 -0
  234. package/sha.js.map +1 -0
  235. package/sha.ts +164 -0
  236. package/styles.css +2823 -0
  237. package/subs.js +36 -0
  238. package/subs.js.map +1 -0
  239. package/subs.ts +40 -0
  240. package/terminal-route.js +13 -0
  241. package/terminal-route.js.map +1 -0
  242. package/terminal-route.ts +17 -0
  243. package/terminal.js +251 -0
  244. package/terminal.js.map +1 -0
  245. package/terminal.ts +186 -0
  246. package/time.js +142 -0
  247. package/time.js.map +1 -0
  248. package/time.ts +133 -0
  249. package/title.js +25 -0
  250. package/title.js.map +1 -0
  251. package/title.ts +50 -0
  252. package/tui/doc.ts +6 -0
  253. package/tui/testing.ts +19 -0
  254. package/twin.js +11 -0
  255. package/twin.js.map +1 -0
  256. package/twin.ts +13 -0
  257. package/types.js +456 -0
  258. package/types.js.map +1 -0
  259. package/types.ts +1370 -0
  260. package/url.js +77 -0
  261. package/url.js.map +1 -0
  262. package/url.ts +85 -0
  263. package/verb.js +82 -0
  264. package/verb.js.map +1 -0
  265. package/verb.ts +137 -0
  266. package/warmth.js +41 -0
  267. package/warmth.js.map +1 -0
  268. package/warmth.ts +54 -0
  269. package/wire.js +86 -0
  270. package/wire.js.map +1 -0
  271. package/wire.ts +63 -0
@@ -0,0 +1,22 @@
1
+ // Browser anchors keep shared addresses and follow the app in place.
2
+ import { appRoute, visit } from './components/nav.tsx';
3
+ import { localPath } from "./hosting.js";
4
+ // Internal anchors retain their native shared-link/new-tab address, while a
5
+ // plain click follows the app's controlled navigation in this tab: an
6
+ // entity's own address peeks it, as its links do (nav.tsx visit).
7
+ addEventListener('click', (event)=>{
8
+ let ev = event;
9
+ if (ev.defaultPrevented || ev.metaKey || ev.ctrlKey || ev.shiftKey || ev.altKey || ev.button != 0) return;
10
+ let a = ev.target?.closest?.('a[href]');
11
+ if (!a || a.hasAttribute('download') || a.target && a.target != '_self') {
12
+ return;
13
+ }
14
+ let url = new URL(a.href, location.href);
15
+ if (url.origin != location.origin || !appRoute(localPath(url.pathname))) {
16
+ return;
17
+ }
18
+ if (url.hash && url.pathname + url.search == location.pathname + location.search) return;
19
+ ev.preventDefault();
20
+ visit(localPath(url.pathname) + url.search + url.hash, ev);
21
+ });
22
+ //# sourceMappingURL=browser-links.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser-links.js","sources":["./browser-links.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,SAAS,QAAQ,EAAE,KAAK,QAAQ,uBAAsB;AACtD,SAAS,SAAS,uBAAsB;AACxC,4EAA4E;AAC5E,sEAAsE;AACtE,kEAAkE;AAClE,iBAAiB,SAAS,CAAC;EACzB,IAAI,KAAK;EACT,IACE,GAAG,gBAAgB,IAAI,GAAG,OAAO,IAAI,GAAG,OAAO,IAAI,GAAG,QAAQ,IAC9D,GAAG,MAAM,IAAI,GAAG,MAAM,IAAI,GAC1B;EACF,IAAI,IAAK,GAAG,MAAM,EAAqB,UAAU;EAGjD,IAAI,CAAC,KAAK,EAAE,YAAY,CAAC,eAAe,EAAE,MAAM,IAAI,EAAE,MAAM,IAAI,SAAS;IACvE;EACF;EACA,IAAI,MAAM,IAAI,IAAI,EAAE,IAAI,EAAE,SAAS,IAAI;EACvC,IAAI,IAAI,MAAM,IAAI,SAAS,MAAM,IAAI,CAAC,SAAS,UAAU,IAAI,QAAQ,IAAI;IACvE;EACF;EACA,IACE,IAAI,IAAI,IAAI,IAAI,QAAQ,GAAG,IAAI,MAAM,IAAI,SAAS,QAAQ,GAAG,SAAS,MAAM,EAC5E;EACF,GAAG,cAAc;EACjB,MAAM,UAAU,IAAI,QAAQ,IAAI,IAAI,MAAM,GAAG,IAAI,IAAI,EAAE;AACzD"}
@@ -0,0 +1,28 @@
1
+ // Browser anchors keep shared addresses and follow the app in place.
2
+ import { appRoute, visit } from './components/nav.tsx'
3
+ import { localPath } from './hosting.js'
4
+ // Internal anchors retain their native shared-link/new-tab address, while a
5
+ // plain click follows the app's controlled navigation in this tab: an
6
+ // entity's own address peeks it, as its links do (nav.tsx visit).
7
+ addEventListener('click', (event) => {
8
+ let ev = event as MouseEvent
9
+ if (
10
+ ev.defaultPrevented || ev.metaKey || ev.ctrlKey || ev.shiftKey ||
11
+ ev.altKey || ev.button != 0
12
+ ) return
13
+ let a = (ev.target as Element | null)?.closest?.('a[href]') as
14
+ | HTMLAnchorElement
15
+ | null
16
+ if (!a || a.hasAttribute('download') || a.target && a.target != '_self') {
17
+ return
18
+ }
19
+ let url = new URL(a.href, location.href)
20
+ if (url.origin != location.origin || !appRoute(localPath(url.pathname))) {
21
+ return
22
+ }
23
+ if (
24
+ url.hash && url.pathname + url.search == location.pathname + location.search
25
+ ) return
26
+ ev.preventDefault()
27
+ visit(localPath(url.pathname) + url.search + url.hash, ev)
28
+ })
package/cli.js ADDED
@@ -0,0 +1,172 @@
1
+ /** Browse's terminal commands serve `web` in their own process: the graph
2
+ * they open answers the terminal's HTTP and subscriptions on a loopback port
3
+ * of its own, so no `yak serve` need run first, and other processes' commits
4
+ * still arrive through the host's feed. `--app` browses a yaks.app store
5
+ * instead; configured domains supply views. */ import { subpath, used } from "@yaks/cli/config";
6
+ // This process's own web, on a port nobody else asked for.
7
+ let listen = async (host)=>{
8
+ if (!host.handler) {
9
+ throw new Error('browse has no handler — compose @yaks/api');
10
+ }
11
+ let { denoListen } = await import("@yaks/api");
12
+ let at = Promise.withResolvers();
13
+ let server = denoListen({
14
+ port: 0,
15
+ hostname: '127.0.0.1',
16
+ onListen: ({ hostname, port })=>at.resolve(`http://${hostname}:${port}`)
17
+ }, host.handler);
18
+ return {
19
+ url: await at.promise,
20
+ close: async ()=>{
21
+ await server.shutdown();
22
+ await server.finished;
23
+ }
24
+ };
25
+ };
26
+ /** The app a person names, as the account door resolves it: `space/app` or
27
+ * a slug, or the app's address on the host (`yourname.yaks.app/packing`).
28
+ *
29
+ * ```ts
30
+ * import { assertEquals } from '@std/assert'
31
+ * assertEquals(named('https://yourname.yaks.app/packing/', 'yaks.app'), 'yourname/packing')
32
+ * assertEquals(named('yourname/packing', 'yaks.app'), 'yourname/packing')
33
+ * ```
34
+ */ export let named = (app, host)=>{
35
+ let at = app.replace(/^https?:\/\//, '').replace(/\/+$/, '');
36
+ let [domain, slug] = at.split('/');
37
+ let space = domain.endsWith(`.${host}`) && domain.slice(0, -host.length - 1);
38
+ return space && slug ? `${space}/${slug}` : at;
39
+ };
40
+ // Only the app's own origin hears the token.
41
+ let signed = (origin, headers)=>(input, init)=>{
42
+ let url = new URL(input instanceof Request ? input.url : input);
43
+ if (url.origin != origin) return fetch(input, init);
44
+ let given = new Headers(init?.headers);
45
+ for (let [k, v] of Object.entries(headers))given.set(k, v);
46
+ return fetch(input, {
47
+ ...init,
48
+ headers: given
49
+ });
50
+ };
51
+ let open = {
52
+ name: 'open',
53
+ description: 'Open a yaks app built on the kits in this terminal, over its own rows: ' + 'Tab walks its controls, Enter and Space press, q quits.',
54
+ inputSchema: {
55
+ type: 'object',
56
+ additionalProperties: false,
57
+ required: [
58
+ 'app'
59
+ ],
60
+ properties: {
61
+ app: {
62
+ type: 'string',
63
+ description: 'the app: space/app, a slug, or its address (yourname.yaks.app/packing)'
64
+ }
65
+ }
66
+ },
67
+ positional: [
68
+ 'app'
69
+ ],
70
+ run: async (args, host, context)=>{
71
+ try {
72
+ let { url, wire } = await (await import("./remote.js")).remote(named(String(args.app), context.host), context.host, context.state, undefined, {
73
+ config: context.config,
74
+ as: context.as
75
+ });
76
+ let page = url.replace(/api\/?$/, '');
77
+ let go = signed(new URL(url).origin, wire.headers);
78
+ await (await import("./kit.js")).open(page, url.replace(/\/$/, ''), go);
79
+ return 0;
80
+ } catch (error) {
81
+ await host.report?.(error, {
82
+ tags: {
83
+ step: 'terminal',
84
+ command: 'yak open'
85
+ }
86
+ });
87
+ context.note(error instanceof Error ? error.message : String(error));
88
+ return 1;
89
+ }
90
+ }
91
+ };
92
+ let browsers = [
93
+ 'browse',
94
+ 'inspect'
95
+ ].map((name)=>({
96
+ name,
97
+ description: name == 'browse' ? 'Browse the graph in this terminal.' : 'Browse an Inspect page: the map, an id, or a query.',
98
+ inputSchema: {
99
+ type: 'object',
100
+ additionalProperties: false,
101
+ properties: {
102
+ app: {
103
+ type: 'string',
104
+ description: 'a yaks.app app: slug or space/app'
105
+ },
106
+ what: {
107
+ type: 'string',
108
+ description: 'id or query to open'
109
+ }
110
+ }
111
+ },
112
+ positional: [
113
+ 'what'
114
+ ],
115
+ roles: [
116
+ 'web'
117
+ ],
118
+ run: async (args, host, context)=>{
119
+ let own;
120
+ try {
121
+ let connection = typeof args.app == 'string' ? await (await import("./remote.js")).remote(args.app, context.host, context.state, undefined, {
122
+ config: context.config,
123
+ as: context.as
124
+ }) : {
125
+ url: (own = await listen(host)).url,
126
+ wire: {}
127
+ };
128
+ let { open } = await import("./terminal.js");
129
+ let { onFailure } = await import("./failure.js");
130
+ let restore = onFailure((error, place, tags)=>{
131
+ void host.report?.(error, {
132
+ tags: {
133
+ step: 'render',
134
+ place,
135
+ command: `yak ${name}`,
136
+ ...tags
137
+ }
138
+ });
139
+ });
140
+ try {
141
+ await open(connection.url, {
142
+ what: String(args.what ?? ''),
143
+ inspect: name == 'inspect',
144
+ wire: connection.wire,
145
+ facets: async ()=>(await Promise.all((host.config.plugins ?? []).map((p)=>subpath(used(p), 'views').then((facet)=>facet && {
146
+ ...facet,
147
+ package: used(p)
148
+ })))).filter((f)=>f != null)
149
+ });
150
+ } finally{
151
+ restore();
152
+ }
153
+ return 0;
154
+ } catch (error) {
155
+ await host.report?.(error, {
156
+ tags: {
157
+ step: 'terminal',
158
+ command: `yak ${name}`
159
+ }
160
+ });
161
+ context.note(error instanceof Error ? error.stack ?? error.message : String(error));
162
+ return 1;
163
+ } finally{
164
+ await own?.close();
165
+ }
166
+ }
167
+ }));
168
+ export let commands = [
169
+ ...browsers,
170
+ open
171
+ ];
172
+ //# sourceMappingURL=cli.js.map
package/cli.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sources":["./cli.ts"],"names":[],"mappings":"AAAA;;;;6CAI6C,GAE7C,SAAS,OAAO,EAAE,IAAI,gCAAqC;AAE3D,2DAA2D;AAC3D,IAAI,SAAS,OAAO;EAClB,IAAI,CAAC,KAAK,OAAO,EAAE;IACjB,MAAM,IAAI,MAAM;EAClB;EACA,IAAI,EAAE,UAAU,EAAE,GAAG,MAAM,MAAM,CAAC;EAClC,IAAI,KAAK,QAAQ,aAAa;EAC9B,IAAI,SAAS,WAAW;IACtB,MAAM;IACN,UAAU;IACV,UAAU,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAK,GAAG,OAAO,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC,EAAE,MAAM;EAC3E,GAAG,KAAK,OAAO;EACf,OAAO;IACL,KAAK,MAAM,GAAG,OAAO;IACrB,OAAO;MACL,MAAM,OAAO,QAAQ;MACrB,MAAM,OAAO,QAAQ;IACvB;EACF;AACF;AAEA;;;;;;;;CAQC,GACD,OAAO,IAAI,QAAQ,CAAC,KAAa;EAC/B,IAAI,KAAK,IAAI,OAAO,CAAC,gBAAgB,IAAI,OAAO,CAAC,QAAQ;EACzD,IAAI,CAAC,QAAQ,KAAK,GAAG,GAAG,KAAK,CAAC;EAC9B,IAAI,QAAQ,OAAO,QAAQ,CAAC,CAAC,CAAC,EAAE,MAAM,KAAK,OAAO,KAAK,CAAC,GAAG,CAAC,KAAK,MAAM,GAAG;EAC1E,OAAO,SAAS,OAAO,GAAG,MAAM,CAAC,EAAE,MAAM,GAAG;AAC9C,EAAC;AAED,6CAA6C;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K,IACL,SACA,IAAI,CAAC,CAAC,QAAU,SAAS;oBAAE,GAAG,KAAK;oBAAE,SAAS,KAAK;kBAAG,IAE3D,EAAE,MAAM,CAAC,CAAC,IAAM,KAAK;UAC1B;QACF,SAAU;UACR;QACF;QACA,OAAO;MACT,EAAE,OAAO,OAAO;QACd,MAAM,KAAK,MAAM,GAAG,OAAO;UACzB,MAAM;YAAE,MAAM;YAAY,SAAS,CAAC,IAAI,EAAE,MAAM;UAAC;QACnD;QACA,QAAQ,IAAI,CACV,iBAAiB,QAAQ,MAAM,KAAK,IAAI,MAAM,OAAO,GAAG,OAAO;QAEjE,OAAO;MACT,SAAU;QACR,MAAM,KAAK;MACb;IACF;EACF,CAAC;AAED,OAAO,IAAI,WAAyB;KAAI;EAAU;CAAK,CAAA"}
package/cli.ts ADDED
@@ -0,0 +1,168 @@
1
+ /** Browse's terminal commands serve `web` in their own process: the graph
2
+ * they open answers the terminal's HTTP and subscriptions on a loopback port
3
+ * of its own, so no `yak serve` need run first, and other processes' commits
4
+ * still arrive through the host's feed. `--app` browses a yaks.app store
5
+ * instead; configured domains supply views. */
6
+ import type { CliCommand, Host } from 'jsr:@yaks/cli@0.2.36/host'
7
+ import { subpath, used } from '@yaks/cli/config'
8
+
9
+ // This process's own web, on a port nobody else asked for.
10
+ let listen = async (host: Host) => {
11
+ if (!host.handler) {
12
+ throw new Error('browse has no handler — compose @yaks/api')
13
+ }
14
+ let { denoListen } = await import('@yaks/api')
15
+ let at = Promise.withResolvers<string>()
16
+ let server = denoListen({
17
+ port: 0,
18
+ hostname: '127.0.0.1',
19
+ onListen: ({ hostname, port }) => at.resolve(`http://${hostname}:${port}`),
20
+ }, host.handler)
21
+ return {
22
+ url: await at.promise,
23
+ close: async () => {
24
+ await server.shutdown()
25
+ await server.finished
26
+ },
27
+ }
28
+ }
29
+
30
+ /** The app a person names, as the account door resolves it: `space/app` or
31
+ * a slug, or the app's address on the host (`yourname.yaks.app/packing`).
32
+ *
33
+ * ```ts
34
+ * import { assertEquals } from '@std/assert'
35
+ * assertEquals(named('https://yourname.yaks.app/packing/', 'yaks.app'), 'yourname/packing')
36
+ * assertEquals(named('yourname/packing', 'yaks.app'), 'yourname/packing')
37
+ * ```
38
+ */
39
+ export let named = (app: string, host: string): string => {
40
+ let at = app.replace(/^https?:\/\//, '').replace(/\/+$/, '')
41
+ let [domain, slug] = at.split('/')
42
+ let space = domain.endsWith(`.${host}`) && domain.slice(0, -host.length - 1)
43
+ return space && slug ? `${space}/${slug}` : at
44
+ }
45
+
46
+ // Only the app's own origin hears the token.
47
+ let signed =
48
+ (origin: string, headers: Record<string, string>): typeof fetch =>
49
+ (input, init) => {
50
+ let url = new URL(input instanceof Request ? input.url : input)
51
+ if (url.origin != origin) return fetch(input, init)
52
+ let given = new Headers(init?.headers)
53
+ for (let [k, v] of Object.entries(headers)) given.set(k, v)
54
+ return fetch(input, { ...init, headers: given })
55
+ }
56
+
57
+ let open: CliCommand = {
58
+ name: 'open',
59
+ description:
60
+ 'Open a yaks app built on the kits in this terminal, over its own rows: ' +
61
+ 'Tab walks its controls, Enter and Space press, q quits.',
62
+ inputSchema: {
63
+ type: 'object',
64
+ additionalProperties: false,
65
+ required: ['app'],
66
+ properties: {
67
+ app: {
68
+ type: 'string',
69
+ description:
70
+ 'the app: space/app, a slug, or its address (yourname.yaks.app/packing)',
71
+ },
72
+ },
73
+ },
74
+ positional: ['app'],
75
+ run: async (args, host, context) => {
76
+ try {
77
+ let { url, wire } = await (await import('./remote.js')).remote(
78
+ named(String(args.app), context.host),
79
+ context.host,
80
+ context.state,
81
+ undefined,
82
+ { config: context.config, as: context.as },
83
+ )
84
+ let page = url.replace(/api\/?$/, '')
85
+ let go = signed(
86
+ new URL(url).origin,
87
+ wire.headers as Record<string, string>,
88
+ )
89
+ await (await import('./kit.js')).open(page, url.replace(/\/$/, ''), go)
90
+ return 0
91
+ } catch (error) {
92
+ await host.report?.(error, {
93
+ tags: { step: 'terminal', command: 'yak open' },
94
+ })
95
+ context.note(error instanceof Error ? error.message : String(error))
96
+ return 1
97
+ }
98
+ },
99
+ }
100
+
101
+ let browsers: CliCommand[] = ['browse', 'inspect'].map((name) => ({
102
+ name,
103
+ description: name == 'browse'
104
+ ? 'Browse the graph in this terminal.'
105
+ : 'Browse an Inspect page: the map, an id, or a query.',
106
+ inputSchema: {
107
+ type: 'object',
108
+ additionalProperties: false,
109
+ properties: {
110
+ app: { type: 'string', description: 'a yaks.app app: slug or space/app' },
111
+ what: { type: 'string', description: 'id or query to open' },
112
+ },
113
+ },
114
+ positional: ['what'],
115
+ roles: ['web'],
116
+ run: async (args, host, context) => {
117
+ let own: Awaited<ReturnType<typeof listen>> | undefined
118
+ try {
119
+ let connection = typeof args.app == 'string'
120
+ ? await (await import('./remote.js')).remote(
121
+ args.app,
122
+ context.host,
123
+ context.state,
124
+ undefined,
125
+ { config: context.config, as: context.as },
126
+ )
127
+ : { url: (own = await listen(host)).url, wire: {} }
128
+ let { open } = await import('./terminal.js')
129
+ let { onFailure } = await import('./failure.js')
130
+ let restore = onFailure((error, place, tags) => {
131
+ void host.report?.(error, {
132
+ tags: { step: 'render', place, command: `yak ${name}`, ...tags },
133
+ })
134
+ })
135
+ try {
136
+ await open(connection.url, {
137
+ what: String(args.what ?? ''),
138
+ inspect: name == 'inspect',
139
+ wire: connection.wire,
140
+ facets: async () =>
141
+ (await Promise.all(
142
+ (host.config.plugins ?? []).map((p) =>
143
+ subpath<import('./components/inspect.tsx').Facet>(
144
+ used(p),
145
+ 'views',
146
+ ).then((facet) => facet && { ...facet, package: used(p) })
147
+ ),
148
+ )).filter((f) => f != null),
149
+ })
150
+ } finally {
151
+ restore()
152
+ }
153
+ return 0
154
+ } catch (error) {
155
+ await host.report?.(error, {
156
+ tags: { step: 'terminal', command: `yak ${name}` },
157
+ })
158
+ context.note(
159
+ error instanceof Error ? error.stack ?? error.message : String(error),
160
+ )
161
+ return 1
162
+ } finally {
163
+ await own?.close()
164
+ }
165
+ },
166
+ }))
167
+
168
+ export let commands: CliCommand[] = [...browsers, open]