agenr 0.7.8 → 0.7.9

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.
@@ -624,46 +624,8 @@ async function ensurePluginDb(config) {
624
624
  var plugin = {
625
625
  id: "agenr",
626
626
  name: "agenr memory context",
627
- description: "Injects agenr long-term memory into every agent session via before_agent_start",
627
+ description: "Injects agenr long-term memory into every agent session via before_prompt_build",
628
628
  register(api) {
629
- api.on(
630
- "before_agent_start",
631
- async (_event, ctx) => {
632
- try {
633
- const sessionKey = ctx.sessionKey ?? "";
634
- const dedupeKey = ctx.sessionId ?? sessionKey;
635
- if (shouldSkipSession(sessionKey)) {
636
- return;
637
- }
638
- if (dedupeKey && hasSeenSession(dedupeKey)) {
639
- return;
640
- }
641
- const config = api.pluginConfig;
642
- if (config?.enabled === false) {
643
- return;
644
- }
645
- if (dedupeKey) {
646
- markSessionSeen(dedupeKey);
647
- }
648
- const agenrPath = resolveAgenrPath(config);
649
- const budget = resolveBudget(config);
650
- const result = await runRecall(agenrPath, budget);
651
- if (!result) {
652
- return;
653
- }
654
- const markdown = formatRecallAsMarkdown(result);
655
- if (!markdown.trim()) {
656
- return;
657
- }
658
- return { prependContext: markdown };
659
- } catch (err) {
660
- api.logger.warn(
661
- `agenr plugin before_agent_start recall failed: ${err instanceof Error ? err.message : String(err)}`
662
- );
663
- return;
664
- }
665
- }
666
- );
667
629
  api.on(
668
630
  "before_prompt_build",
669
631
  async (_event, ctx) => {
@@ -679,26 +641,46 @@ var plugin = {
679
641
  if (config?.enabled === false) {
680
642
  return;
681
643
  }
682
- if (config?.signalsEnabled === false) {
683
- return;
644
+ const dedupeKey = ctx.sessionId ?? sessionKey;
645
+ let markdown;
646
+ const isFirstInSession = dedupeKey ? !hasSeenSession(dedupeKey) : true;
647
+ if (isFirstInSession) {
648
+ if (dedupeKey) {
649
+ markSessionSeen(dedupeKey);
650
+ }
651
+ const agenrPath = resolveAgenrPath(config);
652
+ const budget = resolveBudget(config);
653
+ const recallResult = await runRecall(agenrPath, budget);
654
+ if (recallResult) {
655
+ const formatted = formatRecallAsMarkdown(recallResult);
656
+ if (formatted.trim()) {
657
+ markdown = formatted;
658
+ }
659
+ }
684
660
  }
685
- const signalConfig = resolveSignalConfig(config);
686
- const db = await ensurePluginDb(config);
687
- const signal = await checkSignals(db, sessionKey, signalConfig);
688
- if (!signal) {
689
- return;
661
+ let signal;
662
+ if (config?.signalsEnabled !== false) {
663
+ const signalConfig = resolveSignalConfig(config);
664
+ const db = await ensurePluginDb(config);
665
+ const candidateSignal = await checkSignals(db, sessionKey, signalConfig);
666
+ if (candidateSignal) {
667
+ const state = sessionSignalState.get(sessionKey) ?? { lastSignalAt: 0, signalCount: 0 };
668
+ const inCooldown = signalConfig.cooldownMs > 0 && Date.now() - state.lastSignalAt < signalConfig.cooldownMs;
669
+ const overCap = signalConfig.maxPerSession > 0 && state.signalCount >= signalConfig.maxPerSession;
670
+ if (!inCooldown && !overCap) {
671
+ sessionSignalState.set(sessionKey, {
672
+ lastSignalAt: Date.now(),
673
+ signalCount: state.signalCount + 1
674
+ });
675
+ signal = candidateSignal;
676
+ }
677
+ }
690
678
  }
691
- const state = sessionSignalState.get(sessionKey) ?? { lastSignalAt: 0, signalCount: 0 };
692
- const inCooldown = signalConfig.cooldownMs > 0 && Date.now() - state.lastSignalAt < signalConfig.cooldownMs;
693
- const overCap = signalConfig.maxPerSession > 0 && state.signalCount >= signalConfig.maxPerSession;
694
- if (inCooldown || overCap) {
679
+ const prependContext = [markdown, signal].filter(Boolean).join("\n\n");
680
+ if (!prependContext) {
695
681
  return;
696
682
  }
697
- sessionSignalState.set(sessionKey, {
698
- lastSignalAt: Date.now(),
699
- signalCount: state.signalCount + 1
700
- });
701
- return { prependContext: signal };
683
+ return { prependContext };
702
684
  } catch (err) {
703
685
  api.logger.warn(
704
686
  `agenr plugin before_prompt_build signal check failed: ${err instanceof Error ? err.message : String(err)}`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agenr",
3
- "version": "0.7.8",
3
+ "version": "0.7.9",
4
4
  "openclaw": {
5
5
  "extensions": [
6
6
  "dist/openclaw-plugin/index.js"