minicode-ai 0.14.1 → 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/auto-update.ts +32 -2
- package/cli/index.ts +10 -2
- package/cli/setup.ts +8 -3
- package/cli/tui.ts +18 -15
- 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/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 +13 -9
- package/src/app/tool-layer.ts +6 -0
- 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/tool-contract.ts +4 -10
- package/src/policy/update-check.ts +83 -6
- package/src/policy/usage.ts +17 -7
- 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/i18n/en.ts +3 -0
- package/src/ui/i18n/id.ts +3 -0
- package/src/ui/render/width.ts +107 -79
- package/src/ui/runtime/screen.ts +49 -37
- package/src/ui/tui/app.ts +255 -205
- package/src/ui/tui/transcript.ts +39 -0
- package/CHANGELOG.md +0 -1185
- 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"
|
|
@@ -67,7 +61,7 @@ export interface TuiHost {
|
|
|
67
61
|
}
|
|
68
62
|
|
|
69
63
|
export interface TuiRunResult {
|
|
70
|
-
/** False = layar tak mampu
|
|
64
|
+
/** False = layar tak mampu; caller reports the refusal and sets a failing exit code. */
|
|
71
65
|
started: boolean
|
|
72
66
|
frames: number
|
|
73
67
|
}
|
|
@@ -157,21 +151,24 @@ function highlightColumns(text: string, start: number, end: number): string {
|
|
|
157
151
|
continue
|
|
158
152
|
}
|
|
159
153
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
active
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
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
|
|
171
170
|
}
|
|
172
|
-
|
|
173
|
-
column = next
|
|
174
|
-
i += char.length
|
|
171
|
+
i = endOfRun
|
|
175
172
|
}
|
|
176
173
|
if (active) out += "\x1b[27m"
|
|
177
174
|
return out
|
|
@@ -208,6 +205,8 @@ export class TuiApp {
|
|
|
208
205
|
private frames = 0
|
|
209
206
|
private quitRequested = false
|
|
210
207
|
private finish: (() => void) | null = null
|
|
208
|
+
private runtimeFailure: { error: unknown } | null = null
|
|
209
|
+
private cleanupDone = false
|
|
211
210
|
private decoder: DecoderState = createDecoderState()
|
|
212
211
|
private pump: KeyStreamPump | null = null
|
|
213
212
|
private onData: ((chunk: Buffer) => void) | null = null
|
|
@@ -269,209 +268,256 @@ export class TuiApp {
|
|
|
269
268
|
return { started: false, frames: 0 }
|
|
270
269
|
}
|
|
271
270
|
const stdin = process.stdin as unknown as RawStdin
|
|
272
|
-
this.stdin = stdin
|
|
273
|
-
try {
|
|
274
|
-
this.wasRaw =
|
|
275
|
-
(stdin as unknown as { isRaw?: boolean }).isRaw ??
|
|
276
|
-
(process.stdin as unknown as { isRaw?: boolean }).isRaw ??
|
|
277
|
-
false
|
|
278
|
-
} catch {
|
|
279
|
-
this.wasRaw = false
|
|
280
|
-
}
|
|
281
|
-
const done = new Promise<void>((resolve) => (this.finish = resolve))
|
|
282
|
-
this.pump = createKeyStreamPump({
|
|
283
|
-
state: this.decoder,
|
|
284
|
-
onKeys: (keys) => this.handleKeys(keys),
|
|
285
|
-
})
|
|
286
|
-
this.onData = (chunk: Buffer) => this.pump?.push(new Uint8Array(chunk))
|
|
287
|
-
this.onResize = () => {
|
|
288
|
-
// Saat popup fokus, view popup yang melukis ulang regionnya sendiri;
|
|
289
|
-
// repaint penuh App akan menghapus popup dari layar.
|
|
290
|
-
if (this.suspended > 0) return
|
|
291
|
-
// Lukis layar AKTIF (bukan handle `screen` run() yang basi setelah
|
|
292
|
-
// release+reacquire gagal — dulu repaint/resize melukis ke handle
|
|
293
|
-
// tertutup sekaligus menimpa currentScreen baru dengannya).
|
|
294
|
-
this.paintCurrent()
|
|
295
|
-
}
|
|
296
|
-
try {
|
|
297
|
-
stdin.setRawMode(true)
|
|
298
|
-
} catch {}
|
|
299
|
-
try {
|
|
300
|
-
stdin.resume()
|
|
301
|
-
} catch {}
|
|
302
|
-
stdin.on("data", this.onData)
|
|
303
271
|
const stdout = process.stdout as unknown as {
|
|
304
272
|
on(e: string, fn: () => void): void
|
|
305
273
|
removeListener(e: string, fn: () => void): void
|
|
306
274
|
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
// handler (argumen undefined — beda dengan Node), jadi satu handler
|
|
313
|
-
// bersama tak bisa membedakan TERM vs HUP dari parameternya.
|
|
314
|
-
// WAJIB tetap di blok sinkron yang sama dengan openAltScreen() di atas
|
|
315
|
-
// (tanpa await di antaranya): sinyal hanya disampaikan antar-tick event
|
|
316
|
-
// loop, jadi tak ada jendela nyata; sisipkan await di antara keduanya =
|
|
317
|
-
// membuka race SIGTERM sebelum handler terpasang.
|
|
318
|
-
const restoreAndExit = (code: number) => {
|
|
275
|
+
this.cleanupDone = false
|
|
276
|
+
this.runtimeFailure = null
|
|
277
|
+
this.currentScreen = screen
|
|
278
|
+
this.stdin = stdin
|
|
279
|
+
try {
|
|
319
280
|
try {
|
|
320
|
-
|
|
321
|
-
|
|
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
|
+
}
|
|
322
352
|
try {
|
|
323
|
-
|
|
324
|
-
} catch {
|
|
353
|
+
process.on("SIGTERM", this.onSignalTerm)
|
|
354
|
+
} catch {
|
|
355
|
+
this.onSignalTerm = null
|
|
356
|
+
}
|
|
325
357
|
try {
|
|
326
|
-
|
|
327
|
-
} catch {
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
// exit() eksplisit memicu handler "exit" yang tersisa (spinner,
|
|
331
|
-
// turn-status) — best-effort sinkron. 128+n = konvensi "mati oleh
|
|
332
|
-
// sinyal n" (SIGTERM=15 → 143, SIGHUP=1 → 129) agar automation
|
|
333
|
-
// tetap bisa membedakan sebab.
|
|
334
|
-
process.exit(code)
|
|
335
|
-
}
|
|
336
|
-
this.onSignalTerm = () => restoreAndExit(143)
|
|
337
|
-
this.onSignalHup = () => restoreAndExit(129)
|
|
338
|
-
this.onSignalInt = () => this.requestAbort()
|
|
339
|
-
try {
|
|
340
|
-
process.on("SIGTERM", this.onSignalTerm)
|
|
341
|
-
} catch {
|
|
342
|
-
this.onSignalTerm = null
|
|
343
|
-
}
|
|
344
|
-
try {
|
|
345
|
-
process.on("SIGHUP", this.onSignalHup)
|
|
346
|
-
} catch {
|
|
347
|
-
this.onSignalHup = null
|
|
348
|
-
}
|
|
349
|
-
try {
|
|
350
|
-
process.on("SIGINT", this.onSignalInt)
|
|
351
|
-
} catch {
|
|
352
|
-
this.onSignalInt = null
|
|
353
|
-
}
|
|
354
|
-
this.onExit = () => this.setMouseMode("off")
|
|
355
|
-
try {
|
|
356
|
-
process.on("exit", this.onExit)
|
|
357
|
-
} catch {
|
|
358
|
-
this.onExit = null
|
|
359
|
-
}
|
|
360
|
-
// Repaint live mengikuti event bus (stream teks, ledger, thinking).
|
|
361
|
-
// Suspend menahan repaint (popup melukis sendiri); quit menahan semua.
|
|
362
|
-
const requestPaint = () => {
|
|
363
|
-
if (this.quitRequested || this.suspended > 0 || this.released) return
|
|
364
|
-
if (this.repaintTimer !== undefined) return
|
|
365
|
-
this.repaintTimer = setTimeout(() => {
|
|
366
|
-
this.repaintTimer = undefined
|
|
367
|
-
if (!this.quitRequested && this.suspended === 0 && !this.released) this.paintCurrent()
|
|
368
|
-
}, 30)
|
|
358
|
+
process.on("SIGHUP", this.onSignalHup)
|
|
359
|
+
} catch {
|
|
360
|
+
this.onSignalHup = null
|
|
361
|
+
}
|
|
369
362
|
try {
|
|
370
|
-
|
|
371
|
-
} catch {
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
// tetap longgar di tepi (dokumentasi src/ui/contract.ts:62-71); satu-satunya
|
|
376
|
-
// cast `event as E` menandai perpindahan unknown → bentuk call-site.
|
|
377
|
-
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")
|
|
378
368
|
try {
|
|
379
|
-
this.
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
)
|
|
388
|
-
|
|
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)
|
|
389
439
|
}
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
})
|
|
407
|
-
sub("turn:completed", () => {
|
|
408
|
-
this.thinkingActive = false
|
|
409
|
-
})
|
|
410
|
-
sub("context:compacted")
|
|
411
|
-
this.tailSize = this.transcript.total()
|
|
412
|
-
this.scrollBase = this.tailSize
|
|
413
|
-
this.setMouseMode(mouseSelectionEnabled() ? "drag" : "off")
|
|
414
|
-
this.paint(screen)
|
|
415
|
-
await done
|
|
416
|
-
// Cleanup: urutan penting — lepas listener dulu agar byte liar pasca-quit
|
|
417
|
-
// tak memicu repaint ke layar yang sudah dikembalikan.
|
|
418
|
-
stdin.removeListener("data", this.onData)
|
|
419
|
-
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 {}
|
|
420
456
|
if (this.repaintTimer !== undefined) {
|
|
421
457
|
clearTimeout(this.repaintTimer)
|
|
422
458
|
this.repaintTimer = undefined
|
|
423
459
|
}
|
|
424
460
|
this.stopActivityClock()
|
|
425
|
-
for (const
|
|
426
|
-
try {
|
|
427
|
-
u()
|
|
428
|
-
} catch {}
|
|
429
|
-
}
|
|
430
|
-
this.busUnsubs = []
|
|
431
|
-
this.suspended = 0
|
|
432
|
-
this.released = false
|
|
433
|
-
if (this.onSignalTerm) {
|
|
434
|
-
try {
|
|
435
|
-
process.off("SIGTERM", this.onSignalTerm)
|
|
436
|
-
} catch {}
|
|
437
|
-
this.onSignalTerm = null
|
|
438
|
-
}
|
|
439
|
-
if (this.onSignalHup) {
|
|
461
|
+
for (const unsubscribe of this.busUnsubs.splice(0)) {
|
|
440
462
|
try {
|
|
441
|
-
|
|
463
|
+
unsubscribe()
|
|
442
464
|
} catch {}
|
|
443
|
-
this.onSignalHup = null
|
|
444
465
|
}
|
|
445
|
-
|
|
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
|
|
446
473
|
try {
|
|
447
|
-
process.off(
|
|
474
|
+
process.off(event, listener)
|
|
448
475
|
} catch {}
|
|
449
|
-
this.onSignalInt = null
|
|
450
476
|
}
|
|
451
|
-
|
|
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) {
|
|
452
490
|
try {
|
|
453
|
-
|
|
491
|
+
initialScreen.close()
|
|
454
492
|
} catch {}
|
|
455
|
-
this.onExit = null
|
|
456
493
|
}
|
|
457
|
-
|
|
458
|
-
|
|
494
|
+
try {
|
|
495
|
+
this.pump?.dispose()
|
|
496
|
+
} catch {}
|
|
459
497
|
this.pump = null
|
|
498
|
+
this.onData = null
|
|
499
|
+
this.onResize = null
|
|
460
500
|
try {
|
|
461
501
|
stdin.setRawMode(this.wasRaw)
|
|
462
502
|
} catch {}
|
|
463
503
|
try {
|
|
464
504
|
stdin.pause()
|
|
465
505
|
} catch {}
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
this.
|
|
474
|
-
|
|
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
|
|
475
521
|
}
|
|
476
522
|
|
|
477
523
|
// ── Penanganan key ──
|
|
@@ -748,7 +794,11 @@ export class TuiApp {
|
|
|
748
794
|
try {
|
|
749
795
|
if (this.onData) this.stdin?.removeListener("data", this.onData)
|
|
750
796
|
} catch {}
|
|
751
|
-
|
|
797
|
+
try {
|
|
798
|
+
this.paintDimmed()
|
|
799
|
+
} catch (error) {
|
|
800
|
+
this.stopAfterRuntimeError(error)
|
|
801
|
+
}
|
|
752
802
|
}
|
|
753
803
|
|
|
754
804
|
/**
|
|
@@ -847,9 +897,7 @@ export class TuiApp {
|
|
|
847
897
|
const layout = this.buildLayout(rows, cols, snap)
|
|
848
898
|
this.lastLayout = layout
|
|
849
899
|
const dimmed = layout.frame.map((ln) => TuiApp.applyBackdropDim(ln))
|
|
850
|
-
|
|
851
|
-
screen.paint(dimmed)
|
|
852
|
-
} catch {}
|
|
900
|
+
screen.paint(dimmed)
|
|
853
901
|
this.frames++
|
|
854
902
|
}
|
|
855
903
|
|
|
@@ -979,6 +1027,7 @@ export class TuiApp {
|
|
|
979
1027
|
this.activityTimer = undefined
|
|
980
1028
|
if (!this.isBusy() || this.quitRequested) return
|
|
981
1029
|
if (this.suspended === 0 && !this.released) this.paintCurrent()
|
|
1030
|
+
if (this.quitRequested) return
|
|
982
1031
|
this.startActivityClock()
|
|
983
1032
|
}
|
|
984
1033
|
this.activityTimer = setTimeout(tick, DOT_INTERVAL_MS)
|
|
@@ -1044,7 +1093,12 @@ export class TuiApp {
|
|
|
1044
1093
|
}
|
|
1045
1094
|
|
|
1046
1095
|
private paintCurrent(): void {
|
|
1047
|
-
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
|
+
}
|
|
1048
1102
|
}
|
|
1049
1103
|
|
|
1050
1104
|
/**
|
|
@@ -1364,17 +1418,13 @@ export class TuiApp {
|
|
|
1364
1418
|
const w = Math.max(1, cols)
|
|
1365
1419
|
const frame = [c.warning(truncateToWidth(t("tui.tooSmall"), w))]
|
|
1366
1420
|
while (frame.length < Math.max(1, rows)) frame.push("")
|
|
1367
|
-
|
|
1368
|
-
screen.paint(frame.slice(0, Math.max(1, rows)))
|
|
1369
|
-
} catch {}
|
|
1421
|
+
screen.paint(frame.slice(0, Math.max(1, rows)))
|
|
1370
1422
|
this.frames++
|
|
1371
1423
|
return
|
|
1372
1424
|
}
|
|
1373
1425
|
const layout = this.buildLayout(rows, cols, this.host.getStatus())
|
|
1374
1426
|
this.lastLayout = layout
|
|
1375
|
-
|
|
1376
|
-
screen.paint(layout.frame, layout.cursor)
|
|
1377
|
-
} catch {}
|
|
1427
|
+
screen.paint(layout.frame, layout.cursor)
|
|
1378
1428
|
this.frames++
|
|
1379
1429
|
}
|
|
1380
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
|