minicode-ai 0.28.0 → 0.30.1

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 (41) hide show
  1. package/README.md +1 -1
  2. package/cli/args.ts +93 -70
  3. package/cli/bootstrap/presentation-bridge.ts +383 -0
  4. package/cli/commands/acp.ts +7 -1
  5. package/cli/commands/doctor.ts +7 -3
  6. package/cli/commands/exec.ts +6 -16
  7. package/cli/index.ts +3 -2
  8. package/cli/setup.ts +13 -380
  9. package/cli/tui.ts +3 -4
  10. package/docs/TERMINAL_CONTRACT.md +28 -21
  11. package/docs/UI_RENDER_PIPELINE.md +3 -3
  12. package/docs/architecture.md +14 -29
  13. package/docs/environment.md +1 -1
  14. package/package.json +1 -1
  15. package/src/app/session.ts +201 -53
  16. package/src/app/tool-layer.ts +27 -0
  17. package/src/lib/atomic-write.ts +31 -59
  18. package/src/policy/jail.ts +6 -8
  19. package/src/providers/anthropic.ts +16 -5
  20. package/src/providers/responses.ts +37 -7
  21. package/src/providers/sse-bounds.ts +6 -4
  22. package/src/session/db/runs.ts +397 -0
  23. package/src/session/db/schema.ts +358 -0
  24. package/src/session/persistence.ts +64 -955
  25. package/src/task/db/schema.ts +325 -0
  26. package/src/task/db/types.ts +269 -0
  27. package/src/task/store.ts +74 -986
  28. package/src/ui/assistant/simple.ts +25 -19
  29. package/src/ui/i18n/en.ts +0 -3
  30. package/src/ui/i18n/id.ts +0 -3
  31. package/src/ui/render/logo.ts +15 -18
  32. package/src/ui/render/markdown-layout.ts +293 -0
  33. package/src/ui/render/markdown.ts +36 -44
  34. package/src/ui/render/session-summary.ts +1 -1
  35. package/src/ui/render/table-grid.ts +16 -7
  36. package/src/ui/render/width.ts +71 -18
  37. package/src/ui/render/wrap.ts +39 -22
  38. package/src/ui/session-state.ts +4 -4
  39. package/src/ui/tui/app.ts +15 -36
  40. package/src/ui/tui/transcript.ts +111 -50
  41. package/vendor/minicore/src/providers/openai-compat.ts +7 -0
@@ -19,6 +19,11 @@ import { t } from "../i18n/locale.ts"
19
19
  import { renderActivityPanel } from "../render/activity-panel.ts"
20
20
  import { paintLedger, runMarker, statusWord } from "../render/ledger.ts"
21
21
  import { parseFence, renderInline } from "../render/markdown.ts"
22
+ import {
23
+ computeAssistantLineLayout,
24
+ effectiveAssistantMargin,
25
+ formatAssistantSpacing,
26
+ } from "../render/markdown-layout.ts"
22
27
  import { type MarkdownTable, parseMarkdownBlocks } from "../render/markdown-table.ts"
23
28
  import { sanitizeAnsi, sanitizeAnsiLine, stripSgr } from "../render/sanitize.ts"
24
29
  import { renderMarkdownTable } from "../render/table-grid.ts"
@@ -188,46 +193,26 @@ function renderAssistantLine(line: string, fenceState: FenceState): string | nul
188
193
  if (fenceState === "boundary") return null
189
194
  if (fenceState.startsWith("open:")) {
190
195
  const lang = fenceState.slice(5)
191
- return lang ? c.dim(` ${glyphs.dot} ${lang}`) : null
196
+ return lang ? c.dim(`${glyphs.dot} ${lang}`) : null
192
197
  }
193
198
  if (fenceState === "inside") return line
194
199
  if (!/(?:\*{1,2}|`|^#{1,6}\s|~~|\[[^\]]+\]\()/.test(line)) return line
195
200
  const heading = /^(#{1,6})\s+(.*)$/.exec(line)
196
201
  if (heading) return c.bold(renderInline(heading[2] ?? ""))
202
+ const listItem = /^(\s*)([-*+]|\d+[.)])\s+(.*)$/.exec(line)
203
+ if (listItem) return `${listItem[1]}${listItem[2]} ${renderInline(listItem[3] ?? "")}`
204
+ const blockquote = /^(\s*(?:>\s*)+)(.*)$/.exec(line)
205
+ if (blockquote) return `${blockquote[1]}${renderInline(blockquote[2] ?? "")}`
197
206
  return renderInline(line)
198
207
  }
199
208
 
200
209
  /**
201
210
  * Rapikan hanya whitespace presentasi jawaban model: hapus baris kosong di
202
- * tepi dan batasi jeda berulang di luar fenced code. Isi code fence tetap
203
- * literal karena spasi dan baris kosong di dalamnya adalah bagian contoh.
211
+ * tepi, sisipkan jeda bersih antar-poin/heading/blok, dan batasi jeda berulang
212
+ * di luar fenced code. Isi code fence tetap literal.
204
213
  */
205
214
  function normalizeAssistantOutput(text: string): string {
206
- const lines = text.replace(/\r\n?/g, "\n").split("\n")
207
- const out: string[] = []
208
- let openFence: { char: string; len: number } | null = null
209
- for (const line of lines) {
210
- const fence = parseFence(line)
211
- if (openFence) {
212
- out.push(line)
213
- if (fence && fence.char === openFence.char && fence.len >= openFence.len) openFence = null
214
- continue
215
- }
216
- if (fence) {
217
- openFence = fence
218
- out.push(line)
219
- continue
220
- }
221
- if (!line.trim()) {
222
- if (out.length && out[out.length - 1] !== "") out.push("")
223
- continue
224
- }
225
- out.push(line)
226
- }
227
- // Jika fence belum ditutup, baris kosong di ekor masih bagian dari contoh
228
- // kode dan harus tetap literal. Hanya whitespace di luar fence yang dirapatkan.
229
- if (!openFence) while (out.length && out[out.length - 1] === "") out.pop()
230
- return out.join("\n")
215
+ return formatAssistantSpacing(text)
231
216
  }
232
217
 
233
218
  let selectionSegmenter: Intl.Segmenter | undefined
@@ -601,6 +586,15 @@ export class Transcript {
601
586
  }
602
587
  return
603
588
  }
589
+ if (!this.uiState.reasoningVisible) {
590
+ // Tetap simpan thinking tersembunyi ke buffer `/expand` sebelum reset
591
+ // agar user tetap bisa membuka proses berpikir jika diperlukan.
592
+ if (this.thinkingBuf) this.uiState.rememberCollapsedSection("thinking", this.thinkingBuf)
593
+ this.thinkingBuf = ""
594
+ this.thinkingTail = ""
595
+ this.thinkingArea = []
596
+ return
597
+ }
604
598
  if (this.thinkingTail) {
605
599
  this.append(c.thinking(` ${this.thinkingTail}`), { kind: "diagnostic" })
606
600
  this.thinkingTail = ""
@@ -675,6 +669,7 @@ export class Transcript {
675
669
  this.thinkingBuf = ""
676
670
  this.thinkingTail = ""
677
671
  this.thinkingArea = []
672
+ this.thinkingRowId = null
678
673
  this.evicted = 0
679
674
  this.hasEvictMarker = false
680
675
  this.runningMemo = null
@@ -709,6 +704,7 @@ export class Transcript {
709
704
  fenceState: FenceState = "outside",
710
705
  ): TranscriptRow[] {
711
706
  const w = Math.max(10, width)
707
+ const outerMargin = markdown ? effectiveAssistantMargin(w) : 0
712
708
  const renderedLines = text.split("\n")
713
709
  const sourceLines = sourceText.split("\n")
714
710
  const out: TranscriptRow[] = []
@@ -716,22 +712,43 @@ export class Transcript {
716
712
  for (let lineIndex = 0; lineIndex < renderedLines.length; lineIndex++) {
717
713
  const raw = renderedLines[lineIndex] ?? ""
718
714
  const source = sourceLines[lineIndex] ?? stripSgr(sanitizeAnsi(raw))
719
- let rendered: string | null
720
- if (!markdown) rendered = raw
715
+ let renderedBody: string | null
716
+ if (!markdown) renderedBody = raw
721
717
  else if (sourceId >= 0 && this.assistantDisplay.has(sourceId))
722
- rendered = this.assistantDisplay.get(sourceId)!
718
+ renderedBody = this.assistantDisplay.get(sourceId)!
723
719
  else {
724
- rendered = renderAssistantLine(raw, fenceState)
725
- if (sourceId >= 0) this.assistantDisplay.set(sourceId, rendered)
720
+ renderedBody = renderAssistantLine(raw, fenceState)
721
+ if (sourceId >= 0) this.assistantDisplay.set(sourceId, renderedBody)
726
722
  }
727
- if (rendered === null) {
723
+ if (renderedBody === null) {
728
724
  sourceBase += source.length + 1
729
725
  continue
730
726
  }
731
727
  const isBoundaryHeader = markdown && fenceState.startsWith("open:")
732
- const renderedRows = rendered === "" ? [""] : wrapByWidth(rendered, w)
728
+ let firstLead = ""
729
+ let hangingIndent = ""
730
+ if (markdown) {
731
+ if (isBoundaryHeader) {
732
+ firstLead = outerMargin > 0 ? " ".repeat(outerMargin) : ""
733
+ hangingIndent = firstLead
734
+ } else if (renderedBody !== "") {
735
+ const layout = computeAssistantLineLayout(raw, outerMargin, w, {
736
+ inFence: fenceState === "inside",
737
+ })
738
+ firstLead = layout.firstLead
739
+ hangingIndent = layout.hangingIndent
740
+ }
741
+ }
742
+ const rendered = renderedBody === "" ? "" : `${firstLead}${renderedBody}`
743
+ const renderedRows =
744
+ rendered === ""
745
+ ? [""]
746
+ : wrapByWidth(rendered, w, hangingIndent ? { hangingIndent } : undefined)
747
+ const effectiveHangCols = displayWidth(hangingIndent)
748
+ const effectiveHang = effectiveHangCols > 0 && effectiveHangCols < w ? hangingIndent : ""
733
749
  const plainRenderedFull = stripSgr(sanitizeAnsi(rendered))
734
- const expectedExact = `${sourcePrefix}${source}`
750
+ const linePrefix0 = `${firstLead}${sourcePrefix}`
751
+ const expectedExact = `${linePrefix0}${source}`
735
752
  const exactMatch = !isBoundaryHeader && (!markdown || plainRenderedFull === expectedExact)
736
753
  const prefixTrimmed = sourcePrefix.trimEnd()
737
754
  const rowBodies: Array<{
@@ -745,19 +762,25 @@ export class Transcript {
745
762
  const plainRendered = stripSgr(sanitizeAnsi(renderedRow))
746
763
  let rowDisplayStart = 0
747
764
  let plainBody = plainRendered
748
- if (sourcePrefix && rowIndex === 0) {
749
- if (plainRendered.startsWith(sourcePrefix)) {
750
- rowDisplayStart = displayWidth(sourcePrefix)
751
- plainBody = plainRendered.slice(sourcePrefix.length)
765
+ if (rowIndex === 0 && linePrefix0) {
766
+ if (plainRendered.startsWith(linePrefix0)) {
767
+ rowDisplayStart = displayWidth(linePrefix0)
768
+ plainBody = plainRendered.slice(linePrefix0.length)
752
769
  } else if (
770
+ sourcePrefix &&
753
771
  prefixTrimmed &&
754
- plainRendered.startsWith(prefixTrimmed) &&
755
- plainRendered.length <= sourcePrefix.length
772
+ plainRendered.startsWith(`${firstLead}${prefixTrimmed}`) &&
773
+ plainRendered.length <= linePrefix0.length
756
774
  ) {
757
775
  // Terminal sempit memecah tepat di ujung chrome prefix ("minicode ›").
758
776
  rowDisplayStart = displayWidth(plainRendered)
759
777
  plainBody = ""
760
778
  }
779
+ } else if (rowIndex > 0 && effectiveHang && plainRendered.startsWith(effectiveHang)) {
780
+ // Lewati spasi indentasi gantung sintetis di awal baris lanjutan agar
781
+ // highlight seleksi & clipboard /copy tetap bersih berisi teks asli.
782
+ rowDisplayStart = effectiveHangCols
783
+ plainBody = plainRendered.slice(effectiveHang.length)
761
784
  }
762
785
  rowBodies.push({
763
786
  text: renderedRow,
@@ -913,9 +936,10 @@ export class Transcript {
913
936
  if (this.thinkingTail) logical.push(this.thinkingTail)
914
937
  if (logical.length === 0) return []
915
938
  const visual: string[] = []
939
+ const contentWidth = Math.max(1, w - 2)
916
940
  for (const line of logical) {
917
941
  if (line === "") visual.push("")
918
- else visual.push(...wrapByWidth(line, w))
942
+ else visual.push(...wrapByWidth(line, contentWidth))
919
943
  }
920
944
  const shown = visual.slice(-MAX_THINKING_ROWS)
921
945
  const hidden = visual.length - shown.length
@@ -1134,9 +1158,33 @@ export class Transcript {
1134
1158
  const pending = normalizeAssistantOutput(sanitizeAnsi(this.pending))
1135
1159
  if (pending) {
1136
1160
  for (const block of parseMarkdownBlocks(pending)) {
1137
- if (block.type === "table") rows.push(...this.projectTable(block.table, -1, w))
1138
- else
1139
- for (const line of block.text.split("\n")) {
1161
+ if (block.type === "table") {
1162
+ if (rows.length > 0 && rows[rows.length - 1]!.text !== "") {
1163
+ rows.push({
1164
+ text: "",
1165
+ sourceId: -1,
1166
+ sourceStart: 0,
1167
+ sourceEnd: 0,
1168
+ displayStart: 0,
1169
+ displayEnd: 0,
1170
+ selectable: false,
1171
+ })
1172
+ }
1173
+ rows.push(...this.projectTable(block.table, -1, w))
1174
+ } else {
1175
+ const lineList = block.text.split("\n")
1176
+ if (rows.length > 0 && lineList[0] !== "" && rows[rows.length - 1]!.text !== "") {
1177
+ rows.push({
1178
+ text: "",
1179
+ sourceId: -1,
1180
+ sourceStart: 0,
1181
+ sourceEnd: 0,
1182
+ displayStart: 0,
1183
+ displayEnd: 0,
1184
+ selectable: false,
1185
+ })
1186
+ }
1187
+ for (const line of lineList) {
1140
1188
  const fenceState = pendingFence(line)
1141
1189
  const memoKey =
1142
1190
  line.length <= PENDING_MEMO_LINE_MAX ? `${w}\u0000${fenceState}\u0000${line}` : null
@@ -1155,6 +1203,7 @@ export class Transcript {
1155
1203
  }
1156
1204
  rows.push(...produced)
1157
1205
  }
1206
+ }
1158
1207
  }
1159
1208
  }
1160
1209
  if (this.pendingTruncated) {
@@ -1341,10 +1390,19 @@ export class Transcript {
1341
1390
  // Pisahkan jawaban dari thinking/diagnostik tepat di atasnya dengan satu
1342
1391
  // baris kosong — supaya "berpikir" tidak nempel ke jawaban.
1343
1392
  if (this.lastKind() === "diagnostic") this.append("", { kind: "assistant" })
1344
- for (const block of parseMarkdownBlocks(sanitizeAnsi(text))) {
1345
- if (block.type === "table") this.appendTable(block.table, { kind: "assistant" })
1346
- else {
1347
- for (const row of block.text.split("\n")) this.append(row, { kind: "assistant" })
1393
+ const blocks = parseMarkdownBlocks(sanitizeAnsi(text))
1394
+ for (const block of blocks) {
1395
+ if (block.type === "table") {
1396
+ if (this.lines.length > 0 && this.lines[this.lines.length - 1] !== "") {
1397
+ this.append("", { kind: "assistant" })
1398
+ }
1399
+ this.appendTable(block.table, { kind: "assistant" })
1400
+ } else {
1401
+ const rows = block.text.split("\n")
1402
+ if (this.tables[this.tables.length - 1] && rows[0] !== "") {
1403
+ this.append("", { kind: "assistant" })
1404
+ }
1405
+ for (const row of rows) this.append(row, { kind: "assistant" })
1348
1406
  }
1349
1407
  }
1350
1408
  }
@@ -1884,6 +1942,9 @@ export class Transcript {
1884
1942
  if (index < 0) return false
1885
1943
  this.lines[index] = line
1886
1944
  this.rowCache.delete(id)
1945
+ this.committedProjection = null
1946
+ this.projectedBase = null
1947
+ this.runningMemo = null
1887
1948
  return true
1888
1949
  }
1889
1950
 
@@ -153,6 +153,13 @@ export function createOpenAICompatProvider(config: OpenAICompatConfig): ModelPro
153
153
  }
154
154
  };
155
155
  for await (const chunk of sse(response.body, signal)) {
156
+ if (chunk.error && (typeof chunk.error === "object" || typeof chunk.error === "string")) {
157
+ const e = typeof chunk.error === "object" ? (chunk.error as Record<string, unknown>) : { message: String(chunk.error) };
158
+ const msg = String(e.message ?? e.msg ?? JSON.stringify(chunk.error));
159
+ const c = String(e.code ?? e.type ?? "");
160
+ const cat = /auth|401|403/i.test(msg + c) ? "auth" : /rate|quota|429/i.test(msg + c) ? "rate_limit" : /context/i.test(msg) ? "context_length_exceeded" : "server";
161
+ throw new ProviderError(cat, `${cat === "server" ? "server error" : cat}: ${msg}`);
162
+ }
156
163
  const usage = chunk.usage as {
157
164
  prompt_tokens?: number;
158
165
  completion_tokens?: number;