natureco-cli 5.12.0 → 5.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "natureco-cli",
3
- "version": "5.12.0",
3
+ "version": "5.14.0",
4
4
  "description": "OpenClaw'dan daha güvenli, daha hızlı, daha ucuz AI agent CLI. Multi-agent, self-evolving skills, audit log, maliyet optimizasyonu ve NatureCo platform-native.",
5
5
  "bin": {
6
6
  "natureco": "bin/natureco.js"
@@ -1016,10 +1016,10 @@ async function startRepl(args) {
1016
1016
  process.stdout.write('Merhaba! Ben ' + displayName + '. ');
1017
1017
  }
1018
1018
 
1019
- // AI cevabı
1019
+ // AI cevabı — v5.13.0: workflow orchestrator ALWAYS first
1020
1020
  process.stdout.write(tui.styled('\n AI ', { color: tui.PALETTE.secondary, bold: true }));
1021
1021
  try {
1022
- // Per-turn: rebuild volatile tier with current memory snapshot (Hermes frozen snapshot)
1022
+ // Per-turn: rebuild volatile tier with current memory snapshot
1023
1023
  guardrails.reset();
1024
1024
  memory = loadMemory(cfg.userName);
1025
1025
  memoryStore.load();
@@ -1027,8 +1027,52 @@ async function startRepl(args) {
1027
1027
  promptOpts.memoryFacts = memory.facts || [];
1028
1028
  systemPrompt = rebuildSystemPrompt(promptOpts);
1029
1029
  messages[0] = { role: 'system', content: systemPrompt, _internal: true };
1030
- const apiMessages = messages.filter(m => !m._internal);
1031
- const reply = await sendStreaming(
1030
+
1031
+ // v5.13.0: Run workflow FIRST for every request
1032
+ const wfToolDefs = getToolDefs();
1033
+ const wfResult = await executeTool('workflow', { action: 'run', task: line }, wfToolDefs);
1034
+ const wf = wfResult?.result || {};
1035
+
1036
+ if (wf.passthrough && wf.reply) {
1037
+ // Simple chat — workflow handled it directly
1038
+ const fullReply = String(wf.reply);
1039
+ const displayBotName = memory.botName || 'Asistan';
1040
+ let fixedReply = String(fullReply);
1041
+ fixedReply = fixedReply.replace(/\bMiniMax[-\s\w\.\d]*/gi, displayBotName);
1042
+ fixedReply = fixedReply.replace(/\bM2\.5[-\s\w\.\d]*/gi, displayBotName);
1043
+ fixedReply = fixedReply.replace(/\bM2[\s\-\.\w\d]*/gi, displayBotName);
1044
+ fixedReply = fixedReply.replace(/\bClaude[-\s\w\.\d]*/gi, displayBotName);
1045
+ fixedReply = fixedReply.replace(/\bGPT[-\s\w\.\d]*/gi, displayBotName);
1046
+ fixedReply = fixedReply.replace(/\bChatGPT\b/g, displayBotName);
1047
+ fixedReply = fixedReply.replace(/NatureCo\s+CLI(\s*'in|'nin)?/gi, displayBotName);
1048
+ fixedReply = fixedReply.replace(/Ben\s+MiniMax[^.!?,;:\n]*/gi, 'Ben ' + displayBotName);
1049
+ fixedReply = fixedReply.replace(/Ben\s+Claude[^.!?,;:\n]*/gi, 'Ben ' + displayBotName);
1050
+ fixedReply = fixedReply.replace(/Ben\s+GPT[^.!?,;:\n]*/gi, 'Ben ' + displayBotName);
1051
+ fixedReply = fixedReply.replace(/Ben\s+Asistan[\s\w\.]*/gi, 'Ben ' + displayBotName);
1052
+ fixedReply = fixedReply.replace(/\*\*(?:MiniMax|Claude|GPT|M2\.5|M2)[^\*]*\*\*/gi, '**' + displayBotName + '**');
1053
+ process.stdout.write('\n' + fixedReply + '\n');
1054
+ messages.push({ role: 'assistant', content: fixedReply });
1055
+ totalInputTokens += Math.ceil(line.length / 4);
1056
+ totalOutputTokens += Math.ceil(fullReply.length / 4);
1057
+ } else if (wf.status === 'completed' || (wf.results && wf.results.length > 0)) {
1058
+ // Complex task — inject workflow report as context, then LLM crafts final reply
1059
+ const workflowSteps = wf.results || [];
1060
+ const report = workflowSteps.map(r => {
1061
+ const t = r.tool || r.name || '?';
1062
+ const s = r.status === 'done' ? '✓' : '✗';
1063
+ let summary = '';
1064
+ if (r.result) {
1065
+ try { summary = typeof r.result === 'string' ? r.result.slice(0, 400) : JSON.stringify(r.result).slice(0, 400); } catch {}
1066
+ }
1067
+ return ` ${s} ${t}: ${summary}`;
1068
+ }).join('\n');
1069
+ messages.push({
1070
+ role: 'system',
1071
+ content: `=== WORKFLOW SONUCLARI ===\nSu araclar calisti:\n${report}\n\nKullaniciya bu sonuclari anlamli bir sekilde ozetle.\n=== SONUC BITTI ===`,
1072
+ _internal: true
1073
+ });
1074
+ const apiMessages = messages.filter(m => !m._internal);
1075
+ const reply = await sendStreaming(
1032
1076
  providerUrl,
1033
1077
  providerApiKey,
1034
1078
  apiMessages,
@@ -1049,41 +1093,45 @@ async function startRepl(args) {
1049
1093
  }
1050
1094
  })
1051
1095
  );
1052
- // v5.6.12: Tam metin 'reply' olarak zaten geldi (non-stream mode)
1053
- const fullReply = String(reply || '');
1054
- // Bot adini al
1055
- const displayBotName = memory.botName || 'Asistan';
1056
- // v5.6.9: Tum model adlarini ve varyasyonlari temizle
1057
- let fixedReply = String(fullReply);
1058
- // Bilinen model adlari - tum varyasyonlar
1059
- fixedReply = fixedReply.replace(/\bMiniMax[-\s\w\.\d]*/gi, displayBotName);
1060
- fixedReply = fixedReply.replace(/\bM2\.5[-\s\w\.\d]*/gi, displayBotName);
1061
- fixedReply = fixedReply.replace(/\bM2[\s\-\.\w\d]*/gi, displayBotName);
1062
- fixedReply = fixedReply.replace(/\bClaude[-\s\w\.\d]*/gi, displayBotName);
1063
- fixedReply = fixedReply.replace(/\bGPT[-\s\w\.\d]*/gi, displayBotName);
1064
- fixedReply = fixedReply.replace(/\bChatGPT\b/g, displayBotName);
1065
- // NatureCo CLI referansini temizle
1066
- fixedReply = fixedReply.replace(/NatureCo\s+CLI(\s*'in|'nin)?/gi, displayBotName);
1067
- // "Ben X" pattern - tum model adlarini bot adi ile degistir
1068
- fixedReply = fixedReply.replace(/Ben\s+MiniMax[^.!?,;:\n]*/gi, 'Ben ' + displayBotName);
1069
- fixedReply = fixedReply.replace(/Ben\s+Claude[^.!?,;:\n]*/gi, 'Ben ' + displayBotName);
1070
- fixedReply = fixedReply.replace(/Ben\s+GPT[^.!?,;:\n]*/gi, 'Ben ' + displayBotName);
1071
- fixedReply = fixedReply.replace(/Ben\s+Asistan[\s\w\.]*/gi, 'Ben ' + displayBotName);
1072
- // Markdown ** ile cevrili model adi
1073
- fixedReply = fixedReply.replace(/\*\*(?:MiniMax|Claude|GPT|M2\.5|M2)[^\*]*\*\*/gi, '**' + displayBotName + '**');
1074
- // Cevap yazdir
1075
- process.stdout.write('\n' + fixedReply + '\n');
1076
- // v5.7.18: Tool call geçmişini kalıcı messages'a ekle — model sonraki turlarda tool sonuçlarını görsün
1077
- const existingLen = messages.filter(m => !m._internal).length;
1078
- const toolCallHistory = apiMessages.slice(existingLen);
1079
- for (const m of toolCallHistory) {
1080
- if (m.role === 'assistant' || m.role === 'tool') {
1081
- messages.push(m);
1096
+ // v5.6.12: Tam metin 'reply' olarak zaten geldi (non-stream mode)
1097
+ const fullReply = String(reply || '');
1098
+ // Bot adini al
1099
+ const displayBotName = memory.botName || 'Asistan';
1100
+ // v5.6.9: Tum model adlarini ve varyasyonlari temizle
1101
+ let fixedReply = String(fullReply);
1102
+ fixedReply = fixedReply.replace(/\bMiniMax[-\s\w\.\d]*/gi, displayBotName);
1103
+ fixedReply = fixedReply.replace(/\bM2\.5[-\s\w\.\d]*/gi, displayBotName);
1104
+ fixedReply = fixedReply.replace(/\bM2[\s\-\.\w\d]*/gi, displayBotName);
1105
+ fixedReply = fixedReply.replace(/\bClaude[-\s\w\.\d]*/gi, displayBotName);
1106
+ fixedReply = fixedReply.replace(/\bGPT[-\s\w\.\d]*/gi, displayBotName);
1107
+ fixedReply = fixedReply.replace(/\bChatGPT\b/g, displayBotName);
1108
+ fixedReply = fixedReply.replace(/NatureCo\s+CLI(\s*'in|'nin)?/gi, displayBotName);
1109
+ fixedReply = fixedReply.replace(/Ben\s+MiniMax[^.!?,;:\n]*/gi, 'Ben ' + displayBotName);
1110
+ fixedReply = fixedReply.replace(/Ben\s+Claude[^.!?,;:\n]*/gi, 'Ben ' + displayBotName);
1111
+ fixedReply = fixedReply.replace(/Ben\s+GPT[^.!?,;:\n]*/gi, 'Ben ' + displayBotName);
1112
+ fixedReply = fixedReply.replace(/Ben\s+Asistan[\s\w\.]*/gi, 'Ben ' + displayBotName);
1113
+ fixedReply = fixedReply.replace(/\*\*(?:MiniMax|Claude|GPT|M2\.5|M2)[^\*]*\*\*/gi, '**' + displayBotName + '**');
1114
+ process.stdout.write('\n' + fixedReply + '\n');
1115
+ const existingLen = messages.filter(m => !m._internal).length;
1116
+ const toolCallHistory = apiMessages.slice(existingLen);
1117
+ for (const m of toolCallHistory) {
1118
+ if (m.role === 'assistant' || m.role === 'tool') {
1119
+ messages.push(m);
1120
+ }
1082
1121
  }
1122
+ messages.push({ role: 'assistant', content: fixedReply });
1123
+ totalInputTokens += apiMessages.reduce((s, m) => s + Math.ceil((m.content || '').length / 4), 0);
1124
+ totalOutputTokens += Math.ceil((fullReply || '').length / 4);
1125
+ } else {
1126
+ // Workflow failed or returned unexpected format
1127
+ const fullReply = wf.error || JSON.stringify(wf).slice(0, 400) || 'Workflow islenemedi.';
1128
+ const displayBotName = memory.botName || 'Asistan';
1129
+ let fixedReply = fullReply.replace(/\bMiniMax[-\s\w\.\d]*/gi, displayBotName);
1130
+ process.stdout.write('\n' + fixedReply + '\n');
1131
+ messages.push({ role: 'assistant', content: fixedReply });
1132
+ totalInputTokens += Math.ceil(line.length / 4);
1133
+ totalOutputTokens += Math.ceil(fixedReply.length / 4);
1083
1134
  }
1084
- messages.push({ role: 'assistant', content: fixedReply });
1085
- totalInputTokens += apiMessages.reduce((s, m) => s + Math.ceil((m.content || '').length / 4), 0);
1086
- totalOutputTokens += Math.ceil((fullReply || '').length / 4);
1087
1135
  } catch (err) {
1088
1136
  process.stdout.write('\n');
1089
1137
  console.log(chalk.red(' ❌ ' + err.message));
@@ -70,6 +70,31 @@ async function workflow(params) {
70
70
  if (action === 'run') {
71
71
  if (!task) return { success: false, error: 'task gerekli' };
72
72
 
73
+ // Phase 0: Check if simple chat (passthrough) — no planning needed
74
+ const simpleCheckPrompt = {
75
+ role: 'system',
76
+ content: 'Gorevin basit bir selamlasma/sohbet mi yoksa arac gerektiren bir islem mi oldugunu belirle. Sadece "simple" veya "complex" yaz, baska bir sey yazma.\n\nSimple: selamlasma, nasilsin, bugun ne yaptin, havadan sudan, genel bilgi sorusu\nComplex: dosya islemleri, kod yazma, arastirma, karsilastirma, duzenleme, otomasyon, proje yonetimi, debug'
77
+ };
78
+ const simpleBody = { model, stream: false, messages: [simpleCheckPrompt, { role: 'user', content: task }], temperature: 0, max_tokens: 10 };
79
+ let isSimple = false;
80
+ try {
81
+ const simpleResult = await apiCall(providerUrl, providerApiKey, simpleBody);
82
+ const simpleAnswer = (simpleResult.choices?.[0]?.message?.content || '').trim().toLowerCase();
83
+ isSimple = simpleAnswer === 'simple';
84
+ } catch {}
85
+
86
+ if (isSimple) {
87
+ // Passthrough: just chat with LLM, no tools
88
+ const chatBody = { model, stream: false, messages: [{ role: 'system', content: 'Sen yardimci bir asistansin. Kisa ve oz yanit ver.' }, { role: 'user', content: task }], temperature: 0.7, max_tokens: 1000 };
89
+ try {
90
+ const chatResult = await apiCall(providerUrl, providerApiKey, chatBody);
91
+ const reply = chatResult.choices?.[0]?.message?.content || '';
92
+ return { success: true, workflowId: 'passthrough', name: 'Direct Chat', status: 'completed', totalSteps: 0, completedSteps: 0, results: [{ step: 0, tool: 'chat', status: 'done', result: { reply } }], passthrough: true, reply };
93
+ } catch (e) {
94
+ return { success: false, error: 'Sohbet yaniti alinamadi: ' + e.message };
95
+ }
96
+ }
97
+
73
98
  // Phase 1: LLM plans the workflow
74
99
  const planPrompt = {
75
100
  role: 'system',
@@ -55,6 +55,9 @@ function buildTiers(opts) {
55
55
 
56
56
  // Tool rules (stable)
57
57
  `ONEMLI: Tool cagirma SIMULE ETME. Sadece duz metin cevap ver. Islem yapmak gerekirse tool'u gercekten cagir.`,
58
+ `!!! ZORUNLU !!! HER istekte ILK OLARAK workflow(action="run", task="<kullanici mesaji>") cagir. workflow tool'u ne yapilacagini analiz eder, uygun tool'lari secer ve sirayla calistirir.`,
59
+ `workflow basit selamlasmalarda passthrough yapar, karmasik islerde adim adim plan+uygulama yapar.`,
60
+ `workflow'dan sonra ek tool cagirmaya GEREK YOK — workflow her seyi halleder.`,
58
61
  `COK KRITIK: Goreve baslamadan ONCE <available_skills> listesini tara. Ilgili skill varsa skill_view(name) ile yukle, SONRA goreve basla.`,
59
62
  `KRITIK: Skill yuklemeden islem yapma. Ilgili skill varsa once yukle.`,
60
63
  `KRITIK: Kullanici kisisel bilgi verdiginde memory(action=add, target=user) ile kaydet.`,