-
Notifications
You must be signed in to change notification settings - Fork 0
feat: pre-edit guardrails + session summarization (#116) #116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -200,6 +200,40 @@ async function handleSessionStart(ctx, input) { | |
| } | ||
| } | ||
|
|
||
| // Trigger summarization of recent unsummarized sessions (fire-and-forget). | ||
| // Stop hook doesn't fire reliably (CC bug #19225), so we summarize here instead. | ||
| // Limited to 1 session per start to avoid flooding the LLM. | ||
| if (dbSessionId) { | ||
| try { | ||
| const sessionsResp = await lib.requestGet('/api/sessions/list?limit=5', 3000); | ||
| const sessions = sessionsResp && Array.isArray(sessionsResp.sessions) | ||
| ? sessionsResp.sessions | ||
| : []; | ||
|
|
||
| for (const sess of sessions) { | ||
| if (!sess || typeof sess.id !== 'number') continue; | ||
| // Skip current session | ||
| if (sess.id === dbSessionId) continue; | ||
| // Skip empty sessions (0 prompts) | ||
| if (typeof sess.prompt_counter === 'number' && sess.prompt_counter === 0) continue; | ||
| // Skip sessions that already have a summary | ||
| if (sess.summary && typeof sess.summary === 'string' && sess.summary.length > 0) continue; | ||
|
|
||
| // Fire-and-forget summarization (5s timeout) | ||
| lib.requestPost(`/api/sessions/${sess.id}/summarize`, { | ||
| lastUserMessage: '', | ||
| lastAssistant: '', | ||
| }, 5000).catch((err) => { | ||
| console.error(`[engram] session ${sess.id} summarize failed: ${err.message}`); | ||
| }); | ||
| console.error(`[engram] Triggered summarization for session ${sess.id}`); | ||
| break; // Only 1 per session-start | ||
| } | ||
|
Comment on lines
+213
to
+231
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The const sessionToSummarize = sessions.find(sess => {
if (!sess || typeof sess.id !== 'number') return false;
// Skip current session
if (sess.id === dbSessionId) return false;
// Skip empty sessions (0 prompts)
if (typeof sess.prompt_counter === 'number' && sess.prompt_counter === 0) return false;
// Skip sessions that already have a summary
if (sess.summary && typeof sess.summary === 'string' && sess.summary.length > 0) return false;
return true;
});
if (sessionToSummarize) {
// Fire-and-forget summarization (5s timeout)
lib.requestPost(`/api/sessions/${sessionToSummarize.id}/summarize`, {
lastUserMessage: '',
lastAssistant: '',
}, 5000).catch((err) => {
console.error(`[engram] session ${sessionToSummarize.id} summarize failed: ${err.message}`);
});
console.error(`[engram] Triggered summarization for session ${sessionToSummarize.id}`);
} |
||
| } catch (err) { | ||
| console.error(`[engram] Unsummarized session check failed: ${err.message}`); | ||
| } | ||
| } | ||
|
|
||
| return contextBuilder; | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's significant code duplication in how
warningsandcontextObsare formatted and added to thecontextstring. This can be refactored into a single helper function to improve maintainability and reduce redundancy. Usingmap()can also make the code more concise.