minicode-ai 0.21.0 → 0.23.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 +1 -1
- package/cli/commands/exec.ts +44 -1
- package/cli/commands.ts +15 -2
- package/cli/index.ts +11 -0
- package/cli/setup.ts +88 -33
- package/cli/tui.ts +3 -3
- package/docs/TERMINAL_CONTRACT.md +69 -13
- package/docs/architecture.md +9 -5
- package/docs/concepts.md +1 -1
- package/docs/contributing.md +2 -1
- package/docs/environment.md +4 -0
- package/docs/policy-sandbox.md +6 -1
- package/docs/security.md +12 -4
- package/docs/skills.md +1 -1
- package/package.json +2 -2
- package/src/app/session.ts +129 -20
- package/src/config.ts +108 -8
- package/src/constants.ts +29 -4
- package/src/daemon/discovery.ts +24 -0
- package/src/policy/bash-guard.ts +170 -6
- package/src/policy/compaction.ts +61 -7
- package/src/policy/context-budget.ts +132 -0
- package/src/policy/context-escalation.ts +140 -0
- package/src/policy/context-window.ts +47 -9
- package/src/policy/context.ts +10 -1
- package/src/policy/jail.ts +10 -22
- package/src/policy/microcompact.ts +162 -0
- package/src/policy/permission.ts +9 -6
- package/src/presentation/projection.ts +1 -1
- package/src/providers/anthropic.ts +31 -7
- package/src/providers/detect.ts +128 -13
- package/src/providers/provision.ts +78 -1
- package/src/providers/responses.ts +14 -2
- package/src/providers/sse-bounds.ts +16 -2
- package/src/session/persistence.ts +56 -0
- package/src/ui/approval/prompt.ts +17 -6
- package/src/ui/assistant/simple.ts +1 -1
- package/src/ui/footer.ts +2 -2
- package/src/ui/i18n/en.ts +28 -5
- package/src/ui/i18n/id.ts +30 -5
- package/src/ui/input/input.ts +2 -2
- package/src/ui/input/prompt-engine.ts +6 -0
- package/src/ui/render/activity-panel.ts +21 -3
- package/src/ui/render/diff.ts +51 -2
- package/src/ui/render/highlight.ts +68 -37
- package/src/ui/render/hint.ts +28 -0
- package/src/ui/render/logo.ts +91 -0
- package/src/ui/render/sanitize.ts +5 -1
- package/src/ui/render/session-summary.ts +28 -5
- package/src/ui/render/table-grid.ts +123 -13
- package/src/ui/render/table.ts +4 -2
- package/src/ui/render/theme.ts +16 -3
- package/src/ui/render/width.ts +35 -6
- package/src/ui/render/wrap.ts +28 -6
- package/src/ui/runtime/loading-bar.ts +17 -5
- package/src/ui/runtime/screen.ts +4 -2
- package/src/ui/screens/dialog.ts +23 -2
- package/src/ui/screens/form.ts +71 -33
- package/src/ui/screens/lifecycle.ts +80 -0
- package/src/ui/screens/model-manager.ts +85 -83
- package/src/ui/screens/picker.ts +39 -25
- package/src/ui/screens/provider-manager.ts +58 -55
- package/src/ui/screens/watchdog.ts +27 -0
- package/src/ui/screens/wizard.ts +12 -1
- package/src/ui/tui/app.ts +62 -22
- package/src/ui/tui/transcript.ts +93 -23
- package/vendor/minicore/src/core/compact.ts +10 -0
- package/vendor/minicore/src/core/errors.ts +11 -1
- package/vendor/minicore/src/core/executor.ts +6 -1
- package/vendor/minicore/src/core/loop.ts +92 -2
- package/vendor/minicore/src/core/session.ts +8 -0
- package/vendor/minicore/src/providers/openai-compat.ts +45 -3
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import { readFile } from "node:fs/promises"
|
|
6
6
|
import { resolve } from "node:path"
|
|
7
7
|
import {
|
|
8
|
+
type ContextWindowSource,
|
|
8
9
|
globalConfigPath,
|
|
9
10
|
LOCAL,
|
|
10
11
|
loadConfig,
|
|
@@ -106,6 +107,66 @@ export function deriveProviderId(baseUrl: string, existingIds: string[], id?: st
|
|
|
106
107
|
return uniqId
|
|
107
108
|
}
|
|
108
109
|
|
|
110
|
+
/**
|
|
111
|
+
* Gabungkan metadata kapasitas yang DITEMUKAN endpoint ke entri provider.
|
|
112
|
+
*
|
|
113
|
+
* Aturan presedensi (alasannya sama dengan `resolveContextWindow`):
|
|
114
|
+
* - Nilai ber-`source: "user"` milik operator TIDAK PERNAH ditimpa. Config lama
|
|
115
|
+
* tanpa catatan asal diperlakukan `user` supaya perilaku tidak berubah diam-diam.
|
|
116
|
+
* - Nilai `endpoint`/`probe` boleh diperbarui oleh deteksi berikutnya — endpoint
|
|
117
|
+
* yang dipanggil hari ini lebih tahu daripada hasil deteksi kemarin.
|
|
118
|
+
* - Model yang hilang dari `/models` (sudah tak ada) dibuang agar config tidak
|
|
119
|
+
* mengumpulkan nilai basi untuk model yang tak bisa dipakai lagi.
|
|
120
|
+
*
|
|
121
|
+
* Diekspor untuk test: ini satu-satunya tempat yang menentukan "siapa menang".
|
|
122
|
+
*/
|
|
123
|
+
export function mergeDiscoveredCapacity(
|
|
124
|
+
previous: ProviderEntry | undefined,
|
|
125
|
+
detected: DetectResult,
|
|
126
|
+
): Pick<ProviderEntry, "contextWindows" | "contextWindowSources" | "maxOutputTokens"> {
|
|
127
|
+
const metadata = detected.modelMetadata
|
|
128
|
+
if (!metadata || Object.keys(metadata).length === 0) return {}
|
|
129
|
+
const prevWindows = previous?.contextWindows ?? {}
|
|
130
|
+
const prevSources = previous?.contextWindowSources ?? {}
|
|
131
|
+
const prevMaxOut = previous?.maxOutputTokens ?? {}
|
|
132
|
+
const windows: Record<string, number> = {}
|
|
133
|
+
const sources: Record<string, ContextWindowSource> = {}
|
|
134
|
+
const maxOut: Record<string, number> = {}
|
|
135
|
+
for (const [model, meta] of Object.entries(metadata)) {
|
|
136
|
+
// Buang entri untuk model yang tak lagi ditawarkan endpoint (basi).
|
|
137
|
+
// Model di luar metadata tetap dipertahankan dari config lama di bawah.
|
|
138
|
+
const prevSource = prevSources[model]
|
|
139
|
+
const userOwned =
|
|
140
|
+
prevSource === undefined ? prevWindows[model] !== undefined : prevSource === "user"
|
|
141
|
+
if (meta.contextLength !== undefined && !userOwned) {
|
|
142
|
+
windows[model] = meta.contextLength
|
|
143
|
+
sources[model] = "endpoint"
|
|
144
|
+
}
|
|
145
|
+
if (meta.maxOutputTokens !== undefined) maxOut[model] = meta.maxOutputTokens
|
|
146
|
+
}
|
|
147
|
+
// Pertahankan yang tak dilaporkan endpoint kali ini (endpoint bisa parsial:
|
|
148
|
+
// sebagian gateway hanya menyertakan kapasitas untuk model yang baru
|
|
149
|
+
// ditambahkan). `live` hanya dipakai untuk membuang model yang endpoint
|
|
150
|
+
// TIDAK menawarkan lagi — bukan untuk membuang nilai yang belum dilaporkan.
|
|
151
|
+
const live = new Set(detected.models)
|
|
152
|
+
for (const [model, tokens] of Object.entries(prevWindows)) {
|
|
153
|
+
if (live.size > 0 && !live.has(model)) continue
|
|
154
|
+
if (windows[model] === undefined) {
|
|
155
|
+
windows[model] = tokens
|
|
156
|
+
sources[model] = prevSources[model] ?? "user"
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
for (const [model, tokens] of Object.entries(prevMaxOut)) {
|
|
160
|
+
if (live.size > 0 && !live.has(model)) continue
|
|
161
|
+
if (maxOut[model] === undefined) maxOut[model] = tokens
|
|
162
|
+
}
|
|
163
|
+
return {
|
|
164
|
+
...(Object.keys(windows).length > 0 ? { contextWindows: windows } : {}),
|
|
165
|
+
...(Object.keys(sources).length > 0 ? { contextWindowSources: sources } : {}),
|
|
166
|
+
...(Object.keys(maxOut).length > 0 ? { maxOutputTokens: maxOut } : {}),
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
109
170
|
export async function detectAndSave(
|
|
110
171
|
baseUrl: string,
|
|
111
172
|
apiKey: string,
|
|
@@ -158,6 +219,9 @@ export async function detectAndSave(
|
|
|
158
219
|
// ini tiap add/edit me-reset effort ke default diam-diam ("hilang").
|
|
159
220
|
const previous = prevCfg.providers.find((p) => p.id === uniqId)
|
|
160
221
|
const prevEffort = previous?.reasoningEffort
|
|
222
|
+
// Kapasitas dari metadata endpoint (bila dilaporkan) diutamakan atas tebakan
|
|
223
|
+
// statis, tapi tak pernah menimpa nilai `user` — lihat mergeDiscoveredCapacity.
|
|
224
|
+
const capacity = mergeDiscoveredCapacity(previous, detected)
|
|
161
225
|
const entry: ProviderEntry = {
|
|
162
226
|
id: uniqId,
|
|
163
227
|
baseUrl,
|
|
@@ -165,6 +229,7 @@ export async function detectAndSave(
|
|
|
165
229
|
models: detected.models,
|
|
166
230
|
providerHint: detected.providerHint,
|
|
167
231
|
...(previous?.contextWindows ? { contextWindows: previous.contextWindows } : {}),
|
|
232
|
+
...capacity,
|
|
168
233
|
...(prevEffort ? { reasoningEffort: prevEffort } : {}),
|
|
169
234
|
}
|
|
170
235
|
await saveProvider(entry, opts)
|
|
@@ -250,7 +315,14 @@ export async function refreshProviderModels(
|
|
|
250
315
|
try {
|
|
251
316
|
const detected = await detectModels(p.baseUrl, apiKey)
|
|
252
317
|
if (detected.models.length) {
|
|
253
|
-
|
|
318
|
+
// Metadata kapasitas ikut disegarkan: gateway yang menambah/mengubah
|
|
319
|
+
// model akan memperbarui jendela konteksnya tanpa user menyentuh apa pun.
|
|
320
|
+
updated.set(p.id, {
|
|
321
|
+
...p,
|
|
322
|
+
models: detected.models,
|
|
323
|
+
providerHint: detected.providerHint,
|
|
324
|
+
...mergeDiscoveredCapacity(p, detected),
|
|
325
|
+
})
|
|
254
326
|
} else if (detected.authFailed) {
|
|
255
327
|
// Key ditolak (401/403): bedakan dari provider tanpa endpoint
|
|
256
328
|
// (Anthropic-style, tetap diam) — operator harus periksa key-nya.
|
|
@@ -290,6 +362,11 @@ export async function refreshProviderModels(
|
|
|
290
362
|
if (nu) {
|
|
291
363
|
p.models = nu.models
|
|
292
364
|
p.providerHint = nu.providerHint
|
|
365
|
+
// Kapasitas hanya ditulis bila hasil merge memang punya isi — tanpa
|
|
366
|
+
// guard ini provider tanpa metadata akan menghapus nilai lama.
|
|
367
|
+
if (nu.contextWindows) p.contextWindows = nu.contextWindows
|
|
368
|
+
if (nu.contextWindowSources) p.contextWindowSources = nu.contextWindowSources
|
|
369
|
+
if (nu.maxOutputTokens) p.maxOutputTokens = nu.maxOutputTokens
|
|
293
370
|
changed = true
|
|
294
371
|
}
|
|
295
372
|
}
|
|
@@ -140,7 +140,7 @@ export function createResponsesProvider(config: ResponsesConfig): ModelProvider
|
|
|
140
140
|
// Bila request gagal saat membawa previous_response_id, hapus ID tersebut
|
|
141
141
|
// agar turn berikutnya tidak macet permanen pada ID yang kedaluwarsa/ditolak.
|
|
142
142
|
if (prev) lastResponseByModel.delete(modelKey)
|
|
143
|
-
const txt = await readProviderErrorBody(res).catch(() => "")
|
|
143
|
+
const txt = await readProviderErrorBody(res, signal).catch(() => "")
|
|
144
144
|
const retryAfter = res.headers.get("retry-after")
|
|
145
145
|
if (res.status === 429) {
|
|
146
146
|
const ms = retryAfter ? Number(retryAfter) * 1000 : undefined
|
|
@@ -262,12 +262,23 @@ export function createResponsesProvider(config: ResponsesConfig): ModelProvider
|
|
|
262
262
|
// budget/cost (buta spend). Bentuk shape sama dengan adapter
|
|
263
263
|
// openai-compat agar kolektor tak perlu tahu provider.
|
|
264
264
|
const u = resp?.usage as
|
|
265
|
-
| {
|
|
265
|
+
| {
|
|
266
|
+
input_tokens?: unknown
|
|
267
|
+
output_tokens?: unknown
|
|
268
|
+
total_tokens?: unknown
|
|
269
|
+
cached_tokens?: unknown
|
|
270
|
+
input_tokens_details?: { cached_tokens?: unknown }
|
|
271
|
+
}
|
|
266
272
|
| undefined
|
|
267
273
|
if (
|
|
268
274
|
u &&
|
|
269
275
|
(u.input_tokens != null || u.output_tokens != null || u.total_tokens != null)
|
|
270
276
|
) {
|
|
277
|
+
// Fase 7: cache-hit alias (input_tokens_details.cached_tokens / cached_tokens).
|
|
278
|
+
const cached =
|
|
279
|
+
(u.input_tokens_details?.cached_tokens !== undefined
|
|
280
|
+
? u.input_tokens_details.cached_tokens
|
|
281
|
+
: u.cached_tokens) ?? undefined
|
|
271
282
|
yield {
|
|
272
283
|
type: "extension",
|
|
273
284
|
kind: "usage",
|
|
@@ -276,6 +287,7 @@ export function createResponsesProvider(config: ResponsesConfig): ModelProvider
|
|
|
276
287
|
outputTokens:
|
|
277
288
|
typeof u.output_tokens === "number" ? u.output_tokens : undefined,
|
|
278
289
|
totalTokens: typeof u.total_tokens === "number" ? u.total_tokens : undefined,
|
|
290
|
+
...(typeof cached === "number" ? { cacheReadTokens: cached } : {}),
|
|
279
291
|
},
|
|
280
292
|
}
|
|
281
293
|
}
|
|
@@ -99,16 +99,29 @@ export function boundedSseBody(
|
|
|
99
99
|
})
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
/** Body error dibaca secukupnya untuk kategori/pesan, lalu sisa stream dibuang.
|
|
103
|
-
|
|
102
|
+
/** Body error dibaca secukupnya untuk kategori/pesan, lalu sisa stream dibuang.
|
|
103
|
+
* `signal` membuat pembacaan abort-aware: server yang mengembalikan status error
|
|
104
|
+
* lalu menstall body-nya tidak boleh menggantung reader selamanya — cancel reader
|
|
105
|
+
* saat abort sehingga jalur error tetap terbatas waktu. */
|
|
106
|
+
export async function readProviderErrorBody(
|
|
107
|
+
response: Response,
|
|
108
|
+
signal?: AbortSignal,
|
|
109
|
+
): Promise<string> {
|
|
104
110
|
if (!response.body) return ""
|
|
111
|
+
if (signal?.aborted) return ""
|
|
105
112
|
const reader = response.body.getReader()
|
|
106
113
|
const chunks: Uint8Array[] = []
|
|
107
114
|
let size = 0
|
|
108
115
|
let reachedEof = false
|
|
116
|
+
const onAbort = () => {
|
|
117
|
+
void reader.cancel(signal?.reason).catch(() => {})
|
|
118
|
+
}
|
|
119
|
+
signal?.addEventListener("abort", onAbort, { once: true })
|
|
109
120
|
try {
|
|
110
121
|
while (size < LIMITS.PROVIDER_ERROR_BODY_MAX_BYTES) {
|
|
122
|
+
if (signal?.aborted) break
|
|
111
123
|
const { done, value } = await reader.read()
|
|
124
|
+
if (signal?.aborted) break
|
|
112
125
|
if (done) {
|
|
113
126
|
reachedEof = true
|
|
114
127
|
break
|
|
@@ -121,6 +134,7 @@ export async function readProviderErrorBody(response: Response): Promise<string>
|
|
|
121
134
|
}
|
|
122
135
|
return Buffer.concat(chunks.map((chunk) => Buffer.from(chunk))).toString("utf8")
|
|
123
136
|
} finally {
|
|
137
|
+
signal?.removeEventListener("abort", onAbort)
|
|
124
138
|
if (!reachedEof) await reader.cancel().catch(() => {})
|
|
125
139
|
reader.releaseLock()
|
|
126
140
|
}
|
|
@@ -891,6 +891,22 @@ export function loadPresentationEvents(id: string, cwd?: string): DomainEvent[]
|
|
|
891
891
|
return loadPresentationEventsWithStats(id, cwd).events
|
|
892
892
|
}
|
|
893
893
|
|
|
894
|
+
/** Hitung kompaksi durable via kolom `type` (jangan muat+decode seluruh
|
|
895
|
+
* presentation_events — resume dulu tarik semua baris hanya untuk hitung revisi). */
|
|
896
|
+
export function countDurableCompactionEvents(sessionId: string, cwd?: string): number {
|
|
897
|
+
const db = open(cwd)
|
|
898
|
+
try {
|
|
899
|
+
const row = db
|
|
900
|
+
.prepare(
|
|
901
|
+
"SELECT COUNT(*) AS n FROM presentation_events WHERE session_id = ? AND type = 'context.compacted'",
|
|
902
|
+
)
|
|
903
|
+
.get(sessionId) as { n: number } | null
|
|
904
|
+
return row?.n ?? 0
|
|
905
|
+
} finally {
|
|
906
|
+
db.close()
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
|
|
894
910
|
// P2.12 — baca rentang untuk replay konsumen. WAJIB ada: `loadPresentationEvents`
|
|
895
911
|
// memuat SELURUH riwayat ke memori, dan konsumen yang attach dengan offset lama
|
|
896
912
|
// akan menarik seluruh sesi (ratusan ribu baris) hanya untuk 200 event terakhir
|
|
@@ -1557,6 +1573,46 @@ export function loadSession(
|
|
|
1557
1573
|
}
|
|
1558
1574
|
}
|
|
1559
1575
|
|
|
1576
|
+
/**
|
|
1577
|
+
* Meta sesi TANPA decode histori pesan. Jalur resume hanya butuh turnCount/
|
|
1578
|
+
* workMode/system/cwd; histori penuh dibaca SEKALI lewat `loadThreadHistoryWithSeq`.
|
|
1579
|
+
* Memisahkan meta dari decode menutup bug perf: dulu resume memanggil `loadSession`
|
|
1580
|
+
* (decode SEMUA messages) + `loadThreadHistoryWithSeq` (decode lagi) — dua kali
|
|
1581
|
+
* JSON.parse seluruh histori.
|
|
1582
|
+
*/
|
|
1583
|
+
export function loadSessionMeta(
|
|
1584
|
+
id: string,
|
|
1585
|
+
cwd?: string,
|
|
1586
|
+
): {
|
|
1587
|
+
system?: string
|
|
1588
|
+
cwd?: string
|
|
1589
|
+
turnCount: number
|
|
1590
|
+
workMode?: "DISCUSS" | "PLAN" | "EXECUTE"
|
|
1591
|
+
} | null {
|
|
1592
|
+
const db = open(cwd)
|
|
1593
|
+
try {
|
|
1594
|
+
const sess = db.prepare("SELECT system, cwd, work_mode FROM sessions WHERE id = ?").get(id) as {
|
|
1595
|
+
system: string
|
|
1596
|
+
cwd: string
|
|
1597
|
+
work_mode: string | null
|
|
1598
|
+
} | null
|
|
1599
|
+
if (!sess) return null
|
|
1600
|
+
const turnRow = db
|
|
1601
|
+
.prepare("SELECT MAX(turn_idx) AS m FROM turns WHERE session_id = ?")
|
|
1602
|
+
.get(id) as { m: number | null } | null
|
|
1603
|
+
const turnCount = turnRow?.m != null ? turnRow.m + 1 : 0
|
|
1604
|
+
const workMode = parseStoredWorkMode(sess.work_mode)
|
|
1605
|
+
return {
|
|
1606
|
+
system: sess.system,
|
|
1607
|
+
cwd: sess.cwd,
|
|
1608
|
+
turnCount,
|
|
1609
|
+
...(workMode ? { workMode } : {}),
|
|
1610
|
+
}
|
|
1611
|
+
} finally {
|
|
1612
|
+
db.close()
|
|
1613
|
+
}
|
|
1614
|
+
}
|
|
1615
|
+
|
|
1560
1616
|
// P2.4: baca histori SATU thread (ketat: tanpa NULL transisional).
|
|
1561
1617
|
// Beda dari loadSession (kompatibel): di sini thread scope eksplisit.
|
|
1562
1618
|
export function loadThreadHistory(sessionId: string, threadId: string, cwd?: string): unknown[] {
|
|
@@ -13,6 +13,7 @@ import { t } from "../i18n/locale.ts"
|
|
|
13
13
|
import { askLine } from "../input/input.ts"
|
|
14
14
|
import { sanitizeAnsiLine } from "../render/sanitize.ts"
|
|
15
15
|
import { c } from "../render/theme.ts"
|
|
16
|
+
import { truncateToWidth } from "../render/width.ts"
|
|
16
17
|
import { getApprovalSink } from "../tui/transcript.ts"
|
|
17
18
|
|
|
18
19
|
/** Subset struktural tool call yang dibutuhkan view — tanpa tipe kernel. */
|
|
@@ -73,10 +74,16 @@ export async function promptAsk(call: ApprovalRequest): Promise<"allow" | "deny"
|
|
|
73
74
|
const toolName = sanitizeAnsiLine(call.name)
|
|
74
75
|
const args = (call.args ?? {}) as Record<string, unknown>
|
|
75
76
|
|
|
77
|
+
// Sanitasi DULU, potong SESUDAH: `slice` mentah bisa membelah surrogate
|
|
78
|
+
// pair (byte U+FFFD di layar) dan memotong sekuens ANSI di tengah sehingga
|
|
79
|
+
// ekor `\x1b[` menggantung (terminal menelan output berikutnya sebagai
|
|
80
|
+
// parameter CSI) — audit 2026-11-12, MEDIUM-1.
|
|
81
|
+
const summarize = (value: unknown, max: number): string =>
|
|
82
|
+
truncateToWidth(sanitizeAnsiLine(String(value)), max, "…")
|
|
76
83
|
let actionSummary = ""
|
|
77
|
-
if (args.command) actionSummary = `${t("appr.cmdLabel")} ${
|
|
78
|
-
else if (args.path) actionSummary = `${t("appr.fileLabel")} ${
|
|
79
|
-
else if (args.query) actionSummary = `${t("appr.queryLabel")} ${
|
|
84
|
+
if (args.command) actionSummary = `${t("appr.cmdLabel")} ${summarize(args.command, 100)}`
|
|
85
|
+
else if (args.path) actionSummary = `${t("appr.fileLabel")} ${summarize(args.path, 100)}`
|
|
86
|
+
else if (args.query) actionSummary = `${t("appr.queryLabel")} ${summarize(args.query, 100)}`
|
|
80
87
|
else {
|
|
81
88
|
let json = ""
|
|
82
89
|
try {
|
|
@@ -84,7 +91,7 @@ export async function promptAsk(call: ApprovalRequest): Promise<"allow" | "deny"
|
|
|
84
91
|
} catch {
|
|
85
92
|
json = String(args)
|
|
86
93
|
}
|
|
87
|
-
actionSummary = `${t("appr.argsLabel")} ${json
|
|
94
|
+
actionSummary = `${t("appr.argsLabel")} ${summarize(json, 100)}`
|
|
88
95
|
}
|
|
89
96
|
actionSummary = sanitizeAnsiLine(actionSummary)
|
|
90
97
|
|
|
@@ -162,7 +169,9 @@ export async function promptAskText(question: string, options?: string[]): Promi
|
|
|
162
169
|
// Paritas promptAsk: tanpa sink + stdout pipe = jawab tak terlihat & pipe
|
|
163
170
|
// tercemar → batal fail-closed.
|
|
164
171
|
if (!textSink && !process.stdout.isTTY) return null
|
|
165
|
-
|
|
172
|
+
// Potong SESUDAH sanitasi lewat truncateToWidth (bukan `slice`): `slice`
|
|
173
|
+
// bisa menyisakan `\x1b[` menggantung di ekor potongan.
|
|
174
|
+
const q = truncateToWidth(sanitizeAnsiLine(question), 2000, "…")
|
|
166
175
|
const block = [
|
|
167
176
|
``,
|
|
168
177
|
`${c.warning(c.bold(t("appr.askTitle")))}`,
|
|
@@ -188,7 +197,9 @@ export async function promptAskText(question: string, options?: string[]): Promi
|
|
|
188
197
|
if (ans == null || !ans.trim()) return null
|
|
189
198
|
const out = ans.trim()
|
|
190
199
|
if (sink) {
|
|
191
|
-
|
|
200
|
+
// Gema jawaban juga dipotong lewat truncateToWidth: `slice` bisa membelah
|
|
201
|
+
// surrogate pair (emoji → U+FFFD) atau menyisakan escape menggantung.
|
|
202
|
+
sink.pushBlock([c.muted(` → ${truncateToWidth(sanitizeAnsiLine(out), 200, "…")}`)])
|
|
192
203
|
sink.repaint()
|
|
193
204
|
}
|
|
194
205
|
return out
|
|
@@ -615,7 +615,7 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
|
|
|
615
615
|
const lines = renderActivityPanel(snap.activities, { maxRows: 10 })
|
|
616
616
|
if (lines.length > 0) {
|
|
617
617
|
wErr(c.muted(`${t("panel.header")}\n`))
|
|
618
|
-
for (const line of lines) wErr(
|
|
618
|
+
for (const line of lines) wErr(`${line}\n`)
|
|
619
619
|
}
|
|
620
620
|
}
|
|
621
621
|
}
|
package/src/ui/footer.ts
CHANGED
|
@@ -108,7 +108,7 @@ export function paintPermissionMode(mode: string, style: ModeLabelStyle = "full"
|
|
|
108
108
|
* jadi dirender jelas (bukan redup). */
|
|
109
109
|
export function paintBashStrict(strictBash?: boolean, unrestricted = false): string {
|
|
110
110
|
if (unrestricted) return c.info(glyphs.unlock)
|
|
111
|
-
return strictBash ? c.yellow(glyphs.lock) : c.
|
|
111
|
+
return strictBash ? c.yellow(glyphs.lock) : c.gray(glyphs.lock)
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
/** Spark glyph: redup saat idle, pulse putih↔abu saat busy (frame genap/ganjil). */
|
|
@@ -119,7 +119,7 @@ function sparkGlyph(frame: number): string {
|
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
function paintTimer(text: string, active: boolean, highlight: TimerHighlight = "seconds"): string {
|
|
122
|
-
if (!active) return c.
|
|
122
|
+
if (!active) return c.gray(text)
|
|
123
123
|
const parts = text.split(".")
|
|
124
124
|
if (parts.length !== 3) return c.white(text)
|
|
125
125
|
const rank: Record<TimerHighlight, number> = { seconds: 1, minutes: 2, hours: 3 }
|
package/src/ui/i18n/en.ts
CHANGED
|
@@ -37,9 +37,15 @@ export const en = {
|
|
|
37
37
|
"appr.tier.unknown": "unknown effect",
|
|
38
38
|
"dlg.more": "… {n} more",
|
|
39
39
|
"ts.compacted": "… compacted: {reason}",
|
|
40
|
+
"ts.compactedNoOp": "… compacted: nothing evictable ({reason}) — context did not shrink",
|
|
41
|
+
"ts.compactedFixpoint": "… compaction stopped: target unreachable with only {kept} messages left",
|
|
42
|
+
"ts.compactedImpossible":
|
|
43
|
+
"… compaction impossible: fixed instructions + tool schemas ({fixed}) already exceed the {trigger} threshold",
|
|
44
|
+
"ts.compactedLlmFailed": "… LLM summary failed ({reason}), using mechanical summary",
|
|
45
|
+
"ts.contextWindowSource": "context {tokens} tokens ({source})",
|
|
40
46
|
"ts.providerAttemptDiscarded": "provider attempt {attempt} failed; partial output was discarded",
|
|
41
47
|
"ts.thinking": "… thinking",
|
|
42
|
-
"ts.evictMarker": "… {n} early lines outside viewport
|
|
48
|
+
"ts.evictMarker": "… {n} early lines outside viewport",
|
|
43
49
|
"ts.statusRunning": "running",
|
|
44
50
|
"ts.statusCompleted": "completed",
|
|
45
51
|
"ts.statusFailed": "failed",
|
|
@@ -72,7 +78,7 @@ export const en = {
|
|
|
72
78
|
"model.del": 'Delete model "{id}"?',
|
|
73
79
|
"model.failOpen": "model manager failed to open: {msg}",
|
|
74
80
|
"effort.title": "Thinking effort",
|
|
75
|
-
"effort.saved": "Thinking: {effort} (next session)",
|
|
81
|
+
"effort.saved": "Thinking effort: {effort} (next session)",
|
|
76
82
|
"prov.empty": "No providers",
|
|
77
83
|
"prov.addTitle": "Add provider",
|
|
78
84
|
"prov.customUrl": "Custom URL",
|
|
@@ -128,11 +134,20 @@ export const en = {
|
|
|
128
134
|
"st.input": " Input: {v} (provider usage)",
|
|
129
135
|
"st.output": " Output: {v} (provider usage)",
|
|
130
136
|
"st.total": " Total: {v} (session cumulative)",
|
|
137
|
+
"st.cache": " Cache: {read} hit · {write} write (prompt cache)",
|
|
131
138
|
"st.cost": " Cost: {v} (estimated from price table)",
|
|
132
139
|
"st.budget": " Budget: {v}{extra}",
|
|
133
140
|
"st.costUnknown": " (cost unknown — model without pricing)",
|
|
134
141
|
"help.head": "Commands:",
|
|
135
142
|
"help.keysLine": "Mouse wheel/PgUp/PgDn scroll (Shift = half) · /help keys = all shortcuts",
|
|
143
|
+
"hint.move": "move",
|
|
144
|
+
"hint.select": "select",
|
|
145
|
+
"hint.close": "close",
|
|
146
|
+
"hint.filter": "filter",
|
|
147
|
+
"hint.delete": "delete",
|
|
148
|
+
"hint.edit": "edit",
|
|
149
|
+
"hint.add": "add",
|
|
150
|
+
"hint.effort": "effort",
|
|
136
151
|
"help.cHead": "Commands:",
|
|
137
152
|
"help.cKeys":
|
|
138
153
|
"Keys: Tab work-mode · Shift+Tab permission · ↑↓ history · Mouse wheel/PgUp/PgDn scroll · Ctrl+R search · Ctrl+D exit",
|
|
@@ -239,8 +254,8 @@ export const en = {
|
|
|
239
254
|
"tui.workModeLine": "work mode: {m}",
|
|
240
255
|
"tui.workModeUsage": "usage: /work-mode <DISCUSS|PLAN|BUILD> — current: {m}",
|
|
241
256
|
"tui.workModeUnavailable": "work mode is not available in this session",
|
|
242
|
-
"tui.unrestrictedOn": "
|
|
243
|
-
"tui.unrestrictedOff": "
|
|
257
|
+
"tui.unrestrictedOn": "unrestricted mode enabled - full access",
|
|
258
|
+
"tui.unrestrictedOff": "unrestricted disabled — permission mode restored to {m}",
|
|
244
259
|
"tui.langLine": "lang: {v}",
|
|
245
260
|
"tui.toolCall": "tool call: {v}",
|
|
246
261
|
"tui.modelSet": "model: {v}",
|
|
@@ -312,7 +327,7 @@ export const en = {
|
|
|
312
327
|
"err.timeout": "Run exceeded timeout",
|
|
313
328
|
"err.timeoutFix": "Increase --timeout or use a faster model.",
|
|
314
329
|
"err.steps": "Tool step limit reached",
|
|
315
|
-
"err.stepsFix": "
|
|
330
|
+
"err.stepsFix": "Progress is saved — run /resume to continue, or raise --max-steps.",
|
|
316
331
|
"err.budget": "Session budget exceeded",
|
|
317
332
|
"err.budgetFix": "Start a new session or increase --budget.",
|
|
318
333
|
"err.busy": "A run is still in progress",
|
|
@@ -339,4 +354,12 @@ export const en = {
|
|
|
339
354
|
"loading.rag": "loading context",
|
|
340
355
|
"loading.session": "preparing session",
|
|
341
356
|
"loading.finalize": "finalizing",
|
|
357
|
+
"diff.noChanges": "(no changes)",
|
|
358
|
+
"diff.truncated": "… diff truncated — input too large",
|
|
359
|
+
"tbl.noColumns": "(no columns)",
|
|
360
|
+
"tbl.noEntries": "(no entries)",
|
|
361
|
+
"summary.session": "Session",
|
|
362
|
+
"summary.model": "Model",
|
|
363
|
+
"summary.usage": "Usage",
|
|
364
|
+
"summary.tokens": "tokens",
|
|
342
365
|
} as const
|
package/src/ui/i18n/id.ts
CHANGED
|
@@ -38,9 +38,17 @@ export const id: Record<MsgKey, string> = {
|
|
|
38
38
|
"appr.tier.unknown": "efek tidak diketahui",
|
|
39
39
|
"dlg.more": "… {n} lagi",
|
|
40
40
|
"ts.compacted": "… dipadatkan: {reason}",
|
|
41
|
+
"ts.compactedNoOp":
|
|
42
|
+
"… dipadatkan: tidak ada yang bisa dibuang ({reason}) — konteks tidak menyusut",
|
|
43
|
+
"ts.compactedFixpoint":
|
|
44
|
+
"… kompaksi berhenti: target tak tercapai meski hanya {kept} pesan tersisa",
|
|
45
|
+
"ts.compactedImpossible":
|
|
46
|
+
"… kompaksi mustahil: instruksi tetap + skema tool ({fixed}) sudah melebihi ambang {trigger}",
|
|
47
|
+
"ts.compactedLlmFailed": "… ringkasan LLM gagal ({reason}), memakai ringkasan mekanikal",
|
|
48
|
+
"ts.contextWindowSource": "konteks {tokens} token ({source})",
|
|
41
49
|
"ts.providerAttemptDiscarded": "percobaan provider {attempt} gagal; output parsial dibuang",
|
|
42
50
|
"ts.thinking": "… berpikir",
|
|
43
|
-
"ts.evictMarker": "… {n} baris awal di luar viewport
|
|
51
|
+
"ts.evictMarker": "… {n} baris awal di luar viewport",
|
|
44
52
|
"ts.statusRunning": "berjalan",
|
|
45
53
|
"ts.statusCompleted": "selesai",
|
|
46
54
|
"ts.statusFailed": "gagal",
|
|
@@ -73,7 +81,7 @@ export const id: Record<MsgKey, string> = {
|
|
|
73
81
|
"model.del": 'Hapus model "{id}"?',
|
|
74
82
|
"model.failOpen": "model manager gagal dibuka: {msg}",
|
|
75
83
|
"effort.title": "Upaya berpikir",
|
|
76
|
-
"effort.saved": "
|
|
84
|
+
"effort.saved": "Upaya berpikir: {effort} (sesi berikut)",
|
|
77
85
|
"prov.empty": "Belum ada penyedia",
|
|
78
86
|
"prov.addTitle": "Tambah penyedia",
|
|
79
87
|
"prov.customUrl": "URL kustom",
|
|
@@ -129,11 +137,20 @@ export const id: Record<MsgKey, string> = {
|
|
|
129
137
|
"st.input": " Masukan: {v} (pemakaian provider)",
|
|
130
138
|
"st.output": " Keluaran: {v} (pemakaian provider)",
|
|
131
139
|
"st.total": " Total: {v} (kumulatif sesi)",
|
|
140
|
+
"st.cache": " Cache: {read} hit · {write} tulis (prompt cache)",
|
|
132
141
|
"st.cost": " Biaya: {v} (estimasi tabel harga)",
|
|
133
142
|
"st.budget": " Budget: {v}{extra}",
|
|
134
143
|
"st.costUnknown": " (biaya tak diketahui — model tanpa harga)",
|
|
135
144
|
"help.head": "Perintah:",
|
|
136
145
|
"help.keysLine": "Mouse wheel/PgUp/PgDn gulir (Shift = ½) · /help tombol = semua pintasan",
|
|
146
|
+
"hint.move": "gerak",
|
|
147
|
+
"hint.select": "pilih",
|
|
148
|
+
"hint.close": "tutup",
|
|
149
|
+
"hint.filter": "saring",
|
|
150
|
+
"hint.delete": "hapus",
|
|
151
|
+
"hint.edit": "ubah",
|
|
152
|
+
"hint.add": "tambah",
|
|
153
|
+
"hint.effort": "upaya",
|
|
137
154
|
"help.cHead": "Perintah:",
|
|
138
155
|
"help.cKeys":
|
|
139
156
|
"Tombol: Tab work-mode · Shift+Tab izin · ↑↓ riwayat · Mouse wheel/PgUp/PgDn gulir · Ctrl+R cari · Ctrl+D keluar",
|
|
@@ -240,8 +257,8 @@ export const id: Record<MsgKey, string> = {
|
|
|
240
257
|
"tui.workModeLine": "mode kerja: {m}",
|
|
241
258
|
"tui.workModeUsage": "pemakaian: /work-mode <DISCUSS|PLAN|BUILD> — aktif: {m}",
|
|
242
259
|
"tui.workModeUnavailable": "work mode tidak tersedia di sesi ini",
|
|
243
|
-
"tui.unrestrictedOn": "
|
|
244
|
-
"tui.unrestrictedOff": "
|
|
260
|
+
"tui.unrestrictedOn": "mode unrestricted aktif - akses penuh",
|
|
261
|
+
"tui.unrestrictedOff": "unrestricted nonaktif — mode izin kembali ke {m}",
|
|
245
262
|
"tui.langLine": "lang: {v}",
|
|
246
263
|
"tui.toolCall": "pemanggilan tool: {v}",
|
|
247
264
|
"tui.modelSet": "model: {v}",
|
|
@@ -314,7 +331,7 @@ export const id: Record<MsgKey, string> = {
|
|
|
314
331
|
"err.timeout": "Run melewati batas waktu",
|
|
315
332
|
"err.timeoutFix": "Naikkan --timeout atau pakai model lebih cepat.",
|
|
316
333
|
"err.steps": "Batas langkah tool tercapai",
|
|
317
|
-
"err.stepsFix": "
|
|
334
|
+
"err.stepsFix": "Progres sudah tersimpan — lanjutkan via /resume, atau naikkan --max-steps.",
|
|
318
335
|
"err.budget": "Budget sesi terlampaui",
|
|
319
336
|
"err.budgetFix": "Mulai sesi baru atau naikkan --budget.",
|
|
320
337
|
"err.busy": "Run masih berjalan",
|
|
@@ -341,4 +358,12 @@ export const id: Record<MsgKey, string> = {
|
|
|
341
358
|
"loading.rag": "memuat konteks",
|
|
342
359
|
"loading.session": "menyiapkan sesi",
|
|
343
360
|
"loading.finalize": "menyelesaikan",
|
|
361
|
+
"diff.noChanges": "(tidak ada perubahan)",
|
|
362
|
+
"diff.truncated": "… diff dipotong — input terlalu besar",
|
|
363
|
+
"tbl.noColumns": "(tanpa kolom)",
|
|
364
|
+
"tbl.noEntries": "(tanpa entri)",
|
|
365
|
+
"summary.session": "Sesi",
|
|
366
|
+
"summary.model": "Model",
|
|
367
|
+
"summary.usage": "Pemakaian",
|
|
368
|
+
"summary.tokens": "token",
|
|
344
369
|
}
|
package/src/ui/input/input.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { homedir } from "node:os"
|
|
|
3
3
|
import { join } from "node:path"
|
|
4
4
|
import { createInterface } from "node:readline"
|
|
5
5
|
import { t } from "../i18n/locale.ts"
|
|
6
|
-
import { stripAnsi } from "../render/theme.ts"
|
|
6
|
+
import { glyphs, stripAnsi } from "../render/theme.ts"
|
|
7
7
|
import { displayWidth, escapeLength, truncateToWidth } from "../render/width.ts"
|
|
8
8
|
import { beginInteractiveScreen } from "../runtime/statusline.ts"
|
|
9
9
|
import {
|
|
@@ -877,7 +877,7 @@ export async function askSecret(
|
|
|
877
877
|
.replace(/[\u0000-\u0008\u000b-\u001f\u007f]/g, "")
|
|
878
878
|
if (clean) {
|
|
879
879
|
secret += clean
|
|
880
|
-
process.stdout.write(
|
|
880
|
+
process.stdout.write(glyphs.mask.repeat(toGraphemes(clean).length))
|
|
881
881
|
}
|
|
882
882
|
}
|
|
883
883
|
}
|
|
@@ -232,6 +232,12 @@ export function applyKey(
|
|
|
232
232
|
.replace(/\t/g, " ")
|
|
233
233
|
// biome-ignore lint/suspicious/noControlCharactersInRegex: membuang byte kontrol dari paste
|
|
234
234
|
.replace(/[\u0000-\u0008\u000b-\u001f\u007f]/g, "")
|
|
235
|
+
// C1 (0x80–0x9F) juga dibuang: U+009B bertindak sebagai CSI di banyak
|
|
236
|
+
// terminal, jadi paste bisa menyuntik escape TANPA byte ESC — melewati
|
|
237
|
+
// filter di atas dan gate sanitize (buffer composer dilukis apa adanya).
|
|
238
|
+
.replace(/[\u0080-\u009f]/g, "")
|
|
239
|
+
// Separator garis/paragraf Unicode = pindah baris di sebagian terminal.
|
|
240
|
+
.replace(/[\u2028\u2029]/g, "\n")
|
|
235
241
|
if (!ins) return { state, action: "none" }
|
|
236
242
|
const { line, cursor } = insertAt(state.line, state.cursor, ins)
|
|
237
243
|
return { state: withLine(line, cursor), action: "render" }
|
|
@@ -10,6 +10,7 @@ import type { UiPresentationActivity } from "../contract.ts"
|
|
|
10
10
|
import { t } from "../i18n/locale.ts"
|
|
11
11
|
import { activityGroup } from "./activity-group.ts"
|
|
12
12
|
import { sanitizeAnsiLine, stripSgr } from "./sanitize.ts"
|
|
13
|
+
import { c } from "./theme.ts"
|
|
13
14
|
import { truncateToWidth } from "./width.ts"
|
|
14
15
|
/** Satu grup teragregasi (dipakai renderer + /expand buffer). */
|
|
15
16
|
export interface ActivityGroupView {
|
|
@@ -22,6 +23,8 @@ export interface ActivityGroupView {
|
|
|
22
23
|
denied: number
|
|
23
24
|
/** Nama tool pertama (indikator; sudah tersanitasi & terpotong). */
|
|
24
25
|
names: string[]
|
|
26
|
+
/** Total nama tool unik (sebelum dibatasi 3) untuk penanda `+N`. */
|
|
27
|
+
nameTotal: number
|
|
25
28
|
}
|
|
26
29
|
|
|
27
30
|
const MAX_PANEL_LABEL = 40
|
|
@@ -32,12 +35,15 @@ export function groupActivities(
|
|
|
32
35
|
activities: readonly UiPresentationActivity[],
|
|
33
36
|
): Map<string, ActivityGroupView> {
|
|
34
37
|
const groups = new Map<string, ActivityGroupView>()
|
|
38
|
+
// Nama unik per grup (untuk penanda `+N` saat > 3 nama berbeda).
|
|
39
|
+
const uniqueNames = new Map<string, Set<string>>()
|
|
35
40
|
for (const a of activities) {
|
|
36
41
|
const kind = activityGroup(a.name)
|
|
37
42
|
let g = groups.get(kind)
|
|
38
43
|
if (!g) {
|
|
39
|
-
g = { kind, count: 0, ok: 0, failed: 0, running: 0, denied: 0, names: [] }
|
|
44
|
+
g = { kind, count: 0, ok: 0, failed: 0, running: 0, denied: 0, names: [], nameTotal: 0 }
|
|
40
45
|
groups.set(kind, g)
|
|
46
|
+
uniqueNames.set(kind, new Set())
|
|
41
47
|
}
|
|
42
48
|
g.count++
|
|
43
49
|
const status = a.status
|
|
@@ -48,11 +54,21 @@ export function groupActivities(
|
|
|
48
54
|
// Nama tool dari model/provider = input tak-terpercaya: buang SEMUA ANSI
|
|
49
55
|
// (termasuk SGR) saat masuk — styling ditambahkan renderer sendiri.
|
|
50
56
|
const cleanName = stripSgr(sanitizeAnsiLine(a.name))
|
|
57
|
+
const seen = uniqueNames.get(kind)!
|
|
58
|
+
seen.add(cleanName)
|
|
59
|
+
g.nameTotal = seen.size
|
|
51
60
|
if (g.names.length < 3 && !g.names.includes(cleanName)) g.names.push(cleanName)
|
|
52
61
|
}
|
|
53
62
|
return groups
|
|
54
63
|
}
|
|
55
64
|
|
|
65
|
+
/** Warna grup: gagal → merah, ditolak → kuning, sisanya → redup (tenang). */
|
|
66
|
+
function groupPaint(g: ActivityGroupView): (s: string) => string {
|
|
67
|
+
if (g.failed > 0) return c.error
|
|
68
|
+
if (g.denied > 0) return c.warning
|
|
69
|
+
return c.muted
|
|
70
|
+
}
|
|
71
|
+
|
|
56
72
|
/** Satu baris grup (`+ explore · 3 tools · 2 ok · 1 failed`). */
|
|
57
73
|
export function groupLine(g: ActivityGroupView): string {
|
|
58
74
|
// Kunci i18n literal (bukan template) — MsgKey adalah union, bukan string.
|
|
@@ -69,8 +85,10 @@ export function groupLine(g: ActivityGroupView): string {
|
|
|
69
85
|
if (g.failed > 0) parts.push(t("panel.failed", { n: g.failed }))
|
|
70
86
|
if (g.running > 0) parts.push(t("panel.running", { n: g.running }))
|
|
71
87
|
const names = g.names.map((n) => sanitizeAnsiLine(n)).join(", ")
|
|
72
|
-
|
|
73
|
-
|
|
88
|
+
const more = Math.max(0, g.nameTotal - g.names.length)
|
|
89
|
+
if (names)
|
|
90
|
+
parts.push(`· ${truncateToWidth(names, MAX_PANEL_LABEL, "…")}${more > 0 ? ` +${more}` : ""}`)
|
|
91
|
+
return groupPaint(g)(parts.join(" "))
|
|
74
92
|
}
|
|
75
93
|
|
|
76
94
|
/** Baris panel lengkap (header + satu baris per grup). Kosong bila tak ada
|