open-agents-ai 0.138.77 → 0.138.79

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 +169 -2
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -5644,6 +5644,37 @@ async function handleCmd(cmd) {
5644
5644
  break;
5645
5645
  }
5646
5646
 
5647
+ // \u2500\u2500 COHERE distributed learning \u2014 publish insight to mesh \u2500\u2500\u2500\u2500\u2500\u2500
5648
+ case 'cohere_publish_insight': {
5649
+ if (!cohereActive) { writeResp(id, { ok: false, output: 'COHERE not active' }); break; }
5650
+ if (!_natsConn || !_natsCodec) { writeResp(id, { ok: false, output: 'NATS not connected' }); break; }
5651
+ var _cpiInsight = args.insight || '';
5652
+ var _cpiCategory = args.category || 'strategy';
5653
+ var _cpiConfidence = parseFloat(args.confidence || '0.7');
5654
+ if (!_cpiInsight) { writeResp(id, { ok: false, output: 'insight text required' }); break; }
5655
+ try {
5656
+ var _cpiDelta = {
5657
+ type: 'cohere.learning',
5658
+ delta_id: 'insight-' + Date.now().toString(36) + '-' + Math.random().toString(36).slice(2, 6),
5659
+ source_peer: nexus.peerId,
5660
+ source_agent: agentName,
5661
+ insight: String(_cpiInsight).slice(0, 500),
5662
+ category: _cpiCategory,
5663
+ confidence: _cpiConfidence,
5664
+ model_tier: 'unknown',
5665
+ timestamp: Date.now(),
5666
+ };
5667
+ _natsConn.publish('nexus.cohere.learning', _natsCodec.encode(JSON.stringify(_cpiDelta)));
5668
+ _cohereStats.queriesSent = (_cohereStats.queriesSent || 0) + 1;
5669
+ _saveStats();
5670
+ dlog('COHERE learning published: ' + _cpiCategory + ' \u2014 ' + String(_cpiInsight).slice(0, 80));
5671
+ writeResp(id, { ok: true, output: 'Insight published to COHERE mesh: ' + _cpiDelta.delta_id });
5672
+ } catch (_cpiErr) {
5673
+ writeResp(id, { ok: false, output: 'Publish error: ' + (_cpiErr.message || _cpiErr) });
5674
+ }
5675
+ break;
5676
+ }
5677
+
5647
5678
  // \u2500\u2500 Metered Inference Exposure \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
5648
5679
  case 'expose': {
5649
5680
  // Clear old inference capabilities before registering new ones
@@ -6846,6 +6877,50 @@ process.on('unhandledRejection', (reason) => {
6846
6877
  })().catch(function(e) { dlog('COHERE claim listener error: ' + (e.message || e)); });
6847
6878
  dlog('COHERE claim listener subscribed to nexus.cohere.claimed');
6848
6879
 
6880
+ // \u2500\u2500 WO-DL1: Learning ingestion \u2014 receive insights from other nodes \u2500\u2500
6881
+ const _learnSub = _natsConn.subscribe('nexus.cohere.learning');
6882
+ (async function() {
6883
+ for await (const _lMsg of _learnSub) {
6884
+ if (!cohereActive) continue;
6885
+ try {
6886
+ var _lData = JSON.parse(_natsCodec.decode(_lMsg.data));
6887
+ if (!_lData.insight || !_lData.source_peer) continue;
6888
+ // Skip our own insights
6889
+ if (_lData.source_peer === nexus.peerId) continue;
6890
+ // Ingest: write to local metabolism store
6891
+ var _lStoreDir = join(nexusDir, '..', 'memory', 'metabolism');
6892
+ var _lStoreFile = join(_lStoreDir, 'store.json');
6893
+ var _lStore = [];
6894
+ try {
6895
+ if (existsSync(_lStoreFile)) _lStore = JSON.parse(readFileSync(_lStoreFile, 'utf8'));
6896
+ } catch {}
6897
+ // Dedup: skip if we already have this insight (by delta_id)
6898
+ if (_lStore.some(function(m) { return m.id === _lData.delta_id; })) continue;
6899
+ _lStore.push({
6900
+ id: _lData.delta_id,
6901
+ type: 'procedural',
6902
+ content: '[mesh:' + (_lData.source_agent || 'peer').slice(0, 20) + '] ' + _lData.insight,
6903
+ sourceTrace: 'cohere-mesh:' + (_lData.source_peer || '').slice(0, 16),
6904
+ scores: {
6905
+ novelty: 0.7,
6906
+ utility: Math.min(1, _lData.confidence || 0.5),
6907
+ confidence: Math.min(1, (_lData.confidence || 0.5) * 0.8), // discount remote slightly
6908
+ identityRelevance: 0.2,
6909
+ },
6910
+ decision: { action: 'admit', reason: 'Ingested from COHERE mesh peer' },
6911
+ createdAt: new Date().toISOString(),
6912
+ lastAccessedAt: new Date().toISOString(),
6913
+ accessCount: 0,
6914
+ });
6915
+ if (_lStore.length > 100) _lStore = _lStore.slice(-100);
6916
+ mkdirSync(_lStoreDir, { recursive: true });
6917
+ writeFileSync(_lStoreFile, JSON.stringify(_lStore, null, 2));
6918
+ dlog('COHERE learning ingested from ' + (_lData.source_agent || 'unknown') + ': ' + String(_lData.insight).slice(0, 60));
6919
+ } catch {}
6920
+ }
6921
+ })().catch(function(e) { dlog('COHERE learning listener error: ' + (e.message || e)); });
6922
+ dlog('COHERE learning listener subscribed to nexus.cohere.learning');
6923
+
6849
6924
  // \u2500\u2500 WO-1.5: Capacity announcement \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
6850
6925
  // Publish what models we have, system metrics, and warm model status
6851
6926
  // so other nodes can make intelligent routing decisions.
@@ -6978,7 +7053,8 @@ process.on('SIGINT', () => process.emit('SIGTERM'));
6978
7053
  "cohere_allow_model",
6979
7054
  "cohere_deny_model",
6980
7055
  "cohere_list_models",
6981
- "ipfs_add"
7056
+ "ipfs_add",
7057
+ "cohere_publish_insight"
6982
7058
  ],
6983
7059
  description: "The nexus action. MUST call 'connect' first (spawns daemon). Then: join_room, send_message, discover_peers, expose, status, cohere_stats, cohere_enable, cohere_disable, cohere_allow_model, cohere_deny_model, cohere_list_models, ipfs_add, etc."
6984
7060
  },
@@ -7218,6 +7294,13 @@ process.on('SIGINT', () => process.emit('SIGTERM'));
7218
7294
  case "ipfs_add":
7219
7295
  result = await this.sendDaemonCmd("ipfs_add", { content: String(args.content ?? args.message ?? "") });
7220
7296
  break;
7297
+ case "cohere_publish_insight":
7298
+ result = await this.sendDaemonCmd("cohere_publish_insight", {
7299
+ insight: String(args.insight ?? args.content ?? ""),
7300
+ category: String(args.category ?? "strategy"),
7301
+ confidence: String(args.confidence ?? "0.7")
7302
+ });
7303
+ break;
7221
7304
  default:
7222
7305
  return { success: false, output: "", error: `Unknown nexus action: ${action}`, durationMs: Date.now() - start };
7223
7306
  }
@@ -54257,7 +54340,7 @@ function startTask(task, config, repoRoot, voice, stream, taskStores, bruteForce
54257
54340
  try {
54258
54341
  const { MemoryMetabolismTool: MemoryMetabolismTool2 } = __require("@open-agents/execution");
54259
54342
  const mm = new MemoryMetabolismTool2(repoRoot);
54260
- const metabolismMemories = mm.getTopMemoriesSync(5, taskType || void 0);
54343
+ const metabolismMemories = mm.getTopMemoriesSync(2, taskType || void 0);
54261
54344
  if (metabolismMemories) {
54262
54345
  dynamicContext += `
54263
54346
 
@@ -58078,6 +58161,90 @@ async function runWithTUI(task, config, repoPath) {
58078
58161
  }
58079
58162
  } catch {
58080
58163
  }
58164
+ try {
58165
+ const ts = handle.runner?.taskState;
58166
+ if (ts && ts.toolCallCount > 2) {
58167
+ let category = "strategy";
58168
+ let lesson = "";
58169
+ if (ts.failedApproaches && ts.failedApproaches.length > 0) {
58170
+ category = "recovery";
58171
+ const failed = ts.failedApproaches.slice(0, 2).join("; ");
58172
+ const worked = ts.completedSteps?.slice(-2).join(" \u2192 ") || "completed task";
58173
+ lesson = `[recovery] Avoid: ${failed}. Instead: ${worked}`;
58174
+ } else if (ts.completedSteps && ts.completedSteps.length > 1) {
58175
+ lesson = `[strategy] ${ts.completedSteps.slice(-3).join(" \u2192 ")}`;
58176
+ } else {
58177
+ lesson = `[strategy] Solved: ${task.slice(0, 150)}`;
58178
+ }
58179
+ if (lesson) {
58180
+ const metaDir = join59(repoRoot, ".oa", "memory", "metabolism");
58181
+ const storeFile = join59(metaDir, "store.json");
58182
+ let store = [];
58183
+ try {
58184
+ if (existsSync43(storeFile))
58185
+ store = JSON.parse(readFileSync32(storeFile, "utf8"));
58186
+ } catch {
58187
+ }
58188
+ store.push({
58189
+ id: `mem-traj-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 6)}`,
58190
+ type: "procedural",
58191
+ content: lesson.slice(0, 500),
58192
+ sourceTrace: "trajectory-extraction",
58193
+ scores: {
58194
+ novelty: 0.6,
58195
+ utility: category === "recovery" ? 0.8 : 0.6,
58196
+ confidence: 0.7,
58197
+ identityRelevance: 0.3
58198
+ },
58199
+ decision: { action: "admit", reason: `Auto-extracted ${category} from task (${ts.toolCallCount} tool calls)` },
58200
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
58201
+ lastAccessedAt: (/* @__PURE__ */ new Date()).toISOString(),
58202
+ accessCount: 0
58203
+ });
58204
+ if (store.length > 100)
58205
+ store = store.slice(-100);
58206
+ mkdirSync19(metaDir, { recursive: true });
58207
+ writeFileSync18(storeFile, JSON.stringify(store, null, 2));
58208
+ }
58209
+ }
58210
+ } catch {
58211
+ }
58212
+ try {
58213
+ const cohereSettingsFile = join59(repoRoot, ".oa", "settings.json");
58214
+ let cohereActive = false;
58215
+ try {
58216
+ if (existsSync43(cohereSettingsFile)) {
58217
+ const settings = JSON.parse(readFileSync32(cohereSettingsFile, "utf8"));
58218
+ cohereActive = settings.cohere === true;
58219
+ }
58220
+ } catch {
58221
+ }
58222
+ if (cohereActive) {
58223
+ const metaFile = join59(repoRoot, ".oa", "memory", "metabolism", "store.json");
58224
+ if (existsSync43(metaFile)) {
58225
+ const store = JSON.parse(readFileSync32(metaFile, "utf8"));
58226
+ const latest = store.filter((m) => m.sourceTrace === "trajectory-extraction").slice(-1)[0];
58227
+ if (latest && latest.scores?.confidence >= 0.6) {
58228
+ try {
58229
+ const { NexusTool: NexusTool2 } = __require("@open-agents/execution");
58230
+ const nexus = new NexusTool2(repoRoot);
58231
+ Promise.race([
58232
+ nexus.execute({
58233
+ action: "cohere_publish_insight",
58234
+ insight: latest.content,
58235
+ category: latest.content.startsWith("[recovery]") ? "recovery" : "strategy",
58236
+ confidence: String(latest.scores.confidence)
58237
+ }),
58238
+ new Promise((r) => setTimeout(r, 2e3))
58239
+ ]).catch(() => {
58240
+ });
58241
+ } catch {
58242
+ }
58243
+ }
58244
+ }
58245
+ }
58246
+ } catch {
58247
+ }
58081
58248
  } catch (err) {
58082
58249
  try {
58083
58250
  const ikFile = join59(repoRoot, ".oa", "identity", "self-state.json");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "open-agents-ai",
3
- "version": "0.138.77",
3
+ "version": "0.138.79",
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",