diff --git a/plugin/scripts/context-hook.js b/plugin/scripts/context-hook.js index 80e10048..8fbddd4a 100755 --- a/plugin/scripts/context-hook.js +++ b/plugin/scripts/context-hook.js @@ -249,5 +249,5 @@ ${i.bright}${i.cyan}\u{1F4DD} Recent Session Context${i.reset} ${i.dim}No previous sessions found for this project yet.${i.reset} `:`# Recent Session Context -No previous sessions found for this project yet.`;let s=[];e?(s.push(""),s.push(`${i.bright}${i.cyan}\u{1F4DD} Recent Session Context${i.reset}`),s.push(`${i.gray}${"\u2500".repeat(60)}${i.reset}`),s.push(`${i.dim}Showing last ${a.length} session(s) for ${i.reset}${i.bright}${t}${i.reset}`),s.push("")):(s.push("# Recent Session Context"),s.push(""),s.push(`Showing last ${a.length} session(s) for **${t}**:`),s.push(""));for(let d of a)if(d.sdk_session_id){if(e?(s.push(`${i.gray}${"\u2500".repeat(60)}${i.reset}`),s.push("")):(s.push("---"),s.push("")),d.has_summary){let o=n.getSummaryForSession(d.sdk_session_id);if(o){let m=o.prompt_number?` (Prompt #${o.prompt_number})`:"";e?(s.push(`${i.bright}${i.green}\u2713 Summary${m}${i.reset}`),s.push("")):(s.push(`**Summary${m}**`),s.push("")),o.request&&(e?(s.push(`${i.bright}${i.yellow}Request:${i.reset} ${o.request}`),s.push("")):s.push(`**Request:** ${o.request}`)),o.completed&&(e?(s.push(`${i.bright}${i.green}Completed:${i.reset} ${o.completed}`),s.push("")):s.push(`**Completed:** ${o.completed}`)),o.learned&&(e?(s.push(`${i.bright}${i.blue}Learned:${i.reset} ${o.learned}`),s.push("")):s.push(`**Learned:** ${o.learned}`)),o.next_steps&&(e?(s.push(`${i.bright}${i.magenta}Next Steps:${i.reset} ${o.next_steps}`),s.push("")):s.push(`**Next Steps:** ${o.next_steps}`));let c=n.getFilesForSession(d.sdk_session_id);c.filesRead.length>0&&(e?s.push(`${i.dim}Files Read: ${c.filesRead.join(", ")}${i.reset}`):s.push(`**Files Read:** ${c.filesRead.join(", ")}`)),c.filesModified.length>0&&(e?s.push(`${i.dim}Files Modified: ${c.filesModified.join(", ")}${i.reset}`):s.push(`**Files Modified:** ${c.filesModified.join(", ")}`));let E=new Date(o.created_at).toLocaleString();e?s.push(`${i.dim}Date: ${E}${i.reset}`):s.push(`**Date:** ${E}`)}}else if(d.status==="active"){e?(s.push(`${i.bright}${i.yellow}\u23F3 In Progress${i.reset}`),s.push("")):(s.push("**In Progress**"),s.push("")),d.user_prompt&&(e?(s.push(`${i.bright}${i.yellow}Request:${i.reset} ${d.user_prompt}`),s.push("")):s.push(`**Request:** ${d.user_prompt}`));let o=n.getObservationsForSession(d.sdk_session_id);if(o.length>0)if(s.push(""),e){s.push(`${i.bright}Observations (${o.length}):${i.reset}`);for(let c of o)s.push(` ${i.dim}\u2022${i.reset} ${c.title}`);s.push("")}else{s.push(`**Observations (${o.length}):**`);for(let c of o)s.push(`- ${c.title}`)}else s.push(""),e?(s.push(`${i.dim}No observations yet${i.reset}`),s.push("")):s.push("*No observations yet*");s.push("");let m=new Date(d.started_at).toLocaleString();e?(s.push(`${i.dim}Status: Active - summary pending${i.reset}`),s.push(`${i.dim}Date: ${m}${i.reset}`)):(s.push("**Status:** Active - summary pending"),s.push(`**Date:** ${m}`))}else{let o=d.status==="failed"?"stopped":d.status,m=d.status==="failed"?"\u26A0\uFE0F":"\u25CB";if(e){let E=d.status==="failed"?i.yellow:i.gray;s.push(`${i.bright}${E}${m} ${o.charAt(0).toUpperCase()+o.slice(1)}${i.reset}`),s.push("")}else s.push(`**${o.charAt(0).toUpperCase()+o.slice(1)}**`),s.push("");d.user_prompt&&(e?(s.push(`${i.bright}${i.yellow}Request:${i.reset} ${d.user_prompt}`),s.push("")):s.push(`**Request:** ${d.user_prompt}`)),s.push("");let c=new Date(d.started_at).toLocaleString();e?(s.push(`${i.dim}Status: ${o} - no summary available${i.reset}`),s.push(`${i.dim}Date: ${c}${i.reset}`)):(s.push(`**Status:** ${o} - no summary available`),s.push(`**Date:** ${c}`))}e||s.push("")}return e&&(s.push(""),s.push(`${i.gray}${"\u2500".repeat(60)}${i.reset}`),s.push("")),s.join(` +No previous sessions found for this project yet.`;let s=[];e?(s.push(""),s.push(`${i.bright}${i.cyan}\u{1F4DD} Recent Session Context${i.reset}`),s.push(`${i.gray}${"\u2500".repeat(60)}${i.reset}`),s.push(`${i.dim}Showing last ${a.length} session(s) for ${i.reset}${i.bright}${t}${i.reset}`),s.push("")):(s.push("# Recent Session Context"),s.push(""),s.push(`Showing last ${a.length} session(s) for **${t}**:`),s.push(""));for(let d of a)if(d.sdk_session_id){if(e?(s.push(`${i.gray}${"\u2500".repeat(60)}${i.reset}`),s.push("")):(s.push("---"),s.push("")),d.has_summary){let o=n.getSummaryForSession(d.sdk_session_id);if(o){let m=o.prompt_number?` (Prompt #${o.prompt_number})`:"";e?(s.push(`${i.bright}${i.green}\u2713 Summary${m}${i.reset}`),s.push("")):(s.push(`**Summary${m}**`),s.push("")),o.request&&(e?(s.push(`${i.bright}${i.yellow}Request:${i.reset} ${o.request}`),s.push("")):s.push(`**Request:** ${o.request}`)),o.learned&&(e?(s.push(`${i.bright}${i.blue}Learned:${i.reset} ${o.learned}`),s.push("")):s.push(`**Learned:** ${o.learned}`)),o.completed&&(e?(s.push(`${i.bright}${i.green}Completed:${i.reset} ${o.completed}`),s.push("")):s.push(`**Completed:** ${o.completed}`)),o.next_steps&&(e?(s.push(`${i.bright}${i.magenta}Next Steps:${i.reset} ${o.next_steps}`),s.push("")):s.push(`**Next Steps:** ${o.next_steps}`));let c=n.getFilesForSession(d.sdk_session_id);c.filesRead.length>0&&(e?s.push(`${i.dim}Files Read: ${c.filesRead.join(", ")}${i.reset}`):s.push(`**Files Read:** ${c.filesRead.join(", ")}`)),c.filesModified.length>0&&(e?s.push(`${i.dim}Files Modified: ${c.filesModified.join(", ")}${i.reset}`):s.push(`**Files Modified:** ${c.filesModified.join(", ")}`));let E=new Date(o.created_at).toLocaleString();e?s.push(`${i.dim}Date: ${E}${i.reset}`):s.push(`**Date:** ${E}`)}}else if(d.status==="active"){e?(s.push(`${i.bright}${i.yellow}\u23F3 In Progress${i.reset}`),s.push("")):(s.push("**In Progress**"),s.push("")),d.user_prompt&&(e?(s.push(`${i.bright}${i.yellow}Request:${i.reset} ${d.user_prompt}`),s.push("")):s.push(`**Request:** ${d.user_prompt}`));let o=n.getObservationsForSession(d.sdk_session_id);if(o.length>0)if(s.push(""),e){s.push(`${i.bright}Observations (${o.length}):${i.reset}`);for(let c of o)s.push(` ${i.dim}\u2022${i.reset} ${c.title}`);s.push("")}else{s.push(`**Observations (${o.length}):**`);for(let c of o)s.push(`- ${c.title}`)}else s.push(""),e?(s.push(`${i.dim}No observations yet${i.reset}`),s.push("")):s.push("*No observations yet*");s.push("");let m=new Date(d.started_at).toLocaleString();e?(s.push(`${i.dim}Status: Active - summary pending${i.reset}`),s.push(`${i.dim}Date: ${m}${i.reset}`)):(s.push("**Status:** Active - summary pending"),s.push(`**Date:** ${m}`))}else{let o=d.status==="failed"?"stopped":d.status,m=d.status==="failed"?"\u26A0\uFE0F":"\u25CB";if(e){let E=d.status==="failed"?i.yellow:i.gray;s.push(`${i.bright}${E}${m} ${o.charAt(0).toUpperCase()+o.slice(1)}${i.reset}`),s.push("")}else s.push(`**${o.charAt(0).toUpperCase()+o.slice(1)}**`),s.push("");d.user_prompt&&(e?(s.push(`${i.bright}${i.yellow}Request:${i.reset} ${d.user_prompt}`),s.push("")):s.push(`**Request:** ${d.user_prompt}`)),s.push("");let c=new Date(d.started_at).toLocaleString();e?(s.push(`${i.dim}Status: ${o} - no summary available${i.reset}`),s.push(`${i.dim}Date: ${c}${i.reset}`)):(s.push(`**Status:** ${o} - no summary available`),s.push(`**Date:** ${c}`))}e||s.push("")}return e&&(s.push(""),s.push(`${i.gray}${"\u2500".repeat(60)}${i.reset}`),s.push("")),s.join(` `)}finally{n.close()}}import{stdin as N}from"process";try{if(N.isTTY){let p=S(void 0,!0);console.log(p),process.exit(0)}else{let p="";N.on("data",e=>p+=e),N.on("end",()=>{let e=p.trim()?JSON.parse(p):void 0,t={hookSpecificOutput:{hookEventName:"SessionStart",additionalContext:S(e,!1)}};console.log(JSON.stringify(t)),process.exit(0)})}}catch(p){console.error(`[claude-mem context-hook error: ${p.message}]`),process.exit(0)} diff --git a/src/hooks/context.ts b/src/hooks/context.ts index 8bebd51a..90009429 100644 --- a/src/hooks/context.ts +++ b/src/hooks/context.ts @@ -98,15 +98,6 @@ export function contextHook(input?: SessionStartInput, useColors: boolean = fals } } - if (summary.completed) { - if (useColors) { - output.push(`${colors.bright}${colors.green}Completed:${colors.reset} ${summary.completed}`); - output.push(''); - } else { - output.push(`**Completed:** ${summary.completed}`); - } - } - if (summary.learned) { if (useColors) { output.push(`${colors.bright}${colors.blue}Learned:${colors.reset} ${summary.learned}`); @@ -116,6 +107,15 @@ export function contextHook(input?: SessionStartInput, useColors: boolean = fals } } + if (summary.completed) { + if (useColors) { + output.push(`${colors.bright}${colors.green}Completed:${colors.reset} ${summary.completed}`); + output.push(''); + } else { + output.push(`**Completed:** ${summary.completed}`); + } + } + if (summary.next_steps) { if (useColors) { output.push(`${colors.bright}${colors.magenta}Next Steps:${colors.reset} ${summary.next_steps}`);