skyloom 1.12.0 → 1.13.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 (137) hide show
  1. package/.github/workflows/ci.yml +36 -36
  2. package/README.md +137 -46
  3. package/config/default.yaml +43 -47
  4. package/config/models.yaml +155 -155
  5. package/config/providers.yaml +39 -39
  6. package/config/skills/api_integrator/SKILL.md +15 -15
  7. package/config/skills/arch_designer/SKILL.md +13 -13
  8. package/config/skills/ci_cd_manager/SKILL.md +14 -14
  9. package/config/skills/code_analysis/SKILL.md +13 -13
  10. package/config/skills/code_generator/SKILL.md +12 -12
  11. package/config/skills/code_reviewer/SKILL.md +13 -13
  12. package/config/skills/content_writer/SKILL.md +14 -14
  13. package/config/skills/data_transformer/SKILL.md +15 -15
  14. package/config/skills/document_analysis/SKILL.md +13 -13
  15. package/config/skills/emotional_companion/SKILL.md +15 -15
  16. package/config/skills/performance_checker/SKILL.md +14 -14
  17. package/config/skills/security_auditor/SKILL.md +14 -14
  18. package/config/skills/self_evolve/SKILL.md +13 -13
  19. package/config/skills/sys_operator/SKILL.md +15 -15
  20. package/config/skills/task_planner/SKILL.md +14 -14
  21. package/config/skills/web_research/SKILL.md +14 -14
  22. package/config/skills/workflow_designer/SKILL.md +13 -13
  23. package/dist/agents/dew.js +52 -52
  24. package/dist/agents/fair.js +84 -84
  25. package/dist/agents/fog.js +30 -30
  26. package/dist/agents/frost.js +32 -32
  27. package/dist/agents/rain.js +32 -32
  28. package/dist/agents/snow.js +68 -68
  29. package/dist/cli/main.js +127 -74
  30. package/dist/cli/main.js.map +1 -1
  31. package/dist/cli/tui.d.ts +52 -19
  32. package/dist/cli/tui.d.ts.map +1 -1
  33. package/dist/cli/tui.js +198 -265
  34. package/dist/cli/tui.js.map +1 -1
  35. package/dist/core/agent/task.d.ts +58 -0
  36. package/dist/core/agent/task.d.ts.map +1 -0
  37. package/dist/core/agent/task.js +83 -0
  38. package/dist/core/agent/task.js.map +1 -0
  39. package/dist/core/agent.d.ts +2 -45
  40. package/dist/core/agent.d.ts.map +1 -1
  41. package/dist/core/agent.js +61 -145
  42. package/dist/core/agent.js.map +1 -1
  43. package/dist/core/agent_helpers.d.ts +10 -0
  44. package/dist/core/agent_helpers.d.ts.map +1 -1
  45. package/dist/core/agent_helpers.js +39 -0
  46. package/dist/core/agent_helpers.js.map +1 -1
  47. package/dist/core/catalog.d.ts +71 -0
  48. package/dist/core/catalog.d.ts.map +1 -0
  49. package/dist/core/catalog.js +176 -0
  50. package/dist/core/catalog.js.map +1 -0
  51. package/dist/core/config.d.ts +8 -0
  52. package/dist/core/config.d.ts.map +1 -1
  53. package/dist/core/config.js +12 -4
  54. package/dist/core/config.js.map +1 -1
  55. package/dist/core/factory.js +16 -16
  56. package/dist/core/llm.d.ts +7 -0
  57. package/dist/core/llm.d.ts.map +1 -1
  58. package/dist/core/llm.js +139 -7
  59. package/dist/core/llm.js.map +1 -1
  60. package/dist/core/longdoc.js +5 -5
  61. package/dist/core/memory.d.ts.map +1 -1
  62. package/dist/core/memory.js +69 -62
  63. package/dist/core/memory.js.map +1 -1
  64. package/dist/core/theme.d.ts +46 -0
  65. package/dist/core/theme.d.ts.map +1 -0
  66. package/dist/core/theme.js +42 -0
  67. package/dist/core/theme.js.map +1 -0
  68. package/dist/web/server.js +542 -519
  69. package/dist/web/server.js.map +1 -1
  70. package/docs/AESTHETIC_DESIGN.md +144 -0
  71. package/docs/OPTIMIZATION_PLAN.md +178 -0
  72. package/package.json +60 -60
  73. package/scripts/install.js +48 -48
  74. package/scripts/link.js +10 -10
  75. package/setup.bat +79 -79
  76. package/skill-test-ty2fOA/test.md +10 -10
  77. package/src/agents/dew.ts +70 -70
  78. package/src/agents/fair.ts +102 -102
  79. package/src/agents/fog.ts +48 -48
  80. package/src/agents/frost.ts +50 -50
  81. package/src/agents/rain.ts +50 -50
  82. package/src/agents/snow.ts +239 -239
  83. package/src/cli/main.ts +417 -372
  84. package/src/cli/mode.ts +58 -58
  85. package/src/cli/tui.ts +174 -223
  86. package/src/core/agent/task.ts +100 -0
  87. package/src/core/agent.ts +1446 -1549
  88. package/src/core/agent_helpers.ts +496 -461
  89. package/src/core/arbitrate.ts +162 -162
  90. package/src/core/catalog.ts +178 -0
  91. package/src/core/checkpoint.ts +94 -94
  92. package/src/core/config.ts +20 -4
  93. package/src/core/estimate.ts +104 -104
  94. package/src/core/evolve.ts +191 -191
  95. package/src/core/factory.ts +627 -627
  96. package/src/core/filter.ts +103 -103
  97. package/src/core/graph.ts +156 -156
  98. package/src/core/icons.ts +53 -53
  99. package/src/core/index.ts +37 -37
  100. package/src/core/learn.ts +146 -146
  101. package/src/core/llm.ts +108 -5
  102. package/src/core/longdoc.ts +155 -155
  103. package/src/core/mcp_server.ts +176 -176
  104. package/src/core/memory.ts +1178 -1171
  105. package/src/core/profile.ts +255 -255
  106. package/src/core/router.ts +124 -124
  107. package/src/core/sandbox.ts +142 -142
  108. package/src/core/security.ts +243 -243
  109. package/src/core/skill.ts +342 -342
  110. package/src/core/theme.ts +65 -0
  111. package/src/core/tool_router.ts +193 -193
  112. package/src/core/vector.ts +152 -152
  113. package/src/core/workspace.ts +150 -150
  114. package/src/plugins/loader.ts +66 -66
  115. package/src/skills/loader.ts +46 -46
  116. package/src/sql.js.d.ts +29 -29
  117. package/src/tools/builtin.ts +380 -380
  118. package/src/tools/computer.ts +269 -269
  119. package/src/tools/delegate.ts +49 -49
  120. package/src/web/server.ts +660 -634
  121. package/src/web/tts.ts +93 -93
  122. package/tests/agent_helpers.test.ts +48 -0
  123. package/tests/bus.test.ts +121 -121
  124. package/tests/catalog.test.ts +86 -0
  125. package/tests/config.test.ts +41 -0
  126. package/tests/icons.test.ts +45 -45
  127. package/tests/memory.test.ts +147 -0
  128. package/tests/router.test.ts +86 -86
  129. package/tests/schemas.test.ts +51 -51
  130. package/tests/semantic.test.ts +83 -83
  131. package/tests/setup.ts +10 -10
  132. package/tests/skill.test.ts +172 -172
  133. package/tests/task.test.ts +60 -0
  134. package/tests/tool.test.ts +108 -108
  135. package/tests/tool_router.test.ts +71 -71
  136. package/tests/tui.test.ts +67 -0
  137. package/vitest.config.ts +17 -17
package/dist/cli/tui.d.ts CHANGED
@@ -1,23 +1,12 @@
1
1
  /**
2
- * 天空织机 TUI — Full-screen terminal interface
2
+ * 天空织机 TUI — a polished *linear* terminal interface.
3
3
  *
4
- * Layout:
5
- * ┌─────────────────────────────────────────┐
6
- * Fog · deepseek-chat · $0.02 · ⏻ │ header bar
7
- * ├──────────┬──────────────────────────────┤
8
- * Fair│ ✦ 你好!有什么可以帮你的? │
9
- * 霜 │ │ messages
10
- * │ ≋ 雾 ▸ │ 用户消息右对齐 │
11
- * │ ❉ 雪 │ │
12
- * │ ∘ 露 │ │
13
- * │ ⸽ 雨 │ │
14
- * ├──────────┴──────────────────────────────┤
15
- * │ ┌─ /fog /rain /frost /snow ───────┐│ ← command palette (popup)
16
- * │ ▶ /fog Switch to Fog ││
17
- * │ /rain Switch to Rain ││
18
- * │ └──────────────────────────────────────┘│
19
- * │ > hello world [send] │ ← input bar
20
- * └─────────────────────────────────────────┘
4
+ * Design note: the previous version tried to be a full-screen app, redrawing
5
+ * the whole screen on every keystroke while the reply streamed linearly below
6
+ * it the two fought, the conversation never persisted, and hand-rolled
7
+ * raw-mode editing mangled CJK width. This rewrite is linear (like Claude Code
8
+ * / opencode): real readline line-editing + a CJK-aware wrapping stream
9
+ * renderer. Robust, flicker-free, and it actually reads like a conversation.
21
10
  */
22
11
  export interface TUIContext {
23
12
  agent: any;
@@ -27,5 +16,49 @@ export interface TUIContext {
27
16
  width: number;
28
17
  height: number;
29
18
  }
30
- export declare function readInput(stdin: NodeJS.ReadStream, stdout: NodeJS.WriteStream, ctx: TUIContext): Promise<string>;
19
+ export declare const SLASH_COMMANDS: [string, string][];
20
+ /** Visual columns occupied by a single code point (CJK / fullwidth = 2). */
21
+ export declare function charWidth(cp: number): number;
22
+ /** Visual width of a string, ignoring ANSI color codes. */
23
+ export declare function visualWidth(s: string): number;
24
+ /** Pad a string (containing ANSI) to a visual width. */
25
+ export declare function padVisual(s: string, width: number): string;
26
+ /**
27
+ * Writes streamed text with a fixed left gutter, wrapping at the terminal
28
+ * width. English wraps on word boundaries; CJK wraps per glyph. Color is
29
+ * applied per flushed chunk so styling survives wrapping.
30
+ */
31
+ export declare class StreamRenderer {
32
+ private col;
33
+ private word;
34
+ private atLineStart;
35
+ private out;
36
+ private gutter;
37
+ private maxCols;
38
+ private color;
39
+ constructor(out: NodeJS.WriteStream, opts?: {
40
+ gutter?: string;
41
+ color?: (s: string) => string;
42
+ });
43
+ /** Lazily emit the left gutter at the start of each visual line. */
44
+ private startLine;
45
+ private newline;
46
+ private flushWord;
47
+ /** Feed a chunk of streamed text. */
48
+ write(text: string): void;
49
+ /** Flush any buffered word (call before switching styles / ending). */
50
+ flush(): void;
51
+ }
52
+ /** The prompt string for an agent: a small mineral seal + chevron. */
53
+ export declare function promptFor(agentName: string): string;
54
+ /**
55
+ * Read one line with the agent-themed prompt. A fresh readline interface is
56
+ * created and closed per call — this deliberately avoids clashing with the
57
+ * separate readline prompts used by the setup wizard and tool-approval flow
58
+ * (two live interfaces on one stdin corrupt input). History is preserved
59
+ * manually across turns.
60
+ */
61
+ export declare function readLine(agentName: string, out?: NodeJS.WriteStream): Promise<string>;
62
+ /** Render the inline slash-command palette (printed, not full-screen). */
63
+ export declare function renderPalette(filter: string): string;
31
64
  //# sourceMappingURL=tui.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tui.d.ts","sourceRoot":"","sources":["../../src/cli/tui.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAKH,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,GAAG,CAAC;IACX,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AA+ID,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,CAAC,WAAW,EAAE,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CA6FhH"}
1
+ {"version":3,"file":"tui.d.ts","sourceRoot":"","sources":["../../src/cli/tui.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAQH,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,GAAG,CAAC;IACX,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAGD,eAAO,MAAM,cAAc,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAqB5C,CAAC;AAKF,4EAA4E;AAC5E,wBAAgB,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAoB5C;AAID,2DAA2D;AAC3D,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAI7C;AAED,wDAAwD;AACxD,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAG1D;AAKD;;;;GAIG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,GAAG,CAAK;IAChB,OAAO,CAAC,IAAI,CAAM;IAClB,OAAO,CAAC,WAAW,CAAQ;IAC3B,OAAO,CAAC,GAAG,CAAqB;IAChC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,KAAK,CAAwB;gBAEzB,GAAG,EAAE,MAAM,CAAC,WAAW,EAAE,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,CAAA;KAAE;IAS9F,oEAAoE;IACpE,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,OAAO;IAEf,OAAO,CAAC,SAAS;IAUjB,qCAAqC;IACrC,KAAK,CAAC,IAAI,EAAE,MAAM;IAyBlB,uEAAuE;IACvE,KAAK;CACN;AAaD,sEAAsE;AACtE,wBAAgB,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAGnD;AAKD;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,GAAE,MAAM,CAAC,WAA4B,GAAG,OAAO,CAAC,MAAM,CAAC,CAkBrG;AAED,0EAA0E;AAC1E,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAUpD"}
package/dist/cli/tui.js CHANGED
@@ -1,24 +1,13 @@
1
1
  "use strict";
2
2
  /**
3
- * 天空织机 TUI — Full-screen terminal interface
3
+ * 天空织机 TUI — a polished *linear* terminal interface.
4
4
  *
5
- * Layout:
6
- * ┌─────────────────────────────────────────┐
7
- * Fog · deepseek-chat · $0.02 · ⏻ │ header bar
8
- * ├──────────┬──────────────────────────────┤
9
- * Fair│ ✦ 你好!有什么可以帮你的? │
10
- * 霜 │ │ messages
11
- * │ ≋ 雾 ▸ │ 用户消息右对齐 │
12
- * │ ❉ 雪 │ │
13
- * │ ∘ 露 │ │
14
- * │ ⸽ 雨 │ │
15
- * ├──────────┴──────────────────────────────┤
16
- * │ ┌─ /fog /rain /frost /snow ───────┐│ ← command palette (popup)
17
- * │ ▶ /fog Switch to Fog ││
18
- * │ /rain Switch to Rain ││
19
- * │ └──────────────────────────────────────┘│
20
- * │ > hello world [send] │ ← input bar
21
- * └─────────────────────────────────────────┘
5
+ * Design note: the previous version tried to be a full-screen app, redrawing
6
+ * the whole screen on every keystroke while the reply streamed linearly below
7
+ * it the two fought, the conversation never persisted, and hand-rolled
8
+ * raw-mode editing mangled CJK width. This rewrite is linear (like Claude Code
9
+ * / opencode): real readline line-editing + a CJK-aware wrapping stream
10
+ * renderer. Robust, flicker-free, and it actually reads like a conversation.
22
11
  */
23
12
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
24
13
  if (k2 === undefined) k2 = k;
@@ -57,274 +46,218 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
57
46
  return (mod && mod.__esModule) ? mod : { "default": mod };
58
47
  };
59
48
  Object.defineProperty(exports, "__esModule", { value: true });
60
- exports.readInput = readInput;
49
+ exports.StreamRenderer = exports.SLASH_COMMANDS = void 0;
50
+ exports.charWidth = charWidth;
51
+ exports.visualWidth = visualWidth;
52
+ exports.padVisual = padVisual;
53
+ exports.promptFor = promptFor;
54
+ exports.readLine = readLine;
55
+ exports.renderPalette = renderPalette;
61
56
  const readline = __importStar(require("readline"));
62
57
  const chalk_1 = __importDefault(require("chalk"));
63
- /* ── Slash commands with icons ── */
64
- const AGENT_CMDS = [
65
- ["≋", "/fog", "雾 Fog · 松烟墨"],
66
- ["⸽", "/rain", "雨 Rain · 石青"],
67
- ["✱", "/frost", "霜 Frost · 石绿"],
68
- ["❉", "/snow", "雪 Snow · 铅白"],
69
- ["∘", "/dew", "露 Dew · 赭石"],
70
- ["☼", "/fair", "晴 Fair · 朱砂"],
71
- ];
72
- const ACTION_CMDS = [
73
- ["/help", "所有命令"],
74
- ["/clear", "清屏"],
75
- ["/status", "状态总览"],
76
- ["/cost", "费用统计"],
77
- ["/cost reset", "费用归零"],
78
- ["/compact", "压缩上下文"],
79
- ["/retry", "重发上条"],
58
+ const theme_1 = require("../core/theme");
59
+ const TUI_VERSION = (() => { try {
60
+ return require("../../package.json").version;
61
+ }
62
+ catch {
63
+ return "";
64
+ } })();
65
+ /* ── Slash commands (for tab-completion + the inline palette) ── */
66
+ exports.SLASH_COMMANDS = [
67
+ ["/fog", "≋ · 探索洞察"],
68
+ ["/rain", "⸽ 雨 · 创造产出"],
69
+ ["/frost", "✱ 霜 · 精炼品质"],
70
+ ["/snow", "❉ 雪 · 架构规划"],
71
+ ["/dew", "∘ 露 · 可靠守护"],
72
+ ["/fair", "☼ 晴 · 情感陪伴"],
73
+ ["/help", "查看所有命令"],
80
74
  ["/setup", "配置向导"],
81
- ["/apikey set <p> <k>", "保存API Key"],
82
- ["/apikey", "查看API Key"],
83
- ["/model", "模型管理"],
84
- ["/task <goal>", "多Agent编排"],
75
+ ["/model", "模型信息"],
76
+ ["/cost", "费用统计"],
77
+ ["/status", "状态总览"],
85
78
  ["/memory", "记忆状态"],
86
- ["/memory clear", "清除记忆"],
87
79
  ["/sessions", "会话列表"],
88
80
  ["/workspace", "工作空间"],
89
- ["/mcp", "MCP服务器"],
81
+ ["/compact", "压缩上下文"],
82
+ ["/clear", "清屏"],
83
+ ["/task ", "多 Agent 编排"],
84
+ ["/mcp", "MCP 服务器"],
90
85
  ["/version", "版本信息"],
91
86
  ["/quit", "退出"],
92
87
  ];
93
- /* ── Box drawing characters ── */
94
- const B = { tl: "┌", tr: "┐", bl: "└", br: "┘", h: "─", v: "│", l: "├", r: "┤", cross: "┼", t: "┬", b: "┴", L: "░", o: "●" };
95
- function bar(start, fill, end, width) {
96
- return start + fill.repeat(Math.max(0, width)) + end;
88
+ /* ════════════════════════════════════════
89
+ CJK-aware display width
90
+ ════════════════════════════════════════ */
91
+ /** Visual columns occupied by a single code point (CJK / fullwidth = 2). */
92
+ function charWidth(cp) {
93
+ if (cp === 0)
94
+ return 0;
95
+ if (cp < 32 || (cp >= 0x7f && cp < 0xa0))
96
+ return 0; // control
97
+ // East-Asian wide / fullwidth ranges
98
+ if ((cp >= 0x1100 && cp <= 0x115f) || // Hangul Jamo
99
+ (cp >= 0x2e80 && cp <= 0x303e) || // CJK radicals, Kangxi, punctuation
100
+ (cp >= 0x3041 && cp <= 0x33ff) || // Hiragana…CJK symbols
101
+ (cp >= 0x3400 && cp <= 0x4dbf) || // CJK Ext A
102
+ (cp >= 0x4e00 && cp <= 0x9fff) || // CJK Unified
103
+ (cp >= 0xa000 && cp <= 0xa4cf) || // Yi
104
+ (cp >= 0xac00 && cp <= 0xd7a3) || // Hangul syllables
105
+ (cp >= 0xf900 && cp <= 0xfaff) || // CJK compat
106
+ (cp >= 0xfe10 && cp <= 0xfe19) ||
107
+ (cp >= 0xfe30 && cp <= 0xfe6f) || // CJK compat forms
108
+ (cp >= 0xff00 && cp <= 0xff60) || // Fullwidth forms
109
+ (cp >= 0xffe0 && cp <= 0xffe6) ||
110
+ (cp >= 0x1f300 && cp <= 0x1faff) // emoji / pictographs
111
+ )
112
+ return 2;
113
+ return 1;
97
114
  }
98
- /* ── Render sidebar ── */
99
- function renderSidebar(agent, agents, h) {
100
- const lines = [];
101
- const W = 14; // sidebar width in chars
102
- // Header
103
- lines.push(chalk_1.default.cyan(bar(B.L + " 天空织机 ".padEnd(W - 2, B.L) + B.r, "", "", 0)));
104
- lines.push(chalk_1.default.dim(B.v + " Skyloom " + B.v));
105
- for (const n of ["fog", "rain", "frost", "snow", "dew", "fair"]) {
106
- const isActive = agent.name === n;
107
- const display = { fog: "≋ 雾 Fog", rain: "⸽ 雨 Rain", frost: "✱ 霜 Frost", snow: "❉ 雪 Snow", dew: "∘ 露 Dew", fair: "☼ 晴 Fair" };
108
- const line = isActive
109
- ? chalk_1.default.cyan(B.v + " " + B.o + " " + display[n].padEnd(W - 5) + B.v)
110
- : chalk_1.default.dim(B.v + " " + display[n].padEnd(W - 5) + B.v);
111
- lines.push(line);
112
- }
113
- // Fill remaining space
114
- for (let i = lines.length; i < h; i++) {
115
- lines.push(chalk_1.default.dim(B.v + " ".repeat(W - 2) + B.v));
116
- }
117
- // Footer
118
- try {
119
- const cu = agent.contextUsage();
120
- const pct = cu.pct || 0;
121
- lines.push(chalk_1.default.dim(B.v + " ctx " + String(pct).padStart(3) + "%" + " ".repeat(W - 10) + B.v));
122
- }
123
- catch {
124
- lines.push(chalk_1.default.dim(B.v + " ".repeat(W - 2) + B.v));
125
- }
126
- lines.push(chalk_1.default.dim(bar(B.bl, B.h, B.br, W - 2)));
127
- return lines;
115
+ const ANSI_RE = /\x1b\[[0-9;]*m/g;
116
+ /** Visual width of a string, ignoring ANSI color codes. */
117
+ function visualWidth(s) {
118
+ let w = 0;
119
+ for (const ch of s.replace(ANSI_RE, ""))
120
+ w += charWidth(ch.codePointAt(0) || 0);
121
+ return w;
122
+ }
123
+ /** Pad a string (containing ANSI) to a visual width. */
124
+ function padVisual(s, width) {
125
+ const diff = width - visualWidth(s);
126
+ return diff > 0 ? s + " ".repeat(diff) : s;
128
127
  }
129
- /* ── Render command palette ── */
130
- function renderPalette(filter, selIdx, width) {
131
- const lines = [];
132
- const W = Math.min(width - 4, 56);
133
- // Agent section first
134
- const agentMatches = AGENT_CMDS.filter(([, cmd]) => cmd.includes(filter) || filter === "/");
135
- const actionMatches = ACTION_CMDS.filter(([cmd]) => cmd.includes(filter));
136
- const allItems = [];
137
- for (const [icon, cmd, desc] of agentMatches)
138
- allItems.push(`${icon} ${cmd.padEnd(16)} ${desc}`);
139
- for (const [cmd, desc] of actionMatches)
140
- allItems.push(` ${cmd.padEnd(18)} ${desc}`);
141
- if (allItems.length === 0 && filter.length > 1) {
142
- // No matches — show message
143
- lines.push(chalk_1.default.dim(bar(B.tl, B.h, B.tr, W)));
144
- lines.push(chalk_1.default.dim(B.v + " 未找到匹配命令 (esc 关闭)".padEnd(W) + B.v));
145
- lines.push(chalk_1.default.dim(bar(B.bl, B.h, B.br, W)));
146
- return lines;
128
+ /* ════════════════════════════════════════
129
+ Streaming renderer — word-wrap aware, CJK aware
130
+ ════════════════════════════════════════ */
131
+ /**
132
+ * Writes streamed text with a fixed left gutter, wrapping at the terminal
133
+ * width. English wraps on word boundaries; CJK wraps per glyph. Color is
134
+ * applied per flushed chunk so styling survives wrapping.
135
+ */
136
+ class StreamRenderer {
137
+ constructor(out, opts) {
138
+ this.col = 0;
139
+ this.word = "";
140
+ this.atLineStart = true;
141
+ this.out = out;
142
+ this.gutter = opts?.gutter ?? " ";
143
+ this.color = opts?.color ?? ((s) => s);
144
+ const cols = out.columns || 80;
145
+ // content width excludes the gutter; clamp for readability
146
+ this.maxCols = Math.max(32, Math.min(cols - visualWidth(this.gutter) - 1, 96));
147
147
  }
148
- if (allItems.length === 0)
149
- return lines;
150
- const start = Math.max(0, Math.min(selIdx - 5, allItems.length - 10));
151
- const end = Math.min(allItems.length, start + 10);
152
- lines.push(chalk_1.default.dim(bar(B.tl, B.h, B.tr, W - 5)) + " ".padEnd(5));
153
- for (let i = start; i < end; i++) {
154
- const item = allItems[i];
155
- const isSelected = i === selIdx;
156
- const pad = W - item.replace(/\x1b\[[0-9;]*m/g, "").length + 2; // account for ANSI codes
157
- lines.push(isSelected
158
- ? chalk_1.default.cyan(B.v + " " + item).padEnd(W + 10) + chalk_1.default.cyan(B.v)
159
- : chalk_1.default.dim(B.v + " " + item).padEnd(W + 10) + chalk_1.default.dim(B.v));
148
+ /** Lazily emit the left gutter at the start of each visual line. */
149
+ startLine() { if (this.atLineStart) {
150
+ this.out.write(this.gutter);
151
+ this.atLineStart = false;
152
+ } }
153
+ newline() { this.out.write("\n"); this.atLineStart = true; this.col = 0; }
154
+ flushWord() {
155
+ if (!this.word)
156
+ return;
157
+ const w = visualWidth(this.word);
158
+ if (this.col > 0 && this.col + w > this.maxCols)
159
+ this.newline();
160
+ this.startLine();
161
+ this.out.write(this.color(this.word));
162
+ this.col += w;
163
+ this.word = "";
160
164
  }
161
- lines.push(chalk_1.default.dim(bar(B.bl, B.h, B.br, W - 5)) + " ".padEnd(5));
162
- return lines;
163
- }
164
- /* ── Render message ── */
165
- function renderMessage(role, text, width) {
166
- const lines = [];
167
- const maxW = Math.min(width - 24, 60);
168
- const prefix = role === "user" ? " " : " ";
169
- const suffix = role === "user" ? "" : "";
170
- for (const para of text.split("\n")) {
171
- let remaining = para;
172
- while (remaining.length > 0) {
173
- const cut = remaining.length > maxW ? remaining.lastIndexOf(" ", maxW) : remaining.length;
174
- const idx = cut > 0 ? cut : maxW;
175
- const line = remaining.slice(0, idx).trimEnd();
176
- if (role === "user") {
177
- lines.push(chalk_1.default.dim(" ".repeat(Math.max(0, width - line.length - 4))) + chalk_1.default.cyan(line) + " ");
165
+ /** Feed a chunk of streamed text. */
166
+ write(text) {
167
+ for (const ch of text) {
168
+ if (ch === "\r")
169
+ continue; // normalize CRLF / stray CR from providers
170
+ if (ch === "\n") {
171
+ this.flushWord();
172
+ this.newline();
173
+ continue;
174
+ }
175
+ if (ch === " " || ch === "\t") {
176
+ this.flushWord();
177
+ if (this.col > 0 && this.col < this.maxCols) {
178
+ this.startLine();
179
+ this.out.write(" ");
180
+ this.col += 1;
181
+ }
182
+ continue;
178
183
  }
179
- else if (role === "assistant") {
180
- lines.push(prefix + line + suffix);
184
+ const cp = ch.codePointAt(0) || 0;
185
+ if (charWidth(cp) === 2) {
186
+ // CJK / wide: flush any pending latin word, then place this glyph
187
+ this.flushWord();
188
+ if (this.col > 0 && this.col + 2 > this.maxCols)
189
+ this.newline();
190
+ this.startLine();
191
+ this.out.write(this.color(ch));
192
+ this.col += 2;
181
193
  }
182
194
  else {
183
- lines.push(chalk_1.default.dim(" " + line));
195
+ this.word += ch;
196
+ // very long unbroken token: hard-break to avoid overflow
197
+ if (visualWidth(this.word) >= this.maxCols)
198
+ this.flushWord();
184
199
  }
185
- remaining = remaining.slice(idx).trimStart();
186
200
  }
187
201
  }
188
- return lines;
202
+ /** Flush any buffered word (call before switching styles / ending). */
203
+ flush() { this.flushWord(); }
189
204
  }
190
- /* ── Read input with command palette ── */
191
- function readInput(stdin, stdout, ctx) {
192
- return new Promise(resolve => {
193
- let buf = "";
194
- let cursor = 0;
195
- let palette = false;
196
- let selIdx = 0;
197
- function render() {
198
- // Clear screen and render full TUI
199
- readline.cursorTo(stdout, 0, 0);
200
- readline.clearScreenDown(stdout);
201
- const w = stdout.columns || 80;
202
- const h = stdout.rows || 24;
203
- const sidebarW = 16;
204
- // Header
205
- stdout.write(chalk_1.default.bgBlack.cyan(" 天空织机 Skyloom v1.10 ".padEnd(w - 20, " ")) + chalk_1.default.bgBlack.dim(" deepseek".padEnd(10)) + chalk_1.default.bgBlack("\n"));
206
- stdout.write(chalk_1.default.dim(bar("", B.h, "", w)) + "\n");
207
- // Sidebar
208
- const sidebar = renderSidebar(ctx.agent, ctx.agents, h - 5);
209
- for (let i = 0; i < sidebar.length && i < h - 5; i++) {
210
- stdout.write(sidebar[i] + "\n");
211
- }
212
- // Command palette (overlaid)
213
- if (palette) {
214
- const paletteLines = renderPalette(buf, selIdx, w);
215
- // Move cursor up to position palette below header
216
- const paletteY = 2;
217
- for (let i = 0; i < paletteLines.length; i++) {
218
- stdout.write(`\x1b[${paletteY + i};${sidebarW}H`); // position cursor
219
- stdout.write(paletteLines[i]);
220
- }
221
- }
222
- // Input bar at bottom
223
- readline.cursorTo(stdout, sidebarW, h - 1);
224
- stdout.write(chalk_1.default.dim(B.l + B.h.repeat(w - sidebarW - 2) + B.r));
225
- readline.cursorTo(stdout, sidebarW, h);
226
- stdout.write(chalk_1.default.cyan(" > ") + buf.slice(0, cursor) + chalk_1.default.inverse(buf[cursor] || " ") + buf.slice(cursor + 1));
227
- }
228
- if (!stdin.isTTY) {
229
- const rl = readline.createInterface({ input: stdin });
230
- rl.on("line", (line) => { rl.close(); resolve(line.trim()); });
231
- return;
232
- }
233
- stdin.setRawMode(true);
234
- stdin.resume();
235
- render();
236
- let escBuf = "";
237
- stdin.on("data", (data) => {
238
- const str = data.toString();
239
- escBuf += str;
240
- if (escBuf.startsWith("\x1b[") && escBuf.length >= 3) {
241
- const code = escBuf[2];
242
- escBuf = "";
243
- if (code === "A") {
244
- if (palette)
245
- selIdx = Math.max(0, selIdx - 1);
246
- render();
247
- return;
248
- }
249
- if (code === "B") {
250
- if (palette) {
251
- const all = [...AGENT_CMDS.map(c => c[1]), ...ACTION_CMDS.map(c => c[0])];
252
- selIdx = Math.min(all.filter(a => a.includes(buf)).length - 1, selIdx + 1);
253
- }
254
- render();
255
- return;
256
- }
257
- if (code === "C") {
258
- if (cursor < buf.length)
259
- cursor++;
260
- render();
261
- return;
262
- }
263
- if (code === "D") {
264
- if (cursor > 0)
265
- cursor--;
266
- render();
267
- return;
268
- }
269
- }
270
- for (const ch of escBuf) {
271
- escBuf = "";
272
- if (ch === "\x1b") {
273
- palette = false;
274
- render();
275
- return;
276
- }
277
- if (ch === "\r" || ch === "\n") {
278
- if (palette) {
279
- const all = [...AGENT_CMDS.map(c => c[1]), ...ACTION_CMDS.map(c => c[0])];
280
- const filtered = all.filter(a => a.includes(buf));
281
- if (filtered[selIdx])
282
- buf = filtered[selIdx];
283
- palette = false;
284
- render();
285
- stdin.setRawMode(false);
286
- stdin.pause();
287
- resolve(buf.trim());
288
- return;
289
- }
290
- stdin.setRawMode(false);
291
- stdin.pause();
292
- resolve(buf.trim());
293
- return;
294
- }
295
- if (ch === "\t") { /* ignore */
296
- return;
297
- }
298
- if (ch === "\x7f" || ch === "\b") {
299
- if (cursor > 0) {
300
- buf = buf.slice(0, cursor - 1) + buf.slice(cursor);
301
- cursor--;
302
- }
303
- if (!buf)
304
- palette = false;
305
- render();
306
- return;
307
- }
308
- if (ch === "\x03") {
309
- stdin.setRawMode(false);
310
- stdin.pause();
311
- resolve("/quit");
312
- return;
313
- }
314
- if (ch >= " ") {
315
- buf = buf.slice(0, cursor) + ch + buf.slice(cursor);
316
- cursor++;
317
- if (ch === "/") {
318
- palette = true;
319
- selIdx = 0;
320
- }
321
- else if (palette)
322
- selIdx = 0;
323
- render();
324
- return;
325
- }
326
- }
205
+ exports.StreamRenderer = StreamRenderer;
206
+ /* ════════════════════════════════════════
207
+ Input readline-based, robust line editing
208
+ ════════════════════════════════════════ */
209
+ /** Tab-completer for slash commands. */
210
+ function slashCompleter(line) {
211
+ if (!line.startsWith("/"))
212
+ return [[], line];
213
+ const names = exports.SLASH_COMMANDS.map(([c]) => c.trimEnd());
214
+ const hits = names.filter((c) => c.startsWith(line));
215
+ return [hits.length ? hits : names, line];
216
+ }
217
+ /** The prompt string for an agent: a small mineral seal + chevron. */
218
+ function promptFor(agentName) {
219
+ const t = (0, theme_1.agentTheme)(agentName);
220
+ return chalk_1.default.hex(t.hex)(` ${t.symbol} ${t.kanji} `) + chalk_1.default.hex(theme_1.PALETTE.inkLight)("");
221
+ }
222
+ /** Cross-turn input history (↑/↓), shared by every per-turn reader. */
223
+ const inputHistory = [];
224
+ /**
225
+ * Read one line with the agent-themed prompt. A fresh readline interface is
226
+ * created and closed per call — this deliberately avoids clashing with the
227
+ * separate readline prompts used by the setup wizard and tool-approval flow
228
+ * (two live interfaces on one stdin corrupt input). History is preserved
229
+ * manually across turns.
230
+ */
231
+ function readLine(agentName, out = process.stdout) {
232
+ return new Promise((resolve) => {
233
+ const rl = readline.createInterface({
234
+ input: process.stdin,
235
+ output: out,
236
+ completer: slashCompleter,
237
+ terminal: process.stdin.isTTY ?? false,
238
+ history: [...inputHistory],
239
+ historySize: 200,
240
+ });
241
+ rl.on("SIGINT", () => { out.write("\n" + chalk_1.default.dim(" 再会。\n")); rl.close(); process.exit(0); });
242
+ rl.question(promptFor(agentName), (answer) => {
243
+ const trimmed = answer.trim();
244
+ if (trimmed)
245
+ inputHistory.unshift(trimmed);
246
+ rl.close();
247
+ resolve(trimmed);
327
248
  });
328
249
  });
329
250
  }
251
+ /** Render the inline slash-command palette (printed, not full-screen). */
252
+ function renderPalette(filter) {
253
+ const f = filter.toLowerCase();
254
+ const matches = exports.SLASH_COMMANDS.filter(([c]) => c.toLowerCase().startsWith(f));
255
+ const list = matches.length ? matches : exports.SLASH_COMMANDS;
256
+ const lines = list.slice(0, 12).map(([cmd, desc]) => {
257
+ const isAgent = ["/fog", "/rain", "/frost", "/snow", "/dew", "/fair"].includes(cmd.trim());
258
+ const name = isAgent ? chalk_1.default.hex((0, theme_1.agentTheme)(cmd.trim().slice(1)).hex)(cmd.padEnd(12)) : chalk_1.default.hex(theme_1.PALETTE.inkMid)(cmd.padEnd(12));
259
+ return " " + name + chalk_1.default.hex(theme_1.PALETTE.inkLight)(desc);
260
+ });
261
+ return chalk_1.default.dim(" 命令 · Tab 补全\n") + lines.join("\n") + "\n";
262
+ }
330
263
  //# sourceMappingURL=tui.js.map