psyche-ai 9.2.6 → 9.2.8
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/README.md +89 -2
- package/dist/adapters/http.js +25 -3
- package/dist/adapters/langchain.d.ts +4 -0
- package/dist/adapters/langchain.js +28 -5
- package/dist/adapters/mcp.js +13 -4
- package/dist/adapters/openclaw.js +2 -2
- package/dist/adapters/vercel-ai.js +6 -4
- package/dist/core.d.ts +27 -9
- package/dist/core.js +145 -183
- package/dist/external-continuity.d.ts +4 -0
- package/dist/external-continuity.js +21 -0
- package/dist/index.d.ts +7 -2
- package/dist/index.js +5 -1
- package/dist/input-turn.d.ts +30 -0
- package/dist/input-turn.js +164 -0
- package/dist/prompt.d.ts +13 -24
- package/dist/prompt.js +48 -81
- package/dist/psyche-file.d.ts +5 -1
- package/dist/psyche-file.js +39 -1
- package/dist/relation-dynamics.d.ts +22 -1
- package/dist/relation-dynamics.js +431 -12
- package/dist/reply-envelope.d.ts +7 -2
- package/dist/reply-envelope.js +2 -1
- package/dist/response-contract.d.ts +1 -0
- package/dist/response-contract.js +47 -16
- package/dist/thronglets-export.d.ts +10 -0
- package/dist/thronglets-export.js +200 -0
- package/dist/thronglets-runtime.d.ts +4 -0
- package/dist/thronglets-runtime.js +49 -0
- package/dist/types.d.ts +147 -0
- package/dist/types.js +3 -0
- package/llms.txt +115 -83
- package/package.json +1 -1
package/dist/core.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// PsycheEngine — Framework-agnostic emotional intelligence core
|
|
3
3
|
//
|
|
4
4
|
// Three-phase API:
|
|
5
|
-
// processInput(text) → systemContext + dynamicContext + stimulus
|
|
5
|
+
// processInput(text) → systemContext + dynamicContext + replyEnvelope + stimulus
|
|
6
6
|
// processOutput(text) → cleanedText + stateChanged
|
|
7
7
|
// processOutcome(text) → outcomeScore (optional: evaluate last interaction)
|
|
8
8
|
//
|
|
@@ -23,17 +23,21 @@ import { decayDrives, feedDrives, detectExistentialThreat, computeEffectiveBasel
|
|
|
23
23
|
import { checkForUpdate, getPackageVersion } from "./update.js";
|
|
24
24
|
import { DiagnosticCollector, generateReport, formatLogEntry, submitFeedback } from "./diagnostics.js";
|
|
25
25
|
import { evaluateOutcome, computeContextHash, updateLearnedVector, predictChemistry, recordPrediction, } from "./learning.js";
|
|
26
|
-
import { assessMetacognition, updateMetacognitiveState } from "./metacognition.js";
|
|
27
|
-
import { buildDecisionContext } from "./decision-bias.js";
|
|
28
|
-
import { computeExperientialField } from "./experiential-field.js";
|
|
29
|
-
import { computeGenerativeSelf } from "./generative-self.js";
|
|
30
|
-
import { updateSharedIntentionality, buildSharedIntentionalityContext } from "./shared-intentionality.js";
|
|
31
|
-
import { assessEthics, buildEthicalContext } from "./ethics.js";
|
|
32
26
|
import { computeCircadianModulation, computeHomeostaticPressure, computeEnergyDepletion, computeEnergyRecovery } from "./circadian.js";
|
|
33
|
-
import {
|
|
34
|
-
import {
|
|
35
|
-
import {
|
|
36
|
-
import {
|
|
27
|
+
import { runReflectiveTurnPhases } from "./input-turn.js";
|
|
28
|
+
import { applyRelationalTurn, applySessionBridge, applyWritebackSignals, createWritebackCalibrations, evaluateWritebackCalibrations } from "./relation-dynamics.js";
|
|
29
|
+
import { buildExternalContinuityEnvelope } from "./external-continuity.js";
|
|
30
|
+
import { deriveThrongletsExports } from "./thronglets-export.js";
|
|
31
|
+
function formatWritebackFeedbackNote(feedback, locale) {
|
|
32
|
+
const top = feedback?.[0];
|
|
33
|
+
if (!top)
|
|
34
|
+
return undefined;
|
|
35
|
+
if (locale === "zh") {
|
|
36
|
+
const effect = top.effect === "converging" ? "收敛" : top.effect === "diverging" ? "发散" : "持平";
|
|
37
|
+
return `写回:${top.signal} ${effect}。`;
|
|
38
|
+
}
|
|
39
|
+
return `Writeback: ${top.signal} ${top.effect}.`;
|
|
40
|
+
}
|
|
37
41
|
const NOOP_LOGGER = { info: () => { }, warn: () => { }, debug: () => { } };
|
|
38
42
|
const REPAIRING_STIMULI = new Set(["praise", "validation", "intimacy"]);
|
|
39
43
|
const RELATIONSHIP_DELTAS = {
|
|
@@ -127,6 +131,8 @@ export class PsycheEngine {
|
|
|
127
131
|
lastReport = null;
|
|
128
132
|
/** URL for auto-submitting diagnostic reports */
|
|
129
133
|
feedbackUrl;
|
|
134
|
+
/** Most recent algorithmic stimulus read + confidence band */
|
|
135
|
+
lastStimulusAssessment = null;
|
|
130
136
|
constructor(config = {}, storage) {
|
|
131
137
|
this.traits = config.traits;
|
|
132
138
|
this.classifier = config.classifier ?? new BuiltInClassifier();
|
|
@@ -204,6 +210,12 @@ export class PsycheEngine {
|
|
|
204
210
|
if (!loaded.pendingRelationSignals) {
|
|
205
211
|
loaded.pendingRelationSignals = { _default: [] };
|
|
206
212
|
}
|
|
213
|
+
if (!loaded.pendingWritebackCalibrations) {
|
|
214
|
+
loaded.pendingWritebackCalibrations = [];
|
|
215
|
+
}
|
|
216
|
+
if (!loaded.lastWritebackFeedback) {
|
|
217
|
+
loaded.lastWritebackFeedback = [];
|
|
218
|
+
}
|
|
207
219
|
this.state = loaded;
|
|
208
220
|
}
|
|
209
221
|
else {
|
|
@@ -219,6 +231,9 @@ export class PsycheEngine {
|
|
|
219
231
|
*/
|
|
220
232
|
async processInput(text, opts) {
|
|
221
233
|
let state = this.ensureInitialized();
|
|
234
|
+
let sessionBridge = null;
|
|
235
|
+
let writebackFeedback = [];
|
|
236
|
+
let throngletsExports = [];
|
|
222
237
|
// ── Auto-learning: evaluate previous turn's outcome ──────
|
|
223
238
|
if (this.pendingPrediction && text.length > 0) {
|
|
224
239
|
const nextClassifications = classifyStimulus(text);
|
|
@@ -261,6 +276,9 @@ export class PsycheEngine {
|
|
|
261
276
|
}
|
|
262
277
|
// P12: Track session start for homeostatic pressure
|
|
263
278
|
if (!state.sessionStartedAt) {
|
|
279
|
+
const bridged = applySessionBridge(state, { userId: opts?.userId, now: now.toISOString() });
|
|
280
|
+
state = bridged.state;
|
|
281
|
+
sessionBridge = bridged.bridge;
|
|
264
282
|
state = { ...state, sessionStartedAt: now.toISOString() };
|
|
265
283
|
}
|
|
266
284
|
// Apply homeostatic pressure (fatigue from extended sessions)
|
|
@@ -311,6 +329,7 @@ export class PsycheEngine {
|
|
|
311
329
|
}
|
|
312
330
|
}
|
|
313
331
|
const primary = classifications[0];
|
|
332
|
+
const primaryConfidence = primary?.confidence ?? 0;
|
|
314
333
|
let current = state.current;
|
|
315
334
|
if (primary && primary.confidence >= 0.5) {
|
|
316
335
|
appliedStimulus = primary.type;
|
|
@@ -334,6 +353,18 @@ export class PsycheEngine {
|
|
|
334
353
|
if (appliedStimulus) {
|
|
335
354
|
state = applyRelationshipDrift(state, appliedStimulus, opts?.userId);
|
|
336
355
|
}
|
|
356
|
+
this.lastStimulusAssessment = {
|
|
357
|
+
stimulus: primary?.type ?? null,
|
|
358
|
+
confidence: primaryConfidence,
|
|
359
|
+
overrideWindow: primaryConfidence >= 0.78 ? "narrow" : primaryConfidence >= 0.62 ? "balanced" : "wide",
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
else {
|
|
363
|
+
this.lastStimulusAssessment = {
|
|
364
|
+
stimulus: null,
|
|
365
|
+
confidence: 0,
|
|
366
|
+
overrideWindow: "wide",
|
|
367
|
+
};
|
|
337
368
|
}
|
|
338
369
|
// v9: Deplete energy budgets from this interaction turn
|
|
339
370
|
energyBudgets = computeEnergyDepletion(energyBudgets, appliedStimulus, isExtravert);
|
|
@@ -361,48 +392,19 @@ export class PsycheEngine {
|
|
|
361
392
|
},
|
|
362
393
|
};
|
|
363
394
|
}
|
|
395
|
+
const writebackEvaluation = evaluateWritebackCalibrations(state);
|
|
396
|
+
state = writebackEvaluation.state;
|
|
397
|
+
writebackFeedback = writebackEvaluation.feedback;
|
|
398
|
+
const throngletsExportResult = deriveThrongletsExports(state, {
|
|
399
|
+
relationContext: relationalTurn.relationContext,
|
|
400
|
+
sessionBridge,
|
|
401
|
+
writebackFeedback,
|
|
402
|
+
now: now.toISOString(),
|
|
403
|
+
});
|
|
404
|
+
state = throngletsExportResult.state;
|
|
405
|
+
throngletsExports = throngletsExportResult.exports;
|
|
364
406
|
// ── Locale (used by multiple subsystems below) ──────────
|
|
365
407
|
const locale = state.meta.locale ?? this.cfg.locale;
|
|
366
|
-
// ── P7+P10: Autonomic nervous system + Processing depth ────
|
|
367
|
-
const autonomicResult = computeAutonomicResult(state.current, state.drives, state.autonomicState ?? null, minutesElapsed, locale, state.baseline, state.energyBudgets);
|
|
368
|
-
state = {
|
|
369
|
-
...state,
|
|
370
|
-
autonomicState: autonomicResult.state,
|
|
371
|
-
};
|
|
372
|
-
const skip = new Set(autonomicResult.skippedStages);
|
|
373
|
-
// ── P9: Primary emotional systems (Panksepp) ──────────────
|
|
374
|
-
const rawSystems = computePrimarySystems(state.current, state.drives, appliedStimulus);
|
|
375
|
-
const interactedSystems = computeSystemInteractions(rawSystems);
|
|
376
|
-
const gatedSystems = gatePrimarySystemsByAutonomic(interactedSystems, autonomicResult.state);
|
|
377
|
-
const primarySystemsDescription = describeBehavioralTendencies(gatedSystems, locale);
|
|
378
|
-
// ── Metacognition: assess emotional state before acting ────
|
|
379
|
-
// P10: Skip metacognition when processingDepth < 0.2 (System 1 mode)
|
|
380
|
-
let metacognitiveAssessment = null;
|
|
381
|
-
if (!skip.has("metacognition")) {
|
|
382
|
-
metacognitiveAssessment = assessMetacognition(state, appliedStimulus ?? "casual", state.learning.outcomeHistory);
|
|
383
|
-
// Apply self-soothing regulation if suggested with high confidence
|
|
384
|
-
for (const reg of metacognitiveAssessment.regulationSuggestions) {
|
|
385
|
-
if (reg.strategy === "self-soothing" && reg.confidence >= 0.6 && reg.chemistryAdjustment) {
|
|
386
|
-
const adj = reg.chemistryAdjustment;
|
|
387
|
-
state = {
|
|
388
|
-
...state,
|
|
389
|
-
current: {
|
|
390
|
-
...state.current,
|
|
391
|
-
DA: clamp(state.current.DA + (adj.DA ?? 0)),
|
|
392
|
-
HT: clamp(state.current.HT + (adj.HT ?? 0)),
|
|
393
|
-
CORT: clamp(state.current.CORT + (adj.CORT ?? 0)),
|
|
394
|
-
OT: clamp(state.current.OT + (adj.OT ?? 0)),
|
|
395
|
-
NE: clamp(state.current.NE + (adj.NE ?? 0)),
|
|
396
|
-
END: clamp(state.current.END + (adj.END ?? 0)),
|
|
397
|
-
},
|
|
398
|
-
};
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
state = {
|
|
402
|
-
...state,
|
|
403
|
-
metacognition: updateMetacognitiveState(state.metacognition, metacognitiveAssessment),
|
|
404
|
-
};
|
|
405
|
-
}
|
|
406
408
|
// Push snapshot to emotional history
|
|
407
409
|
const semanticSummary = text
|
|
408
410
|
? summarizeTurnSemantic(text, locale, {
|
|
@@ -432,83 +434,22 @@ export class PsycheEngine {
|
|
|
432
434
|
else {
|
|
433
435
|
this.pendingPrediction = null;
|
|
434
436
|
}
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
:
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
: updateSharedIntentionality(state, appliedStimulus, opts?.userId);
|
|
452
|
-
// Ethics — emotional self-care check
|
|
453
|
-
const ethicalAssessment = skip.has("ethics")
|
|
454
|
-
? null
|
|
455
|
-
: assessEthics(state);
|
|
456
|
-
// Generative self — update identity narrative periodically (every 10 turns)
|
|
457
|
-
if (!skip.has("generative-self")
|
|
458
|
-
&& state.meta.totalInteractions % 10 === 0 && state.meta.totalInteractions > 0) {
|
|
459
|
-
const selfModel = computeGenerativeSelf(state);
|
|
460
|
-
state = {
|
|
461
|
-
...state,
|
|
462
|
-
personhood: {
|
|
463
|
-
...state.personhood,
|
|
464
|
-
identityNarrative: selfModel.identityNarrative,
|
|
465
|
-
growthDirection: selfModel.growthArc.direction,
|
|
466
|
-
causalInsights: selfModel.causalInsights.slice(0, 20).map((ci) => ({
|
|
467
|
-
trait: ci.trait,
|
|
468
|
-
because: ci.because,
|
|
469
|
-
confidence: ci.confidence,
|
|
470
|
-
discoveredAt: new Date().toISOString(),
|
|
471
|
-
})),
|
|
472
|
-
},
|
|
473
|
-
};
|
|
474
|
-
}
|
|
475
|
-
// Persist ethical concerns if significant
|
|
476
|
-
if (ethicalAssessment && ethicalAssessment.ethicalHealth < 0.7) {
|
|
477
|
-
const newConcerns = ethicalAssessment.concerns
|
|
478
|
-
.filter((c) => c.severity > 0.4)
|
|
479
|
-
.map((c) => ({ type: c.type, severity: c.severity, timestamp: new Date().toISOString() }));
|
|
480
|
-
if (newConcerns.length > 0) {
|
|
481
|
-
state = {
|
|
482
|
-
...state,
|
|
483
|
-
personhood: {
|
|
484
|
-
...state.personhood,
|
|
485
|
-
ethicalConcernHistory: [
|
|
486
|
-
...state.personhood.ethicalConcernHistory.slice(-14),
|
|
487
|
-
...newConcerns,
|
|
488
|
-
],
|
|
489
|
-
},
|
|
490
|
-
};
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
// Persist theory of mind
|
|
494
|
-
if (sharedState && sharedState.theoryOfMind.confidence > 0.3) {
|
|
495
|
-
const userId = opts?.userId ?? "_default";
|
|
496
|
-
state = {
|
|
497
|
-
...state,
|
|
498
|
-
personhood: {
|
|
499
|
-
...state.personhood,
|
|
500
|
-
theoryOfMind: {
|
|
501
|
-
...state.personhood.theoryOfMind,
|
|
502
|
-
[userId]: {
|
|
503
|
-
estimatedMood: sharedState.theoryOfMind.estimatedMood,
|
|
504
|
-
estimatedIntent: sharedState.theoryOfMind.estimatedIntent,
|
|
505
|
-
confidence: sharedState.theoryOfMind.confidence,
|
|
506
|
-
lastUpdated: sharedState.theoryOfMind.lastUpdated,
|
|
507
|
-
},
|
|
508
|
-
},
|
|
509
|
-
},
|
|
510
|
-
};
|
|
511
|
-
}
|
|
437
|
+
const writebackNote = formatWritebackFeedbackNote(writebackFeedback, locale);
|
|
438
|
+
const reflectiveTurn = runReflectiveTurnPhases({
|
|
439
|
+
state,
|
|
440
|
+
appraisalAxes,
|
|
441
|
+
relationContext: relationalTurn.relationContext,
|
|
442
|
+
appliedStimulus,
|
|
443
|
+
userText: text || undefined,
|
|
444
|
+
userId: opts?.userId,
|
|
445
|
+
localeFallback: this.cfg.locale,
|
|
446
|
+
personalityIntensity: this.cfg.personalityIntensity,
|
|
447
|
+
classificationConfidence: this.lastStimulusAssessment?.confidence,
|
|
448
|
+
minutesElapsed,
|
|
449
|
+
nowIso: now.toISOString(),
|
|
450
|
+
writebackNote,
|
|
451
|
+
});
|
|
452
|
+
state = reflectiveTurn.state;
|
|
512
453
|
// Persist
|
|
513
454
|
this.state = state;
|
|
514
455
|
await this.storage.save(state);
|
|
@@ -516,77 +457,64 @@ export class PsycheEngine {
|
|
|
516
457
|
if (this.diagnosticCollector) {
|
|
517
458
|
this.diagnosticCollector.recordInput(appliedStimulus, appliedStimulus ? 1.0 : 0.0, state.current, appraisalAxes);
|
|
518
459
|
}
|
|
519
|
-
//
|
|
520
|
-
const
|
|
521
|
-
const
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
const
|
|
527
|
-
locale,
|
|
460
|
+
// v9: Compute structured reply surfaces
|
|
461
|
+
const derivedReplyEnvelope = reflectiveTurn.replyEnvelope;
|
|
462
|
+
const replyEnvelope = {
|
|
463
|
+
subjectivityKernel: derivedReplyEnvelope.subjectivityKernel,
|
|
464
|
+
responseContract: derivedReplyEnvelope.responseContract,
|
|
465
|
+
generationControls: derivedReplyEnvelope.generationControls,
|
|
466
|
+
};
|
|
467
|
+
const promptRenderInputs = {
|
|
528
468
|
userText: text || undefined,
|
|
529
469
|
algorithmStimulus: appliedStimulus,
|
|
530
470
|
personalityIntensity: this.cfg.personalityIntensity,
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
}
|
|
471
|
+
metacognitiveNote: reflectiveTurn.metacognitiveNote,
|
|
472
|
+
decisionContext: reflectiveTurn.decisionContext,
|
|
473
|
+
ethicsContext: reflectiveTurn.ethicsContext,
|
|
474
|
+
sharedIntentionalityContext: reflectiveTurn.sharedIntentionalityContext,
|
|
475
|
+
experientialNarrative: reflectiveTurn.experientialNarrative,
|
|
476
|
+
autonomicDescription: reflectiveTurn.autonomicDescription,
|
|
477
|
+
autonomicState: reflectiveTurn.autonomicState,
|
|
478
|
+
primarySystemsDescription: reflectiveTurn.primarySystemsDescription,
|
|
479
|
+
subjectivityContext: derivedReplyEnvelope.subjectivityContext,
|
|
480
|
+
responseContractContext: derivedReplyEnvelope.responseContractContext,
|
|
481
|
+
policyContext: derivedReplyEnvelope.policyContext || undefined,
|
|
482
|
+
};
|
|
544
483
|
if (this.cfg.compactMode) {
|
|
484
|
+
const externalContinuity = buildExternalContinuityEnvelope(throngletsExports);
|
|
545
485
|
return {
|
|
546
486
|
systemContext: "",
|
|
547
|
-
dynamicContext: buildCompactContext(state, opts?.userId,
|
|
548
|
-
userText: text || undefined,
|
|
549
|
-
algorithmStimulus: appliedStimulus,
|
|
550
|
-
personalityIntensity: this.cfg.personalityIntensity,
|
|
551
|
-
metacognitiveNote: metacogNote || undefined,
|
|
552
|
-
decisionContext: decisionCtx || undefined,
|
|
553
|
-
ethicsContext: ethicsCtx || undefined,
|
|
554
|
-
sharedIntentionalityContext: sharedCtx || undefined,
|
|
555
|
-
experientialNarrative: experientialNarrative,
|
|
556
|
-
autonomicDescription: autonomicDesc,
|
|
557
|
-
autonomicState: autonomicResult.state,
|
|
558
|
-
primarySystemsDescription: primarySystemsDescription || undefined,
|
|
559
|
-
subjectivityContext: replyEnvelope.subjectivityContext,
|
|
560
|
-
responseContractContext: replyEnvelope.responseContractContext,
|
|
561
|
-
policyContext: replyEnvelope.policyContext || undefined,
|
|
562
|
-
}),
|
|
487
|
+
dynamicContext: buildCompactContext(state, opts?.userId, promptRenderInputs),
|
|
563
488
|
stimulus: appliedStimulus,
|
|
564
|
-
|
|
489
|
+
stimulusConfidence: this.lastStimulusAssessment?.confidence,
|
|
490
|
+
replyEnvelope,
|
|
491
|
+
policyModifiers: derivedReplyEnvelope.policyModifiers,
|
|
565
492
|
subjectivityKernel: replyEnvelope.subjectivityKernel,
|
|
566
493
|
responseContract: replyEnvelope.responseContract,
|
|
567
494
|
generationControls: replyEnvelope.generationControls,
|
|
568
|
-
|
|
495
|
+
sessionBridge,
|
|
496
|
+
writebackFeedback,
|
|
497
|
+
externalContinuity,
|
|
498
|
+
throngletsExports,
|
|
499
|
+
policyContext: derivedReplyEnvelope.policyContext,
|
|
569
500
|
};
|
|
570
501
|
}
|
|
502
|
+
const externalContinuity = buildExternalContinuityEnvelope(throngletsExports);
|
|
571
503
|
return {
|
|
572
504
|
systemContext: this.getProtocol(locale),
|
|
573
|
-
dynamicContext: buildDynamicContext(state, opts?.userId,
|
|
574
|
-
metacognitiveNote: metacogNote || undefined,
|
|
575
|
-
decisionContext: decisionCtx || undefined,
|
|
576
|
-
ethicsContext: ethicsCtx || undefined,
|
|
577
|
-
sharedIntentionalityContext: sharedCtx || undefined,
|
|
578
|
-
experientialNarrative: experientialNarrative,
|
|
579
|
-
autonomicDescription: autonomicDesc,
|
|
580
|
-
autonomicState: autonomicResult.state,
|
|
581
|
-
primarySystemsDescription: primarySystemsDescription || undefined,
|
|
582
|
-
policyContext: replyEnvelope.policyContext || undefined,
|
|
583
|
-
}),
|
|
505
|
+
dynamicContext: buildDynamicContext(state, opts?.userId, promptRenderInputs),
|
|
584
506
|
stimulus: appliedStimulus,
|
|
585
|
-
|
|
507
|
+
stimulusConfidence: this.lastStimulusAssessment?.confidence,
|
|
508
|
+
replyEnvelope,
|
|
509
|
+
policyModifiers: derivedReplyEnvelope.policyModifiers,
|
|
586
510
|
subjectivityKernel: replyEnvelope.subjectivityKernel,
|
|
587
511
|
responseContract: replyEnvelope.responseContract,
|
|
588
512
|
generationControls: replyEnvelope.generationControls,
|
|
589
|
-
|
|
513
|
+
sessionBridge,
|
|
514
|
+
writebackFeedback,
|
|
515
|
+
externalContinuity,
|
|
516
|
+
throngletsExports,
|
|
517
|
+
policyContext: derivedReplyEnvelope.policyContext,
|
|
590
518
|
};
|
|
591
519
|
}
|
|
592
520
|
/**
|
|
@@ -645,6 +573,8 @@ export class PsycheEngine {
|
|
|
645
573
|
// Anti-sycophancy: track agreement streak
|
|
646
574
|
state = updateAgreementStreak(state, text);
|
|
647
575
|
// Parse and merge <psyche_update> from LLM output
|
|
576
|
+
let combinedSignals = [];
|
|
577
|
+
let combinedSignalConfidence = opts?.signalConfidence;
|
|
648
578
|
if (text.includes("<psyche_update>")) {
|
|
649
579
|
const parseResult = parsePsycheUpdate(text, NOOP_LOGGER);
|
|
650
580
|
if (parseResult) {
|
|
@@ -652,7 +582,8 @@ export class PsycheEngine {
|
|
|
652
582
|
stateChanged = true;
|
|
653
583
|
// LLM-assisted classification: if algorithm didn't apply a stimulus
|
|
654
584
|
// but LLM classified one, retroactively apply chemistry + drives
|
|
655
|
-
|
|
585
|
+
const overrideAllowed = this.lastStimulusAssessment?.overrideWindow !== "narrow";
|
|
586
|
+
if (parseResult.llmStimulus && (!this._lastAlgorithmApplied || overrideAllowed)) {
|
|
656
587
|
state = {
|
|
657
588
|
...state,
|
|
658
589
|
drives: feedDrives(state.drives, parseResult.llmStimulus),
|
|
@@ -660,11 +591,38 @@ export class PsycheEngine {
|
|
|
660
591
|
const effectiveSensitivity = computeEffectiveSensitivity(getSensitivity(state.mbti), state.drives, parseResult.llmStimulus, state.traitDrift);
|
|
661
592
|
state = {
|
|
662
593
|
...state,
|
|
663
|
-
current: applyStimulus(state.current, parseResult.llmStimulus, effectiveSensitivity, this.cfg.maxChemicalDelta, NOOP_LOGGER),
|
|
594
|
+
current: applyStimulus(state.current, parseResult.llmStimulus, effectiveSensitivity * (overrideAllowed && this._lastAlgorithmApplied ? 0.8 : 1), this.cfg.maxChemicalDelta, NOOP_LOGGER),
|
|
664
595
|
};
|
|
665
596
|
}
|
|
597
|
+
if (parseResult.signals && parseResult.signals.length > 0) {
|
|
598
|
+
combinedSignals.push(...parseResult.signals);
|
|
599
|
+
combinedSignalConfidence = Math.max(combinedSignalConfidence ?? 0, parseResult.signalConfidence ?? 0);
|
|
600
|
+
}
|
|
666
601
|
}
|
|
667
602
|
}
|
|
603
|
+
if (opts?.signals && opts.signals.length > 0) {
|
|
604
|
+
combinedSignals.push(...opts.signals);
|
|
605
|
+
combinedSignalConfidence = Math.max(combinedSignalConfidence ?? 0, opts.signalConfidence ?? 0);
|
|
606
|
+
}
|
|
607
|
+
if (combinedSignals.length > 0) {
|
|
608
|
+
const dedupedSignals = [...new Set(combinedSignals)];
|
|
609
|
+
const pending = createWritebackCalibrations(state, dedupedSignals, {
|
|
610
|
+
userId: opts?.userId,
|
|
611
|
+
confidence: combinedSignalConfidence,
|
|
612
|
+
});
|
|
613
|
+
state = applyWritebackSignals(state, dedupedSignals, {
|
|
614
|
+
userId: opts?.userId,
|
|
615
|
+
confidence: combinedSignalConfidence,
|
|
616
|
+
});
|
|
617
|
+
state = {
|
|
618
|
+
...state,
|
|
619
|
+
pendingWritebackCalibrations: [
|
|
620
|
+
...(state.pendingWritebackCalibrations ?? []),
|
|
621
|
+
...pending,
|
|
622
|
+
].slice(-12),
|
|
623
|
+
};
|
|
624
|
+
stateChanged = true;
|
|
625
|
+
}
|
|
668
626
|
// Persist
|
|
669
627
|
this.state = state;
|
|
670
628
|
await this.storage.save(state);
|
|
@@ -850,6 +808,8 @@ export class PsycheEngine {
|
|
|
850
808
|
},
|
|
851
809
|
},
|
|
852
810
|
pendingRelationSignals: { _default: [] },
|
|
811
|
+
pendingWritebackCalibrations: [],
|
|
812
|
+
lastWritebackFeedback: [],
|
|
853
813
|
meta: {
|
|
854
814
|
agentName: name,
|
|
855
815
|
createdAt: now,
|
|
@@ -889,6 +849,8 @@ export class PsycheEngine {
|
|
|
889
849
|
},
|
|
890
850
|
},
|
|
891
851
|
pendingRelationSignals: { _default: [] },
|
|
852
|
+
pendingWritebackCalibrations: [],
|
|
853
|
+
lastWritebackFeedback: [],
|
|
892
854
|
relationships: opts?.preserveRelationships !== false
|
|
893
855
|
? state.relationships
|
|
894
856
|
: { _default: { ...DEFAULT_RELATIONSHIP } },
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ExternalContinuityEnvelope, ThrongletsExport } from "./types.js";
|
|
2
|
+
export declare const EXTERNAL_CONTINUITY_SIGNAL_KINDS: readonly ["relation-milestone", "writeback-calibration"];
|
|
3
|
+
export declare const EXTERNAL_CONTINUITY_TRACE_KINDS: readonly ["continuity-anchor", "open-loop-anchor"];
|
|
4
|
+
export declare function buildExternalContinuityEnvelope(events: ThrongletsExport[]): ExternalContinuityEnvelope<ThrongletsExport>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export const EXTERNAL_CONTINUITY_SIGNAL_KINDS = [
|
|
2
|
+
"relation-milestone",
|
|
3
|
+
"writeback-calibration",
|
|
4
|
+
];
|
|
5
|
+
export const EXTERNAL_CONTINUITY_TRACE_KINDS = [
|
|
6
|
+
"continuity-anchor",
|
|
7
|
+
"open-loop-anchor",
|
|
8
|
+
];
|
|
9
|
+
export function buildExternalContinuityEnvelope(events) {
|
|
10
|
+
const exports = [...events];
|
|
11
|
+
const signals = exports.filter((event) => event.primitive === "signal");
|
|
12
|
+
const traces = exports.filter((event) => event.primitive === "trace");
|
|
13
|
+
return {
|
|
14
|
+
provider: "thronglets",
|
|
15
|
+
mode: "optional",
|
|
16
|
+
version: 1,
|
|
17
|
+
exports,
|
|
18
|
+
signals,
|
|
19
|
+
traces,
|
|
20
|
+
};
|
|
21
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export { PsycheEngine } from "./core.js";
|
|
|
2
2
|
export type { PsycheEngineConfig, ProcessInputResult, ProcessOutputResult, ProcessOutcomeResult } from "./core.js";
|
|
3
3
|
export { FileStorageAdapter, MemoryStorageAdapter } from "./storage.js";
|
|
4
4
|
export type { StorageAdapter } from "./storage.js";
|
|
5
|
-
export type { PsycheState, MBTIType, Locale, StimulusType, ChemicalState, ChemicalSnapshot, SelfModel, RelationshipState, EmpathyEntry, EmotionPattern, DriveType, InnateDrives, LearningState, LearnedVectorAdjustment, PredictionRecord, OutcomeScore, OutcomeSignals, AttachmentStyle, AttachmentData, MetacognitiveState, RegulationRecord, DefensePatternRecord, RegulationStrategyType, DefenseMechanismType, PersonhoodState, PersistedCausalInsight, GrowthDirection, PersonalityTraits, PsycheMode, PolicyModifiers, SubjectivityKernel, ResponseContract, GenerationControls, AppraisalAxes, SubjectResidue, TaskPlaneState, SubjectPlaneState, RelationPlaneState, AmbiguityPlaneState, RelationMoveType, RelationMove, OpenLoopType, OpenLoopState, PendingRelationSignalState, DyadicFieldState, TraitDriftState, EnergyBudgets, ClassifierProvider, ClassifierContext, ClassificationResult, } from "./types.js";
|
|
5
|
+
export type { PsycheState, MBTIType, Locale, StimulusType, ChemicalState, ChemicalSnapshot, SelfModel, RelationshipState, EmpathyEntry, EmotionPattern, DriveType, InnateDrives, LearningState, LearnedVectorAdjustment, PredictionRecord, OutcomeScore, OutcomeSignals, AttachmentStyle, AttachmentData, MetacognitiveState, RegulationRecord, DefensePatternRecord, RegulationStrategyType, DefenseMechanismType, PersonhoodState, PersistedCausalInsight, GrowthDirection, PersonalityTraits, PsycheMode, PolicyModifiers, SubjectivityKernel, ResponseContract, GenerationControls, AppraisalAxes, SubjectResidue, TaskPlaneState, SubjectPlaneState, RelationPlaneState, AmbiguityPlaneState, RelationMoveType, RelationMove, OpenLoopType, OpenLoopState, PendingRelationSignalState, DyadicFieldState, SessionBridgeState, ThrongletsExportSubject, ThrongletsExportPrimitive, ThrongletsExportBase, RelationMilestoneExport, OpenLoopAnchorExport, WritebackCalibrationExport, ContinuityAnchorExport, ThrongletsExport, ThrongletsExportState, ExternalContinuityEvent, ExternalContinuityEnvelope, ThrongletsTraceTaxonomy, ThrongletsExternalContinuityRecord, ThrongletsTracePayload, ThrongletsTraceSerializationOptions, WritebackSignalType, WritebackSignalWeightMap, PendingWritebackCalibration, WritebackCalibrationFeedback, WritebackCalibrationMetric, TraitDriftState, EnergyBudgets, ClassifierProvider, ClassifierContext, ClassificationResult, } from "./types.js";
|
|
6
6
|
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, DEFAULT_TRAIT_DRIFT, DEFAULT_ENERGY_BUDGETS, DEFAULT_APPRAISAL_AXES, DEFAULT_SUBJECT_RESIDUE, DEFAULT_DYADIC_FIELD, } from "./types.js";
|
|
7
7
|
export { computeSelfReflection, computeEmotionalTendency, buildSelfReflectionContext } from "./self-recognition.js";
|
|
8
8
|
export type { SelfReflection } from "./self-recognition.js";
|
|
@@ -26,8 +26,13 @@ export type { DecisionBiasVector, AttentionWeights } from "./decision-bias.js";
|
|
|
26
26
|
export { computeSubjectivityKernel, buildSubjectivityContext } from "./subjectivity.js";
|
|
27
27
|
export { computeResponseContract, buildResponseContractContext } from "./response-contract.js";
|
|
28
28
|
export { deriveGenerationControls } from "./host-controls.js";
|
|
29
|
+
export { deriveReplyEnvelope } from "./reply-envelope.js";
|
|
30
|
+
export type { ReplyEnvelope } from "./reply-envelope.js";
|
|
29
31
|
export { computeAppraisalAxes, mergeAppraisalResidue, getResidueIntensity } from "./appraisal.js";
|
|
30
|
-
export { computeRelationMove, evolveDyadicField, evolvePendingRelationSignals, getLoopPressure } from "./relation-dynamics.js";
|
|
32
|
+
export { computeRelationMove, evolveDyadicField, evolvePendingRelationSignals, getLoopPressure, applySessionBridge, applyWritebackSignals, createWritebackCalibrations, evaluateWritebackCalibrations, } from "./relation-dynamics.js";
|
|
33
|
+
export { EXTERNAL_CONTINUITY_SIGNAL_KINDS, EXTERNAL_CONTINUITY_TRACE_KINDS, buildExternalContinuityEnvelope, } from "./external-continuity.js";
|
|
34
|
+
export { deriveThrongletsExports } from "./thronglets-export.js";
|
|
35
|
+
export { taxonomyForThrongletsExport, serializeThrongletsExportAsTrace, serializeExternalContinuityForThronglets, } from "./thronglets-runtime.js";
|
|
31
36
|
export { computeExperientialField, computeCoherence, detectUnnamedEmotion, computeAffectCore } from "./experiential-field.js";
|
|
32
37
|
export type { ExperientialField, ExperientialQuality, ConstructionContext } from "./experiential-field.js";
|
|
33
38
|
export { computeGenerativeSelf, predictSelfReaction, detectInternalConflicts, buildIdentityNarrative } from "./generative-self.js";
|
package/dist/index.js
CHANGED
|
@@ -37,8 +37,12 @@ export { computeDecisionBias, computeAttentionWeights, computeExploreExploit, bu
|
|
|
37
37
|
export { computeSubjectivityKernel, buildSubjectivityContext } from "./subjectivity.js";
|
|
38
38
|
export { computeResponseContract, buildResponseContractContext } from "./response-contract.js";
|
|
39
39
|
export { deriveGenerationControls } from "./host-controls.js";
|
|
40
|
+
export { deriveReplyEnvelope } from "./reply-envelope.js";
|
|
40
41
|
export { computeAppraisalAxes, mergeAppraisalResidue, getResidueIntensity } from "./appraisal.js";
|
|
41
|
-
export { computeRelationMove, evolveDyadicField, evolvePendingRelationSignals, getLoopPressure } from "./relation-dynamics.js";
|
|
42
|
+
export { computeRelationMove, evolveDyadicField, evolvePendingRelationSignals, getLoopPressure, applySessionBridge, applyWritebackSignals, createWritebackCalibrations, evaluateWritebackCalibrations, } from "./relation-dynamics.js";
|
|
43
|
+
export { EXTERNAL_CONTINUITY_SIGNAL_KINDS, EXTERNAL_CONTINUITY_TRACE_KINDS, buildExternalContinuityEnvelope, } from "./external-continuity.js";
|
|
44
|
+
export { deriveThrongletsExports } from "./thronglets-export.js";
|
|
45
|
+
export { taxonomyForThrongletsExport, serializeThrongletsExportAsTrace, serializeExternalContinuityForThronglets, } from "./thronglets-runtime.js";
|
|
42
46
|
// Experiential field (P6 + P8 Barrett construction)
|
|
43
47
|
export { computeExperientialField, computeCoherence, detectUnnamedEmotion, computeAffectCore } from "./experiential-field.js";
|
|
44
48
|
// Generative self (P6)
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { AppraisalAxes, Locale, PsycheState, ResolvedRelationContext, StimulusType } from "./types.js";
|
|
2
|
+
import { computeAutonomicResult } from "./autonomic.js";
|
|
3
|
+
import type { DerivedReplyEnvelope } from "./reply-envelope.js";
|
|
4
|
+
export interface ReflectiveTurnArtifacts {
|
|
5
|
+
state: PsycheState;
|
|
6
|
+
locale: Locale;
|
|
7
|
+
autonomicState: ReturnType<typeof computeAutonomicResult>["state"];
|
|
8
|
+
autonomicDescription?: string;
|
|
9
|
+
primarySystemsDescription?: string;
|
|
10
|
+
metacognitiveNote?: string;
|
|
11
|
+
decisionContext?: string;
|
|
12
|
+
ethicsContext?: string;
|
|
13
|
+
sharedIntentionalityContext?: string;
|
|
14
|
+
experientialNarrative?: string;
|
|
15
|
+
replyEnvelope: DerivedReplyEnvelope;
|
|
16
|
+
}
|
|
17
|
+
export declare function runReflectiveTurnPhases(input: {
|
|
18
|
+
state: PsycheState;
|
|
19
|
+
appraisalAxes: AppraisalAxes;
|
|
20
|
+
relationContext: ResolvedRelationContext;
|
|
21
|
+
appliedStimulus: StimulusType | null;
|
|
22
|
+
userText?: string;
|
|
23
|
+
userId?: string;
|
|
24
|
+
localeFallback: Locale;
|
|
25
|
+
personalityIntensity: number;
|
|
26
|
+
classificationConfidence?: number;
|
|
27
|
+
minutesElapsed: number;
|
|
28
|
+
nowIso: string;
|
|
29
|
+
writebackNote?: string;
|
|
30
|
+
}): ReflectiveTurnArtifacts;
|