werkmeister 0.93.5 → 0.93.7
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/budget-CDZF7WAA.js +4 -0
- package/dist/{cache-VT7GBHR2.js → cache-CM5A6RX6.js} +2 -2
- package/dist/{chunk-CT5ZOPSZ.js → chunk-3B3Y2ZCY.js} +2 -2
- package/dist/{chunk-ZDES3QTI.js → chunk-425KLJUM.js} +2 -2
- package/dist/chunk-46UPT6E4.js +43 -0
- package/dist/{chunk-KVUJVYPS.js → chunk-4LDSXD4V.js} +2 -2
- package/dist/{chunk-ASZUX3IC.js → chunk-5GF3MYUC.js} +2 -2
- package/dist/{chunk-ZIQQKTQL.js → chunk-64Y2E3MH.js} +2 -2
- package/dist/{chunk-AXMV4XZL.js → chunk-6HMEQ75K.js} +2 -2
- package/dist/{chunk-TKQ5HXSL.js → chunk-6JGCAD3L.js} +2 -2
- package/dist/{chunk-IAXCJW3Y.js → chunk-6S3DONTF.js} +2 -2
- package/dist/{chunk-V6ABNI4V.js → chunk-6TUZKO7O.js} +2 -2
- package/dist/{chunk-KIZ25SQA.js → chunk-AHEEIMKV.js} +3 -3
- package/dist/{chunk-UIHG7MJY.js → chunk-AI74Y2N6.js} +6 -6
- package/dist/{chunk-YXHHBENO.js → chunk-BBM2J5K4.js} +3 -3
- package/dist/{chunk-2YAWKN4B.js → chunk-BTVLOG7I.js} +2 -2
- package/dist/{chunk-ZUL6VITT.js → chunk-C4LKFK4W.js} +2 -2
- package/dist/{chunk-YJNUGHQC.js → chunk-C6ZSGKIL.js} +2 -2
- package/dist/{chunk-S6BMUOIS.js → chunk-CSXROZTW.js} +2 -2
- package/dist/{chunk-GK2EJLFI.js → chunk-CUSUDZYU.js} +20 -20
- package/dist/{chunk-OB2ENKLA.js → chunk-D3SKYBS2.js} +2 -2
- package/dist/{chunk-T7GQISYS.js → chunk-DOKRZG4F.js} +2 -2
- package/dist/{chunk-CYUCIEOU.js → chunk-DXNCTLX7.js} +2 -2
- package/dist/{chunk-TSQUAG3D.js → chunk-DYXLKAWL.js} +2 -2
- package/dist/{chunk-QQ6BITFP.js → chunk-FGG3WG6U.js} +2 -2
- package/dist/chunk-FPELCH3B.js +82 -0
- package/dist/{chunk-XFJ6IA6A.js → chunk-G3QGLNVJ.js} +2 -2
- package/dist/{chunk-GVAGLIEH.js → chunk-HPKFXOK4.js} +2 -2
- package/dist/{chunk-RXOXD4KA.js → chunk-ICGEKJEU.js} +2 -2
- package/dist/{chunk-K6LZ6MYO.js → chunk-IT2WX7OL.js} +2 -2
- package/dist/{chunk-6EEGEZLE.js → chunk-JPSOT3UD.js} +2 -2
- package/dist/{chunk-K6FB7R3Q.js → chunk-K2KMJOXU.js} +3 -3
- package/dist/{chunk-K4ZH6HZB.js → chunk-K3BFBBN2.js} +2 -2
- package/dist/{chunk-WZXSZF5H.js → chunk-KPM6JPOX.js} +2 -2
- package/dist/{chunk-6MPWPONJ.js → chunk-KUGCKCGK.js} +2 -2
- package/dist/{chunk-MEA4YAAA.js → chunk-KWUXS2Q7.js} +2 -2
- package/dist/{chunk-TXZ3WERB.js → chunk-LYJPUDGR.js} +2 -2
- package/dist/{chunk-EP6B44PA.js → chunk-MZWQPHMY.js} +2 -2
- package/dist/chunk-N2CABQDG.js +4 -0
- package/dist/chunk-N6K27EGE.js +137 -0
- package/dist/{chunk-6REQWPAV.js → chunk-NWBQFKAY.js} +2 -2
- package/dist/{chunk-XMPFPQR7.js → chunk-NYSHEC6J.js} +2 -2
- package/dist/{chunk-67CKCUOX.js → chunk-O2QUWSMC.js} +2 -2
- package/dist/{chunk-KA2NIJJG.js → chunk-OCAJL5N2.js} +2 -2
- package/dist/{chunk-4SK2WDFU.js → chunk-OFA2CMOB.js} +2 -2
- package/dist/{chunk-CMXQQKD3.js → chunk-PI3NHMYM.js} +2 -2
- package/dist/{chunk-PMHCVUVZ.js → chunk-PLNDHVPI.js} +2 -2
- package/dist/{chunk-NILGDPG6.js → chunk-PXSFA2ZJ.js} +2 -2
- package/dist/{chunk-FCE6GV5P.js → chunk-QS3JZSFP.js} +61 -59
- package/dist/{chunk-PN7ZUG3R.js → chunk-RBHU6MP6.js} +2 -2
- package/dist/{chunk-XKMV6M6E.js → chunk-RK54J7VX.js} +2 -2
- package/dist/chunk-S6YZIRMD.js +4 -0
- package/dist/{chunk-MO2LKTAN.js → chunk-SV3LFH6S.js} +2 -2
- package/dist/{chunk-4FGT5BTG.js → chunk-TGWVNFQD.js} +2 -2
- package/dist/{chunk-NWLMPCZE.js → chunk-TJ5BFKRS.js} +2 -2
- package/dist/chunk-U5DPXZVY.js +12 -0
- package/dist/{chunk-THGF3KVB.js → chunk-UH2WQRMS.js} +2 -2
- package/dist/{chunk-WIMNMYJZ.js → chunk-UO5PTDO7.js} +2 -2
- package/dist/{chunk-4ADQJ3NO.js → chunk-UWACLY2H.js} +2 -2
- package/dist/{chunk-GWQPTTUF.js → chunk-UZV4V46V.js} +2 -2
- package/dist/{chunk-FQRFNYV3.js → chunk-V3L2WH76.js} +2 -2
- package/dist/{chunk-CWEZ7RUW.js → chunk-VD4KZXIS.js} +2 -2
- package/dist/{chunk-6FXTI2WZ.js → chunk-WIN5Y2R3.js} +2 -2
- package/dist/{chunk-V7Z5RKSZ.js → chunk-XLXZNUMS.js} +2 -2
- package/dist/{chunk-OSXCWDE3.js → chunk-XW3SCZHA.js} +2 -2
- package/dist/chunk-YBUVVNO7.js +113 -0
- package/dist/{chunk-VJDVYESQ.js → chunk-ZXNZJ7TC.js} +2 -2
- package/dist/clean-2VHOC4EG.js +8 -0
- package/dist/close_out-4AOTWTQP.js +8 -0
- package/dist/code-YA7NUBKZ.js +4 -0
- package/dist/config-Z2NNLCXP.js +4 -0
- package/dist/{connect-LUMP5WGL.js → connect-56RUSFMA.js} +2 -2
- package/dist/daemon-7RDZHU6Z.js +4 -0
- package/dist/dashboard.js +4 -4
- package/dist/{detect-YLGSUUK6.js → detect-WA7KHWIT.js} +2 -2
- package/dist/{down-GCO7CXP2.js → down-2TNSAVGV.js} +3 -3
- package/dist/{fixture-3PYLA2QP.js → fixture-DEXVYXVK.js} +5 -5
- package/dist/form-cli.js +1 -1
- package/dist/hooks-WR273L27.js +4 -0
- package/dist/hooks_gen-R47F5EJ4.js +4 -0
- package/dist/infra-J7CIK4LH.js +4 -0
- package/dist/init_workspace-7SSXM35S.js +4 -0
- package/dist/intercept-LF47RSZZ.js +7 -0
- package/dist/{issue-KSQLNFFN.js → issue-XGIB5DLS.js} +2 -2
- package/dist/lib/agent_state.js +1 -1
- package/dist/lib/gate.js +1 -1
- package/dist/lib/pr_guard.js +1 -1
- package/dist/list_workspaces-E5K7F777.js +7 -0
- package/dist/logs-J527F4C3.js +6 -0
- package/dist/main.js +5 -4
- package/dist/mcp-proxy.js +1 -1
- package/dist/mcp.js +6 -6
- package/dist/migrate-UMOIXI3W.js +8 -0
- package/dist/notes-5IGVLEMC.js +4 -0
- package/dist/open-4L3HUGQ5.js +6 -0
- package/dist/{optimize-EZQC25XK.js → optimize-YDOMF4L2.js} +2 -2
- package/dist/pause-ERVAGQJE.js +4 -0
- package/dist/pr-LUGEOHMR.js +5 -0
- package/dist/proxy_reload-JE5M5CFI.js +6 -0
- package/dist/{registry-NTJQLH6O.js → registry-3HCIPVGM.js} +2 -2
- package/dist/remove-LLDAJMON.js +7 -0
- package/dist/remove_workspace-QO3SHIJ4.js +8 -0
- package/dist/restart-HTILAXC2.js +8 -0
- package/dist/resume-4D2RIRTU.js +8 -0
- package/dist/{safari-KIIBWIP4.js → safari-IDOFC6ZA.js} +2 -2
- package/dist/sandbox-7M5ICEJV.js +4 -0
- package/dist/{services-YOJGXYRZ.js → services-UWNSP3KX.js} +2 -2
- package/dist/{setup-PMD3POPQ.js → setup-2UOCIH2Y.js} +2 -2
- package/dist/skills-ITFUNVFD.js +4 -0
- package/dist/slots-W5KNA2KJ.js +4 -0
- package/dist/{standards-GRSOC6KW.js → standards-25UDZCS4.js} +2 -2
- package/dist/start_args-6WVHVPU6.js +4 -0
- package/dist/starting_prompt-R7RFEUOM.js +4 -0
- package/dist/stats-MYZXBYUF.js +4 -0
- package/dist/status-L555BVSM.js +13 -0
- package/dist/stop-UK6AOWBE.js +9 -0
- package/dist/telepresence-MM45AMTK.js +4 -0
- package/dist/{test-2YV4BCIU.js → test-O6OGOKNI.js} +2 -2
- package/dist/{tokens-SPHIRGGH.js → tokens-K3NGN4UH.js} +2 -2
- package/dist/up-HJ6D2UF6.js +12 -0
- package/dist/{v4-VGZU4RUI.js → v4-L3JEJBY7.js} +2 -2
- package/dist/wait_load-RDGCQXIQ.js +4 -0
- package/dist/werkmeister-workspaces.vsix +0 -0
- package/dist/workspace-5Y7MOMUQ.js +4 -0
- package/package.json +3 -3
- package/dist/budget-PGVVUWSC.js +0 -4
- package/dist/chunk-5RTBQAT7.js +0 -43
- package/dist/chunk-7D7R3M4U.js +0 -111
- package/dist/chunk-A7TH7DWD.js +0 -4
- package/dist/chunk-ER73PEUY.js +0 -12
- package/dist/chunk-RAHGSCT6.js +0 -4
- package/dist/chunk-VI7SAKRI.js +0 -82
- package/dist/chunk-WNCAJR6C.js +0 -137
- package/dist/chunk-WWR2XBXR.js +0 -4
- package/dist/clean-UMHA2CZW.js +0 -8
- package/dist/close_out-6QIFICEY.js +0 -8
- package/dist/code-KPLG4S4Q.js +0 -4
- package/dist/config-GFQPPHSQ.js +0 -4
- package/dist/daemon-2GYHL7NR.js +0 -4
- package/dist/hooks-A2N7MOHQ.js +0 -4
- package/dist/hooks_gen-33QXMNK3.js +0 -4
- package/dist/infra-BJBFWNYC.js +0 -4
- package/dist/init_workspace-KNZPCZ7S.js +0 -4
- package/dist/intercept-V4WSD2HC.js +0 -7
- package/dist/list_workspaces-OSB3UOFL.js +0 -7
- package/dist/logs-AXUBC2A5.js +0 -6
- package/dist/migrate-M6L2DJNT.js +0 -8
- package/dist/notes-LYRXRKH6.js +0 -4
- package/dist/open-EC7WIO6M.js +0 -6
- package/dist/pause-3E3MFPFK.js +0 -4
- package/dist/pr-XWM6Z626.js +0 -5
- package/dist/proxy_reload-FFFETHCF.js +0 -6
- package/dist/remove-WJQRF6YC.js +0 -7
- package/dist/remove_workspace-L7636Q7E.js +0 -8
- package/dist/restart-DBUOKL72.js +0 -8
- package/dist/resume-37G4RFXR.js +0 -8
- package/dist/sandbox-W5W6PZP2.js +0 -4
- package/dist/skills-GNYIC2MO.js +0 -4
- package/dist/slots-C7ZEGGJ4.js +0 -4
- package/dist/start_args-LH56QN7T.js +0 -4
- package/dist/starting_prompt-4YEXCGD3.js +0 -4
- package/dist/stats-XWSD26T3.js +0 -4
- package/dist/status-MFH7DYEC.js +0 -13
- package/dist/stop-HR4IXTQF.js +0 -9
- package/dist/telepresence-R5BVS2K3.js +0 -4
- package/dist/up-JBNSO2TH.js +0 -12
- package/dist/wait_load-FRLSYOSG.js +0 -4
- package/dist/workspace-77ZSJKH6.js +0 -4
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { createRequire as __sandboxCreateRequire } from "node:module";
|
|
2
|
+
const require = __sandboxCreateRequire(import.meta.url);
|
|
3
|
+
import{d as v,m as L}from"./chunk-46UPT6E4.js";import"./chunk-TJ5BFKRS.js";import"./chunk-AI74Y2N6.js";import"./chunk-64Y2E3MH.js";import"./chunk-KPM6JPOX.js";import"./chunk-V3L2WH76.js";import"./chunk-BBM2J5K4.js";import"./chunk-BTVLOG7I.js";import"./chunk-UO5PTDO7.js";import"./chunk-QS3JZSFP.js";import"./chunk-DXNCTLX7.js";import"./chunk-SV3LFH6S.js";import"./chunk-6TUZKO7O.js";import"./chunk-S6YZIRMD.js";import"./chunk-CUSUDZYU.js";import"./chunk-FPELCH3B.js";import"./chunk-ICGEKJEU.js";import"./chunk-DOKRZG4F.js";import{B as h,C as w,I as b,L as y,Q as k,v as f,w as $}from"./chunk-OFA2CMOB.js";import"./chunk-UWACLY2H.js";import"./chunk-JPSOT3UD.js";import"./chunk-6HMEQ75K.js";import"./chunk-KUGCKCGK.js";import{p as d}from"./chunk-U5DPXZVY.js";import"./chunk-6S3DONTF.js";import"./chunk-425KLJUM.js";import"./chunk-PI3NHMYM.js";import"./chunk-O2QUWSMC.js";import"./chunk-MZWQPHMY.js";import"./chunk-K3BFBBN2.js";import"./chunk-PXSFA2ZJ.js";import{a as c,f as g}from"./chunk-C4LKFK4W.js";g();import N from"node:os";var M=2**30,x=c((r,t)=>Number.isFinite(r)?`${Number(r.toFixed(1))}${t}`:"no limit","limit");async function P(r){let t=await h(),m=w(N.cpus().length),u=$(),l=await k(),n=L(),a=f(y(l,n??[])).map((o,e)=>{let s=u[o.feature]?.workspace,i=s&&d(s)?.services||null,B=s?b(s,i??void 0):null;return{...o,position:e+1,services:i,cost:B}});if(r.json){let o=c(e=>Number.isFinite(e)?e:null,"n");console.log(JSON.stringify({budget:{memory:o(t.memory),cpus:o(t.cpus),preempt:t.preempt},host_load:m,leases:u,waiting:l,running:n?.map(e=>({feature:e.feature,cpus:e.cost.cpus,memory:e.cost.memory,rank:e.rank,busy:e.busy}))??null,waiters:a.map(e=>({feature:e.feature,position:e.position,services:e.services,cpus:e.cost?.cpus??null,memory:e.cost?.memory??null,waited_ms:e.waitedMs,gate:e.gate}))}));return}console.log(`Budget: ${x(t.memory/M," GiB")} memory, ${x(t.cpus," CPUs")}, host load ${m||"unchecked"}, preemption ${t.preempt?"on":"off"}`);let p=Object.entries(u).sort(([,o],[,e])=>o.slot-e.slot);console.log(p.length?"Slots:":"Slots: none held");for(let[o,e]of p)console.log(` ${e.slot} ${o}${e.workspace?` ${e.workspace}`:""}`);console.log(n?n.length?"Running:":"Running: none":"Running: docker unavailable");for(let o of[...n??[]].sort((e,s)=>s.cost.cpus-e.cost.cpus))console.log(` ${v(o)}`);console.log(a.length?"Waiting:":"Waiting: none");for(let o of a){let e=o.services?`${o.services.join(", ")}${o.gate?" for a running feature":""}`:"whole feature",s=o.cost?` (${Number(o.cost.cpus.toFixed(1))} CPUs, ${(o.cost.memory/M).toFixed(1)} GiB)`:"",i=o.waitedMs?` waited ${Math.round(o.waitedMs/6e4)} min${o.position===1&&o.waitedMs>=3e5?", gets the next free room":""}`:"";console.log(` ${o.position}. ${o.feature} ${e}${s}${i}`)}}c(P,"run");export{P as run};
|
|
4
|
+
//# sourceMappingURL=budget-CDZF7WAA.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { createRequire as __sandboxCreateRequire } from "node:module";
|
|
2
2
|
const require = __sandboxCreateRequire(import.meta.url);
|
|
3
|
-
import"./chunk-
|
|
4
|
-
//# sourceMappingURL=cache-
|
|
3
|
+
import"./chunk-N2CABQDG.js";import{d as s}from"./chunk-DXNCTLX7.js";import"./chunk-S6YZIRMD.js";import"./chunk-UWACLY2H.js";import"./chunk-6HMEQ75K.js";import"./chunk-MZWQPHMY.js";import{h as e,l as c}from"./chunk-K3BFBBN2.js";import"./chunk-PXSFA2ZJ.js";import{a as r,f as i}from"./chunk-C4LKFK4W.js";i();async function u(o){o.action!=="prune"&&(c(`Unknown action \`${String(o.action)}\` \u2014 the only action is \`prune\`.`),process.exit(2));let t=await s({name:typeof o.name=="string"?o.name:void 0,reset:!!o.reset,force:!!o.force,dryRun:!!o.dry_run});t.length||console.log("No caches in the registry.");for(let n of t){let a=n.ok?`${e.GREEN}\u2713${e.RESET}`:`${e.RED}\u2717${e.RESET}`;console.log(`${a} ${n.name} (${n.action}): ${n.detail}`)}t.some(n=>!n.ok)&&process.exit(1)}r(u,"run");export{u as run};
|
|
4
|
+
//# sourceMappingURL=cache-CM5A6RX6.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRequire as __sandboxCreateRequire } from "node:module";
|
|
2
2
|
const require = __sandboxCreateRequire(import.meta.url);
|
|
3
|
-
import{b as st}from"./chunk-XFJ6IA6A.js";import{f as _e,g as $e,h as H,i as be}from"./chunk-FQRFNYV3.js";import{a as ve,b as S,c as se,d as K,f as y,g as w,i as ye}from"./chunk-WIMNMYJZ.js";import{r as ke}from"./chunk-67CKCUOX.js";import{A as he,X as ge,a as F,w as ue}from"./chunk-K4ZH6HZB.js";import{a as p,e as M,f as $}from"./chunk-ZUL6VITT.js";$();var ie=M(F(),1);import*as z from"node:fs";import*as oe from"node:path";var re=class extends Error{static{p(this,"AllocationError")}};function Ct(e=he()){try{let t=(0,ie.parse)(z.readFileSync(e,"utf8"))?.feature_slots?.ports_per_slot;return Number.isInteger(t)&&t>0?t:20}catch{return 20}}p(Ct,"portsPerSlot");function ne(e,t){for(let r of["services","infrastructure"])for(let a of Object.values(e?.[r]??{})){if(!a||typeof a!="object")continue;let i=a;Number.isInteger(i.port_offset)&&t.offsets.add(i.port_offset),Number.isInteger(i.k8s_forward_port)&&t.forwards.add(i.k8s_forward_port)}}p(ne,"collect");function xe(e,t,r,a){let i={offsets:new Set,forwards:new Set};for(let n of H(e))oe.resolve(n.path)!==oe.resolve(t)&&ne(n.doc,i);return z.existsSync(r)&&ne((0,ie.parse)(z.readFileSync(r,"utf8"))??null,i),ne(a,i),i}p(xe,"takenPorts");function we(e,t,r){let a=new Set(t),i=new Map;for(let n of[...e].sort()){let s=0;for(;a.has(s);)s++;if(s>=r)throw new re(`port_offset exhausted: ${r} offsets (ports.yaml ports_per_slot) are all used \u2014 raise ports_per_slot or free one`);a.add(s),i.set(n,s)}return i}p(we,"allocateOffsets");function Se(e,t,r=9050){let a=new Set(t),i=new Map;for(let n of[...e].sort()){let s=r;for(;a.has(s);)s++;a.add(s),i.set(n,s)}return i}p(Se,"allocateForwards");var nt=p(e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),"escapeRe");function je(e,t,r){let a={...e},i=[];for(let n of t){let s=a[n];if(s===void 0)continue;let o=s;for(let c of r)o=o.replace(new RegExp(`(?<![\\w.-])${nt(c.host??c.name)}:${c.port}\\b`,"g"),`k8s-${c.name}:${c.forward}`);o!==s&&(a[n]=o,i.push(n))}return{env:a,rewritten:i}}p(je,"rewriteEnv");$();var Ie=M(F(),1);$();$();import*as U from"node:path";var ae={redis:{health:"redis",port:6379},postgres:{health:"postgres",port:5432},postgis:{health:"postgres",port:5432},mysql:{health:"",port:3306},mariadb:{health:"",port:3306},mongo:{health:"",port:27017},rabbitmq:{health:"",port:5672}};function Ae(e){return(e.split("@")[0].split("/").pop()??e).split(":")[0]}p(Ae,"imageRepoName");var Oe=p((e,t)=>e.name.localeCompare(t.name),"byName");function Ee(e){let t=e.image?Ae(e.image):"";return Object.hasOwn(ae,t)?t:null}p(Ee,"datastoreOf");function Ne(e,t){let r=e.filter(f=>f.kind==="package"||f.kind==="dockerfile"),a=e.filter(f=>f.kind==="k8s"||f.kind==="compose"),i=[...new Set(r.map(f=>f.dir))].sort(),n=p(f=>f==="."?t:U.posix.basename(f),"base"),s=p(f=>{let h=U.posix.dirname(f);return h==="."?t:U.posix.basename(h)},"parent"),o=new Map;for(let f of i)o.set(n(f),(o.get(n(f))??0)+1);let c=i.map(f=>({dir:f,name:(o.get(n(f))??0)>1?`${s(f)}-${n(f)}`:n(f),findings:r.filter(h=>h.dir===f)})),u=[(f,h)=>f.kind==="k8s"&&f.dir!==null&&h.dir!=="."&&(f.dir===h.dir||f.dir.startsWith(`${h.dir}/`)),(f,h)=>f.kind==="compose"&&f.dir!==null&&f.dir===h.dir,(f,h)=>f.name===h.name,(f,h)=>!!f.image&&Ae(f.image)===h.name],m=[];for(let f of a){let h=Ee(f)?[u[2]]:u,b;for(let N of h)if(b=c.find(j=>N(f,j)),b)break;b?b.findings.push(f):m.push(f)}let d=[],g=new Map,k=[];for(let f of m){let h=Ee(f);if(h){let b=g.get(f.name)??{name:f.name,datastore:h,findings:[]};b.findings.push(f),g.set(f.name,b)}else{k.push(f);let b=f.kind==="k8s"?"Deployment":"compose service";d.push({item:f.file,reason:`found ${b} ${f.name} \u2014 no source dir in this repo, skipped`})}}return{services:c.filter(f=>{let h=f.findings.some(b=>b.kind!=="package"||b.runnable);return h||d.push({item:f.dir,reason:"library package (no Dockerfile, deploy config or dev/start script), skipped"}),h}).sort(Oe),infrastructure:[...g.values()].sort(Oe),unmatched:k,skipped:d}}p(Ne,"correlate");var ot={type:["package"],archetype:["package"],test:["package"],internal_port:["k8s","compose","dockerfile"],health_endpoint:["k8s","compose"],setup_service:["package"],image:["dockerfile","package"],command:["package","compose","dockerfile"],memory_limit:["k8s"],memory_reservation:["k8s"],node_modules_volume:["package"],secrets:["k8s"],k8s_deployment:["k8s"],k8s_namespace:["k8s"],k8s_port:["k8s"],k8s_port_name:["k8s"],k8s_pod_prefix:["k8s"],feature_router:["k8s"],depends_on:["compose"]},ce=p((e,t)=>JSON.stringify(e)===JSON.stringify(t),"same");function rt(e){return Object.fromEntries(Object.entries(e).sort(([t],[r])=>t.localeCompare(r)))}p(rt,"sortKeys");function Pe(e,t){return Object.assign({},...e.filter(r=>r.kind===t&&r.fields.environment).map(r=>r.fields.environment.value))}p(Pe,"envOf");function V(e){let t={path:y(e.dir,"source directory")},r=[];for(let[o,c]of Object.entries(ot)){let u=c.flatMap(g=>e.findings.filter(k=>k.kind===g&&k.fields[o]!==void 0).map(k=>k.fields[o]));if(!u.length)continue;let m=u[0];if(t[o]=m,m.confidence!=="stated")continue;let d=u.slice(1).filter(g=>g.confidence==="stated"&&!ce(g.value,m.value)).filter((g,k,v)=>v.findIndex(f=>ce(f.value,g.value))===k);d.length&&r.push({service:e.name,key:o,chosen:m,also:d})}t.internal_port??=w(3e3,"no port in any source \u2014 default 3000"),t.health_endpoint??=w("","no readiness probe or healthcheck \u2014 TCP-only"),t.type??=w("api","no package.json \u2014 assumed a service"),t.image??=w("alpine:3","no usable FROM and no package.json \u2014 set the dev image"),!t.feature_router&&t.type.value==="web"&&(t.feature_router=w({},"type: web \u2014 routed through Caddy"));let a=Pe(e.findings,"k8s"),i=Pe(e.findings,"compose"),n={...a,...i};if(Object.keys(n).length){let o=[Object.keys(i).length?"compose environment":"",Object.keys(a).length?"k8s env":""];t.environment=y(rt(n),o.filter(Boolean).join(" + "))}let s=Object.keys(a).filter(o=>!(o in i)).sort();return{name:e.name,dir:e.dir,fields:t,conflicts:r,k8sEnvKeys:s,findings:e.findings}}p(V,"resolveService");function Me(e,t=[]){let r=ae[e.datastore],a=e.findings.filter(o=>o.kind==="k8s"),i=a[0];for(let o of a.slice(1))for(let c of["internal_port","k8s_namespace"]){let u=i.fields[c],m=o.fields[c];u&&m&&!ce(u.value,m.value)&&t.push({item:o.file,reason:`infrastructure ${e.name}: ${c} ${m.value} disagrees with ${u.value} (${u.source}), kept ${u.value}`})}let n=i?.fields.internal_port??e.findings.find(o=>o.fields.internal_port)?.fields.internal_port,s="no k8s manifest for this datastore";return{name:e.name,fields:{internal_port:n??y(r.port,`${e.datastore} default port`),k8s_namespace:i?.fields.k8s_namespace??w("default",s),k8s_pod_prefix:i?.fields.k8s_pod_prefix??w(e.name,s),health_endpoint:y(r.health,r.health?`${e.datastore} wire probe`:"no wire probe for this datastore \u2014 TCP-only")}}}p(Me,"resolveInfra");var Xt={type:"object",required:["answers"],additionalProperties:!1,properties:{answers:{type:"array",items:{type:"object",required:["item","value","reason","files_read"],additionalProperties:!1,properties:{item:{type:"string"},value:{},reason:{type:"string"},files_read:{type:"array",items:{type:"string"}}}}}}};function it(e){let t=e.existing?(0,Ie.parse)(e.existing)??{}:{},r=p((n,s)=>t?.services?.[n]?.[s]!==void 0,"inFile"),a=e.services.map(n=>n.name),i=[];for(let n of e.services){let s=n.fields,o=p((m,d)=>{r(n.name,m)||i.push({id:`${n.name}.${m}`,service:n.name,...d})},"ask");s.command?.confidence==="guessed"&&o("command",{kind:"command",prompt:`What command starts ${n.name} for local development? It runs with the repo root mounted at /app as the working directory.`,facts:{dir:n.dir,guess:s.command.value,why:s.command.source}}),s.health_endpoint?.confidence==="guessed"&&o("health_endpoint",{kind:"health_endpoint",prompt:`Which HTTP path answers 200 when ${n.name} is healthy? Answer "" if it has none.`,facts:{dir:n.dir,port:s.internal_port?.value}});let c=e.envExample[n.name]??[];c.length&&(o("environment",{kind:"environment",prompt:`Which environment variables does ${n.name} need for local development, with development values? Leave secrets out.`,facts:{dir:n.dir,env_example_keys:c,current:s.environment?.value??{}}}),s.secrets||o("secrets",{kind:"secrets",prompt:`Which of these keys must be set for ${n.name} to start at all? A declared secret that is missing stops \`werkmeister feature up\`.`,facts:{dir:n.dir},choices:c}));let u=a.filter(m=>m!==n.name);u.length&&!s.depends_on&&o("depends_on",{kind:"depends_on",prompt:`Which of these services must be running before ${n.name} starts (it calls them at startup)? Answer [] for none.`,facts:{dir:n.dir},choices:u});for(let m of n.conflicts)o(m.key,{kind:"conflict",prompt:`Sources disagree on ${n.name}.${m.key}. Which value is right for local development?`,facts:{sources:[m.chosen,...m.also].map(d=>({value:d.value,source:d.source}))},choices:[m.chosen.value,...m.also.map(d=>d.value)]})}for(let n of[...new Set(e.unmatched.map(s=>s.name))]){let s=e.unmatched.filter(c=>c.name===n),o=s.map(c=>c.file).join(", ");i.push({id:`unmatched.${n}`,kind:"unmatched",service:null,prompt:`${o} define${s.length>1?"":"s"} ${n}, but no source directory matched it. Which service is it? Answer null if its code lives in another repo.`,facts:{files:s.map(c=>c.file),image:s.find(c=>c.image)?.image??null},choices:[...a,null]})}return i}p(it,"collectQuestions");var at=p(e=>!!e&&typeof e=="object"&&!Array.isArray(e)&&Object.values(e).every(t=>typeof t=="string"),"isStringMap"),De=p((e,t)=>Array.isArray(e)&&e.every(r=>typeof r=="string"&&t.includes(r)),"subsetOf"),ct=p((e,t)=>JSON.stringify(e)===JSON.stringify(t),"same");function ft(e,t,r,a){if(r===null)return null;let i=typeof r=="string"?e.services.find(o=>o.name===r):void 0,n=e.unmatched.filter(o=>`unmatched.${o.name}`===t);if(!i||!n.length)return"expected one of this repo's services, or null";let s=V({name:i.name,dir:i.dir,findings:[...i.findings,...n]});for(let[o,c]of Object.entries(s.fields))o in i.fields||(i.fields[o]={...c,confidence:"inferred",source:`${c.source}; matched by Claude: ${a}`});return i.findings.push(...n),e.unmatched=e.unmatched.filter(o=>!n.includes(o)),e.skipped=e.skipped.filter(o=>!n.some(c=>o.item===c.file&&o.reason.includes(` ${c.name} \u2014 `))),null}p(ft,"applyUnmatched");function Qt(e,t){let r=structuredClone(e),a=new Map(it(e).map(o=>[o.id,o])),i=[],n=[],s=new Set;for(let o of t){let c=a.get(o.item);if(!c){n.push({item:o.item,reason:"not one of the questions asked"});continue}if(s.has(o.item)){n.push({item:o.item,reason:"answered twice; kept the first"});continue}s.add(o.item);let u=o.reason?.trim()||"no reason given",m=p(k=>({value:k,source:u,confidence:"inferred"}),"inferred"),d=c.service?r.services.find(k=>k.name===c.service):void 0,g=null;if(c.kind==="unmatched")g=ft(r,c.id,o.value,u);else if(!d)g=`no service named ${c.service} in this plan`;else switch(c.kind){case"command":typeof o.value=="string"&&o.value.trim()?d.fields.command=m(o.value.trim()):g="expected a non-empty command string";break;case"health_endpoint":typeof o.value=="string"&&(o.value===""||o.value.startsWith("/"))?d.fields.health_endpoint=m(o.value):g='expected "" or a path starting with /';break;case"environment":{if(!at(o.value)){g="expected an object of string values";break}let k=d.fields.environment?.value??{},v=Object.fromEntries(Object.entries({...o.value,...k}).sort(([h],[b])=>h.localeCompare(b))),f=d.fields.environment?.source;d.fields.environment=m(v),f&&(d.fields.environment.source=`${f}; Claude added keys: ${u}`);break}case"secrets":De(o.value,c.choices??[])?o.value.length&&(d.fields.secrets=m([...o.value].sort())):g="expected a list of keys from .env.example";break;case"depends_on":De(o.value,c.choices??[])?o.value.length&&(d.fields.depends_on=m([...o.value].sort())):g="expected a list of this repo's other services";break;case"conflict":{let k=(c.choices??[]).find(f=>ct(f,o.value));if(k===void 0){g="not one of the conflicting values";break}let v=c.id.slice(d.name.length+1);d.fields[v]=m(k),d.conflicts=d.conflicts.filter(f=>f.key!==v);break}}g?n.push({item:o.item,reason:g}):i.push(o.item)}return{plan:r,accepted:i,rejected:n}}p(Qt,"applyAnswers");function es(e){return["You are helping generate a werkmeister service-registry fragment for the repository in your working directory.","A deterministic scan already filled every field it could read from package manifests, Dockerfiles, compose files and Kubernetes manifests.","The questions below are the fields it had to guess. Answer each one from the repository's own files, using Read, Glob and Grep.","","Rules:","- Answer only the questions listed, using each question's `id` as `item`.","- When a question has `choices`, `value` must be one of them; for list questions, a subset of them.","- Leave a question out if the repository doesn't settle it. A missing answer keeps the scan's guess; a wrong answer is worse than none.","- Never put credentials, tokens or keys in environment values. Those belong in `secrets`.",'- `reason` is one short sentence naming the evidence, e.g. "apps/api/src/main.ts registers GET /healthz". It is written into the file as a comment.',"- `files_read` lists the files that support the answer.","","Questions (JSON):",JSON.stringify(e,null,2)].join(`
|
|
3
|
+
import{b as st}from"./chunk-G3QGLNVJ.js";import{f as _e,g as $e,h as H,i as be}from"./chunk-V3L2WH76.js";import{a as ve,b as S,c as se,d as K,f as y,g as w,i as ye}from"./chunk-UO5PTDO7.js";import{r as ke}from"./chunk-O2QUWSMC.js";import{A as he,X as ge,a as F,w as ue}from"./chunk-K3BFBBN2.js";import{a as p,e as M,f as $}from"./chunk-C4LKFK4W.js";$();var ie=M(F(),1);import*as z from"node:fs";import*as oe from"node:path";var re=class extends Error{static{p(this,"AllocationError")}};function Ct(e=he()){try{let t=(0,ie.parse)(z.readFileSync(e,"utf8"))?.feature_slots?.ports_per_slot;return Number.isInteger(t)&&t>0?t:20}catch{return 20}}p(Ct,"portsPerSlot");function ne(e,t){for(let r of["services","infrastructure"])for(let a of Object.values(e?.[r]??{})){if(!a||typeof a!="object")continue;let i=a;Number.isInteger(i.port_offset)&&t.offsets.add(i.port_offset),Number.isInteger(i.k8s_forward_port)&&t.forwards.add(i.k8s_forward_port)}}p(ne,"collect");function xe(e,t,r,a){let i={offsets:new Set,forwards:new Set};for(let n of H(e))oe.resolve(n.path)!==oe.resolve(t)&&ne(n.doc,i);return z.existsSync(r)&&ne((0,ie.parse)(z.readFileSync(r,"utf8"))??null,i),ne(a,i),i}p(xe,"takenPorts");function we(e,t,r){let a=new Set(t),i=new Map;for(let n of[...e].sort()){let s=0;for(;a.has(s);)s++;if(s>=r)throw new re(`port_offset exhausted: ${r} offsets (ports.yaml ports_per_slot) are all used \u2014 raise ports_per_slot or free one`);a.add(s),i.set(n,s)}return i}p(we,"allocateOffsets");function Se(e,t,r=9050){let a=new Set(t),i=new Map;for(let n of[...e].sort()){let s=r;for(;a.has(s);)s++;a.add(s),i.set(n,s)}return i}p(Se,"allocateForwards");var nt=p(e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),"escapeRe");function je(e,t,r){let a={...e},i=[];for(let n of t){let s=a[n];if(s===void 0)continue;let o=s;for(let c of r)o=o.replace(new RegExp(`(?<![\\w.-])${nt(c.host??c.name)}:${c.port}\\b`,"g"),`k8s-${c.name}:${c.forward}`);o!==s&&(a[n]=o,i.push(n))}return{env:a,rewritten:i}}p(je,"rewriteEnv");$();var Ie=M(F(),1);$();$();import*as U from"node:path";var ae={redis:{health:"redis",port:6379},postgres:{health:"postgres",port:5432},postgis:{health:"postgres",port:5432},mysql:{health:"",port:3306},mariadb:{health:"",port:3306},mongo:{health:"",port:27017},rabbitmq:{health:"",port:5672}};function Ae(e){return(e.split("@")[0].split("/").pop()??e).split(":")[0]}p(Ae,"imageRepoName");var Oe=p((e,t)=>e.name.localeCompare(t.name),"byName");function Ee(e){let t=e.image?Ae(e.image):"";return Object.hasOwn(ae,t)?t:null}p(Ee,"datastoreOf");function Ne(e,t){let r=e.filter(f=>f.kind==="package"||f.kind==="dockerfile"),a=e.filter(f=>f.kind==="k8s"||f.kind==="compose"),i=[...new Set(r.map(f=>f.dir))].sort(),n=p(f=>f==="."?t:U.posix.basename(f),"base"),s=p(f=>{let h=U.posix.dirname(f);return h==="."?t:U.posix.basename(h)},"parent"),o=new Map;for(let f of i)o.set(n(f),(o.get(n(f))??0)+1);let c=i.map(f=>({dir:f,name:(o.get(n(f))??0)>1?`${s(f)}-${n(f)}`:n(f),findings:r.filter(h=>h.dir===f)})),u=[(f,h)=>f.kind==="k8s"&&f.dir!==null&&h.dir!=="."&&(f.dir===h.dir||f.dir.startsWith(`${h.dir}/`)),(f,h)=>f.kind==="compose"&&f.dir!==null&&f.dir===h.dir,(f,h)=>f.name===h.name,(f,h)=>!!f.image&&Ae(f.image)===h.name],m=[];for(let f of a){let h=Ee(f)?[u[2]]:u,b;for(let N of h)if(b=c.find(j=>N(f,j)),b)break;b?b.findings.push(f):m.push(f)}let d=[],g=new Map,k=[];for(let f of m){let h=Ee(f);if(h){let b=g.get(f.name)??{name:f.name,datastore:h,findings:[]};b.findings.push(f),g.set(f.name,b)}else{k.push(f);let b=f.kind==="k8s"?"Deployment":"compose service";d.push({item:f.file,reason:`found ${b} ${f.name} \u2014 no source dir in this repo, skipped`})}}return{services:c.filter(f=>{let h=f.findings.some(b=>b.kind!=="package"||b.runnable);return h||d.push({item:f.dir,reason:"library package (no Dockerfile, deploy config or dev/start script), skipped"}),h}).sort(Oe),infrastructure:[...g.values()].sort(Oe),unmatched:k,skipped:d}}p(Ne,"correlate");var ot={type:["package"],archetype:["package"],test:["package"],internal_port:["k8s","compose","dockerfile"],health_endpoint:["k8s","compose"],setup_service:["package"],image:["dockerfile","package"],command:["package","compose","dockerfile"],memory_limit:["k8s"],memory_reservation:["k8s"],node_modules_volume:["package"],secrets:["k8s"],k8s_deployment:["k8s"],k8s_namespace:["k8s"],k8s_port:["k8s"],k8s_port_name:["k8s"],k8s_pod_prefix:["k8s"],feature_router:["k8s"],depends_on:["compose"]},ce=p((e,t)=>JSON.stringify(e)===JSON.stringify(t),"same");function rt(e){return Object.fromEntries(Object.entries(e).sort(([t],[r])=>t.localeCompare(r)))}p(rt,"sortKeys");function Pe(e,t){return Object.assign({},...e.filter(r=>r.kind===t&&r.fields.environment).map(r=>r.fields.environment.value))}p(Pe,"envOf");function V(e){let t={path:y(e.dir,"source directory")},r=[];for(let[o,c]of Object.entries(ot)){let u=c.flatMap(g=>e.findings.filter(k=>k.kind===g&&k.fields[o]!==void 0).map(k=>k.fields[o]));if(!u.length)continue;let m=u[0];if(t[o]=m,m.confidence!=="stated")continue;let d=u.slice(1).filter(g=>g.confidence==="stated"&&!ce(g.value,m.value)).filter((g,k,v)=>v.findIndex(f=>ce(f.value,g.value))===k);d.length&&r.push({service:e.name,key:o,chosen:m,also:d})}t.internal_port??=w(3e3,"no port in any source \u2014 default 3000"),t.health_endpoint??=w("","no readiness probe or healthcheck \u2014 TCP-only"),t.type??=w("api","no package.json \u2014 assumed a service"),t.image??=w("alpine:3","no usable FROM and no package.json \u2014 set the dev image"),!t.feature_router&&t.type.value==="web"&&(t.feature_router=w({},"type: web \u2014 routed through Caddy"));let a=Pe(e.findings,"k8s"),i=Pe(e.findings,"compose"),n={...a,...i};if(Object.keys(n).length){let o=[Object.keys(i).length?"compose environment":"",Object.keys(a).length?"k8s env":""];t.environment=y(rt(n),o.filter(Boolean).join(" + "))}let s=Object.keys(a).filter(o=>!(o in i)).sort();return{name:e.name,dir:e.dir,fields:t,conflicts:r,k8sEnvKeys:s,findings:e.findings}}p(V,"resolveService");function Me(e,t=[]){let r=ae[e.datastore],a=e.findings.filter(o=>o.kind==="k8s"),i=a[0];for(let o of a.slice(1))for(let c of["internal_port","k8s_namespace"]){let u=i.fields[c],m=o.fields[c];u&&m&&!ce(u.value,m.value)&&t.push({item:o.file,reason:`infrastructure ${e.name}: ${c} ${m.value} disagrees with ${u.value} (${u.source}), kept ${u.value}`})}let n=i?.fields.internal_port??e.findings.find(o=>o.fields.internal_port)?.fields.internal_port,s="no k8s manifest for this datastore";return{name:e.name,fields:{internal_port:n??y(r.port,`${e.datastore} default port`),k8s_namespace:i?.fields.k8s_namespace??w("default",s),k8s_pod_prefix:i?.fields.k8s_pod_prefix??w(e.name,s),health_endpoint:y(r.health,r.health?`${e.datastore} wire probe`:"no wire probe for this datastore \u2014 TCP-only")}}}p(Me,"resolveInfra");var Xt={type:"object",required:["answers"],additionalProperties:!1,properties:{answers:{type:"array",items:{type:"object",required:["item","value","reason","files_read"],additionalProperties:!1,properties:{item:{type:"string"},value:{},reason:{type:"string"},files_read:{type:"array",items:{type:"string"}}}}}}};function it(e){let t=e.existing?(0,Ie.parse)(e.existing)??{}:{},r=p((n,s)=>t?.services?.[n]?.[s]!==void 0,"inFile"),a=e.services.map(n=>n.name),i=[];for(let n of e.services){let s=n.fields,o=p((m,d)=>{r(n.name,m)||i.push({id:`${n.name}.${m}`,service:n.name,...d})},"ask");s.command?.confidence==="guessed"&&o("command",{kind:"command",prompt:`What command starts ${n.name} for local development? It runs with the repo root mounted at /app as the working directory.`,facts:{dir:n.dir,guess:s.command.value,why:s.command.source}}),s.health_endpoint?.confidence==="guessed"&&o("health_endpoint",{kind:"health_endpoint",prompt:`Which HTTP path answers 200 when ${n.name} is healthy? Answer "" if it has none.`,facts:{dir:n.dir,port:s.internal_port?.value}});let c=e.envExample[n.name]??[];c.length&&(o("environment",{kind:"environment",prompt:`Which environment variables does ${n.name} need for local development, with development values? Leave secrets out.`,facts:{dir:n.dir,env_example_keys:c,current:s.environment?.value??{}}}),s.secrets||o("secrets",{kind:"secrets",prompt:`Which of these keys must be set for ${n.name} to start at all? A declared secret that is missing stops \`werkmeister feature up\`.`,facts:{dir:n.dir},choices:c}));let u=a.filter(m=>m!==n.name);u.length&&!s.depends_on&&o("depends_on",{kind:"depends_on",prompt:`Which of these services must be running before ${n.name} starts (it calls them at startup)? Answer [] for none.`,facts:{dir:n.dir},choices:u});for(let m of n.conflicts)o(m.key,{kind:"conflict",prompt:`Sources disagree on ${n.name}.${m.key}. Which value is right for local development?`,facts:{sources:[m.chosen,...m.also].map(d=>({value:d.value,source:d.source}))},choices:[m.chosen.value,...m.also.map(d=>d.value)]})}for(let n of[...new Set(e.unmatched.map(s=>s.name))]){let s=e.unmatched.filter(c=>c.name===n),o=s.map(c=>c.file).join(", ");i.push({id:`unmatched.${n}`,kind:"unmatched",service:null,prompt:`${o} define${s.length>1?"":"s"} ${n}, but no source directory matched it. Which service is it? Answer null if its code lives in another repo.`,facts:{files:s.map(c=>c.file),image:s.find(c=>c.image)?.image??null},choices:[...a,null]})}return i}p(it,"collectQuestions");var at=p(e=>!!e&&typeof e=="object"&&!Array.isArray(e)&&Object.values(e).every(t=>typeof t=="string"),"isStringMap"),De=p((e,t)=>Array.isArray(e)&&e.every(r=>typeof r=="string"&&t.includes(r)),"subsetOf"),ct=p((e,t)=>JSON.stringify(e)===JSON.stringify(t),"same");function ft(e,t,r,a){if(r===null)return null;let i=typeof r=="string"?e.services.find(o=>o.name===r):void 0,n=e.unmatched.filter(o=>`unmatched.${o.name}`===t);if(!i||!n.length)return"expected one of this repo's services, or null";let s=V({name:i.name,dir:i.dir,findings:[...i.findings,...n]});for(let[o,c]of Object.entries(s.fields))o in i.fields||(i.fields[o]={...c,confidence:"inferred",source:`${c.source}; matched by Claude: ${a}`});return i.findings.push(...n),e.unmatched=e.unmatched.filter(o=>!n.includes(o)),e.skipped=e.skipped.filter(o=>!n.some(c=>o.item===c.file&&o.reason.includes(` ${c.name} \u2014 `))),null}p(ft,"applyUnmatched");function Qt(e,t){let r=structuredClone(e),a=new Map(it(e).map(o=>[o.id,o])),i=[],n=[],s=new Set;for(let o of t){let c=a.get(o.item);if(!c){n.push({item:o.item,reason:"not one of the questions asked"});continue}if(s.has(o.item)){n.push({item:o.item,reason:"answered twice; kept the first"});continue}s.add(o.item);let u=o.reason?.trim()||"no reason given",m=p(k=>({value:k,source:u,confidence:"inferred"}),"inferred"),d=c.service?r.services.find(k=>k.name===c.service):void 0,g=null;if(c.kind==="unmatched")g=ft(r,c.id,o.value,u);else if(!d)g=`no service named ${c.service} in this plan`;else switch(c.kind){case"command":typeof o.value=="string"&&o.value.trim()?d.fields.command=m(o.value.trim()):g="expected a non-empty command string";break;case"health_endpoint":typeof o.value=="string"&&(o.value===""||o.value.startsWith("/"))?d.fields.health_endpoint=m(o.value):g='expected "" or a path starting with /';break;case"environment":{if(!at(o.value)){g="expected an object of string values";break}let k=d.fields.environment?.value??{},v=Object.fromEntries(Object.entries({...o.value,...k}).sort(([h],[b])=>h.localeCompare(b))),f=d.fields.environment?.source;d.fields.environment=m(v),f&&(d.fields.environment.source=`${f}; Claude added keys: ${u}`);break}case"secrets":De(o.value,c.choices??[])?o.value.length&&(d.fields.secrets=m([...o.value].sort())):g="expected a list of keys from .env.example";break;case"depends_on":De(o.value,c.choices??[])?o.value.length&&(d.fields.depends_on=m([...o.value].sort())):g="expected a list of this repo's other services";break;case"conflict":{let k=(c.choices??[]).find(f=>ct(f,o.value));if(k===void 0){g="not one of the conflicting values";break}let v=c.id.slice(d.name.length+1);d.fields[v]=m(k),d.conflicts=d.conflicts.filter(f=>f.key!==v);break}}g?n.push({item:o.item,reason:g}):i.push(o.item)}return{plan:r,accepted:i,rejected:n}}p(Qt,"applyAnswers");function es(e){return["You are helping generate a werkmeister service-registry fragment for the repository in your working directory.","A deterministic scan already filled every field it could read from package manifests, Dockerfiles, compose files and Kubernetes manifests.","The questions below are the fields it had to guess. Answer each one from the repository's own files, using Read, Glob and Grep.","","Rules:","- Answer only the questions listed, using each question's `id` as `item`.","- When a question has `choices`, `value` must be one of them; for list questions, a subset of them.","- Leave a question out if the repository doesn't settle it. A missing answer keeps the scan's guess; a wrong answer is worse than none.","- Never put credentials, tokens or keys in environment values. Those belong in `secrets`.",'- `reason` is one short sentence naming the evidence, e.g. "apps/api/src/main.ts registers GET /healthz". It is written into the file as a comment.',"- `files_read` lists the files that support the answer.","","Questions (JSON):",JSON.stringify(e,null,2)].join(`
|
|
4
4
|
`)}p(es,"assistPrompt");$();var Je=M(F(),1);import*as X from"node:fs";import*as T from"node:path";$();var Te=M(F(),1);import*as Z from"node:path";var fe=/(^|\/)(docker-)?compose(\.[\w-]+)?\.ya?ml$/;function Fe(e){if(typeof e=="number")return Number.isInteger(e)&&e>0?e:void 0;if(typeof e=="string"){let t=(e.split(":").pop()??"").split("/")[0].split("-")[0],r=Number(t);return Number.isInteger(r)&&r>0?r:void 0}if(e&&typeof e=="object"){let t=e.target;return typeof t=="number"&&Number.isInteger(t)?t:void 0}}p(Fe,"containerPort");function pt(e){return Array.isArray(e)?Object.fromEntries(e.map(String).filter(t=>t.includes("=")).map(t=>[t.slice(0,t.indexOf("=")),t.slice(t.indexOf("=")+1)])):e&&typeof e=="object"?Object.fromEntries(Object.entries(e).filter(([,t])=>t!=null).map(([t,r])=>[t,String(r)])):{}}p(pt,"envMap");function mt(e){let t=e?.test,r=Array.isArray(t)?t.join(" "):String(t??"");return/https?:\/\/[^/\s"']+(\/[^\s"']*)/.exec(r)?.[1]}p(mt,"healthPath");function Re(e){let t=[];for(let r of e.files.filter(a=>fe.test(a))){let a;try{a=(0,Te.parse)(S(e,r),{merge:!0})}catch(i){e.skipped.push({item:r,reason:`unparsable YAML: ${i instanceof Error?i.message:String(i)}`});continue}for(let[i,n]of Object.entries(a?.services??{})){if(!n||typeof n!="object")continue;let s=n,o=p(f=>`${r} \u2192 services.${i}.${f}`,"src"),c=typeof s.build=="string"?s.build:s.build?.context,u=c===void 0?null:Z.posix.normalize(Z.posix.join(Z.posix.dirname(r),String(c))).replace(/\/$/,"")||".",m={},d=pt(s.environment);Object.keys(d).length&&(m.environment=y(d,o("environment")));let g=Array.isArray(s.depends_on)?s.depends_on.map(String):s.depends_on&&typeof s.depends_on=="object"?Object.keys(s.depends_on):[];g.length&&(m.depends_on=y([...g].sort(),o("depends_on"))),s.command!==void 0&&(m.command=y(Array.isArray(s.command)?s.command.join(" "):String(s.command),o("command")));let k=Fe(s.ports?.[0])??Fe(s.expose?.[0]);k&&(m.internal_port=y(k,o(s.ports?"ports":"expose")));let v=mt(s.healthcheck);v&&(m.health_endpoint=y(v,o("healthcheck"))),t.push({kind:"compose",name:i,dir:u,file:r,...s.image?{image:String(s.image)}:{},fields:m})}}return t}p(Re,"detectCompose");$();import*as R from"node:path";var lt=/^(?!.*\.(md|dockerignore)$)(Dockerfile(\..+)?|.+\.Dockerfile)$/,dt=/(^|\.)dev(\.|$)/i;function ut(e){let t=[];for(let r of e.replace(/\\\r?\n/g," ").split(/\r?\n/)){let a=r.trim();if(!a||a.startsWith("#"))continue;let i=/^(\w+)\s+(.*)$/.exec(a);i&&t.push([i[1].toUpperCase(),i[2].trim()])}return t}p(ut,"dockerInstructions");function ht(e){if(e.startsWith("["))try{let t=JSON.parse(e);if(Array.isArray(t))return t.map(String).join(" ")}catch{}return e}p(ht,"commandText");function qe(e){let t=p(a=>dt.test(R.posix.basename(a)),"isDev");return e.files.filter(a=>lt.test(R.posix.basename(a))).sort((a,i)=>Number(t(i))-Number(t(a))||a.localeCompare(i)).map(a=>{let i=R.posix.dirname(a),n=ut(S(e,a)),s={},c=n.find(([k])=>k==="FROM")?.[1].split(/\s+/).find(k=>!k.startsWith("--"));c&&!c.includes("$")&&(s.image=y(c,`${a} \u2192 FROM`));let u=n.find(([k])=>k==="EXPOSE"),m=Number(/(\d+)/.exec(u?.[1]??"")?.[1]);Number.isInteger(m)&&m>0&&(s.internal_port=y(m,`${a} \u2192 EXPOSE`));let d=p(k=>[...n].reverse().find(([v])=>v===k),"last"),g=d("CMD")??d("ENTRYPOINT");if(g){let k=ht(g[1]);s.command=w(i==="."?k:`cd ${i} && exec ${k}`,`${a} \u2192 ${g[0]} is the production entrypoint`)}return{kind:"dockerfile",name:i==="."?R.basename(e.root):R.posix.basename(i),dir:i,file:a,fields:s}})}p(qe,"detectDockerfiles");$();var Ke=M(F(),1);import*as P from"node:path";$();import*as G from"node:path";var gt=new Set(["Deployment","StatefulSet"]);function Ce(e){let t=/^(\d+)([KMG])?i?$/.exec(String(e??""));return t?`${t[1]}${t[2]??""}`:void 0}p(Ce,"memory");function kt(e){let t=e?.spec?.rules??[];return[e?.spec?.defaultBackend?.service?.name,...t.flatMap(r=>(r?.http?.paths??[]).map(a=>a?.backend?.service?.name))].filter(r=>typeof r=="string")}p(kt,"ingressBackends");function J(e){let t=e.flatMap(n=>n.docs.flatMap(s=>s?.kind==="List"&&Array.isArray(s.items)?s.items:[s]).filter(s=>s&&typeof s=="object"&&typeof s.kind=="string").map(s=>({doc:s,source:n}))),r=t.filter(n=>n.doc.kind==="Service").map(n=>n.doc),a=new Set(t.filter(n=>n.doc.kind==="Ingress").flatMap(n=>kt(n.doc))),i=[];for(let{doc:n,source:s}of t.filter(o=>gt.has(o.doc.kind))){let o=n.metadata?.name,c=n.spec?.template?.spec?.containers?.[0];if(typeof o!="string"||!c)continue;let u=p(x=>`${s.file} \u2192 ${x}`,"src"),m={k8s_namespace:n.metadata?.namespace?y(n.metadata.namespace,u("metadata.namespace")):y("default",`${s.file} \u2192 no metadata.namespace (Kubernetes default)`),k8s_pod_prefix:y(o,u(`${n.kind} ${o}`))};n.kind==="Deployment"&&(m.k8s_deployment=y(o,u(`Deployment ${o}`)));let d=c.ports?.[0]?.containerPort;Number.isInteger(d)&&(m.internal_port=y(d,u("containerPort")));let g=c.readinessProbe?.httpGet?.path?["readinessProbe",c.readinessProbe.httpGet.path]:c.livenessProbe?.httpGet?.path?["livenessProbe",c.livenessProbe.httpGet.path]:null;g&&(m.health_endpoint=y(String(g[1]),u(`${g[0]}.httpGet.path`)));let k=Ce(c.resources?.limits?.memory),v=Ce(c.resources?.requests?.memory);k&&(m.memory_limit=y(k,u("resources.limits.memory"))),v&&(m.memory_reservation=y(v,u("resources.requests.memory")));let f={},h=[];for(let x of Array.isArray(c.env)?c.env:[])typeof x?.name=="string"&&(x.valueFrom?.secretKeyRef?h.push(x.name):x.value!==void 0&&x.value!==null&&(f[x.name]=String(x.value)));Object.keys(f).length&&(m.environment=y(f,u("env"))),h.length&&(m.secrets=y([...h].sort(),u("env[].valueFrom.secretKeyRef")));let b=n.spec?.template?.metadata?.labels??{},N=r.find(x=>{let Y=x.spec?.selector??{};return Object.keys(Y).length>0&&Object.entries(Y).every(([Q,ee])=>b[Q]===ee)}),j=N?.metadata?.name,I=N?.spec?.ports?.[0];Number.isInteger(I?.port)&&(m.k8s_port=y(I.port,u(`Service ${j} port`))),typeof I?.name=="string"&&(m.k8s_port_name=y(I.name,u(`Service ${j} port name`))),j&&a.has(j)&&(m.feature_router=y({},u(`Ingress \u2192 Service ${j}`))),i.push({kind:"k8s",name:o,dir:s.dir,file:s.file,...typeof c.image=="string"?{image:c.image}:{},fields:m})}return i}p(J,"findingsFromManifests");function pe(e){return e.filter(t=>G.posix.basename(t)==="Chart.yaml").map(t=>G.posix.dirname(t))}p(pe,"chartDirs");var me=/(^|\/)kustomization\.ya?ml$/,vt=[/(^|\/)values[^/]*\.ya?ml$/,/\.values\.ya?ml$/,/^pnpm-workspace\.yaml$/,fe],yt=/^\s*kind:\s*(Deployment|StatefulSet|Service|Ingress|List)\b/m;function We(e){let t=[...pe(e.files),...e.files.filter(i=>me.test(i)).map(i=>G.posix.dirname(i))],r=p(i=>t.some(n=>n==="."||i.startsWith(`${n}/`)),"ownedElsewhere"),a=[];for(let i of e.files){if(!/\.ya?ml$/.test(i)||r(i)||vt.some(s=>s.test(i)))continue;let n=S(e,i);if(yt.test(n))try{a.push({file:i,dir:G.posix.dirname(i),docs:K(n)})}catch(s){e.skipped.push({item:i,reason:`unparsable YAML: ${s instanceof Error?s.message:String(s)}`})}}return J(a)}p(We,"detectK8s");function _t(e,t){try{let r=(0,Ke.parse)(S(e,`${t}/Chart.yaml`))?.name;return typeof r=="string"&&r?r:P.posix.basename(t)}catch{return P.posix.basename(t)}}p(_t,"chartName");function Le(e){let t=pe(e.files),r=[];for(let a of t){let i=P.posix.dirname(a),n=t.filter(c=>P.posix.dirname(c)===i),s=e.files.filter(c=>P.posix.dirname(c)===i&&/[^/]\.values\.ya?ml$/.test(c));if(s.length&&n.length>1){if(a===n[0])for(let c of s)e.skipped.push({item:c,reason:`several charts in ${i}/ \u2014 can't tell which one ${c} is for`});continue}let o=s.length?s.map(c=>({release:P.posix.basename(c).replace(/\.values\.ya?ml$/,""),values:c})):[{release:_t(e,a),values:null}];for(let{release:c,values:u}of o){let m=["helm","template",c,P.join(e.root,a)];u&&m.push("-f",P.join(e.root,u));let[d,g]=e.runner(m);if(d===127)return e.skipped.push({item:"helm charts",reason:"helm is not installed \u2014 charts skipped"}),r;let k=u??a;if(d!==0){e.skipped.push({item:k,reason:`helm template failed: ${g.split(`
|
|
5
5
|
`)[0]}`});continue}try{r.push(...J([{file:`${k} (helm template)`,dir:null,docs:K(g)}]))}catch(v){e.skipped.push({item:k,reason:`unparsable helm output: ${v instanceof Error?v.message:String(v)}`})}}}return r}p(Le,"detectHelm");$();var Ye=M(F(),1);import*as q from"node:path";function $t(e,t){let r=new Set;for(let a of t){let i;try{i=(0,Ye.parse)(S(e,a))}catch{continue}let n=q.posix.dirname(a);for(let s of[i?.resources,i?.bases,i?.components].flatMap(o=>Array.isArray(o)?o:[]))typeof s=="string"&&r.add(q.posix.normalize(q.posix.join(n,s)).replace(/\/$/,""))}return r}p($t,"referencedDirs");function ze(e){let t=[],r=e.files.filter(i=>me.test(i)),a=$t(e,r);for(let i of r){let n=q.posix.dirname(i);if(a.has(n))continue;let[s,o]=e.runner(["kubectl","kustomize",q.join(e.root,n)]);if(s===127)return e.skipped.push({item:"kustomize overlays",reason:"kubectl is not installed \u2014 overlays skipped"}),t;if(s!==0){e.skipped.push({item:i,reason:`kubectl kustomize failed: ${o.split(`
|
|
6
6
|
`)[0]}`});continue}try{t.push(...J([{file:`${i} (kubectl kustomize)`,dir:null,docs:K(o)}]))}catch(c){e.skipped.push({item:i,reason:`unparsable kustomize output: ${c instanceof Error?c.message:String(c)}`})}}return t}p(ze,"detectKustomize");$();import*as B from"node:path";var bt=["next","vite","react","expo"],xt=["express","fastify","@nestjs/core","koa"],wt=["sharp","better-sqlite3","esbuild","@swc/core"];function St(e,t,r,a){let i=a.map(s=>s==="test"?s:`run ${s}`),n=p(s=>i.map(s).join(" && "),"chain");return t==="."?n(s=>`${e.pm} ${s}`):r!==void 0?e.pm==="pnpm"?n(s=>`pnpm --filter ${r} ${s}`):e.pm==="yarn"?n(s=>`yarn workspace ${r} ${s}`):n(s=>`npm ${s} -w ${r}`):e.pm==="pnpm"?n(s=>`pnpm --filter ./${t} ${s}`):e.pm==="yarn"?`cd ${t} && ${n(s=>`yarn ${s}`)}`:n(s=>`npm ${s} -w ${t}`)}p(St,"testCommand");function jt(e,t,r,a){for(let i of[r.engines?.node,a?.engines?.node]){let n=/(\d+)/.exec(String(i??""));if(n)return n[1]}for(let i of[B.posix.join(t,".nvmrc"),".nvmrc"]){if(!e.files.includes(i))continue;let n=/(\d+)/.exec(S(e,i));if(n)return n[1]}return"22"}p(jt,"nodeMajor");function Ge(e,t){let r=se(e,"package.json"),a=t.packageDirs.length?t.packageDirs:r?["."]:[],i=[];for(let n of a){let s=n==="."?"package.json":`${n}/package.json`,o=se(e,s);if(!o)continue;let c=o.scripts??{},u={...o.dependencies,...o.devDependencies},m={},d=c.dev?"dev":c.start?"start":null;if(d){let h=`exec ${t.pm} run ${d}`;m.command=y(n==="."?h:`cd ${n} && ${h}`,`${s} \u2192 scripts.${d}`)}if(c.test){let h=c.typecheck?["typecheck","test"]:["test"];m.test=y(St(t,n,o.name,h),`${s} \u2192 ${h.map(b=>`scripts.${b}`).join(", ")}`)}let g=bt.find(h=>h in u),k=xt.find(h=>h in u),v=g?["web","node-web",`${s} \u2192 dependency ${g}`]:k?["api","node-service",`${s} \u2192 dependency ${k}`]:o.bin?["cli","node-tool",`${s} \u2192 bin`]:null;if(v)m.type=y(v[0],v[2]),m.archetype=y(v[1],v[2]);else{let h=`no web, api or bin marker in ${s} \u2014 assumed a service`;m.type=w("api",h),m.archetype=w("node-service",h)}let f=wt.find(h=>h in u);m.image=w(`node:${jt(e,n,o,r)}${f?"":"-alpine"}`,`no Dockerfile \u2014 Node major from engines/.nvmrc${f?`; glibc image because of ${f}`:""}`),t.setupName&&(m.setup_service=y(t.setupName,"shared workspace install"),m.node_modules_volume=y(t.setupFields.node_modules_volume.value,"shared workspace install")),i.push({kind:"package",name:n==="."?B.basename(e.root):B.posix.basename(n),dir:n,file:s,runnable:!!d,fields:m})}return i}p(Ge,"detectPackages");var Ot=[".env.example",".env.sample",".env.template"];function C(e,t,r,a){try{return a()}catch(i){return e.push({item:t,reason:`${t} failed: ${i instanceof Error?i.message:String(i)}`}),r}}p(C,"safely");function Et(e,t){let r=new Set,a=Ot.flatMap(i=>[T.posix.join(t,i),i]);for(let i of new Set(a))if(e.files.includes(i))for(let n of S(e,i).split(/\r?\n/)){let s=/^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=/.exec(n);s&&r.add(s[1])}return[...r].sort()}p(Et,"envExampleKeys");function Hs(e,t){let r=T.resolve(e),a=T.basename(r),i=T.join(r,_e),n=X.existsSync(i)?X.readFileSync(i,"utf8"):null,s=n?(0,Je.parse)(n)??null:null,o={root:r,files:ve(r,t.runner),runner:t.runner,skipped:[]},c=Object.values(s?.services??{}).map(l=>l?.setup_service).find(l=>typeof l=="string")??null,u=Object.values(s?.services??{}).map(l=>l?.node_modules_volume).find(l=>typeof l=="string")??null,m={pm:"npm",packageDirs:[],setupName:null,setupFields:{}},d=C(o.skipped,"workspace detection",m,()=>ye(o,c,u)),g=[...C(o.skipped,"package.json detection",[],()=>Ge(o,d)),...C(o.skipped,"Dockerfile detection",[],()=>qe(o)),...C(o.skipped,"k8s manifest detection",[],()=>We(o)),...C(o.skipped,"Helm detection",[],()=>Le(o)),...C(o.skipped,"kustomize detection",[],()=>ze(o)),...C(o.skipped,"compose detection",[],()=>Re(o))],k=Ne(g,a),v=k.services.map(V),f=k.infrastructure.map(l=>Me(l,k.skipped)),h=p((l,_,O)=>Object.entries(s?.[l]??{}).find(([,A])=>A?.[_]===O)?.[0],"adopt"),b=new Map;for(let l of v){let _=h("services","path",l.dir);if(_&&_!==l.name){b.set(l.name,_),l.name=_;for(let O of l.conflicts)O.service=_}}let N=new Map(f.map(l=>[l.name,l.name]));for(let l of f){let _=h("infrastructure","k8s_pod_prefix",l.fields.k8s_pod_prefix.value);_&&_!==l.name&&(b.set(l.name,_),N.set(_,l.name),l.name=_)}let j=p((l,_)=>l.name.localeCompare(_.name),"byName");v.sort(j),f.sort(j);let I=new Set(v.map(l=>l.name)),x=p((l,_,O)=>s?.[l]?.[_]?.[O]!==void 0,"inFile"),Y=xe(t.reposRoot,i,t.localPath,s),Q=we(v.filter(l=>!x("services",l.name,"port_offset")).map(l=>l.name),Y.offsets,t.portsPerSlot);for(let l of v){let _=Q.get(l.name);_!==void 0&&(l.fields.port_offset=y(_,"lowest free offset across registered repos"))}let ee=Se(f.filter(l=>!x("infrastructure",l.name,"k8s_forward_port")).map(l=>l.name),Y.forwards);for(let l of f){let _=ee.get(l.name);_!==void 0&&(l.fields.k8s_forward_port=y(_,"lowest free forward port from 9050"))}let et=f.map(l=>({name:l.name,host:N.get(l.name),port:Number(s?.infrastructure?.[l.name]?.internal_port??l.fields.internal_port.value),forward:Number(s?.infrastructure?.[l.name]?.k8s_forward_port??l.fields.k8s_forward_port?.value)}));for(let l of v){let _=l.fields.environment;if(!_)continue;let{env:O,rewritten:A}=je(_.value,l.k8sEnvKeys,et);A.length&&(l.fields.environment=w(O,`${_.source}; ${A.join(", ")} rewritten from the in-cluster address to the werkmeister tunnel`))}for(let l of v){let _=l.fields.depends_on;if(!_)continue;let O=[...new Set(_.value.map(A=>b.get(A)??A))].filter(A=>I.has(A)&&A!==l.name).sort();O.length?l.fields.depends_on={..._,value:O}:delete l.fields.depends_on}let te=v.filter(l=>l.fields.setup_service),tt=d.setupName&&te.length?{name:d.setupName,fields:{image:{...te[0].fields.image,source:`same image as ${te[0].name}`},...d.setupFields}}:null,de={};for(let l of v){let _=new Set([...Object.keys(l.fields.environment?.value??{}),...l.fields.secrets?.value??[]]),O=Et(o,l.dir).filter(A=>!_.has(A));O.length&&(de[l.name]=O)}return{repo:a,root:r,fragmentPath:i,existing:n,services:v,infrastructure:f,setup:tt,envExample:de,unmatched:k.unmatched,skipped:[...o.skipped,...k.skipped]}}p(Hs,"planFragment");function Us(e){let t=p(r=>Object.fromEntries(Object.entries(r).map(([a,i])=>[a,{value:i.value,source:i.source,confidence:i.confidence}])),"fields");return{repo:e.repo,fragment:e.fragmentPath,existed:e.existing!==null,services:e.services.map(r=>({name:r.name,dir:r.dir,fields:t(r.fields),conflicts:r.conflicts.map(a=>({key:a.key,chosen:a.chosen,also:a.also}))})),infrastructure:e.infrastructure.map(r=>({name:r.name,fields:t(r.fields)})),setup:e.setup?{name:e.setup.name,fields:t(e.setup.fields)}:null,envExample:e.envExample,skipped:e.skipped}}p(Us,"planSummary");$();var D=M(F(),1);var At=["# Werkmeister service-registry fragment for this repo.","#","# `werkmeister registry sync` (run by `werkmeister machine setup`) merges every","# <repo>/.werkmeister/services.yaml under paths.repos_root into","# ~/.werkmeister/services.yaml. Only `services:`, `setup_services:` and","# `infrastructure:` may appear here; `repo:` is the checkout's directory name","# and `repos:` is derived. Generated by `werkmeister machine detect`; re-running it only","# adds what is missing, so edit freely.","",""].join(`
|
|
@@ -21,4 +21,4 @@ import{b as st}from"./chunk-XFJ6IA6A.js";import{f as _e,g as $e,h as H,i as be}f
|
|
|
21
21
|
|
|
22
22
|
`)+n.join(`
|
|
23
23
|
`)),{path:e.fragmentPath,yaml:u,added:s,changed:u!==t,skipped:o}}p(Qs,"renderFragment");$();var le=M(st(),1),Qe=M(F(),1);import*as L from"node:fs";import*as Xe from"node:os";import*as W from"node:path";var Ft=le.default.default??le.default;function Tt(){return W.join(ge(),"infra","schemas","services-fragment.schema.json")}p(Tt,"defaultSchemaPath");function an(e,t,r,a=Tt()){let i;try{i=(0,Qe.parse)(e.yaml)??{}}catch(o){return[`generated YAML does not parse: ${o instanceof Error?o.message:String(o)}`]}let n=new Ft({allErrors:!0,strict:!1}).compile(JSON.parse(L.readFileSync(a,"utf8"))),s=n(i)?[]:(n.errors??[]).map(o=>`${o.instancePath||"/"} ${o.message??"is invalid"}`);try{let o=H(r).filter(c=>W.resolve(c.path)!==W.resolve(t.fragmentPath));be([...o,{repo:t.repo,path:t.fragmentPath,doc:i}],{defaults:{},local:{},paths:{home:Xe.homedir(),repos_root:r,workspaces_root:r,werkmeister_home:ue(),local_domain:ke().local_domain}})}catch(o){if(!(o instanceof $e))throw o;s.push(o.message)}return s}p(an,"validateFragment");function cn(e){L.mkdirSync(W.dirname(e.path),{recursive:!0}),L.writeFileSync(e.path,e.yaml)}p(cn,"writeFragment");$();export{re as a,Ct as b,Xt as c,it as d,Qt as e,es as f,Hs as g,Us as h,Qs as i,an as j,cn as k};
|
|
24
|
-
//# sourceMappingURL=chunk-
|
|
24
|
+
//# sourceMappingURL=chunk-3B3Y2ZCY.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { createRequire as __sandboxCreateRequire } from "node:module";
|
|
2
2
|
const require = __sandboxCreateRequire(import.meta.url);
|
|
3
|
-
import{b as O}from"./chunk-
|
|
4
|
-
//# sourceMappingURL=chunk-
|
|
3
|
+
import{b as O}from"./chunk-PI3NHMYM.js";import{n as N}from"./chunk-O2QUWSMC.js";import{b as d}from"./chunk-MZWQPHMY.js";import{l as g,s as l}from"./chunk-K3BFBBN2.js";import{b as x}from"./chunk-PXSFA2ZJ.js";import{a as n,f as T}from"./chunk-C4LKFK4W.js";T();import*as c from"node:fs";import*as $ from"node:os";import*as i from"node:path";var P=3002;function U(){let t=l("MCP_PORT")||N().overrides?.mcp_port,e=Number(t);return Number.isInteger(e)&&e>0?e:P}n(U,"daemonPort");function w(){return(l("HOST")||`http://127.0.0.1:${U()}`).replace(/\/+$/,"")}n(w,"daemonUrl");function S(t){try{return c.readFileSync(t,"utf8").trim()||null}catch{return null}}n(S,"readToken");function H(t){return l("MCP_TOKEN")||(t?S(O(t)):null)||S(i.join(x($.homedir()),"mcp-token"))}n(H,"daemonToken");var m=class extends d{static{n(this,"DaemonUnavailable")}constructor(e){super(`werkmeister daemon not reachable at ${w()} (${e}). Run \`werkmeister machine setup\` (macOS) or \`werkmeister infra connect\`.`,"DAEMON_DOWN")}};function y(t){let e=t===void 0?H():t;return e?{Authorization:`Bearer ${e}`}:{}}n(y,"headers");var p=class extends d{static{n(this,"DaemonTimeout")}constructor(e){super(`werkmeister daemon at ${w()} took the call but did not answer in time (${e}); it may still be running it.`,"DAEMON_TIMEOUT")}},b={ECONNREFUSED:"ECONNREFUSED: nothing is listening, the daemon is not running",ECONNRESET:"ECONNRESET: the daemon reset the connection while exiting or restarting"},I=n(()=>Number(l("DAEMON_RETRY_MS"))||15e3,"restartGapMs"),E=!1,L=n(t=>t==="TimeoutError"||t.startsWith("UND_ERR_")&&t!=="UND_ERR_CONNECT_TIMEOUT","tookTheCall"),R=n(t=>{let e=t;return e.cause?.code??e.name},"codeOf");async function A(t,e,r=!0){let s=Date.now()+(E?0:I());for(;;)try{let a=await fetch(t,e);return r&&(E=!1),a}catch(a){let o=R(a);if(L(o))throw new p(o);if(!(o in b))throw new m(o);if(!r||Date.now()>=s)throw r&&(E=!0),new m(b[o]);await new Promise(f=>setTimeout(f,500))}}n(A,"send");var D="x-werkmeister-build",_="x-werkmeister-stream",q="x-werkmeister-launcher",z="x-werkmeister-client-ui";function K(t){if(!t)return null;try{let e=c.statSync(t).mtime.toISOString().replace(/\.\d+Z$/,"Z");for(let r=i.dirname(t);;r=i.dirname(r)){let s=i.join(r,"package.json");if(c.existsSync(s))return`${JSON.parse(c.readFileSync(s,"utf8")).version} @ ${e}`;if(i.dirname(r)===r)return null}}catch{return null}}n(K,"buildOf");var C=null,k=!1;function V(t){C=t}n(V,"expectDaemonBuild");function j(t,e){let r=e.headers.get(D);k||!t||!r||r===t||(k=!0,g(`The werkmeister daemon runs an older build (loaded ${r}, on disk ${t}); it restarts by itself once idle, or run \`werkmeister daemon restart\`.`))}n(j,"checkBuild");async function Y(){try{let t=await A(`${w()}/api/status`,{headers:y(void 0),signal:AbortSignal.timeout(5e3)},!1);return t.ok?await t.json():null}catch{return null}}n(Y,"daemonStatus");async function Q(t,e={},r={}){let s=AbortSignal.timeout(r.timeoutMs??12e4),a=C?.()??null,o=await A(`${w()}/api/tool`,{method:"POST",headers:{"Content-Type":"application/json",...y(r.token),...a?{[D]:a}:{},[_]:"1"},body:JSON.stringify({name:t,arguments:e}),signal:r.signal?AbortSignal.any([r.signal,s]):s});if(j(a,o),!o.headers.get("content-type")?.includes("json")&&o.status!==401&&o.status!==403)throw new m(`HTTP ${o.status}: the port is held by something that is not the werkmeister daemon`);let f=o.headers.get(_)==="1",u=await o.json().catch(M=>{if(f)throw new p(R(M));return{}}),h=f?u.status??500:o.status;if(h<200||h>299)throw u.error?.replace(/^MCP error -?\d+: /,"")===`Tool ${t} not found`?new d(`The werkmeister daemon is older than this CLI: it has no \`${t}\` tool. Run \`werkmeister daemon restart\`.`,"DAEMON_STALE"):new d(u.error??`daemon answered HTTP ${h} to ${t}`,u.code??`HTTP_${h}`);return{data:u.structuredContent,text:u.text??""}}n(Q,"callTool");export{P as a,U as b,w as c,H as d,m as e,D as f,_ as g,q as h,z as i,K as j,V as k,Y as l,Q as m};
|
|
4
|
+
//# sourceMappingURL=chunk-425KLJUM.js.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { createRequire as __sandboxCreateRequire } from "node:module";
|
|
2
|
+
const require = __sandboxCreateRequire(import.meta.url);
|
|
3
|
+
import{a as ue}from"./chunk-TJ5BFKRS.js";import{a as kt,b as vt,c as xt,e as _t,f as Ot,g as ce,h as At,k as Te,l as De,m as Le,n as G}from"./chunk-AI74Y2N6.js";import{j as Rt}from"./chunk-64Y2E3MH.js";import{d as ae,h as Ct,l as bt,m as Nt}from"./chunk-KPM6JPOX.js";import{m as Pe}from"./chunk-V3L2WH76.js";import{i as tt,p as nt,t as Ie}from"./chunk-BBM2J5K4.js";import{g as Xe,v as Ze}from"./chunk-BTVLOG7I.js";import{D as te}from"./chunk-CUSUDZYU.js";import{a as et,b as ye,d as $e}from"./chunk-DOKRZG4F.js";import{$ as ie,A as gt,B as Re,H as _e,I as re,J as Oe,K as ht,L as wt,M as yt,P as se,Q as $t,S as Ae,U as be,Z as St,a as I,aa as Ne,ba as B,ca as Fe,d as it,da as Et,h as at,i as Ce,j as ct,k as ke,l as ut,m as lt,n as ve,o as dt,p as ft,s as P,t as pt,v as mt,w as oe,x as D,y as V,z as xe}from"./chunk-OFA2CMOB.js";import{c as Se,d as ne,j as ot,k as Ee,l as rt,o as st}from"./chunk-UWACLY2H.js";import{a as A,d as ge}from"./chunk-JPSOT3UD.js";import{l as ee,m as F}from"./chunk-6HMEQ75K.js";import{c as Ke,d as Z,f as he,j as Qe,m as M,n as Je,o as we,p as W,r as ze,s as U,t as q}from"./chunk-U5DPXZVY.js";import{n as He}from"./chunk-O2QUWSMC.js";import{b as y}from"./chunk-MZWQPHMY.js";import{J as Be,M as z,Q as X,W as Ge,_ as Ye,h as m,j as f,k as N,l as $,m as _,n as S,u as j}from"./chunk-K3BFBBN2.js";import{b as Ve}from"./chunk-PXSFA2ZJ.js";import{a as c,f as J}from"./chunk-C4LKFK4W.js";J();import*as k from"node:fs";import*as b from"node:path";import{setTimeout as mn}from"node:timers/promises";J();import*as Ft from"node:fs";var le="w9r-caddy",de="/tmp/Caddyfile",nn=/\breverse_proxy\b/g,on=/^\s*(handle(?:_path)?)\b\s*([^{]*)\{\s*$/,rn=/^\s*(handle(?:_path)?)\b\s*([^{]*)\{.*\}\s*$/;function It(e){let t=e.indexOf("#");return t===-1?e:e.slice(0,t)}c(It,"_stripComment");function sn(e){return e.replace(/"(?:[^"\\]|\\.)*"/g,'""').replace(/\{[^{}\s]*\}/g,"")}c(sn,"_stripBraceNoise");function an(e){function t(r){let s=0;for(let i of r)if(!(typeof i!="object"||i===null||Array.isArray(i)))for(let a of i.handle??[]){if(typeof a!="object"||a===null||Array.isArray(a))continue;let u=a.handler;u==="subroute"?s+=t(a.routes??[]):u==="reverse_proxy"&&(s+=1)}return s}c(t,"walkRouteBlocks");let n=e?.apps?.http?.servers;if(typeof n!="object"||n===null||Array.isArray(n))return 0;let o=0;for(let r of Object.values(n))typeof r=="object"&&r!==null&&!Array.isArray(r)&&(o+=t(r.routes??[]));return o}c(an,"countCompiledRoutes");function cn(e){let t=0;for(let n of e.split(/\r?\n/)){if(n.trim().startsWith("#"))continue;let o=It(n);t+=(o.match(nn)??[]).length}return t}c(cn,"computeExpectedRouteCount");function un(e){let t=[],n=e.split(/\r?\n/),o=0,r="(global)",s=[],i=new Map,a=new Set;function u(l){let d=i.get(l)??[];if(i.delete(l),d.length<2||a.has(l))return;let w=d.filter(E=>E[2]===""),p=d.filter(E=>E[2]!=="");if(w.length&&p.length)for(let[E,v]of w)t.push(`${r}: line ${E}: bare unscoped '${v} {' coexists with path-scoped sibling handle blocks (route-drop risk)`);let h=new Map;for(let[E,v,g]of p)h.has(g)?t.push(`${r}: line ${E}: duplicate '${v} ${g}' matcher also used at line ${h.get(g)} (route-drop risk)`):h.set(g,E)}c(u,"flushGroup");for(let l=0;l<n.length;l++){let d=l+1,w=n[l],p=It(w),h=p.trim();if(o===0&&h.endsWith("{")&&!h.startsWith("#")){let g=h.slice(0,-1).trim();s.push(g||"(global)"),r=s[s.length-1]}else s.length&&h.endsWith("{");h.startsWith("route")&&/^route\b.*\{\s*$/.test(h)&&a.add(o+1);let E=on.exec(p);if(E){let g=E[1],x=E[2].trim(),R=i.get(o)??[];i.set(o,R),R.push([d,g,x,a.has(o)])}else{let g=rn.exec(p);if(g){let x=g[1],R=g[2].trim(),O=i.get(o)??[];i.set(o,O),O.push([d,x,R,a.has(o)]);continue}}let v=sn(h);for(let g=0;g<(v.match(/\{/g)??[]).length;g++)o+=1;for(let g=0;g<(v.match(/\}/g)??[]).length;g++)i.has(o)&&u(o),a.delete(o),o=Math.max(o-1,0),o===0&&s.length&&(s.pop(),r=s.length?s[s.length-1]:"(global)")}for(let l of[...i.keys()])u(l);return t}c(un,"lintCaddyfileStructure");async function ln(e,t=le,n=de){f(`Copying Caddyfile into container: ${e} -> ${t}:${n}`);try{return await ot(t,e,n),!0}catch(o){return _(`Copying the Caddyfile failed: ${o.message}`),!1}}c(ln,"cpCaddyfileToContainer");async function dn(e=le,t=de){let n;try{n=await Ee(e,["caddy","adapt","--config",t])}catch(r){return[!1,0,r.message]}if(n.exitCode!==0)return[!1,0,n.stderr.trim()];let o;try{o=JSON.parse(n.stdout)}catch(r){return[!1,0,`failed to parse caddy adapt output as JSON: ${r}`]}return[!0,an(o),""]}c(dn,"adaptAndCountRoutes");function fn(e,{capture:t=!1}={}){let{argv:n,env:o,cwd:r}=Ct(),s=[...n,...e];f(`Running: ${s.join(" ")}`);let i;try{i=F(s,{capture:t,timeout:60,env:o,cwd:r})}catch(a){if(a instanceof ee&&a.code==="ENOENT")return _("docker compose not found. Ensure Docker Desktop is installed."),!1;if(a instanceof ee&&a.code==="ETIMEDOUT")return _("Proxy command timed out after 60 seconds"),!1;throw a}if(i.status!==0){let a=t?i.stderr:"";return _(`Proxy command failed (exit ${i.status})`),a&&S(`${m.DIM}${a.trim()}${m.RESET}
|
|
4
|
+
`),!1}return!0}c(fn,"_runCaddyCompose");async function Y(){let e=j();if(e)return f(`Caddy reload skipped (${e})`),!0;let t=`${Ye()}/proxy/Caddyfile`;if(f("Copying Caddyfile into Caddy container..."),!await ln(t))return _(`Failed to copy ${t} into ${le}:${de}`),!1;let n=Ft.readFileSync(t,"utf8"),o=un(n);for(let l of o)$(`Structural lint: ${l}`);f("Validating config and counting compiled routes...");let[r,s,i]=await dn();if(!r)return _(`caddy adapt failed -- not reloading: ${i}`),!1;let a=cn(n);if(s<a)return _(`Route-count guard tripped: compiled ${s} routes, expected ${a} (from ${t}) -- not reloading. This usually means the Caddyfile uses overlapping/unscoped \`handle\` blocks instead of a \`route\` block.`),!1;f(`Route count OK: ${s} compiled routes (expected >= ${a})`),f("Reloading Caddy configuration...");let u;try{u=await Ee(le,["caddy","reload","--config",de])}catch(l){return _(`Caddy reload failed: ${l.message}`),!1}if(u.exitCode!==0){$(`Caddy reload failed: ${u.stderr.trim()}`),$("Falling back to restarting the Caddy container; it reads the bind-mounted /etc/caddy/Caddyfile which may lag behind the latest copy."),f("Attempting to restart Caddy container instead...");let l=await dt("restart",ae,"caddy");return l&&_(l),l===null}return N("Caddy configuration reloaded"),!0}c(Y,"reloadCaddy");function je(){let e=j();if(e)return f(`Caddy start skipped (${e})`),!0;f("Starting Caddy reverse proxy...");let t=fn(["up","-d","caddy"],{capture:!0});return t&&N("Caddy reverse proxy started"),t}c(je,"startCaddy");var L="werkmeister-shared";function Pt(){try{if(F(["docker","network","inspect",L],{capture:!0,timeout:30}).status===0)return!0;let e=F(["docker","network","create","--label",`com.docker.compose.project=${ae}`,"--label",`com.docker.compose.network=${L}`,L],{capture:!0,timeout:30});if(e.status!==0)return _(`Could not create the ${L} network: ${e.stderr.trim()}`),!1}catch(e){if(e instanceof ee)return _(`Could not create the ${L} network: ${e.message}`),!1;throw e}return f(`Created the ${L} network`),!0}c(Pt,"ensureSharedNetwork");async function H(){return(await ne(ae,"caddy")??[]).some(t=>t.state==="running")}c(H,"isCaddyRunning");function gn(e){Ie(e).refresh(e),Rt(e,"chore: refresh Claude settings",[".claude/settings.json",".werkmeister/claude-permissions.json"])&&f("Committed the refreshed .claude/settings.json on the record branch")}c(gn,"refreshWorkspaceSettings");async function hn(e,t,{signal:n,byPerson:o}={}){if(T(e,"up"),Jt(e,t),ge(t),!k.existsSync(b.join(t,A)))throw new y(`No ${A} found in workspace: ${t}
|
|
5
|
+
Run 'werkmeister workspace init' first to generate it.`,"NO_COMPOSE");f("Loading configuration...");let r=Pe(z(),t),s={services:r,ports:X()},i=Vt(t);Bt(r,i,t),De(t,i,r),gn(t);let{slot:a,regenerated:u,staleCompose:l}=await Mt(e,t,s,i),[d,w]=Fe(a);if(i.length){await _e(t,void 0);let C=await Me(e,t,o??An(t));if(C!==null)return $(`Waiting for capacity, position ${C} \u2014 it starts when another feature stops`),{waitingNote:await Ut(e,C,!0,re(t)),feature:e,slot:a,portRange:[d,w],localServices:i,urls:[],servicePorts:[],regenerated:u,staleCompose:l,containersStarted:!1,caddy:"skipped",waiting:C}}else await V(e),U(t);Le(e,a,i,s,t),S(`
|
|
6
|
+
${m.CYAN}Local services: ${m.BOLD}${i.length?i.join(", "):"(none -- all via k8s)"}${m.RESET}
|
|
7
|
+
|
|
8
|
+
`);let p=et(r),h=Be(i,r),E=h||i.some(C=>p[C]);h?(f("Checking k8s port-forwards..."),await bt()==="restarted"&&await Nt()):f("No local service needs the cluster -- skipping k8s port-forwards");let v=!1;if(i.length){if(qt(),f("Starting containers..."),!await ue(t,"up",()=>ct(e,n)))throw new y("Failed to start containers. Check docker compose output above.","COMPOSE_UP_FAILED");v=!0}else{f("No local services to start -- routing entirely to k8s");let C=Ot(r,i,t);C.length&&f(`start one with: werkmeister feature up --service <name> (${C.join(", ")})`)}f("Configuring reverse proxy..."),await G(null,s),await $e(ye(r));let g,x=j();x?(f(`Caddy skipped (${x})`),g="skipped"):await H()?(await Y(),g="reloaded"):E?(f("Caddy not running -- starting it..."),je(),g="started"):(f("Caddy not running and nothing here is routed -- leaving it stopped"),g="skipped");let R=i.map(C=>p[C]?.hostname).filter(C=>!!C).map(C=>`https://${C}`),O=[...i].sort().map(C=>{let me=r[C]??{},en=typeof me=="object"&&me!==null?me.port_offset??0:0;return{service:C,port:Et(a,en)}});return{feature:e,slot:a,portRange:[d,w],localServices:i,urls:R,servicePorts:O,regenerated:u,staleCompose:l,containersStarted:v,caddy:g}}c(hn,"up");async function Mt(e,t,n,o){f("Allocating feature slot...");let r=Cn(t),s=await St(e,t,r),[i,a]=Fe(s);f(`Slot ${s} -> port range ${i}-${a}`);let u=r!==null&&s!==r,l=!1;return u?($(`Slot changed (${r} \u2192 ${s}) \u2014 regenerating compose...`),ce(e,s,o,n,t,"werkmeister feature up"),Te(e,s,o,n,t)):At(e,s,o,n,t)&&(l=!0,$(`${A} predates the current template or registry \u2014 regenerating...`),ce(e,s,o,n,t,"werkmeister feature up")),{slot:s,regenerated:u,staleCompose:l}}c(Mt,"prepareSlot");async function wn(e,t,n,o=A,{skipCurrentSetups:r=!1,park:s=!1,grant:i=!0,waitMs:a}={}){T(e,"pr gate"),ge(t);let u=b.join(t,A);if(!k.existsSync(u))throw new y(`No ${A} found in workspace: ${t}
|
|
9
|
+
Run 'werkmeister workspace init' first to generate it.`,"NO_COMPOSE");let l={services:Pe(z(),t),ports:X()};Bt(l.services,[n],t),De(t,[n],l.services),await Mt(e,t,l,Vt(t));let d=r&&await ht(b.join(t,o),n);await _e(t,d?[n]:Oe(t,n)),await $n(e,t,n,{noDeps:d,park:s,grant:i,...a!==void 0&&{waitMs:a}});let w;try{qt(),w=await ue(t,"gate",()=>ke(e,n,b.join(t,o),d))}finally{i&&await Wt()}if(!w){let p=(await P(e)).find(h=>h.service===n)?.status;throw new y(`Failed to start ${n}${p?` (left ${p})`:""} \u2014 see the compose output above`,"COMPOSE_UP_FAILED")}}c(wn,"startService");var Tt=15e3,yn=10*6e4;async function $n(e,t,n,{sleep:o=mn,waitMs:r=yn,noDeps:s=!1,park:i=!1,grant:a=!0}={}){let u=(await P(e)).filter(g=>g.status==="running"),l=new Set(u.map(g=>g.service)),d=(s?[n]:Oe(t,n)).filter(g=>!l.has(g));if(!d.length)return;let w=W(t);if(w&&!w.services&&(await $t()).includes(e))throw new y(`'${e}' is waiting for capacity (${w.reason}, position ${w.position}); ${n} was not started. It starts with the rest of the feature when room frees.`,"NO_CAPACITY");let p={services:d},h=[],E=!1,v=!1;try{for(let g=0;;g+=Tt){let x=await Me(e,t,!1,p);if(x!==null&&u.length&&!h.length&&te(t)&&(await qe(e,{grant:!1}),h=u.map(R=>R.name),p={services:[...l,...d],gate:!0},f(`Stopped ${[...l].join(", ")} while waiting, so '${e}' holds no capacity`),x=await Me(e,t,!1,p)),x===null){if(E=!0,h.length&&!await ke(e,[...l],b.join(t,A),!0)){let R=new Set((await P(e)).filter(O=>O.status==="running").map(O=>O.name));throw new y(`Could not start ${[...l].join(", ")} again after waiting for capacity; still stopped: ${h.filter(O=>!R.has(O)).join(", ")||"none"}. \`werkmeister feature up\` starts the feature again.`,"COMPOSE_UP_FAILED")}return}if(g>=r){let R=i&&!h.length?W(t):null;throw R&&(ze(t,{...R,parked:{service:n}}),v=!0),new y(`No capacity to start ${d.join(", ")} for '${e}' after ${r/6e4} min (queue position ${x})${v?"; it stays queued":""}.`+(h.length?` ${[...l].join(", ")} stayed stopped; \`werkmeister feature up\` starts the feature again.`:"")+`
|
|
10
|
+
${await Ut(e,x,v,re(t,p.services))}`,"NO_CAPACITY")}g||$(`Waiting for capacity to start ${d.join(", ")}: position ${x}, up to ${r/6e4} min. Stopping the command ends the wait; \`pr gate\` and \`pr open\` start no service the PR file's \`skip_tests\` names.`),await o(Tt)}}finally{!E&&!v&&(await V(e),U(t)),!E&&a&&await Wt()}}c($n,"admitServiceStart");async function Wt(){D().length&&await Ue()}c(Wt,"grantIfQueued");var K=c(e=>`${(e/2**30).toFixed(1)} GiB`,"gib"),Q=c(e=>`${Number(e.toFixed(1))} CPUs`,"cpus"),Sn={idle:"idle","human-check":"waiting on a person",working:"working",person:"a person's workspace"};function En(e){return`${e.feature} (${Q(e.cost.cpus)}, ${K(e.cost.memory)}, ${Sn[e.rank]}${e.busy?", gate running":""})`}c(En,"describeLease");async function Ut(e,t,n,o){let r=Qt()??[],s=[`running: ${r.map(En).join(", ")||"nothing werkmeister started"}`],i=await Re();if(Number.isFinite(i.cpus)&&Number.isFinite(i.memory)){let u=r.reduce((l,d)=>({cpus:l.cpus+d.cost.cpus,memory:l.memory+d.cost.memory}),{cpus:0,memory:0});s.push(`this start needs ${Q(o.cpus)}, ${K(o.memory)}; free ${Q(Math.max(0,i.cpus-u.cpus))}, ${K(Math.max(0,i.memory-u.memory))} of the budget's ${Q(i.cpus)}, ${K(i.memory)}`)}let a=t>1?mt(wt(D(),r))[0]:void 0;if(a&&a.feature!==e){let u=oe()[a.feature]?.workspace,l=u?re(u,W(u)?.services):null;s.push(`behind ${a.feature}${l?` (needs ${Q(l.cpus)}, ${K(l.memory)})`:""}`+(a.waitedMs>=3e5&&!a.parked?`, which has waited ${Math.round(a.waitedMs/6e4)} min and gets the next free room`:""))}return s.push(n?"It starts by itself when room frees, and the session is told to continue. Exit 75: queued, not a failure.":"Exit 75: no capacity yet, not a failure of the change. Rerun the same command; nothing to ask a person."),r.length&&r.every(u=>u.rank==="person")&&s.push(`Only a person can free room: werkmeister feature stop ${r.map(u=>u.feature).join(" or ")}.`),s.join(`
|
|
11
|
+
`)}c(Ut,"capacityWait");function qt(){if(!Pt())throw new y("Could not create the werkmeister-shared network","COMPOSE_UP_FAILED")}c(qt,"requireSharedNetwork");function Cn(e){let t=b.join(e,".env");if(!k.existsSync(t)||!k.statSync(t).isFile())return null;for(let n of k.readFileSync(t,"utf8").split(`
|
|
12
|
+
`)){let o=n.trim();if(o.startsWith("WERKMEISTER_SLOT=")){let r=o.slice(17).trim(),s=Number(r);if(r!==""&&Number.isInteger(s))return s}}return null}c(Cn,"readSlotFromWorkspace");function Vt(e){let t=b.join(e,".env");if(!k.existsSync(t)||!k.statSync(t).isFile())return[];for(let n of k.readFileSync(t,"utf8").split(`
|
|
13
|
+
`)){let o=n.trim();if(o.startsWith("SERVICES="))return o.slice(9).trim().split(",").map(r=>r.trim()).filter(r=>r)}return[]}c(Vt,"readServicesFromWorkspace");function Bt(e,t,n){let o=vt(),{missing:r}=kt(xt(o),e,t,_t(n));if(r.length)throw new y(`Missing required secret(s) in ${o}: ${r.join(", ")}
|
|
14
|
+
Run \`werkmeister machine setup\` to write a template to ${o}, then fill in the missing values (or pin them under \`env_vars:\` in .werkmeister/workspace.yml).`,"MISSING_SECRETS")}c(Bt,"requireSecrets");function Gt(e,t=process.env,n="/.dockerenv"){return(t.WERKMEISTER_FEATURE??t.SANDBOX_FEATURE)===e&&k.existsSync(n)}c(Gt,"insideOwnContainer");function T(e,t){if(Gt(e))throw new y(`'werkmeister ${t}' is running inside ${e}'s own container, which it would recreate or stop and so kill itself.
|
|
15
|
+
Run it from the host: cd to the workspace and run 'werkmeister ${t}'.`,"INSIDE_OWN_CONTAINER")}c(T,"refuseInsideOwnContainer");var kn=new Set(["clear","resume"]);function fe(e,t=Date.now()){return Object.entries(Z(e,t)).map(([n,o])=>({sessionId:n,status:o.status,statusUpdatedAt:Date.parse(o.last??o.at),asking:o.ask!==void 0})).filter(n=>t-n.statusUpdatedAt<Ke)}c(fe,"liveSessions");function vn(e,t){return fe(e).map(n=>n.sessionId).filter(n=>n!==t)}c(vn,"otherLiveSessions");function xn(e,t,n){let o=c(s=>(s.statusUpdatedAt??1/0)>n,"recent");return t.sessions(e.workspace).some(s=>s.asking&&t.queued?o(s):s.status!=="idle"||o(s))?"session active":e.startedAt.some(s=>s>n)?`started < ${t.minutes} min ago`:(t.lastExec(e.workspace)??0)>n?`gate ran < ${t.minutes} min ago`:null}c(xn,"busyReason");function Rn(){let e=He().overrides?.idle_stop_minutes;return Number.isInteger(e)&&e>=0?e:30}c(Rn,"idleStopMinutes");function Yt(e){return b.join(Ve(e),"last-exec")}c(Yt,"lastExecMarker");function Ht(e){try{return k.statSync(e).mtimeMs}catch{return null}}c(Ht,"mtimeMs");var _n="com.docker.compose.project.working_dir";function Kt(e=t=>F(t,{capture:!0,timeout:20})){try{let t=new Set;for(let i of[Ae,be]){let a=e(["docker","ps","-q","--filter",`label=${i}`]);if(a.status!==0)return null;for(let u of a.stdout.split(`
|
|
16
|
+
`).filter(Boolean))t.add(u)}if(!t.size)return[];let o=`{{${`or (index .Config.Labels "${Ae}") (index .Config.Labels "${be}")`}}} {{index .Config.Labels "${_n}"}} {{.State.StartedAt}} {{.HostConfig.MemoryReservation}} {{.HostConfig.NanoCpus}}`,r=e(["docker","inspect","--format",o,...t]);if(r.status!==0)return null;let s=new Map;for(let i of r.stdout.split(`
|
|
17
|
+
`).filter(Boolean)){let[a,u,l,d,w]=i.split(" ");if(!a||!u)continue;let p=s.get(a)??{feature:a,workspace:u,startedAt:[],memory:0,cpus:0};p.startedAt.push(Date.parse(l)),p.memory+=Number(d)||0,p.cpus+=(Number(w)||0)/1e9,s.set(a,p)}return[...s.values()]}catch{return null}}c(Kt,"runningFeatures");async function Ro(e,t={}){let n=t.run??(d=>F(d,{capture:!0,timeout:20})),o=Kt(n);if(!o)return{ok:!0,lines:["docker unavailable \u2014 nothing reaped"]};let r=o.filter(d=>!t.only||d.feature===t.only);if(!r.length)return{ok:!0,lines:["no running feature containers"]};let s=t.now??Date.now(),i={minutes:e,now:s,running:r,sessions:c(d=>fe(d,s),"sessions"),lastExec:c(d=>Ht(Yt(d)),"lastExec"),queued:t.queued??D().length>0},a=i.now-e*6e4,u=[],l=!0;for(let d of r){let w=d.feature==="infra"?"shared infra":Gt(d.feature)?"running inside its own container":xn(d,i,a);if(w){u.push(`${d.feature}: kept (${w})`);continue}let p=i.sessions(d.workspace).some(h=>h.asking);try{await(t.stop??qe)(d.feature),u.push(p?`${d.feature}: stopped (waiting on a person \u2265 ${e} min, others queued)`:`${d.feature}: stopped (idle \u2265 ${e} min)`)}catch(h){l=!1,u.push(`${d.feature}: stop failed \u2014 ${h.message}`)}}return{ok:l,lines:u}}c(Ro,"stopIdle");function _o(e){let{feature:t,workspaceRoot:n,sessionId:o,reason:r,entrypoint:s}=e;return!t||t==="infra"||r&&kn.has(r)||s?.startsWith("sdk")||vn(n,o).length?null:t}c(_o,"idleStopFeature");var On="Capacity freed: this workspace's containers are up. Continue where you left off.";async function Dt(e){let t=(await P(e)).filter(n=>n.status!=="running"&&!pt(n.service,n.role));return t.length?`Capacity freed: this workspace started, but these containers are still stopped: ${t.map(n=>n.name).join(", ")}. Start them with ${t.map(n=>`\`werkmeister feature up --service ${n.service}\``).join(", ")}, then continue where you left off.`:On}c(Dt,"grantedNudge");function Qt(e){let t=Kt(e);if(!t)return null;let n=Date.now()-Math.max(Rn(),2)*6e4;return t.map(o=>{let r=he(Z(o.workspace)),s=o.feature==="infra"?"person":r?.agent==="needs-you"?"human-check":te(o.workspace)?r?.agent==="working"?"working":"idle":"person",i=M(o.workspace)!==null||(Ht(Yt(o.workspace))??0)>n;return{lease:{feature:o.feature,cost:{memory:o.memory,cpus:o.cpus},rank:s,busy:i},at:r?Date.parse(r.at):0}}).sort((o,r)=>o.at-r.at).map(o=>o.lease)}c(Qt,"runningLeases");function An(e,t=process.env){return!te(e)&&!t.CLAUDECODE}c(An,"startsAsPerson");function Me(e,t,n,o){return se("admit",{feature:e,workspace:t,byPerson:n,starting:o},()=>bn(e,t,n,o),15*6e4)}c(Me,"admitOrQueue");async function bn(e,t,n,o){let r=Qt();if(r===null)return null;let s=await Re(),i=await yt(e,t,n,r,s,o);if(i.kind==="never-fits"){let{cost:a}=i,u=c(d=>`${(d/2**30).toFixed(1)} GiB`,"gib"),l=a.cpus>s.cpus?`cost ${a.cpus.toFixed(1)} CPUs > budget ${s.cpus}; raise the engine's CPUs or budget.cpus`:`cost ${u(a.memory)} memory > budget ${u(s.memory)}; raise the engine's memory or budget.memory`;throw new y(`'${e}' can never fit the budget${o?` to start ${o.services.join(", ")}`:""}: ${l} in ~/.werkmeister/config.yaml, or start fewer services.`,"NEVER_FITS")}if(i.kind==="wait")return i.position;if(i.kind==="preempt")for(let a of i.victims){let u=oe()[a]?.workspace||I(a);try{await qe(a,{grant:!1})}catch(d){let w=(await P(a)).some(p=>p.status==="running");return u&&!w&&await xe(a,u),$(`Could not stop '${a}' to make room (${d.message}); waiting instead`+(w?`, and '${a}' keeps running`:"")),gt(e,t,o)}u&&await xe(a,u);let l=r.find(d=>d.feature===a)?.rank;f(`Stopped '${a}' to make room: its session is ${l==="human-check"?"waiting on a person":l==="working"?"working":"idle"} (preemption; budget.preempt: false turns it off)`)}return null}c(bn,"admitOrQueueHere");function Oo(){return se("grant",{},We,15*6e4)}c(Oo,"grantWaiters");var Lt=Promise.resolve();function We(){let e=Lt.then(jt,jt);return Lt=e.catch(()=>{}),e}c(We,"grantHere");function Ao(){let e=D().length;return e&&We().catch(t=>$(`Waiting queue: ${t.message}`)),e}c(Ao,"grantInBackground");async function jt(){let e=[];for(let t of D()){let n=oe()[t]?.workspace;if(!n){await V(t);continue}let o=W(n);if(o?.parked){await Nn(t,n,o.parked.service)&&(e.push(t),fe(n).length&&q(n,await Dt(t)));continue}if(o?.services)continue;let r;try{r=await hn(t,n,{byPerson:!1})}catch(s){$(`Could not start '${t}' from the waiting queue: ${s.message}`),s instanceof y&&s.code==="NEVER_FITS"&&q(n,s.message);continue}r.waiting===void 0&&(e.push(t),fe(n).length&&q(n,await Dt(t)))}return e}c(jt,"grantWaitersNow");async function Nn(e,t,n){try{await wn(e,t,n,A,{park:!0,waitMs:0,grant:!1})}catch(o){if(!(o instanceof y&&o.code==="NO_CAPACITY")){let r=`Could not start '${e}' ${n} from the waiting queue: ${o.message}`;$(r),q(t,r)}return!1}return await In().catch(o=>$(`Proxy not reloaded for '${e}': ${o.message}`)),!0}c(Nn,"startParked");async function Ue(){try{let e=await se("grant-later",{},async()=>null);if(e!==null){e&&f(`The daemon will start the next waiting feature (${e} waiting)`);return}for(let t of await We())N(`Started '${t}' from the waiting queue`)}catch(e){$(`Could not start the next waiting feature: ${e instanceof Error?e.message:String(e)}`)}}c(Ue,"grantWaitersQuietly");async function qe(e,{grant:t=!0}={}){T(e,"stop");let n=await pe(e);if(f(`Stopping containers for '${e}' (slot ${n})...`),!await lt(e))throw new y(`Failed to stop containers for '${e}'`,"COMPOSE_STOP_FAILED");return t&&await Ue(),{feature:e,slot:n}}c(qe,"stop");async function bo(e){T(e,"restart");let t=await pe(e),n=I(e);if(Jt(e,n),f(`Restarting containers for '${e}' (slot ${t})...`),!(n?await ue(n,"restart",()=>ve(e)):await ve(e)))throw new y(`Failed to restart containers for '${e}'`,"COMPOSE_RESTART_FAILED");return await V(e),n&&U(n),{feature:e,slot:t}}c(bo,"restart");function Jt(e,t){if(t&&M(t))throw new y(`'${e}' is paused; Resume it first`,"PAUSED")}c(Jt,"refusePaused");function zt(e){let t=I(e);if(!t)throw new y(`No workspace folder for '${e}'`,"NO_WORKSPACE");return t}c(zt,"workspaceOrThrow");var Xt=c(e=>e.statusCode,"statusOf"),Zt=c(e=>e.json?.message??e.message,"daemonMessage");async function No(e){T(e,"pause");let t=await pe(e),n=zt(e);if(M(n))throw new y(`'${e}' is already paused`,"ALREADY_PAUSED");let o=await ne(await it(e),void 0,{all:!1});if(o===null)throw new y("docker not found / not running","COMPOSE_PAUSE_FAILED");let r=ft(o.filter(i=>i.state==="running")).map(i=>i.name);Xe(n)&&Ze(n),Je(n,{at:new Date().toISOString(),containers:r,was_working:he(Z(n))?.agent==="working"}),f(`Pausing ${r.length} container(s) for '${e}' (slot ${t})...`);let s=[];for(let i of[...r].reverse())try{await Se().getContainer(i).pause()}catch(a){Xt(a)!==409&&s.push(`${i}: ${Zt(a)}`)}if(s.length)throw new y(`docker pause failed: ${s.join("; ")}`,"COMPOSE_PAUSE_FAILED");return N(`Paused '${e}': its Claude session is held until Resume`),{feature:e,slot:t,containers:r}}c(No,"pause");async function Fo(e){T(e,"resume");let t=zt(e),n=M(t);if(!n)throw new y(`'${e}' is not paused`,"NOT_PAUSED");f(`Resuming ${n.containers.length} container(s) for '${e}'...`);let o=[];for(let r of n.containers){let s=Se().getContainer(r);try{let{State:i}=await s.inspect();i.Paused?(await s.unpause(),o.push({name:r,did:"unpaused"})):i.Running||(await s.start(),o.push({name:r,did:"started"}))}catch(i){if(Xt(i)!==404)throw new y(`docker resume ${r} failed: ${Zt(i)}`,"COMPOSE_RESUME_FAILED");$(`${r} is gone; nothing to resume`),o.push({name:r,did:"missing"})}}return we(t),N(`Resumed '${e}'`),{feature:e,workspace:t,containers:o,wasWorking:n.was_working}}c(Fo,"resume");async function Io(e,{removeVolumes:t=!1,signal:n}={}){T(e,"down");try{let{leaveFeatureIntercepts:s,releaseIdleTelepresence:i}=await import("./telepresence-MM45AMTK.js"),a=s(e);a.length&&f(`Left k8s intercept(s): ${a.join(", ")}`),await i(a)}catch(s){$(`Could not clean up k8s intercepts: ${s instanceof Error?s.message:String(s)}`)}let o=I(e),r=await Ne(e);return r===null&&($(`Feature '${e}' does not have an allocated slot`),$("It may already be stopped. Cleaning up anyway...")),f("Stopping containers..."),t&&f("Per-feature Docker volumes will be removed"),await ut(e,{removeVolumes:t,signal:n})||$(`Containers for '${e}' may still exist -- see the docker compose output above`),f("Releasing feature slot..."),await ie(e),o&&(we(o),U(o),k.rmSync(Qe(o),{force:!0})),await Ue(),{feature:e,slot:r}}c(Io,"down");async function Po(e,t){let n={services:z(),ports:X()},o=await pe(e),r=[...(await B())[e]?.services??[]];if(!r.includes(t))throw new y(`Service '${t}' is not running locally for '${e}'`,"NOT_LOCAL");r.splice(r.indexOf(t),1),f(`Removed '${t}' from local services -- will fall back to k8s`),f("Regenerating configuration files..."),ce(e,o,r,n),Te(e,o,r,n),Le(e,o,r,n);let s=!1;r.length?(f("Restarting containers..."),at(e)):(f("No local services remaining -- containers will be stopped"),s=!0,Ce(e)||$(`Containers for '${e}' may still exist -- see the docker compose output above`)),f("Updating reverse proxy..."),await G(null,n);let i=!1;return await H()&&(await Y(),i=!0),{feature:e,removed:t,remaining:[...r].sort(),containersStopped:s,proxyReloaded:i}}c(Po,"removeService");var Fn={generate:c(()=>G(),"generate"),slots:c(()=>B(),"slots"),running:c(()=>H(),"running"),reload:c(()=>Y(),"reload"),start:c(()=>je(),"start"),hosts:c(()=>ye(),"hosts")};async function In({start:e=!1}={},t=Fn){f(e?"Regenerating Caddyfile...":"Updating reverse proxy configuration..."),await t.generate(),await $e(t.hosts(),t.lookup);let n=await t.slots(),o=Object.keys(n).sort().map(i=>({feature:i,slot:n[i].slot,services:n[i].services}));if(e)if(!o.length)f("No active features in Caddyfile");else{S(`
|
|
18
|
+
${m.CYAN}Features in Caddyfile:${m.RESET}
|
|
19
|
+
`);for(let{feature:i,slot:a,services:u}of o){let l=u.length?u.join(", "):"(no local services)";S(` ${m.GREEN}*${m.RESET} ${i} (slot ${a}): ${l}
|
|
20
|
+
`)}S(`
|
|
21
|
+
`)}let r=!1,s=!0;return await t.running()?(e&&f("Reloading Caddy..."),s=await t.reload()):e?($("Caddy is not running -- starting it..."),s=t.start(),r=!0):f("Caddy is not running -- skipping reload"),{features:o,started:r,ok:s}}c(In,"reloadProxy");function Pn(){let e;try{e=Ge()}catch(t){return $(`Could not read the service registry (${t instanceof Error?t.message:String(t)}) -- skipping Docker volume cleanup`),[]}return e.sort((t,n)=>n.length-t.length||t.localeCompare(n))}c(Pn,"volumeBaseNames");async function Tn(e){if(!e.length)return[];let t=await rt();if(t===null)return[];let n=[];for(let o of t)for(let r of e)if(o.endsWith(`-${r}`)){n.push(o);break}return n.sort()}c(Tn,"listSandboxVolumes");function Dn(e,t){for(let n of t){let o=`-${n}`;if(e.endsWith(o))return e.slice(0,e.length-o.length)}return null}c(Dn,"featureFromVolume");function Ln(e,t,n){let o=[],r=[];for(let s of e){let i=Dn(s,t);(i&&n.has(i)?o:r).push(s)}return{activeVolumes:o,orphanedVolumes:r}}c(Ln,"classifyVolumes");async function To(e={}){return jn({...e,dryRun:!0})}c(To,"planClean");async function jn({all:e=!1,dryRun:t=!1}={}){t&&f(`Dry run -- nothing will be removed
|
|
22
|
+
`);let n=Object.keys(await B()).sort(),o=new Set(n);if(o.size?S(` ${m.CYAN}Active features:${m.RESET} ${n.join(", ")}
|
|
23
|
+
`):S(` ${m.DIM}No active features${m.RESET}
|
|
24
|
+
`),S(`
|
|
25
|
+
`),e&&o.size){f("--all: tearing down active features...");for(let p of n){if(t){S(` ${m.DIM}[dry-run] Would stop: ${p}${m.RESET}
|
|
26
|
+
`);continue}f(`Stopping ${p}...`),Ce(p,{removeVolumes:!0})||$(`Containers for '${p}' may still exist -- see the docker compose output above`),await ie(p)}t||(await G(),await H()&&await Y()),S(`
|
|
27
|
+
`),o=new Set}f("Scanning for per-feature Docker volumes...");let r=Pn(),s=await Tn(r),i=[],{activeVolumes:a,orphanedVolumes:u}=Ln(s,r,o);if(!s.length)S(` ${m.DIM}No per-feature Docker volumes found${m.RESET}
|
|
28
|
+
`);else{if(a.length){S(`
|
|
29
|
+
${m.CYAN}Active feature volumes (kept):${m.RESET}
|
|
30
|
+
`);for(let p of a)S(` ${m.DIM}${p}${m.RESET}
|
|
31
|
+
`)}if(u.length){S(`
|
|
32
|
+
${m.YELLOW}Orphaned volumes to remove:${m.RESET}
|
|
33
|
+
`);for(let p of u)t?S(` ${m.DIM}[dry-run] Would remove: ${p}${m.RESET}
|
|
34
|
+
`):await st(p)?(S(` ${m.GREEN}Removed:${m.RESET} ${p}
|
|
35
|
+
`),i.push(p)):S(` ${m.RED}Failed:${m.RESET} ${p} (may be in use)
|
|
36
|
+
`);t||N(`Removed ${i.length}/${u.length} orphaned volume(s)`)}else S(`
|
|
37
|
+
${m.DIM}No orphaned volumes found${m.RESET}
|
|
38
|
+
`)}let l=Object.keys(await B()),d=[],w=[];if(!e){for(let p of l)!(await P(p)).filter(E=>E.status==="running").length&&I(p)===null&&d.push(p);if(d.length){S(`
|
|
39
|
+
${m.YELLOW}Stale slot entries (no running containers or compose file):${m.RESET}
|
|
40
|
+
`);for(let p of d)t?S(` ${m.DIM}[dry-run] Would release slot: ${p}${m.RESET}
|
|
41
|
+
`):(await ie(p),w.push(p),S(` ${m.GREEN}Released:${m.RESET} ${p}
|
|
42
|
+
`))}}return{activeFeatures:n,activeVolumes:a,orphanedVolumes:u,staleSlots:d,removedVolumes:i,releasedSlots:w}}c(jn,"runClean");async function pe(e){let t=await Ne(e);if(t===null)throw new y(`Feature '${e}' is not running (no slot allocated)`,"NOT_RUNNING");return t}c(pe,"requireSlot");async function Do(e){let t=I(e);if(t===null)return{workspace:null,handoff:null,decisions:[],graduated:[]};let{decisions:n}=Ie(t),o=nt(t,null,n);return{workspace:t,handoff:tt(t),decisions:n.open(t),graduated:o}}c(Do,"teardownNotes");export{gn as a,hn as b,wn as c,En as d,Vt as e,Gt as f,fe as g,Rn as h,Yt as i,Kt as j,Ro as k,_o as l,Qt as m,Me as n,Oo as o,Ao as p,qe as q,bo as r,No as s,Fo as t,Io as u,Po as v,In as w,To as x,jn as y,Do as z};
|
|
43
|
+
//# sourceMappingURL=chunk-46UPT6E4.js.map
|