minicode-ai 0.25.0 → 0.27.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 +3 -1
- package/cli/commands/config.ts +123 -0
- package/cli/commands.ts +23 -2
- package/cli/context-command-run.ts +159 -0
- package/cli/context-command.ts +87 -0
- package/cli/index.ts +48 -0
- package/cli/setup.ts +107 -8
- package/cli/tui.ts +8 -9
- package/docs/TERMINAL_CONTRACT.md +32 -1
- package/docs/config.md +29 -1
- package/docs/environment.md +3 -1
- package/docs/getting-started.md +11 -3
- package/docs/repl.md +1 -0
- package/package.json +1 -1
- package/src/app/session.ts +187 -17
- package/src/config.ts +19 -8
- package/src/constants.ts +33 -4
- package/src/lib/net.ts +6 -15
- package/src/lib/public-http.ts +128 -0
- package/src/policy/auto-resume.ts +63 -0
- package/src/policy/compaction.ts +354 -70
- package/src/policy/context-budget.ts +4 -6
- package/src/policy/context-window-assign.ts +114 -0
- package/src/policy/context-window-catalog.ts +4 -1
- package/src/policy/context-window-presets.ts +165 -0
- package/src/policy/context-window.ts +105 -4
- package/src/policy/context.ts +27 -10
- package/src/policy/executor.ts +69 -27
- package/src/policy/microcompact.ts +76 -15
- package/src/policy/recovery-budget.ts +281 -0
- package/src/policy/step-escalation.ts +82 -0
- package/src/policy/tokenizer-registry.ts +1 -0
- package/src/providers/detect.ts +13 -7
- package/src/providers/guards.ts +41 -2
- package/src/providers/provision.ts +8 -4
- package/src/repo/repomap.ts +180 -23
- package/src/runtime/child-execution.ts +4 -2
- package/src/runtime/execution-backend.ts +3 -0
- package/src/sandbox/os.ts +53 -9
- package/src/session/context-assembly.ts +11 -7
- package/src/session/persistence.ts +19 -3
- package/src/tools/bash.ts +12 -9
- package/src/tools/code_run.ts +19 -20
- package/src/tools/task.ts +4 -1
- package/src/tools/web_fetch.ts +13 -19
- package/src/ui/assistant/simple.ts +61 -10
- package/src/ui/i18n/en.ts +15 -0
- package/src/ui/i18n/id.ts +15 -0
- package/src/ui/input/prompt-engine.ts +53 -21
- package/src/ui/render/activity-group.ts +8 -0
- package/src/ui/render/activity-panel.ts +20 -2
- package/src/ui/screens/model-manager.ts +6 -1
- package/src/ui/tui/app.ts +26 -11
- package/src/ui/tui/transcript.ts +175 -29
- package/vendor/minicore/src/core/loop.ts +20 -1
- package/vendor/minicore/src/core/session.ts +6 -0
package/src/tools/web_fetch.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Tool } from "#minicore"
|
|
2
2
|
import { LIMITS } from "../constants.ts"
|
|
3
|
-
import {
|
|
3
|
+
import { isPrivateHost } from "../lib/net.ts"
|
|
4
|
+
import { publicHttp } from "../lib/public-http.ts"
|
|
4
5
|
import { fenceUntrustedToolOutput, isAlreadyFenced, scrubSecrets } from "../policy/scrub.ts"
|
|
5
6
|
|
|
6
7
|
const MAX_REDIRECTS = LIMITS.WEB_FETCH_MAX_REDIRECTS
|
|
@@ -92,6 +93,10 @@ export const webFetchTool: Tool = {
|
|
|
92
93
|
throw new Error(`invalid url: ${u}`)
|
|
93
94
|
}
|
|
94
95
|
|
|
96
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
97
|
+
throw new Error(`disallowed protocol: ${parsed.protocol}`)
|
|
98
|
+
}
|
|
99
|
+
|
|
95
100
|
// Default 8000 (bukan 20000): hasil web rakus konteks — satu fetch `README`
|
|
96
101
|
// /halaman GitHub bisa 17 KB yang menggelembungkan jendela konteks hingga
|
|
97
102
|
// melampaui batas model. 8000 tetap cukup utk membaca section, jauh lebih
|
|
@@ -106,18 +111,11 @@ export const webFetchTool: Tool = {
|
|
|
106
111
|
if (ctx.signal.aborted) controller.abort(ctx.signal.reason)
|
|
107
112
|
|
|
108
113
|
try {
|
|
109
|
-
//
|
|
110
|
-
//
|
|
111
|
-
// yang mengandalkan cache basi. SISA RESIDUAL jujur (audit 2026-09-16
|
|
112
|
-
// B6): validasi-lalu-fetch = check-then-connect; resolver OS bisa
|
|
113
|
-
// mengembalikan IP berbeda saat connect dibanding saat cek. Menutupnya
|
|
114
|
-
// butuh pin-IP di level socket (di luar API fetch) — ditunda sadar,
|
|
115
|
-
// bukan diklaim tertutup.
|
|
114
|
+
// Each redirect uses a fresh validated DNS answer pinned to socket lookup.
|
|
115
|
+
// Host/SNI remain bound to the original hostname, not the selected address.
|
|
116
116
|
let current = parsed
|
|
117
|
-
//
|
|
118
|
-
|
|
119
|
-
// redirect harus resolve ulang, bukan memakai cache basi.
|
|
120
|
-
if (await isPrivateHostWithDns(current.hostname, { noCache: true })) {
|
|
117
|
+
// Every hop resolves independently; validated addresses are never reused across redirects.
|
|
118
|
+
if (isPrivateHost(current.hostname)) {
|
|
121
119
|
throw new Error(`blocked private host: ${current.hostname}`)
|
|
122
120
|
}
|
|
123
121
|
const headers = {
|
|
@@ -126,12 +124,9 @@ export const webFetchTool: Tool = {
|
|
|
126
124
|
}
|
|
127
125
|
let res: Response | undefined
|
|
128
126
|
for (let hop = 0; hop <= MAX_REDIRECTS; hop++) {
|
|
129
|
-
res = await fetch(current.
|
|
130
|
-
signal: controller.signal,
|
|
131
|
-
headers,
|
|
132
|
-
redirect: "manual",
|
|
133
|
-
})
|
|
127
|
+
res = await publicHttp.fetch(current, { signal: controller.signal, headers })
|
|
134
128
|
if (res.status < 300 || res.status >= 400) break
|
|
129
|
+
void res.body?.cancel().catch(() => {})
|
|
135
130
|
const loc = res.headers.get("location")
|
|
136
131
|
if (!loc) break
|
|
137
132
|
let next: URL
|
|
@@ -143,11 +138,10 @@ export const webFetchTool: Tool = {
|
|
|
143
138
|
if (next.protocol !== "http:" && next.protocol !== "https:") {
|
|
144
139
|
throw new Error(`redirect to disallowed protocol: ${next.protocol}`)
|
|
145
140
|
}
|
|
146
|
-
if (
|
|
141
|
+
if (isPrivateHost(next.hostname)) {
|
|
147
142
|
throw new Error(`blocked private host (redirect target): ${next.hostname}`)
|
|
148
143
|
}
|
|
149
144
|
current = next
|
|
150
|
-
void res.body?.cancel().catch(() => {})
|
|
151
145
|
}
|
|
152
146
|
if (!res) throw new Error("unreachable")
|
|
153
147
|
if (res.status >= 300 && res.status < 400) {
|
|
@@ -176,6 +176,19 @@ function patchBlocks(patches: unknown): [string, string] {
|
|
|
176
176
|
return [list.map((p) => p.search ?? "").join("\n"), list.map((p) => p.replace ?? "").join("\n")]
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
+
/** Tool yang baris `execution:completed`-nya sudah mencetak chevron + nama +
|
|
180
|
+
* target dengan bentuk sama seperti baris `execution:started`. Baris start
|
|
181
|
+
* dilewati untuk tool ini agar tidak tercetak duplikat.
|
|
182
|
+
*
|
|
183
|
+
* Sengaja daftar EKSPLISIT, bukan "semua tool": tool yang baris hasilnya tidak
|
|
184
|
+
* berbentuk chevron+nama+target tetap butuh baris start sebagai satu-satunya
|
|
185
|
+
* penanda "sedang berjalan". */
|
|
186
|
+
function toolPrintsOwnCompletionLine(name: string, args: Record<string, unknown>): boolean {
|
|
187
|
+
if (name === "read_file" || name === "write_file") return typeof args.path === "string"
|
|
188
|
+
if (name === "edit_file" || name === "multi_edit_file") return typeof args.path === "string"
|
|
189
|
+
return false
|
|
190
|
+
}
|
|
191
|
+
|
|
179
192
|
export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () => void {
|
|
180
193
|
// Shadow module-level wOut/wErr: saat quiet, paint ditekan tapi SEMUA state
|
|
181
194
|
// (rememberTurn, rememberCollapsedSection, pendingError, sanitizer) tetap jalan.
|
|
@@ -385,8 +398,22 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
|
|
|
385
398
|
emitAnswer(`${rendered}\n`)
|
|
386
399
|
}
|
|
387
400
|
}
|
|
388
|
-
|
|
389
|
-
|
|
401
|
+
/**
|
|
402
|
+
* Selesaikan teks yang tertahan.
|
|
403
|
+
*
|
|
404
|
+
* `includePartial = false` dipakai saat menyisipkan baris ledger di TENGAH
|
|
405
|
+
* stream. `tableStream.flush()` mengeluarkan `lineBuffer` parsial sebagai
|
|
406
|
+
* baris utuh, sehingga satu baris markdown terpotong di titik event datang
|
|
407
|
+
* dan tiap potongan dibungkus ulang sendiri ("export const" / "multiply =" /
|
|
408
|
+
* "(a: number)" = gejala output pipa terfragmentasi).
|
|
409
|
+
* Tanpa itu, baris parsial tetap tertahan di `tableStream` sampai `
|
|
410
|
+
`
|
|
411
|
+
* berikutnya tiba — urutan teks akhir tidak berubah.
|
|
412
|
+
* Default `true` untuk batas turn/teardown, di mana sisa parsial memang
|
|
413
|
+
* harus dicetak agar tidak hilang diam-diam.
|
|
414
|
+
*/
|
|
415
|
+
const flushTableStream = (includePartial = true): void => {
|
|
416
|
+
if (includePartial) consumeTableEvents(tableStream.flush())
|
|
390
417
|
if (plainLineBuffer) {
|
|
391
418
|
flushLine(plainLineBuffer)
|
|
392
419
|
plainLineBuffer = ""
|
|
@@ -442,9 +469,25 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
|
|
|
442
469
|
if (provenance === "replay" || provenance === "reconstructed") parts.push(provenance)
|
|
443
470
|
return parts.length > 0 ? ` ${c.muted(`[${parts.join(" · ")}]`)}` : ""
|
|
444
471
|
}
|
|
472
|
+
/** Tulis satu baris ledger (status/verifikasi/cutoff) di tengah stream teks.
|
|
473
|
+
* `flushTableStream(false)` memaksa baris yang sudah lengkap keluar lebih
|
|
474
|
+
* dulu agar urutan baris benar, TANPA memotong baris yang belum selesai. */
|
|
475
|
+
const emitLedger = (line: string): void => {
|
|
476
|
+
// `false`: jangan keluarkan baris teks yang belum selesai.
|
|
477
|
+
flushTableStream(false)
|
|
478
|
+
wErr(line)
|
|
479
|
+
}
|
|
480
|
+
|
|
445
481
|
const writePresentationTerminal = (event: UiPresentationEvent): void => {
|
|
446
482
|
if (!presentationEnabled) return
|
|
447
|
-
flushTableStream()
|
|
483
|
+
// JANGAN flush di sini. `flushTableStream()` mengeluarkan `lineBuffer`
|
|
484
|
+
// parsial sebagai baris UTUH; dipanggil pada setiap presentation event
|
|
485
|
+
// (status task, clock, verifikasi, consequence) yang datang di tengah
|
|
486
|
+
// stream teks, ia memecah satu baris markdown menjadi potongan-potongan
|
|
487
|
+
// dan masing-masing dibungkus ulang sendiri — gejala "output pipa
|
|
488
|
+
// terfragmentasi" (satu baris kode jadi 3-4 baris acak).
|
|
489
|
+
// Flush hanya perlu tepat SEBELUM sebuah baris ledger ditulis, jadi
|
|
490
|
+
// ditangani oleh `ledgerLine` di bawah.
|
|
448
491
|
// F-TASK-1: status task kanonik juga punya baris ledger di jalur linear
|
|
449
492
|
// (scrollback non-TTY). Sebelum ini event hanya hidup di TUI + machine
|
|
450
493
|
// envelope — pengguna `minicode exec`/pipe tak pernah melihatnya.
|
|
@@ -476,7 +519,7 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
|
|
|
476
519
|
: raw === "COMPLETED"
|
|
477
520
|
? c.success(line)
|
|
478
521
|
: c.muted(line)
|
|
479
|
-
|
|
522
|
+
emitLedger(`${paint}\n`)
|
|
480
523
|
return
|
|
481
524
|
}
|
|
482
525
|
// Observasi verifikasi punya baris sendiri (dedup per invocation):
|
|
@@ -496,7 +539,7 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
|
|
|
496
539
|
verification.verdict === "present"
|
|
497
540
|
? ` ${glyphs.arrow} ${name}${targetText} verified`
|
|
498
541
|
: ` ? ${name}${targetText} unverified (${verification.verdict})`
|
|
499
|
-
|
|
542
|
+
emitLedger(`${verification.verdict === "present" ? c.success(line) : c.muted(line)}\n`)
|
|
500
543
|
return
|
|
501
544
|
}
|
|
502
545
|
// P1.5: consequence/context diagnostics juga tampil di scrollback linear.
|
|
@@ -516,12 +559,12 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
|
|
|
516
559
|
: verdict === "PASS"
|
|
517
560
|
? c.success(line)
|
|
518
561
|
: c.warning(line)
|
|
519
|
-
|
|
562
|
+
emitLedger(`${paint}\n`)
|
|
520
563
|
return
|
|
521
564
|
}
|
|
522
565
|
if (event.type === "context.cutoff") {
|
|
523
566
|
const reason = event.reason ? `: ${sanitizeAnsiLine(String(event.reason))}` : ""
|
|
524
|
-
|
|
567
|
+
emitLedger(`${c.warning(` ${glyphs.bullet} context cutoff${reason}`)}\n`)
|
|
525
568
|
return
|
|
526
569
|
}
|
|
527
570
|
if (event.type === "context.window") {
|
|
@@ -532,7 +575,7 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
|
|
|
532
575
|
used != null
|
|
533
576
|
? ` ${used.toLocaleString()}${window ? `/${window.toLocaleString()}` : ""} tokens`
|
|
534
577
|
: ""
|
|
535
|
-
|
|
578
|
+
emitLedger(`${c.muted(` ${glyphs.bullet} context window${tokens}${pct}`)}\n`)
|
|
536
579
|
return
|
|
537
580
|
}
|
|
538
581
|
if (
|
|
@@ -563,7 +606,7 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
|
|
|
563
606
|
const marker = runMarker(activity)
|
|
564
607
|
const prefix = isChild ? ` ↳ ${marker ? `${marker} ` : ""}` : ` ${glyphs.arrow} `
|
|
565
608
|
const line = `${prefix}${name}${targetText}${linearSuffix(activity)}${detail}`
|
|
566
|
-
|
|
609
|
+
emitLedger(paintLedger(status, `${line}\n`))
|
|
567
610
|
}
|
|
568
611
|
|
|
569
612
|
const offs: (() => void)[] = []
|
|
@@ -812,10 +855,18 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
|
|
|
812
855
|
}
|
|
813
856
|
// Expanded: user melihat tool apa yang mulai berjalan SEBELUM hasilnya,
|
|
814
857
|
// inline di aliran output — transparansi ala shell (`set -x`).
|
|
858
|
+
//
|
|
859
|
+
// KECUALI tool yang `execution:completed`-nya sudah mencetak baris dengan
|
|
860
|
+
// bentuk sama (chevron + nama + target). Dulu keduanya aktif bersamaan,
|
|
861
|
+
// sehingga satu `read_file` tampil dua kali berturut-turut persis sama.
|
|
862
|
+
// Baris hasil lebih kaya (membawa suffix durasi/status), jadi yang
|
|
863
|
+
// dibuang adalah baris start.
|
|
864
|
+
const startName = e.execution.call.name
|
|
815
865
|
const args = (e.execution.call.args ?? {}) as Record<string, unknown>
|
|
866
|
+
if (toolPrintsOwnCompletionLine(startName, args)) return
|
|
816
867
|
wErr(
|
|
817
868
|
c.muted(
|
|
818
|
-
` ${glyphs.arrow} ${sanitizeAnsiLine(
|
|
869
|
+
` ${glyphs.arrow} ${sanitizeAnsiLine(startName)} ${sanitizeAnsiLine(formatArgsPreview(args))}\n`,
|
|
819
870
|
),
|
|
820
871
|
)
|
|
821
872
|
}),
|
package/src/ui/i18n/en.ts
CHANGED
|
@@ -80,6 +80,7 @@ export const en = {
|
|
|
80
80
|
"model.failOpen": "model manager failed to open: {msg}",
|
|
81
81
|
"effort.title": "Thinking effort",
|
|
82
82
|
"effort.saved": "Thinking effort: {effort} (next session)",
|
|
83
|
+
"effort.noThinking": "this model has no thinking effort — nothing to set",
|
|
83
84
|
"prov.empty": "No providers",
|
|
84
85
|
"prov.addTitle": "Add provider",
|
|
85
86
|
"prov.customUrl": "Custom URL",
|
|
@@ -131,6 +132,17 @@ export const en = {
|
|
|
131
132
|
"st.workMode": " WorkMode: {v} (intent layer)",
|
|
132
133
|
"st.permissionMode": " Permission: {v} (allow/deny authority)",
|
|
133
134
|
"st.context": " Context: ~{v} tok (window estimate)",
|
|
135
|
+
"help.desc.context": "Show or set the context window",
|
|
136
|
+
"ctx.title": "Context window",
|
|
137
|
+
"ctx.colModel": "Model",
|
|
138
|
+
"ctx.colWindow": "Window",
|
|
139
|
+
"ctx.colOrigin": "Origin",
|
|
140
|
+
"ctx.empty": "no models configured — add a provider first",
|
|
141
|
+
"ctx.pickTitle": "Context window — effective {label} ({origin})",
|
|
142
|
+
"ctx.saved": "saved: {label} ({tokens} tokens) for the next turn",
|
|
143
|
+
"ctx.savedAuto": "back to automatic detection",
|
|
144
|
+
"ctx.saveFailed": "could not save the window: {msg}",
|
|
145
|
+
"ctx.usage": " /context <128k|1m|1024x1024|auto> -> set for the active model",
|
|
134
146
|
"st.turn": " Turn: {v} (last turn only)",
|
|
135
147
|
"st.input": " Input: {v} (provider usage)",
|
|
136
148
|
"st.output": " Output: {v} (provider usage)",
|
|
@@ -346,6 +358,9 @@ export const en = {
|
|
|
346
358
|
"panel.tools": "{n} tools",
|
|
347
359
|
"panel.ok": "{n} ok",
|
|
348
360
|
"panel.failed": "{n} failed",
|
|
361
|
+
"panel.denied": "{n} denied",
|
|
362
|
+
"panel.cancelled": "{n} cancelled",
|
|
363
|
+
"panel.interrupted": "{n} interrupted",
|
|
349
364
|
"panel.running": "{n} running",
|
|
350
365
|
"panel.thinking": "thinking",
|
|
351
366
|
"panel.lines": "{n} lines",
|
package/src/ui/i18n/id.ts
CHANGED
|
@@ -83,6 +83,7 @@ export const id: Record<MsgKey, string> = {
|
|
|
83
83
|
"model.failOpen": "model manager gagal dibuka: {msg}",
|
|
84
84
|
"effort.title": "Upaya berpikir",
|
|
85
85
|
"effort.saved": "Upaya berpikir: {effort} (sesi berikut)",
|
|
86
|
+
"effort.noThinking": "model ini tidak punya upaya berpikir — tidak ada yang bisa diatur",
|
|
86
87
|
"prov.empty": "Belum ada penyedia",
|
|
87
88
|
"prov.addTitle": "Tambah penyedia",
|
|
88
89
|
"prov.customUrl": "URL kustom",
|
|
@@ -134,6 +135,17 @@ export const id: Record<MsgKey, string> = {
|
|
|
134
135
|
"st.workMode": " WorkMode: {v} (lapis intent)",
|
|
135
136
|
"st.permissionMode": " Izin: {v} (otoritas allow/deny)",
|
|
136
137
|
"st.context": " Konteks: ~{v} tok (estimasi jendela)",
|
|
138
|
+
"help.desc.context": "Lihat atau atur jendela konteks",
|
|
139
|
+
"ctx.title": "Jendela konteks",
|
|
140
|
+
"ctx.colModel": "Model",
|
|
141
|
+
"ctx.colWindow": "Jendela",
|
|
142
|
+
"ctx.colOrigin": "Asal",
|
|
143
|
+
"ctx.empty": "belum ada model — tambahkan penyedia dulu",
|
|
144
|
+
"ctx.pickTitle": "Jendela konteks — efektif {label} ({origin})",
|
|
145
|
+
"ctx.saved": "tersimpan: {label} ({tokens} token) untuk turn berikutnya",
|
|
146
|
+
"ctx.savedAuto": "kembali ke deteksi otomatis",
|
|
147
|
+
"ctx.saveFailed": "gagal menyimpan jendela: {msg}",
|
|
148
|
+
"ctx.usage": " /context <128k|1m|1024x1024|auto> -> setel untuk model aktif",
|
|
137
149
|
"st.turn": " Turn: {v} (turn terakhir saja)",
|
|
138
150
|
"st.input": " Masukan: {v} (pemakaian provider)",
|
|
139
151
|
"st.output": " Keluaran: {v} (pemakaian provider)",
|
|
@@ -350,6 +362,9 @@ export const id: Record<MsgKey, string> = {
|
|
|
350
362
|
"panel.tools": "{n} tool",
|
|
351
363
|
"panel.ok": "{n} sukses",
|
|
352
364
|
"panel.failed": "{n} gagal",
|
|
365
|
+
"panel.denied": "{n} ditolak",
|
|
366
|
+
"panel.cancelled": "{n} dibatalkan",
|
|
367
|
+
"panel.interrupted": "{n} terhenti",
|
|
353
368
|
"panel.running": "{n} berjalan",
|
|
354
369
|
"panel.thinking": "berpikir",
|
|
355
370
|
"panel.lines": "{n} baris",
|
|
@@ -403,12 +403,17 @@ export interface DecodedKey {
|
|
|
403
403
|
export interface DecoderState {
|
|
404
404
|
/** Byte yang belum lengkap jadi satu key (tail dari chunk sebelumnya). */
|
|
405
405
|
pending: number[]
|
|
406
|
+
/** Overlong sequences retain only their termination rule, never their payload. */
|
|
407
|
+
discard?: "csi" | "sgr"
|
|
406
408
|
}
|
|
407
409
|
|
|
408
410
|
export function createDecoderState(): DecoderState {
|
|
409
411
|
return { pending: [] }
|
|
410
412
|
}
|
|
411
413
|
|
|
414
|
+
// Bound incomplete control sequences independently of bracketed paste payloads.
|
|
415
|
+
const MAX_CONTROL_SEQUENCE_BYTES = 64
|
|
416
|
+
|
|
412
417
|
function isCsiParam(b: number): boolean {
|
|
413
418
|
return b >= 0x30 && b <= 0x3f
|
|
414
419
|
}
|
|
@@ -480,6 +485,17 @@ export function decodeKeysStream(chunk: Uint8Array, state: DecoderState): Decode
|
|
|
480
485
|
let i = 0
|
|
481
486
|
while (i < buf.length) {
|
|
482
487
|
const b = buf[i]!
|
|
488
|
+
if (state.discard) {
|
|
489
|
+
if (b < 0x20 || b >= 0x7f) {
|
|
490
|
+
// Recover at an independent byte without consuming it (including ESC).
|
|
491
|
+
state.discard = undefined
|
|
492
|
+
} else {
|
|
493
|
+
const final = state.discard === "sgr" ? b === 0x4d || b === 0x6d : isCsiFinal(b)
|
|
494
|
+
if (final) state.discard = undefined
|
|
495
|
+
i++
|
|
496
|
+
continue
|
|
497
|
+
}
|
|
498
|
+
}
|
|
483
499
|
if (b === 0x1b) {
|
|
484
500
|
const n1 = buf[i + 1]
|
|
485
501
|
// ESC di ujung chunk = awal sekuens yang terbelah (panah ESC[A jadi
|
|
@@ -531,13 +547,26 @@ export function decodeKeysStream(chunk: Uint8Array, state: DecoderState): Decode
|
|
|
531
547
|
}
|
|
532
548
|
if (n1 === 0x5b && buf[i + 2] === 0x3c) {
|
|
533
549
|
let j = i + 3
|
|
534
|
-
while (
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
550
|
+
while (
|
|
551
|
+
j < buf.length &&
|
|
552
|
+
j - i < MAX_CONTROL_SEQUENCE_BYTES &&
|
|
553
|
+
buf[j]! >= 0x20 &&
|
|
554
|
+
buf[j]! < 0x7f &&
|
|
555
|
+
buf[j] !== 0x4d &&
|
|
556
|
+
buf[j] !== 0x6d
|
|
557
|
+
) {
|
|
558
|
+
j++
|
|
559
|
+
}
|
|
560
|
+
if (
|
|
561
|
+
j - i >= MAX_CONTROL_SEQUENCE_BYTES ||
|
|
562
|
+
(j < buf.length && (buf[j]! < 0x20 || buf[j]! >= 0x7f))
|
|
563
|
+
) {
|
|
564
|
+
if (j - i >= MAX_CONTROL_SEQUENCE_BYTES) state.discard = "sgr"
|
|
565
|
+
out.push({ key: { type: "ignore" }, width: j - i })
|
|
566
|
+
i = j
|
|
539
567
|
continue
|
|
540
568
|
}
|
|
569
|
+
if (j >= buf.length) break
|
|
541
570
|
const first = buf.indexOf(0x3b, i + 3)
|
|
542
571
|
const second = first >= 0 ? buf.indexOf(0x3b, first + 1) : -1
|
|
543
572
|
const valid =
|
|
@@ -561,11 +590,18 @@ export function decodeKeysStream(chunk: Uint8Array, state: DecoderState): Decode
|
|
|
561
590
|
let j = i + 2
|
|
562
591
|
while (
|
|
563
592
|
j < buf.length &&
|
|
593
|
+
j - i < MAX_CONTROL_SEQUENCE_BYTES &&
|
|
564
594
|
!isCsiFinal(buf[j]!) &&
|
|
565
595
|
(isCsiParam(buf[j]!) || (buf[j]! >= 0x20 && buf[j]! <= 0x2f))
|
|
566
596
|
) {
|
|
567
597
|
j++
|
|
568
598
|
}
|
|
599
|
+
if (j - i >= MAX_CONTROL_SEQUENCE_BYTES) {
|
|
600
|
+
state.discard = "csi"
|
|
601
|
+
out.push({ key: { type: "ignore" }, width: j - i })
|
|
602
|
+
i = j
|
|
603
|
+
continue
|
|
604
|
+
}
|
|
569
605
|
if (j < buf.length && isCsiFinal(buf[j]!)) {
|
|
570
606
|
const seq = String.fromCharCode(...buf.slice(i, j + 1))
|
|
571
607
|
const d = decodeKey(seq, 0)
|
|
@@ -573,14 +609,12 @@ export function decodeKeysStream(chunk: Uint8Array, state: DecoderState): Decode
|
|
|
573
609
|
i = j + 1
|
|
574
610
|
continue
|
|
575
611
|
}
|
|
576
|
-
if (j ===
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
}
|
|
583
|
-
break // ada parameter tapi belum ada byte final — tahan
|
|
612
|
+
if (j === buf.length) break // Valid incomplete prefix: wait for the next chunk.
|
|
613
|
+
// Drop only the malformed prefix; decode the independent byte next
|
|
614
|
+
// (especially Ctrl+C, Enter, or ESC starting a fresh sequence).
|
|
615
|
+
out.push({ key: { type: "ignore" }, width: j - i })
|
|
616
|
+
i = j
|
|
617
|
+
continue
|
|
584
618
|
}
|
|
585
619
|
// ESC + byte lain: ESC tunggal (lengkap, tidak menunggu apa pun).
|
|
586
620
|
out.push({ key: { type: "esc" }, width: 0 })
|
|
@@ -734,8 +768,6 @@ function parseDecimalBytes(bytes: number[], from: number, to: number): number |
|
|
|
734
768
|
return value
|
|
735
769
|
}
|
|
736
770
|
|
|
737
|
-
const MAX_MOUSE_REPORT_BYTES = 64
|
|
738
|
-
|
|
739
771
|
export function decodeKey(s: string, i: number): DecodedKey | null {
|
|
740
772
|
const c = s[i]!
|
|
741
773
|
const code = c.charCodeAt(0)
|
|
@@ -796,7 +828,7 @@ export function decodeKey(s: string, i: number): DecodedKey | null {
|
|
|
796
828
|
// Dua varian sah: polos ESC[5~ (4 byte) dan bermodifier ESC[5;<m>~
|
|
797
829
|
// (modifier bisa multi-digit: 2=shift, 5=ctrl, 3=alt, kombinasi >9
|
|
798
830
|
// seperti 23). HANYA terminator '~' yang dianggap PgUp/PgDn — response
|
|
799
|
-
// DSR kursor (ESC[5;34R) dsb. harus jatuh ke catch-all
|
|
831
|
+
// DSR kursor (ESC[5;34R) dsb. harus jatuh ke catch-all ignore di bawah;
|
|
800
832
|
// tanpa guard ini, response DSR baris-5/6 dibajak jadi pageup + residu
|
|
801
833
|
// char bocor ke prompt (bug ditemukan audit typing, probe ESC[5;34R).
|
|
802
834
|
// Width dihitung dari posisi terminator — width tetap 5 membuat sisa
|
|
@@ -816,14 +848,14 @@ export function decodeKey(s: string, i: number): DecodedKey | null {
|
|
|
816
848
|
return { key: { type, modifier: mod }, width: j + 1 - i }
|
|
817
849
|
}
|
|
818
850
|
}
|
|
819
|
-
// selain itu (ESC[5;34R, ESC[5x, …) → catch-all
|
|
851
|
+
// selain itu (ESC[5;34R, ESC[5x, …) → catch-all ignore di bawah
|
|
820
852
|
}
|
|
821
853
|
// Shift+Tab (backtab) ESC [ Z — dipakai TUI untuk toggle permission mode.
|
|
822
854
|
// Tanpa cabang eksplisit ini ia jatuh ke catch-all "esc" di bawah,
|
|
823
855
|
// sehingga tipe "shift-tab" tidak pernah dihasilkan decodeKeys.
|
|
824
856
|
if (kind === "Z") return { key: { type: "shift-tab" }, width: 3 }
|
|
825
857
|
// ESC [ … lainnya -> konsumsi saja
|
|
826
|
-
return { key: { type: "
|
|
858
|
+
return { key: { type: "ignore" }, width: scanCsi(s, i) }
|
|
827
859
|
}
|
|
828
860
|
return { key: { type: "esc" }, width: 1 }
|
|
829
861
|
}
|
|
@@ -858,8 +890,8 @@ export function decodeKey(s: string, i: number): DecodedKey | null {
|
|
|
858
890
|
}
|
|
859
891
|
|
|
860
892
|
function scanCsi(s: string, i: number): number {
|
|
861
|
-
//
|
|
893
|
+
// CSI finals include punctuation such as '~', not only letters.
|
|
862
894
|
let j = i + 2
|
|
863
|
-
while (j < s.length &&
|
|
864
|
-
return j - i
|
|
895
|
+
while (j < s.length && !isCsiFinal(s.charCodeAt(j))) j++
|
|
896
|
+
return Math.min(j + 1, s.length) - i
|
|
865
897
|
}
|
|
@@ -20,6 +20,14 @@ const GROUP_BY_TOOL: Readonly<Record<string, ActivityGroupKind>> = {
|
|
|
20
20
|
lsp_diagnostics: "explore",
|
|
21
21
|
lsp_symbols: "explore",
|
|
22
22
|
lsp_workspace_symbols: "explore",
|
|
23
|
+
lsp_definition: "explore",
|
|
24
|
+
lsp_references: "explore",
|
|
25
|
+
lsp_hover: "explore",
|
|
26
|
+
todo_read: "explore",
|
|
27
|
+
todo_write: "edit",
|
|
28
|
+
bash_output: "execute",
|
|
29
|
+
bash_kill: "execute",
|
|
30
|
+
submit_result: "execute",
|
|
23
31
|
// ── edit: mengubah file / working tree ──
|
|
24
32
|
edit: "edit",
|
|
25
33
|
apply_patch: "edit",
|
|
@@ -21,6 +21,8 @@ export interface ActivityGroupView {
|
|
|
21
21
|
failed: number
|
|
22
22
|
running: number
|
|
23
23
|
denied: number
|
|
24
|
+
cancelled: number
|
|
25
|
+
interrupted: number
|
|
24
26
|
/** Nama tool pertama (indikator; sudah tersanitasi & terpotong). */
|
|
25
27
|
names: string[]
|
|
26
28
|
/** Total nama tool unik (sebelum dibatasi 3) untuk penanda `+N`. */
|
|
@@ -41,7 +43,18 @@ export function groupActivities(
|
|
|
41
43
|
const kind = activityGroup(a.name)
|
|
42
44
|
let g = groups.get(kind)
|
|
43
45
|
if (!g) {
|
|
44
|
-
g = {
|
|
46
|
+
g = {
|
|
47
|
+
kind,
|
|
48
|
+
count: 0,
|
|
49
|
+
ok: 0,
|
|
50
|
+
failed: 0,
|
|
51
|
+
running: 0,
|
|
52
|
+
denied: 0,
|
|
53
|
+
cancelled: 0,
|
|
54
|
+
interrupted: 0,
|
|
55
|
+
names: [],
|
|
56
|
+
nameTotal: 0,
|
|
57
|
+
}
|
|
45
58
|
groups.set(kind, g)
|
|
46
59
|
uniqueNames.set(kind, new Set())
|
|
47
60
|
}
|
|
@@ -51,6 +64,8 @@ export function groupActivities(
|
|
|
51
64
|
else if (status === "failed") g.failed++
|
|
52
65
|
else if (status === "running") g.running++
|
|
53
66
|
else if (status === "denied") g.denied++
|
|
67
|
+
else if (status === "cancelled") g.cancelled++
|
|
68
|
+
else if (status === "interrupted") g.interrupted++
|
|
54
69
|
// Nama tool dari model/provider = input tak-terpercaya: buang SEMUA ANSI
|
|
55
70
|
// (termasuk SGR) saat masuk — styling ditambahkan renderer sendiri.
|
|
56
71
|
const cleanName = stripSgr(sanitizeAnsiLine(a.name))
|
|
@@ -65,7 +80,7 @@ export function groupActivities(
|
|
|
65
80
|
/** Warna grup: gagal → merah, ditolak → kuning, sisanya → redup (tenang). */
|
|
66
81
|
function groupPaint(g: ActivityGroupView): (s: string) => string {
|
|
67
82
|
if (g.failed > 0) return c.error
|
|
68
|
-
if (g.denied > 0) return c.warning
|
|
83
|
+
if (g.denied > 0 || g.cancelled > 0 || g.interrupted > 0) return c.warning
|
|
69
84
|
return c.muted
|
|
70
85
|
}
|
|
71
86
|
|
|
@@ -84,6 +99,9 @@ export function groupLine(g: ActivityGroupView): string {
|
|
|
84
99
|
if (g.ok > 0) parts.push(t("panel.ok", { n: g.ok }))
|
|
85
100
|
if (g.failed > 0) parts.push(t("panel.failed", { n: g.failed }))
|
|
86
101
|
if (g.running > 0) parts.push(t("panel.running", { n: g.running }))
|
|
102
|
+
if (g.denied > 0) parts.push(t("panel.denied", { n: g.denied }))
|
|
103
|
+
if (g.cancelled > 0) parts.push(t("panel.cancelled", { n: g.cancelled }))
|
|
104
|
+
if (g.interrupted > 0) parts.push(t("panel.interrupted", { n: g.interrupted }))
|
|
87
105
|
const names = g.names.map((n) => sanitizeAnsiLine(n)).join(", ")
|
|
88
106
|
const more = Math.max(0, g.nameTotal - g.names.length)
|
|
89
107
|
if (names)
|
|
@@ -503,7 +503,12 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
|
|
|
503
503
|
;(async () => {
|
|
504
504
|
try {
|
|
505
505
|
const picked = await pickEffort(row.id)
|
|
506
|
-
if (picked
|
|
506
|
+
if (picked === "skip") {
|
|
507
|
+
// Keluarga tanpa thinking: sebelumnya cabang ini diam total —
|
|
508
|
+
// user menekan Tab, layar tak berubah, dan itu terbaca sebagai
|
|
509
|
+
// "minicode macet". Nyatakan alasannya, tetap di daftar.
|
|
510
|
+
notice = t("effort.noThinking")
|
|
511
|
+
} else if (picked) {
|
|
507
512
|
await withWatchdog(() => opts.onSetEffort!(row.id, picked))
|
|
508
513
|
// Notice terlihat di daftar (manager tetap terbuka) —
|
|
509
514
|
// inilah kehidupan baru `effort.saved` setelah A5.
|
package/src/ui/tui/app.ts
CHANGED
|
@@ -1737,22 +1737,31 @@ export class TuiApp {
|
|
|
1737
1737
|
// dan baris lebih lebar dari `cols` membungkus sendiri → frame jadi
|
|
1738
1738
|
// `rows+1`, alt-screen scroll, seluruh diff CUP meleset (audit 2026-11-12,
|
|
1739
1739
|
// HIGH-3).
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1740
|
+
// Indikator status (abort hint / "N baris di bawah") TIDAK memakai baris
|
|
1741
|
+
// frame sendiri: ia MENGGANTIKAN isi baris footer selama aktif (lihat
|
|
1742
|
+
// `frame` di bawah). Dua alasan:
|
|
1743
|
+
// (a) tinggi frame tidak bergantung status. Dulu baris indikator
|
|
1744
|
+
// menambah/mengurangi satu baris, dan karena `viewH` memilih jendela
|
|
1745
|
+
// transkrip, seluruh isi layar bergeser di antara frame — gejala
|
|
1746
|
+
// "teks naik-turun";
|
|
1747
|
+
// (b) tidak memakan satu baris transkrip permanen demi pesan sementara.
|
|
1748
|
+
const indicatorLine =
|
|
1749
|
+
busy && this.abortHintOn
|
|
1750
|
+
? c.warning(truncateToWidth(t("app.abortHint"), width))
|
|
1751
|
+
: newCount > 0
|
|
1752
|
+
? c.muted(truncateToWidth(t("app.newBelow", { n: newCount }), width))
|
|
1753
|
+
: ""
|
|
1745
1754
|
|
|
1746
1755
|
const allMenu = this.menuRows(height, width, busy)
|
|
1747
1756
|
const allComposer = this.composerRows(width, snap, busy, now)
|
|
1748
|
-
const contentBudget = Math.max(1, height - 3
|
|
1757
|
+
const contentBudget = Math.max(1, height - 3)
|
|
1749
1758
|
let menu = allMenu
|
|
1750
1759
|
let composerH = Math.min(MAX_INPUT_ROWS, Math.max(1, allComposer.length))
|
|
1751
1760
|
if (menu.length + composerH > contentBudget) {
|
|
1752
1761
|
menu = menu.slice(0, Math.max(0, contentBudget - 1))
|
|
1753
1762
|
composerH = Math.max(1, contentBudget - menu.length)
|
|
1754
1763
|
}
|
|
1755
|
-
const viewH = Math.max(1, height - 2 - composerH - menu.length
|
|
1764
|
+
const viewH = Math.max(1, height - 2 - composerH - menu.length)
|
|
1756
1765
|
let viewport = this.transcript.viewport(width, viewH, this.scrollBack)
|
|
1757
1766
|
const curWrapped = viewport.totalRows
|
|
1758
1767
|
if (this.scrollBack > 0 && this.lastWrapped > 0) {
|
|
@@ -1790,11 +1799,11 @@ export class TuiApp {
|
|
|
1790
1799
|
const winStart = Math.max(0, Math.min(allComposer.length - composerH, cursor.visIdx))
|
|
1791
1800
|
composerOffset = winStart
|
|
1792
1801
|
shownComposer = allComposer.slice(winStart, winStart + composerH)
|
|
1793
|
-
cursorRow = viewH + menu.length +
|
|
1802
|
+
cursorRow = viewH + menu.length + (cursor.visIdx - winStart) + 1
|
|
1794
1803
|
cursorCol = cursor.col
|
|
1795
1804
|
} else {
|
|
1796
1805
|
shownComposer = allComposer.slice(0, composerH)
|
|
1797
|
-
cursorRow = viewH + menu.length +
|
|
1806
|
+
cursorRow = viewH + menu.length + 1
|
|
1798
1807
|
// Kursor parkir tepat setelah prompt saat idle (bukan kolom 1) supaya
|
|
1799
1808
|
// caret terlihat di tempat user akan mengetik.
|
|
1800
1809
|
if (!busy) cursorCol = displayWidth(PROMPT_FIRST) + 1
|
|
@@ -1822,7 +1831,13 @@ export class TuiApp {
|
|
|
1822
1831
|
},
|
|
1823
1832
|
width,
|
|
1824
1833
|
)[0] ?? ""
|
|
1825
|
-
const frame = [
|
|
1834
|
+
const frame = [
|
|
1835
|
+
...body,
|
|
1836
|
+
...menu,
|
|
1837
|
+
...shownComposer,
|
|
1838
|
+
"",
|
|
1839
|
+
indicatorLine ? truncateToWidth(indicatorLine, width) : footer,
|
|
1840
|
+
]
|
|
1826
1841
|
const rawLength = frame.length
|
|
1827
1842
|
const crop = Math.max(0, rawLength - height)
|
|
1828
1843
|
const topPad = Math.max(0, height - rawLength)
|
|
@@ -1836,7 +1851,7 @@ export class TuiApp {
|
|
|
1836
1851
|
},
|
|
1837
1852
|
transcriptRows: bodyRows,
|
|
1838
1853
|
transcriptTop: topPad - crop,
|
|
1839
|
-
composerTop: topPad - crop + body.length + menu.length
|
|
1854
|
+
composerTop: topPad - crop + body.length + menu.length,
|
|
1840
1855
|
composerLines: allComposer,
|
|
1841
1856
|
composerOffset,
|
|
1842
1857
|
}
|