@hallohuman/hightea 0.1.31 → 0.1.32
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/dist/bin.js +26 -20
- package/dist/chunk-3emak1d3.js +2 -0
- package/dist/chunk-55a0ndzw.js +5 -0
- package/dist/chunk-5hvk5pvs.js +9 -0
- package/dist/chunk-749gsvce.js +139 -0
- package/dist/chunk-7mgx0krk.js +5 -0
- package/dist/chunk-ah99zytf.js +58 -0
- package/dist/chunk-c7atktnb.js +5 -0
- package/dist/{chunk-r9yjtfhp.js → chunk-dvsftn8z.js} +4 -4
- package/dist/chunk-dzr0pvfa.js +1 -0
- package/dist/chunk-gbwfgq6g.js +1 -0
- package/dist/chunk-h9f45p57.js +4 -0
- package/dist/chunk-hrtxeg8j.js +1 -0
- package/dist/chunk-nfmmht3j.js +2 -0
- package/dist/chunk-pdnrwmme.js +1 -0
- package/dist/chunk-pexgyagn.js +2 -0
- package/dist/chunk-v221hgba.js +2 -0
- package/dist/chunk-vr4rsfaf.js +13 -0
- package/dist/chunk-w2f84aab.js +1 -0
- package/dist/{chunk-5s85pw9m.js → chunk-wyzpk81n.js} +1 -1
- package/dist/plugin/plugin.json +4 -1
- package/dist/plugin/plugin.mjs +36 -36
- package/package.json +1 -1
- package/dist/chunk-19pwmgzg.js +0 -5
- package/dist/chunk-5zb06f9b.js +0 -2
- package/dist/chunk-69dva4cx.js +0 -58
- package/dist/chunk-8rbp82rh.js +0 -139
- package/dist/chunk-8x5daqht.js +0 -1
- package/dist/chunk-9pv1nvfv.js +0 -5
- package/dist/chunk-db8mr7mp.js +0 -1
- package/dist/chunk-dkzzzkex.js +0 -13
- package/dist/chunk-f04t1q6v.js +0 -2
- package/dist/chunk-gcqhggbh.js +0 -1
- package/dist/chunk-jdzvh3gk.js +0 -1
- package/dist/chunk-p616vcdm.js +0 -4
- package/dist/chunk-xj3c5jgm.js +0 -5
- package/dist/chunk-xy8j3npr.js +0 -1
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{a}from"./chunk-pexgyagn.js";import"./chunk-ah99zytf.js";import{i}from"./chunk-c7atktnb.js";import{S,E}from"./chunk-v221hgba.js";import{readFile as D}from"node:fs/promises";import{join as O}from"node:path";var h=`hightea deploy <service> --pin <sha> [--host <id>] [--json]
|
|
2
|
+
hightea deploy status <service> [--host <id>] [--json]`,P=/^[0-9a-fA-F]{40}$/u,y=()=>({out:(e)=>console.log(e),err:(e)=>console.error(e)}),_=(e)=>typeof e==="object"&&e!==null&&!Array.isArray(e),u=(e)=>e.hostIds.length>0?`${e.hostIds.join(",")} (pid ${String(e.pid)})`:`pid ${String(e.pid)}`;async function N(e,n){if(e.port!==void 0)return e.port;try{let s=JSON.parse(await n(e.config));if(_(s)&&typeof s.port==="number"&&Number.isInteger(s.port))return s.port}catch{return}return}async function R(e,n){let s=e.connectionTokenFile??O(e.configDir,"connection.token");try{return(await n(s)).trim()||void 0}catch{return}}async function f(e,n={}){let s=n.readFile??((t)=>D(t,"utf8")),d;try{d=await(n.runningAhpds??i)()}catch(t){return{error:`DEPLOY_NO_AHPD: the process table could not be read: ${t.message}`}}let l=e?.trim(),r;if(l!==void 0&&l!==""){let t=d.filter((p)=>p.hostIds.includes(l));if(t.length===0)return{error:`DEPLOY_NO_AHPD: no running ahpd on this machine serves host ${l} (running: ${d.map(u).join("; ")||"none"})`};if(t.length>1)return{error:`DEPLOY_NO_AHPD: ${String(t.length)} running ahpds serve host ${l} (${t.map(u).join("; ")}); the process table cannot tell them apart`};r=t[0]}else{if(d.length===0)return{error:"DEPLOY_NO_AHPD: no running ahpd on this machine; start one with `hightea host join` first"};if(d.length>1)return{error:`DEPLOY_NO_AHPD: this machine runs ${String(d.length)} ahpds (${d.map(u).join("; ")}); name one with --host <id>`};r=d[0]}if(r===void 0)return{error:"DEPLOY_NO_AHPD: no running ahpd on this machine"};let c=await N(r,s);if(c===void 0)return{error:`DEPLOY_NO_AHPD: ${r.config} names no port and its command line has no --port; cannot reach this ahpd`};let o=await R(r,s);return{url:`ws://${r.host??"127.0.0.1"}:${String(c)}`,...o===void 0?{}:{token:o},label:r.hostIds[0]??`pid ${String(r.pid)}`}}async function g(e,n){try{return await(n.connect??a)(e.url,{token:e.token,clientId:"hightea-deploy"})}catch(s){return{error:`DEPLOY_NO_AHPD: ${e.url} did not answer: ${s.message}`}}}var I=(e,n)=>{if(e==="RUNNING")return`DEPLOY_RUNNING: ${n}`;if(e==="UNKNOWN_SERVICE")return`DEPLOY_UNKNOWN_SERVICE: ${n}`;return`DEPLOY_REFUSED ${e}: ${n}`},m=(e)=>/No channel at x-hh-deploys:\/\//u.test(e.message)?"DEPLOY_NO_DRIVER: this ahpd has no deploy driver loaded (x-hh-deploys://); its deploy plugin is not in its configuration":`DEPLOY_DRIVER_UNREADABLE: ${e.message}`;async function x(e,n=y(),s={}){let d=e.service.trim();if(d==="")return n.err(`DEPLOY_SERVICE_REQUIRED: name the service to deploy
|
|
3
|
+
${h}`),1;let l=e.pin.trim();if(!P.test(l))return n.err(`DEPLOY_PIN_NOT_SHA: --pin must be a full 40-character commit sha; '${l}' is not`),1;let r=await f(e.host,s);if("error"in r)return n.err(r.error),1;let c=await g(r,s);if("error"in c)return n.err(c.error),1;try{let o=await S(c,{service:d,version:l.toLowerCase()});if(!o.ok)return n.err(I(o.code,o.message)),1;if(e.json)n.out(JSON.stringify({machine:r.label,service:o.service,pin:o.sha,deployId:o.deployId,state:o.state}));else n.out(`started ${o.service} at ${o.sha}: deploy ${o.deployId} on ${r.label}`);return 0}catch(o){return n.err(m(o)),1}finally{c.close()}}var A=(e,n)=>({machine:n,service:e.service,state:e.state,pin:e.to??null,from:e.from??null,...e.step===void 0?{}:{step:e.step},...e.reason===void 0?{}:{reason:e.reason},...e.exit===void 0?{}:{exit:e.exit},deployId:e.deployId,...e.at===void 0?{}:{at:e.at}});async function j(e,n=y(),s={}){let d=e.service.trim();if(d==="")return n.err(`DEPLOY_SERVICE_REQUIRED: name the service to read
|
|
4
|
+
${h}`),1;let l=await f(e.host,s);if("error"in l)return n.err(l.error),1;let r=await g(l,s);if("error"in r)return n.err(r.error),1;try{let c=await E(r),o=c.runs.filter((p)=>p.service===d);if(o.length===0){let p=c.error===void 0?"":` (${c.error})`;return n.err(`DEPLOY_UNKNOWN_SERVICE: ${d} has no deploy on ${c.machine||l.label}${p}`),1}let t=A(o[0],c.machine||l.label);if(e.json)n.out(JSON.stringify(t));else n.out(`${t.state} ${t.service} pin ${t.pin??"?"} ${t.step===void 0?"":`${t.step} `}deploy ${t.deployId}${t.reason===void 0?"":` last error: ${t.reason}`}`);return 0}catch(c){return n.err(m(c)),1}finally{r.close()}}export{x as deployPlace,j as deployStatus};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{L,u,p,w,D,P}from"./chunk-ah99zytf.js";export{L as agentAppsOnPath,w as appInstalled,p as describedApp,u as installLineOf,D as isShippedApp,P as noAgentAppsLine};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{m,o,g,n,i}from"./chunk-c7atktnb.js";import{r}from"./chunk-v221hgba.js";import{writeJsonAtomic as k}from"@ahpd/sdk";import{existsSync as b}from"node:fs";import{isAbsolute as _,join as S,resolve as A}from"node:path";async function R(e,a,T){if(e.configDir!==void 0){let s=_(e.configDir)?A(e.configDir):void 0;if(s===void 0)return{error:`TRUST_CONFIG_DIR_INVALID: --config-dir needs an absolute path; ${JSON.stringify(e.configDir)} is not one`};if(!b(S(s,"config.json")))return{error:`TRUST_CONFIG_DIR_INVALID: ${s} holds no config.json; name the directory holding this host's ahpd configuration (in a hab-managed host that is its xdg-config/ahpd)`};return{configDir:s,...s===a.configDir?{}:{note:`Trusting in the configuration you named at ${s}; this machine's claim names ${a.configDir}.`}}}let c=(await T.runningAhpds()).filter((s)=>s.hostIds.includes(a.hostId));if(c.length>1)return{error:`TRUST_HOST_AMBIGUOUS: ${String(c.length)} running ahpd processes serve ${a.hostId} (${c.map((s)=>`${String(s.pid)} at ${s.configDir}`).join(", ")}); stop the extras or name one with --config-dir`};let d=c[0];if(d!==void 0)return d.configDir===a.configDir?{configDir:d.configDir}:{configDir:d.configDir,note:`Using the running host's configuration at ${d.configDir} (pid ${String(d.pid)}); this machine's claim names ${a.configDir}, which that host does not read.`};if(e.action==="list")return{configDir:a.configDir,note:`No ahpd process serving ${a.hostId} is running on this machine; reading the claim's copy at ${a.configDir}, which a hab-managed host would not read.`};return{error:`TRUST_NO_RUNNING_HOST: no ahpd process serving ${a.hostId} is running on this machine, so there is no configuration to change; start the host, or name its configuration with --config-dir <dir> (this machine's claim names ${a.configDir})`}}var D="A trusted browser key lets posts made in that browser ask this machine's agents; a trusted host key lets that machine's agents ask them too.";async function h(e,a=()=>new Date,T={runningAhpds:()=>i()}){if(e.action!=="list")try{r(e.caller,"key-trust")}catch(t){return console.error(`${t.message}; nothing was changed`),1}let c=await n(e.host);if("error"in c)return console.error(c.error.replace(/^SERVICE_/u,"TRUST_")),1;let d=await R(e,c,T);if("error"in d)return console.error(d.error),1;let s;try{s=g(d.configDir)}catch(t){return console.error(`${t.message}; it was left unchanged`),1}let l=s.state==="read"?s.keys:[],f=`host ${c.hostId} (${s.file})`;if(d.note!==void 0)console.error(d.note);if(e.action==="list"){if(e.json===!0)return console.log(JSON.stringify({hostId:c.hostId,file:s.file,keys:l})),0;if(e.browsers===!0){if(l.length===0)return console.log(`No browsers are approved on ${f}. A browser's own page shows the code when someone presses "Approve this browser"; approve it here with \`hightea approve <code>\`.`),0;console.log(`Browsers approved on ${f}:`);for(let t of l)console.log(` ${t.name.padEnd(22)} approved ${E(t.addedAt)}${t.personName===void 0?"":` ${t.personName}`}`);return 0}if(l.length===0)return console.log(`No trusted keys for ${f}: room asks to this machine's agents are refused until you add one with \`hightea host trust add <name> <public key>\`.`),0;console.log(`Trusted keys for ${f}:`);for(let t of l)console.log(` ${t.name} key ${t.keyId} added ${t.addedAt}`);return console.log(D),0}if(!m.test(e.name))return console.error("TRUST_NAME_INVALID: a name is 1 to 64 letters, digits, '.', '_' or '-' (single spaces are allowed between them), starting with a letter or digit; nothing was changed"),1;let u=l.find((t)=>t.name===e.name);if(e.action==="remove"){if(u===void 0)return console.error(`TRUST_NAME_UNKNOWN: ${f} trusts no key named ${e.name} (trusted: ${l.map((t)=>t.name).join(", ")||"none"}); nothing was changed`),1;if(!I(s.file,l.filter((t)=>t!==u)))return 1;if(e.browsers===!0)return console.log(`Removed. The next message from ${u.name} will ask again.`),0;return console.log(`Removed ${e.name} (key ${u.keyId}) from ${f}. Asks signed with it are refused from now on.`),0}let y=o(e.publicKey);if("error"in y)return console.error(`${y.error}; nothing was changed`),1;let p=(t)=>{if(e.quiet!==!0)console.log(t)};if(u!==void 0){if(u.publicKey===e.publicKey)return p(`${e.name} (key ${y.keyId}) is already trusted by ${f}; it was left unchanged.`),0;return console.error(`TRUST_NAME_TAKEN: ${f} already trusts another key as ${e.name}; remove it first or pick another name. Nothing was changed`),1}let w=l.find((t)=>t.keyId===y.keyId);if(w!==void 0)return console.error(`TRUST_KEY_TAKEN: ${f} already trusts this key as ${w.name}; nothing was changed`),1;let N={name:e.name,keyId:y.keyId,publicKey:e.publicKey,addedAt:a().toISOString(),...e.personName===void 0||e.personName===""?{}:{personName:e.personName}};if(!I(s.file,[...l,N]))return 1;return p(`Trusted ${e.name} (key ${y.keyId}) on ${f}. ${D}`),0}function E(e){let a=new Date(e);if(Number.isNaN(a.getTime()))return e;return new Intl.DateTimeFormat("sv-SE",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}).format(a)}function I(e,a){try{k(e,{v:1,keys:a},{mode:384})}catch(T){return console.error(`TRUST_FILE_UNWRITABLE: ${e}: ${T.message}`),!1}return!0}
|
|
2
|
+
export{h};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{h}from"./chunk-nfmmht3j.js";import"./chunk-c7atktnb.js";import"./chunk-ah99zytf.js";export{h as hostTrust};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import w from"ws";async function a(i,s){let u=s.token===void 0?i:`${i}${i.includes("?")?"&":"?"}tkn=${encodeURIComponent(s.token)}`,o=new w(u),d=new Map,t,f=0;o.on("message",(n)=>{let e=JSON.parse(String(n));if(e.id!==void 0&&e.method===void 0)d.get(e.id)?.(e)}),o.on("close",(n,e)=>{t=`${String(n)} ${e.toString()}`;for(let r of d.values())r({error:{code:0,message:`closed: ${t}`}})}),await new Promise((n,e)=>{o.once("open",()=>n()),o.once("error",(r)=>e(r))});let l=(n,e)=>new Promise((r,m)=>{if(t!==void 0)return m(Error(`the machine's connection closed: ${t}`));let g=++f;d.set(g,(c)=>{if(c.error!==void 0)m(Error(c.error.message));else r(c.result)}),o.send(JSON.stringify({jsonrpc:"2.0",id:g,method:n,params:e}))});return await l("initialize",{channel:"ahp-root://",protocolVersions:["1.1.0"],clientId:s.clientId}),{call:l,close:()=>o.close()}}
|
|
2
|
+
export{a};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var y=(e,t)=>({kind:e,id:t}),O=(e,t)=>e!==void 0&&t!==void 0&&e.kind===t.kind&&e.id===t.id,A=(e)=>`${e.kind}:${e.id}`;function r(e,t){if(e.kind==="agent")throw Error(`${t}: a person must grant this; agent ${e.id} cannot`)}var N="source",w="x-hh/source",J=["command","cwd","env","schedule","restart","depends_on","health"],C=(e)=>({command:e.command,cwd:e.cwd,env:e.env,schedule:e.schedule,restart:e.restart,depends_on:e.depends_on,health:e.health}),h=(e)=>{if(e===void 0)return"undefined";if(Array.isArray(e))return`[${e.map(h).join(",")}]`;if(e!==null&&typeof e==="object")return`{${Object.keys(e).sort().map((n)=>`${JSON.stringify(n)}:${h(e[n])}`).join(",")}}`;return JSON.stringify(e)},L=(e,t)=>{let n=C(e),o=C(t);return J.filter((i)=>h(n[i])!==h(o[i]))},R="x-hh-services://",v=(e,t,n)=>e.call("x-ahpd/invokeOperation",{channel:R,operationId:t,...n}),F=async(e)=>{let t=await e.call("subscribe",{channel:R});await e.call("unsubscribe",{channel:R});let n=t?.snapshot?.state;if(typeof n?.error==="string")throw Error(`the machine's services could not be read: ${n.error}`);if(n===void 0||!Array.isArray(n.rows))throw Error("the services channel answered no rows");let o=n.rows;return{services:o.flatMap((i)=>i.record===void 0?[]:[U(i.record,i.state)]),readOnly:o.flatMap((i)=>i.readOnly===void 0?[]:[{name:i.name,reason:i.readOnly}]),capabilities:n.capabilities,ifVersion:n.ifVersion,...typeof n.file==="string"?{file:n.file}:{}}},U=(e,t)=>{if(!p(t)||typeof t.status!=="string")return e;return{...e,state:{status:t.status,...typeof t.why==="string"?{why:t.why}:{}}}},H="x-hh-deploys://";async function S(e,t){if(typeof t?.service!=="string"||t.service.trim()==="")throw Error("deployService: service is a non-empty name");if(typeof t?.version!=="string"||t.version.trim()==="")throw Error("deployService: version is a branch, a tag or a commit sha");let n=await e.call("x-ahpd/invokeOperation",{channel:H,operationId:"deploy",target:{id:t.service},input:{service:t.service,version:t.version}});if(!p(n))throw Error(`the deploys channel answered no record: ${JSON.stringify(n)}`);if(n.ok===!0){let{service:a,sha:f,deployId:c}=n;if(typeof a!=="string"||typeof f!=="string"||typeof c!=="string"||n.state!=="started")throw Error(`the deploys channel answered a start without service, sha, deployId and state: ${JSON.stringify(n)}`);return{ok:!0,service:a,sha:f,deployId:c,state:"started"}}let{code:o,message:i}=n;if(n.ok===!1&&typeof o==="string"&&o!==""&&typeof i==="string")return{ok:!1,code:o,message:i};throw Error(`the deploys channel answered neither a start nor a named refusal: ${JSON.stringify(n)}`)}var W=(e)=>{if(!p(e))return;let{service:t,deployId:n,state:o}=e;if(typeof t!=="string"||typeof n!=="string"||typeof o!=="string")return;let{step:i,from:a,to:f,at:c,last:l}=e,s=p(l)&&typeof l.reason==="string"?l.reason:void 0,d=p(l)&&(l.exit===null||typeof l.exit==="number")?l.exit:void 0;return{service:t,deployId:n,state:o,...typeof i==="string"?{step:i}:{},...a===null||typeof a==="string"?{from:a}:{},...typeof f==="string"?{to:f}:{},...typeof c==="string"?{at:c}:{},...s===void 0?{}:{reason:s},...d===void 0?{}:{exit:d}}};async function E(e){let t=await e.call("subscribe",{channel:H});await e.call("unsubscribe",{channel:H});let n=t?.snapshot?.state;if(n===void 0)throw Error("the deploys channel answered no state");let o=Array.isArray(n.runs)?n.runs.flatMap((f)=>{let c=W(f);return c===void 0?[]:[c]}):[],i=typeof n.machine==="string"?n.machine:"",a=typeof n.error==="string"?n.error:void 0;return{machine:i,runs:o,...a===void 0?{}:{error:a}}}async function b(e,t,n){let o=Y(e);return{...(e.services===void 0?void 0:await G(e.services,t,n))??{create:[],change:[],unchanged:[],readOnly:[],remove:[],keep:[],unmanaged:[]},...e.agents===void 0?{}:{agents:await ee(e.agents,t,n)},...o.length===0?{}:{hosts:await q(o,n)}}}async function G(e,t,n){let o=await F(t),i=o.capabilities?.fields??[];if(!i.includes(N))throw Error(`this machine's services driver records no "${N}" (its fields are ${i.join(", ")}); it cannot say which client wrote an entry, so nothing is written`);let a=new Map(o.services.map((u)=>[u.name,u])),f=new Map(o.readOnly.map((u)=>[u.name,u.reason])),c=[],l=[],s=[],d=new Set;for(let u of e){d.add(u.name);let m=a.get(u.name);if(f.has(u.name))throw Error(`${u.name} is read-only on this machine: ${f.get(u.name)??""}`);if(m===void 0)c.push(u);else{let P=L(m,u);if(P.length===0)s.push(u.name);else l.push({name:u.name,before:m,after:u,changed:P})}}let g=n.prune===!0?o.services.filter((u)=>O(u.source,n.source)&&!d.has(u.name)):[];if(g.length>0&&n.removal===void 0){let u=g.map((m)=>`${m.name} (${m.state?.status??"state unknown"})`).join(", ");throw Error(`prune would remove ${u}: pass stop (stop each program, then remove the entry) or keep (leave it running here and clear its source)`)}let x=n.removal==="stop"?g:[],j=n.removal==="keep"?g:[],V=n.prune===!0?o.services.filter((u)=>!O(u.source,n.source)&&!d.has(u.name)):[];return{ifVersion:o.ifVersion,create:c,change:l,unchanged:s,readOnly:o.readOnly,remove:x,keep:j,unmanaged:V}}function Y(e){let t=e.hosts;if(t===void 0)return[];if(!Array.isArray(t))throw Error("the plan's hosts is not a list: a host entry is {name, agents}");let n=new Set;return t.map((o,i)=>{if(!p(o))throw Error(`host entry ${i+1} is not an object: a host entry is {name, agents}`);let a=o.name;if(typeof a!=="string"||a.trim().length===0)throw Error(`host entry ${i+1} names no machine: every host entry needs a non-empty "name"`);let f=Object.keys(o).filter((l)=>l!=="name"&&l!=="agents");if(f.length>0)throw Error(`host entry ${a}: unknown ${f.length===1?"field":"fields"} ${f.join(", ")} (a host entry is {name, agents})`);if(n.has(a))throw Error(`${a} is named twice in one plan`);n.add(a);let c=o.agents;if(c!==void 0&&(!Array.isArray(c)||!c.every((l)=>typeof l==="string"&&l.length>0&&l.length<=256)))throw Error(`host entry ${a}: agents must be a list of agent member ids`);return c===void 0?{name:a}:{name:a,agents:c}})}function K(e,t){let n=t.hostJoin;if(n!==void 0)return n;let o=e.map((i)=>`host:${i.name}`).join(", ");throw Error(`host entries need a workspace to mint their join links and this apply has none: ${o}. Nothing is sent and no host is created from a plan: run it with the workspace's origin and slug, signed in as a person, or take the hosts out of the plan.`)}async function q(e,t){r(t.source.kind==="agent"?{kind:"agent",id:t.source.id}:{kind:"person",id:t.source.id},"host-join"),K(e,t);let n=e.map((o)=>({name:o.name,agents:[...o.agents??[]]}));if(t.prune!==!0)return{pending:n};return{pending:n,pruneNote:"host links are not pruned; each unconsumed link expires on its own, and its expiry is printed when it is minted"}}var _="x-ahpd-agents://",z=["engine","owner","name","description","tags","model"],p=(e)=>e!==null&&typeof e==="object"&&!Array.isArray(e),B=(e,t)=>{let n=t[w];if(n===void 0)return;if(!p(n))throw Error(`${e}: config.${w} is not a source ({kind, id})`);let{kind:o,id:i}=n;if(o!=="file"&&o!=="program"&&o!=="agent"&&o!=="ci")throw Error(`${e}: config.${w}.kind is not one of file, program, agent, ci`);if(typeof i!=="string"||i==="")throw Error(`${e}: config.${w}.id is empty`);return{kind:o,id:i}},Q=(e)=>{if(!p(e))throw Error("the agents channel answered an entry that is not an object");let t=p(e.record)?e.record:e,n=e.id;if(typeof n!=="string"||n==="")throw Error("the agents channel answered a record that names no id");let o=typeof t.revision==="number"&&Number.isInteger(t.revision)&&t.revision>=0?t.revision:void 0,i=p(t.config)?t.config:{},a=B(n,i);return{id:n,...o===void 0?{}:{revision:o},record:t,...a===void 0?{}:{source:a}}};async function X(e){let t=await e.call("subscribe",{channel:_});await e.call("unsubscribe",{channel:_});let n=t?.snapshot?.state,o=p(n)?n.records:void 0;if(!Array.isArray(o))throw Error("the agents channel answered no records");return o.map(Q)}var I=(e)=>({engine:e.engine,owner:e.owner,name:e.name,...e.description===void 0?{}:{description:e.description},...e.tags===void 0?{}:{tags:e.tags},...e.model===void 0?{}:{model:e.model}}),M=(e)=>Object.fromEntries(Object.entries(e).filter(([t])=>t!==w)),Z=(e,t)=>{let n=I(t),o=z.filter((a)=>h(e.record[a])!==h(n[a])),i=p(e.record.config)?e.record.config:{};if(h(M(i))!==h(M(t.config??{})))o.push("config");return o};async function ee(e,t,n){let o=await X(t),i=new Map(o.map((d)=>[d.id,d])),a=[],f=[],c=[],l=new Set;for(let d of e){if(l.has(d.id))throw Error(`${d.id} is named twice in one plan`);l.add(d.id);let g=i.get(d.id);if(g===void 0)a.push(d);else{let x=Z(g,d);if(x.length===0)c.push(d.id);else if(g.revision===void 0)throw Error(`${d.id} has no revision on this machine; it cannot be edited from here`);else f.push({id:d.id,before:g,after:d,changed:x})}}let s=n.prune===!0?o.filter((d)=>O(d.source,n.source)&&!l.has(d.id)):[];for(let d of s)if(d.revision===void 0)throw Error(`${d.id} has no revision on this machine; it cannot be removed from here`);return{create:a,change:f,unchanged:c,remove:s}}async function k(e,t,n){let o=e.ifVersion??"",i=[],a=[];for(let s of e.hosts?.pending??[]){if(n===void 0)throw Error(`host ${s.name}: host links need a workspace to mint them and this apply has none; nothing was minted`);let d;try{d=await n.mintHostJoin(s.agents)}catch(g){throw Error(`host ${s.name} was not minted: ${g.message}`)}a.push({name:s.name,link:d})}for(let s of e.create)o=(await v(t,"put",{input:{service:s,ifVersion:"absent"}})).ifVersion??o,i.push(s.name);for(let s of e.change)o=(await v(t,"put",{input:{service:s.after,ifVersion:o}})).ifVersion??o,i.push(s.name);let f=[];for(let s of e.keep??[])o=(await v(t,"put",{input:{service:{name:s.name,source:null},ifVersion:o}})).ifVersion??o,f.push(s.name);let c=[];for(let s of e.remove??[]){if(s.state?.status.toLowerCase()==="running")await v(t,"stop",{target:{id:s.name},input:{}});o=(await v(t,"remove",{target:{id:s.name},input:{ifVersion:o}})).ifVersion??o,c.push(s.name)}if(e.agents!==void 0){for(let s of e.agents.create)await D(t,s,0),i.push(`agent:${s.id}`);for(let s of e.agents.change){if(s.before.revision===void 0)throw Error(`${s.id} has no revision on this machine; it cannot be edited from here`);await D(t,s.after,s.before.revision),i.push(`agent:${s.id}`)}for(let s of e.agents.remove){if(s.revision===void 0)throw Error(`${s.id} has no revision on this machine; it cannot be removed from here`);await ne(t,s.id,s.revision),c.push(`agent:${s.id}`)}}let l=e.hosts?.pruneNote===void 0?void 0:a.length===0?"host links are not pruned; this apply minted none, so nothing of its own is outstanding":`host links are not pruned; unconsumed ones expire at ${a.map((s)=>s.link.expiresAt).sort()[0]}`;return{preview:e,written:i,removed:c,kept:f,...e.hosts===void 0?{}:{hostLinks:a},...l===void 0?{}:{hostNote:l}}}var D=(e,t,n)=>e.call("x-ahpd/agents/put",{id:t.id,...I(t),config:{...t.config,[w]:t.source},ifRevision:n}),ne=(e,t,n)=>e.call("x-ahpd/agents/remove",{id:t,ifRevision:n});function T(e){let t=[];for(let n of e.create)t.push(`+ ${n.name}`);for(let n of e.change)t.push(`~ ${n.name} (${n.changed.join(", ")})`);for(let n of e.remove??[]){let o=n.state?.status.toLowerCase()==="running";t.push(`- ${n.name} (${o?"stop, then remove":"remove"}; source ${A(n.source)})`)}for(let n of e.keep??[])t.push(`= ${n.name} (kept: left running here, source cleared)`);for(let n of e.unmanaged??[]){let o=n.source===void 0?"no source":`source ${A(n.source)}`;t.push(`? ${n.name} (not managed by this apply: ${o})`)}for(let n of e.unchanged)t.push(`= ${n}`);for(let n of e.readOnly)t.push(`! ${n.name} read-only: ${n.reason}`);if(e.hosts!==void 0){for(let n of e.hosts.pending){let o=n.agents.length===0?"no agents":`agents ${n.agents.join(",")}`;t.push(`+ host:${n.name} (pending link: the machine must join; ${o})`)}if(e.hosts.pruneNote!==void 0)t.push(`note: ${e.hosts.pruneNote}`)}if(e.agents!==void 0){for(let n of e.agents.create)t.push(`+ agent:${n.id}`);for(let n of e.agents.change)t.push(`~ agent:${n.id} (${n.changed.join(", ")})`);for(let n of e.agents.remove)t.push(`- agent:${n.id} (source ${n.source===void 0?"unknown":A(n.source)})`);for(let n of e.agents.unchanged)t.push(`= agent:${n}`)}return t}
|
|
2
|
+
export{y,r,S,E,b,k,T};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import"./chunk-dvsftn8z.js";import{t,e}from"./chunk-55a0ndzw.js";var E=`hightea service list (--host HOST --origin URL --workspace SLUG | --local [--host HOST]) [--json]
|
|
2
|
+
`+`hightea service add|change NAME [--command CMD] [--cwd DIR] [--patch JSON] (--host … | --local)
|
|
3
|
+
`+`hightea service remove|start|stop|restart NAME (--host … | --local)
|
|
4
|
+
`+`hightea service logs NAME [--limit N] [--end N] (--host … | --local)
|
|
5
|
+
`+`hightea service acknowledge (--host … | --local)
|
|
6
|
+
`+`hightea service backup --host HOST --origin URL --workspace SLUG [--json]
|
|
7
|
+
hightea service restore [NAME...] --from OLD_HOST (--host NEW_HOST | --local) --origin URL --workspace SLUG [--yes] [--json]
|
|
8
|
+
hightea service enable|disable [--host HOST] (run on the machine)`,O=(n)=>typeof n==="object"&&n!==null&&!Array.isArray(n)&&typeof n.ok==="boolean"?n:void 0;function N(n,o){let r=encodeURIComponent((n.host??"").trim()),l=async(c,s,i,m)=>{let u=await e(n,o,{method:c,path:`/hosts/${r}/services${s}`,what:i,label:"SERVICE",...m===void 0?{}:{body:m}});if("error"in u){let f=O(u.body?.answer);return f===void 0?u:{answer:f}}let g=O(u.answer.answer);return g===void 0?{exit:1,error:`SERVICE_ANSWER_INVALID: ${i} answered without the host's answer: ${JSON.stringify(u.answer).slice(0,300)}`}:{answer:g}},a=(c)=>`/${encodeURIComponent(c)}`;return{machine:(n.host??"").trim(),list:()=>l("GET","","list"),put:(c)=>l("PUT",a(String(c.service.name)),"put",c),remove:(c)=>l("DELETE",a(c.name),"remove",{ifVersion:c.ifVersion}),control:(c,s)=>l("POST",`${a(c)}/${s}`,s),logs:(c)=>{let s=new URLSearchParams;if(c.end!==void 0)s.set("end",String(c.end));if(c.limit!==void 0)s.set("limit",String(c.limit));let i=s.size===0?"":`?${s}`;return l("GET",`${a(c.name)}/logs${i}`,"logs")},acknowledge:(c)=>l("POST","/acknowledge","acknowledge",c)}}async function T(n){let{localHost:o}=await import("./chunk-gbwfgq6g.js"),r=await o(n.host);if("error"in r)return r;let{localServices:l,LOG_LINES_MAX:a}=await import("@hallohuman/hightea-services"),c=l(r.configDir);if(typeof c==="string")return{error:`SERVICE_NOT_CONFIGURED: ${c}`};let s=(i)=>({answer:i});return{machine:c.machine.name,list:async()=>s(c.list()),put:async(i)=>s(await c.put(i)),remove:async(i)=>s(await c.remove(i)),control:async(i,m)=>s(await c.control(i,m)),logs:async(i)=>s(await c.logs({name:i.name,endOffset:i.end??0,limit:Math.min(i.limit??100,a)})),acknowledge:async(i)=>s(await c.acknowledge(i))}}async function J(n,o,r=t(),l={}){let a=!n.local;if(a&&((n.host??"").trim()===""||n.workspace.trim()===""))return r.err(`SERVICE_INPUT: name the host with --host and --workspace, or act on this machine with --local.
|
|
9
|
+
${E}`),1;let c=o.command!=="list"&&o.command!=="acknowledge",s=o.name?.trim()??"";if(c&&s==="")return r.err(`SERVICE_INPUT: ${o.command} names one service.
|
|
10
|
+
${E}`),1;let i=a?N(n,r):await(l.local??T)(n);if("error"in i)return r.err(i.error),1;let m=(u,g)=>{if("error"in u)return r.err(u.error),u.exit;let f=u.answer;if(!f.ok){if(r.err(`${String(f.code??"SERVICE_REFUSED")}: ${String(f.message??"the machine refused")}`),typeof f.diff==="string"&&f.diff!=="")r.err(f.diff);if(n.json)r.out(JSON.stringify(f));return 1}if(n.json)r.out(JSON.stringify(f));else g(f);return 0};switch(o.command){case"list":return m(await i.list(),(u)=>r.out(C(u,i.machine)));case"start":case"stop":case"restart":return m(await i.control(s,o.command),()=>r.out(`${o.command}: ${s} on ${i.machine}`));case"logs":{let u=A(o.end,0),g=A(o.limit,1);if(u===null||g===null)return r.err("SERVICE_INPUT: --end and --limit are whole numbers of lines; --limit is at least 1"),1;let f=await i.logs({name:s,...u===void 0?{}:{end:u},...g===void 0?{}:{limit:g}});return m(f,(w)=>{r.out(`raw output from ${s} on ${i.machine}:`);for(let h of Array.isArray(w.lines)?w.lines:[])r.out(String(h))})}case"acknowledge":case"add":case"change":case"remove":{let u=await i.list();if("error"in u)return r.err(u.error),u.exit;if(!u.answer.ok)return m(u,()=>{});let g=String(u.answer.ifVersion??""),w=(Array.isArray(u.answer.services)?u.answer.services:[]).some((d)=>d.name===s);if(o.command==="acknowledge"){let d=u.answer.hashes??{};return m(await i.acknowledge({hashes:d}),()=>r.out(`acknowledged ${Object.keys(d).join(", ")||"no files"} on ${i.machine} as they are now`))}if(o.command==="remove")return m(await i.remove({name:s,ifVersion:g}),()=>r.out(`removed ${s} on ${i.machine}`));if(o.command==="add"&&w)return r.err(`SERVICE_EXISTS: ${s} is already a service on ${i.machine}; use \`hightea service change\``),1;if(o.command==="change"&&!w)return r.err(`SERVICE_NOT_FOUND: ${s} is not a service on ${i.machine}; use \`hightea service add\``),1;let h=j(s,o.fields??{});if(typeof h==="string")return r.err(`SERVICE_INPUT: ${h}`),1;let y=P(u.answer.capabilities,h,i.machine);if(y!==void 0)return r.err(`SERVICE_UNSUPPORTED: ${y} Nothing was sent.`),1;if(o.command==="add"&&h.command===void 0)return r.err("SERVICE_INPUT: a new service needs --command"),1;return m(await i.put({service:h,ifVersion:g}),(d)=>r.out(d.changed===!1?`${s} on ${i.machine} already reads so; nothing was written`:`${o.command==="add"?"added":"changed"} ${s} on ${i.machine}`))}}}function j(n,o){let r={};if(o.patch!==void 0){try{r=JSON.parse(o.patch)}catch{return"--patch is a JSON object of service fields"}if(typeof r!=="object"||r===null||Array.isArray(r))return"--patch is a JSON object of service fields";if(r.name!==void 0&&r.name!==n)return"--patch names another service"}return{...r,name:n,...o.command===void 0?{}:{command:o.command},...o.cwd===void 0?{}:{cwd:o.cwd}}}function P(n,o,r){if(typeof n!=="object"||n===null)return;let{fields:l,schedule:a}=n;if(Array.isArray(l)){let s=Object.keys(o).filter((i)=>!l.includes(i));if(s.length>0)return`${r}'s driver does not take ${s.join(", ")}; it takes ${l.join(", ")}.`}let c=o.schedule;if(Array.isArray(a)&&typeof c==="object"&&c!==null){let i=Object.keys(c).filter((m)=>m==="cron"||m==="interval").filter((m)=>!a.includes(m));if(i.length>0)return`${r}'s driver does not take ${i.map((m)=>`schedule.${m}`).join(", ")}; it takes ${a.map((m)=>`schedule.${String(m)}`).join(", ")}.`}return}function A(n,o){if(n===void 0)return;return/^\d{1,7}$/u.test(n.trim())&&Number(n)>=o?Number(n):null}function C(n,o){let r=Array.isArray(n.services)?n.services:[],l=Array.isArray(n.readOnly)?n.readOnly:[],a=r.map((s)=>{let i=Array.isArray(s.plainEnv)&&s.plainEnv.length>0?` (plain env: ${s.plainEnv.join("; ")})`:"";return`${String(s.name)} ${String(s.command??"")}${i}`});for(let s of l)a.push(`${String(s.name)} read-only: ${String(s.reason)}`);if(a.length===0)a.push(`no services on ${o} (${String(n.file??"its file")})`);let c=U(n);if(c.length>0){a.push(`drift on ${o} (${c.length}), shown only; nothing was repaired:`);for(let s of c)a.push(` ${s.level}: ${s.text}`)}return a.join(`
|
|
11
|
+
`)}function U(n){let o=(l)=>(Array.isArray(l)?l:[]).filter((a)=>p(a)&&typeof a.text==="string").map((a)=>({level:typeof a.level==="string"?a.level:"warning",text:String(a.text)})),r=Array.isArray(n.rows)?n.rows:[];return[...o(n.alerts),...r.flatMap((l)=>p(l)?o(l.alerts):[])]}var p=(n)=>typeof n==="object"&&n!==null&&!Array.isArray(n);async function x(n,o,r){let l=await e(n,o,{method:"GET",path:`/hosts/${encodeURIComponent(r)}/services/backup`,what:"backup",label:"SERVICE"});if("error"in l)return l;let a=l.answer.backup;if(!p(a)||typeof a.label!=="string"||!p(a.listing)||!Array.isArray(a.lines))return{exit:1,error:`SERVICE_ANSWER_INVALID: backup answered without a backup: ${JSON.stringify(l.answer).slice(0,300)}`};return{backup:a}}function D(n){if(n.unreadable===!0)return`unreadable line at ${String(n.offset)} (${String(n.bytes)} bytes)`;if(n.boundary===!0)return`--- ${String(n.message)} ---`;let o=p(n.refused)?` refused ${String(n.refused.code)}`:"",r=typeof n.name==="string"&&n.name!==""?` ${n.name}`:"";return`${String(n.at??"")} ${String(n.principal??"")} ${String(n.op??"")}${r}${o}`}async function H(n,o=t()){let r=(n.host??"").trim();if(r===""||n.workspace.trim()===""||n.local)return o.err(`SERVICE_INPUT: name the host with --host and --workspace; a backup is read from Hightea, never --local.
|
|
12
|
+
${E}`),1;let l=await x(n,o,r);if("error"in l)return o.err(l.error),l.exit;let{backup:a}=l;if(n.json)return o.out(JSON.stringify(a)),0;let c=a.hostStatus==="revoked"?`revoked ${a.revokedAt??""}`.trim():a.connected?"connected":"offline";if(o.out(`${r} (${c}): ${a.label}`),typeof a.reason==="string")o.out(`last pull: ${a.reason}`);o.out(C({ok:!0,...a.listing},r)),o.out(a.lines.length===0?"no changes backed up":`changes, oldest first (${a.lines.length}):`);for(let{line:s}of a.lines)o.out(` ${D(s)}`);return 0}function L(){return{...t(),confirm:async(n)=>{let{createInterface:o}=await import("node:readline/promises"),r=o({input:process.stdin,output:process.stderr});try{return/^y(es)?$/iu.test((await r.question(n)).trim())}finally{r.close()}}}}async function B(n,o,r=L(),l={}){let a=o.from.trim(),c=(n.host??"").trim();if(a===""||n.workspace.trim()===""||!n.local&&c==="")return r.err(`SERVICE_INPUT: restore names the old host with --from, the workspace with --workspace, and the new host with --host or --local.
|
|
13
|
+
${E}`),1;let s=await x(n,r,a);if("error"in s)return r.err(s.error),s.exit;let{backup:i}=s,m=Array.isArray(i.listing.services)?i.listing.services.filter(p):[],u=o.names.filter((d)=>!m.some((S)=>S.name===d));if(u.length>0)return r.err(`SERVICE_NOT_IN_BACKUP: ${u.join(", ")} ${u.length===1?"is":"are"} not in ${a}'s backup (${i.label}); it holds ${m.map((d)=>String(d.name)).join(", ")||"no services"}`),1;let g=o.names.length===0?m:m.filter((d)=>o.names.includes(String(d.name)));if(g.length===0)return r.err(`SERVICE_NOTHING_TO_RESTORE: ${a}'s backup (${i.label}) holds no services`),1;let f=n.local?await(l.local??T)(n):N(n,r);if("error"in f)return r.err(f.error),1;let w=(d)=>p(d.env)?Object.entries(d.env).map(([S,v])=>`${S} (${String(p(v)?v.$secret:v)})`):[],h=(d)=>Array.isArray(d.plainEnv)?d.plainEnv.map(String):[];r.err(`restore from ${a} (${i.label}) to ${f.machine}, create only:`);for(let d of g){r.err(` ${String(d.name)} ${String(d.command??"")}`);let S=w(d);if(S.length>0)r.err(` secrets to enter again on ${f.machine}: ${S.join(", ")}`)}if(!o.yes&&!await r.confirm(`create ${g.length} service${g.length===1?"":"s"} on ${f.machine}? [y/N] `))return r.err("SERVICE_RESTORE_DECLINED: nothing was sent"),1;let y=[];for(let d of g){let{plainEnv:S,...v}=d,R=String(d.name),b=w(d),I=h(d),k=await f.put({service:v,ifVersion:"absent"});if("error"in k){let[V="SERVICE_FAILED",..._]=k.error.split(": ");y.push({name:R,outcome:"failed",code:V,message:_.join(": "),secrets:b,plainEnv:I})}else if(!k.answer.ok)y.push({name:R,outcome:"refused",code:String(k.answer.code??"SERVICE_REFUSED"),message:String(k.answer.message??""),secrets:b,plainEnv:I});else y.push({name:R,outcome:"created",secrets:b,plainEnv:I})}if(n.json)r.out(JSON.stringify({from:a,to:f.machine,label:i.label,results:y}));else for(let d of y){if(r.out(d.outcome==="created"?`created ${d.name}`:`${d.outcome} ${d.name}: ${d.code}: ${d.message}`),d.outcome==="created"&&d.secrets.length>0)r.out(` secrets to enter again: ${d.secrets.join(", ")}`);if(d.outcome==="created"&&d.plainEnv.length>0)r.out(` plain values never backed up: ${d.plainEnv.join("; ")}`)}return y.every((d)=>d.outcome==="created")?0:1}export{H as serviceBackupCommand,J as serviceCommand,B as serviceRestore};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{s,f,I,v,N}from"./chunk-dvsftn8z.js";export{I as authLogin,N as authLogout,v as authStatus,s as checkedOrigin,f as ensureCredential};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import"./chunk-
|
|
1
|
+
import"./chunk-dvsftn8z.js";import{t,e}from"./chunk-55a0ndzw.js";var u=`hightea source bind --origin https://your-deployment --workspace SLUG --source SOURCE --host HOST [--refresh 1h] [--session-file FILE] [--json]
|
|
2
2
|
hightea source bind-linear --origin https://your-deployment --workspace SLUG --team TEAM [--refresh 5m] [--session-file FILE] [--json]
|
|
3
3
|
hightea source teams --origin https://your-deployment --workspace SLUG [--session-file FILE] [--json]
|
|
4
4
|
hightea source unbind --origin https://your-deployment --workspace SLUG --source SOURCE [--session-file FILE] [--json]
|
package/dist/plugin/plugin.json
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "hightea-pipe",
|
|
3
3
|
"main": "./plugin.mjs",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.32",
|
|
5
5
|
"grants": [
|
|
6
6
|
"session:write",
|
|
7
7
|
"session:state",
|
|
8
8
|
"session:list",
|
|
9
9
|
"chat:turns",
|
|
10
10
|
"agent:list"
|
|
11
|
+
],
|
|
12
|
+
"callerGrants": [
|
|
13
|
+
"records:read"
|
|
11
14
|
]
|
|
12
15
|
}
|