From 676a3d175e3bda00cfced04baf0769474ad2a8b3 Mon Sep 17 00:00:00 2001 From: Alex Newman Date: Mon, 16 Feb 2026 00:11:25 -0500 Subject: [PATCH] fix: make context and colored timeline fetches truly parallel Address PR #1125 review feedback - both fetches now start simultaneously via Promise.all instead of sequential-then-parallel. Co-Authored-By: Claude Opus 4.6 --- plugin/scripts/worker-service.cjs | 4 ++-- src/cli/handlers/context.ts | 11 +++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/plugin/scripts/worker-service.cjs b/plugin/scripts/worker-service.cjs index cdc9dd1c..1aacd59b 100755 --- a/plugin/scripts/worker-service.cjs +++ b/plugin/scripts/worker-service.cjs @@ -800,9 +800,9 @@ ${Y.gray}${"\u2500".repeat(60)}${Y.reset} ${Y.dim}No previous sessions found for this project yet.${Y.reset} `}var Iu=Ae(()=>{"use strict";Kd();Hr();lo()});function w9(t,e,r,n){let i=[];return n?i.push(...l9(t)):i.push(...JF(t)),n?i.push(...p9()):i.push(...XF()),n?i.push(...d9()):i.push(...YF()),n?i.push(...m9()):i.push(...QF()),Xv(r)&&(n?i.push(...f9(e,r)):i.push(...e9(e,r))),i}var E9=Ae(()=>{"use strict";lo();Tu();Iu()});function Rye(t){let e=new Map;for(let n of t){let i=n.type==="observation"?n.data.created_at:n.data.displayTime,a=da(i);e.has(a)||e.set(a,[]),e.get(a).push(n)}let r=Array.from(e.entries()).sort((n,i)=>{let a=new Date(n[0]).getTime(),s=new Date(i[0]).getTime();return a-s});return new Map(r)}function Cye(t,e){return e.fullObservationField==="narrative"?t.narrative:t.facts?rv(t.facts).join(` `):null}function Pye(t,e,r,n,i,a){let s=[];a?s.push(...h9(t)):s.push(...t9(t));let o=null,c="",u=!1;for(let l of e)if(l.type==="summary"){u&&(s.push(""),u=!1,o=null,c="");let p=l.data,d=Zn(p.displayTime);a?s.push(...b9(p,d)):s.push(...a9(p,d))}else{let p=l.data,d=di(p.files_modified,i,p.files_read),m=br(p.created_at),f=m!==c,h=f?m:"";c=m;let g=r.has(p.id);if(d!==o&&(u&&s.push(""),a?s.push(...g9(d)):s.push(...r9(d)),o=d,u=!0),g){let v=Cye(p,n);a?s.push(...y9(p,m,f,v,n)):(u&&!a&&(s.push(""),u=!1),s.push(...i9(p,h,v,n)),o=null)}else a?s.push(v9(p,m,f,n)):s.push(n9(p,h,n))}return u&&s.push(""),s}function k9(t,e,r,n,i){let a=[],s=Rye(t);for(let[o,c]of s)a.push(...Pye(o,c,e,r,n,i));return a}var $9=Ae(()=>{"use strict";eo();Tu();Iu()});function T9(t,e,r){return!(!t.showLastSummary||!e||!!!(e.investigated||e.learned||e.completed||e.next_steps)||r&&e.created_at_epoch<=r.created_at_epoch)}function I9(t,e){let r=[];return e?(r.push(...Xd("Investigated",t.investigated,Y.blue)),r.push(...Xd("Learned",t.learned,Y.yellow)),r.push(...Xd("Completed",t.completed,Y.green)),r.push(...Xd("Next Steps",t.next_steps,Y.magenta))):(r.push(...Jd("Investigated",t.investigated)),r.push(...Jd("Learned",t.learned)),r.push(...Jd("Completed",t.completed)),r.push(...Jd("Next Steps",t.next_steps))),r}var O9=Ae(()=>{"use strict";Kd();Tu();Iu()});function R9(t,e){return e?_9(t):s9(t)}function C9(t,e,r){return!Xv(e)||t.totalDiscoveryTokens<=0||t.savings<=0?[]:r?x9(t.totalDiscoveryTokens,t.totalReadTokens):o9(t.totalDiscoveryTokens,t.totalReadTokens)}var P9=Ae(()=>{"use strict";lo();Tu();Iu()});function Nye(){try{return new Xa}catch(t){if(t.code==="ERR_DLOPEN_FAILED"){try{(0,j9.unlinkSync)(Aye)}catch(e){_.debug("SYSTEM","Marker file cleanup failed (may not exist)",{},e)}return _.error("SYSTEM","Native module rebuild needed - restart Claude Code to auto-fix"),null}throw t}}function jye(t,e){return e?S9(t):c9(t)}function Mye(t,e,r,n,i,a,s){let o=[],c=lT(e);o.push(...w9(t,c,n,s));let u=r.slice(0,n.sessionCount),l=GF(u,r),p=fT(e,l),d=WF(e,n.fullObservationCount);o.push(...k9(p,d,n,i,s));let m=r[0],f=e[0];T9(n,m,f)&&o.push(...I9(m,s));let h=mT(e,n,a,i);return o.push(...R9(h,s)),o.push(...C9(c,n,s)),o.join(` -`).trimEnd()}async function gT(t,e=!1){let r=sT(),n=t?.cwd??process.cwd(),i=Wd(n),a=t?.projects||[i],s=Nye();if(!s)return"";try{let o=a.length>1?BF(s,a,r):pT(s,i,r),c=a.length>1?VF(s,a,r):dT(s,i,r);return o.length===0&&c.length===0?jye(i,e):Mye(i,o,c,r,n,t?.session_id,e)}finally{s.close()}}var A9,N9,j9,Aye,M9=Ae(()=>{"use strict";A9=Ne(require("path"),1),N9=require("os"),j9=require("fs");Pg();he();Jv();oT();lo();hT();E9();$9();O9();P9();Tu();Iu();Aye=A9.default.join((0,N9.homedir)(),".claude","plugins","marketplaces","thedotmack","plugin",".install-version")});var D9=Ae(()=>{"use strict";M9();oT();lo();hT()});var vT={};mn(vT,{generateContext:()=>gT});var yT=Ae(()=>{"use strict";D9()});function zye(){try{let t=process.stdin;return t.isTTY?!1:(t.readable,!0)}catch{return!1}}function Uye(t){let e=t.trim();if(!e)return{success:!1};try{return{success:!0,value:JSON.parse(e)}}catch{return{success:!1}}}async function F9(){if(zye())return new Promise((t,e)=>{let r="",n=!1,i=null,a=()=>{try{process.stdin.removeAllListeners("data"),process.stdin.removeAllListeners("end"),process.stdin.removeAllListeners("error")}catch{}},s=l=>{n||(n=!0,i&&clearTimeout(i),clearTimeout(u),a(),t(l))},o=l=>{n||(n=!0,i&&clearTimeout(i),clearTimeout(u),a(),e(l))},c=()=>{let l=Uye(r);return l.success?(s(l.value),!0):!1},u=setTimeout(()=>{n||c()||(r.trim()?o(new Error(`Incomplete JSON after ${q9}ms: ${r.slice(0,100)}...`)):s(void 0))},q9);try{process.stdin.on("data",l=>{r+=l,i&&(clearTimeout(i),i=null),!c()&&(i=setTimeout(()=>{c()},Lye))}),process.stdin.on("end",()=>{n||c()||s((r.trim(),void 0))}),process.stdin.on("error",()=>{n||s(void 0)})}catch{n=!0,clearTimeout(u),a(),t(void 0)}})}var q9,Lye,Z9=Ae(()=>{"use strict";q9=3e4,Lye=50});var H9,B9=Ae(()=>{"use strict";H9={normalizeInput(t){let e=t??{};return{sessionId:e.session_id,cwd:e.cwd??process.cwd(),prompt:e.prompt,toolName:e.tool_name,toolInput:e.tool_input,toolResponse:e.tool_response,transcriptPath:e.transcript_path}},formatOutput(t){if(t.hookSpecificOutput){let e={hookSpecificOutput:t.hookSpecificOutput};return t.systemMessage&&(e.systemMessage=t.systemMessage),e}return{continue:t.continue??!0,suppressOutput:t.suppressOutput??!0}}}});var V9,G9=Ae(()=>{"use strict";V9={normalizeInput(t){let e=t??{},r=!!e.command&&!e.tool_name;return{sessionId:e.conversation_id||e.generation_id,cwd:e.workspace_roots?.[0]??process.cwd(),prompt:e.prompt,toolName:r?"Bash":e.tool_name,toolInput:r?{command:e.command}:e.tool_input,toolResponse:r?{output:e.output}:e.result_json,transcriptPath:void 0,filePath:e.file_path,edits:e.edits}},formatOutput(t){return{continue:t.continue??!0}}}});var W9,K9=Ae(()=>{"use strict";W9={normalizeInput(t){let e=t;return{sessionId:e.sessionId??e.session_id??"unknown",cwd:e.cwd??process.cwd(),prompt:e.prompt,toolName:e.toolName??e.tool_name,toolInput:e.toolInput??e.tool_input,toolResponse:e.toolResponse??e.tool_response,transcriptPath:e.transcriptPath??e.transcript_path,filePath:e.filePath??e.file_path,edits:e.edits}},formatOutput(t){return t}}});function J9(t){switch(t){case"claude-code":return H9;case"cursor":return V9;case"raw":return W9;default:throw new Error(`Unknown platform: ${t}`)}}var X9=Ae(()=>{"use strict";B9();G9();K9()});var wT,ET=Ae(()=>{"use strict";qr();Jv();An();he();wT={async execute(t){if(!await en())return{hookSpecificOutput:{hookEventName:"SessionStart",additionalContext:""},exitCode:dt.SUCCESS};let r=t.cwd??process.cwd(),n=LF(r),i=gt(),a=n.allProjects.join(","),s=`http://127.0.0.1:${i}/api/context/inject?projects=${encodeURIComponent(a)}`;try{let o=await fetch(s);if(!o.ok)return _.warn("HOOK","Context generation failed, returning empty",{status:o.status}),{hookSpecificOutput:{hookEventName:"SessionStart",additionalContext:""},exitCode:dt.SUCCESS};let c=`${s}&colors=true`,[u,l]=await Promise.all([o.text(),fetch(c).then(f=>f.ok?f.text():"").catch(()=>"")]),p=u.trim(),d=l.trim(),m=d?`${d} +`).trimEnd()}async function gT(t,e=!1){let r=sT(),n=t?.cwd??process.cwd(),i=Wd(n),a=t?.projects||[i],s=Nye();if(!s)return"";try{let o=a.length>1?BF(s,a,r):pT(s,i,r),c=a.length>1?VF(s,a,r):dT(s,i,r);return o.length===0&&c.length===0?jye(i,e):Mye(i,o,c,r,n,t?.session_id,e)}finally{s.close()}}var A9,N9,j9,Aye,M9=Ae(()=>{"use strict";A9=Ne(require("path"),1),N9=require("os"),j9=require("fs");Pg();he();Jv();oT();lo();hT();E9();$9();O9();P9();Tu();Iu();Aye=A9.default.join((0,N9.homedir)(),".claude","plugins","marketplaces","thedotmack","plugin",".install-version")});var D9=Ae(()=>{"use strict";M9();oT();lo();hT()});var vT={};mn(vT,{generateContext:()=>gT});var yT=Ae(()=>{"use strict";D9()});function zye(){try{let t=process.stdin;return t.isTTY?!1:(t.readable,!0)}catch{return!1}}function Uye(t){let e=t.trim();if(!e)return{success:!1};try{return{success:!0,value:JSON.parse(e)}}catch{return{success:!1}}}async function F9(){if(zye())return new Promise((t,e)=>{let r="",n=!1,i=null,a=()=>{try{process.stdin.removeAllListeners("data"),process.stdin.removeAllListeners("end"),process.stdin.removeAllListeners("error")}catch{}},s=l=>{n||(n=!0,i&&clearTimeout(i),clearTimeout(u),a(),t(l))},o=l=>{n||(n=!0,i&&clearTimeout(i),clearTimeout(u),a(),e(l))},c=()=>{let l=Uye(r);return l.success?(s(l.value),!0):!1},u=setTimeout(()=>{n||c()||(r.trim()?o(new Error(`Incomplete JSON after ${q9}ms: ${r.slice(0,100)}...`)):s(void 0))},q9);try{process.stdin.on("data",l=>{r+=l,i&&(clearTimeout(i),i=null),!c()&&(i=setTimeout(()=>{c()},Lye))}),process.stdin.on("end",()=>{n||c()||s((r.trim(),void 0))}),process.stdin.on("error",()=>{n||s(void 0)})}catch{n=!0,clearTimeout(u),a(),t(void 0)}})}var q9,Lye,Z9=Ae(()=>{"use strict";q9=3e4,Lye=50});var H9,B9=Ae(()=>{"use strict";H9={normalizeInput(t){let e=t??{};return{sessionId:e.session_id,cwd:e.cwd??process.cwd(),prompt:e.prompt,toolName:e.tool_name,toolInput:e.tool_input,toolResponse:e.tool_response,transcriptPath:e.transcript_path}},formatOutput(t){if(t.hookSpecificOutput){let e={hookSpecificOutput:t.hookSpecificOutput};return t.systemMessage&&(e.systemMessage=t.systemMessage),e}return{continue:t.continue??!0,suppressOutput:t.suppressOutput??!0}}}});var V9,G9=Ae(()=>{"use strict";V9={normalizeInput(t){let e=t??{},r=!!e.command&&!e.tool_name;return{sessionId:e.conversation_id||e.generation_id,cwd:e.workspace_roots?.[0]??process.cwd(),prompt:e.prompt,toolName:r?"Bash":e.tool_name,toolInput:r?{command:e.command}:e.tool_input,toolResponse:r?{output:e.output}:e.result_json,transcriptPath:void 0,filePath:e.file_path,edits:e.edits}},formatOutput(t){return{continue:t.continue??!0}}}});var W9,K9=Ae(()=>{"use strict";W9={normalizeInput(t){let e=t;return{sessionId:e.sessionId??e.session_id??"unknown",cwd:e.cwd??process.cwd(),prompt:e.prompt,toolName:e.toolName??e.tool_name,toolInput:e.toolInput??e.tool_input,toolResponse:e.toolResponse??e.tool_response,transcriptPath:e.transcriptPath??e.transcript_path,filePath:e.filePath??e.file_path,edits:e.edits}},formatOutput(t){return t}}});function J9(t){switch(t){case"claude-code":return H9;case"cursor":return V9;case"raw":return W9;default:throw new Error(`Unknown platform: ${t}`)}}var X9=Ae(()=>{"use strict";B9();G9();K9()});var wT,ET=Ae(()=>{"use strict";qr();Jv();An();he();wT={async execute(t){if(!await en())return{hookSpecificOutput:{hookEventName:"SessionStart",additionalContext:""},exitCode:dt.SUCCESS};let r=t.cwd??process.cwd(),n=LF(r),i=gt(),a=n.allProjects.join(","),s=`http://127.0.0.1:${i}/api/context/inject?projects=${encodeURIComponent(a)}`;try{let o=`${s}&colors=true`,[c,u]=await Promise.all([fetch(s),fetch(o).catch(()=>null)]);if(!c.ok)return _.warn("HOOK","Context generation failed, returning empty",{status:c.status}),{hookSpecificOutput:{hookEventName:"SessionStart",additionalContext:""},exitCode:dt.SUCCESS};let[l,p]=await Promise.all([c.text(),u?.ok?u.text():Promise.resolve("")]),d=l.trim(),m=p.trim(),f=m?`${m} -View Observations Live @ http://localhost:${i}`:void 0;return{hookSpecificOutput:{hookEventName:"SessionStart",additionalContext:p},systemMessage:m}}catch(o){return _.warn("HOOK","Context fetch error, returning empty",{error:o instanceof Error?o.message:String(o)}),{hookSpecificOutput:{hookEventName:"SessionStart",additionalContext:""},exitCode:dt.SUCCESS}}}}});function qye(t){let e=t.startsWith("~")?(0,Y9.homedir)()+t.slice(1):t;e=e.replace(/\\/g,"/");let r=e.replace(/[.+^${}()|[\]\\]/g,"\\$&");return r=r.replace(/\*\*/g,"<<>>").replace(/\*/g,"[^/]*").replace(/\?/g,"[^/]").replace(/<<>>/g,".*"),new RegExp(`^${r}$`)}function cy(t,e){if(!e||!e.trim())return!1;let r=t.replace(/\\/g,"/"),n=e.split(",").map(i=>i.trim()).filter(Boolean);for(let i of n)try{if(qye(i).test(r))return!0}catch{continue}return!1}var Y9,kT=Ae(()=>{"use strict";Y9=require("os")});var $T,TT=Ae(()=>{"use strict";qr();Jv();he();An();kT();ar();Wt();$T={async execute(t){if(!await en())return{continue:!0,suppressOutput:!0,exitCode:dt.SUCCESS};let{sessionId:r,cwd:n,prompt:i}=t,a=Re.loadFromFile(or);if(n&&cy(n,a.CLAUDE_MEM_EXCLUDED_PROJECTS))return _.info("HOOK","Project excluded from tracking",{cwd:n}),{continue:!0,suppressOutput:!0};let s=!i||!i.trim()?"[media prompt]":i,o=Wd(n),c=gt();_.debug("HOOK","session-init: Calling /api/sessions/init",{contentSessionId:r,project:o});let u=await fetch(`http://127.0.0.1:${c}/api/sessions/init`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({contentSessionId:r,project:o,prompt:s})});if(!u.ok)return _.failure("HOOK",`Session initialization failed: ${u.status}`,{contentSessionId:r,project:o}),{continue:!0,suppressOutput:!0,exitCode:dt.SUCCESS};let l=await u.json(),p=l.sessionDbId,d=l.promptNumber;if(_.debug("HOOK","session-init: Received from /api/sessions/init",{sessionDbId:p,promptNumber:d,skipped:l.skipped}),_.debug("HOOK",`[ALIGNMENT] Hook Entry | contentSessionId=${r} | prompt#=${d} | sessionDbId=${p}`),l.skipped&&l.reason==="private")return _.info("HOOK",`INIT_COMPLETE | sessionDbId=${p} | promptNumber=${d} | skipped=true | reason=private`,{sessionId:p}),{continue:!0,suppressOutput:!0};if(t.platform!=="cursor"&&p){let m=s.startsWith("/")?s.substring(1):s;_.debug("HOOK","session-init: Calling /sessions/{sessionDbId}/init",{sessionDbId:p,promptNumber:d});let f=await fetch(`http://127.0.0.1:${c}/sessions/${p}/init`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({userPrompt:m,promptNumber:d})});f.ok||_.failure("HOOK",`SDK agent start failed: ${f.status}`,{sessionDbId:p,promptNumber:d})}else t.platform==="cursor"&&_.debug("HOOK","session-init: Skipping SDK agent init for Cursor platform",{sessionDbId:p,promptNumber:d});return _.info("HOOK",`INIT_COMPLETE | sessionDbId=${p} | promptNumber=${d} | project=${o}`,{sessionId:p}),{continue:!0,suppressOutput:!0}}}});var IT,OT=Ae(()=>{"use strict";qr();he();An();kT();ar();Wt();IT={async execute(t){if(!await en())return{continue:!0,suppressOutput:!0,exitCode:dt.SUCCESS};let{sessionId:r,cwd:n,toolName:i,toolInput:a,toolResponse:s}=t;if(!i)throw new Error("observationHandler requires toolName");let o=gt(),c=_.formatTool(i,a);if(_.dataIn("HOOK",`PostToolUse: ${c}`,{workerPort:o}),!n)throw new Error(`Missing cwd in PostToolUse hook input for session ${r}, tool ${i}`);let u=Re.loadFromFile(or);if(cy(n,u.CLAUDE_MEM_EXCLUDED_PROJECTS))return _.debug("HOOK","Project excluded from tracking, skipping observation",{cwd:n,toolName:i}),{continue:!0,suppressOutput:!0};try{let l=await fetch(`http://127.0.0.1:${o}/api/sessions/observations`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({contentSessionId:r,tool_name:i,tool_input:a,tool_response:s,cwd:n})});if(!l.ok)return _.warn("HOOK","Observation storage failed, skipping",{status:l.status,toolName:i}),{continue:!0,suppressOutput:!0,exitCode:dt.SUCCESS};_.debug("HOOK","Observation sent successfully",{toolName:i})}catch(l){return _.warn("HOOK","Observation fetch error, skipping",{error:l instanceof Error?l.message:String(l)}),{continue:!0,suppressOutput:!0,exitCode:dt.SUCCESS}}return{continue:!0,suppressOutput:!0}}}});function Q9(t,e,r=!1){if(!t||!(0,uy.existsSync)(t))throw new Error(`Transcript path missing or file does not exist: ${t}`);let n=(0,uy.readFileSync)(t,"utf-8").trim();if(!n)throw new Error(`Transcript file exists but is empty: ${t}`);let i=n.split(` +View Observations Live @ http://localhost:${i}`:void 0;return{hookSpecificOutput:{hookEventName:"SessionStart",additionalContext:d},systemMessage:f}}catch(o){return _.warn("HOOK","Context fetch error, returning empty",{error:o instanceof Error?o.message:String(o)}),{hookSpecificOutput:{hookEventName:"SessionStart",additionalContext:""},exitCode:dt.SUCCESS}}}}});function qye(t){let e=t.startsWith("~")?(0,Y9.homedir)()+t.slice(1):t;e=e.replace(/\\/g,"/");let r=e.replace(/[.+^${}()|[\]\\]/g,"\\$&");return r=r.replace(/\*\*/g,"<<>>").replace(/\*/g,"[^/]*").replace(/\?/g,"[^/]").replace(/<<>>/g,".*"),new RegExp(`^${r}$`)}function cy(t,e){if(!e||!e.trim())return!1;let r=t.replace(/\\/g,"/"),n=e.split(",").map(i=>i.trim()).filter(Boolean);for(let i of n)try{if(qye(i).test(r))return!0}catch{continue}return!1}var Y9,kT=Ae(()=>{"use strict";Y9=require("os")});var $T,TT=Ae(()=>{"use strict";qr();Jv();he();An();kT();ar();Wt();$T={async execute(t){if(!await en())return{continue:!0,suppressOutput:!0,exitCode:dt.SUCCESS};let{sessionId:r,cwd:n,prompt:i}=t,a=Re.loadFromFile(or);if(n&&cy(n,a.CLAUDE_MEM_EXCLUDED_PROJECTS))return _.info("HOOK","Project excluded from tracking",{cwd:n}),{continue:!0,suppressOutput:!0};let s=!i||!i.trim()?"[media prompt]":i,o=Wd(n),c=gt();_.debug("HOOK","session-init: Calling /api/sessions/init",{contentSessionId:r,project:o});let u=await fetch(`http://127.0.0.1:${c}/api/sessions/init`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({contentSessionId:r,project:o,prompt:s})});if(!u.ok)return _.failure("HOOK",`Session initialization failed: ${u.status}`,{contentSessionId:r,project:o}),{continue:!0,suppressOutput:!0,exitCode:dt.SUCCESS};let l=await u.json(),p=l.sessionDbId,d=l.promptNumber;if(_.debug("HOOK","session-init: Received from /api/sessions/init",{sessionDbId:p,promptNumber:d,skipped:l.skipped}),_.debug("HOOK",`[ALIGNMENT] Hook Entry | contentSessionId=${r} | prompt#=${d} | sessionDbId=${p}`),l.skipped&&l.reason==="private")return _.info("HOOK",`INIT_COMPLETE | sessionDbId=${p} | promptNumber=${d} | skipped=true | reason=private`,{sessionId:p}),{continue:!0,suppressOutput:!0};if(t.platform!=="cursor"&&p){let m=s.startsWith("/")?s.substring(1):s;_.debug("HOOK","session-init: Calling /sessions/{sessionDbId}/init",{sessionDbId:p,promptNumber:d});let f=await fetch(`http://127.0.0.1:${c}/sessions/${p}/init`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({userPrompt:m,promptNumber:d})});f.ok||_.failure("HOOK",`SDK agent start failed: ${f.status}`,{sessionDbId:p,promptNumber:d})}else t.platform==="cursor"&&_.debug("HOOK","session-init: Skipping SDK agent init for Cursor platform",{sessionDbId:p,promptNumber:d});return _.info("HOOK",`INIT_COMPLETE | sessionDbId=${p} | promptNumber=${d} | project=${o}`,{sessionId:p}),{continue:!0,suppressOutput:!0}}}});var IT,OT=Ae(()=>{"use strict";qr();he();An();kT();ar();Wt();IT={async execute(t){if(!await en())return{continue:!0,suppressOutput:!0,exitCode:dt.SUCCESS};let{sessionId:r,cwd:n,toolName:i,toolInput:a,toolResponse:s}=t;if(!i)throw new Error("observationHandler requires toolName");let o=gt(),c=_.formatTool(i,a);if(_.dataIn("HOOK",`PostToolUse: ${c}`,{workerPort:o}),!n)throw new Error(`Missing cwd in PostToolUse hook input for session ${r}, tool ${i}`);let u=Re.loadFromFile(or);if(cy(n,u.CLAUDE_MEM_EXCLUDED_PROJECTS))return _.debug("HOOK","Project excluded from tracking, skipping observation",{cwd:n,toolName:i}),{continue:!0,suppressOutput:!0};try{let l=await fetch(`http://127.0.0.1:${o}/api/sessions/observations`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({contentSessionId:r,tool_name:i,tool_input:a,tool_response:s,cwd:n})});if(!l.ok)return _.warn("HOOK","Observation storage failed, skipping",{status:l.status,toolName:i}),{continue:!0,suppressOutput:!0,exitCode:dt.SUCCESS};_.debug("HOOK","Observation sent successfully",{toolName:i})}catch(l){return _.warn("HOOK","Observation fetch error, skipping",{error:l instanceof Error?l.message:String(l)}),{continue:!0,suppressOutput:!0,exitCode:dt.SUCCESS}}return{continue:!0,suppressOutput:!0}}}});function Q9(t,e,r=!1){if(!t||!(0,uy.existsSync)(t))throw new Error(`Transcript path missing or file does not exist: ${t}`);let n=(0,uy.readFileSync)(t,"utf-8").trim();if(!n)throw new Error(`Transcript file exists but is empty: ${t}`);let i=n.split(` `),a=!1;for(let s=i.length-1;s>=0;s--){let o=JSON.parse(i[s]);if(o.type===e&&(a=!0,o.message?.content)){let c="",u=o.message.content;if(typeof u=="string")c=u;else if(Array.isArray(u))c=u.filter(l=>l.type==="text").map(l=>l.text).join(` `);else throw new Error(`Unknown message content format in transcript. Type: ${typeof u}`);return r&&(c=c.replace(/[\s\S]*?<\/system-reminder>/g,""),c=c.replace(/\n{3,}/g,` diff --git a/src/cli/handlers/context.ts b/src/cli/handlers/context.ts index aeea2df4..a373b8f5 100644 --- a/src/cli/handlers/context.ts +++ b/src/cli/handlers/context.ts @@ -37,7 +37,12 @@ export const contextHandler: EventHandler = { // Note: Removed AbortSignal.timeout due to Windows Bun cleanup issue (libuv assertion) // Worker service has its own timeouts, so client-side timeout is redundant try { - const response = await fetch(url); + // Fetch both markdown (for Claude context) and colored (for user display) truly in parallel + const colorUrl = `${url}&colors=true`; + const [response, colorResponse] = await Promise.all([ + fetch(url), + fetch(colorUrl).catch(() => null) + ]); if (!response.ok) { // Log but don't throw — context fetch failure should not block session start @@ -48,11 +53,9 @@ export const contextHandler: EventHandler = { }; } - // Fetch both markdown (for Claude context) and colored (for user display) in parallel - const colorUrl = `${url}&colors=true`; const [contextResult, colorResult] = await Promise.all([ response.text(), - fetch(colorUrl).then(r => r.ok ? r.text() : '').catch(() => '') + colorResponse?.ok ? colorResponse.text() : Promise.resolve('') ]); const additionalContext = contextResult.trim();