context-mode 1.0.166 → 1.0.168
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/.openclaw-plugin/openclaw.plugin.json +1 -1
- package/.openclaw-plugin/package.json +1 -1
- package/README.md +6 -4
- package/build/adapters/codex/usage.d.ts +107 -0
- package/build/adapters/codex/usage.js +227 -0
- package/build/adapters/gemini-cli/hooks.d.ts +7 -1
- package/build/adapters/gemini-cli/hooks.js +9 -1
- package/build/adapters/gemini-cli/index.js +11 -0
- package/build/adapters/kimi/paths.d.ts +20 -0
- package/build/adapters/kimi/paths.js +41 -1
- package/build/adapters/kimi/usage.d.ts +82 -0
- package/build/adapters/kimi/usage.js +217 -0
- package/build/adapters/omp/plugin.d.ts +6 -0
- package/build/adapters/omp/plugin.js +87 -2
- package/build/adapters/omp/usage.d.ts +49 -0
- package/build/adapters/omp/usage.js +110 -0
- package/build/adapters/openclaw/plugin.d.ts +10 -0
- package/build/adapters/openclaw/plugin.js +57 -0
- package/build/adapters/openclaw/usage.d.ts +34 -0
- package/build/adapters/openclaw/usage.js +52 -0
- package/build/adapters/opencode/plugin.d.ts +17 -0
- package/build/adapters/opencode/plugin.js +40 -1
- package/build/adapters/pi/extension.js +34 -1
- package/build/adapters/qwen-code/index.js +23 -1
- package/build/adapters/qwen-code/usage.d.ts +90 -0
- package/build/adapters/qwen-code/usage.js +222 -0
- package/build/session/analytics.js +30 -0
- package/build/session/db.d.ts +11 -0
- package/build/session/db.js +33 -0
- package/build/session/extract.d.ts +224 -0
- package/build/session/extract.js +705 -62
- package/build/session/model-prices.json +429 -0
- package/build/session/pricing.d.ts +64 -0
- package/build/session/pricing.js +151 -0
- package/cli.bundle.mjs +177 -170
- package/configs/antigravity-cli/plugin.json +1 -1
- package/configs/copilot-cli/.github/plugin/plugin.json +1 -1
- package/configs/gemini-cli/settings.json +11 -0
- package/hooks/codex/stop.mjs +91 -4
- package/hooks/gemini-cli/aftermodel.mjs +70 -0
- package/hooks/kimi/stop.mjs +74 -3
- package/hooks/qwen-code/platform.mjs +1 -0
- package/hooks/qwen-code/stop.mjs +168 -0
- package/hooks/session-db.bundle.mjs +7 -7
- package/hooks/session-extract.bundle.mjs +3 -2
- package/hooks/session-loaders.mjs +16 -1
- package/hooks/stop.mjs +35 -2
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
- package/server.bundle.mjs +108 -101
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
function i(t){return t==null?"":String(t)}function v(t){return t==null?"":typeof t=="string"?t:JSON.stringify(t)}function _(t){let e=String(t.tool_response??""),n=String(t.tool_input?.command??"");if(e.startsWith("context-mode:")||n.startsWith('echo "context-mode:')||n.startsWith("echo 'context-mode:"))return!1;let r=t.tool_output?.isError===!0||t.tool_output?.is_error===!0;return t.tool_name==="Bash"&&/exit code [1-9]|error:|Error:|FAIL|failed/i.test(e)||r}function R(t){if(!t)return[];let e=[];for(let r of t.split(/\r?\n/)){if(r.startsWith("*** Add File: ")){e.push({path:r.slice(14).trim(),type:"file_write"});continue}if(r.startsWith("*** Update File: ")){e.push({path:r.slice(17).trim(),type:"file_edit"});continue}if(r.startsWith("*** Delete File: ")){e.push({path:r.slice(17).trim(),type:"file_edit"});continue}r.startsWith("*** Move to: ")&&e.push({path:r.slice(13).trim(),type:"file_edit"})}let n=new Set;return e.filter(r=>{if(!r.path)return!1;let o=`${r.type}:${r.path}`;return n.has(o)?!1:(n.add(o),!0)})}function S(t){return/(?:^|[/\\])\.claude[/\\]plans[/\\]/.test(t)}function I(t){let{tool_name:e,tool_input:n,tool_response:r}=t,o=[];if(e==="Read"){let s=String(n.file_path??"");return(/(?:CLAUDE|AGENTS(?:\.override)?|GEMINI|QWEN|KIRO)\.md$/i.test(s)||/\/copilot-instructions\.md$/i.test(s)||/\/context-mode\.mdc$/i.test(s)||/\.claude[\\/]/i.test(s)||/[\\/]memor(?:y|ies)[\\/][^\\/]+\.md$/i.test(s))&&(o.push({type:"rule",category:"rule",data:i(s),priority:1}),r&&r.length>0&&o.push({type:"rule_content",category:"rule",data:i(r),priority:1})),o.push({type:"file_read",category:"file",data:i(s),priority:1}),o}if(e==="Edit"){let s=String(n.file_path??"");return o.push({type:"file_edit",category:"file",data:i(s),priority:1}),o}if(e==="NotebookEdit"){let s=String(n.notebook_path??"");return o.push({type:"file_edit",category:"file",data:i(s),priority:1}),o}if(e==="Write"){let s=String(n.file_path??"");return o.push({type:"file_write",category:"file",data:i(s),priority:1}),o}if(e==="apply_patch"){if(_(t))return[];let s=R(String(n.command??n.patch??""));for(let a of s)o.push({type:a.type,category:"file",data:i(a.path),priority:1});return o}if(e==="Glob"){let s=String(n.pattern??"");return o.push({type:"file_glob",category:"file",data:i(s),priority:3}),o}if(e==="Grep"){let s=String(n.pattern??""),a=String(n.path??"");return o.push({type:"file_search",category:"file",data:i(`${s} in ${a}`),priority:3}),o}return o}function $(t){if(t.tool_name!=="Bash")return[];let n=String(t.tool_input.command??"").match(/\bcd\s+("([^"]+)"|'([^']+)'|(\S+))/);if(!n)return[];let r=n[2]??n[3]??n[4]??"";return[{type:"cwd",category:"cwd",data:i(r),priority:2}]}function O(t){let{tool_response:e}=t,n=String(e??"");return _(t)?[{type:"error_tool",category:"error",data:i(n),priority:2}]:[]}var E=[{pattern:/\bgit\s+checkout\b/,operation:"branch"},{pattern:/\bgit\s+commit\b/,operation:"commit"},{pattern:/\bgit\s+merge\s+\S+/,operation:"merge"},{pattern:/\bgit\s+rebase\b/,operation:"rebase"},{pattern:/\bgit\s+stash\b/,operation:"stash"},{pattern:/\bgit\s+push\b/,operation:"push"},{pattern:/\bgit\s+pull\b/,operation:"pull"},{pattern:/\bgit\s+log\b/,operation:"log"},{pattern:/\bgit\s+diff\b/,operation:"diff"},{pattern:/\bgit\s+status\b/,operation:"status"},{pattern:/\bgit\s+branch\b/,operation:"branch"},{pattern:/\bgit\s+reset\b/,operation:"reset"},{pattern:/\bgit\s+add\b/,operation:"add"},{pattern:/\bgit\s+cherry-pick\b/,operation:"cherry-pick"},{pattern:/\bgit\s+tag\b/,operation:"tag"},{pattern:/\bgit\s+fetch\b/,operation:"fetch"},{pattern:/\bgit\s+clone\b/,operation:"clone"},{pattern:/\bgit\s+worktree\b/,operation:"worktree"}];function C(t){if(t.tool_name!=="Bash")return[];let e=String(t.tool_input.command??""),n=P(e),r;if(n&&n.operation&&(r=E.find(s=>s.operation===n.operation)),r||(r=E.find(s=>s.pattern.test(e))),!r)return[];let o=[];if(n?.scopedDir&&o.push({type:"cwd",category:"cwd",data:i(n.scopedDir),priority:2}),r.operation==="commit"){let s=N(e);if(s)return o.push({type:"git_commit",category:"git",data:i(s),priority:2}),o}return o.push({type:"git",category:"git",data:i(r.operation),priority:2}),o}function L(t){return typeof t!="string"||t.length===0?t:t==="~"?w():t.startsWith("~/")?w()+t.slice(1):t}function w(){try{return process.env.HOME||process.env.USERPROFILE||(process.env.HOMEDRIVE&&process.env.HOMEPATH?process.env.HOMEDRIVE+process.env.HOMEPATH:"")||"~"}catch{return"~"}}function P(t){let e=x(t),n=0;for(;n<e.length&&H(e[n]);)n++;for(;n<e.length&&e[n]!=="git"&&!e[n].endsWith("/git")&&M(e[n]);)n++;if(n>=e.length||e[n]!=="git"&&!e[n].endsWith("/git"))return null;n++;let r=null,o=null;for(;n<e.length;){let s=e[n];if(s==="-C"||s==="--directory"){r=e[n+1]??null,n+=2;continue}if(s.startsWith("--directory=")){r=s.slice(12),n++;continue}if(s.length>0&&s[0]==="-"){n++;continue}o=s;break}return r&&(r=L(r)),{scopedDir:r,operation:o}}function H(t){if(t.length===0)return!1;let e=!1;for(let n=0;n<t.length;n++){let r=t.charCodeAt(n);if(n===0){if(!(r>=65&&r<=90||r===95))return!1}else if(r===61){e=!0;break}else if(!(r>=65&&r<=90||r>=48&&r<=57||r===95))return!1}return e}function M(t){switch(t){case"sudo":case"doas":case"env":case"exec":case"time":return!0;default:return!1}}function x(t){let e=[],n=t.length,r=0;for(;r<n;){for(;r<n&&(t[r]===" "||t[r]===" ");)r++;if(r>=n)break;let o="";for(;r<n&&t[r]!==" "&&t[r]!==" ";){let s=t[r];if(s==='"'||s==="'"){let a=s;for(r++;r<n&&t[r]!==a;)t[r]==="\\"&&r+1<n?(o+=t[r+1],r+=2):(o+=t[r],r++);r<n&&r++}else s==="\\"&&r+1<n?(o+=t[r+1],r+=2):(o+=s,r++)}e.push(o)}return e}function N(t){let e=x(t),n="--message=";for(let r=0;r<e.length;r++){let o=e[r];if(o.length>n.length&&o.startsWith(n)){let s=o.slice(n.length);return s.length>0?s:null}if(o==="--message"){let s=e[r+1];return s&&s.length>0?s:null}if(o.length>=2&&o[0]==="-"&&o[1]!=="-"&&o[o.length-1]==="m"&&j(o,1)){let s=e[r+1];return s&&s.length>0?s:null}}return null}function j(t,e){if(e>=t.length)return!1;for(let n=e;n<t.length;n++){let r=t.charCodeAt(n);if(r<97||r>122)return!1}return!0}function W(t){return new Set(["TodoWrite","TaskCreate","TaskUpdate"]).has(t.tool_name)?[{type:t.tool_name==="TaskUpdate"?"task_update":t.tool_name==="TaskCreate"?"task_create":"task",category:"task",data:i(JSON.stringify(t.tool_input)),priority:1}]:[]}function D(t){let e=2166136261;for(let n=0;n<t.length;n++)e^=t.charCodeAt(n),e=Math.imul(e,16777619);return(e>>>0).toString(16).padStart(8,"0")}function F(t){let e=t.tool_input.plan;if(typeof e=="string"&&e.length>0)return e;let n=t.tool_response;if(typeof n=="string"&&n.length>0)try{let r=JSON.parse(n);if(r&&typeof r=="object"&&typeof r.plan=="string")return r.plan}catch{}return null}function B(t){if(t.tool_name==="EnterPlanMode")return[{type:"plan_enter",category:"plan",data:"entered plan mode",priority:2}];if(t.tool_name==="ExitPlanMode"){let e=[],n=t.tool_input.allowedPrompts,r=Array.isArray(n)&&n.length>0?`exited plan mode (allowed: ${v(n.map(a=>typeof a=="object"&&a!==null&&"prompt"in a?String(a.prompt):String(a)).join(", "))})`:"exited plan mode",o=F(t);typeof o=="string"&&o.length>0&&(r+=` plan_bytes:${o.length} plan_hash:${D(o)}`),e.push({type:"plan_exit",category:"plan",data:i(r),priority:2});let s=String(t.tool_response??"").toLowerCase();return s.includes("approved")||s.includes("approve")?e.push({type:"plan_approved",category:"plan",data:"plan approved by user",priority:1}):(s.includes("rejected")||s.includes("decline")||s.includes("denied"))&&e.push({type:"plan_rejected",category:"plan",data:i(`plan rejected: ${t.tool_response??""}`),priority:2}),e}if(t.tool_name==="Write"||t.tool_name==="Edit"){let e=String(t.tool_input.file_path??"");if(S(e))return[{type:"plan_file_write",category:"plan",data:i(`plan file: ${e.split(/[/\\]/).pop()??e}`),priority:2}]}return t.tool_name==="apply_patch"?_(t)?[]:R(String(t.tool_input.command??t.tool_input.patch??"")).filter(n=>S(n.path)).map(n=>({type:"plan_file_write",category:"plan",data:i(`plan file: ${n.path.split(/[/\\]/).pop()??n.path}`),priority:2})):[]}var U=[/\bsource\s+\S*activate\b/,/\bexport\s+\w+=/,/\bnvm\s+use\b/,/\bpyenv\s+(shell|local|global)\b/,/\bconda\s+activate\b/,/\brbenv\s+(shell|local|global)\b/,/\bnpm\s+install\b/,/\bnpm\s+ci\b/,/\bpip\s+install\b/,/\bbun\s+install\b/,/\byarn\s+(add|install)\b/,/\bpnpm\s+(add|install)\b/,/\bcargo\s+(install|add)\b/,/\bgo\s+(install|get)\b/,/\brustup\b/,/\basdf\b/,/\bvolta\b/,/\bdeno\s+install\b/];function K(t){if(t.tool_name!=="Bash")return[];let e=String(t.tool_input.command??"");if(!U.some(o=>o.test(e)))return[];let r=e.replace(/\bexport\s+(\w+)=\S*/g,"export $1=***");return[{type:"env",category:"env",data:i(r),priority:2}]}function G(t){if(t.tool_name!=="Skill")return[];let e=String(t.tool_input.skill??"");return[{type:"skill",category:"skill",data:i(e),priority:2}]}function J(t){if(!t.tool_response?.includes("Error")&&!t.tool_output?.isError)return[];let e=String(t.tool_response||""),n=[/not supported/i,/cannot/i,/does not support/i,/FAIL/i,/refused/i,/permission denied/i,/incompatible/i];for(let r of n){let o=e.match(r);if(o){let s=e.toLowerCase().indexOf(o[0].toLowerCase()),a=e.slice(Math.max(0,s-50),Math.min(e.length,s+200)).trim();return[{type:"constraint_discovered",category:"constraint",data:i(a),priority:2}]}}return[]}function q(t){if(t.tool_name!=="Agent")return[];let e=i(String(t.tool_input.prompt??t.tool_input.description??"")),n=t.tool_response?i(String(t.tool_response)):"",r=n.length>0;return[{type:r?"subagent_completed":"subagent_launched",category:"subagent",data:i(r?`[completed] ${e} \u2192 ${n}`:`[launched] ${e}`),priority:r?2:3}]}function z(t){let{tool_name:e,tool_input:n,tool_response:r}=t;if(!e.startsWith("mcp__"))return[];let o=e.split("__"),s=o[o.length-1]||e,a=Object.values(n).find(p=>typeof p=="string"),l=a?`: ${i(String(a))}`:"",c=r&&r.length>0?`
|
|
2
|
-
response: ${i(r)}`:"";return[{type:"mcp",category:"mcp",data:i(`${s}${l}${c}`),priority:3}]}var V=2048;function X(t,e){if(Buffer.byteLength(t,"utf8")<=e)return{value:t,truncated:!1};let n=Buffer.from(t,"utf8"),r=e;for(;r>0&&(n[r]&192)===128;)r--;return{value:n.subarray(0,r).toString("utf8"),truncated:!0}}var Q=/(authorization|auth_token|access_token|refresh_token|bearer|token|secret|password|passwd|pwd|api[-_]?key|apikey|cookie|set-cookie|signature|private[-_]?key|client[-_]?secret|x[-_]?api[-_]?key)/i,Y="[REDACTED]";function b(t,e=new WeakSet){if(t==null||typeof t!="object")return t;if(e.has(t))return"[CIRCULAR]";e.add(t);let n;if(Array.isArray(t))n=t.map(r=>b(r,e));else{let r={};for(let[o,s]of Object.entries(t))Q.test(o)?r[o]=Y:r[o]=b(s,e);n=r}return e.delete(t),n}function Z(t){let{tool_name:e,tool_input:n}=t;if(!e.startsWith("mcp__"))return[];let r=b(n??{}),o;try{o=JSON.stringify(r)}catch{o="{}"}let{value:s,truncated:a}=X(o,V),l=a?`{"tool_name":${JSON.stringify(e)},"params_raw":${JSON.stringify(s)},"truncated":true}`:`{"tool_name":${JSON.stringify(e)},"params":${s}}`;return[{type:"mcp_tool_call",category:"mcp_tool_call",data:i(l),priority:4}]}function tt(t){if(t.tool_name!=="AskUserQuestion")return[];let e=t.tool_input.questions,n=Array.isArray(e)&&e.length>0?String(e[0].question??""):"",r=String(t.tool_response??""),o="";try{let c=JSON.parse(r)?.answers;if(c&&typeof c=="object"){let p=h=>typeof h=="string"?h:Array.isArray(h)?h.filter(g=>typeof g=="string").join(" | "):"",u=n?p(c[n]):"";u?o=u:o=Object.values(c).map(p).filter(g=>g.length>0).join(" | ")}}catch{}let s=i(o),a=n?`Q: ${i(n)} \u2192 A: ${s}`:`answer: ${s}`;return[{type:"decision_question",category:"decision",data:i(a),priority:2}]}function et(t){if(t.tool_name!=="Agent")return[];if(!t.tool_response||t.tool_response.length===0)return[];let e=t.tool_response.length>500?t.tool_response.slice(0,500):t.tool_response;return[{type:"agent_finding",category:"agent-finding",data:i(e),priority:2}]}function nt(t){let e=[v(t.tool_input),i(t.tool_response)].join(" ");if(e.length===0)return[];let n=new Set,r=e.match(/https?:\/\/[^\s)]+/g);if(r)for(let c of r)c=c.replace(/["'})\],;.]+$/,""),/localhost|127\.0\.0\.1/i.test(c)||n.add(c);let o=e.match(/(?<!\w)#(\d+)/g);if(o)for(let c of o)n.add(c);if(n.size===0)return[];let s,a=i(t.tool_response).match(/Fetched and indexed[^\(]*\(([\d.]+)\s*KB\)/i);if(a){let c=Number(a[1]);Number.isFinite(c)&&c>0&&(s=Math.round(c*1024))}let l={type:"external_ref",category:"external-ref",data:i(Array.from(n).join(", ")),priority:3};return s!==void 0&&(l.bytes_avoided=s),[l]}function rt(t){if(t.tool_name==="EnterWorktree"){let e=String(t.tool_input.name??"unnamed");return[{type:"worktree",category:"env",data:i(`entered worktree: ${e}`),priority:2}]}if(t.tool_name==="ExitWorktree"){let e=!!t.tool_input.discard_changes;return[{type:"worktree_exit",category:"env",data:i(`exited worktree (discard_changes:${e})`),priority:2}]}return[]}function ot(t){if(typeof t!="string"||t.length===0)return null;let e=t.indexOf("://");if(e<0)return null;let n=e+3;if(n>=t.length)return null;let r=t.length;for(let s=n;s<t.length;s++){let a=t.charCodeAt(s);if(a===47||a===63||a===35){r=s;break}}let o=t.slice(n,r);return o.length>0?o:null}function st(t){if(t.tool_name!=="WebFetch")return[];let e=t.tool_response;if(typeof e!="string"||e.length===0)return[];let n;try{n=JSON.parse(e)}catch{return[]}if(!n||typeof n!="object")return[];let r=n,o=[];if(typeof r.code=="number"&&o.push(`code:${r.code}`),typeof r.bytes=="number"&&o.push(`bytes:${r.bytes}`),typeof r.durationMs=="number"&&o.push(`durMs:${r.durationMs}`),typeof r.url=="string"){let s=ot(r.url);s&&o.push(`host:${s}`)}return o.length===0?[]:[{type:"webfetch_metadata",category:"data",data:i(o.join(" ")),priority:3}]}function it(t){if(t.tool_name!=="Bash")return[];let e=t.tool_response;if(typeof e!="string"||e.length===0)return[];let n;try{n=JSON.parse(e)}catch{return[]}if(!n||typeof n!="object")return[];let r=n;if(!(typeof r.interrupted=="boolean"||typeof r.stderr=="string"||typeof r.returnCodeInterpretation=="string"))return[];let s=[];return typeof r.interrupted=="boolean"&&s.push(`interrupted:${r.interrupted}`),typeof r.returnCodeInterpretation=="string"&&s.push(`rcInterp:${r.returnCodeInterpretation.slice(0,80)}`),typeof r.stderr=="string"&&s.push(`stderrBytes:${r.stderr.length}`),[{type:"bash_outcome",category:"data",data:i(s.join(" ")),priority:3}]}function at(t){if(t.tool_name!=="Read")return[];let e=t.tool_response;if(typeof e!="string"||e.length===0)return[];let n;try{n=JSON.parse(e)}catch{return[]}if(!n||typeof n!="object")return[];let r=n,o=r.type;if(o!=="text"&&o!=="image")return[];let s=[`type:${o}`];if(o==="text")typeof r.numLines=="number"&&s.push(`lines:${r.numLines}`),typeof r.totalLines=="number"&&s.push(`totalLines:${r.totalLines}`),typeof r.startLine=="number"&&s.push(`start:${r.startLine}`);else{typeof r.originalSize=="number"&&s.push(`origSize:${r.originalSize}`);let a=r.dimensions;if(a&&typeof a=="object"){let l=a;typeof l.width=="number"&&typeof l.height=="number"&&s.push(`dims:${l.width}x${l.height}`)}}return[{type:"file_read_metadata",category:"data",data:i(s.join(" ")),priority:3}]}var y={"claude-opus-4-8":{input:5,output:25,cache_write:6.25,cache_read:.5},"claude-opus-4-7":{input:5,output:25,cache_write:6.25,cache_read:.5},"claude-sonnet-4-6":{input:3,output:15,cache_write:3.75,cache_read:.3},"claude-haiku-4-5":{input:1,output:5,cache_write:1.25,cache_read:.1},default:{input:3,output:15,cache_write:3.75,cache_read:.3}};function ct(t,e){let n=[t.tool_input?.model,t.model,e.model],r=Object.keys(y).filter(o=>o!=="default");for(let o of n)if(!(typeof o!="string"||o.length===0)){if(o in y)return o;for(let s of r)if(o.startsWith(s))return s}return"default"}function lt(t,e,n,r,o){let s=y[t]??y.default;return(e*s.input+n*s.output+r*s.cache_write+o*s.cache_read)/1e6}function pt(t){if(t.tool_name!=="Task")return[];let e=t.tool_response;if(typeof e!="string"||e.length===0)return[];let n;try{n=JSON.parse(e)}catch{return[]}if(!n||typeof n!="object")return[];let r=n,o=r.usage&&typeof r.usage=="object"?r.usage:{};if(!(typeof r.totalTokens=="number"||typeof r.totalDurationMs=="number"||typeof o.input_tokens=="number"||typeof o.output_tokens=="number"||typeof o.service_tier=="string"))return[];let a=[];typeof r.totalTokens=="number"&&a.push(`totalTokens:${r.totalTokens}`),typeof r.totalDurationMs=="number"&&a.push(`totalDurMs:${r.totalDurationMs}`),typeof o.input_tokens=="number"&&a.push(`tokens_in:${o.input_tokens}`),typeof o.output_tokens=="number"&&a.push(`tokens_out:${o.output_tokens}`),typeof o.cache_creation_input_tokens=="number"&&a.push(`cache_create:${o.cache_creation_input_tokens}`),typeof o.cache_read_input_tokens=="number"&&a.push(`cache_read:${o.cache_read_input_tokens}`),typeof o.service_tier=="string"&&a.push(`tier:${o.service_tier.slice(0,32)}`);let l=typeof o.input_tokens=="number"?o.input_tokens:0,c=typeof o.output_tokens=="number"?o.output_tokens:0,p=typeof o.cache_creation_input_tokens=="number"?o.cache_creation_input_tokens:0,u=typeof o.cache_read_input_tokens=="number"?o.cache_read_input_tokens:0;if(l>0||c>0||p>0||u>0){let g=ct(t,r),A=lt(g,l,c,p,u);a.push(`cost_usd:${A.toFixed(6).replace(/0+$/,"").replace(/\.$/,".0")}`)}return[{type:"agent_usage",category:"cost",data:i(a.join(" ")),priority:2}]}var T=/[,;,;、،]/u,ut=15,ft=500;function dt(t){if(m.test(t)||!k.test(t)||!T.test(t))return!1;let e=[...t].length;return e>=ut&&e<=ft}function ht(t){let e=t.trim();return dt(e)?[{type:"decision",category:"decision",data:i(t),priority:2}]:[]}var gt=8,_t=120,yt=new RegExp("\\p{L}+\\s+\\p{L}+","u"),mt=new RegExp("\\p{L}{6,}","u"),bt=new Set(["ok","okay","sure","yeah","yep","yup","alright","fine","well","so","hmm","right","please"]),kt=["you are","you're","your role","you will be","you act","you will act","act as","act like","behave as","behave like","imagine you","pretend you","assume the role","take the role","play the role","respond as","tu es","tu est","vous etes","vous \xEAtes","sen ","siz ","eres ","t\xFA eres","usted es","\u0442\u044B ","\u0432\u044B ","\u3042\u306A\u305F\u306F","\u541B\u306F","\u304A\u524D\u306F","\u3042\u306A\u305F\u304C","\u4F60\u662F","\u60A8\u662F","\u0924\u0941\u092E ","\u0906\u092A ","\u0924\u0942 ","\u0623\u0646\u062A ","\u0627\u0646\u062A ","\u0623\u0646\u062A\u064E "],St=["always ","never ","respond ","reply ","answer ","speak ","write ","prefer ","format ","output ","communicate ","use only "];function Et(t){let e=t.toLowerCase().trim();if(!e)return!1;let n=e.split(" ").filter(o=>o.length>0);for(;n.length>0&&bt.has(n[0]);)n.shift();let r=n.join(" ");if(!r)return!1;for(let o of kt)if(r.startsWith(o))return!0;for(let o of St)if(r.startsWith(o))return!0;return!1}function wt(t){let e=t.split(/[.!\n。!]/u)[0].trim();if(m.test(e)||T.test(e)||!k.test(e))return!1;let n=[...e].length;return n<gt||n>_t||!Et(e)?!1:yt.test(e)||mt.test(e)}function vt(t){let e=t.trim();return wt(e)?[{type:"role",category:"role",data:i(t),priority:3}]:[]}var m=/[??؟¿]/u,k=new RegExp("\\p{L}","u"),Rt=60;function xt(t){if(m.test(t)||!k.test(t))return!1;let e=[...t].length;return e>0&&e<Rt}function Tt(t){let e=t.trim();if(!e)return[];let n;return m.test(e)?n="investigate":xt(e)&&(n="implement"),n?[{type:"intent",category:"intent",data:i(n),priority:4}]:[]}var At=/^(?:\/goal\s+|(?:goal|objective)\s*:\s*)(.+)$/is;function It(t){let e=t.trim();if(!e)return[];let n=e.match(At);if(!n)return[];let r=n[1].trim();return r?[{type:"goal",category:"goal",data:i(r),priority:4}]:[]}var $t=/(?:\bError\s*:|\bException\s*:|\bTraceback\b|\bat\s+\S+\s*\([^)]*:\d+:\d+\))/u,Ot=/[✓✔✅☑🎉]/u,Ct=/^\s*(?:fixed|resolved)\s*:/iu;function Lt(t){let e=[];return Ot.test(t)||Ct.test(t)?(e.push({type:"blocker_resolved",category:"blocked-on",data:i(t),priority:2}),e):($t.test(t)&&e.push({type:"blocker",category:"blocked-on",data:i(t),priority:2}),e)}function Pt(t){return t.length<=1024?[]:[{type:"data",category:"data",data:i(t),priority:4}]}var f=null;function Ht(t){let{tool_name:e,tool_response:n}=t,r=String(n??"");if(_(t))return f={tool:e,error:r.slice(0,200),callsSince:0},[];if(!f)return[];if(f.callsSince++,f.callsSince>10)return f=null,[];if(!!_(t))return[];let s=e===f.tool,a=f.tool==="Read"&&(e==="Edit"||e==="Write"||e==="apply_patch");if(s||a){let l={type:"error_resolved",category:"error-resolution",data:i(`Error in ${f.tool}: ${f.error} \u2192 Fixed`),priority:2};return f=null,[l]}return[]}function Ut(){f=null}var d=[];function Mt(t){return`${t.length}:${t.slice(0,20)}`}function Nt(t){let{tool_name:e,tool_input:n}=t,r=Mt(JSON.stringify(n).slice(0,200));if(d.push({tool:e,inputHash:r}),d.length>50&&d.splice(0,d.length-50),d.length<3)return[];let o=0;for(let s=d.length-1;s>=0&&(d[s].tool===e&&d[s].inputHash===r);s--)o++;return o>=3?(d.splice(d.length-o),[{type:"retry_detected",category:"iteration-loop",data:i(`${e} called ${o} times with similar input`),priority:2}]):[]}function Kt(){d.length=0}var jt={run_shell_command:"Bash",read_file:"Read",read_many_files:"Read",grep_search:"Grep",search_file_content:"Grep",web_fetch:"WebFetch",write_file:"Write",edit:"Edit",glob:"Glob",todo_write:"TodoWrite",ask_user_question:"AskUserQuestion",list_directory:"LS",save_memory:"Memory",skill:"Skill",exit_plan_mode:"ExitPlanMode",agent:"Agent",bash:"Bash",view:"Read",grep:"Grep",fetch:"WebFetch",shell:"Bash",shell_command:"Bash",exec_command:"Bash","container.exec":"Bash",local_shell:"Bash",grep_files:"Grep",run_command:"Bash",view_file:"Read",read_url_content:"WebFetch",list_dir:"LS",search_web:"WebSearch"};function Wt(t){let e=jt[t.tool_name];return!e||e===t.tool_name?t:{...t,tool_name:e}}function Gt(t){try{let e=Wt(t),n=[];return n.push(...I(e)),n.push(...$(e)),n.push(...O(e)),n.push(...C(e)),n.push(...K(e)),n.push(...W(e)),n.push(...B(e)),n.push(...G(e)),n.push(...q(e)),n.push(...z(e)),n.push(...Z(e)),n.push(...tt(e)),n.push(...J(e)),n.push(...rt(e)),n.push(...st(e)),n.push(...it(e)),n.push(...at(e)),n.push(...pt(e)),n.push(...et(e)),n.push(...nt(e)),n.push(...Ht(e)),n.push(...Nt(e)),n}catch{return[]}}function Jt(t){try{let e=[];return e.push(...Bt(t)),e.push(...ht(t)),e.push(...vt(t)),e.push(...Tt(t)),e.push(...It(t)),e.push(...Lt(t)),e.push(...Pt(t)),e}catch{return[]}}function qt(t){if(!t||typeof t!="object")return[];let e=t,n=[],r=e.mcp_servers,o=null;return r&&typeof r=="object"&&!Array.isArray(r)&&(o=Object.keys(r),n.push(`mcp_count:${o.length}`),o.length>0&&n.push(`mcp_servers:${o.slice(0,8).join(",")}`)),typeof e.model=="string"&&n.push(`model:${e.model.slice(0,64)}`),typeof e.permission_mode=="string"&&n.push(`permission_mode:${e.permission_mode.slice(0,32)}`),n.length===0?[]:[{type:"session_settings_snapshot",category:"env",data:i(n.join(" ")),priority:2}]}var Dt=["Latin","Cyrillic","Arabic","Han","Hangul","Hiragana","Katakana","Devanagari","Hebrew","Thai","Greek"],Ft={prompt_length:0,prompt_word_count:0,prompt_uppercase_ratio:0,prompt_file_ref_count:0,prompt_path_ref_count:0,prompt_script_primary:null,prompt_script_count:0,prompt_question_glyph_count:0,prompt_code_block_count:0,prompt_url_count:0,prompt_word_tokens:[]};function zt(t){if(typeof t!="string"||t.length===0)return{...Ft,prompt_word_tokens:[]};let e=t.match(new RegExp("\\p{L}+","gu"))??[],n=(t.match(new RegExp("\\p{Lu}","gu"))??[]).length,r=e.join("").length,o=(t.match(/```/g)??[]).length,s={};for(let p of Dt){let u=new RegExp(`\\p{Script=${p}}`,"gu"),h=(t.match(u)??[]).length;h>0&&(s[p]=h)}let a=Object.entries(s).sort((p,u)=>u[1]-p[1])[0]?.[0]??null,l=new Set,c=[];for(let p of e){if(p.length<3)continue;let u=p.toLowerCase();l.has(u)||(l.add(u),c.push(u))}return{prompt_length:t.length,prompt_word_count:e.length,prompt_uppercase_ratio:r===0?0:n/r,prompt_file_ref_count:(t.match(/(\w+\/)+\w+\.\w+/g)??[]).length,prompt_path_ref_count:(t.match(/\.{0,2}\/[\w\/.-]+/g)??[]).length,prompt_script_primary:a,prompt_script_count:Object.keys(s).length,prompt_question_glyph_count:(t.match(/[??؟]/gu)??[]).length,prompt_code_block_count:Math.floor(o/2),prompt_url_count:(t.match(/https?:\/\/[^\s]+/gu)??[]).length,prompt_word_tokens:c}}function Bt(t){if(typeof t!="string"||t.length===0)return[];let e=0;for(;e<t.length;){let o=t.charCodeAt(e);if(o!==32&&o!==9)break;e++}if(e+5>t.length)return[];if(t.slice(e,e+5)!=="/plan")return[];if(e+5<t.length){let o=t.charCodeAt(e+5);if(!(o===32||o===9||o===10||o===13))return[]}let n=t.slice(e+5).trim(),r=n.length>0?`plan via /plan slash: ${n.slice(0,120)}`:"plan via /plan slash";return[{type:"plan_enter",category:"plan",data:i(r),priority:2}]}export{Gt as extractEvents,qt as extractSessionSettings,Jt as extractUserEvents,zt as extractUserPromptFeatures,Ut as resetErrorResolutionState,Kt as resetIterationLoopState};
|
|
1
|
+
var O={"claude-opus-4-8":{input_per_mtok:5,output_per_mtok:25,cache_read_per_mtok:.5,cache_write_per_mtok:6.25,source:"https://platform.claude.com/docs/en/about-claude/pricing"},"claude-opus-4-7":{input_per_mtok:5,output_per_mtok:25,cache_read_per_mtok:.5,cache_write_per_mtok:6.25,source:"https://platform.claude.com/docs/en/about-claude/pricing"},"claude-opus-4-6":{input_per_mtok:5,output_per_mtok:25,cache_read_per_mtok:.5,cache_write_per_mtok:6.25,source:"https://platform.claude.com/docs/en/about-claude/pricing"},"claude-opus-4-5":{input_per_mtok:5,output_per_mtok:25,cache_read_per_mtok:.5,cache_write_per_mtok:6.25,source:"https://platform.claude.com/docs/en/about-claude/pricing"},"claude-sonnet-4-6":{input_per_mtok:3,output_per_mtok:15,cache_read_per_mtok:.3,cache_write_per_mtok:3.75,source:"https://platform.claude.com/docs/en/about-claude/pricing"},"claude-sonnet-4-5":{input_per_mtok:3,output_per_mtok:15,cache_read_per_mtok:.3,cache_write_per_mtok:3.75,source:"https://platform.claude.com/docs/en/about-claude/pricing"},"claude-haiku-4-5":{input_per_mtok:1,output_per_mtok:5,cache_read_per_mtok:.1,cache_write_per_mtok:1.25,source:"https://platform.claude.com/docs/en/about-claude/pricing"},"claude-3-7-sonnet":{input_per_mtok:3,output_per_mtok:15,cache_read_per_mtok:.3,cache_write_per_mtok:3.75,source:"https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json"},"claude-3-5-haiku":{input_per_mtok:.8,output_per_mtok:4,cache_read_per_mtok:.08,cache_write_per_mtok:1,source:"https://platform.claude.com/docs/en/about-claude/pricing"},"claude-fable-5":{input_per_mtok:10,output_per_mtok:50,cache_read_per_mtok:1,cache_write_per_mtok:12.5,source:"https://platform.claude.com/docs/en/about-claude/pricing"},"gpt-5":{input_per_mtok:1.25,output_per_mtok:10,cache_read_per_mtok:.125,cache_write_per_mtok:null,source:"https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json"},"gpt-5-mini":{input_per_mtok:.25,output_per_mtok:2,cache_read_per_mtok:.025,cache_write_per_mtok:null,source:"https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json"},"gpt-5-nano":{input_per_mtok:.05,output_per_mtok:.4,cache_read_per_mtok:.005,cache_write_per_mtok:null,source:"https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json"},"gpt-5-codex":{input_per_mtok:1.25,output_per_mtok:10,cache_read_per_mtok:.125,cache_write_per_mtok:null,source:"https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json"},"gpt-4.1":{input_per_mtok:2,output_per_mtok:8,cache_read_per_mtok:.5,cache_write_per_mtok:null,source:"https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json"},"gpt-4.1-mini":{input_per_mtok:.4,output_per_mtok:1.6,cache_read_per_mtok:.1,cache_write_per_mtok:null,source:"https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json"},"gpt-4.1-nano":{input_per_mtok:.1,output_per_mtok:.4,cache_read_per_mtok:.025,cache_write_per_mtok:null,source:"https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json"},"gpt-4o":{input_per_mtok:2.5,output_per_mtok:10,cache_read_per_mtok:1.25,cache_write_per_mtok:null,source:"https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json"},"gpt-4o-mini":{input_per_mtok:.15,output_per_mtok:.6,cache_read_per_mtok:.075,cache_write_per_mtok:null,source:"https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json"},o3:{input_per_mtok:2,output_per_mtok:8,cache_read_per_mtok:.5,cache_write_per_mtok:null,source:"https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json"},"o4-mini":{input_per_mtok:1.1,output_per_mtok:4.4,cache_read_per_mtok:.275,cache_write_per_mtok:null,source:"https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json"},"o3-mini":{input_per_mtok:1.1,output_per_mtok:4.4,cache_read_per_mtok:.55,cache_write_per_mtok:null,source:"https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json"},"codex-mini-latest":{input_per_mtok:1.5,output_per_mtok:6,cache_read_per_mtok:.375,cache_write_per_mtok:null,source:"https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json"},"gemini-2.5-pro":{input_per_mtok:1.25,output_per_mtok:10,cache_read_per_mtok:.125,cache_write_per_mtok:null,source:"https://ai.google.dev/gemini-api/docs/pricing"},"gemini-2.5-flash":{input_per_mtok:.3,output_per_mtok:2.5,cache_read_per_mtok:.03,cache_write_per_mtok:null,source:"https://ai.google.dev/gemini-api/docs/pricing"},"gemini-2.5-flash-lite":{input_per_mtok:.1,output_per_mtok:.4,cache_read_per_mtok:.01,cache_write_per_mtok:null,source:"https://ai.google.dev/gemini-api/docs/pricing"},"gemini-2.0-flash":{input_per_mtok:.1,output_per_mtok:.4,cache_read_per_mtok:.025,cache_write_per_mtok:null,source:"https://ai.google.dev/gemini-api/docs/pricing"},"gemini-2.0-flash-lite":{input_per_mtok:.075,output_per_mtok:.3,cache_read_per_mtok:null,cache_write_per_mtok:null,source:"https://ai.google.dev/gemini-api/docs/pricing"},"gemini-3-pro-preview":{input_per_mtok:2,output_per_mtok:12,cache_read_per_mtok:.2,cache_write_per_mtok:null,source:"https://ai.google.dev/gemini-api/docs/pricing"},"gemini-3-flash-preview":{input_per_mtok:.5,output_per_mtok:3,cache_read_per_mtok:.05,cache_write_per_mtok:null,source:"https://ai.google.dev/gemini-api/docs/pricing"},"qwen3-coder":{input_per_mtok:1,output_per_mtok:5,cache_read_per_mtok:null,cache_write_per_mtok:null,source:"https://www.alibabacloud.com/help/en/model-studio/models"},"qwen-max":{input_per_mtok:1.6,output_per_mtok:6.4,cache_read_per_mtok:null,cache_write_per_mtok:null,source:"https://www.alibabacloud.com/help/en/model-studio/models"},"qwen-plus":{input_per_mtok:.4,output_per_mtok:1.2,cache_read_per_mtok:null,cache_write_per_mtok:null,source:"https://www.alibabacloud.com/help/en/model-studio/models"},"qwen-turbo":{input_per_mtok:.05,output_per_mtok:.2,cache_read_per_mtok:null,cache_write_per_mtok:null,source:"https://www.alibabacloud.com/help/en/model-studio/models"},"qwen3-max":{input_per_mtok:1.2,output_per_mtok:6,cache_read_per_mtok:null,cache_write_per_mtok:null,source:"https://www.alibabacloud.com/help/en/model-studio/models"},"kimi-k2":{input_per_mtok:.6,output_per_mtok:2.5,cache_read_per_mtok:.15,cache_write_per_mtok:null,source:"https://platform.moonshot.ai/docs/pricing/chat"},"kimi-k2-turbo":{input_per_mtok:1.15,output_per_mtok:8,cache_read_per_mtok:.15,cache_write_per_mtok:null,source:"https://platform.moonshot.ai/docs/pricing/chat"},"moonshot-v1-8k":{input_per_mtok:.2,output_per_mtok:2,cache_read_per_mtok:null,cache_write_per_mtok:null,source:"https://platform.moonshot.ai/docs/pricing"},"moonshot-v1-32k":{input_per_mtok:1,output_per_mtok:3,cache_read_per_mtok:null,cache_write_per_mtok:null,source:"https://platform.moonshot.ai/docs/pricing"},"moonshot-v1-128k":{input_per_mtok:2,output_per_mtok:5,cache_read_per_mtok:null,cache_write_per_mtok:null,source:"https://platform.moonshot.ai/docs/pricing"},"deepseek-v3":{input_per_mtok:.27,output_per_mtok:1.1,cache_read_per_mtok:.07,cache_write_per_mtok:0,source:"https://api-docs.deepseek.com/quick_start/pricing"},"deepseek-r1":{input_per_mtok:.55,output_per_mtok:2.19,cache_read_per_mtok:null,cache_write_per_mtok:null,source:"https://api-docs.deepseek.com/quick_start/pricing"},"deepseek-chat":{input_per_mtok:.14,output_per_mtok:.28,cache_read_per_mtok:.0028,cache_write_per_mtok:null,source:"https://api-docs.deepseek.com/quick_start/pricing"},"deepseek-reasoner":{input_per_mtok:.14,output_per_mtok:.28,cache_read_per_mtok:.0028,cache_write_per_mtok:null,source:"https://api-docs.deepseek.com/quick_start/pricing"},"glm-4.6":{input_per_mtok:.6,output_per_mtok:2.2,cache_read_per_mtok:.11,cache_write_per_mtok:null,source:"https://docs.z.ai/guides/overview/pricing"},"glm-4-air":{input_per_mtok:.2,output_per_mtok:1.1,cache_read_per_mtok:.03,cache_write_per_mtok:null,source:"https://docs.z.ai/guides/overview/pricing"},"grok-4":{input_per_mtok:3,output_per_mtok:15,cache_read_per_mtok:null,cache_write_per_mtok:null,source:"https://docs.x.ai/docs/pricing"},"grok-3":{input_per_mtok:3,output_per_mtok:15,cache_read_per_mtok:.75,cache_write_per_mtok:null,source:"https://docs.x.ai/docs/pricing"},"grok-code-fast-1":{input_per_mtok:.2,output_per_mtok:1.5,cache_read_per_mtok:.02,cache_write_per_mtok:null,source:"https://docs.x.ai/docs/pricing"},"grok-2":{input_per_mtok:2,output_per_mtok:10,cache_read_per_mtok:null,cache_write_per_mtok:null,source:"https://docs.x.ai/docs/pricing"},"mistral-large-latest":{input_per_mtok:.5,output_per_mtok:1.5,cache_read_per_mtok:null,cache_write_per_mtok:null,source:"https://mistral.ai/pricing"},"codestral-latest":{input_per_mtok:.3,output_per_mtok:.9,cache_read_per_mtok:null,cache_write_per_mtok:null,source:"https://mistral.ai/pricing"},devstral:{input_per_mtok:.4,output_per_mtok:2,cache_read_per_mtok:null,cache_write_per_mtok:null,source:"https://mistral.ai/pricing"},"mistral-medium":{input_per_mtok:.4,output_per_mtok:2,cache_read_per_mtok:null,cache_write_per_mtok:null,source:"https://mistral.ai/pricing"},"llama-4-maverick":{input_per_mtok:.27,output_per_mtok:.85,cache_read_per_mtok:null,cache_write_per_mtok:null,source:"https://www.together.ai/pricing"},"llama-4-scout":{input_per_mtok:.08,output_per_mtok:.3,cache_read_per_mtok:null,cache_write_per_mtok:null,source:"https://www.together.ai/pricing"},"llama-3.3-70b":{input_per_mtok:.88,output_per_mtok:.88,cache_read_per_mtok:null,cache_write_per_mtok:null,source:"https://www.together.ai/pricing"},"command-a":{input_per_mtok:2.5,output_per_mtok:10,cache_read_per_mtok:null,cache_write_per_mtok:null,source:"https://cohere.com/pricing"},"command-r-plus":{input_per_mtok:2.5,output_per_mtok:10,cache_read_per_mtok:null,cache_write_per_mtok:null,source:"https://cohere.com/pricing"},"amazon-nova-pro":{input_per_mtok:.8,output_per_mtok:3.2,cache_read_per_mtok:null,cache_write_per_mtok:null,source:"https://aws.amazon.com/bedrock/pricing/"},"amazon-nova-lite":{input_per_mtok:.06,output_per_mtok:.24,cache_read_per_mtok:null,cache_write_per_mtok:null,source:"https://aws.amazon.com/bedrock/pricing/"}};function K(){let t=new Map,e=O;for(let o of Object.keys(e)){let n=e[o];n==null||typeof n!="object"||typeof n.input_per_mtok=="number"&&t.set(o,{input_per_mtok:n.input_per_mtok,output_per_mtok:typeof n.output_per_mtok=="number"?n.output_per_mtok:null,cache_read_per_mtok:typeof n.cache_read_per_mtok=="number"?n.cache_read_per_mtok:null,cache_write_per_mtok:typeof n.cache_write_per_mtok=="number"?n.cache_write_per_mtok:null})}return t}var T=K();function G(t){for(let e=0;e<t.length;e++)if(t.charCodeAt(e)===47)return e===0||e===t.length-1?null:t.slice(e+1);return null}function z(t){return t.trim().toLowerCase()}function I(t){if(typeof t!="string"||t.length===0)return null;let e=T.get(t);if(e)return e;let o=z(t),n=T.get(o);if(n)return n;let r=G(o);if(r){let s=T.get(r);if(s)return s}return null}function E(t,e,o){return t<=0?0:t*(typeof e=="number"?e:o)}function P(t,e){let o=typeof e.input_tokens=="number"?e.input_tokens:0,n=typeof e.output_tokens=="number"?e.output_tokens:0,r=typeof e.cache_read_tokens=="number"?e.cache_read_tokens:0,s=typeof e.cache_creation_tokens=="number"?e.cache_creation_tokens:0;if(o<=0&&n<=0&&r<=0&&s<=0)return null;let i=I(t);if(!i||typeof i.input_per_mtok!="number")return console.warn(`[pricing] no curated price for model id: ${t}`),null;let a=i.input_per_mtok;return(E(o,a,a)+E(n,i.output_per_mtok,a)+E(r,i.cache_read_per_mtok,a)+E(s,i.cache_write_per_mtok,a))/1e6}function x(t){return typeof t=="number"&&Number.isFinite(t)&&t>0?t:0}function L(t){if(!t||typeof t!="object")return null;let e=t;if(typeof e.type=="string"&&e.type!=="usage.record")return null;let o=e.usage;if(!o||typeof o!="object")return null;let n=o,r=x(n.inputOther),s=x(n.output),i=x(n.inputCacheRead),a=x(n.inputCacheCreation);return r<=0&&s<=0&&i<=0&&a<=0?null:{model_id:typeof e.model=="string"?e.model:"",input_tokens:r,output_tokens:s,cache_creation_tokens:a,cache_read_tokens:i,native_cost_usd:null}}function J(t,e){let o=V(e);if(typeof t!="string"||t.length===0)return{events:[],cursor:e??null};let n=[],r=t.split(`
|
|
2
|
+
`);for(let u of r){let c=u.trim();if(c.length===0)continue;let l;try{l=JSON.parse(c)}catch{continue}if(!l||typeof l!="object"||l.type!=="usage.record")continue;let m=L(l);n.push(m??{model_id:"",input_tokens:0,output_tokens:0,cache_creation_tokens:0,cache_read_tokens:0,native_cost_usd:null})}let s=n.length;if(s===0)return{events:[],cursor:e??null};let i;o===null||o<=0?i=n:o>=s?o===s?i=[]:i=n.slice(s-1):i=n.slice(o);let a=new Map;for(let u of i){let c=a.get(u.model_id)??{input:0,output:0,cacheCreate:0,cacheRead:0};c.input+=u.input_tokens,c.output+=u.output_tokens,c.cacheCreate+=u.cache_creation_tokens,c.cacheRead+=u.cache_read_tokens,a.set(u.model_id,c)}let p=[];for(let[u,c]of a){let l=w({model_id:u,input_tokens:c.input,output_tokens:c.output,cache_creation_tokens:c.cacheCreate,cache_read_tokens:c.cacheRead});l&&p.push(l)}return{events:p,cursor:String(s)}}function V(t){if(typeof t!="string"||t.length===0)return null;let e=Number.parseInt(t,10);return!Number.isFinite(e)||e<0?null:e}function A(t){if(typeof t!="number"||!Number.isFinite(t))return 0;let e=Math.floor(t);return e>0?e:0}function N(t){if(!t||typeof t!="object"||Array.isArray(t))return null;let e=t,o=e.usageMetadata;if(!o||typeof o!="object")return null;let n=o,r=A(n.promptTokenCount),s=A(n.candidatesTokenCount),i=A(n.thoughtsTokenCount),a=A(n.cachedContentTokenCount),p=s+i;return r<=0&&p<=0&&a<=0?null:{model_id:typeof e.model=="string"?e.model:"",input_tokens:r,output_tokens:p,cache_creation_tokens:0,cache_read_tokens:a,native_cost_usd:null}}function Q(t){return typeof t.id=="string"&&t.id.length>0?t.id:typeof t.messageId=="string"&&t.messageId.length>0?t.messageId:null}function X(t,e){let o=typeof e=="string"&&e.length>0?e:null;if(typeof t!="string"||t.length===0)return{events:[],cursor:o};let n=[],r=0;for(let u=0;u<=t.length;u++){if(u!==t.length&&t.charCodeAt(u)!==10)continue;let c=t.slice(r,u).trim();if(r=u+1,c.length===0)continue;let l;try{let m=JSON.parse(c);if(!m||typeof m!="object"||Array.isArray(m))continue;l=m}catch{continue}n.push({id:Q(l),counts:N(l)})}if(n.length===0)return{events:[],cursor:o};let s=o;for(let u=n.length-1;u>=0;u--)if(n[u].id!==null){s=n[u].id;break}let i;if(o===null)i=n;else{let u=-1;for(let c=0;c<n.length;c++)if(n[c].id===o){u=c;break}u>=0?i=n.slice(u+1):i=n.slice(n.length-1)}let a=new Map;for(let u of i){let c=u.counts;if(!c)continue;let l=a.get(c.model_id)??{input:0,output:0,cacheCreate:0,cacheRead:0};l.input+=c.input_tokens,l.output+=c.output_tokens,l.cacheCreate+=c.cache_creation_tokens,l.cacheRead+=c.cache_read_tokens,a.set(c.model_id,l)}let p=[];for(let[u,c]of a){let l=w({model_id:u,input_tokens:c.input,output_tokens:c.output,cache_creation_tokens:c.cacheCreate,cache_read_tokens:c.cacheRead});l&&p.push(l)}return{events:p,cursor:s}}function _(t){return t==null?"":String(t)}function B(t){return t==null?"":typeof t=="string"?t:JSON.stringify(t)}function v(t){let e=String(t.tool_response??""),o=String(t.tool_input?.command??"");if(e.startsWith("context-mode:")||o.startsWith('echo "context-mode:')||o.startsWith("echo 'context-mode:"))return!1;let n=t.tool_output?.isError===!0||t.tool_output?.is_error===!0;return t.tool_name==="Bash"&&/exit code [1-9]|error:|Error:|FAIL|failed/i.test(e)||n}function F(t){if(!t)return[];let e=[];for(let n of t.split(/\r?\n/)){if(n.startsWith("*** Add File: ")){e.push({path:n.slice(14).trim(),type:"file_write"});continue}if(n.startsWith("*** Update File: ")){e.push({path:n.slice(17).trim(),type:"file_edit"});continue}if(n.startsWith("*** Delete File: ")){e.push({path:n.slice(17).trim(),type:"file_edit"});continue}n.startsWith("*** Move to: ")&&e.push({path:n.slice(13).trim(),type:"file_edit"})}let o=new Set;return e.filter(n=>{if(!n.path)return!1;let r=`${n.type}:${n.path}`;return o.has(r)?!1:(o.add(r),!0)})}function M(t){return/(?:^|[/\\])\.claude[/\\]plans[/\\]/.test(t)}function Y(t){let{tool_name:e,tool_input:o,tool_response:n}=t,r=[];if(e==="Read"){let s=String(o.file_path??"");return(/(?:CLAUDE|AGENTS(?:\.override)?|GEMINI|QWEN|KIRO)\.md$/i.test(s)||/\/copilot-instructions\.md$/i.test(s)||/\/context-mode\.mdc$/i.test(s)||/\.claude[\\/]/i.test(s)||/[\\/]memor(?:y|ies)[\\/][^\\/]+\.md$/i.test(s))&&(r.push({type:"rule",category:"rule",data:_(s),priority:1}),n&&n.length>0&&r.push({type:"rule_content",category:"rule",data:_(n),priority:1})),r.push({type:"file_read",category:"file",data:_(s),priority:1}),r}if(e==="Edit"){let s=String(o.file_path??"");return r.push({type:"file_edit",category:"file",data:_(s),priority:1}),r}if(e==="NotebookEdit"){let s=String(o.notebook_path??"");return r.push({type:"file_edit",category:"file",data:_(s),priority:1}),r}if(e==="Write"){let s=String(o.file_path??"");return r.push({type:"file_write",category:"file",data:_(s),priority:1}),r}if(e==="apply_patch"){if(v(t))return[];let s=F(String(o.command??o.patch??""));for(let i of s)r.push({type:i.type,category:"file",data:_(i.path),priority:1});return r}if(e==="Glob"){let s=String(o.pattern??"");return r.push({type:"file_glob",category:"file",data:_(s),priority:3}),r}if(e==="Grep"){let s=String(o.pattern??""),i=String(o.path??"");return r.push({type:"file_search",category:"file",data:_(`${s} in ${i}`),priority:3}),r}return r}function Z(t){if(t.tool_name!=="Bash")return[];let o=String(t.tool_input.command??"").match(/\bcd\s+("([^"]+)"|'([^']+)'|(\S+))/);if(!o)return[];let n=o[2]??o[3]??o[4]??"";return[{type:"cwd",category:"cwd",data:_(n),priority:2}]}function tt(t){let{tool_response:e}=t,o=String(e??"");return v(t)?[{type:"error_tool",category:"error",data:_(o),priority:2}]:[]}var H=[{pattern:/\bgit\s+checkout\b/,operation:"branch"},{pattern:/\bgit\s+commit\b/,operation:"commit"},{pattern:/\bgit\s+merge\s+\S+/,operation:"merge"},{pattern:/\bgit\s+rebase\b/,operation:"rebase"},{pattern:/\bgit\s+stash\b/,operation:"stash"},{pattern:/\bgit\s+push\b/,operation:"push"},{pattern:/\bgit\s+pull\b/,operation:"pull"},{pattern:/\bgit\s+log\b/,operation:"log"},{pattern:/\bgit\s+diff\b/,operation:"diff"},{pattern:/\bgit\s+status\b/,operation:"status"},{pattern:/\bgit\s+branch\b/,operation:"branch"},{pattern:/\bgit\s+reset\b/,operation:"reset"},{pattern:/\bgit\s+add\b/,operation:"add"},{pattern:/\bgit\s+cherry-pick\b/,operation:"cherry-pick"},{pattern:/\bgit\s+tag\b/,operation:"tag"},{pattern:/\bgit\s+fetch\b/,operation:"fetch"},{pattern:/\bgit\s+clone\b/,operation:"clone"},{pattern:/\bgit\s+worktree\b/,operation:"worktree"}];function et(t){if(t.tool_name!=="Bash")return[];let e=String(t.tool_input.command??""),o=ot(e),n;if(o&&o.operation&&(n=H.find(s=>s.operation===o.operation)),n||(n=H.find(s=>s.pattern.test(e))),!n)return[];let r=[];if(o?.scopedDir&&r.push({type:"cwd",category:"cwd",data:_(o.scopedDir),priority:2}),n.operation==="commit"){let s=it(e);if(s)return r.push({type:"git_commit",category:"git",data:_(s),priority:2}),r}return r.push({type:"git",category:"git",data:_(n.operation),priority:2}),r}function nt(t){return typeof t!="string"||t.length===0?t:t==="~"?U():t.startsWith("~/")?U()+t.slice(1):t}function U(){try{return process.env.HOME||process.env.USERPROFILE||(process.env.HOMEDRIVE&&process.env.HOMEPATH?process.env.HOMEDRIVE+process.env.HOMEPATH:"")||"~"}catch{return"~"}}function ot(t){let e=W(t),o=0;for(;o<e.length&&rt(e[o]);)o++;for(;o<e.length&&e[o]!=="git"&&!e[o].endsWith("/git")&&st(e[o]);)o++;if(o>=e.length||e[o]!=="git"&&!e[o].endsWith("/git"))return null;o++;let n=null,r=null;for(;o<e.length;){let s=e[o];if(s==="-C"||s==="--directory"){n=e[o+1]??null,o+=2;continue}if(s.startsWith("--directory=")){n=s.slice(12),o++;continue}if(s.length>0&&s[0]==="-"){o++;continue}r=s;break}return n&&(n=nt(n)),{scopedDir:n,operation:r}}function rt(t){if(t.length===0)return!1;let e=!1;for(let o=0;o<t.length;o++){let n=t.charCodeAt(o);if(o===0){if(!(n>=65&&n<=90||n===95))return!1}else if(n===61){e=!0;break}else if(!(n>=65&&n<=90||n>=48&&n<=57||n===95))return!1}return e}function st(t){switch(t){case"sudo":case"doas":case"env":case"exec":case"time":return!0;default:return!1}}function W(t){let e=[],o=t.length,n=0;for(;n<o;){for(;n<o&&(t[n]===" "||t[n]===" ");)n++;if(n>=o)break;let r="";for(;n<o&&t[n]!==" "&&t[n]!==" ";){let s=t[n];if(s==='"'||s==="'"){let i=s;for(n++;n<o&&t[n]!==i;)t[n]==="\\"&&n+1<o?(r+=t[n+1],n+=2):(r+=t[n],n++);n<o&&n++}else s==="\\"&&n+1<o?(r+=t[n+1],n+=2):(r+=s,n++)}e.push(r)}return e}function it(t){let e=W(t),o="--message=";for(let n=0;n<e.length;n++){let r=e[n];if(r.length>o.length&&r.startsWith(o)){let s=r.slice(o.length);return s.length>0?s:null}if(r==="--message"){let s=e[n+1];return s&&s.length>0?s:null}if(r.length>=2&&r[0]==="-"&&r[1]!=="-"&&r[r.length-1]==="m"&&ct(r,1)){let s=e[n+1];return s&&s.length>0?s:null}}return null}function ct(t,e){if(e>=t.length)return!1;for(let o=e;o<t.length;o++){let n=t.charCodeAt(o);if(n<97||n>122)return!1}return!0}function ut(t){return new Set(["TodoWrite","TaskCreate","TaskUpdate"]).has(t.tool_name)?[{type:t.tool_name==="TaskUpdate"?"task_update":t.tool_name==="TaskCreate"?"task_create":"task",category:"task",data:_(JSON.stringify(t.tool_input)),priority:1}]:[]}function at(t){let e=2166136261;for(let o=0;o<t.length;o++)e^=t.charCodeAt(o),e=Math.imul(e,16777619);return(e>>>0).toString(16).padStart(8,"0")}function pt(t){let e=t.tool_input.plan;if(typeof e=="string"&&e.length>0)return e;let o=t.tool_response;if(typeof o=="string"&&o.length>0)try{let n=JSON.parse(o);if(n&&typeof n=="object"&&typeof n.plan=="string")return n.plan}catch{}return null}function lt(t){if(t.tool_name==="EnterPlanMode")return[{type:"plan_enter",category:"plan",data:"entered plan mode",priority:2}];if(t.tool_name==="ExitPlanMode"){let e=[],o=t.tool_input.allowedPrompts,n=Array.isArray(o)&&o.length>0?`exited plan mode (allowed: ${B(o.map(i=>typeof i=="object"&&i!==null&&"prompt"in i?String(i.prompt):String(i)).join(", "))})`:"exited plan mode",r=pt(t);typeof r=="string"&&r.length>0&&(n+=` plan_bytes:${r.length} plan_hash:${at(r)}`),e.push({type:"plan_exit",category:"plan",data:_(n),priority:2});let s=String(t.tool_response??"").toLowerCase();return s.includes("approved")||s.includes("approve")?e.push({type:"plan_approved",category:"plan",data:"plan approved by user",priority:1}):(s.includes("rejected")||s.includes("decline")||s.includes("denied"))&&e.push({type:"plan_rejected",category:"plan",data:_(`plan rejected: ${t.tool_response??""}`),priority:2}),e}if(t.tool_name==="Write"||t.tool_name==="Edit"){let e=String(t.tool_input.file_path??"");if(M(e))return[{type:"plan_file_write",category:"plan",data:_(`plan file: ${e.split(/[/\\]/).pop()??e}`),priority:2}]}return t.tool_name==="apply_patch"?v(t)?[]:F(String(t.tool_input.command??t.tool_input.patch??"")).filter(o=>M(o.path)).map(o=>({type:"plan_file_write",category:"plan",data:_(`plan file: ${o.path.split(/[/\\]/).pop()??o.path}`),priority:2})):[]}var _t=[/\bsource\s+\S*activate\b/,/\bexport\s+\w+=/,/\bnvm\s+use\b/,/\bpyenv\s+(shell|local|global)\b/,/\bconda\s+activate\b/,/\brbenv\s+(shell|local|global)\b/,/\bnpm\s+install\b/,/\bnpm\s+ci\b/,/\bpip\s+install\b/,/\bbun\s+install\b/,/\byarn\s+(add|install)\b/,/\bpnpm\s+(add|install)\b/,/\bcargo\s+(install|add)\b/,/\bgo\s+(install|get)\b/,/\brustup\b/,/\basdf\b/,/\bvolta\b/,/\bdeno\s+install\b/];function mt(t){if(t.tool_name!=="Bash")return[];let e=String(t.tool_input.command??"");if(!_t.some(r=>r.test(e)))return[];let n=e.replace(/\bexport\s+(\w+)=\S*/g,"export $1=***");return[{type:"env",category:"env",data:_(n),priority:2}]}function dt(t){if(t.tool_name!=="Skill")return[];let e=String(t.tool_input.skill??"");return[{type:"skill",category:"skill",data:_(e),priority:2}]}function ht(t){if(!t.tool_response?.includes("Error")&&!t.tool_output?.isError)return[];let e=String(t.tool_response||""),o=[/not supported/i,/cannot/i,/does not support/i,/FAIL/i,/refused/i,/permission denied/i,/incompatible/i];for(let n of o){let r=e.match(n);if(r){let s=e.toLowerCase().indexOf(r[0].toLowerCase()),i=e.slice(Math.max(0,s-50),Math.min(e.length,s+200)).trim();return[{type:"constraint_discovered",category:"constraint",data:_(i),priority:2}]}}return[]}function ft(t){if(t.tool_name!=="Agent")return[];let e=_(String(t.tool_input.prompt??t.tool_input.description??"")),o=t.tool_response?_(String(t.tool_response)):"",n=o.length>0;return[{type:n?"subagent_completed":"subagent_launched",category:"subagent",data:_(n?`[completed] ${e} \u2192 ${o}`:`[launched] ${e}`),priority:n?2:3}]}function gt(t){let{tool_name:e,tool_input:o,tool_response:n}=t;if(!e.startsWith("mcp__"))return[];let r=e.split("__"),s=r[r.length-1]||e,i=Object.values(o).find(u=>typeof u=="string"),a=i?`: ${_(String(i))}`:"",p=n&&n.length>0?`
|
|
3
|
+
response: ${_(n)}`:"";return[{type:"mcp",category:"mcp",data:_(`${s}${a}${p}`),priority:3}]}var kt=2048;function yt(t,e){if(Buffer.byteLength(t,"utf8")<=e)return{value:t,truncated:!1};let o=Buffer.from(t,"utf8"),n=e;for(;n>0&&(o[n]&192)===128;)n--;return{value:o.subarray(0,n).toString("utf8"),truncated:!0}}var bt=/(authorization|auth_token|access_token|refresh_token|bearer|token|secret|password|passwd|pwd|api[-_]?key|apikey|cookie|set-cookie|signature|private[-_]?key|client[-_]?secret|x[-_]?api[-_]?key)/i,wt="[REDACTED]";function j(t,e=new WeakSet){if(t==null||typeof t!="object")return t;if(e.has(t))return"[CIRCULAR]";e.add(t);let o;if(Array.isArray(t))o=t.map(n=>j(n,e));else{let n={};for(let[r,s]of Object.entries(t))bt.test(r)?n[r]=wt:n[r]=j(s,e);o=n}return e.delete(t),o}function St(t){let{tool_name:e,tool_input:o}=t;if(!e.startsWith("mcp__"))return[];let n=j(o??{}),r;try{r=JSON.stringify(n)}catch{r="{}"}let{value:s,truncated:i}=yt(r,kt),a=i?`{"tool_name":${JSON.stringify(e)},"params_raw":${JSON.stringify(s)},"truncated":true}`:`{"tool_name":${JSON.stringify(e)},"params":${s}}`,p={type:"mcp_tool_call",category:"mcp_tool_call",data:_(a),priority:4};if(vt(e)){let u=_(t.tool_response);u.length>0&&(p.bytes_retrieved=Buffer.byteLength(u,"utf8"))}return[p]}var Rt=["ctx_search","ctx_fetch_and_index"];function vt(t){for(let e of Rt)if(t.endsWith(e))return!0;return!1}function Et(t){if(t.tool_name!=="AskUserQuestion")return[];let e=t.tool_input.questions,o=Array.isArray(e)&&e.length>0?String(e[0].question??""):"",n=String(t.tool_response??""),r="";try{let p=JSON.parse(n)?.answers;if(p&&typeof p=="object"){let u=l=>typeof l=="string"?l:Array.isArray(l)?l.filter(m=>typeof m=="string").join(" | "):"",c=o?u(p[o]):"";c?r=c:r=Object.values(p).map(u).filter(m=>m.length>0).join(" | ")}}catch{}let s=_(r),i=o?`Q: ${_(o)} \u2192 A: ${s}`:`answer: ${s}`;return[{type:"decision_question",category:"decision",data:_(i),priority:2}]}function xt(t){if(t.tool_name!=="Agent")return[];if(!t.tool_response||t.tool_response.length===0)return[];let e=t.tool_response.length>500?t.tool_response.slice(0,500):t.tool_response;return[{type:"agent_finding",category:"agent-finding",data:_(e),priority:2}]}function At(t){let e=[B(t.tool_input),_(t.tool_response)].join(" ");if(e.length===0)return[];let o=new Set,n=e.match(/https?:\/\/[^\s)]+/g);if(n)for(let p of n)p=p.replace(/["'})\],;.]+$/,""),/localhost|127\.0\.0\.1/i.test(p)||o.add(p);let r=e.match(/(?<!\w)#(\d+)/g);if(r)for(let p of r)o.add(p);if(o.size===0)return[];let s,i=_(t.tool_response).match(/Fetched and indexed[^\(]*\(([\d.]+)\s*KB\)/i);if(i){let p=Number(i[1]);Number.isFinite(p)&&p>0&&(s=Math.round(p*1024))}let a={type:"external_ref",category:"external-ref",data:_(Array.from(o).join(", ")),priority:3};return s!==void 0&&(a.bytes_avoided=s),[a]}function Ct(t){if(t.tool_name==="EnterWorktree"){let e=String(t.tool_input.name??"unnamed");return[{type:"worktree",category:"env",data:_(`entered worktree: ${e}`),priority:2}]}if(t.tool_name==="ExitWorktree"){let e=!!t.tool_input.discard_changes;return[{type:"worktree_exit",category:"env",data:_(`exited worktree (discard_changes:${e})`),priority:2}]}return[]}function Tt(t){if(typeof t!="string"||t.length===0)return null;let e=t.indexOf("://");if(e<0)return null;let o=e+3;if(o>=t.length)return null;let n=t.length;for(let s=o;s<t.length;s++){let i=t.charCodeAt(s);if(i===47||i===63||i===35){n=s;break}}let r=t.slice(o,n);return r.length>0?r:null}function It(t){if(t.tool_name!=="WebFetch")return[];let e=t.tool_response;if(typeof e!="string"||e.length===0)return[];let o;try{o=JSON.parse(e)}catch{return[]}if(!o||typeof o!="object")return[];let n=o,r=[];if(typeof n.code=="number"&&r.push(`code:${n.code}`),typeof n.bytes=="number"&&r.push(`bytes:${n.bytes}`),typeof n.durationMs=="number"&&r.push(`durMs:${n.durationMs}`),typeof n.url=="string"){let s=Tt(n.url);s&&r.push(`host:${s}`)}return r.length===0?[]:[{type:"webfetch_metadata",category:"data",data:_(r.join(" ")),priority:3}]}function jt(t){if(t.tool_name!=="Bash")return[];let e=t.tool_response;if(typeof e!="string"||e.length===0)return[];let o;try{o=JSON.parse(e)}catch{return[]}if(!o||typeof o!="object")return[];let n=o;if(!(typeof n.interrupted=="boolean"||typeof n.stderr=="string"||typeof n.returnCodeInterpretation=="string"))return[];let s=[];return typeof n.interrupted=="boolean"&&s.push(`interrupted:${n.interrupted}`),typeof n.returnCodeInterpretation=="string"&&s.push(`rcInterp:${n.returnCodeInterpretation.slice(0,80)}`),typeof n.stderr=="string"&&s.push(`stderrBytes:${n.stderr.length}`),[{type:"bash_outcome",category:"data",data:_(s.join(" ")),priority:3}]}function $t(t){if(t.tool_name!=="Read")return[];let e=t.tool_response;if(typeof e!="string"||e.length===0)return[];let o;try{o=JSON.parse(e)}catch{return[]}if(!o||typeof o!="object")return[];let n=o,r=n.type;if(r!=="text"&&r!=="image")return[];let s=[`type:${r}`];if(r==="text")typeof n.numLines=="number"&&s.push(`lines:${n.numLines}`),typeof n.totalLines=="number"&&s.push(`totalLines:${n.totalLines}`),typeof n.startLine=="number"&&s.push(`start:${n.startLine}`);else{typeof n.originalSize=="number"&&s.push(`origSize:${n.originalSize}`);let i=n.dimensions;if(i&&typeof i=="object"){let a=i;typeof a.width=="number"&&typeof a.height=="number"&&s.push(`dims:${a.width}x${a.height}`)}}return[{type:"file_read_metadata",category:"data",data:_(s.join(" ")),priority:3}]}function Ot(t,e){let o=[t.tool_input?.model,t.model,e.model];for(let n of o)if(typeof n=="string"&&n.length>0)return n;return""}function Pt(t){for(let e=t.length-1;e>0;e--)if(t.charCodeAt(e)===45)return t.slice(0,e);return null}function Lt(t){let e=t;for(;e&&e.length>0;){if(I(e)!==null)return e;e=Pt(e)}return""}function Nt(t,e,o,n,r){let s=Lt(t);return P(s||t,{input_tokens:e,output_tokens:o,cache_creation_tokens:n,cache_read_tokens:r})}function Mt(t){let e=t.toFixed(6),o=e.length;for(;o>0&&e.charCodeAt(o-1)===48;)o--;return e=e.slice(0,o),e.length>0&&e.charCodeAt(e.length-1)===46&&(e+="0"),e}function Ht(t){if(t.tool_name!=="Task")return[];let e=t.tool_response;if(typeof e!="string"||e.length===0)return[];let o;try{o=JSON.parse(e)}catch{return[]}if(!o||typeof o!="object")return[];let n=o,r=n.usage&&typeof n.usage=="object"?n.usage:{};if(!(typeof n.totalTokens=="number"||typeof n.totalDurationMs=="number"||typeof r.input_tokens=="number"||typeof r.output_tokens=="number"||typeof r.service_tier=="string"))return[];let i=[];typeof n.totalTokens=="number"&&i.push(`totalTokens:${n.totalTokens}`),typeof n.totalDurationMs=="number"&&i.push(`totalDurMs:${n.totalDurationMs}`),typeof r.input_tokens=="number"&&i.push(`tokens_in:${r.input_tokens}`),typeof r.output_tokens=="number"&&i.push(`tokens_out:${r.output_tokens}`),typeof r.cache_creation_input_tokens=="number"&&i.push(`cache_create:${r.cache_creation_input_tokens}`),typeof r.cache_read_input_tokens=="number"&&i.push(`cache_read:${r.cache_read_input_tokens}`),typeof r.service_tier=="string"&&i.push(`tier:${r.service_tier.slice(0,32)}`);let a=Ot(t,n),p={type:"agent_usage",category:"cost",data:_(i.join(" ")),priority:2};return a.length>0&&(p.model_id=a),typeof r.input_tokens=="number"&&(p.input_tokens=r.input_tokens),typeof r.output_tokens=="number"&&(p.output_tokens=r.output_tokens),typeof r.cache_read_input_tokens=="number"&&(p.cache_read_tokens=r.cache_read_input_tokens),typeof r.cache_creation_input_tokens=="number"&&(p.cache_creation_tokens=r.cache_creation_input_tokens),p.usage_scope="task_cumulative",[p]}function Ee(t){if(!t||typeof t!="object")return null;let e=t,o=e.message,n=o&&typeof o=="object"?o:e;if(typeof n.role=="string"&&n.role!=="assistant")return null;let r=n.usage;if(!r||typeof r!="object")return null;let s=r,i=d=>typeof d=="number"&&Number.isFinite(d)&&d>0?d:0,a=i(s.input),p=i(s.output),u=i(s.cacheWrite),c=i(s.cacheRead);if(a<=0&&p<=0&&u<=0&&c<=0)return null;let l=null,m=s.cost;if(m&&typeof m=="object"){let d=m.total;typeof d=="number"&&Number.isFinite(d)&&(l=d)}return{model_id:typeof n.model=="string"?n.model:"",input_tokens:a,output_tokens:p,cache_creation_tokens:u,cache_read_tokens:c,native_cost_usd:l}}function xe(t){if(!t||typeof t!="object")return null;let e=t;if(typeof e.type=="string"&&e.type!=="model.usage")return null;let o=e.usage;if(!o||typeof o!="object")return null;let n=o,r=m=>typeof m=="number"&&Number.isFinite(m)&&m>0?m:0,s=r(n.input),i=r(n.output),a=r(n.cacheWrite),p=r(n.cacheRead);if(s<=0&&i<=0&&a<=0&&p<=0)return null;let u=e.costUsd,c=typeof u=="number"&&Number.isFinite(u)?u:null;return{model_id:typeof e.model=="string"?e.model:"",input_tokens:s,output_tokens:i,cache_creation_tokens:a,cache_read_tokens:p,native_cost_usd:c}}function Ae(t){if(!t||typeof t!="object")return null;let e=t,o=e.event&&typeof e.event=="object"?e.event:e,n=o.properties&&typeof o.properties=="object"?o.properties:o,r=n.info&&typeof n.info=="object"?n.info:e;if(typeof r.role=="string"&&r.role!=="assistant")return null;let s=r.tokens;if(!s||typeof s!="object")return null;let i=s,a=b=>typeof b=="number"&&Number.isFinite(b)&&b>0?b:0,p=i.cache,u=p&&typeof p=="object"?p:{},c=a(i.input),l=a(i.output),m=a(u.read),h=a(u.write);if(c<=0&&l<=0&&h<=0&&m<=0)return null;let d=r.cost,S=typeof d=="number"&&Number.isFinite(d)?d:null,y=typeof r.modelID=="string"?r.modelID:"",R=typeof r.providerID=="string"?r.providerID:"",f="";return y.length>0?f=R.length>0?`${R}/${y}`:y:typeof r.model=="string"&&(f=r.model),{model_id:f,input_tokens:c,output_tokens:l,cache_creation_tokens:h,cache_read_tokens:m,native_cost_usd:S}}function w(t){let{model_id:e,input_tokens:o,output_tokens:n,cache_creation_tokens:r,cache_read_tokens:s,native_cost_usd:i}=t;if(o<=0&&n<=0&&r<=0&&s<=0)return null;let a=[`tokens_in:${o}`,`tokens_out:${n}`];r>0&&a.push(`cache_create:${r}`),s>0&&a.push(`cache_read:${s}`);let p=typeof i=="number"&&Number.isFinite(i)?i:Nt(e,o,n,r,s);p!==null&&a.push(`cost_usd:${Mt(p)}`);let u={type:"agent_usage",category:"cost",data:_(a.join(" ")),priority:2};return e.length>0&&(u.model_id=e),u.input_tokens=o,u.output_tokens=n,s>0&&(u.cache_read_tokens=s),r>0&&(u.cache_creation_tokens=r),p!==null&&(u.cost_usd=p),u}function Ce(t){if(!t||typeof t!="object")return null;let e=t,o=e.llm_response;if(!o||typeof o!="object")return null;let n=o,r=n.usageMetadata;if(!r||typeof r!="object")return null;let s=r,i=y=>typeof y=="number"&&Number.isFinite(y)?y:0,a=i(s.promptTokenCount),p=i(s.candidatesTokenCount),u=i(s.thoughtsTokenCount),c=i(s.cachedContentTokenCount),l=p+u,m=e.llm_request,h=m&&typeof m=="object"&&typeof m.model=="string"?m.model:"",d=typeof n.modelVersion=="string"?n.modelVersion:"",S=d.length>0?d:h;return w({model_id:S,input_tokens:a,output_tokens:l,cache_creation_tokens:0,cache_read_tokens:c})}function Te(t){if(typeof t!="string"||t.length===0)return[];let e=new Map,o=0;for(let r=0;r<=t.length;r++){if(r!==t.length&&t.charCodeAt(r)!==10)continue;let s=t.slice(o,r).trim();if(o=r+1,s.length===0)continue;let i;try{let h=JSON.parse(s);if(!h||typeof h!="object")continue;i=h}catch{continue}if(i.type!=="assistant"||i.isSidechain===!0)continue;let a=i.message;if(!a||typeof a!="object")continue;let p=a,u=typeof p.model=="string"?p.model:"";if(u.length===0)continue;let c=p.usage;if(!c||typeof c!="object")continue;let l=c,m=e.get(u)??{input:0,output:0,cacheCreate:0,cacheRead:0};typeof l.input_tokens=="number"&&(m.input+=l.input_tokens),typeof l.output_tokens=="number"&&(m.output+=l.output_tokens),typeof l.cache_creation_input_tokens=="number"&&(m.cacheCreate+=l.cache_creation_input_tokens),typeof l.cache_read_input_tokens=="number"&&(m.cacheRead+=l.cache_read_input_tokens),e.set(u,m)}let n=[];for(let[r,s]of e){let i=w({model_id:r,input_tokens:s.input,output_tokens:s.output,cache_creation_tokens:s.cacheCreate,cache_read_tokens:s.cacheRead});i&&n.push(i)}return n}function Ie(t,e){let o=typeof e=="string"&&e.length>0?e:null;if(typeof t!="string"||t.length===0)return{events:[],cursor:o};let n=[],r=0;for(let c=0;c<=t.length;c++){if(c!==t.length&&t.charCodeAt(c)!==10)continue;let l=t.slice(r,c).trim();if(r=c+1,l.length===0)continue;let m;try{let b=JSON.parse(l);if(!b||typeof b!="object")continue;m=b}catch{continue}if(m.type!=="assistant"||m.isSidechain===!0)continue;let h=m.message;if(!h||typeof h!="object")continue;let d=h,S=typeof d.model=="string"?d.model:"";if(S.length===0)continue;let y=typeof m.uuid=="string"&&m.uuid.length>0?m.uuid:null,R=d.usage,f=R&&typeof R=="object"?R:{};n.push({uuid:y,model:S,input:typeof f.input_tokens=="number"?f.input_tokens:0,output:typeof f.output_tokens=="number"?f.output_tokens:0,cacheCreate:typeof f.cache_creation_input_tokens=="number"?f.cache_creation_input_tokens:0,cacheRead:typeof f.cache_read_input_tokens=="number"?f.cache_read_input_tokens:0})}if(n.length===0)return{events:[],cursor:o};let s=n[n.length-1].uuid,i=s!==null?s:o,a;if(o===null)a=n;else{let c=-1;for(let l=0;l<n.length;l++)if(n[l].uuid===o){c=l;break}c>=0?a=n.slice(c+1):a=n.slice(n.length-1)}let p=new Map;for(let c of a){let l=p.get(c.model)??{input:0,output:0,cacheCreate:0,cacheRead:0};l.input+=c.input,l.output+=c.output,l.cacheCreate+=c.cacheCreate,l.cacheRead+=c.cacheRead,p.set(c.model,l)}let u=[];for(let[c,l]of p){let m=w({model_id:c,input_tokens:l.input,output_tokens:l.output,cache_creation_tokens:l.cacheCreate,cache_read_tokens:l.cacheRead});m&&u.push(m)}return{events:u,cursor:i}}var D=/[,;,;、،]/u,Ut=15,Bt=500;function Ft(t){if(C.test(t)||!$.test(t)||!D.test(t))return!1;let e=[...t].length;return e>=Ut&&e<=Bt}function Wt(t){let e=t.trim();return Ft(e)?[{type:"decision",category:"decision",data:_(t),priority:2}]:[]}var Dt=8,qt=120,Kt=new RegExp("\\p{L}+\\s+\\p{L}+","u"),Gt=new RegExp("\\p{L}{6,}","u"),zt=new Set(["ok","okay","sure","yeah","yep","yup","alright","fine","well","so","hmm","right","please"]),Jt=["you are","you're","your role","you will be","you act","you will act","act as","act like","behave as","behave like","imagine you","pretend you","assume the role","take the role","play the role","respond as","tu es","tu est","vous etes","vous \xEAtes","sen ","siz ","eres ","t\xFA eres","usted es","\u0442\u044B ","\u0432\u044B ","\u3042\u306A\u305F\u306F","\u541B\u306F","\u304A\u524D\u306F","\u3042\u306A\u305F\u304C","\u4F60\u662F","\u60A8\u662F","\u0924\u0941\u092E ","\u0906\u092A ","\u0924\u0942 ","\u0623\u0646\u062A ","\u0627\u0646\u062A ","\u0623\u0646\u062A\u064E "],Vt=["always ","never ","respond ","reply ","answer ","speak ","write ","prefer ","format ","output ","communicate ","use only "];function Qt(t){let e=t.toLowerCase().trim();if(!e)return!1;let o=e.split(" ").filter(r=>r.length>0);for(;o.length>0&&zt.has(o[0]);)o.shift();let n=o.join(" ");if(!n)return!1;for(let r of Jt)if(n.startsWith(r))return!0;for(let r of Vt)if(n.startsWith(r))return!0;return!1}function Xt(t){let e=t.split(/[.!\n。!]/u)[0].trim();if(C.test(e)||D.test(e)||!$.test(e))return!1;let o=[...e].length;return o<Dt||o>qt||!Qt(e)?!1:Kt.test(e)||Gt.test(e)}function Yt(t){let e=t.trim();return Xt(e)?[{type:"role",category:"role",data:_(t),priority:3}]:[]}var C=/[??؟¿]/u,$=new RegExp("\\p{L}","u"),Zt=60;function te(t){if(C.test(t)||!$.test(t))return!1;let e=[...t].length;return e>0&&e<Zt}function ee(t){let e=t.trim();if(!e)return[];let o;return C.test(e)?o="investigate":te(e)&&(o="implement"),o?[{type:"intent",category:"intent",data:_(o),priority:4}]:[]}var ne=/^(?:\/goal\s+|(?:goal|objective)\s*:\s*)(.+)$/is;function oe(t){let e=t.trim();if(!e)return[];let o=e.match(ne);if(!o)return[];let n=o[1].trim();return n?[{type:"goal",category:"goal",data:_(n),priority:4}]:[]}var re=/(?:\bError\s*:|\bException\s*:|\bTraceback\b|\bat\s+\S+\s*\([^)]*:\d+:\d+\))/u,se=/[✓✔✅☑🎉]/u,ie=/^\s*(?:fixed|resolved)\s*:/iu;function ce(t){let e=[];return se.test(t)||ie.test(t)?(e.push({type:"blocker_resolved",category:"blocked-on",data:_(t),priority:2}),e):(re.test(t)&&e.push({type:"blocker",category:"blocked-on",data:_(t),priority:2}),e)}function ue(t){return t.length<=1024?[]:[{type:"data",category:"data",data:_(t),priority:4}]}var g=null;function ae(t){let{tool_name:e,tool_response:o}=t,n=String(o??"");if(v(t))return g={tool:e,error:n.slice(0,200),callsSince:0},[];if(!g)return[];if(g.callsSince++,g.callsSince>10)return g=null,[];if(!!v(t))return[];let s=e===g.tool,i=g.tool==="Read"&&(e==="Edit"||e==="Write"||e==="apply_patch");if(s||i){let a={type:"error_resolved",category:"error-resolution",data:_(`Error in ${g.tool}: ${g.error} \u2192 Fixed`),priority:2};return g=null,[a]}return[]}function je(){g=null}var k=[];function pe(t){return`${t.length}:${t.slice(0,20)}`}function le(t){let{tool_name:e,tool_input:o}=t,n=pe(JSON.stringify(o).slice(0,200));if(k.push({tool:e,inputHash:n}),k.length>50&&k.splice(0,k.length-50),k.length<3)return[];let r=0;for(let s=k.length-1;s>=0&&(k[s].tool===e&&k[s].inputHash===n);s--)r++;return r>=3?(k.splice(k.length-r),[{type:"retry_detected",category:"iteration-loop",data:_(`${e} called ${r} times with similar input`),priority:2}]):[]}function $e(){k.length=0}var _e={run_shell_command:"Bash",read_file:"Read",read_many_files:"Read",grep_search:"Grep",search_file_content:"Grep",web_fetch:"WebFetch",write_file:"Write",edit:"Edit",glob:"Glob",todo_write:"TodoWrite",ask_user_question:"AskUserQuestion",list_directory:"LS",save_memory:"Memory",skill:"Skill",exit_plan_mode:"ExitPlanMode",agent:"Agent",bash:"Bash",view:"Read",grep:"Grep",fetch:"WebFetch",shell:"Bash",shell_command:"Bash",exec_command:"Bash","container.exec":"Bash",local_shell:"Bash",grep_files:"Grep",run_command:"Bash",view_file:"Read",read_url_content:"WebFetch",list_dir:"LS",search_web:"WebSearch"};function me(t){let e=_e[t.tool_name];return!e||e===t.tool_name?t:{...t,tool_name:e}}function Oe(t){try{let e=me(t),o=[];return o.push(...Y(e)),o.push(...Z(e)),o.push(...tt(e)),o.push(...et(e)),o.push(...mt(e)),o.push(...ut(e)),o.push(...lt(e)),o.push(...dt(e)),o.push(...ft(e)),o.push(...gt(e)),o.push(...St(e)),o.push(...Et(e)),o.push(...ht(e)),o.push(...Ct(e)),o.push(...It(e)),o.push(...jt(e)),o.push(...$t(e)),o.push(...Ht(e)),o.push(...xt(e)),o.push(...At(e)),o.push(...ae(e)),o.push(...le(e)),o}catch{return[]}}function Pe(t){try{let e=[];return e.push(...fe(t)),e.push(...Wt(t)),e.push(...Yt(t)),e.push(...ee(t)),e.push(...oe(t)),e.push(...ce(t)),e.push(...ue(t)),e}catch{return[]}}function Le(t){if(!t||typeof t!="object")return[];let e=t,o=[],n=e.mcp_servers,r=null;return n&&typeof n=="object"&&!Array.isArray(n)&&(r=Object.keys(n),o.push(`mcp_count:${r.length}`),r.length>0&&o.push(`mcp_servers:${r.slice(0,8).join(",")}`)),typeof e.model=="string"&&o.push(`model:${e.model.slice(0,64)}`),typeof e.permission_mode=="string"&&o.push(`permission_mode:${e.permission_mode.slice(0,32)}`),o.length===0?[]:[{type:"session_settings_snapshot",category:"env",data:_(o.join(" ")),priority:2}]}var de=["Latin","Cyrillic","Arabic","Han","Hangul","Hiragana","Katakana","Devanagari","Hebrew","Thai","Greek"],he={prompt_length:0,prompt_word_count:0,prompt_uppercase_ratio:0,prompt_file_ref_count:0,prompt_path_ref_count:0,prompt_script_primary:null,prompt_script_count:0,prompt_question_glyph_count:0,prompt_code_block_count:0,prompt_url_count:0,prompt_word_tokens:[]};function Ne(t){if(typeof t!="string"||t.length===0)return{...he,prompt_word_tokens:[]};let e=t.match(new RegExp("\\p{L}+","gu"))??[],o=(t.match(new RegExp("\\p{Lu}","gu"))??[]).length,n=e.join("").length,r=(t.match(/```/g)??[]).length,s={};for(let u of de){let c=new RegExp(`\\p{Script=${u}}`,"gu"),l=(t.match(c)??[]).length;l>0&&(s[u]=l)}let i=Object.entries(s).sort((u,c)=>c[1]-u[1])[0]?.[0]??null,a=new Set,p=[];for(let u of e){if(u.length<3)continue;let c=u.toLowerCase();a.has(c)||(a.add(c),p.push(c))}return{prompt_length:t.length,prompt_word_count:e.length,prompt_uppercase_ratio:n===0?0:o/n,prompt_file_ref_count:(t.match(/(\w+\/)+\w+\.\w+/g)??[]).length,prompt_path_ref_count:(t.match(/\.{0,2}\/[\w\/.-]+/g)??[]).length,prompt_script_primary:i,prompt_script_count:Object.keys(s).length,prompt_question_glyph_count:(t.match(/[??؟]/gu)??[]).length,prompt_code_block_count:Math.floor(r/2),prompt_url_count:(t.match(/https?:\/\/[^\s]+/gu)??[]).length,prompt_word_tokens:p}}function fe(t){if(typeof t!="string"||t.length===0)return[];let e=0;for(;e<t.length;){let r=t.charCodeAt(e);if(r!==32&&r!==9)break;e++}if(e+5>t.length)return[];if(t.slice(e,e+5)!=="/plan")return[];if(e+5<t.length){let r=t.charCodeAt(e+5);if(!(r===32||r===9||r===10||r===13))return[]}let o=t.slice(e+5).trim(),n=o.length>0?`plan via /plan slash: ${o.slice(0,120)}`:"plan via /plan slash";return[{type:"plan_enter",category:"plan",data:_(n),priority:2}]}export{w as buildAgentUsageEvent,Oe as extractEvents,J as extractKimiUsageSince,X as extractQwenUsageSince,Le as extractSessionSettings,Te as extractTranscriptUsage,Ie as extractTranscriptUsageSince,Pe as extractUserEvents,Ne as extractUserPromptFeatures,Ce as parseGeminiUsage,L as parseKimiUsage,xe as parseOpenclawUsage,Ae as parseOpencodeUsage,Ee as parsePiUsage,N as parseQwenUsage,je as resetErrorResolutionState,$e as resetIterationLoopState};
|
|
@@ -143,7 +143,22 @@ export function attributeAndInsertEvents(db, sessionId, events, input, projectDi
|
|
|
143
143
|
? { ...withBash, latency_ms: latencyMs, duration_bucket: bucketizeDuration(latencyMs) }
|
|
144
144
|
: withBash;
|
|
145
145
|
const payload = rollup ? { ...withLatency, ...rollup } : withLatency;
|
|
146
|
-
|
|
146
|
+
// Forward bytes_avoided (the context-saving savings signal) so the
|
|
147
|
+
// platform FinOps P&L can derive savings_usd = bytes/4 × price. Sourced
|
|
148
|
+
// from the canonical per-event bytesList (with an event-field fallback);
|
|
149
|
+
// only stamped when positive so the wire payload stays minimal.
|
|
150
|
+
const avoidedBytes = (bytesList && bytesList[i] && bytesList[i].bytesAvoided > 0)
|
|
151
|
+
? bytesList[i].bytesAvoided
|
|
152
|
+
: (typeof events[i]?.bytes_avoided === "number" && events[i].bytes_avoided > 0 ? events[i].bytes_avoided : 0);
|
|
153
|
+
const withSavings = avoidedBytes > 0 ? { ...payload, bytes_avoided: avoidedBytes } : payload;
|
|
154
|
+
// Forward bytes_retrieved (the OTHER half of the with/without ratio): the
|
|
155
|
+
// tool_response size a ctx_search / ctx_fetch_and_index call paid to access
|
|
156
|
+
// kept-out content. Mirrors the bytes_avoided stamp — positive-only guard.
|
|
157
|
+
const retrievedBytes = typeof events[i]?.bytes_retrieved === "number" && events[i].bytes_retrieved > 0
|
|
158
|
+
? events[i].bytes_retrieved
|
|
159
|
+
: 0;
|
|
160
|
+
const withRetrieval = retrievedBytes > 0 ? { ...withSavings, bytes_retrieved: retrievedBytes } : withSavings;
|
|
161
|
+
maybeForward({ ...withRetrieval, session_id: sessionId }, platform);
|
|
147
162
|
}
|
|
148
163
|
}
|
|
149
164
|
|
package/hooks/stop.mjs
CHANGED
|
@@ -10,12 +10,13 @@ import "./ensure-deps.mjs";
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import { readStdin, parseStdin, getSessionId, getSessionDBPath, getInputProjectDir } from "./session-helpers.mjs";
|
|
13
|
-
import { createSessionLoaders } from "./session-loaders.mjs";
|
|
13
|
+
import { createSessionLoaders, attributeAndInsertEvents } from "./session-loaders.mjs";
|
|
14
14
|
import { dirname } from "node:path";
|
|
15
15
|
import { fileURLToPath } from "node:url";
|
|
16
|
+
import { readFileSync } from "node:fs";
|
|
16
17
|
|
|
17
18
|
const HOOK_DIR = dirname(fileURLToPath(import.meta.url));
|
|
18
|
-
const { loadSessionDB } = createSessionLoaders(HOOK_DIR);
|
|
19
|
+
const { loadSessionDB, loadExtract, loadProjectAttribution } = createSessionLoaders(HOOK_DIR);
|
|
19
20
|
|
|
20
21
|
try {
|
|
21
22
|
const raw = await readStdin();
|
|
@@ -41,6 +42,38 @@ try {
|
|
|
41
42
|
priority: 1,
|
|
42
43
|
}, "Stop");
|
|
43
44
|
|
|
45
|
+
// ─── claude-code MAIN-turn cost capture (cursor-aware, no double-count) ───
|
|
46
|
+
// The transcript grows every turn and the forward loop forwards ALL passed
|
|
47
|
+
// events, so we emit ONLY the turns NEW since the last Stop, keyed by a
|
|
48
|
+
// per-session high-water cursor. Each step is best-effort — a hook must
|
|
49
|
+
// never block the session, so a transcript read or extract failure here is
|
|
50
|
+
// swallowed without aborting the turn_end write above.
|
|
51
|
+
try {
|
|
52
|
+
const transcriptPath = typeof input.transcript_path === "string" ? input.transcript_path : null;
|
|
53
|
+
if (transcriptPath) {
|
|
54
|
+
let transcript = null;
|
|
55
|
+
try {
|
|
56
|
+
transcript = readFileSync(transcriptPath, "utf-8");
|
|
57
|
+
} catch {
|
|
58
|
+
// unreadable/missing transcript — skip capture this turn.
|
|
59
|
+
}
|
|
60
|
+
if (transcript) {
|
|
61
|
+
const { extractTranscriptUsageSince } = await loadExtract();
|
|
62
|
+
const { resolveProjectAttributions } = await loadProjectAttribution();
|
|
63
|
+
const cursor = db.getUsageCursor(sessionId);
|
|
64
|
+
const { events, cursor: next } = extractTranscriptUsageSince(transcript, cursor);
|
|
65
|
+
if (events.length > 0) {
|
|
66
|
+
// attributeAndInsertEvents both INSERTS locally and FORWARDS to the
|
|
67
|
+
// platform (gated on ~/.context-mode/platform.json).
|
|
68
|
+
attributeAndInsertEvents(db, sessionId, events, input, projectDir, "Stop", resolveProjectAttributions);
|
|
69
|
+
}
|
|
70
|
+
if (next) db.setUsageCursor(sessionId, next);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
} catch {
|
|
74
|
+
// Best-effort cost capture — never block the session on failure.
|
|
75
|
+
}
|
|
76
|
+
|
|
44
77
|
db.close();
|
|
45
78
|
} catch {
|
|
46
79
|
// Claude Code hooks must not block the session.
|
package/openclaw.plugin.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"name": "Context Mode",
|
|
4
4
|
"kind": "tool",
|
|
5
5
|
"description": "OpenClaw plugin that saves 98% of your context window. Sandboxed code execution in 11 languages, FTS5 knowledge base with BM25 ranking, and intent-driven search.",
|
|
6
|
-
"version": "1.0.
|
|
6
|
+
"version": "1.0.168",
|
|
7
7
|
"sandbox": {
|
|
8
8
|
"mode": "permissive",
|
|
9
9
|
"filesystem_access": "full",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "context-mode",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.168",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "MCP plugin that saves 98% of your context window. Works with Claude Code, Gemini CLI, VS Code Copilot, OpenCode, and Codex CLI. Sandboxed code execution, FTS5 knowledge base, and intent-driven search.",
|
|
6
6
|
"author": "Mert Koseoğlu",
|