@hallohuman/hightea 0.1.30 → 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/LICENSE +5 -0
- package/dist/bin.js +30 -362
- 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-dvsftn8z.js +5 -0
- 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-wyzpk81n.js +13 -0
- package/dist/plugin/plugin.json +4 -1
- package/dist/plugin/plugin.mjs +51 -15364
- package/package.json +2 -1
- package/dist/chunk-0ab6h39c.js +0 -402
- package/dist/chunk-0r70ekxd.js +0 -8
- package/dist/chunk-13tpn1g6.js +0 -465
- package/dist/chunk-3rgfnt23.js +0 -16
- package/dist/chunk-5mezgvms.js +0 -139
- package/dist/chunk-9e325ntw.js +0 -89
- package/dist/chunk-cx3yvvkz.js +0 -7295
- package/dist/chunk-d5h204vj.js +0 -14
- package/dist/chunk-dvnzt54t.js +0 -7168
- package/dist/chunk-dvt4hb8z.js +0 -1491
- package/dist/chunk-gk8tyqac.js +0 -184
- package/dist/chunk-h8pdqn31.js +0 -157
- package/dist/chunk-ph04jess.js +0 -17
- package/dist/chunk-sbqmqp8e.js +0 -123
- package/dist/chunk-w0ebwtch.js +0 -161
- package/dist/chunk-y5r2yxx1.js +0 -347
|
@@ -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};
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
hightea source bind-linear --origin https://your-deployment --workspace SLUG --team TEAM [--refresh 5m] [--session-file FILE] [--json]
|
|
3
|
+
hightea source teams --origin https://your-deployment --workspace SLUG [--session-file FILE] [--json]
|
|
4
|
+
hightea source unbind --origin https://your-deployment --workspace SLUG --source SOURCE [--session-file FILE] [--json]
|
|
5
|
+
hightea source set-refresh --origin https://your-deployment --workspace SLUG --source SOURCE --every 1h [--session-file FILE] [--json]
|
|
6
|
+
hightea source show --origin https://your-deployment --workspace SLUG --source SOURCE [--session-file FILE] [--json]`;function l(n){let r=n.trim().toLowerCase();if(r==="")return"INVALID";if(r==="none"||r==="off")return null;let o=/^(\d+)(s|m|h|d)$/u.exec(r);if(o===null)return"INVALID";let s={s:1000,m:60000,h:3600000,d:86400000}[o[2]],i=Number(o[1])*s;return Number.isSafeInteger(i)&&i>0?i:"INVALID"}var f={SOURCE_BINDING_CONFLICT:4};function a(){return t()}async function h(n,r,o){if(n.workspace.trim().length===0||n.source.trim().length===0)return{exit:1,error:`SOURCE_INPUT: --workspace and --source are required.
|
|
7
|
+
${u}`};return e(n,r,{...o,label:"SOURCE",extraExits:f,path:`/sources/${encodeURIComponent(n.source)}${o.path}`})}function d(n){let r=(s)=>n[s]===null||n[s]===void 0?"none":String(n[s]),o=n.listing===!0?", first list running":n.listing===!1?", no list running":"";return`${r("status")} on ${r("hostId")} as dataset ${r("dataset")} (freshness ${r("freshness")}${o})`}async function S(n,r=a()){if(n.host.trim().length===0)return r.err(`SOURCE_INPUT: --host is required (the host id that serves the source).
|
|
8
|
+
${u}`),1;let o=n.refresh===void 0?void 0:l(n.refresh);if(o==="INVALID"||o===null)return r.err(`SOURCE_INPUT: --refresh takes a whole count and one unit — 30m, 1h, 2d — and a bind never clears a schedule.
|
|
9
|
+
${u}`),1;let s=await h(n,r,{method:"POST",path:"/bind",body:o===void 0?{hostId:n.host.trim()}:{hostId:n.host.trim(),refreshMs:o},what:"bind"});if("error"in s)return r.err(s.error),s.exit;if(n.json)return r.out(JSON.stringify(s.answer)),0;let i=s.answer.source??{};return r.out(`bound ${String(i.sourceId??n.source)} to ${String(i.hostId??n.host)}: ${d(i)}`),r.out("The source's first list fills its dataset; run `hightea source show` to watch its freshness."),0}async function w(n,r=a()){let o=n.team.trim();if(n.workspace.trim().length===0||o.length===0)return r.err(`SOURCE_INPUT: --workspace and --team are required (the Linear team id; \`hightea source teams\` lists them).
|
|
10
|
+
${u}`),1;let s=n.refresh===void 0?void 0:l(n.refresh);if(s==="INVALID"||s===null)return r.err(`SOURCE_INPUT: --refresh takes a whole count and one unit — 5m, 1h, 2d — and a bind never clears a schedule.
|
|
11
|
+
${u}`),1;let i=await e(n,r,{method:"POST",label:"SOURCE",extraExits:f,path:`/linear/teams/${encodeURIComponent(o)}/bind`,body:s===void 0?{}:{refreshMs:s},what:"bind-linear"});if("error"in i)return r.err(i.error),i.exit;if(n.json)return r.out(JSON.stringify(i.answer)),0;let c=i.answer.source??{};return r.out(`bound Linear team ${o} as ${String(c.sourceId??`linear:${o}`)}: ${d(c)}`),r.out("The first sweep is queued with the binding; `hightea source show` watches its freshness."),0}async function p(n,r=a()){let o=await e(n,r,{method:"GET",label:"SOURCE",extraExits:f,path:"/linear/teams",what:"teams"});if("error"in o)return r.err(o.error),o.exit;if(n.json)return r.out(JSON.stringify(o.answer)),0;let s=o.answer.teams??[];if(s.length===0)return r.out("Linear sees no teams for this workspace's token; authorize Linear first."),0;for(let i of s)r.out(`${String(i.id)} ${String(i.key)} ${String(i.name)}`);return 0}async function g(n,r=a()){let o=await h(n,r,{method:"POST",path:"/unbind",what:"unbind"});if("error"in o)return r.err(o.error),o.exit;if(n.json)return r.out(JSON.stringify(o.answer)),0;let s=o.answer.source??{};return r.out(`unbound ${String(s.sourceId??n.source)} from ${String(s.hostId??"its host")}: ${d(s)}`),r.out("Rows kept; rebind refreshes them."),0}async function y(n,r=a()){let o=await h(n,r,{method:"GET",path:"",what:"read"});if("error"in o)return r.err(o.error),o.exit;if(n.json)return r.out(JSON.stringify(o.answer)),0;let s=o.answer.source??{},i=s.position;return r.out(`${String(s.sourceId??n.source)}: ${d(s)}`),r.out(`position ${i===null||i===void 0?"none":`${String(i.epoch)}/${String(i.ordinal)}`}, last error ${s.lastError===null||s.lastError===void 0?"none":String(s.lastError)}, dropped ${String(s.dropped??0)}, duplicates ${String(s.duplicates??0)}`),0}async function I(n,r=a()){if(n.every.trim().length===0)return r.err(`SOURCE_INPUT: --every is required (1h, 30m, 2d, or none).
|
|
12
|
+
${u}`),1;let o=l(n.every);if(o==="INVALID")return r.err(`SOURCE_INPUT: --every takes a whole count and one unit — 45s, 30m, 1h, 2d — or none.
|
|
13
|
+
${u}`),1;let s=await h(n,r,{method:"POST",path:"/schedule",body:{everyMs:o},what:"set its refresh interval"});if("error"in s)return r.err(s.error),s.exit;if(n.json)return r.out(JSON.stringify(s.answer)),0;let i=s.answer.source??{},c=i.reconcileMs===null||i.reconcileMs===void 0?"no schedule (refreshes only when the host reports a gap)":`refresh every ${Math.round(Number(i.reconcileMs)/60000)} min`;return r.out(`${String(i.sourceId??n.source)}: ${c}; ${d(i)}`),0}export{S as sourceBind,w as sourceBindLinear,I as sourceSetRefresh,y as sourceShow,p as sourceTeams,g as sourceUnbind};
|
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
|
}
|