minicode-ai 0.14.0 → 0.14.2
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/args.ts +16 -3
- package/cli/auto-update.ts +32 -2
- package/cli/commands/exec.ts +9 -0
- package/cli/index.ts +31 -13
- package/cli/setup.ts +31 -19
- package/cli/tui.ts +63 -40
- package/docs/OUTPUT_PROTOCOL_SPEC.md +6 -0
- package/docs/OUTPUT_RENDERING_SPEC.md +28 -4
- package/docs/README.md +2 -2
- package/docs/TERMINAL_CONTRACT.md +52 -26
- package/docs/agents.md +2 -2
- package/docs/choosing-mode.md +20 -13
- package/docs/cli.md +11 -11
- package/docs/environment.md +3 -3
- package/docs/getting-started.md +14 -12
- package/docs/glossary.md +1 -1
- package/docs/mcp-lsp.md +1 -1
- package/docs/policy-sandbox.md +7 -1
- package/docs/security-model.md +2 -2
- package/docs/security.md +7 -1
- package/docs/tools.md +4 -4
- package/docs/verify-benchmark.md +16 -0
- package/package.json +1 -3
- package/src/app/mentions.ts +4 -3
- package/src/app/session.ts +19 -9
- package/src/app/tool-layer.ts +10 -3
- package/src/constants.ts +17 -0
- package/src/lib/git-hardening.ts +27 -22
- package/src/lib/safe-open.ts +73 -19
- package/src/lib/trusted-exec.ts +7 -4
- package/src/mcp/client.ts +34 -9
- package/src/mcp/transport.ts +96 -42
- package/src/memory/files.ts +15 -4
- package/src/memory/vector.ts +5 -1
- package/src/policy/context.ts +21 -13
- package/src/policy/permission.ts +75 -16
- package/src/policy/tool-contract.ts +21 -10
- package/src/policy/update-check.ts +83 -6
- package/src/policy/usage.ts +17 -7
- package/src/policy/work-mode.ts +51 -17
- package/src/presentation/adapter.ts +64 -2
- package/src/presentation/events.ts +6 -0
- package/src/presentation/model.ts +1 -0
- package/src/presentation/projection.ts +2 -0
- package/src/presentation/reducer.ts +1 -0
- package/src/providers/anthropic.ts +52 -19
- package/src/providers/guards.ts +98 -13
- package/src/providers/responses.ts +61 -23
- package/src/providers/sse-bounds.ts +170 -0
- package/src/repo/repomap.ts +10 -11
- package/src/runtime/execution-backend.ts +7 -8
- package/src/sandbox/docker.ts +113 -9
- package/src/session/checkpoint.ts +9 -2
- package/src/session/persistence.ts +5 -2
- package/src/session/verification.ts +55 -16
- package/src/skills/loader.ts +16 -3
- package/src/tools/bash.ts +6 -3
- package/src/tools/code_run.ts +6 -5
- package/src/tools/context.ts +8 -0
- package/src/tools/delete_file.ts +2 -1
- package/src/tools/edit.ts +2 -1
- package/src/tools/git.ts +128 -54
- package/src/tools/glob.ts +2 -1
- package/src/tools/grep.ts +31 -6
- package/src/tools/lsp.ts +5 -4
- package/src/tools/mcp_call.ts +3 -1
- package/src/tools/memory.ts +175 -180
- package/src/tools/move_file.ts +2 -1
- package/src/tools/patch.ts +2 -1
- package/src/tools/read_file.ts +94 -1
- package/src/tools/read_image.ts +2 -1
- package/src/tools/task.ts +2 -1
- package/src/tools/todo.ts +4 -5
- package/src/tools/web_fetch.ts +28 -12
- package/src/tools/web_search.ts +28 -9
- package/src/tools/write_file.ts +2 -1
- package/src/ui/assistant/simple.ts +72 -3
- package/src/ui/footer.ts +17 -12
- package/src/ui/i18n/en.ts +6 -3
- package/src/ui/i18n/id.ts +6 -3
- package/src/ui/render/width.ts +107 -79
- package/src/ui/runtime/screen.ts +49 -37
- package/src/ui/tui/app.ts +261 -209
- package/src/ui/tui/transcript.ts +39 -0
- package/CHANGELOG.md +0 -1167
- package/docs/PLAN_UIUX_V6.md +0 -209
- package/docs/changelog.md +0 -3
package/src/ui/tui/app.ts
CHANGED
|
@@ -25,13 +25,7 @@ import {
|
|
|
25
25
|
import { formatError } from "../render/errors.ts"
|
|
26
26
|
import { sanitizeAnsi, sanitizeAnsiLine, stripSgr } from "../render/sanitize.ts"
|
|
27
27
|
import { c } from "../render/theme.ts"
|
|
28
|
-
import {
|
|
29
|
-
charWidth,
|
|
30
|
-
chunkByWidth,
|
|
31
|
-
displayWidth,
|
|
32
|
-
escapeLength,
|
|
33
|
-
truncateToWidth,
|
|
34
|
-
} from "../render/width.ts"
|
|
28
|
+
import { chunkByWidth, displayWidth, escapeLength, truncateToWidth } from "../render/width.ts"
|
|
35
29
|
import { motionReduced } from "../runtime/motion.ts"
|
|
36
30
|
import { type AltScreen, forceRestoreScreenForSignal, openAltScreen } from "../runtime/screen.ts"
|
|
37
31
|
import type { Transcript, TranscriptPoint, TranscriptRow } from "./transcript.ts"
|
|
@@ -57,15 +51,17 @@ export interface TuiHost {
|
|
|
57
51
|
/** Batalkan turn yang berjalan (Esc saat busy). */
|
|
58
52
|
abort(): void
|
|
59
53
|
copySelection(text: string): boolean
|
|
60
|
-
/** Putar
|
|
61
|
-
|
|
54
|
+
/** Putar WorkMode DISCUSS→PLAN→BUILD (Tab). */
|
|
55
|
+
cycleWorkMode(dir: 1 | -1): void
|
|
56
|
+
/** Toggle PermissionMode AUTO↔ASK (Shift+Tab). */
|
|
57
|
+
togglePermissionMode(): void
|
|
62
58
|
/** Toggle compact / reasoning (Ctrl+O / Ctrl+T). */
|
|
63
59
|
toggleCompact(): void
|
|
64
60
|
toggleReasoning(): void
|
|
65
61
|
}
|
|
66
62
|
|
|
67
63
|
export interface TuiRunResult {
|
|
68
|
-
/** False = layar tak mampu
|
|
64
|
+
/** False = layar tak mampu; caller reports the refusal and sets a failing exit code. */
|
|
69
65
|
started: boolean
|
|
70
66
|
frames: number
|
|
71
67
|
}
|
|
@@ -155,21 +151,24 @@ function highlightColumns(text: string, start: number, end: number): string {
|
|
|
155
151
|
continue
|
|
156
152
|
}
|
|
157
153
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
active
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
active
|
|
154
|
+
let endOfRun = text.indexOf("\x1b", i)
|
|
155
|
+
if (endOfRun < 0) endOfRun = text.length
|
|
156
|
+
if (endOfRun === i) endOfRun++
|
|
157
|
+
for (const grapheme of toGraphemes(text.slice(i, endOfRun))) {
|
|
158
|
+
const width = displayWidth(grapheme)
|
|
159
|
+
const next = column + width
|
|
160
|
+
const inside = column < end && next > start
|
|
161
|
+
if (inside && !active) {
|
|
162
|
+
out += "\x1b[7m"
|
|
163
|
+
active = true
|
|
164
|
+
} else if (!inside && active) {
|
|
165
|
+
out += "\x1b[27m"
|
|
166
|
+
active = false
|
|
167
|
+
}
|
|
168
|
+
out += grapheme
|
|
169
|
+
column = next
|
|
169
170
|
}
|
|
170
|
-
|
|
171
|
-
column = next
|
|
172
|
-
i += char.length
|
|
171
|
+
i = endOfRun
|
|
173
172
|
}
|
|
174
173
|
if (active) out += "\x1b[27m"
|
|
175
174
|
return out
|
|
@@ -206,6 +205,8 @@ export class TuiApp {
|
|
|
206
205
|
private frames = 0
|
|
207
206
|
private quitRequested = false
|
|
208
207
|
private finish: (() => void) | null = null
|
|
208
|
+
private runtimeFailure: { error: unknown } | null = null
|
|
209
|
+
private cleanupDone = false
|
|
209
210
|
private decoder: DecoderState = createDecoderState()
|
|
210
211
|
private pump: KeyStreamPump | null = null
|
|
211
212
|
private onData: ((chunk: Buffer) => void) | null = null
|
|
@@ -267,209 +268,256 @@ export class TuiApp {
|
|
|
267
268
|
return { started: false, frames: 0 }
|
|
268
269
|
}
|
|
269
270
|
const stdin = process.stdin as unknown as RawStdin
|
|
270
|
-
this.stdin = stdin
|
|
271
|
-
try {
|
|
272
|
-
this.wasRaw =
|
|
273
|
-
(stdin as unknown as { isRaw?: boolean }).isRaw ??
|
|
274
|
-
(process.stdin as unknown as { isRaw?: boolean }).isRaw ??
|
|
275
|
-
false
|
|
276
|
-
} catch {
|
|
277
|
-
this.wasRaw = false
|
|
278
|
-
}
|
|
279
|
-
const done = new Promise<void>((resolve) => (this.finish = resolve))
|
|
280
|
-
this.pump = createKeyStreamPump({
|
|
281
|
-
state: this.decoder,
|
|
282
|
-
onKeys: (keys) => this.handleKeys(keys),
|
|
283
|
-
})
|
|
284
|
-
this.onData = (chunk: Buffer) => this.pump?.push(new Uint8Array(chunk))
|
|
285
|
-
this.onResize = () => {
|
|
286
|
-
// Saat popup fokus, view popup yang melukis ulang regionnya sendiri;
|
|
287
|
-
// repaint penuh App akan menghapus popup dari layar.
|
|
288
|
-
if (this.suspended > 0) return
|
|
289
|
-
// Lukis layar AKTIF (bukan handle `screen` run() yang basi setelah
|
|
290
|
-
// release+reacquire gagal — dulu repaint/resize melukis ke handle
|
|
291
|
-
// tertutup sekaligus menimpa currentScreen baru dengannya).
|
|
292
|
-
this.paintCurrent()
|
|
293
|
-
}
|
|
294
|
-
try {
|
|
295
|
-
stdin.setRawMode(true)
|
|
296
|
-
} catch {}
|
|
297
|
-
try {
|
|
298
|
-
stdin.resume()
|
|
299
|
-
} catch {}
|
|
300
|
-
stdin.on("data", this.onData)
|
|
301
271
|
const stdout = process.stdout as unknown as {
|
|
302
272
|
on(e: string, fn: () => void): void
|
|
303
273
|
removeListener(e: string, fn: () => void): void
|
|
304
274
|
}
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
// handler (argumen undefined — beda dengan Node), jadi satu handler
|
|
311
|
-
// bersama tak bisa membedakan TERM vs HUP dari parameternya.
|
|
312
|
-
// WAJIB tetap di blok sinkron yang sama dengan openAltScreen() di atas
|
|
313
|
-
// (tanpa await di antaranya): sinyal hanya disampaikan antar-tick event
|
|
314
|
-
// loop, jadi tak ada jendela nyata; sisipkan await di antara keduanya =
|
|
315
|
-
// membuka race SIGTERM sebelum handler terpasang.
|
|
316
|
-
const restoreAndExit = (code: number) => {
|
|
275
|
+
this.cleanupDone = false
|
|
276
|
+
this.runtimeFailure = null
|
|
277
|
+
this.currentScreen = screen
|
|
278
|
+
this.stdin = stdin
|
|
279
|
+
try {
|
|
317
280
|
try {
|
|
318
|
-
|
|
319
|
-
|
|
281
|
+
this.wasRaw =
|
|
282
|
+
(stdin as unknown as { isRaw?: boolean }).isRaw ??
|
|
283
|
+
(process.stdin as unknown as { isRaw?: boolean }).isRaw ??
|
|
284
|
+
false
|
|
285
|
+
} catch {
|
|
286
|
+
this.wasRaw = false
|
|
287
|
+
}
|
|
288
|
+
const done = new Promise<void>((resolve) => (this.finish = resolve))
|
|
289
|
+
this.pump = createKeyStreamPump({
|
|
290
|
+
state: this.decoder,
|
|
291
|
+
onKeys: (keys) => {
|
|
292
|
+
try {
|
|
293
|
+
return this.handleKeys(keys)
|
|
294
|
+
} catch (error) {
|
|
295
|
+
this.stopAfterRuntimeError(error)
|
|
296
|
+
return true
|
|
297
|
+
}
|
|
298
|
+
},
|
|
299
|
+
})
|
|
300
|
+
this.onData = (chunk: Buffer) => {
|
|
301
|
+
try {
|
|
302
|
+
this.pump?.push(new Uint8Array(chunk))
|
|
303
|
+
} catch (error) {
|
|
304
|
+
this.stopAfterRuntimeError(error)
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
this.onResize = () => {
|
|
308
|
+
// Saat popup fokus, view popup yang melukis ulang regionnya sendiri;
|
|
309
|
+
// repaint penuh App akan menghapus popup dari layar.
|
|
310
|
+
if (this.suspended > 0) return
|
|
311
|
+
// Lukis layar AKTIF (bukan handle `screen` run() yang basi setelah
|
|
312
|
+
// release+reacquire gagal — dulu repaint/resize melukis ke handle
|
|
313
|
+
// tertutup sekaligus menimpa currentScreen baru dengannya).
|
|
314
|
+
this.paintCurrent()
|
|
315
|
+
}
|
|
316
|
+
stdin.setRawMode(true)
|
|
317
|
+
stdin.resume()
|
|
318
|
+
stdin.on("data", this.onData)
|
|
319
|
+
stdout.on("resize", this.onResize)
|
|
320
|
+
// Sinyal fatal (temuan audit TUI-001): default kernel-kill TIDAK
|
|
321
|
+
// menjalankan handler "exit" Node — terminal bisa tertinggal alt-screen
|
|
322
|
+
// + raw mode. Dipasang per-run, dilepas di cleanup (pasangan ketat).
|
|
323
|
+
// Handler TERPISAH per sinyal: Bun TIDAK menyampaikan nama sinyal ke
|
|
324
|
+
// handler (argumen undefined — beda dengan Node), jadi satu handler
|
|
325
|
+
// bersama tak bisa membedakan TERM vs HUP dari parameternya.
|
|
326
|
+
// WAJIB tetap di blok sinkron yang sama dengan openAltScreen() di atas
|
|
327
|
+
// (tanpa await di antaranya): sinyal hanya disampaikan antar-tick event
|
|
328
|
+
// loop, jadi tak ada jendela nyata; sisipkan await di antara keduanya =
|
|
329
|
+
// membuka race SIGTERM sebelum handler terpasang.
|
|
330
|
+
const restoreAndExit = (code: number) => {
|
|
331
|
+
// Selesaikan loop lebih dulu: cleanup melepas referensi resolver.
|
|
332
|
+
// Ini juga penting saat process.exit di-stub oleh test atau host.
|
|
333
|
+
this.quitRequested = true
|
|
334
|
+
this.finish?.()
|
|
335
|
+
this.cleanupRun(stdin, stdout, screen)
|
|
336
|
+
forceRestoreScreenForSignal()
|
|
337
|
+
// exit() eksplisit memicu handler "exit" yang tersisa (spinner,
|
|
338
|
+
// turn-status) — best-effort sinkron. 128+n = konvensi "mati oleh
|
|
339
|
+
// sinyal n" (SIGTERM=15 → 143, SIGHUP=1 → 129) agar automation
|
|
340
|
+
// tetap bisa membedakan sebab.
|
|
341
|
+
process.exit(code)
|
|
342
|
+
}
|
|
343
|
+
this.onSignalTerm = () => restoreAndExit(143)
|
|
344
|
+
this.onSignalHup = () => restoreAndExit(129)
|
|
345
|
+
this.onSignalInt = () => {
|
|
346
|
+
try {
|
|
347
|
+
this.requestAbort()
|
|
348
|
+
} catch (error) {
|
|
349
|
+
this.stopAfterRuntimeError(error)
|
|
350
|
+
}
|
|
351
|
+
}
|
|
320
352
|
try {
|
|
321
|
-
|
|
322
|
-
} catch {
|
|
353
|
+
process.on("SIGTERM", this.onSignalTerm)
|
|
354
|
+
} catch {
|
|
355
|
+
this.onSignalTerm = null
|
|
356
|
+
}
|
|
323
357
|
try {
|
|
324
|
-
|
|
325
|
-
} catch {
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
// exit() eksplisit memicu handler "exit" yang tersisa (spinner,
|
|
329
|
-
// turn-status) — best-effort sinkron. 128+n = konvensi "mati oleh
|
|
330
|
-
// sinyal n" (SIGTERM=15 → 143, SIGHUP=1 → 129) agar automation
|
|
331
|
-
// tetap bisa membedakan sebab.
|
|
332
|
-
process.exit(code)
|
|
333
|
-
}
|
|
334
|
-
this.onSignalTerm = () => restoreAndExit(143)
|
|
335
|
-
this.onSignalHup = () => restoreAndExit(129)
|
|
336
|
-
this.onSignalInt = () => this.requestAbort()
|
|
337
|
-
try {
|
|
338
|
-
process.on("SIGTERM", this.onSignalTerm)
|
|
339
|
-
} catch {
|
|
340
|
-
this.onSignalTerm = null
|
|
341
|
-
}
|
|
342
|
-
try {
|
|
343
|
-
process.on("SIGHUP", this.onSignalHup)
|
|
344
|
-
} catch {
|
|
345
|
-
this.onSignalHup = null
|
|
346
|
-
}
|
|
347
|
-
try {
|
|
348
|
-
process.on("SIGINT", this.onSignalInt)
|
|
349
|
-
} catch {
|
|
350
|
-
this.onSignalInt = null
|
|
351
|
-
}
|
|
352
|
-
this.onExit = () => this.setMouseMode("off")
|
|
353
|
-
try {
|
|
354
|
-
process.on("exit", this.onExit)
|
|
355
|
-
} catch {
|
|
356
|
-
this.onExit = null
|
|
357
|
-
}
|
|
358
|
-
// Repaint live mengikuti event bus (stream teks, ledger, thinking).
|
|
359
|
-
// Suspend menahan repaint (popup melukis sendiri); quit menahan semua.
|
|
360
|
-
const requestPaint = () => {
|
|
361
|
-
if (this.quitRequested || this.suspended > 0 || this.released) return
|
|
362
|
-
if (this.repaintTimer !== undefined) return
|
|
363
|
-
this.repaintTimer = setTimeout(() => {
|
|
364
|
-
this.repaintTimer = undefined
|
|
365
|
-
if (!this.quitRequested && this.suspended === 0 && !this.released) this.paintCurrent()
|
|
366
|
-
}, 30)
|
|
358
|
+
process.on("SIGHUP", this.onSignalHup)
|
|
359
|
+
} catch {
|
|
360
|
+
this.onSignalHup = null
|
|
361
|
+
}
|
|
367
362
|
try {
|
|
368
|
-
|
|
369
|
-
} catch {
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
// tetap longgar di tepi (dokumentasi src/ui/contract.ts:62-71); satu-satunya
|
|
374
|
-
// cast `event as E` menandai perpindahan unknown → bentuk call-site.
|
|
375
|
-
const sub = <E = unknown>(type: Parameters<UiBus["on"]>[0], handler?: (event: E) => void) => {
|
|
363
|
+
process.on("SIGINT", this.onSignalInt)
|
|
364
|
+
} catch {
|
|
365
|
+
this.onSignalInt = null
|
|
366
|
+
}
|
|
367
|
+
this.onExit = () => this.setMouseMode("off")
|
|
376
368
|
try {
|
|
377
|
-
this.
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
)
|
|
386
|
-
|
|
369
|
+
process.on("exit", this.onExit)
|
|
370
|
+
} catch {
|
|
371
|
+
this.onExit = null
|
|
372
|
+
}
|
|
373
|
+
// Repaint live mengikuti event bus (stream teks, ledger, thinking).
|
|
374
|
+
// Suspend menahan repaint (popup melukis sendiri); quit menahan semua.
|
|
375
|
+
const requestPaint = () => {
|
|
376
|
+
if (this.quitRequested || this.suspended > 0 || this.released) return
|
|
377
|
+
if (this.repaintTimer !== undefined) return
|
|
378
|
+
this.repaintTimer = setTimeout(() => {
|
|
379
|
+
this.repaintTimer = undefined
|
|
380
|
+
if (!this.quitRequested && this.suspended === 0 && !this.released) this.paintCurrent()
|
|
381
|
+
}, 30)
|
|
382
|
+
try {
|
|
383
|
+
;(this.repaintTimer as unknown as { unref?: () => void }).unref?.()
|
|
384
|
+
} catch {}
|
|
385
|
+
}
|
|
386
|
+
// [F-TYPE-1] Payload tiap call-site dianotasi; `sub` generik (E diinfer dari
|
|
387
|
+
// handler) menjaga anotasi itu, bukan melunturkannya ke `any`. `UiBus.on`
|
|
388
|
+
// tetap longgar di tepi (dokumentasi src/ui/contract.ts:62-71); satu-satunya
|
|
389
|
+
// cast `event as E` menandai perpindahan unknown → bentuk call-site.
|
|
390
|
+
const sub = <E = unknown>(type: Parameters<UiBus["on"]>[0], handler?: (event: E) => void) => {
|
|
391
|
+
try {
|
|
392
|
+
this.busUnsubs.push(
|
|
393
|
+
this.host.bus.on(type, (event: unknown) => {
|
|
394
|
+
try {
|
|
395
|
+
handler?.(event as E)
|
|
396
|
+
} catch (error) {
|
|
397
|
+
this.stopAfterRuntimeError(error)
|
|
398
|
+
} finally {
|
|
399
|
+
try {
|
|
400
|
+
requestPaint()
|
|
401
|
+
} catch (error) {
|
|
402
|
+
this.stopAfterRuntimeError(error)
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
}),
|
|
406
|
+
)
|
|
407
|
+
} catch {}
|
|
408
|
+
}
|
|
409
|
+
sub("turn:started", () => {
|
|
410
|
+
this.thinkingActive = false
|
|
411
|
+
this.turnStartedAt = Date.now()
|
|
412
|
+
this.startActivityClock()
|
|
413
|
+
})
|
|
414
|
+
sub("provider:extension", (event: { kind?: string }) => {
|
|
415
|
+
if (event?.kind === "reasoning") this.thinkingActive = true
|
|
416
|
+
})
|
|
417
|
+
sub("provider:text", () => {
|
|
418
|
+
this.thinkingActive = false
|
|
419
|
+
})
|
|
420
|
+
sub("execution:started", () => {
|
|
421
|
+
this.thinkingActive = false
|
|
422
|
+
})
|
|
423
|
+
sub("execution:completed", () => {
|
|
424
|
+
this.thinkingActive = false
|
|
425
|
+
})
|
|
426
|
+
sub("turn:completed", () => {
|
|
427
|
+
this.thinkingActive = false
|
|
428
|
+
})
|
|
429
|
+
sub("context:compacted")
|
|
430
|
+
this.tailSize = this.transcript.total()
|
|
431
|
+
this.scrollBase = this.tailSize
|
|
432
|
+
this.setMouseMode(mouseSelectionEnabled() ? "drag" : "off")
|
|
433
|
+
this.paint(screen)
|
|
434
|
+
await done
|
|
435
|
+
this.throwRuntimeFailure()
|
|
436
|
+
return { started: true, frames: this.frames }
|
|
437
|
+
} finally {
|
|
438
|
+
this.cleanupRun(stdin, stdout, screen)
|
|
387
439
|
}
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
})
|
|
405
|
-
sub("turn:completed", () => {
|
|
406
|
-
this.thinkingActive = false
|
|
407
|
-
})
|
|
408
|
-
sub("context:compacted")
|
|
409
|
-
this.tailSize = this.transcript.total()
|
|
410
|
-
this.scrollBase = this.tailSize
|
|
411
|
-
this.setMouseMode(mouseSelectionEnabled() ? "drag" : "off")
|
|
412
|
-
this.paint(screen)
|
|
413
|
-
await done
|
|
414
|
-
// Cleanup: urutan penting — lepas listener dulu agar byte liar pasca-quit
|
|
415
|
-
// tak memicu repaint ke layar yang sudah dikembalikan.
|
|
416
|
-
stdin.removeListener("data", this.onData)
|
|
417
|
-
stdout.removeListener("resize", this.onResize)
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/** Tutup resource sesi TUI satu kali, termasuk bila setup berhenti separuh jalan. */
|
|
443
|
+
private cleanupRun(
|
|
444
|
+
stdin: RawStdin,
|
|
445
|
+
stdout: { removeListener(e: string, fn: () => void): void },
|
|
446
|
+
initialScreen: AltScreen,
|
|
447
|
+
): void {
|
|
448
|
+
if (this.cleanupDone) return
|
|
449
|
+
this.cleanupDone = true
|
|
450
|
+
try {
|
|
451
|
+
if (this.onData) stdin.removeListener("data", this.onData)
|
|
452
|
+
} catch {}
|
|
453
|
+
try {
|
|
454
|
+
if (this.onResize) stdout.removeListener("resize", this.onResize)
|
|
455
|
+
} catch {}
|
|
418
456
|
if (this.repaintTimer !== undefined) {
|
|
419
457
|
clearTimeout(this.repaintTimer)
|
|
420
458
|
this.repaintTimer = undefined
|
|
421
459
|
}
|
|
422
460
|
this.stopActivityClock()
|
|
423
|
-
for (const
|
|
424
|
-
try {
|
|
425
|
-
u()
|
|
426
|
-
} catch {}
|
|
427
|
-
}
|
|
428
|
-
this.busUnsubs = []
|
|
429
|
-
this.suspended = 0
|
|
430
|
-
this.released = false
|
|
431
|
-
if (this.onSignalTerm) {
|
|
432
|
-
try {
|
|
433
|
-
process.off("SIGTERM", this.onSignalTerm)
|
|
434
|
-
} catch {}
|
|
435
|
-
this.onSignalTerm = null
|
|
436
|
-
}
|
|
437
|
-
if (this.onSignalHup) {
|
|
461
|
+
for (const unsubscribe of this.busUnsubs.splice(0)) {
|
|
438
462
|
try {
|
|
439
|
-
|
|
463
|
+
unsubscribe()
|
|
440
464
|
} catch {}
|
|
441
|
-
this.onSignalHup = null
|
|
442
465
|
}
|
|
443
|
-
|
|
466
|
+
for (const [event, listener] of [
|
|
467
|
+
["SIGTERM", this.onSignalTerm],
|
|
468
|
+
["SIGHUP", this.onSignalHup],
|
|
469
|
+
["SIGINT", this.onSignalInt],
|
|
470
|
+
["exit", this.onExit],
|
|
471
|
+
] as const) {
|
|
472
|
+
if (!listener) continue
|
|
444
473
|
try {
|
|
445
|
-
process.off(
|
|
474
|
+
process.off(event, listener)
|
|
446
475
|
} catch {}
|
|
447
|
-
this.onSignalInt = null
|
|
448
476
|
}
|
|
449
|
-
|
|
477
|
+
this.onSignalTerm = null
|
|
478
|
+
this.onSignalHup = null
|
|
479
|
+
this.onSignalInt = null
|
|
480
|
+
this.onExit = null
|
|
481
|
+
const activeScreen = this.currentScreen
|
|
482
|
+
this.currentScreen = null
|
|
483
|
+
try {
|
|
484
|
+
this.setMouseMode("off")
|
|
485
|
+
} catch {}
|
|
486
|
+
try {
|
|
487
|
+
activeScreen?.close()
|
|
488
|
+
} catch {}
|
|
489
|
+
if (activeScreen !== initialScreen) {
|
|
450
490
|
try {
|
|
451
|
-
|
|
491
|
+
initialScreen.close()
|
|
452
492
|
} catch {}
|
|
453
|
-
this.onExit = null
|
|
454
493
|
}
|
|
455
|
-
|
|
456
|
-
|
|
494
|
+
try {
|
|
495
|
+
this.pump?.dispose()
|
|
496
|
+
} catch {}
|
|
457
497
|
this.pump = null
|
|
498
|
+
this.onData = null
|
|
499
|
+
this.onResize = null
|
|
458
500
|
try {
|
|
459
501
|
stdin.setRawMode(this.wasRaw)
|
|
460
502
|
} catch {}
|
|
461
503
|
try {
|
|
462
504
|
stdin.pause()
|
|
463
505
|
} catch {}
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
this.
|
|
472
|
-
|
|
506
|
+
this.stdin = null
|
|
507
|
+
this.finish = null
|
|
508
|
+
this.suspended = 0
|
|
509
|
+
this.released = false
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
private stopAfterRuntimeError(error: unknown): void {
|
|
513
|
+
if (!this.runtimeFailure) this.runtimeFailure = { error }
|
|
514
|
+
this.quitRequested = true
|
|
515
|
+
this.finish?.()
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
private throwRuntimeFailure(): void {
|
|
519
|
+
const failure = this.runtimeFailure
|
|
520
|
+
if (failure) throw failure.error
|
|
473
521
|
}
|
|
474
522
|
|
|
475
523
|
// ── Penanganan key ──
|
|
@@ -601,12 +649,12 @@ export class TuiApp {
|
|
|
601
649
|
return
|
|
602
650
|
}
|
|
603
651
|
if (key.type === "tab") {
|
|
604
|
-
this.host.
|
|
652
|
+
this.host.cycleWorkMode(1)
|
|
605
653
|
this.paintCurrent()
|
|
606
654
|
return
|
|
607
655
|
}
|
|
608
656
|
if (key.type === "shift-tab") {
|
|
609
|
-
this.host.
|
|
657
|
+
this.host.togglePermissionMode()
|
|
610
658
|
this.paintCurrent()
|
|
611
659
|
return
|
|
612
660
|
}
|
|
@@ -746,7 +794,11 @@ export class TuiApp {
|
|
|
746
794
|
try {
|
|
747
795
|
if (this.onData) this.stdin?.removeListener("data", this.onData)
|
|
748
796
|
} catch {}
|
|
749
|
-
|
|
797
|
+
try {
|
|
798
|
+
this.paintDimmed()
|
|
799
|
+
} catch (error) {
|
|
800
|
+
this.stopAfterRuntimeError(error)
|
|
801
|
+
}
|
|
750
802
|
}
|
|
751
803
|
|
|
752
804
|
/**
|
|
@@ -845,9 +897,7 @@ export class TuiApp {
|
|
|
845
897
|
const layout = this.buildLayout(rows, cols, snap)
|
|
846
898
|
this.lastLayout = layout
|
|
847
899
|
const dimmed = layout.frame.map((ln) => TuiApp.applyBackdropDim(ln))
|
|
848
|
-
|
|
849
|
-
screen.paint(dimmed)
|
|
850
|
-
} catch {}
|
|
900
|
+
screen.paint(dimmed)
|
|
851
901
|
this.frames++
|
|
852
902
|
}
|
|
853
903
|
|
|
@@ -977,6 +1027,7 @@ export class TuiApp {
|
|
|
977
1027
|
this.activityTimer = undefined
|
|
978
1028
|
if (!this.isBusy() || this.quitRequested) return
|
|
979
1029
|
if (this.suspended === 0 && !this.released) this.paintCurrent()
|
|
1030
|
+
if (this.quitRequested) return
|
|
980
1031
|
this.startActivityClock()
|
|
981
1032
|
}
|
|
982
1033
|
this.activityTimer = setTimeout(tick, DOT_INTERVAL_MS)
|
|
@@ -1042,7 +1093,12 @@ export class TuiApp {
|
|
|
1042
1093
|
}
|
|
1043
1094
|
|
|
1044
1095
|
private paintCurrent(): void {
|
|
1045
|
-
if (this.currentScreen
|
|
1096
|
+
if (!this.currentScreen || this.quitRequested) return
|
|
1097
|
+
try {
|
|
1098
|
+
this.paint(this.currentScreen)
|
|
1099
|
+
} catch (error) {
|
|
1100
|
+
this.stopAfterRuntimeError(error)
|
|
1101
|
+
}
|
|
1046
1102
|
}
|
|
1047
1103
|
|
|
1048
1104
|
/**
|
|
@@ -1362,17 +1418,13 @@ export class TuiApp {
|
|
|
1362
1418
|
const w = Math.max(1, cols)
|
|
1363
1419
|
const frame = [c.warning(truncateToWidth(t("tui.tooSmall"), w))]
|
|
1364
1420
|
while (frame.length < Math.max(1, rows)) frame.push("")
|
|
1365
|
-
|
|
1366
|
-
screen.paint(frame.slice(0, Math.max(1, rows)))
|
|
1367
|
-
} catch {}
|
|
1421
|
+
screen.paint(frame.slice(0, Math.max(1, rows)))
|
|
1368
1422
|
this.frames++
|
|
1369
1423
|
return
|
|
1370
1424
|
}
|
|
1371
1425
|
const layout = this.buildLayout(rows, cols, this.host.getStatus())
|
|
1372
1426
|
this.lastLayout = layout
|
|
1373
|
-
|
|
1374
|
-
screen.paint(layout.frame, layout.cursor)
|
|
1375
|
-
} catch {}
|
|
1427
|
+
screen.paint(layout.frame, layout.cursor)
|
|
1376
1428
|
this.frames++
|
|
1377
1429
|
}
|
|
1378
1430
|
|
package/src/ui/tui/transcript.ts
CHANGED
|
@@ -177,6 +177,11 @@ export class Transcript {
|
|
|
177
177
|
private nextOrder = 1
|
|
178
178
|
private pending = ""
|
|
179
179
|
private pendingTruncated = false
|
|
180
|
+
private activeProviderAttempt: {
|
|
181
|
+
id: number
|
|
182
|
+
pendingLength: number
|
|
183
|
+
pendingTruncated: boolean
|
|
184
|
+
} | null = null
|
|
180
185
|
private maxPendingChars: number
|
|
181
186
|
/** Hitung monotonik baris yang pernah ditambah — basis indikator "baru"
|
|
182
187
|
* yang kebal evict cap 5000 (size() menyusut saat tertua dibuang). */
|
|
@@ -250,6 +255,39 @@ export class Transcript {
|
|
|
250
255
|
|
|
251
256
|
/** Chunk reasoning (`provider:extension` kind reasoning, data {text}). */
|
|
252
257
|
extension(e: { kind: string; data: unknown }): void {
|
|
258
|
+
if (e.kind === "minicode:attempt") {
|
|
259
|
+
const data = e.data as {
|
|
260
|
+
phase?: unknown
|
|
261
|
+
attemptId?: unknown
|
|
262
|
+
hadVisibleOutput?: unknown
|
|
263
|
+
} | null
|
|
264
|
+
const id = data?.attemptId
|
|
265
|
+
if (typeof id !== "number" || !Number.isSafeInteger(id) || id < 1) return
|
|
266
|
+
if (data?.phase === "started") {
|
|
267
|
+
this.activeProviderAttempt = {
|
|
268
|
+
id,
|
|
269
|
+
pendingLength: this.pending.length,
|
|
270
|
+
pendingTruncated: this.pendingTruncated,
|
|
271
|
+
}
|
|
272
|
+
} else if (data?.phase === "completed") {
|
|
273
|
+
if (this.activeProviderAttempt?.id === id) this.activeProviderAttempt = null
|
|
274
|
+
} else if (data?.phase === "invalidated" && this.activeProviderAttempt?.id === id) {
|
|
275
|
+
this.pending = this.pending.slice(0, this.activeProviderAttempt.pendingLength)
|
|
276
|
+
this.pendingTruncated = this.activeProviderAttempt.pendingTruncated
|
|
277
|
+
this.activeProviderAttempt = null
|
|
278
|
+
// Reasoning dari attempt yang gagal tidak boleh tertinggal sebagai
|
|
279
|
+
// konten aktif/collapsible. Baris reasoning yang sudah dipaint tetap
|
|
280
|
+
// diberi marker append-only di bawah.
|
|
281
|
+
this.thinkingBuf = ""
|
|
282
|
+
this.thinkingTail = ""
|
|
283
|
+
if (data.hadVisibleOutput === true) {
|
|
284
|
+
this.push(c.warning(t("ts.providerAttemptDiscarded", { attempt: id })), {
|
|
285
|
+
kind: "diagnostic",
|
|
286
|
+
})
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
return
|
|
290
|
+
}
|
|
253
291
|
if (e.kind !== "reasoning") return
|
|
254
292
|
const text = (e.data as { text?: string } | null)?.text ?? ""
|
|
255
293
|
if (!text) return
|
|
@@ -333,6 +371,7 @@ export class Transcript {
|
|
|
333
371
|
this.meta = []
|
|
334
372
|
this.pending = ""
|
|
335
373
|
this.pendingTruncated = false
|
|
374
|
+
this.activeProviderAttempt = null
|
|
336
375
|
this.thinkingBuf = ""
|
|
337
376
|
this.thinkingTail = ""
|
|
338
377
|
this.evicted = 0
|