@reddb-io/red-skills 2.75.2 → 2.76.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6578,7 +6578,7 @@ Usage:
6578
6578
  ${n} archive --candidate <json> [--root <dir>] [--archive-dir <rel>]
6579
6579
  ${n} restore <name> [--root <dir>] [--archive-dir <rel>]`}function Ux(n){return pVn(typeof n.root=="string"?n.root:process.cwd())}function uut(n){return typeof n["archive-dir"]=="string"?n["archive-dir"]:void 0}async function eK(n){let a=await xs(n);return a?a.mode!=="graph"?{ok:!1,message:`curate: skill telemetry needs graph mode (this project is "${a.mode}") \u2014 run \`${VEe}\``}:ju(a)?{ok:!0}:{ok:!1,message:`curate: skill telemetry is not enabled here \u2014 run \`${VEe}\``}:{ok:!1,message:`curate: memory is not initialized here \u2014 run \`${VEe}\``}}function hVn(){let n=bVn(ZVn(import.meta.url));return n.includes("dist/curate-skill")||n.endsWith("dist/curate-skill")?Gut(n,"..","cli.js"):Gut(n,"..","cli.ts")}async function WVn(n,a){let i=["curate","skills","--json"];a!==void 0&&i.push("--stale-days",String(a));let d=hVn(),h=d.endsWith(".ts")?dut(process.execPath,["--import","tsx",d,...i,"--root",n],{encoding:"utf8"}):dut(process.execPath,[d,...i,"--root",n],{encoding:"utf8"}),g=h.status??1;if(g!==0)throw new Error(`memory curate skills exited ${g}`);return iut(h.stdout??"")}function NVn(n){return typeof n.flags["stale-days"]=="string"?Number(n.flags["stale-days"]):void 0}async function but(n,a){return(a.loadCuratorReport??WVn)(Ux(n.flags),NVn(n))}async function YVn(n){let a=Ux(n.flags),i=await eK(a);return i.ok?(console.log("curate: skill telemetry is enabled \u2014 ready to curate"),0):(console.error(i.message),2)}async function VVn(n,a){let i=Ux(n.flags),d=await eK(i);if(!d.ok)return console.error(d.message),2;let u;try{u=await but(n,a)}catch(J){return console.error(`curate: ${J.message}`),1}let{candidates:h,byCategory:g,filtered:f}=NEe(u);return console.log(JSON.stringify({candidates:h,byCategory:g,filtered:f,totals:{totalSkills:u.totalSkills,curatableSkills:u.curatableSkills,readOnlySkills:u.readOnlySkills}},null,2)),0}async function gVn(n,a){let i=Ux(n.flags),d=await eK(i);if(!d.ok)return console.error(d.message),2;let u;try{u=await but(n,a)}catch(J){return console.error(`curate: ${J.message}`),1}let{byCategory:h}=NEe(u);if(YEe(h)===0)return console.error("curate: no candidates \u2014 no issue filed"),0;let g=typeof n.flags.label=="string"?n.flags.label:void 0,f=await out({byCategory:h,totals:{totalSkills:u.totalSkills,curatableSkills:u.curatableSkills,readOnlySkills:u.readOnlySkills},generatedAt:u.generatedAt},{cwd:i,label:g});return console.log(`curate: filed background issue \u2014 ${f.output||f.title}`),0}async function yVn(n){let a=Ux(n.flags),i=await eK(a);if(!i.ok)return console.error(i.message),2;let d=n.flags.candidate;if(typeof d!="string")return console.error("curate archive: --candidate <json> is required"),2;let u;try{u=JSON.parse(d)}catch(g){return console.error(`curate archive: invalid --candidate JSON: ${g.message}`),2}let h=await rut(u,{rootDir:a,archiveDir:uut(n.flags)});return h.ok?(console.log(`curate: archived "${h.receipt.name}" \u2192 ${h.receipt.archiveRoot} (${h.receipt.files.length} file(s), manifest at ${h.receipt.manifestPath})`),0):(console.error(`curate archive: refused \u2014 ${h.rejection.reason}: ${h.rejection.detail}`),3)}async function RVn(n){let a=Ux(n.flags),i=await eK(a);if(!i.ok)return console.error(i.message),2;let d=n.positional[0];if(!d)return console.error("curate restore: skill name is required"),2;let u=await cut(d,{rootDir:a,archiveDir:uut(n.flags)});return console.log(`curate: restored "${u.name}" \u2192 ${u.restoredRoot} (${u.files.length} file(s) hash-verified)`),0}async function gEe(n,a={}){switch(n.command){case"check":return YVn(n);case"list":return VVn(n,a);case"background":return gVn(n,a);case"archive":return yVn(n);case"restore":return RVn(n);case void 0:case"--help":case"-h":return console.log(mut(a.usageCommand)),0;default:return console.error(`unknown curate subcommand: ${n.command}
6580
6580
 
6581
- ${mut(a.usageCommand)}`),2}}function yEe(n){let a={app:n,version:vVn(Bx("__RED_BUILD_VERSION__",()=>"2.75.2")??"0.0.0-dev"),gitSha:Bx("__RED_BUILD_GIT_SHA__",()=>"3ca11d383515f309d1c7c66b7ccd52d1966cfd10")??"unknown",buildTime:Bx("__RED_BUILD_TIME__",()=>"2026-07-19T09:22:25-03:00")??"unknown",bundleAsset:Bx("__RED_BUNDLE_ASSET__",()=>"memory.bundle.min.mjs")??"unknown"},i=Bx("__REDDB_SDK_VERSION__",()=>"1.23.1"),d=Bx("__REDDB_BINARY_TAG__",()=>"v1.23.1");return i&&(a.reddbSdkVersion=i),d&&(a.reddbBinaryTag=d),a}function vVn(n){return n.startsWith("v")?n.slice(1):n}function REe(n){return`${n.app} ${n.version} ${n.gitSha}`}function Bx(n,a){try{let i=a();return typeof i=="string"&&i.length>0?i:void 0}catch{return process.env[n.replace(/^__|__$/g,"")]}}async function Yut(n){let a=n.positional[0];if(a==="context")return EVn(n);if(a!=="skills")throw new Error("status needs a kind \u2014 supported: memory status skills|context");let i=pa(n.flags),d=n.flags.json===!0,u=await xs(i);if(!u)return vEe(d,"uninitialized","memory is not initialized here",{hint:"run `memory init --mode graph --skill-telemetry`"});if(u.mode!=="graph")return vEe(d,"no-op",`skill telemetry needs graph mode, this project is "${u.mode}"`,{hint:"re-run `memory init --mode graph --skill-telemetry`"});if(!ju(u))return vEe(d,"unavailable","skill telemetry is not enabled here",{hint:"re-run `memory init --mode graph --skill-telemetry`"});let h=n.flags.all===!0,g=Pa(n.flags,"limit")??10,f=await Wi.open({uri:di(i,u)}),J,S;try{J=await DG(f),S=await Hx(f,g)}finally{await f.close()}let ne=J.filter(Pe=>Mx(Pe.source_kind)).length,be=h?J:J.filter(Pe=>Mx(Pe.source_kind)),j=h?S:S.filter(Pe=>Mx(Pe.source_kind));if(d){console.log(JSON.stringify({state:"enabled",scope:h?"all":"curatable",totalSkills:J.length,curatableSkills:ne,readOnlySkills:J.length-ne,skills:be,recentEvents:j},null,2));return}if(console.log("memory: skill telemetry status \u2014 enabled (graph mode)"),console.log(` ${J.length} ${Dv(J.length,"skill")} observed (${ne} curatable, ${J.length-ne} read-only)`),J.length===0){console.log(" no skills observed yet \u2014 telemetry is enabled but nothing has been recorded"),console.log(`
6581
+ ${mut(a.usageCommand)}`),2}}function yEe(n){let a={app:n,version:vVn(Bx("__RED_BUILD_VERSION__",()=>"2.76.0")??"0.0.0-dev"),gitSha:Bx("__RED_BUILD_GIT_SHA__",()=>"98f11e91d3780bfdcbbfec1428f03cece7fc553d")??"unknown",buildTime:Bx("__RED_BUILD_TIME__",()=>"2026-07-19T16:30:47-03:00")??"unknown",bundleAsset:Bx("__RED_BUNDLE_ASSET__",()=>"memory.bundle.min.mjs")??"unknown"},i=Bx("__REDDB_SDK_VERSION__",()=>"1.23.1"),d=Bx("__REDDB_BINARY_TAG__",()=>"v1.23.1");return i&&(a.reddbSdkVersion=i),d&&(a.reddbBinaryTag=d),a}function vVn(n){return n.startsWith("v")?n.slice(1):n}function REe(n){return`${n.app} ${n.version} ${n.gitSha}`}function Bx(n,a){try{let i=a();return typeof i=="string"&&i.length>0?i:void 0}catch{return process.env[n.replace(/^__|__$/g,"")]}}async function Yut(n){let a=n.positional[0];if(a==="context")return EVn(n);if(a!=="skills")throw new Error("status needs a kind \u2014 supported: memory status skills|context");let i=pa(n.flags),d=n.flags.json===!0,u=await xs(i);if(!u)return vEe(d,"uninitialized","memory is not initialized here",{hint:"run `memory init --mode graph --skill-telemetry`"});if(u.mode!=="graph")return vEe(d,"no-op",`skill telemetry needs graph mode, this project is "${u.mode}"`,{hint:"re-run `memory init --mode graph --skill-telemetry`"});if(!ju(u))return vEe(d,"unavailable","skill telemetry is not enabled here",{hint:"re-run `memory init --mode graph --skill-telemetry`"});let h=n.flags.all===!0,g=Pa(n.flags,"limit")??10,f=await Wi.open({uri:di(i,u)}),J,S;try{J=await DG(f),S=await Hx(f,g)}finally{await f.close()}let ne=J.filter(Pe=>Mx(Pe.source_kind)).length,be=h?J:J.filter(Pe=>Mx(Pe.source_kind)),j=h?S:S.filter(Pe=>Mx(Pe.source_kind));if(d){console.log(JSON.stringify({state:"enabled",scope:h?"all":"curatable",totalSkills:J.length,curatableSkills:ne,readOnlySkills:J.length-ne,skills:be,recentEvents:j},null,2));return}if(console.log("memory: skill telemetry status \u2014 enabled (graph mode)"),console.log(` ${J.length} ${Dv(J.length,"skill")} observed (${ne} curatable, ${J.length-ne} read-only)`),J.length===0){console.log(" no skills observed yet \u2014 telemetry is enabled but nothing has been recorded"),console.log(`
6582
6582
  Diagnostic command: normal-use ingestion stays silent; this surface only reads.`);return}if(console.log(h?" scope: all observed skills (including bundled plugin/hub skills)":" scope: curatable skills (use --all to include bundled plugin/hub skills)"),be.length===0)console.log(" no curatable skills observed \u2014 re-run with --all to see bundled skills");else{console.log(`
6583
6583
  skill / kind / events (v\xB7u\xB7p\xB7c\xB7r) / outcomes / last-activity:`);for(let Pe of be){let ye=OVn(Pe.outcome_counts);console.log(` ${Pe.name} (${Pe.source_kind}) \u2014 ${Pe.event_count} event(s) (v${Pe.view_count}\xB7u${Pe.use_count}\xB7p${Pe.patch_count}\xB7c${Pe.change_count}\xB7r${Pe.result_count})${ye?` ${ye}`:""} \u2014 ${Pe.last_activity}`)}}if(j.length>0){console.log(`
6584
6584
  recent events (newest first, up to ${g}):`);for(let Pe of j){let ye=Pe.status?` [${Pe.status}]`:"";console.log(` ${Pe.timestamp} ${Pe.event_type}${ye} ${Pe.name} (${Pe.source_kind}) <${Pe.runner}>`)}}console.log(`
@@ -155,7 +155,7 @@ const timer = setInterval(() => {
155
155
  }, 500);
156
156
  `,String(process.pid)],{detached:!0,stdio:"ignore"});return t.unref(),t}function _s(){for(let e of ZR())try{process.kill(e,"SIGTERM")}catch{}}function ZR(){if(process.platform==="win32")return[];let e="";try{e=DR("ps",["-eo","pid=,ppid=,args="],{encoding:"utf8"})}catch{return[]}let t=[];for(let r of e.split(/\n/)){let n=/^\s*(\d+)\s+(\d+)\s+([\s\S]*)$/.exec(r);if(!n)continue;let s=Number(n[1]),i=Number(n[2]),o=n[3]??"";i===process.pid&&/(^|\s)\S*red(?:\.exe)?\s+rpc\s+--stdio(\s|$)/.test(o)&&t.push(s)}return t}async function XR(e){if(e.collection!==ce)return e;let t=await cf(e.raw_text,lf(e.raw_bytes)),r=await cf(e.emitted_text,lf(e.emitted_bytes)),{raw_text:n,emitted_text:s,...i}=e;return{...i,tokens_raw:t.tokens,tokens_emitted:r.tokens,estimated:t.estimated||r.estimated}}async function cf(e,t){if(typeof e=="string"){let r=Buffer.byteLength(e,"utf8");if(r<=jR)try{return await hf((async()=>({tokens:(await eS())("cl100k_base").encode(e).length,estimated:!1}))(),UR,"telemetry tokenization timed out")}catch{return{tokens:Math.ceil(r/4),estimated:!0}}return{tokens:Math.ceil(r/4),estimated:!0}}return t!=null?{tokens:Math.ceil(t/4),estimated:!0}:{tokens:0,estimated:!1}}async function eS(){return uf??=import(BR(tS()).href).then(e=>{let t=e.getEncoding;if(!t)throw new Error("js-tiktoken getEncoding export not found");return t}),await uf}function tS(){let e=sa(LR(import.meta.url)),r=[bs(e,"..","node_modules","js-tiktoken","dist","index.js"),bs(e,"..","apps","rsp","node_modules","js-tiktoken","dist","index.js")].find(n=>AR(n));if(!r)throw new Error("js-tiktoken dependency not found");return r}function lf(e){return typeof e=="number"&&Number.isFinite(e)&&e>=0?e:void 0}function H(e){return typeof e=="string"&&e.trim()!==""?e:void 0}function ra(e){return e.trim().split(/\s+/).filter(Boolean)[0]??"unknown"}async function hf(e,t,r){let n;try{return await Promise.race([e,new Promise((s,i)=>{n=setTimeout(()=>i(new Error(r)),t),n.unref()})])}finally{n&&clearTimeout(n)}}function rS(e){try{return JSON.parse(e)}catch{return e}}function nS(e){return df(e)&&e.version===1&&Array.isArray(e.records)&&e.records.every(t=>df(t)&&(t.collection===te||t.collection===G||t.collection===ce||t.collection===Ce)&&typeof t.key=="string"&&typeof t.created_at=="string"&&typeof t.expires_at=="string"&&typeof t.bytes=="number")}function df(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function sS(e,t){let r="";e.setEncoding("utf8"),e.on("error",()=>{}),e.on("data",n=>{r+=n;let s=r.indexOf(`
157
157
  `);if(s<0)return;let i=r.slice(0,s);e.pause(),(async()=>{let o;try{o=JSON.parse(i),await t(o)}catch(a){let u={id:o?.id??sr(),ok:!1,error:a instanceof Error?a.message:String(a)};yf(e,u)}finally{e.end()}})()})}function yf(e,t){if(!(e.destroyed||!e.writable))try{e.write(`${JSON.stringify(t)}
158
- `)}catch{}}async function iS(e,t,r,n){if(t.op==="handover")return{handover:!0,version:n,clientVersion:t.clientVersion};if(e.kind==="opening")throw new Error("rsp resident store is not ready");if(e.kind==="failed")throw new Error(`rsp resident store failed to open: ${e.error.message}`);let s=e.store;if(t.op==="ping")return{pong:!0,version:n};if(t.op==="stats")return await s.stats();if(t.op==="accounting-stats"){let i=s.redDb();if(!i)throw new Error("rsp accounting stats require the shared RedDB store");return await Ji(i,t.byteBudget)}if(t.op==="telemetry-stats"){let i=s.redDb();if(!i)throw new Error("rsp telemetry stats require the shared RedDB store");return await Bn(i,t.sinceDays)}if(t.op==="telemetry-gains"){let i=s.redDb();if(!i)throw new Error("rsp telemetry gains require the shared RedDB store");return await Gi(i,t.sinceDays)}if(t.op==="mint")return{handle:await s.mint(Buffer.from(t.original,"base64"),t.meta)};if(t.op==="get")return aS(await s.get(t.handle));if(t.op==="memory")return await s.memory(t.action,t.payload);if(t.op==="brain")return await oS(s,r,t.action,t.payload);throw new Error(`unsupported resident op: ${t.op??"unknown"}`)}async function oS(e,t,r,n){let s=e.redDb();if(!s)throw new Error("resident brain operations require the shared RedDB store");return await Xd(s,t).request(r,n)}function aS(e){return e?"status"in e?e:{...e,original:e.original.toString("base64"),original_encoding:"base64"}:null}var jR,UR,mf,FR,JR,GR,na,af,uf,bf=_(()=>{"use strict";Be();wn();Me();et();sf();_e();Pe();jR=256*1024,UR=500,mf=2e3,FR=Math.max(1,Number(process.env.RSP_TEST_IDLE_SHUTDOWN_WATCHDOG_MS??"10000")),JR="rsp-status-summary.json",GR=[te,G,ce,Ce,Cr],na=class{constructor(t,r){this.store=t;this.opts=r;this.pendingHeals=[...r.bootHeals??[]]}running;pending=!1;pendingHeals;async drainAndSweep(){if(this.running){this.pending=!0,await this.running;return}this.running=(async()=>{do this.pending=!1,await this.drainAndSweepOnce();while(this.pending)})().finally(()=>{this.running=void 0}),await this.running}async drainAndSweepOnce(){let t=this.store.redDb();if(!t)return;let r=await qR(t);r.unshift(...this.pendingHeals),this.pendingHeals=[];let n=await this.readIndex(t),s=n.records.length,i=[...n.records];for(let a of r)i.push(await this.writeDrainDegradation(t,{reason:"telemetry collection model mismatch",command:"rsp resident telemetry drain",source_collection:a.collection,error:`expected kv, got ${a.previousModel}`,bytes:0}));await Fi(this.opts.rootDir,async a=>{let c=Kt(a);if(!c){let u=await this.writeDrainDegradation(t,{reason:"telemetry parse failed",command:"unknown",bytes:Buffer.byteLength(a,"utf8")});return i.push(u),!0}try{let u=await this.writeEvent(t,c);i.push(u);let l=await this.writeAccountingMirror(t,c);return l&&i.push(l),!0}catch(u){let l=await this.writeDrainDegradation(t,{reason:"telemetry event dropped",command:H(c.command)||"unknown",source_id:H(c.id),source_collection:H(c.collection),error:u instanceof Error?u.message:String(u),bytes:Buffer.byteLength(a,"utf8")});return i.push(l),!0}});let o=i.length>s;await this.prune(t,{version:1,records:i},o),await HR(t,this.opts.rootDir)}async writeEvent(t,r){let n=new Date,s=typeof r.created_at=="string"?r.created_at:n.toISOString(),i=new Date(Date.parse(s)+this.opts.ttlDays*24*60*60*1e3).toISOString(),o=typeof r.id=="string"&&r.id.trim()!==""?r.id:sr(),a={...await XR(r),id:o,created_at:s,expires_at:i};return await t.kv(r.collection).put(o,a),{collection:r.collection,key:o,created_at:s,expires_at:i,bytes:r.collection===te?0:typeof r.bytes=="number"&&Number.isFinite(r.bytes)?Math.max(0,r.bytes):Buffer.byteLength(JSON.stringify(a),"utf8")}}async writeAccountingMirror(t,r){return r.collection===te||r.accounting_recorded===!0?null:r.collection===ce?await this.writeEvent(t,{collection:te,id:`mirror:${H(r.id)||sr()}`,created_at:H(r.created_at)||H(r.ts)||new Date().toISOString(),event_type:"invocation",command:H(r.command)||"unknown",command_class:ra(H(r.command)||"unknown"),wrapper:r.wrapper,loss:r.loss,elided:r.elided,raw_bytes:r.raw_bytes,emitted_bytes:r.emitted_bytes,tokens_raw:r.tokens_raw,tokens_emitted:r.tokens_emitted,estimated:r.estimated,wrapper_ms:r.wrapper_ms,store_open_count:r.store_open_count,store_elapsed_ms:r.store_elapsed_ms}):r.collection===Ce?await this.writeEvent(t,{collection:te,id:`mirror:${H(r.id)||sr()}`,created_at:H(r.created_at)||H(r.ts)||new Date().toISOString(),event_type:"invocation",command:H(r.command)||"unknown",command_class:ra(H(r.command)||"unknown"),loss:"lossless",raw_bytes:0,emitted_bytes:0,degradation_reason:H(r.reason)||"unknown",wrapper_family:H(r.wrapper_family),wrapper_exit_code:r.wrapper_exit_code,stderr_head:H(r.stderr_head)}):null}async writeDrainDegradation(t,r){let n=await this.writeEvent(t,{collection:Ce,id:sr(),created_at:new Date().toISOString(),reason:r.reason,command:r.command,bytes:r.bytes,source_id:r.source_id,source_collection:r.source_collection,error:r.error});return await this.writeEvent(t,{collection:te,id:`mirror:${sr()}`,created_at:n.created_at,event_type:"invocation",command:r.command,command_class:ra(r.command),loss:"lossless",raw_bytes:0,emitted_bytes:0,degradation_reason:r.reason,source_id:r.source_id,source_collection:r.source_collection,error:r.error}),n}async readIndex(t){let r=await t.kv(Cr).get("index:v1"),n=typeof r=="string"?rS(r):r;return nS(n)?n:{version:1,records:[]}}async writeIndex(t,r){await t.kv(Cr).put("index:v1",r)}async prune(t,r,n=!1){let s=Date.now(),i=[];for(let a of r.records)Date.parse(a.expires_at)<=s?await t.kv(a.collection).delete(a.key):i.push(a);let o=i.reduce((a,c)=>a+c.bytes,0);for(i.sort((a,c)=>a.created_at.localeCompare(c.created_at));o>this.opts.byteBudget&&i.length>0;){let a=i.shift();o-=a.bytes,await t.kv(a.collection).delete(a.key)}(n||i.length<r.records.length)&&await this.writeIndex(t,{version:1,records:i})}};af=!1});ve();function ge(e,t){let r=e.indexOf(t);return r>=0?e[r+1]:void 0}function U(e,t){let r=ge(e,t);if(r==null)return;let n=Number(r);return Number.isFinite(n)&&n>0?n:void 0}function Pa(e){return e[0]==="--help"||e[0]==="-h"||e.includes("--help")||e.includes("-h")}function Ca(e){let t={level:"lossless",positional:[]},r=[];for(let n=0;n<e.length;n++){let s=e[n];if(s==="--store-uri")t.storeUri=e[++n];else if(s==="--brief")t.level="brief";else if(s==="--terse")t.level="terse";else if(s==="--query")t.query=e[++n];else if(s.startsWith("--query="))t.query=s.slice(8);else{if(r.length===0&&s.startsWith("--"))throw new js(s);r.push(s)}}return t.query&&r[0]!=="show"&&!r.some(n=>n==="--query"||n.startsWith("--query="))&&r.push("--query",t.query),t.command=r[0],t.handle=r[1],t.positional=r,t}var js=class extends Error{constructor(r){super(`unknown flag: ${r}`);this.flag=r}render(){return sn("rsp",this.flag,["--store-uri","--brief","--terse","--query"],"rsp --help")}};function $t(e){return typeof e=="object"&&e!==null&&"render"in e&&typeof e.render=="function"}function Da(e){let t=e[1];if(!t)return null;let r={};for(let n=2;n<e.length;n++){let s=e[n];if(s!=="-f"&&s!=="-F")continue;let i=e[++n]??"",o=i.indexOf("=");o<=0||(r[i.slice(0,o)]=i.slice(o+1))}return{path:t,params:r}}function on(e,t){let r=ge(e,"--since")??e.find(i=>i.startsWith("--since="))?.slice(8);if(!r)return t;let n=/^(\d+)(d)?$/.exec(r);if(!n)return t;let s=Number(n[1]);return Number.isFinite(s)&&s>0?s:t}function Ia(e){return e.includes("--full")}Me();import{existsSync as cS}from"node:fs";import{fileURLToPath as uS}from"node:url";function Ma(e){let t={app:e,version:up(Bt("__RED_BUILD_VERSION__",()=>"2.75.2")??"0.0.0-dev"),gitSha:Bt("__RED_BUILD_GIT_SHA__",()=>"3ca11d383515f309d1c7c66b7ccd52d1966cfd10")??"unknown",buildTime:Bt("__RED_BUILD_TIME__",()=>"2026-07-19T09:22:25-03:00")??"unknown",bundleAsset:Bt("__RED_BUNDLE_ASSET__",()=>"rsp.bundle.min.mjs")??"unknown"},r=Bt("__REDDB_SDK_VERSION__",()=>"1.23.1"),n=Bt("__REDDB_BINARY_TAG__",()=>"v1.23.1");return r&&(t.reddbSdkVersion=r),n&&(t.reddbBinaryTag=n),t}function up(e){return e.startsWith("v")?e.slice(1):e}function Bt(e,t){try{let r=t();return typeof r=="string"&&r.length>0?r:void 0}catch{return process.env[e.replace(/^__|__$/g,"")]}}ve();Me();pr();import{existsSync as Xh}from"node:fs";import{fileURLToPath as ey}from"node:url";oi();Me();ui();import{existsSync as Xg}from"node:fs";import{fileURLToPath as eh}from"node:url";async function Xt(e,t){let r={stats:th(e.telemetryByteBudget),telemetry:Wi(t)};if(!e.storeUri.startsWith("file://"))return r;let n=eh(e.storeUri);if(!Xg(n))return r;if(!n.endsWith("red-skills.rdb")){let{RspElisionStore:c}=await Promise.resolve().then(()=>(et(),Wt)),u=await c.open({uri:e.storeUri,ttlDays:e.ttlDays,ephemeralTtlHours:e.ephemeralTtlHours,byteBudget:e.byteBudget});try{return{stats:await u.stats(),telemetry:Wi(t)}}finally{await u.close()}}let{ensureReddbBinaryFromWarmCache:s}=await Promise.resolve().then(()=>(et(),Wt));await s();let{readAccountingLaneStats:i,readTelemetryStats:o}=await Promise.resolve().then(()=>(_e(),Ar)),a=await Ut(e.storeUri);try{return{stats:await i(a,e.telemetryByteBudget),telemetry:await o(a,t)}}finally{await a.close()}}function Vi(e,t=Wi(30),r=!1){return`${j(zi(e,t,r))}
158
+ `)}catch{}}async function iS(e,t,r,n){if(t.op==="handover")return{handover:!0,version:n,clientVersion:t.clientVersion};if(e.kind==="opening")throw new Error("rsp resident store is not ready");if(e.kind==="failed")throw new Error(`rsp resident store failed to open: ${e.error.message}`);let s=e.store;if(t.op==="ping")return{pong:!0,version:n};if(t.op==="stats")return await s.stats();if(t.op==="accounting-stats"){let i=s.redDb();if(!i)throw new Error("rsp accounting stats require the shared RedDB store");return await Ji(i,t.byteBudget)}if(t.op==="telemetry-stats"){let i=s.redDb();if(!i)throw new Error("rsp telemetry stats require the shared RedDB store");return await Bn(i,t.sinceDays)}if(t.op==="telemetry-gains"){let i=s.redDb();if(!i)throw new Error("rsp telemetry gains require the shared RedDB store");return await Gi(i,t.sinceDays)}if(t.op==="mint")return{handle:await s.mint(Buffer.from(t.original,"base64"),t.meta)};if(t.op==="get")return aS(await s.get(t.handle));if(t.op==="memory")return await s.memory(t.action,t.payload);if(t.op==="brain")return await oS(s,r,t.action,t.payload);throw new Error(`unsupported resident op: ${t.op??"unknown"}`)}async function oS(e,t,r,n){let s=e.redDb();if(!s)throw new Error("resident brain operations require the shared RedDB store");return await Xd(s,t).request(r,n)}function aS(e){return e?"status"in e?e:{...e,original:e.original.toString("base64"),original_encoding:"base64"}:null}var jR,UR,mf,FR,JR,GR,na,af,uf,bf=_(()=>{"use strict";Be();wn();Me();et();sf();_e();Pe();jR=256*1024,UR=500,mf=2e3,FR=Math.max(1,Number(process.env.RSP_TEST_IDLE_SHUTDOWN_WATCHDOG_MS??"10000")),JR="rsp-status-summary.json",GR=[te,G,ce,Ce,Cr],na=class{constructor(t,r){this.store=t;this.opts=r;this.pendingHeals=[...r.bootHeals??[]]}running;pending=!1;pendingHeals;async drainAndSweep(){if(this.running){this.pending=!0,await this.running;return}this.running=(async()=>{do this.pending=!1,await this.drainAndSweepOnce();while(this.pending)})().finally(()=>{this.running=void 0}),await this.running}async drainAndSweepOnce(){let t=this.store.redDb();if(!t)return;let r=await qR(t);r.unshift(...this.pendingHeals),this.pendingHeals=[];let n=await this.readIndex(t),s=n.records.length,i=[...n.records];for(let a of r)i.push(await this.writeDrainDegradation(t,{reason:"telemetry collection model mismatch",command:"rsp resident telemetry drain",source_collection:a.collection,error:`expected kv, got ${a.previousModel}`,bytes:0}));await Fi(this.opts.rootDir,async a=>{let c=Kt(a);if(!c){let u=await this.writeDrainDegradation(t,{reason:"telemetry parse failed",command:"unknown",bytes:Buffer.byteLength(a,"utf8")});return i.push(u),!0}try{let u=await this.writeEvent(t,c);i.push(u);let l=await this.writeAccountingMirror(t,c);return l&&i.push(l),!0}catch(u){let l=await this.writeDrainDegradation(t,{reason:"telemetry event dropped",command:H(c.command)||"unknown",source_id:H(c.id),source_collection:H(c.collection),error:u instanceof Error?u.message:String(u),bytes:Buffer.byteLength(a,"utf8")});return i.push(l),!0}});let o=i.length>s;await this.prune(t,{version:1,records:i},o),await HR(t,this.opts.rootDir)}async writeEvent(t,r){let n=new Date,s=typeof r.created_at=="string"?r.created_at:n.toISOString(),i=new Date(Date.parse(s)+this.opts.ttlDays*24*60*60*1e3).toISOString(),o=typeof r.id=="string"&&r.id.trim()!==""?r.id:sr(),a={...await XR(r),id:o,created_at:s,expires_at:i};return await t.kv(r.collection).put(o,a),{collection:r.collection,key:o,created_at:s,expires_at:i,bytes:r.collection===te?0:typeof r.bytes=="number"&&Number.isFinite(r.bytes)?Math.max(0,r.bytes):Buffer.byteLength(JSON.stringify(a),"utf8")}}async writeAccountingMirror(t,r){return r.collection===te||r.accounting_recorded===!0?null:r.collection===ce?await this.writeEvent(t,{collection:te,id:`mirror:${H(r.id)||sr()}`,created_at:H(r.created_at)||H(r.ts)||new Date().toISOString(),event_type:"invocation",command:H(r.command)||"unknown",command_class:ra(H(r.command)||"unknown"),wrapper:r.wrapper,loss:r.loss,elided:r.elided,raw_bytes:r.raw_bytes,emitted_bytes:r.emitted_bytes,tokens_raw:r.tokens_raw,tokens_emitted:r.tokens_emitted,estimated:r.estimated,wrapper_ms:r.wrapper_ms,store_open_count:r.store_open_count,store_elapsed_ms:r.store_elapsed_ms}):r.collection===Ce?await this.writeEvent(t,{collection:te,id:`mirror:${H(r.id)||sr()}`,created_at:H(r.created_at)||H(r.ts)||new Date().toISOString(),event_type:"invocation",command:H(r.command)||"unknown",command_class:ra(H(r.command)||"unknown"),loss:"lossless",raw_bytes:0,emitted_bytes:0,degradation_reason:H(r.reason)||"unknown",wrapper_family:H(r.wrapper_family),wrapper_exit_code:r.wrapper_exit_code,stderr_head:H(r.stderr_head)}):null}async writeDrainDegradation(t,r){let n=await this.writeEvent(t,{collection:Ce,id:sr(),created_at:new Date().toISOString(),reason:r.reason,command:r.command,bytes:r.bytes,source_id:r.source_id,source_collection:r.source_collection,error:r.error});return await this.writeEvent(t,{collection:te,id:`mirror:${sr()}`,created_at:n.created_at,event_type:"invocation",command:r.command,command_class:ra(r.command),loss:"lossless",raw_bytes:0,emitted_bytes:0,degradation_reason:r.reason,source_id:r.source_id,source_collection:r.source_collection,error:r.error}),n}async readIndex(t){let r=await t.kv(Cr).get("index:v1"),n=typeof r=="string"?rS(r):r;return nS(n)?n:{version:1,records:[]}}async writeIndex(t,r){await t.kv(Cr).put("index:v1",r)}async prune(t,r,n=!1){let s=Date.now(),i=[];for(let a of r.records)Date.parse(a.expires_at)<=s?await t.kv(a.collection).delete(a.key):i.push(a);let o=i.reduce((a,c)=>a+c.bytes,0);for(i.sort((a,c)=>a.created_at.localeCompare(c.created_at));o>this.opts.byteBudget&&i.length>0;){let a=i.shift();o-=a.bytes,await t.kv(a.collection).delete(a.key)}(n||i.length<r.records.length)&&await this.writeIndex(t,{version:1,records:i})}};af=!1});ve();function ge(e,t){let r=e.indexOf(t);return r>=0?e[r+1]:void 0}function U(e,t){let r=ge(e,t);if(r==null)return;let n=Number(r);return Number.isFinite(n)&&n>0?n:void 0}function Pa(e){return e[0]==="--help"||e[0]==="-h"||e.includes("--help")||e.includes("-h")}function Ca(e){let t={level:"lossless",positional:[]},r=[];for(let n=0;n<e.length;n++){let s=e[n];if(s==="--store-uri")t.storeUri=e[++n];else if(s==="--brief")t.level="brief";else if(s==="--terse")t.level="terse";else if(s==="--query")t.query=e[++n];else if(s.startsWith("--query="))t.query=s.slice(8);else{if(r.length===0&&s.startsWith("--"))throw new js(s);r.push(s)}}return t.query&&r[0]!=="show"&&!r.some(n=>n==="--query"||n.startsWith("--query="))&&r.push("--query",t.query),t.command=r[0],t.handle=r[1],t.positional=r,t}var js=class extends Error{constructor(r){super(`unknown flag: ${r}`);this.flag=r}render(){return sn("rsp",this.flag,["--store-uri","--brief","--terse","--query"],"rsp --help")}};function $t(e){return typeof e=="object"&&e!==null&&"render"in e&&typeof e.render=="function"}function Da(e){let t=e[1];if(!t)return null;let r={};for(let n=2;n<e.length;n++){let s=e[n];if(s!=="-f"&&s!=="-F")continue;let i=e[++n]??"",o=i.indexOf("=");o<=0||(r[i.slice(0,o)]=i.slice(o+1))}return{path:t,params:r}}function on(e,t){let r=ge(e,"--since")??e.find(i=>i.startsWith("--since="))?.slice(8);if(!r)return t;let n=/^(\d+)(d)?$/.exec(r);if(!n)return t;let s=Number(n[1]);return Number.isFinite(s)&&s>0?s:t}function Ia(e){return e.includes("--full")}Me();import{existsSync as cS}from"node:fs";import{fileURLToPath as uS}from"node:url";function Ma(e){let t={app:e,version:up(Bt("__RED_BUILD_VERSION__",()=>"2.76.0")??"0.0.0-dev"),gitSha:Bt("__RED_BUILD_GIT_SHA__",()=>"98f11e91d3780bfdcbbfec1428f03cece7fc553d")??"unknown",buildTime:Bt("__RED_BUILD_TIME__",()=>"2026-07-19T16:30:47-03:00")??"unknown",bundleAsset:Bt("__RED_BUNDLE_ASSET__",()=>"rsp.bundle.min.mjs")??"unknown"},r=Bt("__REDDB_SDK_VERSION__",()=>"1.23.1"),n=Bt("__REDDB_BINARY_TAG__",()=>"v1.23.1");return r&&(t.reddbSdkVersion=r),n&&(t.reddbBinaryTag=n),t}function up(e){return e.startsWith("v")?e.slice(1):e}function Bt(e,t){try{let r=t();return typeof r=="string"&&r.length>0?r:void 0}catch{return process.env[e.replace(/^__|__$/g,"")]}}ve();Me();pr();import{existsSync as Xh}from"node:fs";import{fileURLToPath as ey}from"node:url";oi();Me();ui();import{existsSync as Xg}from"node:fs";import{fileURLToPath as eh}from"node:url";async function Xt(e,t){let r={stats:th(e.telemetryByteBudget),telemetry:Wi(t)};if(!e.storeUri.startsWith("file://"))return r;let n=eh(e.storeUri);if(!Xg(n))return r;if(!n.endsWith("red-skills.rdb")){let{RspElisionStore:c}=await Promise.resolve().then(()=>(et(),Wt)),u=await c.open({uri:e.storeUri,ttlDays:e.ttlDays,ephemeralTtlHours:e.ephemeralTtlHours,byteBudget:e.byteBudget});try{return{stats:await u.stats(),telemetry:Wi(t)}}finally{await u.close()}}let{ensureReddbBinaryFromWarmCache:s}=await Promise.resolve().then(()=>(et(),Wt));await s();let{readAccountingLaneStats:i,readTelemetryStats:o}=await Promise.resolve().then(()=>(_e(),Ar)),a=await Ut(e.storeUri);try{return{stats:await i(a,e.telemetryByteBudget),telemetry:await o(a,t)}}finally{await a.close()}}function Vi(e,t=Wi(30),r=!1){return`${j(zi(e,t,r))}
159
159
  `}function zi(e,t,r){let n=t.savings.top_commands.slice(0,r?10:3),s=r?t.savings.daily_tokens_saved:t.savings.daily_tokens_saved.slice(-7),i=e.storage_classes??Mn(),o=t.health.recent_failures.slice(0,r?20:5),a=t.decisions.top_pass_reasons.slice(0,r?10:3);return{records:e.records,bytes:e.bytes,oldest:e.oldest,budget:e.budget,storage_classes:i,savings:{window_days:t.window_days,empty:t.empty,...t.savings,tokens_saved_display:rh(t.savings),dollars_saved_estimate_usd_display:nh(t.savings),daily_tokens_saved:s,daily_tokens_saved_elided:r?0:Math.max(0,t.savings.daily_tokens_saved.length-s.length),top_commands:n,top_commands_elided:r?0:Math.max(0,t.savings.top_commands.length-n.length)},health:{...t.health,degradation_rate_display:qi(t.health.degradation_rate),show_hit_rate_display:qi(t.health.show_hit_rate),by_reason:t.health.by_reason,by_family:t.health.by_family,recent_failures:o,recent_failures_elided:r?0:Math.max(0,t.health.recent_failures.length-o.length),most_recent_degradation_at:t.health.most_recent?.timestamp??null,most_recent_degradation_reason:t.health.most_recent?.reason??null},decisions:{...t.decisions,contribution_rate_display:qi(t.decisions.contribution_rate),top_pass_reasons:a,top_pass_reasons_elided:r?0:Math.max(0,t.decisions.top_pass_reasons.length-a.length)},latency:{...t.latency,wrapper_ms_p50_display:Hi(t.latency.wrapper_ms_p50),wrapper_ms_p95_display:Hi(t.latency.wrapper_ms_p95),store_elapsed_ms_avg_display:Hi(t.latency.store_elapsed_ms_avg)}}}function gu(e){return`${j(e)}
160
160
  `}function Wi(e){return{window_days:e,empty:!0,savings:{invocations:0,elided:0,raw_bytes:0,emitted_bytes:0,bytes_saved:0,tokens_saved:0,tokens_saved_estimated:!1,token_estimate_range_pct:null,tokens_saved_low:null,tokens_saved_high:null,dollars_saved_estimate_usd:0,dollars_saved_low_usd:null,dollars_saved_high_usd:null,pricing_model_family:"gpt-5",pricing_input_usd_per_million_tokens:1.25,pricing_note:"estimate derived from byte-based token estimate when token counts are estimated",daily_tokens_saved:[],top_commands:[]},health:{degradations:0,degradation_rate:0,show_total:0,show_hits:0,show_misses:0,show_hit_rate:0,by_reason:[],by_family:[],recent_failures:[],most_recent:null},latency:{wrapper_ms_p50:null,wrapper_ms_p95:null,store_open_count_sum:0,store_elapsed_ms_sum:0,store_elapsed_ms_avg:null},decisions:{seen:0,contributed:0,passed:0,failed_open:0,quota_free_saved_units:0,contribution_rate:0,top_pass_reasons:[]}}}function th(e){return{records:0,bytes:0,oldest:null,budget:e,storage_classes:Mn()}}function Mn(){return{derivable:{records:0,bytes:0,raw_bytes:0},"re-executable":{records:0,bytes:0,raw_bytes:0},ephemeral:{records:0,bytes:0,raw_bytes:0}}}function Ki(e){let t=e.legacyStoreMigrated?"migrated":e.storeCreated?"created":"existing";return[`config: ${e.configChanged?"updated":"unchanged"}`,`store: ${t}`,""].join(`
161
161
  `)}function rh(e){return e.tokens_saved_estimated?`${e.tokens_saved_low}-${e.tokens_saved_high} (estimate_midpoint: ${e.tokens_saved}, range_pct: ${e.token_estimate_range_pct})`:String(e.tokens_saved)}function nh(e){return e.dollars_saved_low_usd==null||e.dollars_saved_high_usd==null?_r(e.dollars_saved_estimate_usd):`${_r(e.dollars_saved_low_usd)}-${_r(e.dollars_saved_high_usd)} (estimate_midpoint: ${_r(e.dollars_saved_estimate_usd)})`}function Hi(e){return e==null?"none":String(e)}function qi(e){return e.toFixed(4).replace(/0+$/,"").replace(/\.$/,".0")}async function Ou(e){let{stats:t,telemetry:r}=await Xt(e,30),[n,s]=await Promise.all([ty(e),Promise.resolve().then(()=>(ao(),oo)).then(i=>i.listWaits(process.cwd()),()=>[])]);return{stats:t,telemetry:r,recoveryHandles:n,waits:s}}function Pu(e){let t=zi(e.stats,e.telemetry,!1),r=Fs({executable:{name:"rsp",command:"rsp"},recovery:{pending:e.recoveryHandles.length,handles:e.recoveryHandles},waits:{active:e.waits.length,entries:e.waits},store:{records:e.stats.records,bytes:e.stats.bytes,oldest:e.stats.oldest,budget:e.stats.budget,storage_classes:e.stats.storage_classes??Mn()},savings:t.savings,health:t.health,decisions:t.decisions,latency:t.latency},ry(e));return`${j(r)}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reddb-io/red-skills",
3
- "version": "2.75.2",
3
+ "version": "2.76.0",
4
4
  "description": "RedSkills plugin runtime bundles (dev, code-nav, memory, brain) distributed over npm — the v2 client transport (ADR 0091). Carries the platform-independent JS bundles inside the tarball plus thin bin shims; no postinstall download.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",