MCPcopy Create free account
hub / github.com/ChinaSiro/claude-code-sourcemap / aLY

Function aLY

package/cli.js:6788–6847  ·  view source on GitHub ↗
(q,K)

Source from the content-addressed store, hash-verified

6786}`,Y=await OQ8({systemPrompt:iK([]),userPrompt:z,signal:new AbortController().signal,options:{model:opK(),querySource:"insights",agents:[],isNonInteractiveSession:!0,hasAppendSystemPrompt:!1,mcpTools:[],maxOutputTokensOverride:4096}}),A=L3(Y.message.content).match(/\{[\s\S]*\}/);if(!A)return null;let O=r8(A[0]);if(!tpK(O))return null;return{...O,session_id:K}}catch(_){return H6(Error(`Facet extraction failed: ${x1(_).message}`)),null}}function apK(q){let _=[];for(let w of q)for(let j of w.user_message_timestamps)try{let H=new Date(j).getTime();_.push({ts:H,sessionId:w.session_id})}catch{}_.sort((w,j)=>w.ts-j.ts);let z=new Set,Y=new Set,$=0,A=new Map;for(let w=0;w<_.length;w++){let j=_[w];while($<w&&j.ts-_[$].ts>1800000){let J=_[$];if(A.get(J.sessionId)===$)A.delete(J.sessionId);$++}let H=A.get(j.sessionId);if(H!==void 0)for(let J=H+1;J<w;J++){let M=_[J];if(M.sessionId!==j.sessionId){let X=[j.sessionId,M.sessionId].sort().join(":");z.add(X),Y.add(`${_[H].ts}:${j.sessionId}`),Y.add(`${M.ts}:${M.sessionId}`),Y.add(`${j.ts}:${j.sessionId}`);break}}A.set(j.sessionId,w)}let O=new Set;for(let w of z){let[j,H]=w.split(":");if(j)O.add(j);if(H)O.add(H)}return{overlap_events:z.size,sessions_involved:O.size,user_messages_during:Y.size}}function rLY(q,K){let _={total_sessions:q.length,sessions_with_facets:K.size,date_range:{start:"",end:""},total_messages:0,total_duration_hours:0,total_input_tokens:0,total_output_tokens:0,tool_counts:{},languages:{},git_commits:0,git_pushes:0,projects:{},goal_categories:{},outcomes:{},satisfaction:{},helpfulness:{},session_types:{},friction:{},success:{},session_summaries:[],total_interruptions:0,total_tool_errors:0,tool_error_categories:{},user_response_times:[],median_response_time:0,avg_response_time:0,sessions_using_task_agent:0,sessions_using_mcp:0,sessions_using_web_search:0,sessions_using_web_fetch:0,total_lines_added:0,total_lines_removed:0,total_files_modified:0,days_active:0,messages_per_day:0,message_hours:[],multi_clauding:{overlap_events:0,sessions_involved:0,user_messages_during:0}},z=[],Y=[],$=[];for(let O of q){z.push(O.start_time),_.total_messages+=O.user_message_count,_.total_duration_hours+=O.duration_minutes/60,_.total_input_tokens+=O.input_tokens,_.total_output_tokens+=O.output_tokens,_.git_commits+=O.git_commits,_.git_pushes+=O.git_pushes,_.total_interruptions+=O.user_interruptions,_.total_tool_errors+=O.tool_errors;for(let[j,H]of Object.entries(O.tool_error_categories))_.tool_error_categories[j]=(_.tool_error_categories[j]||0)+H;if(Y.push(...O.user_response_times),O.uses_task_agent)_.sessions_using_task_agent++;if(O.uses_mcp)_.sessions_using_mcp++;if(O.uses_web_search)_.sessions_using_web_search++;if(O.uses_web_fetch)_.sessions_using_web_fetch++;_.total_lines_added+=O.lines_added,_.total_lines_removed+=O.lines_removed,_.total_files_modified+=O.files_modified,$.push(...O.message_hours);for(let[j,H]of Object.entries(O.tool_counts))_.tool_counts[j]=(_.tool_counts[j]||0)+H;for(let[j,H]of Object.entries(O.languages))_.languages[j]=(_.languages[j]||0)+H;if(O.project_path)_.projects[O.project_path]=(_.projects[O.project_path]||0)+1;let w=K.get(O.session_id);if(w){for(let[j,H]of mS6(w.goal_categories))if(H>0)_.goal_categories[j]=(_.goal_categories[j]||0)+H;_.outcomes[w.outcome]=(_.outcomes[w.outcome]||0)+1;for(let[j,H]of mS6(w.user_satisfaction_counts))if(H>0)_.satisfaction[j]=(_.satisfaction[j]||0)+H;_.helpfulness[w.claude_helpfulness]=(_.helpfulness[w.claude_helpfulness]||0)+1,_.session_types[w.session_type]=(_.session_types[w.session_type]||0)+1;for(let[j,H]of mS6(w.friction_counts))if(H>0)_.friction[j]=(_.friction[j]||0)+H;if(w.primary_success!=="none")_.success[w.primary_success]=(_.success[w.primary_success]||0)+1}if(_.session_summaries.length<50)_.session_summaries.push({id:O.session_id.slice(0,8),date:O.start_time.split("T")[0]||"",summary:O.summary||O.first_prompt.slice(0,100),goal:w?.underlying_goal})}if(z.sort(),_.date_range.start=z[0]?.split("T")[0]||"",_.date_range.end=z[z.length-1]?.split("T")[0]||"",_.user_response_times=Y,Y.length>0){let O=[...Y].sort((w,j)=>w-j);_.median_response_time=O[Math.floor(O.length/2)]||0,_.avg_response_time=Y.reduce((w,j)=>w+j,0)/Y.length}let A=new Set(z.map((O)=>O.split("T")[0]));return _.days_active=A.size,_.messages_per_day=_.days_active>0?Math.round(_.total_messages/_.days_active*10)/10:0,_.message_hours=$,_.multi_clauding=apK(q),_}async function ipK(q,K){try{let _=await OQ8({systemPrompt:iK([]),userPrompt:q.prompt+`
6787
6788DATA:
6789`+K,signal:new AbortController().signal,options:{model:CLY(),querySource:"insights",agents:[],isNonInteractiveSession:!0,hasAppendSystemPrompt:!1,mcpTools:[],maxOutputTokensOverride:q.maxTokens}}),z=L3(_.message.content);if(z){let Y=z.match(/\{[\s\S]*\}/);if(Y)try{return{name:q.name,result:r8(Y[0])}}catch{return{name:q.name,result:null}}}return{name:q.name,result:null}}catch(_){return H6(Error(`${q.name} failed: ${x1(_).message}`)),{name:q.name,result:null}}}async function aLY(q,K){let _=Array.from(K.values()).slice(0,50).map((G)=>`- ${G.brief_summary} (${G.outcome}, ${G.claude_helpfulness})`).join(`
6790`),z=Array.from(K.values()).filter((G)=>G.friction_detail).slice(0,20).map((G)=>`- ${G.friction_detail}`).join(`
6791`),Y=Array.from(K.values()).flatMap((G)=>G.user_instructions_to_claude||[]).slice(0,15).map((G)=>`- ${G}`).join(`
6792`),A=g6({sessions:q.total_sessions,analyzed:q.sessions_with_facets,date_range:q.date_range,messages:q.total_messages,hours:Math.round(q.total_duration_hours),commits:q.git_commits,top_tools:Object.entries(q.tool_counts).sort((G,Z)=>Z[1]-G[1]).slice(0,8),top_goals:Object.entries(q.goal_categories).sort((G,Z)=>Z[1]-G[1]).slice(0,8),outcomes:q.outcomes,satisfaction:q.satisfaction,friction:q.friction,success:q.success,languages:q.languages},null,2)+`
6793
6794SESSION SUMMARIES:
6795`+_+`
6796
6797FRICTION DETAILS:
6798`+z+`
6799
6800USER INSTRUCTIONS TO CLAUDE:
6801`+(Y||"None captured"),O=await Promise.all(oLY.map((G)=>ipK(G,A))),w={};for(let{name:G,result:Z}of O)if(Z)w[G]=Z;let j=w.project_areas?.areas?.map((G)=>`- ${G.name}: ${G.description}`).join(`
6802`)||"",H=w.what_works?.impressive_workflows?.map((G)=>`- ${G.title}: ${G.description}`).join(`
6803`)||"",J=w.friction_analysis?.categories?.map((G)=>`- ${G.category}: ${G.description}`).join(`
6804`)||"",M=w.suggestions?.features_to_try?.map((G)=>`- ${G.feature}: ${G.one_liner}`).join(`
6805`)||"",X=w.suggestions?.usage_patterns?.map((G)=>`- ${G.title}: ${G.suggestion}`).join(`
6806`)||"",P=w.on_the_horizon?.opportunities?.map((G)=>`- ${G.title}: ${G.whats_possible}`).join(`
6807`)||"",D={name:"at_a_glance",prompt:`You're writing an "At a Glance" summary for a Claude Code usage insights report for Claude Code users. The goal is to help them understand their usage and improve how they can use Claude better, especially as models improve.
6808
6809Use this 4-part structure:
6810
68111. **What's working** - What is the user's unique style of interacting with Claude and what are some impactful things they've done? You can include one or two details, but keep it high level since things might not be fresh in the user's memory. Don't be fluffy or overly complimentary. Also, don't focus on the tool calls they use.
6812
68132. **What's hindering you** - Split into (a) Claude's fault (misunderstandings, wrong approaches, bugs) and (b) user-side friction (not providing enough context, environment issues -- ideally more general than just one project). Be honest but constructive.
6814
68153. **Quick wins to try** - Specific Claude Code features they could try from the examples below, or a workflow technique if you think it's really compelling. (Avoid stuff like "Ask Claude to confirm before taking actions" or "Type out more context up front" which are less compelling.)
6816
68174. **Ambitious workflows for better models** - As we move to much more capable models over the next 3-6 months, what should they prepare for? What workflows that seem impossible now will become possible? Draw from the appropriate section below.
6818
6819Keep each section to 2-3 not-too-long sentences. Don't overwhelm the user. Don't mention specific numerical stats or underlined_categories from the session data below. Use a coaching tone.
6820
6821RESPOND WITH ONLY A VALID JSON OBJECT:
6822{
6823 "whats_working": "(refer to instructions above)",
6824 "whats_hindering": "(refer to instructions above)",
6825 "quick_wins": "(refer to instructions above)",
6826 "ambitious_workflows": "(refer to instructions above)"
6827}
6828
6829SESSION DATA:
6830${A}
6831
6832## Project Areas (what user works on)
6833${j}
6834
6835## Big Wins (impressive accomplishments)
6836${H}
6837
6838## Friction Categories (where things go wrong)
6839${J}
6840
6841## Features to Try
6842${M}
6843
6844## Usage Patterns to Adopt
6845${X}

Callers 1

spKFunction · 0.85

Calls 9

g6Function · 0.85
ipKFunction · 0.85
filterMethod · 0.80
joinMethod · 0.45
sliceMethod · 0.45
fromMethod · 0.45
valuesMethod · 0.45
sortMethod · 0.45
entriesMethod · 0.45

Tested by

no test coverage detected