@promptbook/cli 0.112.0-30 → 0.112.0-31

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/esm/index.es.js CHANGED
@@ -57,7 +57,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
57
57
  * @generated
58
58
  * @see https://github.com/webgptorg/promptbook
59
59
  */
60
- const PROMPTBOOK_ENGINE_VERSION = '0.112.0-30';
60
+ const PROMPTBOOK_ENGINE_VERSION = '0.112.0-31';
61
61
  /**
62
62
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
63
63
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -47749,6 +47749,7 @@ class SelfLearningManager {
47749
47749
 
47750
47750
  - Decide what the agent should learn from this interaction.
47751
47751
  - Append new commitments at the end of the agent source.
47752
+ - Return only newly learned commitments, never repeat commitments that are already present.
47752
47753
  - Do not modify the current agent source, just return new commitments (KNOWLEDGE, RULE, etc.).
47753
47754
  - If there is nothing new to learn, return empty book code block
47754
47755
  - Wrap the commitments in a book code block.
@@ -47801,10 +47802,42 @@ class SelfLearningManager {
47801
47802
  */
47802
47803
  appendToAgentSource(section) {
47803
47804
  const currentSource = this.options.getAgentSource();
47804
- const newSource = padBook(validateBook(spaceTrim$1(currentSource) + section));
47805
+ const normalizedSection = normalizeBookSection(section);
47806
+ if (!normalizedSection) {
47807
+ return;
47808
+ }
47809
+ if (containsNormalizedBookSection(currentSource, normalizedSection)) {
47810
+ return;
47811
+ }
47812
+ const newSource = padBook(validateBook(`${normalizeBookSection(currentSource)}\n\n${normalizedSection}`));
47805
47813
  this.options.updateAgentSource(newSource);
47806
47814
  }
47807
47815
  }
47816
+ /**
47817
+ * Normalizes one book fragment for deduplication and append composition.
47818
+ *
47819
+ * @param section Raw fragment from self-learning workflow.
47820
+ * @returns Trimmed fragment, or empty string when nothing remains.
47821
+ * @private function of Agent
47822
+ */
47823
+ function normalizeBookSection(section) {
47824
+ return spaceTrim$1(section).replace(/\r\n/g, '\n');
47825
+ }
47826
+ /**
47827
+ * Checks whether one normalized fragment already exists inside the current source.
47828
+ *
47829
+ * @param agentSource Current source.
47830
+ * @param normalizedSection Candidate fragment expected to be normalized first.
47831
+ * @returns True when appending would duplicate an existing fragment.
47832
+ * @private function of Agent
47833
+ */
47834
+ function containsNormalizedBookSection(agentSource, normalizedSection) {
47835
+ if (!normalizedSection) {
47836
+ return true;
47837
+ }
47838
+ const normalizedSource = normalizeBookSection(agentSource);
47839
+ return normalizedSource.includes(normalizedSection);
47840
+ }
47808
47841
  /**
47809
47842
  * Determines whether the interaction runs in OpenAI-compatible JSON schema mode.
47810
47843
  *