minicode-ai 0.15.0 → 0.20.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 +6 -4
- package/cli/commands/exec.ts +3 -2
- package/cli/commands/openwork.ts +1 -1
- package/cli/commands.ts +6 -6
- package/cli/index.ts +4 -4
- package/cli/model-manager.ts +1 -1
- package/cli/setup.ts +57 -30
- package/cli/tui.ts +106 -11
- package/docs/CONTROL-PLANE-MAP.md +6 -4
- package/docs/OUTPUT_EVENT_MODEL.md +4 -3
- package/docs/OUTPUT_PROTOCOL_SPEC.md +1 -1
- package/docs/OUTPUT_RENDERING_SPEC.md +16 -4
- package/docs/OUTPUT_UX_RULES.md +38 -32
- package/docs/P14_OPEN_WORK.md +290 -0
- package/docs/README.md +1 -1
- package/docs/SUMMARY.md +36 -22
- package/docs/TERMINAL_CONTRACT.md +54 -7
- package/docs/UI_RENDER_PIPELINE.md +47 -8
- package/docs/agents.md +1 -1
- package/docs/architecture.md +9 -8
- package/docs/autonomous-scheduler.md +142 -0
- package/docs/choosing-mode.md +2 -2
- package/docs/cli.md +4 -4
- package/docs/concepts.md +5 -5
- package/docs/config-providers.md +3 -3
- package/docs/contributing.md +7 -9
- package/docs/environment.md +5 -4
- package/docs/getting-started.md +4 -4
- package/docs/mcp-lsp.md +2 -2
- package/docs/memory-sessions.md +1 -1
- package/docs/policy-sandbox.md +7 -4
- package/docs/pricing-budget.md +3 -3
- package/docs/quickstart.md +1 -1
- package/docs/repl.md +5 -5
- package/docs/security-model.md +1 -1
- package/docs/security.md +9 -8
- package/docs/skills.md +2 -2
- package/docs/terminal.md +10 -2
- package/docs/tools.md +4 -4
- package/docs/troubleshooting.md +3 -3
- package/docs/verify-benchmark.md +0 -3
- package/package.json +9 -18
- package/src/app/session.ts +40 -7
- package/src/constants.ts +31 -0
- package/src/hooks/run.ts +5 -6
- package/src/mcp/http-transport.ts +1 -1
- package/src/policy/bash-guard.ts +26 -6
- package/src/policy/compaction.ts +107 -17
- package/src/policy/consequence-engine.ts +3 -3
- package/src/policy/context-window.ts +24 -1
- package/src/policy/context.ts +16 -4
- package/src/policy/permission.ts +219 -4
- package/src/presentation/adapter.ts +1 -1
- package/src/presentation/events.ts +2 -2
- package/src/presentation/label.ts +3 -3
- package/src/presentation/model.ts +4 -0
- package/src/presentation/store.ts +2 -2
- package/src/runtime/child-execution.ts +1 -1
- package/src/runtime/composition.ts +5 -5
- package/src/runtime/execution-registry.ts +1 -1
- package/src/runtime/production-execution.ts +3 -3
- package/src/runtime/production-runtime.ts +2 -2
- package/src/runtime/runtime-capabilities.ts +1 -1
- package/src/runtime/runtime-status-facts.ts +1 -1
- package/src/runtime/runtime-task-admission.ts +2 -2
- package/src/session/context-assembly.ts +8 -1
- package/src/session/context-identity.ts +2 -2
- package/src/session/context-projection.ts +36 -11
- package/src/session/persistence.ts +1 -1
- package/src/task/autonomous-context.ts +2 -2
- package/src/task/autonomous-policy.ts +3 -3
- package/src/task/model.ts +2 -2
- package/src/task/production-scheduler.ts +2 -2
- package/src/task/scheduler.ts +3 -2
- package/src/task/scheduling-policy.ts +2 -1
- package/src/task/trigger.ts +5 -5
- package/src/tools/read_image.ts +2 -1
- package/src/tools/task.ts +1 -1
- package/src/ui/assistant/simple.ts +33 -30
- package/src/ui/footer.ts +48 -9
- package/src/ui/i18n/en.ts +1 -0
- package/src/ui/i18n/id.ts +1 -0
- package/src/ui/input/prompt-engine.ts +36 -10
- package/src/ui/render/cells.ts +320 -0
- package/src/ui/render/composer-wrap.ts +73 -0
- package/src/ui/render/detail.ts +2 -2
- package/src/ui/render/ledger.ts +47 -0
- package/src/ui/render/theme.ts +32 -4
- package/src/ui/render/width.ts +2 -2
- package/src/ui/render/wrap.ts +5 -3
- package/src/ui/runtime/screen.ts +84 -7
- package/src/ui/runtime/statusline.ts +26 -0
- package/src/ui/screens/model-manager.ts +1 -1
- package/src/ui/tui/app.ts +336 -65
- package/src/ui/tui/transcript.ts +247 -88
- package/vendor/minicore/VENDOR.md +15 -11
- package/vendor/minicore/src/core/events.ts +1 -0
- package/vendor/minicore/src/core/loop.ts +10 -0
- package/vendor/minicore/src/core/session.ts +39 -0
|
@@ -187,7 +187,7 @@ export const TOOL_CAPABILITIES: readonly ToolClassification[] = [
|
|
|
187
187
|
capability: "PRIVILEGED",
|
|
188
188
|
autonomous: false,
|
|
189
189
|
evidence:
|
|
190
|
-
"VERIFIED: writes history and identity. The existing sub-agent layer strips it for the same reason (src/tools/task.ts:
|
|
190
|
+
"VERIFIED: writes history and identity. The existing sub-agent layer strips it for the same reason (src/tools/task.ts:309-321).",
|
|
191
191
|
},
|
|
192
192
|
|
|
193
193
|
// ── memory (session state) ──
|
|
@@ -222,7 +222,7 @@ export const TOOL_CAPABILITIES: readonly ToolClassification[] = [
|
|
|
222
222
|
capability: "MUTATING",
|
|
223
223
|
autonomous: false,
|
|
224
224
|
evidence:
|
|
225
|
-
"VERIFIED as a task-ownership hazard, not merely a write: todo_write can author TaskStatus, and under 6P `IN_PROGRESS` is a Scheduler-owned execution state. Letting an autonomous model write it would let a model fabricate a claim the lineage would then treat as real. The existing sub-agent layer strips it for the same reason (src/tools/task.ts:
|
|
225
|
+
"VERIFIED as a task-ownership hazard, not merely a write: todo_write can author TaskStatus, and under 6P `IN_PROGRESS` is a Scheduler-owned execution state. Letting an autonomous model write it would let a model fabricate a claim the lineage would then treat as real. The existing sub-agent layer strips it for the same reason (src/tools/task.ts:309-321).",
|
|
226
226
|
},
|
|
227
227
|
{
|
|
228
228
|
name: "submit_result",
|
|
@@ -235,7 +235,7 @@ export const TOOL_CAPABILITIES: readonly ToolClassification[] = [
|
|
|
235
235
|
capability: "PRIVILEGED",
|
|
236
236
|
autonomous: false,
|
|
237
237
|
evidence:
|
|
238
|
-
"Escalation vector: it creates a child with its OWN permission mode (src/tools/task.ts:
|
|
238
|
+
"Escalation vector: it creates a child with its OWN permission mode (src/tools/task.ts:274-276), so a restricted parent could in principle produce a less-restricted child. Stripped from sub-agents for exactly this reason. Autonomous context has no sessionFactory for delegation at all (6R), so nesting is NOT IMPLEMENTED and cannot occur.",
|
|
239
239
|
},
|
|
240
240
|
|
|
241
241
|
// ── network / external ──
|
package/src/task/model.ts
CHANGED
|
@@ -200,8 +200,8 @@ export type TaskAcceptance = Record<string, unknown>
|
|
|
200
200
|
* Where a task came from.
|
|
201
201
|
*
|
|
202
202
|
* The `rowToTask` default is
|
|
203
|
-
* `{ origin: "runtime", source: "unknown" }` and `
|
|
204
|
-
* `{ origin: "model", source: "todo_write" }`. So `origin` is a closed
|
|
203
|
+
* `{ origin: "runtime", source: "unknown" }` and `synchronizeCanonicalTasks`
|
|
204
|
+
* writes `{ origin: "model", source: "todo_write" }`. So `origin` is a closed
|
|
205
205
|
* two-value union and `source` is an open string.
|
|
206
206
|
*/
|
|
207
207
|
export interface TaskProvenance {
|
|
@@ -212,8 +212,8 @@ export async function createProductionScheduler(
|
|
|
212
212
|
const d = await deps()
|
|
213
213
|
|
|
214
214
|
// [DESIGN DECISION] The tool set is NOT recomputed here. It comes from the
|
|
215
|
-
// caller's
|
|
216
|
-
// the 6S matrix's own
|
|
215
|
+
// caller's adapter.tools, and buildAutonomousRunTurn validates it against
|
|
216
|
+
// the 6S matrix's own assertAutonomousToolScope at construction. Deriving it
|
|
217
217
|
// here would create a THIRD copy of one policy, furthest from the tests that
|
|
218
218
|
// justify it and therefore most likely to drift.
|
|
219
219
|
|
package/src/task/scheduler.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// Phase 6C — Scheduler core: headless, dependency-injected, single-session,
|
|
2
2
|
// serial. NEW ARCHITECTURE.
|
|
3
3
|
//
|
|
4
|
-
// Implements the Phase 6A design lock.
|
|
5
|
-
// src/
|
|
4
|
+
// Implements the Phase 6A design lock. Wired into production via
|
|
5
|
+
// `src/task/production-scheduler.ts` (`new Scheduler(...)`), diaktifkan dari
|
|
6
|
+
// composition root saat scheduler di-enable.
|
|
6
7
|
//
|
|
7
8
|
// ── WHAT IT IS ───────────────────────────────────────────────────────────────
|
|
8
9
|
//
|
|
@@ -158,7 +158,8 @@ export const SELECTION_IS_STARVATION_FREE = true
|
|
|
158
158
|
* [PHASE 6T] The conditional fairness rule, stated now and NOT implemented.
|
|
159
159
|
*
|
|
160
160
|
* Exported so the dependency is machine-visible: when a requeueing authority
|
|
161
|
-
* appears, this is the property that must hold, and
|
|
161
|
+
* appears, this is the property that must hold, and
|
|
162
|
+
* `test/phase6t-trigger-policy-lifecycle.test.ts` asserts
|
|
162
163
|
* the current model satisfies the *unconditional* form.
|
|
163
164
|
*/
|
|
164
165
|
export const ANTISTARVATION_REQUIREMENT =
|
package/src/task/trigger.ts
CHANGED
|
@@ -34,13 +34,13 @@
|
|
|
34
34
|
/**
|
|
35
35
|
* [FACT] Where an evaluation request came from. Classification from survey §2:
|
|
36
36
|
*
|
|
37
|
-
* - `startup` AVAILABLE BUT UNUSED — a composition root exists
|
|
38
|
-
* `cli/setup.ts
|
|
37
|
+
* - `startup` AVAILABLE BUT UNUSED — a composition root exists in
|
|
38
|
+
* `cli/setup.ts`; nothing calls `cycle()` there.
|
|
39
39
|
* - `task-mutation` AVAILABLE BUT UNUSED — `TaskStore.patchTask`/`createTask`
|
|
40
40
|
* emit nothing, so there is no signal to subscribe to.
|
|
41
|
-
* - `explicit-command` AVAILABLE BUT UNUSED — `cli/router.ts` has
|
|
42
|
-
*
|
|
43
|
-
*
|
|
41
|
+
* - `explicit-command` AVAILABLE BUT UNUSED — `cli/router.ts` has 14 subcommands;
|
|
42
|
+
* `openwork` membaca task tapi tak memicu `cycle()`. Adding a
|
|
43
|
+
* trigger subcommand is an enablement decision, out of scope.
|
|
44
44
|
* - `interval` NOT IMPLEMENTED, and deliberately not added: a repeating
|
|
45
45
|
* timer is the one option that would require assuming
|
|
46
46
|
* MiniCode is a long-running server. It is not.
|
package/src/tools/read_image.ts
CHANGED
|
@@ -75,7 +75,8 @@ export const readImageTool: Tool = {
|
|
|
75
75
|
: "image/png"
|
|
76
76
|
const tokens = estimateImageTokens(buf.byteLength)
|
|
77
77
|
// S4 — kirim utuh + laporkan bytes (dulu slice 200k diam-diam → gambar korup).
|
|
78
|
-
// File sudah di-cap
|
|
78
|
+
// File sudah di-cap (READ_FILE_MAX_BYTES + IMAGE_B64_MAX_CHARS) di atas,
|
|
79
|
+
// jadi b64 selalu muat anggaran truncate konteks.
|
|
79
80
|
return `data:${mime};base64,${b64}\n(${buf.byteLength} bytes ${mime}, tokens ~${tokens})`
|
|
80
81
|
},
|
|
81
82
|
}
|
package/src/tools/task.ts
CHANGED
|
@@ -43,7 +43,7 @@ const pool = new Pool(LIMITS.SUB_AGENT_POOL_SIZE)
|
|
|
43
43
|
|
|
44
44
|
// Harness-P2: scope read-only bersama untuk sub-agen explore DAN sesi utama
|
|
45
45
|
// (--tool-scope explore). Satu daftar, satu makna: scoping per fase (pelajaran
|
|
46
|
-
// Vercel: tool minimum per fase, bukan semua
|
|
46
|
+
// Vercel: tool minimum per fase, bukan semua 37 sekaligus). Diuji oleh
|
|
47
47
|
// test/harness-p2 + audit invariant bench/harness-audit.
|
|
48
48
|
// [Fase 2 / TOOL-01] Diimpor dari registry kontrak tool — dulu daftar manual
|
|
49
49
|
// di sini yang harus disinkronkan dengan tool-layer.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Printer linier —
|
|
1
|
+
// Printer linier — renderer output jalur one-shot (dan TUI non-verbose).
|
|
2
2
|
// Output append-only ke scrollback terminal, tanpa alternate screen. Tool call
|
|
3
3
|
// inline dan EXPANDED by default (transparansi shell); mode compact via
|
|
4
4
|
// MINICODE_COMPACT=1 atau setCompactMode (/compact).
|
|
@@ -15,6 +15,7 @@ import { t } from "../i18n/locale.ts"
|
|
|
15
15
|
import { renderDiffCard } from "../render/diff.ts"
|
|
16
16
|
import { formatArgsPreview, formatProviderError, formatUsage } from "../render/format.ts"
|
|
17
17
|
import { highlightCode } from "../render/highlight.ts"
|
|
18
|
+
import { paintLedger, runMarker, statusWord } from "../render/ledger.ts"
|
|
18
19
|
import { decorateMarkdown, type FenceMatch, parseFence, renderInline } from "../render/markdown.ts"
|
|
19
20
|
import { MarkdownTableStream } from "../render/markdown-table.ts"
|
|
20
21
|
import {
|
|
@@ -98,6 +99,18 @@ const rememberTurn = (ui: UiSessionState, s: string) => {
|
|
|
98
99
|
ui.appendTurnText(process.stdout.isTTY ? s : stripSgr(s))
|
|
99
100
|
}
|
|
100
101
|
|
|
102
|
+
/**
|
|
103
|
+
* Batas byte payload OSC 52. Terminal tak menegosiasikan ukuran OSC 52; payload
|
|
104
|
+
* raksasa bisa memblokir/menggantung TTY atau dibuang diam-diam. 256 KB jauh di
|
|
105
|
+
* atas kebutuhan salin normal, tapi cukup kecil untuk aman di semua terminal.
|
|
106
|
+
*/
|
|
107
|
+
export const MAX_CLIPBOARD_BYTES = 256 * 1024
|
|
108
|
+
|
|
109
|
+
/** Panjang UTF-8 (byte) teks — dasar guard OSC 52 sebelum base64. */
|
|
110
|
+
export function clipboardByteLength(text: string): number {
|
|
111
|
+
return Buffer.byteLength(text, "utf8")
|
|
112
|
+
}
|
|
113
|
+
|
|
101
114
|
/**
|
|
102
115
|
* Tulis teks ke clipboard terminal via OSC 52 (`ESC ] 52 ; c ; base64 BEL`).
|
|
103
116
|
*
|
|
@@ -105,10 +118,13 @@ const rememberTurn = (ui: UiSessionState, s: string) => {
|
|
|
105
118
|
* TAK TERPERCAYA (model/tool), sedangkan payload di sini dibuat sendiri dari
|
|
106
119
|
* buffer yang sudah sanitize + base64 murni — tidak ada byte kontrol asing
|
|
107
120
|
* yang bisa lolos. Banyak terminal memblokir OSC 52 default; pemanggil wajib
|
|
108
|
-
* menyampaikan fallback-nya ke user. Return false bila bukan TTY
|
|
121
|
+
* menyampaikan fallback-nya ke user. Return false bila bukan TTY ATAU payload
|
|
122
|
+
* melewati `MAX_CLIPBOARD_BYTES` (guard byte — pemanggil disarankan mengecek
|
|
123
|
+
* `clipboardByteLength` lebih dulu agar bisa memberi pesan spesifik).
|
|
109
124
|
*/
|
|
110
125
|
export function writeClipboardOsc52(text: string): boolean {
|
|
111
126
|
if (!process.stdout.isTTY) return false
|
|
127
|
+
if (clipboardByteLength(text) > MAX_CLIPBOARD_BYTES) return false
|
|
112
128
|
const b64 = Buffer.from(text, "utf8").toString("base64")
|
|
113
129
|
process.stdout.write(`\x1b]52;c;${b64}\x07`)
|
|
114
130
|
return true
|
|
@@ -122,7 +138,7 @@ const wErrDirect = (s: string) =>
|
|
|
122
138
|
// Error provider terakhir turn ini — diingat, BUKAN dicetak langsung.
|
|
123
139
|
// Alasan: error tengah-turn sering pulih via fallback router; mencetak tiap
|
|
124
140
|
// event + sekali lagi di catch driver = dua blok ✗ untuk satu kegagalan.
|
|
125
|
-
// Driver (index.ts
|
|
141
|
+
// Driver (`cli/index.ts`) mencetak sekali via takePendingError().
|
|
126
142
|
//
|
|
127
143
|
// [Area A · PROMPT 06] Error tertunda milik SESI (state per-sesi), bukan
|
|
128
144
|
// variabel modul — dua sesi dalam satu proses tak lagi saling menimpa
|
|
@@ -201,11 +217,14 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
|
|
|
201
217
|
// per baris utuh agar tampilan rapi, bukan salad fragmen per chunk.
|
|
202
218
|
let reasoningLine = ""
|
|
203
219
|
|
|
204
|
-
// Section answer (jawaban model):
|
|
220
|
+
// Section answer (jawaban model): minimize hanya bila diminta (env/opsi) — teks lengkap
|
|
205
221
|
// TETAP ditulis (buffer), tampilan default satu baris ` + answer (N)`.
|
|
206
222
|
// /copy tak tersentuh (rememberTurn selalu jalan sebelum sink).
|
|
207
223
|
let answerBuf = ""
|
|
208
224
|
let answerTruncated = false
|
|
225
|
+
// K.3 (item 12): lacak apakah sudah ada isi jawaban yang tercetak — untuk
|
|
226
|
+
// menambahkan satu baris kosong pemisah sebelum heading (paritas dengan TUI).
|
|
227
|
+
let answerHasLine = false
|
|
209
228
|
let activeProviderAttempt: number | null = null
|
|
210
229
|
let attemptCopyText = ""
|
|
211
230
|
let attemptAnswerBuf = ""
|
|
@@ -335,10 +354,16 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
|
|
|
335
354
|
// bahasa tidak boleh kehilangan *value* karena dianggap italic).
|
|
336
355
|
const content = fence.lang ? highlightCode(line, fence.lang) : line
|
|
337
356
|
emitAnswer(` ${content}\n`)
|
|
357
|
+
answerHasLine = true
|
|
338
358
|
return
|
|
339
359
|
}
|
|
340
|
-
|
|
360
|
+
// Heading (K.3 item 12): satu baris kosong pemisah bila sudah ada isi —
|
|
361
|
+
// paritas dengan decorateMarkdown TUI (spasi vertikal sebelum heading).
|
|
362
|
+
const isHeading = /^#{1,3}\s/.test(line)
|
|
363
|
+
if (isHeading && answerHasLine) emitAnswer("\n")
|
|
364
|
+
emitAnswer(formatWrapped(decorateMarkdown(line), w))
|
|
341
365
|
emitAnswer("\n")
|
|
366
|
+
answerHasLine = answerHasLine || line.trim() !== ""
|
|
342
367
|
}
|
|
343
368
|
const consumePlainText = (text: string): void => {
|
|
344
369
|
const combined = plainLineBuffer + text
|
|
@@ -385,17 +410,9 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
|
|
|
385
410
|
if (!toolCallId) return undefined
|
|
386
411
|
return presentationSnapshot()?.activities.find((activity) => activity.toolCallId === toolCallId)
|
|
387
412
|
}
|
|
388
|
-
|
|
389
|
-
if (status === "completed") return t("ts.statusCompleted")
|
|
390
|
-
if (status === "failed") return t("ts.statusFailed")
|
|
391
|
-
if (status === "denied") return t("ts.statusDenied")
|
|
392
|
-
if (status === "cancelled") return t("ts.statusCancelled")
|
|
393
|
-
if (status === "interrupted") return t("ts.statusInterrupted")
|
|
394
|
-
return t("ts.statusRunning")
|
|
395
|
-
}
|
|
413
|
+
// Bagian suffix dipilih policy kanonik bila di-inject; format tetap di sini.
|
|
396
414
|
const linearSuffix = (activity: UiPresentationActivity | undefined): string => {
|
|
397
415
|
if (!activity) return ""
|
|
398
|
-
// Bagian suffix dipilih policy kanonik bila di-inject; format tetap di sini.
|
|
399
416
|
const desc = opts.policy ? opts.policy.describeActivity(activity) : undefined
|
|
400
417
|
const status = desc?.status ?? activity.status
|
|
401
418
|
const parts: string[] = [statusWord(status)]
|
|
@@ -424,21 +441,6 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
|
|
|
424
441
|
if (provenance === "replay" || provenance === "reconstructed") parts.push(provenance)
|
|
425
442
|
return parts.length > 0 ? ` ${c.muted(`[${parts.join(" · ")}]`)}` : ""
|
|
426
443
|
}
|
|
427
|
-
const paintTerminal = (status: UiPresentationActivity["status"], line: string): string => {
|
|
428
|
-
if (status === "failed") return c.error(line)
|
|
429
|
-
if (status === "denied") return c.warning(line)
|
|
430
|
-
if (status === "completed") return c.success(line)
|
|
431
|
-
return c.muted(line)
|
|
432
|
-
}
|
|
433
|
-
// F-AGENT-1: label run pendek stabil (`run_<8>` | `sub_<8>`) — identitas anak,
|
|
434
|
-
// sama dengan TUI, supaya failure tool anak paralel tak saling tertukar.
|
|
435
|
-
const runMarker = (activity: UiPresentationActivity | undefined): string => {
|
|
436
|
-
const id = activity?.runId ?? activity?.childSessionId
|
|
437
|
-
if (!id) return ""
|
|
438
|
-
const prefix = id.startsWith("run_") ? "run_" : id.startsWith("sub_") ? "sub_" : ""
|
|
439
|
-
const bare = id.slice(prefix.length).replace(/-/g, "")
|
|
440
|
-
return prefix + bare.slice(0, 8)
|
|
441
|
-
}
|
|
442
444
|
const writePresentationTerminal = (event: UiPresentationEvent): void => {
|
|
443
445
|
if (!presentationEnabled) return
|
|
444
446
|
flushTableStream()
|
|
@@ -560,7 +562,7 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
|
|
|
560
562
|
const marker = runMarker(activity)
|
|
561
563
|
const prefix = isChild ? ` ↳ ${marker ? `${marker} ` : ""}` : ` ${glyphs.arrow} `
|
|
562
564
|
const line = `${prefix}${name}${targetText}${linearSuffix(activity)}${detail}`
|
|
563
|
-
wErr(
|
|
565
|
+
wErr(paintLedger(status, `${line}\n`))
|
|
564
566
|
}
|
|
565
567
|
|
|
566
568
|
const offs: (() => void)[] = []
|
|
@@ -579,6 +581,7 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
|
|
|
579
581
|
reasoningLine = ""
|
|
580
582
|
answerBuf = ""
|
|
581
583
|
answerTruncated = false
|
|
584
|
+
answerHasLine = false
|
|
582
585
|
activeProviderAttempt = null
|
|
583
586
|
attemptCopyText = ""
|
|
584
587
|
ui.clearCollapsedSections()
|
package/src/ui/footer.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
// dengan spasi dan warna, tanpa bullet separator. Work Mode ada di kiri;
|
|
9
9
|
// Permission Mode berwarna cyan di sisi kanan, dekat penggunaan konteks.
|
|
10
10
|
import { sanitizeAnsiLine } from "./render/sanitize.ts"
|
|
11
|
-
import { c, glyphs } from "./render/theme.ts"
|
|
11
|
+
import { c, glyphs, themeCapabilityKey } from "./render/theme.ts"
|
|
12
12
|
import { displayWidth, truncateToWidth } from "./render/width.ts"
|
|
13
13
|
|
|
14
14
|
export type TimerHighlight = "seconds" | "minutes" | "hours"
|
|
@@ -107,9 +107,8 @@ export function paintPermissionMode(mode: string, style: ModeLabelStyle = "full"
|
|
|
107
107
|
* Saat `unrestricted` aktif, gembok jadi TERBUKA (🔓) — satu-satunya penanda,
|
|
108
108
|
* jadi dirender jelas (bukan redup). */
|
|
109
109
|
export function paintBashStrict(strictBash?: boolean, unrestricted = false): string {
|
|
110
|
-
if (unrestricted) return c.info(
|
|
111
|
-
|
|
112
|
-
return strictBash ? c.yellow(lock) : c.faint(lock)
|
|
110
|
+
if (unrestricted) return c.info(glyphs.unlock)
|
|
111
|
+
return strictBash ? c.yellow(glyphs.lock) : c.faint(glyphs.lock)
|
|
113
112
|
}
|
|
114
113
|
|
|
115
114
|
/** Spark glyph: redup saat idle, pulse putih↔abu saat busy (frame genap/ganjil). */
|
|
@@ -146,6 +145,36 @@ export function shortenPath(p: string, maxSegments = 2): string {
|
|
|
146
145
|
return `...${sep}${tail}`
|
|
147
146
|
}
|
|
148
147
|
|
|
148
|
+
/**
|
|
149
|
+
* Cache satu-entri: footer dirender ulang SETIAP paint, padahal isinya jarang
|
|
150
|
+
* berubah (idle: mode/model/cwd/konteks tetap). Key memuat SEMUA field +
|
|
151
|
+
* kapabilitas tema supaya cache tak menyajikan output basi setelah env/lebar
|
|
152
|
+
* berubah. Satu entri cukup: perubahan beruntun (mis. timer busy) memang selalu
|
|
153
|
+
* miss, dan entri lama tak berguna lagi.
|
|
154
|
+
*/
|
|
155
|
+
let footerCache: { key: string; line: string } | null = null
|
|
156
|
+
|
|
157
|
+
function footerCacheKey(s: FooterStatus, cols: number): string {
|
|
158
|
+
// JSON.stringify = pemisah tak ambigu; nilai model/cwd bisa memuat karakter
|
|
159
|
+
// apa pun (termasuk separator buatan), dan tabrakan key = footer salah.
|
|
160
|
+
return JSON.stringify([
|
|
161
|
+
themeCapabilityKey(),
|
|
162
|
+
cols,
|
|
163
|
+
s.mode,
|
|
164
|
+
s.strictBash === true,
|
|
165
|
+
s.workMode ?? "",
|
|
166
|
+
s.model,
|
|
167
|
+
s.cwd,
|
|
168
|
+
s.context ?? "",
|
|
169
|
+
s.metrics ?? "",
|
|
170
|
+
s.sparkFrame ?? 0,
|
|
171
|
+
s.activity ?? "",
|
|
172
|
+
s.timer ?? "",
|
|
173
|
+
s.timerActive === true,
|
|
174
|
+
s.timerHighlight ?? "",
|
|
175
|
+
])
|
|
176
|
+
}
|
|
177
|
+
|
|
149
178
|
/**
|
|
150
179
|
* Render 1 baris footer untuk lebar `columns` (+ 1 baris kosong di atasnya
|
|
151
180
|
* bila dilukis lengket). Tanpa garis separator — clean (keputusan user).
|
|
@@ -153,7 +182,17 @@ export function shortenPath(p: string, maxSegments = 2): string {
|
|
|
153
182
|
*/
|
|
154
183
|
export function renderFooter(s: FooterStatus, columns: number): string[] {
|
|
155
184
|
const cols = Math.max(10, Math.floor(columns) || 80)
|
|
185
|
+
const key = footerCacheKey(s, cols)
|
|
186
|
+
const cached = footerCache
|
|
187
|
+
// Kembalikan array BARU tiap panggilan: pemanggil bebas memutasi hasilnya
|
|
188
|
+
// tanpa merusak cache.
|
|
189
|
+
if (cached && cached.key === key) return [cached.line]
|
|
190
|
+
const line = buildFooterLine(s, cols)
|
|
191
|
+
footerCache = { key, line }
|
|
192
|
+
return [line]
|
|
193
|
+
}
|
|
156
194
|
|
|
195
|
+
function buildFooterLine(s: FooterStatus, cols: number): string {
|
|
157
196
|
const spark = sparkGlyph(s.sparkFrame ?? 0)
|
|
158
197
|
const timerText = s.timer ? sanitizeAnsiLine(s.timer) : ""
|
|
159
198
|
const timer = timerText
|
|
@@ -229,7 +268,7 @@ export function renderFooter(s: FooterStatus, columns: number): string[] {
|
|
|
229
268
|
for (const [workStyle, permissionStyle] of pairGroup) {
|
|
230
269
|
for (const left of leftCandidates(workStyle)) {
|
|
231
270
|
const line = align(left, rightFor(permissionStyle))
|
|
232
|
-
if (line && displayWidth(line) <= target) return
|
|
271
|
+
if (line && displayWidth(line) <= target) return line
|
|
233
272
|
}
|
|
234
273
|
}
|
|
235
274
|
}
|
|
@@ -237,7 +276,7 @@ export function renderFooter(s: FooterStatus, columns: number): string[] {
|
|
|
237
276
|
for (const pairGroup of labelPairGroups) {
|
|
238
277
|
for (const [workStyle, permissionStyle] of pairGroup) {
|
|
239
278
|
const line = align(leftModeOnlyFor(workStyle), rightFor(permissionStyle))
|
|
240
|
-
if (line && displayWidth(line) <= target) return
|
|
279
|
+
if (line && displayWidth(line) <= target) return line
|
|
241
280
|
}
|
|
242
281
|
}
|
|
243
282
|
|
|
@@ -255,9 +294,9 @@ export function renderFooter(s: FooterStatus, columns: number): string[] {
|
|
|
255
294
|
if (contextBudget > 0) {
|
|
256
295
|
const shortenedContext = truncateToWidth(context, contextBudget, "…")
|
|
257
296
|
const withContext = `${spark} ${shortWorkValue} ${c.gray(shortenedContext)} ${[permissionValue, strictValue].filter(Boolean).join(" ")}`
|
|
258
|
-
if (displayWidth(withContext) <= target) return
|
|
297
|
+
if (displayWidth(withContext) <= target) return withContext
|
|
259
298
|
}
|
|
260
299
|
}
|
|
261
|
-
if (displayWidth(modeOnly) <= target) return
|
|
262
|
-
return
|
|
300
|
+
if (displayWidth(modeOnly) <= target) return modeOnly
|
|
301
|
+
return truncateToWidth(modeOnly, target, "…")
|
|
263
302
|
}
|
package/src/ui/i18n/en.ts
CHANGED
|
@@ -232,6 +232,7 @@ export const en = {
|
|
|
232
232
|
"copied {turns} turns ({n} chars · OSC 52 — allow clipboard access in terminal if empty)",
|
|
233
233
|
"tui.copyInvalid": "invalid turn count: {n} (use 1–{max})",
|
|
234
234
|
"tui.copyNeedTty": "(clipboard needs a TTY terminal)",
|
|
235
|
+
"tui.copyTooLarge": "copy payload too large ({n} bytes, max {max})",
|
|
235
236
|
"tui.unknownMode": "unknown mode: {a} — choices: {modes}",
|
|
236
237
|
"tui.modeLine": "mode: {m}",
|
|
237
238
|
"tui.workModeUnknown": "unknown work mode: {a} — choices: {modes}",
|
package/src/ui/i18n/id.ts
CHANGED
|
@@ -233,6 +233,7 @@ export const id: Record<MsgKey, string> = {
|
|
|
233
233
|
"tersalin {turns} turn ({n} chars · OSC 52 — izinkan akses clipboard di terminal bila kosong)",
|
|
234
234
|
"tui.copyInvalid": "jumlah turn tidak valid: {n} (gunakan 1–{max})",
|
|
235
235
|
"tui.copyNeedTty": "(clipboard butuh terminal TTY)",
|
|
236
|
+
"tui.copyTooLarge": "payload salin terlalu besar ({n} byte, maks {max})",
|
|
236
237
|
"tui.unknownMode": "mode tidak dikenal: {a} — pilihan: {modes}",
|
|
237
238
|
"tui.modeLine": "mode: {m}",
|
|
238
239
|
"tui.workModeUnknown": "work mode tidak dikenal: {a} — pilihan: {modes}",
|
|
@@ -64,10 +64,10 @@ export type PromptKey =
|
|
|
64
64
|
| { type: "ctrl-w" } // delete previous word
|
|
65
65
|
| { type: "ctrl-o" } // expand detail (TUI)
|
|
66
66
|
| { type: "ctrl-r" } // reverse-i-search history
|
|
67
|
-
| { type: "ctrl-t" } // toggle expand/minimize reasoning
|
|
67
|
+
| { type: "ctrl-t" } // toggle expand/minimize reasoning (TUI)
|
|
68
68
|
| { type: "ctrl-n" } // tambah (model-manager: Ctrl+N = add model)
|
|
69
69
|
| { type: "ctrl-j" } // sisipkan newline (multiline opt-in; Enter=\r tetap submit)
|
|
70
|
-
| { type: "shift-tab" } //
|
|
70
|
+
| { type: "shift-tab" } // toggle permission mode (TUI) — ESC[Z didekode decodeKey
|
|
71
71
|
| { type: "ignore" } // sekuens yang sengaja dibuang (mis. byte mouse)
|
|
72
72
|
|
|
73
73
|
// Terapkan satu keypress -> state baru + render spec + action (submit/cancel).
|
|
@@ -80,7 +80,22 @@ export type PromptAction = "none" | "render" | "submit" | "cancel"
|
|
|
80
80
|
// batas grapheme sungguhan (Node 16+ / Bun tersedia); fallback ke code point
|
|
81
81
|
// di runtime tanpa dukungan.
|
|
82
82
|
let segmenter: Intl.Segmenter | undefined
|
|
83
|
-
|
|
83
|
+
/**
|
|
84
|
+
* Pisah string menjadi grapheme. ASCII murni dilewati cepat (satu char = satu
|
|
85
|
+
* grapheme) dan hasilnya di-memo satu entri: satu paint memanggil ini berkali-
|
|
86
|
+
* kali untuk baris yang SAMA (layout, posisi kursor, dsb.), dan `Intl.Segmenter`
|
|
87
|
+
* adalah biaya terbesar di jalur ketik. Pemanggil MENGUBAH array hasil
|
|
88
|
+
* (splice), jadi cache selalu disalin keluar — bukan dikembalikan langsung.
|
|
89
|
+
*/
|
|
90
|
+
function segmentInto(s: string): string[] {
|
|
91
|
+
let ascii = true
|
|
92
|
+
for (let i = 0; i < s.length; i++) {
|
|
93
|
+
if (s.charCodeAt(i) > 0x7f) {
|
|
94
|
+
ascii = false
|
|
95
|
+
break
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (ascii) return s.split("")
|
|
84
99
|
try {
|
|
85
100
|
segmenter ??= new Intl.Segmenter("und", { granularity: "grapheme" })
|
|
86
101
|
return [...segmenter.segment(s)].map((seg) => seg.segment)
|
|
@@ -89,6 +104,17 @@ export function toGraphemes(s: string): string[] {
|
|
|
89
104
|
}
|
|
90
105
|
}
|
|
91
106
|
|
|
107
|
+
let memoInput: string | null = null
|
|
108
|
+
let memoOutput: string[] | null = null
|
|
109
|
+
|
|
110
|
+
export function toGraphemes(s: string): string[] {
|
|
111
|
+
if (memoInput === s && memoOutput !== null) return memoOutput.slice()
|
|
112
|
+
const out = segmentInto(s)
|
|
113
|
+
memoInput = s
|
|
114
|
+
memoOutput = out
|
|
115
|
+
return out.slice()
|
|
116
|
+
}
|
|
117
|
+
|
|
92
118
|
/** Panjang dalam satuan grapheme (bukan code point / UTF-16 unit). */
|
|
93
119
|
export function pointLength(s: string): number {
|
|
94
120
|
return toGraphemes(s).length
|
|
@@ -198,8 +224,8 @@ export function applyKey(
|
|
|
198
224
|
// Paste bisa memuat newline/tab/kontrol. Dulu "\n" digepeng jadi spasi
|
|
199
225
|
// agar tidak melebihi tinggi terminal, tapi itu membuat copas code
|
|
200
226
|
// multilines cuma baris pertama (keluhan nyata). Sekarang "\n" dipertahankan
|
|
201
|
-
// sebagai baris baru — renderer `
|
|
202
|
-
// tinggi (`
|
|
227
|
+
// sebagai baris baru — renderer `buildRenderSpec` sudah memperhitungkan
|
|
228
|
+
// tinggi (`maxVisible`) sehingga tidak
|
|
203
229
|
// menabrak footer. Tab jadi spasi; kontrol lain dibuang.
|
|
204
230
|
const ins = key.ch
|
|
205
231
|
.replace(/\r\n|\r/g, "\n")
|
|
@@ -277,11 +303,11 @@ export function applyKey(
|
|
|
277
303
|
case "ctrl-c":
|
|
278
304
|
case "ctrl-d":
|
|
279
305
|
return { state, action: "cancel" }
|
|
280
|
-
case "ctrl-o": // toggle compact — ditangani
|
|
306
|
+
case "ctrl-o": // toggle compact — ditangani host TUI (app.ts)
|
|
281
307
|
case "ctrl-r": // reverse-i-search — ditangani askLine (input.ts) sebelum applyKey
|
|
282
|
-
case "ctrl-t": // toggle expand/minimize reasoning
|
|
308
|
+
case "ctrl-t": // toggle expand/minimize reasoning — ditangani host TUI (app.ts)
|
|
283
309
|
case "ctrl-n": // tambah model — ditangani view yang membutuhkan (model-manager); di prompt teks diabaikan
|
|
284
|
-
case "shift-tab": //
|
|
310
|
+
case "shift-tab": // toggle permission mode — ditangani host TUI (app.ts)
|
|
285
311
|
case "ignore":
|
|
286
312
|
return { state, action: "none" }
|
|
287
313
|
case "ctrl-u": {
|
|
@@ -604,7 +630,7 @@ export function flushLoneEsc(state: DecoderState): DecodedKey[] {
|
|
|
604
630
|
// panah split secara sinkron). Pompa ini membungkus pola yang dipakai SEMUA
|
|
605
631
|
// konsumen interaktif (askLine/askSecret/picker/manager): decode chunk →
|
|
606
632
|
// teruskan key sinkron → bila pending Esc tunggal, tunggu ~50ms (pola
|
|
607
|
-
// lone-ESC yang sama saat busy di
|
|
633
|
+
// lone-ESC yang sama saat busy di TUI, `src/ui/tui/app.ts`); byte lanjutan membatalkan
|
|
608
634
|
// timer dan melengkapi sekuens, sunyi berarti Esc asli → flush sebagai esc.
|
|
609
635
|
//
|
|
610
636
|
// Tanpa pompa tiap konsumen harus menulis timer sendiri (duplikasi 5× dan
|
|
@@ -786,7 +812,7 @@ export function decodeKey(s: string, i: number): DecodedKey | null {
|
|
|
786
812
|
}
|
|
787
813
|
// selain itu (ESC[5;34R, ESC[5x, …) → catch-all esc di bawah
|
|
788
814
|
}
|
|
789
|
-
// Shift+Tab (backtab) ESC [ Z — dipakai
|
|
815
|
+
// Shift+Tab (backtab) ESC [ Z — dipakai TUI untuk toggle permission mode.
|
|
790
816
|
// Tanpa cabang eksplisit ini ia jatuh ke catch-all "esc" di bawah,
|
|
791
817
|
// sehingga tipe "shift-tab" tidak pernah dihasilkan decodeKeys.
|
|
792
818
|
if (kind === "Z") return { key: { type: "shift-tab" }, width: 3 }
|