minicode-ai 0.14.6 → 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/args.ts +20 -8
- package/cli/commands/exec.ts +17 -14
- package/cli/commands/openwork.ts +1 -1
- package/cli/commands.ts +39 -23
- package/cli/index.ts +29 -7
- package/cli/model-manager.ts +1 -1
- package/cli/router.ts +22 -9
- package/cli/setup.ts +77 -35
- package/cli/tui.ts +179 -25
- package/docs/CONTROL-PLANE-MAP.md +7 -5
- 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 +89 -17
- package/docs/UI_RENDER_PIPELINE.md +47 -8
- package/docs/agents.md +1 -1
- package/docs/architecture.md +10 -8
- package/docs/autonomous-scheduler.md +142 -0
- package/docs/choosing-mode.md +4 -2
- package/docs/cli.md +11 -9
- package/docs/concepts.md +5 -5
- package/docs/config-providers.md +3 -3
- package/docs/config.md +1 -1
- package/docs/contributing.md +7 -9
- package/docs/environment.md +8 -5
- package/docs/getting-started.md +5 -5
- package/docs/mcp-lsp.md +2 -2
- package/docs/memory-sessions.md +3 -3
- package/docs/policy-sandbox.md +7 -4
- package/docs/pricing-budget.md +3 -3
- package/docs/quickstart.md +1 -1
- package/docs/repl.md +11 -8
- package/docs/security-model.md +4 -2
- 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/scripts/vendor-overlays/minicode-context.patch +1 -1
- package/src/app/mentions.ts +1 -1
- package/src/app/rag-layer.ts +11 -2
- package/src/app/session.ts +128 -10
- package/src/constants.ts +32 -1
- package/src/daemon/client.ts +11 -6
- package/src/daemon/control.ts +2 -9
- package/src/daemon/resource.ts +5 -4
- package/src/hooks/run.ts +5 -6
- package/src/lib/keystore.ts +11 -9
- package/src/lib/net.ts +8 -3
- package/src/lib/safe-open.ts +29 -5
- package/src/lib/trusted-exec.ts +4 -1
- package/src/lsp/client.ts +9 -10
- package/src/mcp/http-transport.ts +1 -1
- package/src/mcp/server.ts +17 -7
- package/src/memory/files.ts +2 -1
- package/src/memory/vector.ts +25 -16
- package/src/policy/bash-guard.ts +58 -16
- package/src/policy/bpe.ts +110 -0
- package/src/policy/compaction.ts +139 -22
- package/src/policy/consequence-engine.ts +3 -3
- package/src/policy/context-window.ts +43 -1
- package/src/policy/context.ts +50 -12
- package/src/policy/jail.ts +48 -3
- package/src/policy/no-progress.ts +15 -8
- package/src/policy/permission.ts +243 -5
- package/src/policy/tokenizer-registry.ts +104 -0
- package/src/policy/usage.ts +20 -13
- package/src/policy/verifier.ts +7 -4
- package/src/policy/work-mode.ts +9 -5
- package/src/presentation/adapter.ts +8 -4
- package/src/presentation/events.ts +2 -2
- package/src/presentation/label.ts +3 -3
- package/src/presentation/model.ts +4 -0
- package/src/presentation/projection.ts +10 -2
- package/src/presentation/store.ts +2 -2
- package/src/providers/anthropic.ts +13 -3
- package/src/providers/responses.ts +16 -6
- package/src/runtime/capability.ts +22 -4
- package/src/runtime/child-execution.ts +1 -1
- package/src/runtime/composition.ts +5 -5
- package/src/runtime/execution-journal.ts +13 -7
- package/src/runtime/execution-registry.ts +1 -1
- package/src/runtime/production-execution.ts +7 -6
- 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/sandbox/os.ts +4 -3
- package/src/session/checkpoint.ts +29 -4
- 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 +22 -11
- package/src/task/autonomous-context.ts +2 -3
- 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-observability.ts +1 -0
- 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/git.ts +22 -4
- package/src/tools/lsp.ts +10 -8
- package/src/tools/read_image.ts +2 -1
- package/src/tools/task.ts +1 -1
- package/src/tools/web_fetch.ts +6 -2
- package/src/tools/web_search.ts +2 -1
- package/src/ui/assistant/simple.ts +42 -33
- package/src/ui/contract.ts +4 -0
- package/src/ui/footer.ts +63 -12
- package/src/ui/i18n/en.ts +14 -2
- package/src/ui/i18n/id.ts +14 -2
- 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/diff.ts +14 -5
- package/src/ui/render/highlight.ts +4 -4
- package/src/ui/render/ledger.ts +47 -0
- package/src/ui/render/markdown.ts +12 -5
- package/src/ui/render/session-summary.ts +50 -0
- package/src/ui/render/table-grid.ts +134 -6
- package/src/ui/render/theme.ts +49 -4
- package/src/ui/render/width.ts +91 -4
- package/src/ui/render/wrap.ts +5 -3
- package/src/ui/runtime/screen.ts +100 -22
- package/src/ui/runtime/statusline.ts +26 -0
- package/src/ui/screens/model-manager.ts +1 -1
- package/src/ui/session-state.ts +27 -1
- package/src/ui/tui/app.ts +336 -65
- package/src/ui/tui/transcript.ts +335 -104
- package/vendor/minicore/VENDOR.md +16 -12
- package/vendor/minicore/src/core/events.ts +1 -0
- package/vendor/minicore/src/core/loop.ts +11 -1
- package/vendor/minicore/src/core/session.ts +39 -0
package/src/ui/tui/transcript.ts
CHANGED
|
@@ -16,15 +16,20 @@ import type {
|
|
|
16
16
|
UiToolStatus,
|
|
17
17
|
} from "../contract.ts"
|
|
18
18
|
import { t } from "../i18n/locale.ts"
|
|
19
|
+
import { paintLedger, runMarker, statusGlyph, statusWord } from "../render/ledger.ts"
|
|
19
20
|
import { parseFence, renderInline } from "../render/markdown.ts"
|
|
20
21
|
import { type MarkdownTable, parseMarkdownBlocks } from "../render/markdown-table.ts"
|
|
21
22
|
import { sanitizeAnsi, sanitizeAnsiLine, stripSgr } from "../render/sanitize.ts"
|
|
22
23
|
import { renderMarkdownTable } from "../render/table-grid.ts"
|
|
23
24
|
import { c, glyphs } from "../render/theme.ts"
|
|
24
|
-
import {
|
|
25
|
+
import { displayWidth, truncateToWidth, wrapByWidth } from "../render/width.ts"
|
|
25
26
|
import { defaultUiState, type UiSessionState } from "../session-state.ts"
|
|
26
27
|
|
|
27
28
|
/** Cap memori: baris logis tertua dibuang diam-diam (kontrak I12). */
|
|
29
|
+
// Catatan retention (K.7): ini cap TAMPILAN transkrip. Berbeda dan sengaja tak
|
|
30
|
+
// sama dengan MAX_STATE_ENTRIES=4096 di presentation/model.ts yang membatasi
|
|
31
|
+
// reducer presentasi (state durable/resume) — dua lapis retention berbeda untuk
|
|
32
|
+
// substansi berbeda (viewport vs riwayat yang bisa di-replay).
|
|
28
33
|
export const TRANSCRIPT_CAP = 5000
|
|
29
34
|
export const TRANSCRIPT_TEXT_MAX_CHARS = 1_000_000
|
|
30
35
|
const TRANSCRIPT_TRUNCATION_MARKER = "… [transcript truncated: turn cap exceeded]"
|
|
@@ -234,7 +239,56 @@ export class Transcript {
|
|
|
234
239
|
private presentedTerminals = new Set<string>()
|
|
235
240
|
private presentedVerifications = new Set<string>()
|
|
236
241
|
private summarizedTurns = new Set<number>()
|
|
242
|
+
/** Lipat aktivitas (minimizeActivity): baris ledger per-tool ditahan dulu,
|
|
243
|
+
* lalu saat turn selesai dirangkum jadi SATU baris (opencode-like) + detail
|
|
244
|
+
* di-buffer untuk /expand. */
|
|
245
|
+
private activityFold: { name: string; status: string; line: string }[] = []
|
|
237
246
|
private unsubs: (() => void)[] = []
|
|
247
|
+
/**
|
|
248
|
+
* Fase 1 perf (butir 2): memo daftar activity "running". Snapshot presentasi
|
|
249
|
+
* kini stabil antar-event (cache di composition root), jadi filter
|
|
250
|
+
* `status === "running"` tak perlu diulang tiap paint — cukup sekali per
|
|
251
|
+
* snapshot. Key = identitas objek snapshot.
|
|
252
|
+
*/
|
|
253
|
+
private runningMemo: {
|
|
254
|
+
snapshot: UiPresentationSnapshot
|
|
255
|
+
running: UiPresentationActivity[]
|
|
256
|
+
} | null = null
|
|
257
|
+
/**
|
|
258
|
+
* Fase 1 perf (butir 3): cache proyeksi baris. Proyeksi sudah punya
|
|
259
|
+
* `rowCache` per baris logis, tetapi `projectAll` tetap membangun ulang array
|
|
260
|
+
* seluruh baris visual + parseFence + parse markdown `pending` pada tiap
|
|
261
|
+
* paint (ketikan/scroll), meski isinya tak berubah. Cache di bawah menghindari
|
|
262
|
+
* kerja itu: baris ter-commit di-cache per (width, totalAppended), pending
|
|
263
|
+
* per (width, pendingVersion, truncated).
|
|
264
|
+
*/
|
|
265
|
+
private committedProjection: {
|
|
266
|
+
width: number
|
|
267
|
+
totalAppended: number
|
|
268
|
+
rows: TranscriptRow[]
|
|
269
|
+
} | null = null
|
|
270
|
+
private pendingProjection: {
|
|
271
|
+
width: number
|
|
272
|
+
version: number
|
|
273
|
+
truncated: boolean
|
|
274
|
+
rows: TranscriptRow[]
|
|
275
|
+
} | null = null
|
|
276
|
+
/**
|
|
277
|
+
* Fase 1 perf (lanjutan): cache gabungan committed+pending — bagian O(N)
|
|
278
|
+
* dari `projectAll`. Saat thinking/running kosong (kasus idle ketik/scroll,
|
|
279
|
+
* mayoritas paint), hasil ini dikembalikan APA ADANYA tanpa salinan, sehingga
|
|
280
|
+
* `[...committed, ...pending]` tak diulang O(N) tiap keystroke saat transkrip
|
|
281
|
+
* sudah menumpuk. Di-invalidate oleh sinyal yang sama dengan dua cache di atas.
|
|
282
|
+
*/
|
|
283
|
+
private projectedBase: {
|
|
284
|
+
width: number
|
|
285
|
+
totalAppended: number
|
|
286
|
+
pendingVersion: number
|
|
287
|
+
pendingTruncated: boolean
|
|
288
|
+
rows: TranscriptRow[]
|
|
289
|
+
} | null = null
|
|
290
|
+
/** Naik setiap `this.pending` berubah (stream/commit/invalidated/clear). */
|
|
291
|
+
private pendingVersion = 0
|
|
238
292
|
|
|
239
293
|
constructor(bus: UiBus, opts: TranscriptOptions = {}) {
|
|
240
294
|
this.getSnapshot = opts.getSnapshot
|
|
@@ -247,6 +301,7 @@ export class Transcript {
|
|
|
247
301
|
bus.on("turn:started", () => {
|
|
248
302
|
this.commit()
|
|
249
303
|
this.commitThinking()
|
|
304
|
+
this.activityFold = []
|
|
250
305
|
}),
|
|
251
306
|
bus.on("turn:completed", () => {
|
|
252
307
|
this.commit()
|
|
@@ -277,12 +332,14 @@ export class Transcript {
|
|
|
277
332
|
}
|
|
278
333
|
if (text.length <= remaining) {
|
|
279
334
|
this.pending += text
|
|
335
|
+
this.pendingVersion++
|
|
280
336
|
return
|
|
281
337
|
}
|
|
282
338
|
let keep = text.slice(0, remaining)
|
|
283
339
|
const last = keep.charCodeAt(keep.length - 1)
|
|
284
340
|
if (last >= 0xd800 && last <= 0xdbff) keep = keep.slice(0, -1)
|
|
285
341
|
this.pending += keep
|
|
342
|
+
this.pendingVersion++
|
|
286
343
|
this.pendingTruncated = true
|
|
287
344
|
}
|
|
288
345
|
|
|
@@ -306,6 +363,7 @@ export class Transcript {
|
|
|
306
363
|
if (this.activeProviderAttempt?.id === id) this.activeProviderAttempt = null
|
|
307
364
|
} else if (data?.phase === "invalidated" && this.activeProviderAttempt?.id === id) {
|
|
308
365
|
this.pending = this.pending.slice(0, this.activeProviderAttempt.pendingLength)
|
|
366
|
+
this.pendingVersion++
|
|
309
367
|
this.pendingTruncated = this.activeProviderAttempt.pendingTruncated
|
|
310
368
|
this.activeProviderAttempt = null
|
|
311
369
|
// Reasoning dari attempt yang gagal tidak boleh tertinggal sebagai
|
|
@@ -326,11 +384,12 @@ export class Transcript {
|
|
|
326
384
|
if (!text) return
|
|
327
385
|
const clean = sanitizeAnsi(text)
|
|
328
386
|
if (this.uiState.reasoningVisible) {
|
|
329
|
-
// Expanded: alir
|
|
387
|
+
// Expanded: alir per baris dengan indentasi 2 kolom (line-buffered, ekor
|
|
388
|
+
// hidup) — membedakan thinking dari jawaban model yang mulai di kolom 0.
|
|
330
389
|
this.thinkingTail += clean
|
|
331
390
|
const parts = this.thinkingTail.split("\n")
|
|
332
391
|
for (let i = 0; i < parts.length - 1; i++)
|
|
333
|
-
this.append(c.
|
|
392
|
+
this.append(c.thinking(` ${parts[i] ?? ""}`), { kind: "diagnostic" })
|
|
334
393
|
|
|
335
394
|
this.thinkingTail = parts[parts.length - 1] ?? ""
|
|
336
395
|
} else {
|
|
@@ -340,10 +399,10 @@ export class Transcript {
|
|
|
340
399
|
}
|
|
341
400
|
|
|
342
401
|
/** Selesaikan fase thinking: minimized → penanda hilang; expanded → flush
|
|
343
|
-
* ekor
|
|
402
|
+
* ekor (berindentasi sama dengan baris thinking). */
|
|
344
403
|
private commitThinking(): void {
|
|
345
404
|
if (this.thinkingTail) {
|
|
346
|
-
this.append(c.
|
|
405
|
+
this.append(c.thinking(` ${this.thinkingTail}`), { kind: "diagnostic" })
|
|
347
406
|
this.thinkingTail = ""
|
|
348
407
|
}
|
|
349
408
|
this.thinkingBuf = ""
|
|
@@ -370,7 +429,7 @@ export class Transcript {
|
|
|
370
429
|
}
|
|
371
430
|
|
|
372
431
|
pushError(message: string): void {
|
|
373
|
-
this.push(c.error(
|
|
432
|
+
this.push(c.error(sanitizeAnsiLine(message)), { kind: "diagnostic" })
|
|
374
433
|
}
|
|
375
434
|
|
|
376
435
|
pushInfo(lines: string[]): void {
|
|
@@ -409,9 +468,15 @@ export class Transcript {
|
|
|
409
468
|
this.thinkingTail = ""
|
|
410
469
|
this.evicted = 0
|
|
411
470
|
this.hasEvictMarker = false
|
|
471
|
+
this.runningMemo = null
|
|
472
|
+
this.committedProjection = null
|
|
473
|
+
this.pendingProjection = null
|
|
474
|
+
this.projectedBase = null
|
|
475
|
+
this.pendingVersion = 0
|
|
412
476
|
this.presentedTerminals.clear()
|
|
413
477
|
this.presentedVerifications.clear()
|
|
414
478
|
this.summarizedTurns.clear()
|
|
479
|
+
this.activityFold = []
|
|
415
480
|
}
|
|
416
481
|
|
|
417
482
|
/** Jumlah baris logis (untuk test; bukan API paint). */
|
|
@@ -454,8 +519,8 @@ export class Transcript {
|
|
|
454
519
|
sourceBase += source.length + 1
|
|
455
520
|
continue
|
|
456
521
|
}
|
|
457
|
-
const renderedRows = rendered === "" ? [""] :
|
|
458
|
-
const sourceRows = sourcePrefix || source ?
|
|
522
|
+
const renderedRows = rendered === "" ? [""] : wrapByWidth(rendered, w)
|
|
523
|
+
const sourceRows = sourcePrefix || source ? wrapByWidth(`${sourcePrefix}${source}`, w) : [""]
|
|
459
524
|
let offset = sourceBase
|
|
460
525
|
const count = Math.max(renderedRows.length, sourceRows.length)
|
|
461
526
|
for (let rowIndex = 0; rowIndex < count; rowIndex++) {
|
|
@@ -546,6 +611,76 @@ export class Transcript {
|
|
|
546
611
|
|
|
547
612
|
private projectAll(width: number): TranscriptRow[] {
|
|
548
613
|
const w = Math.max(10, width)
|
|
614
|
+
const running = this.runningRows()
|
|
615
|
+
// Kasus umum (idle ketik/scroll — thinking tau cara running kosong):
|
|
616
|
+
// kembalikan gabungan committed+pending yang ter-cache TANPA menyalin ulang.
|
|
617
|
+
// Ini memberantas biaya concat O(N) pada setiap paint (biaya yang TUMBUH
|
|
618
|
+
// seiring transkrip menumpuk — tepat gejala "mengetik berat saat history penuh").
|
|
619
|
+
if (!this.thinkingTail && running.length === 0) {
|
|
620
|
+
if (
|
|
621
|
+
this.projectedBase &&
|
|
622
|
+
this.projectedBase.width === w &&
|
|
623
|
+
this.projectedBase.totalAppended === this.totalAppended &&
|
|
624
|
+
this.projectedBase.pendingVersion === this.pendingVersion &&
|
|
625
|
+
this.projectedBase.pendingTruncated === this.pendingTruncated
|
|
626
|
+
) {
|
|
627
|
+
return this.projectedBase.rows
|
|
628
|
+
}
|
|
629
|
+
const base: TranscriptRow[] = [...this.committedRows(w), ...this.pendingRows(w)]
|
|
630
|
+
this.projectedBase = {
|
|
631
|
+
width: w,
|
|
632
|
+
totalAppended: this.totalAppended,
|
|
633
|
+
pendingVersion: this.pendingVersion,
|
|
634
|
+
pendingTruncated: this.pendingTruncated,
|
|
635
|
+
rows: base,
|
|
636
|
+
}
|
|
637
|
+
return base
|
|
638
|
+
}
|
|
639
|
+
// thinking/running aktif: bangun segar (jarang — hanya saat turn berjalan,
|
|
640
|
+
// dan repaint-nya sudah dicoalesce 30ms, bukan per-keypress).
|
|
641
|
+
const rows: TranscriptRow[] = [...this.committedRows(w), ...this.pendingRows(w)]
|
|
642
|
+
if (this.thinkingTail) {
|
|
643
|
+
for (const chunk of this.thinkingTail.split("\n")) {
|
|
644
|
+
const chunkRows = chunk === "" ? [""] : wrapByWidth(chunk, w)
|
|
645
|
+
for (const row of chunkRows) {
|
|
646
|
+
rows.push({
|
|
647
|
+
text: c.thinking(row),
|
|
648
|
+
sourceId: -1,
|
|
649
|
+
sourceStart: 0,
|
|
650
|
+
sourceEnd: 0,
|
|
651
|
+
displayStart: 0,
|
|
652
|
+
displayEnd: displayWidth(row),
|
|
653
|
+
selectable: false,
|
|
654
|
+
})
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
for (const row of running) {
|
|
659
|
+
rows.push({
|
|
660
|
+
text: row,
|
|
661
|
+
sourceId: -1,
|
|
662
|
+
sourceStart: 0,
|
|
663
|
+
sourceEnd: 0,
|
|
664
|
+
displayStart: 0,
|
|
665
|
+
displayEnd: displayWidth(row),
|
|
666
|
+
selectable: false,
|
|
667
|
+
})
|
|
668
|
+
}
|
|
669
|
+
return rows
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
/** Proyeksi baris ter-commit (Fase 1 perf butir 3). Di-cache per (width,
|
|
673
|
+
* totalAppended): totalAppended monotonik dan hanya naik saat baris baru
|
|
674
|
+
* masuk/evict, jadi paint idle (ketik/scroll) tidak mengulang iterasi 5000
|
|
675
|
+
* baris + parseFence. Cache disamakan objeknya, hasil dipakai read-only. */
|
|
676
|
+
private committedRows(w: number): TranscriptRow[] {
|
|
677
|
+
if (
|
|
678
|
+
this.committedProjection &&
|
|
679
|
+
this.committedProjection.width === w &&
|
|
680
|
+
this.committedProjection.totalAppended === this.totalAppended
|
|
681
|
+
) {
|
|
682
|
+
return this.committedProjection.rows
|
|
683
|
+
}
|
|
549
684
|
const rows: TranscriptRow[] = []
|
|
550
685
|
const committedFence = this.fenceTracker()
|
|
551
686
|
for (let i = 0; i < this.lines.length; i++) {
|
|
@@ -587,20 +722,38 @@ export class Transcript {
|
|
|
587
722
|
})
|
|
588
723
|
rows.push(...produced)
|
|
589
724
|
}
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
725
|
+
this.committedProjection = { width: w, totalAppended: this.totalAppended, rows }
|
|
726
|
+
return rows
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
/** Proyeksi `pending` (jawaban streaming) + marker truncasi. Di-cache per
|
|
730
|
+
* (width, pendingVersion, truncated): tanpa ini `parseMarkdownBlocks(pending)`
|
|
731
|
+
* + `normalizeAssistantOutput` diulang penuh tiap paint saat jawaban panjang
|
|
732
|
+
* mengalir (O(pending) per frame). pendingVersion naik di stream/commit/clear. */
|
|
733
|
+
private pendingRows(w: number): TranscriptRow[] {
|
|
734
|
+
if (!this.pending) {
|
|
735
|
+
this.pendingProjection = null
|
|
736
|
+
return []
|
|
737
|
+
}
|
|
738
|
+
if (
|
|
739
|
+
this.pendingProjection &&
|
|
740
|
+
this.pendingProjection.width === w &&
|
|
741
|
+
this.pendingProjection.version === this.pendingVersion &&
|
|
742
|
+
this.pendingProjection.truncated === this.pendingTruncated
|
|
743
|
+
) {
|
|
744
|
+
return this.pendingProjection.rows
|
|
745
|
+
}
|
|
746
|
+
const rows: TranscriptRow[] = []
|
|
747
|
+
const pendingFence = this.fenceTracker()
|
|
748
|
+
const pending = normalizeAssistantOutput(sanitizeAnsi(this.pending))
|
|
749
|
+
if (pending) {
|
|
750
|
+
for (const block of parseMarkdownBlocks(pending)) {
|
|
751
|
+
if (block.type === "table") rows.push(...this.projectTable(block.table, -1, w))
|
|
752
|
+
else
|
|
753
|
+
for (const line of block.text.split("\n")) {
|
|
754
|
+
const clean = stripSgr(sanitizeAnsi(line))
|
|
755
|
+
rows.push(...this.projectText(line, clean, -1, w, false, "", true, pendingFence(line)))
|
|
756
|
+
}
|
|
604
757
|
}
|
|
605
758
|
}
|
|
606
759
|
if (this.pendingTruncated) {
|
|
@@ -614,32 +767,11 @@ export class Transcript {
|
|
|
614
767
|
selectable: false,
|
|
615
768
|
})
|
|
616
769
|
}
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
text: c.muted(row),
|
|
623
|
-
sourceId: -1,
|
|
624
|
-
sourceStart: 0,
|
|
625
|
-
sourceEnd: 0,
|
|
626
|
-
displayStart: 0,
|
|
627
|
-
displayEnd: displayWidth(row),
|
|
628
|
-
selectable: false,
|
|
629
|
-
})
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
|
-
for (const row of this.runningRows()) {
|
|
634
|
-
rows.push({
|
|
635
|
-
text: row,
|
|
636
|
-
sourceId: -1,
|
|
637
|
-
sourceStart: 0,
|
|
638
|
-
sourceEnd: 0,
|
|
639
|
-
displayStart: 0,
|
|
640
|
-
displayEnd: displayWidth(row),
|
|
641
|
-
selectable: false,
|
|
642
|
-
})
|
|
770
|
+
this.pendingProjection = {
|
|
771
|
+
width: w,
|
|
772
|
+
version: this.pendingVersion,
|
|
773
|
+
truncated: this.pendingTruncated,
|
|
774
|
+
rows,
|
|
643
775
|
}
|
|
644
776
|
return rows
|
|
645
777
|
}
|
|
@@ -722,10 +854,15 @@ export class Transcript {
|
|
|
722
854
|
const to = Math.max(start.offset, end.offset)
|
|
723
855
|
return source.slice(from, to)
|
|
724
856
|
}
|
|
857
|
+
// `ids` terurut menaik menurut `order` (monotonik saat append + eviction
|
|
858
|
+
// dari depan), jadi lompati sumber SEBELUM awal seleksi dengan pencarian
|
|
859
|
+
// biner — bukan memindai seluruh transkrip (bisa 5.000 entri) tiap salin.
|
|
725
860
|
const parts: string[] = []
|
|
726
|
-
for (
|
|
861
|
+
for (let i = this.orderLowerBound(first.order); i < this.ids.length; i++) {
|
|
862
|
+
const id = this.ids[i]!
|
|
727
863
|
const order = this.sourceOrders.get(id)
|
|
728
|
-
if (order === undefined
|
|
864
|
+
if (order === undefined) continue
|
|
865
|
+
if (order > last.order) break
|
|
729
866
|
const source = this.sourceTexts.get(id) ?? ""
|
|
730
867
|
if (order === first.order) parts.push(source.slice(first.point.offset))
|
|
731
868
|
else if (order === last.order) parts.push(source.slice(0, last.point.offset))
|
|
@@ -734,6 +871,28 @@ export class Transcript {
|
|
|
734
871
|
return parts.join("\n")
|
|
735
872
|
}
|
|
736
873
|
|
|
874
|
+
/** Seleksi kosong (anchor == focus pada sumber yang sama) tanpa menyusun teks. */
|
|
875
|
+
selectionIsEmpty(start: TranscriptPoint, end: TranscriptPoint): boolean {
|
|
876
|
+
const startOrder = this.sourceOrders.get(start.id)
|
|
877
|
+
const endOrder = this.sourceOrders.get(end.id)
|
|
878
|
+
if (startOrder === undefined || endOrder === undefined) return true
|
|
879
|
+
if (start.id === end.id) return start.offset === end.offset
|
|
880
|
+
return false
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
/** Indeks pertama di `ids` dengan order >= `order` (ids terurut menaik). */
|
|
884
|
+
private orderLowerBound(order: number): number {
|
|
885
|
+
let lo = 0
|
|
886
|
+
let hi = this.ids.length
|
|
887
|
+
while (lo < hi) {
|
|
888
|
+
const mid = (lo + hi) >> 1
|
|
889
|
+
const o = this.sourceOrders.get(this.ids[mid]!) ?? -1
|
|
890
|
+
if (o < order) lo = mid + 1
|
|
891
|
+
else hi = mid
|
|
892
|
+
}
|
|
893
|
+
return lo
|
|
894
|
+
}
|
|
895
|
+
|
|
737
896
|
dispose(): void {
|
|
738
897
|
for (const u of this.unsubs) u()
|
|
739
898
|
this.unsubs = []
|
|
@@ -749,9 +908,18 @@ export class Transcript {
|
|
|
749
908
|
? `${this.pending}\n${TRANSCRIPT_TRUNCATION_MARKER}`
|
|
750
909
|
: this.pending
|
|
751
910
|
this.pending = ""
|
|
911
|
+
this.pendingVersion++
|
|
752
912
|
this.pendingTruncated = false
|
|
753
|
-
|
|
913
|
+
this.appendAssistantText(rawText)
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
/** Render jawaban asisten (markdown) menjadi baris logis kind "assistant". */
|
|
917
|
+
private appendAssistantText(raw: string): void {
|
|
918
|
+
const text = normalizeAssistantOutput(raw)
|
|
754
919
|
if (!text) return
|
|
920
|
+
// Pisahkan jawaban dari thinking/diagnostik tepat di atasnya dengan satu
|
|
921
|
+
// baris kosong — supaya "berpikir" tidak nempel ke jawaban.
|
|
922
|
+
if (this.lastKind() === "diagnostic") this.append("", { kind: "assistant" })
|
|
755
923
|
for (const block of parseMarkdownBlocks(sanitizeAnsi(text))) {
|
|
756
924
|
if (block.type === "table") this.appendTable(block.table, { kind: "assistant" })
|
|
757
925
|
else {
|
|
@@ -760,6 +928,34 @@ export class Transcript {
|
|
|
760
928
|
}
|
|
761
929
|
}
|
|
762
930
|
|
|
931
|
+
/**
|
|
932
|
+
* Rebuild riwayat transkrip dari event presentasi durable (jalur resume).
|
|
933
|
+
* Dipanggil SEKALI sebelum turn live berikutnya, jadi tak ada double-render.
|
|
934
|
+
* `user.message` → echo prompt; `model.completed` → jawaban model; sisanya
|
|
935
|
+
* (turn.*, tool.*, task.status, …) melewati jalur `presentationEvent` yang
|
|
936
|
+
* sama seperti live — snapshot presentasi sudah di-rebuild saat resume,
|
|
937
|
+
* sehingga ledger/provenance mengacu data yang benar.
|
|
938
|
+
*/
|
|
939
|
+
replayHistory(events: readonly UiPresentationEvent[]): void {
|
|
940
|
+
for (const event of events) {
|
|
941
|
+
if (event.type === "user.message") {
|
|
942
|
+
if (event.text) this.pushUser(event.text)
|
|
943
|
+
continue
|
|
944
|
+
}
|
|
945
|
+
if (event.type === "model.completed") {
|
|
946
|
+
if (event.text) this.appendAssistantText(event.text)
|
|
947
|
+
continue
|
|
948
|
+
}
|
|
949
|
+
// reasoning/plan/finding/result/diagnostic/approval/… tak punya baris
|
|
950
|
+
// transkrip di jalur live; presentationEvent men-drop-nya (no-op aman).
|
|
951
|
+
this.presentationEvent(event)
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
private lastKind(): TranscriptMeta["kind"] | undefined {
|
|
956
|
+
return this.meta[this.meta.length - 1]?.kind
|
|
957
|
+
}
|
|
958
|
+
|
|
763
959
|
private presentationSnapshot(): UiPresentationSnapshot | null {
|
|
764
960
|
if (!this.getSnapshot) return null
|
|
765
961
|
try {
|
|
@@ -770,10 +966,25 @@ export class Transcript {
|
|
|
770
966
|
}
|
|
771
967
|
|
|
772
968
|
private presentationEvent(event: UiPresentationEvent): void {
|
|
969
|
+
if (event.type === "turn.started") {
|
|
970
|
+
this.commit()
|
|
971
|
+
this.commitThinking()
|
|
972
|
+
this.activityFold = []
|
|
973
|
+
return
|
|
974
|
+
}
|
|
773
975
|
if (event.type === "turn.completed") {
|
|
774
976
|
this.commit()
|
|
775
977
|
this.commitThinking()
|
|
776
|
-
|
|
978
|
+
// minimizeActivity ON → fold meringkas sendiri (nama tool + ok/gagal);
|
|
979
|
+
// turnSummary (turn · files · durasi) dilewati agar tidak ada dua ringkasan.
|
|
980
|
+
if (!this.uiState.minimizeActivity) this.turnSummary(event.summary, event)
|
|
981
|
+
this.flushActivityFold()
|
|
982
|
+
return
|
|
983
|
+
}
|
|
984
|
+
if (event.type === "turn.failed" || event.type === "turn.cancelled") {
|
|
985
|
+
this.commit()
|
|
986
|
+
this.commitThinking()
|
|
987
|
+
this.flushActivityFold()
|
|
777
988
|
return
|
|
778
989
|
}
|
|
779
990
|
// F-TASK-1: status task kanonik (t<n>) + DAG dirender sebagai baris ledger,
|
|
@@ -813,29 +1024,6 @@ export class Transcript {
|
|
|
813
1024
|
return this.presentationSnapshot()?.activities.find((a) => a.toolCallId === toolCallId)
|
|
814
1025
|
}
|
|
815
1026
|
|
|
816
|
-
private statusWord(status: UiToolStatus): string {
|
|
817
|
-
if (status === "completed") return t("ts.statusCompleted")
|
|
818
|
-
if (status === "failed") return t("ts.statusFailed")
|
|
819
|
-
if (status === "denied") return t("ts.statusDenied")
|
|
820
|
-
if (status === "cancelled") return t("ts.statusCancelled")
|
|
821
|
-
if (status === "interrupted") return t("ts.statusInterrupted")
|
|
822
|
-
return t("ts.statusRunning")
|
|
823
|
-
}
|
|
824
|
-
|
|
825
|
-
private statusGlyph(status: UiToolStatus): string {
|
|
826
|
-
if (status === "completed") return glyphs.check
|
|
827
|
-
if (status === "failed") return glyphs.cross
|
|
828
|
-
if (status === "denied") return glyphs.denied
|
|
829
|
-
return glyphs.circle
|
|
830
|
-
}
|
|
831
|
-
|
|
832
|
-
private statusPaint(status: UiToolStatus, line: string): string {
|
|
833
|
-
if (status === "completed") return c.success(line)
|
|
834
|
-
if (status === "failed") return c.error(line)
|
|
835
|
-
if (status === "denied") return c.warning(line)
|
|
836
|
-
return c.muted(line)
|
|
837
|
-
}
|
|
838
|
-
|
|
839
1027
|
private presentationLedger(event: UiPresentationEvent): void {
|
|
840
1028
|
// Observasi verifikasi punya baris ledger sendiri (dedup per invocation):
|
|
841
1029
|
// terminal tool sudah tampil duluan, dan transcript append-only tak bisa
|
|
@@ -880,14 +1068,20 @@ export class Transcript {
|
|
|
880
1068
|
// P2.11: penanda verifikasi/provenans dari deskripsi policy (ASCII aman).
|
|
881
1069
|
// Absen = unknown/live — tidak dirender sebagai keberhasilan.
|
|
882
1070
|
const verification = desc?.verification ?? activity?.verification
|
|
883
|
-
const verificationMark = !verification
|
|
884
|
-
? ""
|
|
885
|
-
: verification.verdict === "present"
|
|
886
|
-
? " [verified]"
|
|
887
|
-
: ` [unverified:${verification.verdict}]`
|
|
888
1071
|
const provenance = desc?.provenance ?? activity?.provenance
|
|
889
|
-
|
|
890
|
-
|
|
1072
|
+
// Keputusan marker lewat policy kanonik bila di-inject; fallback inline
|
|
1073
|
+
// legacy (tanpa policy) dijaga test display agar tak divergen dari
|
|
1074
|
+
// projection.ts (`verificationMark`/`provenanceMark`).
|
|
1075
|
+
const verificationMark = this.policy
|
|
1076
|
+
? this.policy.verificationMark(verification)
|
|
1077
|
+
: !verification
|
|
1078
|
+
? ""
|
|
1079
|
+
: verification.verdict === "present"
|
|
1080
|
+
? " [verified]"
|
|
1081
|
+
: ` [unverified:${verification.verdict}]`
|
|
1082
|
+
const provenanceMark = this.policy
|
|
1083
|
+
? this.policy.provenanceMark(provenance)
|
|
1084
|
+
: provenance === "reconstructed"
|
|
891
1085
|
? " [reconstructed]"
|
|
892
1086
|
: provenance === "replay"
|
|
893
1087
|
? " [replay]"
|
|
@@ -903,8 +1097,15 @@ export class Transcript {
|
|
|
903
1097
|
: denyReason
|
|
904
1098
|
? `: ${truncateToWidth(sanitizeAnsi(denyReason), 200, "…").split("\n")[0] ?? ""}`
|
|
905
1099
|
: ""
|
|
906
|
-
const line = ` ${
|
|
907
|
-
|
|
1100
|
+
const line = ` ${statusGlyph(status)} ${name}${targetText} ${statusWord(status)}${retry}${child}${verificationMark}${provenanceMark}${message}`
|
|
1101
|
+
// Lipat aktivitas (opencode-like): saat minimizeActivity aktif, baris ledger
|
|
1102
|
+
// per-tool TIDAK boleh menghilang diam-diam — ditahan lalu dirangkum jadi
|
|
1103
|
+
// SATU baris saat turn selesai (detail via /expand).
|
|
1104
|
+
if (this.uiState.minimizeActivity) {
|
|
1105
|
+
this.activityFold.push({ name, status, line })
|
|
1106
|
+
return
|
|
1107
|
+
}
|
|
1108
|
+
this.append(paintLedger(status, line), {
|
|
908
1109
|
kind: "activity",
|
|
909
1110
|
...(event.seq !== undefined ? { seq: event.seq } : {}),
|
|
910
1111
|
...(event.turnId !== undefined ? { turnId: event.turnId } : {}),
|
|
@@ -914,23 +1115,13 @@ export class Transcript {
|
|
|
914
1115
|
})
|
|
915
1116
|
}
|
|
916
1117
|
|
|
917
|
-
/** F-AGENT-1:
|
|
918
|
-
private runMarker(activity: UiPresentationActivity): string {
|
|
919
|
-
const id = activity.runId ?? activity.childSessionId
|
|
920
|
-
if (!id) return ""
|
|
921
|
-
const prefix = id.startsWith("run_") ? "run_" : id.startsWith("sub_") ? "sub_" : ""
|
|
922
|
-
const bare = id.slice(prefix.length).replace(/-/g, "")
|
|
923
|
-
return prefix + bare.slice(0, 8)
|
|
924
|
-
}
|
|
925
|
-
|
|
926
|
-
/**
|
|
927
|
-
* F-AGENT-1: baris terminal tool anak — identitas run + tool + status.
|
|
1118
|
+
/** F-AGENT-1: baris terminal tool anak — identitas run + tool + status.
|
|
928
1119
|
* Paralel dipisah via runMarker (data aktual runId/childSessionId), bukan
|
|
929
1120
|
* hitungan "n tool anak" yang menyatukan run berbeda.
|
|
930
1121
|
*/
|
|
931
1122
|
private childLedger(event: UiPresentationEvent, activity: UiPresentationActivity): void {
|
|
932
1123
|
this.commit()
|
|
933
|
-
const marker =
|
|
1124
|
+
const marker = runMarker(activity)
|
|
934
1125
|
const name = sanitizeAnsiLine(activity.name ?? event.name ?? "tool")
|
|
935
1126
|
const target = activity.target ?? event.target
|
|
936
1127
|
const targetText = target ? ` ${truncateToWidth(sanitizeAnsiLine(target), 120, "")}` : ""
|
|
@@ -940,8 +1131,8 @@ export class Transcript {
|
|
|
940
1131
|
? `: ${truncateToWidth(sanitizeAnsi(String(event.message)), 200, "…").split("\n")[0] ?? ""}`
|
|
941
1132
|
: ""
|
|
942
1133
|
const markerText = marker ? `${marker} ` : ""
|
|
943
|
-
const line = ` ↳ ${markerText}${name}${targetText} ${
|
|
944
|
-
this.append(
|
|
1134
|
+
const line = ` ↳ ${markerText}${name}${targetText} ${statusWord(status)}${message}`
|
|
1135
|
+
this.append(paintLedger(status, line), {
|
|
945
1136
|
kind: "activity",
|
|
946
1137
|
...(event.seq !== undefined ? { seq: event.seq } : {}),
|
|
947
1138
|
...(event.turnId !== undefined ? { turnId: event.turnId } : {}),
|
|
@@ -963,10 +1154,10 @@ export class Transcript {
|
|
|
963
1154
|
const targetText = target ? ` ${truncateToWidth(sanitizeAnsiLine(target), 120, "")}` : ""
|
|
964
1155
|
const line =
|
|
965
1156
|
verification.verdict === "present"
|
|
966
|
-
? ` ${
|
|
1157
|
+
? ` ${statusGlyph("completed")} ${name}${targetText} verified`
|
|
967
1158
|
: ` ? ${name}${targetText} unverified (${verification.verdict})`
|
|
968
1159
|
this.append(
|
|
969
|
-
verification.verdict === "present" ?
|
|
1160
|
+
verification.verdict === "present" ? paintLedger("completed", line) : c.muted(line),
|
|
970
1161
|
{
|
|
971
1162
|
kind: "activity",
|
|
972
1163
|
...(event.seq !== undefined ? { seq: event.seq } : {}),
|
|
@@ -1097,7 +1288,8 @@ export class Transcript {
|
|
|
1097
1288
|
)
|
|
1098
1289
|
}))
|
|
1099
1290
|
: undefined
|
|
1100
|
-
const turnId =
|
|
1291
|
+
const turnId =
|
|
1292
|
+
event.turnId ?? turn?.turnId ?? snapshot?.turns[snapshot.turns.length - 1]?.turnId ?? 0
|
|
1101
1293
|
if (event.turnId !== undefined) {
|
|
1102
1294
|
if (this.summarizedTurns.has(event.turnId)) return
|
|
1103
1295
|
this.summarizedTurns.add(event.turnId)
|
|
@@ -1120,10 +1312,49 @@ export class Transcript {
|
|
|
1120
1312
|
})
|
|
1121
1313
|
}
|
|
1122
1314
|
|
|
1315
|
+
/** Flush lipatan aktivitas (minimizeActivity) menjadi SATU baris ringkas
|
|
1316
|
+
* (opencode-like) + buffer detail untuk /expand. Tidak menghilangkan isi
|
|
1317
|
+
* diam-diam: nama tool + hitung ok/gagal tetap terlihat. */
|
|
1318
|
+
private flushActivityFold(): void {
|
|
1319
|
+
const fold = this.activityFold
|
|
1320
|
+
this.activityFold = []
|
|
1321
|
+
if (fold.length === 0) return
|
|
1322
|
+
const count = (status: string) => fold.reduce((n, e) => n + (e.status === status ? 1 : 0), 0)
|
|
1323
|
+
const ok = count("completed")
|
|
1324
|
+
const failed = count("failed")
|
|
1325
|
+
const denied = count("denied")
|
|
1326
|
+
const names = [...new Set(fold.map((e) => e.name))]
|
|
1327
|
+
const shown = names.slice(0, 3).join(", ")
|
|
1328
|
+
const more = names.length - 3
|
|
1329
|
+
const namePart = shown ? ` · ${shown}${more > 0 ? ` +${more}` : ""}` : ""
|
|
1330
|
+
const stats = [
|
|
1331
|
+
ok ? `${ok} ok` : "",
|
|
1332
|
+
failed ? `${failed} ${t("ts.statusFailed")}` : "",
|
|
1333
|
+
denied ? `${denied} ${t("ts.statusDenied")}` : "",
|
|
1334
|
+
]
|
|
1335
|
+
.filter(Boolean)
|
|
1336
|
+
.join(", ")
|
|
1337
|
+
const statPart = stats ? ` · ${stats}` : ""
|
|
1338
|
+
const line = ` ${glyphs.check} ${fold.length} tool${fold.length > 1 ? "s" : ""}${namePart}${statPart}`
|
|
1339
|
+
// Detail tetap tersedia via /expand (tidak dibuang).
|
|
1340
|
+
this.uiState.rememberCollapsedSection("activity", fold.map((e) => e.line).join("\n"))
|
|
1341
|
+
this.append(line, { kind: "activity" })
|
|
1342
|
+
}
|
|
1343
|
+
|
|
1344
|
+
/** Fase 1 perf (butir 2): daftar activity running per snapshot (memoized). */
|
|
1345
|
+
private runningActivities(snapshot: UiPresentationSnapshot): UiPresentationActivity[] {
|
|
1346
|
+
if (this.runningMemo && this.runningMemo.snapshot === snapshot) {
|
|
1347
|
+
return this.runningMemo.running
|
|
1348
|
+
}
|
|
1349
|
+
const running = snapshot.activities.filter((a) => a.status === "running")
|
|
1350
|
+
this.runningMemo = { snapshot, running }
|
|
1351
|
+
return running
|
|
1352
|
+
}
|
|
1353
|
+
|
|
1123
1354
|
private runningRows(): string[] {
|
|
1124
1355
|
const snapshot = this.presentationSnapshot()
|
|
1125
1356
|
if (!snapshot) return []
|
|
1126
|
-
const running =
|
|
1357
|
+
const running = this.runningActivities(snapshot)
|
|
1127
1358
|
const roots = running.filter((a) => !a.parentToolCallId)
|
|
1128
1359
|
const row = (activity: (typeof running)[number], child: boolean, marker: string): string => {
|
|
1129
1360
|
const name = sanitizeAnsiLine(activity.name)
|
|
@@ -1147,7 +1378,7 @@ export class Transcript {
|
|
|
1147
1378
|
for (const activity of roots) {
|
|
1148
1379
|
out.push(row(activity, false, ""))
|
|
1149
1380
|
for (const child of running.filter((a) => a.parentToolCallId === activity.toolCallId))
|
|
1150
|
-
out.push(row(child, true,
|
|
1381
|
+
out.push(row(child, true, runMarker(child)))
|
|
1151
1382
|
}
|
|
1152
1383
|
// Anak yatim (parent tak lagi running/root): tetap tampil, jangan hilang.
|
|
1153
1384
|
for (const activity of running) {
|
|
@@ -1156,7 +1387,7 @@ export class Transcript {
|
|
|
1156
1387
|
roots.some((r) => r.toolCallId === activity.parentToolCallId)
|
|
1157
1388
|
)
|
|
1158
1389
|
continue
|
|
1159
|
-
out.push(row(activity, true,
|
|
1390
|
+
out.push(row(activity, true, runMarker(activity)))
|
|
1160
1391
|
}
|
|
1161
1392
|
return out
|
|
1162
1393
|
}
|