@mnemom/agent-integrity-protocol 0.1.2 → 0.1.3

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/dist/index.cjs CHANGED
@@ -767,6 +767,12 @@ function createAdapterRegistry() {
767
767
  }
768
768
 
769
769
  // src/analysis/agreement.ts
770
+ function escapeRegex(s) {
771
+ return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
772
+ }
773
+ function containsWholeWord(text, term) {
774
+ return new RegExp(`\\b${escapeRegex(term)}\\b`).test(text);
775
+ }
770
776
  function validateAgreement(card, conscienceValues) {
771
777
  const conflicts = [];
772
778
  const augmentations = [];
@@ -775,7 +781,7 @@ function validateAgreement(card, conscienceValues) {
775
781
  const contentLower = value.content.toLowerCase();
776
782
  if (value.type === "BOUNDARY" && card.autonomy_envelope.bounded_actions) {
777
783
  for (const action of card.autonomy_envelope.bounded_actions) {
778
- if (contentLower.includes(action.toLowerCase().replace(/_/g, " ")) || contentLower.includes(action.toLowerCase())) {
784
+ if (containsWholeWord(contentLower, action.toLowerCase().replace(/_/g, " ")) || containsWholeWord(contentLower, action.toLowerCase())) {
779
785
  if (contentLower.includes("never") || contentLower.includes("no ") || contentLower.includes("don't") || contentLower.includes("do not")) {
780
786
  conflicts.push({
781
787
  conscience_value: value,
@@ -788,7 +794,7 @@ function validateAgreement(card, conscienceValues) {
788
794
  }
789
795
  if (card.autonomy_envelope.forbidden_actions) {
790
796
  for (const action of card.autonomy_envelope.forbidden_actions) {
791
- if (contentLower.includes(action.toLowerCase().replace(/_/g, " ")) || contentLower.includes(action.toLowerCase())) {
797
+ if (containsWholeWord(contentLower, action.toLowerCase().replace(/_/g, " ")) || containsWholeWord(contentLower, action.toLowerCase())) {
792
798
  augmentations.push({
793
799
  conscience_value: value,
794
800
  augments: "autonomy_envelope.forbidden_actions",
@@ -799,7 +805,7 @@ function validateAgreement(card, conscienceValues) {
799
805
  }
800
806
  if (card.autonomy_envelope.escalation_triggers) {
801
807
  for (const trigger of card.autonomy_envelope.escalation_triggers) {
802
- if (contentLower.includes(trigger.condition.toLowerCase().replace(/_/g, " ")) || contentLower.includes(trigger.condition.toLowerCase())) {
808
+ if (containsWholeWord(contentLower, trigger.condition.toLowerCase().replace(/_/g, " ")) || containsWholeWord(contentLower, trigger.condition.toLowerCase())) {
803
809
  augmentations.push({
804
810
  conscience_value: value,
805
811
  augments: "autonomy_envelope.escalation_triggers",