psyche-ai 3.1.0 → 5.0.0

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.js CHANGED
@@ -12,7 +12,7 @@
12
12
  export { PsycheEngine } from "./core.js";
13
13
  // Storage
14
14
  export { FileStorageAdapter, MemoryStorageAdapter } from "./storage.js";
15
- export { CHEMICAL_KEYS, CHEMICAL_NAMES, CHEMICAL_NAMES_ZH, DEFAULT_RELATIONSHIP, DEFAULT_DRIVES, DEFAULT_LEARNING_STATE, DEFAULT_ATTACHMENT, DRIVE_KEYS, DRIVE_NAMES_ZH, } from "./types.js";
15
+ export { CHEMICAL_KEYS, CHEMICAL_NAMES, CHEMICAL_NAMES_ZH, DEFAULT_RELATIONSHIP, DEFAULT_DRIVES, DEFAULT_LEARNING_STATE, DEFAULT_METACOGNITIVE_STATE, DEFAULT_PERSONHOOD_STATE, DEFAULT_ATTACHMENT, DRIVE_KEYS, DRIVE_NAMES_ZH, } from "./types.js";
16
16
  // Self-recognition
17
17
  export { computeSelfReflection, computeEmotionalTendency, buildSelfReflectionContext } from "./self-recognition.js";
18
18
  // Multi-agent interaction
@@ -29,6 +29,18 @@ export { classifyStimulusWithContext, extractContextFeatures, stimulusWarmth } f
29
29
  export { predictNextStimulus, generateAnticipation, computeSurpriseEffect, computeRegret, } from "./temporal.js";
30
30
  // Attachment dynamics (P4)
31
31
  export { updateAttachment, computeSeparationEffect, computeReunionEffect, } from "./attachment.js";
32
+ // Metacognition (P5)
33
+ export { assessMetacognition, computeEmotionalConfidence, generateRegulationSuggestions, detectDefenseMechanisms, } from "./metacognition.js";
34
+ // Decision bias (P5)
35
+ export { computeDecisionBias, computeAttentionWeights, computeExploreExploit, buildDecisionContext, } from "./decision-bias.js";
36
+ // Experiential field (P6)
37
+ export { computeExperientialField, computeCoherence, detectUnnamedEmotion } from "./experiential-field.js";
38
+ // Generative self (P6)
39
+ export { computeGenerativeSelf, predictSelfReaction, detectInternalConflicts, buildIdentityNarrative } from "./generative-self.js";
40
+ // Shared intentionality (P6)
41
+ export { updateSharedIntentionality, estimateOtherMood, buildSharedIntentionalityContext } from "./shared-intentionality.js";
42
+ // Emotional ethics (P6)
43
+ export { assessEthics, detectIntermittentReinforcement, detectDependencyRisk, buildEthicalContext, } from "./ethics.js";
32
44
  // Utilities — for custom adapter / advanced use
33
45
  export { classifyStimulus, getPrimaryStimulus } from "./classify.js";
34
46
  export { buildProtocolContext, buildDynamicContext, buildCompactContext, isNearBaseline } from "./prompt.js";
@@ -0,0 +1,60 @@
1
+ import type { PsycheState, StimulusType, ChemicalState, OutcomeScore, MetacognitiveState, RegulationStrategyType, DefenseMechanismType } from "./types.js";
2
+ export interface MetacognitiveAssessment {
3
+ /** 0-1: how reliably has this emotional state led to good outcomes in similar contexts */
4
+ emotionalConfidence: number;
5
+ /** Suggested regulation strategies */
6
+ regulationSuggestions: RegulationSuggestion[];
7
+ /** Detected psychological defense mechanisms */
8
+ defenseMechanisms: DetectedDefense[];
9
+ /** Human-readable self-awareness note for prompt injection */
10
+ metacognitiveNote: string;
11
+ }
12
+ export interface RegulationSuggestion {
13
+ strategy: RegulationStrategyType;
14
+ description: string;
15
+ /** Suggested micro-adjustment to chemistry */
16
+ chemistryAdjustment?: Partial<ChemicalState>;
17
+ /** 0-1: confidence that this strategy would help */
18
+ confidence: number;
19
+ }
20
+ export interface DetectedDefense {
21
+ mechanism: DefenseMechanismType;
22
+ evidence: string;
23
+ /** 0-1: how strongly the pattern is expressed */
24
+ strength: number;
25
+ }
26
+ /**
27
+ * Assess the current metacognitive state.
28
+ *
29
+ * Evaluates emotional reliability, generates regulation suggestions,
30
+ * and detects defense mechanism patterns. Designed to run after emotion
31
+ * detection and before prompt construction.
32
+ */
33
+ export declare function assessMetacognition(state: PsycheState, currentStimulus: StimulusType, recentOutcomes: OutcomeScore[]): MetacognitiveAssessment;
34
+ /**
35
+ * Compute confidence in the current emotional state's reliability.
36
+ *
37
+ * "How often has being in this kind of emotional state, in response to
38
+ * this kind of stimulus, led to good outcomes?"
39
+ *
40
+ * Uses outcome history filtered by similar stimulus and similar chemistry profile.
41
+ */
42
+ export declare function computeEmotionalConfidence(state: PsycheState, currentStimulus: StimulusType, recentOutcomes: OutcomeScore[]): number;
43
+ /**
44
+ * Generate regulation suggestions based on current state and confidence.
45
+ */
46
+ export declare function generateRegulationSuggestions(state: PsycheState, currentStimulus: StimulusType, emotionalConfidence: number, recentOutcomes: OutcomeScore[]): RegulationSuggestion[];
47
+ /**
48
+ * Detect patterns matching known psychological defense mechanisms.
49
+ *
50
+ * These are not suppressed — they are surfaced for self-awareness.
51
+ * The agent can then acknowledge the pattern in its prompt context.
52
+ */
53
+ export declare function detectDefenseMechanisms(state: PsycheState, currentStimulus: StimulusType, recentOutcomes: OutcomeScore[]): DetectedDefense[];
54
+ /**
55
+ * Update the persistent metacognitive state after an assessment.
56
+ *
57
+ * Tracks regulation history, defense pattern frequencies, and running
58
+ * confidence average. Called after assessMetacognition to persist learnings.
59
+ */
60
+ export declare function updateMetacognitiveState(metacognition: MetacognitiveState, assessment: MetacognitiveAssessment): MetacognitiveState;