@byte5ai/palaia 2.0.11 → 2.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/hooks.ts +40 -3
package/package.json
CHANGED
package/src/hooks.ts
CHANGED
|
@@ -892,9 +892,15 @@ export async function extractWithLLM(
|
|
|
892
892
|
}
|
|
893
893
|
|
|
894
894
|
const allTexts = extractMessageTexts(messages);
|
|
895
|
+
// Strip Palaia-injected recall context from user messages to prevent feedback loop
|
|
896
|
+
const cleanedTexts = allTexts.map(t =>
|
|
897
|
+
t.role === "user"
|
|
898
|
+
? { ...t, text: stripPalaiaInjectedContext(t.text) }
|
|
899
|
+
: t
|
|
900
|
+
);
|
|
895
901
|
// Only extract from recent exchanges — full history causes LLM timeouts
|
|
896
902
|
// and dilutes extraction quality
|
|
897
|
-
const recentTexts = trimToRecentExchanges(
|
|
903
|
+
const recentTexts = trimToRecentExchanges(cleanedTexts);
|
|
898
904
|
const exchangeText = recentTexts
|
|
899
905
|
.map((t) => `[${t.role}]: ${t.text}`)
|
|
900
906
|
.join("\n");
|
|
@@ -1103,6 +1109,24 @@ export function extractSignificance(
|
|
|
1103
1109
|
return { tags, type: primaryType, summary };
|
|
1104
1110
|
}
|
|
1105
1111
|
|
|
1112
|
+
/**
|
|
1113
|
+
* Strip Palaia-injected recall context from message text.
|
|
1114
|
+
* The recall block is prepended to user messages by before_prompt_build via prependContext.
|
|
1115
|
+
* OpenClaw merges it into the user message, so agent_end sees it as user content.
|
|
1116
|
+
* Without stripping, auto-capture re-captures the injected memories → feedback loop.
|
|
1117
|
+
*
|
|
1118
|
+
* The block has a stable structure:
|
|
1119
|
+
* - Starts with "## Active Memory (Palaia)"
|
|
1120
|
+
* - Contains [t/m], [t/pr], [t/tk] prefixed entries
|
|
1121
|
+
* - Ends with "[palaia] auto-capture=on..." nudge line
|
|
1122
|
+
*/
|
|
1123
|
+
export function stripPalaiaInjectedContext(text: string): string {
|
|
1124
|
+
// Pattern: "## Active Memory (Palaia)" ... "[palaia] auto-capture=on..." + optional trailing newlines
|
|
1125
|
+
// The nudge line is always present and marks the end of the injected block
|
|
1126
|
+
const PALAIA_BLOCK_RE = /## Active Memory \(Palaia\)[\s\S]*?\[palaia\][^\n]*\n*/;
|
|
1127
|
+
return text.replace(PALAIA_BLOCK_RE, '').trim();
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1106
1130
|
export function extractMessageTexts(messages: unknown[]): Array<{ role: string; text: string; provenance?: string }> {
|
|
1107
1131
|
const result: Array<{ role: string; text: string; provenance?: string }> = [];
|
|
1108
1132
|
|
|
@@ -1232,7 +1256,11 @@ function isSystemOnlyContent(text: string): boolean {
|
|
|
1232
1256
|
* - Hard-caps at 500 characters.
|
|
1233
1257
|
*/
|
|
1234
1258
|
export function buildRecallQuery(messages: unknown[]): string {
|
|
1235
|
-
const texts = extractMessageTexts(messages)
|
|
1259
|
+
const texts = extractMessageTexts(messages).map(t =>
|
|
1260
|
+
t.role === "user"
|
|
1261
|
+
? { ...t, text: stripPalaiaInjectedContext(t.text) }
|
|
1262
|
+
: t
|
|
1263
|
+
);
|
|
1236
1264
|
|
|
1237
1265
|
// Step 1: Filter out inter_session messages (sub-agent results, sessions_send)
|
|
1238
1266
|
const candidates = texts.filter(
|
|
@@ -1709,9 +1737,18 @@ export function registerHooks(api: any, config: PalaiaPluginConfig): void {
|
|
|
1709
1737
|
collectedHints.push(...hints);
|
|
1710
1738
|
}
|
|
1711
1739
|
|
|
1740
|
+
// Strip Palaia-injected recall context from user messages to prevent feedback loop.
|
|
1741
|
+
// The recall block is prepended to user messages by before_prompt_build.
|
|
1742
|
+
// Without stripping, auto-capture would re-capture previously recalled memories.
|
|
1743
|
+
const cleanedTexts = allTexts.map(t =>
|
|
1744
|
+
t.role === "user"
|
|
1745
|
+
? { ...t, text: stripPalaiaInjectedContext(t.text) }
|
|
1746
|
+
: t
|
|
1747
|
+
);
|
|
1748
|
+
|
|
1712
1749
|
// Only extract from recent exchanges — full history causes LLM timeouts
|
|
1713
1750
|
// and dilutes extraction quality
|
|
1714
|
-
const recentTexts = trimToRecentExchanges(
|
|
1751
|
+
const recentTexts = trimToRecentExchanges(cleanedTexts);
|
|
1715
1752
|
|
|
1716
1753
|
// Build exchange text from recent window only
|
|
1717
1754
|
const exchangeParts: string[] = [];
|