minicode-ai 0.25.0 → 0.26.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/setup.ts +107 -8
- package/docs/TERMINAL_CONTRACT.md +32 -1
- package/docs/config.md +13 -1
- package/docs/environment.md +1 -0
- package/docs/getting-started.md +11 -3
- package/package.json +1 -1
- package/src/app/session.ts +187 -17
- package/src/config.ts +19 -8
- package/src/constants.ts +14 -1
- 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 +19 -4
- package/src/policy/context.ts +11 -9
- 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/provision.ts +8 -0
- 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 +3 -0
- package/src/ui/i18n/id.ts +3 -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/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
|
@@ -1212,9 +1212,18 @@ export async function saveSession(
|
|
|
1212
1212
|
// P2.5: tiap baris baru mendapat event_id fresh SATU KALI di sini;
|
|
1213
1213
|
// save ulang identik = no-op (prefixSame) sehingga id stabil.
|
|
1214
1214
|
// P2.6: baris baru dicap run_id pemanggil (bila ada).
|
|
1215
|
+
//
|
|
1216
|
+
// [T-004 OBSERVATION] `ts` WAJIB per-baris, bukan satu `now` untuk seluruh
|
|
1217
|
+
// batch. Dengan satu nilai, seluruh riwayat yang tersimpan lewat jalur ini
|
|
1218
|
+
// berbagi timestamp identik (sesi 17b6a5ff: 159 pesan / 1 nilai) sehingga
|
|
1219
|
+
// linimasa tidak bisa direkonstruksi dari DB sama sekali. Penjaga monotonic
|
|
1220
|
+
// mempertahankan invariant yang selama ini tak sengaja berlaku: ts tidak
|
|
1221
|
+
// pernah mundur terhadap seq (jam sistem bisa mundur/NTP koreksi).
|
|
1222
|
+
let stamp = now
|
|
1215
1223
|
for (let i = known; i < messages.length; i++) {
|
|
1216
1224
|
const m = messages[i] as StoredMsg
|
|
1217
1225
|
const w = normalizeMessageTupleForDedup(m)
|
|
1226
|
+
stamp = Math.max(stamp, Date.now())
|
|
1218
1227
|
ins.run(
|
|
1219
1228
|
id,
|
|
1220
1229
|
tid,
|
|
@@ -1226,7 +1235,7 @@ export async function saveSession(
|
|
|
1226
1235
|
w[4],
|
|
1227
1236
|
w[5],
|
|
1228
1237
|
w[6],
|
|
1229
|
-
|
|
1238
|
+
stamp,
|
|
1230
1239
|
allocateHistoryEventId(),
|
|
1231
1240
|
opts?.runId ?? null,
|
|
1232
1241
|
)
|
|
@@ -2825,6 +2834,12 @@ export function appendHistoryEvent(
|
|
|
2825
2834
|
opts?.runId ?? null,
|
|
2826
2835
|
)
|
|
2827
2836
|
recomputeThreadHeadInTxn(db, sessionId, threadId)
|
|
2837
|
+
// [T-005 OBSERVATION] `updated_at` sesi ikut maju di sini. Sebelumnya
|
|
2838
|
+
// hanya `saveSession` yang menyentuhnya, padahal turn berjalan pasca-
|
|
2839
|
+
// kompaksi menulis lewat jalur per-event ini — akibatnya `updated_at`
|
|
2840
|
+
// mandek di save terakhir (sesi 17b6a5ff: 10:45 vs jurnal 12:07) dan
|
|
2841
|
+
// setiap konsumen yang memakainya sebagai "terakhir aktif" salah.
|
|
2842
|
+
db.prepare("UPDATE sessions SET updated_at = ? WHERE id = ?").run(now, sessionId)
|
|
2828
2843
|
// P2.6: event + kursor dalam SATU txn yang sama. Jalur append per-event
|
|
2829
2844
|
// tak boleh jadi celah "event durable tapi kursor basi".
|
|
2830
2845
|
if (opts?.runId !== undefined) {
|
|
@@ -3675,7 +3690,7 @@ export function shrinkThreadHistory(
|
|
|
3675
3690
|
const oldHead = threadHeadInTxn(db, sessionId, threadId)
|
|
3676
3691
|
const stored = db
|
|
3677
3692
|
.prepare(
|
|
3678
|
-
"SELECT seq, role, content, toolCalls, toolCallId, name, reasoning, is_error, event_id, run_id, migrated, migrated_compacted, projection_note FROM messages WHERE session_id = ? AND thread_id = ? ORDER BY seq",
|
|
3693
|
+
"SELECT seq, role, content, toolCalls, toolCallId, name, reasoning, is_error, ts, event_id, run_id, migrated, migrated_compacted, projection_note FROM messages WHERE session_id = ? AND thread_id = ? ORDER BY seq",
|
|
3679
3694
|
)
|
|
3680
3695
|
.all(sessionId, threadId) as {
|
|
3681
3696
|
seq: number
|
|
@@ -3686,6 +3701,7 @@ export function shrinkThreadHistory(
|
|
|
3686
3701
|
name: string | null
|
|
3687
3702
|
reasoning: string | null
|
|
3688
3703
|
is_error: number | null
|
|
3704
|
+
ts: number | null
|
|
3689
3705
|
event_id: string | null
|
|
3690
3706
|
run_id: string | null
|
|
3691
3707
|
migrated: number
|
|
@@ -3726,7 +3742,7 @@ export function shrinkThreadHistory(
|
|
|
3726
3742
|
w[4],
|
|
3727
3743
|
w[5],
|
|
3728
3744
|
w[6],
|
|
3729
|
-
|
|
3745
|
+
got.ts,
|
|
3730
3746
|
got.event_id ?? allocateHistoryEventId(),
|
|
3731
3747
|
got.run_id,
|
|
3732
3748
|
got.migrated,
|
package/src/tools/bash.ts
CHANGED
|
@@ -372,7 +372,7 @@ function makeBashTool(ownerSid: string | null): Tool {
|
|
|
372
372
|
"background:true is not supported while --sandbox is active (the process must outlive the turn)",
|
|
373
373
|
)
|
|
374
374
|
}
|
|
375
|
-
const id = startBackground(cmd as string,
|
|
375
|
+
const id = startBackground(cmd as string, effectiveCwd, ownerSid, relaxed)
|
|
376
376
|
// F-07: echo perintah di-scrub seperti output foreground — command line
|
|
377
377
|
// bisa membawa secret (`curl -H "Authorization: Bearer …"`), dan versi
|
|
378
378
|
// lama menaruhnya mentah ke konteks model.
|
|
@@ -410,12 +410,13 @@ function makeBashTool(ownerSid: string | null): Tool {
|
|
|
410
410
|
) {
|
|
411
411
|
if (osSandboxAvailable()) {
|
|
412
412
|
const res = await runInOsSandbox(cmd as string, effectiveCwd, {
|
|
413
|
+
signal: ctx.signal,
|
|
413
414
|
timeoutMs: timeout,
|
|
414
415
|
env: sanitizeSpawnEnv(process.env, undefined, relaxed) as Record<string, string>,
|
|
415
416
|
})
|
|
416
417
|
const text = scrubSecrets(res.output)
|
|
417
|
-
if (res.code !== 0
|
|
418
|
-
return `exit ${res.code}\n${capMarked(text, LIMITS.BASH_OUTPUT_MAX_CHARS)}`
|
|
418
|
+
if (res.code !== 0)
|
|
419
|
+
return `exit ${res.code ?? "unknown"}\n${capMarked(text, LIMITS.BASH_OUTPUT_MAX_CHARS)}`
|
|
419
420
|
return capMarked(text, LIMITS.BASH_OUTPUT_MAX_CHARS)
|
|
420
421
|
}
|
|
421
422
|
if (sandboxStrict() || !sandboxExplicitFallbackAllowed()) {
|
|
@@ -443,7 +444,7 @@ function makeBashTool(ownerSid: string | null): Tool {
|
|
|
443
444
|
// terhadap sessionRoot — eksekusi harus di direktori yang sama.
|
|
444
445
|
cwd: effectiveCwd,
|
|
445
446
|
env: sanitizeSpawnEnv(process.env, undefined, relaxed),
|
|
446
|
-
|
|
447
|
+
// Cancellation is owned below and settles only after process close.
|
|
447
448
|
// detached agar shell jadi group leader → killTree bisa bunuh
|
|
448
449
|
// seluruh grup (POSIX kill(-pid)). Tanpa ini cucu yatim menahan pipe.
|
|
449
450
|
detached: process.platform !== "win32",
|
|
@@ -466,6 +467,10 @@ function makeBashTool(ownerSid: string | null): Tool {
|
|
|
466
467
|
p.on("error", reject)
|
|
467
468
|
p.on("close", (code) => {
|
|
468
469
|
const text = buf.text()
|
|
470
|
+
if (ctx.signal.aborted) {
|
|
471
|
+
reject(ctx.signal.reason)
|
|
472
|
+
return
|
|
473
|
+
}
|
|
469
474
|
if (timedOut) {
|
|
470
475
|
// Prefix deterministik (parsing oleh jurnal/recovery) + instruksi
|
|
471
476
|
// eksplisit. `isError: true` dicapai dengan reject: kernel
|
|
@@ -507,13 +512,11 @@ function makeBashTool(ownerSid: string | null): Tool {
|
|
|
507
512
|
const onAbort = () => {
|
|
508
513
|
clearTimeout(t)
|
|
509
514
|
if (killTimer) clearTimeout(killTimer)
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
killTimer = setTimeout(() => {
|
|
513
|
-
killTree(p)
|
|
514
|
-
}, 1000)
|
|
515
|
+
// Kill the group before close can release executor quarantine.
|
|
516
|
+
killTree(p)
|
|
515
517
|
}
|
|
516
518
|
ctx.signal.addEventListener("abort", onAbort, { once: true })
|
|
519
|
+
if (ctx.signal.aborted) onAbort()
|
|
517
520
|
p.on("close", () => {
|
|
518
521
|
ctx.signal.removeEventListener("abort", onAbort)
|
|
519
522
|
clearTimeout(t)
|
package/src/tools/code_run.ts
CHANGED
|
@@ -70,28 +70,27 @@ export const codeRunTool: Tool = {
|
|
|
70
70
|
`code_run: MINICODE_SANDBOX=${sandbox} but no OS sandbox is available`,
|
|
71
71
|
)
|
|
72
72
|
}
|
|
73
|
-
return runInOsSandbox(inner, root, { timeoutMs })
|
|
73
|
+
return runInOsSandbox(inner, root, { timeoutMs, signal: ctx.signal })
|
|
74
74
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
const onAbort = (): Promise<never> =>
|
|
79
|
-
Promise.reject(ctx.signal.reason instanceof Error ? ctx.signal.reason : new Error("aborted"))
|
|
80
|
-
const settled: { code: number | null; output: string } = ctx.signal.aborted
|
|
81
|
-
? await onAbort()
|
|
82
|
-
: await Promise.race([
|
|
83
|
-
started,
|
|
84
|
-
new Promise<never>((_, rej) =>
|
|
85
|
-
ctx.signal.addEventListener(
|
|
86
|
-
"abort",
|
|
87
|
-
() =>
|
|
88
|
-
rej(ctx.signal.reason instanceof Error ? ctx.signal.reason : new Error("aborted")),
|
|
89
|
-
{ once: true },
|
|
90
|
-
),
|
|
91
|
-
),
|
|
92
|
-
])
|
|
75
|
+
// Both runners own cancellation and remove their abort listeners on completion.
|
|
76
|
+
const settled = await runSandboxed()
|
|
77
|
+
ctx.signal.throwIfAborted()
|
|
93
78
|
const text = capMarked(scrubSecrets(settled.output), LIMITS.BASH_OUTPUT_MAX_CHARS).trim()
|
|
94
|
-
|
|
79
|
+
// code=null dari runner berarti proses tidak pernah melaporkan exit sendiri:
|
|
80
|
+
// timeout (dan abort sudah dilempar di atas). Dulu hasil ini tampil sebagai
|
|
81
|
+
// `exit unknown` tanpa menyebut timeout sama sekali — model tak bisa tahu
|
|
82
|
+
// efeknya ambiguous. Sekarang dikembalikan dengan tag outcome yang sama
|
|
83
|
+
// bentuknya dengan jalur bash, bukan sebagai error tak terduga.
|
|
84
|
+
if (settled.code === null) {
|
|
85
|
+
return (
|
|
86
|
+
`[TOOL_OUTCOME state=UNKNOWN reason=TIMEOUT side_effect_tier=LOCAL_ENV_MUTATION ` +
|
|
87
|
+
`timeout_ms=${timeoutMs}]\n` +
|
|
88
|
+
`Sandboxed run was cut off by the ${timeoutMs} ms timeout. Its side effects are UNKNOWN ` +
|
|
89
|
+
`(the snippet may have partially run). Do NOT re-run before inspecting workspace state.\n` +
|
|
90
|
+
(text ? `--- partial output ---\n${text}` : "--- partial output ---\n(none)")
|
|
91
|
+
)
|
|
92
|
+
}
|
|
93
|
+
if (settled.code !== 0) return `exit ${settled.code}\n${text}`
|
|
95
94
|
return text
|
|
96
95
|
},
|
|
97
96
|
}
|
package/src/tools/task.ts
CHANGED
|
@@ -294,9 +294,12 @@ export const delegateTaskTool: Tool = {
|
|
|
294
294
|
// Jalur autonomous TIDAK memakai M7: mode-less (readonly tetap) + default 8
|
|
295
295
|
// tak representable tanpa mengarang mode/grant. Kontrak dipin test
|
|
296
296
|
// `test/p9-admission-boundaries.test.ts`; jangan menyeragamkan tanpa ADR.
|
|
297
|
+
// [T-008] Cap eksplisit sub-agent memakai konstanta SENDIRI (50), bukan
|
|
298
|
+
// `DEFAULT_MAX_STEPS` sesi utama (200). Menyamakannya = memperluas
|
|
299
|
+
// kewenangan delegasi diam-diam saat default sesi utama naik.
|
|
297
300
|
const cap =
|
|
298
301
|
Number.isFinite(requested) && requested > 0
|
|
299
|
-
? Math.min(Math.floor(requested), LIMITS.
|
|
302
|
+
? Math.min(Math.floor(requested), LIMITS.SUB_AGENT_MAX_STEPS)
|
|
300
303
|
: m === "explore"
|
|
301
304
|
? LIMITS.SUB_AGENT_BUDGET_EXPLORE
|
|
302
305
|
: LIMITS.SUB_AGENT_BUDGET_PLAN
|
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
|
@@ -346,6 +346,9 @@ export const en = {
|
|
|
346
346
|
"panel.tools": "{n} tools",
|
|
347
347
|
"panel.ok": "{n} ok",
|
|
348
348
|
"panel.failed": "{n} failed",
|
|
349
|
+
"panel.denied": "{n} denied",
|
|
350
|
+
"panel.cancelled": "{n} cancelled",
|
|
351
|
+
"panel.interrupted": "{n} interrupted",
|
|
349
352
|
"panel.running": "{n} running",
|
|
350
353
|
"panel.thinking": "thinking",
|
|
351
354
|
"panel.lines": "{n} lines",
|
package/src/ui/i18n/id.ts
CHANGED
|
@@ -350,6 +350,9 @@ export const id: Record<MsgKey, string> = {
|
|
|
350
350
|
"panel.tools": "{n} tool",
|
|
351
351
|
"panel.ok": "{n} sukses",
|
|
352
352
|
"panel.failed": "{n} gagal",
|
|
353
|
+
"panel.denied": "{n} ditolak",
|
|
354
|
+
"panel.cancelled": "{n} dibatalkan",
|
|
355
|
+
"panel.interrupted": "{n} terhenti",
|
|
353
356
|
"panel.running": "{n} berjalan",
|
|
354
357
|
"panel.thinking": "berpikir",
|
|
355
358
|
"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)
|