@yunuseon/kayra 0.17.2 → 0.19.0
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/README.md +2 -0
- package/agent/skills/kayra-rollout/SKILL.md +3 -2
- package/ansible/playbooks/edge.yml +5 -0
- package/ansible/playbooks/nas.yml +9 -1
- package/ansible/playbooks/platform.yml +8 -2
- package/ansible/roles/app/tasks/main.yml +11 -3
- package/ansible/roles/kayra-version/defaults/main.yml +5 -0
- package/ansible/roles/kayra-version/tasks/main.yml +18 -0
- package/ansible/roles/platform/tasks/main.yml +6 -4
- package/cli/dist/browser/assets/index-C4HCL022.js +7 -0
- package/cli/dist/browser/index.html +1 -1
- package/cli/dist/clients/api/api.js +6 -4
- package/cli/dist/clients/api/commands.js +0 -48
- package/cli/dist/clients/api/{contract.js → openapi.js} +2 -51
- package/cli/dist/clients/api/protocol.js +1 -66
- package/cli/dist/clients/api/start.js +1 -1
- package/cli/dist/clients/cli/parser.js +4 -0
- package/cli/dist/clients/cli/status.js +28 -7
- package/cli/dist/clients/mcp/run.js +69 -0
- package/cli/dist/clients/mcp/server.js +130 -0
- package/cli/dist/clients/mcp/tools.js +101 -0
- package/cli/dist/clients/wire/contract.js +53 -0
- package/cli/dist/clients/wire/schemas.js +68 -0
- package/cli/dist/clients/{api → wire}/status.js +7 -1
- package/cli/dist/clients/wire/words.js +48 -0
- package/cli/dist/core/adapters/network.js +20 -1
- package/cli/dist/core/fleet/brand.js +5 -0
- package/cli/dist/core/fleet/parse.js +10 -1
- package/cli/dist/core/fleet/settings.js +18 -3
- package/cli/dist/core/operations/dispatch.js +3 -3
- package/cli/dist/core/recipes/doctor.js +3 -3
- package/cli/dist/core/recipes/host.js +8 -3
- package/cli/dist/core/status/look.js +33 -13
- package/cli/dist/core/status/model.js +2 -0
- package/cli/dist/deployer/brand.js +5 -0
- package/cli/dist/deployer/build/builder.js +5 -0
- package/cli/dist/deployer/build/bundle.js +5 -0
- package/cli/dist/deployer/build/compose.js +21 -8
- package/cli/dist/deployer/build/routes.js +128 -0
- package/cli/dist/deployer/deployer.js +15 -13
- package/cli/dist/deployer/runs/queue.js +7 -0
- package/cli/dist/deployer/runs/run.js +14 -7
- package/cli/dist/main.js +11 -3
- package/package.json +3 -1
- package/schema/app.json +64 -8
- package/scripts/agent/guard.sh +28 -6
- package/scripts/local/app-check.sh +12 -9
- package/scripts/local/app-manifests.sh +11 -6
- package/scripts/local/verify.sh +22 -11
- package/scripts/platform/compose-policy.sh +37 -40
- package/cli/dist/browser/assets/index-hcyM6f6T.js +0 -7
- package/compose/traefik/dynamic/ratelimit.yml +0 -21
- /package/cli/dist/clients/{api → wire}/contract.gen.js +0 -0
- /package/cli/dist/clients/{api → wire}/queries.js +0 -0
- /package/cli/dist/clients/{api → wire}/validate.js +0 -0
package/README.md
CHANGED
|
@@ -62,6 +62,7 @@ kayra deploy shop-prod # host setup + apps, no re-provision (from main only)
|
|
|
62
62
|
kayra status
|
|
63
63
|
kayra serve # the fleet in the browser
|
|
64
64
|
kayra serve --ui --api # browser and the local program API
|
|
65
|
+
kayra mcp # every command as a tool, for an agent (from .mcp.json)
|
|
65
66
|
```
|
|
66
67
|
|
|
67
68
|
## Documentation
|
|
@@ -73,6 +74,7 @@ kayra serve --ui --api # browser and the local program API
|
|
|
73
74
|
| [CI isolation](https://yunuseon.github.io/kayra/concepts/ci-isolation/) | why app code cannot reach the host or the platform |
|
|
74
75
|
| [Authentication](https://yunuseon.github.io/kayra/concepts/authentication/) | staff login (Authelia), adding people, recovery |
|
|
75
76
|
| [Local API](https://yunuseon.github.io/kayra/reference/api/) | program access, authentication, operations, runs and terminal sessions |
|
|
77
|
+
| [MCP](https://yunuseon.github.io/kayra/reference/mcp/) | every operation as a tool for an agent such as Claude Code, and what asks |
|
|
76
78
|
| [Upgrade to 0.17.0](https://yunuseon.github.io/kayra/reference/upgrading-0-17/) | replacing `kayra ui`, client changes and the fleet dependency bump |
|
|
77
79
|
| [`CLAUDE.md`](CLAUDE.md) | how everything fits together, and the rules that keep it working |
|
|
78
80
|
|
|
@@ -88,7 +88,8 @@ Things that have bitten before:
|
|
|
88
88
|
|
|
89
89
|
## 4. Report
|
|
90
90
|
|
|
91
|
-
Per server: the version it runs now
|
|
92
|
-
the
|
|
91
|
+
Per server: the version it runs now (`kayra status`'s `KAYRA` column, read
|
|
92
|
+
from the server: `1.2.2 → 1.2.3` is one the rollout has not reached), the
|
|
93
|
+
deploy's recap (nothing failed?), the `kayra verify` result, and anything left for the user (a DNS apply, a
|
|
93
94
|
switch in a vendor UI, a manual cleanup). Then whether the user's checkouts
|
|
94
95
|
are as they left them.
|
|
@@ -18,13 +18,16 @@
|
|
|
18
18
|
- "{{ server_dir }}/vars.yml"
|
|
19
19
|
- "{{ server_dir }}/secrets.yml"
|
|
20
20
|
|
|
21
|
+
vars:
|
|
22
|
+
kayra_dir: "{{ nas_root }}/.kayra"
|
|
23
|
+
|
|
21
24
|
pre_tasks:
|
|
22
25
|
- name: Write only inside nas_root
|
|
23
26
|
ansible.builtin.assert:
|
|
24
27
|
that: item is match('^' ~ nas_root ~ '/') and '/../' not in item ~ '/'
|
|
25
28
|
fail_msg: "{{ item }} lies outside {{ nas_root }}"
|
|
26
29
|
quiet: true
|
|
27
|
-
loop: "{{ [restic_backup.dir, compose_stacks.dir] }}"
|
|
30
|
+
loop: "{{ [restic_backup.dir, compose_stacks.dir, kayra_dir] }}"
|
|
28
31
|
|
|
29
32
|
# Docker creates a missing bind-mount source, a write wherever it points.
|
|
30
33
|
- name: Find the backed-up paths
|
|
@@ -45,3 +48,8 @@
|
|
|
45
48
|
roles:
|
|
46
49
|
- restic-backup
|
|
47
50
|
- compose-stacks
|
|
51
|
+
|
|
52
|
+
post_tasks:
|
|
53
|
+
- name: Record which kayra set this server up
|
|
54
|
+
ansible.builtin.import_role:
|
|
55
|
+
name: kayra-version
|
|
@@ -10,8 +10,9 @@
|
|
|
10
10
|
# The platform lives in /opt/platform and knows no app by name. Apps live in
|
|
11
11
|
# /opt/apps/<name> and register through /opt/platform/bin/app-apply.
|
|
12
12
|
#
|
|
13
|
-
# server, server_dir, domain and
|
|
14
|
-
# (git_token, webhook_secret, etc.) come from
|
|
13
|
+
# server, server_dir, domain, target and kayra_version are passed via -e.
|
|
14
|
+
# Platform vars (git_token, webhook_secret, etc.) come from
|
|
15
|
+
# servers/<server>/vars.yml.
|
|
15
16
|
#
|
|
16
17
|
# Usage: kayra setup <server>
|
|
17
18
|
# =============================================================================
|
|
@@ -52,6 +53,11 @@
|
|
|
52
53
|
when: forgejo_config is defined
|
|
53
54
|
|
|
54
55
|
post_tasks:
|
|
56
|
+
- name: Record which kayra set this server up
|
|
57
|
+
ansible.builtin.import_role:
|
|
58
|
+
name: kayra-version
|
|
59
|
+
become: true
|
|
60
|
+
|
|
55
61
|
- name: Show platform status
|
|
56
62
|
ansible.builtin.debug:
|
|
57
63
|
msg: |
|
|
@@ -54,23 +54,31 @@
|
|
|
54
54
|
- {name: app_secrets, suffix: .secrets.yml}
|
|
55
55
|
loop_control: {label: "{{ app.name }}{{ item.suffix }}"}
|
|
56
56
|
|
|
57
|
+
# An app's hosts are its routes' hosts; the routes themselves are read at
|
|
58
|
+
# each commit, by the builder.
|
|
59
|
+
- name: Read the app's hosts from its routes
|
|
60
|
+
ansible.builtin.set_fact:
|
|
61
|
+
app_subdomains: "{{ manifest.routes | default([]) | map(attribute='host') | unique | list }}"
|
|
62
|
+
|
|
57
63
|
- name: Check the app against the platform
|
|
58
64
|
ansible.builtin.assert:
|
|
59
65
|
that:
|
|
60
66
|
- manifest.name == app.name
|
|
67
|
+
- manifest.subdomains is not defined
|
|
61
68
|
- missing_secrets | length == 0
|
|
62
69
|
- missing_config | length == 0
|
|
63
70
|
- reserved_subdomains | length == 0
|
|
64
71
|
fail_msg: >-
|
|
65
72
|
{{ app.name }}: app.yml name={{ manifest.name }};
|
|
73
|
+
{{ 'subdomains is gone: declare routes instead (the app contract);' if manifest.subdomains is defined else '' }}
|
|
66
74
|
missing config {{ missing_config }} in servers/{{ server }}/apps/{{ app.name }}.yml,
|
|
67
75
|
missing secrets {{ missing_secrets }} in servers/{{ server }}/apps/{{ app.name }}.secrets.yml;
|
|
68
|
-
|
|
76
|
+
hosts reserved by the platform {{ reserved_subdomains }}
|
|
69
77
|
quiet: true
|
|
70
78
|
vars:
|
|
71
79
|
missing_secrets: "{{ manifest.secrets | default([]) | difference(app_secrets | default({}) | list) }}"
|
|
72
80
|
missing_config: "{{ manifest.config | default([]) | difference(app_config | default({}) | list) }}"
|
|
73
|
-
reserved_subdomains: "{{
|
|
81
|
+
reserved_subdomains: "{{ app_subdomains | intersect(lookup('file', kayra_root ~ '/hosts.conf').splitlines() | reject('match', '^\\s*(#|$)') | list) }}"
|
|
74
82
|
|
|
75
83
|
- name: Create app directory
|
|
76
84
|
ansible.builtin.file:
|
|
@@ -114,6 +122,6 @@
|
|
|
114
122
|
repo: "{{ app_repo }}"
|
|
115
123
|
ref: "{{ app_ref }}"
|
|
116
124
|
path: "{{ app.path | default('.') }}"
|
|
117
|
-
hosts: "{{
|
|
125
|
+
hosts: "{{ app_subdomains | map('regex_replace', '$', '.' ~ domain) | list }}"
|
|
118
126
|
secrets: "{{ manifest.secrets | default([]) }}"
|
|
119
127
|
become: true
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
---
|
|
2
|
+
# =============================================================================
|
|
3
|
+
# kayra-version role — which kayra set this server up, last in every host
|
|
4
|
+
# play, so only a setup that got this far records it. kayra passes its own
|
|
5
|
+
# version as kayra_version (-e); `kayra status` and `kayra verify` read it.
|
|
6
|
+
# =============================================================================
|
|
7
|
+
|
|
8
|
+
- name: Create kayra's directory
|
|
9
|
+
ansible.builtin.file:
|
|
10
|
+
path: "{{ kayra_dir }}"
|
|
11
|
+
state: directory
|
|
12
|
+
mode: "0755"
|
|
13
|
+
|
|
14
|
+
- name: Record which kayra set this server up
|
|
15
|
+
ansible.builtin.copy:
|
|
16
|
+
content: "{{ kayra_version }}\n"
|
|
17
|
+
dest: "{{ kayra_dir }}/version"
|
|
18
|
+
mode: "0644"
|
|
@@ -369,13 +369,15 @@
|
|
|
369
369
|
- bin/jenkins-app-apply
|
|
370
370
|
become: true
|
|
371
371
|
|
|
372
|
-
#
|
|
373
|
-
#
|
|
374
|
-
|
|
372
|
+
# Retired dynamic config; the copy above never deletes files. The registry
|
|
373
|
+
# used to have a public, basic-auth router, but nothing outside the server
|
|
374
|
+
# pushes or pulls. ratelimit.yml held one app's rate limit: routes declare
|
|
375
|
+
# their own now.
|
|
376
|
+
- name: Remove retired Traefik dynamic config
|
|
375
377
|
ansible.builtin.file:
|
|
376
378
|
path: "{{ platform_dir }}/traefik/dynamic/{{ item }}"
|
|
377
379
|
state: absent
|
|
378
|
-
loop: [registry-auth.yml, registry-htpasswd]
|
|
380
|
+
loop: [registry-auth.yml, registry-htpasswd, ratelimit.yml]
|
|
379
381
|
become: true
|
|
380
382
|
|
|
381
383
|
# ---------------------------------------------------------------------------
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h={},g=[],_=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,v=Array.isArray;function y(e,t){for(var n in t)e[n]=t[n];return e}function ee(e){e&&e.parentNode&&e.parentNode.removeChild(e)}function b(t,n,r){var i,a,o,s={};for(o in n)o==`key`?i=n[o]:o==`ref`?a=n[o]:s[o]=n[o];if(arguments.length>2&&(s.children=arguments.length>3?e.call(arguments,2):r),typeof t==`function`&&t.defaultProps!=null)for(o in t.defaultProps)s[o]===void 0&&(s[o]=t.defaultProps[o]);return x(t,s,i,a,null)}function x(e,r,i,a,o){var s={type:e,props:r,key:i,ref:a,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:o??++n,__i:-1,__u:0};return o==null&&t.vnode!=null&&t.vnode(s),s}function S(e){return e.children}function te(e,t){this.props=e,this.context=t}function C(e,t){if(t==null)return e.__?C(e.__,e.__i+1):null;for(var n;t<e.__k.length;t++)if((n=e.__k[t])!=null&&n.__e!=null)return n.__e;return typeof e.type==`function`?C(e):null}function w(e){if(e.__P&&e.__d){var n=e.__v,r=n.__e,i=[],a=[],o=y({},n);o.__v=n.__v+1,t.vnode&&t.vnode(o),ce(e.__P,o,n,e.__n,e.__P.namespaceURI,32&n.__u?[r]:null,i,r??C(n),!!(32&n.__u),a),o.__v=n.__v,o.__.__k[o.__i]=o,ue(i,o,a),n.__e=n.__=null,o.__e!=r&&T(o)}}function T(e){if((e=e.__)!=null&&e.__c!=null)return e.__e=e.__c.base=null,e.__k.some(function(t){if(t!=null&&t.__e!=null)return e.__e=e.__c.base=t.__e}),T(e)}function E(e){(!e.__d&&(e.__d=!0)&&i.push(e)&&!D.__r++||a!=t.debounceRendering)&&((a=t.debounceRendering)||o)(D)}function D(){try{for(var e,t=1;i.length;)i.length>t&&i.sort(s),e=i.shift(),t=i.length,w(e)}finally{i.length=D.__r=0}}function ne(e,t,n,r,i,a,o,s,c,l,u){var d,f,p,m,_,v,y=r&&r.__k||g,ee=t.length;for(c=re(n,t,y,c,ee),d=0;d<ee;d++)(p=n.__k[d])!=null&&(f=p.__i!=-1&&y[p.__i]||h,p.__i=d,v=ce(e,p,f,i,a,o,s,c,l,u),m=p.__e,p.ref&&f.ref!=p.ref&&(f.ref&&pe(f.ref,null,p),u.push(p.ref,p.__c||m,p)),_==null&&m!=null&&(_=m),4&p.__u?(c=ie(p,c,e),f.__e&&(f.__e=null)):typeof p.type==`function`&&v!==void 0?c=v:m&&(c=m.nextSibling),p.__u&=-7);return n.__e=_,c}function re(e,t,n,r,i){var a,o,s,c,l,u=n.length,d=u,f=0;for(e.__k=Array(i),a=0;a<i;a++)(o=t[a])!=null&&typeof o!=`boolean`&&typeof o!=`function`?(typeof o==`string`||typeof o==`number`||typeof o==`bigint`||o.constructor==String?o=e.__k[a]=x(null,o,null,null,null):v(o)?o=e.__k[a]=x(S,{children:o},null,null,null):o.constructor===void 0&&o.__b>0?o=e.__k[a]=x(o.type,o.props,o.key,o.ref?o.ref:null,o.__v):e.__k[a]=o,c=a+f,o.__=e,o.__b=e.__b+1,s=null,(l=o.__i=ae(o,n,c,d))!=-1&&(d--,(s=n[l])&&(s.__u|=2)),s==null||s.__v==null?(l==-1&&(i>u?f--:i<u&&f++),typeof o.type!=`function`&&(o.__u|=4)):l!=c&&(l==c-1?f--:l==c+1?f++:(l>c?f--:f++,o.__u|=4))):e.__k[a]=null;if(d)for(a=0;a<u;a++)(s=n[a])!=null&&!(2&s.__u)&&(s.__e==r&&(r=C(s)),me(s,s));return r}function ie(e,t,n){var r,i;if(typeof e.type==`function`){for(r=e.__k,i=0;r&&i<r.length;i++)r[i]&&(r[i].__=e,t=ie(r[i],t,n));return t}e.__e!=t&&(t&&e.type&&!t.parentNode&&(t=C(e)),t=n.insertBefore(e.__e,t||null));do t&&=t.nextSibling;while(t!=null&&t.nodeType==8);return t}function ae(e,t,n,r){var i,a,o,s=e.key,c=e.type,l=t[n],u=l!=null&&!(2&l.__u);if(l===null&&s==null||u&&s==l.key&&c==l.type)return n;if(r>+!!u){for(i=n-1,a=n+1;i>=0||a<t.length;)if((l=t[o=i>=0?i--:a++])!=null&&!(2&l.__u)&&s==l.key&&c==l.type)return o}return-1}function oe(e,t,n){t[0]==`-`?e.setProperty(t,n??``):e[t]=n==null?``:typeof n!=`number`||_.test(t)?n:n+`px`}function O(e,t,n,r,i){var a,o;n:if(t==`style`){if(typeof n==`string`)e.style.cssText=n;else{if(typeof r==`string`&&(e.style.cssText=r=``),r)for(t in r)n&&t in n||oe(e.style,t,``);if(n)for(t in n)r&&n[t]==r[t]||oe(e.style,t,n[t])}}else if(t[0]==`o`&&t[1]==`n`)a=t!=(t=t.replace(d,`$1`)),o=t.toLowerCase(),t=o in e||t==`onFocusOut`||t==`onFocusIn`?o.slice(2):t.slice(2),e.l||={},e.l[t+a]=n,n?r?n[u]=r[u]:(n[u]=f,e.addEventListener(t,a?m:p,a)):e.removeEventListener(t,a?m:p,a);else{if(i==`http://www.w3.org/2000/svg`)t=t.replace(/xlink(H|:h)/,`h`).replace(/sName$/,`s`);else if(t!=`width`&&t!=`height`&&t!=`href`&&t!=`list`&&t!=`form`&&t!=`tabIndex`&&t!=`download`&&t!=`rowSpan`&&t!=`colSpan`&&t!=`role`&&t!=`popover`&&t in e)try{e[t]=n??``;break n}catch{}typeof n==`function`||(n==null||!1===n&&t[4]!=`-`?e.removeAttribute(t):e.setAttribute(t,t==`popover`&&n==1?``:n))}}function se(e){return function(n){if(this.l){var r=this.l[n.type+e];if(n[l]==null)n[l]=f++;else if(n[l]<r[u])return;return r(t.event?t.event(n):n)}}}function ce(e,n,r,i,a,o,s,c,l,u){var d,f,p,m,h,_,b,x,w,T,E,D,re,ie,ae,oe,O=n.type;if(n.constructor!==void 0)return null;128&r.__u&&(l=!!(32&r.__u),o=[c=n.__e=r.__e]),(d=t.__b)&&d(n);n:if(typeof O==`function`){f=s.length;try{if(w=n.props,T=O.prototype&&O.prototype.render,E=(d=O.contextType)&&i[d.__c],D=d?E?E.props.value:d.__:i,r.__c?x=(p=n.__c=r.__c).__=p.__E:(T?n.__c=p=new O(w,D):(n.__c=p=new te(w,D),p.constructor=O,p.render=he),E&&E.sub(p),p.state||(p.state={}),p.__n=i,m=p.__d=!0,p.__h=[],p._sb=[]),T&&p.__s==null&&(p.__s=p.state),T&&O.getDerivedStateFromProps!=null&&(p.__s==p.state&&(p.__s=y({},p.__s)),y(p.__s,O.getDerivedStateFromProps(w,p.__s))),h=p.props,_=p.state,p.__v=n,m)T&&O.getDerivedStateFromProps==null&&p.componentWillMount!=null&&p.componentWillMount(),T&&p.componentDidMount!=null&&p.__h.push(p.componentDidMount);else{if(T&&O.getDerivedStateFromProps==null&&w!==h&&p.componentWillReceiveProps!=null&&p.componentWillReceiveProps(w,D),n.__v==r.__v||!p.__e&&p.shouldComponentUpdate!=null&&!1===p.shouldComponentUpdate(w,p.__s,D)){n.__v!=r.__v&&(p.props=w,p.state=p.__s,p.__d=!1),n.__e=r.__e,n.__k=r.__k,n.__k.some(function(e){e&&(e.__=n)}),g.push.apply(p.__h,p._sb),p._sb=[],p.__h.length&&s.push(p),c=C(r);break n}p.componentWillUpdate!=null&&p.componentWillUpdate(w,p.__s,D),T&&p.componentDidUpdate!=null&&p.__h.push(function(){p.componentDidUpdate(h,_,b)})}if(p.context=D,p.props=w,p.__P=e,p.__e=!1,re=t.__r,ie=0,T)p.state=p.__s,p.__d=!1,re&&re(n),d=p.render(p.props,p.state,p.context),g.push.apply(p.__h,p._sb),p._sb=[];else do p.__d=!1,re&&re(n),d=p.render(p.props,p.state,p.context),p.state=p.__s;while(p.__d&&++ie<25);p.state=p.__s,p.getChildContext!=null&&(i=y(y({},i),p.getChildContext())),T&&!m&&p.getSnapshotBeforeUpdate!=null&&(b=p.getSnapshotBeforeUpdate(h,_)),ae=d!=null&&d.type===S&&d.key==null?de(d.props.children):d,c=ne(e,v(ae)?ae:[ae],n,r,i,a,o,s,c,l,u),p.base=n.__e,n.__u&=-161,p.__h.length&&s.push(p),x&&(p.__E=p.__=null)}catch(e){if(s.length=f,n.__v=null,l||o!=null){if(e.then){for(n.__u|=l?160:128;c&&c.nodeType==8&&c.nextSibling;)c=c.nextSibling;o!=null&&(o[o.indexOf(c)]=null),n.__e=c}else if(o!=null)for(oe=o.length;oe--;)ee(o[oe])}else n.__e=r.__e;n.__k??=r.__k||[],e.then||le(n),t.__e(e,n,r)}}else o==null&&n.__v==r.__v?(n.__k=r.__k,n.__e=r.__e):c=n.__e=fe(r.__e,n,r,i,a,o,s,l,u);return(d=t.diffed)&&d(n),128&n.__u?void 0:c}function le(e){e&&(e.__c&&(e.__c.__e=!0),e.__k&&e.__k.some(le))}function ue(e,n,r){for(var i=0;i<r.length;i++)pe(r[i],r[++i],r[++i]);t.__c&&t.__c(n,e),e.some(function(n){try{e=n.__h,n.__h=[],e.some(function(e){e.call(n)})}catch(e){t.__e(e,n.__v)}})}function de(e){return typeof e!=`object`||!e||e.__b>0?e:v(e)?e.map(de):e.constructor===void 0?y({},e):null}function fe(n,r,i,a,o,s,c,l,u){var d,f,p,m,g,_,y,b=i.props||h,x=r.props,S=r.type;if(S==`svg`?o=`http://www.w3.org/2000/svg`:S==`math`?o=`http://www.w3.org/1998/Math/MathML`:o||=`http://www.w3.org/1999/xhtml`,s!=null){for(d=0;d<s.length;d++)if((g=s[d])&&`setAttribute`in g==!!S&&(S?g.localName==S:g.nodeType==3)){n=g,s[d]=null;break}}if(n==null){if(S==null)return document.createTextNode(x);n=document.createElementNS(o,S,x.is&&x),l&&=(t.__m&&t.__m(r,s),!1),s=null}if(S==null)b===x||l&&n.data==x||(n.data=x);else{if(s=S==`textarea`&&x.defaultValue!=null?null:s&&e.call(n.childNodes),!l&&s!=null)for(b={},d=0;d<n.attributes.length;d++)b[(g=n.attributes[d]).name]=g.value;for(d in b)g=b[d],d==`dangerouslySetInnerHTML`?p=g:d==`children`||d in x||d==`value`&&`defaultValue`in x||d==`checked`&&`defaultChecked`in x||O(n,d,null,g,o);for(d in x)g=x[d],d==`children`?m=g:d==`dangerouslySetInnerHTML`?f=g:d==`value`?_=g:d==`checked`?y=g:l&&typeof g!=`function`||b[d]===g||O(n,d,g,b[d],o);if(f)l||p&&(f.__html==p.__html||f.__html==n.innerHTML)||(n.innerHTML=f.__html),r.__k=[];else if(p&&(n.innerHTML=``),ne(r.type==`template`?n.content:n,v(m)?m:[m],r,i,a,S==`foreignObject`?`http://www.w3.org/1999/xhtml`:o,s,c,s?s[0]:i.__k&&C(i,0),l,u),s!=null)for(d=s.length;d--;)ee(s[d]);l&&S!=`textarea`||(d=`value`,S==`progress`&&_==null?n.removeAttribute(`value`):_!=null&&(_!==n[d]||S==`progress`&&!_||S==`option`&&_!=b[d])&&O(n,d,_,b[d],o),d=`checked`,y!=null&&y!=n[d]&&O(n,d,y,b[d],o))}return n}function pe(e,n,r){try{if(typeof e==`function`){var i=typeof e.__u==`function`;i&&e.__u(),i&&n==null||(e.__u=e(n))}else e.current=n}catch(e){t.__e(e,r)}}function me(e,n,r){var i,a;if(t.unmount&&t.unmount(e),(i=e.ref)&&(i.current&&i.current!=e.__e||pe(i,null,n)),(i=e.__c)!=null){if(i.componentWillUnmount)try{i.componentWillUnmount()}catch(e){t.__e(e,n)}i.base=i.__P=i.__n=null}if(i=e.__k)for(a=0;a<i.length;a++)i[a]&&me(i[a],n,r||typeof e.type!=`function`);r||ee(e.__e),e.__c=e.__=e.__e=void 0}function he(e,t,n){return this.constructor(e,n)}function ge(n,r,i){var a,o,s,c;r==document&&(r=document.documentElement),t.__&&t.__(n,r),o=(a=typeof i==`function`)?null:i&&i.__k||r.__k,s=[],c=[],ce(r,n=(!a&&i||r).__k=b(S,null,[n]),o||h,h,r.namespaceURI,!a&&i?[i]:o?null:r.firstChild?e.call(r.childNodes):null,s,!a&&i?i:o?o.__e:r.firstChild,a,c),ue(s,n,c),n.props.children=null}e=g.slice,t={__e:function(e,t,n,r){for(var i,a,o;t=t.__;)if((i=t.__c)&&!i.__)try{if((a=i.constructor)&&a.getDerivedStateFromError!=null&&(i.setState(a.getDerivedStateFromError(e)),o=i.__d),i.componentDidCatch!=null&&(i.componentDidCatch(e,r||{}),o=i.__d),o)return i.__E=i}catch(t){e=t}throw e}},n=0,r=function(e){return e!=null&&e.constructor===void 0},te.prototype.setState=function(e,t){var n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=y({},this.state);typeof e==`function`&&(e=e(y({},n),this.props)),e&&y(n,e),e!=null&&this.__v&&(t&&this._sb.push(t),E(this))},te.prototype.forceUpdate=function(e){this.__v&&(this.__e=!0,e&&this.__h.push(e),E(this))},te.prototype.render=S,i=[],o=typeof Promise==`function`?Promise.prototype.then.bind(Promise.resolve()):setTimeout,s=function(e,t){return e.__v.__b-t.__v.__b},D.__r=0,c=Math.random().toString(8),l=`__d`+c,u=`__a`+c,d=/(PointerCapture)$|Capture$/i,f=0,p=se(!1),m=se(!0);var _e,k,ve,ye,be=0,xe=[],A=t,Se=A.__b,Ce=A.__r,we=A.diffed,Te=A.__c,Ee=A.unmount,De=A.__;function Oe(e,t){A.__h&&A.__h(k,e,be||t),be=0;var n=k.__H||(k.__H={__:[],__h:[]});return e>=n.__.length&&n.__.push({}),n.__[e]}function j(e){return be=1,ke(Re,e)}function ke(e,t,n){var r=Oe(_e++,2);if(r.t=e,!r.__c&&(r.__=[n?n(t):Re(void 0,t),function(e){var t=r.__N?r.__N[0]:r.__[0],n=r.t(t,e);t!==n&&(r.__N=[n,r.__[1]],r.__c.setState({}))}],r.__c=k,!k.__f)){var i=function(e,t,n){if(!r.__c.__H)return!0;var i=!1,o=r.__c.props!==e;if(r.__c.__H.__.some(function(e){if(e.__N){i=!0;var t=e.__[0];e.__=e.__N,e.__N=void 0,t!==e.__[0]&&(o=!0)}}),a){var s=a.call(this,e,t,n);return i?s||o:s}return!i||o};k.__f=!0;var a=k.shouldComponentUpdate,o=k.componentWillUpdate;k.componentWillUpdate=function(e,t,n){if(this.__e){var r=a;a=void 0,i(e,t,n),a=r}o&&o.call(this,e,t,n)},k.shouldComponentUpdate=i}return r.__N||r.__}function M(e,t){var n=Oe(_e++,3);!A.__s&&Le(n.__H,t)&&(n.__=e,n.u=t,k.__H.__h.push(n))}function Ae(e){return be=5,je(function(){return{current:e}},[])}function je(e,t){var n=Oe(_e++,7);return Le(n.__H,t)&&(n.__=e(),n.__H=t,n.__h=e),n.__}function Me(){for(var e;e=xe.shift();){var t=e.__H;if(e.__P&&t)try{t.__h.some(Fe),t.__h.some(Ie),t.__h=[]}catch(n){t.__h=[],A.__e(n,e.__v)}}}A.__b=function(e){k=null,Se&&Se(e)},A.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),De&&De(e,t)},A.__r=function(e){Ce&&Ce(e),_e=0;var t=(k=e.__c).__H;t&&(ve===k?(t.__h=[],k.__h=[],t.__.some(function(e){e.__N&&(e.__=e.__N),e.u=e.__N=void 0})):(t.__h.some(Fe),t.__h.some(Ie),t.__h=[],_e=0)),ve=k},A.diffed=function(e){we&&we(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&(xe.push(t)!==1&&ye===A.requestAnimationFrame||((ye=A.requestAnimationFrame)||Pe)(Me)),t.__H.__.some(function(e){e.u&&=(e.__H=e.u,void 0)})),ve=k=null},A.__c=function(e,t){t.some(function(e){try{e.__h.some(Fe),e.__h=e.__h.filter(function(e){return!e.__||Ie(e)})}catch(n){t.some(function(e){e.__h&&=[]}),t=[],A.__e(n,e.__v)}}),Te&&Te(e,t)},A.unmount=function(e){Ee&&Ee(e);var t,n=e.__c;n&&n.__H&&(n.__H.__.some(function(e){try{Fe(e)}catch(e){t=e}}),n.__H=void 0,t&&A.__e(t,n.__v))};var Ne=typeof requestAnimationFrame==`function`;function Pe(e){var t,n=function(){clearTimeout(r),Ne&&cancelAnimationFrame(t),setTimeout(e)},r=setTimeout(n,35);Ne&&(t=requestAnimationFrame(n))}function Fe(e){var t=k,n=e.__c;typeof n==`function`&&(e.__c=void 0,n()),k=t}function Ie(e){var t=k;e.__c=e.__(),k=t}function Le(e,t){return!e||e.length!==t.length||t.some(function(t,n){return t!==e[n]})}function Re(e,t){return typeof t==`function`?t(e):t}var ze=Symbol.for(`preact-signals`);function Be(){if(P>1)P--;else{var e,t=!1;for((function(){var e=Je;for(Je=void 0;e!==void 0;){var t=e.S;if(t.v===e.v)for(var n=t.t;n!==void 0;n=n.x)n.i===e.i&&(n.i=t.i);e=e.o}})();We!==void 0;){var n=We;for(We=void 0,Ge++;n!==void 0;){var r=n.u;if(n.u=void 0,n.f&=-3,!(8&n.f)&&Ze(n))try{n.c()}catch(n){t||=(e=n,!0)}n=r}}if(Ge=0,P--,t)throw e}}function Ve(e){if(P>0)return e();qe=++Ke,P++;try{return e()}finally{Be()}}var He,N=void 0;function Ue(e){var t=N,n=He;N=void 0,He=void 0;try{return e()}finally{N=t,He=n}}var We=void 0,P=0,Ge=0,Ke=0,qe=0,Je=void 0,Ye=0;function Xe(e){if(N!==void 0){var t=e.n;if(t===void 0||t.t!==N)return t={i:0,S:e,p:N.s,n:void 0,t:N,e:void 0,x:void 0,r:t},N.s!==void 0&&(N.s.n=t),N.s=t,e.n=t,32&N.f&&e.S(t),t;if(t.i===-1)return t.i=0,t.n!==void 0&&(t.n.p=t.p,t.p!==void 0&&(t.p.n=t.n),t.p=N.s,t.n=void 0,N.s.n=t,N.s=t),t}}function F(e,t){this.v=e,this.i=0,this.n=void 0,this.t=void 0,this.l=0,this.W=t?.watched,this.Z=t?.unwatched,this.name=t?.name}F.prototype.brand=ze,F.prototype.h=function(){return!0},F.prototype.S=function(e){var t=this,n=this.t;n!==e&&e.e===void 0&&(e.x=n,this.t=e,n===void 0?Ue(function(){var e;(e=t.W)==null||e.call(t)}):n.e=e)},F.prototype.U=function(e){var t=this;if(this.t!==void 0){var n=e.e,r=e.x;n!==void 0&&(n.x=r,e.e=void 0),r!==void 0&&(r.e=n,e.x=void 0),e===this.t&&(this.t=r,r===void 0&&Ue(function(){var e;(e=t.Z)==null||e.call(t)}))}},F.prototype.subscribe=function(e){var t=this;return it(function(){var n=t.value;Ue(function(){return e(n)})},{name:`sub`})},F.prototype.valueOf=function(){return this.value},F.prototype.toString=function(){return this.value+``},F.prototype.toJSON=function(){return this.value},F.prototype.peek=function(){var e=this;return Ue(function(){return e.value})},Object.defineProperty(F.prototype,"value",{get:function(){var e=Xe(this);return e!==void 0&&(e.i=this.i),this.v},set:function(e){if(e!==this.v){if(Ge>100)throw Error(`Cycle detected`);(function(e){P!==0&&Ge===0&&e.l!==qe&&(e.l=qe,Je={S:e,v:e.v,i:e.i,o:Je})})(this),this.v=e,this.i++,Ye++,P++;try{for(var t=this.t;t!==void 0;t=t.x)t.t.N()}finally{Be()}}}});function I(e,t){return new F(e,t)}function Ze(e){for(var t=e.s;t!==void 0;t=t.n)if(t.S.i!==t.i||!t.S.h()||t.S.i!==t.i)return!0;return!1}function Qe(e){for(var t=e.s;t!==void 0;t=t.n){var n=t.S.n;if(n!==void 0&&(t.r=n),t.S.n=t,t.i=-1,t.n===void 0){e.s=t;break}}}function $e(e){for(var t=e.s,n=void 0;t!==void 0;){var r=t.p;t.i===-1?(t.S.U(t),r!==void 0&&(r.n=t.n),t.n!==void 0&&(t.n.p=r)):n=t,t.S.n=t.r,t.r!==void 0&&(t.r=void 0),t=r}e.s=n}function L(e,t){F.call(this,void 0,t),this.x=e,this.s=void 0,this.g=Ye-1,this.f=4}L.prototype=new F,L.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===Ye))return!0;if(this.g=Ye,this.f|=1,this.i>0&&!Ze(this))return this.f&=-2,!0;var e=N;try{Qe(this),N=this;var t=this.x();(16&this.f||this.v!==t||this.i===0)&&(this.v=t,this.f&=-17,this.i++)}catch(e){this.v=e,this.f|=16,this.i++}return N=e,$e(this),this.f&=-2,!0},L.prototype.S=function(e){if(this.t===void 0){this.f|=36;for(var t=this.s;t!==void 0;t=t.n)t.S.S(t)}F.prototype.S.call(this,e)},L.prototype.U=function(e){if(this.t!==void 0&&(F.prototype.U.call(this,e),this.t===void 0)){this.f&=-33;for(var t=this.s;t!==void 0;t=t.n)t.S.U(t)}},L.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var e=this.t;e!==void 0;e=e.x)e.t.N()}},Object.defineProperty(L.prototype,"value",{get:function(){if(1&this.f)throw Error(`Cycle detected`);var e=Xe(this);if(this.h(),e!==void 0&&(e.i=this.i),16&this.f)throw this.v;return this.v}});function et(e,t){return new L(e,t)}function tt(e){var t=e.m;if(e.m=void 0,typeof t==`function`){P++;var n=N;N=void 0;try{t()}catch(t){throw e.f&=-2,e.f|=8,nt(e),t}finally{N=n,Be()}}}function nt(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,tt(e)}function rt(e){if(N!==this)throw Error(`Out-of-order effect`);$e(this),N=e,this.f&=-2,8&this.f&&nt(this),Be()}function R(e,t){this.x=e,this.m=void 0,this.s=void 0,this.u=void 0,this.f=32,this.name=t?.name,He&&He.push(this)}R.prototype.c=function(){var e=this.S();try{if(8&this.f||this.x===void 0)return;var t=this.x();typeof t==`function`&&(this.m=t)}finally{e()}},R.prototype.S=function(){if(1&this.f)throw Error(`Cycle detected`);this.f|=1,this.f&=-9,tt(this),Qe(this),P++;var e=N;return N=this,rt.bind(this,e)},R.prototype.N=function(){2&this.f||(this.f|=2,this.u=We,We=this)},R.prototype.d=function(){this.f|=8,1&this.f||nt(this)},R.prototype.dispose=function(){this.d()};function it(e,t){var n=new R(e,t);try{n.c()}catch(e){throw n.d(),e}var r=n.d.bind(n);return r[Symbol.dispose]=r,r}var at,ot,st=typeof window<`u`&&!!window.__PREACT_SIGNALS_DEVTOOLS__,ct=[];it(function(){at=this.N})();function z(e,n){t[e]=n.bind(null,t[e]||function(){})}function lt(e){if(ot){var t=ot;ot=void 0,t()}ot=e&&e.S()}function ut(e){var t=this,n=e.data,i=ft(n);i.name=`ReactiveDom`,i.value=n;var a=je(function(){for(var e=t,n=t.__v;n=n.__;)if(n.__c){n.__c.__$f|=4;break}var a=et(function(){var e=i.value.value;return e===0?0:!0===e?``:e||``}),o=et(function(){return!Array.isArray(a.value)&&!r(a.value)}),s=it(function(){if(this.N=ht,o.value){var t=a.value;e.__v&&e.__v.__e&&e.__v.__e.nodeType===3&&(e.__v.__e.data=t)}}),c=t.__$u.d;return t.__$u.d=function(){s(),c.call(this)},[o,a]},[]),o=a[0],s=a[1];return o.value?s.peek():s.value}ut.displayName=`ReactiveTextNode`,Object.defineProperties(F.prototype,{constructor:{configurable:!0,value:void 0},type:{configurable:!0,value:ut},props:{configurable:!0,get:function(){var e=this;return{data:{get value(){return e.value}}}}},__b:{configurable:!0,value:1}}),z(`__b`,function(e,t){if(lt(),typeof t.type==`string`){var n,r=t.props;for(var i in r)if(i!==`children`){var a=r[i];a instanceof F&&(n||(t.__np=n={}),n[i]=a,r[i]=a.peek())}}e(t)}),z(`__r`,function(e,t){if(e(t),t.type!==S){lt();var n,r=t.__c;r&&(r.__$f&=-2,(n=r.__$u)===void 0&&(r.__$u=n=function(e,t){var n;return it(function(){n=this},{name:t}),n.c=e,n}(function(e){return function(){var t;st&&((t=this.y)==null||t.call(this)),e.__$f|=1,e.setState({})}}(r),typeof t.type==`function`?t.type.displayName||t.type.name:``))),lt(n)}}),z(`__e`,function(e,t,n,r){lt(),e(t,n,r)}),z(`diffed`,function(e,t){lt();var n;if(typeof t.type==`string`&&(n=t.__e)){var r=t.__np,i=t.props,a=n.U;if(a)for(var o in a){var s=a[o];s===void 0||r&&o in r||(s.d(),a[o]=void 0)}if(r)for(var c in a||(a={},n.U=a),r){var l=a[c],u=r[c];l===void 0?(l=dt(n,c,u,i),a[c]=l):l.o(u,i)}}e(t)});function dt(e,t,n,r){var i=t in e&&e.ownerSVGElement===void 0,a=I(n);return{o:function(e,t){a.value=e,r=t},d:it(function(){this.N=ht;var n=a.value.value;r[t]!==n&&(r[t]=n,i?e[t]=n:n!=null&&(!1!==n||t[4]===`-`)?e.setAttribute(t,n):e.removeAttribute(t))})}}z(`unmount`,function(e,t){if(typeof t.type==`string`){var n=t.__e;if(n){var r=n.U;if(r)for(var i in n.U=void 0,r){var a=r[i];a&&a.d()}}var o=t.__np;if(o){var s=t.props;for(var c in o)s[c]=o[c]}t.__np=void 0}else{var l=t.__c;if(l){l.__$f|=8;var u=l.__$u;u&&(l.__$u=void 0,u.d())}}e(t)}),z(`__h`,function(e,t,n,r){r<3&&(t.__$f|=2),e(t,n,r)}),te.prototype.shouldComponentUpdate=function(e,t){if(this.__R)return!0;var n=this.__$u,r=n&&n.s!==void 0;for(var i in t)return!0;if(this.__f||typeof this.u==`boolean`&&!0===this.u){var a=2&this.__$f;if(!(r||a||4&this.__$f)||1&this.__$f)return!0}else if(!(r||4&this.__$f)||3&this.__$f)return!0;for(var o in e)if(o!==`__source`&&e[o]!==this.props[o])return!0;for(var s in this.props)if(!(s in e))return!0;return!1};function ft(e,t){return je(function(){return I(e,t)},[])}var pt=function(e){queueMicrotask(function(){queueMicrotask(e)})};function mt(){Ve(function(){for(var e;e=ct.shift();)at.call(e)})}function ht(){ct.push(this)===1&&(t.requestAnimationFrame||pt)(mt)}var B=e=>e,gt={up:{label:`Up`,icon:`↑`},provision:{label:`Provision`,icon:`+`},deploy:{label:`Deploy`,icon:`↑`},setup:{label:`Setup`,icon:`⚙`},plan:{label:`Plan`,icon:`≡`},verify:{label:`Verify`,icon:`✓`},apps:{label:`Register apps`,icon:`▦`},hosts:{label:`Local hosts`,icon:`⌂`},ssh:{label:`SSH terminal`,icon:`>_`},"ssh.exec":{label:`SSH command`,icon:`>`},down:{label:`Destroy`,icon:`×`},adopt:{label:`Adopt`,icon:`+`},"backup.test":{label:`Test backup`,icon:`✓`},"app.check":{label:`Check app repository`,icon:`✓`},"app.purge":{label:`Purge app data`,icon:`×`},"app.runs":{label:`App runs`,icon:`≡`},"app.log":{label:`App log`,icon:`≡`},"app.deploy":{label:`Deploy app`,icon:`↑`},"app.releases":{label:`App releases`,icon:`≡`},"app.rollback":{label:`Roll back app`,icon:`↶`},job:{label:`Run job`,icon:`▶`},status:{label:`Status`,icon:`●`},validate:{label:`Validate`,icon:`✓`},doctor:{label:`Doctor`,icon:`✓`},certs:{label:`Local certificates`,icon:`◇`},version:{label:`Version`,icon:`i`}},_t=e=>typeof e==`object`&&!!e&&!Array.isArray(e),vt=e=>_t(e)?e:B({}),yt=e=>Array.isArray(e)?e.filter(e=>typeof e==`string`):B([]),bt=e=>Object.freeze(Object.entries(vt(e.properties)).map(([t,n])=>{let r=vt(n);return{name:t,type:r.type,required:yt(e.required).includes(t),description:typeof r.description==`string`?r.description:``,choices:yt(r.enum),default:r.default,minLength:typeof r.minLength==`number`?r.minLength:void 0,pattern:typeof r.pattern==`string`?r.pattern:void 0,supported:r.type===`string`||r.type===`boolean`||r.type===`array`&&vt(r.items).type===`string`}})),xt=e=>typeof e==`boolean`||typeof e==`string`?e:Array.isArray(e)?yt(e).join(`
|
|
2
|
+
`):B(``),St=(e,t)=>Object.freeze(Object.fromEntries(bt(e).map(e=>[e.name,xt(t[e.name]??e.default)]))),Ct=(e,t)=>Object.freeze(Object.fromEntries(bt(e).flatMap(e=>{let n=t[e.name];return e.type===`boolean`?B([[e.name,n===!0]]):B(typeof n!=`string`||n===``?[]:[[e.name,e.type===`array`?n.split(/\r?\n/):n]])}))),wt=(e,t)=>Object.freeze(e.filter(e=>e.scope===`app`&&t.kind===`platform`||e.scope===`server`&&(t.commands.some(t=>t===e.name)||e.name===`ssh`||e.name===`ssh.exec`||e.name===`hosts`&&t.target===`multipass`))),Tt=(e,t)=>{let n=t.toLowerCase().replace(/\s+/g,``);if(n===``)return B(0);let r=e.toLowerCase(),i=Array.from(n).reduce((e,t)=>{if(e===void 0)return;let n=r.indexOf(t,e.at);return n===-1?void 0:{at:n+1,gaps:e.gaps+(e.first===-1?0:n-e.at),first:e.first===-1?n:e.first}},{at:0,gaps:0,first:-1});return i===void 0?void 0:i.gaps*2+i.first+(r.startsWith(n)?-10:0)},Et=(e,t)=>Object.freeze(e.flatMap(e=>{let n=Tt(`${e.label} ${e.hint}`,t);return Object.freeze(n===void 0?[]:[{choice:e,scored:n}])}).toSorted((e,t)=>e.scored-t.scored).map(e=>e.choice)),Dt=e=>e,Ot=async(e,t)=>e.ok?B({ok:!0,value:Dt(await t(e))}):B({ok:!1,failure:{status:e.status,message:(await e.text()).trim()}}),kt=async e=>{try{return await e()}catch{return B({ok:!1,failure:{status:0,message:`Cannot reach kayra. Check that kayra serve is still running.`}})}},At=e=>kt(()=>fetch(e).then(e=>Ot(e,e=>e.json()))),V=(e,t)=>kt(async()=>Ot(await fetch(e,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)}),async e=>e.status===204?void 0:e.json())),jt=(e,t)=>V(`/api/operations/${e.name}/preview`,{input:e.input,options:t}),Mt=(e,t,n)=>V(`/api/operations/${e.name}`,{input:e.input,options:t,...n===void 0?{}:{confirm:n}}),Nt=(e,t={})=>V(`/api/operations/${e}`,{input:t}),Pt=(e,t)=>V(`/api/runs/${encodeURIComponent(e)}/answers`,{text:t}),Ft=e=>V(`/api/runs/${encodeURIComponent(e)}/cancel`,{}),It=(e,t)=>V(`/api/sessions/${encodeURIComponent(e)}/input`,{text:t}),Lt=e=>kt(async()=>Ot(await fetch(`/api/sessions/${encodeURIComponent(e)}`,{method:`DELETE`}),()=>Promise.resolve(void 0))),Rt=()=>At(`/api/runs`),zt=(e,t,n,r,i)=>{let a=new AbortController;return(async()=>{let n=await fetch(e,{signal:a.signal,...r===void 0?{}:{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(r)}});if(!n.ok){i?.({status:n.status,message:(await n.text()).trim()});return}if(n.body===null)throw Error(`No stream`);let o=n.body.getReader(),s=new TextDecoder,c={text:``},l=async()=>{let e=await o.read();if(e.done)return;let n=(c.text+s.decode(e.value,{stream:!0})).split(`
|
|
3
|
+
|
|
4
|
+
`);c.text=n.pop()??``,n.forEach(e=>{e.startsWith(`data: `)&&t(Dt(JSON.parse(e.slice(6))))}),await l()};await l()})().catch(()=>{a.signal.aborted||i?.({status:0,message:`The connection to kayra was interrupted.`})}).finally(n),()=>{a.abort()}},Bt=/^[A-Za-z0-9._-]+$/,Vt=e=>{let t=e.split(`/`).filter(e=>e!==``).map(decodeURIComponent);if(!t.every(e=>Bt.test(e)))return B({page:`missing`,path:e});let[n,r,i,a]=t;return n===void 0?B({page:`fleet`}):n===`runs`&&r===void 0?B({page:`runs`}):n===`runs`&&r!==void 0&&i===void 0?B({page:`run`,id:r}):n===`sessions`&&r!==void 0&&i===void 0?B({page:`session`,id:r}):n===`validate`&&r===void 0?B({page:`validate`}):n===`servers`&&r!==void 0&&i===void 0?B({page:`server`,server:r}):n===`servers`&&r!==void 0&&i===`apps`&&a!==void 0&&t.length===4?B({page:`app`,server:r,app:a}):B({page:`missing`,path:e})},Ht=e=>{switch(e.page){case`fleet`:return`/`;case`server`:return`/servers/${encodeURIComponent(e.server)}`;case`app`:return`/servers/${encodeURIComponent(e.server)}/apps/${encodeURIComponent(e.app)}`;case`runs`:return`/runs`;case`run`:return`/runs/${encodeURIComponent(e.id)}`;case`session`:return`/sessions/${encodeURIComponent(e.id)}`;case`validate`:return`/validate`;case`missing`:return e.path}},Ut=I(Vt(location.pathname)),Wt=e=>{history.pushState(null,``,Ht(e)),Ut.value=e,scrollTo({top:0})};addEventListener(`popstate`,()=>{Ut.value=Vt(location.pathname)});var H=I({state:`loading`}),Gt=I({state:`loading`}),Kt=async()=>{let e=await At(`/api/operations`);Gt.value=e.ok?{state:`ready`,value:e.value}:{state:`failed`,failure:e.failure}},U=I({value:void 0,live:!1}),qt=I({state:`loading`}),Jt=async()=>{let e=await At(`/api/fleet`);H.value=e.ok?{state:`ready`,value:e.value}:{state:`failed`,failure:e.failure}},Yt=()=>{U.value={value:U.value.value,live:!0},zt(`/api/operations/status`,e=>{U.value={value:e,live:!0}},()=>{U.value={value:U.value.value,live:!1}},{input:{}})},Xt=async()=>{qt.value={state:`loading`};let e=await Nt(`validate`);qt.value=e.ok?{state:`ready`,value:e.value}:{state:`failed`,failure:e.failure}},Zt=0;Array.isArray;function W(e,n,r,i,a,o){n||={};var s,c,l=n;if(`ref`in l)for(c in l={},n)c==`ref`?s=n[c]:l[c]=n[c];var u={type:e,props:l,key:r,ref:s,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--Zt,__i:-1,__u:0,__source:a,__self:o};if(typeof e==`function`&&(s=e.defaultProps))for(c in s)l[c]===void 0&&(l[c]=s[c]);return t.vnode&&t.vnode(u),u}var Qt=(e,t)=>{if(typeof e==`string`)return e;let n=e.tone===void 0?void 0:`tone-${e.tone}`;return e.href===void 0?W(`span`,{class:n,children:e.text},t):W(`a`,{class:n,href:e.href,target:`_blank`,rel:`noreferrer`,children:e.text},t)},$t=({text:e})=>W(S,{children:(typeof e==`string`?[e]:e).map(Qt)}),en=({lines:e})=>W(`div`,{class:`lines`,children:e.map((e,t)=>W(`div`,{children:W($t,{text:e})},t))}),G=({tone:e,label:t})=>W(`span`,{class:`dot dot-${e}`,title:t,"aria-label":t,role:t===void 0?void 0:`img`}),K=({children:e,tone:t})=>W(`span`,{class:`pill${t===void 0?``:` pill-${t}`}`,children:e}),q=({label:e,cell:t})=>t===void 0?null:W(`div`,{class:`fact`,children:[W(`dt`,{children:e}),W(`dd`,{title:t.title,children:[W(G,{tone:t.tone}),W(`span`,{class:t.tone===`waiting`?`tone-muted`:`tone-${t.tone}`,children:t.text})]})]}),J=({failure:e})=>W(`div`,{class:`problem`,role:`alert`,children:[W(`strong`,{children:e.status===0?`Connection problem`:`kayra answered ${String(e.status)}`}),W(`pre`,{children:e.message})]}),Y=({what:e})=>W(`div`,{class:`waiting`,children:[W(`span`,{class:`spinner`,"aria-hidden":`true`}),` `,e]}),X=({title:e,sub:t,children:n})=>W(`header`,{class:`page-header`,children:[W(`div`,{children:[W(`h1`,{children:e}),t===void 0?null:W(`div`,{class:`sub`,children:t})]}),n===void 0?null:W(`div`,{class:`actions`,children:n})]}),tn=({initial:e,choose:t,close:n})=>{let[r,i]=j(e===``?`.`:e),[a,o]=j(void 0);return M(()=>{let e={current:!1};return o(void 0),At(`/api/directories?path=${encodeURIComponent(r)}`).then(t=>{e.current||o(t)}),()=>{e.current=!0}},[r]),W(`section`,{class:`directory-picker`,"aria-label":`Choose a local directory`,children:[W(`div`,{class:`buttons`,children:[W(`strong`,{children:`Choose a local directory`}),W(`button`,{type:`button`,class:`button small`,onClick:n,children:`Close picker`})]}),a===void 0?W(Y,{what:`Reading directories`}):a.ok?W(S,{children:[W(`code`,{class:`directory-path`,children:a.value.path}),W(`ul`,{class:`directory-list`,children:[a.value.parent===a.value.path?null:W(`li`,{children:W(`button`,{type:`button`,onClick:()=>{i(a.value.parent)},children:`↑ Parent directory`})}),a.value.directories.map(e=>W(`li`,{children:W(`button`,{type:`button`,onClick:()=>{i(e.path)},children:[`▸ `,e.name]})},e.path))]}),W(`button`,{type:`button`,class:`button`,onClick:()=>{t(a.value.path)},children:`Use this directory`})]}):W(J,{failure:a.failure})]})},nn=I(void 0),rn=(e,t={})=>{nn.value={name:e,input:t}},an=e=>{rn(e.name,Object.fromEntries(Object.entries(e).filter(([e])=>e!==`name`)))},Z=()=>{nn.value=void 0},on=({step:e})=>W(`li`,{class:`plan-step`,children:[W(`span`,{class:`plan-index`,children:e.index+1}),W(`div`,{children:[W(`div`,{class:`plan-title`,children:[W(K,{tone:e.kind===`guard`?`warn`:e.kind===`confirm`?`bad`:`active`,children:e.kind}),` `,e.title]}),e.command===void 0?null:W(`code`,{class:`plan-command`,children:e.command})]})]}),sn=({field:e,value:t,change:n,server:r})=>{let[i,a]=j(!1),o=H.value,s=o.state===`ready`?o.value.servers:[],c=typeof t==`string`?t:``,l=`operation-${e.name}`;return e.type===`boolean`?W(`label`,{class:`toggle`,children:[W(`input`,{type:`checkbox`,checked:t===!0,onChange:e=>{n(e.currentTarget.checked)}}),e.description||e.name]}):W(`div`,{class:`operation-field`,children:[W(`label`,{for:l,children:[e.name,e.required?``:` (optional)`]}),e.name===`server`||e.choices.length>0?W(`select`,{id:l,required:e.required,value:c,onChange:e=>{n(e.currentTarget.value)},children:[W(`option`,{value:``,children:e.required?`Choose…`:`All servers`}),(e.name===`server`?s.map(e=>e.name):e.choices).map(e=>W(`option`,{value:e,children:e},e))]}):e.type===`array`?W(`textarea`,{id:l,rows:3,value:c,required:e.required,placeholder:`One item per line`,onInput:e=>{n(e.currentTarget.value)}}):W(`div`,{class:`inline`,children:[W(`input`,{id:l,value:c,required:e.required,minLength:e.minLength,pattern:e.pattern,list:e.name===`app`?`operation-apps`:void 0,spellcheck:!1,onInput:e=>{n(e.currentTarget.value)}}),e.name===`dir`?W(`button`,{type:`button`,class:`button`,onClick:()=>{a(!i)},children:`Browse…`}):null]}),e.name===`app`?W(`datalist`,{id:`operation-apps`,children:s.find(e=>e.name===r)?.apps.map(e=>W(`option`,{value:e},e))}):null,e.description===``?null:W(`span`,{class:`hint`,children:e.description}),e.type===`array`?W(`span`,{class:`hint`,children:[`One `,e.name===`command`?`argument`:`item`,` per line. Spaces within a line are preserved.`]}):null,i?W(tn,{initial:c,close:()=>{a(!1)},choose:e=>{n(e),a(!1)}}):null]})},cn=({info:e,seed:t,options:n,submit:r})=>{let[i,a]=j(()=>St(e.input,t.input)),[o,s]=j(n.verbose??!1),[c,l]=j(n.dryRun??!1),u=e.kind===`plan`||e.kind===`session`,d=bt(e.input),f=d.some(e=>!e.supported);return W(`form`,{onSubmit:t=>{t.preventDefault(),r({draft:{name:e.name,input:Ct(e.input,i)},options:{verbose:o,dryRun:c}})},children:[W(`div`,{class:`sheet-body operation-fields`,children:[d.map(e=>W(sn,{field:e,value:i[e.name]??``,server:i.server,change:t=>{a({...i,[e.name]:t})}},e.name)),f?W(`p`,{role:`alert`,children:`This operation has an unsupported input. Update the UI before running it.`}):null,u?W(`fieldset`,{class:`run-options`,children:[W(`legend`,{children:`Run options`}),W(`label`,{class:`toggle`,children:[W(`input`,{type:`checkbox`,checked:o,onChange:e=>{s(e.currentTarget.checked)}}),`Verbose output`]}),W(`label`,{class:`toggle`,children:[W(`input`,{type:`checkbox`,checked:c,onChange:e=>{l(e.currentTarget.checked)}}),`Dry run — preview only`]})]}):null]}),W(`div`,{class:`sheet-foot buttons`,children:[W(`button`,{type:`button`,class:`button`,onClick:Z,children:`Cancel`}),W(`button`,{type:`submit`,class:`button primary`,disabled:f,children:u?`Preview plan`:`Run query`})]})]})},ln=e=>{let t=H.value,n=t.state===`ready`?t.value.servers.find(t=>t.name===e.input.server):void 0;return n?.target===`multipass`?void 0:n?.name},un=({prepared:e,back:t})=>{let{draft:n,options:r}=e,[i,a]=j(void 0),[o,s]=j(``),[c,l]=j(void 0);if(M(()=>{jt(n,r).then(a)},[e]),i===void 0)return W(`div`,{class:`sheet-body`,children:W(Y,{what:`Planning`})});if(!i.ok)return W(`div`,{class:`sheet-body`,children:[W(J,{failure:i.failure}),W(`button`,{class:`button`,onClick:t,children:`Edit inputs`})]});let{invocation:u,steps:d,changes:f}=i.value,p=f&&!r.dryRun?ln(n):void 0,m=p===void 0||o===p,h=async()=>{l(`starting`);let e=await Mt(n,r,p===void 0?void 0:o);e.ok?(Z(),Wt(`session`in e.value?{page:`session`,id:e.value.session}:{page:`run`,id:e.value.run})):l(e.failure)};return W(S,{children:[W(`div`,{class:`sheet-body`,children:[W(`code`,{class:`command`,children:u.command}),W(`p`,{class:`sub`,children:[d.length,` steps · `,f?`changes things`:`reads only`,r.verbose?` · verbose`:``,r.dryRun?` · preview only`:``]}),W(`ol`,{class:`plan`,children:d.map(e=>W(on,{step:e},e.index))})]}),W(`form`,{class:`sheet-foot`,onSubmit:e=>{e.preventDefault(),m&&!r.dryRun&&h()},children:[p===void 0?null:W(`label`,{class:`confirm`,children:[W(`span`,{children:[`This changes `,W(`strong`,{children:p}),`, a real server. Type its name to go on:`]}),W(`input`,{value:o,onInput:e=>{s(e.currentTarget.value)},placeholder:p,autoComplete:`off`,spellcheck:!1})]}),c===void 0||c===`starting`?null:W(J,{failure:c}),W(`div`,{class:`buttons`,children:[W(`button`,{type:`button`,class:`button`,onClick:t,disabled:c===`starting`,children:`Edit inputs`}),r.dryRun?W(`button`,{type:`button`,class:`button primary`,onClick:Z,children:`Done`}):W(`button`,{type:`submit`,class:p===void 0?`button primary`:`button danger`,disabled:!m||c===`starting`,children:c===`starting`?`Starting…`:n.name===`ssh`?`Open terminal`:`Run`})]})]})]})},dn=({prepared:e,info:t,back:n})=>{let[r,i]=j(void 0),[a,o]=j(t.kind===`stream`);return M(()=>{let n={current:!0};return t.kind===`stream`?zt(`/api/operations/${t.name}`,e=>{i({ok:!0,value:e})},()=>{o(!1)},{input:e.draft.input},e=>{i({ok:!1,failure:e})}):(Nt(t.name,e.draft.input).then(e=>{n.current&&i(e)}),()=>{n.current=!1})},[e]),W(S,{children:[W(`div`,{class:`sheet-body`,children:[r===void 0?W(Y,{what:`Asking kayra`}):r.ok?W(`pre`,{class:`query-result`,children:typeof r.value==`string`?r.value:JSON.stringify(r.value,null,2)}):W(J,{failure:r.failure}),a?W(Y,{what:`Receiving updates`}):null]}),W(`div`,{class:`sheet-foot buttons`,children:[W(`button`,{class:`button`,onClick:n,children:`Edit inputs`}),W(`button`,{class:`button`,onClick:Z,children:`Close`})]})]})},fn=({draft:e,info:t})=>{let[n,r]=j(void 0),[i,a]=j({draft:e,options:{}}),o=()=>{n!==void 0&&a(n),r(void 0)};return W(S,{children:[W(`div`,{class:`sheet-head`,children:[W(`h2`,{id:`operation-title`,children:[gt[t.name].icon,` `,gt[t.name].label]}),W(`p`,{class:`sub`,children:t.summary})]}),n===void 0?W(cn,{info:t,seed:i.draft,options:i.options,submit:r}):t.kind===`plan`||t.kind===`session`?W(un,{prepared:n,back:o}):W(dn,{prepared:n,info:t,back:o})]})},pn=()=>{let e=nn.value,t=Ae(null),n=e!==void 0;if(M(()=>{if(!n)return;let e=document.activeElement;t.current?.focus();let r=e=>{if(e.key===`Escape`&&Z(),e.key===`Tab`){let n=t.current?.querySelectorAll(`button:not(:disabled), input:not(:disabled), select:not(:disabled), textarea:not(:disabled)`),r=n?.[0],i=n?.[n.length-1];r===void 0?e.preventDefault():e.shiftKey&&(document.activeElement===r||document.activeElement===t.current)?(e.preventDefault(),i?.focus()):!e.shiftKey&&document.activeElement===i&&(e.preventDefault(),r.focus())}};return addEventListener(`keydown`,r),()=>{removeEventListener(`keydown`,r),e instanceof HTMLElement&&e.focus()}},[n]),e===void 0)return null;let r=Gt.value,i=r.state===`ready`?r.value.find(t=>t.name===e.name):void 0;return W(`div`,{class:`overlay`,onClick:Z,children:W(`div`,{ref:t,tabIndex:-1,class:`sheet`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`operation-title`,onClick:e=>{e.stopPropagation()},children:r.state===`loading`?W(Y,{what:`Reading operations`}):r.state===`failed`?W(J,{failure:r.failure}):i===void 0?W(`p`,{role:`alert`,children:`Operation unavailable.`}):W(fn,{draft:e,info:i},JSON.stringify(e))})})},Q=I(!1),mn=()=>{let e=H.value,t=e.state===`ready`?e.value.servers:[],n=Gt.value.state===`ready`?Gt.value.value:[];return B([{label:`Fleet`,hint:`every server`,go:{page:`fleet`}},{label:`Runs`,hint:`what ran from here`,go:{page:`runs`}},{label:`Validate`,hint:`the fleet beyond its schemas`,go:{page:`validate`}},...n.map(e=>B({label:`${e.name} · ${gt[e.name].label}`,hint:e.summary,run:{name:e.name,input:{}}})),...t.flatMap(e=>B([{label:e.name,hint:`${e.kind} on ${e.target}`,go:{page:`server`,server:e.name}},...e.apps.map(t=>B({label:`${e.name}/${t}`,hint:`app`,go:{page:`app`,server:e.name,app:t}})),...wt(n,e).map(t=>B({label:`${t.name} ${e.name}`,hint:t.summary,run:{name:t.name,input:{server:e.name}}}))]))])},hn=e=>{Q.value=!1,`go`in e?Wt(e.go):rn(e.run.name,e.run.input)},gn=()=>{let[e,t]=j(``),[n,r]=j(0),i=Ae(null),a=Q.value;if(M(()=>{a&&i.current?.focus()},[a]),M(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&e.key.toLowerCase()===`k`?(e.preventDefault(),Q.value=!Q.value,t(``),r(0)):e.key===`Escape`&&(Q.value=!1)};return addEventListener(`keydown`,e),()=>{removeEventListener(`keydown`,e)}},[]),!Q.value)return null;let o=Et(mn(),e).slice(0,12);return W(`div`,{class:`overlay`,onClick:()=>{Q.value=!1},children:W(`div`,{class:`palette`,role:`dialog`,"aria-modal":`true`,onClick:e=>{e.stopPropagation()},children:[W(`input`,{ref:i,value:e,placeholder:`Go to, or run…`,spellcheck:!1,onInput:e=>{t(e.currentTarget.value),r(0)},onKeyDown:e=>{if(e.key===`ArrowDown`)r(Math.min(n+1,o.length-1));else if(e.key===`ArrowUp`)r(Math.max(n-1,0));else if(e.key===`Enter`){let e=o[n];e!==void 0&&hn(e)}else return;e.preventDefault()}}),W(`ul`,{children:o.map((e,t)=>W(`li`,{class:t===n?`selected`:void 0,onMouseEnter:()=>{r(t)},onClick:()=>{hn(e)},children:[W(`span`,{children:e.label}),W(`span`,{class:`hint`,children:e.hint})]},e.label))})]})})},_n=()=>{Q.value=!0},vn=e=>e===null?``:` · ${String(e)} ms`,yn={pending:`asking`,open:`open`,answered:`answered`,refused:`refused`,"no-answer":`no answer`,unreachable:`unreachable`,"unknown-host":`unknown host`,"bad-certificate":`bad certificate`,failed:`failed`,skipped:`not asked`},bn=e=>{let{state:t,address:n,reason:r}=e.machine;switch(t){case`pending`:return B({text:`asking OpenTofu`,tone:`waiting`});case`found`:return B({text:n??`an address OpenTofu does not give`,tone:n===null?`warn`:`strong`});case`not-provisioned`:return B({text:`not provisioned`,tone:`muted`});case`no-machine`:return B({text:`no machine in its state`,tone:`muted`});case`unreadable`:return B({text:`state unreadable`,tone:`bad`,...r===null?{}:{title:r}})}},xn=e=>{let{state:t,error:n}=e.ssh;switch(t){case`pending`:return B({text:`connecting`,tone:`waiting`});case`open`:return B({text:`port ${String(e.ssh.port)} open${vn(e.ssh.ms)}`,tone:`ok`});case`refused`:return B({text:`off (refused)`,tone:`warn`,title:`Nothing listens: SSH may be on only on demand.`});case`skipped`:return B({text:`not asked`,tone:`muted`});case`answered`:case`no-answer`:case`unreachable`:case`unknown-host`:case`bad-certificate`:case`failed`:return B({text:yn[t],tone:`bad`,...n===null?{}:{title:n}})}},Sn=e=>{let{https:t}=e;if(t!==null)switch(t.state){case`pending`:return B({text:`asking`,tone:`waiting`});case`answered`:return B({text:`HTTP ${String(t.status??`?`)}${vn(t.ms)}`,tone:t.status!==null&&t.status<400?`ok`:`bad`});case`skipped`:return B({text:`not asked`,tone:`muted`});case`open`:case`refused`:case`no-answer`:case`unreachable`:case`unknown-host`:case`bad-certificate`:case`failed`:return B({text:yn[t.state],tone:`bad`,...t.error===null?{}:{title:t.error}})}},Cn=e=>{let{state:t,pin:n,version:r,error:i}=e.kayra,a=`This fleet pins kayra ${n}: a setup records it.`;switch(t){case`pending`:return B({text:`asking`,tone:`waiting`});case`recorded`:return B(r===n?{text:n,tone:`ok`}:{text:`${r??`?`} → ${n}`,tone:`warn`,title:a});case`unrecorded`:return B({text:`unrecorded → ${n}`,tone:`warn`,title:`Set up by a kayra that recorded no version. ${a}`});case`unreadable`:return B({text:`unreadable`,tone:`bad`,...i===null?{}:{title:i}});case`skipped`:return B({text:`not asked`,tone:`muted`})}},wn=e=>{if(e===void 0)return B(`waiting`);let t=[bn(e),xn(e),Sn(e)].flatMap(e=>Object.freeze(e===void 0?[]:[e.tone]));return t.includes(`waiting`)?B(`waiting`):t.includes(`bad`)?B(`bad`):t.includes(`warn`)?B(`warn`):t.includes(`ok`)?B(`ok`):B(`muted`)},$=({to:e,children:t,class:n})=>W(`a`,{href:Ht(e),class:n,onClick:t=>{t.metaKey||t.ctrlKey||t.shiftKey||t.button!==0||(t.preventDefault(),Wt(e))},children:t}),Tn=(e,t)=>Ht(e)===Ht(t),En=({to:e,label:t})=>W($,{to:e,class:Tn(Ut.value,e)?`nav-item current`:`nav-item`,children:t}),Dn=()=>{let e=H.value;if(e.state!==`ready`)return null;let t=Ut.value;return W(`nav`,{class:`servers`,"aria-label":`Servers`,children:[W(`div`,{class:`nav-title`,children:`Servers`}),e.value.servers.map(e=>W($,{to:{page:`server`,server:e.name},class:`server`in t&&t.server===e.name?`nav-item current`:`nav-item`,children:[W(G,{tone:wn(U.value.value?.servers.find(t=>t.name===e.name))}),W(`span`,{children:e.name}),W(`span`,{class:`nav-meta`,children:e.kind})]},e.name))]})},On=({children:e})=>{let t=H.value;return W(`div`,{class:`shell`,children:[W(`aside`,{class:`sidebar`,children:[W($,{to:{page:`fleet`},class:`brand`,children:[W(`span`,{class:`logo`,"aria-hidden":`true`,children:`k`}),W(`span`,{children:[W(`strong`,{children:`kayra`}),W(`span`,{class:`brand-sub`,children:t.state===`ready`?t.value.fleet:`…`})]})]}),W(`nav`,{"aria-label":`Pages`,children:[W(En,{to:{page:`fleet`},label:`Fleet`}),W(En,{to:{page:`runs`},label:`Runs`}),W(En,{to:{page:`validate`},label:`Validate`})]}),W(Dn,{}),W(`div`,{class:`sidebar-foot`,children:t.state===`ready`?`kayra ${t.value.version}`:``})]}),W(`main`,{class:`main`,children:e})]})},kn=e=>{let t=Math.max(0,e)/1e3;if(t<10)return`${(Math.floor(t*10)/10).toFixed(1)}s`;if(t<60)return`${String(Math.floor(t))}s`;let n=Math.floor(t/60);return n<60?`${String(n)}m${String(Math.floor(t%60)).padStart(2,`0`)}s`:`${String(Math.floor(n/60))}h${String(n%60).padStart(2,`0`)}m`},An=e=>{let t=Math.floor(Math.max(0,e)/1e3);if(t<10)return`just now`;if(t<60)return`${String(t)}s ago`;let n=Math.floor(t/60);if(n<60)return`${String(n)}m ago`;let r=Math.floor(n/60);return r<48?`${String(r)}h ago`:`${String(Math.floor(r/24))}d ago`},jn=e=>Date.parse(e),Mn=(e,t)=>{let[n,r]=j(void 0),i=()=>{r(void 0),e().then(r)};return M(i,[t]),B([n,i])},Nn=e=>e===`success`?`ok`:e===`failure`?`bad`:`waiting`,Pn=({server:e,app:t,open:n})=>{let[r]=Mn(()=>Nt(`app.runs`,{server:e,app:t}),`${e}/${t}`);if(r===void 0)return W(Y,{what:`Asking the deployer`});if(!r.ok)return W(J,{failure:r.failure});let i=Date.now(),{live:a,runs:o}=r.value;return W(S,{children:[W(`p`,{class:`sub`,children:a===void 0?`Not deployed yet.`:`Live: ${a.sha.slice(0,7)} since ${An(i-Date.parse(a.time))}`}),W(`table`,{class:`table`,children:[W(`thead`,{children:W(`tr`,{children:[W(`th`,{}),W(`th`,{children:`Commit`}),W(`th`,{children:`Why`}),W(`th`,{children:`What`}),W(`th`,{class:`right`,children:`When`}),W(`th`,{class:`right`,children:`Took`})]})}),W(`tbody`,{children:o.map(e=>W(`tr`,{class:`clickable`,onClick:()=>{n(e.id)},children:[W(`td`,{class:`narrow`,children:W(G,{tone:Nn(e.state),label:e.state})}),W(`td`,{children:W(`code`,{children:e.sha?.slice(0,7)??``})}),W(`td`,{children:e.why}),W(`td`,{children:e.what}),W(`td`,{class:`right tone-muted`,children:An(i-Date.parse(e.started))}),W(`td`,{class:`right tone-muted`,children:e.finished===void 0?``:kn(Date.parse(e.finished)-Date.parse(e.started))})]},e.id))})]})]})},Fn=({server:e,app:t})=>{let[n]=Mn(()=>Nt(`app.releases`,{server:e,app:t}),`${e}/${t}`);if(n===void 0)return W(Y,{what:`Asking the deployer`});if(!n.ok)return W(J,{failure:n.failure});let r=Date.now();return W(`ul`,{class:`releases`,children:n.value.releases.map(n=>W(`li`,{children:[W(`code`,{children:n.sha.slice(0,12)}),W(`span`,{class:`tone-muted`,children:An(r-Date.parse(n.time))}),n.live?W(K,{tone:`ok`,children:`live`}):W(`button`,{class:`button small`,onClick:()=>{an({name:`app.rollback`,server:e,app:t,sha:n.sha})},children:`Roll back to it`})]},n.sha))})},In=e=>{if(/\b(error|failed|fatal|refused)\b/i.test(e))return B(`tone-bad`);if(/\bwarn(ing)?\b/i.test(e))return B(`tone-warn`)},Ln=({server:e,app:t,run:n})=>{let[r]=Mn(()=>Nt(`app.log`,{server:e,app:t,...n===void 0?{}:{run:n}}),`${e}/${t}/${n??``}`);return r===void 0?W(Y,{what:`Fetching the log`}):r.ok?W(`pre`,{class:`log`,children:r.value.split(`
|
|
5
|
+
`).map((e,t)=>W(`div`,{class:In(e),children:e===``?` `:e},t))}):W(J,{failure:r.failure})},Rn=({server:e,app:t})=>{let[n,r]=j(`runs`),[i,a]=j(void 0),[o,s]=j(``);return W(S,{children:[W(X,{title:t,sub:`on ${e}`,children:W(`form`,{class:`inline`,onSubmit:n=>{n.preventDefault(),an({name:`app.deploy`,server:e,app:t,...o.trim()===``?{}:{ref:o.trim()}})},children:[W(`input`,{value:o,onInput:e=>{s(e.currentTarget.value)},placeholder:`its ref`,spellcheck:!1,"aria-label":`Branch, tag or commit`}),W(`button`,{type:`submit`,class:`button primary`,children:`Deploy`})]})}),W(`nav`,{class:`tabs`,role:`tablist`,children:[`runs`,`releases`,`log`].map(e=>W(`button`,{role:`tab`,"aria-selected":n===e,class:n===e?`tab current`:`tab`,onClick:()=>{r(e)},children:[e,e===`log`&&i!==void 0?` · ${i}`:``]},e))}),W(`section`,{class:`card`,children:n===`runs`?W(Pn,{server:e,app:t,open:e=>{a(e),r(`log`)}}):n===`releases`?W(Fn,{server:e,app:t}):W(Ln,{server:e,app:t,run:i})}),W(`p`,{class:`tone-muted small`,children:[`Purging an app's data is irreversible:`,` `,W(`button`,{class:`link danger-link`,onClick:()=>{an({name:`app.purge`,server:e,app:t})},children:[`purge `,t,`'s volumes`]})]})]})},zn=({server:e})=>{let t=Gt.value;return t.state===`loading`?W(Y,{what:`Reading operations`}):t.state===`failed`?W(J,{failure:t.failure}):W(`div`,{class:`action-grid`,children:(e===void 0?t.value.filter(e=>e.scope===`fleet`||e.scope===`repo`):wt(t.value,e)).map(t=>W(`button`,{class:`action${t.effect===`destroys`?` danger`:``}`,onClick:()=>{rn(t.name,e===void 0?{}:{server:e.name})},children:[W(`strong`,{children:[W(`span`,{"aria-hidden":`true`,children:gt[t.name].icon}),` `,gt[t.name].label]}),W(`span`,{children:t.summary})]},t.name))})},Bn=({facts:e,seen:t})=>W($,{to:{page:`server`,server:e.name},class:`card server-card`,children:[W(`div`,{class:`card-head`,children:[W(G,{tone:wn(t)}),W(`h2`,{children:e.name}),W(K,{children:e.kind}),W(K,{tone:e.target===`multipass`?`muted`:e.target===`hetzner`?`accent`:`active`,children:e.target})]}),W(`div`,{class:`domain`,children:e.domain}),t===void 0?W(Y,{what:`asking`}):W(`dl`,{class:`facts`,children:[W(q,{label:`Address`,cell:bn(t)}),W(q,{label:`SSH`,cell:xn(t)}),W(q,{label:`Login`,cell:Sn(t)}),W(q,{label:`kayra`,cell:Cn(t)})]}),e.apps.length===0?null:W(`div`,{class:`chips`,children:e.apps.map(e=>W(K,{children:e},e))})]}),Vn=()=>{let e=H.value;if(e.state===`loading`)return W(Y,{what:`Reading the fleet`});if(e.state===`failed`)return W(J,{failure:e.failure});let{value:t,live:n}=U.value,{servers:r}=e.value,i=r.filter(e=>wn(t?.servers.find(t=>t.name===e.name))===`ok`).length;return W(S,{children:[W(X,{title:`Fleet`,sub:W(S,{children:[r.length,` servers · `,t===void 0?`asking each`:`${String(i)} answering everything they were asked`]}),children:W(`button`,{class:`button`,onClick:()=>{Yt()},disabled:n,children:n?`Asking…`:`Ask again`})}),W(`div`,{class:`cards`,children:r.map(e=>W(Bn,{facts:e,seen:t?.servers.find(t=>t.name===e.name)},e.name))}),W(`section`,{class:`card`,children:[W(`h2`,{children:`Fleet and local commands`}),W(zn,{})]})]})},Hn=({id:e,question:t})=>{let[n,r]=j(``),[i,a]=j(!1),[o,s]=j(void 0),c=Ae(null);M(()=>{c.current?.focus()},[]);let l=async t=>{a(!0),r(``);let n=await Pt(e,t);n.ok||(s(n.failure),a(!1))};return W(`form`,{class:`ask`,onSubmit:e=>{e.preventDefault(),i||l(n)},children:[W(`label`,{for:`run-answer`,children:W($t,{text:t.prompt})}),W(`input`,{id:`run-answer`,ref:c,type:t.secret?`password`:`text`,autoComplete:`off`,value:n,disabled:i,onInput:e=>{r(e.currentTarget.value)},spellcheck:!1}),W(`button`,{type:`submit`,class:`button primary`,disabled:i,children:i?`Sending…`:`Answer`}),W(`button`,{type:`button`,class:`button`,disabled:i,onClick:()=>{l(``)},children:`Decline`}),o===void 0?null:W(J,{failure:o})]})},Un={invocation:void 0,steps:[],current:void 0,asking:void 0,ended:void 0},Wn=(e,t,n)=>t===void 0?e:B({...e,steps:e.steps.map((e,r)=>r===t?n(e):e)}),Gn=(e,t)=>Wn(e,e.current,e=>({...e,said:[...e.said,t]})),Kn=(e,t,n)=>{switch(t.kind){case`plan`:return B({...e,invocation:t.invocation,steps:t.steps.map(e=>({listed:e,state:`waiting`,said:[]}))});case`started`:return Wn({...e,current:t.index},t.index,e=>({...e,state:`running`,started:n}));case`done`:return Wn(e,t.index,e=>({...e,state:t.failed?`failed`:t.stopped?`stopped`:`passed`,ms:t.ms,...t.why===void 0?{}:{why:t.why}}));case`ended`:{let n={failures:t.failures,ms:t.ms,footer:t.footer,...t.stop===void 0?{}:{stop:t.stop}};return B({...e,asking:void 0,ended:n,steps:e.steps.map((e,n)=>e.state===`running`||t.stop?.why===`interrupted`&&t.stop.index===n?{...e,state:`stopped`}:e.state===`waiting`?{...e,state:`skipped`}:e)})}case`output`:return Gn(e,{kind:`output`,stream:t.stream,chunk:t.chunk});case`said`:return Gn(e,{kind:`said`,stream:t.stream,text:t.text});case`ask`:return B({...e,asking:t});case`answered`:return B({...e,asking:void 0})}},qn=e=>{let{ended:t}=e;return t===void 0?B(`running`):t.stop?.why===`interrupted`?B(`interrupted`):t.stop?.why===`declined`?B(`declined`):t.failures===0?B(`passed`):B(`failed`)},Jn={fg:void 0,bold:!1,dim:!1},Yn=[`black`,`red`,`green`,`yellow`,`blue`,`magenta`,`cyan`,`white`],Xn=(e,t)=>{let n=t===``?[0]:t.split(`;`).map(Number),r=(e,t)=>{let[n,...i]=t;return n===void 0?e:n===38||n===48?r(e,i[0]===5?i.slice(2):i[0]===2?i.slice(4):i):r(n===0?Jn:n===1?{...e,bold:!0}:n===2?{...e,dim:!0}:n===22?{...e,bold:!1,dim:!1}:n===39?{...e,fg:void 0}:n>=30&&n<=37?{...e,fg:Yn[n-30]}:n>=90&&n<=97?{...e,fg:`bright-${Yn[n-90]??`white`}`}:e,i)};return r(e,n)},Zn=e=>[e.fg===void 0?``:`sgr-${e.fg}`,e.bold?`sgr-bold`:``,e.dim?`sgr-dim`:``].filter(e=>e!==``).join(` `),Qn=/\u001b\[([0-9;]*)m|\u001b\[[0-9;?]*[A-Za-z]|\u001b\][^\u0007\u001b]*(?:\u0007|\u001b\\)/g,$n=e=>{let t=[...e.matchAll(Qn)].reduce((t,n)=>{let r=e.slice(t.at,n.index),i=r===``?t.out:[...t.out,{text:r,classes:Zn(t.look)}],a=n[1];return{out:i,look:a===void 0?t.look:Xn(t.look,a),at:n.index+n[0].length}},{out:[],look:Jn,at:0}),n=e.slice(t.at);return n===``?t.out:B([...t.out,{text:n,classes:Zn(t.look)}])},er={running:`active`,passed:`ok`,failed:`bad`,interrupted:`warn`,declined:`warn`},tr={waiting:`○`,running:``,passed:`✓`,failed:`✗`,stopped:`■`,skipped:`–`},nr=({step:e})=>W(`div`,{class:`output`,children:e.said.map((e,t)=>e.kind===`output`?W(`span`,{class:e.stream===`stderr`?`stderr`:void 0,children:$n(e.chunk).map((e,t)=>W(`span`,{class:e.classes===``?void 0:e.classes,children:e.text},t))},t):W(`div`,{class:e.stream===`err`?`said said-err`:`said`,children:W($t,{text:e.text})},t))}),rr=({step:e,now:t})=>{let n=e.state===`running`||e.state===`failed`,r=e.ms??(e.started===void 0?void 0:t-e.started),i=e.said.length===0?null:W(nr,{step:e});return W(`details`,{class:`step step-${e.state}`,open:n,children:[W(`summary`,{children:[W(`span`,{class:`step-icon`,children:e.state===`running`?W(`span`,{class:`spinner`}):tr[e.state]}),W(`span`,{class:`step-title`,children:e.listed.title}),W(`span`,{class:`step-kind`,children:e.listed.kind}),W(`span`,{class:`step-time`,children:[e.why===void 0?``:`${e.why} · `,r===void 0?``:kn(r)]})]}),i]})},ir=({id:e})=>{let[t,n]=ke((e,t)=>Kn(e,t,Date.now()),Un),[r,i]=j(Date.now()),[a,o]=j(void 0);M(()=>zt(`/api/runs/${encodeURIComponent(e)}/events`,n,()=>void 0,void 0,o),[e]);let s=qn(t)===`running`;M(()=>{if(!s)return;let e=setInterval(()=>{i(Date.now())},250);return()=>{clearInterval(e)}},[s]);let{invocation:c,steps:l,ended:u,asking:d}=t;if(c===void 0)return a===void 0?W(Y,{what:`Starting`}):W(J,{failure:a});let f=qn(t);return W(S,{children:[W(X,{title:W(`code`,{class:`command`,children:c.command}),sub:`${c.about.join(` · `)} · ${String(l.length)} steps`,children:[W(K,{tone:er[f],children:f}),s?W(`button`,{class:`button danger`,onClick:()=>{Ft(e).then(e=>{e.ok||o(e.failure)})},children:`Stop`}):null]}),a===void 0?null:W(J,{failure:a}),d===void 0?null:W(Hn,{id:e,question:d},JSON.stringify(d)),W(`div`,{class:`timeline`,children:l.map(e=>W(`div`,{children:[e.listed.opens===void 0?null:W(`h3`,{class:`part`,children:e.listed.opens}),W(rr,{step:e,now:r})]},e.listed.index))}),u===void 0?null:W(`footer`,{class:`run-footer tone-border-${er[f]}`,children:W(en,{lines:u.footer})})]})},ar={running:`waiting`,passed:`ok`,failed:`bad`,interrupted:`warn`,declined:`warn`},or=({server:e})=>{let[t,n]=j(void 0);if(M(()=>{let e=()=>{Rt().then(n)};e();let t=setInterval(e,3e3);return()=>{clearInterval(t)}},[]),t===void 0)return W(Y,{what:`Reading the runs`});if(!t.ok)return W(J,{failure:t.failure});let r=t.value.filter(t=>e===void 0||t.server===e);if(r.length===0)return W(`p`,{class:`empty`,children:`Nothing run from here yet.`});let i=Date.now();return W(`table`,{class:`table`,children:W(`tbody`,{children:r.map(e=>W(`tr`,{children:[W(`td`,{class:`narrow`,children:W(G,{tone:ar[e.state],label:e.state})}),W(`td`,{children:W($,{to:{page:e.session?`session`:`run`,id:e.id},children:W(`code`,{children:e.command})})}),W(`td`,{class:`tone-${ar[e.state]===`waiting`?`active`:ar[e.state]}`,children:e.state}),W(`td`,{class:`tone-muted right`,children:An(i-jn(e.started))})]},e.id))})})},sr=()=>W(S,{children:[W(X,{title:`Runs`,sub:`Every command run from here, recorded in the fleet's .cache/ui/runs`}),W(`section`,{class:`card`,children:W(or,{})})]}),cr=({name:e})=>{let t=H.value;if(t.state!==`ready`)return W(Y,{what:`Reading the fleet`});let n=t.value.servers.find(t=>t.name===e);if(n===void 0)return W(`p`,{class:`empty`,children:[`No server `,e,` in this fleet.`]});let r=U.value.value?.servers.find(t=>t.name===e);return W(S,{children:[W(X,{title:W(S,{children:[W(G,{tone:wn(r)}),` `,n.name]}),sub:W(S,{children:[W(K,{children:n.kind}),` `,W(K,{children:n.target}),` `,W(`a`,{href:`https://${n.domain}`,target:`_blank`,rel:`noreferrer`,children:n.domain})]})}),W(`div`,{class:`columns`,children:[W(`section`,{class:`card`,children:[W(`h2`,{children:`Now`}),r===void 0?W(Y,{what:`asking`}):W(`dl`,{class:`facts`,children:[W(q,{label:`Address`,cell:bn(r)}),W(q,{label:`SSH`,cell:xn(r)}),W(q,{label:`Login`,cell:Sn(r)}),W(q,{label:`kayra`,cell:Cn(r)})]})]}),W(`section`,{class:`card`,children:[W(`h2`,{children:`Apps`}),n.apps.length===0?W(`p`,{class:`empty`,children:n.kind===`platform`?`None in server.yml.`:`A ${n.kind} server runs no apps.`}):W(`ul`,{class:`links`,children:n.apps.map(e=>W(`li`,{children:W($,{to:{page:`app`,server:n.name,app:e},children:e})},e))})]})]}),W(`section`,{class:`card`,children:[W(`h2`,{children:`Commands`}),W(zn,{server:n})]}),W(`section`,{class:`card`,children:[W(`h2`,{children:`Runs from here`}),W(or,{server:n.name})]})]})},lr=e=>e===`problem`?`bad`:e===`unchecked`?`warn`:`ok`,ur=e=>e===`problem`?`✗`:e===`unchecked`?`·`:`✓`,dr={problem:`problems`,unchecked:`partly checked`,passed:`holds`},fr=()=>{M(()=>{Xt()},[]);let e=qt.value;if(e.state===`loading`)return W(Y,{what:`Checking the fleet beyond its schemas`});if(e.state===`failed`)return W(J,{failure:e.failure});let{result:t,servers:n}=e.value,r=e=>n.flatMap(e=>e.findings).filter(t=>t.result===e).length;return W(S,{children:[W(X,{title:`Validate`,sub:`Secrets, apps against their contract, stacks, routes · ${String(r(`problem`))} problems · ${String(r(`unchecked`))} not checked`,children:[W(K,{tone:lr(t),children:dr[t]}),W(`button`,{class:`button`,onClick:()=>void Xt(),children:`Check again`})]}),n.map(e=>W(`section`,{class:`card`,children:[W(`div`,{class:`card-head`,children:[W(G,{tone:lr(e.result)}),W(`h2`,{children:e.name}),W(K,{children:e.kind}),W(K,{children:e.target}),W(`span`,{class:`grow`}),W(K,{tone:lr(e.result),children:dr[e.result]})]}),W(`ul`,{class:`findings`,children:e.findings.map((e,t)=>W(`li`,{class:`finding finding-${e.result}`,children:[W(`span`,{class:`glyph tone-${lr(e.result)}`,children:ur(e.result)}),W(`span`,{children:[e.text,e.hint===null?null:W(`span`,{class:`hint`,children:[`→ `,e.hint]})]})]},t))})]},e.name))]})},pr=e=>typeof e==`string`?e:e.map(e=>typeof e==`string`?e:e.text).join(``),mr=e=>e.kind===`output`?e.chunk:e.kind===`said`?`${pr(e.text)}\r\n`:``,hr=(e,t)=>{let n={current:Promise.resolve(!0)};return r=>{n.current=n.current.then(async n=>{if(!n)return!1;let i=await e(r);return i.ok||t(i.failure),i.ok})}},gr=`modulepreload`,_r=function(e){return`/`+e},vr={},yr=function(e){return e.pathname.endsWith(`.css`)},br=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e,i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?new URL(import.meta.resolve(e)):new URL(e,import.meta.url)}r=o(t.map(t=>{t=_r(t,n);let r=s(t);if(r.href in vr)return;vr[r.href]=!0;let i=yr(r);if(e===void 0){e={all:new Set,styles:new Set};let t=document.getElementsByTagName(`link`);for(let n=t.length-1;n>=0;n--){let r=t[n];e.all.add(r.href),r.rel===`stylesheet`&&e.styles.add(r.href)}}if((i?e.styles:e.all).has(r.href))return;let o=document.createElement(`link`);if(o.rel=i?`stylesheet`:gr,i||(o.as=`script`),o.crossOrigin=``,o.href=r.href,a&&o.setAttribute(`nonce`,a),document.head.appendChild(o),i)return new Promise((e,t)=>{o.addEventListener(`load`,e),o.addEventListener(`error`,()=>t(Error(`Unable to preload CSS for ${r}`)))})}).filter(e=>e!==void 0))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},xr=({id:e})=>{let t=Ae(null),[n,r]=j(void 0),[i,a]=j(void 0),[o,s]=j(`running`),[c,l]=j(void 0),[u,d]=j(!1);M(()=>{let n={current:!0},i={current:()=>void 0};return(async()=>{let{Terminal:o}=await br(async()=>{let{Terminal:e}=await import(`./xterm-CerOhKYV.js`);return{Terminal:e}},[]);if(!n.current||t.current===null)return;let c=new o({cols:120,rows:32,fontSize:13,cursorBlink:!0,disableStdin:!0,theme:{background:`#0a0a0c`,foreground:`#e4e4e8`}});c.open(t.current),c.focus();let u={current:[]},d={current:!1},f={current:!1},p={current:!1},m=e=>{f.current=!e,c.options.disableStdin=e},h=e=>{p.current=!0,m(!0),l(e)},g=hr(t=>It(e,t),h),_=c.onData(e=>{f.current&&g(e)}),v=zt(`/api/sessions/${encodeURIComponent(e)}/output`,e=>{e.kind===`plan`&&(r(e.invocation),u.current=e.steps),e.kind===`started`&&u.current.find(t=>t.index===e.index)?.kind===`session`&&m(!1),e.kind===`ask`&&(m(!0),a(e)),e.kind===`answered`&&a(void 0);let t=mr(e);t!==``&&c.write(t),e.kind===`ended`&&(d.current=!0,m(!0),s(e.stop?.why===`interrupted`?`interrupted`:e.stop?.why===`declined`?`declined`:e.failures>0||e.stop!==void 0?`failed`:`passed`),c.write(`\r
|
|
6
|
+
[Session ended]\r
|
|
7
|
+
`))},()=>{m(!0),n.current&&!d.current&&!p.current&&l({status:0,message:`Session output disconnected. Reload this page to reconnect.`})},void 0,h);i.current=()=>{v(),_.dispose(),c.dispose()}})().catch(()=>{n.current&&l({status:0,message:`The terminal could not start. Reload this page to reconnect.`})}),()=>{n.current=!1,i.current()}},[e]);let f=async()=>{d(!0);let t=await Lt(e);t.ok||(l(t.failure),d(!1))};return W(S,{children:[W(X,{title:n?.command??`SSH terminal`,sub:`120 columns × 32 rows`,children:[W(K,{tone:o===`running`?`active`:o===`passed`?`ok`:`warn`,children:o}),o===`running`?W(`button`,{class:`button danger`,disabled:u,onClick:()=>{f()},children:u?`Closing…`:`Close session`}):null]}),c===void 0?null:W(J,{failure:c}),i===void 0?null:W(Hn,{id:e,question:i},JSON.stringify(i)),W(`div`,{class:`terminal-scroll`,children:W(`div`,{ref:t,class:`terminal`})}),W(`p`,{class:`hint`,children:`Leaving this page keeps the session open. Use Close session to disconnect.`})]})},Sr=()=>{let e=Ut.value;switch(e.page){case`fleet`:return W(Vn,{});case`server`:return W(cr,{name:e.server});case`app`:return W(Rn,{server:e.server,app:e.app});case`runs`:return W(sr,{});case`run`:return W(ir,{id:e.id},e.id);case`session`:return W(xr,{id:e.id},e.id);case`validate`:return W(fr,{});case`missing`:return W(`p`,{class:`empty`,children:[`Nothing at `,e.path,`.`]})}},Cr=()=>(M(()=>{Jt(),Kt(),Yt()},[]),W(S,{children:[W(On,{children:[W(`div`,{class:`topbar`,children:[W(`button`,{class:`search`,onClick:_n,children:[W(`span`,{children:`Go to, or run…`}),W(`kbd`,{children:`⌘K`})]}),W(`button`,{class:`button`,onClick:()=>{an({name:`doctor`})},children:`Doctor`})]}),W(Sr,{})]}),W(pn,{}),W(gn,{})]})),wr=document.getElementById(`app`);wr!==null&&ge(W(Cr,{}),wr);
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
<meta name="color-scheme" content="light dark" />
|
|
7
7
|
<title>kayra</title>
|
|
8
8
|
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Crect width='32' height='32' rx='8' fill='%235b5bd6'/%3E%3Cpath d='M11 8v16M11 16l9-8M14 13l7 11' stroke='white' stroke-width='3' stroke-linecap='round' fill='none'/%3E%3C/svg%3E" />
|
|
9
|
-
<script type="module" crossorigin src="/assets/index-
|
|
9
|
+
<script type="module" crossorigin src="/assets/index-C4HCL022.js"></script>
|
|
10
10
|
<link rel="stylesheet" crossorigin href="/assets/index-Ct0Eudk4.css">
|
|
11
11
|
</head>
|
|
12
12
|
<body>
|
|
@@ -7,14 +7,16 @@ import { contextFor, invocation, isQuery, isStream, stream } from "../../core/op
|
|
|
7
7
|
import { follow } from "../../core/status/updates.js";
|
|
8
8
|
import { json, send } from "../../deployer/http/http.js";
|
|
9
9
|
import { facts } from "./commands.js";
|
|
10
|
-
import { catalog
|
|
10
|
+
import { catalog } from "../wire/contract.js";
|
|
11
|
+
import { openapi } from "./openapi.js";
|
|
11
12
|
import { directories } from "./directories.js";
|
|
12
13
|
import { inFlight, liveRuns } from "./live.js";
|
|
13
|
-
import { options
|
|
14
|
-
import {
|
|
14
|
+
import { options } from "../wire/schemas.js";
|
|
15
|
+
import { requestBody } from "./protocol.js";
|
|
16
|
+
import { answer as queryAnswer } from "../wire/queries.js";
|
|
15
17
|
import { stateOf, summary } from "./runs.js";
|
|
16
18
|
import { allRuns, preview, start } from "./start.js";
|
|
17
|
-
import { statusJson } from "
|
|
19
|
+
import { statusJson } from "../wire/status.js";
|
|
18
20
|
const answerJson = (response, status, value) => {
|
|
19
21
|
send(response, status, JSON.stringify(value), "application/json; charset=utf-8");
|
|
20
22
|
};
|
|
@@ -13,51 +13,3 @@ export const facts = (server) => typed({
|
|
|
13
13
|
name: server.name, kind: server.kind, target: server.target, domain: server.domain,
|
|
14
14
|
apps: server.apps.map((app) => app.name), commands: offered(server),
|
|
15
15
|
});
|
|
16
|
-
/** What follows the server and the app on the command line, by operation. */
|
|
17
|
-
const extra = (call) => {
|
|
18
|
-
switch (call.name) {
|
|
19
|
-
case "ssh.exec":
|
|
20
|
-
return ["--", ...call.input.command];
|
|
21
|
-
case "job":
|
|
22
|
-
return [call.input.job, ...(call.input.noPrs ? ["--no-prs"] : [])];
|
|
23
|
-
case "app.rollback":
|
|
24
|
-
return [call.input.sha];
|
|
25
|
-
case "app.deploy":
|
|
26
|
-
return call.input.ref === undefined ? [] : [call.input.ref];
|
|
27
|
-
case "app.log":
|
|
28
|
-
return call.input.run === undefined ? [] : [call.input.run];
|
|
29
|
-
case "app.check":
|
|
30
|
-
return [call.input.dir];
|
|
31
|
-
case "certs":
|
|
32
|
-
return [call.input.domain, ...call.input.subdomains];
|
|
33
|
-
case "up":
|
|
34
|
-
case "provision":
|
|
35
|
-
case "deploy":
|
|
36
|
-
case "setup":
|
|
37
|
-
case "plan":
|
|
38
|
-
case "verify":
|
|
39
|
-
case "apps":
|
|
40
|
-
case "hosts":
|
|
41
|
-
case "ssh":
|
|
42
|
-
case "down":
|
|
43
|
-
case "adopt":
|
|
44
|
-
case "backup.test":
|
|
45
|
-
case "app.purge":
|
|
46
|
-
case "app.runs":
|
|
47
|
-
case "app.releases":
|
|
48
|
-
case "status":
|
|
49
|
-
case "validate":
|
|
50
|
-
case "doctor":
|
|
51
|
-
case "version":
|
|
52
|
-
return [];
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
/** How the command line spells an operation where its words are not its name's. */
|
|
56
|
-
const spelled = { "ssh.exec": "ssh", "app.releases": "app rollback", "app.log": "app logs" };
|
|
57
|
-
/** The command's words, as typed on the command line. */
|
|
58
|
-
export const words = (call) => {
|
|
59
|
-
const { input } = call;
|
|
60
|
-
const scope = ["server" in input ? input.server : undefined, "app" in input ? input.app : undefined];
|
|
61
|
-
const name = spelled[call.name] ?? call.name.replaceAll(".", " ");
|
|
62
|
-
return ["kayra", name, ...scope, ...extra(call)].filter((word) => word !== undefined).join(" ");
|
|
63
|
-
};
|
|
@@ -1,56 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import {
|
|
3
|
-
import { options, schemas, querySchemas } from "
|
|
2
|
+
import { catalog } from "../wire/contract.js";
|
|
3
|
+
import { options, schemas, querySchemas } from "../wire/schemas.js";
|
|
4
4
|
import { typed } from "../../lib/typed.js";
|
|
5
|
-
export const catalog = () => Object.freeze(operationNames.map((name) => {
|
|
6
|
-
const { summary, scope, effect, kind, input } = operations[name];
|
|
7
|
-
return { name, summary, scope, effect, kind, input: z.toJSONSchema(input, { io: "input" }) };
|
|
8
|
-
}));
|
|
9
|
-
const isObject = (value) => typeof value === "object" && value !== null;
|
|
10
|
-
const object = (value) => isObject(value) ? value : typed({});
|
|
11
|
-
const list = (value) => typed(Array.isArray(value) ? value : []);
|
|
12
|
-
const literal = (value) => JSON.stringify(value);
|
|
13
|
-
// Recursive: TypeScript cannot infer what it returns.
|
|
14
|
-
const typescript = (value) => {
|
|
15
|
-
const schema = object(value);
|
|
16
|
-
if ("const" in schema)
|
|
17
|
-
return literal(schema["const"]);
|
|
18
|
-
if (Array.isArray(schema["enum"]))
|
|
19
|
-
return schema["enum"].map(literal).join(" | ");
|
|
20
|
-
if (Array.isArray(schema["anyOf"]))
|
|
21
|
-
return schema["anyOf"].map(typescript).join(" | ");
|
|
22
|
-
if (Array.isArray(schema["oneOf"]))
|
|
23
|
-
return schema["oneOf"].map(typescript).join(" | ");
|
|
24
|
-
if (Array.isArray(schema["type"]))
|
|
25
|
-
return schema["type"].map((type) => typescript({ ...schema, type })).join(" | ");
|
|
26
|
-
switch (schema["type"]) {
|
|
27
|
-
case "null": return "null";
|
|
28
|
-
case "string": return "string";
|
|
29
|
-
case "integer":
|
|
30
|
-
case "number": return "number";
|
|
31
|
-
case "boolean": return "boolean";
|
|
32
|
-
case "array": return `readonly (${typescript(schema["items"])})[]`;
|
|
33
|
-
case "object": {
|
|
34
|
-
const properties = Object.entries(object(schema["properties"]));
|
|
35
|
-
const required = list(schema["required"]);
|
|
36
|
-
const fields = properties.map(([key, property]) => `readonly ${literal(key)}${required.includes(key) ? "" : "?"}: ${typescript(property)}`).join("; ");
|
|
37
|
-
if (properties.length === 0 && schema["additionalProperties"] === false)
|
|
38
|
-
return "Readonly<Record<string, never>>";
|
|
39
|
-
return properties.length === 0 ? `Readonly<Record<string, ${typescript(schema["additionalProperties"])}>>` : `{ ${fields} }`;
|
|
40
|
-
}
|
|
41
|
-
default: return "unknown";
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
export const contractTypes = () => [
|
|
45
|
-
"// Generated by npm run contract. The pinned kayra version defines this /api contract.",
|
|
46
|
-
...Object.entries(schemas).map(([name, schema]) => `export type ${name} = ${typescript(z.toJSONSchema(schema))};`),
|
|
47
|
-
`export type OperationInputs = { ${operationNames.map((name) => `readonly ${literal(name)}: ${typescript(z.toJSONSchema(operations[name].input, { io: "input" }))}`).join("; ")} };`,
|
|
48
|
-
'export type OperationName = keyof OperationInputs;',
|
|
49
|
-
'export type InputOf<N extends OperationName> = OperationInputs[N];',
|
|
50
|
-
'export type OperationCall = { readonly [N in OperationName]: { readonly name: N; readonly input: InputOf<N> } }[OperationName];',
|
|
51
|
-
`export type RunOptions = ${typescript(z.toJSONSchema(options, { io: "input" }))};`,
|
|
52
|
-
"",
|
|
53
|
-
].join("\n");
|
|
54
5
|
const response = (description, schema, media = "application/json") => ({ description, content: { [media]: { schema } } });
|
|
55
6
|
const ref = (name) => ({ $ref: `#/components/schemas/${name}` });
|
|
56
7
|
const isQueryName = (name) => Object.hasOwn(querySchemas, name);
|
|
@@ -1,68 +1,3 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import {
|
|
3
|
-
import { serverKinds } from "../../core/fleet/settings.js";
|
|
4
|
-
import { serverTargets } from "../../core/fleet/model.js";
|
|
5
|
-
import { parts } from "../../core/plan/model.js";
|
|
6
|
-
import { stopReasons } from "../../core/interpreter/progress.js";
|
|
7
|
-
import { machineStates, reachStates } from "../../core/status/model.js";
|
|
8
|
-
import { tones } from "../../core/text/spans.js";
|
|
9
|
-
import { verdicts } from "../../core/validation/findings.js";
|
|
10
|
-
import { releasesSchema, runsSchema } from "../../core/ctl/answers.js";
|
|
11
|
-
const tone = z.enum(tones);
|
|
12
|
-
const span = z.union([z.string(), z.object({ tone: tone.exactOptional(), text: z.string(), href: z.string().exactOptional() })]);
|
|
13
|
-
const line = z.array(span);
|
|
14
|
-
const text = z.union([z.string(), line]);
|
|
15
|
-
const part = z.enum(parts);
|
|
16
|
-
const listed = z.object({ index: z.number().int(), kind: z.string(), title: z.string(), command: z.string().exactOptional(), part: part.exactOptional(), opens: part.exactOptional() });
|
|
17
|
-
const invocation = z.object({ command: z.string(), server: z.string().exactOptional(), about: z.array(z.string()) });
|
|
18
|
-
const stop = z.enum(stopReasons);
|
|
19
|
-
const state = z.enum(["running", "passed", "failed", "interrupted", "declined"]);
|
|
20
|
-
const summary = z.object({ id: z.string(), command: z.string(), server: z.string().exactOptional(), started: z.string(), state, session: z.boolean() });
|
|
21
|
-
const ended = z.object({ kind: z.literal("ended"), failures: z.number(), stop: z.object({ index: z.number(), why: stop }).exactOptional(), ms: z.number(), footer: z.array(line) });
|
|
22
|
-
const event = z.discriminatedUnion("kind", [
|
|
23
|
-
z.object({ kind: z.literal("plan"), invocation, steps: z.array(listed) }),
|
|
24
|
-
z.object({ kind: z.literal("started"), index: z.number() }),
|
|
25
|
-
z.object({ kind: z.literal("done"), index: z.number(), failed: z.boolean(), stopped: z.boolean(), why: z.string().exactOptional(), ms: z.number() }),
|
|
26
|
-
ended,
|
|
27
|
-
z.object({ kind: z.literal("output"), stream: z.enum(["stdout", "stderr"]), chunk: z.string() }),
|
|
28
|
-
z.object({ kind: z.literal("said"), stream: z.enum(["out", "err"]), text }),
|
|
29
|
-
z.object({ kind: z.literal("ask"), prompt: text, secret: z.boolean(), expect: z.string().exactOptional() }),
|
|
30
|
-
z.object({ kind: z.literal("answered") }),
|
|
31
|
-
]);
|
|
32
|
-
const reach = z.enum(reachStates);
|
|
33
|
-
const verdict = z.enum(verdicts);
|
|
34
|
-
const serverCommand = z.enum(["up", "provision", "deploy", "setup", "plan", "verify", "apps", "down", "adopt", "backup.test"]);
|
|
35
|
-
const serverFacts = z.object({
|
|
36
|
-
name: z.string(), kind: z.enum(serverKinds), target: z.enum(serverTargets), domain: z.string(), apps: z.array(z.string()),
|
|
37
|
-
commands: z.array(z.union([serverCommand, z.literal("job")])),
|
|
38
|
-
});
|
|
39
|
-
export const options = z.strictObject({
|
|
40
|
-
verbose: z.boolean().default(false),
|
|
41
|
-
dryRun: z.boolean().default(false),
|
|
42
|
-
columns: z.number().int().min(1).max(1000).default(120),
|
|
43
|
-
rows: z.number().int().min(1).max(1000).default(32),
|
|
44
|
-
});
|
|
2
|
+
import { options } from "../wire/schemas.js";
|
|
45
3
|
export const requestBody = z.strictObject({ input: z.unknown().exactOptional(), options: options.exactOptional(), confirm: z.string().exactOptional() });
|
|
46
|
-
export const schemas = {
|
|
47
|
-
Tone: tone, Span: span, Line: line, Text: text, Part: part, Listed: listed, Invocation: invocation, Stop: stop, RunState: state,
|
|
48
|
-
RunEvent: event, RunSummary: summary,
|
|
49
|
-
Run: summary.extend({ events: z.array(event) }),
|
|
50
|
-
Preview: z.object({ invocation, steps: z.array(listed), changes: z.boolean() }),
|
|
51
|
-
ServerCommand: serverCommand,
|
|
52
|
-
ServerFacts: serverFacts,
|
|
53
|
-
FleetFacts: z.object({ fleet: z.string(), version: z.string(), servers: z.array(serverFacts) }),
|
|
54
|
-
DirectoryListing: z.object({ path: z.string(), parent: z.string(), directories: z.array(z.object({ name: z.string(), path: z.string() })) }),
|
|
55
|
-
ReachState: reach,
|
|
56
|
-
Status: z.object({ servers: z.array(z.object({
|
|
57
|
-
name: z.string(), kind: z.string(), target: z.string(), domain: z.string(), apps: z.array(z.string()),
|
|
58
|
-
machine: z.object({ state: z.enum(machineStates), address: z.string().nullable(), from: z.enum(["inventory", "opentofu"]).nullable(), reason: z.string().nullable() }),
|
|
59
|
-
ssh: z.object({ port: z.number(), state: reach, ms: z.number().nullable(), error: z.string().nullable() }),
|
|
60
|
-
https: z.object({ url: z.string(), state: reach, status: z.number().nullable(), ms: z.number().nullable(), error: z.string().nullable() }).nullable(),
|
|
61
|
-
})) }),
|
|
62
|
-
Validation: z.object({ result: verdict, servers: z.array(z.object({ name: z.string(), kind: z.string(), target: z.string(), result: verdict, findings: z.array(z.object({ result: verdict, text: z.string(), hint: z.string().nullable() })) })) }),
|
|
63
|
-
AppRuns: runsSchema, AppReleases: releasesSchema,
|
|
64
|
-
OperationInfo: z.object({ name: z.enum(operationNames), summary: z.string(), scope: z.enum(scopes), effect: z.enum(effects), kind: z.enum(kinds), input: z.record(z.string(), z.unknown()) }),
|
|
65
|
-
};
|
|
66
|
-
export const querySchemas = {
|
|
67
|
-
validate: schemas.Validation, version: z.string(), "app.runs": schemas.AppRuns, "app.releases": schemas.AppReleases, "app.log": z.string(),
|
|
68
|
-
};
|
|
@@ -10,7 +10,7 @@ import { hasPlan, planOf, serverOf } from "../../core/operations/dispatch.js";
|
|
|
10
10
|
import { verbose } from "../../core/recipes/steps.js";
|
|
11
11
|
import { err, ok } from "../../lib/result.js";
|
|
12
12
|
import { typed } from "../../lib/typed.js";
|
|
13
|
-
import { words } from "
|
|
13
|
+
import { words } from "../wire/words.js";
|
|
14
14
|
import { busy, readRecord, recordLine, runId } from "./runs.js";
|
|
15
15
|
/** Every run there is: the live ones, then those recorded, newest first. */
|
|
16
16
|
export const allRuns = (served) => {
|
|
@@ -169,6 +169,10 @@ export const parser = (fleet) => {
|
|
|
169
169
|
brief: message `The local browser interface and API: the fleet, its servers and apps, every command with its steps live.`,
|
|
170
170
|
description: message `Listens on 127.0.0.1 only. The URL it prints carries this launch's token; nothing else gets in. Runs the same plans as the command line, with the same guards; a change to a real server asks for its name first.`,
|
|
171
171
|
footer: footer(["kayra serve", "open it in the browser"], ["kayra serve --port 7700 --no-open", "for web/'s dev server"]),
|
|
172
|
+
}), command("mcp", object({ name: constant("mcp") }), {
|
|
173
|
+
brief: message `An MCP server on stdin and stdout: every operation as a tool, for an agent such as Claude Code.`,
|
|
174
|
+
description: message `Started by the agent from the fleet's .mcp.json, not by hand. Runs the same plans as the command line, with the same guards; asks for no password, and has the operator type a server's name before destroying it.`,
|
|
175
|
+
footer: footer(["kayra mcp", "what the fleet's .mcp.json starts: {\"command\": \"kayra\", \"args\": [\"mcp\"]}"]),
|
|
172
176
|
}), command("certs", object({
|
|
173
177
|
name: constant("certs"),
|
|
174
178
|
domain: argument(domainParser, { description: message `The domain the certificates are for.` }),
|