mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-17 05:00:16 +00:00
Add fromHook field to CompactionEntry and BranchSummaryEntry
- fromHook: true = hook generated, skip file extraction - fromHook: undefined/false = pi generated, extract files (backward compatible) - branchWithSummary now accepts fromHook parameter - File extraction only runs for !entry.fromHook entries
This commit is contained in:
parent
0445da666c
commit
f118cdc67b
3 changed files with 9 additions and 3 deletions
|
|
@ -1704,7 +1704,7 @@ export class AgentSession {
|
||||||
let summaryEntry: BranchSummaryEntry | undefined;
|
let summaryEntry: BranchSummaryEntry | undefined;
|
||||||
if (summaryText) {
|
if (summaryText) {
|
||||||
// Create summary at target position (can be null for root)
|
// Create summary at target position (can be null for root)
|
||||||
const summaryId = this.sessionManager.branchWithSummary(newLeafId, summaryText, summaryDetails);
|
const summaryId = this.sessionManager.branchWithSummary(newLeafId, summaryText, summaryDetails, fromHook);
|
||||||
summaryEntry = this.sessionManager.getEntry(summaryId) as BranchSummaryEntry;
|
summaryEntry = this.sessionManager.getEntry(summaryId) as BranchSummaryEntry;
|
||||||
} else if (newLeafId === null) {
|
} else if (newLeafId === null) {
|
||||||
// No summary, navigating to root - reset leaf
|
// No summary, navigating to root - reset leaf
|
||||||
|
|
|
||||||
|
|
@ -215,8 +215,9 @@ export function prepareBranchEntries(entries: SessionEntry[], tokenBudget: numbe
|
||||||
|
|
||||||
// First pass: collect file ops from ALL entries (even if they don't fit in token budget)
|
// First pass: collect file ops from ALL entries (even if they don't fit in token budget)
|
||||||
// This ensures we capture cumulative file tracking from nested branch summaries
|
// This ensures we capture cumulative file tracking from nested branch summaries
|
||||||
|
// Only extract from pi-generated summaries (fromHook !== true), not hook-generated ones
|
||||||
for (const entry of entries) {
|
for (const entry of entries) {
|
||||||
if (entry.type === "branch_summary" && entry.details) {
|
if (entry.type === "branch_summary" && !entry.fromHook && entry.details) {
|
||||||
const details = entry.details as BranchSummaryDetails;
|
const details = entry.details as BranchSummaryDetails;
|
||||||
if (Array.isArray(details.readFiles)) {
|
if (Array.isArray(details.readFiles)) {
|
||||||
for (const f of details.readFiles) fileOps.read.add(f);
|
for (const f of details.readFiles) fileOps.read.add(f);
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,8 @@ export interface CompactionEntry<T = unknown> extends SessionEntryBase {
|
||||||
tokensBefore: number;
|
tokensBefore: number;
|
||||||
/** Hook-specific data (e.g., ArtifactIndex, version markers for structured compaction) */
|
/** Hook-specific data (e.g., ArtifactIndex, version markers for structured compaction) */
|
||||||
details?: T;
|
details?: T;
|
||||||
|
/** True if generated by a hook, undefined/false if pi-generated (backward compatible) */
|
||||||
|
fromHook?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface BranchSummaryEntry<T = unknown> extends SessionEntryBase {
|
export interface BranchSummaryEntry<T = unknown> extends SessionEntryBase {
|
||||||
|
|
@ -72,6 +74,8 @@ export interface BranchSummaryEntry<T = unknown> extends SessionEntryBase {
|
||||||
summary: string;
|
summary: string;
|
||||||
/** Hook-specific data (not sent to LLM) */
|
/** Hook-specific data (not sent to LLM) */
|
||||||
details?: T;
|
details?: T;
|
||||||
|
/** True if generated by a hook, false if pi-generated */
|
||||||
|
fromHook?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -872,7 +876,7 @@ export class SessionManager {
|
||||||
* Same as branch(), but also appends a branch_summary entry that captures
|
* Same as branch(), but also appends a branch_summary entry that captures
|
||||||
* context from the abandoned conversation path.
|
* context from the abandoned conversation path.
|
||||||
*/
|
*/
|
||||||
branchWithSummary(branchFromId: string | null, summary: string, details?: unknown): string {
|
branchWithSummary(branchFromId: string | null, summary: string, details?: unknown, fromHook?: boolean): string {
|
||||||
if (branchFromId !== null && !this.byId.has(branchFromId)) {
|
if (branchFromId !== null && !this.byId.has(branchFromId)) {
|
||||||
throw new Error(`Entry ${branchFromId} not found`);
|
throw new Error(`Entry ${branchFromId} not found`);
|
||||||
}
|
}
|
||||||
|
|
@ -885,6 +889,7 @@ export class SessionManager {
|
||||||
fromId: branchFromId ?? "root",
|
fromId: branchFromId ?? "root",
|
||||||
summary,
|
summary,
|
||||||
details,
|
details,
|
||||||
|
fromHook,
|
||||||
};
|
};
|
||||||
this._appendEntry(entry);
|
this._appendEntry(entry);
|
||||||
return entry.id;
|
return entry.id;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue