maidang 29.8.3 → 29.9.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.
package/README.md CHANGED
@@ -27,13 +27,13 @@ maidang skills 可分享的 Agent Skills
27
27
  maidang cat|meow 麦麦
28
28
  maidang contact 给麦当留言(直发,不经过大模型)
29
29
  maidang manifest 面向 AI 的公开资料清单
30
- maidang chat 和我对话
31
- maidang news AI 日报(--list 最近 10 期,--date 指定日期)
30
+ maidang chat 和我对话(TUI / -m 渲染 Markdown;默认新会话,-c 续接上一次)
31
+ maidang news AI 日报(TTY 渲染 Markdown;--list 最近 10 期,--date 指定日期)
32
32
  maidang changelog 站点更新日志
33
33
  maidang upgrade 升级 maidang(--yes 跳过确认,--json 仅检查)
34
34
  ```
35
35
 
36
- 所有命令支持 **--json** 输出,结构化数据,方便程序读取。
36
+ 所有命令支持 **--json** 输出,结构化数据,方便程序读取。TTY 下 `chat`、`chat -m`、`news` 会排版标题、列表和代码块;`--json` 仍是原文。
37
37
 
38
38
  ## 退出码
39
39
 
package/dist/index.js CHANGED
@@ -1651,10 +1651,264 @@ function createWhoAmICommand() {
1651
1651
  }
1652
1652
 
1653
1653
  // src/commands/chat.tsx
1654
- import React, { useState, useRef, useEffect } from "react";
1655
- import { render, Box, Text, useInput } from "ink";
1654
+ import React2, { useState, useRef, useEffect } from "react";
1655
+ import { render, Box as Box2, Text as Text2, useInput } from "ink";
1656
1656
  import { Command as Command12 } from "commander";
1657
+ import chalk4 from "chalk";
1658
+
1659
+ // src/components/markdown-view.tsx
1660
+ import React from "react";
1661
+ import { Box, Text } from "ink";
1662
+
1663
+ // src/utils/markdown-ast.ts
1664
+ var FENCE_OPEN = /^(`{3,}|~{3,})(.*)$/;
1665
+ var HEADING = /^(#{1,6})\s+(.+?)\s*$/;
1666
+ var UNORDERED = /^\s*[-*+]\s+(.+)$/;
1667
+ var ORDERED = /^\s*\d+\.\s+(.+)$/;
1668
+ var isBlockStart = (line) => FENCE_OPEN.test(line) || HEADING.test(line) || UNORDERED.test(line) || ORDERED.test(line);
1669
+ var plainPaint = {
1670
+ heading: (text) => text,
1671
+ bold: (text) => text,
1672
+ italic: (text) => text,
1673
+ code: (text) => text,
1674
+ linkText: (text) => text,
1675
+ href: (text) => text,
1676
+ marker: (text) => text,
1677
+ codeLine: (text) => text
1678
+ };
1679
+ var matchLink = (input, start) => {
1680
+ if (input[start] !== "[") return null;
1681
+ const close = input.indexOf("]", start + 1);
1682
+ if (close === -1 || input[close + 1] !== "(") return null;
1683
+ const hrefEnd = input.indexOf(")", close + 2);
1684
+ if (hrefEnd === -1) return null;
1685
+ return {
1686
+ text: input.slice(start + 1, close),
1687
+ href: input.slice(close + 2, hrefEnd),
1688
+ end: hrefEnd + 1
1689
+ };
1690
+ };
1691
+ var isWordChar = (ch) => Boolean(ch && /[A-Za-z0-9]/.test(ch));
1692
+ var parseInlines = (input) => {
1693
+ const nodes = [];
1694
+ let i = 0;
1695
+ let text = "";
1696
+ const flush = () => {
1697
+ if (!text) return;
1698
+ nodes.push({ type: "text", value: text });
1699
+ text = "";
1700
+ };
1701
+ while (i < input.length) {
1702
+ const ch = input[i];
1703
+ if (ch === "\\" && i + 1 < input.length) {
1704
+ text += input[i + 1];
1705
+ i += 2;
1706
+ continue;
1707
+ }
1708
+ if (ch === "`") {
1709
+ const end = input.indexOf("`", i + 1);
1710
+ if (end !== -1) {
1711
+ flush();
1712
+ nodes.push({ type: "code", value: input.slice(i + 1, end) });
1713
+ i = end + 1;
1714
+ continue;
1715
+ }
1716
+ }
1717
+ if (ch === "[") {
1718
+ const link = matchLink(input, i);
1719
+ if (link) {
1720
+ flush();
1721
+ nodes.push({ type: "link", text: link.text, href: link.href });
1722
+ i = link.end;
1723
+ continue;
1724
+ }
1725
+ }
1726
+ if (input.startsWith("**", i) || input.startsWith("__", i)) {
1727
+ const delim = input.slice(i, i + 2);
1728
+ const end = input.indexOf(delim, i + 2);
1729
+ if (end !== -1) {
1730
+ flush();
1731
+ nodes.push({ type: "bold", children: parseInlines(input.slice(i + 2, end)) });
1732
+ i = end + 2;
1733
+ continue;
1734
+ }
1735
+ }
1736
+ if (ch === "_" && isWordChar(input[i - 1]) && isWordChar(input[i + 1])) {
1737
+ text += ch;
1738
+ i += 1;
1739
+ continue;
1740
+ }
1741
+ if (ch === "*" || ch === "_") {
1742
+ const end = input.indexOf(ch, i + 1);
1743
+ if (end !== -1 && input[end + 1] !== ch) {
1744
+ flush();
1745
+ nodes.push({ type: "italic", children: parseInlines(input.slice(i + 1, end)) });
1746
+ i = end + 1;
1747
+ continue;
1748
+ }
1749
+ }
1750
+ text += ch;
1751
+ i += 1;
1752
+ }
1753
+ flush();
1754
+ return nodes;
1755
+ };
1756
+ var parseMarkdown = (source) => {
1757
+ const lines = source.replace(/\r\n/g, "\n").split("\n");
1758
+ const blocks = [];
1759
+ let i = 0;
1760
+ while (i < lines.length) {
1761
+ const line = lines[i];
1762
+ if (!line.trim()) {
1763
+ i += 1;
1764
+ continue;
1765
+ }
1766
+ const fence = line.match(FENCE_OPEN);
1767
+ if (fence) {
1768
+ const marker = fence[1];
1769
+ const lang = fence[2].trim();
1770
+ const body = [];
1771
+ i += 1;
1772
+ while (i < lines.length && !lines[i].startsWith(marker)) {
1773
+ body.push(lines[i]);
1774
+ i += 1;
1775
+ }
1776
+ if (i < lines.length) i += 1;
1777
+ blocks.push({ type: "code", lang, value: body.join("\n") });
1778
+ continue;
1779
+ }
1780
+ const heading = line.match(HEADING);
1781
+ if (heading) {
1782
+ blocks.push({
1783
+ type: "heading",
1784
+ level: heading[1].length,
1785
+ children: parseInlines(heading[2].replace(/\s+#+\s*$/, "").trim())
1786
+ });
1787
+ i += 1;
1788
+ continue;
1789
+ }
1790
+ const unordered = UNORDERED.test(line);
1791
+ const ordered = ORDERED.test(line);
1792
+ if (unordered || ordered) {
1793
+ const pattern = ordered ? ORDERED : UNORDERED;
1794
+ const items = [];
1795
+ while (i < lines.length) {
1796
+ const item = lines[i].match(pattern);
1797
+ if (!item) break;
1798
+ items.push(parseInlines(item[1]));
1799
+ i += 1;
1800
+ }
1801
+ blocks.push({ type: "list", ordered, items });
1802
+ continue;
1803
+ }
1804
+ const para = [];
1805
+ while (i < lines.length && lines[i].trim() && !isBlockStart(lines[i])) {
1806
+ para.push(lines[i].trim());
1807
+ i += 1;
1808
+ }
1809
+ blocks.push({ type: "paragraph", children: parseInlines(para.join(" ")) });
1810
+ }
1811
+ return blocks;
1812
+ };
1813
+ var renderInlines = (nodes, paint) => nodes.map((node) => {
1814
+ switch (node.type) {
1815
+ case "text":
1816
+ return node.value;
1817
+ case "bold":
1818
+ return paint.bold(renderInlines(node.children, paint));
1819
+ case "italic":
1820
+ return paint.italic(renderInlines(node.children, paint));
1821
+ case "code":
1822
+ return paint.code(node.value);
1823
+ case "link":
1824
+ return `${paint.linkText(node.text)}${node.href ? paint.href(` ${node.href}`) : ""}`;
1825
+ }
1826
+ }).join("");
1827
+ var renderBlock = (block, paint) => {
1828
+ switch (block.type) {
1829
+ case "heading":
1830
+ return paint.heading(renderInlines(block.children, paint));
1831
+ case "paragraph":
1832
+ return renderInlines(block.children, paint);
1833
+ case "list":
1834
+ return block.items.map((item, index) => {
1835
+ const marker = block.ordered ? `${index + 1}.` : "\u2022";
1836
+ return `${paint.marker(marker)} ${renderInlines(item, paint)}`;
1837
+ }).join("\n");
1838
+ case "code": {
1839
+ const lines = block.value.length > 0 ? block.value.split("\n") : [""];
1840
+ const body = lines.map((line) => paint.codeLine(line || " ")).join("\n");
1841
+ return block.lang ? `${paint.marker(block.lang)}
1842
+ ${body}` : body;
1843
+ }
1844
+ }
1845
+ };
1846
+ var formatMarkdown = (source, options = {}) => {
1847
+ const indent = options.indent ?? "";
1848
+ const paint = options.paint ?? plainPaint;
1849
+ const blocks = parseMarkdown(source);
1850
+ if (blocks.length === 0) return indent;
1851
+ const body = blocks.map((block) => renderBlock(block, paint)).join("\n\n");
1852
+ if (!indent) return body;
1853
+ return body.split("\n").map((line) => indent + line).join("\n");
1854
+ };
1855
+
1856
+ // src/components/markdown-view.tsx
1857
+ var renderInlines2 = (nodes) => nodes.map((node, index) => renderInline(node, index));
1858
+ var renderInline = (node, index) => {
1859
+ switch (node.type) {
1860
+ case "text":
1861
+ return /* @__PURE__ */ React.createElement(Text, { key: index }, node.value);
1862
+ case "bold":
1863
+ return /* @__PURE__ */ React.createElement(Text, { key: index, bold: true }, renderInlines2(node.children));
1864
+ case "italic":
1865
+ return /* @__PURE__ */ React.createElement(Text, { key: index, italic: true }, renderInlines2(node.children));
1866
+ case "code":
1867
+ return /* @__PURE__ */ React.createElement(Text, { key: index, color: "cyan" }, node.value);
1868
+ case "link":
1869
+ return /* @__PURE__ */ React.createElement(Text, { key: index }, /* @__PURE__ */ React.createElement(Text, { color: "cyan" }, node.text), node.href ? /* @__PURE__ */ React.createElement(Text, { dimColor: true }, " ", node.href) : null);
1870
+ }
1871
+ };
1872
+ var renderListItem = (item, index, ordered) => /* @__PURE__ */ React.createElement(Box, { key: index, width: "100%" }, /* @__PURE__ */ React.createElement(Text, { dimColor: true }, ordered ? `${index + 1}. ` : "\u2022 "), /* @__PURE__ */ React.createElement(Text, { wrap: "wrap" }, renderInlines2(item)));
1873
+ var renderCodeLine = (line, index) => /* @__PURE__ */ React.createElement(Text, { key: index, color: "gray" }, line || " ");
1874
+ var renderBlock2 = (block, index) => {
1875
+ switch (block.type) {
1876
+ case "heading":
1877
+ return /* @__PURE__ */ React.createElement(Box, { key: index, width: "100%", marginBottom: 1 }, /* @__PURE__ */ React.createElement(Text, { bold: true, color: "cyan", wrap: "wrap" }, renderInlines2(block.children)));
1878
+ case "paragraph":
1879
+ return /* @__PURE__ */ React.createElement(Box, { key: index, width: "100%", marginBottom: 1 }, /* @__PURE__ */ React.createElement(Text, { wrap: "wrap" }, renderInlines2(block.children)));
1880
+ case "list":
1881
+ return /* @__PURE__ */ React.createElement(Box, { key: index, flexDirection: "column", width: "100%", marginBottom: 1 }, block.items.map((item, itemIndex) => renderListItem(item, itemIndex, block.ordered)));
1882
+ case "code":
1883
+ return /* @__PURE__ */ React.createElement(Box, { key: index, flexDirection: "column", width: "100%", marginBottom: 1 }, block.lang ? /* @__PURE__ */ React.createElement(Text, { dimColor: true }, block.lang) : null, block.value.split("\n").map((line, lineIndex) => renderCodeLine(line, lineIndex)));
1884
+ }
1885
+ };
1886
+ var MarkdownView = ({ source }) => {
1887
+ const blocks = parseMarkdown(source);
1888
+ if (blocks.length === 0) {
1889
+ return /* @__PURE__ */ React.createElement(Text, { wrap: "wrap" }, source);
1890
+ }
1891
+ return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column", width: "100%" }, blocks.map((block, index) => renderBlock2(block, index)));
1892
+ };
1893
+
1894
+ // src/utils/markdown.ts
1657
1895
  import chalk3 from "chalk";
1896
+ var ansiPaint = {
1897
+ heading: (text) => theme.accentBold(text),
1898
+ bold: (text) => chalk3.bold(text),
1899
+ italic: (text) => chalk3.italic(text),
1900
+ code: (text) => theme.accent(text),
1901
+ linkText: (text) => theme.link(text),
1902
+ href: (text) => theme.inkMuted(text),
1903
+ marker: (text) => theme.inkMuted(text),
1904
+ codeLine: (text) => theme.inkSoft(text)
1905
+ };
1906
+ var renderMarkdownAnsi = (source, options = {}) => formatMarkdown(source, { indent: options.indent, paint: ansiPaint });
1907
+ var printMarkdownAnsi = (source, options = {}) => {
1908
+ const text = renderMarkdownAnsi(source, options);
1909
+ if (!text) return;
1910
+ console.log(text);
1911
+ };
1658
1912
 
1659
1913
  // src/utils/os-agent-api.ts
1660
1914
  import { mkdirSync, readFileSync, writeFileSync } from "fs";
@@ -1679,6 +1933,9 @@ function saveConfig(config) {
1679
1933
  } catch {
1680
1934
  }
1681
1935
  }
1936
+ function readLastSessionId() {
1937
+ return loadConfig().sessionId;
1938
+ }
1682
1939
  var RateLimitError = class extends Error {
1683
1940
  constructor(retryAfter) {
1684
1941
  super(`\u8BF7\u6C42\u592A\u9891\u7E41\uFF0C\u8BF7\u5728 ${retryAfter} \u79D2\u540E\u518D\u8BD5`);
@@ -1703,7 +1960,7 @@ async function readError(response) {
1703
1960
  async function runAgentChat(input) {
1704
1961
  const config = loadConfig();
1705
1962
  const token = config.agentToken;
1706
- const sessionId = input.sessionId ?? config.sessionId;
1963
+ const sessionId = input.sessionId;
1707
1964
  const runsResponse = await fetch(`${API_URL}/api/os-agent/runs`, {
1708
1965
  method: "POST",
1709
1966
  headers: {
@@ -1814,22 +2071,36 @@ function parseFrame(frame) {
1814
2071
  }
1815
2072
 
1816
2073
  // src/commands/chat.tsx
2074
+ var writeHumanMarkdown = (source) => {
2075
+ const rendered = renderMarkdownAnsi(source);
2076
+ if (!rendered) return;
2077
+ process.stdout.write(rendered);
2078
+ if (!rendered.endsWith("\n")) process.stdout.write("\n");
2079
+ };
1817
2080
  async function chatSync(message, json = false, sessionId) {
1818
2081
  try {
1819
- let streamed = "";
2082
+ let pending = "";
2083
+ let wrote = false;
2084
+ const flushPending = () => {
2085
+ if (!pending) return;
2086
+ if (!json) {
2087
+ writeHumanMarkdown(pending);
2088
+ wrote = true;
2089
+ }
2090
+ pending = "";
2091
+ };
1820
2092
  const result = await runAgentChat({
1821
2093
  message,
1822
2094
  sessionId,
1823
2095
  onEvent: (event) => {
1824
2096
  if (json) return;
1825
2097
  if (event.type === "delta") {
1826
- streamed += event.text;
1827
- process.stdout.write(event.text);
2098
+ pending += event.text;
1828
2099
  } else if (event.type === "tool") {
1829
- if (streamed && !streamed.endsWith("\n")) process.stdout.write("\n");
1830
- process.stdout.write(`${chalk3.dim("\u26A1")} ${chalk3.yellow(event.name)}
2100
+ flushPending();
2101
+ process.stdout.write(`${chalk4.dim("\u26A1")} ${chalk4.yellow(event.name)}
1831
2102
  `);
1832
- streamed = "";
2103
+ wrote = true;
1833
2104
  }
1834
2105
  }
1835
2106
  });
@@ -1844,34 +2115,34 @@ async function chatSync(message, json = false, sessionId) {
1844
2115
  }, null, 2));
1845
2116
  return;
1846
2117
  }
1847
- if (streamed && !streamed.endsWith("\n")) process.stdout.write("\n");
1848
- if (!streamed.trim() && !result.response.trim()) console.log(chalk3.dim("(\u5BF9\u65B9\u6C89\u9ED8\u4E86)"));
1849
- else if (!streamed.trim()) console.log(result.response);
2118
+ flushPending();
2119
+ if (!wrote && !result.response.trim()) console.log(chalk4.dim("(\u5BF9\u65B9\u6C89\u9ED8\u4E86)"));
2120
+ else if (!wrote) writeHumanMarkdown(result.response);
1850
2121
  if (result.sessionId && result.sessionId !== sessionId) {
1851
2122
  console.log();
1852
- console.log(chalk3.dim(`Session: ${chalk3.cyan(result.sessionId)}`));
1853
- console.log(chalk3.dim("\u4F7F\u7528 --session-id \u7EE7\u7EED\u5BF9\u8BDD"));
2123
+ console.log(chalk4.dim(`Session: ${chalk4.cyan(result.sessionId)}`));
2124
+ console.log(chalk4.dim("\u4F7F\u7528 -c \u7EED\u63A5\uFF0C\u6216 --session-id <id> \u6307\u5B9A\u4F1A\u8BDD"));
1854
2125
  }
1855
2126
  } catch (err) {
1856
2127
  if (json) {
1857
2128
  console.error(JSON.stringify({ tool: "maidang", command: "chat", error: err.message }, null, 2));
1858
2129
  process.exit(1);
1859
2130
  } else {
1860
- console.error(chalk3.red(`Error: ${err.message}`));
2131
+ console.error(chalk4.red(`Error: ${err.message}`));
1861
2132
  process.exit(1);
1862
2133
  }
1863
2134
  }
1864
2135
  }
1865
2136
  var _id = 0;
1866
2137
  var uid = () => ++_id;
1867
- var ItemUser = ({ content }) => /* @__PURE__ */ React.createElement(Box, { width: "100%", marginBottom: 1 }, /* @__PURE__ */ React.createElement(Box, { width: "100%", backgroundColor: "cyan", paddingX: 1, paddingY: 0 }, /* @__PURE__ */ React.createElement(Text, { color: "black", wrap: "wrap" }, content)));
1868
- var ItemThinking = ({ content, expanded }) => /* @__PURE__ */ React.createElement(Box, { flexDirection: "column", width: "100%", marginBottom: 1 }, /* @__PURE__ */ React.createElement(Text, { dimColor: true }, "\u601D\u8003"), expanded && /* @__PURE__ */ React.createElement(Box, { width: "100%", borderStyle: "round", borderColor: "gray", paddingX: 1, paddingY: 0, marginTop: 0 }, /* @__PURE__ */ React.createElement(Text, { dimColor: true, wrap: "wrap" }, content)));
1869
- var ItemLoading = () => /* @__PURE__ */ React.createElement(Box, { width: "100%", marginBottom: 1 }, /* @__PURE__ */ React.createElement(Text, { dimColor: true }, "\u601D\u8003\u4E2D..."));
1870
- var ItemTool = ({ content }) => /* @__PURE__ */ React.createElement(Box, { flexDirection: "column", width: "100%", marginBottom: 1 }, /* @__PURE__ */ React.createElement(Text, { color: "yellow" }, "\u26A1"), /* @__PURE__ */ React.createElement(Box, { width: "100%", borderStyle: "round", borderColor: "yellow", paddingX: 1, paddingY: 0, marginTop: 0 }, /* @__PURE__ */ React.createElement(Text, { color: "yellow", wrap: "wrap" }, content)));
1871
- var ItemContent = ({ content }) => /* @__PURE__ */ React.createElement(Box, { width: "100%", marginBottom: 1 }, /* @__PURE__ */ React.createElement(Text, { wrap: "wrap" }, content));
1872
- var ItemError = ({ content }) => /* @__PURE__ */ React.createElement(Box, { width: "100%", marginBottom: 1 }, /* @__PURE__ */ React.createElement(Text, { color: "red" }, content));
2138
+ var ItemUser = ({ content }) => /* @__PURE__ */ React2.createElement(Box2, { width: "100%", marginBottom: 1 }, /* @__PURE__ */ React2.createElement(Box2, { width: "100%", backgroundColor: "cyan", paddingX: 1, paddingY: 0 }, /* @__PURE__ */ React2.createElement(Text2, { color: "black", wrap: "wrap" }, content)));
2139
+ var ItemThinking = ({ content, expanded }) => /* @__PURE__ */ React2.createElement(Box2, { flexDirection: "column", width: "100%", marginBottom: 1 }, /* @__PURE__ */ React2.createElement(Text2, { dimColor: true }, "\u601D\u8003"), expanded && /* @__PURE__ */ React2.createElement(Box2, { width: "100%", borderStyle: "round", borderColor: "gray", paddingX: 1, paddingY: 0, marginTop: 0 }, /* @__PURE__ */ React2.createElement(Text2, { dimColor: true, wrap: "wrap" }, content)));
2140
+ var ItemLoading = () => /* @__PURE__ */ React2.createElement(Box2, { width: "100%", marginBottom: 1 }, /* @__PURE__ */ React2.createElement(Text2, { dimColor: true }, "\u601D\u8003\u4E2D..."));
2141
+ var ItemTool = ({ content }) => /* @__PURE__ */ React2.createElement(Box2, { flexDirection: "column", width: "100%", marginBottom: 1 }, /* @__PURE__ */ React2.createElement(Text2, { color: "yellow" }, "\u26A1"), /* @__PURE__ */ React2.createElement(Box2, { width: "100%", borderStyle: "round", borderColor: "yellow", paddingX: 1, paddingY: 0, marginTop: 0 }, /* @__PURE__ */ React2.createElement(Text2, { color: "yellow", wrap: "wrap" }, content)));
2142
+ var ItemContent = ({ content }) => /* @__PURE__ */ React2.createElement(Box2, { width: "100%", marginBottom: 1 }, /* @__PURE__ */ React2.createElement(MarkdownView, { source: content }));
2143
+ var ItemError = ({ content }) => /* @__PURE__ */ React2.createElement(Box2, { width: "100%", marginBottom: 1 }, /* @__PURE__ */ React2.createElement(Text2, { color: "red" }, content));
1873
2144
  var DOUBLE_PRESS_WINDOW = 1e3;
1874
- var ChatApp = ({ sessionId: initialSessionId }) => {
2145
+ var ChatApp = ({ sessionId: initialSessionId, notice }) => {
1875
2146
  const [items, setItems] = useState([]);
1876
2147
  const [input, setInput] = useState("");
1877
2148
  const [cursorPos, setCursorPos] = useState(0);
@@ -2026,27 +2297,41 @@ var ChatApp = ({ sessionId: initialSessionId }) => {
2026
2297
  const cursorChar = input[cursorPos] ?? " ";
2027
2298
  const after = input.slice(cursorPos + 1);
2028
2299
  const fw = isFullWidth(cursorChar) ? 2 : 1;
2029
- return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(Text, { color: "cyan" }, "> "), /* @__PURE__ */ React.createElement(Text, null, before), /* @__PURE__ */ React.createElement(Text, { backgroundColor: "gray", color: "black" }, cursorChar, fw === 2 ? " " : ""), /* @__PURE__ */ React.createElement(Text, null, after), loading && /* @__PURE__ */ React.createElement(Text, { dimColor: true }, " "));
2300
+ return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(Text2, { color: "cyan" }, "> "), /* @__PURE__ */ React2.createElement(Text2, null, before), /* @__PURE__ */ React2.createElement(Text2, { backgroundColor: "gray", color: "black" }, cursorChar, fw === 2 ? " " : ""), /* @__PURE__ */ React2.createElement(Text2, null, after), loading && /* @__PURE__ */ React2.createElement(Text2, { dimColor: true }, " "));
2030
2301
  };
2031
- return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column", paddingX: 1, flexGrow: 1 }, /* @__PURE__ */ React.createElement(Box, { flexDirection: "column", flexGrow: 1 }, items.map((item) => {
2302
+ return /* @__PURE__ */ React2.createElement(Box2, { flexDirection: "column", paddingX: 1, flexGrow: 1 }, /* @__PURE__ */ React2.createElement(Box2, { flexDirection: "column", flexGrow: 1 }, notice && /* @__PURE__ */ React2.createElement(Box2, { marginBottom: 1 }, /* @__PURE__ */ React2.createElement(Text2, { dimColor: true }, notice)), items.map((item) => {
2032
2303
  switch (item.type) {
2033
2304
  case "user":
2034
- return /* @__PURE__ */ React.createElement(ItemUser, { key: item.id, content: item.content });
2305
+ return /* @__PURE__ */ React2.createElement(ItemUser, { key: item.id, content: item.content });
2035
2306
  case "thinking":
2036
- return /* @__PURE__ */ React.createElement(ItemThinking, { key: item.id, content: item.content, expanded: showThinking });
2307
+ return /* @__PURE__ */ React2.createElement(ItemThinking, { key: item.id, content: item.content, expanded: showThinking });
2037
2308
  case "loading":
2038
- return /* @__PURE__ */ React.createElement(ItemLoading, { key: item.id });
2309
+ return /* @__PURE__ */ React2.createElement(ItemLoading, { key: item.id });
2039
2310
  case "tool":
2040
- return /* @__PURE__ */ React.createElement(ItemTool, { key: item.id, content: item.content });
2311
+ return /* @__PURE__ */ React2.createElement(ItemTool, { key: item.id, content: item.content });
2041
2312
  case "content":
2042
- return /* @__PURE__ */ React.createElement(ItemContent, { key: item.id, content: item.content });
2313
+ return /* @__PURE__ */ React2.createElement(ItemContent, { key: item.id, content: item.content });
2043
2314
  case "error":
2044
- return /* @__PURE__ */ React.createElement(ItemError, { key: item.id, content: item.content });
2315
+ return /* @__PURE__ */ React2.createElement(ItemError, { key: item.id, content: item.content });
2045
2316
  }
2046
- })), /* @__PURE__ */ React.createElement(Box, { flexDirection: "column", flexShrink: 0 }, /* @__PURE__ */ React.createElement(Box, { borderStyle: "single", borderColor: "gray", paddingX: 1 }, renderInputLine()), /* @__PURE__ */ React.createElement(Box, { paddingTop: 1 }, /* @__PURE__ */ React.createElement(Text, { dimColor: true }, "Ctrl+C \u9000\u51FA \xB7 Enter \u53D1\u9001 \xB7 Esc Esc \u6E05\u7A7A\u8F93\u5165 \xB7 \u2190\u2192 \u79FB\u52A8\u5149\u6807")), hint && /* @__PURE__ */ React.createElement(Box, { paddingTop: 0 }, /* @__PURE__ */ React.createElement(Text, { dimColor: true, color: "yellow" }, hint)), !loading && items.some((i) => i.type === "thinking") && !showThinking && /* @__PURE__ */ React.createElement(Box, { paddingTop: 0 }, /* @__PURE__ */ React.createElement(Text, { dimColor: true, color: "cyan" }, "Ctrl+O \u67E5\u770B\u601D\u8003"))), /* @__PURE__ */ React.createElement(Box, { ref: bottomRef }));
2317
+ })), /* @__PURE__ */ React2.createElement(Box2, { flexDirection: "column", flexShrink: 0 }, /* @__PURE__ */ React2.createElement(Box2, { borderStyle: "single", borderColor: "gray", paddingX: 1 }, renderInputLine()), /* @__PURE__ */ React2.createElement(Box2, { paddingTop: 1 }, /* @__PURE__ */ React2.createElement(Text2, { dimColor: true }, "Ctrl+C \u9000\u51FA \xB7 Enter \u53D1\u9001 \xB7 Esc Esc \u6E05\u7A7A\u8F93\u5165 \xB7 \u2190\u2192 \u79FB\u52A8\u5149\u6807")), hint && /* @__PURE__ */ React2.createElement(Box2, { paddingTop: 0 }, /* @__PURE__ */ React2.createElement(Text2, { dimColor: true, color: "yellow" }, hint)), !loading && items.some((i) => i.type === "thinking") && !showThinking && /* @__PURE__ */ React2.createElement(Box2, { paddingTop: 0 }, /* @__PURE__ */ React2.createElement(Text2, { dimColor: true, color: "cyan" }, "Ctrl+O \u67E5\u770B\u601D\u8003"))), /* @__PURE__ */ React2.createElement(Box2, { ref: bottomRef }));
2318
+ };
2319
+ var resolveSessionId = (opts) => {
2320
+ if (opts.sessionId && opts.continue) {
2321
+ const message = "--session-id \u4E0E -c \u4E0D\u80FD\u540C\u65F6\u4F7F\u7528";
2322
+ if (opts.json) {
2323
+ console.error(JSON.stringify({ tool: "maidang", command: "chat", error: message }, null, 2));
2324
+ } else {
2325
+ console.error(chalk4.red(`Error: ${message}`));
2326
+ }
2327
+ process.exit(1);
2328
+ }
2329
+ if (opts.sessionId) return opts.sessionId;
2330
+ if (opts.continue) return readLastSessionId();
2331
+ return void 0;
2047
2332
  };
2048
2333
  function createChatCommand() {
2049
- const cmd = new Command12("chat").description("\u548C\u9EA6\u5F53\u5BF9\u8BDD\uFF08-m \u5355\u8F6E\u6D88\u606F\uFF0C--session-id \u7EED\u63A5\u5BF9\u8BDD\uFF09").option("-m, --message <text>", "\u76F4\u63A5\u53D1\u9001\u6D88\u606F\uFF08\u975E\u4EA4\u4E92\u6A21\u5F0F\uFF09").option("--json", "\u8F93\u51FA JSON \u683C\u5F0F").option("--session-id <id>", "\u7EED\u63A5\u5DF2\u6709\u5BF9\u8BDD");
2334
+ const cmd = new Command12("chat").description("\u548C\u9EA6\u5F53\u5BF9\u8BDD\uFF08\u9ED8\u8BA4\u65B0\u4F1A\u8BDD\uFF1B-c \u7EED\u4E0A\u4E00\u6B21\uFF0C--session-id \u7EED\u63A5\u6307\u5B9A\u5BF9\u8BDD\uFF09").option("-m, --message <text>", "\u76F4\u63A5\u53D1\u9001\u6D88\u606F\uFF08\u975E\u4EA4\u4E92\u6A21\u5F0F\uFF09").option("--json", "\u8F93\u51FA JSON \u683C\u5F0F").option("--session-id <id>", "\u7EED\u63A5\u5DF2\u6709\u5BF9\u8BDD").option("-c, --continue", "\u7EED\u63A5\u4E0A\u4E00\u6B21\u5BF9\u8BDD");
2050
2335
  cmd.action(async (opts) => {
2051
2336
  if (opts.json || opts.message) {
2052
2337
  if (!opts.message) {
@@ -2057,10 +2342,12 @@ function createChatCommand() {
2057
2342
  }
2058
2343
  process.exit(1);
2059
2344
  }
2060
- await chatSync(opts.message, !!opts.json, opts.sessionId);
2345
+ await chatSync(opts.message, !!opts.json, resolveSessionId(opts));
2061
2346
  return;
2062
2347
  }
2063
- render(/* @__PURE__ */ React.createElement(ChatApp, { sessionId: opts.sessionId }));
2348
+ const sessionId = resolveSessionId(opts);
2349
+ const notice = opts.continue && !sessionId ? "\u6CA1\u6709\u53EF\u7EED\u63A5\u7684\u5BF9\u8BDD\uFF0C\u5DF2\u5F00\u59CB\u65B0\u4F1A\u8BDD" : void 0;
2350
+ render(/* @__PURE__ */ React2.createElement(ChatApp, { sessionId, notice }));
2064
2351
  });
2065
2352
  return cmd;
2066
2353
  }
@@ -2183,7 +2470,7 @@ function printIssue(issue) {
2183
2470
  console.log(" " + hairline());
2184
2471
  console.log("");
2185
2472
  if (issue.headline) {
2186
- console.log(" " + theme.inkBody(`\u5934\u6761\uFF1A${issue.headline}`));
2473
+ console.log(" " + theme.inkBody("\u5934\u6761\uFF1A") + renderMarkdownAnsi(issue.headline).trimEnd());
2187
2474
  console.log("");
2188
2475
  }
2189
2476
  let lastSection = "";
@@ -2193,10 +2480,12 @@ function printIssue(issue) {
2193
2480
  console.log(" " + theme.accent(`\u25CF ${item.section}`));
2194
2481
  lastSection = item.section;
2195
2482
  }
2196
- console.log(` ${theme.inkMuted(String(item.rank).padStart(2, "0"))} ${theme.inkBody(item.title)}`);
2197
- if (item.summary) console.log(` ${theme.inkSoft(item.summary)}`);
2483
+ console.log(` ${theme.inkMuted(String(item.rank).padStart(2, "0"))} ${renderMarkdownAnsi(item.title).trimEnd()}`);
2484
+ if (item.summary) printMarkdownAnsi(item.summary, { indent: " " });
2198
2485
  if (item.ordinaryExplanation) {
2199
- console.log(` ${theme.inkMuted(`\u548C\u4F60\u6709\u4EC0\u4E48\u5173\u7CFB\uFF1A${item.ordinaryExplanation}`)}`);
2486
+ const explanation = renderMarkdownAnsi(item.ordinaryExplanation).split("\n");
2487
+ console.log(` ${theme.inkMuted("\u548C\u4F60\u6709\u4EC0\u4E48\u5173\u7CFB\uFF1A")}${explanation[0] ?? ""}`);
2488
+ explanation.slice(1).forEach((line) => console.log(` ${line}`));
2200
2489
  }
2201
2490
  });
2202
2491
  console.log("");
@@ -2212,7 +2501,7 @@ function printIssueList(issues) {
2212
2501
  console.log("");
2213
2502
  issues.forEach((issue, index) => {
2214
2503
  console.log(` ${theme.inkMuted(String(index + 1).padStart(2, "0"))} ${theme.inkBody(`${issue.issueDate.slice(0, 10)} \xB7 \u7B2C ${issue.issueNumber} \u671F`)}`);
2215
- if (issue.headline) console.log(` ${theme.inkSoft(issue.headline)}`);
2504
+ if (issue.headline) printMarkdownAnsi(issue.headline, { indent: " " });
2216
2505
  });
2217
2506
  console.log("");
2218
2507
  }