minicode-ai 0.20.0 → 0.22.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/README.md +1 -1
- package/cli/auto-update.ts +24 -15
- package/cli/commands/exec.ts +44 -1
- package/cli/commands.ts +5 -2
- package/cli/index.ts +57 -18
- package/cli/setup.ts +88 -34
- package/cli/tui.ts +22 -2
- package/docs/TERMINAL_CONTRACT.md +50 -11
- package/docs/UI_RENDER_PIPELINE.md +6 -3
- package/docs/architecture.md +10 -6
- package/docs/concepts.md +1 -1
- package/docs/contributing.md +4 -3
- package/docs/environment.md +2 -0
- package/docs/policy-sandbox.md +6 -1
- package/docs/security.md +12 -4
- package/docs/skills.md +1 -1
- package/package.json +2 -2
- package/src/config.ts +8 -6
- package/src/daemon/discovery.ts +24 -0
- package/src/policy/bash-guard.ts +170 -6
- package/src/policy/compaction.ts +34 -7
- package/src/policy/jail.ts +10 -22
- package/src/policy/permission.ts +9 -6
- package/src/policy/update-check.ts +6 -4
- package/src/presentation/projection.ts +1 -1
- package/src/providers/anthropic.ts +14 -4
- package/src/providers/responses.ts +1 -1
- package/src/providers/sse-bounds.ts +16 -2
- package/src/ui/approval/prompt.ts +17 -6
- package/src/ui/assistant/simple.ts +14 -0
- package/src/ui/footer.ts +2 -2
- package/src/ui/i18n/en.ts +29 -1
- package/src/ui/i18n/id.ts +29 -1
- package/src/ui/input/prompt-engine.ts +6 -0
- package/src/ui/render/activity-group.ts +53 -0
- package/src/ui/render/activity-panel.ts +91 -0
- package/src/ui/render/cells.ts +33 -6
- package/src/ui/render/diff.ts +58 -2
- package/src/ui/render/highlight.ts +68 -37
- package/src/ui/render/markdown.ts +6 -1
- package/src/ui/render/sanitize.ts +5 -1
- package/src/ui/render/session-summary.ts +11 -4
- package/src/ui/render/table-grid.ts +123 -13
- package/src/ui/render/table.ts +4 -2
- package/src/ui/render/theme.ts +19 -3
- package/src/ui/render/width.ts +35 -6
- package/src/ui/render/wrap.ts +28 -6
- package/src/ui/runtime/loading-bar.ts +137 -0
- package/src/ui/screens/dialog.ts +23 -2
- package/src/ui/screens/form.ts +52 -10
- package/src/ui/screens/model-manager.ts +8 -2
- package/src/ui/screens/picker.ts +11 -3
- package/src/ui/screens/provider-manager.ts +11 -3
- package/src/ui/screens/wizard.ts +29 -1
- package/src/ui/session-state.ts +22 -0
- package/src/ui/tui/app.ts +57 -20
- package/src/ui/tui/transcript.ts +204 -27
- package/vendor/minicore/src/providers/openai-compat.ts +30 -1
package/src/ui/tui/transcript.ts
CHANGED
|
@@ -16,7 +16,8 @@ import type {
|
|
|
16
16
|
UiToolStatus,
|
|
17
17
|
} from "../contract.ts"
|
|
18
18
|
import { t } from "../i18n/locale.ts"
|
|
19
|
-
import {
|
|
19
|
+
import { renderActivityPanel } from "../render/activity-panel.ts"
|
|
20
|
+
import { paintLedger, runMarker, statusWord } from "../render/ledger.ts"
|
|
20
21
|
import { parseFence, renderInline } from "../render/markdown.ts"
|
|
21
22
|
import { type MarkdownTable, parseMarkdownBlocks } from "../render/markdown-table.ts"
|
|
22
23
|
import { sanitizeAnsi, sanitizeAnsiLine, stripSgr } from "../render/sanitize.ts"
|
|
@@ -32,6 +33,12 @@ import { defaultUiState, type UiSessionState } from "../session-state.ts"
|
|
|
32
33
|
// substansi berbeda (viewport vs riwayat yang bisa di-replay).
|
|
33
34
|
export const TRANSCRIPT_CAP = 5000
|
|
34
35
|
export const TRANSCRIPT_TEXT_MAX_CHARS = 1_000_000
|
|
36
|
+
/** Baris pending lebih panjang dari ini tidak dimemo (kunci = isi baris). */
|
|
37
|
+
const PENDING_MEMO_LINE_MAX = 4096
|
|
38
|
+
/** Batas entri memo proyeksi pending sebelum dibuang seluruhnya. */
|
|
39
|
+
const PENDING_MEMO_MAX_ENTRIES = 4000
|
|
40
|
+
/** Baris thinking yang terlihat di area live (Fase 3). */
|
|
41
|
+
const MAX_THINKING_ROWS = 10
|
|
35
42
|
const TRANSCRIPT_TRUNCATION_MARKER = "… [transcript truncated: turn cap exceeded]"
|
|
36
43
|
/**
|
|
37
44
|
* Sink approval TUI: pemilik layar (cli/tui.ts) mendaftarkan transkrip +
|
|
@@ -228,6 +235,9 @@ export class Transcript {
|
|
|
228
235
|
* expanded: mengalir redup seperti teks. */
|
|
229
236
|
private thinkingBuf = ""
|
|
230
237
|
private thinkingTail = ""
|
|
238
|
+
/** Baris thinking turn berjalan (mode AREA, Fase 3): dirender sebagai blok
|
|
239
|
+
* live maks 10 baris, bukan di-commit per baris. Diringkas saat turn selesai. */
|
|
240
|
+
private thinkingArea: string[] = []
|
|
231
241
|
private meta: TranscriptMeta[] = []
|
|
232
242
|
private evicted = 0
|
|
233
243
|
private hasEvictMarker = false
|
|
@@ -371,6 +381,7 @@ export class Transcript {
|
|
|
371
381
|
// diberi marker append-only di bawah.
|
|
372
382
|
this.thinkingBuf = ""
|
|
373
383
|
this.thinkingTail = ""
|
|
384
|
+
this.thinkingArea = []
|
|
374
385
|
if (data.hadVisibleOutput === true) {
|
|
375
386
|
this.push(c.warning(t("ts.providerAttemptDiscarded", { attempt: id })), {
|
|
376
387
|
kind: "diagnostic",
|
|
@@ -384,28 +395,69 @@ export class Transcript {
|
|
|
384
395
|
if (!text) return
|
|
385
396
|
const clean = sanitizeAnsi(text)
|
|
386
397
|
if (this.uiState.reasoningVisible) {
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
this.
|
|
393
|
-
|
|
394
|
-
|
|
398
|
+
if (this.thinkingAreaMode()) {
|
|
399
|
+
// Mode AREA (Fase 3): tahan baris di buffer, dirender sebagai blok live
|
|
400
|
+
// terbatas (projectAll). JANGAN di-commit per baris — area yang
|
|
401
|
+
// menggantikannya + ringkasan saat turn selesai.
|
|
402
|
+
this.thinkingTail += clean
|
|
403
|
+
const parts = this.thinkingTail.split("\n")
|
|
404
|
+
for (let i = 0; i < parts.length - 1; i++) this.thinkingArea.push(parts[i] ?? "")
|
|
405
|
+
// Batasi memori; detail penuh sudah dipangkas per turn saat ringkasan.
|
|
406
|
+
if (this.thinkingArea.length > 2000)
|
|
407
|
+
this.thinkingArea.splice(0, this.thinkingArea.length - 2000)
|
|
408
|
+
this.thinkingTail = parts[parts.length - 1] ?? ""
|
|
409
|
+
} else {
|
|
410
|
+
// Legacy (panel off): alir per baris dengan indentasi 2 kolom
|
|
411
|
+
// (line-buffered, ekor hidup) — membedakan thinking dari jawaban model.
|
|
412
|
+
this.thinkingTail += clean
|
|
413
|
+
const parts = this.thinkingTail.split("\n")
|
|
414
|
+
for (let i = 0; i < parts.length - 1; i++)
|
|
415
|
+
this.append(c.thinking(` ${parts[i] ?? ""}`), { kind: "diagnostic" })
|
|
416
|
+
|
|
417
|
+
this.thinkingTail = parts[parts.length - 1] ?? ""
|
|
418
|
+
}
|
|
395
419
|
} else {
|
|
396
420
|
// Minimized: penanda hidup; isi disimpan di collapsed view linear.
|
|
397
421
|
this.thinkingBuf = (this.thinkingBuf + clean).slice(-20000)
|
|
398
422
|
}
|
|
399
423
|
}
|
|
400
424
|
|
|
401
|
-
/**
|
|
402
|
-
*
|
|
425
|
+
/** Mode area thinking aktif? Panel aktivitas ON + reasoning terlihat.
|
|
426
|
+
* Panel off = perilaku legacy (stream per baris) agar `/fold` benar-benar
|
|
427
|
+
* mengembalikan tampilan mentah. */
|
|
428
|
+
private thinkingAreaMode(): boolean {
|
|
429
|
+
return this.uiState.reasoningVisible && this.uiState.activityPanel
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
/** Selesaikan fase thinking.
|
|
433
|
+
* - Mode area: ringkas jadi SATU baris (detail penuh di `/expand`).
|
|
434
|
+
* - Legacy: flush ekor berindentasi.
|
|
435
|
+
* - Minimized: penanda hilang. */
|
|
403
436
|
private commitThinking(): void {
|
|
437
|
+
if (this.thinkingAreaMode()) {
|
|
438
|
+
const lines = [...this.thinkingArea]
|
|
439
|
+
if (this.thinkingTail) {
|
|
440
|
+
lines.push(this.thinkingTail)
|
|
441
|
+
this.thinkingTail = ""
|
|
442
|
+
}
|
|
443
|
+
this.thinkingArea = []
|
|
444
|
+
this.thinkingBuf = ""
|
|
445
|
+
if (lines.length > 0) {
|
|
446
|
+
// Detail penuh tidak hilang: masuk buffer `/expand`.
|
|
447
|
+
this.uiState.rememberCollapsedSection("thinking", lines.join("\n"))
|
|
448
|
+
this.append(
|
|
449
|
+
c.thinking(` + ${t("panel.thinking")} · ${t("panel.lines", { n: lines.length })}`),
|
|
450
|
+
{ kind: "diagnostic" },
|
|
451
|
+
)
|
|
452
|
+
}
|
|
453
|
+
return
|
|
454
|
+
}
|
|
404
455
|
if (this.thinkingTail) {
|
|
405
456
|
this.append(c.thinking(` ${this.thinkingTail}`), { kind: "diagnostic" })
|
|
406
457
|
this.thinkingTail = ""
|
|
407
458
|
}
|
|
408
459
|
this.thinkingBuf = ""
|
|
460
|
+
this.thinkingArea = []
|
|
409
461
|
}
|
|
410
462
|
|
|
411
463
|
/** Dorong baris logis (sudah final, mis. gema prompt user). */
|
|
@@ -452,6 +504,7 @@ export class Transcript {
|
|
|
452
504
|
clear(): void {
|
|
453
505
|
this.lines = []
|
|
454
506
|
this.rowCache.clear()
|
|
507
|
+
this.pendingRowMemo.clear()
|
|
455
508
|
this.tables = []
|
|
456
509
|
this.ids = []
|
|
457
510
|
this.sourcePrefixes = []
|
|
@@ -466,6 +519,7 @@ export class Transcript {
|
|
|
466
519
|
this.activeProviderAttempt = null
|
|
467
520
|
this.thinkingBuf = ""
|
|
468
521
|
this.thinkingTail = ""
|
|
522
|
+
this.thinkingArea = []
|
|
469
523
|
this.evicted = 0
|
|
470
524
|
this.hasEvictMarker = false
|
|
471
525
|
this.runningMemo = null
|
|
@@ -609,14 +663,77 @@ export class Transcript {
|
|
|
609
663
|
}
|
|
610
664
|
}
|
|
611
665
|
|
|
666
|
+
/** Baris live area thinking (mode area): header `+ berpikir` + maks 10 baris
|
|
667
|
+
* visual terakhir dari turn berjalan. Baris panjang dibungkus (bukan
|
|
668
|
+
* dipotong). Kosong bila mode area off / belum ada thinking. */
|
|
669
|
+
private thinkingRows(w: number): TranscriptRow[] {
|
|
670
|
+
if (!this.thinkingAreaMode()) return []
|
|
671
|
+
const logical = [...this.thinkingArea]
|
|
672
|
+
if (this.thinkingTail) logical.push(this.thinkingTail)
|
|
673
|
+
if (logical.length === 0) return []
|
|
674
|
+
const visual: string[] = []
|
|
675
|
+
for (const line of logical) {
|
|
676
|
+
if (line === "") visual.push("")
|
|
677
|
+
else visual.push(...wrapByWidth(line, w))
|
|
678
|
+
}
|
|
679
|
+
const shown = visual.slice(-MAX_THINKING_ROWS)
|
|
680
|
+
const hidden = visual.length - shown.length
|
|
681
|
+
const out: TranscriptRow[] = []
|
|
682
|
+
const push = (raw: string) => {
|
|
683
|
+
out.push({
|
|
684
|
+
text: c.thinking(raw),
|
|
685
|
+
sourceId: -1,
|
|
686
|
+
sourceStart: 0,
|
|
687
|
+
sourceEnd: 0,
|
|
688
|
+
displayStart: 0,
|
|
689
|
+
displayEnd: displayWidth(raw),
|
|
690
|
+
selectable: false,
|
|
691
|
+
})
|
|
692
|
+
}
|
|
693
|
+
push(
|
|
694
|
+
hidden > 0
|
|
695
|
+
? ` + ${t("panel.thinking")} · ${t("panel.moreLines", { n: hidden })}`
|
|
696
|
+
: ` + ${t("panel.thinking")}`,
|
|
697
|
+
)
|
|
698
|
+
for (const row of shown) push(` ${row}`)
|
|
699
|
+
return out
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
/** Proyeksi panel aktivitas (Fase 2): baris grup dari tool TURN BERJALAN.
|
|
703
|
+
* Sumber = `activityFold` (dikumpulkan per turn oleh event tool), BUKAN
|
|
704
|
+
* snapshot sesi — snapshot bersifat kumulatif sampai cap, jadi akan
|
|
705
|
+
* menampilkan tool dari turn lama. Kosong bila panel off / belum ada tool. */
|
|
706
|
+
private panelRows(): TranscriptRow[] {
|
|
707
|
+
if (!this.uiState.activityPanel) return []
|
|
708
|
+
if (this.activityFold.length === 0) return []
|
|
709
|
+
const activities = this.activityFold.map((e) => ({
|
|
710
|
+
toolCallId: "",
|
|
711
|
+
name: e.name,
|
|
712
|
+
status: e.status as UiToolStatus,
|
|
713
|
+
tsStart: 0,
|
|
714
|
+
}))
|
|
715
|
+
const lines = renderActivityPanel(activities, { maxRows: 10 })
|
|
716
|
+
return lines.map((line) => ({
|
|
717
|
+
text: line,
|
|
718
|
+
sourceId: -1,
|
|
719
|
+
sourceStart: 0,
|
|
720
|
+
sourceEnd: 0,
|
|
721
|
+
displayStart: 0,
|
|
722
|
+
displayEnd: displayWidth(line),
|
|
723
|
+
selectable: false,
|
|
724
|
+
}))
|
|
725
|
+
}
|
|
726
|
+
|
|
612
727
|
private projectAll(width: number): TranscriptRow[] {
|
|
613
728
|
const w = Math.max(10, width)
|
|
729
|
+
const thinking = this.thinkingRows(w)
|
|
614
730
|
const running = this.runningRows()
|
|
731
|
+
const panel = this.panelRows()
|
|
615
732
|
// Kasus umum (idle ketik/scroll — thinking tau cara running kosong):
|
|
616
733
|
// kembalikan gabungan committed+pending yang ter-cache TANPA menyalin ulang.
|
|
617
734
|
// Ini memberantas biaya concat O(N) pada setiap paint (biaya yang TUMBUH
|
|
618
735
|
// seiring transkrip menumpuk — tepat gejala "mengetik berat saat history penuh").
|
|
619
|
-
if (!this.thinkingTail && running.length === 0) {
|
|
736
|
+
if (!this.thinkingTail && thinking.length === 0 && running.length === 0 && panel.length === 0) {
|
|
620
737
|
if (
|
|
621
738
|
this.projectedBase &&
|
|
622
739
|
this.projectedBase.width === w &&
|
|
@@ -639,7 +756,7 @@ export class Transcript {
|
|
|
639
756
|
// thinking/running aktif: bangun segar (jarang — hanya saat turn berjalan,
|
|
640
757
|
// dan repaint-nya sudah dicoalesce 30ms, bukan per-keypress).
|
|
641
758
|
const rows: TranscriptRow[] = [...this.committedRows(w), ...this.pendingRows(w)]
|
|
642
|
-
if (this.thinkingTail) {
|
|
759
|
+
if (!this.thinkingAreaMode() && this.thinkingTail) {
|
|
643
760
|
for (const chunk of this.thinkingTail.split("\n")) {
|
|
644
761
|
const chunkRows = chunk === "" ? [""] : wrapByWidth(chunk, w)
|
|
645
762
|
for (const row of chunkRows) {
|
|
@@ -655,6 +772,12 @@ export class Transcript {
|
|
|
655
772
|
}
|
|
656
773
|
}
|
|
657
774
|
}
|
|
775
|
+
// Area thinking (Fase 3): blok live maks 10 baris terakhir (mode area).
|
|
776
|
+
// Mode legacy sudah menaruh thinking-nya di atas (stream per baris).
|
|
777
|
+
rows.push(...thinking)
|
|
778
|
+
// Baris tool yang SEDANG berjalan (dari snapshot). Panel aktivitas hanya
|
|
779
|
+
// memuat tool TERMINAL (fold), jadi running tetap punya barisnya sendiri —
|
|
780
|
+
// tak ada duplikasi, dan tool yang belum selesai tidak pernah hilang.
|
|
658
781
|
for (const row of running) {
|
|
659
782
|
rows.push({
|
|
660
783
|
text: row,
|
|
@@ -666,6 +789,9 @@ export class Transcript {
|
|
|
666
789
|
selectable: false,
|
|
667
790
|
})
|
|
668
791
|
}
|
|
792
|
+
// Panel aktivitas (Fase 2): baris grup tool terminal — tampil di bawah
|
|
793
|
+
// running, di atas transkrip. Hanya saat ada activity.
|
|
794
|
+
rows.push(...panel)
|
|
669
795
|
return rows
|
|
670
796
|
}
|
|
671
797
|
|
|
@@ -726,13 +852,28 @@ export class Transcript {
|
|
|
726
852
|
return rows
|
|
727
853
|
}
|
|
728
854
|
|
|
855
|
+
/**
|
|
856
|
+
* Memo proyeksi baris pending, dikunci isi baris (bukan indeks).
|
|
857
|
+
*
|
|
858
|
+
* Cache `pendingProjection` lama hanya valid per `pendingVersion`, dan versi
|
|
859
|
+
* itu naik SETIAP delta — jadi tiap paint memproyeksikan ulang seluruh
|
|
860
|
+
* jawaban. Biayanya O(pending) per frame → total O(n²) per turn (audit
|
|
861
|
+
* 2026-11-12, CRITICAL-1): terukur 295 ms/frame pada 200 KB dan 1,4 dtk/
|
|
862
|
+
* frame pada batas 1 MB. Mayoritas baris saat streaming sudah final, jadi
|
|
863
|
+
* proyeksi per baris dimemo: yang tumbuh hanya baris terakhir.
|
|
864
|
+
*
|
|
865
|
+
* Dikunci juga `w` dan fenceState karena keduanya mengubah hasil proyeksi.
|
|
866
|
+
* Baris sangat panjang tidak dimemo (kuncinya akan sebesar barisnya sendiri).
|
|
867
|
+
*/
|
|
868
|
+
private pendingRowMemo = new Map<string, TranscriptRow[]>()
|
|
869
|
+
|
|
729
870
|
/** Proyeksi `pending` (jawaban streaming) + marker truncasi. Di-cache per
|
|
730
|
-
* (width, pendingVersion, truncated)
|
|
731
|
-
*
|
|
732
|
-
* mengalir (O(pending) per frame). pendingVersion naik di stream/commit/clear. */
|
|
871
|
+
* (width, pendingVersion, truncated) untuk hasil total; proyeksi per baris
|
|
872
|
+
* dimemo terpisah agar delta baru tidak memaksa kerja ulang penuh. */
|
|
733
873
|
private pendingRows(w: number): TranscriptRow[] {
|
|
734
874
|
if (!this.pending) {
|
|
735
875
|
this.pendingProjection = null
|
|
876
|
+
this.pendingRowMemo.clear()
|
|
736
877
|
return []
|
|
737
878
|
}
|
|
738
879
|
if (
|
|
@@ -751,8 +892,23 @@ export class Transcript {
|
|
|
751
892
|
if (block.type === "table") rows.push(...this.projectTable(block.table, -1, w))
|
|
752
893
|
else
|
|
753
894
|
for (const line of block.text.split("\n")) {
|
|
895
|
+
const fenceState = pendingFence(line)
|
|
896
|
+
const memoKey =
|
|
897
|
+
line.length <= PENDING_MEMO_LINE_MAX ? `${w}\u0000${fenceState}\u0000${line}` : null
|
|
898
|
+
const memo = memoKey === null ? undefined : this.pendingRowMemo.get(memoKey)
|
|
899
|
+
if (memo) {
|
|
900
|
+
rows.push(...memo)
|
|
901
|
+
continue
|
|
902
|
+
}
|
|
754
903
|
const clean = stripSgr(sanitizeAnsi(line))
|
|
755
|
-
|
|
904
|
+
const produced = this.projectText(line, clean, -1, w, false, "", true, fenceState)
|
|
905
|
+
if (memoKey !== null) {
|
|
906
|
+
// Batas sederhana: memo adalah cache tampilan, bukan struktur
|
|
907
|
+
// data — dibuang seluruhnya saat terlalu besar.
|
|
908
|
+
if (this.pendingRowMemo.size >= PENDING_MEMO_MAX_ENTRIES) this.pendingRowMemo.clear()
|
|
909
|
+
this.pendingRowMemo.set(memoKey, produced)
|
|
910
|
+
}
|
|
911
|
+
rows.push(...produced)
|
|
756
912
|
}
|
|
757
913
|
}
|
|
758
914
|
}
|
|
@@ -975,9 +1131,11 @@ export class Transcript {
|
|
|
975
1131
|
if (event.type === "turn.completed") {
|
|
976
1132
|
this.commit()
|
|
977
1133
|
this.commitThinking()
|
|
978
|
-
// minimizeActivity ON → fold meringkas sendiri (nama
|
|
979
|
-
// turnSummary (turn · files · durasi) dilewati agar
|
|
980
|
-
|
|
1134
|
+
// minimizeActivity ON / activityPanel ON → fold meringkas sendiri (nama
|
|
1135
|
+
// tool + ok/gagal); turnSummary (turn · files · durasi) dilewati agar
|
|
1136
|
+
// tidak ada dua ringkasan.
|
|
1137
|
+
if (!this.uiState.minimizeActivity && !this.uiState.activityPanel)
|
|
1138
|
+
this.turnSummary(event.summary, event)
|
|
981
1139
|
this.flushActivityFold()
|
|
982
1140
|
return
|
|
983
1141
|
}
|
|
@@ -1097,11 +1255,12 @@ export class Transcript {
|
|
|
1097
1255
|
: denyReason
|
|
1098
1256
|
? `: ${truncateToWidth(sanitizeAnsi(denyReason), 200, "…").split("\n")[0] ?? ""}`
|
|
1099
1257
|
: ""
|
|
1100
|
-
const line = ` ${
|
|
1101
|
-
// Lipat aktivitas (opencode-like): saat minimizeActivity
|
|
1102
|
-
// per-tool TIDAK boleh menghilang diam-diam
|
|
1103
|
-
//
|
|
1104
|
-
|
|
1258
|
+
const line = ` ${name}${targetText} ${statusWord(status)}${retry}${child}${verificationMark}${provenanceMark}${message}`
|
|
1259
|
+
// Lipat aktivitas (opencode-like): saat minimizeActivity ATAU panel
|
|
1260
|
+
// aktivitas aktif, baris ledger per-tool TIDAK boleh menghilang diam-diam
|
|
1261
|
+
// — ditahan lalu dirangkum saat turn selesai (panel: per keluarga tool;
|
|
1262
|
+
// minimize: satu baris nama+hitungan). Detail via /expand.
|
|
1263
|
+
if (this.uiState.minimizeActivity || this.uiState.activityPanel) {
|
|
1105
1264
|
this.activityFold.push({ name, status, line })
|
|
1106
1265
|
return
|
|
1107
1266
|
}
|
|
@@ -1154,7 +1313,7 @@ export class Transcript {
|
|
|
1154
1313
|
const targetText = target ? ` ${truncateToWidth(sanitizeAnsiLine(target), 120, "")}` : ""
|
|
1155
1314
|
const line =
|
|
1156
1315
|
verification.verdict === "present"
|
|
1157
|
-
? ` ${
|
|
1316
|
+
? ` ${name}${targetText} verified`
|
|
1158
1317
|
: ` ? ${name}${targetText} unverified (${verification.verdict})`
|
|
1159
1318
|
this.append(
|
|
1160
1319
|
verification.verdict === "present" ? paintLedger("completed", line) : c.muted(line),
|
|
@@ -1314,11 +1473,29 @@ export class Transcript {
|
|
|
1314
1473
|
|
|
1315
1474
|
/** Flush lipatan aktivitas (minimizeActivity) menjadi SATU baris ringkas
|
|
1316
1475
|
* (opencode-like) + buffer detail untuk /expand. Tidak menghilangkan isi
|
|
1317
|
-
* diam-diam: nama tool + hitung ok/gagal tetap terlihat.
|
|
1476
|
+
* diam-diam: nama tool + hitung ok/gagal tetap terlihat.
|
|
1477
|
+
*
|
|
1478
|
+
* Saat activityPanel ON, ringkasan memakai KELUARGA tool (satu baris per
|
|
1479
|
+
* grup — `+ explore · 3 tools · 2 ok`) alih-alih daftar nama rata.
|
|
1480
|
+
* Detail penuh tetap masuk /expand. */
|
|
1318
1481
|
private flushActivityFold(): void {
|
|
1319
1482
|
const fold = this.activityFold
|
|
1320
1483
|
this.activityFold = []
|
|
1321
1484
|
if (fold.length === 0) return
|
|
1485
|
+
// Panel ON: render per-grup (sumber: event tool yang sudah dikumpulkan).
|
|
1486
|
+
if (this.uiState.activityPanel) {
|
|
1487
|
+
const activities = fold.map((e) => ({
|
|
1488
|
+
toolCallId: "",
|
|
1489
|
+
name: e.name,
|
|
1490
|
+
status: e.status as UiToolStatus,
|
|
1491
|
+
tsStart: 0,
|
|
1492
|
+
}))
|
|
1493
|
+
const lines = renderActivityPanel(activities, { maxRows: 10 })
|
|
1494
|
+
if (lines.length === 0) return
|
|
1495
|
+
this.uiState.rememberCollapsedSection("activity", fold.map((e) => e.line).join("\n"))
|
|
1496
|
+
for (const line of lines) this.append(line, { kind: "activity" })
|
|
1497
|
+
return
|
|
1498
|
+
}
|
|
1322
1499
|
const count = (status: string) => fold.reduce((n, e) => n + (e.status === status ? 1 : 0), 0)
|
|
1323
1500
|
const ok = count("completed")
|
|
1324
1501
|
const failed = count("failed")
|
|
@@ -7,6 +7,13 @@ import type { ModelProvider, ProviderEvent, StreamRequest } from "../core/provid
|
|
|
7
7
|
import type { ToolSchema } from "../core/tool.ts";
|
|
8
8
|
import type { Content, Message } from "../core/types.ts";
|
|
9
9
|
|
|
10
|
+
// HOST seam (F2): byte bounds SSE — sejajar LIMITS.PROVIDER_SSE_FRAME_MAX_BYTES
|
|
11
|
+
// (16MB) dan LIMITS.PROVIDER_SSE_TOTAL_MAX_BYTES (64MB) di sisi host. Vendor
|
|
12
|
+
// self-contained, tak impor src/; nilai diduplikasi sengaja (single source di
|
|
13
|
+
// host tetap src/constants.ts — ini salinan wire-level).
|
|
14
|
+
const MAX_FRAME_BYTES = 16_777_216;
|
|
15
|
+
const MAX_TOTAL_BYTES = 67_108_864;
|
|
16
|
+
|
|
10
17
|
// Provider-metadata side-map: toolCallId -> extra provider payload (e.g.
|
|
11
18
|
// Gemini thought_signature / extra_content). It must NOT travel inside
|
|
12
19
|
// `args` — the executor rejects unknown properties (all schemas are
|
|
@@ -352,16 +359,31 @@ async function* sse(body: ReadableStream<Uint8Array>, signal: AbortSignal): Asyn
|
|
|
352
359
|
const reader = body.getReader();
|
|
353
360
|
const decoder = new TextDecoder();
|
|
354
361
|
let buffer = "";
|
|
362
|
+
let totalBytes = 0;
|
|
363
|
+
let reachedEof = false;
|
|
355
364
|
try {
|
|
356
365
|
while (true) {
|
|
357
366
|
if (signal.aborted) throw new Error("AbortError");
|
|
358
367
|
const { done, value } = await reader.read();
|
|
359
|
-
if (done)
|
|
368
|
+
if (done) {
|
|
369
|
+
reachedEof = true;
|
|
370
|
+
break;
|
|
371
|
+
}
|
|
372
|
+
// HOST seam (F2): byte bounds. Sebelumnya stream menumpuk baris tanpa batas
|
|
373
|
+
// sehingga satu `data:` raksasa (upstream rusak/hostil) di-buffer + JSON.parse
|
|
374
|
+
// sebelum guard host sempat memotong event yang sudah ter-decode → OOM.
|
|
375
|
+
totalBytes += value.byteLength;
|
|
376
|
+
if (totalBytes > MAX_TOTAL_BYTES) {
|
|
377
|
+
throw new ProviderError("invalid_request", "SSE stream exceeds total byte limit");
|
|
378
|
+
}
|
|
360
379
|
buffer += decoder.decode(value, { stream: true });
|
|
361
380
|
let index: number;
|
|
362
381
|
while ((index = buffer.indexOf("\n")) >= 0) {
|
|
363
382
|
const line = buffer.slice(0, index).replace(/\r$/, "");
|
|
364
383
|
buffer = buffer.slice(index + 1);
|
|
384
|
+
if (line.length > MAX_FRAME_BYTES) {
|
|
385
|
+
throw new ProviderError("invalid_request", "SSE frame exceeds byte limit");
|
|
386
|
+
}
|
|
365
387
|
if (!line.startsWith("data:")) continue;
|
|
366
388
|
const payload = line.slice(5).trim();
|
|
367
389
|
if (payload === "[DONE]") return;
|
|
@@ -373,8 +395,15 @@ async function* sse(body: ReadableStream<Uint8Array>, signal: AbortSignal): Asyn
|
|
|
373
395
|
}
|
|
374
396
|
}
|
|
375
397
|
}
|
|
398
|
+
// Satu baris tak-berakhir yang tumbuh melebihi cap frame = runaway buffer.
|
|
399
|
+
if (buffer.length > MAX_FRAME_BYTES) {
|
|
400
|
+
throw new ProviderError("invalid_request", "SSE frame exceeds byte limit");
|
|
401
|
+
}
|
|
376
402
|
}
|
|
377
403
|
} finally {
|
|
404
|
+
// HOST seam (F2): cancel (bukan hanya releaseLock) agar exit prematur /
|
|
405
|
+
// [DONE] melepas body & koneksi, bukan membiarkannya menggantung.
|
|
406
|
+
if (!reachedEof) await reader.cancel().catch(() => {});
|
|
378
407
|
reader.releaseLock();
|
|
379
408
|
}
|
|
380
409
|
}
|