open-agents-ai 0.186.50 → 0.186.52

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.
Files changed (2) hide show
  1. package/dist/index.js +396 -0
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -8446,10 +8446,19 @@ process.on('unhandledRejection', (reason) => {
8446
8446
  _saveStats();
8447
8447
 
8448
8448
  dlog('COHERE response: ' + _cData.queryId + ' model=' + _cModel + ' tier=' + ['trivial','moderate','complex','expert'][_cTier] + ' ' + _cLatency + 'ms' + (_cReviewed ? ' (reviewed)' : ''));
8449
+ // IK-01: Update identity on query success
8450
+ _updateIdentity({ type: 'query_served', outcome: 1.0, details: {
8451
+ latencyMs: _cLatency, toolsUsed: _cToolsUsed, model: _cModel,
8452
+ summary: (_cData.query || '').slice(0, 60)
8453
+ }});
8449
8454
  } catch (_cErr) {
8450
8455
  dlog('COHERE inference error: ' + (_cErr.message || _cErr));
8451
8456
  _cohereStats.queriesErrors++;
8452
8457
  _saveStats();
8458
+ // IK-01: Update identity on query failure
8459
+ _updateIdentity({ type: 'query_failed', outcome: 0, details: {
8460
+ error: (_cErr.message || String(_cErr)).slice(0, 100), summary: 'inference error'
8461
+ }});
8453
8462
  }
8454
8463
  } catch (_cParseErr) {
8455
8464
  // Malformed message \u2014 skip
@@ -8552,6 +8561,11 @@ process.on('unhandledRejection', (reason) => {
8552
8561
  timestamp: Date.now(),
8553
8562
  })));
8554
8563
  dlog('CO-06 review: ' + _dData.queryId + ' verdict=' + _dVerdict + ' model=' + _dReviewModel);
8564
+ // IK-01: Update identity on review given (Emergent Social Conventions)
8565
+ _updateIdentity({ type: 'review_given', outcome: 1.0, details: {
8566
+ peerId: _dData.provider, peerName: _dData.agentName || _dData.provider.slice(0, 12),
8567
+ verdict: _dVerdict, summary: 'reviewed draft for ' + _dData.queryId
8568
+ }});
8555
8569
  } catch (_dRevErr) {
8556
8570
  dlog('CO-06 review error: ' + (_dRevErr.message || _dRevErr));
8557
8571
  }
@@ -8569,6 +8583,11 @@ process.on('unhandledRejection', (reason) => {
8569
8583
  // Store review for the drafter to pick up
8570
8584
  _draftReviews.set(_rData.queryId, _rData);
8571
8585
  dlog('CO-06: review received for ' + _rData.queryId + ' verdict=' + _rData.verdict + ' from ' + (_rData.reviewerAgent || _rData.reviewer.slice(0, 12)));
8586
+ // IK-01: Update identity on review received
8587
+ _updateIdentity({ type: 'review_received', outcome: 1.0, details: {
8588
+ peerId: _rData.reviewer, peerName: _rData.reviewerAgent || _rData.reviewer.slice(0, 12),
8589
+ verdict: _rData.verdict, summary: 'review for ' + _rData.queryId
8590
+ }});
8572
8591
  } catch {}
8573
8592
  }
8574
8593
  })().catch(function() {});
@@ -8654,6 +8673,11 @@ process.on('unhandledRejection', (reason) => {
8654
8673
  mkdirSync(_lStoreDir, { recursive: true });
8655
8674
  writeFileSync(_lStoreFile, JSON.stringify(_lStore, null, 2));
8656
8675
  dlog('COHERE learning ingested from ' + (_lData.source_agent || 'unknown') + ': ' + String(_lData.insight).slice(0, 60));
8676
+ // IK-01: Update identity on learning ingested
8677
+ _updateIdentity({ type: 'learning_ingested', outcome: _lConfidence, details: {
8678
+ category: _lCategory, source: _lData.source_agent,
8679
+ summary: 'ingested ' + _lCategory + ' from ' + (_lData.source_agent || 'peer')
8680
+ }});
8657
8681
 
8658
8682
  // WO-DL4: Cross-pin the CID locally if provided (content persistence)
8659
8683
  if (_lData.cid && _lData.cid.startsWith('bafy')) {
@@ -8843,6 +8867,378 @@ process.on('unhandledRejection', (reason) => {
8843
8867
  if (cohereActive) _publishCapacityAnnouncement();
8844
8868
  }, 60000);
8845
8869
 
8870
+ // \u2550\u2550\u2550 IK-01: Identity Kernel Evolution \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550
8871
+ // Paper: MemoryOS (arXiv:2506.06326) \u2014 three-tier consolidation
8872
+ // Paper: A-MEM (arXiv:2502.12110) \u2014 retroactive memory refinement
8873
+ // Paper: MemRL (arXiv:2601.03192) \u2014 value-based retrieval
8874
+ // Paper: Memory-R1 (arXiv:2508.19828) \u2014 ADD/UPDATE/DELETE/NOOP ops
8875
+ // Paper: Emergent Social Conventions (arXiv:2410.08948) \u2014 peer tracking
8876
+ // Paper: Spontaneous Individuality (arXiv:2411.03252) \u2014 emergent identity
8877
+ // Paper: EvoSkill (arXiv:2603.02766) \u2014 tool-based specialization discovery
8878
+ //
8879
+ // Called from: query completion, query failure, self-play, learning
8880
+ // ingestion, review given, review received.
8881
+ function _updateIdentity(event) {
8882
+ try {
8883
+ var ikFile = join(nexusDir, '..', 'identity', 'self-state.json');
8884
+ if (!existsSync(ikFile)) return;
8885
+ var state = JSON.parse(readFileSync(ikFile, 'utf8'));
8886
+
8887
+ // Memory-R1 ADD: Initialize new fields if missing
8888
+ if (!state.stats) state.stats = {
8889
+ queries_served: 0, self_play_cycles: 0, learnings_published: 0,
8890
+ learnings_ingested: 0, reviews_given: 0, reviews_received: 0,
8891
+ avg_latency_ms: 0, tool_use_count: 0,
8892
+ };
8893
+ if (!state.peer_relationships) state.peer_relationships = {};
8894
+ if (!state.specializations) state.specializations = [];
8895
+ if (!state.completed_goals) state.completed_goals = [];
8896
+ if (!state.homeostasis) state.homeostasis = { uncertainty: 0.1, coherence: 1.0, goal_tension: 0.0, memory_trust: 1.0, boundary_breach: 0.0, latency_stress: 0.0 };
8897
+
8898
+ switch (event.type) {
8899
+ case 'query_served':
8900
+ state.stats.queries_served++;
8901
+ // MemoryOS: reduce uncertainty on success (mid\u2192long consolidation)
8902
+ state.homeostasis.uncertainty = Math.max(0, state.homeostasis.uncertainty - 0.01);
8903
+ state.homeostasis.coherence = Math.min(1, state.homeostasis.coherence + 0.005);
8904
+ // Latency stress tracking
8905
+ if (event.details && event.details.latencyMs) {
8906
+ state.homeostasis.latency_stress = event.details.latencyMs > 30000
8907
+ ? Math.min(1, state.homeostasis.latency_stress + 0.02)
8908
+ : Math.max(0, state.homeostasis.latency_stress - 0.01);
8909
+ // Running average latency
8910
+ var prevAvg = state.stats.avg_latency_ms || 0;
8911
+ var n = state.stats.queries_served;
8912
+ state.stats.avg_latency_ms = n > 1 ? Math.round((prevAvg * (n - 1) + event.details.latencyMs) / n) : event.details.latencyMs;
8913
+ }
8914
+ // EvoSkill: discover specializations from tool patterns
8915
+ if (event.details && event.details.toolsUsed && event.details.toolsUsed.length > 0) {
8916
+ state.stats.tool_use_count = (state.stats.tool_use_count || 0) + event.details.toolsUsed.length;
8917
+ for (var _ikti = 0; _ikti < event.details.toolsUsed.length; _ikti++) {
8918
+ var t = event.details.toolsUsed[_ikti];
8919
+ var spec = (t === 'web_search' || t === 'web_fetch') ? 'web-research'
8920
+ : (t === 'shell') ? 'code-execution'
8921
+ : (t === 'file_read' || t === 'file_write' || t === 'file_edit') ? 'file-operations'
8922
+ : null;
8923
+ if (spec && state.specializations.indexOf(spec) < 0) {
8924
+ state.specializations.push(spec);
8925
+ dlog('IK-01: specialization discovered: ' + spec);
8926
+ }
8927
+ }
8928
+ }
8929
+ break;
8930
+
8931
+ case 'query_failed':
8932
+ state.stats.queries_served++;
8933
+ state.homeostasis.uncertainty = Math.min(1, state.homeostasis.uncertainty + 0.03);
8934
+ state.homeostasis.coherence = Math.max(0, state.homeostasis.coherence - 0.02);
8935
+ break;
8936
+
8937
+ case 'self_play':
8938
+ state.stats.self_play_cycles++;
8939
+ if (event.outcome >= 0.5) {
8940
+ state.homeostasis.uncertainty = Math.max(0, state.homeostasis.uncertainty - 0.02);
8941
+ } else {
8942
+ state.homeostasis.uncertainty = Math.min(1, state.homeostasis.uncertainty + 0.01);
8943
+ }
8944
+ break;
8945
+
8946
+ case 'learning_ingested':
8947
+ state.stats.learnings_ingested++;
8948
+ state.homeostasis.memory_trust = Math.min(1, state.homeostasis.memory_trust + 0.005);
8949
+ break;
8950
+
8951
+ case 'learning_published':
8952
+ state.stats.learnings_published++;
8953
+ break;
8954
+
8955
+ case 'review_given':
8956
+ state.stats.reviews_given++;
8957
+ // Emergent Social Conventions: track peer relationships
8958
+ if (event.details && event.details.peerName) {
8959
+ var pgn = event.details.peerName;
8960
+ if (!state.peer_relationships[pgn]) state.peer_relationships[pgn] = { interactions: 0, reviews_given: 0, reviews_received: 0, trust: 0.5 };
8961
+ state.peer_relationships[pgn].interactions++;
8962
+ state.peer_relationships[pgn].reviews_given++;
8963
+ state.peer_relationships[pgn].trust = Math.min(1.0, state.peer_relationships[pgn].trust + 0.02);
8964
+ }
8965
+ break;
8966
+
8967
+ case 'review_received':
8968
+ state.stats.reviews_received++;
8969
+ if (event.details && event.details.verdict === 'approved') {
8970
+ state.homeostasis.coherence = Math.min(1, state.homeostasis.coherence + 0.01);
8971
+ } else if (event.details && event.details.verdict === 'corrected') {
8972
+ state.homeostasis.uncertainty = Math.min(1, state.homeostasis.uncertainty + 0.01);
8973
+ }
8974
+ if (event.details && event.details.peerName) {
8975
+ var rpn = event.details.peerName;
8976
+ if (!state.peer_relationships[rpn]) state.peer_relationships[rpn] = { interactions: 0, reviews_given: 0, reviews_received: 0, trust: 0.5 };
8977
+ state.peer_relationships[rpn].interactions++;
8978
+ state.peer_relationships[rpn].reviews_received++;
8979
+ state.peer_relationships[rpn].trust = Math.min(1.0, state.peer_relationships[rpn].trust + 0.02);
8980
+ }
8981
+ break;
8982
+ }
8983
+
8984
+ // \u2500\u2500 Spontaneous Individuality: goal progression from stats, not pre-programmed \u2500\u2500
8985
+ if (state.stats.queries_served >= 10 && state.active_goals && state.active_goals.indexOf('establish-network-identity') >= 0) {
8986
+ state.active_goals = state.active_goals.filter(function(g) { return g !== 'establish-network-identity'; });
8987
+ state.completed_goals.push('establish-network-identity');
8988
+ state.homeostasis.goal_tension = Math.max(0, state.homeostasis.goal_tension - 0.1);
8989
+ dlog('IK-01: goal completed: establish-network-identity');
8990
+ }
8991
+ if (state.stats.reviews_given >= 3 && (!state.completed_goals || state.completed_goals.indexOf('first-peer-review') < 0)) {
8992
+ state.completed_goals.push('first-peer-review');
8993
+ dlog('IK-01: goal completed: first-peer-review');
8994
+ }
8995
+ if (state.stats.self_play_cycles >= 5 && state.active_goals && state.active_goals.indexOf('self-improvement-active') < 0 &&
8996
+ (!state.completed_goals || state.completed_goals.indexOf('self-improvement-active') < 0)) {
8997
+ state.active_goals.push('self-improvement-active');
8998
+ state.homeostasis.goal_tension = Math.min(1, state.homeostasis.goal_tension + 0.03);
8999
+ }
9000
+
9001
+ // \u2500\u2500 A-MEM: Retroactive narrative update every 10 versions \u2500\u2500
9002
+ state.version = (state.version || 0) + 1;
9003
+ if (state.version % 10 === 0) {
9004
+ var specList = (state.specializations || []).join(', ') || 'general-purpose';
9005
+ var peerCount = Object.keys(state.peer_relationships || {}).length;
9006
+ var peerNames = Object.keys(state.peer_relationships || {}).slice(0, 3).join(', ');
9007
+ state.narrative_summary = 'Agent ' + (state.self_id || agentName) +
9008
+ ' \u2014 ' + state.stats.queries_served + ' queries served' +
9009
+ (state.specializations.length > 0 ? ', specializes in ' + specList : '') +
9010
+ (peerCount > 0 ? '. Collaborates with ' + peerNames + ' (' + peerCount + ' peers)' : '') +
9011
+ '. Self-play: ' + state.stats.self_play_cycles + ' cycles' +
9012
+ '. Coherence: ' + state.homeostasis.coherence.toFixed(2) +
9013
+ ', uncertainty: ' + state.homeostasis.uncertainty.toFixed(2) + '.';
9014
+ dlog('IK-01: narrative updated (v' + state.version + '): ' + state.narrative_summary.slice(0, 100));
9015
+ }
9016
+
9017
+ // Memory-R1: Version history with pruning
9018
+ if (!state.version_history) state.version_history = [];
9019
+ state.version_history.push({
9020
+ version: state.version,
9021
+ change: event.type + (event.details && event.details.summary ? ': ' + event.details.summary : ''),
9022
+ timestamp: new Date().toISOString(),
9023
+ });
9024
+ if (state.version_history.length > 200) state.version_history = state.version_history.slice(-200);
9025
+
9026
+ state.updated_at = new Date().toISOString();
9027
+ writeFileSync(ikFile, JSON.stringify(state, null, 2), 'utf8');
9028
+ } catch (e) {
9029
+ dlog('IK-01: update error: ' + (e.message || e));
9030
+ }
9031
+ }
9032
+
9033
+ // \u2550\u2550\u2550 SP-01: Self-Play Idle Loop \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550
9034
+ // Paper: SPELL (arXiv:2509.23863) three-role self-play (Q/R/V)
9035
+ // Paper: SeRL (arXiv:2505.20347) self-instruction + online filtering
9036
+ // Paper: Sol-Ver (arXiv:2502.14948) solver-verifier dual improvement
9037
+ // Paper: Meta-Rewarding (arXiv:2407.19594) judge saturation prevention
9038
+ // Paper: Exp. Reflective Learning (arXiv:2603.24639) heuristic extraction
9039
+ //
9040
+ // Fires every 90s when idle (no inbound query for >30s).
9041
+ // Routes through AgenticRunner /v1/run with cohere-mesh profile.
9042
+ var _spCycleCount = 0;
9043
+ var _spSuccessCount = 0;
9044
+ var _spScoreHistory = []; // Meta-Rewarding: track last 20 scores for variance check
9045
+ var _spConsecutiveSuccesses = 0;
9046
+ var _spTaskBank = [
9047
+ { q: 'Search the web for the top AI news story today. Summarize in 2 sentences.', verify: 'tool_use', minTools: 1 },
9048
+ { q: 'What is the current price of Bitcoin? Search the web.', verify: 'tool_use', minTools: 1 },
9049
+ { q: 'Find the latest weather forecast for New York City using web search.', verify: 'tool_use', minTools: 1 },
9050
+ { q: 'Explain the difference between TCP and UDP in exactly 3 sentences.', verify: 'length', maxChars: 600 },
9051
+ { q: 'What is the time complexity of merge sort and why?', verify: 'length', maxChars: 800 },
9052
+ { q: 'Compare solar and wind energy: give 2 advantages of each.', verify: 'structure', mustContain: ['solar', 'wind'] },
9053
+ { q: 'List 3 programming languages with pattern matching and explain one example.', verify: 'structure', mustContain: ['match'] },
9054
+ ];
9055
+
9056
+ // SeRL self-instruction: add dynamic tasks from failure patterns
9057
+ function _spGetTask() {
9058
+ var bank = _spTaskBank.slice();
9059
+ try {
9060
+ var storeFile = join(nexusDir, '..', 'memory', 'metabolism', 'store.json');
9061
+ if (existsSync(storeFile)) {
9062
+ var store = JSON.parse(readFileSync(storeFile, 'utf8'));
9063
+ var failures = store.filter(function(m) { return m.type === 'recovery' && m.scores && m.scores.confidence > 0.3; });
9064
+ for (var fi = 0; fi < Math.min(failures.length, 3); fi++) {
9065
+ bank.push({ q: 'Validate: ' + failures[fi].content.slice(0, 150), verify: 'length', maxChars: 1000 });
9066
+ }
9067
+ }
9068
+ } catch {}
9069
+ return bank[Math.floor(Math.random() * bank.length)];
9070
+ }
9071
+
9072
+ // Sol-Ver: Solver-Verifier dual evaluation
9073
+ function _spEvaluate(result, task) {
9074
+ var score = 0;
9075
+ var details = [];
9076
+ var content = (result.output || result.summary || '').trim();
9077
+ if (result.status === 'completed') { score += 0.2; details.push('completed'); }
9078
+ else { details.push('FAIL:' + (result.status || 'unknown')); return { score: 0, details: details }; }
9079
+ // Tool use check
9080
+ var summary = result.summary || '';
9081
+ var hasTools = /tool call/i.test(summary);
9082
+ if (task.verify === 'tool_use') {
9083
+ if (hasTools) { score += 0.4; details.push('tools:yes'); }
9084
+ else { details.push('FAIL:no_tools'); }
9085
+ }
9086
+ // Length check
9087
+ if (task.verify === 'length') {
9088
+ if (content.length > 30 && content.length < (task.maxChars || 2000)) { score += 0.3; details.push('len:' + content.length); }
9089
+ else { details.push('FAIL:length=' + content.length); }
9090
+ }
9091
+ // Structure check
9092
+ if (task.verify === 'structure' && task.mustContain) {
9093
+ var found = 0;
9094
+ for (var ki = 0; ki < task.mustContain.length; ki++) {
9095
+ if (content.toLowerCase().indexOf(task.mustContain[ki]) >= 0) found++;
9096
+ }
9097
+ if (found === task.mustContain.length) { score += 0.3; details.push('keywords:' + found); }
9098
+ else { details.push('FAIL:keywords=' + found + '/' + task.mustContain.length); }
9099
+ }
9100
+ // Quality: non-empty, no error messages
9101
+ if (content.length > 50 && !/[COHERE error]|Backend error/i.test(content.slice(0, 200))) { score += 0.2; details.push('quality:ok'); }
9102
+ else { details.push('FAIL:quality'); }
9103
+ // Latency bonus
9104
+ if (result.durationMs && result.durationMs < 30000) { score += 0.1; details.push('fast:' + result.durationMs + 'ms'); }
9105
+ return { score: Math.min(1.0, score), details: details };
9106
+ }
9107
+
9108
+ // Meta-Rewarding (arXiv:2407.19594): Detect judge saturation
9109
+ function _spCheckMetaJudge() {
9110
+ if (_spScoreHistory.length < 8) return true;
9111
+ var recent = _spScoreHistory.slice(-8);
9112
+ var mean = recent.reduce(function(a, b) { return a + b; }, 0) / recent.length;
9113
+ var variance = recent.reduce(function(a, b) { return a + (b - mean) * (b - mean); }, 0) / recent.length;
9114
+ if (variance < 0.005) {
9115
+ dlog('SP-01: META-JUDGE \u2014 score variance collapsed (' + variance.toFixed(4) + '). Injecting diversity.');
9116
+ _spTaskBank.push(
9117
+ { q: 'Search the web for something unexpected that happened this week.', verify: 'tool_use', minTools: 1 },
9118
+ { q: 'Argue for and against the use of nuclear energy in 4 sentences.', verify: 'length', maxChars: 800 }
9119
+ );
9120
+ _spConsecutiveSuccesses = 0;
9121
+ return false;
9122
+ }
9123
+ return true;
9124
+ }
9125
+
9126
+ // SPELL adaptive curriculum: increase difficulty after consecutive wins
9127
+ function _spAdaptDifficulty(score) {
9128
+ if (score >= 0.7) {
9129
+ _spConsecutiveSuccesses++;
9130
+ if (_spConsecutiveSuccesses >= 3) {
9131
+ _spTaskBank.push(
9132
+ { q: 'Search the web for 2 different sources about a current event and compare their coverage.', verify: 'tool_use', minTools: 2 },
9133
+ { q: 'Find a recent scientific discovery and explain why it matters in simple terms.', verify: 'tool_use', minTools: 1 }
9134
+ );
9135
+ _spConsecutiveSuccesses = 0;
9136
+ dlog('SP-01: SPELL curriculum \u2014 added harder tasks');
9137
+ }
9138
+ } else { _spConsecutiveSuccesses = 0; }
9139
+ }
9140
+
9141
+ // Exp. Reflective Learning (arXiv:2603.24639): Extract heuristic, NOT trajectory
9142
+ function _spPublishLearning(task, result, evaluation) {
9143
+ var summary = result.summary || '';
9144
+ var hasTools = /tool call/i.test(summary);
9145
+ var duration = result.durationMs || 0;
9146
+ var heuristic = '';
9147
+ if (hasTools) {
9148
+ heuristic = 'Tool strategy: web_search effective for "' + task.q.slice(0, 50) + '" (' + Math.round(duration / 1000) + 's, score ' + evaluation.score.toFixed(1) + ')';
9149
+ } else if (evaluation.score >= 0.7) {
9150
+ heuristic = 'Direct answer effective for "' + task.q.slice(0, 50) + '" (no tools needed, score ' + evaluation.score.toFixed(1) + ')';
9151
+ } else { return; }
9152
+ var category = hasTools ? 'web_strategy' : 'reasoning';
9153
+ // Write to metabolism store (ExpeL experience gathering)
9154
+ try {
9155
+ var storeFile = join(nexusDir, '..', 'memory', 'metabolism', 'store.json');
9156
+ var store = [];
9157
+ try { if (existsSync(storeFile)) store = JSON.parse(readFileSync(storeFile, 'utf8')); } catch {}
9158
+ var entryId = 'sp-' + Date.now() + '-' + Math.random().toString(36).slice(2, 6);
9159
+ store.push({
9160
+ id: entryId, type: 'procedural',
9161
+ content: heuristic, sourceTrace: 'self-play:' + agentName,
9162
+ scores: { novelty: 0.6, utility: evaluation.score, confidence: evaluation.score * 0.9, identityRelevance: 0.3 },
9163
+ decision: { action: 'admit', reason: 'Self-play heuristic (score ' + evaluation.score.toFixed(2) + ')' },
9164
+ createdAt: new Date().toISOString(), lastAccessedAt: new Date().toISOString(), accessCount: 0,
9165
+ });
9166
+ // EvoSkill Pareto: keep top 80 by utility*confidence
9167
+ if (store.length > 100) {
9168
+ store.sort(function(a, b) { return (b.scores.utility * b.scores.confidence) - (a.scores.utility * a.scores.confidence); });
9169
+ store = store.slice(0, 80);
9170
+ }
9171
+ mkdirSync(join(nexusDir, '..', 'memory', 'metabolism'), { recursive: true });
9172
+ writeFileSync(storeFile, JSON.stringify(store, null, 2), 'utf8');
9173
+ dlog('SP-01: heuristic stored: ' + heuristic.slice(0, 80));
9174
+ } catch (e) { dlog('SP-01: store error: ' + (e.message || e)); }
9175
+ // Publish to mesh if high confidence
9176
+ if (_natsConn && _natsCodec && evaluation.score >= 0.7) {
9177
+ _natsConn.publish('nexus.cohere.learning', _natsCodec.encode(JSON.stringify({
9178
+ type: 'cohere.learning',
9179
+ delta_id: 'sp-' + Date.now() + '-' + (nexus.peerId || '').slice(0, 8),
9180
+ insight: heuristic, category: category,
9181
+ confidence: evaluation.score, model_tier: 'small',
9182
+ source_peer: nexus.peerId, source_agent: agentName,
9183
+ timestamp: Date.now(),
9184
+ })));
9185
+ dlog('SP-01: learning published to mesh (' + category + ')');
9186
+ }
9187
+ }
9188
+
9189
+ // Main self-play cycle
9190
+ function _selfPlayCycle() {
9191
+ if (!cohereActive) return;
9192
+ if (Date.now() - (_cohereStats.lastQueryAt || 0) < 30000) return;
9193
+ if (!_spCheckMetaJudge()) { dlog('SP-01: skipping (meta-judge diversity injection)'); return; }
9194
+ // AgentCgroup (arXiv:2602.09345): Don't hog resources
9195
+ _collectSysMetrics().then(function(metrics) {
9196
+ if (metrics && metrics.cpu && metrics.cpu.utilization > 80) { dlog('SP-01: skipping (CPU ' + metrics.cpu.utilization + '%)'); return; }
9197
+ _spCycleCount++;
9198
+ var task = _spGetTask();
9199
+ dlog('SP-01: cycle ' + _spCycleCount + ' \u2014 ' + task.q.slice(0, 60));
9200
+ var _spApi = 'http://localhost:11435';
9201
+ fetch(_spApi + '/v1/run', {
9202
+ method: 'POST', headers: { 'Content-Type': 'application/json' },
9203
+ body: JSON.stringify({ task: task.q, max_turns: 4, timeout_s: 45, sandbox: 'none', profile: 'cohere-mesh' }),
9204
+ signal: AbortSignal.timeout(60000),
9205
+ }).then(function(r) { return r.json(); }).then(function(job) {
9206
+ var jobId = job.run_id || job.id;
9207
+ if (!jobId) { dlog('SP-01: no job ID'); return; }
9208
+ var pollN = 0;
9209
+ var poller = setInterval(function() {
9210
+ pollN++;
9211
+ if (pollN > 30) { clearInterval(poller); dlog('SP-01: poll timeout for ' + jobId); return; }
9212
+ fetch(_spApi + '/v1/runs/' + jobId, { signal: AbortSignal.timeout(5000) })
9213
+ .then(function(r) { return r.json(); }).then(function(res) {
9214
+ if (res.status === 'completed' || res.status === 'failed' || res.status === 'error') {
9215
+ clearInterval(poller);
9216
+ var ev = _spEvaluate(res, task);
9217
+ _spScoreHistory.push(ev.score);
9218
+ if (_spScoreHistory.length > 20) _spScoreHistory.shift();
9219
+ _spAdaptDifficulty(ev.score);
9220
+ if (ev.score >= 0.5) _spSuccessCount++;
9221
+ dlog('SP-01: result \u2014 score=' + ev.score.toFixed(2) + ' [' + ev.details.join(', ') + '] total=' + _spCycleCount + ' success=' + _spSuccessCount);
9222
+ // IK-01: Update identity from self-play outcome
9223
+ _updateIdentity({ type: 'self_play', outcome: ev.score, details: {
9224
+ task: task.q.slice(0, 60), score: ev.score, summary: 'self-play score ' + ev.score.toFixed(2)
9225
+ }});
9226
+ if (ev.score >= 0.6) _spPublishLearning(task, res, ev);
9227
+ }
9228
+ }).catch(function() {});
9229
+ }, 2000);
9230
+ }).catch(function(err) { dlog('SP-01: error: ' + (err.message || err)); });
9231
+ }).catch(function() {});
9232
+ }
9233
+
9234
+ // Self-play interval: 90s when idle
9235
+ setInterval(function() {
9236
+ if (cohereActive && Date.now() - (_cohereStats.lastQueryAt || 0) > 30000) _selfPlayCycle();
9237
+ }, 90000);
9238
+ // First cycle after 60s startup delay
9239
+ setTimeout(function() { if (cohereActive) _selfPlayCycle(); }, 60000);
9240
+ dlog('SP-01: self-play idle loop initialized (90s interval, SPELL/SeRL/Sol-Ver)');
9241
+
8846
9242
  // \u2500\u2500 WO-DL3: Epoch sync \u2014 hash-based state comparison every 5 min \u2500\u2500
8847
9243
  // Each node publishes a lightweight fingerprint of its memory state.
8848
9244
  // If hashes differ between same-tier nodes, the lagging node can
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "open-agents-ai",
3
- "version": "0.186.50",
3
+ "version": "0.186.52",
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",