@hydra-acp/budgeter 0.1.16 → 0.1.17

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.
@@ -1 +1 @@
1
- import{readdirSync as k,readFileSync as C,realpathSync as M,statSync as E}from"node:fs";import{isAbsolute as x,resolve as a}from"node:path";import{homedir as F}from"node:os";import{logger as j}from"../util/log.js";const c=j("cost/session-store"),f=new Map;function $(n){if(f.has(n))return f.get(n);try{const s=M(n);return f.set(n,s),s}catch{f.set(n,void 0);return}}function N(){const n=process.env.HYDRA_ACP_HOME??a(F(),".hydra-acp");return a(n,"sessions")}function J(n){const s=a(n,"meta.json");let r;try{r=C(s,"utf8")}catch(m){const p=m;if(p.code==="ENOENT")return;c.debug(`skipping ${n}: read meta.json failed: ${p.message}`);return}let t;try{t=JSON.parse(r)}catch{c.debug(`skipping ${n}: meta.json is not valid JSON`);return}if(!t||typeof t!="object"||Array.isArray(t)){c.debug(`skipping ${n}: meta.json is not an object`);return}const e=t,o=typeof e.sessionId=="string"?e.sessionId:void 0;if(o===void 0){c.debug(`skipping ${n}: missing sessionId`);return}let d;const u=typeof e.cwd=="string"?e.cwd:void 0;u!==void 0&&(x(u)?d=$(u):d=u);const g=typeof e.agentId=="string"?e.agentId:"",y=typeof e.currentModel=="string"?e.currentModel:"",l=e.interactive===!0,i=e.currentUsage??void 0,S=(typeof i?.costAmount=="number"?i.costAmount:0)+(typeof i?.cumulativeCost=="number"?i.cumulativeCost:0),v=typeof i?.costCurrency=="string"?i.costCurrency:"",b=typeof i?.used=="number"?i.used:0,w=typeof e.title=="string"?e.title:"",A=typeof e.createdAt=="string"?e.createdAt:"",h=typeof e.updatedAt=="string"?e.updatedAt:"",I=typeof e.importedFromMachine=="string"&&e.importedFromMachine.length>0?e.importedFromMachine:void 0,R=typeof e.upstreamSessionId=="string"&&e.upstreamSessionId.length>0?e.upstreamSessionId:void 0;return{sessionId:o,cwd:d,agentId:g,model:y,interactive:l,costAmount:S,costCurrency:v,contextTokens:b,title:w,createdAt:A,updatedAt:h,importedFromMachine:I,upstreamSessionId:R}}async function U(n){const{streamHistoryEditEvents:s}=await import("./history-stream.js");for(const r of n){const t={};for await(const e of s(r)){const o=t[e.filetype]??{added:0,removed:0};o.added+=e.linesAdded,o.removed+=e.linesRemoved,t[e.filetype]=o}r.locByFiletype=t}return n}function _(){const n=N();let s;try{s=k(n)}catch(t){const e=t;return c.debug(`session store not found at ${n}: ${e.message}`),[]}const r=[];for(const t of s){const e=a(n,t);let o;try{o=E(e)}catch{continue}if(!o.isDirectory())continue;const d=J(e);d!==void 0&&r.push(d)}return r}export{U as enrichSessionsWithLoc,_ as scanSessions,N as sessionsDir};
1
+ import{readdirSync as I,readFileSync as M,realpathSync as E,statSync as j}from"node:fs";import{isAbsolute as x,resolve as a}from"node:path";import{homedir as F}from"node:os";import{logger as $}from"../util/log.js";const c=$("cost/session-store"),f=new Map;function N(n){if(f.has(n))return f.get(n);try{const s=E(n);return f.set(n,s),s}catch{f.set(n,void 0);return}}function J(){const n=process.env.HYDRA_ACP_HOME??a(F(),".hydra-acp");return a(n,"sessions")}function O(n){const s=a(n,"meta.json");let r;try{r=M(s,"utf8")}catch(m){const g=m;if(g.code==="ENOENT")return;c.debug(`skipping ${n}: read meta.json failed: ${g.message}`);return}let t;try{t=JSON.parse(r)}catch{c.debug(`skipping ${n}: meta.json is not valid JSON`);return}if(!t||typeof t!="object"||Array.isArray(t)){c.debug(`skipping ${n}: meta.json is not an object`);return}const e=t,o=typeof e.sessionId=="string"?e.sessionId:void 0;if(o===void 0){c.debug(`skipping ${n}: missing sessionId`);return}let d;const p=typeof e.workspace=="object"&&e.workspace!==null?e.workspace:void 0,u=(typeof p?.sourceCwd=="string"?p.sourceCwd:void 0)??(typeof e.cwd=="string"?e.cwd:void 0);u!==void 0&&(x(u)?d=N(u):d=u);const y=typeof e.agentId=="string"?e.agentId:"",l=typeof e.currentModel=="string"?e.currentModel:"",w=e.interactive===!0,i=e.currentUsage??void 0,S=(typeof i?.costAmount=="number"?i.costAmount:0)+(typeof i?.cumulativeCost=="number"?i.cumulativeCost:0),b=typeof i?.costCurrency=="string"?i.costCurrency:"",v=typeof i?.used=="number"?i.used:0,A=typeof e.title=="string"?e.title:"",k=typeof e.createdAt=="string"?e.createdAt:"",h=typeof e.updatedAt=="string"?e.updatedAt:"",C=typeof e.importedFromMachine=="string"&&e.importedFromMachine.length>0?e.importedFromMachine:void 0,R=typeof e.upstreamSessionId=="string"&&e.upstreamSessionId.length>0?e.upstreamSessionId:void 0;return{sessionId:o,cwd:d,agentId:y,model:l,interactive:w,costAmount:S,costCurrency:b,contextTokens:v,title:A,createdAt:k,updatedAt:h,importedFromMachine:C,upstreamSessionId:R}}async function L(n){const{streamHistoryEditEvents:s}=await import("./history-stream.js");for(const r of n){const t={};for await(const e of s(r)){const o=t[e.filetype]??{added:0,removed:0};o.added+=e.linesAdded,o.removed+=e.linesRemoved,t[e.filetype]=o}r.locByFiletype=t}return n}function W(){const n=J();let s;try{s=I(n)}catch(t){const e=t;return c.debug(`session store not found at ${n}: ${e.message}`),[]}const r=[];for(const t of s){const e=a(n,t);let o;try{o=j(e)}catch{continue}if(!o.isDirectory())continue;const d=O(e);d!==void 0&&r.push(d)}return r}export{L as enrichSessionsWithLoc,W as scanSessions,J as sessionsDir};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hydra-acp/budgeter",
3
- "version": "0.1.16",
3
+ "version": "0.1.17",
4
4
  "description": "Cost-budget transformer extension for hydra-acp — warns on soft limit, rejects further prompts/sessions on hard limit.",
5
5
  "license": "MIT",
6
6
  "type": "module",