@lensmcp/cluster 1.26.1 → 1.26.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/README.md +1 -1
  2. package/build-host.js +1 -1
  3. package/devserver-host.d.ts +5 -0
  4. package/devserver-host.js +1 -1
  5. package/executors/gateway/main.rollout.d.ts +1 -2
  6. package/executors/gateway/main.rollout.js +1 -1
  7. package/executors/gateway/runtime/auth.js +1 -1
  8. package/executors/gateway/runtime/client-ip-env.d.ts +10 -0
  9. package/executors/gateway/runtime/client-ip-env.js +1 -0
  10. package/executors/gateway/runtime/control.d.ts +25 -0
  11. package/executors/gateway/runtime/control.js +2 -2
  12. package/executors/gateway/runtime/discovery.js +1 -1
  13. package/executors/gateway/runtime/docker-sweep.d.ts +51 -0
  14. package/executors/gateway/runtime/docker-sweep.js +1 -0
  15. package/executors/gateway/runtime/edge.d.ts +2 -0
  16. package/executors/gateway/runtime/edge.js +1 -1
  17. package/executors/gateway/runtime/frontend-updates.d.ts +24 -0
  18. package/executors/gateway/runtime/frontend-updates.js +1 -0
  19. package/executors/gateway/runtime/handler.js +1 -1
  20. package/executors/gateway/runtime/legacy-dashboard-link.d.ts +10 -0
  21. package/executors/gateway/runtime/legacy-dashboard-link.js +1 -0
  22. package/executors/gateway/runtime/lens-children.d.ts +9 -0
  23. package/executors/gateway/runtime/lens-children.js +1 -1
  24. package/executors/gateway/runtime/lifecycle.d.ts +2 -0
  25. package/executors/gateway/runtime/lifecycle.js +4 -4
  26. package/executors/gateway/runtime/peer-hub.d.ts +54 -0
  27. package/executors/gateway/runtime/peer-hub.js +1 -0
  28. package/executors/gateway/runtime/proxy.js +1 -1
  29. package/executors/gateway/runtime/remote-instances.d.ts +167 -0
  30. package/executors/gateway/runtime/remote-instances.js +1 -0
  31. package/executors/gateway/runtime/run-routes.d.ts +186 -0
  32. package/executors/gateway/runtime/run-routes.js +1 -0
  33. package/executors/gateway/runtime/server.d.ts +2 -1
  34. package/executors/gateway/runtime/server.js +2 -2
  35. package/executors/gateway/runtime/service-updates.d.ts +44 -0
  36. package/executors/gateway/runtime/service-updates.js +1 -0
  37. package/executors/gateway/runtime/shared-build.d.ts +8 -1
  38. package/executors/gateway/runtime/shared-build.js +4 -4
  39. package/executors/gateway/runtime/types.d.ts +54 -0
  40. package/executors/gateway/runtime/update-wiring.d.ts +57 -0
  41. package/executors/gateway/runtime/update-wiring.js +2 -0
  42. package/executors/gateway/runtime/updates.d.ts +148 -0
  43. package/executors/gateway/runtime/updates.js +1 -0
  44. package/executors/gateway/runtime/upgrade.js +1 -1
  45. package/executors/serve/serve.impl.js +1 -1
  46. package/executors/serve/updates-gate.d.ts +147 -0
  47. package/executors/serve/updates-gate.js +2 -0
  48. package/main.devserver.js +10 -10
  49. package/package.json +5 -5
  50. package/program-id.d.ts +4 -0
  51. package/program-id.js +1 -0
  52. package/shared-build/host.d.ts +102 -2
  53. package/shared-build/host.js +3 -3
  54. package/shared-build/protocol.d.ts +59 -3
  55. package/shared-build/protocol.js +1 -1
  56. package/shared-build/shared-compilation.d.ts +21 -0
  57. package/shared-build/shared-compilation.js +3 -3
  58. package/static-checks-record.d.ts +391 -0
  59. package/static-checks-record.js +5 -0
  60. package/tsgo-check-plugin.d.ts +107 -43
  61. package/tsgo-check-plugin.js +4 -5
  62. package/tsgo-shim.d.ts +112 -0
  63. package/tsgo-shim.js +2 -0
  64. package/typecheck-bus.d.ts +36 -5
  65. package/typecheck-bus.js +4 -4
  66. package/typecheck-memory.d.ts +187 -0
  67. package/typecheck-memory.js +1 -0
  68. package/typecheck-queue.d.ts +41 -3
  69. package/typecheck-queue.js +1 -1
@@ -1,3 +1,3 @@
1
- "use strict";var j=Object.defineProperty;var y=(p,e)=>j(p,"name",{value:e,configurable:!0});var k=Object.defineProperty,h=y((p,e)=>k(p,"name",{value:e,configurable:!0}),"h");Object.defineProperty(exports,"__esModule",{value:!0}),exports.BuildHost=exports.DEFAULT_PAUSE_MS=void 0,exports.withEnv=withEnv,exports.buildTargetString=buildTargetString;const tslib_1=require("tslib"),node_crypto_1=require("node:crypto"),path=tslib_1.__importStar(require("node:path")),checkout_cache_1=require("../checkout-cache"),config_files_1=require("../config-files"),compile_retry_1=require("../compile-retry"),dev_devtool_1=require("../dev-devtool"),create_webpack_dev_1=require("../create-webpack-dev"),perf_rules_plugin_1=require("../perf/perf-rules-plugin"),signature_1=require("./signature"),shared_compilation_1=require("./shared-compilation");exports.DEFAULT_PAUSE_MS=5e3;function withEnv(p,e){const t={...process.env};for(const o of Object.keys(process.env))delete process.env[o];for(const[o,s]of Object.entries(p))s!==void 0&&(process.env[o]=s);try{return e()}finally{for(const o of Object.keys(process.env))delete process.env[o];Object.assign(process.env,t)}}y(withEnv,"withEnv"),h(withEnv,"withEnv");function buildTargetString(p){return`${p.project}:${p.target}${p.configuration?`:${p.configuration}`:""}`}y(buildTargetString,"buildTargetString"),h(buildTargetString,"buildTargetString");const shortHash=h(p=>(0,node_crypto_1.createHash)("sha256").update(p).digest("hex").slice(0,16),"shortHash"),firstLine=h(p=>(p?.message??String(p)).split(`
2
- `)[0],"firstLine");class BuildHost{static{y(this,"BuildHost")}static{h(this,"BuildHost")}constructor(e){this.opts=e,this.groups=new Map,this.members=new Map,this.stopped=!1,this.pauseMs=e.pauseMs??exports.DEFAULT_PAUSE_MS,this.webpack=e.webpack??require("webpack")}tell(e,t){this.opts.send({type:"member",member:e,event:t})}describe(){return[...this.groups.values()].map(e=>({group:e.key,projects:e.registry.projects()}))}evaluate(e){const t=e.options;if(t.webpackConfigPath)try{delete require.cache[require.resolve(path.resolve(t.appRoot,t.webpackConfigPath))]}catch{}const o={...e.env,NODE_ENV:"development",NX_BUILD_TARGET:buildTargetString(e),NX_WORKSPACE_ROOT:this.opts.root,LENSMCP_TYPECHECK:"off"},s=withEnv(o,()=>(0,create_webpack_dev_1.createDevWebpackConfig)(t)),i=(0,signature_1.transpileCompilerOptions)(t.tsConfig,this.opts.root),r=(0,signature_1.memberSignature)({join:e,devtool:s.devtool,config:s,compilerOptions:i});return{config:s,signature:r,configFiles:(0,config_files_1.configFilesOf)({...t,workspaceRoot:this.opts.root})}}join(e,t){if(this.stopped)return this.tell(e,{type:"refused",reason:"the build host is stopping"});this.leave(e,{quiet:!0});const o=(0,signature_1.refusalOf)(t,this.opts.root);if(o)return this.opts.log(`${t.project}: compiles on its own \u2014 ${o}`),this.tell(e,{type:"refused",reason:o});let s;try{s=this.evaluate(t)}catch(i){const r=`its webpack config could not be built here (${firstLine(i)})`;return this.opts.log(`${t.project}: compiles on its own \u2014 ${r}`),this.tell(e,{type:"refused",reason:r})}this.admit(e,t,s)}admit(e,t,o){let s=this.groups.get(o.signature.key);if(!s){for(const a of this.groups.values()){const l=(0,signature_1.describeDifference)(o.signature,a.signature);this.opts.log(`${t.project}: compiled apart from ${a.registry.projects().sort().join(", ")||"the other group"} \u2014 ${l??"its compile signature differs"}`);break}try{s=this.createGroup(o,t)}catch(a){const l=`the shared compiler could not be created (${firstLine(a)})`;return this.opts.log(`${t.project}: compiles on its own \u2014 ${l}`),this.tell(e,{type:"refused",reason:l})}this.groups.set(s.key,s)}this.members.set(e,{project:t.project,group:s,join:t});for(const a of o.configFiles)s.configFiles.add(a);const i=s.projects.get(t.project)??new Set;i.add(e);const r=!s.projects.has(t.project);s.projects.set(t.project,i);const c=s.pausing.get(t.project);if(c&&(clearTimeout(c),s.pausing.delete(t.project)),this.tell(e,{type:"accepted",group:s.key,projects:[...s.projects.keys()]}),r)s.registry.set(t.project,(0,shared_compilation_1.memberEntries)(t.project,t.options)),this.opts.log(`shared compilation ${s.key.slice(0,8)}: ${s.registry.projects().sort().join(", ")}`),this.kick(s);else{const a=s.last.get(t.project);a&&this.tellBuilt(s,e,a)}}leave(e,t={}){const o=this.members.get(e);if(!o)return;this.members.delete(e);const{project:s,group:i}=o;i.told.delete(e),i.toldFiles.delete(e);const r=i.projects.get(s);if(r?.delete(e),r&&r.size>0)return;t.quiet||this.opts.log(`${s}: no member left \u2014 its entries pause in ${Math.round(this.pauseMs/1e3)} s`);const c=setTimeout(()=>this.pause(i,s),this.pauseMs);c.unref?.(),i.pausing.set(s,c)}pause(e,t){if(e.pausing.delete(t),!((e.projects.get(t)?.size??0)>0)){if(e.projects.delete(t),e.registry.delete(t),e.last.delete(t),e.projects.size===0){this.opts.log(`shared compilation ${e.key.slice(0,8)}: no service left \u2014 closed`),this.groups.delete(e.key),this.closeGroup(e);return}this.opts.log(`shared compilation ${e.key.slice(0,8)}: ${t} paused \u2014 ${e.registry.projects().sort().join(", ")}`),this.kick(e)}}kick(e){if(e.watching){e.watching.invalidate();return}e.watching=e.compiler.watch(e.watchOptions,(t,o)=>this.onBuild(e,t,o))}createGroup(e,t){const o=e.signature.key,s=new shared_compilation_1.EntryRegistry,i=t.options,r=e.config,c=r.devtool,a=path.join((0,checkout_cache_1.checkoutCacheDir)(this.opts.root,"lensmcp-build"),o,"out"),l=(0,create_webpack_dev_1.devCacheOptions)(i,c),n={key:o,signature:e.signature,registry:s,projects:new Map,pausing:new Map,last:new Map,told:new Map,toldFiles:new Map,compiler:void 0,watching:void 0,watchOptions:{},sourceMaps:!1,webpackVersion:"",retry:(0,compile_retry_1.createFailureRetry)(()=>this.compileAgain(n),this.opts.retryDelaysMs??compile_retry_1.RETRY_AFTER_FAILURE_MS),configFiles:new Set(e.configFiles),configChanged:new Set},u=r.plugins.filter(d=>!signature_1.PER_SERVICE_PLUGINS.has(d?.constructor?.name));u.push(new perf_rules_plugin_1.PerfRulesPlugin({project:t.project,workspaceRoot:this.opts.root,tsConfig:i.tsConfig,entries:h(()=>s.entryProjects(),"entries")}),new shared_compilation_1.SharedEntriesPlugin({registry:s,workspaceRoot:this.opts.root,outputPath:a,cache:{...l,name:`shared-${o}`,version:`${l.version}-${o}`}}),new config_files_1.ConfigFilesPlugin({files:h(()=>n.configFiles,"files"),changed:h(d=>{for(const f of d)n.configChanged.add(f)},"changed")}),{apply:h(d=>{d.hooks.watchRun.tap("LensmcpSharedBuild",f=>{const w=[...f.modifiedFiles??[],...f.removedFiles??[]].filter(b=>typeof b=="string").slice(-32);for(const b of this.membersOf(n))this.tell(b,{type:"watch-run",paths:w})}),d.hooks.watchClose.tap("LensmcpSharedBuild",()=>{for(const f of this.membersOf(n))this.tell(f,{type:"watch-closed"})})},"apply")});const g={...r,plugins:u};delete g.watch,n.watchOptions=r.watchOptions??{};const m={...t.env,NODE_ENV:"development",NX_BUILD_TARGET:buildTargetString(t),NX_WORKSPACE_ROOT:this.opts.root,LENSMCP_TYPECHECK:"off"};return n.compiler=withEnv(m,()=>this.webpack(g)),n.sourceMaps=(0,dev_devtool_1.bundleCarriesSourceMaps)(n.compiler.options.devtool),n.webpackVersion=String(n.compiler.webpack?.version??"5"),n}membersOf(e){const t=[];for(const o of e.projects.values())t.push(...o);return t}compileAgain(e){this.stopped||this.groups.get(e.key)!==e||!e.watching||(this.opts.log(`shared compilation ${e.key.slice(0,8)}: compiling again after the failure`),e.watching.invalidate())}onBuild(e,t,o){if(this.stopped||e.configChanged.size>0&&!this.reconfigure(e))return;if(t){const n=t?.message??String(t),{delayMs:u,retry:g}=e.retry.failed();this.opts.log(`shared compilation ${e.key.slice(0,8)} failed: ${n} \u2014 compiling again in ${Math.round(u/1e3)} s (retry ${g})`);for(const m of this.membersOf(e))this.tell(m,{type:"failed",message:n});return}const s=e.retry.succeeded();s>0&&this.opts.log(`shared compilation ${e.key.slice(0,8)}: compiled again after ${s} failure${s===1?"":"s"} \u2014 watching again`);const i=o,r=Math.max(0,(i.endTime??0)-(i.startTime??0)),c=(0,shared_compilation_1.attributeCompilation)(i.compilation,e.registry),a=[];for(const[n,u]of c){e.last.get(n)?.attribution.hash!==u.hash&&a.push(n);const g={attribution:u,durationMs:r};e.last.set(n,g);for(const m of e.projects.get(n)??[])this.tellBuilt(e,m,g)}const l=[...c.values()].filter(n=>n.errorCount>0).map(n=>n.project);this.opts.log(`built ${[...c.keys()].sort().join(", ")||"nothing"} in ${r} ms \u2014 ${a.length?`changed: ${a.sort().join(", ")}`:"no bundle changed"}${l.length?`; errors in: ${l.sort().join(", ")}`:""}`)}reconfigure(e){const t=[...e.configChanged].map(c=>path.relative(this.opts.root,c)).sort().join(", ");e.configChanged.clear();const o=[];for(const[c,a]of this.members){if(a.group!==e)continue;let l;try{l=this.evaluate(a.join)}catch(n){this.opts.log(`${a.project}: ${t} changed, but its webpack config could not be built from it (${firstLine(n)}) \u2014 it compiles as before`);continue}for(const n of l.configFiles)e.configFiles.add(n);l.signature.key!==e.key&&o.push({member:c,join:a.join,evaluated:l})}const s=`shared compilation ${e.key.slice(0,8)}`;if(o.length===0)return this.opts.log(`${s}: ${t} changed \u2014 nothing it compiles with did`),!0;const i=[...new Set(o.map(c=>c.join.project))].sort();for(const c of o)this.detach(c.member);const r=e.projects.size>0;this.opts.log(`${s}: ${t} changed what ${i.join(", ")} compile${i.length===1?"s":""} with \u2014 a new compiler reads it${r?"":"; this one closes"}`),r||(this.groups.delete(e.key),setImmediate(()=>this.closeGroup(e)));for(const c of o)this.admit(c.member,c.join,c.evaluated);return r}detach(e){const t=this.members.get(e);if(!t)return;this.members.delete(e);const{project:o,group:s}=t;s.told.delete(e),s.toldFiles.delete(e);const i=s.projects.get(o);if(i?.delete(e),i&&i.size>0)return;s.projects.delete(o),s.registry.delete(o),s.last.delete(o);const r=s.pausing.get(o);r&&(clearTimeout(r),s.pausing.delete(o))}tellBuilt(e,t,o){const s=o.attribution,i=e.told.get(t)!==s.hash;e.told.set(t,s.hash);const r=shortHash([...s.files].sort().join(`
3
- `)),c=e.toldFiles.get(t)!==r;e.toldFiles.set(t,r),this.tell(t,{type:"built",ok:s.errorCount===0,changed:i,hash:s.hash,text:(0,shared_compilation_1.describeBuild)(s,{webpackVersion:e.webpackVersion,durationMs:o.durationMs,changed:i}),errors:s.errorCount,warnings:s.warningCount,durationMs:o.durationMs,sourceMaps:e.sourceMaps,...c?{files:s.files}:{}})}closeGroup(e){e.retry.dispose();for(const i of e.pausing.values())clearTimeout(i);e.pausing.clear();const t=e.compiler,o=e.watching;e.watching=void 0;const s=h(()=>{try{t?.close?.(()=>{})}catch{}},"closeCompiler");o?o.close(s):s()}stop(e=5e3){this.stopped=!0;const t=[...this.groups.values()];return this.groups.clear(),this.members.clear(),new Promise(o=>{let s=t.length;if(s===0)return o();const i=setTimeout(o,e);i.unref?.();for(const r of t){r.retry.dispose();for(const n of r.pausing.values())clearTimeout(n);const c=h(()=>{--s===0&&(clearTimeout(i),o())},"done"),a=r.compiler,l=h(()=>{try{a.close(()=>c())}catch{c()}},"closeCompiler");r.watching?r.watching.close(l):l()}})}}exports.BuildHost=BuildHost;
1
+ "use strict";var $=Object.defineProperty;var v=(a,e)=>$(a,"name",{value:e,configurable:!0});var _=Object.defineProperty,u=v((a,e)=>_(a,"name",{value:e,configurable:!0}),"u");Object.defineProperty(exports,"__esModule",{value:!0}),exports.BuildHost=exports.DEFAULT_PAUSE_MS=void 0,exports.suspendedChanges=suspendedChanges,exports.withEnv=withEnv,exports.buildTargetString=buildTargetString;const tslib_1=require("tslib"),node_crypto_1=require("node:crypto"),path=tslib_1.__importStar(require("node:path")),checkout_cache_1=require("../checkout-cache"),config_files_1=require("../config-files"),compile_retry_1=require("../compile-retry"),dev_devtool_1=require("../dev-devtool"),create_webpack_dev_1=require("../create-webpack-dev"),perf_rules_plugin_1=require("../perf/perf-rules-plugin"),protocol_1=require("./protocol"),signature_1=require("./signature"),shared_compilation_1=require("./shared-compilation");exports.DEFAULT_PAUSE_MS=5e3;const WATCH_RUN_PATHS=32,reportKey=u(a=>JSON.stringify([a.files,a.count??null,a.skipped]),"reportKey"),EMPTY_REPORT=reportKey({files:[],count:0,skipped:0});function suspendedChanges(a){const e=new Set;for(const t of a._collectedChangedFiles??[])e.add(t);for(const t of a._collectedRemovedFiles??[])e.add(t);try{const t=(a.watcher??a.pausedWatcher)?.getInfo?.();for(const s of t?.changes??[])e.add(s);for(const s of t?.removals??[])e.add(s)}catch{}return e}v(suspendedChanges,"suspendedChanges"),u(suspendedChanges,"suspendedChanges");function withEnv(a,e){const t={...process.env};for(const s of Object.keys(process.env))delete process.env[s];for(const[s,o]of Object.entries(a))o!==void 0&&(process.env[s]=o);try{return e()}finally{for(const s of Object.keys(process.env))delete process.env[s];Object.assign(process.env,t)}}v(withEnv,"withEnv"),u(withEnv,"withEnv");function buildTargetString(a){return`${a.project}:${a.target}${a.configuration?`:${a.configuration}`:""}`}v(buildTargetString,"buildTargetString"),u(buildTargetString,"buildTargetString");const shortHash=u(a=>(0,node_crypto_1.createHash)("sha256").update(a).digest("hex").slice(0,16),"shortHash"),firstLine=u(a=>(a?.message??String(a)).split(`
2
+ `)[0],"firstLine");class BuildHost{static{v(this,"BuildHost")}static{u(this,"BuildHost")}constructor(e){this.opts=e,this.groups=new Map,this.members=new Map,this.stopped=!1,this.holds=new Map,this.served=new Set,this.pauseMs=e.pauseMs??exports.DEFAULT_PAUSE_MS,this.heldReportMs=e.heldReportMs??protocol_1.HELD_REPORT_MS,this.webpack=e.webpack??require("webpack")}tell(e,t){this.opts.send({type:"member",member:e,event:t})}hold(e,t){if(this.stopped||typeof e!="string"||!e)return;const s=this.holds.get(e);if(t){if(s?.held)return;const o=s??{held:!0,deliver:!1,files:new Set,unsure:!1,skipped:0,spared:new Set};o.held=!0,o.lastHash??=this.deliveredHash(e),this.holds.set(e,o),this.opts.log(`${e}: held \u2014 its bundle stays as built, its saves are collected (planning/updates)`),this.startTicker();for(const i of this.groupsOf(e))this.settle(i);return}if(!s?.held){s||this.opts.send({type:"update-done",project:e,delivered:!1});return}s.held=!1,this.owes(e,s)?(s.deliver=!0,this.opts.log(`${e}: released \u2014 compiling what was held, then live`)):(this.holds.delete(e),s.sent!==void 0&&s.sent!==EMPTY_REPORT&&this.opts.send({type:"held",project:e,files:[],count:0,skipped:0}),this.opts.send({type:"update-done",project:e,delivered:!1}),this.opts.log(`${e}: released \u2014 nothing changed since its last build, live again`));for(const o of this.groupsOf(e))this.settle(o)}update(e){if(this.stopped||typeof e!="string")return;const t=this.holds.get(e);if(!t?.held){this.opts.send({type:"update-done",project:e,delivered:!1}),this.opts.log(`${e}: update \u2014 not held, it builds on every save`);return}if(!t.deliver){if(!this.owes(e,t)){t.files.clear(),t.spared.clear(),t.unsure=!1,t.skipped=0,this.opts.send({type:"update-done",project:e,delivered:!1}),this.opts.log(`${e}: update \u2014 nothing changed since its last build`);return}t.deliver=!0,this.opts.log(`${e}: update \u2014 compiling what was held; it stays held`);for(const s of this.groupsOf(e))this.settle(s)}}groupsOf(e){return[...this.groups.values()].filter(t=>t.projects.has(e))}deliveredHash(e){for(const t of this.groupsOf(e)){const s=t.last.get(e);if(s)return s.attribution.hash}}owes(e,t){for(const s of this.groupsOf(e)){const o=s.last.get(e)?.attribution.hash;if(t.lastHash!==void 0&&t.lastHash!==o)return!0;const i=s.watching;if(this.busy(s)||i?.invalid)return!0;if(i?.suspended)for(const n of suspendedChanges(i)){const c=s.owners.get(n);if(c?c.includes(e):s.owners.size===0)return!0}}return!1}withholds(e,t){const s=this.holds.get(t);if(!s?.held||s.deliver)return!1;for(const o of e.projects.get(t)??[])if(!this.served.has(o))return!1;return!0}withheldNow(e){const t=new Set;for(const s of e.registry.projects())this.withholds(e,s)&&t.add(s);return t}owedDelivery(e,t){const s=this.holds.get(t);return s?s.deliver?!0:s.held&&!this.withholds(e,t):!1}everyHeld(e){if(!e.compiled||e.projects.size===0)return!1;for(const t of e.projects.keys())if(!this.holds.get(t)?.held)return!1;return!0}settle(e,t={}){if(this.stopped||this.groups.get(e.key)!==e)return;const s=e.watching;if(!s||s.closed)return;const o=this.everyHeld(e),i=[...e.projects.keys()].some(c=>this.owedDelivery(e,c)),n=`shared compilation ${e.key.slice(0,8)}`;if(s.suspended){let c=i||!!t.compile&&!o;if(!c&&!o){const r=suspendedChanges(s);if(!(s.watcher||s.running)||this.liveChanged(e,r))c=!0;else if(r.size===0){if(this.busy(e))return this.defer(e,t);s.suspended=!1,this.opts.log(`${n}: watching again`);return}}if(!c)return;if(this.busy(e))return this.defer(e,t);e.seenPending.clear(),s.resume(),o&&s.suspend(),this.opts.log(`${n}: compiling once${o?" \u2014 every service stays held":" \u2014 watching again"}`);return}if(i||t.compile&&!o){if(s.invalid)return;if(this.busy(e))return this.defer(e,t);s.invalidate();return}o&&(s.suspend(),e.seenPending.clear(),this.opts.log(`${n}: every service held \u2014 nothing compiles until an update or a release`))}defer(e,t){e.settleOwed=!0,t.compile&&(e.compileOwed=!0)}busy(e){return!!e.watching?.running||e.finishing}liveChanged(e,t){const s=[...e.projects.keys()].filter(o=>!this.holds.get(o)?.held);if(s.length===0)return!1;for(const o of t){const i=e.owners.get(o);if(!i||i.some(n=>s.includes(n)))return!0}return!1}collect(e,t){e.files.delete(t),e.files.add(t)}startTicker(){this.ticker||this.stopped||(this.ticker=setInterval(()=>this.tick(),this.heldReportMs),this.ticker.unref?.())}tick(){if(!this.stopped){for(const e of this.groups.values()){const t=e.watching;if(!t?.suspended)continue;const s=suspendedChanges(t),o=new Set;for(const i of s){if(e.seenPending.has(i))continue;e.seenPending.add(i);const n=e.owners.get(i);for(const c of n??(e.owners.size===0?[...e.projects.keys()]:[])){if(!e.projects.has(c))continue;const r=this.holds.get(c);r?.held&&(this.collect(r,i),r.spared.add(i),n||(r.unsure=!0),o.add(r))}}for(const i of o)i.skipped+=1;!this.everyHeld(e)&&this.liveChanged(e,s)&&this.settle(e)}for(const[e,t]of this.holds){if(!t.held)continue;const s=[...t.files].slice(-protocol_1.HELD_REPORT_FILES),o={type:"held",project:e,files:s,...t.unsure?{}:{count:t.files.size},skipped:t.skipped},i=reportKey(o);i!==t.sent&&(t.sent===void 0&&i===EMPTY_REPORT||(t.sent=i,this.opts.send(o)))}this.holds.size===0&&this.ticker&&(clearInterval(this.ticker),this.ticker=void 0)}}describe(){return[...this.groups.values()].map(e=>({group:e.key,projects:e.registry.projects()}))}evaluate(e){const t=e.options;if(t.webpackConfigPath)try{delete require.cache[require.resolve(path.resolve(t.appRoot,t.webpackConfigPath))]}catch{}const s={...e.env,NODE_ENV:"development",NX_BUILD_TARGET:buildTargetString(e),NX_WORKSPACE_ROOT:this.opts.root,LENSMCP_TYPECHECK:"off"},o=withEnv(s,()=>(0,create_webpack_dev_1.createDevWebpackConfig)(t)),i=(0,signature_1.transpileCompilerOptions)(t.tsConfig,this.opts.root),n=(0,signature_1.memberSignature)({join:e,devtool:o.devtool,config:o,compilerOptions:i});return{config:o,signature:n,configFiles:(0,config_files_1.configFilesOf)({...t,workspaceRoot:this.opts.root})}}join(e,t,s={}){if(this.stopped)return this.tell(e,{type:"refused",reason:"the build host is stopping"});this.leave(e,{quiet:!0}),s.served&&this.served.add(e);const o=(0,signature_1.refusalOf)(t,this.opts.root);if(o)return this.served.delete(e),this.opts.log(`${t.project}: compiles on its own \u2014 ${o}`),this.tell(e,{type:"refused",reason:o});let i;try{i=this.evaluate(t)}catch(n){this.served.delete(e);const c=`its webpack config could not be built here (${firstLine(n)})`;return this.opts.log(`${t.project}: compiles on its own \u2014 ${c}`),this.tell(e,{type:"refused",reason:c})}this.admit(e,t,i)}admit(e,t,s){let o=this.groups.get(s.signature.key);if(!o){for(const r of this.groups.values()){const h=(0,signature_1.describeDifference)(s.signature,r.signature);this.opts.log(`${t.project}: compiled apart from ${r.registry.projects().sort().join(", ")||"the other group"} \u2014 ${h??"its compile signature differs"}`);break}try{o=this.createGroup(s,t)}catch(r){const h=`the shared compiler could not be created (${firstLine(r)})`;return this.opts.log(`${t.project}: compiles on its own \u2014 ${h}`),this.tell(e,{type:"refused",reason:h})}this.groups.set(o.key,o)}this.members.set(e,{project:t.project,group:o,join:t});for(const r of s.configFiles)o.configFiles.add(r);const i=o.projects.get(t.project)??new Set;i.add(e);const n=!o.projects.has(t.project);o.projects.set(t.project,i);const c=o.pausing.get(t.project);if(c&&(clearTimeout(c),o.pausing.delete(t.project)),this.tell(e,{type:"accepted",group:o.key,projects:[...o.projects.keys()]}),n)o.registry.set(t.project,(0,shared_compilation_1.memberEntries)(t.project,t.options)),this.opts.log(`shared compilation ${o.key.slice(0,8)}: ${o.registry.projects().sort().join(", ")}`),this.kick(o);else{const r=o.last.get(t.project);r?this.tellBuilt(o,e,r):this.settle(o)}}leave(e,t={}){const s=this.members.get(e);if(!s)return;this.members.delete(e),this.served.delete(e);const{project:o,group:i}=s;i.told.delete(e),i.toldFiles.delete(e);const n=i.projects.get(o);if(n?.delete(e),n&&n.size>0)return;t.quiet||this.opts.log(`${o}: no member left \u2014 its entries pause in ${Math.round(this.pauseMs/1e3)} s`);const c=setTimeout(()=>this.pause(i,o),this.pauseMs);c.unref?.(),i.pausing.set(o,c)}pause(e,t){if(e.pausing.delete(t),!((e.projects.get(t)?.size??0)>0)){if(e.projects.delete(t),e.registry.delete(t),e.last.delete(t),e.projects.size===0){this.opts.log(`shared compilation ${e.key.slice(0,8)}: no service left \u2014 closed`),this.groups.delete(e.key),this.closeGroup(e);return}this.opts.log(`shared compilation ${e.key.slice(0,8)}: ${t} paused \u2014 ${e.registry.projects().sort().join(", ")}`),this.kick(e)}}kick(e){if(e.watching){if(e.watching.suspended||this.everyHeld(e))return this.settle(e,{compile:!0});e.watching.invalidate();return}e.watching=e.compiler.watch(e.watchOptions,(t,s)=>this.onBuild(e,t,s))}createGroup(e,t){const s=e.signature.key,o=new shared_compilation_1.EntryRegistry,i=t.options,n=e.config,c=n.devtool,r=path.join((0,checkout_cache_1.checkoutCacheDir)(this.opts.root,"lensmcp-build"),s,"out"),h=(0,create_webpack_dev_1.devCacheOptions)(i,c),l={key:s,signature:e.signature,registry:o,projects:new Map,pausing:new Map,last:new Map,told:new Map,toldFiles:new Map,compiler:void 0,watching:void 0,watchOptions:{},sourceMaps:!1,webpackVersion:"",retry:(0,compile_retry_1.createFailureRetry)(()=>this.compileAgain(l),this.opts.retryDelaysMs??compile_retry_1.RETRY_AFTER_FAILURE_MS),configFiles:new Set(e.configFiles),configChanged:new Set,owners:new Map,changedSinceBuild:new Set,withheldBy:new WeakMap,compiled:!1,finishing:!1,settleOwed:!1,compileOwed:!1,seenPending:new Set},m=n.plugins.filter(f=>!signature_1.PER_SERVICE_PLUGINS.has(f?.constructor?.name));m.push(new perf_rules_plugin_1.PerfRulesPlugin({project:t.project,workspaceRoot:this.opts.root,tsConfig:i.tsConfig,entries:u(()=>o.entryProjects(),"entries")}),new shared_compilation_1.SharedEntriesPlugin({registry:o,workspaceRoot:this.opts.root,outputPath:r,cache:{...h,name:`shared-${s}`,version:`${h.version}-${s}`}}),new config_files_1.ConfigFilesPlugin({files:u(()=>l.configFiles,"files"),changed:u(f=>{for(const p of f)l.configChanged.add(p)},"changed")}),{apply:u(f=>{f.hooks.watchRun.tap("LensmcpSharedBuild",p=>{const g=[...p.modifiedFiles??[],...p.removedFiles??[]].filter(w=>typeof w=="string");for(const w of g)l.changedSinceBuild.add(w);const j=g.slice(-WATCH_RUN_PATHS);for(const[w,k]of l.projects)if(!this.holds.get(w)?.held)for(const b of k)this.tell(b,{type:"watch-run",paths:j})}),f.hooks.watchClose.tap("LensmcpSharedBuild",()=>{for(const p of this.membersOf(l))this.tell(p,{type:"watch-closed"})}),f.hooks.thisCompilation.tap("LensmcpSharedBuild",p=>{p.hooks.processAssets.tap({name:"LensmcpSharedBuildHolds",stage:1/0},()=>{const g=this.withheldNow(l);l.withheldBy.set(p,g),g.size>0&&(0,shared_compilation_1.withholdAssets)(p,o,g)})}),f.hooks.done.tap("LensmcpSharedBuild",()=>{l.finishing=!0}),f.hooks.failed.tap("LensmcpSharedBuild",()=>{l.finishing=!1}),f.hooks.afterDone.tap("LensmcpSharedBuild",()=>{process.nextTick(()=>this.afterBuild(l))})},"apply")});const y={...n,plugins:m};delete y.watch,l.watchOptions=n.watchOptions??{};const d={...t.env,NODE_ENV:"development",NX_BUILD_TARGET:buildTargetString(t),NX_WORKSPACE_ROOT:this.opts.root,LENSMCP_TYPECHECK:"off"};return l.compiler=withEnv(d,()=>this.webpack(y)),l.sourceMaps=(0,dev_devtool_1.bundleCarriesSourceMaps)(l.compiler.options.devtool),l.webpackVersion=String(l.compiler.webpack?.version??"5"),l}membersOf(e){const t=[];for(const s of e.projects.values())t.push(...s);return t}compileAgain(e){if(this.stopped||this.groups.get(e.key)!==e||!e.watching)return;const t=`shared compilation ${e.key.slice(0,8)}`;if(this.everyHeld(e)&&![...e.projects.keys()].some(s=>this.owedDelivery(e,s))){this.opts.log(`${t}: every service held \u2014 not compiling again after the failure until an update`),this.settle(e);return}this.opts.log(`${t}: compiling again after the failure`),e.watching.suspended?this.settle(e,{compile:!0}):e.watching.invalidate()}afterBuild(e){e.finishing=!1;const t=e.compileOwed;e.settleOwed=!1,e.compileOwed=!1,this.settle(e,{compile:t})}onBuild(e,t,s){if(this.stopped||e.configChanged.size>0&&!this.reconfigure(e))return;if(t){const d=t?.message??String(t),{delayMs:f,retry:p}=e.retry.failed();this.opts.log(`shared compilation ${e.key.slice(0,8)} failed: ${d} \u2014 compiling again in ${Math.round(f/1e3)} s (retry ${p})`);for(const g of this.membersOf(e))this.tell(g,{type:"failed",message:d});return}const o=e.retry.succeeded();o>0&&this.opts.log(`shared compilation ${e.key.slice(0,8)}: compiled again after ${o} failure${o===1?"":"s"} \u2014 watching again`);const i=s,n=Math.max(0,(i.endTime??0)-(i.startTime??0)),c=(0,shared_compilation_1.attributeCompilation)(i.compilation,e.registry),r=e.withheldBy.get(i.compilation)??new Set,h=e.changedSinceBuild;e.changedSinceBuild=new Set,e.compiled=!0,e.owners=this.ownersOf(e,c);const l=[],m=[];for(const[d,f]of c){let p=this.holds.get(d);if(r.has(d)){p||this.holds.set(d,p={held:!1,deliver:!0,files:new Set,unsure:!1,skipped:0,spared:new Set}),m.push(d),this.keptBack(e,p,f,h);continue}e.last.get(d)?.attribution.hash!==f.hash&&l.push(d);const g={attribution:f,durationMs:n};e.last.set(d,g);const j=e.projects.get(d)??[],w=p?this.carried(p,f,h):[];if(w.length>0)for(const k of j)this.tell(k,{type:"watch-run",paths:w});for(const k of j)this.tellBuilt(e,k,g);p&&this.delivered(e,d,p,f)}const y=[...c.values()].filter(d=>d.errorCount>0).map(d=>d.project);this.opts.log(`built ${[...c.keys()].sort().join(", ")||"nothing"} in ${n} ms \u2014 ${l.length?`changed: ${l.sort().join(", ")}`:"no bundle changed"}${y.length?`; errors in: ${y.sort().join(", ")}`:""}${m.length?`; held, not written: ${m.sort().join(", ")}`:""}`)}ownersOf(e,t){const s=new Map;for(const[i,n]of t)for(const c of n.files){const r=s.get(c);r?r.push(i):s.set(c,[i])}const o=[...t.keys()];for(const i of e.configFiles)s.set(i,o);return s}keptBack(e,t,s,o){const i=[];if(o.size>0){const c=new Set(s.files);for(const r of o)(c.has(r)||e.configFiles.has(r))&&i.push(r)}for(const c of i)this.collect(t,c);const n=i.length>0&&i.every(c=>t.spared.has(c));for(const c of i)t.spared.delete(c);s.hash!==t.lastHash&&(n||(t.skipped+=1),t.lastHash=s.hash)}carried(e,t,s){const o=new Set(e.files);if(s.size>0){const i=new Set(t.files);for(const n of s)i.has(n)&&o.add(n)}return[...o].slice(-WATCH_RUN_PATHS)}delivered(e,t,s,o){const i=s.deliver;if(s.deliver=!1,s.lastHash=o.hash,i&&this.opts.send({type:"update-done",project:t,delivered:!0}),!s.held){this.holds.delete(t),this.opts.log(`${t}: released \u2014 delivered, live again`);return}const n=e.watching,c=n?.suspended?suspendedChanges(n):new Set;for(const r of[...s.files])c.has(r)||s.files.delete(r);for(const r of[...s.spared])c.has(r)||s.spared.delete(r);s.unsure=!1,s.skipped=0,i&&this.opts.log(`${t}: update delivered \u2014 held again`)}reconfigure(e){const t=[...e.configChanged].map(r=>path.relative(this.opts.root,r)).sort().join(", ");e.configChanged.clear();const s=[];for(const[r,h]of this.members){if(h.group!==e)continue;let l;try{l=this.evaluate(h.join)}catch(m){this.opts.log(`${h.project}: ${t} changed, but its webpack config could not be built from it (${firstLine(m)}) \u2014 it compiles as before`);continue}for(const m of l.configFiles)e.configFiles.add(m);l.signature.key!==e.key&&s.push({member:r,join:h.join,evaluated:l})}const o=`shared compilation ${e.key.slice(0,8)}`;if(s.length===0)return this.opts.log(`${o}: ${t} changed \u2014 nothing it compiles with did`),!0;const i=[...new Set(s.map(r=>r.join.project))].sort(),n=new Map;for(const r of s){const h=this.holds.get(r.join.project)?.held?e.last.get(r.join.project):void 0;h&&n.set(r.join.project,h)}for(const r of s)this.detach(r.member);const c=e.projects.size>0;this.opts.log(`${o}: ${t} changed what ${i.join(", ")} compile${i.length===1?"s":""} with \u2014 a new compiler reads it${c?"":"; this one closes"}`),c||(this.groups.delete(e.key),setImmediate(()=>this.closeGroup(e)));for(const r of s)this.admit(r.member,r.join,r.evaluated);for(const[r,h]of n)for(const l of this.groupsOf(r))l!==e&&!l.last.has(r)&&l.last.set(r,h);return c}detach(e){const t=this.members.get(e);if(!t)return;this.members.delete(e);const{project:s,group:o}=t;o.told.delete(e),o.toldFiles.delete(e);const i=o.projects.get(s);if(i?.delete(e),i&&i.size>0)return;o.projects.delete(s),o.registry.delete(s),o.last.delete(s);const n=o.pausing.get(s);n&&(clearTimeout(n),o.pausing.delete(s))}tellBuilt(e,t,s){const o=s.attribution,i=e.told.get(t)!==o.hash;e.told.set(t,o.hash);const n=shortHash([...o.files].sort().join(`
3
+ `)),c=e.toldFiles.get(t)!==n;e.toldFiles.set(t,n),this.served.add(t),this.tell(t,{type:"built",ok:o.errorCount===0,changed:i,hash:o.hash,text:(0,shared_compilation_1.describeBuild)(o,{webpackVersion:e.webpackVersion,durationMs:s.durationMs,changed:i}),errors:o.errorCount,warnings:o.warningCount,durationMs:s.durationMs,sourceMaps:e.sourceMaps,...c?{files:o.files}:{}})}closeGroup(e){e.retry.dispose();for(const i of e.pausing.values())clearTimeout(i);e.pausing.clear();const t=e.compiler,s=e.watching;e.watching=void 0;const o=u(()=>{try{t?.close?.(()=>{})}catch{}},"closeCompiler");s?s.close(o):o()}stop(e=5e3){this.stopped=!0,this.ticker&&(clearInterval(this.ticker),this.ticker=void 0);const t=[...this.groups.values()];return this.groups.clear(),this.members.clear(),new Promise(s=>{let o=t.length;if(o===0)return s();const i=setTimeout(s,e);i.unref?.();for(const n of t){n.retry.dispose();for(const l of n.pausing.values())clearTimeout(l);const c=u(()=>{--o===0&&(clearTimeout(i),s())},"done"),r=n.compiler,h=u(()=>{try{r.close(()=>c())}catch{c()}},"closeCompiler");n.watching?n.watching.close(h):h()}})}}exports.BuildHost=BuildHost;
@@ -47,15 +47,60 @@ export interface RunnerJoinMessage {
47
47
  type: 'join';
48
48
  join: MemberJoinRequest;
49
49
  }
50
- /** gateway → host. `member` names one runner tree: `<project>#g<generation>`. */
50
+ /**
51
+ * gateway → host: hold a project's builds, or let them go (planning/updates/00-plan.md U1b). While held, the project's
52
+ * bundle on disk is not rewritten and its members are told no build — their runners keep serving what they run, and a
53
+ * pod that restarts loads the same bundle — while the saves are collected; the other projects of its compilation keep
54
+ * building. When every project of a compilation is held, nothing compiles. `held: false` (a release) is an
55
+ * {@link HostUpdate} and then live; a release with nothing changed for it compiles nothing and tells nobody anything.
56
+ * Holds are the gateway's: a host that restarts has none, so the gateway sends them again with the joins.
57
+ */
58
+ export interface HostHold {
59
+ type: 'hold';
60
+ project: string;
61
+ held: boolean;
62
+ }
63
+ /**
64
+ * gateway → host: compile what changed for a held project and deliver it — its members hear it as a `built` event,
65
+ * its bundle is written — and keep holding it. Other held projects of the same compilation stay held. A project with
66
+ * nothing changed since its last delivered build compiles nothing: its next {@link HeldReport} has no files.
67
+ */
68
+ export interface HostUpdate {
69
+ type: 'update';
70
+ project: string;
71
+ }
72
+ /**
73
+ * gateway → host. `member` names one runner tree: `<project>#g<generation>`. `served` on a join: the member already runs
74
+ * a build the gateway relayed to it — set when it joins again a host that restarted — so a held project's member is not
75
+ * handed the current sources as its "first" build (planning/updates/00-plan.md U1b); without it, it is.
76
+ */
51
77
  export type HostInbound = {
52
78
  type: 'join';
53
79
  member: string;
54
80
  join: MemberJoinRequest;
81
+ served?: boolean;
55
82
  } | {
56
83
  type: 'leave';
57
84
  member: string;
58
- };
85
+ } | HostHold | HostUpdate;
86
+ /** The most files a {@link HeldReport} names — the newest. */
87
+ export declare const HELD_REPORT_FILES = 50;
88
+ /** How often the host reports on held projects, at most — a report goes only when it changed. */
89
+ export declare const HELD_REPORT_MS = 1000;
90
+ /**
91
+ * host → gateway, at most once per {@link HELD_REPORT_MS} per held project, when it changed: what its hold is keeping
92
+ * back. A delivered update starts it again (an empty report says so).
93
+ */
94
+ export interface HeldReport {
95
+ type: 'held';
96
+ project: string;
97
+ /** Absolute paths of the files changed since its hold (or its last delivered update) that its bundle is built from — the newest {@link HELD_REPORT_FILES}, oldest first. */
98
+ files: string[];
99
+ /** How many such files in all. Absent when not knowable: some were listed before any compilation could say whose they are. */
100
+ count?: number;
101
+ /** Builds it was not given: compiles of the others that rebuilt it, or rounds of saves nothing compiled while every project was held. */
102
+ skipped: number;
103
+ }
59
104
  /** The host joined the member: its entries are (or are being) compiled in `group`. */
60
105
  export interface AcceptedEvent {
61
106
  type: 'accepted';
@@ -102,6 +147,17 @@ export interface WatchClosedEvent {
102
147
  type: 'watch-closed';
103
148
  }
104
149
  export type MemberEvent = AcceptedEvent | RefusedEvent | WatchRunEvent | BuiltEvent | FailedEvent | WatchClosedEvent;
150
+ /**
151
+ * host → gateway: an `update` or a release (`hold` with `held: false`) of `project` is done. `delivered: false` — nothing
152
+ * was owed, nothing compiled, nobody was told anything; `delivered: true` — its members were just told the build (their
153
+ * `built` member events came first). The gateway answers the update it was asked for from this (planning/updates U2):
154
+ * without it, «nothing to build» and «still building» look the same.
155
+ */
156
+ export interface HostUpdateDone {
157
+ type: 'update-done';
158
+ project: string;
159
+ delivered: boolean;
160
+ }
105
161
  /** host → gateway. */
106
162
  export type HostOutbound = {
107
163
  type: 'member';
@@ -110,7 +166,7 @@ export type HostOutbound = {
110
166
  } | {
111
167
  type: 'ready';
112
168
  pid: number;
113
- };
169
+ } | HeldReport | HostUpdateDone;
114
170
  /** gateway → runner. */
115
171
  export interface RunnerInbound {
116
172
  channel: typeof SHARED_BUILD_CHANNEL;
@@ -1 +1 @@
1
- "use strict";var _=Object.defineProperty;var r=(t,e)=>_(t,"name",{value:e,configurable:!0});var o=Object.defineProperty,s=r((t,e)=>o(t,"name",{value:e,configurable:!0}),"s");Object.defineProperty(exports,"__esModule",{value:!0}),exports.SHARED_COMPILER_DEFAULT=exports.BUILD_HOST_ROOT_FLAG=exports.BUILD_HOST_ROLE=exports.SHARED_BUILD_CHANNEL=exports.SHARED_BUILD_ENV=exports.SHARED_COMPILER_ENV=void 0,exports.sharedCompilerEnabled=sharedCompilerEnabled,exports.isRunnerJoinMessage=isRunnerJoinMessage,exports.isRunnerInbound=isRunnerInbound,exports.buildHostArgs=buildHostArgs,exports.isBuildHostCommandOf=isBuildHostCommandOf,exports.SHARED_COMPILER_ENV="LENSMCP_SHARED_COMPILER",exports.SHARED_BUILD_ENV="LENSMCP_SHARED_BUILD",exports.SHARED_BUILD_CHANNEL="lensmcp-shared-build",exports.BUILD_HOST_ROLE="build",exports.BUILD_HOST_ROOT_FLAG="--workspace-root=";const ON=/^(1|on|true|yes)$/i,OFF=/^(0|off|false|no)$/i;exports.SHARED_COMPILER_DEFAULT=!0;function sharedCompilerEnabled(t=process.env,e){const n=(t[exports.SHARED_COMPILER_ENV]??"").trim();return ON.test(n)?!0:OFF.test(n)?!1:e??exports.SHARED_COMPILER_DEFAULT}r(sharedCompilerEnabled,"sharedCompilerEnabled"),s(sharedCompilerEnabled,"sharedCompilerEnabled");function isRunnerJoinMessage(t){const e=t;return!!e&&e.channel===exports.SHARED_BUILD_CHANNEL&&e.type==="join"&&typeof e.join?.project=="string"}r(isRunnerJoinMessage,"isRunnerJoinMessage"),s(isRunnerJoinMessage,"isRunnerJoinMessage");function isRunnerInbound(t){const e=t;return!!e&&e.channel===exports.SHARED_BUILD_CHANNEL&&typeof e.event?.type=="string"}r(isRunnerInbound,"isRunnerInbound"),s(isRunnerInbound,"isRunnerInbound");function buildHostArgs(t){return["host",`${exports.BUILD_HOST_ROOT_FLAG}${t.replace(/\/+$/,"")}`]}r(buildHostArgs,"buildHostArgs"),s(buildHostArgs,"buildHostArgs");function isBuildHostCommandOf(t,e){return/\bbuild-host\.(js|ts)\b/.test(t)&&t.trimEnd().endsWith(` ${exports.BUILD_HOST_ROOT_FLAG}${e.replace(/\/+$/,"")}`)}r(isBuildHostCommandOf,"isBuildHostCommandOf"),s(isBuildHostCommandOf,"isBuildHostCommandOf");
1
+ "use strict";var _=Object.defineProperty;var r=(t,e)=>_(t,"name",{value:e,configurable:!0});var o=Object.defineProperty,s=r((t,e)=>o(t,"name",{value:e,configurable:!0}),"s");Object.defineProperty(exports,"__esModule",{value:!0}),exports.HELD_REPORT_MS=exports.HELD_REPORT_FILES=exports.SHARED_COMPILER_DEFAULT=exports.BUILD_HOST_ROOT_FLAG=exports.BUILD_HOST_ROLE=exports.SHARED_BUILD_CHANNEL=exports.SHARED_BUILD_ENV=exports.SHARED_COMPILER_ENV=void 0,exports.sharedCompilerEnabled=sharedCompilerEnabled,exports.isRunnerJoinMessage=isRunnerJoinMessage,exports.isRunnerInbound=isRunnerInbound,exports.buildHostArgs=buildHostArgs,exports.isBuildHostCommandOf=isBuildHostCommandOf,exports.SHARED_COMPILER_ENV="LENSMCP_SHARED_COMPILER",exports.SHARED_BUILD_ENV="LENSMCP_SHARED_BUILD",exports.SHARED_BUILD_CHANNEL="lensmcp-shared-build",exports.BUILD_HOST_ROLE="build",exports.BUILD_HOST_ROOT_FLAG="--workspace-root=";const ON=/^(1|on|true|yes)$/i,OFF=/^(0|off|false|no)$/i;exports.SHARED_COMPILER_DEFAULT=!0;function sharedCompilerEnabled(t=process.env,e){const n=(t[exports.SHARED_COMPILER_ENV]??"").trim();return ON.test(n)?!0:OFF.test(n)?!1:e??exports.SHARED_COMPILER_DEFAULT}r(sharedCompilerEnabled,"sharedCompilerEnabled"),s(sharedCompilerEnabled,"sharedCompilerEnabled"),exports.HELD_REPORT_FILES=50,exports.HELD_REPORT_MS=1e3;function isRunnerJoinMessage(t){const e=t;return!!e&&e.channel===exports.SHARED_BUILD_CHANNEL&&e.type==="join"&&typeof e.join?.project=="string"}r(isRunnerJoinMessage,"isRunnerJoinMessage"),s(isRunnerJoinMessage,"isRunnerJoinMessage");function isRunnerInbound(t){const e=t;return!!e&&e.channel===exports.SHARED_BUILD_CHANNEL&&typeof e.event?.type=="string"}r(isRunnerInbound,"isRunnerInbound"),s(isRunnerInbound,"isRunnerInbound");function buildHostArgs(t){return["host",`${exports.BUILD_HOST_ROOT_FLAG}${t.replace(/\/+$/,"")}`]}r(buildHostArgs,"buildHostArgs"),s(buildHostArgs,"buildHostArgs");function isBuildHostCommandOf(t,e){return/\bbuild-host\.(js|ts)\b/.test(t)&&t.trimEnd().endsWith(` ${exports.BUILD_HOST_ROOT_FLAG}${e.replace(/\/+$/,"")}`)}r(isBuildHostCommandOf,"isBuildHostCommandOf"),s(isBuildHostCommandOf,"isBuildHostCommandOf");
@@ -73,6 +73,27 @@ export interface EntryAttribution {
73
73
  size: number;
74
74
  }>;
75
75
  }
76
+ /** The parts of a chunk this reads. */
77
+ interface ChunkLike {
78
+ id?: unknown;
79
+ hash?: string;
80
+ files?: Iterable<string>;
81
+ auxiliaryFiles?: Iterable<string>;
82
+ getAllAsyncChunks?: () => Iterable<unknown>;
83
+ }
84
+ /**
85
+ * A project's chunks in a compilation: its entries' and every async chunk they load. Undefined when none of its entries
86
+ * is in it (it joined after this compilation started — the next one has it).
87
+ */
88
+ export declare function projectChunks(compilation: any, registry: EntryRegistry, project: string): Set<ChunkLike> | undefined;
89
+ /**
90
+ * Keep held projects' bundles off the disk (planning/updates/00-plan.md U1b): every file of their chunks leaves the
91
+ * compilation's assets before webpack emits, so the bundle a held service's pods restart from stays the one they were
92
+ * last told about. A chunk a project that is NOT withheld also loads is written for it all the same — an async chunk
93
+ * two services share lands in one directory, and the delivered one must find the chunk its bundle asks for. Returns the
94
+ * files kept back.
95
+ */
96
+ export declare function withholdAssets(compilation: any, registry: EntryRegistry, withheld: ReadonlySet<string>): string[];
76
97
  /**
77
98
  * Split a finished compilation by service: each project's chunks (its entries' and every async chunk they
78
99
  * load), the modules in them, the errors and warnings whose module is among them, and a hash over the chunks.
@@ -1,3 +1,3 @@
1
- "use strict";var w=Object.defineProperty;var l=(t,e)=>w(t,"name",{value:e,configurable:!0});var $=Object.defineProperty,c=l((t,e)=>$(t,"name",{value:e,configurable:!0}),"c");Object.defineProperty(exports,"__esModule",{value:!0}),exports.SharedEntriesPlugin=exports.EntryRegistry=void 0,exports.memberEntries=memberEntries,exports.attributeCompilation=attributeCompilation,exports.describeBuild=describeBuild;const tslib_1=require("tslib"),node_crypto_1=require("node:crypto"),path=tslib_1.__importStar(require("node:path"));function memberEntries(t,e){const r=[{name:t,project:t,import:e.main,outputFile:path.join(e.outputDir,"main.js")}];for(const o of e.additionalEntryPoints??[])r.push({name:`${t}~${o.entryName}`,project:t,import:o.entryPath,outputFile:path.join(e.outputDir,`${o.entryName}.js`)});return r}l(memberEntries,"memberEntries"),c(memberEntries,"memberEntries");class EntryRegistry{static{l(this,"EntryRegistry")}static{c(this,"EntryRegistry")}constructor(){this.byProject=new Map}set(e,r){this.byProject.set(e,r)}delete(e){return this.byProject.delete(e)}has(e){return this.byProject.has(e)}projects(){return[...this.byProject.keys()]}entriesOf(e){return this.byProject.get(e)??[]}entryProjects(){const e={};for(const[r,o]of this.byProject)for(const n of o)e[n.name]=r;return e}entry(e){for(const r of this.byProject.values()){const o=r.find(n=>n.name===e);if(o)return o}}webpackEntries(e){const r={};for(const o of this.byProject.values())for(const n of o)r[n.name]={import:[n.import],filename:path.relative(e,n.outputFile)};return r}}exports.EntryRegistry=EntryRegistry;class SharedEntriesPlugin{static{l(this,"SharedEntriesPlugin")}static{c(this,"SharedEntriesPlugin")}constructor(e){this.options=e}apply(e){const{registry:r,workspaceRoot:o,outputPath:n,cache:s}=this.options;e.options.context=o,e.context=o,e.options.output={...e.options.output,path:n,clean:!1,chunkFilename:c(m=>{const i=m.chunk?.runtime,d=typeof i=="string"?i:i?[...i].sort()[0]:void 0,u=d?r.entry(d):void 0;return`${u?path.relative(n,path.dirname(u.outputFile)):"."}/[id].js`},"chunkFilename")},e.options.cache={...s,buildDependencies:{...s.buildDependencies}},e.options.entry=()=>Promise.resolve(r.webpackEntries(n))}}exports.SharedEntriesPlugin=SharedEntriesPlugin;const resourceOf=c(t=>{if(typeof t.resource!="string"||!t.resource)return;const e=t.resource.search(/[?#]/);return e===-1?t.resource:t.resource.slice(0,e)},"resourceOf");function formatLoc(t){const e=t?.start;if(!e||typeof e.line!="number")return"";const r=`${e.line}:${e.column??0}`,o=t?.end;return!o||typeof o.line!="number"?r:o.line===e.line?`${r}-${o.column??0}`:`${r}-${o.line}:${o.column??0}`}l(formatLoc,"formatLoc"),c(formatLoc,"formatLoc");function formatProblem(t,e,r){const o=e.module;let n="";try{n=o?.readableIdentifier?o.readableIdentifier(r.requestShortener):""}catch{}const s=formatLoc(e.loc);return`${n?`${t} in ${n}${s?` ${s}`:""}`:t}
2
- ${String(e.message??e).trim()}`}l(formatProblem,"formatProblem"),c(formatProblem,"formatProblem");const MAX_PROBLEMS=30,MAX_PROBLEM_CHARS=4e3;function attributeCompilation(t,e){const r=new Map,o=new Map,n=t.compiler?.context??t.options?.context??process.cwd();for(const i of e.projects()){const d=new Set;let u=!1;for(const a of e.entriesOf(i)){const p=t.entrypoints?.get(a.name);if(p){u=!0;for(const f of p.chunks??[]){d.add(f);for(const y of f.getAllAsyncChunks?.()??[])d.add(y)}}}if(!u)continue;const h=new Set,g=[],b=[];for(const a of d){g.push(`${String(a.id)}:${a.hash??""}`);for(const p of t.chunkGraph.getChunkModulesIterable(a)){let f=o.get(p);f||o.set(p,f=new Set),f.add(i);const y=resourceOf(p);y&&h.add(y)}for(const p of a.files??[]){const f=t.getAsset?.(p),y=path.resolve(t.outputOptions?.path??n,p);b.push({file:path.relative(n,y),size:f?.info?.size??f?.source?.size?.()??0})}}r.set(i,{project:i,hash:(0,node_crypto_1.createHash)("sha256").update(g.sort().join("|")).digest("hex").slice(0,16),errors:[],warnings:[],errorCount:0,warningCount:0,files:[...h],assets:b})}const s=e.entryProjects(),m=c((i,d)=>{for(const u of d){let h=u.module?o.get(u.module):void 0;!h&&u.loc?.name&&s[u.loc.name]&&(h=[s[u.loc.name]]),h||(h=r.keys());const g=formatProblem(i==="errors"?"ERROR":"WARNING",u,t);for(const b of h){const a=r.get(b);a&&(i==="errors"?a.errorCount+=1:a.warningCount+=1,a[i].length<MAX_PROBLEMS&&a[i].push(g.length>MAX_PROBLEM_CHARS?`${g.slice(0,MAX_PROBLEM_CHARS)}\u2026`:g))}}},"assign");return m("errors",t.errors??[]),m("warnings",t.warnings??[]),r}l(attributeCompilation,"attributeCompilation"),c(attributeCompilation,"attributeCompilation");function describeBuild(t,e){const r=[];if(e.changed)for(const s of t.assets)r.push(`asset ${s.file} ${formatSize(s.size)} [emitted]`);for(const s of t.errors)r.push("",s);for(const s of t.warnings)r.push("",s);(t.errors.length||t.warnings.length)&&r.push("");const o=c((s,m)=>`${s} ${m}${s===1?"":"s"}`,"plural"),n=t.errorCount?`compiled with ${o(t.errorCount,"error")}${t.warningCount?` and ${o(t.warningCount,"warning")}`:""}`:t.warningCount?`compiled with ${o(t.warningCount,"warning")}`:"compiled successfully";return r.push(`webpack ${e.webpackVersion} ${n} in ${e.durationMs} ms (shared compilation${e.changed?"":" \u2014 this service's bundle is unchanged"})`),r.join(`
3
- `)}l(describeBuild,"describeBuild"),c(describeBuild,"describeBuild");function formatSize(t){return t>=1024*1024?`${(t/(1024*1024)).toFixed(2)} MiB`:t>=1024?`${(t/1024).toFixed(1)} KiB`:`${t} bytes`}l(formatSize,"formatSize"),c(formatSize,"formatSize");
1
+ "use strict";var $=Object.defineProperty;var f=(t,e)=>$(t,"name",{value:e,configurable:!0});var m=Object.defineProperty,u=f((t,e)=>m(t,"name",{value:e,configurable:!0}),"u");Object.defineProperty(exports,"__esModule",{value:!0}),exports.SharedEntriesPlugin=exports.EntryRegistry=void 0,exports.memberEntries=memberEntries,exports.projectChunks=projectChunks,exports.withholdAssets=withholdAssets,exports.attributeCompilation=attributeCompilation,exports.describeBuild=describeBuild;const tslib_1=require("tslib"),node_crypto_1=require("node:crypto"),path=tslib_1.__importStar(require("node:path"));function memberEntries(t,e){const r=[{name:t,project:t,import:e.main,outputFile:path.join(e.outputDir,"main.js")}];for(const o of e.additionalEntryPoints??[])r.push({name:`${t}~${o.entryName}`,project:t,import:o.entryPath,outputFile:path.join(e.outputDir,`${o.entryName}.js`)});return r}f(memberEntries,"memberEntries"),u(memberEntries,"memberEntries");class EntryRegistry{static{f(this,"EntryRegistry")}static{u(this,"EntryRegistry")}constructor(){this.byProject=new Map}set(e,r){this.byProject.set(e,r)}delete(e){return this.byProject.delete(e)}has(e){return this.byProject.has(e)}projects(){return[...this.byProject.keys()]}entriesOf(e){return this.byProject.get(e)??[]}entryProjects(){const e={};for(const[r,o]of this.byProject)for(const n of o)e[n.name]=r;return e}entry(e){for(const r of this.byProject.values()){const o=r.find(n=>n.name===e);if(o)return o}}webpackEntries(e){const r={};for(const o of this.byProject.values())for(const n of o)r[n.name]={import:[n.import],filename:path.relative(e,n.outputFile)};return r}}exports.EntryRegistry=EntryRegistry;class SharedEntriesPlugin{static{f(this,"SharedEntriesPlugin")}static{u(this,"SharedEntriesPlugin")}constructor(e){this.options=e}apply(e){const{registry:r,workspaceRoot:o,outputPath:n,cache:s}=this.options;e.options.context=o,e.context=o,e.options.output={...e.options.output,path:n,clean:!1,chunkFilename:u(c=>{const i=c.chunk?.runtime,p=typeof i=="string"?i:i?[...i].sort()[0]:void 0,a=p?r.entry(p):void 0;return`${a?path.relative(n,path.dirname(a.outputFile)):"."}/[id].js`},"chunkFilename")},e.options.cache={...s,buildDependencies:{...s.buildDependencies}},e.options.entry=()=>Promise.resolve(r.webpackEntries(n))}}exports.SharedEntriesPlugin=SharedEntriesPlugin;const resourceOf=u(t=>{if(typeof t.resource!="string"||!t.resource)return;const e=t.resource.search(/[?#]/);return e===-1?t.resource:t.resource.slice(0,e)},"resourceOf");function formatLoc(t){const e=t?.start;if(!e||typeof e.line!="number")return"";const r=`${e.line}:${e.column??0}`,o=t?.end;return!o||typeof o.line!="number"?r:o.line===e.line?`${r}-${o.column??0}`:`${r}-${o.line}:${o.column??0}`}f(formatLoc,"formatLoc"),u(formatLoc,"formatLoc");function formatProblem(t,e,r){const o=e.module;let n="";try{n=o?.readableIdentifier?o.readableIdentifier(r.requestShortener):""}catch{}const s=formatLoc(e.loc);return`${n?`${t} in ${n}${s?` ${s}`:""}`:t}
2
+ ${String(e.message??e).trim()}`}f(formatProblem,"formatProblem"),u(formatProblem,"formatProblem");const MAX_PROBLEMS=30,MAX_PROBLEM_CHARS=4e3;function projectChunks(t,e,r){const o=new Set;let n=!1;for(const s of e.entriesOf(r)){const c=t.entrypoints?.get(s.name);if(c){n=!0;for(const i of c.chunks??[]){o.add(i);for(const p of i.getAllAsyncChunks?.()??[])o.add(p)}}}return n?o:void 0}f(projectChunks,"projectChunks"),u(projectChunks,"projectChunks");function withholdAssets(t,e,r){const o=new Set,n=new Set;for(const c of e.projects())for(const i of projectChunks(t,e,c)??[])(r.has(c)?n:o).add(i);const s=new Set;for(const c of n)if(!o.has(c)){for(const i of c.files??[])s.add(i);for(const i of c.auxiliaryFiles??[])s.add(i)}for(const c of s)t.deleteAsset(c);return[...s]}f(withholdAssets,"withholdAssets"),u(withholdAssets,"withholdAssets");function attributeCompilation(t,e){const r=new Map,o=new Map,n=t.compiler?.context??t.options?.context??process.cwd();for(const i of e.projects()){const p=projectChunks(t,e,i);if(!p)continue;const a=new Set,d=[],h=[];for(const g of p){d.push(`${String(g.id)}:${g.hash??""}`);for(const l of t.chunkGraph.getChunkModulesIterable(g)){let y=o.get(l);y||o.set(l,y=new Set),y.add(i);const b=resourceOf(l);b&&a.add(b)}for(const l of g.files??[]){const y=t.getAsset?.(l),b=path.resolve(t.outputOptions?.path??n,l);h.push({file:path.relative(n,b),size:y?.info?.size??y?.source?.size?.()??0})}}r.set(i,{project:i,hash:(0,node_crypto_1.createHash)("sha256").update(d.sort().join("|")).digest("hex").slice(0,16),errors:[],warnings:[],errorCount:0,warningCount:0,files:[...a],assets:h})}const s=e.entryProjects(),c=u((i,p)=>{for(const a of p){let d=a.module?o.get(a.module):void 0;!d&&a.loc?.name&&s[a.loc.name]&&(d=[s[a.loc.name]]),d||(d=r.keys());const h=formatProblem(i==="errors"?"ERROR":"WARNING",a,t);for(const g of d){const l=r.get(g);l&&(i==="errors"?l.errorCount+=1:l.warningCount+=1,l[i].length<MAX_PROBLEMS&&l[i].push(h.length>MAX_PROBLEM_CHARS?`${h.slice(0,MAX_PROBLEM_CHARS)}\u2026`:h))}}},"assign");return c("errors",t.errors??[]),c("warnings",t.warnings??[]),r}f(attributeCompilation,"attributeCompilation"),u(attributeCompilation,"attributeCompilation");function describeBuild(t,e){const r=[];if(e.changed)for(const s of t.assets)r.push(`asset ${s.file} ${formatSize(s.size)} [emitted]`);for(const s of t.errors)r.push("",s);for(const s of t.warnings)r.push("",s);(t.errors.length||t.warnings.length)&&r.push("");const o=u((s,c)=>`${s} ${c}${s===1?"":"s"}`,"plural"),n=t.errorCount?`compiled with ${o(t.errorCount,"error")}${t.warningCount?` and ${o(t.warningCount,"warning")}`:""}`:t.warningCount?`compiled with ${o(t.warningCount,"warning")}`:"compiled successfully";return r.push(`webpack ${e.webpackVersion} ${n} in ${e.durationMs} ms (shared compilation${e.changed?"":" \u2014 this service's bundle is unchanged"})`),r.join(`
3
+ `)}f(describeBuild,"describeBuild"),u(describeBuild,"describeBuild");function formatSize(t){return t>=1024*1024?`${(t/(1024*1024)).toFixed(2)} MiB`:t>=1024?`${(t/1024).toFixed(1)} KiB`:`${t} bytes`}f(formatSize,"formatSize"),u(formatSize,"formatSize");
@@ -0,0 +1,391 @@
1
+ /** Moves when what a record, its stamps or a trust record hold changes: one kept by another version is never read as this one's. */
2
+ export declare const RECORD_SCHEMA = 1;
3
+ /** A verdict record keeps at most this many diagnostics; past it, it says how many it did not keep, and the counts stay exact. */
4
+ export declare const MAX_RECORD_DIAGNOSTICS = 50000;
5
+ /** How a program is checked: tsgo on the tsconfig as it is, or through the shim. */
6
+ export type RecordRoute = 'tsgo' | 'tsgo-shim';
7
+ /** MIRROR of `ToolErrorKind` in `@lensmcp/protocol-types` (static-checks.ts), which cluster does not depend on. */
8
+ export type RecordToolErrorKind = 'config-refused' | 'program-error' | 'timeout' | 'signal' | 'exit-without-diagnostics' | 'spawn-failed' | 'unparseable-output';
9
+ /** One diagnostic as a record holds it — `ReportedDiagnostic` of `@lensmcp/protocol-types`: `file` workspace-relative POSIX, positions 1-based. */
10
+ export interface RecordDiagnostic {
11
+ file: string;
12
+ line: number;
13
+ col: number;
14
+ code: string;
15
+ severity: 'error' | 'warning';
16
+ message: string;
17
+ }
18
+ /** A path as the workspace names it: relative to the root, POSIX. One outside the root keeps its `../`. */
19
+ export declare function toWorkspacePath(root: string, file: string): string;
20
+ export interface ProgramFiles {
21
+ /** `<root>/tmp/lensmcp-tsgo/<id>.tsconfig.json` — in-tree, so `@types` are found by walking up from it (tsgo-shim.ts). */
22
+ shim: string;
23
+ buildInfo: string;
24
+ trust: string;
25
+ lock: string;
26
+ /** `<root>/.lensmcp/static-checks/typecheck/<id>.json`. */
27
+ record: string;
28
+ stamps: string;
29
+ }
30
+ /** Where the verdict records of a checkout are kept. */
31
+ export declare function typecheckRecordsDir(root: string): string;
32
+ /** The files of one program, by its id (program-id.ts): what a check works with in `tmp/`, what it leaves in `.lensmcp/`. */
33
+ export declare function programFiles(root: string, id: string): ProgramFiles;
34
+ /** What says a file is the one it was, without reading it. `ctime` too: a copy that keeps its mtime still moves it. */
35
+ export interface FileStat {
36
+ mtimeMs: number;
37
+ ctimeMs: number;
38
+ size: number;
39
+ ino: number;
40
+ }
41
+ export interface FileStamp extends FileStat {
42
+ /** Workspace-relative, POSIX. */
43
+ file: string;
44
+ /** Of its content. */
45
+ hash: string;
46
+ }
47
+ /** A regular file's stat; null when it is not there (or is no file). */
48
+ export declare function statFile(root: string, file: string): FileStat | null;
49
+ export declare function sameStat(a: FileStat, b: FileStat): boolean;
50
+ /** A file's content hash; null when it cannot be read. */
51
+ export declare function hashFile(root: string, file: string): string | null;
52
+ export interface ProgramInputsArgs {
53
+ root: string;
54
+ /** Absolute. */
55
+ tsconfig: string;
56
+ route: RecordRoute;
57
+ /** The compiler options its command adds (`--composite false`). */
58
+ flags?: readonly string[];
59
+ /** Through the shim of the workspace compiler's defaults alone (tsgo-shim.ts `pinsOnly`): another program than through the shim that migrates. */
60
+ pinsOnly?: boolean;
61
+ compiler: {
62
+ version: string;
63
+ bin: string;
64
+ };
65
+ }
66
+ export interface ConfigInputs {
67
+ /** sha256 over `inputs`: the `configKey` of the plan. */
68
+ key: string;
69
+ /** Each input by name, with what says it is the same: a content hash, or the text itself. In a fixed order. */
70
+ inputs: Array<[string, string]>;
71
+ }
72
+ /**
73
+ * The tsconfigs of the projects a tsconfig references, absolute: a folder stands for its `tsconfig.json`. Read from
74
+ * the file itself — references are not inherited — so the dev checker and `lensmcp typecheck` name the same ones.
75
+ */
76
+ export declare function declaredReferences(tsconfig: string): string[];
77
+ /**
78
+ * What a program's build info is trusted with (plan § 5): the compiler's version and the real path of its binary, the
79
+ * route and the shim's version, the options its command adds, the content of every file in the tsconfig chain and in
80
+ * the chains of the projects it references, and the lockfiles. Any of them different is a different key, and the build
81
+ * info made under the old one is not read.
82
+ */
83
+ export declare function configInputs(args: ProgramInputsArgs): ConfigInputs;
84
+ /** The inputs that differ between two readings, as a person names them: the file, `the compiler`, `the route`. */
85
+ export declare function changedInputs(then: ReadonlyArray<[string, string]>, now: ReadonlyArray<[string, string]>): string[];
86
+ /**
87
+ * `Version 7.0.0-dev.20260707.2` → the version, asked of the binary once while the file is the one it was (a reinstall
88
+ * in a long-lived service asks again); undefined when it does not answer.
89
+ */
90
+ export declare function compilerVersion(bin: string): string | undefined;
91
+ /**
92
+ * Before a run: is there a build info to start from? Only one whose trust record names this program and this key —
93
+ * any other is deleted, so the check starts cold. The trust record is removed either way: for the length of the run
94
+ * nobody may trust the file a compiler is writing, and {@link settleBuildInfo} writes it back with a verdict.
95
+ */
96
+ export declare function trustBuildInfo(files: ProgramFiles, id: string, configKey: string): boolean;
97
+ /** A run without a verdict may have left a build info nobody should read: the next check starts cold. */
98
+ export declare function dropBuildInfo(files: ProgramFiles): void;
99
+ /** After a run: a verdict keeps the build info, under the key it was made with; anything else deletes it. */
100
+ export declare function settleBuildInfo(files: ProgramFiles, id: string, configKey: string | undefined, verdict: boolean, now?: () => number): void;
101
+ export interface ProgramLock {
102
+ token: string;
103
+ /** Give it back. Idempotent; a lock someone took over after its time is left to them. */
104
+ release(): void;
105
+ }
106
+ export interface LockHolder {
107
+ pid: number;
108
+ token: string;
109
+ /** `dev-checker`, `runner`. */
110
+ who: string;
111
+ at: number;
112
+ /** Past this it is abandoned whatever its pid says: a reused pid looks alive. */
113
+ until: number;
114
+ }
115
+ /** Who holds a program's lock, as its file says; null when there is none or it cannot be read. */
116
+ export declare function readLock(file: string): LockHolder | null;
117
+ /**
118
+ * Take a program's lock now, or null when a check of it is running. The file is created exclusively, so of two that
119
+ * try at once one gets it. A lock whose holder is gone, or that stands past its own time, is taken over.
120
+ * `holdMs`: the check's time limit. Throws only when the lock's folder cannot be written.
121
+ */
122
+ export declare function tryLock(file: string, opts: {
123
+ holdMs: number;
124
+ who: string;
125
+ now?: () => number;
126
+ isAlive?: (pid: number) => boolean;
127
+ }): ProgramLock | null;
128
+ export interface HeadState {
129
+ /** The commit; empty when git did not answer. */
130
+ sha: string;
131
+ /** Uncommitted or untracked changes. True when git did not answer: an unknown checkout is never called clean. */
132
+ dirty: boolean;
133
+ }
134
+ /** The commit a checkout is on and whether it has uncommitted or untracked changes, in one read that takes no lock in the repository. */
135
+ export declare function readHead(root: string): Promise<HeadState>;
136
+ /** A compiler error that says the program was not checked as configured (typecheck-bus.ts `TscProgramError`). */
137
+ export interface RecordProgramError {
138
+ code: string;
139
+ message: string;
140
+ source?: string;
141
+ line?: number;
142
+ col?: number;
143
+ }
144
+ /**
145
+ * The compiler's output, read a line at a time as it arrives: a program of 50,000 errors prints tens of megabytes, and
146
+ * a record keeps the first {@link MAX_RECORD_DIAGNOSTICS} of them with the exact counts. The same reading as the bus
147
+ * writer's `parseTscOutput` / `parseTscProgramErrors` — the cluster's spec holds the two equal on the parity fixtures.
148
+ */
149
+ export declare class RunOutput {
150
+ private readonly root;
151
+ readonly diagnostics: RecordDiagnostic[];
152
+ readonly programErrors: RecordProgramError[];
153
+ errorCount: number;
154
+ warningCount: number;
155
+ /** Diagnostics counted and not kept. */
156
+ dropped: number;
157
+ /** The first line printed, for a run that says nothing else. */
158
+ firstLine: string;
159
+ private rest;
160
+ constructor(root: string);
161
+ push(chunk: string): void;
162
+ end(): this;
163
+ private line;
164
+ }
165
+ /** How a run ended: a verdict, or why there is none. */
166
+ export type RunConclusion = {
167
+ outcome: 'verdict';
168
+ } | {
169
+ outcome: 'tool-error';
170
+ kind: RecordToolErrorKind;
171
+ code?: string;
172
+ detail: string;
173
+ };
174
+ /**
175
+ * What a run's ending says. The dev checker's rules (tsgo-check-plugin.ts), in its order and its words: killed at the
176
+ * time limit, ended by someone else's signal, a program error, a failing exit with no diagnostic — none of them is a
177
+ * verdict, and a program error is none whatever the exit code was.
178
+ */
179
+ export declare function concludeRun(args: {
180
+ exitCode: number | null;
181
+ signal: string | null;
182
+ timedOut: boolean;
183
+ timeoutMs: number;
184
+ spawnError?: string;
185
+ output: RunOutput;
186
+ }): RunConclusion;
187
+ /**
188
+ * The input files of a program, from the build info its check left: workspace-relative, sorted, without what the
189
+ * lockfile and the compiler's version stand for (`node_modules`, the compiler's own `lib.*.d.ts`). Null when the build
190
+ * info is not there or holds no list — then the run's record has no stamps, and is never fresh.
191
+ */
192
+ export declare function programInputFiles(buildInfo: string, root: string): string[] | null;
193
+ /** The files of a program as a run found them before it started. */
194
+ export interface RunStart {
195
+ at: number;
196
+ /** Each file known before the run; null: it was not there. */
197
+ stats: Map<string, FileStat | null>;
198
+ /** The content hash, read at the start, of each file written so close to it that its times cannot tell a later write apart. */
199
+ recent: Map<string, string>;
200
+ }
201
+ /** Stat every file the program is known to hold, at `at` — taken before the first stat, so a later write is a later time. */
202
+ export declare function statAtStart(root: string, files: readonly string[], at: number): RunStart;
203
+ /**
204
+ * The stamps of a run, and the files that changed while it ran. `files` is the program's list AFTER the run. A file is
205
+ * stamped as it was at the START:
206
+ *
207
+ * • one the start knew: its stat now must be its stat then — and written within moments of the start, its content
208
+ * must hash as it did then;
209
+ * • one the start did not know (an import added since the list was made, a first check): it must not have been
210
+ * touched since moments BEFORE the start, by its times — else nothing says the checker read what is there now.
211
+ *
212
+ * Anything else changed during the run. Hashes are read after the run, off the caller's path; the file is looked at
213
+ * again once read, and a file that moved meanwhile counts as changed. A hash of the last record is kept while the
214
+ * file's stat is what that record stamped.
215
+ */
216
+ export declare function stampAfterRun(args: {
217
+ root: string;
218
+ start: RunStart;
219
+ files: readonly string[];
220
+ previous?: ReadonlyMap<string, FileStamp> | null;
221
+ }): Promise<{
222
+ stamps: FileStamp[];
223
+ changed: string[];
224
+ }>;
225
+ export interface VerdictRecord {
226
+ schema: number;
227
+ /** program-id.ts. */
228
+ id: string;
229
+ /** Workspace-relative. */
230
+ tsconfig: string;
231
+ route: RecordRoute;
232
+ flags?: string[];
233
+ compiler: {
234
+ name: 'tsgo';
235
+ version: string;
236
+ };
237
+ /** Through the shim: its version. */
238
+ shimVersion?: number;
239
+ /** The key of {@link configInputs} at the start; empty when the run failed before it could be read. */
240
+ configKey: string;
241
+ inputs: Array<[string, string]>;
242
+ by: {
243
+ who: 'dev-checker' | 'runner';
244
+ pid: number;
245
+ };
246
+ startedAt: number;
247
+ endedAt: number;
248
+ durationMs: number;
249
+ peakMb?: number;
250
+ /** `sampled` is a lower bound. */
251
+ peakHow?: 'footprint' | 'maxrss' | 'sampled';
252
+ outcome: 'verdict' | 'tool-error';
253
+ toolError?: {
254
+ kind: RecordToolErrorKind;
255
+ code?: string;
256
+ detail: string;
257
+ };
258
+ /** The checkout at the start. */
259
+ head: HeadState;
260
+ /** Exact, whatever `diagnostics` holds. */
261
+ errorCount: number;
262
+ warningCount: number;
263
+ diagnostics: RecordDiagnostic[];
264
+ /** Past {@link MAX_RECORD_DIAGNOSTICS}: how many were not kept. */
265
+ droppedDiagnostics?: number;
266
+ /** An input changed while the checker ran: the verdict is of no state the checkout was in, and the record is stale at once. */
267
+ changedDuringRun: boolean;
268
+ /** The first of them, and how many. */
269
+ changed?: string[];
270
+ changedCount?: number;
271
+ /** The stamped file list: how many, and its hash. Null: the run left no list (no build info), and the record is never fresh. */
272
+ files: {
273
+ count: number;
274
+ hash: string;
275
+ } | null;
276
+ /** The build info the run left: its size, and whether the run started from a trusted one. */
277
+ buildInfo?: {
278
+ bytes: number;
279
+ warm: boolean;
280
+ };
281
+ }
282
+ /**
283
+ * The hash of a run's stamps — each file it vouches for, with its content's hash, in the order they are kept. With the
284
+ * inputs' key it is what a verdict reflects; and a record names it, so stamps that are not the ones it was written
285
+ * with do not pass for them.
286
+ */
287
+ export declare function stampsHashOf(stamps: Iterable<FileStamp>): string;
288
+ /** What a verdict was computed from, as one hash: the inputs' key and every stamped file's content. Empty without stamps. */
289
+ export declare function inputsHashOf(record: Pick<VerdictRecord, 'configKey' | 'files'>): string;
290
+ /**
291
+ * Keep a run's record and its stamps: stamps first, the record last — it is what says the stamps are its own. Not
292
+ * written over a record of a LATER run: the dev checker writes after it gave the lock back, and a slow write of an
293
+ * older run must not replace a newer one. False when it was not written.
294
+ */
295
+ export declare function writeVerdict(files: ProgramFiles, record: VerdictRecord, stamps: readonly FileStamp[] | null): boolean;
296
+ /** A program's record, when one of this schema is kept for this id. */
297
+ export declare function readRecord(files: ProgramFiles, id: string): VerdictRecord | null;
298
+ /**
299
+ * The stamps of a record, by file; null when there are none, or the ones on disk belong to another run. A stamp with
300
+ * no hash is a file that changed while that run ran.
301
+ */
302
+ export declare function readStamps(files: ProgramFiles, record: Pick<VerdictRecord, 'id' | 'startedAt'>): Map<string, FileStamp> | null;
303
+ /**
304
+ * What a run does with the program's build info:
305
+ * • `kept` — start from the last verdict's when it is trusted, and keep this run's under its inputs' key;
306
+ * • `cold` — start from none and keep none: the compiler still writes one, only for its file list to be read;
307
+ * • `none` — the compiler is not given one (the dev checker with `LENSMCP_TSGO_INCREMENTAL` off). The one on disk, if
308
+ * `lensmcp typecheck` left one, is not touched, and the run's record has no file list: it is never fresh.
309
+ */
310
+ export type BuildInfoUse = 'kept' | 'cold' | 'none';
311
+ export interface BeginRunArgs extends ProgramInputsArgs {
312
+ id: string;
313
+ who: 'dev-checker' | 'runner';
314
+ buildInfo: BuildInfoUse;
315
+ /** The program's files as last listed, for a run that has neither a build info nor a record to read them from. */
316
+ knownFiles?: readonly string[];
317
+ now?: () => number;
318
+ }
319
+ export interface BegunRun {
320
+ root: string;
321
+ id: string;
322
+ /** Workspace-relative. */
323
+ tsconfig: string;
324
+ route: RecordRoute;
325
+ flags: string[];
326
+ compilerVersion: string;
327
+ who: 'dev-checker' | 'runner';
328
+ files: ProgramFiles;
329
+ /** What the compiler's `-p` is given: the shim, or the tsconfig as it is. */
330
+ project: string;
331
+ config: ConfigInputs;
332
+ buildInfo: BuildInfoUse;
333
+ /** A trusted build info is there to start from. */
334
+ warm: boolean;
335
+ startedAt: number;
336
+ start: RunStart;
337
+ previous: Map<string, FileStamp> | null;
338
+ head: Promise<HeadState>;
339
+ now: () => number;
340
+ }
341
+ /**
342
+ * Everything a run does before its compiler starts, for whoever holds the program's lock: read the inputs' key, delete
343
+ * a build info it does not vouch for, write the shim from the chain as it is now, stat the files the program is known
344
+ * to hold, and start reading the checkout's commit. Throws what the file system said when the shim cannot be written.
345
+ */
346
+ export declare function beginRun(args: BeginRunArgs): BegunRun;
347
+ /**
348
+ * A check that could not even begin — no compiler to run, a shim that cannot be written — is a run with no verdict
349
+ * like any other: its record takes the place of the last one. Without it the verdict before would go on reading as
350
+ * this program's answer, with nothing checking it any more.
351
+ * `locked`: the caller holds the program's lock. Without it the lock is taken for the write, and while someone else's
352
+ * check holds it nothing is written: that check's own record is about to say what the program's state is.
353
+ */
354
+ export declare function recordUnrun(args: {
355
+ root: string;
356
+ id: string;
357
+ tsconfig: string;
358
+ route: RecordRoute;
359
+ flags?: readonly string[];
360
+ compilerVersion?: string;
361
+ who: 'dev-checker' | 'runner';
362
+ detail: string;
363
+ locked: boolean;
364
+ now?: () => number;
365
+ }): FinishedRun;
366
+ export interface RunResult {
367
+ conclusion: RunConclusion;
368
+ diagnostics: readonly RecordDiagnostic[];
369
+ errorCount: number;
370
+ warningCount: number;
371
+ /** Diagnostics counted and not among `diagnostics`. */
372
+ dropped?: number;
373
+ peakMb?: number;
374
+ peakHow?: 'footprint' | 'maxrss' | 'sampled';
375
+ }
376
+ export interface FinishedRun {
377
+ record: VerdictRecord;
378
+ /** The record is on disk. False: it could not be written, a later run's is there, or the caller no longer wants one. */
379
+ kept: boolean;
380
+ }
381
+ /**
382
+ * Everything a run does once its compiler ended: read the program's file list from the build info it left, settle that
383
+ * build info ({@link BuildInfoUse}: kept with a verdict, deleted without one), stamp the files as they were at the
384
+ * start, and keep the record. Everything up to the hashing happens before
385
+ * this returns its promise: the build info is settled and every file is looked at in the caller's own turn, so a check
386
+ * that follows at once finds the trust record there, and a write after the run ended is seen as one.
387
+ * `keep` answering false (a dev server going away): the build info is settled, and nothing is recorded.
388
+ */
389
+ export declare function finishRun(begun: BegunRun, result: RunResult, opts?: {
390
+ keep?: () => boolean;
391
+ }): Promise<FinishedRun>;