minicode-ai 0.11.0 → 0.13.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.
Files changed (221) hide show
  1. package/CHANGELOG.md +98 -0
  2. package/LICENSE +21 -21
  3. package/README.md +4 -4
  4. package/cli/args.ts +46 -0
  5. package/cli/commands/acp.ts +163 -10
  6. package/cli/commands/config.ts +33 -18
  7. package/cli/commands/daemon.ts +515 -0
  8. package/cli/commands/exec.ts +145 -53
  9. package/cli/commands/openwork.ts +986 -0
  10. package/cli/commands/sessions.ts +4 -1
  11. package/cli/commands/stats.ts +34 -4
  12. package/cli/commands.ts +217 -2
  13. package/cli/index.ts +146 -14
  14. package/cli/recovery-warning.ts +115 -0
  15. package/cli/router.ts +32 -1
  16. package/cli/setup.ts +2332 -171
  17. package/cli/tui.ts +113 -7
  18. package/docs/OUTPUT_ARCHITECTURE_AUDIT.md +489 -0
  19. package/docs/OUTPUT_EVENT_MODEL.md +289 -0
  20. package/docs/OUTPUT_IMPLEMENTATION_PLAN.md +391 -0
  21. package/docs/OUTPUT_PROTOCOL_SPEC.md +285 -0
  22. package/docs/OUTPUT_RENDERING_SPEC.md +248 -0
  23. package/docs/OUTPUT_UX_RULES.md +449 -0
  24. package/docs/PLAN_UIUX_V6.md +2 -2
  25. package/docs/README.md +4 -3
  26. package/docs/TERMINAL_CONTRACT.md +278 -66
  27. package/docs/architecture.md +89 -7
  28. package/docs/changelog.md +1 -1
  29. package/docs/choosing-mode.md +2 -2
  30. package/docs/cli.md +9 -5
  31. package/docs/concepts.md +1 -1
  32. package/docs/contributing.md +9 -2
  33. package/docs/environment.md +6 -2
  34. package/docs/exec.md +46 -5
  35. package/docs/memory-sessions.md +2 -0
  36. package/docs/policy-sandbox.md +1 -1
  37. package/docs/pricing-budget.md +1 -1
  38. package/docs/quickstart.md +2 -2
  39. package/docs/repl.md +6 -2
  40. package/docs/security-model.md +1 -1
  41. package/docs/security.md +1 -1
  42. package/docs/skills.md +2 -2
  43. package/docs/terminal.md +9 -5
  44. package/docs/tools.md +1 -1
  45. package/package.json +35 -5
  46. package/src/app/session.ts +261 -15
  47. package/src/app/tool-layer.ts +94 -7
  48. package/src/daemon/approvals.ts +361 -0
  49. package/src/daemon/capability.ts +145 -0
  50. package/src/daemon/children.ts +142 -0
  51. package/src/daemon/client.ts +267 -0
  52. package/src/daemon/control.ts +350 -0
  53. package/src/daemon/discovery.ts +234 -0
  54. package/src/daemon/feed.ts +155 -0
  55. package/src/daemon/framing.ts +94 -0
  56. package/src/daemon/host.ts +316 -0
  57. package/src/daemon/protocol.ts +217 -0
  58. package/src/daemon/resource.ts +170 -0
  59. package/src/daemon/sanitize.ts +57 -0
  60. package/src/daemon/server.ts +627 -0
  61. package/src/daemon/store.ts +317 -0
  62. package/src/daemon/subscription.ts +270 -0
  63. package/src/daemon/telemetry.ts +81 -0
  64. package/src/hooks/run.ts +12 -1
  65. package/src/lib/atomic-write.ts +29 -3
  66. package/src/lib/db-path.ts +26 -0
  67. package/src/lib/keystore.ts +544 -42
  68. package/src/lib/net.ts +43 -1
  69. package/src/lib/safe-open.ts +116 -1
  70. package/src/lib/session-id.ts +15 -0
  71. package/src/lsp/client.ts +123 -5
  72. package/src/mcp/client.ts +139 -17
  73. package/src/mcp/server.ts +177 -50
  74. package/src/mcp/transport.ts +16 -19
  75. package/src/memory/vector.ts +770 -55
  76. package/src/policy/allowlist.ts +14 -2
  77. package/src/policy/bash-guard.ts +105 -10
  78. package/src/policy/compaction.ts +82 -5
  79. package/src/policy/consequence-engine.ts +220 -0
  80. package/src/policy/context.ts +132 -0
  81. package/src/policy/executor.ts +187 -121
  82. package/src/policy/no-progress.ts +559 -0
  83. package/src/policy/permission.ts +4 -8
  84. package/src/policy/pricing.ts +17 -3
  85. package/src/policy/scrub.ts +69 -2
  86. package/src/policy/tool-contract.ts +515 -0
  87. package/src/policy/usage.ts +310 -24
  88. package/src/policy/verifier.ts +6 -3
  89. package/src/policy/work-mode.ts +182 -0
  90. package/src/presentation/adapter.ts +533 -26
  91. package/src/presentation/events.ts +151 -0
  92. package/src/presentation/model.ts +180 -27
  93. package/src/presentation/projection.ts +858 -0
  94. package/src/presentation/reducer.ts +645 -310
  95. package/src/presentation/store.ts +12 -7
  96. package/src/providers/anthropic.ts +18 -10
  97. package/src/providers/responses.ts +17 -7
  98. package/src/runtime/capability.ts +409 -0
  99. package/src/runtime/child-execution.ts +274 -0
  100. package/src/runtime/composition.ts +958 -0
  101. package/src/runtime/dispatch.ts +591 -0
  102. package/src/runtime/execution-backend.ts +632 -0
  103. package/src/runtime/execution-events.ts +272 -0
  104. package/src/runtime/execution-id.ts +230 -0
  105. package/src/runtime/execution-journal.ts +926 -0
  106. package/src/runtime/execution-kernel.ts +456 -0
  107. package/src/runtime/execution-registry.ts +379 -0
  108. package/src/runtime/process-supervision.ts +276 -0
  109. package/src/runtime/production-execution.ts +551 -0
  110. package/src/runtime/production-runtime.ts +217 -0
  111. package/src/runtime/recovery-safety.ts +70 -0
  112. package/src/runtime/recovery.ts +477 -0
  113. package/src/runtime/runtime-capabilities.ts +179 -0
  114. package/src/runtime/runtime-diagnostics.ts +141 -0
  115. package/src/runtime/runtime-host.ts +365 -0
  116. package/src/runtime/runtime-status-facts.ts +222 -0
  117. package/src/runtime/runtime-status-provider.ts +74 -0
  118. package/src/runtime/runtime-status.ts +459 -0
  119. package/src/runtime/runtime-task-admission.ts +101 -0
  120. package/src/runtime/supervisor.ts +444 -0
  121. package/src/session/authority.ts +168 -0
  122. package/src/session/checkpoint.ts +88 -1
  123. package/src/session/context-adapter.ts +251 -0
  124. package/src/session/context-assembly.ts +242 -0
  125. package/src/session/context-identity.ts +389 -0
  126. package/src/session/context-projection.ts +248 -0
  127. package/src/session/context-selector.ts +500 -0
  128. package/src/session/cross-session-adoption.ts +249 -0
  129. package/src/session/full-history-fold.ts +171 -0
  130. package/src/session/identity.ts +192 -0
  131. package/src/session/journal.ts +805 -102
  132. package/src/session/open-work-intent.ts +732 -0
  133. package/src/session/open-work.ts +767 -0
  134. package/src/session/pending-tools.ts +94 -0
  135. package/src/session/persistence.ts +3569 -127
  136. package/src/session/runtime-header.ts +208 -0
  137. package/src/session/shadow-git.ts +13 -5
  138. package/src/session/verification.ts +1623 -0
  139. package/src/task/assignment.ts +136 -0
  140. package/src/task/autonomous-adapter.ts +168 -0
  141. package/src/task/autonomous-context.ts +630 -0
  142. package/src/task/autonomous-policy.ts +490 -0
  143. package/src/task/continuity.ts +179 -0
  144. package/src/task/execution-cancellation.ts +165 -0
  145. package/src/task/graph-validate.ts +379 -0
  146. package/src/task/graph.ts +305 -0
  147. package/src/task/identity.ts +230 -0
  148. package/src/task/model.ts +417 -0
  149. package/src/task/production-scheduler.ts +293 -0
  150. package/src/task/readiness.ts +229 -0
  151. package/src/task/scheduler-observability.ts +387 -0
  152. package/src/task/scheduler.ts +1197 -0
  153. package/src/task/scheduling-policy.ts +165 -0
  154. package/src/task/session-authority.ts +148 -0
  155. package/src/task/session-ownership.ts +211 -0
  156. package/src/task/store.ts +2887 -0
  157. package/src/task/sync.ts +343 -0
  158. package/src/task/trigger.ts +260 -0
  159. package/src/tools/bash.ts +377 -211
  160. package/src/tools/code_run.ts +1 -1
  161. package/src/tools/delete_file.ts +1 -1
  162. package/src/tools/edit.ts +33 -6
  163. package/src/tools/evidence.ts +30 -0
  164. package/src/tools/git.ts +4 -4
  165. package/src/tools/glob.ts +12 -3
  166. package/src/tools/grep.ts +1 -1
  167. package/src/tools/lsp.ts +4 -4
  168. package/src/tools/mcp_call.ts +11 -4
  169. package/src/tools/memory.ts +153 -18
  170. package/src/tools/move_file.ts +1 -1
  171. package/src/tools/patch.ts +1 -1
  172. package/src/tools/read_file.ts +1 -1
  173. package/src/tools/read_image.ts +1 -1
  174. package/src/tools/submit_result.ts +1 -1
  175. package/src/tools/task.ts +437 -41
  176. package/src/tools/todo.ts +662 -35
  177. package/src/tools/web_fetch.ts +4 -2
  178. package/src/tools/web_search.ts +9 -3
  179. package/src/tools/write_file.ts +1 -1
  180. package/src/ui/assistant/simple.ts +123 -50
  181. package/src/ui/assistant/turn-status.ts +17 -3
  182. package/src/ui/contract.ts +184 -0
  183. package/src/ui/footer.ts +54 -18
  184. package/src/ui/i18n/en.ts +62 -6
  185. package/src/ui/i18n/id.ts +62 -6
  186. package/src/ui/input/prompt-engine.ts +120 -25
  187. package/src/ui/render/errors.ts +39 -1
  188. package/src/ui/render/markdown-table.ts +455 -0
  189. package/src/ui/render/markdown.ts +22 -1
  190. package/src/ui/render/table-grid.ts +184 -0
  191. package/src/ui/render/table.ts +15 -76
  192. package/src/ui/runtime/screen.ts +7 -2
  193. package/src/ui/runtime/statusline.ts +25 -6
  194. package/src/ui/tui/app.ts +598 -133
  195. package/src/ui/tui/transcript.ts +531 -89
  196. package/vendor/minicore/VENDOR.md +1 -1
  197. package/vendor/minicore/src/core/budget.ts +25 -25
  198. package/vendor/minicore/src/core/compact.ts +75 -75
  199. package/vendor/minicore/src/core/errors.ts +59 -59
  200. package/vendor/minicore/src/core/events.ts +73 -73
  201. package/vendor/minicore/src/core/executor.ts +139 -139
  202. package/vendor/minicore/src/core/history.ts +31 -31
  203. package/vendor/minicore/src/core/index.ts +41 -41
  204. package/vendor/minicore/src/core/loop.ts +355 -355
  205. package/vendor/minicore/src/core/permission.ts +22 -22
  206. package/vendor/minicore/src/core/provider.ts +39 -39
  207. package/vendor/minicore/src/core/recovery.ts +35 -35
  208. package/vendor/minicore/src/core/session.ts +327 -327
  209. package/vendor/minicore/src/core/snapshot.ts +146 -146
  210. package/vendor/minicore/src/core/tokens.ts +107 -107
  211. package/vendor/minicore/src/core/tool.ts +115 -115
  212. package/vendor/minicore/src/core/types.ts +50 -50
  213. package/vendor/minicore/src/providers/openai-compat.ts +417 -417
  214. package/AGENTS.md +0 -45
  215. package/PLAN.md +0 -491
  216. package/docs/ARCHITECTURE.html +0 -1248
  217. package/docs/CONTROL-PLANE-MAP.md +0 -139
  218. package/docs/HARNESS.md +0 -150
  219. package/docs/SUMMARY.md +0 -52
  220. package/docs/UI_RENDER_PIPELINE.md +0 -165
  221. package/docs/USAGE.md +0 -11
@@ -8,19 +8,25 @@
8
8
  // Mode compact saja di Fase 1: teks model mengalir, ledger tool satu baris
9
9
  // ` › nama target` (grammar sama dengan REPL), error merah satu baris.
10
10
  import type {
11
+ PresentationPolicy,
11
12
  UiBus,
12
13
  UiPresentationEvent,
13
14
  UiPresentationSnapshot,
14
15
  UiToolStatus,
15
16
  } from "../contract.ts"
16
17
  import { t } from "../i18n/locale.ts"
18
+ import { parseFence, renderInline } from "../render/markdown.ts"
19
+ import { type MarkdownTable, parseMarkdownBlocks } from "../render/markdown-table.ts"
17
20
  import { reasoning } from "../render/reasoning.ts"
18
- import { sanitizeAnsi, sanitizeAnsiLine } from "../render/sanitize.ts"
21
+ import { sanitizeAnsi, sanitizeAnsiLine, stripSgr } from "../render/sanitize.ts"
22
+ import { renderMarkdownTable } from "../render/table-grid.ts"
19
23
  import { c, glyphs } from "../render/theme.ts"
20
- import { chunkByWidth, truncateToWidth } from "../render/width.ts"
24
+ import { chunkByWidth, displayWidth, truncateToWidth } from "../render/width.ts"
21
25
 
22
26
  /** Cap memori: baris logis tertua dibuang diam-diam (kontrak I12). */
23
27
  export const TRANSCRIPT_CAP = 5000
28
+ export const TRANSCRIPT_TEXT_MAX_CHARS = 1_000_000
29
+ const TRANSCRIPT_TRUNCATION_MARKER = "… [transcript truncated: turn cap exceeded]"
24
30
  /**
25
31
  * Sink approval TUI: pemilik layar (cli/tui.ts) mendaftarkan transkrip +
26
32
  * repaint + suspend/resume agar prompt persetujuan tercatat di transkrip dan
@@ -55,18 +61,36 @@ export interface TranscriptMeta {
55
61
  approvalId?: string
56
62
  status?: UiToolStatus
57
63
  expandRef?: { toolCallId: string; idx: number }
64
+ table?: MarkdownTable
58
65
  }
59
66
 
60
67
  export interface TranscriptOptions {
61
68
  getSnapshot?: () => UiPresentationSnapshot | null
62
69
  onPresentationEvent?: (handler: (event: UiPresentationEvent) => void) => () => void
70
+ /** Kebijakan kanonik dari composition root; absen = logika inline legacy. */
71
+ policy?: PresentationPolicy
72
+ maxPendingChars?: number
63
73
  }
64
74
 
65
- function targetForFallback(args: Record<string, unknown>): string | undefined {
66
- if (typeof args.path === "string" && args.path) return args.path
67
- const cmd = args.cmd ?? args.command
68
- if (typeof cmd === "string" && cmd) return `$ ${cmd}`
69
- return undefined
75
+ export interface TranscriptPoint {
76
+ id: number
77
+ offset: number
78
+ }
79
+
80
+ export interface TranscriptRow {
81
+ text: string
82
+ sourceId: number
83
+ sourceStart: number
84
+ sourceEnd: number
85
+ displayStart: number
86
+ displayEnd: number
87
+ selectable: boolean
88
+ }
89
+
90
+ export interface TranscriptViewport {
91
+ rows: TranscriptRow[]
92
+ firstIndex: number
93
+ totalRows: number
70
94
  }
71
95
 
72
96
  function formatElapsed(ms: number): string {
@@ -77,9 +101,56 @@ function formatElapsed(ms: number): string {
77
101
  return `${Math.floor(minutes / 60)}h${String(minutes % 60).padStart(2, "0")}m`
78
102
  }
79
103
 
104
+ type FenceState = "outside" | "inside" | "boundary"
105
+
106
+ function renderAssistantLine(line: string, fenceState: FenceState): string | null {
107
+ if (fenceState === "boundary") return null
108
+ if (fenceState === "inside") return line
109
+ if (!/(?:\*{1,2}|`|^#{1,6}\s|~~|\[[^\]]+\]\()/.test(line)) return line
110
+ const heading = /^(#{1,6})\s+(.*)$/.exec(line)
111
+ if (heading) return c.bold(renderInline(heading[2] ?? ""))
112
+ return renderInline(line)
113
+ }
114
+
115
+ let selectionSegmenter: Intl.Segmenter | undefined
116
+
117
+ function offsetAtColumn(text: string, start: number, end: number, column: number): number {
118
+ const from = Math.max(0, Math.min(start, text.length))
119
+ const to = Math.max(from, Math.min(end, text.length))
120
+ const target = Math.max(0, column)
121
+ let used = 0
122
+ try {
123
+ selectionSegmenter ??= new Intl.Segmenter("und", { granularity: "grapheme" })
124
+ for (const part of selectionSegmenter.segment(text.slice(from, to))) {
125
+ const width = displayWidth(part.segment)
126
+ if (target <= used + width / 2) return from + part.index
127
+ used += width
128
+ if (target <= used) return from + part.index + part.segment.length
129
+ }
130
+ } catch {
131
+ for (const part of text.slice(from, to)) {
132
+ const width = displayWidth(part)
133
+ if (target <= used + width / 2) return from + text.indexOf(part, from)
134
+ used += width
135
+ if (target <= used) return from + text.indexOf(part, from) + part.length
136
+ }
137
+ }
138
+ return to
139
+ }
140
+
80
141
  export class Transcript {
81
142
  private lines: string[] = []
143
+ private tables: (MarkdownTable | null)[] = []
144
+ private ids: number[] = []
145
+ private sourcePrefixes: string[] = []
146
+ private sourceTexts = new Map<number, string>()
147
+ private sourceOrders = new Map<number, number>()
148
+ private assistantDisplay = new Map<number, string | null>()
149
+ private nextId = 1
150
+ private nextOrder = 1
82
151
  private pending = ""
152
+ private pendingTruncated = false
153
+ private maxPendingChars: number
83
154
  /** Hitung monotonik baris yang pernah ditambah — basis indikator "baru"
84
155
  * yang kebal evict cap 5000 (size() menyusut saat tertua dibuang). */
85
156
  private totalAppended = 0
@@ -91,14 +162,17 @@ export class Transcript {
91
162
  private evicted = 0
92
163
  private hasEvictMarker = false
93
164
  private getSnapshot: (() => UiPresentationSnapshot | null) | undefined
94
- private presentationEvents = false
165
+ private policy: PresentationPolicy | undefined
95
166
  private presentationUnsub: (() => void) | null = null
96
167
  private presentedTerminals = new Set<string>()
168
+ private presentedVerifications = new Set<string>()
97
169
  private summarizedTurns = new Set<number>()
98
170
  private unsubs: (() => void)[] = []
99
171
 
100
172
  constructor(bus: UiBus, opts: TranscriptOptions = {}) {
101
173
  this.getSnapshot = opts.getSnapshot
174
+ this.policy = opts.policy
175
+ this.maxPendingChars = Math.max(1, opts.maxPendingChars ?? TRANSCRIPT_TEXT_MAX_CHARS)
102
176
  // Gagal subscribe = transcript mati total; biarkan throw (fail-closed).
103
177
  this.unsubs = [
104
178
  bus.on("provider:text", (e: { text: string }) => this.stream(e.text)),
@@ -114,27 +188,34 @@ export class Transcript {
114
188
  this.commit()
115
189
  this.commitThinking()
116
190
  }),
117
- bus.on("execution:completed", (e) => {
118
- if (!this.presentationEvents) this.ledger(e)
119
- }),
120
191
  bus.on("provider:extension", (e: { kind: string; data: unknown }) => this.extension(e)),
121
192
  bus.on("context:compacted", (e: { reason: string }) =>
122
193
  this.push(c.muted(t("ts.compacted", { reason: sanitizeAnsiLine(e.reason ?? "") }))),
123
194
  ),
124
195
  ]
125
196
  if (opts.onPresentationEvent) {
126
- this.presentationEvents = true
127
197
  this.presentationUnsub = opts.onPresentationEvent((event) => this.presentationEvent(event))
128
198
  }
129
199
  }
130
200
 
131
201
  /** Teks model mengalir — ditahan sebagai ekor hidup sampai commit. */
132
202
  stream(text: string): void {
133
- if (text) {
134
- // Jawaban dimulai = fase thinking selesai.
135
- this.commitThinking()
203
+ if (!text) return
204
+ this.commitThinking()
205
+ const remaining = this.maxPendingChars - this.pending.length
206
+ if (remaining <= 0) {
207
+ this.pendingTruncated = true
208
+ return
209
+ }
210
+ if (text.length <= remaining) {
136
211
  this.pending += text
212
+ return
137
213
  }
214
+ let keep = text.slice(0, remaining)
215
+ const last = keep.charCodeAt(keep.length - 1)
216
+ if (last >= 0xd800 && last <= 0xdbff) keep = keep.slice(0, -1)
217
+ this.pending += keep
218
+ this.pendingTruncated = true
138
219
  }
139
220
 
140
221
  /** Chunk reasoning (`provider:extension` kind reasoning, data {text}). */
@@ -177,8 +258,14 @@ export class Transcript {
177
258
  pushUser(prompt: string): void {
178
259
  const rows = sanitizeAnsi(prompt).split("\n")
179
260
  const [first, ...rest] = rows
180
- this.push(`${c.accent("minicode")} ${c.muted("›")} ${first ?? ""}`, { kind: "user" })
181
- for (const r of rest) this.append(` ${r}`, { kind: "user" })
261
+ this.commit()
262
+ this.appendWithSource(
263
+ `${c.accent("minicode")} ${c.muted("›")} ${first ?? ""}`,
264
+ { kind: "user" },
265
+ first ?? "",
266
+ "minicode › ",
267
+ )
268
+ for (const r of rest) this.appendWithSource(` ${r}`, { kind: "user" }, r, " · ")
182
269
  }
183
270
 
184
271
  pushError(message: string): void {
@@ -187,19 +274,40 @@ export class Transcript {
187
274
 
188
275
  pushInfo(lines: string[]): void {
189
276
  this.commit()
190
- for (const l of lines) this.append(l)
277
+ if (lines.length === 0) return
278
+ const blocks = parseMarkdownBlocks(sanitizeAnsi(lines.join("\n")))
279
+ if (blocks.length === 0) {
280
+ for (const line of lines) this.append(line)
281
+ return
282
+ }
283
+ for (const block of blocks) {
284
+ if (block.type === "table") this.appendTable(block.table, { kind: "system" })
285
+ else {
286
+ for (const line of block.text.split("\n")) this.append(line)
287
+ }
288
+ }
191
289
  }
192
290
 
193
291
  /** Kosongkan transkrip (`/clear`): viewport kembali ke layar kosong. */
194
292
  clear(): void {
195
293
  this.lines = []
294
+ this.tables = []
295
+ this.ids = []
296
+ this.sourcePrefixes = []
297
+ this.sourceTexts.clear()
298
+ this.sourceOrders.clear()
299
+ this.assistantDisplay.clear()
300
+ this.nextId = 1
301
+ this.nextOrder = 1
196
302
  this.meta = []
197
303
  this.pending = ""
304
+ this.pendingTruncated = false
198
305
  this.thinkingBuf = ""
199
306
  this.thinkingTail = ""
200
307
  this.evicted = 0
201
308
  this.hasEvictMarker = false
202
309
  this.presentedTerminals.clear()
310
+ this.presentedVerifications.clear()
203
311
  this.summarizedTurns.clear()
204
312
  }
205
313
 
@@ -213,51 +321,291 @@ export class Transcript {
213
321
  return this.totalAppended + (this.pending ? 1 : 0)
214
322
  }
215
323
 
216
- /** Baris visual (ter-wrap) untuk lebar kolom — dipakai view + kunci scroll. */
217
- private wrapAll(width: number): string[] {
324
+ private projectText(
325
+ text: string,
326
+ sourceText: string,
327
+ sourceId: number,
328
+ width: number,
329
+ selectable: boolean,
330
+ sourcePrefix = "",
331
+ markdown = false,
332
+ fenceState: FenceState = "outside",
333
+ ): TranscriptRow[] {
218
334
  const w = Math.max(10, width)
219
- const wrapped: string[] = []
220
- for (const logical of this.lines) {
221
- const clean = logical === "" ? [""] : chunkByWidth(logical, w)
222
- for (const r of clean) wrapped.push(r)
335
+ const renderedLines = text.split("\n")
336
+ const sourceLines = sourceText.split("\n")
337
+ const out: TranscriptRow[] = []
338
+ let sourceBase = 0
339
+ for (let lineIndex = 0; lineIndex < renderedLines.length; lineIndex++) {
340
+ const raw = renderedLines[lineIndex] ?? ""
341
+ const source = sourceLines[lineIndex] ?? stripSgr(sanitizeAnsi(raw))
342
+ let rendered: string | null
343
+ if (!markdown) rendered = raw
344
+ else if (sourceId >= 0 && this.assistantDisplay.has(sourceId))
345
+ rendered = this.assistantDisplay.get(sourceId)!
346
+ else {
347
+ rendered = renderAssistantLine(raw, fenceState)
348
+ if (sourceId >= 0) this.assistantDisplay.set(sourceId, rendered)
349
+ }
350
+ if (rendered === null) {
351
+ sourceBase += source.length + 1
352
+ continue
353
+ }
354
+ const renderedRows = rendered === "" ? [""] : chunkByWidth(rendered, w)
355
+ const sourceRows = sourcePrefix || source ? chunkByWidth(`${sourcePrefix}${source}`, w) : [""]
356
+ let offset = sourceBase
357
+ const count = Math.max(renderedRows.length, sourceRows.length)
358
+ for (let rowIndex = 0; rowIndex < count; rowIndex++) {
359
+ const renderedRow = renderedRows[rowIndex] ?? ""
360
+ const rawSourceRow = sourceRows[rowIndex] ?? ""
361
+ const sourceRow =
362
+ sourcePrefix && rowIndex === 0 && rawSourceRow.startsWith(sourcePrefix)
363
+ ? rawSourceRow.slice(sourcePrefix.length)
364
+ : rawSourceRow
365
+ out.push({
366
+ text: renderedRow,
367
+ sourceId: selectable ? sourceId : -1,
368
+ sourceStart: offset,
369
+ sourceEnd: offset + sourceRow.length,
370
+ displayStart: 0,
371
+ displayEnd: displayWidth(renderedRow),
372
+ selectable: selectable && sourceId >= 0,
373
+ })
374
+ offset += sourceRow.length
375
+ }
376
+ sourceBase += source.length + 1
377
+ }
378
+ return out
379
+ }
380
+
381
+ private projectTable(table: MarkdownTable, sourceId: number, width: number): TranscriptRow[] {
382
+ const rendered = renderMarkdownTable(table, Math.max(1, width), renderInline)
383
+ if (!rendered) return []
384
+ const renderedRows = rendered.split("\n")
385
+ const logicalRows = [table.headers, ...table.rows].map((row) => row.join("\t"))
386
+ const ranges: Array<{ start: number; end: number }> = []
387
+ let base = 0
388
+ for (const row of logicalRows) {
389
+ ranges.push({ start: base, end: base + row.length })
390
+ base += row.length + 1
391
+ }
392
+ const plainRows = renderedRows.map((row) => stripSgr(sanitizeAnsi(row)))
393
+ const horizontal = plainRows.some((row) => /^[\s─━┌┐└┘├┤┬┴┼]+$/.test(row))
394
+ const fields = Math.max(1, table.headers.length)
395
+ let logicalIndex = 0
396
+ return renderedRows.map((row, index) => {
397
+ const plain = plainRows[index] ?? ""
398
+ const isBorder = /^[\s─━┌┐└┘├┤┬┴┼]+$/.test(plain)
399
+ let range = ranges[0] ?? { start: 0, end: 0 }
400
+ if (horizontal) {
401
+ if (!isBorder) range = ranges[logicalIndex] ?? range
402
+ if (!isBorder) logicalIndex++
403
+ } else {
404
+ const dataIndex = table.rows.length === 0 ? 0 : Math.floor(index / fields) + 1
405
+ range = ranges[dataIndex] ?? range
406
+ }
407
+ return {
408
+ text: row,
409
+ sourceId: isBorder ? -1 : sourceId,
410
+ sourceStart: range.start,
411
+ sourceEnd: range.end,
412
+ displayStart: 0,
413
+ displayEnd: displayWidth(row),
414
+ selectable: !isBorder && sourceId >= 0,
415
+ }
416
+ })
417
+ }
418
+
419
+ /**
420
+ * Pelacak code fence per aliran teks: baris DI DALAM fence tidak kena
421
+ * render markdown (kode harus literal). Marker pembuka/penutup sendiri
422
+ * juga dilewati agar state tetap sinkron dengan decorateMarkdown.
423
+ */
424
+ private fenceTracker(): (line: string) => FenceState {
425
+ let open = false
426
+ let char = ""
427
+ let len = 0
428
+ return (line: string): FenceState => {
429
+ const fence = parseFence(line)
430
+ if (!open && fence) {
431
+ open = true
432
+ char = fence.char
433
+ len = fence.len
434
+ return "boundary"
435
+ }
436
+ if (open && fence && fence.char === char && fence.len >= len) {
437
+ open = false
438
+ return "boundary"
439
+ }
440
+ return open ? "inside" : "outside"
441
+ }
442
+ }
443
+
444
+ private projectAll(width: number): TranscriptRow[] {
445
+ const w = Math.max(10, width)
446
+ const rows: TranscriptRow[] = []
447
+ const committedFence = this.fenceTracker()
448
+ for (let i = 0; i < this.lines.length; i++) {
449
+ const table = this.tables[i]
450
+ const id = this.ids[i] ?? -1
451
+ const raw = this.lines[i] ?? ""
452
+ const assistant = this.meta[i]?.kind === "assistant"
453
+ const fenceState = assistant ? committedFence(raw) : "outside"
454
+ if (table) rows.push(...this.projectTable(table, id, w))
455
+ else
456
+ rows.push(
457
+ ...this.projectText(
458
+ raw,
459
+ this.sourceTexts.get(id) ?? "",
460
+ id,
461
+ w,
462
+ true,
463
+ this.sourcePrefixes[i] ?? "",
464
+ assistant,
465
+ fenceState,
466
+ ),
467
+ )
223
468
  }
224
469
  if (this.pending) {
225
- for (const chunk of sanitizeAnsi(this.pending).split("\n")) {
226
- const rows = chunk === "" ? [""] : chunkByWidth(chunk, w)
227
- for (const r of rows) wrapped.push(r)
470
+ const pendingFence = this.fenceTracker()
471
+ for (const block of parseMarkdownBlocks(sanitizeAnsi(this.pending))) {
472
+ if (block.type === "table") rows.push(...this.projectTable(block.table, -1, w))
473
+ else
474
+ for (const line of block.text.split("\n")) {
475
+ const clean = stripSgr(sanitizeAnsi(line))
476
+ rows.push(...this.projectText(line, clean, -1, w, false, "", true, pendingFence(line)))
477
+ }
228
478
  }
229
479
  }
230
- // Ekor hidup thinking: expanded = sisa baris redup; minimized = satu
231
- // penanda redup (isi tidak membanjiri transkrip).
480
+ if (this.pendingTruncated) {
481
+ rows.push({
482
+ text: c.muted(TRANSCRIPT_TRUNCATION_MARKER),
483
+ sourceId: -1,
484
+ sourceStart: 0,
485
+ sourceEnd: 0,
486
+ displayStart: 0,
487
+ displayEnd: displayWidth(TRANSCRIPT_TRUNCATION_MARKER),
488
+ selectable: false,
489
+ })
490
+ }
232
491
  if (this.thinkingTail) {
233
492
  for (const chunk of this.thinkingTail.split("\n")) {
234
- const rows = chunk === "" ? [""] : chunkByWidth(chunk, w)
235
- for (const r of rows) wrapped.push(c.muted(r))
493
+ const chunkRows = chunk === "" ? [""] : chunkByWidth(chunk, w)
494
+ for (const row of chunkRows) {
495
+ rows.push({
496
+ text: c.muted(row),
497
+ sourceId: -1,
498
+ sourceStart: 0,
499
+ sourceEnd: 0,
500
+ displayStart: 0,
501
+ displayEnd: displayWidth(row),
502
+ selectable: false,
503
+ })
504
+ }
236
505
  }
237
- } else if (this.thinkingBuf.trim()) {
238
- wrapped.push(c.muted(t("ts.thinking")))
239
506
  }
240
- wrapped.push(...this.runningRows())
241
- return wrapped
507
+ for (const row of this.runningRows()) {
508
+ rows.push({
509
+ text: row,
510
+ sourceId: -1,
511
+ sourceStart: 0,
512
+ sourceEnd: 0,
513
+ displayStart: 0,
514
+ displayEnd: displayWidth(row),
515
+ selectable: false,
516
+ })
517
+ }
518
+ return rows
242
519
  }
243
520
 
244
- /** Panjang visual viewport (untuk kunci posisi baca App saat stream masuk). */
245
521
  wrappedLength(width: number): number {
246
- return this.wrapAll(width).length
522
+ return this.projectAll(width).length
523
+ }
524
+
525
+ viewport(width: number, height: number, scrollBack: number): TranscriptViewport {
526
+ const wrapped = this.projectAll(width)
527
+ const safeHeight = Math.max(1, Math.floor(height))
528
+ const back = Math.max(0, Math.min(scrollBack, Math.max(0, wrapped.length - safeHeight)))
529
+ const firstIndex = Math.max(0, wrapped.length - back - safeHeight)
530
+ const rows = wrapped.slice(firstIndex, firstIndex + safeHeight)
531
+ while (rows.length < safeHeight) {
532
+ rows.unshift({
533
+ text: "",
534
+ sourceId: -1,
535
+ sourceStart: 0,
536
+ sourceEnd: 0,
537
+ displayStart: 0,
538
+ displayEnd: 0,
539
+ selectable: false,
540
+ })
541
+ }
542
+ return { rows, firstIndex, totalRows: wrapped.length }
247
543
  }
248
544
 
249
- /**
250
- * Baris tampil untuk viewport: wrap ke `width`, ambil `height` baris
251
- * terakhir dikurangi `scrollBack` (0 = ikut ekor). Selalu kembalikan
252
- * TEPAT `height` string (padding "" bila kurang) supaya frame penuh.
253
- */
254
545
  view(width: number, height: number, scrollBack: number): string[] {
255
- const wrapped = this.wrapAll(width)
256
- const back = Math.max(0, Math.min(scrollBack, Math.max(0, wrapped.length - height)))
257
- const tail = wrapped.slice(0, wrapped.length - back)
258
- const shown = tail.slice(Math.max(0, tail.length - height))
259
- while (shown.length < height) shown.unshift("")
260
- return shown
546
+ return this.viewport(width, height, scrollBack).rows.map((row) => row.text)
547
+ }
548
+
549
+ pointAt(row: TranscriptRow, column: number): TranscriptPoint | null {
550
+ if (!row.selectable || row.sourceId < 0) return null
551
+ const source = this.sourceTexts.get(row.sourceId)
552
+ if (source === undefined) return null
553
+ const relative = Math.max(0, column - row.displayStart)
554
+ return {
555
+ id: row.sourceId,
556
+ offset: offsetAtColumn(source, row.sourceStart, row.sourceEnd, relative),
557
+ }
558
+ }
559
+
560
+ hasSource(id: number): boolean {
561
+ return this.sourceTexts.has(id)
562
+ }
563
+
564
+ columnAtOffset(row: TranscriptRow, offset: number): number {
565
+ const source = this.sourceTexts.get(row.sourceId)
566
+ if (source === undefined) return 0
567
+ const clamped = Math.max(row.sourceStart, Math.min(offset, row.sourceEnd))
568
+ return displayWidth(source.slice(row.sourceStart, clamped))
569
+ }
570
+
571
+ comparePoints(left: TranscriptPoint, right: TranscriptPoint): number {
572
+ const leftOrder = this.sourceOrders.get(left.id)
573
+ const rightOrder = this.sourceOrders.get(right.id)
574
+ if (leftOrder === undefined || rightOrder === undefined) return 0
575
+ if (leftOrder !== rightOrder) return leftOrder < rightOrder ? -1 : 1
576
+ return left.offset === right.offset ? 0 : left.offset < right.offset ? -1 : 1
577
+ }
578
+
579
+ selectionText(start: TranscriptPoint, end: TranscriptPoint): string {
580
+ const startOrder = this.sourceOrders.get(start.id)
581
+ const endOrder = this.sourceOrders.get(end.id)
582
+ if (startOrder === undefined || endOrder === undefined) return ""
583
+ const [first, last] =
584
+ startOrder <= endOrder
585
+ ? [
586
+ { order: startOrder, point: start },
587
+ { order: endOrder, point: end },
588
+ ]
589
+ : [
590
+ { order: endOrder, point: end },
591
+ { order: startOrder, point: start },
592
+ ]
593
+ if (start.id === end.id) {
594
+ const source = this.sourceTexts.get(start.id) ?? ""
595
+ const from = Math.min(start.offset, end.offset)
596
+ const to = Math.max(start.offset, end.offset)
597
+ return source.slice(from, to)
598
+ }
599
+ const parts: string[] = []
600
+ for (const id of this.ids) {
601
+ const order = this.sourceOrders.get(id)
602
+ if (order === undefined || order < first.order || order > last.order) continue
603
+ const source = this.sourceTexts.get(id) ?? ""
604
+ if (order === first.order) parts.push(source.slice(first.point.offset))
605
+ else if (order === last.order) parts.push(source.slice(0, last.point.offset))
606
+ else parts.push(source)
607
+ }
608
+ return parts.join("\n")
261
609
  }
262
610
 
263
611
  dispose(): void {
@@ -271,9 +619,17 @@ export class Transcript {
271
619
 
272
620
  private commit(): void {
273
621
  if (!this.pending) return
274
- const text = this.pending
622
+ const text = this.pendingTruncated
623
+ ? `${this.pending}\n${TRANSCRIPT_TRUNCATION_MARKER}`
624
+ : this.pending
275
625
  this.pending = ""
276
- for (const row of sanitizeAnsi(text).split("\n")) this.append(row, { kind: "assistant" })
626
+ this.pendingTruncated = false
627
+ for (const block of parseMarkdownBlocks(sanitizeAnsi(text))) {
628
+ if (block.type === "table") this.appendTable(block.table, { kind: "assistant" })
629
+ else {
630
+ for (const row of block.text.split("\n")) this.append(row, { kind: "assistant" })
631
+ }
632
+ }
277
633
  }
278
634
 
279
635
  private presentationSnapshot(): UiPresentationSnapshot | null {
@@ -330,6 +686,13 @@ export class Transcript {
330
686
  }
331
687
 
332
688
  private presentationLedger(event: UiPresentationEvent): void {
689
+ // Observasi verifikasi punya baris ledger sendiri (dedup per invocation):
690
+ // terminal tool sudah tampil duluan, dan transcript append-only tak bisa
691
+ // menimpa baris lama. Baris ini tak pernah mengklaim status tool.
692
+ if (event.type === "verification.observed") {
693
+ this.verificationLedger(event)
694
+ return
695
+ }
333
696
  if (event.toolCallId) {
334
697
  if (this.presentedTerminals.has(event.toolCallId)) return
335
698
  this.presentedTerminals.add(event.toolCallId)
@@ -337,22 +700,43 @@ export class Transcript {
337
700
  const activity = this.snapshotActivity(event.toolCallId)
338
701
  if (activity?.parentToolCallId) return
339
702
  this.commit()
340
- const name = sanitizeAnsiLine(activity?.name ?? event.name ?? "tool")
341
- const target = activity?.target ?? event.target
342
- const targetText = target ? ` ${truncateToWidth(sanitizeAnsiLine(target), 120, "")}` : ""
343
- const status = activity?.status ?? event.status ?? "completed"
344
703
  const snapshot = this.presentationSnapshot()
345
704
  const children = activity
346
705
  ? (snapshot?.activities ?? []).filter((a) => a.parentToolCallId === activity.toolCallId)
347
706
  .length
348
707
  : 0
349
- const retry = activity?.supersedes ? ` ${t("ts.retry")}` : ""
708
+ // Keputusan node dari policy kanonik bila di-inject; paint/sanitasi tetap
709
+ // di sini. Tanpa policy = logika inline legacy (rollback flag).
710
+ const desc =
711
+ this.policy && activity
712
+ ? this.policy.describeActivity(activity, { childCount: children })
713
+ : undefined
714
+ const name = sanitizeAnsiLine(desc?.name ?? activity?.name ?? event.name ?? "tool")
715
+ const target = desc?.target ?? activity?.target ?? event.target
716
+ const targetText = target ? ` ${truncateToWidth(sanitizeAnsiLine(target), 120, "")}` : ""
717
+ const status = desc?.status ?? activity?.status ?? event.status ?? "completed"
718
+ const retry = (desc ? desc.retryOf : activity?.supersedes) ? ` ${t("ts.retry")}` : ""
350
719
  const child = children > 0 ? ` ${t("ts.childGroup", { n: children })}` : ""
720
+ // P2.11: penanda verifikasi/provenans dari deskripsi policy (ASCII aman).
721
+ // Absen = unknown/live — tidak dirender sebagai keberhasilan.
722
+ const verification = desc?.verification ?? activity?.verification
723
+ const verificationMark = !verification
724
+ ? ""
725
+ : verification.verdict === "present"
726
+ ? " [verified]"
727
+ : ` [unverified:${verification.verdict}]`
728
+ const provenance = desc?.provenance ?? activity?.provenance
729
+ const provenanceMark =
730
+ provenance === "reconstructed"
731
+ ? " [reconstructed]"
732
+ : provenance === "replay"
733
+ ? " [replay]"
734
+ : ""
351
735
  const message =
352
736
  status === "failed" && event.message
353
737
  ? `: ${truncateToWidth(sanitizeAnsi(String(event.message)), 200, "…").split("\n")[0] ?? ""}`
354
738
  : ""
355
- const line = ` ${this.statusGlyph(status)} ${name}${targetText} ${this.statusWord(status)}${retry}${child}${message}`
739
+ const line = ` ${this.statusGlyph(status)} ${name}${targetText} ${this.statusWord(status)}${retry}${child}${verificationMark}${provenanceMark}${message}`
356
740
  this.append(this.statusPaint(status, line), {
357
741
  kind: "activity",
358
742
  ...(event.seq !== undefined ? { seq: event.seq } : {}),
@@ -363,18 +747,47 @@ export class Transcript {
363
747
  })
364
748
  }
365
749
 
750
+ private verificationLedger(event: UiPresentationEvent): void {
751
+ const verification = event.verification
752
+ if (!verification || !event.toolCallId) return
753
+ if (this.presentedVerifications.has(verification.invocationId)) return
754
+ this.presentedVerifications.add(verification.invocationId)
755
+ const activity = this.snapshotActivity(event.toolCallId)
756
+ if (activity?.parentToolCallId) return
757
+ const name = sanitizeAnsiLine(activity?.name ?? event.name ?? "tool")
758
+ const target = activity?.target ?? event.target
759
+ const targetText = target ? ` ${truncateToWidth(sanitizeAnsiLine(target), 120, "")}` : ""
760
+ const line =
761
+ verification.verdict === "present"
762
+ ? ` ${this.statusGlyph("completed")} ${name}${targetText} verified`
763
+ : ` ? ${name}${targetText} unverified (${verification.verdict})`
764
+ this.append(
765
+ verification.verdict === "present" ? this.statusPaint("completed", line) : c.muted(line),
766
+ {
767
+ kind: "activity",
768
+ ...(event.seq !== undefined ? { seq: event.seq } : {}),
769
+ ...(event.turnId !== undefined ? { turnId: event.turnId } : {}),
770
+ toolCallId: event.toolCallId,
771
+ status: activity?.status ?? "completed",
772
+ },
773
+ )
774
+ }
775
+
366
776
  private turnSummary(summary: UiPresentationEvent["summary"], event: UiPresentationEvent): void {
367
777
  if (!summary) return
368
778
  const snapshot = this.presentationSnapshot()
369
- const turn = snapshot?.turns.find((candidate) => {
370
- const value = candidate.summary
371
- return (
372
- value?.toolsOk === summary.toolsOk &&
373
- value?.toolsFailed === summary.toolsFailed &&
374
- value?.toolsDenied === summary.toolsDenied &&
375
- value?.filesChanged === summary.filesChanged
376
- )
377
- })
779
+ const turn = snapshot
780
+ ? (this.policy?.matchTurn(snapshot.turns, summary) ??
781
+ snapshot.turns.find((candidate) => {
782
+ const value = candidate.summary
783
+ return (
784
+ value?.toolsOk === summary.toolsOk &&
785
+ value?.toolsFailed === summary.toolsFailed &&
786
+ value?.toolsDenied === summary.toolsDenied &&
787
+ value?.filesChanged === summary.filesChanged
788
+ )
789
+ }))
790
+ : undefined
378
791
  const turnId = turn?.turnId ?? snapshot?.turns[snapshot.turns.length - 1]?.turnId ?? 0
379
792
  if (event.turnId !== undefined) {
380
793
  if (this.summarizedTurns.has(event.turnId)) return
@@ -410,7 +823,10 @@ export class Transcript {
410
823
  ? ` ${truncateToWidth(sanitizeAnsiLine(activity.target), 120, "")}`
411
824
  : ""
412
825
  const elapsed = Date.now() - activity.tsStart
413
- const elapsedText = elapsed >= 2000 ? ` (${formatElapsed(elapsed)})` : ""
826
+ const showElapsed = this.policy
827
+ ? this.policy.elapsedVisible(activity.tsStart, Date.now())
828
+ : elapsed >= 2000
829
+ const elapsedText = showElapsed ? ` (${formatElapsed(elapsed)})` : ""
414
830
  const retry = activity.supersedes ? ` ${t("ts.retry")}` : ""
415
831
  const prefix = child ? " ↳ " : ` ${glyphs.arrow} `
416
832
  return c.info(`${prefix}${name}${target} … ${t("ts.statusRunning")}${elapsedText}${retry}`)
@@ -427,46 +843,72 @@ export class Transcript {
427
843
  return out
428
844
  }
429
845
 
430
- private ledger(e: {
431
- execution: {
432
- call: { name: string; args?: unknown }
433
- result: { isError?: boolean; content?: unknown }
434
- }
435
- }): void {
436
- this.commit()
437
- const rawName = e.execution.call.name ?? "tool"
438
- const name = sanitizeAnsiLine(String(rawName))
439
- const args = (e.execution.call.args ?? {}) as Record<string, unknown>
440
- const r = e.execution.result
441
- if (r?.isError) {
442
- const msg =
443
- truncateToWidth(sanitizeAnsi(String(r.content ?? "")), 200, "…").split("\n")[0] ?? ""
444
- this.append(c.error(` › ${name}: ${msg}`), { kind: "activity" })
445
- return
446
- }
447
- const target = targetForFallback(args)
448
- const label = target ? ` ${truncateToWidth(sanitizeAnsiLine(target), 120, "")}` : ""
449
- // Glyph ledger memakai arrow tema (› di UTF-8, > di ASCII) — konsisten
450
- // dengan grammar REPL walau bentuknya disusun manual di sini.
451
- this.append(c.success(` ›${name ? ` ${name}` : ""}${label}`), { kind: "activity" })
846
+ private append(line: string, meta: TranscriptMeta = { kind: "system" }): void {
847
+ this.appendWithSource(line, meta, stripSgr(sanitizeAnsi(line)))
452
848
  }
453
849
 
454
- private append(line: string, meta: TranscriptMeta = { kind: "system" }): void {
850
+ private appendWithSource(
851
+ line: string,
852
+ meta: TranscriptMeta,
853
+ sourceText: string,
854
+ sourcePrefix = "",
855
+ ): void {
856
+ this.appendEntry(line, null, meta, sourceText, sourcePrefix)
857
+ }
858
+
859
+ private appendTable(table: MarkdownTable, meta: TranscriptMeta = { kind: "assistant" }): void {
860
+ const sourceText = [table.headers, ...table.rows].map((row) => row.join("\t")).join("\n")
861
+ this.appendEntry(table.source, table, { ...meta, table }, sourceText, "")
862
+ }
863
+
864
+ private appendEntry(
865
+ line: string,
866
+ table: MarkdownTable | null,
867
+ meta: TranscriptMeta,
868
+ sourceText: string,
869
+ sourcePrefix: string,
870
+ ): void {
871
+ const id = this.nextId++
872
+ const order = this.nextOrder++
455
873
  this.lines.push(line)
874
+ this.tables.push(table)
875
+ this.ids.push(id)
876
+ this.sourcePrefixes.push(sourcePrefix)
877
+ this.sourceTexts.set(id, sourceText)
878
+ this.sourceOrders.set(id, order)
456
879
  this.meta.push(meta)
457
880
  this.totalAppended++
458
881
  if (!this.hasEvictMarker && this.lines.length > TRANSCRIPT_CAP) {
459
882
  const overflow = this.lines.length - TRANSCRIPT_CAP
883
+ const removed = this.ids.splice(0, overflow)
884
+ for (const removedId of removed) {
885
+ this.sourceTexts.delete(removedId)
886
+ this.assistantDisplay.delete(removedId)
887
+ this.sourceOrders.delete(removedId)
888
+ }
460
889
  this.lines.splice(0, overflow)
890
+ this.tables.splice(0, overflow)
891
+ this.sourcePrefixes.splice(0, overflow)
461
892
  this.meta.splice(0, overflow)
462
893
  this.evicted += overflow
463
894
  this.lines.unshift(c.muted(t("ts.evictMarker", { n: this.evicted })))
895
+ this.tables.unshift(null)
896
+ this.ids.unshift(-1)
897
+ this.sourcePrefixes.unshift("")
464
898
  this.meta.unshift({ kind: "system" })
465
899
  this.hasEvictMarker = true
466
900
  }
467
901
  if (this.hasEvictMarker && this.lines.length > TRANSCRIPT_CAP + 1) {
468
902
  const overflow = this.lines.length - (TRANSCRIPT_CAP + 1)
903
+ const removed = this.ids.splice(1, overflow)
904
+ for (const removedId of removed) {
905
+ this.sourceTexts.delete(removedId)
906
+ this.assistantDisplay.delete(removedId)
907
+ this.sourceOrders.delete(removedId)
908
+ }
469
909
  this.lines.splice(1, overflow)
910
+ this.tables.splice(1, overflow)
911
+ this.sourcePrefixes.splice(1, overflow)
470
912
  this.meta.splice(1, overflow)
471
913
  this.evicted += overflow
472
914
  this.lines[0] = c.muted(t("ts.evictMarker", { n: this.evicted }))