open-agents-ai 0.187.510 → 0.187.511

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
@@ -516798,6 +516798,148 @@ var init_homeostaticRegulation = __esm({
516798
516798
  }
516799
516799
  });
516800
516800
 
516801
+ // packages/memory/dist/socialInfluence.js
516802
+ function clamp2(x, lo, hi) {
516803
+ if (!Number.isFinite(x))
516804
+ return (lo + hi) / 2;
516805
+ if (x < lo)
516806
+ return lo;
516807
+ if (x > hi)
516808
+ return hi;
516809
+ return x;
516810
+ }
516811
+ function clamp012(x) {
516812
+ return clamp2(x, 0, 1);
516813
+ }
516814
+ function conformityBias(myConfidence, groupAgreement, memoryAlignsWithGroup, weight = 0.5) {
516815
+ const conf = clamp012(myConfidence);
516816
+ const agree = clamp012(groupAgreement);
516817
+ const w = clamp012(weight);
516818
+ const pull = (agree - 0.5) * 2 * conf * w;
516819
+ return memoryAlignsWithGroup ? 1 + pull : 1 - pull;
516820
+ }
516821
+ function authorityBias(sourceTrust, weight = 0.4) {
516822
+ const t2 = clamp012(sourceTrust);
516823
+ const w = clamp012(weight);
516824
+ return 1 + (t2 - 0.5) * 2 * w;
516825
+ }
516826
+ function noveltyBias(memoryDivergence, weight = 0.3) {
516827
+ const d2 = clamp012(memoryDivergence);
516828
+ const w = clamp012(weight);
516829
+ return 1 + d2 * w;
516830
+ }
516831
+ function reciprocityBias(relationshipStrength, relationshipValence, weight = 0.3) {
516832
+ const s2 = clamp012(relationshipStrength);
516833
+ const v = clamp2(relationshipValence, -1, 1);
516834
+ const w = clamp012(weight);
516835
+ return 1 + s2 * v * w;
516836
+ }
516837
+ function applyInfluence(baseScore, ctx3) {
516838
+ let m2 = 1;
516839
+ if (ctx3.myConfidence != null && ctx3.groupAgreement != null && ctx3.memoryAlignsWithGroup != null) {
516840
+ m2 *= conformityBias(ctx3.myConfidence, ctx3.groupAgreement, ctx3.memoryAlignsWithGroup, ctx3.weights?.conformity);
516841
+ }
516842
+ if (ctx3.sourceTrust != null) {
516843
+ m2 *= authorityBias(ctx3.sourceTrust, ctx3.weights?.authority);
516844
+ }
516845
+ if (ctx3.memoryDivergence != null) {
516846
+ m2 *= noveltyBias(ctx3.memoryDivergence, ctx3.weights?.novelty);
516847
+ }
516848
+ if (ctx3.relationshipStrength != null && ctx3.relationshipValence != null) {
516849
+ m2 *= reciprocityBias(ctx3.relationshipStrength, ctx3.relationshipValence, ctx3.weights?.reciprocity);
516850
+ }
516851
+ return baseScore * m2;
516852
+ }
516853
+ var init_socialInfluence = __esm({
516854
+ "packages/memory/dist/socialInfluence.js"() {
516855
+ "use strict";
516856
+ }
516857
+ });
516858
+
516859
+ // packages/memory/dist/embodiedTrace.js
516860
+ function clamp3(x, lo, hi) {
516861
+ if (!Number.isFinite(x))
516862
+ return (lo + hi) / 2;
516863
+ if (x < lo)
516864
+ return lo;
516865
+ if (x > hi)
516866
+ return hi;
516867
+ return x;
516868
+ }
516869
+ function clamp013(x) {
516870
+ return clamp3(x, 0, 1);
516871
+ }
516872
+ function nonNegative(x) {
516873
+ if (!Number.isFinite(x) || x < 0)
516874
+ return 0;
516875
+ return x;
516876
+ }
516877
+ function buildTrace(input) {
516878
+ const i2 = input ?? {};
516879
+ const used = nonNegative(i2.contextTokensUsed ?? DEFAULT_TRACE.contextTokensUsed);
516880
+ const max = nonNegative(i2.contextTokensMax ?? DEFAULT_TRACE.contextTokensMax);
516881
+ const derivedLoad = max > 0 ? used / max : 0;
516882
+ const load2 = i2.cognitiveLoad != null ? clamp013(i2.cognitiveLoad) : clamp013(derivedLoad);
516883
+ return {
516884
+ durationMs: nonNegative(i2.durationMs ?? DEFAULT_TRACE.durationMs),
516885
+ hesitationCount: Math.max(0, Math.floor(i2.hesitationCount ?? 0)),
516886
+ retryCount: Math.max(0, Math.floor(i2.retryCount ?? 0)),
516887
+ intensity: clamp013(i2.intensity ?? DEFAULT_TRACE.intensity),
516888
+ visualGist: typeof i2.visualGist === "string" ? i2.visualGist : void 0,
516889
+ auditoryGist: typeof i2.auditoryGist === "string" ? i2.auditoryGist : void 0,
516890
+ screenState: typeof i2.screenState === "string" ? i2.screenState : void 0,
516891
+ confidence: clamp013(i2.confidence ?? DEFAULT_TRACE.confidence),
516892
+ cognitiveLoad: load2,
516893
+ contextTokensUsed: used,
516894
+ contextTokensMax: max,
516895
+ affect: sanitizeEmotionalState(i2.affect ?? NEUTRAL_AFFECT),
516896
+ timeOfDay: clamp3(Math.floor(i2.timeOfDay ?? DEFAULT_TRACE.timeOfDay), 0, 23),
516897
+ sessionDurationMin: nonNegative(i2.sessionDurationMin ?? 0),
516898
+ consecutiveActions: Math.max(0, Math.floor(i2.consecutiveActions ?? 0))
516899
+ };
516900
+ }
516901
+ function attachTrace(metadata, trace) {
516902
+ return { ...metadata ?? {}, [EMBODIED_KEY]: trace };
516903
+ }
516904
+ function extractTrace(metadata) {
516905
+ if (!metadata || typeof metadata !== "object")
516906
+ return null;
516907
+ const raw = metadata[EMBODIED_KEY];
516908
+ if (!raw || typeof raw !== "object")
516909
+ return null;
516910
+ return buildTrace(raw);
516911
+ }
516912
+ function engagementScore(trace) {
516913
+ const alertness = 1 - trace.cognitiveLoad;
516914
+ return clamp013((trace.intensity + alertness + trace.confidence) / 3);
516915
+ }
516916
+ function wasHesitant(trace, threshold = 0.4) {
516917
+ return trace.hesitationCount >= 2 || trace.retryCount >= 1 || trace.confidence < threshold;
516918
+ }
516919
+ var NEUTRAL_AFFECT, DEFAULT_TRACE, EMBODIED_KEY;
516920
+ var init_embodiedTrace = __esm({
516921
+ "packages/memory/dist/embodiedTrace.js"() {
516922
+ "use strict";
516923
+ init_homeostaticRegulation();
516924
+ NEUTRAL_AFFECT = { valence: 0, arousal: 0 };
516925
+ DEFAULT_TRACE = {
516926
+ durationMs: 0,
516927
+ hesitationCount: 0,
516928
+ retryCount: 0,
516929
+ intensity: 0,
516930
+ confidence: 0.5,
516931
+ cognitiveLoad: 0,
516932
+ contextTokensUsed: 0,
516933
+ contextTokensMax: 0,
516934
+ affect: NEUTRAL_AFFECT,
516935
+ timeOfDay: 0,
516936
+ sessionDurationMin: 0,
516937
+ consecutiveActions: 0
516938
+ };
516939
+ EMBODIED_KEY = "embodiedTrace";
516940
+ }
516941
+ });
516942
+
516801
516943
  // packages/memory/dist/pprRetrieval.js
516802
516944
  function readEpisodeAffect(metadata) {
516803
516945
  if (!metadata || typeof metadata !== "object")
@@ -516994,14 +517136,30 @@ function retrieveByPPR(query, graph, episodeStore, config) {
516994
517136
  }
516995
517137
  }
516996
517138
  let entries = [...episodeScores.entries()];
516997
- if (cfg.currentEmotionalState) {
517139
+ const engagementWeight = cfg.engagementWeight ?? 0;
517140
+ if (cfg.currentEmotionalState || cfg.influenceFor || engagementWeight !== 0) {
516998
517141
  const current = cfg.currentEmotionalState;
516999
517142
  entries = entries.map(([epId, payload]) => {
517000
517143
  const ep = episodeStore.get(epId);
517001
- const memoryAffect = ep ? readEpisodeAffect(ep.metadata) : null;
517002
- if (!memoryAffect)
517003
- return [epId, payload];
517004
- return [epId, { ...payload, score: modulateRetrievalScore(payload.score, current, memoryAffect) }];
517144
+ let score = payload.score;
517145
+ if (current) {
517146
+ const memoryAffect = ep ? readEpisodeAffect(ep.metadata) : null;
517147
+ if (memoryAffect)
517148
+ score = modulateRetrievalScore(score, current, memoryAffect);
517149
+ }
517150
+ if (cfg.influenceFor) {
517151
+ const ctx3 = cfg.influenceFor(epId);
517152
+ if (ctx3)
517153
+ score = applyInfluence(score, ctx3);
517154
+ }
517155
+ if (engagementWeight !== 0 && ep) {
517156
+ const trace = extractTrace(ep.metadata);
517157
+ if (trace) {
517158
+ const eng = engagementScore(trace);
517159
+ score = score * (1 + (eng - 0.5) * engagementWeight);
517160
+ }
517161
+ }
517162
+ return [epId, { ...payload, score }];
517005
517163
  });
517006
517164
  }
517007
517165
  const ranked = entries.sort((a2, b) => b[1].score - a2[1].score).slice(0, cfg.topK);
@@ -517025,6 +517183,8 @@ var init_pprRetrieval = __esm({
517025
517183
  "use strict";
517026
517184
  init_zettelkasten();
517027
517185
  init_homeostaticRegulation();
517186
+ init_socialInfluence();
517187
+ init_embodiedTrace();
517028
517188
  DEFAULT_CONFIG4 = {
517029
517189
  damping: 0.5,
517030
517190
  maxIterations: 50,
@@ -517050,6 +517210,28 @@ function readEpisodeAffect2(metadata) {
517050
517210
  return null;
517051
517211
  return sanitizeEmotionalState(affect);
517052
517212
  }
517213
+ function readEpisodeEngagement(metadata) {
517214
+ if (!metadata || typeof metadata !== "object")
517215
+ return null;
517216
+ const trace = metadata["embodiedTrace"];
517217
+ if (!trace || typeof trace !== "object")
517218
+ return null;
517219
+ const t2 = trace;
517220
+ const intensity = typeof t2["intensity"] === "number" ? clamp01Local(t2["intensity"]) : 0;
517221
+ const cogLoad = typeof t2["cognitiveLoad"] === "number" ? clamp01Local(t2["cognitiveLoad"]) : 0;
517222
+ const conf = typeof t2["confidence"] === "number" ? clamp01Local(t2["confidence"]) : 0.5;
517223
+ const alertness = 1 - cogLoad;
517224
+ return clamp01Local((intensity + alertness + conf) / 3);
517225
+ }
517226
+ function clamp01Local(x) {
517227
+ if (!Number.isFinite(x))
517228
+ return 0;
517229
+ if (x < 0)
517230
+ return 0;
517231
+ if (x > 1)
517232
+ return 1;
517233
+ return x;
517234
+ }
517053
517235
  function sanitizeImportance(raw, fallback = 5) {
517054
517236
  if (typeof raw !== "number" || !Number.isFinite(raw))
517055
517237
  return fallback;
@@ -517118,6 +517300,7 @@ var init_episodeStore = __esm({
517118
517300
  init_db();
517119
517301
  init_zettelkasten();
517120
517302
  init_homeostaticRegulation();
517303
+ init_socialInfluence();
517121
517304
  init_pprRetrieval();
517122
517305
  DECAY_TAU = {
517123
517306
  session: 36e5,
@@ -517139,6 +517322,22 @@ var init_episodeStore = __esm({
517139
517322
  graph = null;
517140
517323
  /** WO-AM-05: Zettelkasten config for neighbor linking */
517141
517324
  zettelConfig = { topK: 5, minSimilarity: 0.7, evolutionThreshold: 0.6, maxLinksPerEpisode: 10 };
517325
+ /** AUDIT-3 (A2 completion): minimum importance an inserted episode must
517326
+ * meet (or beat) to actually persist. When 0 (default), all episodes
517327
+ * pass the gate — preserves backward-compatible behavior. The
517328
+ * orchestrator sets this from `MemoryStageContext.importanceFloor()`
517329
+ * so wisdom-stage agents store fewer routine episodes than
517330
+ * exploration-stage agents. */
517331
+ importanceFloor = 0;
517332
+ /** AUDIT-3: opt-in setter so the orchestrator can override the
517333
+ * hardcoded zettelConfig at session start (and after sleep
517334
+ * consolidation) with stage-derived values. */
517335
+ setZettelConfig(partial) {
517336
+ this.zettelConfig = { ...this.zettelConfig, ...partial };
517337
+ }
517338
+ setImportanceFloor(floor) {
517339
+ this.importanceFloor = Number.isFinite(floor) && floor > 0 ? floor : 0;
517340
+ }
517142
517341
  constructor(dbPath, graph, zettelConfig) {
517143
517342
  const dir = dbPath === ":memory:" ? null : join75(dbPath, "..");
517144
517343
  if (dir && !existsSync59(dir))
@@ -517190,6 +517389,9 @@ var init_episodeStore = __esm({
517190
517389
  const rawImportance = ep.importance ?? autoImportance(ep.toolName ?? null, modality, ep.content);
517191
517390
  const modulated = ep.emotionalState ? modulateImportance(sanitizeImportance(rawImportance), ep.emotionalState) : sanitizeImportance(rawImportance);
517192
517391
  const importance = sanitizeImportance(modulated);
517392
+ if (this.importanceFloor > 0 && importance < this.importanceFloor) {
517393
+ return "";
517394
+ }
517193
517395
  const decayClass = ep.decayClass ?? autoDecayClass(ep.toolName ?? null, modality, ep.content);
517194
517396
  const existing = this.db.prepare("SELECT id FROM episodes WHERE content_hash = ? AND session_id = ? LIMIT 1").get(contentHash, ep.sessionId ?? null);
517195
517397
  if (existing)
@@ -517314,7 +517516,18 @@ var init_episodeStore = __esm({
517314
517516
  if (opts.currentEmotionalState) {
517315
517517
  const memoryAffect = readEpisodeAffect2(ep.metadata);
517316
517518
  if (memoryAffect) {
517317
- score = modulateRetrievalScore(baseScore, opts.currentEmotionalState, memoryAffect);
517519
+ score = modulateRetrievalScore(score, opts.currentEmotionalState, memoryAffect);
517520
+ }
517521
+ }
517522
+ if (opts.influenceFor) {
517523
+ const ctx3 = opts.influenceFor(ep);
517524
+ if (ctx3)
517525
+ score = applyInfluence(score, ctx3);
517526
+ }
517527
+ if ((opts.engagementWeight ?? 0) !== 0) {
517528
+ const eng = readEpisodeEngagement(ep.metadata);
517529
+ if (eng != null) {
517530
+ score = score * (1 + (eng - 0.5) * (opts.engagementWeight ?? 0));
517318
517531
  }
517319
517532
  }
517320
517533
  return { episode: ep, score };
@@ -520702,7 +520915,7 @@ var init_selfModel = __esm({
520702
520915
  });
520703
520916
 
520704
520917
  // packages/memory/dist/predictionStore.js
520705
- function clamp012(x) {
520918
+ function clamp014(x) {
520706
520919
  if (!Number.isFinite(x))
520707
520920
  return 0.5;
520708
520921
  if (x < 0)
@@ -520733,7 +520946,7 @@ function durationError(predicted, actual) {
520733
520946
  return 0;
520734
520947
  const safePred = Math.max(predicted, 50);
520735
520948
  const ratio = Math.abs(predicted - actual) / safePred;
520736
- return clamp012(ratio);
520949
+ return clamp014(ratio);
520737
520950
  }
520738
520951
  var DEFAULT_AXIS_WEIGHTS, PredictionStore;
520739
520952
  var init_predictionStore = __esm({
@@ -520759,7 +520972,7 @@ var init_predictionStore = __esm({
520759
520972
  predict(p2) {
520760
520973
  const sanitized = {
520761
520974
  ...p2,
520762
- predictedConfidence: clamp012(p2.predictedConfidence),
520975
+ predictedConfidence: clamp014(p2.predictedConfidence),
520763
520976
  predictedDuration: p2.predictedDuration != null && Number.isFinite(p2.predictedDuration) ? Math.max(0, p2.predictedDuration) : null
520764
520977
  };
520765
520978
  this.pending.set(p2.correlationId, sanitized);
@@ -520773,14 +520986,14 @@ var init_predictionStore = __esm({
520773
520986
  this.pending.delete(correlationId);
520774
520987
  const actualDuration = observed.actualDuration != null && Number.isFinite(observed.actualDuration) ? Math.max(0, observed.actualDuration) : null;
520775
520988
  const sim = tokenSimilarity(pred.predictedOutcome, observed.actualOutcome);
520776
- const outcomeErr = clamp012(1 - sim);
520989
+ const outcomeErr = clamp014(1 - sim);
520777
520990
  const successErr = pred.predictedSuccess === observed.actualSuccess ? 0 : 1;
520778
- const confidenceErr = clamp012(observed.actualSuccess ? 1 - pred.predictedConfidence : pred.predictedConfidence);
520991
+ const confidenceErr = clamp014(observed.actualSuccess ? 1 - pred.predictedConfidence : pred.predictedConfidence);
520779
520992
  const durationErr = durationError(pred.predictedDuration, actualDuration);
520780
520993
  const w = this.axisWeights;
520781
520994
  const total = w.outcome * outcomeErr + w.success * successErr + w.confidence * confidenceErr + w.duration * durationErr;
520782
520995
  const sumWeights = w.outcome + w.success + w.confidence + w.duration;
520783
- const errorMagnitude = clamp012(sumWeights > 0 ? total / sumWeights : 0);
520996
+ const errorMagnitude = clamp014(sumWeights > 0 ? total / sumWeights : 0);
520784
520997
  const errorByAxis = {
520785
520998
  outcome: outcomeErr,
520786
520999
  success: successErr,
@@ -520798,7 +521011,7 @@ var init_predictionStore = __esm({
520798
521011
  errorByAxis,
520799
521012
  dominantAxis,
520800
521013
  // Learning signal: large errors with high confidence drive bigger updates
520801
- learningSignal: clamp012(errorMagnitude * (0.5 + 0.5 * pred.predictedConfidence))
521014
+ learningSignal: clamp014(errorMagnitude * (0.5 + 0.5 * pred.predictedConfidence))
520802
521015
  };
520803
521016
  this.history.push(err);
520804
521017
  if (this.history.length > this.capacity) {
@@ -520945,7 +521158,7 @@ var init_predictionStore = __esm({
520945
521158
  errorMagnitude: r2.error_magnitude ?? 0,
520946
521159
  errorByAxis: axes,
520947
521160
  dominantAxis: r2.dominant_axis ?? "outcome",
520948
- learningSignal: clamp012((r2.error_magnitude ?? 0) * 0.75)
521161
+ learningSignal: clamp014((r2.error_magnitude ?? 0) * 0.75)
520949
521162
  });
520950
521163
  }
520951
521164
  }
@@ -520953,90 +521166,6 @@ var init_predictionStore = __esm({
520953
521166
  }
520954
521167
  });
520955
521168
 
520956
- // packages/memory/dist/embodiedTrace.js
520957
- function clamp2(x, lo, hi) {
520958
- if (!Number.isFinite(x))
520959
- return (lo + hi) / 2;
520960
- if (x < lo)
520961
- return lo;
520962
- if (x > hi)
520963
- return hi;
520964
- return x;
520965
- }
520966
- function clamp013(x) {
520967
- return clamp2(x, 0, 1);
520968
- }
520969
- function nonNegative(x) {
520970
- if (!Number.isFinite(x) || x < 0)
520971
- return 0;
520972
- return x;
520973
- }
520974
- function buildTrace(input) {
520975
- const i2 = input ?? {};
520976
- const used = nonNegative(i2.contextTokensUsed ?? DEFAULT_TRACE.contextTokensUsed);
520977
- const max = nonNegative(i2.contextTokensMax ?? DEFAULT_TRACE.contextTokensMax);
520978
- const derivedLoad = max > 0 ? used / max : 0;
520979
- const load2 = i2.cognitiveLoad != null ? clamp013(i2.cognitiveLoad) : clamp013(derivedLoad);
520980
- return {
520981
- durationMs: nonNegative(i2.durationMs ?? DEFAULT_TRACE.durationMs),
520982
- hesitationCount: Math.max(0, Math.floor(i2.hesitationCount ?? 0)),
520983
- retryCount: Math.max(0, Math.floor(i2.retryCount ?? 0)),
520984
- intensity: clamp013(i2.intensity ?? DEFAULT_TRACE.intensity),
520985
- visualGist: typeof i2.visualGist === "string" ? i2.visualGist : void 0,
520986
- auditoryGist: typeof i2.auditoryGist === "string" ? i2.auditoryGist : void 0,
520987
- screenState: typeof i2.screenState === "string" ? i2.screenState : void 0,
520988
- confidence: clamp013(i2.confidence ?? DEFAULT_TRACE.confidence),
520989
- cognitiveLoad: load2,
520990
- contextTokensUsed: used,
520991
- contextTokensMax: max,
520992
- affect: sanitizeEmotionalState(i2.affect ?? NEUTRAL_AFFECT),
520993
- timeOfDay: clamp2(Math.floor(i2.timeOfDay ?? DEFAULT_TRACE.timeOfDay), 0, 23),
520994
- sessionDurationMin: nonNegative(i2.sessionDurationMin ?? 0),
520995
- consecutiveActions: Math.max(0, Math.floor(i2.consecutiveActions ?? 0))
520996
- };
520997
- }
520998
- function attachTrace(metadata, trace) {
520999
- return { ...metadata ?? {}, [EMBODIED_KEY]: trace };
521000
- }
521001
- function extractTrace(metadata) {
521002
- if (!metadata || typeof metadata !== "object")
521003
- return null;
521004
- const raw = metadata[EMBODIED_KEY];
521005
- if (!raw || typeof raw !== "object")
521006
- return null;
521007
- return buildTrace(raw);
521008
- }
521009
- function engagementScore(trace) {
521010
- const alertness = 1 - trace.cognitiveLoad;
521011
- return clamp013((trace.intensity + alertness + trace.confidence) / 3);
521012
- }
521013
- function wasHesitant(trace, threshold = 0.4) {
521014
- return trace.hesitationCount >= 2 || trace.retryCount >= 1 || trace.confidence < threshold;
521015
- }
521016
- var NEUTRAL_AFFECT, DEFAULT_TRACE, EMBODIED_KEY;
521017
- var init_embodiedTrace = __esm({
521018
- "packages/memory/dist/embodiedTrace.js"() {
521019
- "use strict";
521020
- init_homeostaticRegulation();
521021
- NEUTRAL_AFFECT = { valence: 0, arousal: 0 };
521022
- DEFAULT_TRACE = {
521023
- durationMs: 0,
521024
- hesitationCount: 0,
521025
- retryCount: 0,
521026
- intensity: 0,
521027
- confidence: 0.5,
521028
- cognitiveLoad: 0,
521029
- contextTokensUsed: 0,
521030
- contextTokensMax: 0,
521031
- affect: NEUTRAL_AFFECT,
521032
- timeOfDay: 0,
521033
- sessionDurationMin: 0,
521034
- consecutiveActions: 0
521035
- };
521036
- EMBODIED_KEY = "embodiedTrace";
521037
- }
521038
- });
521039
-
521040
521169
  // packages/memory/dist/sleepConsolidation.js
521041
521170
  function slowWaveReplay(db, options2 = {}) {
521042
521171
  const topK = options2.topK ?? 20;
@@ -521118,10 +521247,11 @@ function remDream(db, options2 = {}) {
521118
521247
  return { cycle: emptyCycle("rem", start2) };
521119
521248
  }
521120
521249
  const walkDepth = Math.max(1, options2.walkDepth ?? 3);
521250
+ const minSim = options2.minSimilarity ?? 0.6;
521121
521251
  for (const seed of seedRows) {
521122
- let temporalNeighbors = [];
521252
+ let candidateRows = [];
521123
521253
  try {
521124
- temporalNeighbors = db.prepare(`SELECT id FROM episodes
521254
+ candidateRows = db.prepare(`SELECT id, embedding, timestamp AS ts FROM episodes
521125
521255
  WHERE session_id IS (SELECT session_id FROM episodes WHERE id = ?)
521126
521256
  AND id != ?
521127
521257
  ORDER BY timestamp DESC
@@ -521129,11 +521259,40 @@ function remDream(db, options2 = {}) {
521129
521259
  } catch {
521130
521260
  continue;
521131
521261
  }
521132
- if (temporalNeighbors.length > walkDepth) {
521133
- const target = temporalNeighbors[walkDepth];
521262
+ if (candidateRows.length === 0)
521263
+ continue;
521264
+ let seedEmb = null;
521265
+ try {
521266
+ seedEmb = db.prepare(`SELECT embedding FROM episodes WHERE id = ?`).get(seed.id)?.embedding ?? null;
521267
+ } catch {
521268
+ }
521269
+ let chosen = null;
521270
+ const seedFloat = toFloat32(seedEmb);
521271
+ if (seedFloat) {
521272
+ const distantCandidates = candidateRows.slice(walkDepth);
521273
+ let bestSim = minSim;
521274
+ let bestId = null;
521275
+ for (const cand of distantCandidates) {
521276
+ const candFloat = toFloat32(cand.embedding);
521277
+ if (!candFloat || candFloat.length !== seedFloat.length)
521278
+ continue;
521279
+ const sim = cosineSim(seedFloat, candFloat);
521280
+ if (sim > bestSim) {
521281
+ bestSim = sim;
521282
+ bestId = cand.id;
521283
+ }
521284
+ }
521285
+ if (bestId) {
521286
+ chosen = { id: bestId, reason: `rem-embedding-similarity:${bestSim.toFixed(3)}` };
521287
+ }
521288
+ }
521289
+ if (!chosen && candidateRows.length > walkDepth) {
521290
+ const target = candidateRows[walkDepth];
521134
521291
  if (target)
521135
- novel.push({ from: seed.id, to: target.id, reason: "rem-temporal-distance" });
521292
+ chosen = { id: target.id, reason: "rem-temporal-distance" };
521136
521293
  }
521294
+ if (chosen)
521295
+ novel.push({ from: seed.id, to: chosen.id, reason: chosen.reason });
521137
521296
  }
521138
521297
  if (options2.graph && novel.length > 0) {
521139
521298
  for (const link of novel) {
@@ -521311,6 +521470,42 @@ function emptyCycle(phase, start2) {
521311
521470
  integratedNodes: []
521312
521471
  };
521313
521472
  }
521473
+ function toFloat32(raw) {
521474
+ if (raw == null)
521475
+ return null;
521476
+ if (raw instanceof Float32Array) {
521477
+ return new Float32Array(raw);
521478
+ }
521479
+ if (raw instanceof Uint8Array) {
521480
+ if (raw.byteLength === 0 || raw.byteLength % 4 !== 0)
521481
+ return null;
521482
+ const fresh = new Uint8Array(raw.byteLength);
521483
+ fresh.set(raw);
521484
+ return new Float32Array(fresh.buffer, 0, raw.byteLength / 4);
521485
+ }
521486
+ if (raw instanceof ArrayBuffer) {
521487
+ if (raw.byteLength === 0 || raw.byteLength % 4 !== 0)
521488
+ return null;
521489
+ return new Float32Array(raw.slice(0));
521490
+ }
521491
+ return null;
521492
+ }
521493
+ function cosineSim(a2, b) {
521494
+ if (a2.length !== b.length || a2.length === 0)
521495
+ return 0;
521496
+ let dot = 0, na = 0, nb = 0;
521497
+ for (let i2 = 0; i2 < a2.length; i2++) {
521498
+ const x = a2[i2];
521499
+ const y = b[i2];
521500
+ dot += x * y;
521501
+ na += x * x;
521502
+ nb += y * y;
521503
+ }
521504
+ const denom = Math.sqrt(na) * Math.sqrt(nb);
521505
+ if (denom === 0)
521506
+ return 0;
521507
+ return dot / denom;
521508
+ }
521314
521509
  function episodeCount(db) {
521315
521510
  try {
521316
521511
  const row = db.prepare(`SELECT COUNT(*) AS c FROM episodes`).get();
@@ -521328,7 +521523,7 @@ var init_sleepConsolidation = __esm({
521328
521523
 
521329
521524
  // packages/memory/dist/socialMemory.js
521330
521525
  import { randomUUID as randomUUID11 } from "node:crypto";
521331
- function clamp3(x, lo, hi) {
521526
+ function clamp4(x, lo, hi) {
521332
521527
  if (!Number.isFinite(x))
521333
521528
  return (lo + hi) / 2;
521334
521529
  if (x < lo)
@@ -521337,19 +521532,19 @@ function clamp3(x, lo, hi) {
521337
521532
  return hi;
521338
521533
  return x;
521339
521534
  }
521340
- function clamp014(x) {
521341
- return clamp3(x, 0, 1);
521535
+ function clamp015(x) {
521536
+ return clamp4(x, 0, 1);
521342
521537
  }
521343
521538
  function clampSigned(x) {
521344
- return clamp3(x, -1, 1);
521539
+ return clamp4(x, -1, 1);
521345
521540
  }
521346
521541
  function sanitizeBig5(p2) {
521347
521542
  return {
521348
- openness: clamp014(p2?.openness ?? NEUTRAL_BIG5.openness),
521349
- conscientiousness: clamp014(p2?.conscientiousness ?? NEUTRAL_BIG5.conscientiousness),
521350
- extraversion: clamp014(p2?.extraversion ?? NEUTRAL_BIG5.extraversion),
521351
- agreeableness: clamp014(p2?.agreeableness ?? NEUTRAL_BIG5.agreeableness),
521352
- neuroticism: clamp014(p2?.neuroticism ?? NEUTRAL_BIG5.neuroticism)
521543
+ openness: clamp015(p2?.openness ?? NEUTRAL_BIG5.openness),
521544
+ conscientiousness: clamp015(p2?.conscientiousness ?? NEUTRAL_BIG5.conscientiousness),
521545
+ extraversion: clamp015(p2?.extraversion ?? NEUTRAL_BIG5.extraversion),
521546
+ agreeableness: clamp015(p2?.agreeableness ?? NEUTRAL_BIG5.agreeableness),
521547
+ neuroticism: clamp015(p2?.neuroticism ?? NEUTRAL_BIG5.neuroticism)
521353
521548
  };
521354
521549
  }
521355
521550
  function pairKey(a2, b) {
@@ -521468,13 +521663,13 @@ var init_socialMemory = __esm({
521468
521663
  const id = input.id ?? randomUUID11();
521469
521664
  const existing = this.getAgent(id);
521470
521665
  const personality = sanitizeBig5({ ...existing?.personality ?? {}, ...input.personality ?? {} });
521471
- const trustOverall = clamp014(input.trust?.overall ?? existing?.trust.overall ?? 0.5);
521666
+ const trustOverall = clamp015(input.trust?.overall ?? existing?.trust.overall ?? 0.5);
521472
521667
  const trustByDomain = {
521473
521668
  ...existing?.trust.byDomain ?? {},
521474
521669
  ...input.trust?.byDomain ?? {}
521475
521670
  };
521476
521671
  for (const k of Object.keys(trustByDomain))
521477
- trustByDomain[k] = clamp014(trustByDomain[k]);
521672
+ trustByDomain[k] = clamp015(trustByDomain[k]);
521478
521673
  const metadata = input.metadata ?? existing?.metadata ?? null;
521479
521674
  if (existing) {
521480
521675
  this.db.prepare(`UPDATE social_agents
@@ -521514,13 +521709,13 @@ var init_socialMemory = __esm({
521514
521709
  const agent = this.getAgent(agentId);
521515
521710
  if (!agent)
521516
521711
  return null;
521517
- const weight = clamp014(interaction.weight ?? 0.1);
521712
+ const weight = clamp015(interaction.weight ?? 0.1);
521518
521713
  const targetOverall = interaction.positive ? 1 : 0;
521519
- const newOverall = clamp014(agent.trust.overall + (targetOverall - agent.trust.overall) * weight);
521714
+ const newOverall = clamp015(agent.trust.overall + (targetOverall - agent.trust.overall) * weight);
521520
521715
  const newByDomain = { ...agent.trust.byDomain };
521521
521716
  if (interaction.domain) {
521522
521717
  const cur = newByDomain[interaction.domain] ?? 0.5;
521523
- newByDomain[interaction.domain] = clamp014(cur + (targetOverall - cur) * weight);
521718
+ newByDomain[interaction.domain] = clamp015(cur + (targetOverall - cur) * weight);
521524
521719
  }
521525
521720
  const now = Date.now();
521526
521721
  this.db.prepare(`UPDATE social_agents
@@ -521550,14 +521745,14 @@ var init_socialMemory = __esm({
521550
521745
  history.push(newEvent);
521551
521746
  if (history.length > 200)
521552
521747
  history.splice(0, history.length - 200);
521553
- const strength = clamp014(existing.strength + Math.abs(dStrength));
521748
+ const strength = clamp015(existing.strength + Math.abs(dStrength));
521554
521749
  const valence = clampSigned(existing.valence + dValence);
521555
- const reciprocity = clamp014(existing.reciprocity * 0.95 + 0.05 * 0.5);
521750
+ const reciprocity = clamp015(existing.reciprocity * 0.95 + 0.05 * 0.5);
521556
521751
  this.db.prepare(`UPDATE social_relationships
521557
521752
  SET strength = ?, valence = ?, reciprocity = ?, last_updated = ?, history = ?
521558
521753
  WHERE agent_a = ? AND agent_b = ?`).run(strength, valence, reciprocity, now, JSON.stringify(history), lo, hi);
521559
521754
  } else {
521560
- const strength = clamp014(Math.abs(dStrength));
521755
+ const strength = clamp015(Math.abs(dStrength));
521561
521756
  const valence = clampSigned(dValence);
521562
521757
  this.db.prepare(`INSERT INTO social_relationships
521563
521758
  (agent_a, agent_b, strength, valence, reciprocity, last_updated, history)
@@ -521580,7 +521775,7 @@ var init_socialMemory = __esm({
521580
521775
  recordLesson(input) {
521581
521776
  const id = randomUUID11();
521582
521777
  const now = Date.now();
521583
- const conf = clamp014(input.confidence ?? 0.5);
521778
+ const conf = clamp015(input.confidence ?? 0.5);
521584
521779
  const adopted = input.adopted ? 1 : 0;
521585
521780
  this.db.prepare(`INSERT INTO social_lessons (id, source_agent, lesson, confidence, adopted, timestamp)
521586
521781
  VALUES (?, ?, ?, ?, ?, ?)`).run(id, input.sourceAgent, input.lesson, conf, adopted, now);
@@ -521598,7 +521793,7 @@ var init_socialMemory = __esm({
521598
521793
  recordOpinion(input) {
521599
521794
  const id = randomUUID11();
521600
521795
  const now = Date.now();
521601
- const conf = clamp014(input.confidence ?? 0.5);
521796
+ const conf = clamp015(input.confidence ?? 0.5);
521602
521797
  this.db.prepare(`INSERT INTO social_shared_knowledge (id, topic, agent_id, opinion, confidence, timestamp)
521603
521798
  VALUES (?, ?, ?, ?, ?, ?)`).run(id, input.topic, input.agentId, input.opinion, conf, now);
521604
521799
  return { id, topic: input.topic, agentId: input.agentId, opinion: input.opinion, confidence: conf, timestamp: now };
@@ -521733,64 +521928,6 @@ var init_memoryStageContext = __esm({
521733
521928
  }
521734
521929
  });
521735
521930
 
521736
- // packages/memory/dist/socialInfluence.js
521737
- function clamp4(x, lo, hi) {
521738
- if (!Number.isFinite(x))
521739
- return (lo + hi) / 2;
521740
- if (x < lo)
521741
- return lo;
521742
- if (x > hi)
521743
- return hi;
521744
- return x;
521745
- }
521746
- function clamp015(x) {
521747
- return clamp4(x, 0, 1);
521748
- }
521749
- function conformityBias(myConfidence, groupAgreement, memoryAlignsWithGroup, weight = 0.5) {
521750
- const conf = clamp015(myConfidence);
521751
- const agree = clamp015(groupAgreement);
521752
- const w = clamp015(weight);
521753
- const pull = (agree - 0.5) * 2 * conf * w;
521754
- return memoryAlignsWithGroup ? 1 + pull : 1 - pull;
521755
- }
521756
- function authorityBias(sourceTrust, weight = 0.4) {
521757
- const t2 = clamp015(sourceTrust);
521758
- const w = clamp015(weight);
521759
- return 1 + (t2 - 0.5) * 2 * w;
521760
- }
521761
- function noveltyBias(memoryDivergence, weight = 0.3) {
521762
- const d2 = clamp015(memoryDivergence);
521763
- const w = clamp015(weight);
521764
- return 1 + d2 * w;
521765
- }
521766
- function reciprocityBias(relationshipStrength, relationshipValence, weight = 0.3) {
521767
- const s2 = clamp015(relationshipStrength);
521768
- const v = clamp4(relationshipValence, -1, 1);
521769
- const w = clamp015(weight);
521770
- return 1 + s2 * v * w;
521771
- }
521772
- function applyInfluence(baseScore, ctx3) {
521773
- let m2 = 1;
521774
- if (ctx3.myConfidence != null && ctx3.groupAgreement != null && ctx3.memoryAlignsWithGroup != null) {
521775
- m2 *= conformityBias(ctx3.myConfidence, ctx3.groupAgreement, ctx3.memoryAlignsWithGroup, ctx3.weights?.conformity);
521776
- }
521777
- if (ctx3.sourceTrust != null) {
521778
- m2 *= authorityBias(ctx3.sourceTrust, ctx3.weights?.authority);
521779
- }
521780
- if (ctx3.memoryDivergence != null) {
521781
- m2 *= noveltyBias(ctx3.memoryDivergence, ctx3.weights?.novelty);
521782
- }
521783
- if (ctx3.relationshipStrength != null && ctx3.relationshipValence != null) {
521784
- m2 *= reciprocityBias(ctx3.relationshipStrength, ctx3.relationshipValence, ctx3.weights?.reciprocity);
521785
- }
521786
- return baseScore * m2;
521787
- }
521788
- var init_socialInfluence = __esm({
521789
- "packages/memory/dist/socialInfluence.js"() {
521790
- "use strict";
521791
- }
521792
- });
521793
-
521794
521931
  // packages/memory/dist/index.js
521795
521932
  var dist_exports2 = {};
521796
521933
  __export(dist_exports2, {
@@ -527169,6 +527306,13 @@ Respond with your assessment, then take action.`;
527169
527306
  totalEpisodes,
527170
527307
  creativeAssociationCount: 0
527171
527308
  });
527309
+ if (this._episodeStore) {
527310
+ try {
527311
+ this._episodeStore.setZettelConfig?.(stageCtx.toZettelkastenConfig());
527312
+ this._episodeStore.setImportanceFloor?.(stageCtx.importanceFloor());
527313
+ } catch {
527314
+ }
527315
+ }
527172
527316
  this.emit({
527173
527317
  type: "status",
527174
527318
  content: `Memory stage: ${snap.stage} (importanceFloor=${snap.thresholds.importanceFloor}, linkThreshold=${snap.thresholds.linkThreshold})`,
@@ -527539,6 +527683,43 @@ TASK: ${task}` : task;
527539
527683
  content: `STAGNATION DETECTED — injected diagnostic mode at turn ${turn} (${signals.variantCount} variants, ${signals.failureSum} failures, ${signals.filesDelta} files in window)`,
527540
527684
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
527541
527685
  });
527686
+ try {
527687
+ const memMod = await Promise.resolve().then(() => (init_dist7(), dist_exports2));
527688
+ const hs = this._homeostat;
527689
+ if (hs) {
527690
+ const actions = memMod.suggestRegulationActions(hs);
527691
+ for (const a2 of actions) {
527692
+ this.emit({
527693
+ type: "status",
527694
+ content: `[REGULATION SUGGESTION] ${a2} — homeostat is off-target (current valence=${hs.current.valence.toFixed(2)}, arousal=${hs.current.arousal.toFixed(2)}, streak=${hs.streak})`,
527695
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
527696
+ });
527697
+ }
527698
+ }
527699
+ if (this._selfModel && this._episodeStore) {
527700
+ const sm = this._selfModel;
527701
+ const report2 = sm.snapshot();
527702
+ for (const [domain, c9] of Object.entries(report2.calibration.byDomain)) {
527703
+ if (c9.n >= 5 && c9.confidence - c9.accuracy > 0.2) {
527704
+ this.emit({
527705
+ type: "status",
527706
+ content: `[SELF-MODEL CALIBRATION mid-session] overconfident in '${domain}': stated ${c9.confidence.toFixed(2)} vs actual ${c9.accuracy.toFixed(2)} across ${c9.n} samples — temper next-action confidence in this domain.`,
527707
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
527708
+ });
527709
+ }
527710
+ }
527711
+ this._episodeStore.insert({
527712
+ sessionId: this._sessionId,
527713
+ modality: "reflection",
527714
+ toolName: "self_model_snapshot",
527715
+ content: `mid-session self-report (stagnation @ turn ${turn}): stage=${report2.developmental?.stage ?? "?"} calGap=${report2.calibration.calibrationGap.toFixed(2)} (n=${report2.calibration.sampleCount}) blindSpots=${report2.blindSpots.length}`,
527716
+ importance: 7,
527717
+ decayClass: "session",
527718
+ metadata: { selfReport: report2, stagnationTurn: turn }
527719
+ });
527720
+ }
527721
+ } catch {
527722
+ }
527542
527723
  }
527543
527724
  }
527544
527725
  }
@@ -528392,7 +528573,12 @@ If you're stuck, try a completely different approach. Do NOT repeat what failed
528392
528573
  if (turn > 0 && turn % 3 === 0 && this._temporalGraph && this._episodeStore) {
528393
528574
  try {
528394
528575
  const taskGoal = this._taskState.goal || cleanedTask.slice(0, 200);
528395
- const pprResult = retrieveByPPR(taskGoal, this._temporalGraph, this._episodeStore, { topK: 3 });
528576
+ const _hs = this._homeostat;
528577
+ const pprResult = retrieveByPPR(taskGoal, this._temporalGraph, this._episodeStore, {
528578
+ topK: 3,
528579
+ currentEmotionalState: _hs?.current,
528580
+ engagementWeight: 0.2
528581
+ });
528396
528582
  if (pprResult.episodes.length > 0) {
528397
528583
  const memoryLines = pprResult.episodes.map(({ episode, pprScore, matchedNodes }) => `- [${episode.toolName ?? episode.modality}] ${episode.content.slice(0, 120)} (via: ${matchedNodes.slice(0, 2).join(", ")})`);
528398
528584
  compacted.push({
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "open-agents-ai",
3
- "version": "0.187.510",
3
+ "version": "0.187.511",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "open-agents-ai",
9
- "version": "0.187.510",
9
+ "version": "0.187.511",
10
10
  "hasInstallScript": true,
11
11
  "license": "CC-BY-NC-4.0",
12
12
  "dependencies": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "open-agents-ai",
3
- "version": "0.187.510",
3
+ "version": "0.187.511",
4
4
  "description": "AI coding agent powered by open-source models (Ollama/vLLM) — interactive TUI with agentic tool-calling loop",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",