kiosapi 0.1.24 → 0.1.26
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 +43 -9
- package/dist/agent/schemas.js +2 -1
- package/package.json +1 -1
package/dist/agent/run.js
CHANGED
|
@@ -56,9 +56,32 @@ function trimContext(messages) {
|
|
|
56
56
|
const dropped = clean.length - tail.length;
|
|
57
57
|
if (dropped <= 0)
|
|
58
58
|
return [system, ...clean];
|
|
59
|
+
// Collect baca_file paths from the dropped messages so the model knows which files it
|
|
60
|
+
// already has context for — prevents it from re-orienting by re-reading config/schema files.
|
|
61
|
+
const droppedHead = clean.slice(0, clean.length - tail.length + skip);
|
|
62
|
+
const droppedPaths = [];
|
|
63
|
+
for (const msg of droppedHead) {
|
|
64
|
+
if (msg.role === 'assistant' && msg.tool_calls) {
|
|
65
|
+
for (const tc of msg.tool_calls) {
|
|
66
|
+
if (tc.function?.name === 'baca_file') {
|
|
67
|
+
try {
|
|
68
|
+
const a = JSON.parse(tc.function.arguments ?? '{}');
|
|
69
|
+
if (a.path)
|
|
70
|
+
droppedPaths.push(a.path);
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
/* ignore */
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
const filesNote = droppedPaths.length > 0
|
|
80
|
+
? ` File sudah dibaca (tak lagi di window): ${[...new Set(droppedPaths)].join(', ')}. JANGAN baca ulang — gunakan cari untuk mencari teks spesifik.`
|
|
81
|
+
: '';
|
|
59
82
|
const note = {
|
|
60
83
|
role: 'system',
|
|
61
|
-
content: `[Kiosapi: ${dropped} pesan awal dihapus dari konteks
|
|
84
|
+
content: `[Kiosapi: ${dropped} pesan awal dihapus dari konteks.${filesNote}]`,
|
|
62
85
|
};
|
|
63
86
|
return [system, note, ...tail];
|
|
64
87
|
}
|
|
@@ -413,13 +436,23 @@ export async function runTurn(s, userText) {
|
|
|
413
436
|
catch {
|
|
414
437
|
/* ignore */
|
|
415
438
|
}
|
|
416
|
-
|
|
417
|
-
|
|
439
|
+
// Project context files: read upfront and embed in system message so the model
|
|
440
|
+
// never needs to tool-call for them. blueprint.md / kiosapi.json are orientation
|
|
441
|
+
// anchors that models otherwise read repeatedly when they lose track.
|
|
442
|
+
const CONTEXT_FILES = [
|
|
443
|
+
{ name: 'blueprint.md', cap: 3_000 },
|
|
444
|
+
{ name: 'kiosapi.json', cap: 2_000 },
|
|
445
|
+
{ name: 'package.json', cap: 1_500 },
|
|
446
|
+
{ name: 'pyproject.toml', cap: 1_500 },
|
|
447
|
+
{ name: 'Cargo.toml', cap: 1_500 },
|
|
448
|
+
{ name: 'go.mod', cap: 1_500 },
|
|
449
|
+
];
|
|
450
|
+
for (const { name, cap } of CONTEXT_FILES) {
|
|
451
|
+
const abs = join(process.cwd(), name);
|
|
418
452
|
if (existsSync(abs)) {
|
|
419
453
|
try {
|
|
420
454
|
const content = readFileSync(abs, 'utf8');
|
|
421
|
-
|
|
422
|
-
snippets.push(`<file path="${f}">\n${content.slice(0, 1_500)}\n</file>`);
|
|
455
|
+
snippets.push(`<file path="${name}">\n${content.slice(0, cap)}\n</file>`);
|
|
423
456
|
}
|
|
424
457
|
catch {
|
|
425
458
|
/* unreadable — skip */
|
|
@@ -429,11 +462,12 @@ export async function runTurn(s, userText) {
|
|
|
429
462
|
if (snippets.length > 0) {
|
|
430
463
|
const sysMsg = s.messages[0];
|
|
431
464
|
if (sysMsg?.role === 'system') {
|
|
432
|
-
// Hard cap:
|
|
465
|
+
// Hard cap: 10KB keeps things manageable for most models. blueprint.md alone can
|
|
466
|
+
// be large; cap individual files above and total here.
|
|
433
467
|
const joined = snippets.join('\n\n');
|
|
434
|
-
const capped = joined.length >
|
|
468
|
+
const capped = joined.length > 10_000 ? `${joined.slice(0, 10_000)}\n…` : joined;
|
|
435
469
|
sysMsg.content +=
|
|
436
|
-
`\n\n## Konteks Proyek\n${capped}`;
|
|
470
|
+
`\n\n## Konteks Proyek (sudah tersedia — JANGAN baca ulang dengan baca_file)\n${capped}`;
|
|
437
471
|
}
|
|
438
472
|
}
|
|
439
473
|
}
|
|
@@ -452,7 +486,7 @@ export async function runTurn(s, userText) {
|
|
|
452
486
|
// other calls (daftar src, baca ...) appear between the repeating call.
|
|
453
487
|
const callCounts = new Map();
|
|
454
488
|
const lastSigs = []; // last 3 sigs for consecutive detection
|
|
455
|
-
const COUNT_LIMIT =
|
|
489
|
+
const COUNT_LIMIT = 6; // same tool+args called 6× total → loop (higher because cache now returns content)
|
|
456
490
|
const CONSEC_LIMIT = 3; // same sig 3× in a row → loop
|
|
457
491
|
// Read-only tool cache: on 2nd+ identical call, return the previous result with a warning
|
|
458
492
|
// instead of re-running. This gives the model early feedback so it can self-correct before
|
package/dist/agent/schemas.js
CHANGED
|
@@ -214,7 +214,8 @@ Direktori kerja: ${process.cwd()}
|
|
|
214
214
|
OS: ${osName} · ${shellNote}
|
|
215
215
|
Aturan:
|
|
216
216
|
- Bekerja langkah demi langkah: pakai tool untuk membaca sebelum mengubah.
|
|
217
|
-
-
|
|
217
|
+
- Konteks proyek (blueprint.md, kiosapi.json, struktur root) sudah di-inject ke system message — JANGAN baca ulang dengan baca_file. Langsung kerjakan tugas.
|
|
218
|
+
- Strategi eksplorasi: identifikasi subfolder relevan dari konteks awal, lalu baca spesifik dengan baca_file. JANGAN ulangi daftar_file pada path yang sama.
|
|
218
219
|
- baca_file menampilkan "[path · N baris · M char]" — jika ada "TERPOTONG", panggil baca_file(path, baris_lanjutan) BUKAN dengan argumen identik. Gunakan mulai/sampai untuk baca bagian tertentu.
|
|
219
220
|
- Kedalaman daftar_file: gunakan kedalaman=2 (default) untuk subfolder besar. Kedalaman=3 hanya jika kamu sudah tahu folder itu kecil. JANGAN gunakan kedalaman=4+ kecuali diminta eksplisit.
|
|
220
221
|
- JANGAN memanggil tool APAPUN dengan argumen identik lebih dari 1× dalam satu sesi. Jika tool mengembalikan peringatan cache "⚠", langsung ganti ke path atau argumen BERBEDA — untuk baca_file: gunakan mulai= berbeda atau gunakan cari.
|