minicode-ai 0.14.1 → 0.14.4
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 +34 -178
- package/cli/args.ts +10 -18
- package/cli/auto-update.ts +32 -2
- package/cli/commands/acp.ts +20 -27
- package/cli/commands/daemon.ts +6 -7
- package/cli/commands/exec.ts +12 -10
- package/cli/commands.ts +6 -9
- package/cli/index.ts +40 -17
- package/cli/provider-manager.ts +1 -3
- package/cli/setup.ts +174 -145
- package/cli/tui.ts +33 -38
- package/docs/CONTROL-PLANE-MAP.md +145 -0
- package/docs/OUTPUT_EVENT_MODEL.md +1 -1
- package/docs/OUTPUT_PROTOCOL_SPEC.md +8 -2
- package/docs/OUTPUT_RENDERING_SPEC.md +35 -6
- package/docs/OUTPUT_UX_RULES.md +1 -1
- package/docs/README.md +14 -102
- package/docs/SUMMARY.md +53 -0
- package/docs/TERMINAL_CONTRACT.md +136 -77
- package/docs/UI_RENDER_PIPELINE.md +204 -0
- package/docs/agents.md +5 -5
- package/docs/architecture.md +23 -12
- package/docs/choosing-mode.md +7 -7
- package/docs/cli.md +22 -29
- package/docs/concepts.md +1 -1
- package/docs/config.md +10 -5
- package/docs/contributing.md +6 -6
- package/docs/environment.md +3 -1
- package/docs/exec.md +5 -5
- package/docs/getting-started.md +14 -12
- package/docs/glossary.md +9 -7
- package/docs/mcp-lsp.md +1 -1
- package/docs/memory-sessions.md +7 -5
- package/docs/policy-sandbox.md +23 -15
- package/docs/quickstart.md +2 -2
- package/docs/repl.md +4 -3
- package/docs/security-model.md +16 -17
- package/docs/security.md +15 -30
- package/docs/skills.md +1 -1
- package/docs/tools.md +6 -6
- package/docs/verify-benchmark.md +16 -0
- package/package.json +5 -5
- package/scripts/vendor-overlays/minicode-context.patch +109 -0
- package/src/app/mentions.ts +4 -3
- package/src/app/provider-layer.ts +13 -1
- package/src/app/session.ts +229 -22
- package/src/app/tool-layer.ts +6 -0
- package/src/config.ts +30 -3
- package/src/constants.ts +19 -0
- package/src/daemon/control.ts +1 -1
- 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/server.ts +2 -3
- package/src/mcp/transport.ts +96 -42
- package/src/memory/files.ts +15 -4
- package/src/memory/vector.ts +5 -1
- package/src/policy/compaction.ts +272 -16
- package/src/policy/context-window.ts +73 -0
- package/src/policy/context.ts +76 -16
- package/src/policy/ratelimit.ts +47 -18
- package/src/policy/tool-contract.ts +4 -10
- package/src/policy/update-check.ts +83 -6
- package/src/policy/usage.ts +31 -14
- package/src/policy/work-mode.ts +1 -1
- 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 +158 -16
- package/src/providers/provision.ts +12 -3
- package/src/providers/responses.ts +61 -23
- package/src/providers/router.ts +56 -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/context-projection.ts +14 -0
- package/src/session/context-selector.ts +58 -20
- package/src/session/persistence.ts +6 -3
- package/src/session/verification.ts +55 -16
- package/src/skills/loader.ts +16 -3
- package/src/task/model.ts +21 -70
- 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 +9 -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 +131 -66
- package/src/ui/i18n/en.ts +3 -11
- package/src/ui/i18n/id.ts +3 -11
- package/src/ui/input/input.ts +2 -3
- package/src/ui/input/prompt-engine.ts +2 -5
- package/src/ui/render/width.ts +107 -79
- package/src/ui/runtime/screen.ts +49 -37
- package/src/ui/screens/model-manager.ts +3 -10
- package/src/ui/screens/picker.ts +23 -40
- package/src/ui/screens/provider-manager.ts +12 -33
- package/src/ui/screens/wizard.ts +0 -1
- package/src/ui/tui/app.ts +265 -211
- package/src/ui/tui/transcript.ts +87 -8
- package/vendor/minicore/VENDOR.md +9 -5
- package/vendor/minicore/src/core/loop.ts +47 -12
- package/vendor/minicore/src/core/provider.ts +4 -0
- package/vendor/minicore/src/core/session.ts +14 -1
- package/CHANGELOG.md +0 -1185
- package/docs/OUTPUT_ARCHITECTURE_AUDIT.md +0 -489
- package/docs/OUTPUT_IMPLEMENTATION_PLAN.md +0 -391
- 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
|
|
@@ -220,6 +219,7 @@ export class TuiApp {
|
|
|
220
219
|
private onSignalTerm: (() => void) | null = null
|
|
221
220
|
private onSignalHup: (() => void) | null = null
|
|
222
221
|
private onSignalInt: (() => void) | null = null
|
|
222
|
+
private signalExitHandled = false
|
|
223
223
|
|
|
224
224
|
private wasRaw = false
|
|
225
225
|
/**
|
|
@@ -269,209 +269,258 @@ export class TuiApp {
|
|
|
269
269
|
return { started: false, frames: 0 }
|
|
270
270
|
}
|
|
271
271
|
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
272
|
const stdout = process.stdout as unknown as {
|
|
304
273
|
on(e: string, fn: () => void): void
|
|
305
274
|
removeListener(e: string, fn: () => void): void
|
|
306
275
|
}
|
|
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) => {
|
|
276
|
+
this.cleanupDone = false
|
|
277
|
+
this.runtimeFailure = null
|
|
278
|
+
this.currentScreen = screen
|
|
279
|
+
this.stdin = stdin
|
|
280
|
+
try {
|
|
319
281
|
try {
|
|
320
|
-
|
|
321
|
-
|
|
282
|
+
this.wasRaw =
|
|
283
|
+
(stdin as unknown as { isRaw?: boolean }).isRaw ??
|
|
284
|
+
(process.stdin as unknown as { isRaw?: boolean }).isRaw ??
|
|
285
|
+
false
|
|
286
|
+
} catch {
|
|
287
|
+
this.wasRaw = false
|
|
288
|
+
}
|
|
289
|
+
const done = new Promise<void>((resolve) => (this.finish = resolve))
|
|
290
|
+
this.pump = createKeyStreamPump({
|
|
291
|
+
state: this.decoder,
|
|
292
|
+
onKeys: (keys) => {
|
|
293
|
+
try {
|
|
294
|
+
return this.handleKeys(keys)
|
|
295
|
+
} catch (error) {
|
|
296
|
+
this.stopAfterRuntimeError(error)
|
|
297
|
+
return true
|
|
298
|
+
}
|
|
299
|
+
},
|
|
300
|
+
})
|
|
301
|
+
this.onData = (chunk: Buffer) => {
|
|
302
|
+
try {
|
|
303
|
+
this.pump?.push(new Uint8Array(chunk))
|
|
304
|
+
} catch (error) {
|
|
305
|
+
this.stopAfterRuntimeError(error)
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
this.onResize = () => {
|
|
309
|
+
// Saat popup fokus, view popup yang melukis ulang regionnya sendiri;
|
|
310
|
+
// repaint penuh App akan menghapus popup dari layar.
|
|
311
|
+
if (this.suspended > 0) return
|
|
312
|
+
// Lukis layar AKTIF (bukan handle `screen` run() yang basi setelah
|
|
313
|
+
// release+reacquire gagal — dulu repaint/resize melukis ke handle
|
|
314
|
+
// tertutup sekaligus menimpa currentScreen baru dengannya).
|
|
315
|
+
this.paintCurrent()
|
|
316
|
+
}
|
|
317
|
+
stdin.setRawMode(true)
|
|
318
|
+
stdin.resume()
|
|
319
|
+
stdin.on("data", this.onData)
|
|
320
|
+
stdout.on("resize", this.onResize)
|
|
321
|
+
// Sinyal fatal (temuan audit TUI-001): default kernel-kill TIDAK
|
|
322
|
+
// menjalankan handler "exit" Node — terminal bisa tertinggal alt-screen
|
|
323
|
+
// + raw mode. Dipasang per-run, dilepas di cleanup (pasangan ketat).
|
|
324
|
+
// Handler TERPISAH per sinyal: Bun TIDAK menyampaikan nama sinyal ke
|
|
325
|
+
// handler (argumen undefined — beda dengan Node), jadi satu handler
|
|
326
|
+
// bersama tak bisa membedakan TERM vs HUP dari parameternya.
|
|
327
|
+
// WAJIB tetap di blok sinkron yang sama dengan openAltScreen() di atas
|
|
328
|
+
// (tanpa await di antaranya): sinyal hanya disampaikan antar-tick event
|
|
329
|
+
// loop, jadi tak ada jendela nyata; sisipkan await di antara keduanya =
|
|
330
|
+
// membuka race SIGTERM sebelum handler terpasang.
|
|
331
|
+
const restoreAndExit = (code: number) => {
|
|
332
|
+
if (this.signalExitHandled) return
|
|
333
|
+
this.signalExitHandled = true
|
|
334
|
+
// Selesaikan loop lebih dulu: cleanup melepas referensi resolver.
|
|
335
|
+
// Ini juga penting saat process.exit di-stub oleh test atau host.
|
|
336
|
+
this.quitRequested = true
|
|
337
|
+
this.finish?.()
|
|
338
|
+
this.cleanupRun(stdin, stdout, screen)
|
|
339
|
+
forceRestoreScreenForSignal()
|
|
340
|
+
// exit() eksplisit memicu handler "exit" yang tersisa (spinner,
|
|
341
|
+
// turn-status) — best-effort sinkron. 128+n = konvensi "mati oleh
|
|
342
|
+
// sinyal n" (SIGTERM=15 → 143, SIGHUP=1 → 129) agar automation
|
|
343
|
+
// tetap bisa membedakan sebab.
|
|
344
|
+
process.exit(code)
|
|
345
|
+
}
|
|
346
|
+
this.onSignalTerm = () => restoreAndExit(143)
|
|
347
|
+
this.onSignalHup = () => restoreAndExit(129)
|
|
348
|
+
this.onSignalInt = () => {
|
|
349
|
+
try {
|
|
350
|
+
this.requestAbort()
|
|
351
|
+
} catch (error) {
|
|
352
|
+
this.stopAfterRuntimeError(error)
|
|
353
|
+
}
|
|
354
|
+
}
|
|
322
355
|
try {
|
|
323
|
-
|
|
324
|
-
} catch {
|
|
356
|
+
process.on("SIGTERM", this.onSignalTerm)
|
|
357
|
+
} catch {
|
|
358
|
+
this.onSignalTerm = null
|
|
359
|
+
}
|
|
325
360
|
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)
|
|
361
|
+
process.on("SIGHUP", this.onSignalHup)
|
|
362
|
+
} catch {
|
|
363
|
+
this.onSignalHup = null
|
|
364
|
+
}
|
|
369
365
|
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) => {
|
|
366
|
+
process.on("SIGINT", this.onSignalInt)
|
|
367
|
+
} catch {
|
|
368
|
+
this.onSignalInt = null
|
|
369
|
+
}
|
|
370
|
+
this.onExit = () => this.setMouseMode("off")
|
|
378
371
|
try {
|
|
379
|
-
this.
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
)
|
|
388
|
-
|
|
372
|
+
process.on("exit", this.onExit)
|
|
373
|
+
} catch {
|
|
374
|
+
this.onExit = null
|
|
375
|
+
}
|
|
376
|
+
// Repaint live mengikuti event bus (stream teks, ledger, thinking).
|
|
377
|
+
// Suspend menahan repaint (popup melukis sendiri); quit menahan semua.
|
|
378
|
+
const requestPaint = () => {
|
|
379
|
+
if (this.quitRequested || this.suspended > 0 || this.released) return
|
|
380
|
+
if (this.repaintTimer !== undefined) return
|
|
381
|
+
this.repaintTimer = setTimeout(() => {
|
|
382
|
+
this.repaintTimer = undefined
|
|
383
|
+
if (!this.quitRequested && this.suspended === 0 && !this.released) this.paintCurrent()
|
|
384
|
+
}, 30)
|
|
385
|
+
try {
|
|
386
|
+
;(this.repaintTimer as unknown as { unref?: () => void }).unref?.()
|
|
387
|
+
} catch {}
|
|
388
|
+
}
|
|
389
|
+
// [F-TYPE-1] Payload tiap call-site dianotasi; `sub` generik (E diinfer dari
|
|
390
|
+
// handler) menjaga anotasi itu, bukan melunturkannya ke `any`. `UiBus.on`
|
|
391
|
+
// tetap longgar di tepi (dokumentasi src/ui/contract.ts:62-71); satu-satunya
|
|
392
|
+
// cast `event as E` menandai perpindahan unknown → bentuk call-site.
|
|
393
|
+
const sub = <E = unknown>(type: Parameters<UiBus["on"]>[0], handler?: (event: E) => void) => {
|
|
394
|
+
try {
|
|
395
|
+
this.busUnsubs.push(
|
|
396
|
+
this.host.bus.on(type, (event: unknown) => {
|
|
397
|
+
try {
|
|
398
|
+
handler?.(event as E)
|
|
399
|
+
} catch (error) {
|
|
400
|
+
this.stopAfterRuntimeError(error)
|
|
401
|
+
} finally {
|
|
402
|
+
try {
|
|
403
|
+
requestPaint()
|
|
404
|
+
} catch (error) {
|
|
405
|
+
this.stopAfterRuntimeError(error)
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
}),
|
|
409
|
+
)
|
|
410
|
+
} catch {}
|
|
411
|
+
}
|
|
412
|
+
sub("turn:started", () => {
|
|
413
|
+
this.thinkingActive = false
|
|
414
|
+
this.turnStartedAt = Date.now()
|
|
415
|
+
this.startActivityClock()
|
|
416
|
+
})
|
|
417
|
+
sub("provider:extension", (event: { kind?: string }) => {
|
|
418
|
+
if (event?.kind === "reasoning") this.thinkingActive = true
|
|
419
|
+
})
|
|
420
|
+
sub("provider:text", () => {
|
|
421
|
+
this.thinkingActive = false
|
|
422
|
+
})
|
|
423
|
+
sub("execution:started", () => {
|
|
424
|
+
this.thinkingActive = false
|
|
425
|
+
})
|
|
426
|
+
sub("execution:completed", () => {
|
|
427
|
+
this.thinkingActive = false
|
|
428
|
+
})
|
|
429
|
+
sub("turn:completed", () => {
|
|
430
|
+
this.thinkingActive = false
|
|
431
|
+
})
|
|
432
|
+
sub("context:compacted")
|
|
433
|
+
this.tailSize = this.transcript.total()
|
|
434
|
+
this.scrollBase = this.tailSize
|
|
435
|
+
this.setMouseMode(mouseSelectionEnabled() ? "drag" : "off")
|
|
436
|
+
this.paint(screen)
|
|
437
|
+
await done
|
|
438
|
+
this.throwRuntimeFailure()
|
|
439
|
+
return { started: true, frames: this.frames }
|
|
440
|
+
} finally {
|
|
441
|
+
this.cleanupRun(stdin, stdout, screen)
|
|
389
442
|
}
|
|
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)
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/** Tutup resource sesi TUI satu kali, termasuk bila setup berhenti separuh jalan. */
|
|
446
|
+
private cleanupRun(
|
|
447
|
+
stdin: RawStdin,
|
|
448
|
+
stdout: { removeListener(e: string, fn: () => void): void },
|
|
449
|
+
initialScreen: AltScreen,
|
|
450
|
+
): void {
|
|
451
|
+
if (this.cleanupDone) return
|
|
452
|
+
this.cleanupDone = true
|
|
453
|
+
try {
|
|
454
|
+
if (this.onData) stdin.removeListener("data", this.onData)
|
|
455
|
+
} catch {}
|
|
456
|
+
try {
|
|
457
|
+
if (this.onResize) stdout.removeListener("resize", this.onResize)
|
|
458
|
+
} catch {}
|
|
420
459
|
if (this.repaintTimer !== undefined) {
|
|
421
460
|
clearTimeout(this.repaintTimer)
|
|
422
461
|
this.repaintTimer = undefined
|
|
423
462
|
}
|
|
424
463
|
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) {
|
|
464
|
+
for (const unsubscribe of this.busUnsubs.splice(0)) {
|
|
440
465
|
try {
|
|
441
|
-
|
|
466
|
+
unsubscribe()
|
|
442
467
|
} catch {}
|
|
443
|
-
this.onSignalHup = null
|
|
444
468
|
}
|
|
445
|
-
|
|
469
|
+
for (const [event, listener] of [
|
|
470
|
+
["SIGTERM", this.onSignalTerm],
|
|
471
|
+
["SIGHUP", this.onSignalHup],
|
|
472
|
+
["SIGINT", this.onSignalInt],
|
|
473
|
+
["exit", this.onExit],
|
|
474
|
+
] as const) {
|
|
475
|
+
if (!listener) continue
|
|
446
476
|
try {
|
|
447
|
-
process.off(
|
|
477
|
+
process.off(event, listener)
|
|
448
478
|
} catch {}
|
|
449
|
-
this.onSignalInt = null
|
|
450
479
|
}
|
|
451
|
-
|
|
480
|
+
this.onSignalTerm = null
|
|
481
|
+
this.onSignalHup = null
|
|
482
|
+
this.onSignalInt = null
|
|
483
|
+
this.onExit = null
|
|
484
|
+
const activeScreen = this.currentScreen
|
|
485
|
+
this.currentScreen = null
|
|
486
|
+
try {
|
|
487
|
+
this.setMouseMode("off")
|
|
488
|
+
} catch {}
|
|
489
|
+
try {
|
|
490
|
+
activeScreen?.close()
|
|
491
|
+
} catch {}
|
|
492
|
+
if (activeScreen !== initialScreen) {
|
|
452
493
|
try {
|
|
453
|
-
|
|
494
|
+
initialScreen.close()
|
|
454
495
|
} catch {}
|
|
455
|
-
this.onExit = null
|
|
456
496
|
}
|
|
457
|
-
|
|
458
|
-
|
|
497
|
+
try {
|
|
498
|
+
this.pump?.dispose()
|
|
499
|
+
} catch {}
|
|
459
500
|
this.pump = null
|
|
501
|
+
this.onData = null
|
|
502
|
+
this.onResize = null
|
|
460
503
|
try {
|
|
461
504
|
stdin.setRawMode(this.wasRaw)
|
|
462
505
|
} catch {}
|
|
463
506
|
try {
|
|
464
507
|
stdin.pause()
|
|
465
508
|
} catch {}
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
this.
|
|
474
|
-
|
|
509
|
+
this.stdin = null
|
|
510
|
+
this.finish = null
|
|
511
|
+
this.suspended = 0
|
|
512
|
+
this.released = false
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
private stopAfterRuntimeError(error: unknown): void {
|
|
516
|
+
if (!this.runtimeFailure) this.runtimeFailure = { error }
|
|
517
|
+
this.quitRequested = true
|
|
518
|
+
this.finish?.()
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
private throwRuntimeFailure(): void {
|
|
522
|
+
const failure = this.runtimeFailure
|
|
523
|
+
if (failure) throw failure.error
|
|
475
524
|
}
|
|
476
525
|
|
|
477
526
|
// ── Penanganan key ──
|
|
@@ -691,7 +740,10 @@ export class TuiApp {
|
|
|
691
740
|
return
|
|
692
741
|
}
|
|
693
742
|
this.rememberHistory(line)
|
|
694
|
-
|
|
743
|
+
// Built-in commands and shortcuts belong to the composer history, not the
|
|
744
|
+
// conversation transcript. The command result remains independently
|
|
745
|
+
// visible when it carries useful user-facing information.
|
|
746
|
+
if (!line.startsWith("/")) this.transcript.pushUser(rawLine)
|
|
695
747
|
this.busy = true
|
|
696
748
|
this.thinkingActive = false
|
|
697
749
|
this.turnStartedAt = Date.now()
|
|
@@ -748,7 +800,11 @@ export class TuiApp {
|
|
|
748
800
|
try {
|
|
749
801
|
if (this.onData) this.stdin?.removeListener("data", this.onData)
|
|
750
802
|
} catch {}
|
|
751
|
-
|
|
803
|
+
try {
|
|
804
|
+
this.paintDimmed()
|
|
805
|
+
} catch (error) {
|
|
806
|
+
this.stopAfterRuntimeError(error)
|
|
807
|
+
}
|
|
752
808
|
}
|
|
753
809
|
|
|
754
810
|
/**
|
|
@@ -847,9 +903,7 @@ export class TuiApp {
|
|
|
847
903
|
const layout = this.buildLayout(rows, cols, snap)
|
|
848
904
|
this.lastLayout = layout
|
|
849
905
|
const dimmed = layout.frame.map((ln) => TuiApp.applyBackdropDim(ln))
|
|
850
|
-
|
|
851
|
-
screen.paint(dimmed)
|
|
852
|
-
} catch {}
|
|
906
|
+
screen.paint(dimmed)
|
|
853
907
|
this.frames++
|
|
854
908
|
}
|
|
855
909
|
|
|
@@ -979,6 +1033,7 @@ export class TuiApp {
|
|
|
979
1033
|
this.activityTimer = undefined
|
|
980
1034
|
if (!this.isBusy() || this.quitRequested) return
|
|
981
1035
|
if (this.suspended === 0 && !this.released) this.paintCurrent()
|
|
1036
|
+
if (this.quitRequested) return
|
|
982
1037
|
this.startActivityClock()
|
|
983
1038
|
}
|
|
984
1039
|
this.activityTimer = setTimeout(tick, DOT_INTERVAL_MS)
|
|
@@ -1044,7 +1099,12 @@ export class TuiApp {
|
|
|
1044
1099
|
}
|
|
1045
1100
|
|
|
1046
1101
|
private paintCurrent(): void {
|
|
1047
|
-
if (this.currentScreen
|
|
1102
|
+
if (!this.currentScreen || this.quitRequested) return
|
|
1103
|
+
try {
|
|
1104
|
+
this.paint(this.currentScreen)
|
|
1105
|
+
} catch (error) {
|
|
1106
|
+
this.stopAfterRuntimeError(error)
|
|
1107
|
+
}
|
|
1048
1108
|
}
|
|
1049
1109
|
|
|
1050
1110
|
/**
|
|
@@ -1089,14 +1149,12 @@ export class TuiApp {
|
|
|
1089
1149
|
const room = Math.max(0, rows - 2 - this.composerHeight(cols, busy) - 3)
|
|
1090
1150
|
const shown = hints.slice(0, Math.min(MAX_DROPDOWN_ROWS, room))
|
|
1091
1151
|
const w = Math.max(10, cols)
|
|
1092
|
-
const out: string[] = [
|
|
1152
|
+
const out: string[] = []
|
|
1093
1153
|
shown.forEach((h, i) => {
|
|
1094
1154
|
const picked = i === this.state.sel
|
|
1095
|
-
const text = sanitizeAnsiLine(h)
|
|
1096
|
-
out.push(picked ? c.accent(
|
|
1155
|
+
const text = sanitizeAnsiLine(h).replace(/^\/+/, "")
|
|
1156
|
+
out.push(picked ? c.accent(c.bold(text)) : text)
|
|
1097
1157
|
})
|
|
1098
|
-
if (hints.length > shown.length)
|
|
1099
|
-
out.push(c.muted(t("app.moreLines", { n: hints.length - shown.length })))
|
|
1100
1158
|
return out.map((l) => chunkByWidth(l, w)[0] ?? "")
|
|
1101
1159
|
}
|
|
1102
1160
|
|
|
@@ -1364,17 +1422,13 @@ export class TuiApp {
|
|
|
1364
1422
|
const w = Math.max(1, cols)
|
|
1365
1423
|
const frame = [c.warning(truncateToWidth(t("tui.tooSmall"), w))]
|
|
1366
1424
|
while (frame.length < Math.max(1, rows)) frame.push("")
|
|
1367
|
-
|
|
1368
|
-
screen.paint(frame.slice(0, Math.max(1, rows)))
|
|
1369
|
-
} catch {}
|
|
1425
|
+
screen.paint(frame.slice(0, Math.max(1, rows)))
|
|
1370
1426
|
this.frames++
|
|
1371
1427
|
return
|
|
1372
1428
|
}
|
|
1373
1429
|
const layout = this.buildLayout(rows, cols, this.host.getStatus())
|
|
1374
1430
|
this.lastLayout = layout
|
|
1375
|
-
|
|
1376
|
-
screen.paint(layout.frame, layout.cursor)
|
|
1377
|
-
} catch {}
|
|
1431
|
+
screen.paint(layout.frame, layout.cursor)
|
|
1378
1432
|
this.frames++
|
|
1379
1433
|
}
|
|
1380
1434
|
|