psyche-ai 5.0.0 → 5.1.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/core.js +75 -0
- package/dist/prompt.d.ts +6 -0
- package/dist/prompt.js +27 -0
- package/dist/update.js +1 -1
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
package/dist/core.js
CHANGED
|
@@ -23,6 +23,10 @@ import { checkForUpdate } from "./update.js";
|
|
|
23
23
|
import { evaluateOutcome, computeContextHash, updateLearnedVector, predictChemistry, recordPrediction, } from "./learning.js";
|
|
24
24
|
import { assessMetacognition } from "./metacognition.js";
|
|
25
25
|
import { buildDecisionContext } from "./decision-bias.js";
|
|
26
|
+
import { computeExperientialField } from "./experiential-field.js";
|
|
27
|
+
import { computeGenerativeSelf } from "./generative-self.js";
|
|
28
|
+
import { updateSharedIntentionality, buildSharedIntentionalityContext } from "./shared-intentionality.js";
|
|
29
|
+
import { assessEthics, buildEthicalContext } from "./ethics.js";
|
|
26
30
|
const NOOP_LOGGER = { info: () => { }, warn: () => { }, debug: () => { } };
|
|
27
31
|
// ── PsycheEngine ─────────────────────────────────────────────
|
|
28
32
|
export class PsycheEngine {
|
|
@@ -206,6 +210,68 @@ export class PsycheEngine {
|
|
|
206
210
|
else {
|
|
207
211
|
this.pendingPrediction = null;
|
|
208
212
|
}
|
|
213
|
+
// ── P6: Digital Personhood computations ────────────────────
|
|
214
|
+
// Experiential field — unified inner experience
|
|
215
|
+
const experientialField = computeExperientialField(state, metacognitiveAssessment);
|
|
216
|
+
// Shared intentionality — theory of mind + joint attention
|
|
217
|
+
const sharedState = updateSharedIntentionality(state, appliedStimulus, opts?.userId);
|
|
218
|
+
// Ethics — emotional self-care check
|
|
219
|
+
const ethicalAssessment = assessEthics(state);
|
|
220
|
+
// Generative self — update identity narrative periodically (every 10 turns)
|
|
221
|
+
if (state.meta.totalInteractions % 10 === 0 && state.meta.totalInteractions > 0) {
|
|
222
|
+
const selfModel = computeGenerativeSelf(state);
|
|
223
|
+
state = {
|
|
224
|
+
...state,
|
|
225
|
+
personhood: {
|
|
226
|
+
...state.personhood,
|
|
227
|
+
identityNarrative: selfModel.identityNarrative,
|
|
228
|
+
growthDirection: selfModel.growthArc.direction,
|
|
229
|
+
causalInsights: selfModel.causalInsights.slice(0, 20).map((ci) => ({
|
|
230
|
+
trait: ci.trait,
|
|
231
|
+
because: ci.because,
|
|
232
|
+
confidence: ci.confidence,
|
|
233
|
+
discoveredAt: new Date().toISOString(),
|
|
234
|
+
})),
|
|
235
|
+
},
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
// Persist ethical concerns if significant
|
|
239
|
+
if (ethicalAssessment.ethicalHealth < 0.7) {
|
|
240
|
+
const newConcerns = ethicalAssessment.concerns
|
|
241
|
+
.filter((c) => c.severity > 0.4)
|
|
242
|
+
.map((c) => ({ type: c.type, severity: c.severity, timestamp: new Date().toISOString() }));
|
|
243
|
+
if (newConcerns.length > 0) {
|
|
244
|
+
state = {
|
|
245
|
+
...state,
|
|
246
|
+
personhood: {
|
|
247
|
+
...state.personhood,
|
|
248
|
+
ethicalConcernHistory: [
|
|
249
|
+
...state.personhood.ethicalConcernHistory.slice(-14),
|
|
250
|
+
...newConcerns,
|
|
251
|
+
],
|
|
252
|
+
},
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
// Persist theory of mind
|
|
257
|
+
if (sharedState.theoryOfMind.confidence > 0.3) {
|
|
258
|
+
const userId = opts?.userId ?? "_default";
|
|
259
|
+
state = {
|
|
260
|
+
...state,
|
|
261
|
+
personhood: {
|
|
262
|
+
...state.personhood,
|
|
263
|
+
theoryOfMind: {
|
|
264
|
+
...state.personhood.theoryOfMind,
|
|
265
|
+
[userId]: {
|
|
266
|
+
estimatedMood: sharedState.theoryOfMind.estimatedMood,
|
|
267
|
+
estimatedIntent: sharedState.theoryOfMind.estimatedIntent,
|
|
268
|
+
confidence: sharedState.theoryOfMind.confidence,
|
|
269
|
+
lastUpdated: sharedState.theoryOfMind.lastUpdated,
|
|
270
|
+
},
|
|
271
|
+
},
|
|
272
|
+
},
|
|
273
|
+
};
|
|
274
|
+
}
|
|
209
275
|
// Persist
|
|
210
276
|
this.state = state;
|
|
211
277
|
await this.storage.save(state);
|
|
@@ -213,6 +279,9 @@ export class PsycheEngine {
|
|
|
213
279
|
// Build metacognitive and decision context strings
|
|
214
280
|
const metacogNote = metacognitiveAssessment.metacognitiveNote;
|
|
215
281
|
const decisionCtx = buildDecisionContext(state);
|
|
282
|
+
const ethicsCtx = buildEthicalContext(ethicalAssessment, locale);
|
|
283
|
+
const sharedCtx = buildSharedIntentionalityContext(sharedState, locale);
|
|
284
|
+
const experientialNarrative = experientialField.narrative || undefined;
|
|
216
285
|
if (this.cfg.compactMode) {
|
|
217
286
|
return {
|
|
218
287
|
systemContext: "",
|
|
@@ -221,6 +290,9 @@ export class PsycheEngine {
|
|
|
221
290
|
algorithmStimulus: appliedStimulus,
|
|
222
291
|
metacognitiveNote: metacogNote || undefined,
|
|
223
292
|
decisionContext: decisionCtx || undefined,
|
|
293
|
+
ethicsContext: ethicsCtx || undefined,
|
|
294
|
+
sharedIntentionalityContext: sharedCtx || undefined,
|
|
295
|
+
experientialNarrative: experientialNarrative,
|
|
224
296
|
}),
|
|
225
297
|
stimulus: appliedStimulus,
|
|
226
298
|
};
|
|
@@ -230,6 +302,9 @@ export class PsycheEngine {
|
|
|
230
302
|
dynamicContext: buildDynamicContext(state, opts?.userId, {
|
|
231
303
|
metacognitiveNote: metacogNote || undefined,
|
|
232
304
|
decisionContext: decisionCtx || undefined,
|
|
305
|
+
ethicsContext: ethicsCtx || undefined,
|
|
306
|
+
sharedIntentionalityContext: sharedCtx || undefined,
|
|
307
|
+
experientialNarrative: experientialNarrative,
|
|
233
308
|
}),
|
|
234
309
|
stimulus: appliedStimulus,
|
|
235
310
|
};
|
package/dist/prompt.d.ts
CHANGED
|
@@ -8,6 +8,9 @@ import type { ChannelType } from "./channels.js";
|
|
|
8
8
|
export declare function buildDynamicContext(state: PsycheState, userId?: string, opts?: {
|
|
9
9
|
metacognitiveNote?: string;
|
|
10
10
|
decisionContext?: string;
|
|
11
|
+
ethicsContext?: string;
|
|
12
|
+
sharedIntentionalityContext?: string;
|
|
13
|
+
experientialNarrative?: string;
|
|
11
14
|
}): string;
|
|
12
15
|
/**
|
|
13
16
|
* Build the static protocol injected as cacheable system context.
|
|
@@ -39,4 +42,7 @@ export declare function buildCompactContext(state: PsycheState, userId?: string,
|
|
|
39
42
|
channelType?: ChannelType;
|
|
40
43
|
metacognitiveNote?: string;
|
|
41
44
|
decisionContext?: string;
|
|
45
|
+
ethicsContext?: string;
|
|
46
|
+
sharedIntentionalityContext?: string;
|
|
47
|
+
experientialNarrative?: string;
|
|
42
48
|
}): string;
|
package/dist/prompt.js
CHANGED
|
@@ -98,6 +98,19 @@ export function buildDynamicContext(state, userId, opts) {
|
|
|
98
98
|
const dbTitle = locale === "zh" ? "决策倾向" : "Decision Bias";
|
|
99
99
|
parts.push("", `[${dbTitle}] ${opts.decisionContext}`);
|
|
100
100
|
}
|
|
101
|
+
// Experiential field narrative (P6)
|
|
102
|
+
if (opts?.experientialNarrative) {
|
|
103
|
+
const efTitle = locale === "zh" ? "内在体验" : "Inner Experience";
|
|
104
|
+
parts.push("", `[${efTitle}] ${opts.experientialNarrative}`);
|
|
105
|
+
}
|
|
106
|
+
// Shared intentionality (P6)
|
|
107
|
+
if (opts?.sharedIntentionalityContext) {
|
|
108
|
+
parts.push("", opts.sharedIntentionalityContext);
|
|
109
|
+
}
|
|
110
|
+
// Ethics (P6)
|
|
111
|
+
if (opts?.ethicsContext) {
|
|
112
|
+
parts.push("", opts.ethicsContext);
|
|
113
|
+
}
|
|
101
114
|
parts.push("", agencyReminder, sycophancyWarning, "", t("dynamic.update_reminder", locale));
|
|
102
115
|
return parts.filter((l) => l !== undefined).join("\n");
|
|
103
116
|
}
|
|
@@ -500,6 +513,20 @@ export function buildCompactContext(state, userId, opts) {
|
|
|
500
513
|
? `[决策倾向] ${opts.decisionContext}`
|
|
501
514
|
: `[Decision Bias] ${opts.decisionContext}`);
|
|
502
515
|
}
|
|
516
|
+
// 9c. Experiential field narrative (P6) — inner experience beyond named emotions
|
|
517
|
+
if (opts?.experientialNarrative) {
|
|
518
|
+
parts.push(locale === "zh"
|
|
519
|
+
? `[内在体验] ${opts.experientialNarrative}`
|
|
520
|
+
: `[Inner Experience] ${opts.experientialNarrative}`);
|
|
521
|
+
}
|
|
522
|
+
// 9d. Shared intentionality (P6) — theory of mind, joint attention
|
|
523
|
+
if (opts?.sharedIntentionalityContext) {
|
|
524
|
+
parts.push(opts.sharedIntentionalityContext);
|
|
525
|
+
}
|
|
526
|
+
// 9e. Ethics (P6) — manipulation detection, self-protection
|
|
527
|
+
if (opts?.ethicsContext) {
|
|
528
|
+
parts.push(opts.ethicsContext);
|
|
529
|
+
}
|
|
503
530
|
// 10. Cross-session emotional memory — surface relationship history
|
|
504
531
|
const relationship = getRelationship(state, userId);
|
|
505
532
|
if (relationship.memory && relationship.memory.length > 0) {
|
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 = "5.
|
|
14
|
+
const CURRENT_VERSION = "5.1.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");
|
package/openclaw.plugin.json
CHANGED