psyche-ai 3.1.0 → 4.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/prompt.js CHANGED
@@ -15,7 +15,7 @@ import { getChannelProfile, buildChannelModifier } from "./channels.js";
15
15
  *
16
16
  * This is the "current moment" — what the agent is feeling RIGHT NOW.
17
17
  */
18
- export function buildDynamicContext(state, userId) {
18
+ export function buildDynamicContext(state, userId, opts) {
19
19
  const { current, baseline, mbti, empathyLog, selfModel, meta, agreementStreak, emotionalHistory } = state;
20
20
  const locale = meta.locale ?? "zh";
21
21
  const relationship = getRelationship(state, userId);
@@ -88,6 +88,16 @@ export function buildDynamicContext(state, userId) {
88
88
  if (reciprocity) {
89
89
  parts.push("", reciprocity);
90
90
  }
91
+ // Metacognitive awareness (P5)
92
+ if (opts?.metacognitiveNote) {
93
+ const mcTitle = locale === "zh" ? "元认知" : "Metacognition";
94
+ parts.push("", `[${mcTitle}] ${opts.metacognitiveNote}`);
95
+ }
96
+ // Decision bias context (P5)
97
+ if (opts?.decisionContext) {
98
+ const dbTitle = locale === "zh" ? "决策倾向" : "Decision Bias";
99
+ parts.push("", `[${dbTitle}] ${opts.decisionContext}`);
100
+ }
91
101
  parts.push("", agencyReminder, sycophancyWarning, "", t("dynamic.update_reminder", locale));
92
102
  return parts.filter((l) => l !== undefined).join("\n");
93
103
  }
@@ -478,7 +488,19 @@ export function buildCompactContext(state, userId, opts) {
478
488
  if (selfCtx)
479
489
  parts.push(selfCtx);
480
490
  }
481
- // 9. Cross-session emotional memory — surface relationship history
491
+ // 9. Metacognitive awareness (P5)
492
+ if (opts?.metacognitiveNote) {
493
+ parts.push(locale === "zh"
494
+ ? `[元认知] ${opts.metacognitiveNote}`
495
+ : `[Metacognition] ${opts.metacognitiveNote}`);
496
+ }
497
+ // 9b. Decision bias (P5) — only if significantly non-neutral
498
+ if (opts?.decisionContext) {
499
+ parts.push(locale === "zh"
500
+ ? `[决策倾向] ${opts.decisionContext}`
501
+ : `[Decision Bias] ${opts.decisionContext}`);
502
+ }
503
+ // 10. Cross-session emotional memory — surface relationship history
482
504
  const relationship = getRelationship(state, userId);
483
505
  if (relationship.memory && relationship.memory.length > 0) {
484
506
  const memLines = relationship.memory.slice(-3); // last 3 sessions
@@ -486,12 +508,12 @@ export function buildCompactContext(state, userId, opts) {
486
508
  ? `[记忆]\n${memLines.join("\n")}`
487
509
  : `[Memory]\n${memLines.join("\n")}`);
488
510
  }
489
- // 10. Channel modifier — expression style per platform (between memory and empathy)
511
+ // 11. Channel modifier — expression style per platform (between memory and empathy)
490
512
  if (opts?.channelType) {
491
513
  const channelProfile = getChannelProfile(opts.channelType);
492
514
  parts.push(buildChannelModifier(channelProfile, locale));
493
515
  }
494
- // 11. Empathy report — only when user shares feelings
516
+ // 12. Empathy report — only when user shares feelings
495
517
  parts.push(locale === "zh"
496
518
  ? `如果对方在分享感受,在回复末尾用 <psyche_update> 报告:\nuserState: 对方情绪\nprojectedFeeling: 你的感受\nresonance: match|partial|mismatch\n否则不需要报告。`
497
519
  : `If user shares feelings, report at end with <psyche_update>:\nuserState: their emotion\nprojectedFeeling: your feeling\nresonance: match|partial|mismatch\nOtherwise no report needed.`);
@@ -4,7 +4,7 @@
4
4
  // ============================================================
5
5
  import { readFile, writeFile, access, rename, constants } from "node:fs/promises";
6
6
  import { join } from "node:path";
7
- import { CHEMICAL_KEYS, CHEMICAL_NAMES, CHEMICAL_NAMES_ZH, DEFAULT_RELATIONSHIP, DEFAULT_DRIVES, DEFAULT_LEARNING_STATE, MAX_EMOTIONAL_HISTORY, MAX_RELATIONSHIP_MEMORY, } from "./types.js";
7
+ import { CHEMICAL_KEYS, CHEMICAL_NAMES, CHEMICAL_NAMES_ZH, DEFAULT_RELATIONSHIP, DEFAULT_DRIVES, DEFAULT_LEARNING_STATE, DEFAULT_METACOGNITIVE_STATE, MAX_EMOTIONAL_HISTORY, MAX_RELATIONSHIP_MEMORY, } from "./types.js";
8
8
  import { getBaseline, getDefaultSelfModel, extractMBTI, getSensitivity, getTemperament } from "./profiles.js";
9
9
  import { applyDecay, detectEmotions } from "./chemistry.js";
10
10
  import { decayDrives, computeEffectiveBaseline } from "./drives.js";
@@ -241,11 +241,13 @@ export function migrateToLatest(raw, fallbackName) {
241
241
  }
242
242
  // v2→v3: add drives
243
243
  // v3→v4: add learning
244
+ // v4→v5: add metacognition
244
245
  return {
245
246
  ...state,
246
- version: 4,
247
+ version: 5,
247
248
  drives: state.drives ?? { ...DEFAULT_DRIVES },
248
249
  learning: state.learning ?? { ...DEFAULT_LEARNING_STATE },
250
+ metacognition: state.metacognition ?? { ...DEFAULT_METACOGNITIVE_STATE },
249
251
  };
250
252
  }
251
253
  /**
@@ -259,7 +261,7 @@ export async function initializeState(workspaceDir, opts, logger = NOOP_LOGGER)
259
261
  const selfModel = getDefaultSelfModel(mbti);
260
262
  const now = new Date().toISOString();
261
263
  const state = {
262
- version: 4,
264
+ version: 5,
263
265
  mbti,
264
266
  baseline,
265
267
  current: { ...baseline },
@@ -274,6 +276,7 @@ export async function initializeState(workspaceDir, opts, logger = NOOP_LOGGER)
274
276
  agreementStreak: 0,
275
277
  lastDisagreement: null,
276
278
  learning: { ...DEFAULT_LEARNING_STATE },
279
+ metacognition: { ...DEFAULT_METACOGNITIVE_STATE },
277
280
  meta: {
278
281
  agentName,
279
282
  createdAt: now,
package/dist/types.d.ts CHANGED
@@ -145,9 +145,39 @@ export declare const MAX_PREDICTION_HISTORY = 50;
145
145
  export declare const MAX_OUTCOME_HISTORY = 50;
146
146
  /** Max regret history entries */
147
147
  export declare const MAX_REGRET_HISTORY = 20;
148
- /** Persisted psyche state for an agent (v4: emotional learning) */
148
+ /** Max metacognitive regulation history entries */
149
+ export declare const MAX_REGULATION_HISTORY = 30;
150
+ /** Max defense pattern entries */
151
+ export declare const MAX_DEFENSE_PATTERNS = 10;
152
+ /** Regulation strategy type */
153
+ export type RegulationStrategyType = "reappraisal" | "strategic-expression" | "self-soothing";
154
+ /** Defense mechanism type */
155
+ export type DefenseMechanismType = "rationalization" | "projection" | "sublimation" | "avoidance";
156
+ /** Record of a past regulation attempt */
157
+ export interface RegulationRecord {
158
+ strategy: RegulationStrategyType;
159
+ timestamp: string;
160
+ effective: boolean;
161
+ }
162
+ /** Tracked defense pattern frequency */
163
+ export interface DefensePatternRecord {
164
+ mechanism: DefenseMechanismType;
165
+ frequency: number;
166
+ lastSeen: string;
167
+ }
168
+ /** Persistent metacognitive state */
169
+ export interface MetacognitiveState {
170
+ regulationHistory: RegulationRecord[];
171
+ defensePatterns: DefensePatternRecord[];
172
+ /** Running average of emotional confidence across assessments */
173
+ avgEmotionalConfidence: number;
174
+ totalAssessments: number;
175
+ }
176
+ /** Default empty metacognitive state */
177
+ export declare const DEFAULT_METACOGNITIVE_STATE: MetacognitiveState;
178
+ /** Persisted psyche state for an agent (v5: metacognition + decision modulation) */
149
179
  export interface PsycheState {
150
- version: 3 | 4;
180
+ version: 3 | 4 | 5;
151
181
  mbti: MBTIType;
152
182
  baseline: ChemicalState;
153
183
  current: ChemicalState;
@@ -160,6 +190,7 @@ export interface PsycheState {
160
190
  agreementStreak: number;
161
191
  lastDisagreement: string | null;
162
192
  learning: LearningState;
193
+ metacognition: MetacognitiveState;
163
194
  meta: {
164
195
  agentName: string;
165
196
  createdAt: string;
package/dist/types.js CHANGED
@@ -85,6 +85,17 @@ export const MAX_PREDICTION_HISTORY = 50;
85
85
  export const MAX_OUTCOME_HISTORY = 50;
86
86
  /** Max regret history entries */
87
87
  export const MAX_REGRET_HISTORY = 20;
88
+ /** Max metacognitive regulation history entries */
89
+ export const MAX_REGULATION_HISTORY = 30;
90
+ /** Max defense pattern entries */
91
+ export const MAX_DEFENSE_PATTERNS = 10;
92
+ /** Default empty metacognitive state */
93
+ export const DEFAULT_METACOGNITIVE_STATE = {
94
+ regulationHistory: [],
95
+ defensePatterns: [],
96
+ avgEmotionalConfidence: 0.5,
97
+ totalAssessments: 0,
98
+ };
88
99
  /** Default relationship for new users */
89
100
  export const DEFAULT_RELATIONSHIP = {
90
101
  trust: 50,
package/dist/update.js CHANGED
@@ -11,7 +11,7 @@ import { execFile } from "node:child_process";
11
11
  import { promisify } from "node:util";
12
12
  const execFileAsync = promisify(execFile);
13
13
  const PACKAGE_NAME = "psyche-ai";
14
- const CURRENT_VERSION = "3.1.0";
14
+ const CURRENT_VERSION = "4.0.0";
15
15
  const CHECK_INTERVAL_MS = 60 * 60 * 1000; // 1 hour
16
16
  const CACHE_DIR = join(homedir(), ".psyche-ai");
17
17
  const CACHE_FILE = join(CACHE_DIR, "update-check.json");
@@ -2,7 +2,7 @@
2
2
  "id": "psyche-ai",
3
3
  "name": "Artificial Psyche",
4
4
  "description": "Virtual endocrine system, empathy engine, and agency for OpenClaw agents",
5
- "version": "3.1.0",
5
+ "version": "4.0.0",
6
6
  "configSchema": {
7
7
  "type": "object",
8
8
  "additionalProperties": false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "psyche-ai",
3
- "version": "3.1.0",
3
+ "version": "4.0.0",
4
4
  "description": "Artificial Psyche — universal emotional intelligence plugin for any AI agent",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",