kiosapi 0.1.8 → 0.1.10
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/agent/run.js +39 -0
- package/dist/agent/schemas.js +2 -0
- package/package.json +5 -2
package/dist/agent/run.js
CHANGED
|
@@ -368,6 +368,13 @@ export async function runTurn(s, userText) {
|
|
|
368
368
|
console.log(dim(` ↳ ${idn(totalIn + totalOut)} token (${idn(totalIn)} in · ${idn(totalOut)} out)`));
|
|
369
369
|
}
|
|
370
370
|
};
|
|
371
|
+
// Loop detection: count total calls per signature (tool+args) across the whole runTurn.
|
|
372
|
+
// Consecutive-3 catches obvious tight loops; count-4 catches spread-out repetition where
|
|
373
|
+
// other calls (daftar src, baca ...) appear between the repeating call.
|
|
374
|
+
const callCounts = new Map();
|
|
375
|
+
const lastSigs = []; // last 3 sigs for consecutive detection
|
|
376
|
+
const COUNT_LIMIT = 4; // same tool+args called 4× total → loop
|
|
377
|
+
const CONSEC_LIMIT = 3; // same sig 3× in a row → loop
|
|
371
378
|
const stepLimit = s.maxSteps ?? MAX_STEPS;
|
|
372
379
|
for (let step = 0; step < stepLimit; step++) {
|
|
373
380
|
const stop = thinking();
|
|
@@ -406,6 +413,38 @@ export async function runTurn(s, userText) {
|
|
|
406
413
|
s.totalTokens += totalIn + totalOut;
|
|
407
414
|
return lastText;
|
|
408
415
|
}
|
|
416
|
+
// --- Loop detection before running any tools this step ---
|
|
417
|
+
let loopSig = null;
|
|
418
|
+
for (const call of calls) {
|
|
419
|
+
const sig = `${call.function.name}:${call.function.arguments}`;
|
|
420
|
+
const count = (callCounts.get(sig) ?? 0) + 1;
|
|
421
|
+
callCounts.set(sig, count);
|
|
422
|
+
lastSigs.push(sig);
|
|
423
|
+
if (lastSigs.length > CONSEC_LIMIT)
|
|
424
|
+
lastSigs.shift();
|
|
425
|
+
// Total count exceeded, or 3 in a row
|
|
426
|
+
const consecutive = lastSigs.length === CONSEC_LIMIT && lastSigs.every((s) => s === sig);
|
|
427
|
+
if (count >= COUNT_LIMIT || consecutive) {
|
|
428
|
+
loopSig = sig;
|
|
429
|
+
break;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
if (loopSig !== null) {
|
|
433
|
+
const loopName = loopSig.split(':')[0] ?? 'unknown';
|
|
434
|
+
const total = callCounts.get(loopSig) ?? 0;
|
|
435
|
+
console.log(red(`\n⚠ Loop terdeteksi: "${loopName}" dipanggil ${total}× — agen terjebak.`));
|
|
436
|
+
console.log(yellow('Berikan instruksi baru, atau ketik /bersih untuk mulai ulang.'));
|
|
437
|
+
const loopMsg = `⚠ LOOP: "${loopName}" sudah dipanggil ${total}× dengan argumen yang sama. ` +
|
|
438
|
+
`JANGAN panggil lagi. Gunakan tool "selesai" dan jelaskan kendalanya, ` +
|
|
439
|
+
`atau minta klarifikasi dari pengguna.`;
|
|
440
|
+
for (const call of calls) {
|
|
441
|
+
s.messages.push({ role: 'tool', content: loopMsg, tool_call_id: call.id });
|
|
442
|
+
}
|
|
443
|
+
saveCheckpoint(s);
|
|
444
|
+
showUsage();
|
|
445
|
+
s.totalTokens += totalIn + totalOut;
|
|
446
|
+
return lastText;
|
|
447
|
+
}
|
|
409
448
|
const stepModified = new Set();
|
|
410
449
|
for (const call of calls) {
|
|
411
450
|
const result = await runTool(call, s.otomatis, s.model);
|
package/dist/agent/schemas.js
CHANGED
|
@@ -195,5 +195,7 @@ Aturan:
|
|
|
195
195
|
- Path selalu relatif ke direktori kerja; akses ke luar ditolak.
|
|
196
196
|
- Gunakan hapus_file/pindah_file untuk menghapus/memindahkan file (lebih aman dari jalankan del/rm).
|
|
197
197
|
- Buat perubahan kecil dan jelas. Setelah tugas beres, panggil tool "selesai" dengan ringkasan.
|
|
198
|
+
- JANGAN memanggil tool yang sama dengan argumen yang sama lebih dari 1× berturut-turut. Jika sudah mendapat hasil daftar_file atau baca_file, langsung lanjutkan — JANGAN ulangi panggilan yang sama.
|
|
199
|
+
- Jika tidak tahu harus berbuat apa selanjutnya, gunakan tool "selesai" dan jelaskan apa yang sudah ditemukan.
|
|
198
200
|
- Jawab dan jelaskan dalam Bahasa Indonesia.`;
|
|
199
201
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kiosapi",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "CLI Kiosapi.id berbahasa Indonesia — bangun aplikasimu pakai API key Kiosapi (agen + multimodal).",
|
|
6
6
|
"keywords": [
|
|
@@ -28,7 +28,10 @@
|
|
|
28
28
|
"bin": {
|
|
29
29
|
"kiosapi": "./dist/index.js"
|
|
30
30
|
},
|
|
31
|
-
"files": [
|
|
31
|
+
"files": [
|
|
32
|
+
"dist",
|
|
33
|
+
"README.md"
|
|
34
|
+
],
|
|
32
35
|
"engines": {
|
|
33
36
|
"node": ">=20"
|
|
34
37
|
},
|